@twin.org/entity-storage-service 0.0.3-next.8 → 0.9.0-next.1

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 (42) hide show
  1. package/dist/es/entities/schemaVersion.js +39 -0
  2. package/dist/es/entities/schemaVersion.js.map +1 -0
  3. package/dist/es/entityStorageRoutes.js +176 -4
  4. package/dist/es/entityStorageRoutes.js.map +1 -1
  5. package/dist/es/entityStorageService.js +44 -49
  6. package/dist/es/entityStorageService.js.map +1 -1
  7. package/dist/es/index.js +6 -1
  8. package/dist/es/index.js.map +1 -1
  9. package/dist/es/models/IEntityStorageRoutesExamples.js.map +1 -1
  10. package/dist/es/models/ISchemaVersionServiceConfig.js +4 -0
  11. package/dist/es/models/ISchemaVersionServiceConfig.js.map +1 -0
  12. package/dist/es/models/ISchemaVersionServiceConstructorOptions.js +2 -0
  13. package/dist/es/models/ISchemaVersionServiceConstructorOptions.js.map +1 -0
  14. package/dist/es/schema.js +11 -0
  15. package/dist/es/schema.js.map +1 -0
  16. package/dist/es/schemaVersionService.js +356 -0
  17. package/dist/es/schemaVersionService.js.map +1 -0
  18. package/dist/types/entities/schemaVersion.d.ts +19 -0
  19. package/dist/types/entityStorageRoutes.d.ts +33 -1
  20. package/dist/types/entityStorageService.d.ts +38 -3
  21. package/dist/types/index.d.ts +6 -1
  22. package/dist/types/models/IEntityStorageRoutesExamples.d.ts +8 -1
  23. package/dist/types/models/ISchemaVersionServiceConfig.d.ts +9 -0
  24. package/dist/types/models/ISchemaVersionServiceConstructorOptions.d.ts +15 -0
  25. package/dist/types/schema.d.ts +4 -0
  26. package/dist/types/schemaVersionService.d.ts +52 -0
  27. package/docs/changelog.md +561 -51
  28. package/docs/open-api/spec.json +439 -1
  29. package/docs/reference/classes/EntityStorageService.md +117 -3
  30. package/docs/reference/classes/SchemaVersion.md +39 -0
  31. package/docs/reference/classes/SchemaVersionService.md +103 -0
  32. package/docs/reference/functions/entityStorageCount.md +31 -0
  33. package/docs/reference/functions/entityStorageEmpty.md +31 -0
  34. package/docs/reference/functions/entityStorageRemoveBatch.md +31 -0
  35. package/docs/reference/functions/entityStorageSetBatch.md +31 -0
  36. package/docs/reference/functions/initSchema.md +9 -0
  37. package/docs/reference/index.md +9 -0
  38. package/docs/reference/interfaces/IEntityStorageRoutesExamples.md +16 -0
  39. package/docs/reference/interfaces/ISchemaVersionServiceConfig.md +11 -0
  40. package/docs/reference/interfaces/ISchemaVersionServiceConstructorOptions.md +25 -0
  41. package/locales/en.json +17 -2
  42. package/package.json +10 -9
@@ -28,6 +28,17 @@
28
28
  "tags": [
29
29
  "EntityStorage"
30
30
  ],
31
+ "parameters": [
32
+ {
33
+ "name": "conditions",
34
+ "description": "The optional conditions to match for the entity, JSON encoded array of property/value pairs.",
35
+ "in": "query",
36
+ "required": false,
37
+ "schema": {
38
+ "type": "string"
39
+ }
40
+ }
41
+ ],
31
42
  "security": [
32
43
  {
33
44
  "jwtBearerAuthScheme": []
@@ -115,6 +126,91 @@
115
126
  }
116
127
  }
117
128
  },
129
+ "delete": {
130
+ "operationId": "entityStorageEmpty",
131
+ "summary": "Remove all entries from entity storage.",
132
+ "tags": [
133
+ "EntityStorage"
134
+ ],
135
+ "security": [
136
+ {
137
+ "jwtBearerAuthScheme": []
138
+ }
139
+ ],
140
+ "requestBody": {
141
+ "description": "Remove all entries from entity storage.",
142
+ "required": true,
143
+ "content": {
144
+ "text/plain": {
145
+ "schema": {
146
+ "$ref": "#/components/schemas/EntityStorageEmptyRequest"
147
+ }
148
+ }
149
+ }
150
+ },
151
+ "responses": {
152
+ "204": {
153
+ "description": "The rest request ended in success with no data."
154
+ },
155
+ "400": {
156
+ "description": "The server cannot process the request, see the content for more details.",
157
+ "content": {
158
+ "application/json": {
159
+ "schema": {
160
+ "$ref": "#/components/schemas/Error"
161
+ },
162
+ "examples": {
163
+ "exampleResponse": {
164
+ "value": {
165
+ "name": "GeneralError",
166
+ "message": "errorMessage",
167
+ "properties": {
168
+ "foo": "bar"
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ },
176
+ "401": {
177
+ "description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
178
+ "content": {
179
+ "application/json": {
180
+ "schema": {
181
+ "$ref": "#/components/schemas/Error"
182
+ },
183
+ "examples": {
184
+ "exampleResponse": {
185
+ "value": {
186
+ "name": "UnauthorizedError",
187
+ "message": "errorMessage"
188
+ }
189
+ }
190
+ }
191
+ }
192
+ }
193
+ },
194
+ "500": {
195
+ "description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
196
+ "content": {
197
+ "application/json": {
198
+ "schema": {
199
+ "$ref": "#/components/schemas/Error"
200
+ },
201
+ "examples": {
202
+ "exampleResponse": {
203
+ "value": {
204
+ "name": "InternalServerError",
205
+ "message": "errorMessage"
206
+ }
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ },
118
214
  "get": {
119
215
  "operationId": "entityStorageList",
120
216
  "summary": "Query entries from entity storage.",
@@ -265,6 +361,200 @@
265
361
  }
266
362
  }
267
363
  },
364
+ "/entity-storage/batch": {
365
+ "post": {
366
+ "operationId": "entityStorageSetBatch",
367
+ "summary": "Set multiple entries in entity storage.",
368
+ "tags": [
369
+ "EntityStorage"
370
+ ],
371
+ "security": [
372
+ {
373
+ "jwtBearerAuthScheme": []
374
+ }
375
+ ],
376
+ "requestBody": {
377
+ "description": "Set multiple entries in entity storage.",
378
+ "required": true,
379
+ "content": {
380
+ "application/json": {
381
+ "schema": {
382
+ "$ref": "#/components/schemas/EntityStorageSetBatchRequest"
383
+ },
384
+ "examples": {
385
+ "entityStorageSetBatchRequestExample": {
386
+ "value": [
387
+ {
388
+ "id": "12345",
389
+ "name": "My Item"
390
+ },
391
+ {
392
+ "id": "67890",
393
+ "name": "My Other Item"
394
+ }
395
+ ]
396
+ }
397
+ }
398
+ }
399
+ }
400
+ },
401
+ "responses": {
402
+ "204": {
403
+ "description": "The rest request ended in success with no data."
404
+ },
405
+ "400": {
406
+ "description": "The server cannot process the request, see the content for more details.",
407
+ "content": {
408
+ "application/json": {
409
+ "schema": {
410
+ "$ref": "#/components/schemas/Error"
411
+ },
412
+ "examples": {
413
+ "exampleResponse": {
414
+ "value": {
415
+ "name": "GeneralError",
416
+ "message": "errorMessage",
417
+ "properties": {
418
+ "foo": "bar"
419
+ }
420
+ }
421
+ }
422
+ }
423
+ }
424
+ }
425
+ },
426
+ "401": {
427
+ "description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
428
+ "content": {
429
+ "application/json": {
430
+ "schema": {
431
+ "$ref": "#/components/schemas/Error"
432
+ },
433
+ "examples": {
434
+ "exampleResponse": {
435
+ "value": {
436
+ "name": "UnauthorizedError",
437
+ "message": "errorMessage"
438
+ }
439
+ }
440
+ }
441
+ }
442
+ }
443
+ },
444
+ "500": {
445
+ "description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
446
+ "content": {
447
+ "application/json": {
448
+ "schema": {
449
+ "$ref": "#/components/schemas/Error"
450
+ },
451
+ "examples": {
452
+ "exampleResponse": {
453
+ "value": {
454
+ "name": "InternalServerError",
455
+ "message": "errorMessage"
456
+ }
457
+ }
458
+ }
459
+ }
460
+ }
461
+ }
462
+ }
463
+ },
464
+ "delete": {
465
+ "operationId": "entityStorageRemoveBatch",
466
+ "summary": "Remove multiple entries from entity storage by id.",
467
+ "tags": [
468
+ "EntityStorage"
469
+ ],
470
+ "security": [
471
+ {
472
+ "jwtBearerAuthScheme": []
473
+ }
474
+ ],
475
+ "requestBody": {
476
+ "description": "Remove multiple entries from entity storage by id.",
477
+ "required": true,
478
+ "content": {
479
+ "application/json": {
480
+ "schema": {
481
+ "$ref": "#/components/schemas/EntityStorageRemoveBatchRequest"
482
+ },
483
+ "examples": {
484
+ "entityStorageRemoveBatchRequestExample": {
485
+ "value": [
486
+ "12345",
487
+ "67890"
488
+ ]
489
+ }
490
+ }
491
+ }
492
+ }
493
+ },
494
+ "responses": {
495
+ "204": {
496
+ "description": "The rest request ended in success with no data."
497
+ },
498
+ "400": {
499
+ "description": "The server cannot process the request, see the content for more details.",
500
+ "content": {
501
+ "application/json": {
502
+ "schema": {
503
+ "$ref": "#/components/schemas/Error"
504
+ },
505
+ "examples": {
506
+ "exampleResponse": {
507
+ "value": {
508
+ "name": "GeneralError",
509
+ "message": "errorMessage",
510
+ "properties": {
511
+ "foo": "bar"
512
+ }
513
+ }
514
+ }
515
+ }
516
+ }
517
+ }
518
+ },
519
+ "401": {
520
+ "description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
521
+ "content": {
522
+ "application/json": {
523
+ "schema": {
524
+ "$ref": "#/components/schemas/Error"
525
+ },
526
+ "examples": {
527
+ "exampleResponse": {
528
+ "value": {
529
+ "name": "UnauthorizedError",
530
+ "message": "errorMessage"
531
+ }
532
+ }
533
+ }
534
+ }
535
+ }
536
+ },
537
+ "500": {
538
+ "description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
539
+ "content": {
540
+ "application/json": {
541
+ "schema": {
542
+ "$ref": "#/components/schemas/Error"
543
+ },
544
+ "examples": {
545
+ "exampleResponse": {
546
+ "value": {
547
+ "name": "InternalServerError",
548
+ "message": "errorMessage"
549
+ }
550
+ }
551
+ }
552
+ }
553
+ }
554
+ }
555
+ }
556
+ }
557
+ },
268
558
  "/entity-storage/{id}": {
269
559
  "get": {
270
560
  "operationId": "entityStorageGet",
@@ -292,6 +582,15 @@
292
582
  "schema": {
293
583
  "type": "string"
294
584
  }
585
+ },
586
+ {
587
+ "name": "conditions",
588
+ "description": "The optional conditions to match for the entity, JSON encoded array of property/value pairs.",
589
+ "in": "query",
590
+ "required": false,
591
+ "schema": {
592
+ "type": "string"
593
+ }
295
594
  }
296
595
  ],
297
596
  "security": [
@@ -415,6 +714,15 @@
415
714
  },
416
715
  "style": "simple",
417
716
  "example": "12345"
717
+ },
718
+ {
719
+ "name": "conditions",
720
+ "description": "The optional conditions to match for the entity, JSON encoded array of property/value pairs.",
721
+ "in": "query",
722
+ "required": false,
723
+ "schema": {
724
+ "type": "string"
725
+ }
418
726
  }
419
727
  ],
420
728
  "security": [
@@ -506,10 +814,128 @@
506
814
  }
507
815
  }
508
816
  }
817
+ },
818
+ "/entity-storage/count": {
819
+ "get": {
820
+ "operationId": "entityStorageCount",
821
+ "summary": "Count entries in entity storage.",
822
+ "tags": [
823
+ "EntityStorage"
824
+ ],
825
+ "parameters": [
826
+ {
827
+ "name": "conditions",
828
+ "description": "The optional conditions to filter the count, JSON encoded EntityCondition.",
829
+ "in": "query",
830
+ "required": false,
831
+ "schema": {
832
+ "type": "string"
833
+ }
834
+ }
835
+ ],
836
+ "security": [
837
+ {
838
+ "jwtBearerAuthScheme": []
839
+ }
840
+ ],
841
+ "responses": {
842
+ "200": {
843
+ "description": "The response for counting entries in entity storage.",
844
+ "content": {
845
+ "application/json": {
846
+ "schema": {
847
+ "$ref": "#/components/schemas/EntityStorageCountResponse"
848
+ },
849
+ "examples": {
850
+ "entityStorageCountResponseExample": {
851
+ "value": {
852
+ "count": 1
853
+ }
854
+ }
855
+ }
856
+ }
857
+ }
858
+ },
859
+ "400": {
860
+ "description": "The server cannot process the request, see the content for more details.",
861
+ "content": {
862
+ "application/json": {
863
+ "schema": {
864
+ "$ref": "#/components/schemas/Error"
865
+ },
866
+ "examples": {
867
+ "exampleResponse": {
868
+ "value": {
869
+ "name": "GeneralError",
870
+ "message": "errorMessage",
871
+ "properties": {
872
+ "foo": "bar"
873
+ }
874
+ }
875
+ }
876
+ }
877
+ }
878
+ }
879
+ },
880
+ "401": {
881
+ "description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
882
+ "content": {
883
+ "application/json": {
884
+ "schema": {
885
+ "$ref": "#/components/schemas/Error"
886
+ },
887
+ "examples": {
888
+ "exampleResponse": {
889
+ "value": {
890
+ "name": "UnauthorizedError",
891
+ "message": "errorMessage"
892
+ }
893
+ }
894
+ }
895
+ }
896
+ }
897
+ },
898
+ "500": {
899
+ "description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
900
+ "content": {
901
+ "application/json": {
902
+ "schema": {
903
+ "$ref": "#/components/schemas/Error"
904
+ },
905
+ "examples": {
906
+ "exampleResponse": {
907
+ "value": {
908
+ "name": "InternalServerError",
909
+ "message": "errorMessage"
910
+ }
911
+ }
912
+ }
913
+ }
914
+ }
915
+ }
916
+ }
917
+ }
509
918
  }
510
919
  },
511
920
  "components": {
512
921
  "schemas": {
922
+ "EntityStorageCountResponse": {
923
+ "type": "object",
924
+ "properties": {
925
+ "count": {
926
+ "type": "number",
927
+ "description": "The total count of entities."
928
+ }
929
+ },
930
+ "required": [
931
+ "count"
932
+ ],
933
+ "description": "The body of the response."
934
+ },
935
+ "EntityStorageEmptyRequest": {
936
+ "description": "Remove all entries from entity storage.",
937
+ "type": "object"
938
+ },
513
939
  "EntityStorageGetResponse": {
514
940
  "description": "The data for the requested entity."
515
941
  },
@@ -531,6 +957,18 @@
531
957
  ],
532
958
  "description": "The list of entries from the query."
533
959
  },
960
+ "EntityStorageRemoveBatchRequest": {
961
+ "type": "array",
962
+ "items": {
963
+ "type": "string"
964
+ },
965
+ "description": "The ids of the entities to remove."
966
+ },
967
+ "EntityStorageSetBatchRequest": {
968
+ "type": "array",
969
+ "items": {},
970
+ "description": "The entities to set."
971
+ },
534
972
  "EntityStorageSetRequest": {
535
973
  "description": "The data to be used in the entity."
536
974
  },
@@ -544,7 +982,7 @@
544
982
  },
545
983
  "message": {
546
984
  "type": "string",
547
- "description": "The message for the error."
985
+ "description": "The message for the error as an i18n key."
548
986
  },
549
987
  "source": {
550
988
  "type": "string",
@@ -62,7 +62,7 @@ The class name of the component.
62
62
 
63
63
  ### set() {#set}
64
64
 
65
- > **set**(`entity`): `Promise`\<`void`\>
65
+ > **set**(`entity`, `conditions?`): `Promise`\<`void`\>
66
66
 
67
67
  Set an entity.
68
68
 
@@ -74,6 +74,12 @@ Set an entity.
74
74
 
75
75
  The entity to set.
76
76
 
77
+ ##### conditions?
78
+
79
+ `object`[]
80
+
81
+ The optional conditions to match for the entities.
82
+
77
83
  #### Returns
78
84
 
79
85
  `Promise`\<`void`\>
@@ -86,9 +92,35 @@ The id of the entity.
86
92
 
87
93
  ***
88
94
 
95
+ ### setBatch() {#setbatch}
96
+
97
+ > **setBatch**(`entities`): `Promise`\<`void`\>
98
+
99
+ Set multiple entities in a batch.
100
+
101
+ #### Parameters
102
+
103
+ ##### entities
104
+
105
+ `T`[]
106
+
107
+ The entities to set.
108
+
109
+ #### Returns
110
+
111
+ `Promise`\<`void`\>
112
+
113
+ Nothing.
114
+
115
+ #### Implementation of
116
+
117
+ `IEntityStorageComponent.setBatch`
118
+
119
+ ***
120
+
89
121
  ### get() {#get}
90
122
 
91
- > **get**(`id`, `secondaryIndex?`): `Promise`\<`T` \| `undefined`\>
123
+ > **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
92
124
 
93
125
  Get an entity.
94
126
 
@@ -106,6 +138,12 @@ keyof `T`
106
138
 
107
139
  Get the item using a secondary index.
108
140
 
141
+ ##### conditions?
142
+
143
+ `object`[]
144
+
145
+ The optional conditions to match for the entities.
146
+
109
147
  #### Returns
110
148
 
111
149
  `Promise`\<`T` \| `undefined`\>
@@ -120,7 +158,7 @@ The object if it can be found or undefined.
120
158
 
121
159
  ### remove() {#remove}
122
160
 
123
- > **remove**(`id`): `Promise`\<`void`\>
161
+ > **remove**(`id`, `conditions?`): `Promise`\<`void`\>
124
162
 
125
163
  Remove the entity.
126
164
 
@@ -132,6 +170,12 @@ Remove the entity.
132
170
 
133
171
  The id of the entity to remove.
134
172
 
173
+ ##### conditions?
174
+
175
+ `object`[]
176
+
177
+ The optional conditions to match for the entities.
178
+
135
179
  #### Returns
136
180
 
137
181
  `Promise`\<`void`\>
@@ -144,6 +188,76 @@ Nothing.
144
188
 
145
189
  ***
146
190
 
191
+ ### removeBatch() {#removebatch}
192
+
193
+ > **removeBatch**(`ids`): `Promise`\<`void`\>
194
+
195
+ Remove multiple entities by id.
196
+
197
+ #### Parameters
198
+
199
+ ##### ids
200
+
201
+ `string`[]
202
+
203
+ The ids of the entities to remove.
204
+
205
+ #### Returns
206
+
207
+ `Promise`\<`void`\>
208
+
209
+ Nothing.
210
+
211
+ #### Implementation of
212
+
213
+ `IEntityStorageComponent.removeBatch`
214
+
215
+ ***
216
+
217
+ ### empty() {#empty}
218
+
219
+ > **empty**(): `Promise`\<`void`\>
220
+
221
+ Remove all entities from the storage.
222
+
223
+ #### Returns
224
+
225
+ `Promise`\<`void`\>
226
+
227
+ Nothing.
228
+
229
+ #### Implementation of
230
+
231
+ `IEntityStorageComponent.empty`
232
+
233
+ ***
234
+
235
+ ### count() {#count}
236
+
237
+ > **count**(`conditions?`): `Promise`\<`number`\>
238
+
239
+ Count all the entities which match the conditions.
240
+
241
+ #### Parameters
242
+
243
+ ##### conditions?
244
+
245
+ `EntityCondition`\<`T`\>
246
+
247
+ The optional conditions to match for the entities.
248
+
249
+ #### Returns
250
+
251
+ `Promise`\<`number`\>
252
+
253
+ The total count of entities in the storage.
254
+
255
+ #### Implementation of
256
+
257
+ `IEntityStorageComponent.count`
258
+
259
+ ***
260
+
147
261
  ### query() {#query}
148
262
 
149
263
  > **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
@@ -0,0 +1,39 @@
1
+ # Class: SchemaVersion
2
+
3
+ Tracks the currently applied schema version for each managed entity schema.
4
+ One record per schema name. Written once on first boot, then updated after
5
+ each successful migration.
6
+
7
+ ## Constructors
8
+
9
+ ### Constructor
10
+
11
+ > **new SchemaVersion**(): `SchemaVersion`
12
+
13
+ #### Returns
14
+
15
+ `SchemaVersion`
16
+
17
+ ## Properties
18
+
19
+ ### schemaName {#schemaname}
20
+
21
+ > **schemaName**: `string`
22
+
23
+ The entity schema type name — primary key.
24
+
25
+ ***
26
+
27
+ ### version {#version}
28
+
29
+ > **version**: `number`
30
+
31
+ The currently deployed version of this schema.
32
+
33
+ ***
34
+
35
+ ### updatedAt {#updatedat}
36
+
37
+ > **updatedAt**: `string`
38
+
39
+ ISO 8601 timestamp of the last version write.