@twin.org/entity-storage-service 0.0.1-next.9 → 0.0.2-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +7 -12
- package/dist/esm/index.mjs +8 -13
- package/dist/types/entityStorageService.d.ts +6 -13
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/IEntityStorageServiceConstructorOptions.d.ts +14 -0
- package/docs/changelog.md +128 -1
- package/docs/open-api/spec.json +641 -608
- package/docs/reference/classes/EntityStorageService.md +72 -48
- package/docs/reference/functions/entityStorageGet.md +9 -3
- package/docs/reference/functions/entityStorageList.md +9 -3
- package/docs/reference/functions/entityStorageRemove.md +9 -3
- package/docs/reference/functions/entityStorageSet.md +9 -3
- package/docs/reference/functions/generateRestRoutesEntityStorage.md +18 -8
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/IEntityStorageServiceConstructorOptions.md +19 -0
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
@@ -224,7 +224,7 @@ async function entityStorageRemove(httpRequestContext, componentName, request) {
|
|
224
224
|
async function entityStorageList(httpRequestContext, componentName, request) {
|
225
225
|
core.Guards.object(ROUTES_SOURCE, "request", request);
|
226
226
|
const component = core.ComponentFactory.get(componentName);
|
227
|
-
const result = await component.query(apiModels.HttpParameterHelper.objectFromString(request.query?.conditions),
|
227
|
+
const result = await component.query(apiModels.HttpParameterHelper.objectFromString(request.query?.conditions), request.query?.orderBy, request.query?.orderByDirection, apiModels.HttpParameterHelper.objectFromString(request.query?.properties), request.query?.cursor, core.Coerce.number(request.query?.pageSize), httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
|
228
228
|
return {
|
229
229
|
body: result
|
230
230
|
};
|
@@ -256,23 +256,15 @@ class EntityStorageService {
|
|
256
256
|
* @internal
|
257
257
|
*/
|
258
258
|
_includeUserIdentity;
|
259
|
-
/**
|
260
|
-
* The primary key for the entity.
|
261
|
-
* @internal
|
262
|
-
*/
|
263
|
-
_primaryKey;
|
264
259
|
/**
|
265
260
|
* Create a new instance of EntityStorageService.
|
266
261
|
* @param options The dependencies for the entity storage service.
|
267
|
-
* @param options.config The configuration for the service.
|
268
|
-
* @param options.entityStorageType The entity storage type.
|
269
262
|
*/
|
270
263
|
constructor(options) {
|
271
264
|
core.Guards.string(this.CLASS_NAME, "options.entityStorageType", options.entityStorageType);
|
272
265
|
this._entityStorage = entityStorageModels.EntityStorageConnectorFactory.get(options.entityStorageType);
|
273
266
|
this._includeNodeIdentity = options.config?.includeNodeIdentity ?? true;
|
274
267
|
this._includeUserIdentity = options.config?.includeUserIdentity ?? true;
|
275
|
-
this._primaryKey = entity.EntitySchemaHelper.getPrimaryKey(this._entityStorage.getSchema());
|
276
268
|
}
|
277
269
|
/**
|
278
270
|
* Set an entity.
|
@@ -343,7 +335,8 @@ class EntityStorageService {
|
|
343
335
|
/**
|
344
336
|
* Query all the entities which match the conditions.
|
345
337
|
* @param conditions The conditions to match for the entities.
|
346
|
-
* @param
|
338
|
+
* @param orderBy The order for the results.
|
339
|
+
* @param orderByDirection The direction for the order, defaults to ascending.
|
347
340
|
* @param properties The optional properties to return, defaults to all.
|
348
341
|
* @param cursor The cursor to request the next page of entities.
|
349
342
|
* @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
@@ -352,7 +345,7 @@ class EntityStorageService {
|
|
352
345
|
* @returns All the entities for the storage matching the conditions,
|
353
346
|
* and a cursor which can be used to request more entities.
|
354
347
|
*/
|
355
|
-
async query(conditions,
|
348
|
+
async query(conditions, orderBy, orderByDirection, properties, cursor, pageSize, userIdentity, nodeIdentity) {
|
356
349
|
const finalConditions = {
|
357
350
|
conditions: [],
|
358
351
|
logicalOperator: entity.LogicalOperator.And
|
@@ -376,7 +369,9 @@ class EntityStorageService {
|
|
376
369
|
if (!core.Is.empty(conditions)) {
|
377
370
|
finalConditions.conditions.push(conditions);
|
378
371
|
}
|
379
|
-
const result = await this._entityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined,
|
372
|
+
const result = await this._entityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, core.Is.stringValue(orderBy)
|
373
|
+
? [{ property: orderBy, sortDirection: orderByDirection ?? entity.SortDirection.Ascending }]
|
374
|
+
: undefined, properties, cursor, pageSize);
|
380
375
|
for (const entity of result.entities) {
|
381
376
|
core.ObjectHelper.propertyDelete(entity, "nodeIdentity");
|
382
377
|
core.ObjectHelper.propertyDelete(entity, "userIdentity");
|
package/dist/esm/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { HttpParameterHelper } from '@twin.org/api-models';
|
2
2
|
import { StringHelper, Guards, ComponentFactory, Coerce, ObjectHelper, Is, NotFoundError } from '@twin.org/core';
|
3
3
|
import { HttpStatusCode } from '@twin.org/web';
|
4
|
-
import {
|
4
|
+
import { LogicalOperator, ComparisonOperator, SortDirection, EntitySchemaHelper } from '@twin.org/entity';
|
5
5
|
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
6
6
|
|
7
7
|
// Copyright 2024 IOTA Stiftung.
|
@@ -222,7 +222,7 @@ async function entityStorageRemove(httpRequestContext, componentName, request) {
|
|
222
222
|
async function entityStorageList(httpRequestContext, componentName, request) {
|
223
223
|
Guards.object(ROUTES_SOURCE, "request", request);
|
224
224
|
const component = ComponentFactory.get(componentName);
|
225
|
-
const result = await component.query(HttpParameterHelper.objectFromString(request.query?.conditions),
|
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
226
|
return {
|
227
227
|
body: result
|
228
228
|
};
|
@@ -254,23 +254,15 @@ class EntityStorageService {
|
|
254
254
|
* @internal
|
255
255
|
*/
|
256
256
|
_includeUserIdentity;
|
257
|
-
/**
|
258
|
-
* The primary key for the entity.
|
259
|
-
* @internal
|
260
|
-
*/
|
261
|
-
_primaryKey;
|
262
257
|
/**
|
263
258
|
* Create a new instance of EntityStorageService.
|
264
259
|
* @param options The dependencies for the entity storage service.
|
265
|
-
* @param options.config The configuration for the service.
|
266
|
-
* @param options.entityStorageType The entity storage type.
|
267
260
|
*/
|
268
261
|
constructor(options) {
|
269
262
|
Guards.string(this.CLASS_NAME, "options.entityStorageType", options.entityStorageType);
|
270
263
|
this._entityStorage = EntityStorageConnectorFactory.get(options.entityStorageType);
|
271
264
|
this._includeNodeIdentity = options.config?.includeNodeIdentity ?? true;
|
272
265
|
this._includeUserIdentity = options.config?.includeUserIdentity ?? true;
|
273
|
-
this._primaryKey = EntitySchemaHelper.getPrimaryKey(this._entityStorage.getSchema());
|
274
266
|
}
|
275
267
|
/**
|
276
268
|
* Set an entity.
|
@@ -341,7 +333,8 @@ class EntityStorageService {
|
|
341
333
|
/**
|
342
334
|
* Query all the entities which match the conditions.
|
343
335
|
* @param conditions The conditions to match for the entities.
|
344
|
-
* @param
|
336
|
+
* @param orderBy The order for the results.
|
337
|
+
* @param orderByDirection The direction for the order, defaults to ascending.
|
345
338
|
* @param properties The optional properties to return, defaults to all.
|
346
339
|
* @param cursor The cursor to request the next page of entities.
|
347
340
|
* @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
@@ -350,7 +343,7 @@ class EntityStorageService {
|
|
350
343
|
* @returns All the entities for the storage matching the conditions,
|
351
344
|
* and a cursor which can be used to request more entities.
|
352
345
|
*/
|
353
|
-
async query(conditions,
|
346
|
+
async query(conditions, orderBy, orderByDirection, properties, cursor, pageSize, userIdentity, nodeIdentity) {
|
354
347
|
const finalConditions = {
|
355
348
|
conditions: [],
|
356
349
|
logicalOperator: LogicalOperator.And
|
@@ -374,7 +367,9 @@ class EntityStorageService {
|
|
374
367
|
if (!Is.empty(conditions)) {
|
375
368
|
finalConditions.conditions.push(conditions);
|
376
369
|
}
|
377
|
-
const result = await this._entityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined,
|
370
|
+
const result = await this._entityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, Is.stringValue(orderBy)
|
371
|
+
? [{ property: orderBy, sortDirection: orderByDirection ?? SortDirection.Ascending }]
|
372
|
+
: undefined, properties, cursor, pageSize);
|
378
373
|
for (const entity of result.entities) {
|
379
374
|
ObjectHelper.propertyDelete(entity, "nodeIdentity");
|
380
375
|
ObjectHelper.propertyDelete(entity, "userIdentity");
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { type
|
1
|
+
import { type EntityCondition, SortDirection } from "@twin.org/entity";
|
2
2
|
import { type IEntityStorageComponent } from "@twin.org/entity-storage-models";
|
3
|
-
import type {
|
3
|
+
import type { IEntityStorageServiceConstructorOptions } from "./models/IEntityStorageServiceConstructorOptions";
|
4
4
|
/**
|
5
5
|
* Class for performing entity service operations.
|
6
6
|
*/
|
@@ -12,13 +12,8 @@ export declare class EntityStorageService<T = any> implements IEntityStorageComp
|
|
12
12
|
/**
|
13
13
|
* Create a new instance of EntityStorageService.
|
14
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
15
|
*/
|
18
|
-
constructor(options:
|
19
|
-
entityStorageType: string;
|
20
|
-
config?: IEntityStorageConfig;
|
21
|
-
});
|
16
|
+
constructor(options: IEntityStorageServiceConstructorOptions);
|
22
17
|
/**
|
23
18
|
* Set an entity.
|
24
19
|
* @param entity The entity to set.
|
@@ -47,7 +42,8 @@ export declare class EntityStorageService<T = any> implements IEntityStorageComp
|
|
47
42
|
/**
|
48
43
|
* Query all the entities which match the conditions.
|
49
44
|
* @param conditions The conditions to match for the entities.
|
50
|
-
* @param
|
45
|
+
* @param orderBy The order for the results.
|
46
|
+
* @param orderByDirection The direction for the order, defaults to ascending.
|
51
47
|
* @param properties The optional properties to return, defaults to all.
|
52
48
|
* @param cursor The cursor to request the next page of entities.
|
53
49
|
* @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
@@ -56,10 +52,7 @@ export declare class EntityStorageService<T = any> implements IEntityStorageComp
|
|
56
52
|
* @returns All the entities for the storage matching the conditions,
|
57
53
|
* and a cursor which can be used to request more entities.
|
58
54
|
*/
|
59
|
-
query(conditions?: EntityCondition<T>,
|
60
|
-
property: keyof T;
|
61
|
-
sortDirection: SortDirection;
|
62
|
-
}[], properties?: (keyof T)[], cursor?: string, pageSize?: number, userIdentity?: string, nodeIdentity?: string): Promise<{
|
55
|
+
query(conditions?: EntityCondition<T>, orderBy?: keyof T, orderByDirection?: SortDirection, properties?: (keyof T)[], cursor?: string, pageSize?: number, userIdentity?: string, nodeIdentity?: string): Promise<{
|
63
56
|
/**
|
64
57
|
* The entities, which can be partial if a limited keys list was provided.
|
65
58
|
*/
|
package/dist/types/index.d.ts
CHANGED
@@ -2,4 +2,5 @@ export * from "./entityStorageRoutes";
|
|
2
2
|
export * from "./entityStorageService";
|
3
3
|
export * from "./models/IEntityStorageConfig";
|
4
4
|
export * from "./models/IEntityStorageRoutesExamples";
|
5
|
+
export * from "./models/IEntityStorageServiceConstructorOptions";
|
5
6
|
export * from "./restEntryPoints";
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { IEntityStorageConfig } from "./IEntityStorageConfig";
|
2
|
+
/**
|
3
|
+
* Options for the Entity Storage Service constructor.
|
4
|
+
*/
|
5
|
+
export interface IEntityStorageServiceConstructorOptions {
|
6
|
+
/**
|
7
|
+
* The type of the entity storage.
|
8
|
+
*/
|
9
|
+
entityStorageType: string;
|
10
|
+
/**
|
11
|
+
* The configuration for the service.
|
12
|
+
*/
|
13
|
+
config?: IEntityStorageConfig;
|
14
|
+
}
|
package/docs/changelog.md
CHANGED
@@ -1,5 +1,132 @@
|
|
1
1
|
# @twin.org/entity-storage-service - Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## [0.0.2-next.1](https://github.com/twinfoundation/entity-storage/compare/entity-storage-service-v0.0.2-next.0...entity-storage-service-v0.0.2-next.1) (2025-07-17)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* add production release automation ([1eb4c8e](https://github.com/twinfoundation/entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
9
|
+
* update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
10
|
+
* use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
16
|
+
|
17
|
+
|
18
|
+
### Dependencies
|
19
|
+
|
20
|
+
* The following workspace dependencies were updated
|
21
|
+
* dependencies
|
22
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.0 to 0.0.2-next.1
|
23
|
+
* devDependencies
|
24
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.0 to 0.0.2-next.1
|
25
|
+
|
26
|
+
## 0.0.1 (2025-07-04)
|
27
|
+
|
28
|
+
|
29
|
+
### Features
|
30
|
+
|
31
|
+
* add production release automation ([1eb4c8e](https://github.com/twinfoundation/entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
32
|
+
* release to production ([a309051](https://github.com/twinfoundation/entity-storage/commit/a3090519adebf7943232b4df12e4c6bd5afe7eed))
|
33
|
+
* update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
34
|
+
* use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
35
|
+
|
36
|
+
|
37
|
+
### Bug Fixes
|
38
|
+
|
39
|
+
* query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
40
|
+
|
41
|
+
|
42
|
+
### Dependencies
|
43
|
+
|
44
|
+
* The following workspace dependencies were updated
|
45
|
+
* dependencies
|
46
|
+
* @twin.org/entity-storage-models bumped from ^0.0.0 to ^0.0.1
|
47
|
+
* devDependencies
|
48
|
+
* @twin.org/entity-storage-connector-memory bumped from ^0.0.0 to ^0.0.1
|
49
|
+
|
50
|
+
## [0.0.1-next.31](https://github.com/twinfoundation/entity-storage/compare/entity-storage-service-v0.0.1-next.30...entity-storage-service-v0.0.1-next.31) (2025-06-20)
|
51
|
+
|
52
|
+
|
53
|
+
### Bug Fixes
|
54
|
+
|
55
|
+
* query params force coercion ([dd6aa87](https://github.com/twinfoundation/entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
56
|
+
|
57
|
+
|
58
|
+
### Dependencies
|
59
|
+
|
60
|
+
* The following workspace dependencies were updated
|
61
|
+
* dependencies
|
62
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
|
63
|
+
* devDependencies
|
64
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.30 to 0.0.1-next.31
|
65
|
+
|
66
|
+
## [0.0.1-next.30](https://github.com/twinfoundation/entity-storage/compare/entity-storage-service-v0.0.1-next.29...entity-storage-service-v0.0.1-next.30) (2025-06-12)
|
67
|
+
|
68
|
+
|
69
|
+
### Features
|
70
|
+
|
71
|
+
* update dependencies ([7ccc0c4](https://github.com/twinfoundation/entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
72
|
+
|
73
|
+
|
74
|
+
### Dependencies
|
75
|
+
|
76
|
+
* The following workspace dependencies were updated
|
77
|
+
* dependencies
|
78
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
|
79
|
+
* devDependencies
|
80
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.29 to 0.0.1-next.30
|
81
|
+
|
82
|
+
## [0.0.1-next.29](https://github.com/twinfoundation/entity-storage/compare/entity-storage-service-v0.0.1-next.28...entity-storage-service-v0.0.1-next.29) (2025-04-17)
|
83
|
+
|
84
|
+
|
85
|
+
### Features
|
86
|
+
|
87
|
+
* use shared store mechanism ([#34](https://github.com/twinfoundation/entity-storage/issues/34)) ([68b6b71](https://github.com/twinfoundation/entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
88
|
+
|
89
|
+
|
90
|
+
### Dependencies
|
91
|
+
|
92
|
+
* The following workspace dependencies were updated
|
93
|
+
* dependencies
|
94
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.28 to 0.0.1-next.29
|
95
|
+
* devDependencies
|
96
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.28 to 0.0.1-next.29
|
97
|
+
|
98
|
+
## [0.0.1-next.28](https://github.com/twinfoundation/entity-storage/compare/entity-storage-service-v0.0.1-next.27...entity-storage-service-v0.0.1-next.28) (2025-04-09)
|
99
|
+
|
100
|
+
|
101
|
+
### Miscellaneous Chores
|
102
|
+
|
103
|
+
* **entity-storage-service:** Synchronize repo versions
|
104
|
+
|
105
|
+
|
106
|
+
### Dependencies
|
107
|
+
|
108
|
+
* The following workspace dependencies were updated
|
109
|
+
* dependencies
|
110
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.27 to 0.0.1-next.28
|
111
|
+
* devDependencies
|
112
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.27 to 0.0.1-next.28
|
113
|
+
|
114
|
+
## [0.0.1-next.27](https://github.com/twinfoundation/entity-storage/compare/entity-storage-service-v0.0.1-next.26...entity-storage-service-v0.0.1-next.27) (2025-03-28)
|
115
|
+
|
116
|
+
|
117
|
+
### Miscellaneous Chores
|
118
|
+
|
119
|
+
* **entity-storage-service:** Synchronize repo versions
|
120
|
+
|
121
|
+
|
122
|
+
### Dependencies
|
123
|
+
|
124
|
+
* The following workspace dependencies were updated
|
125
|
+
* dependencies
|
126
|
+
* @twin.org/entity-storage-models bumped from 0.0.1-next.26 to 0.0.1-next.27
|
127
|
+
* devDependencies
|
128
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.1-next.26 to 0.0.1-next.27
|
129
|
+
|
130
|
+
## v0.0.1-next.26
|
4
131
|
|
5
132
|
- Initial Release
|