@twin.org/entity-storage-connector-dynamodb 0.0.3-next.2 → 0.0.3-next.21

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/docs/examples.md CHANGED
@@ -1 +1,96 @@
1
- # @twin.org/entity-storage-connector-dynamodb - Examples
1
+ # Entity Storage Connector DynamoDB Examples
2
+
3
+ These examples show a complete flow from connector setup through reads, writes, filtered queries, and table maintenance tasks.
4
+
5
+ ## DynamoDbEntityStorageConnector
6
+
7
+ ```typescript
8
+ import {
9
+ DynamoDbEntityStorageConnector,
10
+ type IDynamoDbEntityStorageConnectorConstructorOptions
11
+ } from '@twin.org/entity-storage-connector-dynamodb';
12
+ import {
13
+ ComparisonOperator,
14
+ LogicalOperator,
15
+ SortDirection,
16
+ type EntityCondition
17
+ } from '@twin.org/entity';
18
+
19
+ interface Profile {
20
+ id: string;
21
+ email: string;
22
+ status: 'active' | 'inactive';
23
+ createdAt: string;
24
+ }
25
+
26
+ const options: IDynamoDbEntityStorageConnectorConstructorOptions = {
27
+ entitySchema: 'Profile',
28
+ config: {
29
+ region: 'eu-west-1',
30
+ authMode: 'credentials',
31
+ accessKeyId: 'local-access-key',
32
+ secretAccessKey: 'local-secret-key',
33
+ tableName: 'profiles',
34
+ endpoint: 'http://localhost:10000'
35
+ }
36
+ };
37
+
38
+ const connector = new DynamoDbEntityStorageConnector<Profile>(options);
39
+ await connector.bootstrap();
40
+
41
+ const className = connector.className();
42
+ const schema = connector.getSchema();
43
+
44
+ await connector.set({
45
+ id: 'profile-1',
46
+ email: 'ada@example.com',
47
+ status: 'active',
48
+ createdAt: '2026-03-09T10:30:00.000Z'
49
+ });
50
+
51
+ const byPrimaryKey = await connector.get('profile-1');
52
+ const bySecondaryIndex = await connector.get('ada@example.com', 'email');
53
+
54
+ const activeCondition: EntityCondition<Profile> = {
55
+ logicalOperator: LogicalOperator.And,
56
+ conditions: [
57
+ {
58
+ property: 'status',
59
+ comparison: ComparisonOperator.Equals,
60
+ value: 'active'
61
+ }
62
+ ]
63
+ };
64
+
65
+ const result = await connector.query(
66
+ activeCondition,
67
+ [{ property: 'createdAt', sortDirection: SortDirection.Descending }],
68
+ ['id', 'email', 'status'],
69
+ undefined,
70
+ 25
71
+ );
72
+
73
+ await connector.remove('profile-1');
74
+ ```
75
+
76
+ ```typescript
77
+ import { DynamoDbEntityStorageConnector } from '@twin.org/entity-storage-connector-dynamodb';
78
+
79
+ interface Profile {
80
+ id: string;
81
+ email: string;
82
+ status: 'active' | 'inactive';
83
+ createdAt: string;
84
+ }
85
+
86
+ const connector = new DynamoDbEntityStorageConnector<Profile>({
87
+ entitySchema: 'Profile',
88
+ config: {
89
+ region: 'eu-west-1',
90
+ authMode: 'pod',
91
+ tableName: 'profiles'
92
+ }
93
+ });
94
+
95
+ await connector.bootstrap('logging');
96
+ ```
@@ -10,7 +10,7 @@ Class for performing entity storage operations using Dynamo DB.
10
10
 
11
11
  ## Implements
12
12
 
13
- - `IEntityStorageConnector`\<`T`\>
13
+ - `IEntityStorageMigrationConnector`\<`T`\>
14
14
 
15
15
  ## Constructors
16
16
 
@@ -34,7 +34,7 @@ The options for the connector.
34
34
 
35
35
  ## Properties
36
36
 
37
- ### CLASS\_NAME
37
+ ### CLASS\_NAME {#class_name}
38
38
 
39
39
  > `readonly` `static` **CLASS\_NAME**: `string`
40
40
 
@@ -42,7 +42,7 @@ Runtime name for the class.
42
42
 
43
43
  ## Methods
44
44
 
45
- ### className()
45
+ ### className() {#classname}
46
46
 
47
47
  > **className**(): `string`
48
48
 
@@ -56,11 +56,29 @@ The class name of the component.
56
56
 
57
57
  #### Implementation of
58
58
 
59
- `IEntityStorageConnector.className`
59
+ `IEntityStorageMigrationConnector.className`
60
60
 
61
61
  ***
62
62
 
63
- ### getSchema()
63
+ ### health() {#health}
64
+
65
+ > **health**(): `Promise`\<`IHealth`[]\>
66
+
67
+ Returns the health status of the component.
68
+
69
+ #### Returns
70
+
71
+ `Promise`\<`IHealth`[]\>
72
+
73
+ The health status of the component.
74
+
75
+ #### Implementation of
76
+
77
+ `IEntityStorageMigrationConnector.health`
78
+
79
+ ***
80
+
81
+ ### getSchema() {#getschema}
64
82
 
65
83
  > **getSchema**(): `IEntitySchema`
66
84
 
@@ -74,11 +92,11 @@ The schema for the entities.
74
92
 
75
93
  #### Implementation of
76
94
 
77
- `IEntityStorageConnector.getSchema`
95
+ `IEntityStorageMigrationConnector.getSchema`
78
96
 
79
97
  ***
80
98
 
81
- ### bootstrap()
99
+ ### bootstrap() {#bootstrap}
82
100
 
83
101
  > **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
84
102
 
@@ -100,11 +118,11 @@ True if the bootstrapping process was successful.
100
118
 
101
119
  #### Implementation of
102
120
 
103
- `IEntityStorageConnector.bootstrap`
121
+ `IEntityStorageMigrationConnector.bootstrap`
104
122
 
105
123
  ***
106
124
 
107
- ### get()
125
+ ### get() {#get}
108
126
 
109
127
  > **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
110
128
 
@@ -138,11 +156,11 @@ The object if it can be found or undefined.
138
156
 
139
157
  #### Implementation of
140
158
 
141
- `IEntityStorageConnector.get`
159
+ `IEntityStorageMigrationConnector.get`
142
160
 
143
161
  ***
144
162
 
145
- ### set()
163
+ ### set() {#set}
146
164
 
147
165
  > **set**(`entity`, `conditions?`): `Promise`\<`void`\>
148
166
 
@@ -170,11 +188,55 @@ The id of the entity.
170
188
 
171
189
  #### Implementation of
172
190
 
173
- `IEntityStorageConnector.set`
191
+ `IEntityStorageMigrationConnector.set`
192
+
193
+ ***
194
+
195
+ ### setBatch() {#setbatch}
196
+
197
+ > **setBatch**(`entities`): `Promise`\<`void`\>
198
+
199
+ Set multiple entities in a batch.
200
+
201
+ #### Parameters
202
+
203
+ ##### entities
204
+
205
+ `T`[]
206
+
207
+ The entities to set.
208
+
209
+ #### Returns
210
+
211
+ `Promise`\<`void`\>
212
+
213
+ Nothing.
214
+
215
+ #### Implementation of
216
+
217
+ `IEntityStorageMigrationConnector.setBatch`
174
218
 
175
219
  ***
176
220
 
177
- ### remove()
221
+ ### empty() {#empty}
222
+
223
+ > **empty**(): `Promise`\<`void`\>
224
+
225
+ Empty the entity storage.
226
+
227
+ #### Returns
228
+
229
+ `Promise`\<`void`\>
230
+
231
+ Nothing.
232
+
233
+ #### Implementation of
234
+
235
+ `IEntityStorageMigrationConnector.empty`
236
+
237
+ ***
238
+
239
+ ### remove() {#remove}
178
240
 
179
241
  > **remove**(`id`, `conditions?`): `Promise`\<`void`\>
180
242
 
@@ -202,11 +264,63 @@ Nothing.
202
264
 
203
265
  #### Implementation of
204
266
 
205
- `IEntityStorageConnector.remove`
267
+ `IEntityStorageMigrationConnector.remove`
268
+
269
+ ***
270
+
271
+ ### removeBatch() {#removebatch}
272
+
273
+ > **removeBatch**(`ids`): `Promise`\<`void`\>
274
+
275
+ Remove multiple entities by their IDs in a batch.
276
+
277
+ #### Parameters
278
+
279
+ ##### ids
280
+
281
+ `string`[]
282
+
283
+ The ids of the entities to remove.
284
+
285
+ #### Returns
286
+
287
+ `Promise`\<`void`\>
288
+
289
+ Nothing.
290
+
291
+ #### Implementation of
292
+
293
+ `IEntityStorageMigrationConnector.removeBatch`
294
+
295
+ ***
296
+
297
+ ### teardown() {#teardown}
298
+
299
+ > **teardown**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
300
+
301
+ Teardown the entity storage by deleting the underlying table.
302
+
303
+ #### Parameters
304
+
305
+ ##### nodeLoggingComponentType?
306
+
307
+ `string`
308
+
309
+ The node logging component type.
310
+
311
+ #### Returns
312
+
313
+ `Promise`\<`boolean`\>
314
+
315
+ True if the teardown process was successful.
316
+
317
+ #### Implementation of
318
+
319
+ `IEntityStorageMigrationConnector.teardown`
206
320
 
207
321
  ***
208
322
 
209
- ### query()
323
+ ### query() {#query}
210
324
 
211
325
  > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
212
326
 
@@ -253,18 +367,168 @@ and a cursor which can be used to request more entities.
253
367
 
254
368
  #### Implementation of
255
369
 
256
- `IEntityStorageConnector.query`
370
+ `IEntityStorageMigrationConnector.query`
371
+
372
+ ***
373
+
374
+ ### count() {#count}
375
+
376
+ > **count**(`conditions?`): `Promise`\<`number`\>
377
+
378
+ Count all the entities which match the conditions.
379
+
380
+ #### Parameters
381
+
382
+ ##### conditions?
383
+
384
+ `EntityCondition`\<`T`\>
385
+
386
+ The optional conditions to match for the entities.
387
+
388
+ #### Returns
389
+
390
+ `Promise`\<`number`\>
391
+
392
+ The total count of entities in the storage.
393
+
394
+ #### Implementation of
395
+
396
+ `IEntityStorageMigrationConnector.count`
397
+
398
+ ***
399
+
400
+ ### getPartitionContextIds() {#getpartitioncontextids}
401
+
402
+ > **getPartitionContextIds**(): `Promise`\<`IContextIds`[]\>
403
+
404
+ Get a unique list of all the context ids from the storage.
405
+
406
+ #### Returns
407
+
408
+ `Promise`\<`IContextIds`[]\>
409
+
410
+ The list of unique context ids.
411
+
412
+ #### Implementation of
413
+
414
+ `IEntityStorageMigrationConnector.getPartitionContextIds`
415
+
416
+ ***
417
+
418
+ ### createTargetConnector() {#createtargetconnector}
419
+
420
+ > **createTargetConnector**\<`U`\>(`newEntitySchema`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
421
+
422
+ Create the target connector for performing the migration it will use a temporary storage location.
423
+
424
+ #### Type Parameters
425
+
426
+ ##### U
427
+
428
+ `U`
429
+
430
+ #### Parameters
431
+
432
+ ##### newEntitySchema
433
+
434
+ `string`
435
+
436
+ The name of the new entity schema to create the connector for.
437
+
438
+ #### Returns
439
+
440
+ `Promise`\<`IEntityStorageConnector`\<`U`\>\>
441
+
442
+ Connector for performing the migration.
443
+
444
+ #### Implementation of
445
+
446
+ `IEntityStorageMigrationConnector.createTargetConnector`
257
447
 
258
448
  ***
259
449
 
260
- ### tableDelete()
450
+ ### finalizeMigration() {#finalizemigration}
261
451
 
262
- > **tableDelete**(): `Promise`\<`void`\>
452
+ > **finalizeMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`DynamoDbEntityStorageConnector`\<`U`\>\>
263
453
 
264
- Delete the table.
454
+ Finalize the migration by tearing down the old connector and replacing it with the new one.
455
+
456
+ #### Type Parameters
457
+
458
+ ##### U
459
+
460
+ `U`
461
+
462
+ #### Parameters
463
+
464
+ ##### targetConnector
465
+
466
+ `DynamoDbEntityStorageConnector`\<`U`\>
467
+
468
+ The target connector to finalize the migration with.
469
+
470
+ ##### options?
471
+
472
+ `IMigrationOptions`\<`T`, `U`\>
473
+
474
+ The options to control how the migration is finalized.
475
+
476
+ ##### loggingComponentType?
477
+
478
+ `string`
479
+
480
+ The logging component type to use for logging during the migration finalization.
481
+
482
+ #### Returns
483
+
484
+ `Promise`\<`DynamoDbEntityStorageConnector`\<`U`\>\>
485
+
486
+ A promise that resolves when the migration is finalized.
487
+
488
+ #### Implementation of
489
+
490
+ `IEntityStorageMigrationConnector.finalizeMigration`
491
+
492
+ ***
493
+
494
+ ### cleanupMigration() {#cleanupmigration}
495
+
496
+ > **cleanupMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`void`\>
497
+
498
+ Cleanup the migration if a migration fails or needs to be aborted.
499
+
500
+ #### Type Parameters
501
+
502
+ ##### U
503
+
504
+ `U`
505
+
506
+ #### Parameters
507
+
508
+ ##### targetConnector
509
+
510
+ `IEntityStorageConnector`\<`U`\> \| `undefined`
511
+
512
+ The target connector to cleanup the migration with.
513
+
514
+ ##### options?
515
+
516
+ `IMigrationOptions`\<`T`, `U`\>
517
+
518
+ The options to control how the migration is cleaned up.
519
+
520
+ ##### loggingComponentType?
521
+
522
+ `string`
523
+
524
+ The optional component type to use for logging the migration progress.
265
525
 
266
526
  #### Returns
267
527
 
268
528
  `Promise`\<`void`\>
269
529
 
270
- Nothing.
530
+ A promise that resolves when the migration is cleaned up.
531
+
532
+ #### Implementation of
533
+
534
+ `IEntityStorageMigrationConnector.cleanupMigration`
@@ -4,7 +4,7 @@ Configuration for the Dynamo DB Entity Storage Connector.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### region
7
+ ### region {#region}
8
8
 
9
9
  > **region**: `string`
10
10
 
@@ -12,9 +12,9 @@ The region for the AWS connection.
12
12
 
13
13
  ***
14
14
 
15
- ### authMode?
15
+ ### authMode? {#authmode}
16
16
 
17
- > `optional` **authMode**: `"credentials"` \| `"pod"`
17
+ > `optional` **authMode?**: `"credentials"` \| `"pod"`
18
18
 
19
19
  The authentication mode.
20
20
  - "credentials": Use access key ID and secret access key.
@@ -28,23 +28,23 @@ credentials
28
28
 
29
29
  ***
30
30
 
31
- ### accessKeyId?
31
+ ### accessKeyId? {#accesskeyid}
32
32
 
33
- > `optional` **accessKeyId**: `string`
33
+ > `optional` **accessKeyId?**: `string`
34
34
 
35
35
  The AWS access key ID.
36
36
 
37
37
  ***
38
38
 
39
- ### secretAccessKey?
39
+ ### secretAccessKey? {#secretaccesskey}
40
40
 
41
- > `optional` **secretAccessKey**: `string`
41
+ > `optional` **secretAccessKey?**: `string`
42
42
 
43
43
  The AWS secret access key.
44
44
 
45
45
  ***
46
46
 
47
- ### tableName
47
+ ### tableName {#tablename}
48
48
 
49
49
  > **tableName**: `string`
50
50
 
@@ -52,8 +52,25 @@ The name of the table for the storage.
52
52
 
53
53
  ***
54
54
 
55
- ### endpoint?
55
+ ### endpoint? {#endpoint}
56
56
 
57
- > `optional` **endpoint**: `string`
57
+ > `optional` **endpoint?**: `string`
58
58
 
59
59
  AWS endpoint, not usually required but could be used for local DynamoDB instance e.g. http://localhost:10000.
60
+
61
+ ***
62
+
63
+ ### connectionTimeoutMs? {#connectiontimeoutms}
64
+
65
+ > `optional` **connectionTimeoutMs?**: `number`
66
+
67
+ The connection timeout in milliseconds.
68
+
69
+ ***
70
+
71
+ ### maxAttempts? {#maxattempts}
72
+
73
+ > `optional` **maxAttempts?**: `number`
74
+
75
+ Maximum number of attempts for each SDK request (1 = no retries).
76
+ Defaults to the AWS SDK default (3).
@@ -4,7 +4,7 @@ Options for the Dynamo DB Entity Storage Connector constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### entitySchema
7
+ ### entitySchema {#entityschema}
8
8
 
9
9
  > **entitySchema**: `string`
10
10
 
@@ -12,23 +12,23 @@ The schema for the entity
12
12
 
13
13
  ***
14
14
 
15
- ### partitionContextIds?
15
+ ### partitionContextIds? {#partitioncontextids}
16
16
 
17
- > `optional` **partitionContextIds**: `string`[]
17
+ > `optional` **partitionContextIds?**: `string`[]
18
18
 
19
19
  The keys to use from the context ids to create partitions.
20
20
 
21
21
  ***
22
22
 
23
- ### loggingComponentType?
23
+ ### loggingComponentType? {#loggingcomponenttype}
24
24
 
25
- > `optional` **loggingComponentType**: `string`
25
+ > `optional` **loggingComponentType?**: `string`
26
26
 
27
27
  The type of logging component to use, defaults to no logging.
28
28
 
29
29
  ***
30
30
 
31
- ### config
31
+ ### config {#config}
32
32
 
33
33
  > **config**: [`IDynamoDbEntityStorageConnectorConfig`](IDynamoDbEntityStorageConnectorConfig.md)
34
34
 
package/locales/en.json CHANGED
@@ -3,7 +3,9 @@
3
3
  "dynamoDbEntityStorageConnector": {
4
4
  "tableCreating": "Creating table \"{tableName}\"",
5
5
  "tableCreated": "Created table \"{tableName}\"",
6
- "tableExists": "Skipping create table \"{tableName}\" as it already exists"
6
+ "tableExists": "Skipping create table \"{tableName}\" as it already exists",
7
+ "tableDeleting": "Deleting table \"{tableName}\"",
8
+ "tableDeleted": "Table \"{tableName}\" deleted"
7
9
  }
8
10
  },
9
11
  "error": {
@@ -18,7 +20,20 @@
18
20
  "conditionalNotSupported": "Conditional operator \"{operator}\" is not supported",
19
21
  "sortSingle": "You can only sort by a single property",
20
22
  "sortNotIndexed": "The property \"{property}\" is not indexed and cannot be used for sorting",
21
- "propertyNotFound": "The property \"{property}\" was not found on the entity schema"
23
+ "propertyNotFound": "The property \"{property}\" was not found on the entity schema",
24
+ "getPartitionContextIdsFailed": "Unable to get partition context ids",
25
+ "setBatchFailed": "Unable to set batch of entities",
26
+ "removeBatchFailed": "Unable to remove batch of entities",
27
+ "emptyFailed": "Unable to empty entity storage",
28
+ "countFailed": "Unable to count entities",
29
+ "teardownFailed": "Unable to teardown entity storage",
30
+ "finalizeMigrationFailedBootstrap": "Finalizing migration failed during bootstrap phase"
31
+ }
32
+ },
33
+ "health": {
34
+ "dynamoDbEntityStorageConnector": {
35
+ "healthDescription": "Checks if the DynamoDB table \"{tableName}\" is available",
36
+ "connectionFailed": "Failed to connect to DynamoDB table \"{tableName}\""
22
37
  }
23
38
  }
24
39
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-dynamodb",
3
- "version": "0.0.3-next.2",
4
- "description": "Entity Storage connector implementation using DynamoDb storage",
3
+ "version": "0.0.3-next.21",
4
+ "description": "Amazon DynamoDB connector for managed NoSQL persistence.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/entity-storage.git",
7
+ "url": "git+https://github.com/iotaledger/twin-entity-storage.git",
8
8
  "directory": "packages/entity-storage-connector-dynamodb"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -14,13 +14,13 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@aws-sdk/client-dynamodb": "3.927",
18
- "@aws-sdk/lib-dynamodb": "3.927",
19
- "@aws-sdk/util-dynamodb": "3.927",
17
+ "@aws-sdk/client-dynamodb": "3.1050",
18
+ "@aws-sdk/lib-dynamodb": "3.1050",
19
+ "@aws-sdk/util-dynamodb": "3.996",
20
20
  "@twin.org/context": "next",
21
21
  "@twin.org/core": "next",
22
22
  "@twin.org/entity": "next",
23
- "@twin.org/entity-storage-models": "0.0.3-next.2",
23
+ "@twin.org/entity-storage-models": "0.0.3-next.21",
24
24
  "@twin.org/logging-models": "next",
25
25
  "@twin.org/nameof": "next"
26
26
  },
@@ -56,7 +56,7 @@
56
56
  "integration"
57
57
  ],
58
58
  "bugs": {
59
- "url": "git+https://github.com/twinfoundation/entity-storage/issues"
59
+ "url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
60
60
  },
61
61
  "homepage": "https://twindev.org"
62
62
  }