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.
- package/README.md +0 -6
- package/dist/builders.cjs +14 -13
- package/dist/builders.d.cts +2 -2
- package/dist/builders.d.ts +2 -2
- package/dist/builders.js +2 -1
- package/dist/{chunk-EODPMYPE.js → chunk-64DG2EEI.js} +31 -24
- package/dist/{chunk-XYL43FDX.cjs → chunk-AHF4H42Q.cjs} +109 -96
- package/dist/chunk-ELULXDSB.cjs +564 -0
- package/dist/chunk-FF7FYGDH.js +543 -0
- package/dist/{chunk-DTFJJASK.js → chunk-GWHGUKAL.js} +106 -91
- package/dist/{chunk-KA3VPIPS.cjs → chunk-OLURZQ7R.cjs} +46 -39
- package/dist/{chunk-2EWNZOUK.js → chunk-U6MQGB6Y.js} +275 -72
- package/dist/{chunk-NTA6GDPP.cjs → chunk-ZXM6LPRV.cjs} +295 -71
- package/dist/{conditions-D_w7vVYG.d.ts → conditions-BSAcZswY.d.ts} +1 -1
- package/dist/{conditions-CcZL0sR2.d.cts → conditions-C8bM__Pn.d.cts} +1 -1
- package/dist/conditions.d.cts +1 -1
- package/dist/conditions.d.ts +1 -1
- package/dist/entity.cjs +5 -4
- package/dist/entity.d.cts +7 -4
- package/dist/entity.d.ts +7 -4
- package/dist/entity.js +2 -1
- package/dist/{index-DlN8G9hd.d.cts → index-BX-MSZHj.d.cts} +216 -11
- package/dist/{index-2cbm07Bi.d.ts → index-DdTolMJW.d.ts} +216 -11
- package/dist/index.cjs +178 -17
- package/dist/index.d.cts +267 -2
- package/dist/index.d.ts +267 -2
- package/dist/index.js +4 -3
- package/dist/table.cjs +4 -3
- package/dist/table.d.cts +2 -2
- package/dist/table.d.ts +2 -2
- package/dist/table.js +3 -2
- package/package.json +1 -1
|
@@ -1,16 +1,7 @@
|
|
|
1
|
+
import { BatchErrors, BatchError, ErrorCodes, ExpressionErrors, ConfigurationErrors, TransactionErrors, ValidationErrors } from './chunk-FF7FYGDH.js';
|
|
1
2
|
import { not, or, and, attributeNotExists, attributeExists, contains, beginsWith, inArray, between, gte, gt, lte, lt, ne, eq } from './chunk-2WIBY7PZ.js';
|
|
2
3
|
|
|
3
4
|
// src/builders/batch-builder.ts
|
|
4
|
-
var BatchError = class extends Error {
|
|
5
|
-
operation;
|
|
6
|
-
cause;
|
|
7
|
-
constructor(message, operation, cause) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = "BatchError";
|
|
10
|
-
this.operation = operation;
|
|
11
|
-
this.cause = cause;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
5
|
var BatchBuilder = class {
|
|
15
6
|
constructor(batchWriteExecutor, batchGetExecutor, config) {
|
|
16
7
|
this.batchWriteExecutor = batchWriteExecutor;
|
|
@@ -45,10 +36,7 @@ var BatchBuilder = class {
|
|
|
45
36
|
*/
|
|
46
37
|
validateNotEmpty() {
|
|
47
38
|
if (this.isEmpty()) {
|
|
48
|
-
throw
|
|
49
|
-
"Cannot execute empty batch. Add operations using entity builders with .withBatch()",
|
|
50
|
-
"write"
|
|
51
|
-
);
|
|
39
|
+
throw BatchErrors.batchEmpty("write");
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
/**
|
|
@@ -139,13 +127,14 @@ var BatchBuilder = class {
|
|
|
139
127
|
key
|
|
140
128
|
};
|
|
141
129
|
}
|
|
142
|
-
throw
|
|
130
|
+
throw BatchErrors.unsupportedType("write", item);
|
|
143
131
|
});
|
|
144
132
|
return await this.batchWriteExecutor(operations);
|
|
145
133
|
} catch (error) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
if (error instanceof BatchError) throw error;
|
|
135
|
+
throw BatchErrors.batchWriteFailed(
|
|
136
|
+
[],
|
|
137
|
+
{ operationCount: this.writeItems.length },
|
|
149
138
|
error instanceof Error ? error : void 0
|
|
150
139
|
);
|
|
151
140
|
}
|
|
@@ -172,13 +161,14 @@ var BatchBuilder = class {
|
|
|
172
161
|
sk: this.config.sortKey ? tableKey[this.config.sortKey] : void 0
|
|
173
162
|
};
|
|
174
163
|
}
|
|
175
|
-
throw
|
|
164
|
+
throw BatchErrors.unsupportedType("read", item);
|
|
176
165
|
});
|
|
177
166
|
return await this.batchGetExecutor(keys);
|
|
178
167
|
} catch (error) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
168
|
+
if (error instanceof BatchError) throw error;
|
|
169
|
+
throw BatchErrors.batchGetFailed(
|
|
170
|
+
[],
|
|
171
|
+
{ operationCount: this.getItems.length },
|
|
182
172
|
error instanceof Error ? error : void 0
|
|
183
173
|
);
|
|
184
174
|
}
|
|
@@ -230,7 +220,10 @@ var BatchBuilder = class {
|
|
|
230
220
|
errors.push(
|
|
231
221
|
new BatchError(
|
|
232
222
|
"Unexpected error during write operations",
|
|
223
|
+
ErrorCodes.BATCH_WRITE_FAILED,
|
|
233
224
|
"write",
|
|
225
|
+
[],
|
|
226
|
+
{},
|
|
234
227
|
error instanceof Error ? error : void 0
|
|
235
228
|
)
|
|
236
229
|
);
|
|
@@ -247,7 +240,10 @@ var BatchBuilder = class {
|
|
|
247
240
|
errors.push(
|
|
248
241
|
new BatchError(
|
|
249
242
|
"Unexpected error during read operations",
|
|
243
|
+
ErrorCodes.BATCH_GET_FAILED,
|
|
250
244
|
"read",
|
|
245
|
+
[],
|
|
246
|
+
{},
|
|
251
247
|
error instanceof Error ? error : void 0
|
|
252
248
|
)
|
|
253
249
|
);
|
|
@@ -314,16 +310,16 @@ var generateValueName = (params, value) => {
|
|
|
314
310
|
};
|
|
315
311
|
var validateCondition = (condition, requiresAttr = true, requiresValue = true) => {
|
|
316
312
|
if (requiresAttr && !condition.attr) {
|
|
317
|
-
throw
|
|
313
|
+
throw ExpressionErrors.missingAttribute(condition.type, condition);
|
|
318
314
|
}
|
|
319
315
|
if (requiresValue && condition.value === void 0) {
|
|
320
|
-
throw
|
|
316
|
+
throw ExpressionErrors.missingValue(condition.type, condition);
|
|
321
317
|
}
|
|
322
318
|
};
|
|
323
319
|
var buildComparisonExpression = (condition, operator, params) => {
|
|
324
320
|
validateCondition(condition);
|
|
325
321
|
if (!condition.attr) {
|
|
326
|
-
throw
|
|
322
|
+
throw ExpressionErrors.missingAttribute(condition.type, condition);
|
|
327
323
|
}
|
|
328
324
|
const attrName = generateAttributeName(params, condition.attr);
|
|
329
325
|
const valueName = generateValueName(params, condition.value);
|
|
@@ -332,10 +328,14 @@ var buildComparisonExpression = (condition, operator, params) => {
|
|
|
332
328
|
var buildBetweenExpression = (condition, params) => {
|
|
333
329
|
validateCondition(condition);
|
|
334
330
|
if (!condition.attr) {
|
|
335
|
-
throw
|
|
331
|
+
throw ExpressionErrors.missingAttribute(condition.type, condition);
|
|
336
332
|
}
|
|
337
333
|
if (!Array.isArray(condition.value) || condition.value.length !== 2) {
|
|
338
|
-
throw
|
|
334
|
+
throw ExpressionErrors.invalidCondition(
|
|
335
|
+
condition.type,
|
|
336
|
+
condition,
|
|
337
|
+
"Provide an array with exactly two values: [lowerBound, upperBound]"
|
|
338
|
+
);
|
|
339
339
|
}
|
|
340
340
|
const attrName = generateAttributeName(params, condition.attr);
|
|
341
341
|
const lowerName = generateValueName(params, condition.value[0]);
|
|
@@ -345,13 +345,17 @@ var buildBetweenExpression = (condition, params) => {
|
|
|
345
345
|
var buildInExpression = (condition, params) => {
|
|
346
346
|
validateCondition(condition);
|
|
347
347
|
if (!condition.attr) {
|
|
348
|
-
throw
|
|
348
|
+
throw ExpressionErrors.missingAttribute(condition.type, condition);
|
|
349
349
|
}
|
|
350
350
|
if (!Array.isArray(condition.value) || condition.value.length === 0) {
|
|
351
|
-
throw
|
|
351
|
+
throw ExpressionErrors.emptyArray(condition.type, condition.value);
|
|
352
352
|
}
|
|
353
353
|
if (condition.value.length > 100) {
|
|
354
|
-
throw
|
|
354
|
+
throw ExpressionErrors.invalidCondition(
|
|
355
|
+
condition.type,
|
|
356
|
+
condition,
|
|
357
|
+
"Split your query into multiple operations or use a different condition type"
|
|
358
|
+
);
|
|
355
359
|
}
|
|
356
360
|
const attrName = generateAttributeName(params, condition.attr);
|
|
357
361
|
const valueNames = condition.value.map((value) => generateValueName(params, value));
|
|
@@ -360,7 +364,7 @@ var buildInExpression = (condition, params) => {
|
|
|
360
364
|
var buildFunctionExpression = (functionName, condition, params) => {
|
|
361
365
|
validateCondition(condition);
|
|
362
366
|
if (!condition.attr) {
|
|
363
|
-
throw
|
|
367
|
+
throw ExpressionErrors.missingAttribute(condition.type, condition);
|
|
364
368
|
}
|
|
365
369
|
const attrName = generateAttributeName(params, condition.attr);
|
|
366
370
|
const valueName = generateValueName(params, condition.value);
|
|
@@ -369,66 +373,65 @@ var buildFunctionExpression = (functionName, condition, params) => {
|
|
|
369
373
|
var buildAttributeFunction = (functionName, condition, params) => {
|
|
370
374
|
validateCondition(condition, true, false);
|
|
371
375
|
if (!condition.attr) {
|
|
372
|
-
throw
|
|
376
|
+
throw ExpressionErrors.missingAttribute(condition.type, condition);
|
|
373
377
|
}
|
|
374
378
|
const attrName = generateAttributeName(params, condition.attr);
|
|
375
379
|
return `${functionName}(${attrName})`;
|
|
376
380
|
};
|
|
377
381
|
var buildLogicalExpression = (operator, conditions, params) => {
|
|
378
382
|
if (!conditions || conditions.length === 0) {
|
|
379
|
-
throw
|
|
383
|
+
throw ExpressionErrors.emptyArray(operator, conditions);
|
|
380
384
|
}
|
|
381
385
|
const expressions = conditions.map((c) => buildExpression(c, params));
|
|
382
386
|
return `(${expressions.join(` ${operator} `)})`;
|
|
383
387
|
};
|
|
384
388
|
var buildExpression = (condition, params) => {
|
|
385
389
|
if (!condition) return "";
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
or: () => {
|
|
407
|
-
if (!condition.conditions) {
|
|
408
|
-
throw new Error("Conditions array is required for OR operator");
|
|
409
|
-
}
|
|
410
|
-
return buildLogicalExpression("OR", condition.conditions, params);
|
|
411
|
-
},
|
|
412
|
-
not: () => {
|
|
413
|
-
if (!condition.condition) {
|
|
414
|
-
throw new Error("Condition is required for NOT operator");
|
|
415
|
-
}
|
|
416
|
-
return `NOT (${buildExpression(condition.condition, params)})`;
|
|
390
|
+
const expressionBuilders = {
|
|
391
|
+
eq: () => buildComparisonExpression(condition, "=", params),
|
|
392
|
+
ne: () => buildComparisonExpression(condition, "<>", params),
|
|
393
|
+
lt: () => buildComparisonExpression(condition, "<", params),
|
|
394
|
+
lte: () => buildComparisonExpression(condition, "<=", params),
|
|
395
|
+
gt: () => buildComparisonExpression(condition, ">", params),
|
|
396
|
+
gte: () => buildComparisonExpression(condition, ">=", params),
|
|
397
|
+
between: () => buildBetweenExpression(condition, params),
|
|
398
|
+
in: () => buildInExpression(condition, params),
|
|
399
|
+
beginsWith: () => buildFunctionExpression("begins_with", condition, params),
|
|
400
|
+
contains: () => buildFunctionExpression("contains", condition, params),
|
|
401
|
+
attributeExists: () => buildAttributeFunction("attribute_exists", condition, params),
|
|
402
|
+
attributeNotExists: () => buildAttributeFunction("attribute_not_exists", condition, params),
|
|
403
|
+
and: () => {
|
|
404
|
+
if (!condition.conditions) {
|
|
405
|
+
throw ExpressionErrors.invalidCondition(
|
|
406
|
+
condition.type,
|
|
407
|
+
condition,
|
|
408
|
+
"Provide an array of conditions to combine with AND"
|
|
409
|
+
);
|
|
417
410
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
411
|
+
return buildLogicalExpression("AND", condition.conditions, params);
|
|
412
|
+
},
|
|
413
|
+
or: () => {
|
|
414
|
+
if (!condition.conditions) {
|
|
415
|
+
throw ExpressionErrors.invalidCondition(
|
|
416
|
+
condition.type,
|
|
417
|
+
condition,
|
|
418
|
+
"Provide an array of conditions to combine with OR"
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
return buildLogicalExpression("OR", condition.conditions, params);
|
|
422
|
+
},
|
|
423
|
+
not: () => {
|
|
424
|
+
if (!condition.condition) {
|
|
425
|
+
throw ExpressionErrors.invalidCondition(condition.type, condition, "Provide a condition to negate with NOT");
|
|
426
|
+
}
|
|
427
|
+
return `NOT (${buildExpression(condition.condition, params)})`;
|
|
429
428
|
}
|
|
430
|
-
|
|
429
|
+
};
|
|
430
|
+
const builder = expressionBuilders[condition.type];
|
|
431
|
+
if (!builder) {
|
|
432
|
+
throw ExpressionErrors.unknownType(condition.type, condition);
|
|
431
433
|
}
|
|
434
|
+
return builder();
|
|
432
435
|
};
|
|
433
436
|
var prepareExpressionParams = (condition) => {
|
|
434
437
|
if (!condition) return {};
|
|
@@ -1755,7 +1758,7 @@ var TransactionBuilder = class {
|
|
|
1755
1758
|
const pkValue = newItem[pkName];
|
|
1756
1759
|
const skValue = skName ? newItem[skName] : void 0;
|
|
1757
1760
|
if (!pkValue) {
|
|
1758
|
-
throw
|
|
1761
|
+
throw ConfigurationErrors.primaryKeyMissing(tableName, pkName, newItem);
|
|
1759
1762
|
}
|
|
1760
1763
|
const duplicateItem = this.items.find((item) => {
|
|
1761
1764
|
let itemKey;
|
|
@@ -1787,8 +1790,10 @@ var TransactionBuilder = class {
|
|
|
1787
1790
|
return false;
|
|
1788
1791
|
});
|
|
1789
1792
|
if (duplicateItem) {
|
|
1790
|
-
throw
|
|
1791
|
-
|
|
1793
|
+
throw TransactionErrors.duplicateItem(
|
|
1794
|
+
tableName,
|
|
1795
|
+
{ name: pkName, value: pkValue },
|
|
1796
|
+
skName ? { name: skName, value: skValue } : void 0
|
|
1792
1797
|
);
|
|
1793
1798
|
}
|
|
1794
1799
|
}
|
|
@@ -1798,7 +1803,7 @@ var TransactionBuilder = class {
|
|
|
1798
1803
|
};
|
|
1799
1804
|
if (this.indexConfig.sortKey) {
|
|
1800
1805
|
if (key.sk === void 0) {
|
|
1801
|
-
throw
|
|
1806
|
+
throw ConfigurationErrors.sortKeyRequired("", this.indexConfig.partitionKey, this.indexConfig.sortKey);
|
|
1802
1807
|
}
|
|
1803
1808
|
keyCondition[this.indexConfig.sortKey] = key.sk;
|
|
1804
1809
|
}
|
|
@@ -2172,7 +2177,7 @@ var TransactionBuilder = class {
|
|
|
2172
2177
|
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2173
2178
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2174
2179
|
if (!expression) {
|
|
2175
|
-
throw
|
|
2180
|
+
throw ConfigurationErrors.conditionGenerationFailed(condition);
|
|
2176
2181
|
}
|
|
2177
2182
|
const transactionItem = {
|
|
2178
2183
|
type: "ConditionCheck",
|
|
@@ -2326,7 +2331,7 @@ var TransactionBuilder = class {
|
|
|
2326
2331
|
*/
|
|
2327
2332
|
async execute() {
|
|
2328
2333
|
if (this.items.length === 0) {
|
|
2329
|
-
throw
|
|
2334
|
+
throw TransactionErrors.transactionEmpty();
|
|
2330
2335
|
}
|
|
2331
2336
|
const transactItems = this.items.map((item) => {
|
|
2332
2337
|
switch (item.type) {
|
|
@@ -2373,7 +2378,7 @@ var TransactionBuilder = class {
|
|
|
2373
2378
|
};
|
|
2374
2379
|
default: {
|
|
2375
2380
|
const exhaustiveCheck = item;
|
|
2376
|
-
throw
|
|
2381
|
+
throw TransactionErrors.unsupportedType(exhaustiveCheck);
|
|
2377
2382
|
}
|
|
2378
2383
|
}
|
|
2379
2384
|
});
|
|
@@ -2386,9 +2391,7 @@ var TransactionBuilder = class {
|
|
|
2386
2391
|
try {
|
|
2387
2392
|
await this.executor(params);
|
|
2388
2393
|
} catch (error) {
|
|
2389
|
-
|
|
2390
|
-
console.error("Error executing transaction:", error);
|
|
2391
|
-
throw error;
|
|
2394
|
+
throw TransactionErrors.transactionFailed(this.items.length, {}, error instanceof Error ? error : void 0);
|
|
2392
2395
|
}
|
|
2393
2396
|
}
|
|
2394
2397
|
};
|
|
@@ -2410,6 +2413,9 @@ var UpdateBuilder = class {
|
|
|
2410
2413
|
set(valuesOrPath, value) {
|
|
2411
2414
|
if (typeof valuesOrPath === "object") {
|
|
2412
2415
|
for (const [key, value2] of Object.entries(valuesOrPath)) {
|
|
2416
|
+
if (value2 === void 0) {
|
|
2417
|
+
throw ValidationErrors.undefinedValue(key, this.tableName, this.key);
|
|
2418
|
+
}
|
|
2413
2419
|
this.updates.push({
|
|
2414
2420
|
type: "SET",
|
|
2415
2421
|
path: key,
|
|
@@ -2417,6 +2423,9 @@ var UpdateBuilder = class {
|
|
|
2417
2423
|
});
|
|
2418
2424
|
}
|
|
2419
2425
|
} else {
|
|
2426
|
+
if (value === void 0) {
|
|
2427
|
+
throw ValidationErrors.undefinedValue(valuesOrPath, this.tableName, this.key);
|
|
2428
|
+
}
|
|
2420
2429
|
this.updates.push({
|
|
2421
2430
|
type: "SET",
|
|
2422
2431
|
path: valuesOrPath,
|
|
@@ -2472,6 +2481,9 @@ var UpdateBuilder = class {
|
|
|
2472
2481
|
* @returns The builder instance for method chaining
|
|
2473
2482
|
*/
|
|
2474
2483
|
add(path, value) {
|
|
2484
|
+
if (value === void 0) {
|
|
2485
|
+
throw ValidationErrors.undefinedValue(path, this.tableName, this.key);
|
|
2486
|
+
}
|
|
2475
2487
|
this.updates.push({
|
|
2476
2488
|
type: "ADD",
|
|
2477
2489
|
path,
|
|
@@ -2508,6 +2520,9 @@ var UpdateBuilder = class {
|
|
|
2508
2520
|
* @returns The builder instance for method chaining
|
|
2509
2521
|
*/
|
|
2510
2522
|
deleteElementsFromSet(path, value) {
|
|
2523
|
+
if (value === void 0) {
|
|
2524
|
+
throw ValidationErrors.undefinedValue(path, this.tableName, this.key);
|
|
2525
|
+
}
|
|
2511
2526
|
let valuesToDelete;
|
|
2512
2527
|
if (Array.isArray(value)) {
|
|
2513
2528
|
valuesToDelete = new Set(value);
|
|
@@ -2626,7 +2641,7 @@ var UpdateBuilder = class {
|
|
|
2626
2641
|
*/
|
|
2627
2642
|
toDynamoCommand() {
|
|
2628
2643
|
if (this.updates.length === 0) {
|
|
2629
|
-
throw
|
|
2644
|
+
throw ValidationErrors.noUpdateActions(this.tableName, this.key);
|
|
2630
2645
|
}
|
|
2631
2646
|
const expressionParams = {
|
|
2632
2647
|
expressionAttributeNames: {},
|
|
@@ -2900,11 +2915,11 @@ var ConditionCheckBuilder = class {
|
|
|
2900
2915
|
*/
|
|
2901
2916
|
toDynamoCommand() {
|
|
2902
2917
|
if (!this.conditionExpression) {
|
|
2903
|
-
throw
|
|
2918
|
+
throw ValidationErrors.conditionRequired(this.tableName, this.key);
|
|
2904
2919
|
}
|
|
2905
2920
|
const { expression, names, values } = prepareExpressionParams(this.conditionExpression);
|
|
2906
2921
|
if (!expression) {
|
|
2907
|
-
throw
|
|
2922
|
+
throw ConfigurationErrors.conditionGenerationFailed(this.conditionExpression);
|
|
2908
2923
|
}
|
|
2909
2924
|
return {
|
|
2910
2925
|
tableName: this.tableName,
|
|
@@ -2936,7 +2951,7 @@ var ConditionCheckBuilder = class {
|
|
|
2936
2951
|
*/
|
|
2937
2952
|
withTransaction(transaction) {
|
|
2938
2953
|
if (!this.conditionExpression) {
|
|
2939
|
-
throw
|
|
2954
|
+
throw ValidationErrors.conditionRequired(this.tableName, this.key);
|
|
2940
2955
|
}
|
|
2941
2956
|
const command = this.toDynamoCommand();
|
|
2942
2957
|
transaction.conditionCheckWithCommand(command);
|
|
@@ -3197,4 +3212,4 @@ var ScanBuilder = class _ScanBuilder extends FilterBuilder {
|
|
|
3197
3212
|
}
|
|
3198
3213
|
};
|
|
3199
3214
|
|
|
3200
|
-
export { BatchBuilder,
|
|
3215
|
+
export { BatchBuilder, ConditionCheckBuilder, DeleteBuilder, FilterBuilder, GetBuilder, Paginator, PutBuilder, QueryBuilder, ResultIterator, ScanBuilder, TransactionBuilder, UpdateBuilder, buildExpression, generateAttributeName };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkAHF4H42Q_cjs = require('./chunk-AHF4H42Q.cjs');
|
|
4
|
+
var chunkELULXDSB_cjs = require('./chunk-ELULXDSB.cjs');
|
|
4
5
|
var chunk7UJJ7JXM_cjs = require('./chunk-7UJJ7JXM.cjs');
|
|
5
6
|
|
|
6
7
|
// src/utils/chunk-array.ts
|
|
7
8
|
function* chunkArray(array, size) {
|
|
8
9
|
if (size <= 0) {
|
|
9
|
-
throw
|
|
10
|
+
throw chunkELULXDSB_cjs.ConfigurationErrors.invalidChunkSize(size);
|
|
10
11
|
}
|
|
11
12
|
for (let i = 0; i < array.length; i += size) {
|
|
12
13
|
yield array.slice(i, i + size);
|
|
@@ -42,7 +43,7 @@ var Table = class {
|
|
|
42
43
|
const primaryCondition = { [this.partitionKey]: keyCondition.pk };
|
|
43
44
|
if (this.sortKey) {
|
|
44
45
|
if (!keyCondition.sk) {
|
|
45
|
-
throw
|
|
46
|
+
throw chunkELULXDSB_cjs.ConfigurationErrors.sortKeyRequired(this.tableName, this.partitionKey, this.sortKey);
|
|
46
47
|
}
|
|
47
48
|
primaryCondition[this.sortKey] = keyCondition.sk;
|
|
48
49
|
}
|
|
@@ -96,11 +97,10 @@ var Table = class {
|
|
|
96
97
|
item: result.Item ? result.Item : void 0
|
|
97
98
|
};
|
|
98
99
|
} catch (error) {
|
|
99
|
-
|
|
100
|
-
throw error;
|
|
100
|
+
throw chunkELULXDSB_cjs.OperationErrors.getFailed(params.tableName, keyCondition, error instanceof Error ? error : void 0);
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
|
-
return new
|
|
103
|
+
return new chunkAHF4H42Q_cjs.GetBuilder(executor, keyCondition, this.tableName);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Updates an item in the table
|
|
@@ -137,11 +137,10 @@ var Table = class {
|
|
|
137
137
|
}
|
|
138
138
|
return result.Attributes;
|
|
139
139
|
} catch (error) {
|
|
140
|
-
|
|
141
|
-
throw error;
|
|
140
|
+
throw chunkELULXDSB_cjs.OperationErrors.putFailed(params.tableName, params.item, error instanceof Error ? error : void 0);
|
|
142
141
|
}
|
|
143
142
|
};
|
|
144
|
-
return new
|
|
143
|
+
return new chunkAHF4H42Q_cjs.PutBuilder(executor, item, this.tableName);
|
|
145
144
|
}
|
|
146
145
|
/**
|
|
147
146
|
* Creates a query builder for complex queries
|
|
@@ -153,7 +152,7 @@ var Table = class {
|
|
|
153
152
|
let keyConditionExpression = chunk7UJJ7JXM_cjs.eq(pkAttributeName, keyCondition.pk);
|
|
154
153
|
if (keyCondition.sk) {
|
|
155
154
|
if (!skAttributeName) {
|
|
156
|
-
throw
|
|
155
|
+
throw chunkELULXDSB_cjs.ConfigurationErrors.sortKeyNotDefined(this.tableName, pkAttributeName);
|
|
157
156
|
}
|
|
158
157
|
const keyConditionOperator = {
|
|
159
158
|
eq: (value) => chunk7UJJ7JXM_cjs.eq(skAttributeName, value),
|
|
@@ -174,7 +173,7 @@ var Table = class {
|
|
|
174
173
|
const gsiName = String(options.indexName);
|
|
175
174
|
const gsi = this.gsis[gsiName];
|
|
176
175
|
if (!gsi) {
|
|
177
|
-
throw
|
|
176
|
+
throw chunkELULXDSB_cjs.ConfigurationErrors.gsiNotFound(gsiName, this.tableName, Object.keys(this.gsis));
|
|
178
177
|
}
|
|
179
178
|
const gsiPkAttributeName = gsi.partitionKey;
|
|
180
179
|
const gsiSkAttributeName = gsi.sortKey;
|
|
@@ -203,7 +202,7 @@ var Table = class {
|
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
204
|
if (!pkValue) {
|
|
206
|
-
throw
|
|
205
|
+
throw chunkELULXDSB_cjs.ConfigurationErrors.pkExtractionFailed(this.tableName, options.indexName, originalKeyCondition);
|
|
207
206
|
}
|
|
208
207
|
let gsiKeyCondition = chunk7UJJ7JXM_cjs.eq(gsiPkAttributeName, pkValue);
|
|
209
208
|
if (skValue && gsiSkAttributeName) {
|
|
@@ -226,12 +225,12 @@ var Table = class {
|
|
|
226
225
|
expressionAttributeValues: {},
|
|
227
226
|
valueCounter: { count: 0 }
|
|
228
227
|
};
|
|
229
|
-
const keyConditionExpression2 =
|
|
228
|
+
const keyConditionExpression2 = chunkAHF4H42Q_cjs.buildExpression(finalKeyCondition, expressionParams);
|
|
230
229
|
let filterExpression;
|
|
231
230
|
if (options.filter) {
|
|
232
|
-
filterExpression =
|
|
231
|
+
filterExpression = chunkAHF4H42Q_cjs.buildExpression(options.filter, expressionParams);
|
|
233
232
|
}
|
|
234
|
-
const projectionExpression = options.projection?.map((p) =>
|
|
233
|
+
const projectionExpression = options.projection?.map((p) => chunkAHF4H42Q_cjs.generateAttributeName(expressionParams, p)).join(", ");
|
|
235
234
|
const { expressionAttributeNames, expressionAttributeValues } = expressionParams;
|
|
236
235
|
const { indexName, limit, consistentRead, scanIndexForward, lastEvaluatedKey } = options;
|
|
237
236
|
const params = {
|
|
@@ -254,12 +253,14 @@ var Table = class {
|
|
|
254
253
|
lastEvaluatedKey: result.LastEvaluatedKey
|
|
255
254
|
};
|
|
256
255
|
} catch (error) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
throw chunkELULXDSB_cjs.OperationErrors.queryFailed(
|
|
257
|
+
this.tableName,
|
|
258
|
+
{ indexName, keyConditionExpression: keyConditionExpression2, filterExpression },
|
|
259
|
+
error instanceof Error ? error : void 0
|
|
260
|
+
);
|
|
260
261
|
}
|
|
261
262
|
};
|
|
262
|
-
return new
|
|
263
|
+
return new chunkAHF4H42Q_cjs.QueryBuilder(executor, keyConditionExpression);
|
|
263
264
|
}
|
|
264
265
|
/**
|
|
265
266
|
* Creates a scan builder for scanning the entire table
|
|
@@ -279,9 +280,9 @@ var Table = class {
|
|
|
279
280
|
};
|
|
280
281
|
let filterExpression;
|
|
281
282
|
if (options.filter) {
|
|
282
|
-
filterExpression =
|
|
283
|
+
filterExpression = chunkAHF4H42Q_cjs.buildExpression(options.filter, expressionParams);
|
|
283
284
|
}
|
|
284
|
-
const projectionExpression = options.projection?.map((p) =>
|
|
285
|
+
const projectionExpression = options.projection?.map((p) => chunkAHF4H42Q_cjs.generateAttributeName(expressionParams, p)).join(", ");
|
|
285
286
|
const { expressionAttributeNames, expressionAttributeValues } = expressionParams;
|
|
286
287
|
const { indexName, limit, consistentRead, lastEvaluatedKey } = options;
|
|
287
288
|
const params = {
|
|
@@ -302,12 +303,14 @@ var Table = class {
|
|
|
302
303
|
lastEvaluatedKey: result.LastEvaluatedKey
|
|
303
304
|
};
|
|
304
305
|
} catch (error) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
throw chunkELULXDSB_cjs.OperationErrors.scanFailed(
|
|
307
|
+
this.tableName,
|
|
308
|
+
{ indexName: options.indexName, filterExpression },
|
|
309
|
+
error instanceof Error ? error : void 0
|
|
310
|
+
);
|
|
308
311
|
}
|
|
309
312
|
};
|
|
310
|
-
return new
|
|
313
|
+
return new chunkAHF4H42Q_cjs.ScanBuilder(executor);
|
|
311
314
|
}
|
|
312
315
|
delete(keyCondition) {
|
|
313
316
|
const executor = async (params) => {
|
|
@@ -324,11 +327,10 @@ var Table = class {
|
|
|
324
327
|
item: result.Attributes
|
|
325
328
|
};
|
|
326
329
|
} catch (error) {
|
|
327
|
-
|
|
328
|
-
throw error;
|
|
330
|
+
throw chunkELULXDSB_cjs.OperationErrors.deleteFailed(params.tableName, keyCondition, error instanceof Error ? error : void 0);
|
|
329
331
|
}
|
|
330
332
|
};
|
|
331
|
-
return new
|
|
333
|
+
return new chunkAHF4H42Q_cjs.DeleteBuilder(executor, this.tableName, keyCondition);
|
|
332
334
|
}
|
|
333
335
|
/**
|
|
334
336
|
* Updates an item in the table
|
|
@@ -352,11 +354,10 @@ var Table = class {
|
|
|
352
354
|
item: result.Attributes
|
|
353
355
|
};
|
|
354
356
|
} catch (error) {
|
|
355
|
-
|
|
356
|
-
throw error;
|
|
357
|
+
throw chunkELULXDSB_cjs.OperationErrors.updateFailed(params.tableName, keyCondition, error instanceof Error ? error : void 0);
|
|
357
358
|
}
|
|
358
359
|
};
|
|
359
|
-
return new
|
|
360
|
+
return new chunkAHF4H42Q_cjs.UpdateBuilder(executor, this.tableName, keyCondition);
|
|
360
361
|
}
|
|
361
362
|
/**
|
|
362
363
|
* Creates a transaction builder for performing multiple operations atomically
|
|
@@ -365,7 +366,7 @@ var Table = class {
|
|
|
365
366
|
const executor = async (params) => {
|
|
366
367
|
await this.dynamoClient.transactWrite(params);
|
|
367
368
|
};
|
|
368
|
-
return new
|
|
369
|
+
return new chunkAHF4H42Q_cjs.TransactionBuilder(executor, {
|
|
369
370
|
partitionKey: this.partitionKey,
|
|
370
371
|
sortKey: this.sortKey
|
|
371
372
|
});
|
|
@@ -412,7 +413,7 @@ var Table = class {
|
|
|
412
413
|
const batchGetExecutor = async (keys) => {
|
|
413
414
|
return this.batchGet(keys);
|
|
414
415
|
};
|
|
415
|
-
return new
|
|
416
|
+
return new chunkAHF4H42Q_cjs.BatchBuilder(batchWriteExecutor, batchGetExecutor, {
|
|
416
417
|
partitionKey: this.partitionKey,
|
|
417
418
|
sortKey: this.sortKey
|
|
418
419
|
});
|
|
@@ -428,7 +429,7 @@ var Table = class {
|
|
|
428
429
|
const transactionExecutor = async (params) => {
|
|
429
430
|
await this.dynamoClient.transactWrite(params);
|
|
430
431
|
};
|
|
431
|
-
const transaction = new
|
|
432
|
+
const transaction = new chunkAHF4H42Q_cjs.TransactionBuilder(transactionExecutor, {
|
|
432
433
|
partitionKey: this.partitionKey,
|
|
433
434
|
sortKey: this.sortKey
|
|
434
435
|
});
|
|
@@ -448,7 +449,7 @@ var Table = class {
|
|
|
448
449
|
* For example, you are updating a record and you want to ensure that another record exists and/or has a specific value before proceeding.
|
|
449
450
|
*/
|
|
450
451
|
conditionCheck(keyCondition) {
|
|
451
|
-
return new
|
|
452
|
+
return new chunkAHF4H42Q_cjs.ConditionCheckBuilder(this.tableName, keyCondition);
|
|
452
453
|
}
|
|
453
454
|
/**
|
|
454
455
|
* Performs a batch get operation to retrieve multiple items at once
|
|
@@ -485,8 +486,11 @@ var Table = class {
|
|
|
485
486
|
allUnprocessedKeys.push(...unprocessedKeys);
|
|
486
487
|
}
|
|
487
488
|
} catch (error) {
|
|
488
|
-
|
|
489
|
-
|
|
489
|
+
throw chunkELULXDSB_cjs.OperationErrors.batchGetFailed(
|
|
490
|
+
this.tableName,
|
|
491
|
+
{ requestedKeys: keys.length },
|
|
492
|
+
error instanceof Error ? error : void 0
|
|
493
|
+
);
|
|
490
494
|
}
|
|
491
495
|
}
|
|
492
496
|
return {
|
|
@@ -547,8 +551,11 @@ var Table = class {
|
|
|
547
551
|
allUnprocessedItems.push(...unprocessedItems);
|
|
548
552
|
}
|
|
549
553
|
} catch (error) {
|
|
550
|
-
|
|
551
|
-
|
|
554
|
+
throw chunkELULXDSB_cjs.OperationErrors.batchWriteFailed(
|
|
555
|
+
this.tableName,
|
|
556
|
+
{ requestedOperations: operations.length },
|
|
557
|
+
error instanceof Error ? error : void 0
|
|
558
|
+
);
|
|
552
559
|
}
|
|
553
560
|
}
|
|
554
561
|
return {
|