@twin.org/entity-storage-connector-cosmosdb 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-cosmosdb - Examples
1
+ # Entity Storage Connector CosmosDB Examples
2
+
3
+ Use these snippets to configure a connector, work with common entity operations, and clean up storage resources when running integration tests.
4
+
5
+ ## CosmosDbEntityStorageConnector
6
+
7
+ ```typescript
8
+ import {
9
+ CosmosDbEntityStorageConnector,
10
+ type ICosmosDbEntityStorageConnectorConstructorOptions
11
+ } from '@twin.org/entity-storage-connector-cosmosdb';
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: ICosmosDbEntityStorageConnectorConstructorOptions = {
27
+ entitySchema: 'Profile',
28
+ config: {
29
+ endpoint: 'https://example.documents.azure.com:443/',
30
+ key: 'cosmos-primary-key',
31
+ databaseId: 'entityStorage',
32
+ containerId: 'profiles',
33
+ offerThroughput: 400
34
+ }
35
+ };
36
+
37
+ const connector = new CosmosDbEntityStorageConnector<Profile>(options);
38
+ await connector.bootstrap();
39
+
40
+ const className = connector.className();
41
+ const schema = connector.getSchema();
42
+
43
+ await connector.set({
44
+ id: 'profile-1',
45
+ email: 'ada@example.com',
46
+ status: 'active',
47
+ createdAt: '2026-03-09T10:30:00.000Z'
48
+ });
49
+
50
+ const byPrimaryKey = await connector.get('profile-1');
51
+ const bySecondaryIndex = await connector.get('ada@example.com', 'email');
52
+
53
+ const activeCondition: EntityCondition<Profile> = {
54
+ logicalOperator: LogicalOperator.And,
55
+ conditions: [
56
+ {
57
+ property: 'status',
58
+ comparison: ComparisonOperator.Equals,
59
+ value: 'active'
60
+ }
61
+ ]
62
+ };
63
+
64
+ const result = await connector.query(
65
+ activeCondition,
66
+ [{ property: 'createdAt', sortDirection: SortDirection.Descending }],
67
+ ['id', 'email', 'status'],
68
+ undefined,
69
+ 25
70
+ );
71
+
72
+ await connector.remove('profile-1');
73
+ ```
74
+
75
+ ```typescript
76
+ import { CosmosDbEntityStorageConnector } from '@twin.org/entity-storage-connector-cosmosdb';
77
+
78
+ interface Profile {
79
+ id: string;
80
+ email: string;
81
+ status: 'active' | 'inactive';
82
+ createdAt: string;
83
+ }
84
+
85
+ const connector = new CosmosDbEntityStorageConnector<Profile>({
86
+ entitySchema: 'Profile',
87
+ config: {
88
+ endpoint: 'https://example.documents.azure.com:443/',
89
+ key: 'cosmos-primary-key',
90
+ databaseId: 'entityStorage',
91
+ containerId: 'profiles'
92
+ }
93
+ });
94
+
95
+ await connector.containerDelete();
96
+ ```
@@ -10,7 +10,7 @@ Class for performing entity storage operations using Cosmos 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
- ### bootstrap()
45
+ ### bootstrap() {#bootstrap}
46
46
 
47
47
  > **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
48
48
 
@@ -64,11 +64,11 @@ A promise that resolves to a boolean indicating success.
64
64
 
65
65
  #### Implementation of
66
66
 
67
- `IEntityStorageConnector.bootstrap`
67
+ `IEntityStorageMigrationConnector.bootstrap`
68
68
 
69
69
  ***
70
70
 
71
- ### className()
71
+ ### className() {#classname}
72
72
 
73
73
  > **className**(): `string`
74
74
 
@@ -82,11 +82,29 @@ The class name of the component.
82
82
 
83
83
  #### Implementation of
84
84
 
85
- `IEntityStorageConnector.className`
85
+ `IEntityStorageMigrationConnector.className`
86
86
 
87
87
  ***
88
88
 
89
- ### getSchema()
89
+ ### health() {#health}
90
+
91
+ > **health**(): `Promise`\<`IHealth`[]\>
92
+
93
+ Returns the health status of the component.
94
+
95
+ #### Returns
96
+
97
+ `Promise`\<`IHealth`[]\>
98
+
99
+ The health status of the component.
100
+
101
+ #### Implementation of
102
+
103
+ `IEntityStorageMigrationConnector.health`
104
+
105
+ ***
106
+
107
+ ### getSchema() {#getschema}
90
108
 
91
109
  > **getSchema**(): `IEntitySchema`
92
110
 
@@ -100,11 +118,11 @@ The schema for the entities.
100
118
 
101
119
  #### Implementation of
102
120
 
103
- `IEntityStorageConnector.getSchema`
121
+ `IEntityStorageMigrationConnector.getSchema`
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 all entities from the 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`
206
268
 
207
269
  ***
208
270
 
209
- ### query()
271
+ ### removeBatch() {#removebatch}
272
+
273
+ > **removeBatch**(`ids`): `Promise`\<`void`\>
274
+
275
+ Remove multiple entities by id.
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 storage by deleting the underlying container.
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`
320
+
321
+ ***
322
+
323
+ ### query() {#query}
210
324
 
211
325
  > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
212
326
 
@@ -253,18 +367,166 @@ 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`
257
415
 
258
416
  ***
259
417
 
260
- ### containerDelete()
418
+ ### createTargetConnector() {#createtargetconnector}
419
+
420
+ > **createTargetConnector**\<`U`\>(`newEntitySchema`): `Promise`\<`IEntityStorageConnector`\<`U`\>\>
421
+
422
+ Create the target connector for performing the migration using a temporary container.
423
+
424
+ #### Type Parameters
425
+
426
+ ##### U
261
427
 
262
- > **containerDelete**(): `Promise`\<`void`\>
428
+ `U`
263
429
 
264
- Delete the container.
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`
447
+
448
+ ***
449
+
450
+ ### finalizeMigration() {#finalizemigration}
451
+
452
+ > **finalizeMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`CosmosDbEntityStorageConnector`\<`U`\>\>
453
+
454
+ Finalize the migration by tearing down the old container and replacing it with the target container.
455
+
456
+ #### Type Parameters
457
+
458
+ ##### U
459
+
460
+ `U`
461
+
462
+ #### Parameters
463
+
464
+ ##### targetConnector
465
+
466
+ `CosmosDbEntityStorageConnector`\<`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 optional component type to use for logging.
481
+
482
+ #### Returns
483
+
484
+ `Promise`\<`CosmosDbEntityStorageConnector`\<`U`\>\>
485
+
486
+ The final connector pointing at the original container id.
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.
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.
265
525
 
266
526
  #### Returns
267
527
 
268
528
  `Promise`\<`void`\>
269
529
 
270
- Nothing.
530
+ #### Implementation of
531
+
532
+ `IEntityStorageMigrationConnector.cleanupMigration`
@@ -4,7 +4,7 @@ Configuration for the Cosmos DB Entity Storage Connector.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### endpoint
7
+ ### endpoint {#endpoint}
8
8
 
9
9
  > **endpoint**: `string`
10
10
 
@@ -12,7 +12,7 @@ The endpoint for the Cosmos DB instance.
12
12
 
13
13
  ***
14
14
 
15
- ### key
15
+ ### key {#key}
16
16
 
17
17
  > **key**: `string`
18
18
 
@@ -20,7 +20,7 @@ The primary key for the Cosmos DB instance.
20
20
 
21
21
  ***
22
22
 
23
- ### databaseId
23
+ ### databaseId {#databaseid}
24
24
 
25
25
  > **databaseId**: `string`
26
26
 
@@ -28,7 +28,7 @@ The ID of the database to be used.
28
28
 
29
29
  ***
30
30
 
31
- ### containerId
31
+ ### containerId {#containerid}
32
32
 
33
33
  > **containerId**: `string`
34
34
 
@@ -36,8 +36,19 @@ The ID of the container for the storage.
36
36
 
37
37
  ***
38
38
 
39
- ### offerThroughput?
39
+ ### offerThroughput? {#offerthroughput}
40
40
 
41
- > `optional` **offerThroughput**: `number`
41
+ > `optional` **offerThroughput?**: `number`
42
42
 
43
43
  The offer throughput for the container.
44
+
45
+ ***
46
+
47
+ ### disableEndpointDiscovery? {#disableendpointdiscovery}
48
+
49
+ > `optional` **disableEndpointDiscovery?**: `boolean`
50
+
51
+ Disable endpoint discovery so the SDK always uses the configured endpoint.
52
+ Required when using the CosmosDB emulator behind a port-mapped Docker container,
53
+ because the emulator's account response advertises its internal container port
54
+ instead of the mapped host port.
@@ -4,7 +4,7 @@ The options for the cosmos 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,17 +12,17 @@ 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.
28
28
 
@@ -34,7 +34,7 @@ logging
34
34
 
35
35
  ***
36
36
 
37
- ### config
37
+ ### config {#config}
38
38
 
39
39
  > **config**: [`ICosmosDbEntityStorageConnectorConfig`](ICosmosDbEntityStorageConnectorConfig.md)
40
40
 
package/locales/en.json CHANGED
@@ -4,7 +4,9 @@
4
4
  "databaseCreating": "Database \"{databaseId}\" creating",
5
5
  "databaseExists": "Database \"{databaseId}\" created or it already exists",
6
6
  "containerCreating": "Container \"{containerId}\" creating",
7
- "containerExists": "Container \"{containerId}\" created or it already exists"
7
+ "containerExists": "Container \"{containerId}\" created or it already exists",
8
+ "containerDeleting": "Deleting container \"{containerId}\"",
9
+ "containerDeleted": "Container \"{containerId}\" deleted"
8
10
  }
9
11
  },
10
12
  "error": {
@@ -19,7 +21,20 @@
19
21
  "sortNotIndexed": "The property \"{property}\" is not indexed and cannot be used for sorting",
20
22
  "containerCreateFailed": "The container couldn't be created \"{containerId}\"",
21
23
  "databaseCreateFailed": "Unable to create database \"{databaseId}\"",
22
- "containerDoesNotExist": "Container \"{containerId}\" does not exist"
24
+ "containerDoesNotExist": "Container \"{containerId}\" does not exist",
25
+ "getPartitionContextIdsFailed": "Unable to get partition context ids",
26
+ "setBatchFailed": "Unable to set batch of entities",
27
+ "countFailed": "Unable to count entities",
28
+ "emptyFailed": "Unable to empty entity storage",
29
+ "removeBatchFailed": "Unable to remove batch of entities",
30
+ "teardownFailed": "Unable to teardown entity storage",
31
+ "finalizeMigrationFailedBootstrap": "Finalizing migration failed during bootstrap phase"
32
+ }
33
+ },
34
+ "health": {
35
+ "cosmosDbEntityStorageConnector": {
36
+ "healthDescription": "Checks if the Cosmos DB container \"{containerId}\" in database \"{databaseId}\" is available",
37
+ "connectionFailed": "Failed to connect to Cosmos DB container \"{containerId}\" in database \"{databaseId}\""
23
38
  }
24
39
  }
25
40
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-cosmosdb",
3
- "version": "0.0.3-next.2",
4
- "description": "Entity Storage connector implementation using CosmosDB storage",
3
+ "version": "0.0.3-next.21",
4
+ "description": "Azure Cosmos DB connector for globally distributed 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-cosmosdb"
9
9
  },
10
10
  "author": "adrian.sanchez.sequeira@iota.org",
@@ -14,12 +14,12 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@azure/cosmos": "4.7.0",
18
- "@azure/identity": "4.13.0",
17
+ "@azure/cosmos": "4.9.3",
18
+ "@azure/identity": "4.13.1",
19
19
  "@twin.org/context": "next",
20
20
  "@twin.org/core": "next",
21
21
  "@twin.org/entity": "next",
22
- "@twin.org/entity-storage-models": "0.0.3-next.2",
22
+ "@twin.org/entity-storage-models": "0.0.3-next.21",
23
23
  "@twin.org/logging-models": "next",
24
24
  "@twin.org/nameof": "next"
25
25
  },
@@ -55,7 +55,7 @@
55
55
  "integration"
56
56
  ],
57
57
  "bugs": {
58
- "url": "git+https://github.com/twinfoundation/entity-storage/issues"
58
+ "url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
59
59
  },
60
60
  "homepage": "https://twindev.org"
61
61
  }