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,374 +0,0 @@
1
- import { a as Condition, c as PrimaryKeyWithoutExpression, s as Path, t as PathType, b as ConditionOperator } from '../conditions-D_w7vVYG.js';
2
- import { DynamoItem } from '../types.js';
3
- import { U as UpdateCommandParams } from '../builder-types-CzuLR4Th.js';
4
- import { TransactionBuilder } from './transaction-builder.js';
5
- import '@aws-sdk/lib-dynamodb';
6
-
7
- /**
8
- * Configuration options for DynamoDB update operations.
9
- */
10
- interface UpdateOptions {
11
- /** Optional condition that must be satisfied for the update to succeed */
12
- condition?: Condition;
13
- /** Determines which item attributes to include in the response */
14
- returnValues?: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE";
15
- }
16
- /**
17
- * Function type for executing DynamoDB update operations.
18
- * @typeParam T - The type of the item being updated
19
- */
20
- type UpdateExecutor<T extends DynamoItem> = (params: UpdateCommandParams) => Promise<{
21
- item?: T;
22
- }>;
23
- /**
24
- * Represents a single update action within an update operation.
25
- * Each action modifies the item in a specific way:
26
- * - SET: Modify or add attributes
27
- * - REMOVE: Delete attributes
28
- * - ADD: Update numbers and sets
29
- * - DELETE: Remove elements from a set
30
- */
31
- type UpdateAction = {
32
- /** The type of update action */
33
- type: "SET" | "REMOVE" | "ADD" | "DELETE";
34
- /** The attribute path to update */
35
- path: string;
36
- /** The value to use in the update (not used for REMOVE actions) */
37
- value?: unknown;
38
- };
39
- /**
40
- * Type utility to get the element type of a set.
41
- * Extracts the element type from either a Set or Array type.
42
- * @typeParam T - The set or array type
43
- */
44
- type SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;
45
- /**
46
- * Type utility to get the element type from a path that points to a set.
47
- * Combines PathType and SetElementType to get the element type at a specific path.
48
- * @typeParam T - The type of the item
49
- * @typeParam K - The path within the item
50
- */
51
- type PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;
52
- /**
53
- * Builder for creating DynamoDB update operations.
54
- *
55
- * The builder supports all DynamoDB update operations:
56
- * - SET: Modify or add attributes
57
- * - REMOVE: Delete attributes
58
- * - ADD: Update numbers and sets
59
- * - DELETE: Remove elements from a set
60
- *
61
- * @example
62
- * ```typescript
63
- * // Simple update
64
- * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
65
- * .set('status', 'HUNTING')
66
- * .set('lastFed', new Date().toISOString())
67
- * .execute();
68
- *
69
- * // Complex update with multiple operations
70
- * const result = await new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
71
- * .set({
72
- * status: 'OCCUPIED',
73
- * occupants: 3,
74
- * 'metadata.lastInspection': new Date().toISOString()
75
- * })
76
- * .add('securityBreaches', 1)
77
- * .deleteElementsFromSet('suitableDinosaurs', ['VELOCIRAPTOR'])
78
- * .condition(op => op.gt('securityLevel', 8))
79
- * .returnValues('ALL_NEW')
80
- * .execute();
81
- * ```
82
- *
83
- * @typeParam T - The type of item being updated
84
- */
85
- declare class UpdateBuilder<T extends DynamoItem> {
86
- protected updates: UpdateAction[];
87
- protected options: UpdateOptions;
88
- protected readonly executor: UpdateExecutor<T>;
89
- protected readonly tableName: string;
90
- protected readonly key: PrimaryKeyWithoutExpression;
91
- constructor(executor: UpdateExecutor<T>, tableName: string, key: PrimaryKeyWithoutExpression);
92
- /**
93
- * Sets multiple attributes of an item using an object.
94
- *
95
- * @example
96
- * ```typescript
97
- * // Update multiple attributes
98
- * builder.set({
99
- * species: 'Tyrannosaurus Rex',
100
- * height: 20,
101
- * diet: 'CARNIVORE',
102
- * 'stats.threatLevel': 10
103
- * });
104
- * ```
105
- */
106
- set(values: Partial<T>): UpdateBuilder<T>;
107
- /**
108
- * Sets a single attribute to a specific value.
109
- *
110
- * @example
111
- * ```typescript
112
- * // Set simple attributes
113
- * builder
114
- * .set('status', 'SLEEPING')
115
- * .set('lastFeeding', new Date().toISOString());
116
- *
117
- * // Set nested attributes
118
- * builder
119
- * .set('location.zone', 'RESTRICTED')
120
- * .set('stats.health', 100);
121
- * ```
122
- */
123
- set<K extends Path<T>>(path: K, value: PathType<T, K>): UpdateBuilder<T>;
124
- /**
125
- * Removes an attribute from the item.
126
- *
127
- * @example
128
- * ```typescript
129
- * // Remove simple attributes
130
- * builder
131
- * .remove('temporaryTag')
132
- * .remove('previousLocation');
133
- *
134
- * // Remove nested attributes
135
- * builder
136
- * .remove('metadata.testData')
137
- * .remove('stats.experimentalMetrics');
138
- * ```
139
- *
140
- * @param path - The path to the attribute to remove
141
- * @returns The builder instance for method chaining
142
- */
143
- remove<K extends Path<T>>(path: K): this;
144
- /**
145
- * Adds a value to a number attribute or adds elements to a set.
146
- *
147
- * @example
148
- * ```typescript
149
- * // Increment counters
150
- * builder
151
- * .add('escapeAttempts', 1)
152
- * .add('feedingCount', 1);
153
- *
154
- * // Add to sets
155
- * builder
156
- * .add('knownBehaviors', new Set(['PACK_HUNTING', 'AMBUSH_TACTICS']))
157
- * .add('visitedZones', new Set(['ZONE_A', 'ZONE_B']));
158
- * ```
159
- *
160
- * @param path - The path to the attribute to update
161
- * @param value - The value to add (number or set)
162
- * @returns The builder instance for method chaining
163
- */
164
- add<K extends Path<T>>(path: K, value: PathType<T, K>): this;
165
- /**
166
- * Removes elements from a set attribute.
167
- *
168
- * @example
169
- * ```typescript
170
- * // Remove from sets using arrays
171
- * builder.deleteElementsFromSet(
172
- * 'allowedHabitats',
173
- * ['JUNGLE', 'COASTAL']
174
- * );
175
- *
176
- * // Remove from sets using Set DynamoItems
177
- * builder.deleteElementsFromSet(
178
- * 'knownBehaviors',
179
- * new Set(['NOCTURNAL', 'TERRITORIAL'])
180
- * );
181
- *
182
- * // Remove from nested sets
183
- * builder.deleteElementsFromSet(
184
- * 'stats.compatibleSpecies',
185
- * ['VELOCIRAPTOR', 'DILOPHOSAURUS']
186
- * );
187
- * ```
188
- *
189
- * @param path - The path to the set attribute
190
- * @param value - Elements to remove (array or Set)
191
- * @returns The builder instance for method chaining
192
- */
193
- deleteElementsFromSet<K extends Path<T>>(path: K, value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>): this;
194
- /**
195
- * Adds a condition that must be satisfied for the update to succeed.
196
- *
197
- * @example
198
- * ```typescript
199
- * // Simple condition
200
- * builder.condition(op =>
201
- * op.eq('status', 'ACTIVE')
202
- * );
203
- *
204
- * // Health check condition
205
- * builder.condition(op =>
206
- * op.and([
207
- * op.gt('health', 50),
208
- * op.eq('status', 'HUNTING')
209
- * ])
210
- * );
211
- *
212
- * // Complex security condition
213
- * builder.condition(op =>
214
- * op.and([
215
- * op.attributeExists('securitySystem'),
216
- * op.eq('containmentStatus', 'SECURE'),
217
- * op.lt('aggressionLevel', 8)
218
- * ])
219
- * );
220
- *
221
- * // Version check (optimistic locking)
222
- * builder.condition(op =>
223
- * op.eq('version', currentVersion)
224
- * );
225
- * ```
226
- *
227
- * @param condition - Either a Condition DynamoItem or a callback function that builds the condition
228
- * @returns The builder instance for method chaining
229
- */
230
- condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
231
- /**
232
- * Sets which item attributes to include in the response.
233
- *
234
- * Available options:
235
- * - ALL_NEW: All attributes after the update (default)
236
- * - UPDATED_NEW: Only updated attributes, new values
237
- * - ALL_OLD: All attributes before the update
238
- * - UPDATED_OLD: Only updated attributes, old values
239
- * - NONE: No attributes returned
240
- *
241
- * @example
242
- * ```typescript
243
- * // Get complete updated dinosaur
244
- * const result = await builder
245
- * .set('status', 'SLEEPING')
246
- * .returnValues('ALL_NEW')
247
- * .execute();
248
- *
249
- * // Track specific attribute changes
250
- * const result = await builder
251
- * .set({
252
- * 'stats.health': 100,
253
- * 'stats.energy': 95
254
- * })
255
- * .returnValues('UPDATED_OLD')
256
- * .execute();
257
- *
258
- * if (result.item) {
259
- * console.log('Previous health:', result.item.stats?.health);
260
- * }
261
- * ```
262
- *
263
- * @param returnValues - Which attributes to return in the response
264
- * @returns The builder instance for method chaining
265
- */
266
- returnValues(returnValues: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE"): this;
267
- /**
268
- * Generate the DynamoDB command parameters
269
- */
270
- toDynamoCommand(): UpdateCommandParams;
271
- /**
272
- * Adds this update operation to a transaction.
273
- *
274
- * @example
275
- * ```typescript
276
- * const transaction = new TransactionBuilder(executor);
277
- *
278
- * // Update dinosaur status and habitat occupancy atomically
279
- * new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
280
- * .set('location', 'PADDOCK_A')
281
- * .set('status', 'CONTAINED')
282
- * .withTransaction(transaction);
283
- *
284
- * new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
285
- * .add('occupants', 1)
286
- * .set('lastOccupied', new Date().toISOString())
287
- * .withTransaction(transaction);
288
- *
289
- * // Execute all operations atomically
290
- * await transaction.execute();
291
- * ```
292
- *
293
- * @param transaction - The transaction builder to add this operation to
294
- * @returns The builder instance for method chaining
295
- */
296
- withTransaction(transaction: TransactionBuilder): void;
297
- /**
298
- * Gets a human-readable representation of the update command.
299
- *
300
- * @example
301
- * ```typescript
302
- * // Create complex update
303
- * const builder = new UpdateBuilder(executor, 'dinosaurs', { id: 'RAPTOR-001' })
304
- * .set({
305
- * status: 'HUNTING',
306
- * 'stats.health': 95,
307
- * 'behavior.lastObserved': new Date().toISOString()
308
- * })
309
- * .add('huntingSuccesses', 1)
310
- * .condition(op => op.gt('health', 50));
311
- *
312
- * // Debug the update
313
- * const debugInfo = builder.debug();
314
- * console.log('Update operation:', debugInfo);
315
- * ```
316
- *
317
- * @returns A readable representation of the update command with resolved expressions
318
- */
319
- debug(): {
320
- raw: UpdateCommandParams;
321
- readable: {
322
- conditionExpression?: string;
323
- updateExpression?: string;
324
- filterExpression?: string;
325
- keyConditionExpression?: string;
326
- projectionExpression?: string;
327
- };
328
- };
329
- /**
330
- * Executes the update operation against DynamoDB.
331
- *
332
- * @example
333
- * ```typescript
334
- * try {
335
- * // Update dinosaur status with conditions
336
- * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
337
- * .set({
338
- * status: 'FEEDING',
339
- * lastMeal: new Date().toISOString(),
340
- * 'stats.hunger': 0
341
- * })
342
- * .add('feedingCount', 1)
343
- * .condition(op =>
344
- * op.and([
345
- * op.gt('stats.hunger', 80),
346
- * op.eq('status', 'HUNTING')
347
- * ])
348
- * )
349
- * .returnValues('ALL_NEW')
350
- * .execute();
351
- *
352
- * if (result.item) {
353
- * console.log('Updated dinosaur:', result.item);
354
- * }
355
- * } catch (error) {
356
- * // Handle condition check failure
357
- * console.error('Failed to update dinosaur:', error);
358
- * // Check if dinosaur wasn't hungry enough
359
- * if (error.name === 'ConditionalCheckFailedException') {
360
- * console.log('Dinosaur not ready for feeding');
361
- * }
362
- * }
363
- * ```
364
- *
365
- * @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)
366
- * @throws {ConditionalCheckFailedException} If the condition check fails
367
- * @throws {Error} If the update operation fails for other reasons
368
- */
369
- execute(): Promise<{
370
- item?: T;
371
- }>;
372
- }
373
-
374
- export { type UpdateAction, UpdateBuilder, type UpdateOptions };