dyno-table 2.3.3 → 2.5.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/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-XYL43FDX.cjs → chunk-3DR6VOFW.cjs} +233 -101
- package/dist/{chunk-EODPMYPE.js → chunk-42LH2UEM.js} +45 -26
- package/dist/chunk-ELULXDSB.cjs +564 -0
- package/dist/chunk-FF7FYGDH.js +543 -0
- package/dist/{chunk-DTFJJASK.js → chunk-NYJGW3XH.js} +230 -96
- package/dist/{chunk-M5Y6JQJN.js → chunk-U6MQGB6Y.js} +239 -39
- package/dist/{chunk-KA3VPIPS.cjs → chunk-ZUBCW3LA.cjs} +58 -39
- package/dist/{chunk-3J5DY7KG.cjs → chunk-ZXM6LPRV.cjs} +259 -38
- 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 +2 -2
- package/dist/entity.d.ts +2 -2
- package/dist/entity.js +2 -1
- package/dist/{index-2cbm07Bi.d.ts → index-C9KOQdSC.d.ts} +258 -13
- package/dist/{index-DlN8G9hd.d.cts → index-Ca76PpXj.d.cts} +258 -13
- 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 +3 -2
- package/dist/table.d.ts +3 -2
- package/dist/table.js +3 -2
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { GetBuilder, PutBuilder, QueryBuilder, ScanBuilder, DeleteBuilder, UpdateBuilder, TransactionBuilder, BatchBuilder, ConditionCheckBuilder, buildExpression, generateAttributeName
|
|
1
|
+
import { GetBuilder, PutBuilder, QueryBuilder, ScanBuilder, DeleteBuilder, UpdateBuilder, TransactionBuilder, BatchBuilder, ConditionCheckBuilder, buildExpression, generateAttributeName } from './chunk-NYJGW3XH.js';
|
|
2
|
+
import { ConfigurationErrors, OperationErrors } from './chunk-FF7FYGDH.js';
|
|
2
3
|
import { eq, and, beginsWith, between, gte, gt, lte, lt } from './chunk-2WIBY7PZ.js';
|
|
3
4
|
|
|
4
5
|
// src/utils/chunk-array.ts
|
|
5
6
|
function* chunkArray(array, size) {
|
|
6
7
|
if (size <= 0) {
|
|
7
|
-
throw
|
|
8
|
+
throw ConfigurationErrors.invalidChunkSize(size);
|
|
8
9
|
}
|
|
9
10
|
for (let i = 0; i < array.length; i += size) {
|
|
10
11
|
yield array.slice(i, i + size);
|
|
@@ -36,11 +37,21 @@ var Table = class {
|
|
|
36
37
|
this.sortKey = config.indexes.sortKey;
|
|
37
38
|
this.gsis = config.indexes.gsis || {};
|
|
38
39
|
}
|
|
40
|
+
getIndexAttributeNames() {
|
|
41
|
+
const names = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const gsi of Object.values(this.gsis)) {
|
|
43
|
+
names.add(gsi.partitionKey);
|
|
44
|
+
if (gsi.sortKey) {
|
|
45
|
+
names.add(gsi.sortKey);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return Array.from(names);
|
|
49
|
+
}
|
|
39
50
|
createKeyForPrimaryIndex(keyCondition) {
|
|
40
51
|
const primaryCondition = { [this.partitionKey]: keyCondition.pk };
|
|
41
52
|
if (this.sortKey) {
|
|
42
53
|
if (!keyCondition.sk) {
|
|
43
|
-
throw
|
|
54
|
+
throw ConfigurationErrors.sortKeyRequired(this.tableName, this.partitionKey, this.sortKey);
|
|
44
55
|
}
|
|
45
56
|
primaryCondition[this.sortKey] = keyCondition.sk;
|
|
46
57
|
}
|
|
@@ -81,6 +92,7 @@ var Table = class {
|
|
|
81
92
|
return this.put(item).condition((op) => op.attributeNotExists(this.partitionKey)).returnValues("INPUT");
|
|
82
93
|
}
|
|
83
94
|
get(keyCondition) {
|
|
95
|
+
const indexAttributeNames = this.getIndexAttributeNames();
|
|
84
96
|
const executor = async (params) => {
|
|
85
97
|
try {
|
|
86
98
|
const result = await this.dynamoClient.get({
|
|
@@ -94,11 +106,10 @@ var Table = class {
|
|
|
94
106
|
item: result.Item ? result.Item : void 0
|
|
95
107
|
};
|
|
96
108
|
} catch (error) {
|
|
97
|
-
|
|
98
|
-
throw error;
|
|
109
|
+
throw OperationErrors.getFailed(params.tableName, keyCondition, error instanceof Error ? error : void 0);
|
|
99
110
|
}
|
|
100
111
|
};
|
|
101
|
-
return new GetBuilder(executor, keyCondition, this.tableName);
|
|
112
|
+
return new GetBuilder(executor, keyCondition, this.tableName, indexAttributeNames);
|
|
102
113
|
}
|
|
103
114
|
/**
|
|
104
115
|
* Updates an item in the table
|
|
@@ -135,8 +146,7 @@ var Table = class {
|
|
|
135
146
|
}
|
|
136
147
|
return result.Attributes;
|
|
137
148
|
} catch (error) {
|
|
138
|
-
|
|
139
|
-
throw error;
|
|
149
|
+
throw OperationErrors.putFailed(params.tableName, params.item, error instanceof Error ? error : void 0);
|
|
140
150
|
}
|
|
141
151
|
};
|
|
142
152
|
return new PutBuilder(executor, item, this.tableName);
|
|
@@ -146,12 +156,13 @@ var Table = class {
|
|
|
146
156
|
* If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
|
|
147
157
|
*/
|
|
148
158
|
query(keyCondition) {
|
|
159
|
+
const indexAttributeNames = this.getIndexAttributeNames();
|
|
149
160
|
const pkAttributeName = this.partitionKey;
|
|
150
161
|
const skAttributeName = this.sortKey;
|
|
151
162
|
let keyConditionExpression = eq(pkAttributeName, keyCondition.pk);
|
|
152
163
|
if (keyCondition.sk) {
|
|
153
164
|
if (!skAttributeName) {
|
|
154
|
-
throw
|
|
165
|
+
throw ConfigurationErrors.sortKeyNotDefined(this.tableName, pkAttributeName);
|
|
155
166
|
}
|
|
156
167
|
const keyConditionOperator = {
|
|
157
168
|
eq: (value) => eq(skAttributeName, value),
|
|
@@ -172,7 +183,7 @@ var Table = class {
|
|
|
172
183
|
const gsiName = String(options.indexName);
|
|
173
184
|
const gsi = this.gsis[gsiName];
|
|
174
185
|
if (!gsi) {
|
|
175
|
-
throw
|
|
186
|
+
throw ConfigurationErrors.gsiNotFound(gsiName, this.tableName, Object.keys(this.gsis));
|
|
176
187
|
}
|
|
177
188
|
const gsiPkAttributeName = gsi.partitionKey;
|
|
178
189
|
const gsiSkAttributeName = gsi.sortKey;
|
|
@@ -201,7 +212,7 @@ var Table = class {
|
|
|
201
212
|
}
|
|
202
213
|
}
|
|
203
214
|
if (!pkValue) {
|
|
204
|
-
throw
|
|
215
|
+
throw ConfigurationErrors.pkExtractionFailed(this.tableName, options.indexName, originalKeyCondition);
|
|
205
216
|
}
|
|
206
217
|
let gsiKeyCondition = eq(gsiPkAttributeName, pkValue);
|
|
207
218
|
if (skValue && gsiSkAttributeName) {
|
|
@@ -252,12 +263,14 @@ var Table = class {
|
|
|
252
263
|
lastEvaluatedKey: result.LastEvaluatedKey
|
|
253
264
|
};
|
|
254
265
|
} catch (error) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
266
|
+
throw OperationErrors.queryFailed(
|
|
267
|
+
this.tableName,
|
|
268
|
+
{ indexName, keyConditionExpression: keyConditionExpression2, filterExpression },
|
|
269
|
+
error instanceof Error ? error : void 0
|
|
270
|
+
);
|
|
258
271
|
}
|
|
259
272
|
};
|
|
260
|
-
return new QueryBuilder(executor, keyConditionExpression);
|
|
273
|
+
return new QueryBuilder(executor, keyConditionExpression, indexAttributeNames);
|
|
261
274
|
}
|
|
262
275
|
/**
|
|
263
276
|
* Creates a scan builder for scanning the entire table
|
|
@@ -300,9 +313,11 @@ var Table = class {
|
|
|
300
313
|
lastEvaluatedKey: result.LastEvaluatedKey
|
|
301
314
|
};
|
|
302
315
|
} catch (error) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
316
|
+
throw OperationErrors.scanFailed(
|
|
317
|
+
this.tableName,
|
|
318
|
+
{ indexName: options.indexName, filterExpression },
|
|
319
|
+
error instanceof Error ? error : void 0
|
|
320
|
+
);
|
|
306
321
|
}
|
|
307
322
|
};
|
|
308
323
|
return new ScanBuilder(executor);
|
|
@@ -322,8 +337,7 @@ var Table = class {
|
|
|
322
337
|
item: result.Attributes
|
|
323
338
|
};
|
|
324
339
|
} catch (error) {
|
|
325
|
-
|
|
326
|
-
throw error;
|
|
340
|
+
throw OperationErrors.deleteFailed(params.tableName, keyCondition, error instanceof Error ? error : void 0);
|
|
327
341
|
}
|
|
328
342
|
};
|
|
329
343
|
return new DeleteBuilder(executor, this.tableName, keyCondition);
|
|
@@ -350,8 +364,7 @@ var Table = class {
|
|
|
350
364
|
item: result.Attributes
|
|
351
365
|
};
|
|
352
366
|
} catch (error) {
|
|
353
|
-
|
|
354
|
-
throw error;
|
|
367
|
+
throw OperationErrors.updateFailed(params.tableName, keyCondition, error instanceof Error ? error : void 0);
|
|
355
368
|
}
|
|
356
369
|
};
|
|
357
370
|
return new UpdateBuilder(executor, this.tableName, keyCondition);
|
|
@@ -483,8 +496,11 @@ var Table = class {
|
|
|
483
496
|
allUnprocessedKeys.push(...unprocessedKeys);
|
|
484
497
|
}
|
|
485
498
|
} catch (error) {
|
|
486
|
-
|
|
487
|
-
|
|
499
|
+
throw OperationErrors.batchGetFailed(
|
|
500
|
+
this.tableName,
|
|
501
|
+
{ requestedKeys: keys.length },
|
|
502
|
+
error instanceof Error ? error : void 0
|
|
503
|
+
);
|
|
488
504
|
}
|
|
489
505
|
}
|
|
490
506
|
return {
|
|
@@ -545,8 +561,11 @@ var Table = class {
|
|
|
545
561
|
allUnprocessedItems.push(...unprocessedItems);
|
|
546
562
|
}
|
|
547
563
|
} catch (error) {
|
|
548
|
-
|
|
549
|
-
|
|
564
|
+
throw OperationErrors.batchWriteFailed(
|
|
565
|
+
this.tableName,
|
|
566
|
+
{ requestedOperations: operations.length },
|
|
567
|
+
error instanceof Error ? error : void 0
|
|
568
|
+
);
|
|
550
569
|
}
|
|
551
570
|
}
|
|
552
571
|
return {
|