@twin.org/entity-storage-connector-cosmosdb 0.0.1-next.12

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,21 @@
1
+ /**
2
+ * Configuration for the Cosmos DB Entity Storage Connector.
3
+ */
4
+ export interface ICosmosDbEntityStorageConnectorConfig {
5
+ /**
6
+ * The endpoint for the Cosmos DB instance.
7
+ */
8
+ endpoint: string;
9
+ /**
10
+ * The primary key for the Cosmos DB instance.
11
+ */
12
+ key: string;
13
+ /**
14
+ * The ID of the database to be used.
15
+ */
16
+ databaseId: string;
17
+ /**
18
+ * The ID of the container for the storage.
19
+ */
20
+ containerId: string;
21
+ }
@@ -0,0 +1,5 @@
1
+ # @twin.org/entity-storage-connector-cosmosdb - Changelog
2
+
3
+ ## v0.0.1-next.12
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/entity-storage-connector-cosmosdb - Examples
@@ -0,0 +1,246 @@
1
+ # Class: CosmosDbEntityStorageConnector\<T\>
2
+
3
+ Class for performing entity storage operations using Cosmos DB.
4
+
5
+ ## Type Parameters
6
+
7
+ • **T** = `unknown`
8
+
9
+ ## Implements
10
+
11
+ - `IEntityStorageConnector`\<`T`\>
12
+
13
+ ## Constructors
14
+
15
+ ### new CosmosDbEntityStorageConnector()
16
+
17
+ > **new CosmosDbEntityStorageConnector**\<`T`\>(`options`): [`CosmosDbEntityStorageConnector`](CosmosDbEntityStorageConnector.md)\<`T`\>
18
+
19
+ Create a new instance of CosmosDbEntityStorageConnector.
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**: [`ICosmosDbEntityStorageConnectorConfig`](../interfaces/ICosmosDbEntityStorageConnectorConfig.md)
36
+
37
+ The configuration for the connector.
38
+
39
+ #### Returns
40
+
41
+ [`CosmosDbEntityStorageConnector`](CosmosDbEntityStorageConnector.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
+ Initialize the Cosmos DB environment.
62
+
63
+ #### Parameters
64
+
65
+ • **nodeLoggingConnectorType?**: `string`
66
+
67
+ Optional type of the logging connector.
68
+
69
+ #### Returns
70
+
71
+ `Promise`\<`boolean`\>
72
+
73
+ A promise that resolves to a boolean indicating success.
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 from Cosmos DB.
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
+ ##### cursor?
227
+
228
+ > `optional` **cursor**: `string`
229
+
230
+ #### Implementation of
231
+
232
+ `IEntityStorageConnector.query`
233
+
234
+ ***
235
+
236
+ ### containerDelete()
237
+
238
+ > **containerDelete**(): `Promise`\<`void`\>
239
+
240
+ Delete the container.
241
+
242
+ #### Returns
243
+
244
+ `Promise`\<`void`\>
245
+
246
+ Nothing.
@@ -0,0 +1,9 @@
1
+ # @twin.org/entity-storage-connector-cosmosdb
2
+
3
+ ## Classes
4
+
5
+ - [CosmosDbEntityStorageConnector](classes/CosmosDbEntityStorageConnector.md)
6
+
7
+ ## Interfaces
8
+
9
+ - [ICosmosDbEntityStorageConnectorConfig](interfaces/ICosmosDbEntityStorageConnectorConfig.md)
@@ -0,0 +1,35 @@
1
+ # Interface: ICosmosDbEntityStorageConnectorConfig
2
+
3
+ Configuration for the Cosmos DB Entity Storage Connector.
4
+
5
+ ## Properties
6
+
7
+ ### endpoint
8
+
9
+ > **endpoint**: `string`
10
+
11
+ The endpoint for the Cosmos DB instance.
12
+
13
+ ***
14
+
15
+ ### key
16
+
17
+ > **key**: `string`
18
+
19
+ The primary key for the Cosmos DB instance.
20
+
21
+ ***
22
+
23
+ ### databaseId
24
+
25
+ > **databaseId**: `string`
26
+
27
+ The ID of the database to be used.
28
+
29
+ ***
30
+
31
+ ### containerId
32
+
33
+ > **containerId**: `string`
34
+
35
+ The ID of the container for the storage.
@@ -0,0 +1,23 @@
1
+ {
2
+ "info": {
3
+ "cosmosDbEntityStorageConnector": {
4
+ "databaseCreating": "Database \"{databaseName}\" creating",
5
+ "databaseExists": "Database \"{databaseName}\" created or it already exists",
6
+ "containerExists": "Container \"{containerName}\" created or it already exists"
7
+ }
8
+ },
9
+ "error": {
10
+ "cosmosDbEntityStorageConnector": {
11
+ "setFailed": "Unable to set entity \"{id}\"",
12
+ "getFailed": "Unable to get entity \"{id}\"",
13
+ "removeFailed": "Unable to remove entity \"{id}\"",
14
+ "queryFailed": "The query failed",
15
+ "comparisonNotSupported": "Comparison operator \"{comparison}\" is not supported",
16
+ "conditionalNotSupported": "Conditional operator \"{operator}\" is not supported",
17
+ "sortSingle": "You can only sort by a single property",
18
+ "sortNotIndexed": "The property \"{property}\" is not indexed and cannot be used for sorting",
19
+ "containerNotExisting": "The expected container definition is undefined",
20
+ "containerNotCreated": "The container couldn't be created"
21
+ }
22
+ }
23
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@twin.org/entity-storage-connector-cosmosdb",
3
+ "version": "0.0.1-next.12",
4
+ "description": "Entity Storage connector implementation using CosmosDB storage",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/twinfoundation/entity-storage.git",
8
+ "directory": "packages/entity-storage-connector-cosmosdb"
9
+ },
10
+ "author": "adrian.sanchez.sequeira@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "dependencies": {
17
+ "@azure/cosmos": "^4.1.1",
18
+ "@azure/identity": "^4.4.1",
19
+ "@twin.org/core": "next",
20
+ "@twin.org/entity": "next",
21
+ "@twin.org/entity-storage-models": "0.0.1-next.12",
22
+ "@twin.org/logging-models": "next",
23
+ "@twin.org/nameof": "next"
24
+ },
25
+ "main": "./dist/cjs/index.cjs",
26
+ "module": "./dist/esm/index.mjs",
27
+ "types": "./dist/types/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "require": "./dist/cjs/index.cjs",
31
+ "import": "./dist/esm/index.mjs",
32
+ "types": "./dist/types/index.d.ts"
33
+ },
34
+ "./locales": "./locales"
35
+ },
36
+ "files": [
37
+ "dist/cjs",
38
+ "dist/esm",
39
+ "dist/types",
40
+ "locales",
41
+ "docs"
42
+ ]
43
+ }