@jaypie/dynamodb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +15 -0
- package/dist/cjs/client.d.ts +27 -0
- package/dist/cjs/constants.d.ts +9 -0
- package/dist/cjs/entities.d.ts +71 -0
- package/dist/cjs/index.cjs +483 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/keyBuilders.d.ts +59 -0
- package/dist/cjs/queries.d.ts +48 -0
- package/dist/cjs/types.d.ts +142 -0
- package/dist/esm/client.d.ts +27 -0
- package/dist/esm/constants.d.ts +9 -0
- package/dist/esm/entities.d.ts +71 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +450 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/keyBuilders.d.ts +59 -0
- package/dist/esm/queries.d.ts +48 -0
- package/dist/esm/types.d.ts +142 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/client.ts","../../../src/constants.ts","../../../src/keyBuilders.ts","../../../src/entities.ts","../../../src/queries.ts"],"sourcesContent":["import { DynamoDBClient } from \"@aws-sdk/client-dynamodb\";\nimport { DynamoDBDocumentClient } from \"@aws-sdk/lib-dynamodb\";\nimport { ConfigurationError } from \"@jaypie/errors\";\n\nimport type { DynamoClientConfig } from \"./types.js\";\n\nconst DEFAULT_REGION = \"us-east-1\";\nconst LOCAL_CREDENTIALS = {\n accessKeyId: \"local\",\n secretAccessKey: \"local\",\n};\n\n// Module-level state\nlet docClient: DynamoDBDocumentClient | null = null;\nlet tableName: string | null = null;\n\n/**\n * Check if endpoint indicates local development mode\n */\nfunction isLocalEndpoint(endpoint?: string): boolean {\n if (!endpoint) return false;\n return endpoint.includes(\"127.0.0.1\") || endpoint.includes(\"localhost\");\n}\n\n/**\n * Initialize the DynamoDB client\n * Must be called once at application startup before using query functions\n *\n * @param config - Client configuration\n */\nexport function initClient(config: DynamoClientConfig): void {\n const { endpoint, region = DEFAULT_REGION } = config;\n\n // Auto-detect local mode and use dummy credentials\n const credentials =\n config.credentials ??\n (isLocalEndpoint(endpoint) ? LOCAL_CREDENTIALS : undefined);\n\n const dynamoClient = new DynamoDBClient({\n ...(credentials && { credentials }),\n ...(endpoint && { endpoint }),\n region,\n });\n\n docClient = DynamoDBDocumentClient.from(dynamoClient, {\n marshallOptions: {\n removeUndefinedValues: true,\n },\n });\n\n tableName = config.tableName;\n}\n\n/**\n * Get the initialized DynamoDB Document Client\n * @throws ConfigurationError if client has not been initialized\n */\nexport function getDocClient(): DynamoDBDocumentClient {\n if (!docClient) {\n throw new ConfigurationError(\n \"DynamoDB client not initialized. Call initClient() first.\",\n );\n }\n return docClient;\n}\n\n/**\n * Get the configured table name\n * @throws ConfigurationError if client has not been initialized\n */\nexport function getTableName(): string {\n if (!tableName) {\n throw new ConfigurationError(\n \"DynamoDB client not initialized. Call initClient() first.\",\n );\n }\n return tableName;\n}\n\n/**\n * Check if the client has been initialized\n */\nexport function isInitialized(): boolean {\n return docClient !== null && tableName !== null;\n}\n\n/**\n * Reset the client state (primarily for testing)\n */\nexport function resetClient(): void {\n docClient = null;\n tableName = null;\n}\n","// Primary markers\nexport const APEX = \"@\"; // Root-level marker (DynamoDB prohibits empty strings)\nexport const SEPARATOR = \"#\"; // Composite key separator\n\n// GSI names\nexport const INDEX_ALIAS = \"indexAlias\";\nexport const INDEX_CLASS = \"indexClass\";\nexport const INDEX_OU = \"indexOu\";\nexport const INDEX_TYPE = \"indexType\";\nexport const INDEX_XID = \"indexXid\";\n\n// Index suffixes for soft state\nexport const ARCHIVED_SUFFIX = \"#archived\";\nexport const DELETED_SUFFIX = \"#deleted\";\n","import { APEX, SEPARATOR } from \"./constants.js\";\nimport type { FabricEntity, ParentReference } from \"./types.js\";\n\n/**\n * Build the indexOu key for hierarchical queries\n * @param ou - The organizational unit (APEX or \"{parent.model}#{parent.id}\")\n * @param model - The entity model name\n * @returns Composite key: \"{ou}#{model}\"\n */\nexport function buildIndexOu(ou: string, model: string): string {\n return `${ou}${SEPARATOR}${model}`;\n}\n\n/**\n * Build the indexAlias key for human-friendly lookups\n * @param ou - The organizational unit\n * @param model - The entity model name\n * @param alias - The human-friendly alias\n * @returns Composite key: \"{ou}#{model}#{alias}\"\n */\nexport function buildIndexAlias(\n ou: string,\n model: string,\n alias: string,\n): string {\n return `${ou}${SEPARATOR}${model}${SEPARATOR}${alias}`;\n}\n\n/**\n * Build the indexClass key for category filtering\n * @param ou - The organizational unit\n * @param model - The entity model name\n * @param recordClass - The category classification\n * @returns Composite key: \"{ou}#{model}#{class}\"\n */\nexport function buildIndexClass(\n ou: string,\n model: string,\n recordClass: string,\n): string {\n return `${ou}${SEPARATOR}${model}${SEPARATOR}${recordClass}`;\n}\n\n/**\n * Build the indexType key for type filtering\n * @param ou - The organizational unit\n * @param model - The entity model name\n * @param type - The type classification\n * @returns Composite key: \"{ou}#{model}#{type}\"\n */\nexport function buildIndexType(\n ou: string,\n model: string,\n type: string,\n): string {\n return `${ou}${SEPARATOR}${model}${SEPARATOR}${type}`;\n}\n\n/**\n * Build the indexXid key for external ID lookups\n * @param ou - The organizational unit\n * @param model - The entity model name\n * @param xid - The external ID\n * @returns Composite key: \"{ou}#{model}#{xid}\"\n */\nexport function buildIndexXid(ou: string, model: string, xid: string): string {\n return `${ou}${SEPARATOR}${model}${SEPARATOR}${xid}`;\n}\n\n/**\n * Calculate the organizational unit from a parent reference\n * @param parent - Optional parent entity reference\n * @returns APEX (\"@\") if no parent, otherwise \"{parent.model}#{parent.id}\"\n */\nexport function calculateOu(parent?: ParentReference): string {\n if (!parent) {\n return APEX;\n }\n return `${parent.model}${SEPARATOR}${parent.id}`;\n}\n\n/**\n * Auto-populate GSI index keys on an entity\n * - indexOu is always populated from ou + model\n * - indexAlias is populated only when alias is present\n * - indexClass is populated only when class is present\n * - indexType is populated only when type is present\n * - indexXid is populated only when xid is present\n *\n * @param entity - The entity to populate index keys for\n * @param suffix - Optional suffix to append to all index keys (e.g., \"#deleted\", \"#archived\")\n * @returns The entity with populated index keys\n */\nexport function indexEntity<T extends FabricEntity>(\n entity: T,\n suffix: string = \"\",\n): T {\n const result = { ...entity };\n\n // indexOu is always set (from ou + model)\n result.indexOu = buildIndexOu(entity.ou, entity.model) + suffix;\n\n // Optional indexes - only set when the source field is present\n if (entity.alias !== undefined) {\n result.indexAlias =\n buildIndexAlias(entity.ou, entity.model, entity.alias) + suffix;\n }\n\n if (entity.class !== undefined) {\n result.indexClass =\n buildIndexClass(entity.ou, entity.model, entity.class) + suffix;\n }\n\n if (entity.type !== undefined) {\n result.indexType =\n buildIndexType(entity.ou, entity.model, entity.type) + suffix;\n }\n\n if (entity.xid !== undefined) {\n result.indexXid =\n buildIndexXid(entity.ou, entity.model, entity.xid) + suffix;\n }\n\n return result;\n}\n","import { DeleteCommand, GetCommand, PutCommand } from \"@aws-sdk/lib-dynamodb\";\n\nimport { getDocClient, getTableName } from \"./client.js\";\nimport { ARCHIVED_SUFFIX, DELETED_SUFFIX } from \"./constants.js\";\nimport { indexEntity } from \"./keyBuilders.js\";\nimport type { FabricEntity } from \"./types.js\";\n\n/**\n * Parameters for getEntity\n */\nexport interface GetEntityParams {\n /** Entity ID (sort key) */\n id: string;\n /** Entity model (partition key) */\n model: string;\n}\n\n/**\n * Parameters for putEntity\n */\nexport interface PutEntityParams<T extends FabricEntity> {\n /** The entity to save */\n entity: T;\n}\n\n/**\n * Parameters for updateEntity\n */\nexport interface UpdateEntityParams<T extends FabricEntity> {\n /** The entity with updated fields */\n entity: T;\n}\n\n/**\n * Parameters for deleteEntity (soft delete)\n */\nexport interface DeleteEntityParams {\n /** Entity ID (sort key) */\n id: string;\n /** Entity model (partition key) */\n model: string;\n}\n\n/**\n * Parameters for archiveEntity\n */\nexport interface ArchiveEntityParams {\n /** Entity ID (sort key) */\n id: string;\n /** Entity model (partition key) */\n model: string;\n}\n\n/**\n * Get a single entity by primary key\n */\nexport async function getEntity<T extends FabricEntity = FabricEntity>(\n params: GetEntityParams,\n): Promise<T | null> {\n const { id, model } = params;\n const docClient = getDocClient();\n const tableName = getTableName();\n\n const command = new GetCommand({\n Key: { id, model },\n TableName: tableName,\n });\n\n const response = await docClient.send(command);\n return (response.Item as T) ?? null;\n}\n\n/**\n * Put (create or replace) an entity\n * Auto-populates GSI index keys via indexEntity\n */\nexport async function putEntity<T extends FabricEntity>(\n params: PutEntityParams<T>,\n): Promise<T> {\n const { entity } = params;\n const docClient = getDocClient();\n const tableName = getTableName();\n\n // Auto-populate index keys\n const indexedEntity = indexEntity(entity);\n\n const command = new PutCommand({\n Item: indexedEntity,\n TableName: tableName,\n });\n\n await docClient.send(command);\n return indexedEntity;\n}\n\n/**\n * Update an existing entity\n * Auto-populates GSI index keys and sets updatedAt\n */\nexport async function updateEntity<T extends FabricEntity>(\n params: UpdateEntityParams<T>,\n): Promise<T> {\n const { entity } = params;\n const docClient = getDocClient();\n const tableName = getTableName();\n\n // Update timestamp and re-index\n const updatedEntity = indexEntity({\n ...entity,\n updatedAt: new Date().toISOString(),\n });\n\n const command = new PutCommand({\n Item: updatedEntity,\n TableName: tableName,\n });\n\n await docClient.send(command);\n return updatedEntity;\n}\n\n/**\n * Calculate suffix based on entity's archived/deleted state\n */\nfunction calculateEntitySuffix(entity: {\n archivedAt?: string;\n deletedAt?: string;\n}): string {\n const hasArchived = Boolean(entity.archivedAt);\n const hasDeleted = Boolean(entity.deletedAt);\n\n if (hasArchived && hasDeleted) {\n return ARCHIVED_SUFFIX + DELETED_SUFFIX;\n }\n if (hasArchived) {\n return ARCHIVED_SUFFIX;\n }\n if (hasDeleted) {\n return DELETED_SUFFIX;\n }\n return \"\";\n}\n\n/**\n * Soft delete an entity by setting deletedAt timestamp\n * Re-indexes with appropriate suffix based on archived/deleted state\n */\nexport async function deleteEntity(\n params: DeleteEntityParams,\n): Promise<boolean> {\n const { id, model } = params;\n const docClient = getDocClient();\n const tableName = getTableName();\n\n // Fetch the current entity\n const existing = await getEntity({ id, model });\n if (!existing) {\n return false;\n }\n\n const now = new Date().toISOString();\n\n // Build updated entity with deletedAt\n const updatedEntity = {\n ...existing,\n deletedAt: now,\n updatedAt: now,\n };\n\n // Calculate suffix based on combined state (may already be archived)\n const suffix = calculateEntitySuffix(updatedEntity);\n const deletedEntity = indexEntity(updatedEntity, suffix);\n\n const command = new PutCommand({\n Item: deletedEntity,\n TableName: tableName,\n });\n\n await docClient.send(command);\n return true;\n}\n\n/**\n * Archive an entity by setting archivedAt timestamp\n * Re-indexes with appropriate suffix based on archived/deleted state\n */\nexport async function archiveEntity(\n params: ArchiveEntityParams,\n): Promise<boolean> {\n const { id, model } = params;\n const docClient = getDocClient();\n const tableName = getTableName();\n\n // Fetch the current entity\n const existing = await getEntity({ id, model });\n if (!existing) {\n return false;\n }\n\n const now = new Date().toISOString();\n\n // Build updated entity with archivedAt\n const updatedEntity = {\n ...existing,\n archivedAt: now,\n updatedAt: now,\n };\n\n // Calculate suffix based on combined state (may already be deleted)\n const suffix = calculateEntitySuffix(updatedEntity);\n const archivedEntity = indexEntity(updatedEntity, suffix);\n\n const command = new PutCommand({\n Item: archivedEntity,\n TableName: tableName,\n });\n\n await docClient.send(command);\n return true;\n}\n\n/**\n * Hard delete an entity (permanently removes from table)\n * Use with caution - prefer deleteEntity for soft delete\n */\nexport async function destroyEntity(\n params: DeleteEntityParams,\n): Promise<boolean> {\n const { id, model } = params;\n const docClient = getDocClient();\n const tableName = getTableName();\n\n const command = new DeleteCommand({\n Key: { id, model },\n TableName: tableName,\n });\n\n await docClient.send(command);\n return true;\n}\n","import { QueryCommand } from \"@aws-sdk/lib-dynamodb\";\n\nimport { getDocClient, getTableName } from \"./client.js\";\nimport {\n ARCHIVED_SUFFIX,\n DELETED_SUFFIX,\n INDEX_ALIAS,\n INDEX_CLASS,\n INDEX_OU,\n INDEX_TYPE,\n INDEX_XID,\n} from \"./constants.js\";\nimport {\n buildIndexAlias,\n buildIndexClass,\n buildIndexOu,\n buildIndexType,\n buildIndexXid,\n} from \"./keyBuilders.js\";\nimport type {\n BaseQueryOptions,\n FabricEntity,\n QueryByAliasParams,\n QueryByClassParams,\n QueryByOuParams,\n QueryByTypeParams,\n QueryByXidParams,\n QueryResult,\n} from \"./types.js\";\n\n/**\n * Calculate the suffix based on archived/deleted flags\n * When both are true, returns combined suffix (archived first, alphabetically)\n */\nfunction calculateSuffix({\n archived,\n deleted,\n}: {\n archived?: boolean;\n deleted?: boolean;\n}): string {\n if (archived && deleted) {\n return ARCHIVED_SUFFIX + DELETED_SUFFIX;\n }\n if (archived) {\n return ARCHIVED_SUFFIX;\n }\n if (deleted) {\n return DELETED_SUFFIX;\n }\n return \"\";\n}\n\n/**\n * Execute a GSI query with common options\n */\nasync function executeQuery<T extends FabricEntity>(\n indexName: string,\n keyValue: string,\n options: BaseQueryOptions = {},\n): Promise<QueryResult<T>> {\n const { ascending = false, limit, startKey } = options;\n\n const docClient = getDocClient();\n const tableName = getTableName();\n\n const command = new QueryCommand({\n ExclusiveStartKey: startKey as Record<string, unknown> | undefined,\n ExpressionAttributeNames: {\n \"#pk\": indexName,\n },\n ExpressionAttributeValues: {\n \":pkValue\": keyValue,\n },\n IndexName: indexName,\n KeyConditionExpression: \"#pk = :pkValue\",\n ...(limit && { Limit: limit }),\n ScanIndexForward: ascending,\n TableName: tableName,\n });\n\n const response = await docClient.send(command);\n\n return {\n items: (response.Items ?? []) as T[],\n lastEvaluatedKey: response.LastEvaluatedKey,\n };\n}\n\n/**\n * Query entities by organizational unit (parent hierarchy)\n * Uses indexOu GSI\n *\n * @param params.archived - Query archived entities instead of active ones\n * @param params.deleted - Query deleted entities instead of active ones\n * @throws ConfigurationError if both archived and deleted are true\n */\nexport async function queryByOu<T extends FabricEntity = FabricEntity>(\n params: QueryByOuParams,\n): Promise<QueryResult<T>> {\n const { archived, deleted, model, ou, ...options } = params;\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexOu(ou, model) + suffix;\n return executeQuery<T>(INDEX_OU, keyValue, options);\n}\n\n/**\n * Query a single entity by human-friendly alias\n * Uses indexAlias GSI\n *\n * @param params.archived - Query archived entities instead of active ones\n * @param params.deleted - Query deleted entities instead of active ones\n * @throws ConfigurationError if both archived and deleted are true\n * @returns The matching entity or null if not found\n */\nexport async function queryByAlias<T extends FabricEntity = FabricEntity>(\n params: QueryByAliasParams,\n): Promise<T | null> {\n const { alias, archived, deleted, model, ou } = params;\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexAlias(ou, model, alias) + suffix;\n const result = await executeQuery<T>(INDEX_ALIAS, keyValue, { limit: 1 });\n return result.items[0] ?? null;\n}\n\n/**\n * Query entities by category classification\n * Uses indexClass GSI\n *\n * @param params.archived - Query archived entities instead of active ones\n * @param params.deleted - Query deleted entities instead of active ones\n * @throws ConfigurationError if both archived and deleted are true\n */\nexport async function queryByClass<T extends FabricEntity = FabricEntity>(\n params: QueryByClassParams,\n): Promise<QueryResult<T>> {\n const { archived, deleted, model, ou, recordClass, ...options } = params;\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexClass(ou, model, recordClass) + suffix;\n return executeQuery<T>(INDEX_CLASS, keyValue, options);\n}\n\n/**\n * Query entities by type classification\n * Uses indexType GSI\n *\n * @param params.archived - Query archived entities instead of active ones\n * @param params.deleted - Query deleted entities instead of active ones\n * @throws ConfigurationError if both archived and deleted are true\n */\nexport async function queryByType<T extends FabricEntity = FabricEntity>(\n params: QueryByTypeParams,\n): Promise<QueryResult<T>> {\n const { archived, deleted, model, ou, type, ...options } = params;\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexType(ou, model, type) + suffix;\n return executeQuery<T>(INDEX_TYPE, keyValue, options);\n}\n\n/**\n * Query a single entity by external ID\n * Uses indexXid GSI\n *\n * @param params.archived - Query archived entities instead of active ones\n * @param params.deleted - Query deleted entities instead of active ones\n * @throws ConfigurationError if both archived and deleted are true\n * @returns The matching entity or null if not found\n */\nexport async function queryByXid<T extends FabricEntity = FabricEntity>(\n params: QueryByXidParams,\n): Promise<T | null> {\n const { archived, deleted, model, ou, xid } = params;\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexXid(ou, model, xid) + suffix;\n const result = await executeQuery<T>(INDEX_XID, keyValue, { limit: 1 });\n return result.items[0] ?? null;\n}\n"],"names":["DynamoDBClient","DynamoDBDocumentClient","ConfigurationError","GetCommand","PutCommand","DeleteCommand","QueryCommand"],"mappings":";;;;;;AAMA,MAAM,cAAc,GAAG,WAAW;AAClC,MAAM,iBAAiB,GAAG;AACxB,IAAA,WAAW,EAAE,OAAO;AACpB,IAAA,eAAe,EAAE,OAAO;CACzB;AAED;AACA,IAAI,SAAS,GAAkC,IAAI;AACnD,IAAI,SAAS,GAAkB,IAAI;AAEnC;;AAEG;AACH,SAAS,eAAe,CAAC,QAAiB,EAAA;AACxC,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,KAAK;AAC3B,IAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC;AACzE;AAEA;;;;;AAKG;AACG,SAAU,UAAU,CAAC,MAA0B,EAAA;IACnD,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,GAAG,MAAM;;AAGpD,IAAA,MAAM,WAAW,GACf,MAAM,CAAC,WAAW;AAClB,SAAC,eAAe,CAAC,QAAQ,CAAC,GAAG,iBAAiB,GAAG,SAAS,CAAC;AAE7D,IAAA,MAAM,YAAY,GAAG,IAAIA,6BAAc,CAAC;AACtC,QAAA,IAAI,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;AACnC,QAAA,IAAI,QAAQ,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC7B,MAAM;AACP,KAAA,CAAC;AAEF,IAAA,SAAS,GAAGC,kCAAsB,CAAC,IAAI,CAAC,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zD,OAAO,YAAY,CAAI,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC;AACvD;AAEA;;;;;;;;AAQG;AACI,eAAe,UAAU,CAC9B,MAAwB,EAAA;AAExB,IAAA,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,MAAM;IACpD,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AACrD,IAAA,MAAM,QAAQ,GAAG,aAAa,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,MAAM;AACvD,IAAA,MAAM,MAAM,GAAG,MAAM,YAAY,CAAI,SAAS,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACvE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI;AAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { getDocClient, getTableName, initClient, isInitialized, resetClient, } from "./client.js";
|
|
2
|
+
export { APEX, ARCHIVED_SUFFIX, DELETED_SUFFIX, INDEX_ALIAS, INDEX_CLASS, INDEX_OU, INDEX_TYPE, INDEX_XID, SEPARATOR, } from "./constants.js";
|
|
3
|
+
export { archiveEntity, deleteEntity, destroyEntity, getEntity, putEntity, updateEntity, } from "./entities.js";
|
|
4
|
+
export { buildIndexAlias, buildIndexClass, buildIndexOu, buildIndexType, buildIndexXid, calculateOu, indexEntity, } from "./keyBuilders.js";
|
|
5
|
+
export { queryByAlias, queryByClass, queryByOu, queryByType, queryByXid, } from "./queries.js";
|
|
6
|
+
export type { ArchiveEntityParams, DeleteEntityParams, GetEntityParams, PutEntityParams, UpdateEntityParams, } from "./entities.js";
|
|
7
|
+
export type { BaseQueryOptions, DynamoClientConfig, FabricEntity, ParentReference, QueryByAliasParams, QueryByClassParams, QueryByOuParams, QueryByTypeParams, QueryByXidParams, QueryResult, } from "./types.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { FabricEntity, ParentReference } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the indexOu key for hierarchical queries
|
|
4
|
+
* @param ou - The organizational unit (APEX or "{parent.model}#{parent.id}")
|
|
5
|
+
* @param model - The entity model name
|
|
6
|
+
* @returns Composite key: "{ou}#{model}"
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildIndexOu(ou: string, model: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Build the indexAlias key for human-friendly lookups
|
|
11
|
+
* @param ou - The organizational unit
|
|
12
|
+
* @param model - The entity model name
|
|
13
|
+
* @param alias - The human-friendly alias
|
|
14
|
+
* @returns Composite key: "{ou}#{model}#{alias}"
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildIndexAlias(ou: string, model: string, alias: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Build the indexClass key for category filtering
|
|
19
|
+
* @param ou - The organizational unit
|
|
20
|
+
* @param model - The entity model name
|
|
21
|
+
* @param recordClass - The category classification
|
|
22
|
+
* @returns Composite key: "{ou}#{model}#{class}"
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildIndexClass(ou: string, model: string, recordClass: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Build the indexType key for type filtering
|
|
27
|
+
* @param ou - The organizational unit
|
|
28
|
+
* @param model - The entity model name
|
|
29
|
+
* @param type - The type classification
|
|
30
|
+
* @returns Composite key: "{ou}#{model}#{type}"
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildIndexType(ou: string, model: string, type: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Build the indexXid key for external ID lookups
|
|
35
|
+
* @param ou - The organizational unit
|
|
36
|
+
* @param model - The entity model name
|
|
37
|
+
* @param xid - The external ID
|
|
38
|
+
* @returns Composite key: "{ou}#{model}#{xid}"
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildIndexXid(ou: string, model: string, xid: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Calculate the organizational unit from a parent reference
|
|
43
|
+
* @param parent - Optional parent entity reference
|
|
44
|
+
* @returns APEX ("@") if no parent, otherwise "{parent.model}#{parent.id}"
|
|
45
|
+
*/
|
|
46
|
+
export declare function calculateOu(parent?: ParentReference): string;
|
|
47
|
+
/**
|
|
48
|
+
* Auto-populate GSI index keys on an entity
|
|
49
|
+
* - indexOu is always populated from ou + model
|
|
50
|
+
* - indexAlias is populated only when alias is present
|
|
51
|
+
* - indexClass is populated only when class is present
|
|
52
|
+
* - indexType is populated only when type is present
|
|
53
|
+
* - indexXid is populated only when xid is present
|
|
54
|
+
*
|
|
55
|
+
* @param entity - The entity to populate index keys for
|
|
56
|
+
* @param suffix - Optional suffix to append to all index keys (e.g., "#deleted", "#archived")
|
|
57
|
+
* @returns The entity with populated index keys
|
|
58
|
+
*/
|
|
59
|
+
export declare function indexEntity<T extends FabricEntity>(entity: T, suffix?: string): T;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { FabricEntity, QueryByAliasParams, QueryByClassParams, QueryByOuParams, QueryByTypeParams, QueryByXidParams, QueryResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Query entities by organizational unit (parent hierarchy)
|
|
4
|
+
* Uses indexOu GSI
|
|
5
|
+
*
|
|
6
|
+
* @param params.archived - Query archived entities instead of active ones
|
|
7
|
+
* @param params.deleted - Query deleted entities instead of active ones
|
|
8
|
+
* @throws ConfigurationError if both archived and deleted are true
|
|
9
|
+
*/
|
|
10
|
+
export declare function queryByOu<T extends FabricEntity = FabricEntity>(params: QueryByOuParams): Promise<QueryResult<T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Query a single entity by human-friendly alias
|
|
13
|
+
* Uses indexAlias GSI
|
|
14
|
+
*
|
|
15
|
+
* @param params.archived - Query archived entities instead of active ones
|
|
16
|
+
* @param params.deleted - Query deleted entities instead of active ones
|
|
17
|
+
* @throws ConfigurationError if both archived and deleted are true
|
|
18
|
+
* @returns The matching entity or null if not found
|
|
19
|
+
*/
|
|
20
|
+
export declare function queryByAlias<T extends FabricEntity = FabricEntity>(params: QueryByAliasParams): Promise<T | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Query entities by category classification
|
|
23
|
+
* Uses indexClass GSI
|
|
24
|
+
*
|
|
25
|
+
* @param params.archived - Query archived entities instead of active ones
|
|
26
|
+
* @param params.deleted - Query deleted entities instead of active ones
|
|
27
|
+
* @throws ConfigurationError if both archived and deleted are true
|
|
28
|
+
*/
|
|
29
|
+
export declare function queryByClass<T extends FabricEntity = FabricEntity>(params: QueryByClassParams): Promise<QueryResult<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* Query entities by type classification
|
|
32
|
+
* Uses indexType GSI
|
|
33
|
+
*
|
|
34
|
+
* @param params.archived - Query archived entities instead of active ones
|
|
35
|
+
* @param params.deleted - Query deleted entities instead of active ones
|
|
36
|
+
* @throws ConfigurationError if both archived and deleted are true
|
|
37
|
+
*/
|
|
38
|
+
export declare function queryByType<T extends FabricEntity = FabricEntity>(params: QueryByTypeParams): Promise<QueryResult<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* Query a single entity by external ID
|
|
41
|
+
* Uses indexXid GSI
|
|
42
|
+
*
|
|
43
|
+
* @param params.archived - Query archived entities instead of active ones
|
|
44
|
+
* @param params.deleted - Query deleted entities instead of active ones
|
|
45
|
+
* @throws ConfigurationError if both archived and deleted are true
|
|
46
|
+
* @returns The matching entity or null if not found
|
|
47
|
+
*/
|
|
48
|
+
export declare function queryByXid<T extends FabricEntity = FabricEntity>(params: QueryByXidParams): Promise<T | null>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DynamoDB client configuration
|
|
3
|
+
*/
|
|
4
|
+
export interface DynamoClientConfig {
|
|
5
|
+
/** DynamoDB table name */
|
|
6
|
+
tableName: string;
|
|
7
|
+
/** Optional endpoint URL for local development (e.g., "http://127.0.0.1:8100") */
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
/** AWS region (default: "us-east-1") */
|
|
10
|
+
region?: string;
|
|
11
|
+
/** Optional credentials for local development */
|
|
12
|
+
credentials?: {
|
|
13
|
+
accessKeyId: string;
|
|
14
|
+
secretAccessKey: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parent reference for calculating OU
|
|
19
|
+
*/
|
|
20
|
+
export interface ParentReference {
|
|
21
|
+
id: string;
|
|
22
|
+
model: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Base query options shared by all query functions
|
|
26
|
+
*/
|
|
27
|
+
export interface BaseQueryOptions {
|
|
28
|
+
/** Query archived entities instead of active ones */
|
|
29
|
+
archived?: boolean;
|
|
30
|
+
/** Whether to sort ascending (oldest first). Default: false (most recent first) */
|
|
31
|
+
ascending?: boolean;
|
|
32
|
+
/** Query deleted entities instead of active ones */
|
|
33
|
+
deleted?: boolean;
|
|
34
|
+
/** Maximum number of items to return */
|
|
35
|
+
limit?: number;
|
|
36
|
+
/** Pagination cursor from previous query */
|
|
37
|
+
startKey?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parameters for queryByOu
|
|
41
|
+
*/
|
|
42
|
+
export interface QueryByOuParams extends BaseQueryOptions {
|
|
43
|
+
/** The entity model name */
|
|
44
|
+
model: string;
|
|
45
|
+
/** The organizational unit (APEX or "{parent.model}#{parent.id}") */
|
|
46
|
+
ou: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parameters for queryByAlias
|
|
50
|
+
*/
|
|
51
|
+
export interface QueryByAliasParams {
|
|
52
|
+
/** The human-friendly alias */
|
|
53
|
+
alias: string;
|
|
54
|
+
/** Query archived entities instead of active ones */
|
|
55
|
+
archived?: boolean;
|
|
56
|
+
/** Query deleted entities instead of active ones */
|
|
57
|
+
deleted?: boolean;
|
|
58
|
+
/** The entity model name */
|
|
59
|
+
model: string;
|
|
60
|
+
/** The organizational unit */
|
|
61
|
+
ou: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parameters for queryByClass
|
|
65
|
+
*/
|
|
66
|
+
export interface QueryByClassParams extends BaseQueryOptions {
|
|
67
|
+
/** The entity model name */
|
|
68
|
+
model: string;
|
|
69
|
+
/** The organizational unit */
|
|
70
|
+
ou: string;
|
|
71
|
+
/** The category classification */
|
|
72
|
+
recordClass: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parameters for queryByType
|
|
76
|
+
*/
|
|
77
|
+
export interface QueryByTypeParams extends BaseQueryOptions {
|
|
78
|
+
/** The entity model name */
|
|
79
|
+
model: string;
|
|
80
|
+
/** The organizational unit */
|
|
81
|
+
ou: string;
|
|
82
|
+
/** The type classification */
|
|
83
|
+
type: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parameters for queryByXid
|
|
87
|
+
*/
|
|
88
|
+
export interface QueryByXidParams {
|
|
89
|
+
/** Query archived entities instead of active ones */
|
|
90
|
+
archived?: boolean;
|
|
91
|
+
/** Query deleted entities instead of active ones */
|
|
92
|
+
deleted?: boolean;
|
|
93
|
+
/** The entity model name */
|
|
94
|
+
model: string;
|
|
95
|
+
/** The organizational unit */
|
|
96
|
+
ou: string;
|
|
97
|
+
/** The external ID */
|
|
98
|
+
xid: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Result of a query operation
|
|
102
|
+
*/
|
|
103
|
+
export interface QueryResult<T = FabricEntity> {
|
|
104
|
+
/** Array of matching entities */
|
|
105
|
+
items: T[];
|
|
106
|
+
/** Pagination cursor for next page (undefined if no more results) */
|
|
107
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Base entity interface for DynamoDB single-table design
|
|
111
|
+
*/
|
|
112
|
+
export interface FabricEntity {
|
|
113
|
+
/** Partition key (e.g., "record", "message") */
|
|
114
|
+
model: string;
|
|
115
|
+
/** Sort key (UUID) */
|
|
116
|
+
id: string;
|
|
117
|
+
/** Human-readable name */
|
|
118
|
+
name: string;
|
|
119
|
+
/** Organizational unit: APEX ("@") or "{parent.model}#{parent.id}" */
|
|
120
|
+
ou: string;
|
|
121
|
+
/** Timestamp for chronological ordering (Date.now()) */
|
|
122
|
+
sequence: number;
|
|
123
|
+
indexAlias?: string;
|
|
124
|
+
indexClass?: string;
|
|
125
|
+
indexOu?: string;
|
|
126
|
+
indexType?: string;
|
|
127
|
+
indexXid?: string;
|
|
128
|
+
/** Human-friendly slug/alias */
|
|
129
|
+
alias?: string;
|
|
130
|
+
/** Category classification */
|
|
131
|
+
class?: string;
|
|
132
|
+
/** Type classification */
|
|
133
|
+
type?: string;
|
|
134
|
+
/** External ID for integration with external systems */
|
|
135
|
+
xid?: string;
|
|
136
|
+
createdAt: string;
|
|
137
|
+
updatedAt: string;
|
|
138
|
+
/** Archive timestamp (for inactive but preserved records) */
|
|
139
|
+
archivedAt?: string;
|
|
140
|
+
/** Soft-delete timestamp */
|
|
141
|
+
deletedAt?: string;
|
|
142
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import type { DynamoClientConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Initialize the DynamoDB client
|
|
5
|
+
* Must be called once at application startup before using query functions
|
|
6
|
+
*
|
|
7
|
+
* @param config - Client configuration
|
|
8
|
+
*/
|
|
9
|
+
export declare function initClient(config: DynamoClientConfig): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get the initialized DynamoDB Document Client
|
|
12
|
+
* @throws ConfigurationError if client has not been initialized
|
|
13
|
+
*/
|
|
14
|
+
export declare function getDocClient(): DynamoDBDocumentClient;
|
|
15
|
+
/**
|
|
16
|
+
* Get the configured table name
|
|
17
|
+
* @throws ConfigurationError if client has not been initialized
|
|
18
|
+
*/
|
|
19
|
+
export declare function getTableName(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Check if the client has been initialized
|
|
22
|
+
*/
|
|
23
|
+
export declare function isInitialized(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Reset the client state (primarily for testing)
|
|
26
|
+
*/
|
|
27
|
+
export declare function resetClient(): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const APEX = "@";
|
|
2
|
+
export declare const SEPARATOR = "#";
|
|
3
|
+
export declare const INDEX_ALIAS = "indexAlias";
|
|
4
|
+
export declare const INDEX_CLASS = "indexClass";
|
|
5
|
+
export declare const INDEX_OU = "indexOu";
|
|
6
|
+
export declare const INDEX_TYPE = "indexType";
|
|
7
|
+
export declare const INDEX_XID = "indexXid";
|
|
8
|
+
export declare const ARCHIVED_SUFFIX = "#archived";
|
|
9
|
+
export declare const DELETED_SUFFIX = "#deleted";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { FabricEntity } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for getEntity
|
|
4
|
+
*/
|
|
5
|
+
export interface GetEntityParams {
|
|
6
|
+
/** Entity ID (sort key) */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Entity model (partition key) */
|
|
9
|
+
model: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parameters for putEntity
|
|
13
|
+
*/
|
|
14
|
+
export interface PutEntityParams<T extends FabricEntity> {
|
|
15
|
+
/** The entity to save */
|
|
16
|
+
entity: T;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parameters for updateEntity
|
|
20
|
+
*/
|
|
21
|
+
export interface UpdateEntityParams<T extends FabricEntity> {
|
|
22
|
+
/** The entity with updated fields */
|
|
23
|
+
entity: T;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parameters for deleteEntity (soft delete)
|
|
27
|
+
*/
|
|
28
|
+
export interface DeleteEntityParams {
|
|
29
|
+
/** Entity ID (sort key) */
|
|
30
|
+
id: string;
|
|
31
|
+
/** Entity model (partition key) */
|
|
32
|
+
model: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parameters for archiveEntity
|
|
36
|
+
*/
|
|
37
|
+
export interface ArchiveEntityParams {
|
|
38
|
+
/** Entity ID (sort key) */
|
|
39
|
+
id: string;
|
|
40
|
+
/** Entity model (partition key) */
|
|
41
|
+
model: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a single entity by primary key
|
|
45
|
+
*/
|
|
46
|
+
export declare function getEntity<T extends FabricEntity = FabricEntity>(params: GetEntityParams): Promise<T | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Put (create or replace) an entity
|
|
49
|
+
* Auto-populates GSI index keys via indexEntity
|
|
50
|
+
*/
|
|
51
|
+
export declare function putEntity<T extends FabricEntity>(params: PutEntityParams<T>): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Update an existing entity
|
|
54
|
+
* Auto-populates GSI index keys and sets updatedAt
|
|
55
|
+
*/
|
|
56
|
+
export declare function updateEntity<T extends FabricEntity>(params: UpdateEntityParams<T>): Promise<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Soft delete an entity by setting deletedAt timestamp
|
|
59
|
+
* Re-indexes with appropriate suffix based on archived/deleted state
|
|
60
|
+
*/
|
|
61
|
+
export declare function deleteEntity(params: DeleteEntityParams): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Archive an entity by setting archivedAt timestamp
|
|
64
|
+
* Re-indexes with appropriate suffix based on archived/deleted state
|
|
65
|
+
*/
|
|
66
|
+
export declare function archiveEntity(params: ArchiveEntityParams): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Hard delete an entity (permanently removes from table)
|
|
69
|
+
* Use with caution - prefer deleteEntity for soft delete
|
|
70
|
+
*/
|
|
71
|
+
export declare function destroyEntity(params: DeleteEntityParams): Promise<boolean>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { getDocClient, getTableName, initClient, isInitialized, resetClient, } from "./client.js";
|
|
2
|
+
export { APEX, ARCHIVED_SUFFIX, DELETED_SUFFIX, INDEX_ALIAS, INDEX_CLASS, INDEX_OU, INDEX_TYPE, INDEX_XID, SEPARATOR, } from "./constants.js";
|
|
3
|
+
export { archiveEntity, deleteEntity, destroyEntity, getEntity, putEntity, updateEntity, } from "./entities.js";
|
|
4
|
+
export { buildIndexAlias, buildIndexClass, buildIndexOu, buildIndexType, buildIndexXid, calculateOu, indexEntity, } from "./keyBuilders.js";
|
|
5
|
+
export { queryByAlias, queryByClass, queryByOu, queryByType, queryByXid, } from "./queries.js";
|
|
6
|
+
export type { ArchiveEntityParams, DeleteEntityParams, GetEntityParams, PutEntityParams, UpdateEntityParams, } from "./entities.js";
|
|
7
|
+
export type { BaseQueryOptions, DynamoClientConfig, FabricEntity, ParentReference, QueryByAliasParams, QueryByClassParams, QueryByOuParams, QueryByTypeParams, QueryByXidParams, QueryResult, } from "./types.js";
|