dynamo-document-builder 0.6.0 → 0.6.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 +270 -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 +36 -0
- package/dist/commands/batch-get.cjs.map +1 -1
- package/dist/commands/batch-get.d.ts +48 -2
- package/dist/commands/batch-get.mjs +36 -0
- 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 +38 -0
- package/dist/commands/batch-write.cjs.map +1 -1
- package/dist/commands/batch-write.d.ts +51 -3
- package/dist/commands/batch-write.mjs +38 -0
- 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.d.ts +62 -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 +36 -1
- package/dist/commands/query.cjs.map +1 -1
- package/dist/commands/query.d.ts +48 -3
- package/dist/commands/query.mjs +36 -1
- 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/transact-get.cjs +35 -0
- package/dist/commands/transact-get.cjs.map +1 -1
- package/dist/commands/transact-get.d.ts +47 -2
- package/dist/commands/transact-get.mjs +35 -0
- 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 +57 -0
- package/dist/core/entity.cjs.map +1 -1
- package/dist/core/entity.d.ts +79 -4
- package/dist/core/entity.mjs +57 -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 +22 -0
- package/dist/core/table.cjs.map +1 -1
- package/dist/core/table.d.ts +35 -1
- package/dist/core/table.mjs +22 -0
- 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 +4 -4
- package/dist/index.d.ts +7 -7
- package/dist/index.mjs +2 -2
- 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/README.md
CHANGED
|
@@ -77,3 +77,273 @@ const retrievedUser = await userEntity.send(new Get({
|
|
|
77
77
|
},
|
|
78
78
|
}));
|
|
79
79
|
```
|
|
80
|
+
|
|
81
|
+
## Examples
|
|
82
|
+
|
|
83
|
+
### Get
|
|
84
|
+
|
|
85
|
+
Retrieve a single item by primary key:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { Get } from 'dynamo-document-builder';
|
|
89
|
+
|
|
90
|
+
// Basic get
|
|
91
|
+
const { item } = await userEntity.send(new Get({
|
|
92
|
+
key: {
|
|
93
|
+
id: '123',
|
|
94
|
+
email: 'johndoe@example.com',
|
|
95
|
+
},
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
// Strongly consistent read
|
|
99
|
+
const { item } = await userEntity.send(new Get({
|
|
100
|
+
key: {
|
|
101
|
+
id: '123',
|
|
102
|
+
email: 'johndoe@example.com',
|
|
103
|
+
},
|
|
104
|
+
consistent: true,
|
|
105
|
+
}));
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Put
|
|
109
|
+
|
|
110
|
+
Create or replace an item:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { Put, ConditionalPut } from 'dynamo-document-builder';
|
|
114
|
+
|
|
115
|
+
// Basic put
|
|
116
|
+
await userEntity.send(new Put({
|
|
117
|
+
item: {
|
|
118
|
+
id: '123',
|
|
119
|
+
name: 'John Doe',
|
|
120
|
+
email: 'johndoe@example.com',
|
|
121
|
+
},
|
|
122
|
+
}));
|
|
123
|
+
|
|
124
|
+
// Put with condition (only if item doesn't exist)
|
|
125
|
+
await userEntity.send(new ConditionalPut({
|
|
126
|
+
item: {
|
|
127
|
+
id: '456',
|
|
128
|
+
name: 'Jane Smith',
|
|
129
|
+
email: 'janesmith@example.com',
|
|
130
|
+
},
|
|
131
|
+
condition: { id: notExists() },
|
|
132
|
+
}));
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Update
|
|
136
|
+
|
|
137
|
+
Modify existing item attributes:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { Update } from 'dynamo-document-builder';
|
|
141
|
+
import { add, append } from 'dynamo-document-builder';
|
|
142
|
+
|
|
143
|
+
await userEntity.send(new Update({
|
|
144
|
+
key: { id: '123', email: 'johndoe@example.com' },
|
|
145
|
+
updates: {
|
|
146
|
+
name: 'John D. Doe',
|
|
147
|
+
loginCount: add(1),
|
|
148
|
+
tags: append(['premium']),
|
|
149
|
+
},
|
|
150
|
+
returnValues: 'ALL_NEW',
|
|
151
|
+
}));
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Delete
|
|
155
|
+
|
|
156
|
+
Remove an item:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { Delete, ConditionalDelete } from 'dynamo-document-builder';
|
|
160
|
+
|
|
161
|
+
// Basic delete
|
|
162
|
+
await userEntity.send(new Delete({
|
|
163
|
+
key: {
|
|
164
|
+
id: '123',
|
|
165
|
+
email: 'johndoe@example.com',
|
|
166
|
+
},
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
// Conditional delete
|
|
170
|
+
await userEntity.send(new ConditionalDelete({
|
|
171
|
+
key: {
|
|
172
|
+
id: '456',
|
|
173
|
+
email: 'janesmith@example.com',
|
|
174
|
+
},
|
|
175
|
+
condition: {
|
|
176
|
+
status: 'inactive',
|
|
177
|
+
},
|
|
178
|
+
}));
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Query
|
|
182
|
+
|
|
183
|
+
Retrieve multiple items by partition key:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { Query } from 'dynamo-document-builder';
|
|
187
|
+
import { beginsWith, greaterThan } from 'dynamo-document-builder';
|
|
188
|
+
|
|
189
|
+
// Query all items with a specific partition key
|
|
190
|
+
const { items } = await userEntity.send(new Query({
|
|
191
|
+
key: {
|
|
192
|
+
id: '123',
|
|
193
|
+
},
|
|
194
|
+
}));
|
|
195
|
+
|
|
196
|
+
// Query with sort key condition
|
|
197
|
+
const { items, lastEvaluatedKey } = await userEntity.send(new Query({
|
|
198
|
+
key: {
|
|
199
|
+
id: '123',
|
|
200
|
+
},
|
|
201
|
+
sortKeyCondition: {
|
|
202
|
+
SK: beginsWith('EMAIL#'),
|
|
203
|
+
},
|
|
204
|
+
limit: 10,
|
|
205
|
+
}));
|
|
206
|
+
|
|
207
|
+
// Paginate through results
|
|
208
|
+
for await (const page of userEntity.paginate(new Query({
|
|
209
|
+
key: {
|
|
210
|
+
id: '123',
|
|
211
|
+
},
|
|
212
|
+
pageSize: 50,
|
|
213
|
+
}))) {
|
|
214
|
+
console.log(`Found ${page.count} items`);
|
|
215
|
+
processItems(page.items);
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Scan
|
|
220
|
+
|
|
221
|
+
Scan entire table (use sparingly, this an expensive operation):
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { Scan } from 'dynamo-document-builder';
|
|
225
|
+
|
|
226
|
+
// Full table scan
|
|
227
|
+
const { items, scannedCount } = await userEntity.send(new Scan());
|
|
228
|
+
|
|
229
|
+
// Scan with filter and limit
|
|
230
|
+
const { items, scannedCount } = await userEntity.send(new Scan({
|
|
231
|
+
filter: {
|
|
232
|
+
status: 'active',
|
|
233
|
+
},
|
|
234
|
+
limit: 100,
|
|
235
|
+
}));
|
|
236
|
+
|
|
237
|
+
// Parallel scan
|
|
238
|
+
async function parallelScan(totalSegments: number) {
|
|
239
|
+
const scanPromises = Array.from({ length: totalSegments }, (_, i) =>
|
|
240
|
+
userEntity.send(new Scan({
|
|
241
|
+
segment: i,
|
|
242
|
+
totalSegments: totalSegments,
|
|
243
|
+
}))
|
|
244
|
+
);
|
|
245
|
+
const results = await Promise.all(scanPromises);
|
|
246
|
+
return results.flatMap(r => r.items);
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### BatchGet
|
|
251
|
+
|
|
252
|
+
Retrieve multiple items by primary keys:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { BatchGet } from 'dynamo-document-builder';
|
|
256
|
+
|
|
257
|
+
const { items, unprocessedKeys } = await userEntity.send(new BatchGet({
|
|
258
|
+
keys: [
|
|
259
|
+
{ id: '123', email: 'johndoe@example.com' },
|
|
260
|
+
{ id: '456', email: 'janesmith@example.com' },
|
|
261
|
+
{ id: '789', email: 'bobwilson@example.com' },
|
|
262
|
+
],
|
|
263
|
+
}));
|
|
264
|
+
|
|
265
|
+
// Handle unprocessed keys
|
|
266
|
+
if (unprocessedKeys?.length) {
|
|
267
|
+
// Retry
|
|
268
|
+
await sleep(100);
|
|
269
|
+
const { items: retryItems } = await userEntity.send(new BatchGet({
|
|
270
|
+
keys: unprocessedKeys,
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### BatchWrite
|
|
276
|
+
|
|
277
|
+
Put and/or delete multiple items:
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { BatchWrite } from 'dynamo-document-builder';
|
|
281
|
+
|
|
282
|
+
const { unprocessedPuts, unprocessedDeletes } = await userEntity.send(new BatchWrite({
|
|
283
|
+
items: [
|
|
284
|
+
{ id: '123', name: 'User 1', email: 'user1@example.com' },
|
|
285
|
+
{ id: '456', name: 'User 2', email: 'user2@example.com' },
|
|
286
|
+
],
|
|
287
|
+
deletes: [
|
|
288
|
+
{ id: '789', email: 'user3@example.com' },
|
|
289
|
+
],
|
|
290
|
+
}));
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### TransactGet
|
|
294
|
+
|
|
295
|
+
Transactional read of multiple items:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
import { TransactGet } from 'dynamo-document-builder';
|
|
299
|
+
|
|
300
|
+
const { items } = await userEntity.send(new TransactGet({
|
|
301
|
+
keys: [
|
|
302
|
+
{ id: '123', email: 'johndoe@example.com' },
|
|
303
|
+
{ id: '456', email: 'janesmith@example.com' },
|
|
304
|
+
],
|
|
305
|
+
}));
|
|
306
|
+
|
|
307
|
+
// Items array has same order as keys
|
|
308
|
+
// Undefined if item not found
|
|
309
|
+
if (items[0]) {
|
|
310
|
+
console.log('First user:', items[0].name);
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### TransactWrite
|
|
315
|
+
|
|
316
|
+
Atomic multi-item write transaction:
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
import { TransactWrite, ConditionCheck } from 'dynamo-document-builder';
|
|
320
|
+
import { Put, Update, Delete } from 'dynamo-document-builder';
|
|
321
|
+
import { add, notExists } from 'dynamo-document-builder';
|
|
322
|
+
|
|
323
|
+
await userEntity.send(new TransactWrite({
|
|
324
|
+
writes: [
|
|
325
|
+
// Create new user
|
|
326
|
+
new Put({
|
|
327
|
+
item: {
|
|
328
|
+
id: '999',
|
|
329
|
+
name: 'New User',
|
|
330
|
+
email: 'newuser@example.com'
|
|
331
|
+
}
|
|
332
|
+
}),
|
|
333
|
+
// Update existing user
|
|
334
|
+
new Update({
|
|
335
|
+
key: { id: '123', email: 'johndoe@example.com' },
|
|
336
|
+
updates: { loginCount: add(1) }
|
|
337
|
+
}),
|
|
338
|
+
// Delete inactive user
|
|
339
|
+
new Delete({
|
|
340
|
+
key: { id: '456', email: 'janesmith@example.com' }
|
|
341
|
+
}),
|
|
342
|
+
// Verify another user exists
|
|
343
|
+
new ConditionCheck({
|
|
344
|
+
key: { id: '789', email: 'admin@example.com' },
|
|
345
|
+
condition: { role: 'admin' },
|
|
346
|
+
}),
|
|
347
|
+
],
|
|
348
|
+
}));
|
|
349
|
+
```
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Class to manage names and values for DynamoDB attribute expressions
|
|
5
|
+
*/
|
|
3
6
|
class AttributeExpressionMap {
|
|
4
7
|
constructor() {
|
|
5
8
|
Object.defineProperty(this, "attributeNames", {
|
|
@@ -45,6 +48,11 @@ class AttributeExpressionMap {
|
|
|
45
48
|
this.reverseLookupValues = new Map();
|
|
46
49
|
this.values = new Set();
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Adds an attribute name to the map and returns its placeholder
|
|
53
|
+
* @param name - The attribute name to add
|
|
54
|
+
* @returns The placeholder for the attribute name
|
|
55
|
+
*/
|
|
48
56
|
addName(name) {
|
|
49
57
|
if (this.names.has(name)) {
|
|
50
58
|
return this.reverseLookupNames[name];
|
|
@@ -55,6 +63,11 @@ class AttributeExpressionMap {
|
|
|
55
63
|
this.names.add(name);
|
|
56
64
|
return placeholder;
|
|
57
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Adds an attribute value to the map and returns its placeholder
|
|
68
|
+
* @param value - The attribute value to add
|
|
69
|
+
* @returns The placeholder for the attribute value
|
|
70
|
+
*/
|
|
58
71
|
addValue(value) {
|
|
59
72
|
if (this.values.has(value)) {
|
|
60
73
|
return this.reverseLookupValues.get(value);
|
|
@@ -65,15 +78,30 @@ class AttributeExpressionMap {
|
|
|
65
78
|
this.values.add(value);
|
|
66
79
|
return valuePlaceholder;
|
|
67
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Adds both an attribute name and value to the map and returns their placeholders
|
|
83
|
+
* @param name - The attribute name to add
|
|
84
|
+
* @param value - The attribute value to add
|
|
85
|
+
* @returns A tuple containing the placeholders for the attribute name and value
|
|
86
|
+
*/
|
|
68
87
|
add(name, value) {
|
|
69
88
|
return [this.addName(name), this.addValue(value)];
|
|
70
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts the attribute names to DynamoDB format
|
|
92
|
+
*/
|
|
71
93
|
toDynamoAttributeNames() {
|
|
72
94
|
return this.attributeNames;
|
|
73
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Converts the attribute values to DynamoDB format
|
|
98
|
+
*/
|
|
74
99
|
toDynamoAttributeValues() {
|
|
75
100
|
return this.attributeValues;
|
|
76
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Converts both attribute names and values to DynamoDB format
|
|
104
|
+
*/
|
|
77
105
|
toDynamoAttributeExpression() {
|
|
78
106
|
const expression = {};
|
|
79
107
|
if (this.names.size > 0) {
|
|
@@ -84,27 +112,51 @@ class AttributeExpressionMap {
|
|
|
84
112
|
}
|
|
85
113
|
return expression;
|
|
86
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the map contains a specific attribute name
|
|
117
|
+
*/
|
|
87
118
|
hasName(name) {
|
|
88
119
|
return this.names.has(name);
|
|
89
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Checks if the map contains a specific attribute value
|
|
123
|
+
*/
|
|
90
124
|
hasValue(value) {
|
|
91
125
|
return this.values.has(value);
|
|
92
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Retrieves the placeholder for a given attribute name, or `undefined` if not found
|
|
129
|
+
*/
|
|
93
130
|
getPlaceholderFromName(name) {
|
|
94
131
|
return this.reverseLookupNames[name];
|
|
95
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Retrieves the placeholder for a given attribute value, or `undefined` if not found
|
|
135
|
+
*/
|
|
96
136
|
getPlaceholderFromValue(value) {
|
|
97
137
|
return this.reverseLookupValues.get(value);
|
|
98
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Retrieves the attribute name for a given placeholder, or `undefined` if not found
|
|
141
|
+
*/
|
|
99
142
|
getNameFromPlaceholder(placeholder) {
|
|
100
143
|
return this.attributeNames[placeholder];
|
|
101
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Retrieves the attribute value for a given placeholder, or `undefined` if not found
|
|
147
|
+
*/
|
|
102
148
|
getValueFromPlaceholder(placeholder) {
|
|
103
149
|
return this.attributeValues[placeholder];
|
|
104
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Gets the count of unique attribute names in the map
|
|
153
|
+
*/
|
|
105
154
|
getNameCount() {
|
|
106
155
|
return this.names.size;
|
|
107
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Gets the count of unique attribute values in the map
|
|
159
|
+
*/
|
|
108
160
|
getValueCount() {
|
|
109
161
|
return this.values.size;
|
|
110
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribute-map.cjs","sources":["../../src/attributes/attribute-map.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"attribute-map.cjs","sources":["../../src/attributes/attribute-map.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA8BA;;AAEG;MACU,sBAAsB,CAAA;AASjC,IAAA,WAAA,GAAA;AARQ,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,gBAAA,EAAA;;;;;AAAwD,SAAA,CAAA;AACxD,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,oBAAA,EAAA;;;;;AAA4D,SAAA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AAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;IAC/B;AAEA;;AAEG;AACI,IAAA,sBAAsB,CAAC,IAAY,EAAA;AACxC,QAAA,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC;IACtC;AAEA;;AAEG;AACI,IAAA,uBAAuB,CAC5B,KAA2B,EAAA;QAE3B,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC;IAC5C;AAEA;;AAEG;AACI,IAAA,sBAAsB,CAAC,WAAqC,EAAA;AACjE,QAAA,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;IACzC;AAEA;;AAEG;AACI,IAAA,uBAAuB,CAC5B,WAAsC,EAAA;AAEtC,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC;IAC1C;AAEA;;AAEG;IACI,YAAY,GAAA;AACjB,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI;IACxB;AAEA;;AAEG;IACI,aAAa,GAAA;AAClB,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;AACD;;;;"}
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import { NativeAttributeValue } from '@aws-sdk/lib-dynamodb';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Record type for DynamoDB attribute values
|
|
5
|
+
*/
|
|
3
6
|
type AttributeValues = Record<string, NativeAttributeValue>;
|
|
7
|
+
/**
|
|
8
|
+
* Record type for DynamoDB attribute names
|
|
9
|
+
*/
|
|
4
10
|
type AttributeNames = Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Type representing DynamoDB attribute expression
|
|
13
|
+
*/
|
|
5
14
|
type DynamoAttributeExpression = {
|
|
6
15
|
ExpressionAttributeValues?: AttributeValues | undefined;
|
|
7
16
|
ExpressionAttributeNames?: AttributeNames | undefined;
|
|
8
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Type representing a placeholder for an attribute expression value
|
|
20
|
+
*/
|
|
9
21
|
type AttributeValuePlaceholder = `:${string}`;
|
|
22
|
+
/**
|
|
23
|
+
* Type representing a placeholder for an attribute expression name
|
|
24
|
+
*/
|
|
10
25
|
type AttributeNamePlaceholder = `#${string}`;
|
|
26
|
+
/**
|
|
27
|
+
* Class to manage names and values for DynamoDB attribute expressions
|
|
28
|
+
*/
|
|
11
29
|
declare class AttributeExpressionMap {
|
|
12
30
|
private attributeNames;
|
|
13
31
|
private reverseLookupNames;
|
|
@@ -16,19 +34,68 @@ declare class AttributeExpressionMap {
|
|
|
16
34
|
private reverseLookupValues;
|
|
17
35
|
private values;
|
|
18
36
|
constructor();
|
|
37
|
+
/**
|
|
38
|
+
* Adds an attribute name to the map and returns its placeholder
|
|
39
|
+
* @param name - The attribute name to add
|
|
40
|
+
* @returns The placeholder for the attribute name
|
|
41
|
+
*/
|
|
19
42
|
addName(name: string): AttributeNamePlaceholder;
|
|
43
|
+
/**
|
|
44
|
+
* Adds an attribute value to the map and returns its placeholder
|
|
45
|
+
* @param value - The attribute value to add
|
|
46
|
+
* @returns The placeholder for the attribute value
|
|
47
|
+
*/
|
|
20
48
|
addValue(value: NativeAttributeValue): AttributeValuePlaceholder;
|
|
49
|
+
/**
|
|
50
|
+
* Adds both an attribute name and value to the map and returns their placeholders
|
|
51
|
+
* @param name - The attribute name to add
|
|
52
|
+
* @param value - The attribute value to add
|
|
53
|
+
* @returns A tuple containing the placeholders for the attribute name and value
|
|
54
|
+
*/
|
|
21
55
|
add(name: string, value: NativeAttributeValue): [AttributeNamePlaceholder, AttributeValuePlaceholder];
|
|
56
|
+
/**
|
|
57
|
+
* Converts the attribute names to DynamoDB format
|
|
58
|
+
*/
|
|
22
59
|
toDynamoAttributeNames(): AttributeNames;
|
|
60
|
+
/**
|
|
61
|
+
* Converts the attribute values to DynamoDB format
|
|
62
|
+
*/
|
|
23
63
|
toDynamoAttributeValues(): AttributeValues;
|
|
64
|
+
/**
|
|
65
|
+
* Converts both attribute names and values to DynamoDB format
|
|
66
|
+
*/
|
|
24
67
|
toDynamoAttributeExpression(): DynamoAttributeExpression;
|
|
68
|
+
/**
|
|
69
|
+
* Checks if the map contains a specific attribute name
|
|
70
|
+
*/
|
|
25
71
|
hasName(name: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if the map contains a specific attribute value
|
|
74
|
+
*/
|
|
26
75
|
hasValue(value: NativeAttributeValue): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves the placeholder for a given attribute name, or `undefined` if not found
|
|
78
|
+
*/
|
|
27
79
|
getPlaceholderFromName(name: string): AttributeNamePlaceholder | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves the placeholder for a given attribute value, or `undefined` if not found
|
|
82
|
+
*/
|
|
28
83
|
getPlaceholderFromValue(value: NativeAttributeValue): AttributeValuePlaceholder | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Retrieves the attribute name for a given placeholder, or `undefined` if not found
|
|
86
|
+
*/
|
|
29
87
|
getNameFromPlaceholder(placeholder: AttributeNamePlaceholder): string | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Retrieves the attribute value for a given placeholder, or `undefined` if not found
|
|
90
|
+
*/
|
|
30
91
|
getValueFromPlaceholder(placeholder: AttributeValuePlaceholder): NativeAttributeValue | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Gets the count of unique attribute names in the map
|
|
94
|
+
*/
|
|
31
95
|
getNameCount(): number;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the count of unique attribute values in the map
|
|
98
|
+
*/
|
|
32
99
|
getValueCount(): number;
|
|
33
100
|
}
|
|
34
101
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to manage names and values for DynamoDB attribute expressions
|
|
3
|
+
*/
|
|
1
4
|
class AttributeExpressionMap {
|
|
2
5
|
constructor() {
|
|
3
6
|
Object.defineProperty(this, "attributeNames", {
|
|
@@ -43,6 +46,11 @@ class AttributeExpressionMap {
|
|
|
43
46
|
this.reverseLookupValues = new Map();
|
|
44
47
|
this.values = new Set();
|
|
45
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Adds an attribute name to the map and returns its placeholder
|
|
51
|
+
* @param name - The attribute name to add
|
|
52
|
+
* @returns The placeholder for the attribute name
|
|
53
|
+
*/
|
|
46
54
|
addName(name) {
|
|
47
55
|
if (this.names.has(name)) {
|
|
48
56
|
return this.reverseLookupNames[name];
|
|
@@ -53,6 +61,11 @@ class AttributeExpressionMap {
|
|
|
53
61
|
this.names.add(name);
|
|
54
62
|
return placeholder;
|
|
55
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Adds an attribute value to the map and returns its placeholder
|
|
66
|
+
* @param value - The attribute value to add
|
|
67
|
+
* @returns The placeholder for the attribute value
|
|
68
|
+
*/
|
|
56
69
|
addValue(value) {
|
|
57
70
|
if (this.values.has(value)) {
|
|
58
71
|
return this.reverseLookupValues.get(value);
|
|
@@ -63,15 +76,30 @@ class AttributeExpressionMap {
|
|
|
63
76
|
this.values.add(value);
|
|
64
77
|
return valuePlaceholder;
|
|
65
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Adds both an attribute name and value to the map and returns their placeholders
|
|
81
|
+
* @param name - The attribute name to add
|
|
82
|
+
* @param value - The attribute value to add
|
|
83
|
+
* @returns A tuple containing the placeholders for the attribute name and value
|
|
84
|
+
*/
|
|
66
85
|
add(name, value) {
|
|
67
86
|
return [this.addName(name), this.addValue(value)];
|
|
68
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Converts the attribute names to DynamoDB format
|
|
90
|
+
*/
|
|
69
91
|
toDynamoAttributeNames() {
|
|
70
92
|
return this.attributeNames;
|
|
71
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Converts the attribute values to DynamoDB format
|
|
96
|
+
*/
|
|
72
97
|
toDynamoAttributeValues() {
|
|
73
98
|
return this.attributeValues;
|
|
74
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Converts both attribute names and values to DynamoDB format
|
|
102
|
+
*/
|
|
75
103
|
toDynamoAttributeExpression() {
|
|
76
104
|
const expression = {};
|
|
77
105
|
if (this.names.size > 0) {
|
|
@@ -82,27 +110,51 @@ class AttributeExpressionMap {
|
|
|
82
110
|
}
|
|
83
111
|
return expression;
|
|
84
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the map contains a specific attribute name
|
|
115
|
+
*/
|
|
85
116
|
hasName(name) {
|
|
86
117
|
return this.names.has(name);
|
|
87
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Checks if the map contains a specific attribute value
|
|
121
|
+
*/
|
|
88
122
|
hasValue(value) {
|
|
89
123
|
return this.values.has(value);
|
|
90
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Retrieves the placeholder for a given attribute name, or `undefined` if not found
|
|
127
|
+
*/
|
|
91
128
|
getPlaceholderFromName(name) {
|
|
92
129
|
return this.reverseLookupNames[name];
|
|
93
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Retrieves the placeholder for a given attribute value, or `undefined` if not found
|
|
133
|
+
*/
|
|
94
134
|
getPlaceholderFromValue(value) {
|
|
95
135
|
return this.reverseLookupValues.get(value);
|
|
96
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Retrieves the attribute name for a given placeholder, or `undefined` if not found
|
|
139
|
+
*/
|
|
97
140
|
getNameFromPlaceholder(placeholder) {
|
|
98
141
|
return this.attributeNames[placeholder];
|
|
99
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves the attribute value for a given placeholder, or `undefined` if not found
|
|
145
|
+
*/
|
|
100
146
|
getValueFromPlaceholder(placeholder) {
|
|
101
147
|
return this.attributeValues[placeholder];
|
|
102
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets the count of unique attribute names in the map
|
|
151
|
+
*/
|
|
103
152
|
getNameCount() {
|
|
104
153
|
return this.names.size;
|
|
105
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Gets the count of unique attribute values in the map
|
|
157
|
+
*/
|
|
106
158
|
getValueCount() {
|
|
107
159
|
return this.values.size;
|
|
108
160
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribute-map.mjs","sources":["../../src/attributes/attribute-map.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"attribute-map.mjs","sources":["../../src/attributes/attribute-map.ts"],"sourcesContent":[null],"names":[],"mappings":"AA8BA;;AAEG;MACU,sBAAsB,CAAA;AASjC,IAAA,WAAA,GAAA;AARQ,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,gBAAA,EAAA;;;;;AAAwD,SAAA,CAAA;AACxD,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,oBAAA,EAAA;;;;;AAA4D,SAAA,CAAA;AAC5D,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,OAAA,EAAA;;;;;AAAkB,SAAA,CAAA;AAElB,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,iBAAA,EAAA;;;;;AAAwE,SAAA,CAAA;AACxE,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,qBAAA,EAAA;;;;;AAAyE,SAAA,CAAA;AACzE,QAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,QAAA,EAAA;;;;;AAAmB,SAAA,CAAA;AAGzB,QAAA,IAAI,CAAC,cAAc,GAAG,EAAE;AACxB,QAAA,IAAI,CAAC,kBAAkB,GAAG,EAAE;AAC5B,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAU;AAC9B,QAAA,IAAI,CAAC,eAAe,GAAG,EAAE;AACzB,QAAA,IAAI,CAAC,mBAAmB,GAAG,IAAI,GAAG,EAAmD;AACrF,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAU;IACjC;AAEA;;;;AAIG;AACI,IAAA,OAAO,CAAC,IAAY,EAAA;QACzB,IAAI,IAAI,CAAC,KA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@aws-sdk/lib-dynamodb');
|
|
|
6
6
|
var pMap = require('p-map');
|
|
7
7
|
|
|
8
8
|
var _BatchGet_config;
|
|
9
|
+
/**
|
|
10
|
+
* Command to perform a batch get operation on a DynamoDB table.
|
|
11
|
+
*
|
|
12
|
+
* @template Schema - The Zod schema defining the structure of the entity.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { DynamoTable, DynamoEntity, key, BatchGet } from 'dynamo-document-builder';
|
|
17
|
+
*
|
|
18
|
+
* const table = new DynamoTable({
|
|
19
|
+
* tableName: 'ExampleTable',
|
|
20
|
+
* documentClient,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const userEntity = new DynamoEntity({
|
|
24
|
+
* table,
|
|
25
|
+
* schema: z.object({
|
|
26
|
+
* userId: z.string(),
|
|
27
|
+
* name: z.string(),
|
|
28
|
+
* age: z.number(),
|
|
29
|
+
* }),
|
|
30
|
+
* partitionKey: user => key('USER', user.userId),
|
|
31
|
+
* sortKey: () => 'USER',
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const batchGetCommand = new BatchGet({
|
|
35
|
+
* keys: [
|
|
36
|
+
* { userId: 'user1' },
|
|
37
|
+
* { userId: 'user2' },
|
|
38
|
+
* ],
|
|
39
|
+
* consistent: true,
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* const { items } = await batchGetCommand.execute(userEntity);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
9
45
|
class BatchGet {
|
|
10
46
|
constructor(config) {
|
|
11
47
|
_BatchGet_config.set(this, void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-get.cjs","sources":["../../src/commands/batch-get.ts"],"sourcesContent":[null],"names":["__classPrivateFieldSet","BatchGetCommand","__classPrivateFieldGet","BATCH_GET_VALIDATION_CONCURRENCY"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"batch-get.cjs","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