@twin.org/entity-storage-models 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.
Files changed (63) hide show
  1. package/README.md +2 -2
  2. package/dist/es/helpers/entityStorageHelper.js +85 -0
  3. package/dist/es/helpers/entityStorageHelper.js.map +1 -0
  4. package/dist/es/helpers/migrationHelper.js +220 -0
  5. package/dist/es/helpers/migrationHelper.js.map +1 -0
  6. package/dist/es/index.js +9 -0
  7. package/dist/es/index.js.map +1 -1
  8. package/dist/es/models/IEntityStorageComponent.js.map +1 -1
  9. package/dist/es/models/IEntityStorageConnector.js.map +1 -1
  10. package/dist/es/models/IEntityStorageMigrationConnector.js +2 -0
  11. package/dist/es/models/IEntityStorageMigrationConnector.js.map +1 -0
  12. package/dist/es/models/IMigrationOptions.js +4 -0
  13. package/dist/es/models/IMigrationOptions.js.map +1 -0
  14. package/dist/es/models/api/IEntityStorageCountRequest.js +4 -0
  15. package/dist/es/models/api/IEntityStorageCountRequest.js.map +1 -0
  16. package/dist/es/models/api/IEntityStorageCountResponse.js +4 -0
  17. package/dist/es/models/api/IEntityStorageCountResponse.js.map +1 -0
  18. package/dist/es/models/api/IEntityStorageEmptyRequest.js +4 -0
  19. package/dist/es/models/api/IEntityStorageEmptyRequest.js.map +1 -0
  20. package/dist/es/models/api/IEntityStorageGetRequest.js.map +1 -1
  21. package/dist/es/models/api/IEntityStorageRemoveBatchRequest.js +4 -0
  22. package/dist/es/models/api/IEntityStorageRemoveBatchRequest.js.map +1 -0
  23. package/dist/es/models/api/IEntityStorageRemoveRequest.js.map +1 -1
  24. package/dist/es/models/api/IEntityStorageSetBatchRequest.js +4 -0
  25. package/dist/es/models/api/IEntityStorageSetBatchRequest.js.map +1 -0
  26. package/dist/es/models/api/IEntityStorageSetRequest.js.map +1 -1
  27. package/dist/types/helpers/entityStorageHelper.d.ts +40 -0
  28. package/dist/types/helpers/migrationHelper.d.ts +61 -0
  29. package/dist/types/index.d.ts +9 -0
  30. package/dist/types/models/IEntityStorageComponent.d.ts +38 -3
  31. package/dist/types/models/IEntityStorageConnector.d.ts +23 -0
  32. package/dist/types/models/IEntityStorageMigrationConnector.d.ts +35 -0
  33. package/dist/types/models/IMigrationOptions.d.ts +32 -0
  34. package/dist/types/models/api/IEntityStorageCountRequest.d.ts +14 -0
  35. package/dist/types/models/api/IEntityStorageCountResponse.d.ts +14 -0
  36. package/dist/types/models/api/IEntityStorageEmptyRequest.d.ts +5 -0
  37. package/dist/types/models/api/IEntityStorageGetRequest.d.ts +4 -0
  38. package/dist/types/models/api/IEntityStorageRemoveBatchRequest.d.ts +9 -0
  39. package/dist/types/models/api/IEntityStorageRemoveRequest.d.ts +9 -0
  40. package/dist/types/models/api/IEntityStorageSetBatchRequest.d.ts +9 -0
  41. package/dist/types/models/api/IEntityStorageSetRequest.d.ts +9 -0
  42. package/docs/changelog.md +224 -43
  43. package/docs/examples.md +87 -1
  44. package/docs/reference/classes/EntityStorageHelper.md +135 -0
  45. package/docs/reference/classes/MigrationHelper.md +247 -0
  46. package/docs/reference/index.md +12 -0
  47. package/docs/reference/interfaces/IEntityStorageComponent.md +105 -7
  48. package/docs/reference/interfaces/IEntityStorageConnector.md +89 -5
  49. package/docs/reference/interfaces/IEntityStorageCountRequest.md +17 -0
  50. package/docs/reference/interfaces/IEntityStorageCountResponse.md +17 -0
  51. package/docs/reference/interfaces/IEntityStorageEmptyRequest.md +3 -0
  52. package/docs/reference/interfaces/IEntityStorageGetRequest.md +10 -4
  53. package/docs/reference/interfaces/IEntityStorageGetResponse.md +1 -1
  54. package/docs/reference/interfaces/IEntityStorageListRequest.md +8 -8
  55. package/docs/reference/interfaces/IEntityStorageListResponse.md +2 -2
  56. package/docs/reference/interfaces/IEntityStorageMigrationConnector.md +402 -0
  57. package/docs/reference/interfaces/IEntityStorageRemoveBatchRequest.md +11 -0
  58. package/docs/reference/interfaces/IEntityStorageRemoveRequest.md +15 -1
  59. package/docs/reference/interfaces/IEntityStorageSetBatchRequest.md +11 -0
  60. package/docs/reference/interfaces/IEntityStorageSetRequest.md +15 -1
  61. package/docs/reference/interfaces/IMigrationOptions.md +119 -0
  62. package/locales/en.json +7 -1
  63. package/package.json +5 -4
@@ -4,7 +4,7 @@ Response to getting the list of entries from a query.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### body
7
+ ### body {#body}
8
8
 
9
9
  > **body**: `object`
10
10
 
@@ -18,6 +18,6 @@ The entities from the query.
18
18
 
19
19
  #### cursor?
20
20
 
21
- > `optional` **cursor**: `string`
21
+ > `optional` **cursor?**: `string`
22
22
 
23
23
  The cursor for the next page.
@@ -0,0 +1,402 @@
1
+ # Interface: IEntityStorageMigrationConnector\<T\>
2
+
3
+ Interface describing an entity storage migration connector.
4
+
5
+ ## Extends
6
+
7
+ - [`IEntityStorageConnector`](IEntityStorageConnector.md)\<`T`\>
8
+
9
+ ## Type Parameters
10
+
11
+ ### T
12
+
13
+ `T` = `unknown`
14
+
15
+ ## Methods
16
+
17
+ ### getSchema() {#getschema}
18
+
19
+ > **getSchema**(): `IEntitySchema`
20
+
21
+ Get the schema for the entities.
22
+
23
+ #### Returns
24
+
25
+ `IEntitySchema`
26
+
27
+ The schema for the entities.
28
+
29
+ #### Inherited from
30
+
31
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`getSchema`](IEntityStorageConnector.md#getschema)
32
+
33
+ ***
34
+
35
+ ### set() {#set}
36
+
37
+ > **set**(`entity`, `conditions?`): `Promise`\<`void`\>
38
+
39
+ Set an entity.
40
+
41
+ #### Parameters
42
+
43
+ ##### entity
44
+
45
+ `T`
46
+
47
+ The entity to set.
48
+
49
+ ##### conditions?
50
+
51
+ `object`[]
52
+
53
+ The optional conditions to match for the entities.
54
+
55
+ #### Returns
56
+
57
+ `Promise`\<`void`\>
58
+
59
+ The id of the entity.
60
+
61
+ #### Inherited from
62
+
63
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`set`](IEntityStorageConnector.md#set)
64
+
65
+ ***
66
+
67
+ ### setBatch() {#setbatch}
68
+
69
+ > **setBatch**(`entities`): `Promise`\<`void`\>
70
+
71
+ Set multiple entities in a batch.
72
+
73
+ #### Parameters
74
+
75
+ ##### entities
76
+
77
+ `T`[]
78
+
79
+ The entities to set.
80
+
81
+ #### Returns
82
+
83
+ `Promise`\<`void`\>
84
+
85
+ Nothing.
86
+
87
+ #### Inherited from
88
+
89
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`setBatch`](IEntityStorageConnector.md#setbatch)
90
+
91
+ ***
92
+
93
+ ### get() {#get}
94
+
95
+ > **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
96
+
97
+ Get an entity.
98
+
99
+ #### Parameters
100
+
101
+ ##### id
102
+
103
+ `string`
104
+
105
+ The id of the entity to get, or the index value if secondaryIndex is set.
106
+
107
+ ##### secondaryIndex?
108
+
109
+ keyof `T`
110
+
111
+ Get the item using a secondary index.
112
+
113
+ ##### conditions?
114
+
115
+ `object`[]
116
+
117
+ The optional conditions to match for the entities.
118
+
119
+ #### Returns
120
+
121
+ `Promise`\<`T` \| `undefined`\>
122
+
123
+ The object if it can be found or undefined.
124
+
125
+ #### Inherited from
126
+
127
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`get`](IEntityStorageConnector.md#get)
128
+
129
+ ***
130
+
131
+ ### remove() {#remove}
132
+
133
+ > **remove**(`id`, `conditions?`): `Promise`\<`void`\>
134
+
135
+ Remove the entity.
136
+
137
+ #### Parameters
138
+
139
+ ##### id
140
+
141
+ `string`
142
+
143
+ The id of the entity to remove.
144
+
145
+ ##### conditions?
146
+
147
+ `object`[]
148
+
149
+ The optional conditions to match for the entities.
150
+
151
+ #### Returns
152
+
153
+ `Promise`\<`void`\>
154
+
155
+ Nothing.
156
+
157
+ #### Inherited from
158
+
159
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`remove`](IEntityStorageConnector.md#remove)
160
+
161
+ ***
162
+
163
+ ### removeBatch() {#removebatch}
164
+
165
+ > **removeBatch**(`ids`): `Promise`\<`void`\>
166
+
167
+ Remove multiple entities by id.
168
+
169
+ #### Parameters
170
+
171
+ ##### ids
172
+
173
+ `string`[]
174
+
175
+ The ids of the entities to remove.
176
+
177
+ #### Returns
178
+
179
+ `Promise`\<`void`\>
180
+
181
+ Nothing.
182
+
183
+ #### Inherited from
184
+
185
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`removeBatch`](IEntityStorageConnector.md#removebatch)
186
+
187
+ ***
188
+
189
+ ### query() {#query}
190
+
191
+ > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
192
+
193
+ Query all the entities which match the conditions.
194
+
195
+ #### Parameters
196
+
197
+ ##### conditions?
198
+
199
+ `EntityCondition`\<`T`\>
200
+
201
+ The conditions to match for the entities.
202
+
203
+ ##### sortProperties?
204
+
205
+ `object`[]
206
+
207
+ The optional sort order.
208
+
209
+ ##### properties?
210
+
211
+ keyof `T`[]
212
+
213
+ The optional properties to return, defaults to all.
214
+
215
+ ##### cursor?
216
+
217
+ `string`
218
+
219
+ The cursor to request the next chunk of entities.
220
+
221
+ ##### limit?
222
+
223
+ `number`
224
+
225
+ The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
226
+
227
+ #### Returns
228
+
229
+ `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
230
+
231
+ All the entities for the storage matching the conditions,
232
+ and a cursor which can be used to request more entities.
233
+
234
+ #### Inherited from
235
+
236
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`query`](IEntityStorageConnector.md#query)
237
+
238
+ ***
239
+
240
+ ### empty() {#empty}
241
+
242
+ > **empty**(): `Promise`\<`void`\>
243
+
244
+ Remove all entities from the storage.
245
+
246
+ #### Returns
247
+
248
+ `Promise`\<`void`\>
249
+
250
+ Nothing.
251
+
252
+ #### Inherited from
253
+
254
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`empty`](IEntityStorageConnector.md#empty)
255
+
256
+ ***
257
+
258
+ ### count() {#count}
259
+
260
+ > **count**(`conditions?`): `Promise`\<`number`\>
261
+
262
+ Count all the entities which match the conditions.
263
+
264
+ #### Parameters
265
+
266
+ ##### conditions?
267
+
268
+ `EntityCondition`\<`T`\>
269
+
270
+ The optional conditions to match for the entities.
271
+
272
+ #### Returns
273
+
274
+ `Promise`\<`number`\>
275
+
276
+ The total count of entities in the storage.
277
+
278
+ #### Inherited from
279
+
280
+ [`IEntityStorageConnector`](IEntityStorageConnector.md).[`count`](IEntityStorageConnector.md#count)
281
+
282
+ ***
283
+
284
+ ### getPartitionContextIds() {#getpartitioncontextids}
285
+
286
+ > **getPartitionContextIds**(): `Promise`\<`IContextIds`[]\>
287
+
288
+ Get a unique list of all the context ids from the storage.
289
+
290
+ #### Returns
291
+
292
+ `Promise`\<`IContextIds`[]\>
293
+
294
+ The list of unique context ids.
295
+
296
+ ***
297
+
298
+ ### createTargetConnector() {#createtargetconnector}
299
+
300
+ > **createTargetConnector**\<`U`\>(`newEntitySchema`): `Promise`\<[`IEntityStorageConnector`](IEntityStorageConnector.md)\<`U`\>\>
301
+
302
+ Create the target connector for performing the migration it will use a temporary storage location.
303
+
304
+ #### Type Parameters
305
+
306
+ ##### U
307
+
308
+ `U`
309
+
310
+ #### Parameters
311
+
312
+ ##### newEntitySchema
313
+
314
+ `string`
315
+
316
+ The name of the new entity schema to create the connector for.
317
+
318
+ #### Returns
319
+
320
+ `Promise`\<[`IEntityStorageConnector`](IEntityStorageConnector.md)\<`U`\>\>
321
+
322
+ Connector for performing the migration.
323
+
324
+ ***
325
+
326
+ ### finalizeMigration() {#finalizemigration}
327
+
328
+ > **finalizeMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<[`IEntityStorageConnector`](IEntityStorageConnector.md)\<`U`\>\>
329
+
330
+ Finalize the migration by tearing down the old connector and replacing it with the target connector.
331
+
332
+ #### Type Parameters
333
+
334
+ ##### U
335
+
336
+ `U`
337
+
338
+ #### Parameters
339
+
340
+ ##### targetConnector
341
+
342
+ [`IEntityStorageConnector`](IEntityStorageConnector.md)\<`U`\>
343
+
344
+ The target connector to finalize the migration with.
345
+
346
+ ##### options?
347
+
348
+ [`IMigrationOptions`](IMigrationOptions.md)\<`T`, `U`\>
349
+
350
+ The options to control how the migration is finalized.
351
+
352
+ ##### loggingComponentType?
353
+
354
+ `string`
355
+
356
+ The optional component type to use for logging the migration progress.
357
+
358
+ #### Returns
359
+
360
+ `Promise`\<[`IEntityStorageConnector`](IEntityStorageConnector.md)\<`U`\>\>
361
+
362
+ A promise that resolves when the migration is finalized and returns the final connector.
363
+
364
+ ***
365
+
366
+ ### cleanupMigration() {#cleanupmigration}
367
+
368
+ > **cleanupMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`void`\>
369
+
370
+ Cleanup the migration if a migration fails or needs to be aborted.
371
+
372
+ #### Type Parameters
373
+
374
+ ##### U
375
+
376
+ `U`
377
+
378
+ #### Parameters
379
+
380
+ ##### targetConnector
381
+
382
+ [`IEntityStorageConnector`](IEntityStorageConnector.md)\<`U`\> \| `undefined`
383
+
384
+ The target connector to cleanup the migration with.
385
+
386
+ ##### options?
387
+
388
+ [`IMigrationOptions`](IMigrationOptions.md)\<`T`, `U`\>
389
+
390
+ The options to control how the migration is cleaned up.
391
+
392
+ ##### loggingComponentType?
393
+
394
+ `string`
395
+
396
+ The optional component type to use for logging the migration progress.
397
+
398
+ #### Returns
399
+
400
+ `Promise`\<`void`\>
401
+
402
+ A promise that resolves when the migration is cleaned up.
@@ -0,0 +1,11 @@
1
+ # Interface: IEntityStorageRemoveBatchRequest
2
+
3
+ Remove multiple entries from entity storage by id.
4
+
5
+ ## Properties
6
+
7
+ ### body {#body}
8
+
9
+ > **body**: `string`[]
10
+
11
+ The ids of the entities to remove.
@@ -4,7 +4,7 @@ Remove an entry from entity storage.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### pathParams
7
+ ### pathParams {#pathparams}
8
8
 
9
9
  > **pathParams**: `object`
10
10
 
@@ -15,3 +15,17 @@ The parameters from the path.
15
15
  > **id**: `string`
16
16
 
17
17
  The id of the entity to remove.
18
+
19
+ ***
20
+
21
+ ### query? {#query}
22
+
23
+ > `optional` **query?**: `object`
24
+
25
+ The query parameters.
26
+
27
+ #### conditions?
28
+
29
+ > `optional` **conditions?**: `string`
30
+
31
+ The optional conditions to match for the entity, JSON encoded array of property/value pairs.
@@ -0,0 +1,11 @@
1
+ # Interface: IEntityStorageSetBatchRequest
2
+
3
+ Set multiple entries in entity storage.
4
+
5
+ ## Properties
6
+
7
+ ### body {#body}
8
+
9
+ > **body**: `unknown`[]
10
+
11
+ The entities to set.
@@ -4,8 +4,22 @@ Set an entry in entity storage.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### body
7
+ ### body {#body}
8
8
 
9
9
  > **body**: `unknown`
10
10
 
11
11
  The data to be used in the entity.
12
+
13
+ ***
14
+
15
+ ### query? {#query}
16
+
17
+ > `optional` **query?**: `object`
18
+
19
+ The query parameters.
20
+
21
+ #### conditions?
22
+
23
+ > `optional` **conditions?**: `string`
24
+
25
+ The optional conditions to match for the entity, JSON encoded array of property/value pairs.
@@ -0,0 +1,119 @@
1
+ # Interface: IMigrationOptions\<T, U\>
2
+
3
+ Options controlling how a schema migration is executed.
4
+
5
+ ## Type Parameters
6
+
7
+ ### T
8
+
9
+ `T`
10
+
11
+ ### U
12
+
13
+ `U`
14
+
15
+ ## Properties
16
+
17
+ ### batchSize? {#batchsize}
18
+
19
+ > `optional` **batchSize?**: `number`
20
+
21
+ Number of entities to read and write per batch.
22
+
23
+ #### Default
24
+
25
+ ```ts
26
+ 100
27
+ ```
28
+
29
+ ***
30
+
31
+ ### transformEntityProperty? {#transformentityproperty}
32
+
33
+ > `optional` **transformEntityProperty?**: (`schema1Property`, `schemaProperty2`, `value`) => `unknown`
34
+
35
+ Optional transformation for properties, usually only called for object and array types.
36
+
37
+ #### Parameters
38
+
39
+ ##### schema1Property
40
+
41
+ `IEntitySchemaProperty`\<`T`\>
42
+
43
+ The property schema in the old schema.
44
+
45
+ ##### schemaProperty2
46
+
47
+ `IEntitySchemaProperty`\<`U`\>
48
+
49
+ The property schema in the new schema.
50
+
51
+ ##### value
52
+
53
+ `unknown`
54
+
55
+ The value of the property in the old schema.
56
+
57
+ #### Returns
58
+
59
+ `unknown`
60
+
61
+ The transformed value to match the new schema.
62
+
63
+ ***
64
+
65
+ ### onPartitionProgress? {#onpartitionprogress}
66
+
67
+ > `optional` **onPartitionProgress?**: (`rowTotal`, `rowIndex`) => `Promise`\<`void`\>
68
+
69
+ Called for each partition for progress tracking.
70
+
71
+ #### Parameters
72
+
73
+ ##### rowTotal
74
+
75
+ `number`
76
+
77
+ The total number of rows to migrate.
78
+
79
+ ##### rowIndex
80
+
81
+ `number`
82
+
83
+ The number of rows migrated so far.
84
+
85
+ #### Returns
86
+
87
+ `Promise`\<`void`\>
88
+
89
+ ***
90
+
91
+ ### onStepProgress? {#onstepprogress}
92
+
93
+ > `optional` **onStepProgress?**: (`stepKey`, `itemTotal`, `itemIndex`) => `Promise`\<`void`\>
94
+
95
+ Called for overall progress tracking.
96
+
97
+ #### Parameters
98
+
99
+ ##### stepKey
100
+
101
+ `string`
102
+
103
+ The key representing the current step in the migration.
104
+
105
+ ##### itemTotal
106
+
107
+ `number`
108
+
109
+ The total number of items in this progress.
110
+
111
+ ##### itemIndex
112
+
113
+ `number`
114
+
115
+ The number of items processed so far.
116
+
117
+ #### Returns
118
+
119
+ `Promise`\<`void`\>
package/locales/en.json CHANGED
@@ -1,3 +1,9 @@
1
1
  {
2
- "error": {}
2
+ "error": {
3
+ "migrationHelper": {
4
+ "migrationFailed": "Migration failed.",
5
+ "transformRequiredForProperty": "A transformation function is required to migrate property \"{from}\" to \"{to}\" of type \"{type}\"",
6
+ "coercionProducedUndefined": "Coercion of property \"{property}\" to type \"{type}\" produced undefined but the property is not optional"
7
+ }
8
+ }
3
9
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-models",
3
- "version": "0.0.3-next.2",
4
- "description": "Models which define the structure of the entity storage contracts and connectors",
3
+ "version": "0.0.3-next.21",
4
+ "description": "Shared models for storage contracts, requests, responses and connector capabilities.",
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-models"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -14,6 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
+ "@twin.org/context": "next",
17
18
  "@twin.org/core": "next",
18
19
  "@twin.org/entity": "next",
19
20
  "@twin.org/nameof": "next"
@@ -50,7 +51,7 @@
50
51
  "schemas"
51
52
  ],
52
53
  "bugs": {
53
- "url": "git+https://github.com/twinfoundation/entity-storage/issues"
54
+ "url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
54
55
  },
55
56
  "homepage": "https://twindev.org"
56
57
  }