@twin.org/entity-storage-service 0.0.1-next.5

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,433 @@
1
+ import { HttpParameterHelper } from '@twin.org/api-models';
2
+ import { StringHelper, Guards, ComponentFactory, Coerce, Is } from '@twin.org/core';
3
+ import { HttpStatusCode } from '@twin.org/web';
4
+ import { ComparisonOperator, LogicalOperator, EntitySchemaHelper } from '@twin.org/entity';
5
+ import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
6
+
7
+ // Copyright 2024 IOTA Stiftung.
8
+ // SPDX-License-Identifier: Apache-2.0.
9
+ /**
10
+ * The source used when communicating about these routes.
11
+ */
12
+ const ROUTES_SOURCE = "entityStorageRoutes";
13
+ /**
14
+ * The tag to associate with the routes.
15
+ */
16
+ const tagsEntityStorage = [
17
+ {
18
+ name: "EntityStorage",
19
+ description: "Endpoints which are modelled to access an entity storage contract."
20
+ }
21
+ ];
22
+ /**
23
+ * The REST routes for entity storage.
24
+ * @param baseRouteName Prefix to prepend to the paths.
25
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
26
+ * @param options Additional options for the routes.
27
+ * @param options.typeName Optional type name to use in the routes, defaults to Entity Storage.
28
+ * @param options.tagName Optional name to use in OpenAPI spec for tag.
29
+ * @param options.examples Optional examples to use in the routes.
30
+ * @returns The generated routes.
31
+ */
32
+ function generateRestRoutesEntityStorage(baseRouteName, componentName, options) {
33
+ const typeName = options?.typeName ?? "Entity Storage";
34
+ const lowerName = typeName.toLowerCase();
35
+ const camelTypeName = StringHelper.camelCase(typeName);
36
+ const setRoute = {
37
+ operationId: `${camelTypeName}Set`,
38
+ summary: `Set an entry in ${lowerName}.`,
39
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
40
+ method: "POST",
41
+ path: `${baseRouteName}/`,
42
+ handler: async (httpRequestContext, request) => entityStorageSet(httpRequestContext, componentName, request),
43
+ requestType: {
44
+ type: "IEntityStorageSetRequest",
45
+ examples: options?.examples?.set?.requestExamples ?? [
46
+ {
47
+ id: `${camelTypeName}SetRequestExample`,
48
+ request: {
49
+ body: {
50
+ id: "12345",
51
+ name: "My Item"
52
+ }
53
+ }
54
+ }
55
+ ]
56
+ },
57
+ responseType: [
58
+ {
59
+ type: "INoContentResponse"
60
+ }
61
+ ]
62
+ };
63
+ const getRoute = {
64
+ operationId: `${camelTypeName}Get`,
65
+ summary: `Get an entry from ${lowerName}.`,
66
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
67
+ method: "GET",
68
+ path: `${baseRouteName}/:id`,
69
+ handler: async (httpRequestContext, request) => entityStorageGet(httpRequestContext, componentName, request),
70
+ requestType: {
71
+ type: "IEntityStorageGetRequest",
72
+ examples: options?.examples?.get?.requestExamples ?? [
73
+ {
74
+ id: `${camelTypeName}GetRequestExample`,
75
+ request: {
76
+ pathParams: {
77
+ id: "12345"
78
+ }
79
+ }
80
+ }
81
+ ]
82
+ },
83
+ responseType: [
84
+ {
85
+ type: "IEntityStorageGetResponse",
86
+ examples: options?.examples?.get?.responseExamples ?? [
87
+ {
88
+ id: `${camelTypeName}GetResponseExample`,
89
+ response: {
90
+ body: {
91
+ id: "12345",
92
+ name: "My Item"
93
+ }
94
+ }
95
+ }
96
+ ]
97
+ }
98
+ ]
99
+ };
100
+ const removeRoute = {
101
+ operationId: `${camelTypeName}Remove`,
102
+ summary: `Remove an entry from ${lowerName}.`,
103
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
104
+ method: "DELETE",
105
+ path: `${baseRouteName}/:id`,
106
+ handler: async (httpRequestContext, request) => entityStorageRemove(httpRequestContext, componentName, request),
107
+ requestType: {
108
+ type: "IEntityStorageRemoveRequest",
109
+ examples: options?.examples?.remove?.requestExamples ?? [
110
+ {
111
+ id: `${camelTypeName}RemoveRequestExample`,
112
+ request: {
113
+ pathParams: {
114
+ id: "12345"
115
+ }
116
+ }
117
+ }
118
+ ]
119
+ },
120
+ responseType: [
121
+ {
122
+ type: "INoContentResponse"
123
+ }
124
+ ]
125
+ };
126
+ const listRoute = {
127
+ operationId: `${camelTypeName}List`,
128
+ summary: `Query entries from ${lowerName}.`,
129
+ tag: options?.tagName ?? tagsEntityStorage[0].name,
130
+ method: "GET",
131
+ path: `${baseRouteName}/`,
132
+ handler: async (httpRequestContext, request) => entityStorageList(httpRequestContext, componentName, request),
133
+ requestType: {
134
+ type: "IEntityStorageListRequest",
135
+ examples: options?.examples?.list?.requestExamples ?? [
136
+ {
137
+ id: `${camelTypeName}ListRequestExample`,
138
+ request: {}
139
+ }
140
+ ]
141
+ },
142
+ responseType: [
143
+ {
144
+ type: "IEntityStorageListResponse",
145
+ examples: options?.examples?.list?.responseExamples ?? [
146
+ {
147
+ id: `${camelTypeName}ListResponseExample`,
148
+ response: {
149
+ body: {
150
+ entities: [{ id: "12345", name: "My Item" }]
151
+ }
152
+ }
153
+ }
154
+ ]
155
+ }
156
+ ]
157
+ };
158
+ return [setRoute, getRoute, removeRoute, listRoute];
159
+ }
160
+ /**
161
+ * Set the entry in entity storage.
162
+ * @param httpRequestContext The request context for the API.
163
+ * @param componentName The name of the component to use in the routes.
164
+ * @param request The request.
165
+ * @returns The response object with additional http response properties.
166
+ */
167
+ async function entityStorageSet(httpRequestContext, componentName, request) {
168
+ Guards.object(ROUTES_SOURCE, "request", request);
169
+ const component = ComponentFactory.get(componentName);
170
+ await component.set(request.body, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
171
+ return {
172
+ statusCode: HttpStatusCode.noContent
173
+ };
174
+ }
175
+ /**
176
+ * Get the entry from entity storage.
177
+ * @param httpRequestContext The request context for the API.
178
+ * @param componentName The name of the component to use in the routes.
179
+ * @param request The request.
180
+ * @returns The response object with additional http response properties.
181
+ */
182
+ async function entityStorageGet(httpRequestContext, componentName, request) {
183
+ Guards.object(ROUTES_SOURCE, "request", request);
184
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
185
+ Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
186
+ const component = ComponentFactory.get(componentName);
187
+ const item = await component.get(request.pathParams.id, request.query?.secondaryIndex, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
188
+ return {
189
+ body: item
190
+ };
191
+ }
192
+ /**
193
+ * Remove the entry from entity storage.
194
+ * @param httpRequestContext The request context for the API.
195
+ * @param componentName The name of the component to use in the routes.
196
+ * @param request The request.
197
+ * @returns The response object with additional http response properties.
198
+ */
199
+ async function entityStorageRemove(httpRequestContext, componentName, request) {
200
+ Guards.object(ROUTES_SOURCE, "request", request);
201
+ Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
202
+ Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
203
+ const component = ComponentFactory.get(componentName);
204
+ await component.remove(request.pathParams.id, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
205
+ return {
206
+ statusCode: HttpStatusCode.noContent
207
+ };
208
+ }
209
+ /**
210
+ * Query the entries from entity storage.
211
+ * @param httpRequestContext The request context for the API.
212
+ * @param componentName The name of the component to use in the routes.
213
+ * @param request The request.
214
+ * @returns The response object with additional http response properties.
215
+ */
216
+ async function entityStorageList(httpRequestContext, componentName, request) {
217
+ Guards.object(ROUTES_SOURCE, "request", request);
218
+ const component = ComponentFactory.get(componentName);
219
+ const result = await component.query(HttpParameterHelper.objectFromString(request.query?.conditions), HttpParameterHelper.objectFromString(request.query?.sortProperties), HttpParameterHelper.objectFromString(request.query?.properties), request.query?.cursor, Coerce.number(request.query?.pageSize), httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
220
+ return {
221
+ body: result
222
+ };
223
+ }
224
+
225
+ // Copyright 2024 IOTA Stiftung.
226
+ // SPDX-License-Identifier: Apache-2.0.
227
+ /**
228
+ * Class for performing entity service operations.
229
+ */
230
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
+ class EntityStorageService {
232
+ /**
233
+ * Runtime name for the class.
234
+ */
235
+ CLASS_NAME = "EntityStorageService";
236
+ /**
237
+ * The entity storage for items.
238
+ * @internal
239
+ */
240
+ _entityStorage;
241
+ /**
242
+ * Include the node identity when performing storage operations, defaults to true.
243
+ * @internal
244
+ */
245
+ _includeNodeIdentity;
246
+ /**
247
+ * Include the user identity when performing storage operations, defaults to true.
248
+ * @internal
249
+ */
250
+ _includeUserIdentity;
251
+ /**
252
+ * Create a new instance of EntityStorageService.
253
+ * @param options The dependencies for the entity storage service.
254
+ * @param options.config The configuration for the service.
255
+ * @param options.entityStorageType The entity storage type.
256
+ */
257
+ constructor(options) {
258
+ Guards.string(this.CLASS_NAME, "options.entityStorageType", options.entityStorageType);
259
+ this._entityStorage = EntityStorageConnectorFactory.get(options.entityStorageType);
260
+ this._includeNodeIdentity = options.config?.includeNodeIdentity ?? true;
261
+ this._includeUserIdentity = options.config?.includeUserIdentity ?? true;
262
+ }
263
+ /**
264
+ * Set an entity.
265
+ * @param entity The entity to set.
266
+ * @param userIdentity The user identity to use with storage operations.
267
+ * @param nodeIdentity The node identity to use with storage operations.
268
+ * @returns The id of the entity.
269
+ */
270
+ async set(entity, userIdentity, nodeIdentity) {
271
+ Guards.object(this.CLASS_NAME, "entity", entity);
272
+ if (this._includeUserIdentity) {
273
+ Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
274
+ }
275
+ if (this._includeNodeIdentity) {
276
+ Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
277
+ }
278
+ entity.nodeIdentity = nodeIdentity;
279
+ entity.userIdentity = userIdentity;
280
+ return this._entityStorage.set(entity);
281
+ }
282
+ /**
283
+ * Get an entity.
284
+ * @param id The id of the entity to get, or the index value if secondaryIndex is set.
285
+ * @param secondaryIndex Get the item using a secondary index.
286
+ * @param userIdentity The user identity to use with storage operations.
287
+ * @param nodeIdentity The node identity to use with storage operations.
288
+ * @returns The object if it can be found or undefined.
289
+ */
290
+ async get(id, secondaryIndex, userIdentity, nodeIdentity) {
291
+ Guards.stringValue(this.CLASS_NAME, "id", id);
292
+ const conditions = [];
293
+ if (this._includeUserIdentity) {
294
+ Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
295
+ conditions.push({
296
+ property: "userIdentity",
297
+ comparison: ComparisonOperator.Equals,
298
+ value: userIdentity
299
+ });
300
+ }
301
+ if (this._includeNodeIdentity) {
302
+ Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
303
+ conditions.push({
304
+ property: "nodeIdentity",
305
+ comparison: ComparisonOperator.Equals,
306
+ value: nodeIdentity
307
+ });
308
+ }
309
+ if (Is.stringValue(secondaryIndex)) {
310
+ conditions.push({
311
+ property: secondaryIndex,
312
+ comparison: ComparisonOperator.Equals,
313
+ value: id
314
+ });
315
+ }
316
+ if (conditions.length === 0) {
317
+ const entity = await this._entityStorage.get(id, secondaryIndex);
318
+ if (!Is.empty(entity)) {
319
+ delete entity.nodeIdentity;
320
+ delete entity.userIdentity;
321
+ }
322
+ return entity;
323
+ }
324
+ const results = await this._entityStorage.query({
325
+ conditions,
326
+ logicalOperator: LogicalOperator.And
327
+ }, undefined, undefined, undefined, 1);
328
+ const entity = results.entities[0];
329
+ delete entity.nodeIdentity;
330
+ delete entity.userIdentity;
331
+ return entity;
332
+ }
333
+ /**
334
+ * Remove the entity.
335
+ * @param id The id of the entity to remove.
336
+ * @param userIdentity The user identity to use with storage operations.
337
+ * @param nodeIdentity The node identity to use with storage operations.
338
+ * @returns Nothing.
339
+ */
340
+ async remove(id, userIdentity, nodeIdentity) {
341
+ Guards.stringValue(this.CLASS_NAME, "id", id);
342
+ const conditions = [];
343
+ if (this._includeUserIdentity) {
344
+ Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
345
+ conditions.push({
346
+ property: "userIdentity",
347
+ comparison: ComparisonOperator.Equals,
348
+ value: userIdentity
349
+ });
350
+ }
351
+ if (this._includeNodeIdentity) {
352
+ Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
353
+ conditions.push({
354
+ property: "nodeIdentity",
355
+ comparison: ComparisonOperator.Equals,
356
+ value: nodeIdentity
357
+ });
358
+ }
359
+ if (conditions.length === 0) {
360
+ return this._entityStorage.remove(id);
361
+ }
362
+ const results = await this._entityStorage.query({
363
+ conditions,
364
+ logicalOperator: LogicalOperator.And
365
+ }, undefined, undefined, undefined, 1);
366
+ if (results.entities.length > 0) {
367
+ const firstEntity = results.entities[0];
368
+ const schema = this._entityStorage.getSchema();
369
+ const primaryKey = EntitySchemaHelper.getPrimaryKey(schema);
370
+ await this._entityStorage.remove(firstEntity[primaryKey.property]);
371
+ }
372
+ }
373
+ /**
374
+ * Query all the entities which match the conditions.
375
+ * @param conditions The conditions to match for the entities.
376
+ * @param sortProperties The optional sort order.
377
+ * @param properties The optional properties to return, defaults to all.
378
+ * @param cursor The cursor to request the next page of entities.
379
+ * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
380
+ * @param userIdentity The user identity to use with storage operations.
381
+ * @param nodeIdentity The node identity to use with storage operations.
382
+ * @returns All the entities for the storage matching the conditions,
383
+ * and a cursor which can be used to request more entities.
384
+ */
385
+ async query(conditions, sortProperties, properties, cursor, pageSize, userIdentity, nodeIdentity) {
386
+ const conditionsList = [];
387
+ if (this._includeUserIdentity) {
388
+ Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
389
+ conditionsList.push({
390
+ property: "userIdentity",
391
+ comparison: ComparisonOperator.Equals,
392
+ value: userIdentity
393
+ });
394
+ }
395
+ if (this._includeNodeIdentity) {
396
+ Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
397
+ conditionsList.push({
398
+ property: "nodeIdentity",
399
+ comparison: ComparisonOperator.Equals,
400
+ value: nodeIdentity
401
+ });
402
+ }
403
+ const finalConditions = {
404
+ conditions: conditionsList,
405
+ logicalOperator: LogicalOperator.And
406
+ };
407
+ if (!Is.empty(conditions)) {
408
+ finalConditions.conditions.push(conditions);
409
+ }
410
+ const result = await this._entityStorage.query(finalConditions, sortProperties, properties, cursor, pageSize);
411
+ for (const entity of result.entities) {
412
+ delete entity.nodeIdentity;
413
+ delete entity.userIdentity;
414
+ }
415
+ return result;
416
+ }
417
+ }
418
+
419
+ /**
420
+ * These are dummy entry points for the entity storage service.
421
+ * In reality your application would create its own entry points based on the
422
+ * entity storage schema objects it wants to store, using a custom defaultBaseRoute.
423
+ */
424
+ const restEntryPoints = [
425
+ {
426
+ name: "entity-storage",
427
+ defaultBaseRoute: "entity-storage",
428
+ tags: tagsEntityStorage,
429
+ generateRoutes: generateRestRoutesEntityStorage
430
+ }
431
+ ];
432
+
433
+ export { EntityStorageService, entityStorageGet, entityStorageList, entityStorageRemove, entityStorageSet, generateRestRoutesEntityStorage, restEntryPoints, tagsEntityStorage };
@@ -0,0 +1,54 @@
1
+ import { type IHttpRequestContext, type INoContentResponse, type IRestRoute, type ITag } from "@twin.org/api-models";
2
+ import type { IEntityStorageGetRequest, IEntityStorageGetResponse, IEntityStorageListRequest, IEntityStorageListResponse, IEntityStorageRemoveRequest, IEntityStorageSetRequest } from "@twin.org/entity-storage-models";
3
+ import type { IEntityStorageRoutesExamples } from "./models/IEntityStorageRoutesExamples";
4
+ /**
5
+ * The tag to associate with the routes.
6
+ */
7
+ export declare const tagsEntityStorage: ITag[];
8
+ /**
9
+ * The REST routes for entity storage.
10
+ * @param baseRouteName Prefix to prepend to the paths.
11
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
12
+ * @param options Additional options for the routes.
13
+ * @param options.typeName Optional type name to use in the routes, defaults to Entity Storage.
14
+ * @param options.tagName Optional name to use in OpenAPI spec for tag.
15
+ * @param options.examples Optional examples to use in the routes.
16
+ * @returns The generated routes.
17
+ */
18
+ export declare function generateRestRoutesEntityStorage(baseRouteName: string, componentName: string, options?: {
19
+ typeName?: string;
20
+ tagName?: string;
21
+ examples?: IEntityStorageRoutesExamples;
22
+ }): IRestRoute[];
23
+ /**
24
+ * Set the entry in entity storage.
25
+ * @param httpRequestContext The request context for the API.
26
+ * @param componentName The name of the component to use in the routes.
27
+ * @param request The request.
28
+ * @returns The response object with additional http response properties.
29
+ */
30
+ export declare function entityStorageSet(httpRequestContext: IHttpRequestContext, componentName: string, request: IEntityStorageSetRequest): Promise<INoContentResponse>;
31
+ /**
32
+ * Get the entry from entity storage.
33
+ * @param httpRequestContext The request context for the API.
34
+ * @param componentName The name of the component to use in the routes.
35
+ * @param request The request.
36
+ * @returns The response object with additional http response properties.
37
+ */
38
+ export declare function entityStorageGet(httpRequestContext: IHttpRequestContext, componentName: string, request: IEntityStorageGetRequest): Promise<IEntityStorageGetResponse>;
39
+ /**
40
+ * Remove the entry from entity storage.
41
+ * @param httpRequestContext The request context for the API.
42
+ * @param componentName The name of the component to use in the routes.
43
+ * @param request The request.
44
+ * @returns The response object with additional http response properties.
45
+ */
46
+ export declare function entityStorageRemove(httpRequestContext: IHttpRequestContext, componentName: string, request: IEntityStorageRemoveRequest): Promise<INoContentResponse>;
47
+ /**
48
+ * Query the entries from entity storage.
49
+ * @param httpRequestContext The request context for the API.
50
+ * @param componentName The name of the component to use in the routes.
51
+ * @param request The request.
52
+ * @returns The response object with additional http response properties.
53
+ */
54
+ export declare function entityStorageList(httpRequestContext: IHttpRequestContext, componentName: string, request: IEntityStorageListRequest): Promise<IEntityStorageListResponse>;
@@ -0,0 +1,75 @@
1
+ import { type SortDirection, type EntityCondition } from "@twin.org/entity";
2
+ import { type IEntityStorageComponent } from "@twin.org/entity-storage-models";
3
+ import type { IEntityStorageConfig } from "./models/IEntityStorageConfig";
4
+ /**
5
+ * Class for performing entity service operations.
6
+ */
7
+ export declare class EntityStorageService<T extends {
8
+ nodeIdentity?: string;
9
+ userIdentity?: string;
10
+ } = any> implements IEntityStorageComponent<T> {
11
+ /**
12
+ * Runtime name for the class.
13
+ */
14
+ readonly CLASS_NAME: string;
15
+ /**
16
+ * Create a new instance of EntityStorageService.
17
+ * @param options The dependencies for the entity storage service.
18
+ * @param options.config The configuration for the service.
19
+ * @param options.entityStorageType The entity storage type.
20
+ */
21
+ constructor(options: {
22
+ entityStorageType: string;
23
+ config?: IEntityStorageConfig;
24
+ });
25
+ /**
26
+ * Set an entity.
27
+ * @param entity The entity to set.
28
+ * @param userIdentity The user identity to use with storage operations.
29
+ * @param nodeIdentity The node identity to use with storage operations.
30
+ * @returns The id of the entity.
31
+ */
32
+ set(entity: T, userIdentity?: string, nodeIdentity?: string): Promise<void>;
33
+ /**
34
+ * Get an entity.
35
+ * @param id The id of the entity to get, or the index value if secondaryIndex is set.
36
+ * @param secondaryIndex Get the item using a secondary index.
37
+ * @param userIdentity The user identity to use with storage operations.
38
+ * @param nodeIdentity The node identity to use with storage operations.
39
+ * @returns The object if it can be found or undefined.
40
+ */
41
+ get(id: string, secondaryIndex?: keyof T, userIdentity?: string, nodeIdentity?: string): Promise<T | undefined>;
42
+ /**
43
+ * Remove the entity.
44
+ * @param id The id of the entity to remove.
45
+ * @param userIdentity The user identity to use with storage operations.
46
+ * @param nodeIdentity The node identity to use with storage operations.
47
+ * @returns Nothing.
48
+ */
49
+ remove(id: string, userIdentity?: string, nodeIdentity?: string): Promise<void>;
50
+ /**
51
+ * Query all the entities which match the conditions.
52
+ * @param conditions The conditions to match for the entities.
53
+ * @param sortProperties The optional sort order.
54
+ * @param properties The optional properties to return, defaults to all.
55
+ * @param cursor The cursor to request the next page of entities.
56
+ * @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
57
+ * @param userIdentity The user identity to use with storage operations.
58
+ * @param nodeIdentity The node identity to use with storage operations.
59
+ * @returns All the entities for the storage matching the conditions,
60
+ * and a cursor which can be used to request more entities.
61
+ */
62
+ query(conditions?: EntityCondition<T>, sortProperties?: {
63
+ property: keyof T;
64
+ sortDirection: SortDirection;
65
+ }[], properties?: (keyof T)[], cursor?: string, pageSize?: number, userIdentity?: string, nodeIdentity?: string): Promise<{
66
+ /**
67
+ * The entities, which can be partial if a limited keys list was provided.
68
+ */
69
+ entities: Partial<T>[];
70
+ /**
71
+ * An optional cursor, when defined can be used to call find to get more entities.
72
+ */
73
+ cursor?: string;
74
+ }>;
75
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./entityStorageRoutes";
2
+ export * from "./entityStorageService";
3
+ export * from "./models/IEntityStorageConfig";
4
+ export * from "./models/IEntityStorageRoutesExamples";
5
+ export * from "./restEntryPoints";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Configuration for the entity storage service.
3
+ */
4
+ export interface IEntityStorageConfig {
5
+ /**
6
+ * Include the node identity when performing storage operations, defaults to true.
7
+ */
8
+ includeNodeIdentity?: boolean;
9
+ /**
10
+ * Include the user identity when performing storage operations, defaults to true.
11
+ */
12
+ includeUserIdentity?: boolean;
13
+ }
@@ -0,0 +1,33 @@
1
+ import type { IRestRouteRequestExample, IRestRouteResponseExample } from "@twin.org/api-models";
2
+ import type { IEntityStorageGetRequest, IEntityStorageGetResponse, IEntityStorageListRequest, IEntityStorageListResponse, IEntityStorageRemoveRequest, IEntityStorageSetRequest } from "@twin.org/entity-storage-models";
3
+ /**
4
+ * Examples for the entity storage routes.
5
+ */
6
+ export interface IEntityStorageRoutesExamples {
7
+ /**
8
+ * Examples for the set route.
9
+ */
10
+ set?: {
11
+ requestExamples: IRestRouteRequestExample<IEntityStorageSetRequest>[];
12
+ };
13
+ /**
14
+ * Examples for the get route.
15
+ */
16
+ get?: {
17
+ requestExamples: IRestRouteRequestExample<IEntityStorageGetRequest>[];
18
+ responseExamples: IRestRouteResponseExample<IEntityStorageGetResponse>[];
19
+ };
20
+ /**
21
+ * Examples for the remove route.
22
+ */
23
+ remove?: {
24
+ requestExamples: IRestRouteRequestExample<IEntityStorageRemoveRequest>[];
25
+ };
26
+ /**
27
+ * Examples for the list route.
28
+ */
29
+ list?: {
30
+ requestExamples: IRestRouteRequestExample<IEntityStorageListRequest>[];
31
+ responseExamples: IRestRouteResponseExample<IEntityStorageListResponse>[];
32
+ };
33
+ }
@@ -0,0 +1,7 @@
1
+ import type { IRestRouteEntryPoint } from "@twin.org/api-models";
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 declare const restEntryPoints: IRestRouteEntryPoint[];
@@ -0,0 +1,5 @@
1
+ # @twin.org/entity-storage-service - Changelog
2
+
3
+ ## v0.0.1-next.5
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/entity-storage-service - Examples