dyno-table 2.3.2 → 2.4.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.
@@ -1,18 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var chunkELULXDSB_cjs = require('./chunk-ELULXDSB.cjs');
3
4
  var chunk7UJJ7JXM_cjs = require('./chunk-7UJJ7JXM.cjs');
4
5
 
5
6
  // src/builders/batch-builder.ts
6
- var BatchError = class extends Error {
7
- operation;
8
- cause;
9
- constructor(message, operation, cause) {
10
- super(message);
11
- this.name = "BatchError";
12
- this.operation = operation;
13
- this.cause = cause;
14
- }
15
- };
16
7
  var BatchBuilder = class {
17
8
  constructor(batchWriteExecutor, batchGetExecutor, config) {
18
9
  this.batchWriteExecutor = batchWriteExecutor;
@@ -47,10 +38,7 @@ var BatchBuilder = class {
47
38
  */
48
39
  validateNotEmpty() {
49
40
  if (this.isEmpty()) {
50
- throw new BatchError(
51
- "Cannot execute empty batch. Add operations using entity builders with .withBatch()",
52
- "write"
53
- );
41
+ throw chunkELULXDSB_cjs.BatchErrors.batchEmpty("write");
54
42
  }
55
43
  }
56
44
  /**
@@ -141,13 +129,14 @@ var BatchBuilder = class {
141
129
  key
142
130
  };
143
131
  }
144
- throw new BatchError(`Unsupported batch item type for write operation: ${item.type}`, "write");
132
+ throw chunkELULXDSB_cjs.BatchErrors.unsupportedType("write", item);
145
133
  });
146
134
  return await this.batchWriteExecutor(operations);
147
135
  } catch (error) {
148
- throw new BatchError(
149
- `Failed to execute batch write operations: ${error instanceof Error ? error.message : "Unknown error"}`,
150
- "write",
136
+ if (error instanceof chunkELULXDSB_cjs.BatchError) throw error;
137
+ throw chunkELULXDSB_cjs.BatchErrors.batchWriteFailed(
138
+ [],
139
+ { operationCount: this.writeItems.length },
151
140
  error instanceof Error ? error : void 0
152
141
  );
153
142
  }
@@ -174,13 +163,14 @@ var BatchBuilder = class {
174
163
  sk: this.config.sortKey ? tableKey[this.config.sortKey] : void 0
175
164
  };
176
165
  }
177
- throw new BatchError(`Unsupported batch item type for get operation: ${item.type}`, "read");
166
+ throw chunkELULXDSB_cjs.BatchErrors.unsupportedType("read", item);
178
167
  });
179
168
  return await this.batchGetExecutor(keys);
180
169
  } catch (error) {
181
- throw new BatchError(
182
- `Failed to execute batch get operations: ${error instanceof Error ? error.message : "Unknown error"}`,
183
- "read",
170
+ if (error instanceof chunkELULXDSB_cjs.BatchError) throw error;
171
+ throw chunkELULXDSB_cjs.BatchErrors.batchGetFailed(
172
+ [],
173
+ { operationCount: this.getItems.length },
184
174
  error instanceof Error ? error : void 0
185
175
  );
186
176
  }
@@ -226,13 +216,16 @@ var BatchBuilder = class {
226
216
  try {
227
217
  writeResults = await this.executeWrites();
228
218
  } catch (error) {
229
- if (error instanceof BatchError) {
219
+ if (error instanceof chunkELULXDSB_cjs.BatchError) {
230
220
  errors.push(error);
231
221
  } else {
232
222
  errors.push(
233
- new BatchError(
223
+ new chunkELULXDSB_cjs.BatchError(
234
224
  "Unexpected error during write operations",
225
+ chunkELULXDSB_cjs.ErrorCodes.BATCH_WRITE_FAILED,
235
226
  "write",
227
+ [],
228
+ {},
236
229
  error instanceof Error ? error : void 0
237
230
  )
238
231
  );
@@ -243,13 +236,16 @@ var BatchBuilder = class {
243
236
  try {
244
237
  getResults = await this.executeGets();
245
238
  } catch (error) {
246
- if (error instanceof BatchError) {
239
+ if (error instanceof chunkELULXDSB_cjs.BatchError) {
247
240
  errors.push(error);
248
241
  } else {
249
242
  errors.push(
250
- new BatchError(
243
+ new chunkELULXDSB_cjs.BatchError(
251
244
  "Unexpected error during read operations",
245
+ chunkELULXDSB_cjs.ErrorCodes.BATCH_GET_FAILED,
252
246
  "read",
247
+ [],
248
+ {},
253
249
  error instanceof Error ? error : void 0
254
250
  )
255
251
  );
@@ -316,16 +312,16 @@ var generateValueName = (params, value) => {
316
312
  };
317
313
  var validateCondition = (condition, requiresAttr = true, requiresValue = true) => {
318
314
  if (requiresAttr && !condition.attr) {
319
- throw new Error(`Attribute is required for ${condition.type} condition`);
315
+ throw chunkELULXDSB_cjs.ExpressionErrors.missingAttribute(condition.type, condition);
320
316
  }
321
317
  if (requiresValue && condition.value === void 0) {
322
- throw new Error(`Value is required for ${condition.type} condition`);
318
+ throw chunkELULXDSB_cjs.ExpressionErrors.missingValue(condition.type, condition);
323
319
  }
324
320
  };
325
321
  var buildComparisonExpression = (condition, operator, params) => {
326
322
  validateCondition(condition);
327
323
  if (!condition.attr) {
328
- throw new Error(`Attribute is required for ${condition.type} condition`);
324
+ throw chunkELULXDSB_cjs.ExpressionErrors.missingAttribute(condition.type, condition);
329
325
  }
330
326
  const attrName = generateAttributeName(params, condition.attr);
331
327
  const valueName = generateValueName(params, condition.value);
@@ -334,10 +330,14 @@ var buildComparisonExpression = (condition, operator, params) => {
334
330
  var buildBetweenExpression = (condition, params) => {
335
331
  validateCondition(condition);
336
332
  if (!condition.attr) {
337
- throw new Error(`Attribute is required for ${condition.type} condition`);
333
+ throw chunkELULXDSB_cjs.ExpressionErrors.missingAttribute(condition.type, condition);
338
334
  }
339
335
  if (!Array.isArray(condition.value) || condition.value.length !== 2) {
340
- throw new Error("Between condition requires an array of two values");
336
+ throw chunkELULXDSB_cjs.ExpressionErrors.invalidCondition(
337
+ condition.type,
338
+ condition,
339
+ "Provide an array with exactly two values: [lowerBound, upperBound]"
340
+ );
341
341
  }
342
342
  const attrName = generateAttributeName(params, condition.attr);
343
343
  const lowerName = generateValueName(params, condition.value[0]);
@@ -347,13 +347,17 @@ var buildBetweenExpression = (condition, params) => {
347
347
  var buildInExpression = (condition, params) => {
348
348
  validateCondition(condition);
349
349
  if (!condition.attr) {
350
- throw new Error(`Attribute is required for ${condition.type} condition`);
350
+ throw chunkELULXDSB_cjs.ExpressionErrors.missingAttribute(condition.type, condition);
351
351
  }
352
352
  if (!Array.isArray(condition.value) || condition.value.length === 0) {
353
- throw new Error("In condition requires a non-empty array of values");
353
+ throw chunkELULXDSB_cjs.ExpressionErrors.emptyArray(condition.type, condition.value);
354
354
  }
355
355
  if (condition.value.length > 100) {
356
- throw new Error("In condition supports a maximum of 100 values");
356
+ throw chunkELULXDSB_cjs.ExpressionErrors.invalidCondition(
357
+ condition.type,
358
+ condition,
359
+ "Split your query into multiple operations or use a different condition type"
360
+ );
357
361
  }
358
362
  const attrName = generateAttributeName(params, condition.attr);
359
363
  const valueNames = condition.value.map((value) => generateValueName(params, value));
@@ -362,7 +366,7 @@ var buildInExpression = (condition, params) => {
362
366
  var buildFunctionExpression = (functionName, condition, params) => {
363
367
  validateCondition(condition);
364
368
  if (!condition.attr) {
365
- throw new Error(`Attribute is required for ${condition.type} condition`);
369
+ throw chunkELULXDSB_cjs.ExpressionErrors.missingAttribute(condition.type, condition);
366
370
  }
367
371
  const attrName = generateAttributeName(params, condition.attr);
368
372
  const valueName = generateValueName(params, condition.value);
@@ -371,66 +375,65 @@ var buildFunctionExpression = (functionName, condition, params) => {
371
375
  var buildAttributeFunction = (functionName, condition, params) => {
372
376
  validateCondition(condition, true, false);
373
377
  if (!condition.attr) {
374
- throw new Error(`Attribute is required for ${condition.type} condition`);
378
+ throw chunkELULXDSB_cjs.ExpressionErrors.missingAttribute(condition.type, condition);
375
379
  }
376
380
  const attrName = generateAttributeName(params, condition.attr);
377
381
  return `${functionName}(${attrName})`;
378
382
  };
379
383
  var buildLogicalExpression = (operator, conditions, params) => {
380
384
  if (!conditions || conditions.length === 0) {
381
- throw new Error(`At least one condition is required for ${operator} expression`);
385
+ throw chunkELULXDSB_cjs.ExpressionErrors.emptyArray(operator, conditions);
382
386
  }
383
387
  const expressions = conditions.map((c) => buildExpression(c, params));
384
388
  return `(${expressions.join(` ${operator} `)})`;
385
389
  };
386
390
  var buildExpression = (condition, params) => {
387
391
  if (!condition) return "";
388
- try {
389
- const expressionBuilders = {
390
- eq: () => buildComparisonExpression(condition, "=", params),
391
- ne: () => buildComparisonExpression(condition, "<>", params),
392
- lt: () => buildComparisonExpression(condition, "<", params),
393
- lte: () => buildComparisonExpression(condition, "<=", params),
394
- gt: () => buildComparisonExpression(condition, ">", params),
395
- gte: () => buildComparisonExpression(condition, ">=", params),
396
- between: () => buildBetweenExpression(condition, params),
397
- in: () => buildInExpression(condition, params),
398
- beginsWith: () => buildFunctionExpression("begins_with", condition, params),
399
- contains: () => buildFunctionExpression("contains", condition, params),
400
- attributeExists: () => buildAttributeFunction("attribute_exists", condition, params),
401
- attributeNotExists: () => buildAttributeFunction("attribute_not_exists", condition, params),
402
- and: () => {
403
- if (!condition.conditions) {
404
- throw new Error("Conditions array is required for AND operator");
405
- }
406
- return buildLogicalExpression("AND", condition.conditions, params);
407
- },
408
- or: () => {
409
- if (!condition.conditions) {
410
- throw new Error("Conditions array is required for OR operator");
411
- }
412
- return buildLogicalExpression("OR", condition.conditions, params);
413
- },
414
- not: () => {
415
- if (!condition.condition) {
416
- throw new Error("Condition is required for NOT operator");
417
- }
418
- return `NOT (${buildExpression(condition.condition, params)})`;
392
+ const expressionBuilders = {
393
+ eq: () => buildComparisonExpression(condition, "=", params),
394
+ ne: () => buildComparisonExpression(condition, "<>", params),
395
+ lt: () => buildComparisonExpression(condition, "<", params),
396
+ lte: () => buildComparisonExpression(condition, "<=", params),
397
+ gt: () => buildComparisonExpression(condition, ">", params),
398
+ gte: () => buildComparisonExpression(condition, ">=", params),
399
+ between: () => buildBetweenExpression(condition, params),
400
+ in: () => buildInExpression(condition, params),
401
+ beginsWith: () => buildFunctionExpression("begins_with", condition, params),
402
+ contains: () => buildFunctionExpression("contains", condition, params),
403
+ attributeExists: () => buildAttributeFunction("attribute_exists", condition, params),
404
+ attributeNotExists: () => buildAttributeFunction("attribute_not_exists", condition, params),
405
+ and: () => {
406
+ if (!condition.conditions) {
407
+ throw chunkELULXDSB_cjs.ExpressionErrors.invalidCondition(
408
+ condition.type,
409
+ condition,
410
+ "Provide an array of conditions to combine with AND"
411
+ );
419
412
  }
420
- };
421
- const builder = expressionBuilders[condition.type];
422
- if (!builder) {
423
- throw new Error(`Unknown condition type: ${condition.type}`);
424
- }
425
- return builder();
426
- } catch (error) {
427
- if (error instanceof Error) {
428
- console.error(`Error building expression for condition type ${condition.type}:`, error.message);
429
- } else {
430
- console.error(`Error building expression for condition type ${condition.type}:`, error);
413
+ return buildLogicalExpression("AND", condition.conditions, params);
414
+ },
415
+ or: () => {
416
+ if (!condition.conditions) {
417
+ throw chunkELULXDSB_cjs.ExpressionErrors.invalidCondition(
418
+ condition.type,
419
+ condition,
420
+ "Provide an array of conditions to combine with OR"
421
+ );
422
+ }
423
+ return buildLogicalExpression("OR", condition.conditions, params);
424
+ },
425
+ not: () => {
426
+ if (!condition.condition) {
427
+ throw chunkELULXDSB_cjs.ExpressionErrors.invalidCondition(condition.type, condition, "Provide a condition to negate with NOT");
428
+ }
429
+ return `NOT (${buildExpression(condition.condition, params)})`;
431
430
  }
432
- throw error;
431
+ };
432
+ const builder = expressionBuilders[condition.type];
433
+ if (!builder) {
434
+ throw chunkELULXDSB_cjs.ExpressionErrors.unknownType(condition.type, condition);
433
435
  }
436
+ return builder();
434
437
  };
435
438
  var prepareExpressionParams = (condition) => {
436
439
  if (!condition) return {};
@@ -1757,7 +1760,7 @@ var TransactionBuilder = class {
1757
1760
  const pkValue = newItem[pkName];
1758
1761
  const skValue = skName ? newItem[skName] : void 0;
1759
1762
  if (!pkValue) {
1760
- throw new Error(`Primary key value for '${pkName}' is missing`);
1763
+ throw chunkELULXDSB_cjs.ConfigurationErrors.primaryKeyMissing(tableName, pkName, newItem);
1761
1764
  }
1762
1765
  const duplicateItem = this.items.find((item) => {
1763
1766
  let itemKey;
@@ -1789,8 +1792,10 @@ var TransactionBuilder = class {
1789
1792
  return false;
1790
1793
  });
1791
1794
  if (duplicateItem) {
1792
- throw new Error(
1793
- `Duplicate item detected in transaction: Table=${tableName}, ${pkName}=${String(pkValue)}, ${skName}=${skValue !== void 0 ? String(skValue) : "undefined"}. DynamoDB transactions do not allow multiple operations on the same item.`
1795
+ throw chunkELULXDSB_cjs.TransactionErrors.duplicateItem(
1796
+ tableName,
1797
+ { name: pkName, value: pkValue },
1798
+ skName ? { name: skName, value: skValue } : void 0
1794
1799
  );
1795
1800
  }
1796
1801
  }
@@ -1800,7 +1805,7 @@ var TransactionBuilder = class {
1800
1805
  };
1801
1806
  if (this.indexConfig.sortKey) {
1802
1807
  if (key.sk === void 0) {
1803
- throw new Error("Sort key is required for delete operation");
1808
+ throw chunkELULXDSB_cjs.ConfigurationErrors.sortKeyRequired("", this.indexConfig.partitionKey, this.indexConfig.sortKey);
1804
1809
  }
1805
1810
  keyCondition[this.indexConfig.sortKey] = key.sk;
1806
1811
  }
@@ -2174,7 +2179,7 @@ var TransactionBuilder = class {
2174
2179
  this.checkForDuplicateItem(tableName, keyCondition);
2175
2180
  const { expression, names, values } = prepareExpressionParams(condition);
2176
2181
  if (!expression) {
2177
- throw new Error("Failed to generate condition expression");
2182
+ throw chunkELULXDSB_cjs.ConfigurationErrors.conditionGenerationFailed(condition);
2178
2183
  }
2179
2184
  const transactionItem = {
2180
2185
  type: "ConditionCheck",
@@ -2328,7 +2333,7 @@ var TransactionBuilder = class {
2328
2333
  */
2329
2334
  async execute() {
2330
2335
  if (this.items.length === 0) {
2331
- throw new Error("No transaction items specified");
2336
+ throw chunkELULXDSB_cjs.TransactionErrors.transactionEmpty();
2332
2337
  }
2333
2338
  const transactItems = this.items.map((item) => {
2334
2339
  switch (item.type) {
@@ -2375,7 +2380,7 @@ var TransactionBuilder = class {
2375
2380
  };
2376
2381
  default: {
2377
2382
  const exhaustiveCheck = item;
2378
- throw new Error(`Unsupported transaction item type: ${String(exhaustiveCheck)}`);
2383
+ throw chunkELULXDSB_cjs.TransactionErrors.unsupportedType(exhaustiveCheck);
2379
2384
  }
2380
2385
  }
2381
2386
  });
@@ -2388,9 +2393,7 @@ var TransactionBuilder = class {
2388
2393
  try {
2389
2394
  await this.executor(params);
2390
2395
  } catch (error) {
2391
- console.log(this.debug());
2392
- console.error("Error executing transaction:", error);
2393
- throw error;
2396
+ throw chunkELULXDSB_cjs.TransactionErrors.transactionFailed(this.items.length, {}, error instanceof Error ? error : void 0);
2394
2397
  }
2395
2398
  }
2396
2399
  };
@@ -2412,6 +2415,9 @@ var UpdateBuilder = class {
2412
2415
  set(valuesOrPath, value) {
2413
2416
  if (typeof valuesOrPath === "object") {
2414
2417
  for (const [key, value2] of Object.entries(valuesOrPath)) {
2418
+ if (value2 === void 0) {
2419
+ throw chunkELULXDSB_cjs.ValidationErrors.undefinedValue(key, this.tableName, this.key);
2420
+ }
2415
2421
  this.updates.push({
2416
2422
  type: "SET",
2417
2423
  path: key,
@@ -2419,6 +2425,9 @@ var UpdateBuilder = class {
2419
2425
  });
2420
2426
  }
2421
2427
  } else {
2428
+ if (value === void 0) {
2429
+ throw chunkELULXDSB_cjs.ValidationErrors.undefinedValue(valuesOrPath, this.tableName, this.key);
2430
+ }
2422
2431
  this.updates.push({
2423
2432
  type: "SET",
2424
2433
  path: valuesOrPath,
@@ -2474,6 +2483,9 @@ var UpdateBuilder = class {
2474
2483
  * @returns The builder instance for method chaining
2475
2484
  */
2476
2485
  add(path, value) {
2486
+ if (value === void 0) {
2487
+ throw chunkELULXDSB_cjs.ValidationErrors.undefinedValue(path, this.tableName, this.key);
2488
+ }
2477
2489
  this.updates.push({
2478
2490
  type: "ADD",
2479
2491
  path,
@@ -2510,6 +2522,9 @@ var UpdateBuilder = class {
2510
2522
  * @returns The builder instance for method chaining
2511
2523
  */
2512
2524
  deleteElementsFromSet(path, value) {
2525
+ if (value === void 0) {
2526
+ throw chunkELULXDSB_cjs.ValidationErrors.undefinedValue(path, this.tableName, this.key);
2527
+ }
2513
2528
  let valuesToDelete;
2514
2529
  if (Array.isArray(value)) {
2515
2530
  valuesToDelete = new Set(value);
@@ -2628,7 +2643,7 @@ var UpdateBuilder = class {
2628
2643
  */
2629
2644
  toDynamoCommand() {
2630
2645
  if (this.updates.length === 0) {
2631
- throw new Error("No update actions specified");
2646
+ throw chunkELULXDSB_cjs.ValidationErrors.noUpdateActions(this.tableName, this.key);
2632
2647
  }
2633
2648
  const expressionParams = {
2634
2649
  expressionAttributeNames: {},
@@ -2902,11 +2917,11 @@ var ConditionCheckBuilder = class {
2902
2917
  */
2903
2918
  toDynamoCommand() {
2904
2919
  if (!this.conditionExpression) {
2905
- throw new Error("Condition is required for condition check operations");
2920
+ throw chunkELULXDSB_cjs.ValidationErrors.conditionRequired(this.tableName, this.key);
2906
2921
  }
2907
2922
  const { expression, names, values } = prepareExpressionParams(this.conditionExpression);
2908
2923
  if (!expression) {
2909
- throw new Error("Failed to generate condition expression");
2924
+ throw chunkELULXDSB_cjs.ConfigurationErrors.conditionGenerationFailed(this.conditionExpression);
2910
2925
  }
2911
2926
  return {
2912
2927
  tableName: this.tableName,
@@ -2938,7 +2953,7 @@ var ConditionCheckBuilder = class {
2938
2953
  */
2939
2954
  withTransaction(transaction) {
2940
2955
  if (!this.conditionExpression) {
2941
- throw new Error("Condition is required for condition check operations");
2956
+ throw chunkELULXDSB_cjs.ValidationErrors.conditionRequired(this.tableName, this.key);
2942
2957
  }
2943
2958
  const command = this.toDynamoCommand();
2944
2959
  transaction.conditionCheckWithCommand(command);
@@ -3200,7 +3215,6 @@ var ScanBuilder = class _ScanBuilder extends FilterBuilder {
3200
3215
  };
3201
3216
 
3202
3217
  exports.BatchBuilder = BatchBuilder;
3203
- exports.BatchError = BatchError;
3204
3218
  exports.ConditionCheckBuilder = ConditionCheckBuilder;
3205
3219
  exports.DeleteBuilder = DeleteBuilder;
3206
3220
  exports.FilterBuilder = FilterBuilder;
@@ -3213,5 +3227,4 @@ exports.ScanBuilder = ScanBuilder;
3213
3227
  exports.TransactionBuilder = TransactionBuilder;
3214
3228
  exports.UpdateBuilder = UpdateBuilder;
3215
3229
  exports.buildExpression = buildExpression;
3216
- exports.debugCommand = debugCommand;
3217
3230
  exports.generateAttributeName = generateAttributeName;