dyno-table 2.2.1 → 2.3.0

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.
Files changed (102) hide show
  1. package/README.md +200 -1860
  2. package/dist/builders.cjs +55 -0
  3. package/dist/builders.d.cts +4 -0
  4. package/dist/builders.d.ts +4 -0
  5. package/dist/builders.js +2 -0
  6. package/dist/chunk-2EWNZOUK.js +618 -0
  7. package/dist/chunk-2WIBY7PZ.js +46 -0
  8. package/dist/chunk-7UJJ7JXM.cjs +63 -0
  9. package/dist/chunk-DTFJJASK.js +3200 -0
  10. package/dist/chunk-EODPMYPE.js +558 -0
  11. package/dist/chunk-KA3VPIPS.cjs +560 -0
  12. package/dist/chunk-NTA6GDPP.cjs +622 -0
  13. package/dist/chunk-PB7BBCZO.cjs +32 -0
  14. package/dist/chunk-QVRMYGC4.js +29 -0
  15. package/dist/chunk-XYL43FDX.cjs +3217 -0
  16. package/dist/conditions.cjs +67 -62
  17. package/dist/conditions.js +1 -48
  18. package/dist/entity.cjs +14 -625
  19. package/dist/entity.d.cts +2 -10
  20. package/dist/entity.d.ts +2 -10
  21. package/dist/entity.js +2 -626
  22. package/dist/index-2cbm07Bi.d.ts +2797 -0
  23. package/dist/index-DlN8G9hd.d.cts +2797 -0
  24. package/dist/index.cjs +111 -4460
  25. package/dist/index.d.cts +2 -10
  26. package/dist/index.d.ts +2 -10
  27. package/dist/index.js +5 -4442
  28. package/dist/standard-schema.cjs +0 -2
  29. package/dist/standard-schema.js +0 -2
  30. package/dist/table.cjs +7 -3796
  31. package/dist/table.d.cts +163 -12
  32. package/dist/table.d.ts +163 -12
  33. package/dist/table.js +3 -3799
  34. package/dist/types.cjs +0 -2
  35. package/dist/types.js +0 -2
  36. package/dist/utils.cjs +10 -30
  37. package/dist/utils.js +1 -31
  38. package/package.json +6 -66
  39. package/dist/batch-builder-BiQDIZ7p.d.cts +0 -398
  40. package/dist/batch-builder-CNsLS6sR.d.ts +0 -398
  41. package/dist/builder-types-BTVhQSHI.d.cts +0 -169
  42. package/dist/builder-types-CzuLR4Th.d.ts +0 -169
  43. package/dist/builders/condition-check-builder.cjs +0 -422
  44. package/dist/builders/condition-check-builder.cjs.map +0 -1
  45. package/dist/builders/condition-check-builder.d.cts +0 -153
  46. package/dist/builders/condition-check-builder.d.ts +0 -153
  47. package/dist/builders/condition-check-builder.js +0 -420
  48. package/dist/builders/condition-check-builder.js.map +0 -1
  49. package/dist/builders/delete-builder.cjs +0 -484
  50. package/dist/builders/delete-builder.cjs.map +0 -1
  51. package/dist/builders/delete-builder.d.cts +0 -211
  52. package/dist/builders/delete-builder.d.ts +0 -211
  53. package/dist/builders/delete-builder.js +0 -482
  54. package/dist/builders/delete-builder.js.map +0 -1
  55. package/dist/builders/paginator.cjs +0 -193
  56. package/dist/builders/paginator.cjs.map +0 -1
  57. package/dist/builders/paginator.d.cts +0 -155
  58. package/dist/builders/paginator.d.ts +0 -155
  59. package/dist/builders/paginator.js +0 -191
  60. package/dist/builders/paginator.js.map +0 -1
  61. package/dist/builders/put-builder.cjs +0 -554
  62. package/dist/builders/put-builder.cjs.map +0 -1
  63. package/dist/builders/put-builder.d.cts +0 -319
  64. package/dist/builders/put-builder.d.ts +0 -319
  65. package/dist/builders/put-builder.js +0 -552
  66. package/dist/builders/put-builder.js.map +0 -1
  67. package/dist/builders/query-builder.cjs +0 -757
  68. package/dist/builders/query-builder.cjs.map +0 -1
  69. package/dist/builders/query-builder.d.cts +0 -6
  70. package/dist/builders/query-builder.d.ts +0 -6
  71. package/dist/builders/query-builder.js +0 -755
  72. package/dist/builders/query-builder.js.map +0 -1
  73. package/dist/builders/transaction-builder.cjs +0 -906
  74. package/dist/builders/transaction-builder.cjs.map +0 -1
  75. package/dist/builders/transaction-builder.d.cts +0 -464
  76. package/dist/builders/transaction-builder.d.ts +0 -464
  77. package/dist/builders/transaction-builder.js +0 -904
  78. package/dist/builders/transaction-builder.js.map +0 -1
  79. package/dist/builders/update-builder.cjs +0 -668
  80. package/dist/builders/update-builder.cjs.map +0 -1
  81. package/dist/builders/update-builder.d.cts +0 -374
  82. package/dist/builders/update-builder.d.ts +0 -374
  83. package/dist/builders/update-builder.js +0 -666
  84. package/dist/builders/update-builder.js.map +0 -1
  85. package/dist/conditions.cjs.map +0 -1
  86. package/dist/conditions.js.map +0 -1
  87. package/dist/entity.cjs.map +0 -1
  88. package/dist/entity.js.map +0 -1
  89. package/dist/index.cjs.map +0 -1
  90. package/dist/index.js.map +0 -1
  91. package/dist/query-builder-D3URwK9k.d.cts +0 -477
  92. package/dist/query-builder-cfEkU0_w.d.ts +0 -477
  93. package/dist/standard-schema.cjs.map +0 -1
  94. package/dist/standard-schema.js.map +0 -1
  95. package/dist/table-ClST8nkR.d.cts +0 -276
  96. package/dist/table-vE3cGoDy.d.ts +0 -276
  97. package/dist/table.cjs.map +0 -1
  98. package/dist/table.js.map +0 -1
  99. package/dist/types.cjs.map +0 -1
  100. package/dist/types.js.map +0 -1
  101. package/dist/utils.cjs.map +0 -1
  102. package/dist/utils.js.map +0 -1
@@ -1,464 +0,0 @@
1
- import { TransactWriteCommandInput } from '@aws-sdk/lib-dynamodb';
2
- import { c as PrimaryKeyWithoutExpression, a as Condition } from '../conditions-D_w7vVYG.js';
3
- import { DynamoItem } from '../types.js';
4
- import { a as PutCommandParams, D as DeleteCommandParams, U as UpdateCommandParams, C as ConditionCheckCommandParams } from '../builder-types-CzuLR4Th.js';
5
-
6
- /**
7
- * Configuration options for DynamoDB transactions.
8
- */
9
- interface TransactionOptions {
10
- /** Unique identifier for the transaction request (idempotency token) */
11
- clientRequestToken?: string;
12
- /** Level of consumed capacity details to return */
13
- returnConsumedCapacity?: "INDEXES" | "TOTAL" | "NONE";
14
- /** Whether to return item collection metrics */
15
- returnItemCollectionMetrics?: "SIZE" | "NONE";
16
- }
17
- /**
18
- * Configuration for table indexes used in duplicate detection.
19
- * Defines the key structure for checking uniqueness constraints.
20
- */
21
- interface IndexConfig {
22
- /** The partition key attribute name */
23
- partitionKey: string;
24
- /** Optional sort key attribute name */
25
- sortKey?: string;
26
- }
27
- /**
28
- * Function type for executing DynamoDB transaction operations.
29
- * @param params - The complete transaction command input
30
- * @returns A promise that resolves when the transaction completes
31
- */
32
- type TransactionExecutor = (params: TransactWriteCommandInput) => Promise<void>;
33
- /**
34
- * Builder for creating and executing DynamoDB transactions.
35
- * Use this builder when you need to:
36
- * - Perform multiple operations atomically
37
- * - Ensure data consistency across operations
38
- * - Implement complex business logic that requires atomic updates
39
- * - Prevent duplicate items across tables
40
- *
41
- * The builder supports:
42
- * - Put operations (insert/replace items)
43
- * - Delete operations
44
- * - Update operations
45
- * - Condition checks
46
- * - Duplicate detection
47
- * - Transaction-wide options
48
- *
49
- * @example
50
- * ```typescript
51
- * // Create a transaction with multiple operations
52
- * const transaction = new TransactionBuilder(executor, {
53
- * partitionKey: 'id',
54
- * sortKey: 'type'
55
- * });
56
- *
57
- * // Add a new order
58
- * transaction.put('orders', {
59
- * orderId: '123',
60
- * status: 'PENDING'
61
- * });
62
- *
63
- * // Update inventory with condition
64
- * transaction.update(
65
- * 'inventory',
66
- * { productId: 'ABC' },
67
- * 'set quantity = quantity - :amount',
68
- * { ':amount': 1 },
69
- * op => op.gte('quantity', 1)
70
- * );
71
- *
72
- * // Execute the transaction atomically
73
- * await transaction.execute();
74
- * ```
75
- *
76
- * Note: DynamoDB transactions have some limitations:
77
- * - Maximum 25 operations per transaction
78
- * - All operations must be in the same AWS region
79
- * - Cannot include table scans or queries
80
- */
81
- declare class TransactionBuilder {
82
- private items;
83
- private options;
84
- private indexConfig;
85
- private readonly executor;
86
- constructor(executor: TransactionExecutor, indexConfig: IndexConfig);
87
- /**
88
- * Checks if an item with the same primary key already exists in the transaction
89
- * @private
90
- */
91
- private checkForDuplicateItem;
92
- createKeyForPrimaryIndex(key: PrimaryKeyWithoutExpression): {
93
- [x: string]: string;
94
- };
95
- /**
96
- * Adds a put operation to the transaction.
97
- *
98
- * The method automatically checks for duplicate items within the transaction
99
- * to prevent multiple operations on the same item.
100
- *
101
- * @example
102
- * ```typescript
103
- * // Simple put operation
104
- * transaction.put('orders', {
105
- * orderId: '123',
106
- * status: 'PENDING',
107
- * amount: 100
108
- * });
109
- *
110
- * // Conditional put operation
111
- * transaction.put(
112
- * 'inventory',
113
- * { productId: 'ABC', quantity: 50 },
114
- * op => op.attributeNotExists('productId')
115
- * );
116
- *
117
- * // Put with complex condition
118
- * transaction.put(
119
- * 'users',
120
- * { userId: '123', status: 'ACTIVE' },
121
- * op => op.and([
122
- * op.attributeNotExists('userId'),
123
- * op.beginsWith('status', 'ACTIVE')
124
- * ])
125
- * );
126
- * ```
127
- *
128
- * @param tableName - The name of the DynamoDB table
129
- * @param item - The item to put into the table
130
- * @param condition - Optional condition that must be satisfied
131
- * @returns The transaction builder for method chaining
132
- * @throws {Error} If a duplicate item is detected in the transaction
133
- */
134
- put<T extends DynamoItem>(tableName: string, item: T, condition?: Condition): this;
135
- /**
136
- * Adds a pre-configured put operation to the transaction.
137
- *
138
- * This method is particularly useful when working with PutBuilder
139
- * to maintain consistency in put operations across your application.
140
- *
141
- * @example
142
- * ```typescript
143
- * // Create a put command with PutBuilder
144
- * const putCommand = new PutBuilder(executor, newItem, 'users')
145
- * .condition(op => op.attributeNotExists('userId'))
146
- * .toDynamoCommand();
147
- *
148
- * // Add the command to the transaction
149
- * transaction.putWithCommand(putCommand);
150
- * ```
151
- *
152
- * @param command - The complete put command configuration
153
- * @returns The transaction builder for method chaining
154
- * @throws {Error} If a duplicate item is detected in the transaction
155
- * @see PutBuilder for creating put commands
156
- */
157
- putWithCommand(command: PutCommandParams): TransactionBuilder;
158
- /**
159
- * Adds a delete operation to the transaction.
160
- *
161
- * The method automatically checks for duplicate items within the transaction
162
- * to prevent multiple operations on the same item.
163
- *
164
- * @example
165
- * ```typescript
166
- * // Simple delete operation
167
- * transaction.delete('orders', {
168
- * pk: 'ORDER#123',
169
- * sk: 'METADATA'
170
- * });
171
- *
172
- * // Conditional delete operation
173
- * transaction.delete(
174
- * 'users',
175
- * { pk: 'USER#123' },
176
- * op => op.eq('status', 'INACTIVE')
177
- * );
178
- *
179
- * // Delete with complex condition
180
- * transaction.delete(
181
- * 'products',
182
- * { pk: 'PROD#ABC' },
183
- * op => op.and([
184
- * op.eq('status', 'DRAFT'),
185
- * op.lt('version', 5)
186
- * ])
187
- * );
188
- * ```
189
- *
190
- * @param tableName - The name of the DynamoDB table
191
- * @param key - The primary key of the item to delete
192
- * @param condition - Optional condition that must be satisfied
193
- * @returns The transaction builder for method chaining
194
- * @throws {Error} If a duplicate item is detected in the transaction
195
- */
196
- delete(tableName: string, key: PrimaryKeyWithoutExpression, condition?: Condition): TransactionBuilder;
197
- /**
198
- * Adds a pre-configured delete operation to the transaction.
199
- *
200
- * This method is particularly useful when working with DeleteBuilder
201
- * to maintain consistency in delete operations across your application.
202
- *
203
- * @example
204
- * ```typescript
205
- * // Create a delete command with DeleteBuilder
206
- * const deleteCommand = new DeleteBuilder(executor, 'users', { pk: 'USER#123' })
207
- * .condition(op => op.and([
208
- * op.attributeExists('pk'),
209
- * op.eq('status', 'INACTIVE')
210
- * ]))
211
- * .toDynamoCommand();
212
- *
213
- * // Add the command to the transaction
214
- * transaction.deleteWithCommand(deleteCommand);
215
- * ```
216
- *
217
- * @param command - The complete delete command configuration
218
- * @returns The transaction builder for method chaining
219
- * @throws {Error} If a duplicate item is detected in the transaction
220
- * @see DeleteBuilder for creating delete commands
221
- */
222
- deleteWithCommand(command: DeleteCommandParams): this;
223
- /**
224
- * Adds an update operation to the transaction.
225
- *
226
- * The method supports all DynamoDB update expressions:
227
- * - SET: Modify or add attributes
228
- * - REMOVE: Delete attributes
229
- * - ADD: Update numbers and sets
230
- * - DELETE: Remove elements from a set
231
- *
232
- * @example
233
- * ```typescript
234
- * // Simple update
235
- * transaction.update(
236
- * 'orders',
237
- * { pk: 'ORDER#123' },
238
- * 'SET #status = :status',
239
- * { '#status': 'status' },
240
- * { ':status': 'PROCESSING' }
241
- * );
242
- *
243
- * // Complex update with multiple operations
244
- * transaction.update(
245
- * 'products',
246
- * { pk: 'PROD#ABC' },
247
- * 'SET #qty = #qty - :amount, #status = :status REMOVE #oldAttr',
248
- * { '#qty': 'quantity', '#status': 'status', '#oldAttr': 'deprecated_field' },
249
- * { ':amount': 1, ':status': 'LOW_STOCK' }
250
- * );
251
- *
252
- * // Conditional update
253
- * transaction.update(
254
- * 'users',
255
- * { pk: 'USER#123' },
256
- * 'SET #lastLogin = :now',
257
- * { '#lastLogin': 'lastLoginDate' },
258
- * { ':now': new Date().toISOString() },
259
- * op => op.attributeExists('pk')
260
- * );
261
- * ```
262
- *
263
- * @param tableName - The name of the DynamoDB table
264
- * @param key - The primary key of the item to update
265
- * @param updateExpression - The update expression (SET, REMOVE, ADD, DELETE)
266
- * @param expressionAttributeNames - Map of attribute name placeholders to actual names
267
- * @param expressionAttributeValues - Map of value placeholders to actual values
268
- * @param condition - Optional condition that must be satisfied
269
- * @returns The transaction builder for method chaining
270
- * @throws {Error} If a duplicate item is detected in the transaction
271
- */
272
- update<T extends DynamoItem>(tableName: string, key: PrimaryKeyWithoutExpression, updateExpression: string, expressionAttributeNames?: Record<string, string>, expressionAttributeValues?: Record<string, unknown>, condition?: Condition): this;
273
- /**
274
- * Adds a pre-configured update operation to the transaction.
275
- *
276
- * This method is particularly useful when working with UpdateBuilder
277
- * to maintain consistency in update operations across your application.
278
- *
279
- * @example
280
- * ```typescript
281
- * // Create an update command with UpdateBuilder
282
- * const updateCommand = new UpdateBuilder(executor, 'inventory', { pk: 'PROD#ABC' })
283
- * .set('quantity', ':qty')
284
- * .set('lastUpdated', ':now')
285
- * .values({
286
- * ':qty': 100,
287
- * ':now': new Date().toISOString()
288
- * })
289
- * .condition(op => op.gt('quantity', 0))
290
- * .toDynamoCommand();
291
- *
292
- * // Add the command to the transaction
293
- * transaction.updateWithCommand(updateCommand);
294
- * ```
295
- *
296
- * @param command - The complete update command configuration
297
- * @returns The transaction builder for method chaining
298
- * @throws {Error} If a duplicate item is detected in the transaction
299
- * @see UpdateBuilder for creating update commands
300
- */
301
- updateWithCommand(command: UpdateCommandParams): TransactionBuilder;
302
- /**
303
- * Adds a condition check operation to the transaction.
304
- *
305
- * Condition checks are particularly useful for:
306
- * - Implementing optimistic locking
307
- * - Ensuring referential integrity
308
- * - Validating business rules atomically
309
- *
310
- * @example
311
- * ```typescript
312
- * // Check if order is in correct state
313
- * transaction.conditionCheck(
314
- * 'orders',
315
- * { pk: 'ORDER#123' },
316
- * op => op.eq('status', 'PENDING')
317
- * );
318
- *
319
- * // Complex condition check
320
- * transaction.conditionCheck(
321
- * 'inventory',
322
- * { pk: 'PROD#ABC' },
323
- * op => op.and([
324
- * op.gt('quantity', 0),
325
- * op.eq('status', 'ACTIVE'),
326
- * op.attributeExists('lastRestockDate')
327
- * ])
328
- * );
329
- *
330
- * // Check with multiple attributes
331
- * transaction.conditionCheck(
332
- * 'users',
333
- * { pk: 'USER#123' },
334
- * op => op.or([
335
- * op.eq('status', 'PREMIUM'),
336
- * op.gte('credits', 100)
337
- * ])
338
- * );
339
- * ```
340
- *
341
- * @param tableName - The name of the DynamoDB table
342
- * @param key - The primary key of the item to check
343
- * @param condition - The condition that must be satisfied
344
- * @returns The transaction builder for method chaining
345
- * @throws {Error} If a duplicate item is detected in the transaction
346
- * @throws {Error} If condition expression generation fails
347
- */
348
- conditionCheck(tableName: string, key: PrimaryKeyWithoutExpression, condition: Condition): TransactionBuilder;
349
- /**
350
- * Adds a pre-configured condition check operation to the transaction.
351
- *
352
- * This method is particularly useful when working with ConditionCheckBuilder
353
- * to maintain consistency in condition checks across your application.
354
- *
355
- * @example
356
- * ```typescript
357
- * // Create a condition check with ConditionCheckBuilder
358
- * const checkCommand = new ConditionCheckBuilder('inventory', { pk: 'PROD#ABC' })
359
- * .condition(op => op.and([
360
- * op.between('quantity', 10, 100),
361
- * op.beginsWith('category', 'ELECTRONICS'),
362
- * op.attributeExists('lastAuditDate')
363
- * ]))
364
- * .toDynamoCommand();
365
- *
366
- * // Add the command to the transaction
367
- * transaction.conditionCheckWithCommand(checkCommand);
368
- * ```
369
- *
370
- * @param command - The complete condition check command configuration
371
- * @returns The transaction builder for method chaining
372
- * @throws {Error} If a duplicate item is detected in the transaction
373
- * @see ConditionCheckBuilder for creating condition check commands
374
- */
375
- conditionCheckWithCommand(command: ConditionCheckCommandParams): TransactionBuilder;
376
- /**
377
- * Sets options for the transaction execution.
378
- *
379
- * @example
380
- * ```typescript
381
- * // Enable idempotency and capacity tracking
382
- * transaction.withOptions({
383
- * clientRequestToken: 'unique-request-id-123',
384
- * returnConsumedCapacity: 'TOTAL'
385
- * });
386
- *
387
- * // Track item collection metrics
388
- * transaction.withOptions({
389
- * returnItemCollectionMetrics: 'SIZE'
390
- * });
391
- * ```
392
- *
393
- * Note: ClientRequestToken can be used to make transactions idempotent,
394
- * ensuring the same transaction is not executed multiple times.
395
- *
396
- * @param options - Configuration options for the transaction
397
- * @returns The transaction builder for method chaining
398
- */
399
- withOptions(options: TransactionOptions): TransactionBuilder;
400
- /**
401
- * Gets a human-readable representation of the transaction items.
402
- *
403
- * The method resolves all expression placeholders with their actual values,
404
- * making it easier to understand the transaction's operations.
405
- *
406
- * @example
407
- * ```typescript
408
- * // Add multiple operations
409
- * transaction
410
- * .put('orders', { orderId: '123', status: 'PENDING' })
411
- * .update('inventory',
412
- * { productId: 'ABC' },
413
- * 'SET quantity = quantity - :amount',
414
- * undefined,
415
- * { ':amount': 1 }
416
- * );
417
- *
418
- * // Debug the transaction
419
- * const debugInfo = transaction.debug();
420
- * console.log('Transaction operations:', debugInfo);
421
- * ```
422
- *
423
- * @returns An array of readable representations of the transaction items
424
- */
425
- debug(): Record<string, unknown>[];
426
- /**
427
- * Executes all operations in the transaction atomically.
428
- *
429
- * The transaction will only succeed if all operations succeed.
430
- * If any operation fails, the entire transaction is rolled back.
431
- *
432
- * @example
433
- * ```typescript
434
- * try {
435
- * // Build and execute transaction
436
- * await transaction
437
- * .put('orders', newOrder)
438
- * .update('inventory',
439
- * { productId: 'ABC' },
440
- * 'SET quantity = quantity - :qty',
441
- * undefined,
442
- * { ':qty': 1 }
443
- * )
444
- * .conditionCheck('products',
445
- * { productId: 'ABC' },
446
- * op => op.eq('status', 'ACTIVE')
447
- * )
448
- * .execute();
449
- *
450
- * console.log('Transaction completed successfully');
451
- * } catch (error) {
452
- * // Handle transaction failure
453
- * console.error('Transaction failed:', error);
454
- * }
455
- * ```
456
- *
457
- * @throws {Error} If no transaction items are specified
458
- * @throws {Error} If any operation in the transaction fails
459
- * @returns A promise that resolves when the transaction completes
460
- */
461
- execute(): Promise<void>;
462
- }
463
-
464
- export { TransactionBuilder, type TransactionExecutor, type TransactionOptions };