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