dyno-table 0.2.0-0 → 1.0.0-alpha.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 (96) hide show
  1. package/README.md +182 -577
  2. package/dist/{table.cjs → index.cjs} +175 -87
  3. package/dist/index.d.cts +2971 -0
  4. package/dist/index.d.ts +2971 -0
  5. package/dist/{table.js → index.js} +127 -86
  6. package/package.json +10 -77
  7. package/dist/builder-types-C_PDZhnP.d.ts +0 -118
  8. package/dist/builder-types-DtwbqMeF.d.cts +0 -118
  9. package/dist/builders/condition-check-builder.cjs +0 -394
  10. package/dist/builders/condition-check-builder.cjs.map +0 -1
  11. package/dist/builders/condition-check-builder.d.cts +0 -157
  12. package/dist/builders/condition-check-builder.d.ts +0 -157
  13. package/dist/builders/condition-check-builder.js +0 -392
  14. package/dist/builders/condition-check-builder.js.map +0 -1
  15. package/dist/builders/delete-builder.cjs +0 -405
  16. package/dist/builders/delete-builder.cjs.map +0 -1
  17. package/dist/builders/delete-builder.d.cts +0 -166
  18. package/dist/builders/delete-builder.d.ts +0 -166
  19. package/dist/builders/delete-builder.js +0 -403
  20. package/dist/builders/delete-builder.js.map +0 -1
  21. package/dist/builders/paginator.cjs +0 -199
  22. package/dist/builders/paginator.cjs.map +0 -1
  23. package/dist/builders/paginator.d.cts +0 -179
  24. package/dist/builders/paginator.d.ts +0 -179
  25. package/dist/builders/paginator.js +0 -197
  26. package/dist/builders/paginator.js.map +0 -1
  27. package/dist/builders/put-builder.cjs +0 -476
  28. package/dist/builders/put-builder.cjs.map +0 -1
  29. package/dist/builders/put-builder.d.cts +0 -274
  30. package/dist/builders/put-builder.d.ts +0 -274
  31. package/dist/builders/put-builder.js +0 -474
  32. package/dist/builders/put-builder.js.map +0 -1
  33. package/dist/builders/query-builder.cjs +0 -674
  34. package/dist/builders/query-builder.cjs.map +0 -1
  35. package/dist/builders/query-builder.d.cts +0 -6
  36. package/dist/builders/query-builder.d.ts +0 -6
  37. package/dist/builders/query-builder.js +0 -672
  38. package/dist/builders/query-builder.js.map +0 -1
  39. package/dist/builders/transaction-builder.cjs +0 -894
  40. package/dist/builders/transaction-builder.cjs.map +0 -1
  41. package/dist/builders/transaction-builder.d.cts +0 -511
  42. package/dist/builders/transaction-builder.d.ts +0 -511
  43. package/dist/builders/transaction-builder.js +0 -892
  44. package/dist/builders/transaction-builder.js.map +0 -1
  45. package/dist/builders/update-builder.cjs +0 -627
  46. package/dist/builders/update-builder.cjs.map +0 -1
  47. package/dist/builders/update-builder.d.cts +0 -365
  48. package/dist/builders/update-builder.d.ts +0 -365
  49. package/dist/builders/update-builder.js +0 -625
  50. package/dist/builders/update-builder.js.map +0 -1
  51. package/dist/conditions--ld9a78i.d.ts +0 -331
  52. package/dist/conditions-ChhQWd6z.d.cts +0 -331
  53. package/dist/conditions.cjs +0 -59
  54. package/dist/conditions.cjs.map +0 -1
  55. package/dist/conditions.d.cts +0 -3
  56. package/dist/conditions.d.ts +0 -3
  57. package/dist/conditions.js +0 -43
  58. package/dist/conditions.js.map +0 -1
  59. package/dist/entity.cjs +0 -228
  60. package/dist/entity.cjs.map +0 -1
  61. package/dist/entity.d.cts +0 -149
  62. package/dist/entity.d.ts +0 -149
  63. package/dist/entity.js +0 -224
  64. package/dist/entity.js.map +0 -1
  65. package/dist/query-builder-Csror9Iu.d.ts +0 -507
  66. package/dist/query-builder-D2FM9rsu.d.cts +0 -507
  67. package/dist/standard-schema.cjs +0 -4
  68. package/dist/standard-schema.cjs.map +0 -1
  69. package/dist/standard-schema.d.cts +0 -57
  70. package/dist/standard-schema.d.ts +0 -57
  71. package/dist/standard-schema.js +0 -3
  72. package/dist/standard-schema.js.map +0 -1
  73. package/dist/table-BEhBPy2G.d.cts +0 -364
  74. package/dist/table-BW3cmUqr.d.ts +0 -364
  75. package/dist/table.cjs.map +0 -1
  76. package/dist/table.d.cts +0 -12
  77. package/dist/table.d.ts +0 -12
  78. package/dist/table.js.map +0 -1
  79. package/dist/types.cjs +0 -4
  80. package/dist/types.cjs.map +0 -1
  81. package/dist/types.d.cts +0 -22
  82. package/dist/types.d.ts +0 -22
  83. package/dist/types.js +0 -3
  84. package/dist/types.js.map +0 -1
  85. package/dist/utils/partition-key-template.cjs +0 -19
  86. package/dist/utils/partition-key-template.cjs.map +0 -1
  87. package/dist/utils/partition-key-template.d.cts +0 -32
  88. package/dist/utils/partition-key-template.d.ts +0 -32
  89. package/dist/utils/partition-key-template.js +0 -17
  90. package/dist/utils/partition-key-template.js.map +0 -1
  91. package/dist/utils/sort-key-template.cjs +0 -19
  92. package/dist/utils/sort-key-template.cjs.map +0 -1
  93. package/dist/utils/sort-key-template.d.cts +0 -35
  94. package/dist/utils/sort-key-template.d.ts +0 -35
  95. package/dist/utils/sort-key-template.js +0 -17
  96. package/dist/utils/sort-key-template.js.map +0 -1
@@ -1,627 +0,0 @@
1
- 'use strict';
2
-
3
- // src/conditions.ts
4
- var createComparisonCondition = (type) => (attr, value) => ({
5
- type,
6
- attr,
7
- value
8
- });
9
- var eq = createComparisonCondition("eq");
10
- var ne = createComparisonCondition("ne");
11
- var lt = createComparisonCondition("lt");
12
- var lte = createComparisonCondition("lte");
13
- var gt = createComparisonCondition("gt");
14
- var gte = createComparisonCondition("gte");
15
- var between = (attr, lower, upper) => ({
16
- type: "between",
17
- attr,
18
- value: [lower, upper]
19
- });
20
- var beginsWith = createComparisonCondition("beginsWith");
21
- var contains = createComparisonCondition("contains");
22
- var attributeExists = (attr) => ({
23
- type: "attributeExists",
24
- attr
25
- });
26
- var attributeNotExists = (attr) => ({
27
- type: "attributeNotExists",
28
- attr
29
- });
30
- var and = (...conditions) => ({
31
- type: "and",
32
- conditions
33
- });
34
- var or = (...conditions) => ({
35
- type: "or",
36
- conditions
37
- });
38
- var not = (condition) => ({
39
- type: "not",
40
- condition
41
- });
42
-
43
- // src/expression.ts
44
- var generateAttributeName = (params, attr) => {
45
- for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {
46
- if (existingAttr === attr) {
47
- return existingName;
48
- }
49
- }
50
- const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;
51
- params.expressionAttributeNames[attrName] = attr;
52
- return attrName;
53
- };
54
- var generateValueName = (params, value) => {
55
- const valueName = `:${params.valueCounter.count++}`;
56
- params.expressionAttributeValues[valueName] = value;
57
- return valueName;
58
- };
59
- var validateCondition = (condition, requiresAttr = true, requiresValue = true) => {
60
- if (requiresAttr && !condition.attr) {
61
- throw new Error(`Attribute is required for ${condition.type} condition`);
62
- }
63
- if (requiresValue && condition.value === void 0) {
64
- throw new Error(`Value is required for ${condition.type} condition`);
65
- }
66
- };
67
- var buildComparisonExpression = (condition, operator, params) => {
68
- validateCondition(condition);
69
- if (!condition.attr) {
70
- throw new Error(`Attribute is required for ${condition.type} condition`);
71
- }
72
- const attrName = generateAttributeName(params, condition.attr);
73
- const valueName = generateValueName(params, condition.value);
74
- return `${attrName} ${operator} ${valueName}`;
75
- };
76
- var buildBetweenExpression = (condition, params) => {
77
- validateCondition(condition);
78
- if (!condition.attr) {
79
- throw new Error(`Attribute is required for ${condition.type} condition`);
80
- }
81
- if (!Array.isArray(condition.value) || condition.value.length !== 2) {
82
- throw new Error("Between condition requires an array of two values");
83
- }
84
- const attrName = generateAttributeName(params, condition.attr);
85
- const lowerName = generateValueName(params, condition.value[0]);
86
- const upperName = generateValueName(params, condition.value[1]);
87
- return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;
88
- };
89
- var buildFunctionExpression = (functionName, condition, params) => {
90
- validateCondition(condition);
91
- if (!condition.attr) {
92
- throw new Error(`Attribute is required for ${condition.type} condition`);
93
- }
94
- const attrName = generateAttributeName(params, condition.attr);
95
- const valueName = generateValueName(params, condition.value);
96
- return `${functionName}(${attrName}, ${valueName})`;
97
- };
98
- var buildAttributeFunction = (functionName, condition, params) => {
99
- validateCondition(condition, true, false);
100
- if (!condition.attr) {
101
- throw new Error(`Attribute is required for ${condition.type} condition`);
102
- }
103
- const attrName = generateAttributeName(params, condition.attr);
104
- return `${functionName}(${attrName})`;
105
- };
106
- var buildLogicalExpression = (operator, conditions, params) => {
107
- if (!conditions || conditions.length === 0) {
108
- throw new Error(`At least one condition is required for ${operator} expression`);
109
- }
110
- const expressions = conditions.map((c) => buildExpression(c, params));
111
- return `(${expressions.join(` ${operator} `)})`;
112
- };
113
- var buildExpression = (condition, params) => {
114
- if (!condition) return "";
115
- try {
116
- const expressionBuilders = {
117
- eq: () => buildComparisonExpression(condition, "=", params),
118
- ne: () => buildComparisonExpression(condition, "<>", params),
119
- lt: () => buildComparisonExpression(condition, "<", params),
120
- lte: () => buildComparisonExpression(condition, "<=", params),
121
- gt: () => buildComparisonExpression(condition, ">", params),
122
- gte: () => buildComparisonExpression(condition, ">=", params),
123
- between: () => buildBetweenExpression(condition, params),
124
- beginsWith: () => buildFunctionExpression("begins_with", condition, params),
125
- contains: () => buildFunctionExpression("contains", condition, params),
126
- attributeExists: () => buildAttributeFunction("attribute_exists", condition, params),
127
- attributeNotExists: () => buildAttributeFunction("attribute_not_exists", condition, params),
128
- and: () => {
129
- if (!condition.conditions) {
130
- throw new Error("Conditions array is required for AND operator");
131
- }
132
- return buildLogicalExpression("AND", condition.conditions, params);
133
- },
134
- or: () => {
135
- if (!condition.conditions) {
136
- throw new Error("Conditions array is required for OR operator");
137
- }
138
- return buildLogicalExpression("OR", condition.conditions, params);
139
- },
140
- not: () => {
141
- if (!condition.condition) {
142
- throw new Error("Condition is required for NOT operator");
143
- }
144
- return `NOT (${buildExpression(condition.condition, params)})`;
145
- }
146
- };
147
- const builder = expressionBuilders[condition.type];
148
- if (!builder) {
149
- throw new Error(`Unknown condition type: ${condition.type}`);
150
- }
151
- return builder();
152
- } catch (error) {
153
- if (error instanceof Error) {
154
- console.error(`Error building expression for condition type ${condition.type}:`, error.message);
155
- } else {
156
- console.error(`Error building expression for condition type ${condition.type}:`, error);
157
- }
158
- throw error;
159
- }
160
- };
161
-
162
- // src/utils/debug-expression.ts
163
- function debugCommand(command) {
164
- const result = {};
165
- function replaceAliases(expressionString) {
166
- if (!expressionString) {
167
- return expressionString;
168
- }
169
- let replacedString = expressionString;
170
- for (const alias in command.expressionAttributeNames) {
171
- const attributeName = command.expressionAttributeNames[alias];
172
- const regex = new RegExp(alias, "g");
173
- replacedString = replacedString.replace(regex, attributeName);
174
- }
175
- for (const alias in command.expressionAttributeValues) {
176
- let attributeValue = command.expressionAttributeValues[alias];
177
- if (attributeValue instanceof Set) {
178
- const array = Array.from(attributeValue);
179
- attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(", ")}}`;
180
- } else {
181
- attributeValue = JSON.stringify(attributeValue);
182
- }
183
- const regex = new RegExp(alias, "g");
184
- replacedString = replacedString.replace(regex, attributeValue);
185
- }
186
- return replacedString;
187
- }
188
- if (command.updateExpression) {
189
- result.updateExpression = replaceAliases(command.updateExpression);
190
- }
191
- if (command.conditionExpression) {
192
- result.conditionExpression = replaceAliases(command.conditionExpression);
193
- }
194
- if (command.filterExpression) {
195
- result.filterExpression = replaceAliases(command.filterExpression);
196
- }
197
- if (command.keyConditionExpression) {
198
- result.keyConditionExpression = replaceAliases(command.keyConditionExpression);
199
- }
200
- if (command.projectionExpression) {
201
- result.projectionExpression = replaceAliases(command.projectionExpression);
202
- }
203
- return {
204
- raw: command,
205
- readable: result
206
- };
207
- }
208
-
209
- // src/builders/update-builder.ts
210
- var UpdateBuilder = class {
211
- updates = [];
212
- options = {
213
- returnValues: "ALL_NEW"
214
- };
215
- executor;
216
- tableName;
217
- key;
218
- constructor(executor, tableName, key) {
219
- this.executor = executor;
220
- this.tableName = tableName;
221
- this.key = key;
222
- }
223
- set(valuesOrPath, value) {
224
- if (typeof valuesOrPath === "object") {
225
- for (const [key, value2] of Object.entries(valuesOrPath)) {
226
- this.updates.push({
227
- type: "SET",
228
- path: key,
229
- value: value2
230
- });
231
- }
232
- } else {
233
- this.updates.push({
234
- type: "SET",
235
- path: valuesOrPath,
236
- value
237
- });
238
- }
239
- return this;
240
- }
241
- /**
242
- * Removes an attribute from the item.
243
- *
244
- * @example
245
- * ```typescript
246
- * // Remove simple attributes
247
- * builder
248
- * .remove('temporaryTag')
249
- * .remove('previousLocation');
250
- *
251
- * // Remove nested attributes
252
- * builder
253
- * .remove('metadata.testData')
254
- * .remove('stats.experimentalMetrics');
255
- * ```
256
- *
257
- * @param path - The path to the attribute to remove
258
- * @returns The builder instance for method chaining
259
- */
260
- remove(path) {
261
- this.updates.push({
262
- type: "REMOVE",
263
- path
264
- });
265
- return this;
266
- }
267
- /**
268
- * Adds a value to a number attribute or adds elements to a set.
269
- *
270
- * @example
271
- * ```typescript
272
- * // Increment counters
273
- * builder
274
- * .add('escapeAttempts', 1)
275
- * .add('feedingCount', 1);
276
- *
277
- * // Add to sets
278
- * builder
279
- * .add('knownBehaviors', new Set(['PACK_HUNTING', 'AMBUSH_TACTICS']))
280
- * .add('visitedZones', new Set(['ZONE_A', 'ZONE_B']));
281
- * ```
282
- *
283
- * @param path - The path to the attribute to update
284
- * @param value - The value to add (number or set)
285
- * @returns The builder instance for method chaining
286
- */
287
- add(path, value) {
288
- this.updates.push({
289
- type: "ADD",
290
- path,
291
- value
292
- });
293
- return this;
294
- }
295
- /**
296
- * Removes elements from a set attribute.
297
- *
298
- * @example
299
- * ```typescript
300
- * // Remove from sets using arrays
301
- * builder.deleteElementsFromSet(
302
- * 'allowedHabitats',
303
- * ['JUNGLE', 'COASTAL']
304
- * );
305
- *
306
- * // Remove from sets using Set DynamoItems
307
- * builder.deleteElementsFromSet(
308
- * 'knownBehaviors',
309
- * new Set(['NOCTURNAL', 'TERRITORIAL'])
310
- * );
311
- *
312
- * // Remove from nested sets
313
- * builder.deleteElementsFromSet(
314
- * 'stats.compatibleSpecies',
315
- * ['VELOCIRAPTOR', 'DILOPHOSAURUS']
316
- * );
317
- * ```
318
- *
319
- * @param path - The path to the set attribute
320
- * @param value - Elements to remove (array or Set)
321
- * @returns The builder instance for method chaining
322
- */
323
- deleteElementsFromSet(path, value) {
324
- let valuesToDelete;
325
- if (Array.isArray(value)) {
326
- valuesToDelete = new Set(value);
327
- } else {
328
- valuesToDelete = value;
329
- }
330
- this.updates.push({
331
- type: "DELETE",
332
- path,
333
- value: valuesToDelete
334
- });
335
- return this;
336
- }
337
- /**
338
- * Adds a condition that must be satisfied for the update to succeed.
339
- *
340
- * @example
341
- * ```typescript
342
- * // Simple condition
343
- * builder.condition(op =>
344
- * op.eq('status', 'ACTIVE')
345
- * );
346
- *
347
- * // Health check condition
348
- * builder.condition(op =>
349
- * op.and([
350
- * op.gt('health', 50),
351
- * op.eq('status', 'HUNTING')
352
- * ])
353
- * );
354
- *
355
- * // Complex security condition
356
- * builder.condition(op =>
357
- * op.and([
358
- * op.attributeExists('securitySystem'),
359
- * op.eq('containmentStatus', 'SECURE'),
360
- * op.lt('aggressionLevel', 8)
361
- * ])
362
- * );
363
- *
364
- * // Version check (optimistic locking)
365
- * builder.condition(op =>
366
- * op.eq('version', currentVersion)
367
- * );
368
- * ```
369
- *
370
- * @param condition - Either a Condition DynamoItem or a callback function that builds the condition
371
- * @returns The builder instance for method chaining
372
- */
373
- condition(condition) {
374
- if (typeof condition === "function") {
375
- const conditionOperator = {
376
- eq,
377
- ne,
378
- lt,
379
- lte,
380
- gt,
381
- gte,
382
- between,
383
- beginsWith,
384
- contains,
385
- attributeExists,
386
- attributeNotExists,
387
- and,
388
- or,
389
- not
390
- };
391
- this.options.condition = condition(conditionOperator);
392
- } else {
393
- this.options.condition = condition;
394
- }
395
- return this;
396
- }
397
- /**
398
- * Sets which item attributes to include in the response.
399
- *
400
- * Available options:
401
- * - ALL_NEW: All attributes after the update
402
- * - UPDATED_NEW: Only updated attributes, new values
403
- * - ALL_OLD: All attributes before the update
404
- * - UPDATED_OLD: Only updated attributes, old values
405
- * - NONE: No attributes returned (default)
406
- *
407
- * @example
408
- * ```typescript
409
- * // Get complete updated dinosaur
410
- * const result = await builder
411
- * .set('status', 'SLEEPING')
412
- * .returnValues('ALL_NEW')
413
- * .execute();
414
- *
415
- * // Track specific attribute changes
416
- * const result = await builder
417
- * .set({
418
- * 'stats.health': 100,
419
- * 'stats.energy': 95
420
- * })
421
- * .returnValues('UPDATED_OLD')
422
- * .execute();
423
- *
424
- * if (result.item) {
425
- * console.log('Previous health:', result.item.stats?.health);
426
- * }
427
- * ```
428
- *
429
- * @param returnValues - Which attributes to return in the response
430
- * @returns The builder instance for method chaining
431
- */
432
- returnValues(returnValues) {
433
- this.options.returnValues = returnValues;
434
- return this;
435
- }
436
- /**
437
- * Generate the DynamoDB command parameters
438
- */
439
- toDynamoCommand() {
440
- if (this.updates.length === 0) {
441
- throw new Error("No update actions specified");
442
- }
443
- const expressionParams = {
444
- expressionAttributeNames: {},
445
- expressionAttributeValues: {},
446
- valueCounter: { count: 0 }
447
- };
448
- let updateExpression = "";
449
- const setUpdates = [];
450
- const removeUpdates = [];
451
- const addUpdates = [];
452
- const deleteUpdates = [];
453
- for (const update of this.updates) {
454
- switch (update.type) {
455
- case "SET":
456
- setUpdates.push(update);
457
- break;
458
- case "REMOVE":
459
- removeUpdates.push(update);
460
- break;
461
- case "ADD":
462
- addUpdates.push(update);
463
- break;
464
- case "DELETE":
465
- deleteUpdates.push(update);
466
- break;
467
- }
468
- }
469
- if (setUpdates.length > 0) {
470
- updateExpression += "SET ";
471
- updateExpression += setUpdates.map((update) => {
472
- const attrName = generateAttributeName(expressionParams, update.path);
473
- const valueName = generateValueName(expressionParams, update.value);
474
- expressionParams.expressionAttributeValues[valueName] = update.value;
475
- return `${attrName} = ${valueName}`;
476
- }).join(", ");
477
- }
478
- if (removeUpdates.length > 0) {
479
- if (updateExpression) {
480
- updateExpression += " ";
481
- }
482
- updateExpression += "REMOVE ";
483
- updateExpression += removeUpdates.map((update) => {
484
- return generateAttributeName(expressionParams, update.path);
485
- }).join(", ");
486
- }
487
- if (addUpdates.length > 0) {
488
- if (updateExpression) {
489
- updateExpression += " ";
490
- }
491
- updateExpression += "ADD ";
492
- updateExpression += addUpdates.map((update) => {
493
- const attrName = generateAttributeName(expressionParams, update.path);
494
- const valueName = generateValueName(expressionParams, update.value);
495
- return `${attrName} ${valueName}`;
496
- }).join(", ");
497
- }
498
- if (deleteUpdates.length > 0) {
499
- if (updateExpression) {
500
- updateExpression += " ";
501
- }
502
- updateExpression += "DELETE ";
503
- updateExpression += deleteUpdates.map((update) => {
504
- const attrName = generateAttributeName(expressionParams, update.path);
505
- const valueName = generateValueName(expressionParams, update.value);
506
- return `${attrName} ${valueName}`;
507
- }).join(", ");
508
- }
509
- let conditionExpression;
510
- if (this.options.condition) {
511
- conditionExpression = buildExpression(this.options.condition, expressionParams);
512
- }
513
- const { expressionAttributeNames, expressionAttributeValues } = expressionParams;
514
- return {
515
- tableName: this.tableName,
516
- key: this.key,
517
- updateExpression,
518
- conditionExpression,
519
- expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0,
520
- expressionAttributeValues: Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : void 0,
521
- returnValues: this.options.returnValues
522
- };
523
- }
524
- /**
525
- * Adds this update operation to a transaction.
526
- *
527
- * @example
528
- * ```typescript
529
- * const transaction = new TransactionBuilder(executor);
530
- *
531
- * // Update dinosaur status and habitat occupancy atomically
532
- * new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
533
- * .set('location', 'PADDOCK_A')
534
- * .set('status', 'CONTAINED')
535
- * .withTransaction(transaction);
536
- *
537
- * new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
538
- * .add('occupants', 1)
539
- * .set('lastOccupied', new Date().toISOString())
540
- * .withTransaction(transaction);
541
- *
542
- * // Execute all operations atomically
543
- * await transaction.execute();
544
- * ```
545
- *
546
- * @param transaction - The transaction builder to add this operation to
547
- * @returns The builder instance for method chaining
548
- */
549
- withTransaction(transaction) {
550
- const command = this.toDynamoCommand();
551
- transaction.updateWithCommand(command);
552
- }
553
- /**
554
- * Gets a human-readable representation of the update command.
555
- *
556
- * @example
557
- * ```typescript
558
- * // Create complex update
559
- * const builder = new UpdateBuilder(executor, 'dinosaurs', { id: 'RAPTOR-001' })
560
- * .set({
561
- * status: 'HUNTING',
562
- * 'stats.health': 95,
563
- * 'behavior.lastObserved': new Date().toISOString()
564
- * })
565
- * .add('huntingSuccesses', 1)
566
- * .condition(op => op.gt('health', 50));
567
- *
568
- * // Debug the update
569
- * const debugInfo = builder.debug();
570
- * console.log('Update operation:', debugInfo);
571
- * ```
572
- *
573
- * @returns A readable representation of the update command with resolved expressions
574
- */
575
- debug() {
576
- const command = this.toDynamoCommand();
577
- return debugCommand(command);
578
- }
579
- /**
580
- * Executes the update operation against DynamoDB.
581
- *
582
- * @example
583
- * ```typescript
584
- * try {
585
- * // Update dinosaur status with conditions
586
- * const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
587
- * .set({
588
- * status: 'FEEDING',
589
- * lastMeal: new Date().toISOString(),
590
- * 'stats.hunger': 0
591
- * })
592
- * .add('feedingCount', 1)
593
- * .condition(op =>
594
- * op.and([
595
- * op.gt('stats.hunger', 80),
596
- * op.eq('status', 'HUNTING')
597
- * ])
598
- * )
599
- * .returnValues('ALL_NEW')
600
- * .execute();
601
- *
602
- * if (result.item) {
603
- * console.log('Updated dinosaur:', result.item);
604
- * }
605
- * } catch (error) {
606
- * // Handle condition check failure
607
- * console.error('Failed to update dinosaur:', error);
608
- * // Check if dinosaur wasn't hungry enough
609
- * if (error.name === 'ConditionalCheckFailedException') {
610
- * console.log('Dinosaur not ready for feeding');
611
- * }
612
- * }
613
- * ```
614
- *
615
- * @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)
616
- * @throws {ConditionalCheckFailedException} If the condition check fails
617
- * @throws {Error} If the update operation fails for other reasons
618
- */
619
- async execute() {
620
- const params = this.toDynamoCommand();
621
- return this.executor(params);
622
- }
623
- };
624
-
625
- exports.UpdateBuilder = UpdateBuilder;
626
- //# sourceMappingURL=update-builder.cjs.map
627
- //# sourceMappingURL=update-builder.cjs.map