@twin.org/entity-storage-connector-dynamodb 0.0.1-next.2
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/LICENSE +201 -0
- package/README.md +35 -0
- package/dist/cjs/index.cjs +647 -0
- package/dist/esm/index.mjs +645 -0
- package/dist/types/dynamoDbEntityStorageConnector.d.ts +77 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/models/IDynamoDbEntityStorageConnectorConfig.d.ts +25 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/DynamoDbEntityStorageConnector.md +220 -0
- package/docs/reference/index.md +9 -0
- package/docs/reference/interfaces/IDynamoDbEntityStorageConnectorConfig.md +43 -0
- package/locales/en.json +23 -0
- package/package.json +74 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type EntityCondition, type SortDirection } from "@twin.org/entity";
|
|
2
|
+
import type { IEntityStorageConnector } from "@twin.org/entity-storage-models";
|
|
3
|
+
import type { IDynamoDbEntityStorageConnectorConfig } from "./models/IDynamoDbEntityStorageConnectorConfig";
|
|
4
|
+
/**
|
|
5
|
+
* Class for performing entity storage operations using Dynamo DB.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DynamoDbEntityStorageConnector<T = unknown> implements IEntityStorageConnector<T> {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of DynamoDbEntityStorageConnector.
|
|
14
|
+
* @param options The options for the connector.
|
|
15
|
+
* @param options.entitySchema The schema for the entity.
|
|
16
|
+
* @param options.loggingConnectorType The type of logging connector to use, defaults to no logging.
|
|
17
|
+
* @param options.config The configuration for the connector.
|
|
18
|
+
*/
|
|
19
|
+
constructor(options: {
|
|
20
|
+
entitySchema: string;
|
|
21
|
+
loggingConnectorType?: string;
|
|
22
|
+
config: IDynamoDbEntityStorageConnectorConfig;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Bootstrap the component by creating and initializing any resources it needs.
|
|
26
|
+
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
|
27
|
+
* @returns True if the bootstrapping process was successful.
|
|
28
|
+
*/
|
|
29
|
+
bootstrap(nodeLoggingConnectorType?: string): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Get an entity.
|
|
32
|
+
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
33
|
+
* @param secondaryIndex Get the item using a secondary index.
|
|
34
|
+
* @returns The object if it can be found or undefined.
|
|
35
|
+
*/
|
|
36
|
+
get(id: string, secondaryIndex?: keyof T): Promise<T | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Set an entity.
|
|
39
|
+
* @param entity The entity to set.
|
|
40
|
+
* @returns The id of the entity.
|
|
41
|
+
*/
|
|
42
|
+
set(entity: T): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Remove the entity.
|
|
45
|
+
* @param id The id of the entity to remove.
|
|
46
|
+
* @returns Nothing.
|
|
47
|
+
*/
|
|
48
|
+
remove(id: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Find all the entities which match the conditions.
|
|
51
|
+
* @param conditions The conditions to match for the entities.
|
|
52
|
+
* @param sortProperties The optional sort order.
|
|
53
|
+
* @param properties The optional properties to return, defaults to all.
|
|
54
|
+
* @param cursor The cursor to request the next page of entities.
|
|
55
|
+
* @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
56
|
+
* @returns All the entities for the storage matching the conditions,
|
|
57
|
+
* and a cursor which can be used to request more entities.
|
|
58
|
+
*/
|
|
59
|
+
query(conditions?: EntityCondition<T>, sortProperties?: {
|
|
60
|
+
property: keyof T;
|
|
61
|
+
sortDirection: SortDirection;
|
|
62
|
+
}[], properties?: (keyof T)[], cursor?: string, pageSize?: number): Promise<{
|
|
63
|
+
/**
|
|
64
|
+
* The entities, which can be partial if a limited keys list was provided.
|
|
65
|
+
*/
|
|
66
|
+
entities: Partial<T>[];
|
|
67
|
+
/**
|
|
68
|
+
* An optional cursor, when defined can be used to call find to get more entities.
|
|
69
|
+
*/
|
|
70
|
+
cursor?: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Delete the table.
|
|
74
|
+
* @returns Nothing.
|
|
75
|
+
*/
|
|
76
|
+
tableDelete(): Promise<void>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the Dynamo DB Entity Storage Connector.
|
|
3
|
+
*/
|
|
4
|
+
export interface IDynamoDbEntityStorageConnectorConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The region for the AWS connection.
|
|
7
|
+
*/
|
|
8
|
+
region: string;
|
|
9
|
+
/**
|
|
10
|
+
* The AWS access key.
|
|
11
|
+
*/
|
|
12
|
+
accessKeyId: string;
|
|
13
|
+
/**
|
|
14
|
+
* The AWS secret access key.
|
|
15
|
+
*/
|
|
16
|
+
secretAccessKey: string;
|
|
17
|
+
/**
|
|
18
|
+
* The name of the table for the storage.
|
|
19
|
+
*/
|
|
20
|
+
tableName: string;
|
|
21
|
+
/**
|
|
22
|
+
* AWS endpoint, not usually required but could be used for local DynamoDB instance e.g. http://localhost:8000.
|
|
23
|
+
*/
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
}
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @twin.org/entity-storage-connector-dynamodb - Examples
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Class: DynamoDbEntityStorageConnector\<T\>
|
|
2
|
+
|
|
3
|
+
Class for performing entity storage operations using Dynamo DB.
|
|
4
|
+
|
|
5
|
+
## Type Parameters
|
|
6
|
+
|
|
7
|
+
• **T** = `unknown`
|
|
8
|
+
|
|
9
|
+
## Implements
|
|
10
|
+
|
|
11
|
+
- `IEntityStorageConnector`\<`T`\>
|
|
12
|
+
|
|
13
|
+
## Constructors
|
|
14
|
+
|
|
15
|
+
### new DynamoDbEntityStorageConnector()
|
|
16
|
+
|
|
17
|
+
> **new DynamoDbEntityStorageConnector**\<`T`\>(`options`): [`DynamoDbEntityStorageConnector`](DynamoDbEntityStorageConnector.md)\<`T`\>
|
|
18
|
+
|
|
19
|
+
Create a new instance of DynamoDbEntityStorageConnector.
|
|
20
|
+
|
|
21
|
+
#### Parameters
|
|
22
|
+
|
|
23
|
+
• **options**
|
|
24
|
+
|
|
25
|
+
The options for the connector.
|
|
26
|
+
|
|
27
|
+
• **options.entitySchema**: `string`
|
|
28
|
+
|
|
29
|
+
The schema for the entity.
|
|
30
|
+
|
|
31
|
+
• **options.loggingConnectorType?**: `string`
|
|
32
|
+
|
|
33
|
+
The type of logging connector to use, defaults to no logging.
|
|
34
|
+
|
|
35
|
+
• **options.config**: [`IDynamoDbEntityStorageConnectorConfig`](../interfaces/IDynamoDbEntityStorageConnectorConfig.md)
|
|
36
|
+
|
|
37
|
+
The configuration for the connector.
|
|
38
|
+
|
|
39
|
+
#### Returns
|
|
40
|
+
|
|
41
|
+
[`DynamoDbEntityStorageConnector`](DynamoDbEntityStorageConnector.md)\<`T`\>
|
|
42
|
+
|
|
43
|
+
## Properties
|
|
44
|
+
|
|
45
|
+
### CLASS\_NAME
|
|
46
|
+
|
|
47
|
+
> `readonly` **CLASS\_NAME**: `string`
|
|
48
|
+
|
|
49
|
+
Runtime name for the class.
|
|
50
|
+
|
|
51
|
+
#### Implementation of
|
|
52
|
+
|
|
53
|
+
`IEntityStorageConnector.CLASS_NAME`
|
|
54
|
+
|
|
55
|
+
## Methods
|
|
56
|
+
|
|
57
|
+
### bootstrap()
|
|
58
|
+
|
|
59
|
+
> **bootstrap**(`nodeLoggingConnectorType`?): `Promise`\<`boolean`\>
|
|
60
|
+
|
|
61
|
+
Bootstrap the component by creating and initializing any resources it needs.
|
|
62
|
+
|
|
63
|
+
#### Parameters
|
|
64
|
+
|
|
65
|
+
• **nodeLoggingConnectorType?**: `string`
|
|
66
|
+
|
|
67
|
+
The node logging connector type, defaults to "node-logging".
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
`Promise`\<`boolean`\>
|
|
72
|
+
|
|
73
|
+
True if the bootstrapping process was successful.
|
|
74
|
+
|
|
75
|
+
#### Implementation of
|
|
76
|
+
|
|
77
|
+
`IEntityStorageConnector.bootstrap`
|
|
78
|
+
|
|
79
|
+
***
|
|
80
|
+
|
|
81
|
+
### get()
|
|
82
|
+
|
|
83
|
+
> **get**(`id`, `secondaryIndex`?): `Promise`\<`undefined` \| `T`\>
|
|
84
|
+
|
|
85
|
+
Get an entity.
|
|
86
|
+
|
|
87
|
+
#### Parameters
|
|
88
|
+
|
|
89
|
+
• **id**: `string`
|
|
90
|
+
|
|
91
|
+
The id of the entity to get, or the index value if secondaryIndex is set.
|
|
92
|
+
|
|
93
|
+
• **secondaryIndex?**: keyof `T`
|
|
94
|
+
|
|
95
|
+
Get the item using a secondary index.
|
|
96
|
+
|
|
97
|
+
#### Returns
|
|
98
|
+
|
|
99
|
+
`Promise`\<`undefined` \| `T`\>
|
|
100
|
+
|
|
101
|
+
The object if it can be found or undefined.
|
|
102
|
+
|
|
103
|
+
#### Implementation of
|
|
104
|
+
|
|
105
|
+
`IEntityStorageConnector.get`
|
|
106
|
+
|
|
107
|
+
***
|
|
108
|
+
|
|
109
|
+
### set()
|
|
110
|
+
|
|
111
|
+
> **set**(`entity`): `Promise`\<`void`\>
|
|
112
|
+
|
|
113
|
+
Set an entity.
|
|
114
|
+
|
|
115
|
+
#### Parameters
|
|
116
|
+
|
|
117
|
+
• **entity**: `T`
|
|
118
|
+
|
|
119
|
+
The entity to set.
|
|
120
|
+
|
|
121
|
+
#### Returns
|
|
122
|
+
|
|
123
|
+
`Promise`\<`void`\>
|
|
124
|
+
|
|
125
|
+
The id of the entity.
|
|
126
|
+
|
|
127
|
+
#### Implementation of
|
|
128
|
+
|
|
129
|
+
`IEntityStorageConnector.set`
|
|
130
|
+
|
|
131
|
+
***
|
|
132
|
+
|
|
133
|
+
### remove()
|
|
134
|
+
|
|
135
|
+
> **remove**(`id`): `Promise`\<`void`\>
|
|
136
|
+
|
|
137
|
+
Remove the entity.
|
|
138
|
+
|
|
139
|
+
#### Parameters
|
|
140
|
+
|
|
141
|
+
• **id**: `string`
|
|
142
|
+
|
|
143
|
+
The id of the entity to remove.
|
|
144
|
+
|
|
145
|
+
#### Returns
|
|
146
|
+
|
|
147
|
+
`Promise`\<`void`\>
|
|
148
|
+
|
|
149
|
+
Nothing.
|
|
150
|
+
|
|
151
|
+
#### Implementation of
|
|
152
|
+
|
|
153
|
+
`IEntityStorageConnector.remove`
|
|
154
|
+
|
|
155
|
+
***
|
|
156
|
+
|
|
157
|
+
### query()
|
|
158
|
+
|
|
159
|
+
> **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
|
|
160
|
+
|
|
161
|
+
Find all the entities which match the conditions.
|
|
162
|
+
|
|
163
|
+
#### Parameters
|
|
164
|
+
|
|
165
|
+
• **conditions?**: `EntityCondition`\<`T`\>
|
|
166
|
+
|
|
167
|
+
The conditions to match for the entities.
|
|
168
|
+
|
|
169
|
+
• **sortProperties?**: `object`[]
|
|
170
|
+
|
|
171
|
+
The optional sort order.
|
|
172
|
+
|
|
173
|
+
• **properties?**: keyof `T`[]
|
|
174
|
+
|
|
175
|
+
The optional properties to return, defaults to all.
|
|
176
|
+
|
|
177
|
+
• **cursor?**: `string`
|
|
178
|
+
|
|
179
|
+
The cursor to request the next page of entities.
|
|
180
|
+
|
|
181
|
+
• **pageSize?**: `number`
|
|
182
|
+
|
|
183
|
+
The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
184
|
+
|
|
185
|
+
#### Returns
|
|
186
|
+
|
|
187
|
+
`Promise`\<`object`\>
|
|
188
|
+
|
|
189
|
+
All the entities for the storage matching the conditions,
|
|
190
|
+
and a cursor which can be used to request more entities.
|
|
191
|
+
|
|
192
|
+
##### entities
|
|
193
|
+
|
|
194
|
+
> **entities**: `Partial`\<`T`\>[]
|
|
195
|
+
|
|
196
|
+
The entities, which can be partial if a limited keys list was provided.
|
|
197
|
+
|
|
198
|
+
##### cursor?
|
|
199
|
+
|
|
200
|
+
> `optional` **cursor**: `string`
|
|
201
|
+
|
|
202
|
+
An optional cursor, when defined can be used to call find to get more entities.
|
|
203
|
+
|
|
204
|
+
#### Implementation of
|
|
205
|
+
|
|
206
|
+
`IEntityStorageConnector.query`
|
|
207
|
+
|
|
208
|
+
***
|
|
209
|
+
|
|
210
|
+
### tableDelete()
|
|
211
|
+
|
|
212
|
+
> **tableDelete**(): `Promise`\<`void`\>
|
|
213
|
+
|
|
214
|
+
Delete the table.
|
|
215
|
+
|
|
216
|
+
#### Returns
|
|
217
|
+
|
|
218
|
+
`Promise`\<`void`\>
|
|
219
|
+
|
|
220
|
+
Nothing.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Interface: IDynamoDbEntityStorageConnectorConfig
|
|
2
|
+
|
|
3
|
+
Configuration for the Dynamo DB Entity Storage Connector.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### region
|
|
8
|
+
|
|
9
|
+
> **region**: `string`
|
|
10
|
+
|
|
11
|
+
The region for the AWS connection.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
### accessKeyId
|
|
16
|
+
|
|
17
|
+
> **accessKeyId**: `string`
|
|
18
|
+
|
|
19
|
+
The AWS access key.
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### secretAccessKey
|
|
24
|
+
|
|
25
|
+
> **secretAccessKey**: `string`
|
|
26
|
+
|
|
27
|
+
The AWS secret access key.
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
### tableName
|
|
32
|
+
|
|
33
|
+
> **tableName**: `string`
|
|
34
|
+
|
|
35
|
+
The name of the table for the storage.
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
39
|
+
### endpoint?
|
|
40
|
+
|
|
41
|
+
> `optional` **endpoint**: `string`
|
|
42
|
+
|
|
43
|
+
AWS endpoint, not usually required but could be used for local DynamoDB instance e.g. http://localhost:8000.
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"info": {
|
|
3
|
+
"dynamoDbEntityStorageConnector": {
|
|
4
|
+
"tableCreating": "Creating table \"{tableName}\"",
|
|
5
|
+
"tableCreated": "Created table \"{tableName}\"",
|
|
6
|
+
"tableExists": "Skipping create table \"{tableName}\" as it already exists"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"error": {
|
|
10
|
+
"dynamoDbEntityStorageConnector": {
|
|
11
|
+
"tableCreateFailed": "Creating table \"{tableName}\" failed",
|
|
12
|
+
"tableDoesNotExist": "Table \"{tableName}\" does not exist",
|
|
13
|
+
"setFailed": "Unable to set entity \"{id}\"",
|
|
14
|
+
"getFailed": "Unable to get entity \"{id}\"",
|
|
15
|
+
"removeFailed": "Unable to remove entity \"{id}\"",
|
|
16
|
+
"queryFailed": "The query failed when issuing the following command \"{sql}\"",
|
|
17
|
+
"comparisonNotSupported": "Comparison operator \"{comparison}\" is not supported",
|
|
18
|
+
"conditionalNotSupported": "Conditional operator \"{operator}\" is not supported",
|
|
19
|
+
"sortSingle": "You can only sort by a single property",
|
|
20
|
+
"sortNotIndexed": "The property \"{property}\" is not indexed and cannot be used for sorting"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twin.org/entity-storage-connector-dynamodb",
|
|
3
|
+
"version": "0.0.1-next.2",
|
|
4
|
+
"description": "Entity Storage connector implementation using DynamoDb storage",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/twinfoundation/entity-storage.git",
|
|
8
|
+
"directory": "packages/entity-storage-connector-dynamodb"
|
|
9
|
+
},
|
|
10
|
+
"author": "martyn.janes@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.0.0"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rimraf dist coverage docs/reference",
|
|
18
|
+
"build": "tspc",
|
|
19
|
+
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
20
|
+
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
21
|
+
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
22
|
+
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
23
|
+
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
24
|
+
"docs:clean": "rimraf docs/reference",
|
|
25
|
+
"docs:generate": "typedoc",
|
|
26
|
+
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
+
"dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@twin.org/core": "next",
|
|
31
|
+
"@twin.org/entity": "next",
|
|
32
|
+
"@twin.org/nameof": "next",
|
|
33
|
+
"@twin.org/entity-storage-models": "0.0.1-next.2",
|
|
34
|
+
"@twin.org/logging-models": "next",
|
|
35
|
+
"@aws-sdk/client-dynamodb": "3.651",
|
|
36
|
+
"@aws-sdk/lib-dynamodb": "3.651",
|
|
37
|
+
"@aws-sdk/util-dynamodb": "3.651"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@twin.org/entity-storage-connector-memory": "0.0.1-next.2",
|
|
41
|
+
"@twin.org/logging-connector-entity-storage": "next",
|
|
42
|
+
"@twin.org/nameof-transformer": "next",
|
|
43
|
+
"@vitest/coverage-v8": "2.1.1",
|
|
44
|
+
"copyfiles": "2.4.1",
|
|
45
|
+
"dotenv": "16.4.5",
|
|
46
|
+
"rimraf": "6.0.1",
|
|
47
|
+
"rollup": "4.21.3",
|
|
48
|
+
"rollup-plugin-copy": "3.5.0",
|
|
49
|
+
"rollup-plugin-typescript2": "0.36.0",
|
|
50
|
+
"ts-patch": "3.2.1",
|
|
51
|
+
"typedoc": "0.26.7",
|
|
52
|
+
"typedoc-plugin-markdown": "4.2.7",
|
|
53
|
+
"typescript": "5.6.2",
|
|
54
|
+
"vitest": "2.1.1"
|
|
55
|
+
},
|
|
56
|
+
"main": "./dist/cjs/index.cjs",
|
|
57
|
+
"module": "./dist/esm/index.mjs",
|
|
58
|
+
"types": "./dist/types/index.d.ts",
|
|
59
|
+
"exports": {
|
|
60
|
+
".": {
|
|
61
|
+
"require": "./dist/cjs/index.cjs",
|
|
62
|
+
"import": "./dist/esm/index.mjs",
|
|
63
|
+
"types": "./dist/types/index.d.ts"
|
|
64
|
+
},
|
|
65
|
+
"./locales": "./locales"
|
|
66
|
+
},
|
|
67
|
+
"files": [
|
|
68
|
+
"dist/cjs",
|
|
69
|
+
"dist/esm",
|
|
70
|
+
"dist/types",
|
|
71
|
+
"locales",
|
|
72
|
+
"docs"
|
|
73
|
+
]
|
|
74
|
+
}
|