@twin.org/entity-storage-connector-dynamodb 0.0.1-next.10

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.
@@ -0,0 +1,94 @@
1
+ import { type EntityCondition, type IEntitySchema, 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 the schema for the entities.
32
+ * @returns The schema for the entities.
33
+ */
34
+ getSchema(): IEntitySchema;
35
+ /**
36
+ * Get an entity.
37
+ * @param id The id of the entity to get, or the index value if secondaryIndex is set.
38
+ * @param secondaryIndex Get the item using a secondary index.
39
+ * @param conditions The optional conditions to match for the entities.
40
+ * @returns The object if it can be found or undefined.
41
+ */
42
+ get(id: string, secondaryIndex?: keyof T, conditions?: {
43
+ property: keyof T;
44
+ value: unknown;
45
+ }[]): Promise<T | undefined>;
46
+ /**
47
+ * Set an entity.
48
+ * @param entity The entity to set.
49
+ * @param conditions The optional conditions to match for the entities.
50
+ * @returns The id of the entity.
51
+ */
52
+ set(entity: T, conditions?: {
53
+ property: keyof T;
54
+ value: unknown;
55
+ }[]): Promise<void>;
56
+ /**
57
+ * Remove the entity.
58
+ * @param id The id of the entity to remove.
59
+ * @param conditions The optional conditions to match for the entities.
60
+ * @returns Nothing.
61
+ */
62
+ remove(id: string, conditions?: {
63
+ property: keyof T;
64
+ value: unknown;
65
+ }[]): Promise<void>;
66
+ /**
67
+ * Find all the entities which match the conditions.
68
+ * @param conditions The conditions to match for the entities.
69
+ * @param sortProperties The optional sort order.
70
+ * @param properties The optional properties to return, defaults to all.
71
+ * @param cursor The cursor to request the next page of entities.
72
+ * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
73
+ * @returns All the entities for the storage matching the conditions,
74
+ * and a cursor which can be used to request more entities.
75
+ */
76
+ query(conditions?: EntityCondition<T>, sortProperties?: {
77
+ property: keyof T;
78
+ sortDirection: SortDirection;
79
+ }[], properties?: (keyof T)[], cursor?: string, pageSize?: number): Promise<{
80
+ /**
81
+ * The entities, which can be partial if a limited keys list was provided.
82
+ */
83
+ entities: Partial<T>[];
84
+ /**
85
+ * An optional cursor, when defined can be used to call find to get more entities.
86
+ */
87
+ cursor?: string;
88
+ }>;
89
+ /**
90
+ * Delete the table.
91
+ * @returns Nothing.
92
+ */
93
+ tableDelete(): Promise<void>;
94
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./dynamoDbEntityStorageConnector";
2
+ export * from "./models/IDynamoDbEntityStorageConnectorConfig";
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ # @twin.org/entity-storage-connector-dynamodb - Changelog
2
+
3
+ ## v0.0.1-next.10
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/entity-storage-connector-dynamodb - Examples
@@ -0,0 +1,250 @@
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
+ ### getSchema()
82
+
83
+ > **getSchema**(): `IEntitySchema`\<`unknown`\>
84
+
85
+ Get the schema for the entities.
86
+
87
+ #### Returns
88
+
89
+ `IEntitySchema`\<`unknown`\>
90
+
91
+ The schema for the entities.
92
+
93
+ #### Implementation of
94
+
95
+ `IEntityStorageConnector.getSchema`
96
+
97
+ ***
98
+
99
+ ### get()
100
+
101
+ > **get**(`id`, `secondaryIndex`?, `conditions`?): `Promise`\<`undefined` \| `T`\>
102
+
103
+ Get an entity.
104
+
105
+ #### Parameters
106
+
107
+ • **id**: `string`
108
+
109
+ The id of the entity to get, or the index value if secondaryIndex is set.
110
+
111
+ • **secondaryIndex?**: keyof `T`
112
+
113
+ Get the item using a secondary index.
114
+
115
+ • **conditions?**: `object`[]
116
+
117
+ The optional conditions to match for the entities.
118
+
119
+ #### Returns
120
+
121
+ `Promise`\<`undefined` \| `T`\>
122
+
123
+ The object if it can be found or undefined.
124
+
125
+ #### Implementation of
126
+
127
+ `IEntityStorageConnector.get`
128
+
129
+ ***
130
+
131
+ ### set()
132
+
133
+ > **set**(`entity`, `conditions`?): `Promise`\<`void`\>
134
+
135
+ Set an entity.
136
+
137
+ #### Parameters
138
+
139
+ • **entity**: `T`
140
+
141
+ The entity to set.
142
+
143
+ • **conditions?**: `object`[]
144
+
145
+ The optional conditions to match for the entities.
146
+
147
+ #### Returns
148
+
149
+ `Promise`\<`void`\>
150
+
151
+ The id of the entity.
152
+
153
+ #### Implementation of
154
+
155
+ `IEntityStorageConnector.set`
156
+
157
+ ***
158
+
159
+ ### remove()
160
+
161
+ > **remove**(`id`, `conditions`?): `Promise`\<`void`\>
162
+
163
+ Remove the entity.
164
+
165
+ #### Parameters
166
+
167
+ • **id**: `string`
168
+
169
+ The id of the entity to remove.
170
+
171
+ • **conditions?**: `object`[]
172
+
173
+ The optional conditions to match for the entities.
174
+
175
+ #### Returns
176
+
177
+ `Promise`\<`void`\>
178
+
179
+ Nothing.
180
+
181
+ #### Implementation of
182
+
183
+ `IEntityStorageConnector.remove`
184
+
185
+ ***
186
+
187
+ ### query()
188
+
189
+ > **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
190
+
191
+ Find all the entities which match the conditions.
192
+
193
+ #### Parameters
194
+
195
+ • **conditions?**: `EntityCondition`\<`T`\>
196
+
197
+ The conditions to match for the entities.
198
+
199
+ • **sortProperties?**: `object`[]
200
+
201
+ The optional sort order.
202
+
203
+ • **properties?**: keyof `T`[]
204
+
205
+ The optional properties to return, defaults to all.
206
+
207
+ • **cursor?**: `string`
208
+
209
+ The cursor to request the next page of entities.
210
+
211
+ • **pageSize?**: `number`
212
+
213
+ The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
214
+
215
+ #### Returns
216
+
217
+ `Promise`\<`object`\>
218
+
219
+ All the entities for the storage matching the conditions,
220
+ and a cursor which can be used to request more entities.
221
+
222
+ ##### entities
223
+
224
+ > **entities**: `Partial`\<`T`\>[]
225
+
226
+ The entities, which can be partial if a limited keys list was provided.
227
+
228
+ ##### cursor?
229
+
230
+ > `optional` **cursor**: `string`
231
+
232
+ An optional cursor, when defined can be used to call find to get more entities.
233
+
234
+ #### Implementation of
235
+
236
+ `IEntityStorageConnector.query`
237
+
238
+ ***
239
+
240
+ ### tableDelete()
241
+
242
+ > **tableDelete**(): `Promise`\<`void`\>
243
+
244
+ Delete the table.
245
+
246
+ #### Returns
247
+
248
+ `Promise`\<`void`\>
249
+
250
+ Nothing.
@@ -0,0 +1,9 @@
1
+ # @twin.org/entity-storage-connector-dynamodb
2
+
3
+ ## Classes
4
+
5
+ - [DynamoDbEntityStorageConnector](classes/DynamoDbEntityStorageConnector.md)
6
+
7
+ ## Interfaces
8
+
9
+ - [IDynamoDbEntityStorageConnectorConfig](interfaces/IDynamoDbEntityStorageConnectorConfig.md)
@@ -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.
@@ -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",
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,44 @@
1
+ {
2
+ "name": "@twin.org/entity-storage-connector-dynamodb",
3
+ "version": "0.0.1-next.10",
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
+ "dependencies": {
17
+ "@aws-sdk/client-dynamodb": "3.656",
18
+ "@aws-sdk/lib-dynamodb": "3.656",
19
+ "@aws-sdk/util-dynamodb": "3.656",
20
+ "@twin.org/core": "next",
21
+ "@twin.org/entity": "next",
22
+ "@twin.org/entity-storage-models": "0.0.1-next.10",
23
+ "@twin.org/logging-models": "next",
24
+ "@twin.org/nameof": "next"
25
+ },
26
+ "main": "./dist/cjs/index.cjs",
27
+ "module": "./dist/esm/index.mjs",
28
+ "types": "./dist/types/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "require": "./dist/cjs/index.cjs",
32
+ "import": "./dist/esm/index.mjs",
33
+ "types": "./dist/types/index.d.ts"
34
+ },
35
+ "./locales": "./locales"
36
+ },
37
+ "files": [
38
+ "dist/cjs",
39
+ "dist/esm",
40
+ "dist/types",
41
+ "locales",
42
+ "docs"
43
+ ]
44
+ }