@twin.org/entity-storage-connector-cosmosdb 0.0.3-next.6 → 0.0.3-next.7
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/README.md +7 -18
- package/docs/changelog.md +19 -1
- package/docs/examples.md +96 -1
- package/docs/reference/classes/CosmosDbEntityStorageConnector.md +9 -9
- package/docs/reference/interfaces/ICosmosDbEntityStorageConnectorConfig.md +5 -5
- package/docs/reference/interfaces/ICosmosDbEntityStorageConnectorConstructorOptions.md +4 -10
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entity Storage Connector Cosmos DB
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides an Azure Cosmos DB backend for globally distributed persistence across regions. It is designed to work with the wider storage ecosystem so applications can keep behaviour consistent across connectors and environments.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,24 +8,13 @@ Entity Storage connector implementation using Cosmos DB storage.
|
|
|
8
8
|
npm install @twin.org/entity-storage-connector-cosmosdb
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Docker
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
To perform testing of this component it may be necessary to launch a local instance to communicate with.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
docker run -d --platform=linux/amd64 -p 8081:8081 -m 3g --name twin-entity-storage-cosmos -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true -e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE='127.0.0.1' mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Or
|
|
22
|
-
|
|
23
|
-
To install and run the Azure CosmosDB Emulator [Azure CosmosDB Emulator](https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator)
|
|
24
|
-
|
|
25
|
-
Afterwards you can run the tests as follows:
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
npm run test
|
|
15
|
+
```shell
|
|
16
|
+
docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
|
|
17
|
+
docker run --publish 8081:8081 --name twin-entity-storage-cosmos --detach --platform=linux/amd64 --memory=3g --cpus=2.0 mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
|
|
29
18
|
```
|
|
30
19
|
|
|
31
20
|
## Examples
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.7](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-cosmosdb-v0.0.3-next.6...entity-storage-connector-cosmosdb-v0.0.3-next.7) (2026-03-13)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* adding tests and fixes for dot notation ([#76](https://github.com/twinfoundation/entity-storage/issues/76)) ([3879337](https://github.com/twinfoundation/entity-storage/commit/387933797e33543e4d8b2d49b8beeb792512a4ff))
|
|
9
|
+
* improve cosmodb tests ([d1a23c7](https://github.com/twinfoundation/entity-storage/commit/d1a23c79a59250351ad71ca7074b4bda79004e2e))
|
|
10
|
+
* improve cosmodb tests ([4819d70](https://github.com/twinfoundation/entity-storage/commit/4819d706500822e8093314b72d8f7923fc903f0c))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Dependencies
|
|
14
|
+
|
|
15
|
+
* The following workspace dependencies were updated
|
|
16
|
+
* dependencies
|
|
17
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
18
|
+
* devDependencies
|
|
19
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
2
20
|
|
|
3
21
|
## [0.0.3-next.6](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-cosmosdb-v0.0.3-next.5...entity-storage-connector-cosmosdb-v0.0.3-next.6) (2026-01-21)
|
|
4
22
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,96 @@
|
|
|
1
|
-
#
|
|
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
|
+
```
|
|
@@ -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
|
|
|
@@ -68,7 +68,7 @@ A promise that resolves to a boolean indicating success.
|
|
|
68
68
|
|
|
69
69
|
***
|
|
70
70
|
|
|
71
|
-
### className()
|
|
71
|
+
### className() {#classname}
|
|
72
72
|
|
|
73
73
|
> **className**(): `string`
|
|
74
74
|
|
|
@@ -86,7 +86,7 @@ The class name of the component.
|
|
|
86
86
|
|
|
87
87
|
***
|
|
88
88
|
|
|
89
|
-
### getSchema()
|
|
89
|
+
### getSchema() {#getschema}
|
|
90
90
|
|
|
91
91
|
> **getSchema**(): `IEntitySchema`
|
|
92
92
|
|
|
@@ -104,7 +104,7 @@ The schema for the entities.
|
|
|
104
104
|
|
|
105
105
|
***
|
|
106
106
|
|
|
107
|
-
### get()
|
|
107
|
+
### get() {#get}
|
|
108
108
|
|
|
109
109
|
> **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
|
|
110
110
|
|
|
@@ -142,7 +142,7 @@ The object if it can be found or undefined.
|
|
|
142
142
|
|
|
143
143
|
***
|
|
144
144
|
|
|
145
|
-
### set()
|
|
145
|
+
### set() {#set}
|
|
146
146
|
|
|
147
147
|
> **set**(`entity`, `conditions?`): `Promise`\<`void`\>
|
|
148
148
|
|
|
@@ -174,7 +174,7 @@ The id of the entity.
|
|
|
174
174
|
|
|
175
175
|
***
|
|
176
176
|
|
|
177
|
-
### remove()
|
|
177
|
+
### remove() {#remove}
|
|
178
178
|
|
|
179
179
|
> **remove**(`id`, `conditions?`): `Promise`\<`void`\>
|
|
180
180
|
|
|
@@ -206,7 +206,7 @@ Nothing.
|
|
|
206
206
|
|
|
207
207
|
***
|
|
208
208
|
|
|
209
|
-
### query()
|
|
209
|
+
### query() {#query}
|
|
210
210
|
|
|
211
211
|
> **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
212
212
|
|
|
@@ -257,7 +257,7 @@ and a cursor which can be used to request more entities.
|
|
|
257
257
|
|
|
258
258
|
***
|
|
259
259
|
|
|
260
|
-
### containerDelete()
|
|
260
|
+
### containerDelete() {#containerdelete}
|
|
261
261
|
|
|
262
262
|
> **containerDelete**(): `Promise`\<`void`\>
|
|
263
263
|
|
|
@@ -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,7 +36,7 @@ The ID of the container for the storage.
|
|
|
36
36
|
|
|
37
37
|
***
|
|
38
38
|
|
|
39
|
-
### offerThroughput?
|
|
39
|
+
### offerThroughput? {#offerthroughput}
|
|
40
40
|
|
|
41
41
|
> `optional` **offerThroughput**: `number`
|
|
42
42
|
|
|
@@ -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,7 +12,7 @@ The schema for the entity.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### partitionContextIds?
|
|
15
|
+
### partitionContextIds? {#partitioncontextids}
|
|
16
16
|
|
|
17
17
|
> `optional` **partitionContextIds**: `string`[]
|
|
18
18
|
|
|
@@ -20,21 +20,15 @@ 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
25
|
> `optional` **loggingComponentType**: `string`
|
|
26
26
|
|
|
27
27
|
The type of logging component to use.
|
|
28
28
|
|
|
29
|
-
#### Default
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
logging
|
|
33
|
-
```
|
|
34
|
-
|
|
35
29
|
***
|
|
36
30
|
|
|
37
|
-
### config
|
|
31
|
+
### config {#config}
|
|
38
32
|
|
|
39
33
|
> **config**: [`ICosmosDbEntityStorageConnectorConfig`](ICosmosDbEntityStorageConnectorConfig.md)
|
|
40
34
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-connector-cosmosdb",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.7",
|
|
4
|
+
"description": "Azure Cosmos DB connector for globally distributed persistence.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/entity-storage.git",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@azure/cosmos": "4.
|
|
17
|
+
"@azure/cosmos": "4.9.1",
|
|
18
18
|
"@azure/identity": "4.13.0",
|
|
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.
|
|
22
|
+
"@twin.org/entity-storage-models": "0.0.3-next.7",
|
|
23
23
|
"@twin.org/logging-models": "next",
|
|
24
24
|
"@twin.org/nameof": "next"
|
|
25
25
|
},
|