dynamo-document-builder 0.6.0 → 0.7.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 +367 -0
- package/dist/attributes/attribute-map.cjs +52 -0
- package/dist/attributes/attribute-map.cjs.map +1 -1
- package/dist/attributes/attribute-map.d.ts +67 -0
- package/dist/attributes/attribute-map.mjs +52 -0
- package/dist/attributes/attribute-map.mjs.map +1 -1
- package/dist/commands/batch-get.cjs +43 -0
- package/dist/commands/batch-get.cjs.map +1 -1
- package/dist/commands/batch-get.d.ts +51 -3
- package/dist/commands/batch-get.mjs +44 -1
- package/dist/commands/batch-get.mjs.map +1 -1
- package/dist/commands/batch-projected-get.cjs +42 -0
- package/dist/commands/batch-projected-get.cjs.map +1 -1
- package/dist/commands/batch-projected-get.d.ts +56 -3
- package/dist/commands/batch-projected-get.mjs +42 -0
- package/dist/commands/batch-projected-get.mjs.map +1 -1
- package/dist/commands/batch-write.cjs +44 -0
- package/dist/commands/batch-write.cjs.map +1 -1
- package/dist/commands/batch-write.d.ts +54 -4
- package/dist/commands/batch-write.mjs +45 -1
- package/dist/commands/batch-write.mjs.map +1 -1
- package/dist/commands/condition-check.cjs +37 -0
- package/dist/commands/condition-check.cjs.map +1 -1
- package/dist/commands/condition-check.d.ts +45 -3
- package/dist/commands/condition-check.mjs +37 -0
- package/dist/commands/condition-check.mjs.map +1 -1
- package/dist/commands/conditional-delete.cjs +33 -0
- package/dist/commands/conditional-delete.cjs.map +1 -1
- package/dist/commands/conditional-delete.d.ts +46 -3
- package/dist/commands/conditional-delete.mjs +33 -0
- package/dist/commands/conditional-delete.mjs.map +1 -1
- package/dist/commands/conditional-put.cjs +34 -0
- package/dist/commands/conditional-put.cjs.map +1 -1
- package/dist/commands/conditional-put.d.ts +48 -4
- package/dist/commands/conditional-put.mjs +34 -0
- package/dist/commands/conditional-put.mjs.map +1 -1
- package/dist/commands/conditional-update.cjs +35 -0
- package/dist/commands/conditional-update.cjs.map +1 -1
- package/dist/commands/conditional-update.d.ts +48 -3
- package/dist/commands/conditional-update.mjs +35 -0
- package/dist/commands/conditional-update.mjs.map +1 -1
- package/dist/commands/delete.cjs +32 -0
- package/dist/commands/delete.cjs.map +1 -1
- package/dist/commands/delete.d.ts +44 -2
- package/dist/commands/delete.mjs +32 -0
- package/dist/commands/delete.mjs.map +1 -1
- package/dist/commands/get.cjs +33 -0
- package/dist/commands/get.cjs.map +1 -1
- package/dist/commands/get.d.ts +45 -2
- package/dist/commands/get.mjs +33 -0
- package/dist/commands/get.mjs.map +1 -1
- package/dist/commands/index.cjs +8 -0
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.ts +160 -1
- package/dist/commands/index.mjs +4 -0
- package/dist/commands/index.mjs.map +1 -1
- package/dist/commands/projected-get.cjs +40 -0
- package/dist/commands/projected-get.cjs.map +1 -1
- package/dist/commands/projected-get.d.ts +54 -3
- package/dist/commands/projected-get.mjs +40 -0
- package/dist/commands/projected-get.mjs.map +1 -1
- package/dist/commands/projected-query.cjs +41 -0
- package/dist/commands/projected-query.cjs.map +1 -1
- package/dist/commands/projected-query.d.ts +56 -3
- package/dist/commands/projected-query.mjs +41 -0
- package/dist/commands/projected-query.mjs.map +1 -1
- package/dist/commands/projected-scan.cjs +41 -0
- package/dist/commands/projected-scan.cjs.map +1 -1
- package/dist/commands/projected-scan.d.ts +55 -3
- package/dist/commands/projected-scan.mjs +41 -0
- package/dist/commands/projected-scan.mjs.map +1 -1
- package/dist/commands/put.cjs +37 -0
- package/dist/commands/put.cjs.map +1 -1
- package/dist/commands/put.d.ts +50 -3
- package/dist/commands/put.mjs +37 -0
- package/dist/commands/put.mjs.map +1 -1
- package/dist/commands/query.cjs +35 -0
- package/dist/commands/query.cjs.map +1 -1
- package/dist/commands/query.d.ts +48 -3
- package/dist/commands/query.mjs +35 -0
- package/dist/commands/query.mjs.map +1 -1
- package/dist/commands/scan.cjs +33 -0
- package/dist/commands/scan.cjs.map +1 -1
- package/dist/commands/scan.d.ts +46 -3
- package/dist/commands/scan.mjs +33 -0
- package/dist/commands/scan.mjs.map +1 -1
- package/dist/commands/table-batch-get.cjs +123 -0
- package/dist/commands/table-batch-get.cjs.map +1 -0
- package/dist/commands/table-batch-get.d.ts +86 -0
- package/dist/commands/table-batch-get.mjs +121 -0
- package/dist/commands/table-batch-get.mjs.map +1 -0
- package/dist/commands/table-batch-write.cjs +119 -0
- package/dist/commands/table-batch-write.cjs.map +1 -0
- package/dist/commands/table-batch-write.d.ts +79 -0
- package/dist/commands/table-batch-write.mjs +117 -0
- package/dist/commands/table-batch-write.mjs.map +1 -0
- package/dist/commands/table-transact-get.cjs +73 -0
- package/dist/commands/table-transact-get.cjs.map +1 -0
- package/dist/commands/table-transact-get.d.ts +60 -0
- package/dist/commands/table-transact-get.mjs +71 -0
- package/dist/commands/table-transact-get.mjs.map +1 -0
- package/dist/commands/table-transact-write.cjs +76 -0
- package/dist/commands/table-transact-write.cjs.map +1 -0
- package/dist/commands/table-transact-write.d.ts +51 -0
- package/dist/commands/table-transact-write.mjs +74 -0
- package/dist/commands/table-transact-write.mjs.map +1 -0
- package/dist/commands/transact-get.cjs +38 -0
- package/dist/commands/transact-get.cjs.map +1 -1
- package/dist/commands/transact-get.d.ts +49 -3
- package/dist/commands/transact-get.mjs +39 -1
- package/dist/commands/transact-get.mjs.map +1 -1
- package/dist/commands/transact-write.cjs +37 -0
- package/dist/commands/transact-write.cjs.map +1 -1
- package/dist/commands/transact-write.d.ts +46 -1
- package/dist/commands/transact-write.mjs +37 -0
- package/dist/commands/transact-write.mjs.map +1 -1
- package/dist/commands/update.cjs +37 -0
- package/dist/commands/update.cjs.map +1 -1
- package/dist/commands/update.d.ts +50 -3
- package/dist/commands/update.mjs +37 -0
- package/dist/commands/update.mjs.map +1 -1
- package/dist/conditions/and.cjs +3 -0
- package/dist/conditions/and.cjs.map +1 -1
- package/dist/conditions/and.d.ts +4 -1
- package/dist/conditions/and.mjs +3 -0
- package/dist/conditions/and.mjs.map +1 -1
- package/dist/conditions/begins-with.cjs +3 -0
- package/dist/conditions/begins-with.cjs.map +1 -1
- package/dist/conditions/begins-with.d.ts +4 -1
- package/dist/conditions/begins-with.mjs +3 -0
- package/dist/conditions/begins-with.mjs.map +1 -1
- package/dist/conditions/between.cjs +3 -0
- package/dist/conditions/between.cjs.map +1 -1
- package/dist/conditions/between.d.ts +4 -1
- package/dist/conditions/between.mjs +3 -0
- package/dist/conditions/between.mjs.map +1 -1
- package/dist/conditions/condition-parser.d.ts +1 -1
- package/dist/conditions/contains.cjs +3 -0
- package/dist/conditions/contains.cjs.map +1 -1
- package/dist/conditions/contains.d.ts +4 -1
- package/dist/conditions/contains.mjs +3 -0
- package/dist/conditions/contains.mjs.map +1 -1
- package/dist/conditions/equals.cjs +3 -0
- package/dist/conditions/equals.cjs.map +1 -1
- package/dist/conditions/equals.d.ts +4 -1
- package/dist/conditions/equals.mjs +3 -0
- package/dist/conditions/equals.mjs.map +1 -1
- package/dist/conditions/exists.cjs +3 -0
- package/dist/conditions/exists.cjs.map +1 -1
- package/dist/conditions/exists.d.ts +4 -1
- package/dist/conditions/exists.mjs +3 -0
- package/dist/conditions/exists.mjs.map +1 -1
- package/dist/conditions/greater-than-or-equal.cjs +3 -0
- package/dist/conditions/greater-than-or-equal.cjs.map +1 -1
- package/dist/conditions/greater-than-or-equal.d.ts +4 -1
- package/dist/conditions/greater-than-or-equal.mjs +3 -0
- package/dist/conditions/greater-than-or-equal.mjs.map +1 -1
- package/dist/conditions/greater-than.cjs +3 -0
- package/dist/conditions/greater-than.cjs.map +1 -1
- package/dist/conditions/greater-than.d.ts +4 -1
- package/dist/conditions/greater-than.mjs +3 -0
- package/dist/conditions/greater-than.mjs.map +1 -1
- package/dist/conditions/index.cjs +2 -2
- package/dist/conditions/index.d.ts +185 -2
- package/dist/conditions/index.mjs +1 -1
- package/dist/conditions/is-in.cjs +3 -0
- package/dist/conditions/is-in.cjs.map +1 -1
- package/dist/conditions/is-in.d.ts +4 -1
- package/dist/conditions/is-in.mjs +3 -0
- package/dist/conditions/is-in.mjs.map +1 -1
- package/dist/conditions/less-than-or-equal.cjs +3 -0
- package/dist/conditions/less-than-or-equal.cjs.map +1 -1
- package/dist/conditions/less-than-or-equal.d.ts +4 -1
- package/dist/conditions/less-than-or-equal.mjs +3 -0
- package/dist/conditions/less-than-or-equal.mjs.map +1 -1
- package/dist/conditions/less-than.cjs +3 -0
- package/dist/conditions/less-than.cjs.map +1 -1
- package/dist/conditions/less-than.d.ts +4 -1
- package/dist/conditions/less-than.mjs +3 -0
- package/dist/conditions/less-than.mjs.map +1 -1
- package/dist/conditions/not-equals.cjs +3 -0
- package/dist/conditions/not-equals.cjs.map +1 -1
- package/dist/conditions/not-equals.d.ts +4 -1
- package/dist/conditions/not-equals.mjs +3 -0
- package/dist/conditions/not-equals.mjs.map +1 -1
- package/dist/conditions/not-exists.cjs +3 -0
- package/dist/conditions/not-exists.cjs.map +1 -1
- package/dist/conditions/not-exists.d.ts +4 -1
- package/dist/conditions/not-exists.mjs +3 -0
- package/dist/conditions/not-exists.mjs.map +1 -1
- package/dist/conditions/not.cjs +3 -0
- package/dist/conditions/not.cjs.map +1 -1
- package/dist/conditions/not.d.ts +4 -1
- package/dist/conditions/not.mjs +3 -0
- package/dist/conditions/not.mjs.map +1 -1
- package/dist/conditions/or.cjs +3 -0
- package/dist/conditions/or.cjs.map +1 -1
- package/dist/conditions/or.d.ts +4 -1
- package/dist/conditions/or.mjs +3 -0
- package/dist/conditions/or.mjs.map +1 -1
- package/dist/conditions/size.cjs +3 -0
- package/dist/conditions/size.cjs.map +1 -1
- package/dist/conditions/size.d.ts +4 -1
- package/dist/conditions/size.mjs +3 -0
- package/dist/conditions/size.mjs.map +1 -1
- package/dist/conditions/type-is.cjs +3 -0
- package/dist/conditions/type-is.cjs.map +1 -1
- package/dist/conditions/type-is.d.ts +4 -1
- package/dist/conditions/type-is.mjs +3 -0
- package/dist/conditions/type-is.mjs.map +1 -1
- package/dist/core/entity.cjs +171 -0
- package/dist/core/entity.cjs.map +1 -1
- package/dist/core/entity.d.ts +99 -4
- package/dist/core/entity.mjs +171 -0
- package/dist/core/entity.mjs.map +1 -1
- package/dist/core/index.d.ts +139 -2
- package/dist/core/key.cjs +1 -1
- package/dist/core/key.cjs.map +1 -1
- package/dist/core/key.d.ts +26 -2
- package/dist/core/key.mjs +1 -1
- package/dist/core/key.mjs.map +1 -1
- package/dist/core/table.cjs +30 -0
- package/dist/core/table.cjs.map +1 -1
- package/dist/core/table.d.ts +40 -1
- package/dist/core/table.mjs +31 -1
- package/dist/core/table.mjs.map +1 -1
- package/dist/errors.cjs +3 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +3 -0
- package/dist/errors.mjs +3 -0
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/projections/index.d.ts +7 -1
- package/dist/projections/projection-parser.d.ts +1 -1
- package/dist/updates/add-to-set.cjs +5 -0
- package/dist/updates/add-to-set.cjs.map +1 -1
- package/dist/updates/add-to-set.d.ts +6 -1
- package/dist/updates/add-to-set.mjs +5 -0
- package/dist/updates/add-to-set.mjs.map +1 -1
- package/dist/updates/add.cjs +5 -0
- package/dist/updates/add.cjs.map +1 -1
- package/dist/updates/add.d.ts +6 -1
- package/dist/updates/add.mjs +5 -0
- package/dist/updates/add.mjs.map +1 -1
- package/dist/updates/append.cjs +5 -0
- package/dist/updates/append.cjs.map +1 -1
- package/dist/updates/append.d.ts +6 -1
- package/dist/updates/append.mjs +5 -0
- package/dist/updates/append.mjs.map +1 -1
- package/dist/updates/index.d.ts +78 -1
- package/dist/updates/prepend.cjs +5 -0
- package/dist/updates/prepend.cjs.map +1 -1
- package/dist/updates/prepend.d.ts +6 -1
- package/dist/updates/prepend.mjs +5 -0
- package/dist/updates/prepend.mjs.map +1 -1
- package/dist/updates/ref.cjs +6 -0
- package/dist/updates/ref.cjs.map +1 -1
- package/dist/updates/ref.d.ts +7 -1
- package/dist/updates/ref.mjs +6 -0
- package/dist/updates/ref.mjs.map +1 -1
- package/dist/updates/remove-from-set.cjs +5 -0
- package/dist/updates/remove-from-set.cjs.map +1 -1
- package/dist/updates/remove-from-set.d.ts +6 -1
- package/dist/updates/remove-from-set.mjs +5 -0
- package/dist/updates/remove-from-set.mjs.map +1 -1
- package/dist/updates/remove.cjs +3 -0
- package/dist/updates/remove.cjs.map +1 -1
- package/dist/updates/remove.d.ts +4 -1
- package/dist/updates/remove.mjs +3 -0
- package/dist/updates/remove.mjs.map +1 -1
- package/dist/updates/subtract.cjs +5 -0
- package/dist/updates/subtract.cjs.map +1 -1
- package/dist/updates/subtract.d.ts +6 -1
- package/dist/updates/subtract.mjs +5 -0
- package/dist/updates/subtract.mjs.map +1 -1
- package/dist/updates/update-parser.cjs +10 -0
- package/dist/updates/update-parser.cjs.map +1 -1
- package/dist/updates/update-parser.d.ts +17 -1
- package/dist/updates/update-parser.mjs +10 -0
- package/dist/updates/update-parser.mjs.map +1 -1
- package/package.json +2 -1
- package/dist/commands/base-command.cjs +0 -3
- package/dist/commands/base-command.cjs.map +0 -1
- package/dist/commands/base-command.d.ts +0 -27
- package/dist/commands/base-command.mjs +0 -2
- package/dist/commands/base-command.mjs.map +0 -1
- package/dist/conditions/condition-types.cjs +0 -3
- package/dist/conditions/condition-types.cjs.map +0 -1
- package/dist/conditions/condition-types.d.ts +0 -95
- package/dist/conditions/condition-types.mjs +0 -2
- package/dist/conditions/condition-types.mjs.map +0 -1
- package/dist/core/core-types.cjs +0 -3
- package/dist/core/core-types.cjs.map +0 -1
- package/dist/core/core-types.d.ts +0 -44
- package/dist/core/core-types.mjs +0 -2
- package/dist/core/core-types.mjs.map +0 -1
- package/dist/projections/projection-types.cjs +0 -3
- package/dist/projections/projection-types.cjs.map +0 -1
- package/dist/projections/projection-types.d.ts +0 -3
- package/dist/projections/projection-types.mjs +0 -2
- package/dist/projections/projection-types.mjs.map +0 -1
- package/dist/updates/update-types.cjs +0 -3
- package/dist/updates/update-types.cjs.map +0 -1
- package/dist/updates/update-types.d.ts +0 -45
- package/dist/updates/update-types.mjs +0 -2
- package/dist/updates/update-types.mjs.map +0 -1
package/dist/core/entity.mjs
CHANGED
|
@@ -2,6 +2,11 @@ import { __classPrivateFieldSet, __classPrivateFieldGet, __awaiter, __asyncGener
|
|
|
2
2
|
import { DocumentBuilderError } from '../errors.mjs';
|
|
3
3
|
|
|
4
4
|
var _DynamoEntity_table, _DynamoEntity_schema, _DynamoEntity_pk, _DynamoEntity_sk, _DynamoEntity_gsi, _DynamoEntity_lsi;
|
|
5
|
+
/**
|
|
6
|
+
* Core class that represents a DynamoDB entity.
|
|
7
|
+
*
|
|
8
|
+
* @template Schema - The Zod schema representing the entity's structure.
|
|
9
|
+
*/
|
|
5
10
|
class DynamoEntity {
|
|
6
11
|
constructor(config) {
|
|
7
12
|
var _a, _b;
|
|
@@ -18,26 +23,46 @@ class DynamoEntity {
|
|
|
18
23
|
__classPrivateFieldSet(this, _DynamoEntity_gsi, (_a = config.globalSecondaryIndexes) !== null && _a !== void 0 ? _a : {}, "f");
|
|
19
24
|
__classPrivateFieldSet(this, _DynamoEntity_lsi, (_b = config.localSecondaryIndexes) !== null && _b !== void 0 ? _b : {}, "f");
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets the DynamoDB table associated with this entity.
|
|
28
|
+
*/
|
|
21
29
|
get table() {
|
|
22
30
|
return __classPrivateFieldGet(this, _DynamoEntity_table, "f");
|
|
23
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets the Zod schema defining the structure of this entity.
|
|
34
|
+
*/
|
|
24
35
|
get schema() {
|
|
25
36
|
return __classPrivateFieldGet(this, _DynamoEntity_schema, "f");
|
|
26
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the key builders for the secondary indexes defined on this entity.
|
|
40
|
+
*/
|
|
27
41
|
get secondaryIndexKeyBuilders() {
|
|
28
42
|
return {
|
|
29
43
|
gsi: __classPrivateFieldGet(this, _DynamoEntity_gsi, "f"),
|
|
30
44
|
lsi: __classPrivateFieldGet(this, _DynamoEntity_lsi, "f"),
|
|
31
45
|
};
|
|
32
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Builds the partition key for the given item using the entity's partition key builder.
|
|
49
|
+
*/
|
|
33
50
|
buildPartitionKey(item) {
|
|
34
51
|
var _a;
|
|
35
52
|
return (_a = __classPrivateFieldGet(this, _DynamoEntity_pk, "f")) === null || _a === void 0 ? void 0 : _a.call(this, item);
|
|
36
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Builds the sort key for the given item using the entity's sort key builder.
|
|
56
|
+
*/
|
|
37
57
|
buildSortKey(item) {
|
|
38
58
|
var _a;
|
|
39
59
|
return (_a = __classPrivateFieldGet(this, _DynamoEntity_sk, "f")) === null || _a === void 0 ? void 0 : _a.call(this, item);
|
|
40
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Builds the primary key for the given item, including both partition and sort keys if defined.
|
|
63
|
+
*
|
|
64
|
+
* If the entity does not have partition or sort key builders defined, the item is returned as-is.
|
|
65
|
+
*/
|
|
41
66
|
buildPrimaryKey(item) {
|
|
42
67
|
if (!__classPrivateFieldGet(this, _DynamoEntity_pk, "f") && !__classPrivateFieldGet(this, _DynamoEntity_sk, "f")) {
|
|
43
68
|
return item;
|
|
@@ -57,6 +82,12 @@ class DynamoEntity {
|
|
|
57
82
|
}
|
|
58
83
|
return key;
|
|
59
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Builds the key for a global secondary index for the given item.
|
|
87
|
+
*
|
|
88
|
+
* If the specified index does not exist or its key builders are not defined,
|
|
89
|
+
* the item is returned as-is.
|
|
90
|
+
*/
|
|
60
91
|
buildGlobalSecondaryIndexKey(indexName, item) {
|
|
61
92
|
const gsiKeyBuilder = __classPrivateFieldGet(this, _DynamoEntity_gsi, "f")[indexName];
|
|
62
93
|
const gsiKeyNames = this.table.globalSecondaryIndexKeyNames[indexName];
|
|
@@ -81,6 +112,12 @@ class DynamoEntity {
|
|
|
81
112
|
}
|
|
82
113
|
return key;
|
|
83
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Builds the key for a local secondary index for the given item.
|
|
117
|
+
*
|
|
118
|
+
* If the specified index does not exist or its key builders are not defined,
|
|
119
|
+
* the item is returned as-is.
|
|
120
|
+
*/
|
|
84
121
|
buildLocalSecondaryIndexKey(indexName, item) {
|
|
85
122
|
const lsiKeyBuilder = __classPrivateFieldGet(this, _DynamoEntity_lsi, "f")[indexName];
|
|
86
123
|
const lsiKeyNames = this.table.localSecondaryIndexKeyNames[indexName];
|
|
@@ -96,6 +133,17 @@ class DynamoEntity {
|
|
|
96
133
|
}
|
|
97
134
|
return key;
|
|
98
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Builds either a primary key or a secondary index key based on the provided input.
|
|
138
|
+
*
|
|
139
|
+
* If the input contains a `key`, the primary key is built.
|
|
140
|
+
* If the input contains an `index`, the corresponding secondary index key is built.
|
|
141
|
+
*
|
|
142
|
+
* Works similarly to the other key building methods and will pass-through the key or index
|
|
143
|
+
* input if the entity does not have the necessary key builders defined.
|
|
144
|
+
*
|
|
145
|
+
* @throws DocumentBuilderError if the index name is missing or not defined on the entity.
|
|
146
|
+
*/
|
|
99
147
|
buildPrimaryOrIndexKey(keyInput) {
|
|
100
148
|
if ('key' in keyInput) {
|
|
101
149
|
return this.buildPrimaryKey(keyInput.key);
|
|
@@ -116,6 +164,9 @@ class DynamoEntity {
|
|
|
116
164
|
}
|
|
117
165
|
throw new DocumentBuilderError(`Index "${indexName}" is not defined on entity`);
|
|
118
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Builds all keys (primary and secondary index keys) for the given item.
|
|
169
|
+
*/
|
|
119
170
|
buildAllKeys(item) {
|
|
120
171
|
const allKeys = this.buildPrimaryKey(item);
|
|
121
172
|
for (const indexName of Object.keys(__classPrivateFieldGet(this, _DynamoEntity_gsi, "f"))) {
|
|
@@ -126,11 +177,17 @@ class DynamoEntity {
|
|
|
126
177
|
}
|
|
127
178
|
return allKeys;
|
|
128
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Sends a command to be executed against this entity's table.
|
|
182
|
+
*/
|
|
129
183
|
send(command) {
|
|
130
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
185
|
return yield command.execute(this);
|
|
132
186
|
});
|
|
133
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Paginates through results of a paginatable command for this entity's table.
|
|
190
|
+
*/
|
|
134
191
|
paginate(paginatable) {
|
|
135
192
|
return __asyncGenerator(this, arguments, function* paginate_1() {
|
|
136
193
|
var _a, e_1, _b, _c;
|
|
@@ -151,6 +208,120 @@ class DynamoEntity {
|
|
|
151
208
|
}
|
|
152
209
|
});
|
|
153
210
|
}
|
|
211
|
+
prepare(input) {
|
|
212
|
+
var _a;
|
|
213
|
+
// WriteTransactable[] — array of transact write operations
|
|
214
|
+
if (Array.isArray(input)) {
|
|
215
|
+
return {
|
|
216
|
+
entity: this,
|
|
217
|
+
writes: input,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// BatchWritePreparable — has items and/or deletes, no keys
|
|
221
|
+
if ('items' in input || ('deletes' in input && !('keys' in input))) {
|
|
222
|
+
const batchWrite = input;
|
|
223
|
+
return {
|
|
224
|
+
entity: this,
|
|
225
|
+
buildRequests: (skipValidation, abortSignal) => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const putRequests = [];
|
|
227
|
+
const deleteRequests = [];
|
|
228
|
+
if (batchWrite.items && batchWrite.items.length > 0) {
|
|
229
|
+
for (const item of batchWrite.items) {
|
|
230
|
+
if (skipValidation) {
|
|
231
|
+
putRequests.push({
|
|
232
|
+
PutRequest: {
|
|
233
|
+
Item: Object.assign(Object.assign({}, item), this.buildAllKeys(item)),
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const encodedData = yield __classPrivateFieldGet(this, _DynamoEntity_schema, "f").encodeAsync(item);
|
|
239
|
+
putRequests.push({
|
|
240
|
+
PutRequest: {
|
|
241
|
+
Item: Object.assign(Object.assign({}, encodedData), this.buildAllKeys(item)),
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (batchWrite.deletes && batchWrite.deletes.length > 0) {
|
|
248
|
+
for (const deleteKey of batchWrite.deletes) {
|
|
249
|
+
deleteRequests.push({
|
|
250
|
+
DeleteRequest: {
|
|
251
|
+
Key: this.buildPrimaryKey(deleteKey),
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return [...putRequests, ...deleteRequests];
|
|
257
|
+
}),
|
|
258
|
+
matchUnprocessedPut: (item) => {
|
|
259
|
+
if (!batchWrite.items)
|
|
260
|
+
return undefined;
|
|
261
|
+
const itemPrimaryKey = this.buildPrimaryKey(item);
|
|
262
|
+
return batchWrite.items.find(original => {
|
|
263
|
+
const originalKey = this.buildPrimaryKey(original);
|
|
264
|
+
return JSON.stringify(originalKey) === JSON.stringify(itemPrimaryKey);
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
matchUnprocessedDelete: (key) => {
|
|
268
|
+
if (!batchWrite.deletes)
|
|
269
|
+
return undefined;
|
|
270
|
+
const keyStr = JSON.stringify(key);
|
|
271
|
+
return batchWrite.deletes.find(original => {
|
|
272
|
+
const originalKey = this.buildPrimaryKey(original);
|
|
273
|
+
return JSON.stringify(originalKey) === keyStr;
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
// BatchGetPreparable — has keys as entity partials plus consistent flag
|
|
279
|
+
if ('consistent' in input) {
|
|
280
|
+
const batchGet = input;
|
|
281
|
+
const builtKeys = batchGet.keys.map(k => this.buildPrimaryKey(k));
|
|
282
|
+
return {
|
|
283
|
+
entity: this,
|
|
284
|
+
keys: builtKeys,
|
|
285
|
+
consistent: (_a = batchGet.consistent) !== null && _a !== void 0 ? _a : false,
|
|
286
|
+
matchItem: (item) => {
|
|
287
|
+
const itemKey = this.buildPrimaryKey(item);
|
|
288
|
+
const itemKeyStr = JSON.stringify(itemKey);
|
|
289
|
+
return builtKeys.some(k => JSON.stringify(k) === itemKeyStr);
|
|
290
|
+
},
|
|
291
|
+
parseResults: (items, skipValidation) => __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
return yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
if (skipValidation)
|
|
294
|
+
return item;
|
|
295
|
+
return yield __classPrivateFieldGet(this, _DynamoEntity_schema, "f").parseAsync(item);
|
|
296
|
+
})));
|
|
297
|
+
}),
|
|
298
|
+
matchUnprocessedKey: (key) => {
|
|
299
|
+
const keyStr = JSON.stringify(key);
|
|
300
|
+
return batchGet.keys.find(original => {
|
|
301
|
+
const originalKey = this.buildPrimaryKey(original);
|
|
302
|
+
return JSON.stringify(originalKey) === keyStr;
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
// GetTransactable — has keys as entity partials, no consistent flag
|
|
308
|
+
return {
|
|
309
|
+
entity: this,
|
|
310
|
+
keys: input.keys.map(key => ({
|
|
311
|
+
TableName: __classPrivateFieldGet(this, _DynamoEntity_table, "f").tableName,
|
|
312
|
+
Key: this.buildPrimaryKey(key),
|
|
313
|
+
})),
|
|
314
|
+
parseResults: (items, skipValidation) => __awaiter(this, void 0, void 0, function* () {
|
|
315
|
+
return yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
316
|
+
if (item === undefined || item === null)
|
|
317
|
+
return undefined;
|
|
318
|
+
if (skipValidation)
|
|
319
|
+
return item;
|
|
320
|
+
return yield __classPrivateFieldGet(this, _DynamoEntity_schema, "f").parseAsync(item);
|
|
321
|
+
})));
|
|
322
|
+
}),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
154
325
|
}
|
|
155
326
|
_DynamoEntity_table = new WeakMap(), _DynamoEntity_schema = new WeakMap(), _DynamoEntity_pk = new WeakMap(), _DynamoEntity_sk = new WeakMap(), _DynamoEntity_gsi = new WeakMap(), _DynamoEntity_lsi = new WeakMap();
|
|
156
327
|
|
package/dist/core/entity.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.mjs","sources":["../../src/core/entity.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"entity.mjs","sources":["../../src/core/entity.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AA8DA;;;;AAIG;MACU,YAAY,CAAA;AAUvB,IAAA,WAAA,CAAY,MAAkC,EAAA;;QAT9C,mBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,oBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QAEA,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QAEA,iBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,iBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAGE,QAAA,sBAAA,CAAA,IAAI,EAAA,mBAAA,EAAU,MAAM,CAAC,KAAK,MAAA;AAC1B,QAAA,sBAAA,CAAA,IAAI,EAAA,oBAAA,EAAW,MAAM,CAAC,MAAM,MAAA;AAE5B,QAAA,sBAAA,CAAA,IAAI,EAAA,gBAAA,EAAO,MAAM,CAAC,YAAY,MAAA;AAC9B,QAAA,sBAAA,CAAA,IAAI,EAAA,gBAAA,EAAO,MAAM,CAAC,OAAO,MAAA;QAEzB,sBAAA,CAAA,IAAI,qBAAQ,CAAA,EAAA,GAAA,MAAM,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AAA,GAAA,CAAO,CAAC,SAAS;AAChC,gBAAA,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;AAC/B,aAAA,CAAC,CAAC;AACH,YAAA,YAAY,EAAE,CAAO,KAAgB,EAAE,cAAuB,KAAI,SAAA,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,aAAA;AAChE,gBAAA,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,KAAK,CAAC,GAAG,CAAC,CAAM,IAAI,KAAG,SAAA,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,aAAA;AACrB,oBAAA,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;AAAE,wBAAA,OAAO,SAAS;AACzD,oBAAA,IAAI,cAAc;AAAE,wBAAA,OAAO,IAA4B;oBACvD,OAAO,MAAM,uBAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;gBAC5C,CAAC,CAAA,CAAC,CACH;AACH,YAAA,CAAC,CAAA;SACuC;IAC5C;AACD;;;;;"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
import { DynamoEntity } from './entity.js';
|
|
2
|
+
export { DynamoEntityConfig, EntityKeyInput } from './entity.js';
|
|
3
3
|
export { DynamoIndexKey, DynamoIndexKeyBuilder, DynamoIndexKeyableValue, DynamoKey, DynamoKeyBuilder, DynamoKeyableValue, GlobalSecondaryIndexKeyBuilders, LocalSecondaryIndexKeyBuilders, indexKey, key } from './key.js';
|
|
4
4
|
export { DynamoTable, DynamoTableConfig } from './table.js';
|
|
5
|
+
import { ZodObject, output, input } from 'zod/v4';
|
|
6
|
+
import { TransactWriteItem, ConditionCheck, Put, Delete, Update } from '@aws-sdk/client-dynamodb';
|
|
7
|
+
import { NativeAttributeValue } from '@aws-sdk/lib-dynamodb';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Utility type used to derive the type from the Zod schema definition. Mainly for internal use.
|
|
11
|
+
*
|
|
12
|
+
* To get the schema type from an entity use [`Entity<E>`](/api-reference/type-aliases/entity) instead.
|
|
13
|
+
*/
|
|
14
|
+
type EntitySchema<Schema extends ZodObject> = output<Schema>;
|
|
15
|
+
/**
|
|
16
|
+
* Utility type used to derive the input type from the Zod schema definition. Mainly for internal use.
|
|
17
|
+
*
|
|
18
|
+
* To get the input schema type from an entity use [`EncodedEntity<E>`](/api-reference/type-aliases/encodedentity) instead.
|
|
19
|
+
*/
|
|
20
|
+
type EncodedEntitySchema<Schema extends ZodObject> = input<Schema>;
|
|
21
|
+
/**
|
|
22
|
+
* Utility type to derive the type of a DynamoEntity's schema.
|
|
23
|
+
*
|
|
24
|
+
* This is the Zod *output* type of a Zod schema (the type after a codec has been applied).
|
|
25
|
+
* It is the equivalent of `z.infer<typeof entity.schema>` or `z.output<typeof entity.schema>`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { DynamoTable, DynamoEntity, type Entity } from 'dynamo-document-builder';
|
|
30
|
+
* import { z } from 'zod';
|
|
31
|
+
*
|
|
32
|
+
* const table = new DynamoTable({
|
|
33
|
+
* tableName: 'ExampleTable',
|
|
34
|
+
* documentClient,
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* const userEntity = new DynamoEntity({
|
|
38
|
+
* table,
|
|
39
|
+
* schema: z.object({
|
|
40
|
+
* id: z.string(),
|
|
41
|
+
* name: z.string(),
|
|
42
|
+
* age: z.number().optional(),
|
|
43
|
+
* }),
|
|
44
|
+
* partitionKey: user => key('USER', user.id),
|
|
45
|
+
* sortKey: user => 'USER',
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* type User = Entity<typeof userEntity>;
|
|
49
|
+
*/
|
|
50
|
+
type Entity<E extends DynamoEntity<any>> = output<E['schema']>;
|
|
51
|
+
/**
|
|
52
|
+
* Utility type to derive the input type of a DynamoEntity's schema.
|
|
53
|
+
*
|
|
54
|
+
* This is the Zod *input* type of a Zod schema (the type before a codec has been applied).
|
|
55
|
+
* It is the equivalent of `z.input<typeof entity.schema>`.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { DynamoTable, DynamoEntity, type EncodedEntity } from 'dynamo-document-builder';
|
|
60
|
+
* import { z } from 'zod';
|
|
61
|
+
*
|
|
62
|
+
* const table = new DynamoTable({
|
|
63
|
+
* tableName: 'ExampleTable',
|
|
64
|
+
* documentClient,
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* const isoDatetimeToDate = z.codec(z.iso.datetime(), z.date(), {
|
|
68
|
+
* decode: isoString => new Date(isoString),
|
|
69
|
+
* encode: date => date.toISOString(),
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* const checkinEntity = new DynamoEntity({
|
|
73
|
+
* table,
|
|
74
|
+
* schema: z.object({
|
|
75
|
+
* id: z.string(),
|
|
76
|
+
* timestamp: isoDatetimeToDate,
|
|
77
|
+
* }),
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* type EncodedUser = EncodedEntity<typeof userEntity>;
|
|
81
|
+
*
|
|
82
|
+
* // EncodedUser is:
|
|
83
|
+
* // {
|
|
84
|
+
* // id: string;
|
|
85
|
+
* // timestamp: string; // ISO datetime string
|
|
86
|
+
* // }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
type EncodedEntity<E extends DynamoEntity<any>> = input<E['schema']>;
|
|
90
|
+
/**
|
|
91
|
+
* Type used to indicate the name of a DynamoDB secondary index.
|
|
92
|
+
*/
|
|
93
|
+
type IndexName = string;
|
|
94
|
+
/**
|
|
95
|
+
* Type representing the key names for a **global** secondary index.
|
|
96
|
+
*/
|
|
97
|
+
type GlobalSecondaryIndexKeyName = {
|
|
98
|
+
partitionKey: string;
|
|
99
|
+
sortKey?: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Type representing the key names for a **local** secondary index.
|
|
103
|
+
*/
|
|
104
|
+
type LocalSecondaryIndexKeyName = {
|
|
105
|
+
sortKey: string;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Type mapping index names to their corresponding global secondary index key names.
|
|
109
|
+
*/
|
|
110
|
+
type NamedGlobalSecondaryIndexKeyNames = Record<IndexName, GlobalSecondaryIndexKeyName>;
|
|
111
|
+
/**
|
|
112
|
+
* Type mapping index names to their corresponding local secondary index key names.
|
|
113
|
+
*/
|
|
114
|
+
type NamedLocalSecondaryIndexKeyNames = Record<IndexName, LocalSecondaryIndexKeyName>;
|
|
115
|
+
/**
|
|
116
|
+
* A modified version of TransactWriteItem that uses NativeAttributeValue for keys and items
|
|
117
|
+
* (dynamodb-lib doesnt export this type for some reason).
|
|
118
|
+
*
|
|
119
|
+
* See: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-lib-dynamodb/TypeAlias/TransactWriteCommandInput/
|
|
120
|
+
*/
|
|
121
|
+
type TransactWriteOperation = Omit<TransactWriteItem, 'ConditionCheck' | 'Put' | 'Delete' | 'Update'> & {
|
|
122
|
+
ConditionCheck?: (Omit<ConditionCheck, 'Key' | 'ExpressionAttributeValues'> & {
|
|
123
|
+
Key: Record<string, NativeAttributeValue> | undefined;
|
|
124
|
+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
|
|
125
|
+
}) | undefined;
|
|
126
|
+
Put?: (Omit<Put, 'Item' | 'ExpressionAttributeValues'> & {
|
|
127
|
+
Item: Record<string, NativeAttributeValue> | undefined;
|
|
128
|
+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
|
|
129
|
+
}) | undefined;
|
|
130
|
+
Delete?: (Omit<Delete, 'Key' | 'ExpressionAttributeValues'> & {
|
|
131
|
+
Key: Record<string, NativeAttributeValue> | undefined;
|
|
132
|
+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
|
|
133
|
+
}) | undefined;
|
|
134
|
+
Update?: (Omit<Update, 'Key' | 'ExpressionAttributeValues'> & {
|
|
135
|
+
Key: Record<string, NativeAttributeValue> | undefined;
|
|
136
|
+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
|
|
137
|
+
}) | undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export { DynamoEntity };
|
|
141
|
+
export type { EncodedEntity, EncodedEntitySchema, Entity, EntitySchema, GlobalSecondaryIndexKeyName, IndexName, LocalSecondaryIndexKeyName, NamedGlobalSecondaryIndexKeyNames, NamedLocalSecondaryIndexKeyNames, TransactWriteOperation };
|
package/dist/core/key.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var errors = require('../errors.cjs');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Builds a DynamoDB key from the given parts by concatenating them with a
|
|
6
|
+
* Builds a DynamoDB key from the given parts by concatenating them with a `#` separator.
|
|
7
7
|
* At least one part must be provided, or a DocumentBuilderError will be thrown.
|
|
8
8
|
*
|
|
9
9
|
* @param parts - The parts to combine into a key.
|
package/dist/core/key.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.cjs","sources":["../../src/core/key.ts"],"sourcesContent":[null],"names":["DocumentBuilderError"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"key.cjs","sources":["../../src/core/key.ts"],"sourcesContent":[null],"names":["DocumentBuilderError"],"mappings":";;;;AAsDA;;;;;;;;;;;;AAYG;AACG,SAAU,GAAG,CAAC,GAAG,KAA2B,EAAA;AAChD,IAAA,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;AACjB,QAAA,MAAM,IAAIA,2BAAoB,CAAC,wCAAwC,CAAC;IAC1E;AACA,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;AACxB;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,QAAQ,CAAC,GAAG,KAAgC,EAAA;IAC1D,IAAI,GAAG,GAAW,EAAE;AACpB,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;AACxB,QAAA,IAAI,IAAI,KAAK,SAAS,EAAE;AACtB,YAAA,OAAO,SAAS;QAClB;AACA,QAAA,GAAG,IAAI,GAAG,GAAG,CAAA,CAAA,EAAI,IAAI,CAAA,CAAE,GAAG,IAAI;IAChC;AACA,IAAA,OAAO,GAAG;AACZ;;;;;"}
|
package/dist/core/key.d.ts
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
import { IndexName } from './
|
|
1
|
+
import { IndexName } from './index.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Represents a value that can be used as a DynamoDB primary key.
|
|
5
|
+
*/
|
|
3
6
|
type DynamoKeyableValue = string | number | Buffer;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a value that can be used as a DynamoDB secondary index key.
|
|
9
|
+
*/
|
|
4
10
|
type DynamoIndexKeyableValue = string | number | Buffer | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* A function that builds a DynamoDB primary key from an item.
|
|
13
|
+
*/
|
|
5
14
|
type DynamoKeyBuilder<Item> = (item: Item) => DynamoKeyableValue;
|
|
15
|
+
/**
|
|
16
|
+
* A function that builds a DynamoDB secondary index key from an item.
|
|
17
|
+
*/
|
|
6
18
|
type DynamoIndexKeyBuilder<Item> = (item: Item) => DynamoIndexKeyableValue;
|
|
19
|
+
/**
|
|
20
|
+
* A mapping type of global secondary index names to their key builders.
|
|
21
|
+
*/
|
|
7
22
|
type GlobalSecondaryIndexKeyBuilders<Item> = Record<IndexName, {
|
|
8
23
|
partitionKey: DynamoIndexKeyBuilder<Item>;
|
|
9
24
|
sortKey?: DynamoIndexKeyBuilder<Item>;
|
|
10
25
|
}>;
|
|
26
|
+
/**
|
|
27
|
+
* A mapping type of local secondary index names to their key builders.
|
|
28
|
+
*/
|
|
11
29
|
type LocalSecondaryIndexKeyBuilders<Item> = Record<IndexName, {
|
|
12
30
|
sortKey: DynamoIndexKeyBuilder<Item>;
|
|
13
31
|
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Record type representing a DynamoDB primary key.
|
|
34
|
+
*/
|
|
14
35
|
type DynamoKey = Record<string, DynamoKeyableValue>;
|
|
36
|
+
/**
|
|
37
|
+
* Record type representing a DynamoDB secondary index key.
|
|
38
|
+
*/
|
|
15
39
|
type DynamoIndexKey = Record<string, DynamoIndexKeyableValue>;
|
|
16
40
|
/**
|
|
17
|
-
* Builds a DynamoDB key from the given parts by concatenating them with a
|
|
41
|
+
* Builds a DynamoDB key from the given parts by concatenating them with a `#` separator.
|
|
18
42
|
* At least one part must be provided, or a DocumentBuilderError will be thrown.
|
|
19
43
|
*
|
|
20
44
|
* @param parts - The parts to combine into a key.
|
package/dist/core/key.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DocumentBuilderError } from '../errors.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Builds a DynamoDB key from the given parts by concatenating them with a
|
|
4
|
+
* Builds a DynamoDB key from the given parts by concatenating them with a `#` separator.
|
|
5
5
|
* At least one part must be provided, or a DocumentBuilderError will be thrown.
|
|
6
6
|
*
|
|
7
7
|
* @param parts - The parts to combine into a key.
|
package/dist/core/key.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.mjs","sources":["../../src/core/key.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"key.mjs","sources":["../../src/core/key.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAsDA;;;;;;;;;;;;AAYG;AACG,SAAU,GAAG,CAAC,GAAG,KAA2B,EAAA;AAChD,IAAA,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;AACjB,QAAA,MAAM,IAAI,oBAAoB,CAAC,wCAAwC,CAAC;IAC1E;AACA,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;AACxB;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,QAAQ,CAAC,GAAG,KAAgC,EAAA;IAC1D,IAAI,GAAG,GAAW,EAAE;AACpB,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;AACxB,QAAA,IAAI,IAAI,KAAK,SAAS,EAAE;AACtB,YAAA,OAAO,SAAS;QAClB;AACA,QAAA,GAAG,IAAI,GAAG,GAAG,CAAA,CAAA,EAAI,IAAI,CAAA,CAAE,GAAG,IAAI;IAChC;AACA,IAAA,OAAO,GAAG;AACZ;;;;"}
|
package/dist/core/table.cjs
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
var tslib_es6 = require('../node_modules/tslib/tslib.es6.cjs');
|
|
4
4
|
|
|
5
5
|
var _DynamoTable_tableName, _DynamoTable_documentClient, _DynamoTable_pk, _DynamoTable_sk, _DynamoTable_gsi, _DynamoTable_lsi;
|
|
6
|
+
/**
|
|
7
|
+
* Core class that represents a DynamoDB table.
|
|
8
|
+
*/
|
|
6
9
|
class DynamoTable {
|
|
7
10
|
constructor(config) {
|
|
8
11
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -23,24 +26,51 @@ class DynamoTable {
|
|
|
23
26
|
tslib_es6.__classPrivateFieldSet(this, _DynamoTable_gsi, (_d = (_c = config.keyNames) === null || _c === void 0 ? void 0 : _c.globalSecondaryIndexes) !== null && _d !== void 0 ? _d : {}, "f");
|
|
24
27
|
tslib_es6.__classPrivateFieldSet(this, _DynamoTable_lsi, (_f = (_e = config.keyNames) === null || _e === void 0 ? void 0 : _e.localSecondaryIndexes) !== null && _f !== void 0 ? _f : {}, "f");
|
|
25
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The name of the DynamoDB table.
|
|
31
|
+
*/
|
|
26
32
|
get tableName() {
|
|
27
33
|
return tslib_es6.__classPrivateFieldGet(this, _DynamoTable_tableName, "f");
|
|
28
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The DynamoDB Document Client instance used for operations.
|
|
37
|
+
*/
|
|
29
38
|
get documentClient() {
|
|
30
39
|
return tslib_es6.__classPrivateFieldGet(this, _DynamoTable_documentClient, "f");
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The name of the partition key for the table.
|
|
43
|
+
*/
|
|
32
44
|
get partitionKeyName() {
|
|
33
45
|
return tslib_es6.__classPrivateFieldGet(this, _DynamoTable_pk, "f");
|
|
34
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The name of the sort key for the table, or `null` if the table does not have a sort key
|
|
49
|
+
* (`null` would indicate a "simple" primary key).
|
|
50
|
+
*/
|
|
35
51
|
get sortKeyName() {
|
|
36
52
|
return tslib_es6.__classPrivateFieldGet(this, _DynamoTable_sk, "f");
|
|
37
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* The key names for the global secondary indexes defined on the table.
|
|
56
|
+
*/
|
|
38
57
|
get globalSecondaryIndexKeyNames() {
|
|
39
58
|
return tslib_es6.__classPrivateFieldGet(this, _DynamoTable_gsi, "f");
|
|
40
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The key names for the local secondary indexes defined on the table.
|
|
62
|
+
*/
|
|
41
63
|
get localSecondaryIndexKeyNames() {
|
|
42
64
|
return tslib_es6.__classPrivateFieldGet(this, _DynamoTable_lsi, "f");
|
|
43
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Sends a table-level command to be executed against this table.
|
|
68
|
+
*/
|
|
69
|
+
send(command) {
|
|
70
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
return yield command.execute(this);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
44
74
|
}
|
|
45
75
|
_DynamoTable_tableName = new WeakMap(), _DynamoTable_documentClient = new WeakMap(), _DynamoTable_pk = new WeakMap(), _DynamoTable_sk = new WeakMap(), _DynamoTable_gsi = new WeakMap(), _DynamoTable_lsi = new WeakMap();
|
|
46
76
|
|
package/dist/core/table.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.cjs","sources":["../../src/core/table.ts"],"sourcesContent":[null],"names":["__classPrivateFieldSet","__classPrivateFieldGet"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"table.cjs","sources":["../../src/core/table.ts"],"sourcesContent":[null],"names":["__classPrivateFieldSet","__classPrivateFieldGet"],"mappings":";;;;;AA2BA;;AAEG;MACU,WAAW,CAAA;AAUtB,IAAA,WAAA,CAAY,MAAyB,EAAA;;QATrC,sBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,2BAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAEA,QAAA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAc,IAAI,CAAA;AAClB,QAAA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAqB,IAAI,CAAA;QAEzB,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,gBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAGE,QAAAA,gCAAA,CAAA,IAAI,EAAA,sBAAA,EAAc,MAAM,CAAC,SAAS,MAAA;AAClC,QAAAA,gCAAA,CAAA,IAAI,EAAA,2BAAA,EAAmB,MAAM,CAAC,cAAc,MAAA;QAC5C,IAAI,CAAA,CAAA,EAAA,GAAA,MAAM,CAAC,QAAQ,0CAAE,YAAY,MAAK,SAAS,EAAE;YAC/CA,gCAAA,CAAA,IAAI,mBAAO,MAAM,CAAC,QAAQ,CAAC,YAAY,MAAA;QACzC;QACA,IAAI,CAAA,CAAA,EAAA,GAAA,MAAM,CAAC,QAAQ,0CAAE,OAAO,MAAK,SAAS,EAAE;YAC1CA,gCAAA,CAAA,IAAI,mBAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,MAAA;QACpC;AACA,QAAAA,gCAAA,CAAA,IAAI,EAAA,gBAAA,EAAQ,CAAA,EAAA,GAAA,CAAA,EAAA,GA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AC;QACpC,CAAC,CAAA;AAAA,IAAA;AACF;;;;;"}
|
package/dist/core/table.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
2
|
-
import { NamedGlobalSecondaryIndexKeyNames, NamedLocalSecondaryIndexKeyNames } from './
|
|
2
|
+
import { NamedGlobalSecondaryIndexKeyNames, NamedLocalSecondaryIndexKeyNames } from './index.js';
|
|
3
|
+
import { TableCommand } from '../commands/index.js';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Configuration type for creating a DynamoTable.
|
|
7
|
+
*
|
|
8
|
+
* The table is assumed to have a primary key composed of a partition key named `"PK"` and
|
|
9
|
+
* a sort key named `"SK"` by default, unless overridden in the `keyNames` property.
|
|
10
|
+
*
|
|
11
|
+
* @template Schema - The Zod schema representing the entity's structure.
|
|
12
|
+
*
|
|
13
|
+
* @property tableName - The name of the DynamoDB table.
|
|
14
|
+
* @property documentClient - The DynamoDB Document Client instance to use for operations.
|
|
15
|
+
* @property keyNames - Key names object for the table's primary key and secondary indexes.
|
|
16
|
+
*/
|
|
4
17
|
type DynamoTableConfig = {
|
|
5
18
|
tableName: string;
|
|
6
19
|
documentClient: DynamoDBDocumentClient;
|
|
@@ -11,15 +24,41 @@ type DynamoTableConfig = {
|
|
|
11
24
|
localSecondaryIndexes?: NamedLocalSecondaryIndexKeyNames;
|
|
12
25
|
};
|
|
13
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Core class that represents a DynamoDB table.
|
|
29
|
+
*/
|
|
14
30
|
declare class DynamoTable {
|
|
15
31
|
#private;
|
|
16
32
|
constructor(config: DynamoTableConfig);
|
|
33
|
+
/**
|
|
34
|
+
* The name of the DynamoDB table.
|
|
35
|
+
*/
|
|
17
36
|
get tableName(): string;
|
|
37
|
+
/**
|
|
38
|
+
* The DynamoDB Document Client instance used for operations.
|
|
39
|
+
*/
|
|
18
40
|
get documentClient(): DynamoDBDocumentClient;
|
|
41
|
+
/**
|
|
42
|
+
* The name of the partition key for the table.
|
|
43
|
+
*/
|
|
19
44
|
get partitionKeyName(): string;
|
|
45
|
+
/**
|
|
46
|
+
* The name of the sort key for the table, or `null` if the table does not have a sort key
|
|
47
|
+
* (`null` would indicate a "simple" primary key).
|
|
48
|
+
*/
|
|
20
49
|
get sortKeyName(): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* The key names for the global secondary indexes defined on the table.
|
|
52
|
+
*/
|
|
21
53
|
get globalSecondaryIndexKeyNames(): NamedGlobalSecondaryIndexKeyNames;
|
|
54
|
+
/**
|
|
55
|
+
* The key names for the local secondary indexes defined on the table.
|
|
56
|
+
*/
|
|
22
57
|
get localSecondaryIndexKeyNames(): NamedLocalSecondaryIndexKeyNames;
|
|
58
|
+
/**
|
|
59
|
+
* Sends a table-level command to be executed against this table.
|
|
60
|
+
*/
|
|
61
|
+
send<CommandOutput>(command: TableCommand<CommandOutput>): Promise<CommandOutput>;
|
|
23
62
|
}
|
|
24
63
|
|
|
25
64
|
export { DynamoTable };
|