@jaypie/dynamodb 0.1.0 → 0.1.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/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
- import { DynamoDBDocumentClient, PutCommand, DeleteCommand, GetCommand, QueryCommand } from '@aws-sdk/lib-dynamodb';
2
+ import { DynamoDBDocumentClient, GetCommand, PutCommand, DeleteCommand, QueryCommand } from '@aws-sdk/lib-dynamodb';
3
3
  import { ConfigurationError } from '@jaypie/errors';
4
+ import { serviceHandler } from '@jaypie/vocabulary';
4
5
 
5
6
  const DEFAULT_REGION = "us-east-1";
6
7
  const LOCAL_CREDENTIALS = {
@@ -185,25 +186,51 @@ function indexEntity(entity, suffix = "") {
185
186
  }
186
187
 
187
188
  /**
188
- * Get a single entity by primary key
189
+ * Calculate suffix based on entity's archived/deleted state
189
190
  */
190
- async function getEntity(params) {
191
- const { id, model } = params;
192
- const docClient = getDocClient();
193
- const tableName = getTableName();
194
- const command = new GetCommand({
195
- Key: { id, model },
196
- TableName: tableName,
197
- });
198
- const response = await docClient.send(command);
199
- return response.Item ?? null;
191
+ function calculateEntitySuffix(entity) {
192
+ const hasArchived = Boolean(entity.archivedAt);
193
+ const hasDeleted = Boolean(entity.deletedAt);
194
+ if (hasArchived && hasDeleted) {
195
+ return ARCHIVED_SUFFIX + DELETED_SUFFIX;
196
+ }
197
+ if (hasArchived) {
198
+ return ARCHIVED_SUFFIX;
199
+ }
200
+ if (hasDeleted) {
201
+ return DELETED_SUFFIX;
202
+ }
203
+ return "";
200
204
  }
205
+ /**
206
+ * Get a single entity by primary key
207
+ */
208
+ const getEntity = serviceHandler({
209
+ alias: "getEntity",
210
+ description: "Get a single entity by primary key",
211
+ input: {
212
+ id: { type: String, description: "Entity ID (sort key)" },
213
+ model: { type: String, description: "Entity model (partition key)" },
214
+ },
215
+ service: async ({ id, model }) => {
216
+ const docClient = getDocClient();
217
+ const tableName = getTableName();
218
+ const command = new GetCommand({
219
+ Key: { id, model },
220
+ TableName: tableName,
221
+ });
222
+ const response = await docClient.send(command);
223
+ return response.Item ?? null;
224
+ },
225
+ });
201
226
  /**
202
227
  * Put (create or replace) an entity
203
228
  * Auto-populates GSI index keys via indexEntity
229
+ *
230
+ * Note: This is a regular async function (not serviceHandler) because it accepts
231
+ * complex FabricEntity objects that can't be coerced by vocabulary's type system.
204
232
  */
205
- async function putEntity(params) {
206
- const { entity } = params;
233
+ async function putEntity({ entity, }) {
207
234
  const docClient = getDocClient();
208
235
  const tableName = getTableName();
209
236
  // Auto-populate index keys
@@ -218,9 +245,11 @@ async function putEntity(params) {
218
245
  /**
219
246
  * Update an existing entity
220
247
  * Auto-populates GSI index keys and sets updatedAt
248
+ *
249
+ * Note: This is a regular async function (not serviceHandler) because it accepts
250
+ * complex FabricEntity objects that can't be coerced by vocabulary's type system.
221
251
  */
222
- async function updateEntity(params) {
223
- const { entity } = params;
252
+ async function updateEntity({ entity, }) {
224
253
  const docClient = getDocClient();
225
254
  const tableName = getTableName();
226
255
  // Update timestamp and re-index
@@ -235,98 +264,102 @@ async function updateEntity(params) {
235
264
  await docClient.send(command);
236
265
  return updatedEntity;
237
266
  }
238
- /**
239
- * Calculate suffix based on entity's archived/deleted state
240
- */
241
- function calculateEntitySuffix(entity) {
242
- const hasArchived = Boolean(entity.archivedAt);
243
- const hasDeleted = Boolean(entity.deletedAt);
244
- if (hasArchived && hasDeleted) {
245
- return ARCHIVED_SUFFIX + DELETED_SUFFIX;
246
- }
247
- if (hasArchived) {
248
- return ARCHIVED_SUFFIX;
249
- }
250
- if (hasDeleted) {
251
- return DELETED_SUFFIX;
252
- }
253
- return "";
254
- }
255
267
  /**
256
268
  * Soft delete an entity by setting deletedAt timestamp
257
269
  * Re-indexes with appropriate suffix based on archived/deleted state
258
270
  */
259
- async function deleteEntity(params) {
260
- const { id, model } = params;
261
- const docClient = getDocClient();
262
- const tableName = getTableName();
263
- // Fetch the current entity
264
- const existing = await getEntity({ id, model });
265
- if (!existing) {
266
- return false;
267
- }
268
- const now = new Date().toISOString();
269
- // Build updated entity with deletedAt
270
- const updatedEntity = {
271
- ...existing,
272
- deletedAt: now,
273
- updatedAt: now,
274
- };
275
- // Calculate suffix based on combined state (may already be archived)
276
- const suffix = calculateEntitySuffix(updatedEntity);
277
- const deletedEntity = indexEntity(updatedEntity, suffix);
278
- const command = new PutCommand({
279
- Item: deletedEntity,
280
- TableName: tableName,
281
- });
282
- await docClient.send(command);
283
- return true;
284
- }
271
+ const deleteEntity = serviceHandler({
272
+ alias: "deleteEntity",
273
+ description: "Soft delete an entity (sets deletedAt timestamp)",
274
+ input: {
275
+ id: { type: String, description: "Entity ID (sort key)" },
276
+ model: { type: String, description: "Entity model (partition key)" },
277
+ },
278
+ service: async ({ id, model }) => {
279
+ const docClient = getDocClient();
280
+ const tableName = getTableName();
281
+ // Fetch the current entity
282
+ const existing = await getEntity({ id, model });
283
+ if (!existing) {
284
+ return false;
285
+ }
286
+ const now = new Date().toISOString();
287
+ // Build updated entity with deletedAt
288
+ const updatedEntity = {
289
+ ...existing,
290
+ deletedAt: now,
291
+ updatedAt: now,
292
+ };
293
+ // Calculate suffix based on combined state (may already be archived)
294
+ const suffix = calculateEntitySuffix(updatedEntity);
295
+ const deletedEntity = indexEntity(updatedEntity, suffix);
296
+ const command = new PutCommand({
297
+ Item: deletedEntity,
298
+ TableName: tableName,
299
+ });
300
+ await docClient.send(command);
301
+ return true;
302
+ },
303
+ });
285
304
  /**
286
305
  * Archive an entity by setting archivedAt timestamp
287
306
  * Re-indexes with appropriate suffix based on archived/deleted state
288
307
  */
289
- async function archiveEntity(params) {
290
- const { id, model } = params;
291
- const docClient = getDocClient();
292
- const tableName = getTableName();
293
- // Fetch the current entity
294
- const existing = await getEntity({ id, model });
295
- if (!existing) {
296
- return false;
297
- }
298
- const now = new Date().toISOString();
299
- // Build updated entity with archivedAt
300
- const updatedEntity = {
301
- ...existing,
302
- archivedAt: now,
303
- updatedAt: now,
304
- };
305
- // Calculate suffix based on combined state (may already be deleted)
306
- const suffix = calculateEntitySuffix(updatedEntity);
307
- const archivedEntity = indexEntity(updatedEntity, suffix);
308
- const command = new PutCommand({
309
- Item: archivedEntity,
310
- TableName: tableName,
311
- });
312
- await docClient.send(command);
313
- return true;
314
- }
308
+ const archiveEntity = serviceHandler({
309
+ alias: "archiveEntity",
310
+ description: "Archive an entity (sets archivedAt timestamp)",
311
+ input: {
312
+ id: { type: String, description: "Entity ID (sort key)" },
313
+ model: { type: String, description: "Entity model (partition key)" },
314
+ },
315
+ service: async ({ id, model }) => {
316
+ const docClient = getDocClient();
317
+ const tableName = getTableName();
318
+ // Fetch the current entity
319
+ const existing = await getEntity({ id, model });
320
+ if (!existing) {
321
+ return false;
322
+ }
323
+ const now = new Date().toISOString();
324
+ // Build updated entity with archivedAt
325
+ const updatedEntity = {
326
+ ...existing,
327
+ archivedAt: now,
328
+ updatedAt: now,
329
+ };
330
+ // Calculate suffix based on combined state (may already be deleted)
331
+ const suffix = calculateEntitySuffix(updatedEntity);
332
+ const archivedEntity = indexEntity(updatedEntity, suffix);
333
+ const command = new PutCommand({
334
+ Item: archivedEntity,
335
+ TableName: tableName,
336
+ });
337
+ await docClient.send(command);
338
+ return true;
339
+ },
340
+ });
315
341
  /**
316
342
  * Hard delete an entity (permanently removes from table)
317
343
  * Use with caution - prefer deleteEntity for soft delete
318
344
  */
319
- async function destroyEntity(params) {
320
- const { id, model } = params;
321
- const docClient = getDocClient();
322
- const tableName = getTableName();
323
- const command = new DeleteCommand({
324
- Key: { id, model },
325
- TableName: tableName,
326
- });
327
- await docClient.send(command);
328
- return true;
329
- }
345
+ const destroyEntity = serviceHandler({
346
+ alias: "destroyEntity",
347
+ description: "Hard delete an entity (permanently removes from table)",
348
+ input: {
349
+ id: { type: String, description: "Entity ID (sort key)" },
350
+ model: { type: String, description: "Entity model (partition key)" },
351
+ },
352
+ service: async ({ id, model }) => {
353
+ const docClient = getDocClient();
354
+ const tableName = getTableName();
355
+ const command = new DeleteCommand({
356
+ Key: { id, model },
357
+ TableName: tableName,
358
+ });
359
+ await docClient.send(command);
360
+ return true;
361
+ },
362
+ });
330
363
 
331
364
  /**
332
365
  * Calculate the suffix based on archived/deleted flags
@@ -375,76 +408,126 @@ async function executeQuery(indexName, keyValue, options = {}) {
375
408
  * Query entities by organizational unit (parent hierarchy)
376
409
  * Uses indexOu GSI
377
410
  *
378
- * @param params.archived - Query archived entities instead of active ones
379
- * @param params.deleted - Query deleted entities instead of active ones
380
- * @throws ConfigurationError if both archived and deleted are true
411
+ * Note: This is a regular async function (not serviceHandler) because it accepts
412
+ * complex startKey objects that can't be coerced by vocabulary's type system.
381
413
  */
382
- async function queryByOu(params) {
383
- const { archived, deleted, model, ou, ...options } = params;
414
+ async function queryByOu({ archived = false, ascending = false, deleted = false, limit, model, ou, startKey, }) {
384
415
  const suffix = calculateSuffix({ archived, deleted });
385
416
  const keyValue = buildIndexOu(ou, model) + suffix;
386
- return executeQuery(INDEX_OU, keyValue, options);
417
+ return executeQuery(INDEX_OU, keyValue, {
418
+ ascending,
419
+ limit,
420
+ startKey,
421
+ });
387
422
  }
388
423
  /**
389
424
  * Query a single entity by human-friendly alias
390
425
  * Uses indexAlias GSI
391
- *
392
- * @param params.archived - Query archived entities instead of active ones
393
- * @param params.deleted - Query deleted entities instead of active ones
394
- * @throws ConfigurationError if both archived and deleted are true
395
- * @returns The matching entity or null if not found
396
426
  */
397
- async function queryByAlias(params) {
398
- const { alias, archived, deleted, model, ou } = params;
399
- const suffix = calculateSuffix({ archived, deleted });
400
- const keyValue = buildIndexAlias(ou, model, alias) + suffix;
401
- const result = await executeQuery(INDEX_ALIAS, keyValue, { limit: 1 });
402
- return result.items[0] ?? null;
403
- }
427
+ const queryByAlias = serviceHandler({
428
+ alias: "queryByAlias",
429
+ description: "Query a single entity by human-friendly alias",
430
+ input: {
431
+ alias: { type: String, description: "Human-friendly alias" },
432
+ archived: {
433
+ type: Boolean,
434
+ default: false,
435
+ required: false,
436
+ description: "Query archived entities instead of active ones",
437
+ },
438
+ deleted: {
439
+ type: Boolean,
440
+ default: false,
441
+ required: false,
442
+ description: "Query deleted entities instead of active ones",
443
+ },
444
+ model: { type: String, description: "Entity model name" },
445
+ ou: { type: String, description: "Organizational unit (@ for root)" },
446
+ },
447
+ service: async ({ alias, archived, deleted, model, ou, }) => {
448
+ const aliasStr = alias;
449
+ const archivedBool = archived;
450
+ const deletedBool = deleted;
451
+ const modelStr = model;
452
+ const ouStr = ou;
453
+ const suffix = calculateSuffix({ archived: archivedBool, deleted: deletedBool });
454
+ const keyValue = buildIndexAlias(ouStr, modelStr, aliasStr) + suffix;
455
+ const result = await executeQuery(INDEX_ALIAS, keyValue, {
456
+ limit: 1,
457
+ });
458
+ return result.items[0] ?? null;
459
+ },
460
+ });
404
461
  /**
405
462
  * Query entities by category classification
406
463
  * Uses indexClass GSI
407
464
  *
408
- * @param params.archived - Query archived entities instead of active ones
409
- * @param params.deleted - Query deleted entities instead of active ones
410
- * @throws ConfigurationError if both archived and deleted are true
465
+ * Note: This is a regular async function (not serviceHandler) because it accepts
466
+ * complex startKey objects that can't be coerced by vocabulary's type system.
411
467
  */
412
- async function queryByClass(params) {
413
- const { archived, deleted, model, ou, recordClass, ...options } = params;
468
+ async function queryByClass({ archived = false, ascending = false, deleted = false, limit, model, ou, recordClass, startKey, }) {
414
469
  const suffix = calculateSuffix({ archived, deleted });
415
470
  const keyValue = buildIndexClass(ou, model, recordClass) + suffix;
416
- return executeQuery(INDEX_CLASS, keyValue, options);
471
+ return executeQuery(INDEX_CLASS, keyValue, {
472
+ ascending,
473
+ limit,
474
+ startKey,
475
+ });
417
476
  }
418
477
  /**
419
478
  * Query entities by type classification
420
479
  * Uses indexType GSI
421
480
  *
422
- * @param params.archived - Query archived entities instead of active ones
423
- * @param params.deleted - Query deleted entities instead of active ones
424
- * @throws ConfigurationError if both archived and deleted are true
481
+ * Note: This is a regular async function (not serviceHandler) because it accepts
482
+ * complex startKey objects that can't be coerced by vocabulary's type system.
425
483
  */
426
- async function queryByType(params) {
427
- const { archived, deleted, model, ou, type, ...options } = params;
484
+ async function queryByType({ archived = false, ascending = false, deleted = false, limit, model, ou, startKey, type, }) {
428
485
  const suffix = calculateSuffix({ archived, deleted });
429
486
  const keyValue = buildIndexType(ou, model, type) + suffix;
430
- return executeQuery(INDEX_TYPE, keyValue, options);
487
+ return executeQuery(INDEX_TYPE, keyValue, {
488
+ ascending,
489
+ limit,
490
+ startKey,
491
+ });
431
492
  }
432
493
  /**
433
494
  * Query a single entity by external ID
434
495
  * Uses indexXid GSI
435
- *
436
- * @param params.archived - Query archived entities instead of active ones
437
- * @param params.deleted - Query deleted entities instead of active ones
438
- * @throws ConfigurationError if both archived and deleted are true
439
- * @returns The matching entity or null if not found
440
496
  */
441
- async function queryByXid(params) {
442
- const { archived, deleted, model, ou, xid } = params;
443
- const suffix = calculateSuffix({ archived, deleted });
444
- const keyValue = buildIndexXid(ou, model, xid) + suffix;
445
- const result = await executeQuery(INDEX_XID, keyValue, { limit: 1 });
446
- return result.items[0] ?? null;
447
- }
497
+ const queryByXid = serviceHandler({
498
+ alias: "queryByXid",
499
+ description: "Query a single entity by external ID",
500
+ input: {
501
+ archived: {
502
+ type: Boolean,
503
+ default: false,
504
+ required: false,
505
+ description: "Query archived entities instead of active ones",
506
+ },
507
+ deleted: {
508
+ type: Boolean,
509
+ default: false,
510
+ required: false,
511
+ description: "Query deleted entities instead of active ones",
512
+ },
513
+ model: { type: String, description: "Entity model name" },
514
+ ou: { type: String, description: "Organizational unit (@ for root)" },
515
+ xid: { type: String, description: "External ID" },
516
+ },
517
+ service: async ({ archived, deleted, model, ou, xid, }) => {
518
+ const archivedBool = archived;
519
+ const deletedBool = deleted;
520
+ const modelStr = model;
521
+ const ouStr = ou;
522
+ const xidStr = xid;
523
+ const suffix = calculateSuffix({ archived: archivedBool, deleted: deletedBool });
524
+ const keyValue = buildIndexXid(ouStr, modelStr, xidStr) + suffix;
525
+ const result = await executeQuery(INDEX_XID, keyValue, {
526
+ limit: 1,
527
+ });
528
+ return result.items[0] ?? null;
529
+ },
530
+ });
448
531
 
449
532
  export { APEX, ARCHIVED_SUFFIX, DELETED_SUFFIX, INDEX_ALIAS, INDEX_CLASS, INDEX_OU, INDEX_TYPE, INDEX_XID, SEPARATOR, archiveEntity, buildIndexAlias, buildIndexClass, buildIndexOu, buildIndexType, buildIndexXid, calculateOu, deleteEntity, destroyEntity, getDocClient, getEntity, getTableName, indexEntity, initClient, isInitialized, putEntity, queryByAlias, queryByClass, queryByOu, queryByType, queryByXid, resetClient, updateEntity };
450
533
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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 executeQ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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;;;;"}
1
+ {"version":3,"file":"index.js","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\";\nimport { serviceHandler } from \"@jaypie/vocabulary\";\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 * 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 * Get a single entity by primary key\n */\nexport const getEntity = serviceHandler({\n alias: \"getEntity\",\n description: \"Get a single entity by primary key\",\n input: {\n id: { type: String, description: \"Entity ID (sort key)\" },\n model: { type: String, description: \"Entity model (partition key)\" },\n },\n service: async ({ id, model }): Promise<FabricEntity | null> => {\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 FabricEntity) ?? null;\n },\n});\n\n/**\n * Put (create or replace) an entity\n * Auto-populates GSI index keys via indexEntity\n *\n * Note: This is a regular async function (not serviceHandler) because it accepts\n * complex FabricEntity objects that can't be coerced by vocabulary's type system.\n */\nexport async function putEntity({\n entity,\n}: {\n entity: FabricEntity;\n}): Promise<FabricEntity> {\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 *\n * Note: This is a regular async function (not serviceHandler) because it accepts\n * complex FabricEntity objects that can't be coerced by vocabulary's type system.\n */\nexport async function updateEntity({\n entity,\n}: {\n entity: FabricEntity;\n}): Promise<FabricEntity> {\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 * Soft delete an entity by setting deletedAt timestamp\n * Re-indexes with appropriate suffix based on archived/deleted state\n */\nexport const deleteEntity = serviceHandler({\n alias: \"deleteEntity\",\n description: \"Soft delete an entity (sets deletedAt timestamp)\",\n input: {\n id: { type: String, description: \"Entity ID (sort key)\" },\n model: { type: String, description: \"Entity model (partition key)\" },\n },\n service: async ({ id, model }): Promise<boolean> => {\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/**\n * Archive an entity by setting archivedAt timestamp\n * Re-indexes with appropriate suffix based on archived/deleted state\n */\nexport const archiveEntity = serviceHandler({\n alias: \"archiveEntity\",\n description: \"Archive an entity (sets archivedAt timestamp)\",\n input: {\n id: { type: String, description: \"Entity ID (sort key)\" },\n model: { type: String, description: \"Entity model (partition key)\" },\n },\n service: async ({ id, model }): Promise<boolean> => {\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/**\n * Hard delete an entity (permanently removes from table)\n * Use with caution - prefer deleteEntity for soft delete\n */\nexport const destroyEntity = serviceHandler({\n alias: \"destroyEntity\",\n description: \"Hard delete an entity (permanently removes from table)\",\n input: {\n id: { type: String, description: \"Entity ID (sort key)\" },\n model: { type: String, description: \"Entity model (partition key)\" },\n },\n service: async ({ id, model }): Promise<boolean> => {\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});\n","import { QueryCommand } from \"@aws-sdk/lib-dynamodb\";\nimport { serviceHandler } from \"@jaypie/vocabulary\";\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 { BaseQueryOptions, FabricEntity, QueryResult } 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 parameters for queryByOu\n */\ninterface QueryByOuParams extends BaseQueryOptions {\n model: string;\n ou: string;\n}\n\n/**\n * Query entities by organizational unit (parent hierarchy)\n * Uses indexOu GSI\n *\n * Note: This is a regular async function (not serviceHandler) because it accepts\n * complex startKey objects that can't be coerced by vocabulary's type system.\n */\nexport async function queryByOu({\n archived = false,\n ascending = false,\n deleted = false,\n limit,\n model,\n ou,\n startKey,\n}: QueryByOuParams): Promise<QueryResult<FabricEntity>> {\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexOu(ou, model) + suffix;\n return executeQuery<FabricEntity>(INDEX_OU, keyValue, {\n ascending,\n limit,\n startKey,\n });\n}\n\n/**\n * Query a single entity by human-friendly alias\n * Uses indexAlias GSI\n */\nexport const queryByAlias = serviceHandler({\n alias: \"queryByAlias\",\n description: \"Query a single entity by human-friendly alias\",\n input: {\n alias: { type: String, description: \"Human-friendly alias\" },\n archived: {\n type: Boolean,\n default: false,\n required: false,\n description: \"Query archived entities instead of active ones\",\n },\n deleted: {\n type: Boolean,\n default: false,\n required: false,\n description: \"Query deleted entities instead of active ones\",\n },\n model: { type: String, description: \"Entity model name\" },\n ou: { type: String, description: \"Organizational unit (@ for root)\" },\n },\n service: async ({\n alias,\n archived,\n deleted,\n model,\n ou,\n }): Promise<FabricEntity | null> => {\n const aliasStr = alias as string;\n const archivedBool = archived as boolean | undefined;\n const deletedBool = deleted as boolean | undefined;\n const modelStr = model as string;\n const ouStr = ou as string;\n\n const suffix = calculateSuffix({ archived: archivedBool, deleted: deletedBool });\n const keyValue = buildIndexAlias(ouStr, modelStr, aliasStr) + suffix;\n const result = await executeQuery<FabricEntity>(INDEX_ALIAS, keyValue, {\n limit: 1,\n });\n return result.items[0] ?? null;\n },\n});\n\n/**\n * Query parameters for queryByClass\n */\ninterface QueryByClassParams extends BaseQueryOptions {\n model: string;\n ou: string;\n recordClass: string;\n}\n\n/**\n * Query entities by category classification\n * Uses indexClass GSI\n *\n * Note: This is a regular async function (not serviceHandler) because it accepts\n * complex startKey objects that can't be coerced by vocabulary's type system.\n */\nexport async function queryByClass({\n archived = false,\n ascending = false,\n deleted = false,\n limit,\n model,\n ou,\n recordClass,\n startKey,\n}: QueryByClassParams): Promise<QueryResult<FabricEntity>> {\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexClass(ou, model, recordClass) + suffix;\n return executeQuery<FabricEntity>(INDEX_CLASS, keyValue, {\n ascending,\n limit,\n startKey,\n });\n}\n\n/**\n * Query parameters for queryByType\n */\ninterface QueryByTypeParams extends BaseQueryOptions {\n model: string;\n ou: string;\n type: string;\n}\n\n/**\n * Query entities by type classification\n * Uses indexType GSI\n *\n * Note: This is a regular async function (not serviceHandler) because it accepts\n * complex startKey objects that can't be coerced by vocabulary's type system.\n */\nexport async function queryByType({\n archived = false,\n ascending = false,\n deleted = false,\n limit,\n model,\n ou,\n startKey,\n type,\n}: QueryByTypeParams): Promise<QueryResult<FabricEntity>> {\n const suffix = calculateSuffix({ archived, deleted });\n const keyValue = buildIndexType(ou, model, type) + suffix;\n return executeQuery<FabricEntity>(INDEX_TYPE, keyValue, {\n ascending,\n limit,\n startKey,\n });\n}\n\n/**\n * Query a single entity by external ID\n * Uses indexXid GSI\n */\nexport const queryByXid = serviceHandler({\n alias: \"queryByXid\",\n description: \"Query a single entity by external ID\",\n input: {\n archived: {\n type: Boolean,\n default: false,\n required: false,\n description: \"Query archived entities instead of active ones\",\n },\n deleted: {\n type: Boolean,\n default: false,\n required: false,\n description: \"Query deleted entities instead of active ones\",\n },\n model: { type: String, description: \"Entity model name\" },\n ou: { type: String, description: \"Organizational unit (@ for root)\" },\n xid: { type: String, description: \"External ID\" },\n },\n service: async ({\n archived,\n deleted,\n model,\n ou,\n xid,\n }): Promise<FabricEntity | null> => {\n const archivedBool = archived as boolean | undefined;\n const deletedBool = deleted as boolean | undefined;\n const modelStr = model as string;\n const ouStr = ou as string;\n const xidStr = xid as string;\n\n const suffix = calculateSuffix({ archived: archivedBool, deleted: deletedBool });\n const keyValue = buildIndexXid(ouStr, modelStr, xidStr) + suffix;\n const result = await executeQuery<FabricEntity>(INDEX_XID, keyValue, {\n limit: 1,\n });\n return result.items[0] ?? null;\n },\n});\n"],"names":[],"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;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AAA,KAAK,EAAE,CAAC;AACT,SAAA,CAAC;QACF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI;IAChC,CAAC;AACF,CAAA;;;;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Create DynamoDB table with Jaypie GSI schema
3
+ */
4
+ export declare const createTableHandler: import("@jaypie/vocabulary").ServiceHandlerFunction<Record<string, unknown>, {
5
+ message: string;
6
+ success: boolean;
7
+ tableName: string;
8
+ }>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generate docker-compose.yml for local DynamoDB development
3
+ */
4
+ export declare const dockerComposeHandler: import("@jaypie/vocabulary").ServiceHandlerFunction<Record<string, unknown>, {
5
+ dockerCompose: string;
6
+ envFile: string;
7
+ envVars: {
8
+ AWS_REGION: string;
9
+ DYNAMODB_ENDPOINT: string;
10
+ DYNAMODB_TABLE_NAME: unknown;
11
+ };
12
+ }>;
@@ -0,0 +1,3 @@
1
+ export { createTableHandler } from "./createTable.js";
2
+ export { dockerComposeHandler } from "./dockerCompose.js";
3
+ export { statusHandler } from "./status.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Check DynamoDB connection status and configuration
3
+ */
4
+ export declare const statusHandler: import("@jaypie/vocabulary").ServiceHandlerFunction<Record<string, unknown>, {
5
+ endpoint: string;
6
+ initialized: boolean;
7
+ region: string;
8
+ tableName: string;
9
+ }>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Ensure DynamoDB client is initialized from environment variables
3
+ * Called automatically before each MCP tool execution
4
+ */
5
+ export declare function ensureInitialized(): void;