@infra-blocks/aws-dynamodb 0.2.1-alpha.0 → 0.3.0-alpha.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 +13 -11
- package/lib/cjs/client.js +37 -22
- package/lib/cjs/client.js.map +1 -1
- package/lib/cjs/commands/create-table.d.ts +20 -0
- package/lib/cjs/commands/create-table.js +102 -0
- package/lib/cjs/commands/create-table.js.map +1 -0
- package/lib/cjs/commands/index.d.ts +1 -0
- package/lib/cjs/commands/index.js +3 -0
- package/lib/cjs/commands/index.js.map +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +10 -0
- package/lib/esm/client.d.ts +13 -11
- package/lib/esm/client.js +37 -22
- package/lib/esm/client.js.map +1 -1
- package/lib/esm/commands/create-table.d.ts +20 -0
- package/lib/esm/commands/create-table.js +98 -0
- package/lib/esm/commands/create-table.js.map +1 -0
- package/lib/esm/commands/index.d.ts +1 -0
- package/lib/esm/commands/index.js +2 -0
- package/lib/esm/commands/index.js.map +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +10 -0
- package/package.json +12 -5
package/lib/cjs/client.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { TranslateConfig } from "@aws-sdk/lib-dynamodb";
|
|
|
3
3
|
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
4
4
|
import type { Logger } from "@infra-blocks/logger-interface";
|
|
5
5
|
import { type Retry, type RetryConfig } from "@infra-blocks/retry";
|
|
6
|
+
import { type CreateTableParams } from "./commands/create-table.js";
|
|
6
7
|
import type { Attributes, GetItem, PutItem, Query, WriteTransaction } from "./types.js";
|
|
7
8
|
/**
|
|
8
9
|
* Creation parameters for the {@link DynamoDbClient}.
|
|
@@ -42,17 +43,7 @@ export declare class DynamoDbClient {
|
|
|
42
43
|
private readonly client;
|
|
43
44
|
private readonly logger;
|
|
44
45
|
private constructor();
|
|
45
|
-
|
|
46
|
-
* Awaits until the DynamoDB service is ready to accept requests.
|
|
47
|
-
*
|
|
48
|
-
* This is mostly useful in local and test environments, where DynamoDB might be started as a docker container.
|
|
49
|
-
* This function uses the {@link @infra-blocks/retry} with its default configuration. If the user wishes
|
|
50
|
-
* to change those, they can do so by passing the `options` parameter that is simply forwarded to the
|
|
51
|
-
* library.
|
|
52
|
-
*
|
|
53
|
-
* @param options - Options to pass to the underlying retry mechanism.
|
|
54
|
-
*/
|
|
55
|
-
ready(options?: Omit<RetryConfig, "isRetryableError">): Retry<void>;
|
|
46
|
+
createTable(params: CreateTableParams): Promise<void>;
|
|
56
47
|
/**
|
|
57
48
|
* Gets an item using the GetItem API.
|
|
58
49
|
*
|
|
@@ -102,6 +93,17 @@ export declare class DynamoDbClient {
|
|
|
102
93
|
* @returns The only item matching the query, or `undefined` if no item matches.
|
|
103
94
|
*/
|
|
104
95
|
queryOne<T extends Attributes = Attributes>(params: Query): Promise<T | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Awaits until the DynamoDB service is ready to accept requests.
|
|
98
|
+
*
|
|
99
|
+
* This is mostly useful in local and test environments, where DynamoDB might be started as a docker container.
|
|
100
|
+
* This function uses the {@link @infra-blocks/retry} with its default configuration. If the user wishes
|
|
101
|
+
* to change those, they can do so by passing the `options` parameter that is simply forwarded to the
|
|
102
|
+
* library.
|
|
103
|
+
*
|
|
104
|
+
* @param options - Options to pass to the underlying retry mechanism.
|
|
105
|
+
*/
|
|
106
|
+
ready(options?: Omit<RetryConfig, "isRetryableError">): Retry<void>;
|
|
105
107
|
/**
|
|
106
108
|
* Executes a write transaction using the TransactWriteItems API.
|
|
107
109
|
*
|
package/lib/cjs/client.js
CHANGED
|
@@ -5,6 +5,7 @@ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
|
5
5
|
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
6
6
|
const null_logger_1 = require("@infra-blocks/null-logger");
|
|
7
7
|
const retry_1 = require("@infra-blocks/retry");
|
|
8
|
+
const create_table_js_1 = require("./commands/create-table.js");
|
|
8
9
|
class DynamoDbClientError extends Error {
|
|
9
10
|
constructor(message, options) {
|
|
10
11
|
super(message, options);
|
|
@@ -24,28 +25,19 @@ class DynamoDbClient {
|
|
|
24
25
|
this.client = client;
|
|
25
26
|
this.logger = logger;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, {
|
|
41
|
-
...options,
|
|
42
|
-
isRetryableError: (err) => {
|
|
43
|
-
if ("code" in err) {
|
|
44
|
-
return err.code === "ECONNRESET";
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
},
|
|
48
|
-
});
|
|
28
|
+
async createTable(params) {
|
|
29
|
+
if (this.logger.isDebugEnabled()) {
|
|
30
|
+
this.logger.debug("createTable(%s)", JSON.stringify(params));
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const command = create_table_js_1.CreateTable.from(params);
|
|
34
|
+
await this.client.send(command.toAwsCommand());
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw new DynamoDbClientError(`error while creating table: ${JSON.stringify(params)}`, {
|
|
38
|
+
cause: err,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
49
41
|
}
|
|
50
42
|
/**
|
|
51
43
|
* Gets an item using the GetItem API.
|
|
@@ -173,6 +165,29 @@ class DynamoDbClient {
|
|
|
173
165
|
});
|
|
174
166
|
}
|
|
175
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Awaits until the DynamoDB service is ready to accept requests.
|
|
170
|
+
*
|
|
171
|
+
* This is mostly useful in local and test environments, where DynamoDB might be started as a docker container.
|
|
172
|
+
* This function uses the {@link @infra-blocks/retry} with its default configuration. If the user wishes
|
|
173
|
+
* to change those, they can do so by passing the `options` parameter that is simply forwarded to the
|
|
174
|
+
* library.
|
|
175
|
+
*
|
|
176
|
+
* @param options - Options to pass to the underlying retry mechanism.
|
|
177
|
+
*/
|
|
178
|
+
ready(options) {
|
|
179
|
+
return (0, retry_1.retry)(async () => {
|
|
180
|
+
await this.client.send(new client_dynamodb_1.ListTablesCommand({}));
|
|
181
|
+
}, {
|
|
182
|
+
...options,
|
|
183
|
+
isRetryableError: (err) => {
|
|
184
|
+
if ("code" in err) {
|
|
185
|
+
return err.code === "ECONNRESET";
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
176
191
|
/**
|
|
177
192
|
* Executes a write transaction using the TransactWriteItems API.
|
|
178
193
|
*
|
package/lib/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AACA,8DAA6E;AAM7E,wDAM+B;AAE/B,2DAAuD;AACvD,+CAA0E;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AACA,8DAA6E;AAM7E,wDAM+B;AAE/B,2DAAuD;AACvD,+CAA0E;AAC1E,gEAGoC;AAmCpC,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAED;;;GAGG;AACH,MAAa,cAAc;IACR,MAAM,CAAyB;IAC/B,MAAM,CAAS;IAEhC,YAAoB,MAGnB;QACC,MAAM,EAAE,MAAM,EAAE,M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
|
|
|
1
|
+
import { CreateTableCommand, type CreateTableCommandInput } from "@aws-sdk/client-dynamodb";
|
|
2
|
+
import type { Index } from "../types.js";
|
|
3
|
+
export interface CreateTableParams {
|
|
4
|
+
name: string;
|
|
5
|
+
primaryKey: Index;
|
|
6
|
+
gsis?: Record<string, Index>;
|
|
7
|
+
lsis?: Record<string, Index>;
|
|
8
|
+
}
|
|
9
|
+
export declare class CreateTable {
|
|
10
|
+
private readonly name;
|
|
11
|
+
private readonly primaryKey;
|
|
12
|
+
private readonly gsis?;
|
|
13
|
+
private readonly lsis?;
|
|
14
|
+
private constructor();
|
|
15
|
+
toInput(): CreateTableCommandInput;
|
|
16
|
+
toAwsCommand(): CreateTableCommand;
|
|
17
|
+
private gsiInput;
|
|
18
|
+
private lsiInput;
|
|
19
|
+
static from(params: CreateTableParams): CreateTable;
|
|
20
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateTable = void 0;
|
|
4
|
+
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
5
|
+
class CreateTable {
|
|
6
|
+
name;
|
|
7
|
+
primaryKey;
|
|
8
|
+
gsis;
|
|
9
|
+
lsis;
|
|
10
|
+
constructor(params) {
|
|
11
|
+
const { name, primaryKey, gsis, lsis } = params;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.primaryKey = primaryKey;
|
|
14
|
+
this.gsis = gsis;
|
|
15
|
+
this.lsis = lsis;
|
|
16
|
+
}
|
|
17
|
+
toInput() {
|
|
18
|
+
const { name } = this;
|
|
19
|
+
const attributeDefinitions = new Map();
|
|
20
|
+
const primaryKeySchema = keySchema({
|
|
21
|
+
attributeDefinitions,
|
|
22
|
+
key: this.primaryKey,
|
|
23
|
+
});
|
|
24
|
+
const globalSecondaryIndexes = this.gsiInput(attributeDefinitions);
|
|
25
|
+
const localSecondaryIndexes = this.lsiInput(attributeDefinitions);
|
|
26
|
+
return {
|
|
27
|
+
AttributeDefinitions: [...attributeDefinitions.entries()].map(([name, type]) => ({
|
|
28
|
+
AttributeName: name,
|
|
29
|
+
AttributeType: type,
|
|
30
|
+
})),
|
|
31
|
+
TableName: name,
|
|
32
|
+
KeySchema: primaryKeySchema,
|
|
33
|
+
GlobalSecondaryIndexes: globalSecondaryIndexes.length > 0 ? globalSecondaryIndexes : undefined,
|
|
34
|
+
LocalSecondaryIndexes: localSecondaryIndexes.length > 0 ? localSecondaryIndexes : undefined,
|
|
35
|
+
BillingMode: "PAY_PER_REQUEST", // Use on-demand billing mode by default.
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
toAwsCommand() {
|
|
39
|
+
return new client_dynamodb_1.CreateTableCommand(this.toInput());
|
|
40
|
+
}
|
|
41
|
+
gsiInput(attributeDefinitions) {
|
|
42
|
+
const { gsis = {} } = this;
|
|
43
|
+
const globalSecondaryIndexes = [];
|
|
44
|
+
for (const [indexName, field] of Object.entries(gsis)) {
|
|
45
|
+
const ks = keySchema({
|
|
46
|
+
attributeDefinitions,
|
|
47
|
+
key: field,
|
|
48
|
+
});
|
|
49
|
+
globalSecondaryIndexes.push({
|
|
50
|
+
IndexName: indexName,
|
|
51
|
+
KeySchema: ks,
|
|
52
|
+
Projection: {
|
|
53
|
+
ProjectionType: "ALL",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return globalSecondaryIndexes;
|
|
58
|
+
}
|
|
59
|
+
lsiInput(attributeDefinitions) {
|
|
60
|
+
const { lsis = {} } = this;
|
|
61
|
+
const localSecondaryIndexes = [];
|
|
62
|
+
for (const [indexName, field] of Object.entries(lsis)) {
|
|
63
|
+
const ks = keySchema({
|
|
64
|
+
attributeDefinitions,
|
|
65
|
+
key: {
|
|
66
|
+
partitionKey: field.partitionKey,
|
|
67
|
+
sortKey: field.sortKey,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
localSecondaryIndexes.push({
|
|
71
|
+
IndexName: indexName,
|
|
72
|
+
KeySchema: ks,
|
|
73
|
+
Projection: {
|
|
74
|
+
ProjectionType: "ALL",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return localSecondaryIndexes;
|
|
79
|
+
}
|
|
80
|
+
static from(params) {
|
|
81
|
+
return new CreateTable(params);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.CreateTable = CreateTable;
|
|
85
|
+
function keySchema(params) {
|
|
86
|
+
const { attributeDefinitions, key } = params;
|
|
87
|
+
const keySchema = [];
|
|
88
|
+
attributeDefinitions.set(key.partitionKey.name, key.partitionKey.type);
|
|
89
|
+
keySchema.push({
|
|
90
|
+
AttributeName: key.partitionKey.name,
|
|
91
|
+
KeyType: "HASH",
|
|
92
|
+
});
|
|
93
|
+
if (key.sortKey != null) {
|
|
94
|
+
attributeDefinitions.set(key.sortKey.name, key.sortKey.type);
|
|
95
|
+
keySchema.push({
|
|
96
|
+
AttributeName: key.sortKey.name,
|
|
97
|
+
KeyType: "RANGE",
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return keySchema;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=create-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-table.js","sourceRoot":"","sources":["../../../src/commands/create-table.ts"],"names":[],"mappings":";;;AAAA,8DAMkC;AAUlC,MAAa,WAAW;IACL,IAAI,CAAS;IACb,UAAU,CAAQ;IAClB,IAAI,CAAyB;IAC7B,IAAI,CAAyB;IAE9C,YAAoB,MAAyB;QAC3C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,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I,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACvE,SAAS,CAAC,IAAI,CAAC;QACb,aAAa,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI;QACpC,OAAO,EAAE,MAAM;KAChB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;QACxB,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7D,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI;YAC/B,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CreateTableParams } from "./create-table.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":""}
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./client.js"), exports);
|
|
18
|
+
__exportStar(require("./commands/index.js"), exports);
|
|
18
19
|
__exportStar(require("./condition-expression.js"), exports);
|
|
19
20
|
__exportStar(require("./key-condition-expression.js"), exports);
|
|
20
21
|
__exportStar(require("./types.js"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,4DAA0C;AAC1C,gEAA8C;AAC9C,6CAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,sDAAoC;AACpC,4DAA0C;AAC1C,gEAA8C;AAC9C,6CAA2B"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ScalarAttributeType } from "@aws-sdk/client-dynamodb";
|
|
1
2
|
import type { NativeAttributeValue } from "@aws-sdk/lib-dynamodb";
|
|
2
3
|
import type { ConditionExpression } from "./condition-expression.js";
|
|
3
4
|
import type { KeyConditionExpression } from "./key-condition-expression.js";
|
|
@@ -10,6 +11,15 @@ export interface Attribute {
|
|
|
10
11
|
value: AttributeValue;
|
|
11
12
|
}
|
|
12
13
|
export type Attributes = Record<AttributeName, NativeAttributeValue>;
|
|
14
|
+
export type IndexFieldType = ScalarAttributeType;
|
|
15
|
+
export interface IndexField {
|
|
16
|
+
name: string;
|
|
17
|
+
type: IndexFieldType;
|
|
18
|
+
}
|
|
19
|
+
export interface Index {
|
|
20
|
+
partitionKey: IndexField;
|
|
21
|
+
sortKey?: IndexField;
|
|
22
|
+
}
|
|
13
23
|
/**
|
|
14
24
|
* The input required to call the GetItem API.
|
|
15
25
|
*/
|
package/lib/esm/client.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { TranslateConfig } from "@aws-sdk/lib-dynamodb";
|
|
|
3
3
|
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
4
4
|
import type { Logger } from "@infra-blocks/logger-interface";
|
|
5
5
|
import { type Retry, type RetryConfig } from "@infra-blocks/retry";
|
|
6
|
+
import { type CreateTableParams } from "./commands/create-table.js";
|
|
6
7
|
import type { Attributes, GetItem, PutItem, Query, WriteTransaction } from "./types.js";
|
|
7
8
|
/**
|
|
8
9
|
* Creation parameters for the {@link DynamoDbClient}.
|
|
@@ -42,17 +43,7 @@ export declare class DynamoDbClient {
|
|
|
42
43
|
private readonly client;
|
|
43
44
|
private readonly logger;
|
|
44
45
|
private constructor();
|
|
45
|
-
|
|
46
|
-
* Awaits until the DynamoDB service is ready to accept requests.
|
|
47
|
-
*
|
|
48
|
-
* This is mostly useful in local and test environments, where DynamoDB might be started as a docker container.
|
|
49
|
-
* This function uses the {@link @infra-blocks/retry} with its default configuration. If the user wishes
|
|
50
|
-
* to change those, they can do so by passing the `options` parameter that is simply forwarded to the
|
|
51
|
-
* library.
|
|
52
|
-
*
|
|
53
|
-
* @param options - Options to pass to the underlying retry mechanism.
|
|
54
|
-
*/
|
|
55
|
-
ready(options?: Omit<RetryConfig, "isRetryableError">): Retry<void>;
|
|
46
|
+
createTable(params: CreateTableParams): Promise<void>;
|
|
56
47
|
/**
|
|
57
48
|
* Gets an item using the GetItem API.
|
|
58
49
|
*
|
|
@@ -102,6 +93,17 @@ export declare class DynamoDbClient {
|
|
|
102
93
|
* @returns The only item matching the query, or `undefined` if no item matches.
|
|
103
94
|
*/
|
|
104
95
|
queryOne<T extends Attributes = Attributes>(params: Query): Promise<T | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Awaits until the DynamoDB service is ready to accept requests.
|
|
98
|
+
*
|
|
99
|
+
* This is mostly useful in local and test environments, where DynamoDB might be started as a docker container.
|
|
100
|
+
* This function uses the {@link @infra-blocks/retry} with its default configuration. If the user wishes
|
|
101
|
+
* to change those, they can do so by passing the `options` parameter that is simply forwarded to the
|
|
102
|
+
* library.
|
|
103
|
+
*
|
|
104
|
+
* @param options - Options to pass to the underlying retry mechanism.
|
|
105
|
+
*/
|
|
106
|
+
ready(options?: Omit<RetryConfig, "isRetryableError">): Retry<void>;
|
|
105
107
|
/**
|
|
106
108
|
* Executes a write transaction using the TransactWriteItems API.
|
|
107
109
|
*
|
package/lib/esm/client.js
CHANGED
|
@@ -2,6 +2,7 @@ import { DynamoDBClient, ListTablesCommand } from "@aws-sdk/client-dynamodb";
|
|
|
2
2
|
import { DynamoDBDocumentClient, GetCommand, PutCommand, QueryCommand, TransactWriteCommand, } from "@aws-sdk/lib-dynamodb";
|
|
3
3
|
import { NullLogger } from "@infra-blocks/null-logger";
|
|
4
4
|
import { retry } from "@infra-blocks/retry";
|
|
5
|
+
import { CreateTable, } from "./commands/create-table.js";
|
|
5
6
|
export class DynamoDbClientError extends Error {
|
|
6
7
|
constructor(message, options) {
|
|
7
8
|
super(message, options);
|
|
@@ -20,28 +21,19 @@ export class DynamoDbClient {
|
|
|
20
21
|
this.client = client;
|
|
21
22
|
this.logger = logger;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, {
|
|
37
|
-
...options,
|
|
38
|
-
isRetryableError: (err) => {
|
|
39
|
-
if ("code" in err) {
|
|
40
|
-
return err.code === "ECONNRESET";
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
},
|
|
44
|
-
});
|
|
24
|
+
async createTable(params) {
|
|
25
|
+
if (this.logger.isDebugEnabled()) {
|
|
26
|
+
this.logger.debug("createTable(%s)", JSON.stringify(params));
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const command = CreateTable.from(params);
|
|
30
|
+
await this.client.send(command.toAwsCommand());
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw new DynamoDbClientError(`error while creating table: ${JSON.stringify(params)}`, {
|
|
34
|
+
cause: err,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
45
37
|
}
|
|
46
38
|
/**
|
|
47
39
|
* Gets an item using the GetItem API.
|
|
@@ -169,6 +161,29 @@ export class DynamoDbClient {
|
|
|
169
161
|
});
|
|
170
162
|
}
|
|
171
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Awaits until the DynamoDB service is ready to accept requests.
|
|
166
|
+
*
|
|
167
|
+
* This is mostly useful in local and test environments, where DynamoDB might be started as a docker container.
|
|
168
|
+
* This function uses the {@link @infra-blocks/retry} with its default configuration. If the user wishes
|
|
169
|
+
* to change those, they can do so by passing the `options` parameter that is simply forwarded to the
|
|
170
|
+
* library.
|
|
171
|
+
*
|
|
172
|
+
* @param options - Options to pass to the underlying retry mechanism.
|
|
173
|
+
*/
|
|
174
|
+
ready(options) {
|
|
175
|
+
return retry(async () => {
|
|
176
|
+
await this.client.send(new ListTablesCommand({}));
|
|
177
|
+
}, {
|
|
178
|
+
...options,
|
|
179
|
+
isRetryableError: (err) => {
|
|
180
|
+
if ("code" in err) {
|
|
181
|
+
return err.code === "ECONNRESET";
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
172
187
|
/**
|
|
173
188
|
* Executes a write transaction using the TransactWriteItems API.
|
|
174
189
|
*
|
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;AAM7E,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAgC,KAAK,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAM7E,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAgC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AAC,EAAE,CAAC;IACzE,OAAO;QACL,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,IAAI;QACV,GAAG,gBAAgB;KACpB,CAAC;AACJ,CAAC;AAED,SAAS,gCAAgC,CACvC,MAAwB;IAExB,OAAO;QACL,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACzC,GAAG,EAAE,mBAAmB,CAAC,IAAI,CAAC;SAC/B,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CreateTableCommand, type CreateTableCommandInput } from "@aws-sdk/client-dynamodb";
|
|
2
|
+
import type { Index } from "../types.js";
|
|
3
|
+
export interface CreateTableParams {
|
|
4
|
+
name: string;
|
|
5
|
+
primaryKey: Index;
|
|
6
|
+
gsis?: Record<string, Index>;
|
|
7
|
+
lsis?: Record<string, Index>;
|
|
8
|
+
}
|
|
9
|
+
export declare class CreateTable {
|
|
10
|
+
private readonly name;
|
|
11
|
+
private readonly primaryKey;
|
|
12
|
+
private readonly gsis?;
|
|
13
|
+
private readonly lsis?;
|
|
14
|
+
private constructor();
|
|
15
|
+
toInput(): CreateTableCommandInput;
|
|
16
|
+
toAwsCommand(): CreateTableCommand;
|
|
17
|
+
private gsiInput;
|
|
18
|
+
private lsiInput;
|
|
19
|
+
static from(params: CreateTableParams): CreateTable;
|
|
20
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CreateTableCommand, } from "@aws-sdk/client-dynamodb";
|
|
2
|
+
export class CreateTable {
|
|
3
|
+
name;
|
|
4
|
+
primaryKey;
|
|
5
|
+
gsis;
|
|
6
|
+
lsis;
|
|
7
|
+
constructor(params) {
|
|
8
|
+
const { name, primaryKey, gsis, lsis } = params;
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.primaryKey = primaryKey;
|
|
11
|
+
this.gsis = gsis;
|
|
12
|
+
this.lsis = lsis;
|
|
13
|
+
}
|
|
14
|
+
toInput() {
|
|
15
|
+
const { name } = this;
|
|
16
|
+
const attributeDefinitions = new Map();
|
|
17
|
+
const primaryKeySchema = keySchema({
|
|
18
|
+
attributeDefinitions,
|
|
19
|
+
key: this.primaryKey,
|
|
20
|
+
});
|
|
21
|
+
const globalSecondaryIndexes = this.gsiInput(attributeDefinitions);
|
|
22
|
+
const localSecondaryIndexes = this.lsiInput(attributeDefinitions);
|
|
23
|
+
return {
|
|
24
|
+
AttributeDefinitions: [...attributeDefinitions.entries()].map(([name, type]) => ({
|
|
25
|
+
AttributeName: name,
|
|
26
|
+
AttributeType: type,
|
|
27
|
+
})),
|
|
28
|
+
TableName: name,
|
|
29
|
+
KeySchema: primaryKeySchema,
|
|
30
|
+
GlobalSecondaryIndexes: globalSecondaryIndexes.length > 0 ? globalSecondaryIndexes : undefined,
|
|
31
|
+
LocalSecondaryIndexes: localSecondaryIndexes.length > 0 ? localSecondaryIndexes : undefined,
|
|
32
|
+
BillingMode: "PAY_PER_REQUEST", // Use on-demand billing mode by default.
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
toAwsCommand() {
|
|
36
|
+
return new CreateTableCommand(this.toInput());
|
|
37
|
+
}
|
|
38
|
+
gsiInput(attributeDefinitions) {
|
|
39
|
+
const { gsis = {} } = this;
|
|
40
|
+
const globalSecondaryIndexes = [];
|
|
41
|
+
for (const [indexName, field] of Object.entries(gsis)) {
|
|
42
|
+
const ks = keySchema({
|
|
43
|
+
attributeDefinitions,
|
|
44
|
+
key: field,
|
|
45
|
+
});
|
|
46
|
+
globalSecondaryIndexes.push({
|
|
47
|
+
IndexName: indexName,
|
|
48
|
+
KeySchema: ks,
|
|
49
|
+
Projection: {
|
|
50
|
+
ProjectionType: "ALL",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return globalSecondaryIndexes;
|
|
55
|
+
}
|
|
56
|
+
lsiInput(attributeDefinitions) {
|
|
57
|
+
const { lsis = {} } = this;
|
|
58
|
+
const localSecondaryIndexes = [];
|
|
59
|
+
for (const [indexName, field] of Object.entries(lsis)) {
|
|
60
|
+
const ks = keySchema({
|
|
61
|
+
attributeDefinitions,
|
|
62
|
+
key: {
|
|
63
|
+
partitionKey: field.partitionKey,
|
|
64
|
+
sortKey: field.sortKey,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
localSecondaryIndexes.push({
|
|
68
|
+
IndexName: indexName,
|
|
69
|
+
KeySchema: ks,
|
|
70
|
+
Projection: {
|
|
71
|
+
ProjectionType: "ALL",
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return localSecondaryIndexes;
|
|
76
|
+
}
|
|
77
|
+
static from(params) {
|
|
78
|
+
return new CreateTable(params);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function keySchema(params) {
|
|
82
|
+
const { attributeDefinitions, key } = params;
|
|
83
|
+
const keySchema = [];
|
|
84
|
+
attributeDefinitions.set(key.partitionKey.name, key.partitionKey.type);
|
|
85
|
+
keySchema.push({
|
|
86
|
+
AttributeName: key.partitionKey.name,
|
|
87
|
+
KeyType: "HASH",
|
|
88
|
+
});
|
|
89
|
+
if (key.sortKey != null) {
|
|
90
|
+
attributeDefinitions.set(key.sortKey.name, key.sortKey.type);
|
|
91
|
+
keySchema.push({
|
|
92
|
+
AttributeName: key.sortKey.name,
|
|
93
|
+
KeyType: "RANGE",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return keySchema;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=create-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-table.js","sourceRoot":"","sources":["../../../src/commands/create-table.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAKnB,MAAM,0BAA0B,CAAC;AAUlC,MAAM,OAAO,WAAW;IACL,IAAI,CAAS;IACb,UAAU,CAAQ;IAClB,IAAI,CAA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AyB;QACnC,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF;AAED,SAAS,SAAS,CAAC,MAGlB;IACC,MAAM,EAAE,oBAAoB,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAC7C,MAAM,SAAS,GAA4B,EAAE,CAAC;IAC9C,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACvE,SAAS,CAAC,IAAI,CAAC;QACb,aAAa,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI;QACpC,OAAO,EAAE,MAAM;KAChB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;QACxB,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7D,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI;YAC/B,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CreateTableParams } from "./create-table.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":""}
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ScalarAttributeType } from "@aws-sdk/client-dynamodb";
|
|
1
2
|
import type { NativeAttributeValue } from "@aws-sdk/lib-dynamodb";
|
|
2
3
|
import type { ConditionExpression } from "./condition-expression.js";
|
|
3
4
|
import type { KeyConditionExpression } from "./key-condition-expression.js";
|
|
@@ -10,6 +11,15 @@ export interface Attribute {
|
|
|
10
11
|
value: AttributeValue;
|
|
11
12
|
}
|
|
12
13
|
export type Attributes = Record<AttributeName, NativeAttributeValue>;
|
|
14
|
+
export type IndexFieldType = ScalarAttributeType;
|
|
15
|
+
export interface IndexField {
|
|
16
|
+
name: string;
|
|
17
|
+
type: IndexFieldType;
|
|
18
|
+
}
|
|
19
|
+
export interface Index {
|
|
20
|
+
partitionKey: IndexField;
|
|
21
|
+
sortKey?: IndexField;
|
|
22
|
+
}
|
|
13
23
|
/**
|
|
14
24
|
* The input required to call the GetItem API.
|
|
15
25
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infra-blocks/aws-dynamodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.0",
|
|
4
4
|
"description": "A convenience wrapper over @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"prebuild": "npm run clean",
|
|
27
|
-
"build": "
|
|
27
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
28
|
+
"build:esm": "tsc -b tsconfig.build.esm.json",
|
|
29
|
+
"build:cjs": "tsc -b tsconfig.build.cjs.json",
|
|
28
30
|
"postbuild": "scripts/post-build.sh",
|
|
29
31
|
"clean": "rm -rf lib && rm -f infra-blocks-*.tgz",
|
|
30
32
|
"compile": "tsc",
|
|
@@ -39,15 +41,20 @@
|
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
43
|
"@biomejs/biome": "^2.0.6",
|
|
42
|
-
"@infra-blocks/checks": "^0.2.
|
|
44
|
+
"@infra-blocks/checks": "^0.2.7",
|
|
45
|
+
"@infra-blocks/node-console-logger": "^0.3.1",
|
|
43
46
|
"@infra-blocks/test": "^0.4.0",
|
|
47
|
+
"@infra-blocks/types": "^0.10.0",
|
|
44
48
|
"@types/mocha": "^10.0.10",
|
|
45
49
|
"@types/node": "^24.0.10",
|
|
46
50
|
"c8": "^10.1.3",
|
|
51
|
+
"dotenv": "^17.0.1",
|
|
47
52
|
"lefthook": "^1.11.16",
|
|
48
|
-
"mocha": "^11.
|
|
53
|
+
"mocha": "^11.6.0",
|
|
54
|
+
"radash": "^12.1.1",
|
|
49
55
|
"tsx": "^4.20.3",
|
|
50
|
-
"typescript": "^5.8.3"
|
|
56
|
+
"typescript": "^5.8.3",
|
|
57
|
+
"zod": "^3.25.74"
|
|
51
58
|
},
|
|
52
59
|
"engines": {
|
|
53
60
|
"node": ">=22.0.0"
|