@infra-blocks/aws-dynamodb 0.52.0 → 0.53.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/lib/cjs/client.d.ts +8 -2
- package/lib/cjs/client.js +46 -125
- package/lib/cjs/client.js.map +1 -1
- package/lib/cjs/error.d.ts +6 -4
- package/lib/cjs/error.js +13 -6
- package/lib/cjs/error.js.map +1 -1
- package/lib/esm/client.d.ts +8 -2
- package/lib/esm/client.js +47 -126
- package/lib/esm/client.js.map +1 -1
- package/lib/esm/error.d.ts +6 -4
- package/lib/esm/error.js +11 -4
- package/lib/esm/error.js.map +1 -1
- package/package.json +1 -1
package/lib/cjs/client.d.ts
CHANGED
|
@@ -145,11 +145,17 @@ export declare class DynamoDbClient {
|
|
|
145
145
|
*/
|
|
146
146
|
query<K extends KeyAttributes, T extends Attributes = Attributes>(params: QueryParams<K>): Promise<QueryResult<K, T>>;
|
|
147
147
|
/**
|
|
148
|
-
* Convenience method over the {@link
|
|
148
|
+
* Convenience method over the {@link query} method enforcing that the query
|
|
149
149
|
* matches at most one item.
|
|
150
150
|
*
|
|
151
151
|
* If the query doesn't match any item, then `undefined` is returned. If there are
|
|
152
|
-
* matches, then the function
|
|
152
|
+
* matches, then the function enforces there is only one.
|
|
153
|
+
*
|
|
154
|
+
* Otherwise, it throws a custom exception of type {@link TooManyItemsException}.
|
|
155
|
+
*
|
|
156
|
+
* This query can be useful in conjunction with an index, where the key is not guaranteed
|
|
157
|
+
* to be unique, unlike `getItem` for the table. It can also be useful in the case where
|
|
158
|
+
* the sort key of an item is unknown, expected to match a {@link KeyConditionExpression} uniquely.
|
|
153
159
|
*
|
|
154
160
|
* @param params - The parameters to use to query the table or index.
|
|
155
161
|
*
|
package/lib/cjs/client.js
CHANGED
|
@@ -39,15 +39,8 @@ class DynamoDbClient {
|
|
|
39
39
|
if (this.logger.isDebugEnabled()) {
|
|
40
40
|
this.logger.debug("createTable(%s)", JSON.stringify(params));
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
await this.client.send(command.toAwsCommand());
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
throw new error_js_1.DynamoDbClientError("error while creating table", {
|
|
48
|
-
cause: err,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
42
|
+
const command = create_table_js_1.CreateTable.from(params);
|
|
43
|
+
await this.client.send(command.toAwsCommand());
|
|
51
44
|
}
|
|
52
45
|
/**
|
|
53
46
|
* Deletes an item using the DeleteItem API.
|
|
@@ -56,20 +49,13 @@ class DynamoDbClient {
|
|
|
56
49
|
*
|
|
57
50
|
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html
|
|
58
51
|
*/
|
|
59
|
-
|
|
52
|
+
deleteItem(params) {
|
|
60
53
|
if (this.logger.isDebugEnabled()) {
|
|
61
54
|
this.logger.debug("deleteItem(%s)", JSON.stringify(params));
|
|
62
55
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
throw new error_js_1.DynamoDbClientError("error while deleting item", {
|
|
70
|
-
cause: err,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
56
|
+
return delete_item_js_1.DeleteItem.from(params).execute({
|
|
57
|
+
client: this.client,
|
|
58
|
+
});
|
|
73
59
|
}
|
|
74
60
|
/**
|
|
75
61
|
* Deletes a table using the DeleteTable API.
|
|
@@ -82,15 +68,8 @@ class DynamoDbClient {
|
|
|
82
68
|
if (this.logger.isDebugEnabled()) {
|
|
83
69
|
this.logger.debug("deleteTable(%s)", JSON.stringify(params));
|
|
84
70
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await this.client.send(command.toAwsCommand());
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
throw new error_js_1.DynamoDbClientError("error while deleting table", {
|
|
91
|
-
cause: err,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
71
|
+
const command = delete_table_js_1.DeleteTable.from(params);
|
|
72
|
+
await this.client.send(command.toAwsCommand());
|
|
94
73
|
}
|
|
95
74
|
/**
|
|
96
75
|
* Gets an item using the GetItem API.
|
|
@@ -106,15 +85,8 @@ class DynamoDbClient {
|
|
|
106
85
|
if (this.logger.isDebugEnabled()) {
|
|
107
86
|
this.logger.debug("getItem(%s)", JSON.stringify(params));
|
|
108
87
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return (0, types_1.trusted)(response.Item);
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
throw new error_js_1.DynamoDbClientError(`error while getting item from DynamoDB: ${JSON.stringify(params)}`, {
|
|
115
|
-
cause: err,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
88
|
+
const response = await this.client.send(get_item_js_1.GetItem.from(params).toAwsCommand());
|
|
89
|
+
return (0, types_1.trusted)(response.Item);
|
|
118
90
|
}
|
|
119
91
|
/**
|
|
120
92
|
* Puts an item using the PutItem API.
|
|
@@ -127,20 +99,13 @@ class DynamoDbClient {
|
|
|
127
99
|
*
|
|
128
100
|
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html
|
|
129
101
|
*/
|
|
130
|
-
|
|
102
|
+
putItem(params) {
|
|
131
103
|
if (this.logger.isDebugEnabled()) {
|
|
132
104
|
this.logger.debug("putItem(%s)", JSON.stringify(params));
|
|
133
105
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
catch (err) {
|
|
140
|
-
throw new error_js_1.DynamoDbClientError("error while putting item", {
|
|
141
|
-
cause: err,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
106
|
+
return put_item_js_1.PutItem.from(params).execute({
|
|
107
|
+
client: this.client,
|
|
108
|
+
});
|
|
144
109
|
}
|
|
145
110
|
/**
|
|
146
111
|
* Iterates the items produced querying a table, or an index, using the Query API.
|
|
@@ -159,18 +124,11 @@ class DynamoDbClient {
|
|
|
159
124
|
if (this.logger.isDebugEnabled()) {
|
|
160
125
|
this.logger.debug("iterateQuery(%s)", JSON.stringify(params));
|
|
161
126
|
}
|
|
162
|
-
|
|
163
|
-
for
|
|
164
|
-
|
|
165
|
-
yield item;
|
|
166
|
-
}
|
|
127
|
+
for await (const page of this.paginateQuery(params)) {
|
|
128
|
+
for (const item of page.items) {
|
|
129
|
+
yield item;
|
|
167
130
|
}
|
|
168
131
|
}
|
|
169
|
-
catch (err) {
|
|
170
|
-
throw new error_js_1.DynamoDbClientError("error while iterating table query", {
|
|
171
|
-
cause: err,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
132
|
}
|
|
175
133
|
/**
|
|
176
134
|
* Paginates the result of querying a table, or an index, using the Query API.
|
|
@@ -189,21 +147,14 @@ class DynamoDbClient {
|
|
|
189
147
|
if (this.logger.isDebugEnabled()) {
|
|
190
148
|
this.logger.debug("paginateQuery(%s)", JSON.stringify(params));
|
|
191
149
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
exclusiveStartKey: page.lastEvaluatedKey,
|
|
199
|
-
});
|
|
200
|
-
yield page;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
catch (err) {
|
|
204
|
-
throw new error_js_1.DynamoDbClientError("error while paginating table query", {
|
|
205
|
-
cause: err,
|
|
150
|
+
let page = await this.query(params);
|
|
151
|
+
yield page;
|
|
152
|
+
while (page.lastEvaluatedKey != null) {
|
|
153
|
+
page = await this.query({
|
|
154
|
+
...params,
|
|
155
|
+
exclusiveStartKey: page.lastEvaluatedKey,
|
|
206
156
|
});
|
|
157
|
+
yield page;
|
|
207
158
|
}
|
|
208
159
|
}
|
|
209
160
|
/**
|
|
@@ -220,48 +171,39 @@ class DynamoDbClient {
|
|
|
220
171
|
*
|
|
221
172
|
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
|
|
222
173
|
*/
|
|
223
|
-
|
|
174
|
+
query(params) {
|
|
224
175
|
if (this.logger.isDebugEnabled()) {
|
|
225
176
|
this.logger.debug("query(%s)", JSON.stringify(params));
|
|
226
177
|
}
|
|
227
|
-
|
|
228
|
-
return await query_js_1.Query.from(params).execute({ client: this.client });
|
|
229
|
-
}
|
|
230
|
-
catch (err) {
|
|
231
|
-
throw new error_js_1.DynamoDbClientError("error while querying table", {
|
|
232
|
-
cause: err,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
178
|
+
return query_js_1.Query.from(params).execute({ client: this.client });
|
|
235
179
|
}
|
|
236
180
|
/**
|
|
237
|
-
* Convenience method over the {@link
|
|
181
|
+
* Convenience method over the {@link query} method enforcing that the query
|
|
238
182
|
* matches at most one item.
|
|
239
183
|
*
|
|
240
184
|
* If the query doesn't match any item, then `undefined` is returned. If there are
|
|
241
|
-
* matches, then the function
|
|
185
|
+
* matches, then the function enforces there is only one.
|
|
186
|
+
*
|
|
187
|
+
* Otherwise, it throws a custom exception of type {@link TooManyItemsException}.
|
|
188
|
+
*
|
|
189
|
+
* This query can be useful in conjunction with an index, where the key is not guaranteed
|
|
190
|
+
* to be unique, unlike `getItem` for the table. It can also be useful in the case where
|
|
191
|
+
* the sort key of an item is unknown, expected to match a {@link KeyConditionExpression} uniquely.
|
|
242
192
|
*
|
|
243
193
|
* @param params - The parameters to use to query the table or index.
|
|
244
194
|
*
|
|
245
195
|
* @returns The only item matching the query, or `undefined` if no item matches.
|
|
246
196
|
*/
|
|
247
197
|
async queryOne(params) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
throw new error_js_1.DynamoDbClientError("expected one item in query but found at least 2");
|
|
254
|
-
}
|
|
255
|
-
item = queryItem;
|
|
198
|
+
let item;
|
|
199
|
+
// TODO: page of only 2 items, remove limit from parameters.
|
|
200
|
+
for await (const queryItem of this.iterateQuery(params)) {
|
|
201
|
+
if (item != null) {
|
|
202
|
+
throw error_js_1.TooManyItemsException.queryingOne(params);
|
|
256
203
|
}
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
catch (err) {
|
|
260
|
-
// TODO: careful here as email is PII.
|
|
261
|
-
throw new error_js_1.DynamoDbClientError(`error while querying one: ${JSON.stringify(params)}`, {
|
|
262
|
-
cause: err,
|
|
263
|
-
});
|
|
204
|
+
item = queryItem;
|
|
264
205
|
}
|
|
206
|
+
return item;
|
|
265
207
|
}
|
|
266
208
|
/**
|
|
267
209
|
* Awaits until the DynamoDB service is ready to accept requests.
|
|
@@ -305,15 +247,8 @@ class DynamoDbClient {
|
|
|
305
247
|
if (this.logger.isDebugEnabled()) {
|
|
306
248
|
this.logger.debug("updateItem(%s)", JSON.stringify(params));
|
|
307
249
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
await this.client.send(command.toAwsCommand());
|
|
311
|
-
}
|
|
312
|
-
catch (err) {
|
|
313
|
-
throw new error_js_1.DynamoDbClientError("error while updating item", {
|
|
314
|
-
cause: err,
|
|
315
|
-
});
|
|
316
|
-
}
|
|
250
|
+
const command = update_item_js_1.UpdateItem.from(params);
|
|
251
|
+
await this.client.send(command.toAwsCommand());
|
|
317
252
|
}
|
|
318
253
|
/**
|
|
319
254
|
* Updates the time to live settings of a table using the UpdateTimeToLive API.
|
|
@@ -326,15 +261,8 @@ class DynamoDbClient {
|
|
|
326
261
|
if (this.logger.isDebugEnabled()) {
|
|
327
262
|
this.logger.debug("updateTimeToLive(%s)", JSON.stringify(params));
|
|
328
263
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
await this.client.send(command.toAwsCommand());
|
|
332
|
-
}
|
|
333
|
-
catch (err) {
|
|
334
|
-
throw new error_js_1.DynamoDbClientError("error while updating time to live", {
|
|
335
|
-
cause: err,
|
|
336
|
-
});
|
|
337
|
-
}
|
|
264
|
+
const command = update_time_to_live_js_1.UpdateTimeToLive.from(params);
|
|
265
|
+
await this.client.send(command.toAwsCommand());
|
|
338
266
|
}
|
|
339
267
|
/**
|
|
340
268
|
* Executes a write transaction using the TransactWriteItems API.
|
|
@@ -347,14 +275,7 @@ class DynamoDbClient {
|
|
|
347
275
|
if (this.logger.isDebugEnabled()) {
|
|
348
276
|
this.logger.debug("transactWriteItems(%s)", JSON.stringify(params));
|
|
349
277
|
}
|
|
350
|
-
|
|
351
|
-
await this.client.send(write_transaction_js_1.WriteTransaction.from(params).toAwsCommand());
|
|
352
|
-
}
|
|
353
|
-
catch (err) {
|
|
354
|
-
throw new error_js_1.DynamoDbClientError("error while transactionally writing items in DynamoDB", {
|
|
355
|
-
cause: err,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
278
|
+
await this.client.send(write_transaction_js_1.WriteTransaction.from(params).toAwsCommand());
|
|
358
279
|
}
|
|
359
280
|
/**
|
|
360
281
|
* Alias for the {@link putItem} method.
|
package/lib/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AACA,8DAA6E;AAE7E,wDAA+D;AAE/D,2DAAuD;AACvD,+CAA0E;AAC1E,+CAA8C;AAC9C,gEAGoC;AACpC,gEAGoC;AACpC,8DAImC;AACnC,wDAAqE;AACrE,wDAIgC;AAChC,kDAAgF;AAChF,8DAA8E;AAC9E,8EAG2C;AAC3C,0EAGyC;AACzC,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AACA,8DAA6E;AAE7E,wDAA+D;AAE/D,2DAAuD;AACvD,+CAA0E;AAC1E,+CAA8C;AAC9C,gEAGoC;AACpC,gEAGoC;AACpC,8DAImC;AACnC,wDAAqE;AACrE,wDAIgC;AAChC,kDAAgF;AAChF,8DAA8E;AAC9E,8EAG2C;AAC3C,0EAGyC;AACzC,yCAAmD;AAuCnD;;;GAGG;AACH,MAAa,cAAc;IACR,MAAM,CAAyB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,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;AAhXD,wCAgXC"}
|
package/lib/cjs/error.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { QueryParams } from "./commands/query.js";
|
|
2
|
+
export declare class TooManyItemsException extends Error {
|
|
3
|
+
readonly operation: "queryOne";
|
|
4
|
+
readonly name: "TooManyItemsException";
|
|
5
|
+
private constructor();
|
|
6
|
+
static queryingOne(params: QueryParams): TooManyItemsException;
|
|
5
7
|
}
|
|
6
8
|
export type TransactionCanceledCheck = {
|
|
7
9
|
index: number;
|
package/lib/cjs/error.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConditionalCheckFailed = exports.
|
|
3
|
+
exports.ConditionalCheckFailed = exports.TooManyItemsException = void 0;
|
|
4
4
|
exports.isTransactionCanceledBy = isTransactionCanceledBy;
|
|
5
5
|
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
6
6
|
const error_1 = require("@infra-blocks/error");
|
|
7
|
-
class
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
class TooManyItemsException extends Error {
|
|
8
|
+
operation;
|
|
9
|
+
name;
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.operation = "queryOne";
|
|
13
|
+
this.name = "TooManyItemsException";
|
|
14
|
+
}
|
|
15
|
+
static queryingOne(params) {
|
|
16
|
+
const { table, index } = params;
|
|
17
|
+
return new TooManyItemsException(`found multiple items while querying one on ${JSON.stringify({ table, index })}`);
|
|
11
18
|
}
|
|
12
19
|
}
|
|
13
|
-
exports.
|
|
20
|
+
exports.TooManyItemsException = TooManyItemsException;
|
|
14
21
|
exports.ConditionalCheckFailed = {
|
|
15
22
|
atIndex(index) {
|
|
16
23
|
return { index, code: "ConditionalCheckFailed" };
|
package/lib/cjs/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";;;AAsDA,0DAUC;AAhED,8DAAwE;AACxE,+CAAsD;AAGtD,MAAa,qBAAsB,SAAQ,KAAK;IACrC,SAAS,CAAa;IACtB,IAAI,CAA0B;IAEvC,YAAoB,OAAe;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAmB;QACpC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QAEhC,OAAO,IAAI,qBAAqB,CAC9B,8CAA8C,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CACjF,CAAC;IACJ,CAAC;CACF;AAjBD,sDAiBC;AAWY,QAAA,sBAAsB,GAAoC;IACrE,OAAO,CAAC,KAAa;QACnB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;IACnD,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,uBAAuB,CACrC,GAAY,EACZ,MAAgC;IAEhC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,gBAAgB,GAAG,IAAA,uBAAe,EAAC,GAAG,EAAE,8CAA4B,CAAC,CAAC;IAC5E,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAgB,CAAC,mBAAmB,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AACrE,CAAC"}
|
package/lib/esm/client.d.ts
CHANGED
|
@@ -145,11 +145,17 @@ export declare class DynamoDbClient {
|
|
|
145
145
|
*/
|
|
146
146
|
query<K extends KeyAttributes, T extends Attributes = Attributes>(params: QueryParams<K>): Promise<QueryResult<K, T>>;
|
|
147
147
|
/**
|
|
148
|
-
* Convenience method over the {@link
|
|
148
|
+
* Convenience method over the {@link query} method enforcing that the query
|
|
149
149
|
* matches at most one item.
|
|
150
150
|
*
|
|
151
151
|
* If the query doesn't match any item, then `undefined` is returned. If there are
|
|
152
|
-
* matches, then the function
|
|
152
|
+
* matches, then the function enforces there is only one.
|
|
153
|
+
*
|
|
154
|
+
* Otherwise, it throws a custom exception of type {@link TooManyItemsException}.
|
|
155
|
+
*
|
|
156
|
+
* This query can be useful in conjunction with an index, where the key is not guaranteed
|
|
157
|
+
* to be unique, unlike `getItem` for the table. It can also be useful in the case where
|
|
158
|
+
* the sort key of an item is unknown, expected to match a {@link KeyConditionExpression} uniquely.
|
|
153
159
|
*
|
|
154
160
|
* @param params - The parameters to use to query the table or index.
|
|
155
161
|
*
|
package/lib/esm/client.js
CHANGED
|
@@ -12,7 +12,7 @@ import { Query } from "./commands/query.js";
|
|
|
12
12
|
import { UpdateItem } from "./commands/update-item.js";
|
|
13
13
|
import { UpdateTimeToLive, } from "./commands/update-time-to-live.js";
|
|
14
14
|
import { WriteTransaction, } from "./commands/write-transaction.js";
|
|
15
|
-
import {
|
|
15
|
+
import { TooManyItemsException } from "./error.js";
|
|
16
16
|
/**
|
|
17
17
|
* Wrapper class around the {@link DynamoDBDocumentClient} that provides added functionality,
|
|
18
18
|
* safer types and some convenience methods.
|
|
@@ -36,15 +36,8 @@ export class DynamoDbClient {
|
|
|
36
36
|
if (this.logger.isDebugEnabled()) {
|
|
37
37
|
this.logger.debug("createTable(%s)", JSON.stringify(params));
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
await this.client.send(command.toAwsCommand());
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
throw new DynamoDbClientError("error while creating table", {
|
|
45
|
-
cause: err,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
39
|
+
const command = CreateTable.from(params);
|
|
40
|
+
await this.client.send(command.toAwsCommand());
|
|
48
41
|
}
|
|
49
42
|
/**
|
|
50
43
|
* Deletes an item using the DeleteItem API.
|
|
@@ -53,20 +46,13 @@ export class DynamoDbClient {
|
|
|
53
46
|
*
|
|
54
47
|
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html
|
|
55
48
|
*/
|
|
56
|
-
|
|
49
|
+
deleteItem(params) {
|
|
57
50
|
if (this.logger.isDebugEnabled()) {
|
|
58
51
|
this.logger.debug("deleteItem(%s)", JSON.stringify(params));
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
throw new DynamoDbClientError("error while deleting item", {
|
|
67
|
-
cause: err,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
53
|
+
return DeleteItem.from(params).execute({
|
|
54
|
+
client: this.client,
|
|
55
|
+
});
|
|
70
56
|
}
|
|
71
57
|
/**
|
|
72
58
|
* Deletes a table using the DeleteTable API.
|
|
@@ -79,15 +65,8 @@ export class DynamoDbClient {
|
|
|
79
65
|
if (this.logger.isDebugEnabled()) {
|
|
80
66
|
this.logger.debug("deleteTable(%s)", JSON.stringify(params));
|
|
81
67
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await this.client.send(command.toAwsCommand());
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
throw new DynamoDbClientError("error while deleting table", {
|
|
88
|
-
cause: err,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
68
|
+
const command = DeleteTable.from(params);
|
|
69
|
+
await this.client.send(command.toAwsCommand());
|
|
91
70
|
}
|
|
92
71
|
/**
|
|
93
72
|
* Gets an item using the GetItem API.
|
|
@@ -103,15 +82,8 @@ export class DynamoDbClient {
|
|
|
103
82
|
if (this.logger.isDebugEnabled()) {
|
|
104
83
|
this.logger.debug("getItem(%s)", JSON.stringify(params));
|
|
105
84
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return trusted(response.Item);
|
|
109
|
-
}
|
|
110
|
-
catch (err) {
|
|
111
|
-
throw new DynamoDbClientError(`error while getting item from DynamoDB: ${JSON.stringify(params)}`, {
|
|
112
|
-
cause: err,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
85
|
+
const response = await this.client.send(GetItem.from(params).toAwsCommand());
|
|
86
|
+
return trusted(response.Item);
|
|
115
87
|
}
|
|
116
88
|
/**
|
|
117
89
|
* Puts an item using the PutItem API.
|
|
@@ -124,20 +96,13 @@ export class DynamoDbClient {
|
|
|
124
96
|
*
|
|
125
97
|
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html
|
|
126
98
|
*/
|
|
127
|
-
|
|
99
|
+
putItem(params) {
|
|
128
100
|
if (this.logger.isDebugEnabled()) {
|
|
129
101
|
this.logger.debug("putItem(%s)", JSON.stringify(params));
|
|
130
102
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
throw new DynamoDbClientError("error while putting item", {
|
|
138
|
-
cause: err,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
103
|
+
return PutItem.from(params).execute({
|
|
104
|
+
client: this.client,
|
|
105
|
+
});
|
|
141
106
|
}
|
|
142
107
|
/**
|
|
143
108
|
* Iterates the items produced querying a table, or an index, using the Query API.
|
|
@@ -156,18 +121,11 @@ export class DynamoDbClient {
|
|
|
156
121
|
if (this.logger.isDebugEnabled()) {
|
|
157
122
|
this.logger.debug("iterateQuery(%s)", JSON.stringify(params));
|
|
158
123
|
}
|
|
159
|
-
|
|
160
|
-
for
|
|
161
|
-
|
|
162
|
-
yield item;
|
|
163
|
-
}
|
|
124
|
+
for await (const page of this.paginateQuery(params)) {
|
|
125
|
+
for (const item of page.items) {
|
|
126
|
+
yield item;
|
|
164
127
|
}
|
|
165
128
|
}
|
|
166
|
-
catch (err) {
|
|
167
|
-
throw new DynamoDbClientError("error while iterating table query", {
|
|
168
|
-
cause: err,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
129
|
}
|
|
172
130
|
/**
|
|
173
131
|
* Paginates the result of querying a table, or an index, using the Query API.
|
|
@@ -186,21 +144,14 @@ export class DynamoDbClient {
|
|
|
186
144
|
if (this.logger.isDebugEnabled()) {
|
|
187
145
|
this.logger.debug("paginateQuery(%s)", JSON.stringify(params));
|
|
188
146
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
exclusiveStartKey: page.lastEvaluatedKey,
|
|
196
|
-
});
|
|
197
|
-
yield page;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
throw new DynamoDbClientError("error while paginating table query", {
|
|
202
|
-
cause: err,
|
|
147
|
+
let page = await this.query(params);
|
|
148
|
+
yield page;
|
|
149
|
+
while (page.lastEvaluatedKey != null) {
|
|
150
|
+
page = await this.query({
|
|
151
|
+
...params,
|
|
152
|
+
exclusiveStartKey: page.lastEvaluatedKey,
|
|
203
153
|
});
|
|
154
|
+
yield page;
|
|
204
155
|
}
|
|
205
156
|
}
|
|
206
157
|
/**
|
|
@@ -217,48 +168,39 @@ export class DynamoDbClient {
|
|
|
217
168
|
*
|
|
218
169
|
* @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
|
|
219
170
|
*/
|
|
220
|
-
|
|
171
|
+
query(params) {
|
|
221
172
|
if (this.logger.isDebugEnabled()) {
|
|
222
173
|
this.logger.debug("query(%s)", JSON.stringify(params));
|
|
223
174
|
}
|
|
224
|
-
|
|
225
|
-
return await Query.from(params).execute({ client: this.client });
|
|
226
|
-
}
|
|
227
|
-
catch (err) {
|
|
228
|
-
throw new DynamoDbClientError("error while querying table", {
|
|
229
|
-
cause: err,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
175
|
+
return Query.from(params).execute({ client: this.client });
|
|
232
176
|
}
|
|
233
177
|
/**
|
|
234
|
-
* Convenience method over the {@link
|
|
178
|
+
* Convenience method over the {@link query} method enforcing that the query
|
|
235
179
|
* matches at most one item.
|
|
236
180
|
*
|
|
237
181
|
* If the query doesn't match any item, then `undefined` is returned. If there are
|
|
238
|
-
* matches, then the function
|
|
182
|
+
* matches, then the function enforces there is only one.
|
|
183
|
+
*
|
|
184
|
+
* Otherwise, it throws a custom exception of type {@link TooManyItemsException}.
|
|
185
|
+
*
|
|
186
|
+
* This query can be useful in conjunction with an index, where the key is not guaranteed
|
|
187
|
+
* to be unique, unlike `getItem` for the table. It can also be useful in the case where
|
|
188
|
+
* the sort key of an item is unknown, expected to match a {@link KeyConditionExpression} uniquely.
|
|
239
189
|
*
|
|
240
190
|
* @param params - The parameters to use to query the table or index.
|
|
241
191
|
*
|
|
242
192
|
* @returns The only item matching the query, or `undefined` if no item matches.
|
|
243
193
|
*/
|
|
244
194
|
async queryOne(params) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
throw new DynamoDbClientError("expected one item in query but found at least 2");
|
|
251
|
-
}
|
|
252
|
-
item = queryItem;
|
|
195
|
+
let item;
|
|
196
|
+
// TODO: page of only 2 items, remove limit from parameters.
|
|
197
|
+
for await (const queryItem of this.iterateQuery(params)) {
|
|
198
|
+
if (item != null) {
|
|
199
|
+
throw TooManyItemsException.queryingOne(params);
|
|
253
200
|
}
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
catch (err) {
|
|
257
|
-
// TODO: careful here as email is PII.
|
|
258
|
-
throw new DynamoDbClientError(`error while querying one: ${JSON.stringify(params)}`, {
|
|
259
|
-
cause: err,
|
|
260
|
-
});
|
|
201
|
+
item = queryItem;
|
|
261
202
|
}
|
|
203
|
+
return item;
|
|
262
204
|
}
|
|
263
205
|
/**
|
|
264
206
|
* Awaits until the DynamoDB service is ready to accept requests.
|
|
@@ -302,15 +244,8 @@ export class DynamoDbClient {
|
|
|
302
244
|
if (this.logger.isDebugEnabled()) {
|
|
303
245
|
this.logger.debug("updateItem(%s)", JSON.stringify(params));
|
|
304
246
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
await this.client.send(command.toAwsCommand());
|
|
308
|
-
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
throw new DynamoDbClientError("error while updating item", {
|
|
311
|
-
cause: err,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
247
|
+
const command = UpdateItem.from(params);
|
|
248
|
+
await this.client.send(command.toAwsCommand());
|
|
314
249
|
}
|
|
315
250
|
/**
|
|
316
251
|
* Updates the time to live settings of a table using the UpdateTimeToLive API.
|
|
@@ -323,15 +258,8 @@ export class DynamoDbClient {
|
|
|
323
258
|
if (this.logger.isDebugEnabled()) {
|
|
324
259
|
this.logger.debug("updateTimeToLive(%s)", JSON.stringify(params));
|
|
325
260
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
await this.client.send(command.toAwsCommand());
|
|
329
|
-
}
|
|
330
|
-
catch (err) {
|
|
331
|
-
throw new DynamoDbClientError("error while updating time to live", {
|
|
332
|
-
cause: err,
|
|
333
|
-
});
|
|
334
|
-
}
|
|
261
|
+
const command = UpdateTimeToLive.from(params);
|
|
262
|
+
await this.client.send(command.toAwsCommand());
|
|
335
263
|
}
|
|
336
264
|
/**
|
|
337
265
|
* Executes a write transaction using the TransactWriteItems API.
|
|
@@ -344,14 +272,7 @@ export class DynamoDbClient {
|
|
|
344
272
|
if (this.logger.isDebugEnabled()) {
|
|
345
273
|
this.logger.debug("transactWriteItems(%s)", JSON.stringify(params));
|
|
346
274
|
}
|
|
347
|
-
|
|
348
|
-
await this.client.send(WriteTransaction.from(params).toAwsCommand());
|
|
349
|
-
}
|
|
350
|
-
catch (err) {
|
|
351
|
-
throw new DynamoDbClientError("error while transactionally writing items in DynamoDB", {
|
|
352
|
-
cause: err,
|
|
353
|
-
});
|
|
354
|
-
}
|
|
275
|
+
await this.client.send(WriteTransaction.from(params).toAwsCommand());
|
|
355
276
|
}
|
|
356
277
|
/**
|
|
357
278
|
* Alias for the {@link putItem} method.
|
package/lib/esm/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAgC,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EACL,WAAW,GAEZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,WAAW,GAEZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,UAAU,GAGX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,OAAO,EAAsB,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACL,OAAO,GAGR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,EAAsC,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAyB,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EACL,gBAAgB,GAEjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,gBAAgB,GAEjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAA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CAAC;QAED,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;IAEtB;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,IAAI,CAAC,MAGX;QACC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,CAAC;QACxD,OAAO,IAAI,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,MAAM,CAAC,MAAqB;QACjC,MAAM,CAAC,GAAG,MAAM,IAAI,EAAE,CAAC;QACvB,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACrB,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,sBAAsB,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;QACjE,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
|
package/lib/esm/error.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { QueryParams } from "./commands/query.js";
|
|
2
|
+
export declare class TooManyItemsException extends Error {
|
|
3
|
+
readonly operation: "queryOne";
|
|
4
|
+
readonly name: "TooManyItemsException";
|
|
5
|
+
private constructor();
|
|
6
|
+
static queryingOne(params: QueryParams): TooManyItemsException;
|
|
5
7
|
}
|
|
6
8
|
export type TransactionCanceledCheck = {
|
|
7
9
|
index: number;
|
package/lib/esm/error.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { TransactionCanceledException } from "@aws-sdk/client-dynamodb";
|
|
2
2
|
import { findCauseByType } from "@infra-blocks/error";
|
|
3
|
-
export class
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export class TooManyItemsException extends Error {
|
|
4
|
+
operation;
|
|
5
|
+
name;
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.operation = "queryOne";
|
|
9
|
+
this.name = "TooManyItemsException";
|
|
10
|
+
}
|
|
11
|
+
static queryingOne(params) {
|
|
12
|
+
const { table, index } = params;
|
|
13
|
+
return new TooManyItemsException(`found multiple items while querying one on ${JSON.stringify({ table, index })}`);
|
|
7
14
|
}
|
|
8
15
|
}
|
|
9
16
|
export const ConditionalCheckFailed = {
|
package/lib/esm/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,SAAS,CAAa;IACtB,IAAI,CAA0B;IAEvC,YAAoB,OAAe;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAmB;QACpC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GA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