@twin.org/entity-storage-connector-mongodb 0.0.1-next.20

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,254 @@
1
+ # Class: MongoDbEntityStorageConnector\<T\>
2
+
3
+ Class for performing entity storage operations using MongoDb.
4
+
5
+ ## Type Parameters
6
+
7
+ • **T** = `unknown`
8
+
9
+ ## Implements
10
+
11
+ - `IEntityStorageConnector`\<`T`\>
12
+
13
+ ## Constructors
14
+
15
+ ### new MongoDbEntityStorageConnector()
16
+
17
+ > **new MongoDbEntityStorageConnector**\<`T`\>(`options`): [`MongoDbEntityStorageConnector`](MongoDbEntityStorageConnector.md)\<`T`\>
18
+
19
+ Create a new instance of MongoDbEntityStorageConnector.
20
+
21
+ #### Parameters
22
+
23
+ ##### options
24
+
25
+ [`IMongoDbEntityStorageConnectorConstructorOptions`](../interfaces/IMongoDbEntityStorageConnectorConstructorOptions.md)
26
+
27
+ The options for the connector.
28
+
29
+ #### Returns
30
+
31
+ [`MongoDbEntityStorageConnector`](MongoDbEntityStorageConnector.md)\<`T`\>
32
+
33
+ ## Properties
34
+
35
+ ### CLASS\_NAME
36
+
37
+ > `readonly` **CLASS\_NAME**: `string`
38
+
39
+ Runtime name for the class.
40
+
41
+ #### Implementation of
42
+
43
+ `IEntityStorageConnector.CLASS_NAME`
44
+
45
+ ## Methods
46
+
47
+ ### bootstrap()
48
+
49
+ > **bootstrap**(`nodeLoggingConnectorType`?): `Promise`\<`boolean`\>
50
+
51
+ Initialize the MongoDb environment.
52
+
53
+ #### Parameters
54
+
55
+ ##### nodeLoggingConnectorType?
56
+
57
+ `string`
58
+
59
+ Optional type of the logging connector.
60
+
61
+ #### Returns
62
+
63
+ `Promise`\<`boolean`\>
64
+
65
+ A promise that resolves to a boolean indicating success.
66
+
67
+ #### Implementation of
68
+
69
+ `IEntityStorageConnector.bootstrap`
70
+
71
+ ***
72
+
73
+ ### getSchema()
74
+
75
+ > **getSchema**(): `IEntitySchema`
76
+
77
+ Get the schema for the entities.
78
+
79
+ #### Returns
80
+
81
+ `IEntitySchema`
82
+
83
+ The schema for the entities.
84
+
85
+ #### Implementation of
86
+
87
+ `IEntityStorageConnector.getSchema`
88
+
89
+ ***
90
+
91
+ ### get()
92
+
93
+ > **get**(`id`, `secondaryIndex`?, `conditions`?): `Promise`\<`undefined` \| `T`\>
94
+
95
+ Get an entity from MongoDb.
96
+
97
+ #### Parameters
98
+
99
+ ##### id
100
+
101
+ `string`
102
+
103
+ The id of the entity to get, or the index value if secondaryIndex is set.
104
+
105
+ ##### secondaryIndex?
106
+
107
+ keyof `T`
108
+
109
+ Get the item using a secondary index.
110
+
111
+ ##### conditions?
112
+
113
+ `object`[]
114
+
115
+ The optional conditions to match for the entities.
116
+
117
+ #### Returns
118
+
119
+ `Promise`\<`undefined` \| `T`\>
120
+
121
+ The object if it can be found or undefined.
122
+
123
+ #### Implementation of
124
+
125
+ `IEntityStorageConnector.get`
126
+
127
+ ***
128
+
129
+ ### set()
130
+
131
+ > **set**(`entity`, `conditions`?): `Promise`\<`void`\>
132
+
133
+ Set an entity.
134
+
135
+ #### Parameters
136
+
137
+ ##### entity
138
+
139
+ `T`
140
+
141
+ The entity to set.
142
+
143
+ ##### conditions?
144
+
145
+ `object`[]
146
+
147
+ The optional conditions to match for the entities.
148
+
149
+ #### Returns
150
+
151
+ `Promise`\<`void`\>
152
+
153
+ The id of the entity.
154
+
155
+ #### Implementation of
156
+
157
+ `IEntityStorageConnector.set`
158
+
159
+ ***
160
+
161
+ ### remove()
162
+
163
+ > **remove**(`id`, `conditions`?): `Promise`\<`void`\>
164
+
165
+ Remove the entity.
166
+
167
+ #### Parameters
168
+
169
+ ##### id
170
+
171
+ `string`
172
+
173
+ The id of the entity to remove.
174
+
175
+ ##### conditions?
176
+
177
+ `object`[]
178
+
179
+ The optional conditions to match for the entities.
180
+
181
+ #### Returns
182
+
183
+ `Promise`\<`void`\>
184
+
185
+ Nothing.
186
+
187
+ #### Implementation of
188
+
189
+ `IEntityStorageConnector.remove`
190
+
191
+ ***
192
+
193
+ ### query()
194
+
195
+ > **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor`: `string`; \}\>
196
+
197
+ Find all the entities which match the conditions.
198
+
199
+ #### Parameters
200
+
201
+ ##### conditions?
202
+
203
+ `EntityCondition`\<`T`\>
204
+
205
+ The conditions to match for the entities.
206
+
207
+ ##### sortProperties?
208
+
209
+ `object`[]
210
+
211
+ The optional sort order.
212
+
213
+ ##### properties?
214
+
215
+ keyof `T`[]
216
+
217
+ The optional properties to return, defaults to all.
218
+
219
+ ##### cursor?
220
+
221
+ `string`
222
+
223
+ The cursor to request the next page of entities.
224
+
225
+ ##### pageSize?
226
+
227
+ `number`
228
+
229
+ The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
230
+
231
+ #### Returns
232
+
233
+ `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor`: `string`; \}\>
234
+
235
+ All the entities for the storage matching the conditions,
236
+ and a cursor which can be used to request more entities.
237
+
238
+ #### Implementation of
239
+
240
+ `IEntityStorageConnector.query`
241
+
242
+ ***
243
+
244
+ ### collectionDrop()
245
+
246
+ > **collectionDrop**(): `Promise`\<`void`\>
247
+
248
+ Drop the collection.
249
+
250
+ #### Returns
251
+
252
+ `Promise`\<`void`\>
253
+
254
+ Nothing.
@@ -0,0 +1,10 @@
1
+ # @twin.org/entity-storage-connector-mongodb
2
+
3
+ ## Classes
4
+
5
+ - [MongoDbEntityStorageConnector](classes/MongoDbEntityStorageConnector.md)
6
+
7
+ ## Interfaces
8
+
9
+ - [IMongoDbEntityStorageConnectorConfig](interfaces/IMongoDbEntityStorageConnectorConfig.md)
10
+ - [IMongoDbEntityStorageConnectorConstructorOptions](interfaces/IMongoDbEntityStorageConnectorConstructorOptions.md)
@@ -0,0 +1,51 @@
1
+ # Interface: IMongoDbEntityStorageConnectorConfig
2
+
3
+ Configuration for the MongoDb Entity Storage Connector.
4
+
5
+ ## Properties
6
+
7
+ ### host
8
+
9
+ > **host**: `string`
10
+
11
+ The host for the MongoDb instance.
12
+
13
+ ***
14
+
15
+ ### port?
16
+
17
+ > `optional` **port**: `number`
18
+
19
+ The port for the MongoDb instance.
20
+
21
+ ***
22
+
23
+ ### user?
24
+
25
+ > `optional` **user**: `string`
26
+
27
+ The user for the MongoDb instance.
28
+
29
+ ***
30
+
31
+ ### password?
32
+
33
+ > `optional` **password**: `string`
34
+
35
+ The password for the MongoDb instance.
36
+
37
+ ***
38
+
39
+ ### database
40
+
41
+ > **database**: `string`
42
+
43
+ The name of the database to be used.
44
+
45
+ ***
46
+
47
+ ### collection
48
+
49
+ > **collection**: `string`
50
+
51
+ The name of the collection to be used.
@@ -0,0 +1,33 @@
1
+ # Interface: IMongoDbEntityStorageConnectorConstructorOptions
2
+
3
+ The options for the MongoDb entity storage connector constructor.
4
+
5
+ ## Properties
6
+
7
+ ### entitySchema
8
+
9
+ > **entitySchema**: `string`
10
+
11
+ The schema for the entity.
12
+
13
+ ***
14
+
15
+ ### loggingConnectorType?
16
+
17
+ > `optional` **loggingConnectorType**: `string`
18
+
19
+ The type of logging connector to use.
20
+
21
+ #### Default
22
+
23
+ ```ts
24
+ logging
25
+ ```
26
+
27
+ ***
28
+
29
+ ### config
30
+
31
+ > **config**: [`IMongoDbEntityStorageConnectorConfig`](IMongoDbEntityStorageConnectorConfig.md)
32
+
33
+ The configuration for the connector.
@@ -0,0 +1,21 @@
1
+ {
2
+ "info": {
3
+ "mongoDbEntityStorageConnector": {
4
+ "databaseCreating": "Database \"{databaseName}\" creating",
5
+ "databaseExists": "Database \"{databaseName}\" created or it already exists",
6
+ "collectionExists": "Database \"{collectionName}\" created or it already exists"
7
+ }
8
+ },
9
+ "error": {
10
+ "mongoDbEntityStorageConnector": {
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
+ }
20
+ }
21
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@twin.org/entity-storage-connector-mongodb",
3
+ "version": "0.0.1-next.20",
4
+ "description": "Entity Storage connector implementation using MongoDb storage",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/twinfoundation/entity-storage.git",
8
+ "directory": "packages/entity-storage-connector-mongodb"
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
+ "@twin.org/core": "next",
18
+ "@twin.org/entity": "next",
19
+ "@twin.org/entity-storage-models": "0.0.1-next.20",
20
+ "@twin.org/logging-models": "next",
21
+ "@twin.org/nameof": "next",
22
+ "mongodb": "^6.12.0"
23
+ },
24
+ "main": "./dist/cjs/index.cjs",
25
+ "module": "./dist/esm/index.mjs",
26
+ "types": "./dist/types/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/types/index.d.ts",
30
+ "require": "./dist/cjs/index.cjs",
31
+ "import": "./dist/esm/index.mjs"
32
+ },
33
+ "./locales/*.json": "./locales/*.json"
34
+ },
35
+ "files": [
36
+ "dist/cjs",
37
+ "dist/esm",
38
+ "dist/types",
39
+ "locales",
40
+ "docs"
41
+ ]
42
+ }