@patternmeshjs/core
v0.9.1
Published
TypeScript-first DynamoDB modeling: logical entities, hidden keys, explicit access patterns, and typed repositories for single-table design.
Downloads
25
Maintainers
Readme
@patternmeshjs/core
The core modeling package for patternmesh.
It provides:
- table and entity declarations
- access-pattern compilation
- typed repositories
- update builders and conditions
- transactions, batch APIs, relations, read bundles, and write recipes
- lifecycle recipes (
softDelete,archive)
Install
pnpm add @patternmeshjs/coreRequirements:
- Node 18+
- ESM-only
Public API reference
Table and keys
defineTablekeyBrand
Field builders
stringnumberbooleandatetimeenumTypeidjsonttlobjectrecordliststringSetnumberSetfieldRefpathRef
Field and schema types
FieldDefSchemaRecordInferItemCreateInputPrimaryKeyInputSettableShapeAddableShapeRemovableKeysFieldRef
Entity compilation
entityCompiledEntityCOMPILED_ENTITY
Connection and repositories
connectConnectOptionsConnectedDb
Each repository exposes:
create(data, options?)— strict not-exists writeput(data, options?)— unconditional writeget(key)delete(key, options?)find.<pattern>(input)batchGet(keys)batchWrite({ puts, deletes })update(key)explain.createexplain.putexplain.getexplain.deleteexplain.find.<pattern>explain.batchGetexplain.batchWrite
Relations, bundles, and recipes
createRelationscreateReadBundlescreateWriteRecipesRelationBuilderReadBundleBuilderReadBundleStepBuilderWriteRecipeBuilderWriteRecipeStepBuilderRelationDeclRelationsConfigHasManyDeclBelongsToDeclHasManyThroughDeclReadBundleStepDeclReadBundleDeclReadBundlesConfigWriteRecipeStepDeclWriteRecipeDeclWriteRecipesConfig
Transactions
TRANSACT_MAX_ITEMSTransactWriteBuilderTransactReadBuildercreateTransactServices
Core types
CompiledOperationPageOpaqueCursorDynamoReadPlanAccessPatternDefFieldMetaBatchChunkPlanQuerySelectModeReturnConsumedCapacityMode
Adapter-facing types
DynamoAdapterGetItemInputPutItemInputDeleteItemInputDeleteItemOutputQueryInputUpdateItemInputQueryOutputScanInputScanOutputConsumedCapacityPutItemOutputBatchGetItemInputBatchGetItemOutputBatchWriteItemInputBatchWriteItemOutputBatchWritePutBatchWriteDeleteTransactGetSlotTransactGetItemsInputTransactGetItemsOutputTransactWriteItemInputTransactWriteItemsInput
Errors
DynamoModelErrorValidationErrorConfigurationErrorConditionFailedErrorItemAlreadyExistsErrorNotUniqueErrorQueryLimitErrorBatchWriteExhaustedErrorBatchGetExhaustedErrorTransactionCanceledErrorIdempotentParameterMismatchErrorTransactionCancellationReason
Utilities
createAccessPatternFactoryBATCH_GET_MAX_KEYSBATCH_WRITE_MAX_OPSchunkArrayCreateReturnModeDeleteReturnModeencodeCursordecodeCursor
Behavioral contracts
Repository semantics
create()enforcesattribute_not_exists(partitionKey)and throwsItemAlreadyExistsErroron collision.put()overwrites unconditionally.- public items omit
pk,sk, index key attributes, and the internal discriminator.
Batch contracts
batchGet(keys)preserves input order and returnsnullfor misses.batchWrite({ puts, deletes })is chunked per DynamoDB limits and throwsBatchWriteExhaustedErrorif unprocessed items remain after retries.
Query / scan rules
ConsistentReadon a GSI route throwsValidationError.ap.count(...)is the supported COUNT surface.ap.scan(...)is explicit; there is no implicit repository scan.
Transactions
db.tx.writesupports at most 100 participants.- duplicate write targets are rejected before calling DynamoDB.
- writes accept
clientRequestTokenfor DynamoDB's 10-minute idempotency window.
Validation
- unknown create/update keys throw
ValidationError - empty Dynamo sets are rejected
ttl()values must be non-negative integer epoch secondsjson()values must be JSON-serializable- cursor decoding validates shape and rejects malformed payloads
Modeling guidance
- Embed
object,list, and set fields when data is bounded and read with the parent item. - Prefer child items and explicit access patterns for large or independently queried collections.
- Reserve logical field names for domain data only; internal table/index attribute names are rejected.
