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