@twin.org/entity-storage-service 0.0.2-next.9 → 0.0.3-next.10

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 (39) hide show
  1. package/README.md +2 -2
  2. package/dist/es/entityStorageRoutes.js +399 -0
  3. package/dist/es/entityStorageRoutes.js.map +1 -0
  4. package/dist/es/entityStorageService.js +113 -0
  5. package/dist/es/entityStorageService.js.map +1 -0
  6. package/dist/es/index.js +9 -0
  7. package/dist/es/index.js.map +1 -0
  8. package/dist/es/models/IEntityStorageRoutesExamples.js +2 -0
  9. package/dist/es/models/IEntityStorageRoutesExamples.js.map +1 -0
  10. package/dist/es/models/IEntityStorageServiceConfig.js +4 -0
  11. package/dist/es/models/IEntityStorageServiceConfig.js.map +1 -0
  12. package/dist/es/models/IEntityStorageServiceConstructorOptions.js +2 -0
  13. package/dist/es/models/IEntityStorageServiceConstructorOptions.js.map +1 -0
  14. package/dist/es/restEntryPoints.js +15 -0
  15. package/dist/es/restEntryPoints.js.map +1 -0
  16. package/dist/types/entityStorageRoutes.d.ts +34 -2
  17. package/dist/types/entityStorageService.d.ts +35 -12
  18. package/dist/types/index.d.ts +6 -6
  19. package/dist/types/models/IEntityStorageRoutesExamples.d.ts +8 -1
  20. package/dist/types/models/IEntityStorageServiceConfig.d.ts +5 -0
  21. package/dist/types/models/IEntityStorageServiceConstructorOptions.d.ts +2 -2
  22. package/docs/changelog.md +220 -31
  23. package/docs/examples.md +77 -1
  24. package/docs/open-api/spec.json +441 -62
  25. package/docs/reference/classes/EntityStorageService.md +114 -36
  26. package/docs/reference/functions/entityStorageCount.md +31 -0
  27. package/docs/reference/functions/entityStorageEmpty.md +31 -0
  28. package/docs/reference/functions/entityStorageRemoveBatch.md +31 -0
  29. package/docs/reference/functions/entityStorageSetBatch.md +31 -0
  30. package/docs/reference/index.md +5 -1
  31. package/docs/reference/interfaces/IEntityStorageRoutesExamples.md +24 -8
  32. package/docs/reference/interfaces/IEntityStorageServiceConfig.md +3 -0
  33. package/docs/reference/interfaces/IEntityStorageServiceConstructorOptions.md +3 -3
  34. package/locales/en.json +1 -7
  35. package/package.json +13 -11
  36. package/dist/cjs/index.cjs +0 -421
  37. package/dist/esm/index.mjs +0 -412
  38. package/dist/types/models/IEntityStorageConfig.d.ts +0 -10
  39. package/docs/reference/interfaces/IEntityStorageConfig.md +0 -17
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # TWIN Entity Storage Service
1
+ # Entity Storage Service
2
2
 
3
- Entity Storage contract implementation and REST endpoint definitions.
3
+ This package defines the service-facing contracts and REST endpoint definitions used to expose storage behaviour consistently. 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
 
@@ -0,0 +1,399 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { HttpParameterHelper } from "@twin.org/api-models";
4
+ import { Coerce, ComponentFactory, Guards, StringHelper } from "@twin.org/core";
5
+ import { HttpStatusCode } from "@twin.org/web";
6
+ /**
7
+ * The source used when communicating about these routes.
8
+ */
9
+ const ROUTES_SOURCE = "entityStorageRoutes";
10
+ /**
11
+ * The tag to associate with the routes.
12
+ */
13
+ export const tagsEntityStorage = [
14
+ {
15
+ name: "EntityStorage",
16
+ description: "Endpoints which are modelled to access an entity storage contract."
17
+ }
18
+ ];
19
+ /**
20
+ * The REST routes for entity storage.
21
+ * @param baseRouteName Prefix to prepend to the paths.
22
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
23
+ * @param options Additional options for the routes.
24
+ * @param options.typeName Optional type name to use in the routes, defaults to Entity Storage.
25
+ * @param options.tagName Optional name to use in OpenAPI spec for tag.
26
+ * @param options.examples Optional examples to use in the routes.
27
+ * @returns The generated routes.
28
+ */
29
+ export function generateRestRoutesEntityStorage(baseRouteName, componentName, options) {
30
+ const typeName = options?.typeName ?? "Entity Storage";
31
+ const lowerName = typeName.toLowerCase();
32
+ const camelTypeName = StringHelper.camelCase(typeName);
33
+ const setRoute = {
34
+ operationId: `${camelTypeName}Set`,
35
+ summary: `Set an entry in ${lowerName}.`,
36
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
37
+ method: "POST",
38
+ path: `${baseRouteName}/`,
39
+ handler: async (httpRequestContext, request) => entityStorageSet(httpRequestContext, componentName, request),
40
+ requestType: {
41
+ type: "IEntityStorageSetRequest",
42
+ examples: options?.examples?.set?.requestExamples ?? [
43
+ {
44
+ id: `${camelTypeName}SetRequestExample`,
45
+ request: {
46
+ body: {
47
+ id: "12345",
48
+ name: "My Item"
49
+ }
50
+ }
51
+ }
52
+ ]
53
+ },
54
+ responseType: [
55
+ {
56
+ type: "INoContentResponse"
57
+ }
58
+ ]
59
+ };
60
+ const setBatchRoute = {
61
+ operationId: `${camelTypeName}SetBatch`,
62
+ summary: `Set multiple entries in ${lowerName}.`,
63
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
64
+ method: "POST",
65
+ path: `${baseRouteName}/batch`,
66
+ handler: async (httpRequestContext, request) => entityStorageSetBatch(httpRequestContext, componentName, request),
67
+ requestType: {
68
+ type: "IEntityStorageSetBatchRequest",
69
+ examples: [
70
+ {
71
+ id: `${camelTypeName}SetBatchRequestExample`,
72
+ request: {
73
+ body: [
74
+ { id: "12345", name: "My Item" },
75
+ { id: "67890", name: "My Other Item" }
76
+ ]
77
+ }
78
+ }
79
+ ]
80
+ },
81
+ responseType: [
82
+ {
83
+ type: "INoContentResponse"
84
+ }
85
+ ]
86
+ };
87
+ const getRoute = {
88
+ operationId: `${camelTypeName}Get`,
89
+ summary: `Get an entry from ${lowerName}.`,
90
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
91
+ method: "GET",
92
+ path: `${baseRouteName}/:id`,
93
+ handler: async (httpRequestContext, request) => entityStorageGet(httpRequestContext, componentName, request),
94
+ requestType: {
95
+ type: "IEntityStorageGetRequest",
96
+ examples: options?.examples?.get?.requestExamples ?? [
97
+ {
98
+ id: `${camelTypeName}GetRequestExample`,
99
+ request: {
100
+ pathParams: {
101
+ id: "12345"
102
+ }
103
+ }
104
+ }
105
+ ]
106
+ },
107
+ responseType: [
108
+ {
109
+ type: "IEntityStorageGetResponse",
110
+ examples: options?.examples?.get?.responseExamples ?? [
111
+ {
112
+ id: `${camelTypeName}GetResponseExample`,
113
+ response: {
114
+ body: {
115
+ id: "12345",
116
+ name: "My Item"
117
+ }
118
+ }
119
+ }
120
+ ]
121
+ },
122
+ {
123
+ type: "INotFoundResponse"
124
+ }
125
+ ]
126
+ };
127
+ const removeRoute = {
128
+ operationId: `${camelTypeName}Remove`,
129
+ summary: `Remove an entry from ${lowerName}.`,
130
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
131
+ method: "DELETE",
132
+ path: `${baseRouteName}/:id`,
133
+ handler: async (httpRequestContext, request) => entityStorageRemove(httpRequestContext, componentName, request),
134
+ requestType: {
135
+ type: "IEntityStorageRemoveRequest",
136
+ examples: options?.examples?.remove?.requestExamples ?? [
137
+ {
138
+ id: `${camelTypeName}RemoveRequestExample`,
139
+ request: {
140
+ pathParams: {
141
+ id: "12345"
142
+ }
143
+ }
144
+ }
145
+ ]
146
+ },
147
+ responseType: [
148
+ {
149
+ type: "INoContentResponse"
150
+ },
151
+ {
152
+ type: "INotFoundResponse"
153
+ }
154
+ ]
155
+ };
156
+ const listRoute = {
157
+ operationId: `${camelTypeName}List`,
158
+ summary: `Query entries from ${lowerName}.`,
159
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
160
+ method: "GET",
161
+ path: `${baseRouteName}/`,
162
+ handler: async (httpRequestContext, request) => entityStorageList(httpRequestContext, componentName, request),
163
+ requestType: {
164
+ type: "IEntityStorageListRequest",
165
+ examples: options?.examples?.list?.requestExamples ?? [
166
+ {
167
+ id: `${camelTypeName}ListRequestExample`,
168
+ request: {}
169
+ }
170
+ ]
171
+ },
172
+ responseType: [
173
+ {
174
+ type: "IEntityStorageListResponse",
175
+ examples: options?.examples?.list?.responseExamples ?? [
176
+ {
177
+ id: `${camelTypeName}ListResponseExample`,
178
+ response: {
179
+ body: {
180
+ entities: [{ id: "12345", name: "My Item" }]
181
+ }
182
+ }
183
+ }
184
+ ]
185
+ }
186
+ ]
187
+ };
188
+ const countRoute = {
189
+ operationId: `${camelTypeName}Count`,
190
+ summary: `Count entries in ${lowerName}.`,
191
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
192
+ method: "GET",
193
+ path: `${baseRouteName}/count`,
194
+ handler: async (httpRequestContext, request) => entityStorageCount(httpRequestContext, componentName, request),
195
+ requestType: {
196
+ type: "IEntityStorageCountRequest",
197
+ examples: options?.examples?.count?.requestExamples ?? [
198
+ {
199
+ id: `${camelTypeName}CountRequestExample`,
200
+ request: {}
201
+ }
202
+ ]
203
+ },
204
+ responseType: [
205
+ {
206
+ type: "IEntityStorageCountResponse",
207
+ examples: options?.examples?.count?.responseExamples ?? [
208
+ {
209
+ id: `${camelTypeName}CountResponseExample`,
210
+ response: {
211
+ body: {
212
+ count: 1
213
+ }
214
+ }
215
+ }
216
+ ]
217
+ }
218
+ ]
219
+ };
220
+ const emptyRoute = {
221
+ operationId: `${camelTypeName}Empty`,
222
+ summary: `Remove all entries from ${lowerName}.`,
223
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
224
+ method: "DELETE",
225
+ path: `${baseRouteName}/`,
226
+ handler: async (httpRequestContext, request) => entityStorageEmpty(httpRequestContext, componentName, request),
227
+ requestType: {
228
+ type: "IEntityStorageEmptyRequest",
229
+ examples: [
230
+ {
231
+ id: `${camelTypeName}EmptyRequestExample`,
232
+ request: {}
233
+ }
234
+ ]
235
+ },
236
+ responseType: [
237
+ {
238
+ type: "INoContentResponse"
239
+ }
240
+ ]
241
+ };
242
+ const removeBatchRoute = {
243
+ operationId: `${camelTypeName}RemoveBatch`,
244
+ summary: `Remove multiple entries from ${lowerName} by id.`,
245
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
246
+ method: "DELETE",
247
+ path: `${baseRouteName}/batch`,
248
+ handler: async (httpRequestContext, request) => entityStorageRemoveBatch(httpRequestContext, componentName, request),
249
+ requestType: {
250
+ type: "IEntityStorageRemoveBatchRequest",
251
+ examples: [
252
+ {
253
+ id: `${camelTypeName}RemoveBatchRequestExample`,
254
+ request: {
255
+ body: ["12345", "67890"]
256
+ }
257
+ }
258
+ ]
259
+ },
260
+ responseType: [
261
+ {
262
+ type: "INoContentResponse"
263
+ }
264
+ ]
265
+ };
266
+ return [
267
+ setRoute,
268
+ setBatchRoute,
269
+ getRoute,
270
+ removeRoute,
271
+ removeBatchRoute,
272
+ emptyRoute,
273
+ listRoute,
274
+ countRoute
275
+ ];
276
+ }
277
+ /**
278
+ * Set the entry in entity storage.
279
+ * @param httpRequestContext The request context for the API.
280
+ * @param componentName The name of the component to use in the routes.
281
+ * @param request The request.
282
+ * @returns The response object with additional http response properties.
283
+ */
284
+ export async function entityStorageSet(httpRequestContext, componentName, request) {
285
+ Guards.object(ROUTES_SOURCE, "request", request);
286
+ const component = ComponentFactory.get(componentName);
287
+ await component.set(request.body);
288
+ return {
289
+ statusCode: HttpStatusCode.noContent
290
+ };
291
+ }
292
+ /**
293
+ * Set multiple entries in entity storage.
294
+ * @param httpRequestContext The request context for the API.
295
+ * @param componentName The name of the component to use in the routes.
296
+ * @param request The request.
297
+ * @returns The response object with additional http response properties.
298
+ */
299
+ export async function entityStorageSetBatch(httpRequestContext, componentName, request) {
300
+ Guards.object(ROUTES_SOURCE, "request", request);
301
+ Guards.arrayValue(ROUTES_SOURCE, "request.body", request.body);
302
+ const component = ComponentFactory.get(componentName);
303
+ await component.setBatch(request.body);
304
+ return {
305
+ statusCode: HttpStatusCode.noContent
306
+ };
307
+ }
308
+ /**
309
+ * Remove all entries from entity storage.
310
+ * @param httpRequestContext The request context for the API.
311
+ * @param componentName The name of the component to use in the routes.
312
+ * @param request The request.
313
+ * @returns The response object with additional http response properties.
314
+ */
315
+ export async function entityStorageEmpty(httpRequestContext, componentName, request) {
316
+ const component = ComponentFactory.get(componentName);
317
+ await component.empty();
318
+ return { statusCode: HttpStatusCode.noContent };
319
+ }
320
+ /**
321
+ * Get the entry from entity storage.
322
+ * @param httpRequestContext The request context for the API.
323
+ * @param componentName The name of the component to use in the routes.
324
+ * @param request The request.
325
+ * @returns The response object with additional http response properties.
326
+ */
327
+ export async function entityStorageGet(httpRequestContext, componentName, request) {
328
+ Guards.object(ROUTES_SOURCE, "request", request);
329
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
330
+ Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
331
+ const component = ComponentFactory.get(componentName);
332
+ const item = await component.get(request.pathParams.id, request.query?.secondaryIndex);
333
+ return {
334
+ body: item
335
+ };
336
+ }
337
+ /**
338
+ * Remove the entry from entity storage.
339
+ * @param httpRequestContext The request context for the API.
340
+ * @param componentName The name of the component to use in the routes.
341
+ * @param request The request.
342
+ * @returns The response object with additional http response properties.
343
+ */
344
+ export async function entityStorageRemove(httpRequestContext, componentName, request) {
345
+ Guards.object(ROUTES_SOURCE, "request", request);
346
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
347
+ Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
348
+ const component = ComponentFactory.get(componentName);
349
+ await component.remove(request.pathParams.id);
350
+ return {
351
+ statusCode: HttpStatusCode.noContent
352
+ };
353
+ }
354
+ /**
355
+ * Query the entries from entity storage.
356
+ * @param httpRequestContext The request context for the API.
357
+ * @param componentName The name of the component to use in the routes.
358
+ * @param request The request.
359
+ * @returns The response object with additional http response properties.
360
+ */
361
+ export async function entityStorageList(httpRequestContext, componentName, request) {
362
+ Guards.object(ROUTES_SOURCE, "request", request);
363
+ const component = ComponentFactory.get(componentName);
364
+ const result = await component.query(HttpParameterHelper.objectFromString(request.query?.conditions), request.query?.orderBy, request.query?.orderByDirection, HttpParameterHelper.objectFromString(request.query?.properties), request.query?.cursor, Coerce.number(request.query?.limit));
365
+ return {
366
+ body: result
367
+ };
368
+ }
369
+ /**
370
+ * Count the entries in entity storage.
371
+ * @param httpRequestContext The request context for the API.
372
+ * @param componentName The name of the component to use in the routes.
373
+ * @param request The request.
374
+ * @returns The response object with additional http response properties.
375
+ */
376
+ export async function entityStorageCount(httpRequestContext, componentName, request) {
377
+ const component = ComponentFactory.get(componentName);
378
+ const count = await component.count();
379
+ return {
380
+ body: { count }
381
+ };
382
+ }
383
+ /**
384
+ * Remove multiple entries from entity storage by id.
385
+ * @param httpRequestContext The request context for the API.
386
+ * @param componentName The name of the component to use in the routes.
387
+ * @param request The request.
388
+ * @returns The response object with additional http response properties.
389
+ */
390
+ export async function entityStorageRemoveBatch(httpRequestContext, componentName, request) {
391
+ Guards.object(ROUTES_SOURCE, "request", request);
392
+ Guards.arrayValue(ROUTES_SOURCE, "request.body", request.body);
393
+ const component = ComponentFactory.get(componentName);
394
+ await component.removeBatch(request.body);
395
+ return {
396
+ statusCode: HttpStatusCode.noContent
397
+ };
398
+ }
399
+ //# sourceMappingURL=entityStorageRoutes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityStorageRoutes.js","sourceRoot":"","sources":["../../src/entityStorageRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,mBAAmB,EAMnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAgBhF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;GAEG;AACH,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAW;IACxC;QACC,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,oEAAoE;KACjF;CACD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,+BAA+B,CAC9C,aAAqB,EACrB,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AC;IAC1C,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpParameterHelper,\n\ttype INotFoundResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { Coerce, ComponentFactory, Guards, StringHelper } from \"@twin.org/core\";\nimport type {\n\tIEntityStorageComponent,\n\tIEntityStorageCountRequest,\n\tIEntityStorageCountResponse,\n\tIEntityStorageEmptyRequest,\n\tIEntityStorageGetRequest,\n\tIEntityStorageGetResponse,\n\tIEntityStorageListRequest,\n\tIEntityStorageListResponse,\n\tIEntityStorageRemoveBatchRequest,\n\tIEntityStorageRemoveRequest,\n\tIEntityStorageSetBatchRequest,\n\tIEntityStorageSetRequest\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HttpStatusCode } from \"@twin.org/web\";\nimport type { IEntityStorageRoutesExamples } from \"./models/IEntityStorageRoutesExamples.js\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"entityStorageRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsEntityStorage: ITag[] = [\n\t{\n\t\tname: \"EntityStorage\",\n\t\tdescription: \"Endpoints which are modelled to access an entity storage contract.\"\n\t}\n];\n\n/**\n * The REST routes for entity storage.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param options Additional options for the routes.\n * @param options.typeName Optional type name to use in the routes, defaults to Entity Storage.\n * @param options.tagName Optional name to use in OpenAPI spec for tag.\n * @param options.examples Optional examples to use in the routes.\n * @returns The generated routes.\n */\nexport function generateRestRoutesEntityStorage(\n\tbaseRouteName: string,\n\tcomponentName: string,\n\toptions?: {\n\t\ttypeName?: string;\n\t\ttagName?: string;\n\t\texamples?: IEntityStorageRoutesExamples;\n\t}\n): IRestRoute[] {\n\tconst typeName = options?.typeName ?? \"Entity Storage\";\n\tconst lowerName = typeName.toLowerCase();\n\tconst camelTypeName = StringHelper.camelCase(typeName);\n\n\tconst setRoute: IRestRoute<IEntityStorageSetRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Set`,\n\t\tsummary: `Set an entry in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageSet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageSetRequest>(),\n\t\t\texamples: options?.examples?.set?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}SetRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"12345\",\n\t\t\t\t\t\t\tname: \"My Item\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst setBatchRoute: IRestRoute<IEntityStorageSetBatchRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}SetBatch`,\n\t\tsummary: `Set multiple entries in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/batch`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageSetBatch(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageSetBatchRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}SetBatchRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t{ id: \"12345\", name: \"My Item\" },\n\t\t\t\t\t\t\t{ id: \"67890\", name: \"My Other Item\" }\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getRoute: IRestRoute<IEntityStorageGetRequest, IEntityStorageGetResponse> = {\n\t\toperationId: `${camelTypeName}Get`,\n\t\tsummary: `Get an entry from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageGetRequest>(),\n\t\t\texamples: options?.examples?.get?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}GetRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"12345\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageGetResponse>(),\n\t\t\t\texamples: options?.examples?.get?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}GetResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"12345\",\n\t\t\t\t\t\t\t\tname: \"My Item\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeRoute: IRestRoute<IEntityStorageRemoveRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Remove`,\n\t\tsummary: `Remove an entry from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageRemoveRequest>(),\n\t\t\texamples: options?.examples?.remove?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}RemoveRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"12345\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listRoute: IRestRoute<IEntityStorageListRequest, IEntityStorageListResponse> = {\n\t\toperationId: `${camelTypeName}List`,\n\t\tsummary: `Query entries from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageListRequest>(),\n\t\t\texamples: options?.examples?.list?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}ListRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageListResponse>(),\n\t\t\t\texamples: options?.examples?.list?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}ListResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentities: [{ id: \"12345\", name: \"My Item\" }]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst countRoute: IRestRoute<IEntityStorageCountRequest, IEntityStorageCountResponse> = {\n\t\toperationId: `${camelTypeName}Count`,\n\t\tsummary: `Count entries in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/count`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageCount(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageCountRequest>(),\n\t\t\texamples: options?.examples?.count?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}CountRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageCountResponse>(),\n\t\t\t\texamples: options?.examples?.count?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}CountResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tcount: 1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst emptyRoute: IRestRoute<IEntityStorageEmptyRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Empty`,\n\t\tsummary: `Remove all entries from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageEmpty(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageEmptyRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}EmptyRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeBatchRoute: IRestRoute<IEntityStorageRemoveBatchRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}RemoveBatch`,\n\t\tsummary: `Remove multiple entries from ${lowerName} by id.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/batch`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageRemoveBatch(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageRemoveBatchRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}RemoveBatchRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: [\"12345\", \"67890\"]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tsetRoute,\n\t\tsetBatchRoute,\n\t\tgetRoute,\n\t\tremoveRoute,\n\t\tremoveBatchRoute,\n\t\temptyRoute,\n\t\tlistRoute,\n\t\tcountRoute\n\t];\n}\n\n/**\n * Set the entry in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageSet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageSetRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageSetRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.set(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Set multiple entries in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageSetBatch(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageSetBatchRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageSetBatchRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.arrayValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.setBatch(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Remove all entries from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageEmpty(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageEmptyRequest\n): Promise<INoContentResponse> {\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.empty();\n\treturn { statusCode: HttpStatusCode.noContent };\n}\n\n/**\n * Get the entry from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageGetRequest\n): Promise<IEntityStorageGetResponse> {\n\tGuards.object<IEntityStorageGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IEntityStorageGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst item = await component.get(\n\t\trequest.pathParams.id,\n\t\trequest.query?.secondaryIndex as keyof unknown\n\t);\n\treturn {\n\t\tbody: item\n\t};\n}\n\n/**\n * Remove the entry from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IEntityStorageRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.remove(request.pathParams.id);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Query the entries from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageListRequest\n): Promise<IEntityStorageListResponse> {\n\tGuards.object<IEntityStorageListRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst result = await component.query(\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions),\n\t\trequest.query?.orderBy as keyof unknown,\n\t\trequest.query?.orderByDirection,\n\t\tHttpParameterHelper.objectFromString(request.query?.properties),\n\t\trequest.query?.cursor,\n\t\tCoerce.number(request.query?.limit)\n\t);\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Count the entries in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageCount(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageCountRequest\n): Promise<IEntityStorageCountResponse> {\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst count = await component.count();\n\treturn {\n\t\tbody: { count }\n\t};\n}\n\n/**\n * Remove multiple entries from entity storage by id.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageRemoveBatch(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageRemoveBatchRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageRemoveBatchRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.arrayValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.removeBatch(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
@@ -0,0 +1,113 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { Guards, Is } from "@twin.org/core";
4
+ import { SortDirection } from "@twin.org/entity";
5
+ import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
6
+ /**
7
+ * Class for performing entity service operations.
8
+ */
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ export class EntityStorageService {
11
+ /**
12
+ * Runtime name for the class.
13
+ */
14
+ static CLASS_NAME = "EntityStorageService";
15
+ /**
16
+ * The entity storage for items.
17
+ * @internal
18
+ */
19
+ _entityStorage;
20
+ /**
21
+ * Create a new instance of EntityStorageService.
22
+ * @param options The dependencies for the entity storage service.
23
+ */
24
+ constructor(options) {
25
+ Guards.string(EntityStorageService.CLASS_NAME, "options.entityStorageType", options.entityStorageType);
26
+ this._entityStorage = EntityStorageConnectorFactory.get(options.entityStorageType);
27
+ }
28
+ /**
29
+ * Returns the class name of the component.
30
+ * @returns The class name of the component.
31
+ */
32
+ className() {
33
+ return EntityStorageService.CLASS_NAME;
34
+ }
35
+ /**
36
+ * Set an entity.
37
+ * @param entity The entity to set.
38
+ * @returns The id of the entity.
39
+ */
40
+ async set(entity) {
41
+ Guards.object(EntityStorageService.CLASS_NAME, "entity", entity);
42
+ return this._entityStorage.set(entity, undefined);
43
+ }
44
+ /**
45
+ * Set multiple entities in a batch.
46
+ * @param entities The entities to set.
47
+ * @returns Nothing.
48
+ */
49
+ async setBatch(entities) {
50
+ Guards.arrayValue(EntityStorageService.CLASS_NAME, "entities", entities);
51
+ return this._entityStorage.setBatch(entities);
52
+ }
53
+ /**
54
+ * Get an entity.
55
+ * @param id The id of the entity to get, or the index value if secondaryIndex is set.
56
+ * @param secondaryIndex Get the item using a secondary index.
57
+ * @returns The object if it can be found or undefined.
58
+ */
59
+ async get(id, secondaryIndex) {
60
+ Guards.stringValue(EntityStorageService.CLASS_NAME, "id", id);
61
+ return this._entityStorage.get(id, secondaryIndex);
62
+ }
63
+ /**
64
+ * Remove the entity.
65
+ * @param id The id of the entity to remove.
66
+ * @returns Nothing.
67
+ */
68
+ async remove(id) {
69
+ Guards.stringValue(EntityStorageService.CLASS_NAME, "id", id);
70
+ await this._entityStorage.remove(id);
71
+ }
72
+ /**
73
+ * Remove multiple entities by id.
74
+ * @param ids The ids of the entities to remove.
75
+ * @returns Nothing.
76
+ */
77
+ async removeBatch(ids) {
78
+ Guards.arrayValue(EntityStorageService.CLASS_NAME, "ids", ids);
79
+ return this._entityStorage.removeBatch(ids);
80
+ }
81
+ /**
82
+ * Remove all entities from the storage.
83
+ * @returns Nothing.
84
+ */
85
+ async empty() {
86
+ return this._entityStorage.empty();
87
+ }
88
+ /**
89
+ * Count all the entities which match the conditions.
90
+ * @returns The total count of entities in the storage.
91
+ */
92
+ async count() {
93
+ return this._entityStorage.count();
94
+ }
95
+ /**
96
+ * Query all the entities which match the conditions.
97
+ * @param conditions The conditions to match for the entities.
98
+ * @param orderBy The order for the results.
99
+ * @param orderByDirection The direction for the order, defaults to ascending.
100
+ * @param properties The optional properties to return, defaults to all.
101
+ * @param cursor The cursor to request the next chunk of entities.
102
+ * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
103
+ * @returns All the entities for the storage matching the conditions,
104
+ * and a cursor which can be used to request more entities.
105
+ */
106
+ async query(conditions, orderBy, orderByDirection, properties, cursor, limit) {
107
+ const result = await this._entityStorage.query(conditions, Is.stringValue(orderBy)
108
+ ? [{ property: orderBy, sortDirection: orderByDirection ?? SortDirection.Ascending }]
109
+ : undefined, properties, cursor, limit);
110
+ return result;
111
+ }
112
+ }
113
+ //# sourceMappingURL=entityStorageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityStorageService.js","sourceRoot":"","sources":["../../src/entityStorageService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAwB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACN,6BAA6B,EAG7B,MAAM,iCAAiC,CAAC;AAIzC;;GAEG;AACH,8DAA8D;AAC9D,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;OAGG;IACc,cAAc,CAA6B;IAE5D;;;OAGG;IACH,YAAY,OAAgD;QAC3D,MAAM,CAAC,MAAM,CACZ,oBAAoB,CAAC,UAAU,+BAE/B,OAAO,CAAC,iBAAiB,CACzB,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,6BAA6B,CAAC,GAAG,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AO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,KAAK;QACjB,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,KAAK,CACjB,UAA+B,EAC/B,OAAiB,EACjB,gBAAgC,EAChC,UAAwB,EACxB,MAAe,EACf,KAAc;QAWd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAC7C,UAAU,EACV,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC;YACtB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,IAAI,aAAa,CAAC,SAAS,EAAE,CAAC;YACrF,CAAC,CAAC,SAAS,EACZ,UAAU,EACV,MAAM,EACN,KAAK,CACL,CAAC;QAEF,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards, Is } from \"@twin.org/core\";\nimport { type EntityCondition, SortDirection } from \"@twin.org/entity\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageComponent,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IEntityStorageServiceConstructorOptions } from \"./models/IEntityStorageServiceConstructorOptions.js\";\n\n/**\n * Class for performing entity service operations.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class EntityStorageService<T = any> implements IEntityStorageComponent<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EntityStorageService>();\n\n\t/**\n\t * The entity storage for items.\n\t * @internal\n\t */\n\tprivate readonly _entityStorage: IEntityStorageConnector<T>;\n\n\t/**\n\t * Create a new instance of EntityStorageService.\n\t * @param options The dependencies for the entity storage service.\n\t */\n\tconstructor(options: IEntityStorageServiceConstructorOptions) {\n\t\tGuards.string(\n\t\t\tEntityStorageService.CLASS_NAME,\n\t\t\tnameof(options.entityStorageType),\n\t\t\toptions.entityStorageType\n\t\t);\n\t\tthis._entityStorage = EntityStorageConnectorFactory.get<IEntityStorageConnector<T>>(\n\t\t\toptions.entityStorageType\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn EntityStorageService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Set an entity.\n\t * @param entity The entity to set.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T): Promise<void> {\n\t\tGuards.object(EntityStorageService.CLASS_NAME, nameof(entity), entity);\n\n\t\treturn this._entityStorage.set(entity, undefined);\n\t}\n\n\t/**\n\t * Set multiple entities in a batch.\n\t * @param entities The entities to set.\n\t * @returns Nothing.\n\t */\n\tpublic async setBatch(entities: T[]): Promise<void> {\n\t\tGuards.arrayValue(EntityStorageService.CLASS_NAME, nameof(entities), entities);\n\n\t\treturn this._entityStorage.setBatch(entities);\n\t}\n\n\t/**\n\t * Get an entity.\n\t * @param id The id of the entity to get, or the index value if secondaryIndex is set.\n\t * @param secondaryIndex Get the item using a secondary index.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(id: string, secondaryIndex?: keyof T): Promise<T | undefined> {\n\t\tGuards.stringValue(EntityStorageService.CLASS_NAME, nameof(id), id);\n\n\t\treturn this._entityStorage.get(id, secondaryIndex);\n\t}\n\n\t/**\n\t * Remove the entity.\n\t * @param id The id of the entity to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(id: string): Promise<void> {\n\t\tGuards.stringValue(EntityStorageService.CLASS_NAME, nameof(id), id);\n\n\t\tawait this._entityStorage.remove(id);\n\t}\n\n\t/**\n\t * Remove multiple entities by id.\n\t * @param ids The ids of the entities to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeBatch(ids: string[]): Promise<void> {\n\t\tGuards.arrayValue(EntityStorageService.CLASS_NAME, nameof(ids), ids);\n\n\t\treturn this._entityStorage.removeBatch(ids);\n\t}\n\n\t/**\n\t * Remove all entities from the storage.\n\t * @returns Nothing.\n\t */\n\tpublic async empty(): Promise<void> {\n\t\treturn this._entityStorage.empty();\n\t}\n\n\t/**\n\t * Count all the entities which match the conditions.\n\t * @returns The total count of entities in the storage.\n\t */\n\tpublic async count(): Promise<number> {\n\t\treturn this._entityStorage.count();\n\t}\n\n\t/**\n\t * Query all the entities which match the conditions.\n\t * @param conditions The conditions to match for the entities.\n\t * @param orderBy The order for the results.\n\t * @param orderByDirection The direction for the order, defaults to ascending.\n\t * @param properties The optional properties to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<T>,\n\t\torderBy?: keyof T,\n\t\torderByDirection?: SortDirection,\n\t\tproperties?: (keyof T)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: Partial<T>[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst result = await this._entityStorage.query(\n\t\t\tconditions,\n\t\t\tIs.stringValue(orderBy)\n\t\t\t\t? [{ property: orderBy, sortDirection: orderByDirection ?? SortDirection.Ascending }]\n\t\t\t\t: undefined,\n\t\t\tproperties,\n\t\t\tcursor,\n\t\t\tlimit\n\t\t);\n\n\t\treturn result;\n\t}\n}\n"]}
@@ -0,0 +1,9 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./entityStorageRoutes.js";
4
+ export * from "./entityStorageService.js";
5
+ export * from "./models/IEntityStorageServiceConfig.js";
6
+ export * from "./models/IEntityStorageRoutesExamples.js";
7
+ export * from "./models/IEntityStorageServiceConstructorOptions.js";
8
+ export * from "./restEntryPoints.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AACzD,cAAc,qDAAqD,CAAC;AACpE,cAAc,sBAAsB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./entityStorageRoutes.js\";\nexport * from \"./entityStorageService.js\";\nexport * from \"./models/IEntityStorageServiceConfig.js\";\nexport * from \"./models/IEntityStorageRoutesExamples.js\";\nexport * from \"./models/IEntityStorageServiceConstructorOptions.js\";\nexport * from \"./restEntryPoints.js\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IEntityStorageRoutesExamples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IEntityStorageRoutesExamples.js","sourceRoot":"","sources":["../../../src/models/IEntityStorageRoutesExamples.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteRequestExample, IRestRouteResponseExample } from \"@twin.org/api-models\";\nimport type {\n\tIEntityStorageCountRequest,\n\tIEntityStorageCountResponse,\n\tIEntityStorageGetRequest,\n\tIEntityStorageGetResponse,\n\tIEntityStorageListRequest,\n\tIEntityStorageListResponse,\n\tIEntityStorageRemoveRequest,\n\tIEntityStorageSetRequest\n} from \"@twin.org/entity-storage-models\";\n\n/**\n * Examples for the entity storage routes.\n */\nexport interface IEntityStorageRoutesExamples {\n\t/**\n\t * Examples for the set route.\n\t */\n\tset?: {\n\t\trequestExamples: IRestRouteRequestExample<IEntityStorageSetRequest>[];\n\t};\n\n\t/**\n\t * Examples for the get route.\n\t */\n\tget?: {\n\t\trequestExamples: IRestRouteRequestExample<IEntityStorageGetRequest>[];\n\t\tresponseExamples: IRestRouteResponseExample<IEntityStorageGetResponse>[];\n\t};\n\n\t/**\n\t * Examples for the remove route.\n\t */\n\tremove?: {\n\t\trequestExamples: IRestRouteRequestExample<IEntityStorageRemoveRequest>[];\n\t};\n\n\t/**\n\t * Examples for the list route.\n\t */\n\tlist?: {\n\t\trequestExamples: IRestRouteRequestExample<IEntityStorageListRequest>[];\n\t\tresponseExamples: IRestRouteResponseExample<IEntityStorageListResponse>[];\n\t};\n\n\t/**\n\t * Examples for the count route.\n\t */\n\tcount?: {\n\t\trequestExamples: IRestRouteRequestExample<IEntityStorageCountRequest>[];\n\t\tresponseExamples: IRestRouteResponseExample<IEntityStorageCountResponse>[];\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IEntityStorageServiceConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IEntityStorageServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IEntityStorageServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the entity storage service.\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IEntityStorageServiceConfig {}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IEntityStorageServiceConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IEntityStorageServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IEntityStorageServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEntityStorageServiceConfig } from \"./IEntityStorageServiceConfig.js\";\n\n/**\n * Options for the Entity Storage Service constructor.\n */\nexport interface IEntityStorageServiceConstructorOptions {\n\t/**\n\t * The type of the entity storage.\n\t */\n\tentityStorageType: string;\n\n\t/**\n\t * The configuration for the service.\n\t */\n\tconfig?: IEntityStorageServiceConfig;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { generateRestRoutesEntityStorage, tagsEntityStorage } from "./entityStorageRoutes.js";
2
+ /**
3
+ * These are dummy entry points for the entity storage service.
4
+ * In reality your application would create its own entry points based on the
5
+ * entity storage schema objects it wants to store, using a custom defaultBaseRoute.
6
+ */
7
+ export const restEntryPoints = [
8
+ {
9
+ name: "entity-storage",
10
+ defaultBaseRoute: "entity-storage",
11
+ tags: tagsEntityStorage,
12
+ generateRoutes: generateRestRoutesEntityStorage
13
+ }
14
+ ];
15
+ //# sourceMappingURL=restEntryPoints.js.map