dinah 0.2.0 → 0.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.
- package/README.md +19 -15
- package/dist/cdk.cjs +33 -0
- package/dist/cdk.cjs.map +1 -0
- package/dist/cdk.d.cts +10 -0
- package/dist/cdk.d.cts.map +1 -0
- package/dist/cdk.d.mts +10 -0
- package/dist/cdk.d.mts.map +1 -0
- package/dist/cdk.mjs +30 -0
- package/dist/cdk.mjs.map +1 -0
- package/dist/index.cjs +121 -278
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -448
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -448
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +114 -245
- package/dist/index.mjs.map +1 -1
- package/dist/streams.cjs +1 -1
- package/dist/table-DBf8kWHl.d.cts +520 -0
- package/dist/table-DBf8kWHl.d.cts.map +1 -0
- package/dist/table-DqJt-sXI.d.mts +520 -0
- package/dist/table-DqJt-sXI.d.mts.map +1 -0
- package/dist/util-B4dDuxlC.mjs +77 -0
- package/dist/util-B4dDuxlC.mjs.map +1 -0
- package/dist/util-BOJ7V5_l.cjs +129 -0
- package/dist/util-BOJ7V5_l.cjs.map +1 -0
- package/package.json +16 -6
package/dist/index.cjs
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
2
|
+
const require_util = require("./util-BOJ7V5_l.cjs");
|
|
24
3
|
let _aws_sdk_client_dynamodb = require("@aws-sdk/client-dynamodb");
|
|
25
4
|
let _aws_sdk_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
|
|
26
|
-
_aws_sdk_lib_dynamodb = __toESM(_aws_sdk_lib_dynamodb);
|
|
5
|
+
_aws_sdk_lib_dynamodb = require_util.__toESM(_aws_sdk_lib_dynamodb);
|
|
27
6
|
let sift = require("sift");
|
|
28
|
-
sift = __toESM(sift);
|
|
29
|
-
let typebox = require("typebox");
|
|
30
|
-
typebox = __toESM(typebox);
|
|
7
|
+
sift = require_util.__toESM(sift);
|
|
31
8
|
//#region src/expression-builder.ts
|
|
32
9
|
const attrTypes = [
|
|
33
10
|
"S",
|
|
@@ -208,18 +185,22 @@ var ExpressionBuilder = class {
|
|
|
208
185
|
};
|
|
209
186
|
//#endregion
|
|
210
187
|
//#region src/repo.ts
|
|
211
|
-
var
|
|
212
|
-
table;
|
|
188
|
+
var AbstractRepo = class {
|
|
213
189
|
db;
|
|
214
|
-
constructor(
|
|
215
|
-
this.table = table;
|
|
190
|
+
constructor(db) {
|
|
216
191
|
this.db = db;
|
|
217
192
|
}
|
|
218
193
|
get tableName() {
|
|
219
194
|
return `${this.db.config?.tableNamePrefix ?? ""}${this.table.def.name}`;
|
|
220
195
|
}
|
|
221
|
-
get
|
|
222
|
-
return
|
|
196
|
+
get defaultPutData() {
|
|
197
|
+
return {};
|
|
198
|
+
}
|
|
199
|
+
get defaultUpdateData() {
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
transformItem(item) {
|
|
203
|
+
return item;
|
|
223
204
|
}
|
|
224
205
|
extractKey(item) {
|
|
225
206
|
const { partitionKey, sortKey } = this.table.def;
|
|
@@ -230,140 +211,141 @@ var Repository = class {
|
|
|
230
211
|
return { [partitionKey]: item[partitionKey] };
|
|
231
212
|
}
|
|
232
213
|
async get(key, options) {
|
|
233
|
-
|
|
214
|
+
const item = await this.db.get({
|
|
234
215
|
table: this.tableName,
|
|
235
216
|
key: this.extractKey(key),
|
|
236
217
|
...options
|
|
237
218
|
});
|
|
219
|
+
return item && this.applyTransformIfNeeded(item, options);
|
|
238
220
|
}
|
|
239
221
|
async getOrThrow(key, options) {
|
|
240
|
-
|
|
222
|
+
const item = await this.db.getOrThrow({
|
|
241
223
|
table: this.tableName,
|
|
242
224
|
key: this.extractKey(key),
|
|
243
225
|
...options
|
|
244
226
|
});
|
|
227
|
+
return this.applyTransformIfNeeded(item, options);
|
|
245
228
|
}
|
|
246
229
|
async put(item, options) {
|
|
247
|
-
const itemWithDefaults =
|
|
248
|
-
...this.
|
|
230
|
+
const itemWithDefaults = {
|
|
231
|
+
...this.defaultPutData,
|
|
249
232
|
...item
|
|
250
|
-
}
|
|
251
|
-
|
|
233
|
+
};
|
|
234
|
+
const result = await this.db.put({
|
|
252
235
|
table: this.tableName,
|
|
253
236
|
item: itemWithDefaults,
|
|
254
237
|
...options
|
|
255
238
|
});
|
|
239
|
+
return this.applyTransformIfNeeded(result);
|
|
256
240
|
}
|
|
257
241
|
async update(key, update, options) {
|
|
258
|
-
const updateWithDefaults =
|
|
259
|
-
...this.
|
|
242
|
+
const updateWithDefaults = {
|
|
243
|
+
...this.defaultUpdateData,
|
|
260
244
|
...update
|
|
261
|
-
}
|
|
262
|
-
|
|
245
|
+
};
|
|
246
|
+
const result = await this.db.update({
|
|
263
247
|
table: this.tableName,
|
|
264
248
|
key: this.extractKey(key),
|
|
265
249
|
update: updateWithDefaults,
|
|
266
250
|
...options
|
|
267
251
|
});
|
|
252
|
+
return this.applyTransformIfNeeded(result);
|
|
268
253
|
}
|
|
269
254
|
async create(item, options) {
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
item: itemWithDefaults,
|
|
277
|
-
partitionKeyName: this.table.def.partitionKey,
|
|
278
|
-
...options
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
async upsert(data) {
|
|
282
|
-
const { update, item, key, ...options } = data;
|
|
283
|
-
const updateWithDefaults = this.table.def.beforeUpdate ? {
|
|
284
|
-
...this.table.def.beforeUpdate(update),
|
|
285
|
-
...update
|
|
286
|
-
} : update;
|
|
287
|
-
const itemWithDefaults = this.table.def.beforePut ? {
|
|
288
|
-
...this.table.def.beforePut(item),
|
|
289
|
-
...item
|
|
290
|
-
} : item;
|
|
291
|
-
return this.db.upsert({
|
|
292
|
-
table: this.tableName,
|
|
293
|
-
key: this.extractKey(key),
|
|
294
|
-
update: updateWithDefaults,
|
|
295
|
-
item: itemWithDefaults,
|
|
296
|
-
...options
|
|
255
|
+
const { condition: otherCondition, ...otherOptions } = options ?? {};
|
|
256
|
+
const condition = { $and: [{ [this.table.def.partitionKey]: { $exists: false } }] };
|
|
257
|
+
if (otherCondition) condition.$and.push(otherCondition);
|
|
258
|
+
return this.put(item, {
|
|
259
|
+
condition,
|
|
260
|
+
...otherOptions
|
|
297
261
|
});
|
|
298
262
|
}
|
|
299
263
|
async delete(key, options) {
|
|
300
|
-
|
|
264
|
+
const item = await this.db.delete({
|
|
301
265
|
table: this.tableName,
|
|
302
266
|
key: this.extractKey(key),
|
|
303
267
|
...options
|
|
304
268
|
});
|
|
269
|
+
return item && this.applyTransformIfNeeded(item);
|
|
305
270
|
}
|
|
306
271
|
async deleteOrThrow(key, options) {
|
|
307
|
-
|
|
272
|
+
const item = await this.db.deleteOrThrow({
|
|
308
273
|
table: this.tableName,
|
|
309
274
|
key: this.extractKey(key),
|
|
310
275
|
...options
|
|
311
276
|
});
|
|
277
|
+
return this.applyTransformIfNeeded(item);
|
|
312
278
|
}
|
|
313
279
|
async query(query, options) {
|
|
314
|
-
|
|
280
|
+
const items = await this.db.query({
|
|
315
281
|
table: this.tableName,
|
|
316
282
|
query,
|
|
317
283
|
...options
|
|
318
284
|
});
|
|
285
|
+
return this.applyTransformsIfNeeded(items, options);
|
|
319
286
|
}
|
|
320
287
|
async *queryPaged(query, options) {
|
|
321
|
-
|
|
288
|
+
for await (const page of this.db.queryPaged({
|
|
322
289
|
table: this.tableName,
|
|
323
290
|
query,
|
|
324
291
|
...options
|
|
325
|
-
});
|
|
292
|
+
})) yield this.applyTransformsIfNeeded(page, options);
|
|
326
293
|
}
|
|
327
294
|
async queryGsi(gsi, query, options) {
|
|
328
|
-
|
|
295
|
+
const items = await this.db.query({
|
|
329
296
|
table: this.tableName,
|
|
330
297
|
index: gsi,
|
|
331
298
|
query,
|
|
332
299
|
...options
|
|
333
300
|
});
|
|
301
|
+
return this.applyTransformsIfNeeded(items, {
|
|
302
|
+
...options,
|
|
303
|
+
gsi
|
|
304
|
+
});
|
|
334
305
|
}
|
|
335
306
|
async *queryGsiPaged(gsi, query, options) {
|
|
336
|
-
|
|
307
|
+
for await (const page of this.db.queryPaged({
|
|
337
308
|
table: this.tableName,
|
|
338
309
|
index: gsi,
|
|
339
310
|
query,
|
|
340
311
|
...options
|
|
312
|
+
})) yield this.applyTransformsIfNeeded(page, {
|
|
313
|
+
...options,
|
|
314
|
+
gsi
|
|
341
315
|
});
|
|
342
316
|
}
|
|
343
317
|
async scan(options) {
|
|
344
|
-
|
|
318
|
+
const items = await this.db.scan({
|
|
345
319
|
table: this.tableName,
|
|
346
320
|
...options
|
|
347
321
|
});
|
|
322
|
+
return this.applyTransformsIfNeeded(items, options);
|
|
348
323
|
}
|
|
349
324
|
async *scanPaged(options) {
|
|
350
|
-
|
|
325
|
+
for await (const page of this.db.scanPaged({
|
|
351
326
|
table: this.tableName,
|
|
352
327
|
...options
|
|
353
|
-
});
|
|
328
|
+
})) yield this.applyTransformsIfNeeded(page, options);
|
|
354
329
|
}
|
|
355
330
|
async scanGsi(gsi, options) {
|
|
356
|
-
|
|
331
|
+
const items = await this.db.scan({
|
|
357
332
|
table: this.tableName,
|
|
358
333
|
index: gsi,
|
|
359
334
|
...options
|
|
360
335
|
});
|
|
336
|
+
return this.applyTransformsIfNeeded(items, {
|
|
337
|
+
...options,
|
|
338
|
+
gsi
|
|
339
|
+
});
|
|
361
340
|
}
|
|
362
341
|
async *scanGsiPaged(gsi, options) {
|
|
363
|
-
|
|
342
|
+
for await (const page of this.db.scanPaged({
|
|
364
343
|
table: this.tableName,
|
|
365
344
|
index: gsi,
|
|
366
345
|
...options
|
|
346
|
+
})) yield this.applyTransformsIfNeeded(page, {
|
|
347
|
+
...options,
|
|
348
|
+
gsi
|
|
367
349
|
});
|
|
368
350
|
}
|
|
369
351
|
async exists(options) {
|
|
@@ -386,16 +368,18 @@ var Repository = class {
|
|
|
386
368
|
keys: keys.map((key) => this.extractKey(key)),
|
|
387
369
|
...options
|
|
388
370
|
} });
|
|
371
|
+
const tableItems = items[this.tableName];
|
|
389
372
|
return {
|
|
390
|
-
items:
|
|
373
|
+
items: tableItems && this.applyTransformsIfNeeded(tableItems, options),
|
|
391
374
|
unprocessed: unprocessed?.[this.tableName]?.keys
|
|
392
375
|
};
|
|
393
376
|
}
|
|
394
377
|
async batchGetOrThrow(keys, options) {
|
|
395
|
-
|
|
378
|
+
const result = await this.db.batchGetOrThrow({ [this.tableName]: {
|
|
396
379
|
keys: keys.map((key) => this.extractKey(key)),
|
|
397
380
|
...options
|
|
398
|
-
} })
|
|
381
|
+
} });
|
|
382
|
+
return this.applyTransformsIfNeeded(result[this.tableName] ?? [], options);
|
|
399
383
|
}
|
|
400
384
|
async batchWrite(requests) {
|
|
401
385
|
const { items, unprocessed } = await this.db.batchWrite({ [this.tableName]: requests.map((request) => {
|
|
@@ -405,10 +389,10 @@ var Repository = class {
|
|
|
405
389
|
};
|
|
406
390
|
else return {
|
|
407
391
|
type: "PUT",
|
|
408
|
-
item:
|
|
409
|
-
...this.
|
|
392
|
+
item: {
|
|
393
|
+
...this.defaultPutData,
|
|
410
394
|
...request.item
|
|
411
|
-
}
|
|
395
|
+
}
|
|
412
396
|
};
|
|
413
397
|
}) });
|
|
414
398
|
return {
|
|
@@ -417,18 +401,19 @@ var Repository = class {
|
|
|
417
401
|
};
|
|
418
402
|
}
|
|
419
403
|
async trxGet(keys, options) {
|
|
420
|
-
return this.db.trxGet(...keys.map((key) => ({
|
|
404
|
+
return (await this.db.trxGet(...keys.map((key) => ({
|
|
421
405
|
table: this.tableName,
|
|
422
406
|
key: this.extractKey(key),
|
|
423
407
|
...options
|
|
424
|
-
})));
|
|
408
|
+
})))).map((item) => item && this.applyTransformIfNeeded(item, options));
|
|
425
409
|
}
|
|
426
410
|
async trxGetOrThrow(keys, options) {
|
|
427
|
-
|
|
411
|
+
const items = await this.db.trxGetOrThrow(...keys.map((key) => ({
|
|
428
412
|
table: this.tableName,
|
|
429
413
|
key: this.extractKey(key),
|
|
430
414
|
...options
|
|
431
415
|
})));
|
|
416
|
+
return this.applyTransformsIfNeeded(items, options);
|
|
432
417
|
}
|
|
433
418
|
async trxWrite(...requests) {
|
|
434
419
|
await this.db.trxWrite(...requests.map((request) => {
|
|
@@ -490,10 +475,10 @@ var Repository = class {
|
|
|
490
475
|
};
|
|
491
476
|
}
|
|
492
477
|
trxPutRequest(item, options) {
|
|
493
|
-
const itemWithDefaults =
|
|
494
|
-
...this.
|
|
478
|
+
const itemWithDefaults = {
|
|
479
|
+
...this.defaultPutData,
|
|
495
480
|
...item
|
|
496
|
-
}
|
|
481
|
+
};
|
|
497
482
|
return {
|
|
498
483
|
table: this.tableName,
|
|
499
484
|
type: "PUT",
|
|
@@ -502,10 +487,10 @@ var Repository = class {
|
|
|
502
487
|
};
|
|
503
488
|
}
|
|
504
489
|
trxUpdateRequest(key, update, options) {
|
|
505
|
-
const updateWithDefaults =
|
|
506
|
-
...this.
|
|
490
|
+
const updateWithDefaults = {
|
|
491
|
+
...this.defaultUpdateData,
|
|
507
492
|
...update
|
|
508
|
-
}
|
|
493
|
+
};
|
|
509
494
|
return {
|
|
510
495
|
table: this.tableName,
|
|
511
496
|
type: "UPDATE",
|
|
@@ -518,10 +503,10 @@ var Repository = class {
|
|
|
518
503
|
const { condition: otherCondition, ...otherOptions } = options ?? {};
|
|
519
504
|
const condition = { $and: [{ [this.table.def.partitionKey]: { $exists: false } }] };
|
|
520
505
|
if (otherCondition) condition.$and.push(otherCondition);
|
|
521
|
-
const itemWithDefaults =
|
|
522
|
-
...this.
|
|
506
|
+
const itemWithDefaults = {
|
|
507
|
+
...this.defaultPutData,
|
|
523
508
|
...item
|
|
524
|
-
}
|
|
509
|
+
};
|
|
525
510
|
return {
|
|
526
511
|
table: this.tableName,
|
|
527
512
|
type: "PUT",
|
|
@@ -530,78 +515,25 @@ var Repository = class {
|
|
|
530
515
|
...otherOptions
|
|
531
516
|
};
|
|
532
517
|
}
|
|
518
|
+
applyTransformsIfNeeded(items, options) {
|
|
519
|
+
if (options?.projection?.length) return items;
|
|
520
|
+
if (options?.gsi) {
|
|
521
|
+
const gsiProj = this.table.def.gsis?.[options.gsi]?.projection;
|
|
522
|
+
if (gsiProj === "KEYS_ONLY" || Array.isArray(gsiProj)) return items;
|
|
523
|
+
}
|
|
524
|
+
return items.map((item) => this.transformItem(item));
|
|
525
|
+
}
|
|
526
|
+
applyTransformIfNeeded(item, options) {
|
|
527
|
+
const [transformedItem] = this.applyTransformsIfNeeded([item], options);
|
|
528
|
+
return transformedItem;
|
|
529
|
+
}
|
|
533
530
|
};
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (typebox.IsObject(schema)) {
|
|
540
|
-
const attrSchema = schema.properties[attrName];
|
|
541
|
-
if (!attrSchema) return [void 0];
|
|
542
|
-
return resolveAttrType(attrSchema, attrName);
|
|
543
|
-
}
|
|
544
|
-
if (typebox.IsIntersect(schema)) return schema.allOf.flatMap((s) => resolveAttrType(s, attrName));
|
|
545
|
-
if (typebox.IsUnion(schema)) return schema.anyOf.flatMap((s) => resolveAttrType(s, attrName));
|
|
546
|
-
return [];
|
|
547
|
-
};
|
|
548
|
-
const getAttrType = (schema, attrName, allowedTypes = [
|
|
549
|
-
"S",
|
|
550
|
-
"N",
|
|
551
|
-
void 0
|
|
552
|
-
]) => {
|
|
553
|
-
const resolvedType = resolveAttrType(schema, attrName);
|
|
554
|
-
if (resolvedType.includes("S") && resolvedType.includes("N")) throw new Error(`Attribute ${attrName} cannot be both a number and a string.`);
|
|
555
|
-
if (!allowedTypes.includes(void 0) && resolvedType.includes(void 0)) throw new Error(`Attribute ${attrName} cannot be optional.`);
|
|
556
|
-
return resolvedType.includes("S") ? "S" : "N";
|
|
557
|
-
};
|
|
558
|
-
const extractAttribute = (schema, attrName, allowedTypes) => {
|
|
559
|
-
return {
|
|
560
|
-
AttributeName: attrName,
|
|
561
|
-
AttributeType: getAttrType(schema, attrName, allowedTypes)
|
|
562
|
-
};
|
|
563
|
-
};
|
|
564
|
-
const extractTableKey = (schema, attrName, allowedTypes) => {
|
|
565
|
-
return {
|
|
566
|
-
name: attrName,
|
|
567
|
-
type: getAttrType(schema, attrName, allowedTypes)
|
|
568
|
-
};
|
|
569
|
-
};
|
|
570
|
-
const extractTableDesc = (schema, def) => {
|
|
571
|
-
const gsis = Object.entries(def.gsis ?? {}).map(([indexName, gsi]) => {
|
|
572
|
-
return {
|
|
573
|
-
indexName,
|
|
574
|
-
partitionKey: extractTableKey(schema, gsi.partitionKey),
|
|
575
|
-
sortKey: gsi.sortKey ? extractTableKey(schema, gsi.sortKey) : void 0,
|
|
576
|
-
projectionType: Array.isArray(gsi.projection) ? "INCLUDE" : gsi.projection ?? "ALL",
|
|
577
|
-
nonKeyAttributes: Array.isArray(gsi.projection) ? gsi.projection : void 0
|
|
578
|
-
};
|
|
579
|
-
});
|
|
580
|
-
return {
|
|
581
|
-
tableName: def.name,
|
|
582
|
-
billingMode: def.billingMode ?? "PAY_PER_REQUEST",
|
|
583
|
-
stream: def.stream,
|
|
584
|
-
partitionKey: extractTableKey(schema, def.partitionKey, ["N", "S"]),
|
|
585
|
-
sortKey: def.sortKey ? extractTableKey(schema, def.sortKey, ["N", "S"]) : void 0,
|
|
586
|
-
gsis: gsis.length ? gsis : void 0
|
|
587
|
-
};
|
|
588
|
-
};
|
|
589
|
-
const chunk = (arr, chunkSize) => {
|
|
590
|
-
if (chunkSize <= 0) return [];
|
|
591
|
-
const chunks = [];
|
|
592
|
-
for (let i = 0; i < arr.length; i += chunkSize) chunks.push(arr.slice(i, i + chunkSize));
|
|
593
|
-
return chunks;
|
|
594
|
-
};
|
|
595
|
-
const removeUndefined = (obj) => {
|
|
596
|
-
const stack = [obj];
|
|
597
|
-
while (stack.length) {
|
|
598
|
-
const currentObj = stack.pop();
|
|
599
|
-
if (currentObj !== void 0) Object.entries(currentObj).forEach(([k, v]) => {
|
|
600
|
-
if (v && v instanceof Object) stack.push(v);
|
|
601
|
-
else if (v === void 0) delete currentObj[k];
|
|
602
|
-
});
|
|
531
|
+
var Repo = class extends AbstractRepo {
|
|
532
|
+
table;
|
|
533
|
+
constructor(db, table) {
|
|
534
|
+
super(db);
|
|
535
|
+
this.table = table;
|
|
603
536
|
}
|
|
604
|
-
return obj;
|
|
605
537
|
};
|
|
606
538
|
//#endregion
|
|
607
539
|
//#region src/db.ts
|
|
@@ -620,7 +552,13 @@ var Db = class {
|
|
|
620
552
|
this.config = dbConfig;
|
|
621
553
|
}
|
|
622
554
|
createRepo(table) {
|
|
623
|
-
return new
|
|
555
|
+
return new Repo(this, table);
|
|
556
|
+
}
|
|
557
|
+
async createTable(table) {
|
|
558
|
+
await this.client.send(new _aws_sdk_client_dynamodb.CreateTableCommand(require_util.extractTableDesc(table)));
|
|
559
|
+
}
|
|
560
|
+
async deleteTable(tableName) {
|
|
561
|
+
await this.client.send(new _aws_sdk_client_dynamodb.DeleteTableCommand({ TableName: tableName }));
|
|
624
562
|
}
|
|
625
563
|
async listTables(data) {
|
|
626
564
|
const tables = [];
|
|
@@ -657,17 +595,18 @@ var Db = class {
|
|
|
657
595
|
}
|
|
658
596
|
async put(data) {
|
|
659
597
|
const exp = new ExpressionBuilder();
|
|
598
|
+
const item = require_util.removeUndefined(data.item);
|
|
660
599
|
const input = new _aws_sdk_lib_dynamodb.PutCommand({
|
|
661
600
|
TableName: data.table,
|
|
662
|
-
Item:
|
|
663
|
-
ReturnValues: data.
|
|
601
|
+
Item: item,
|
|
602
|
+
ReturnValues: data.returnOld ? "ALL_OLD" : "NONE",
|
|
664
603
|
ReturnValuesOnConditionCheckFailure: "ALL_OLD",
|
|
665
604
|
ConditionExpression: exp.condition(data.condition),
|
|
666
605
|
ExpressionAttributeNames: exp.attributeNames,
|
|
667
606
|
ExpressionAttributeValues: exp.attributeValues
|
|
668
607
|
});
|
|
669
608
|
const output = await this.client.send(input);
|
|
670
|
-
return data.
|
|
609
|
+
return data.returnOld ? output.Attributes : item;
|
|
671
610
|
}
|
|
672
611
|
async update(data) {
|
|
673
612
|
const exp = new ExpressionBuilder();
|
|
@@ -676,7 +615,7 @@ var Db = class {
|
|
|
676
615
|
const input = new _aws_sdk_lib_dynamodb.UpdateCommand({
|
|
677
616
|
TableName: data.table,
|
|
678
617
|
Key: data.key,
|
|
679
|
-
ReturnValues:
|
|
618
|
+
ReturnValues: "ALL_NEW",
|
|
680
619
|
ReturnValuesOnConditionCheckFailure: "ALL_OLD",
|
|
681
620
|
UpdateExpression: exp.update(data.update),
|
|
682
621
|
ConditionExpression: exp.condition(condition),
|
|
@@ -685,40 +624,12 @@ var Db = class {
|
|
|
685
624
|
});
|
|
686
625
|
return (await this.client.send(input)).Attributes;
|
|
687
626
|
}
|
|
688
|
-
async create(data) {
|
|
689
|
-
const { condition: otherCondition, partitionKeyName, ...options } = data;
|
|
690
|
-
const condition = { $and: [{ [partitionKeyName]: { $exists: false } }] };
|
|
691
|
-
if (otherCondition) condition.$and.push(otherCondition);
|
|
692
|
-
return this.put({
|
|
693
|
-
...options,
|
|
694
|
-
condition,
|
|
695
|
-
return: "ALL_NEW"
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
async upsert(data) {
|
|
699
|
-
const { key, item, update, ...options } = data;
|
|
700
|
-
try {
|
|
701
|
-
return await this.update({
|
|
702
|
-
...options,
|
|
703
|
-
key,
|
|
704
|
-
update,
|
|
705
|
-
return: "ALL_NEW"
|
|
706
|
-
});
|
|
707
|
-
} catch (e) {
|
|
708
|
-
if (e instanceof _aws_sdk_client_dynamodb.ConditionalCheckFailedException && !e.Item) return this.create({
|
|
709
|
-
item,
|
|
710
|
-
partitionKeyName: Object.keys(key)[0] ?? "",
|
|
711
|
-
...options
|
|
712
|
-
});
|
|
713
|
-
throw e;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
627
|
async delete(data) {
|
|
717
628
|
const exp = new ExpressionBuilder();
|
|
718
629
|
const input = new _aws_sdk_lib_dynamodb.DeleteCommand({
|
|
719
630
|
TableName: data.table,
|
|
720
631
|
Key: data.key,
|
|
721
|
-
ReturnValues:
|
|
632
|
+
ReturnValues: "ALL_OLD",
|
|
722
633
|
ConditionExpression: exp.condition(data.condition),
|
|
723
634
|
ReturnValuesOnConditionCheckFailure: "ALL_OLD",
|
|
724
635
|
ExpressionAttributeNames: exp.attributeNames,
|
|
@@ -972,7 +883,7 @@ var Db = class {
|
|
|
972
883
|
} };
|
|
973
884
|
if (request.type === "PUT") return { Put: {
|
|
974
885
|
TableName: request.table,
|
|
975
|
-
Item: removeUndefined(request.item),
|
|
886
|
+
Item: require_util.removeUndefined(request.item),
|
|
976
887
|
ConditionExpression: exp.condition(request.condition),
|
|
977
888
|
ExpressionAttributeNames: exp.attributeNames,
|
|
978
889
|
ExpressionAttributeValues: exp.attributeValues
|
|
@@ -999,83 +910,15 @@ var Table = class {
|
|
|
999
910
|
this.schema = schema;
|
|
1000
911
|
this.def = def;
|
|
1001
912
|
}
|
|
1002
|
-
async drop(client) {
|
|
1003
|
-
await client.send(new _aws_sdk_client_dynamodb.DeleteTableCommand({ TableName: this.def.name }));
|
|
1004
|
-
}
|
|
1005
|
-
async createTable(client) {
|
|
1006
|
-
const desc = extractTableDesc(this.schema, this.def);
|
|
1007
|
-
const attributes = /* @__PURE__ */ new Map();
|
|
1008
|
-
const setAttribute = (tableKey) => {
|
|
1009
|
-
attributes.set(tableKey.name, {
|
|
1010
|
-
AttributeName: tableKey.name,
|
|
1011
|
-
AttributeType: tableKey.type
|
|
1012
|
-
});
|
|
1013
|
-
};
|
|
1014
|
-
const keySchema = [{
|
|
1015
|
-
AttributeName: desc.partitionKey.name,
|
|
1016
|
-
KeyType: "HASH"
|
|
1017
|
-
}];
|
|
1018
|
-
setAttribute(desc.partitionKey);
|
|
1019
|
-
if (desc.sortKey) {
|
|
1020
|
-
keySchema.push({
|
|
1021
|
-
AttributeName: desc.sortKey.name,
|
|
1022
|
-
KeyType: "RANGE"
|
|
1023
|
-
});
|
|
1024
|
-
setAttribute(desc.sortKey);
|
|
1025
|
-
}
|
|
1026
|
-
const gsis = desc.gsis?.map((gsi) => {
|
|
1027
|
-
const gsiKeySchema = [{
|
|
1028
|
-
AttributeName: gsi.partitionKey.name,
|
|
1029
|
-
KeyType: "HASH"
|
|
1030
|
-
}];
|
|
1031
|
-
setAttribute(gsi.partitionKey);
|
|
1032
|
-
if (gsi.sortKey) {
|
|
1033
|
-
gsiKeySchema.push({
|
|
1034
|
-
AttributeName: gsi.sortKey.name,
|
|
1035
|
-
KeyType: "RANGE"
|
|
1036
|
-
});
|
|
1037
|
-
setAttribute(gsi.sortKey);
|
|
1038
|
-
}
|
|
1039
|
-
return {
|
|
1040
|
-
IndexName: gsi.indexName,
|
|
1041
|
-
KeySchema: gsiKeySchema,
|
|
1042
|
-
Projection: {
|
|
1043
|
-
ProjectionType: gsi.projectionType,
|
|
1044
|
-
NonKeyAttributes: gsi.nonKeyAttributes
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
});
|
|
1048
|
-
await client.send(new _aws_sdk_client_dynamodb.CreateTableCommand({
|
|
1049
|
-
TableName: desc.tableName,
|
|
1050
|
-
KeySchema: keySchema,
|
|
1051
|
-
AttributeDefinitions: [...attributes.values()],
|
|
1052
|
-
BillingMode: desc.billingMode,
|
|
1053
|
-
GlobalSecondaryIndexes: gsis,
|
|
1054
|
-
StreamSpecification: desc.stream ? {
|
|
1055
|
-
StreamEnabled: true,
|
|
1056
|
-
StreamViewType: desc.stream
|
|
1057
|
-
} : void 0
|
|
1058
|
-
}));
|
|
1059
|
-
if (desc.ttlAttribute) await client.send(new _aws_sdk_client_dynamodb.UpdateTimeToLiveCommand({
|
|
1060
|
-
TableName: desc.tableName,
|
|
1061
|
-
TimeToLiveSpecification: {
|
|
1062
|
-
Enabled: true,
|
|
1063
|
-
AttributeName: desc.ttlAttribute
|
|
1064
|
-
}
|
|
1065
|
-
}));
|
|
1066
|
-
}
|
|
1067
913
|
};
|
|
1068
914
|
//#endregion
|
|
915
|
+
exports.AbstractRepo = AbstractRepo;
|
|
1069
916
|
exports.Db = Db;
|
|
1070
|
-
exports.
|
|
917
|
+
exports.Repo = Repo;
|
|
1071
918
|
exports.Table = Table;
|
|
1072
|
-
exports.
|
|
1073
|
-
exports.
|
|
1074
|
-
exports.
|
|
1075
|
-
exports.
|
|
1076
|
-
exports.extractTableKey = extractTableKey;
|
|
1077
|
-
exports.getAttrType = getAttrType;
|
|
1078
|
-
exports.removeUndefined = removeUndefined;
|
|
1079
|
-
exports.resolveAttrType = resolveAttrType;
|
|
919
|
+
exports.chunk = require_util.chunk;
|
|
920
|
+
exports.extractTableDesc = require_util.extractTableDesc;
|
|
921
|
+
exports.removeUndefined = require_util.removeUndefined;
|
|
922
|
+
exports.resolveAttrType = require_util.resolveAttrType;
|
|
1080
923
|
|
|
1081
924
|
//# sourceMappingURL=index.cjs.map
|