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