@twin.org/entity-storage-rest-client 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.
- package/README.md +2 -2
- package/dist/{esm/index.mjs → es/entityStorageRestClient.js} +59 -17
- package/dist/es/entityStorageRestClient.js.map +1 -0
- package/dist/es/index.js +4 -0
- package/dist/es/index.js.map +1 -0
- package/dist/types/{entityStorageClient.d.ts → entityStorageRestClient.d.ts} +33 -6
- package/dist/types/index.d.ts +1 -1
- package/docs/changelog.md +194 -29
- package/docs/examples.md +60 -1
- package/docs/reference/classes/{EntityStorageClient.md → EntityStorageRestClient.md} +119 -17
- package/docs/reference/index.md +1 -1
- package/package.json +13 -11
- package/dist/cjs/index.cjs +0 -95
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entity Storage REST Client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides a client layer for calling storage service endpoints through a consistent REST interface. 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
|
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import { BaseRestClient } from '@twin.org/api-core';
|
|
2
|
-
import { HttpParameterHelper } from '@twin.org/api-models';
|
|
3
|
-
import { Guards } from '@twin.org/core';
|
|
4
|
-
|
|
5
1
|
// Copyright 2024 IOTA Stiftung.
|
|
6
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseRestClient } from "@twin.org/api-core";
|
|
4
|
+
import { HttpParameterHelper } from "@twin.org/api-models";
|
|
5
|
+
import { Coerce, Guards } from "@twin.org/core";
|
|
7
6
|
/**
|
|
8
7
|
* Client for performing entity storage through to REST endpoints.
|
|
9
8
|
*/
|
|
10
|
-
class
|
|
9
|
+
export class EntityStorageRestClient extends BaseRestClient {
|
|
11
10
|
/**
|
|
12
11
|
* Runtime name for the class.
|
|
13
12
|
*/
|
|
14
|
-
CLASS_NAME = "
|
|
13
|
+
static CLASS_NAME = "EntityStorageRestClient";
|
|
15
14
|
/**
|
|
16
|
-
* Create a new instance of
|
|
15
|
+
* Create a new instance of EntityStorageRestClient.
|
|
17
16
|
* @param config The configuration for the client.
|
|
18
17
|
*/
|
|
19
18
|
constructor(config) {
|
|
20
|
-
super("
|
|
19
|
+
super("EntityStorageRestClient", config, "entity-storage");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the class name of the component.
|
|
23
|
+
* @returns The class name of the component.
|
|
24
|
+
*/
|
|
25
|
+
className() {
|
|
26
|
+
return EntityStorageRestClient.CLASS_NAME;
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
29
|
* Set an entity.
|
|
@@ -25,11 +31,22 @@ class EntityStorageClient extends BaseRestClient {
|
|
|
25
31
|
* @returns The id of the entity.
|
|
26
32
|
*/
|
|
27
33
|
async set(entity) {
|
|
28
|
-
Guards.object(
|
|
34
|
+
Guards.object(EntityStorageRestClient.CLASS_NAME, "entity", entity);
|
|
29
35
|
await this.fetch("/", "POST", {
|
|
30
36
|
body: entity
|
|
31
37
|
});
|
|
32
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Set multiple entities in a batch.
|
|
41
|
+
* @param entities The entities to set.
|
|
42
|
+
* @returns Nothing.
|
|
43
|
+
*/
|
|
44
|
+
async setBatch(entities) {
|
|
45
|
+
Guards.arrayValue(EntityStorageRestClient.CLASS_NAME, "entities", entities);
|
|
46
|
+
await this.fetch("/batch", "POST", {
|
|
47
|
+
body: entities
|
|
48
|
+
});
|
|
49
|
+
}
|
|
33
50
|
/**
|
|
34
51
|
* Get an entity.
|
|
35
52
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
@@ -37,7 +54,7 @@ class EntityStorageClient extends BaseRestClient {
|
|
|
37
54
|
* @returns The object if it can be found or undefined.
|
|
38
55
|
*/
|
|
39
56
|
async get(id, secondaryIndex) {
|
|
40
|
-
Guards.stringValue(
|
|
57
|
+
Guards.stringValue(EntityStorageRestClient.CLASS_NAME, "id", id);
|
|
41
58
|
const response = await this.fetch("/:id", "GET", {
|
|
42
59
|
pathParams: {
|
|
43
60
|
id
|
|
@@ -54,32 +71,58 @@ class EntityStorageClient extends BaseRestClient {
|
|
|
54
71
|
* @returns Nothing.
|
|
55
72
|
*/
|
|
56
73
|
async remove(id) {
|
|
57
|
-
Guards.stringValue(
|
|
74
|
+
Guards.stringValue(EntityStorageRestClient.CLASS_NAME, "id", id);
|
|
58
75
|
await this.fetch("/:id", "DELETE", {
|
|
59
76
|
pathParams: {
|
|
60
77
|
id
|
|
61
78
|
}
|
|
62
79
|
});
|
|
63
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Remove multiple entities by id.
|
|
83
|
+
* @param ids The ids of the entities to remove.
|
|
84
|
+
* @returns Nothing.
|
|
85
|
+
*/
|
|
86
|
+
async removeBatch(ids) {
|
|
87
|
+
Guards.arrayValue(EntityStorageRestClient.CLASS_NAME, "ids", ids);
|
|
88
|
+
await this.fetch("/batch", "DELETE", {
|
|
89
|
+
body: ids
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Remove all entities from the storage.
|
|
94
|
+
* @returns Nothing.
|
|
95
|
+
*/
|
|
96
|
+
async empty() {
|
|
97
|
+
await this.fetch("/", "DELETE", {});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Count all the entities which match the conditions.
|
|
101
|
+
* @returns The total count of entities in the storage.
|
|
102
|
+
*/
|
|
103
|
+
async count() {
|
|
104
|
+
const result = await this.fetch("/count", "GET", {});
|
|
105
|
+
return result.body.count;
|
|
106
|
+
}
|
|
64
107
|
/**
|
|
65
108
|
* Query all the entities which match the conditions.
|
|
66
109
|
* @param conditions The conditions to match for the entities.
|
|
67
110
|
* @param orderBy The order for the results.
|
|
68
111
|
* @param orderByDirection The direction for the order, defaults to ascending.
|
|
69
112
|
* @param properties The optional properties to return, defaults to all.
|
|
70
|
-
* @param cursor The cursor to request the next
|
|
71
|
-
* @param
|
|
113
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
114
|
+
* @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
72
115
|
* @returns All the entities for the storage matching the conditions,
|
|
73
116
|
* and a cursor which can be used to request more entities.
|
|
74
117
|
*/
|
|
75
|
-
async query(conditions, orderBy, orderByDirection, properties, cursor,
|
|
118
|
+
async query(conditions, orderBy, orderByDirection, properties, cursor, limit) {
|
|
76
119
|
const result = await this.fetch("/", "GET", {
|
|
77
120
|
query: {
|
|
78
121
|
conditions: HttpParameterHelper.objectToString(conditions),
|
|
79
122
|
orderBy: orderBy,
|
|
80
123
|
orderByDirection,
|
|
81
124
|
properties: HttpParameterHelper.arrayToString(properties),
|
|
82
|
-
|
|
125
|
+
limit: Coerce.string(limit),
|
|
83
126
|
cursor
|
|
84
127
|
}
|
|
85
128
|
});
|
|
@@ -89,5 +132,4 @@ class EntityStorageClient extends BaseRestClient {
|
|
|
89
132
|
};
|
|
90
133
|
}
|
|
91
134
|
}
|
|
92
|
-
|
|
93
|
-
export { EntityStorageClient };
|
|
135
|
+
//# sourceMappingURL=entityStorageRestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityStorageRestClient.js","sourceRoot":"","sources":["../../src/entityStorageRestClient.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport {\n\tHttpParameterHelper,\n\ttype IBaseRestClientConfig,\n\ttype INoContentResponse\n} from \"@twin.org/api-models\";\nimport { Coerce, Guards } from \"@twin.org/core\";\nimport type { EntityCondition, SortDirection } from \"@twin.org/entity\";\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\";\n\n/**\n * Client for performing entity storage through to REST endpoints.\n */\nexport class EntityStorageRestClient<T>\n\textends BaseRestClient\n\timplements IEntityStorageComponent<T>\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EntityStorageRestClient<unknown>>();\n\n\t/**\n\t * Create a new instance of EntityStorageRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<EntityStorageRestClient<T>>(), config, \"entity-storage\");\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 EntityStorageRestClient.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(EntityStorageRestClient.CLASS_NAME, nameof(entity), entity);\n\n\t\tawait this.fetch<IEntityStorageSetRequest, INoContentResponse>(\"/\", \"POST\", {\n\t\t\tbody: entity\n\t\t});\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(EntityStorageRestClient.CLASS_NAME, nameof(entities), entities);\n\n\t\tawait this.fetch<IEntityStorageSetBatchRequest, INoContentResponse>(\"/batch\", \"POST\", {\n\t\t\tbody: entities as unknown[]\n\t\t});\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(EntityStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<IEntityStorageGetRequest, IEntityStorageGetResponse>(\n\t\t\t\"/:id\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\tsecondaryIndex: secondaryIndex as string\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body as T;\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(EntityStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IEntityStorageRemoveRequest, INoContentResponse>(\"/:id\", \"DELETE\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t}\n\t\t});\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(EntityStorageRestClient.CLASS_NAME, nameof(ids), ids);\n\n\t\tawait this.fetch<IEntityStorageRemoveBatchRequest, INoContentResponse>(\"/batch\", \"DELETE\", {\n\t\t\tbody: ids\n\t\t});\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\tawait this.fetch<IEntityStorageEmptyRequest, INoContentResponse>(\"/\", \"DELETE\", {});\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\tconst result = await this.fetch<IEntityStorageCountRequest, IEntityStorageCountResponse>(\n\t\t\t\"/count\",\n\t\t\t\"GET\",\n\t\t\t{}\n\t\t);\n\t\treturn result.body.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.fetch<IEntityStorageListRequest, IEntityStorageListResponse>(\n\t\t\t\"/\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\tquery: {\n\t\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions),\n\t\t\t\t\torderBy: orderBy as string,\n\t\t\t\t\torderByDirection,\n\t\t\t\t\tproperties: HttpParameterHelper.arrayToString(properties),\n\t\t\t\t\tlimit: Coerce.string(limit),\n\t\t\t\t\tcursor\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn {\n\t\t\tentities: result.body.entities as Partial<T>[],\n\t\t\tcursor: result.body.cursor\n\t\t};\n\t}\n}\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,8BAA8B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./entityStorageRestClient.js\";\n"]}
|
|
@@ -5,22 +5,33 @@ import type { IEntityStorageComponent } from "@twin.org/entity-storage-models";
|
|
|
5
5
|
/**
|
|
6
6
|
* Client for performing entity storage through to REST endpoints.
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class EntityStorageRestClient<T> extends BaseRestClient implements IEntityStorageComponent<T> {
|
|
9
9
|
/**
|
|
10
10
|
* Runtime name for the class.
|
|
11
11
|
*/
|
|
12
|
-
readonly CLASS_NAME: string;
|
|
12
|
+
static readonly CLASS_NAME: string;
|
|
13
13
|
/**
|
|
14
|
-
* Create a new instance of
|
|
14
|
+
* Create a new instance of EntityStorageRestClient.
|
|
15
15
|
* @param config The configuration for the client.
|
|
16
16
|
*/
|
|
17
17
|
constructor(config: IBaseRestClientConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Returns the class name of the component.
|
|
20
|
+
* @returns The class name of the component.
|
|
21
|
+
*/
|
|
22
|
+
className(): string;
|
|
18
23
|
/**
|
|
19
24
|
* Set an entity.
|
|
20
25
|
* @param entity The entity to set.
|
|
21
26
|
* @returns The id of the entity.
|
|
22
27
|
*/
|
|
23
28
|
set(entity: T): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Set multiple entities in a batch.
|
|
31
|
+
* @param entities The entities to set.
|
|
32
|
+
* @returns Nothing.
|
|
33
|
+
*/
|
|
34
|
+
setBatch(entities: T[]): Promise<void>;
|
|
24
35
|
/**
|
|
25
36
|
* Get an entity.
|
|
26
37
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
@@ -34,18 +45,34 @@ export declare class EntityStorageClient<T> extends BaseRestClient implements IE
|
|
|
34
45
|
* @returns Nothing.
|
|
35
46
|
*/
|
|
36
47
|
remove(id: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Remove multiple entities by id.
|
|
50
|
+
* @param ids The ids of the entities to remove.
|
|
51
|
+
* @returns Nothing.
|
|
52
|
+
*/
|
|
53
|
+
removeBatch(ids: string[]): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Remove all entities from the storage.
|
|
56
|
+
* @returns Nothing.
|
|
57
|
+
*/
|
|
58
|
+
empty(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Count all the entities which match the conditions.
|
|
61
|
+
* @returns The total count of entities in the storage.
|
|
62
|
+
*/
|
|
63
|
+
count(): Promise<number>;
|
|
37
64
|
/**
|
|
38
65
|
* Query all the entities which match the conditions.
|
|
39
66
|
* @param conditions The conditions to match for the entities.
|
|
40
67
|
* @param orderBy The order for the results.
|
|
41
68
|
* @param orderByDirection The direction for the order, defaults to ascending.
|
|
42
69
|
* @param properties The optional properties to return, defaults to all.
|
|
43
|
-
* @param cursor The cursor to request the next
|
|
44
|
-
* @param
|
|
70
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
71
|
+
* @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
45
72
|
* @returns All the entities for the storage matching the conditions,
|
|
46
73
|
* and a cursor which can be used to request more entities.
|
|
47
74
|
*/
|
|
48
|
-
query(conditions?: EntityCondition<T>, orderBy?: keyof T, orderByDirection?: SortDirection, properties?: (keyof T)[], cursor?: string,
|
|
75
|
+
query(conditions?: EntityCondition<T>, orderBy?: keyof T, orderByDirection?: SortDirection, properties?: (keyof T)[], cursor?: string, limit?: number): Promise<{
|
|
49
76
|
/**
|
|
50
77
|
* The entities, which can be partial if a limited keys list was provided.
|
|
51
78
|
*/
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./entityStorageRestClient.js";
|
package/docs/changelog.md
CHANGED
|
@@ -1,6 +1,171 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.0.
|
|
3
|
+
## [0.0.3-next.10](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.9...entity-storage-rest-client-v0.0.3-next.10) (2026-05-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* entity storage enhancements ([#86](https://github.com/iotaledger/twin-entity-storage/issues/86)) ([1279af4](https://github.com/iotaledger/twin-entity-storage/commit/1279af42615c6497bb06539842cee44842dd1f75))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.9 to 0.0.3-next.10
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.9](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.8...entity-storage-rest-client-v0.0.3-next.9) (2026-04-22)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Miscellaneous Chores
|
|
21
|
+
|
|
22
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.8 to 0.0.3-next.9
|
|
30
|
+
|
|
31
|
+
## [0.0.3-next.8](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.7...entity-storage-rest-client-v0.0.3-next.8) (2026-03-20)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Miscellaneous Chores
|
|
35
|
+
|
|
36
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Dependencies
|
|
40
|
+
|
|
41
|
+
* The following workspace dependencies were updated
|
|
42
|
+
* dependencies
|
|
43
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.7 to 0.0.3-next.8
|
|
44
|
+
|
|
45
|
+
## [0.0.3-next.7](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.6...entity-storage-rest-client-v0.0.3-next.7) (2026-03-13)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Miscellaneous Chores
|
|
49
|
+
|
|
50
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Dependencies
|
|
54
|
+
|
|
55
|
+
* The following workspace dependencies were updated
|
|
56
|
+
* dependencies
|
|
57
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
58
|
+
|
|
59
|
+
## [0.0.3-next.6](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.5...entity-storage-rest-client-v0.0.3-next.6) (2026-01-21)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Miscellaneous Chores
|
|
63
|
+
|
|
64
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Dependencies
|
|
68
|
+
|
|
69
|
+
* The following workspace dependencies were updated
|
|
70
|
+
* dependencies
|
|
71
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.5 to 0.0.3-next.6
|
|
72
|
+
|
|
73
|
+
## [0.0.3-next.5](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.4...entity-storage-rest-client-v0.0.3-next.5) (2026-01-06)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Miscellaneous Chores
|
|
77
|
+
|
|
78
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Dependencies
|
|
82
|
+
|
|
83
|
+
* The following workspace dependencies were updated
|
|
84
|
+
* dependencies
|
|
85
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.4 to 0.0.3-next.5
|
|
86
|
+
|
|
87
|
+
## [0.0.3-next.4](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.3...entity-storage-rest-client-v0.0.3-next.4) (2025-12-03)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### Miscellaneous Chores
|
|
91
|
+
|
|
92
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Dependencies
|
|
96
|
+
|
|
97
|
+
* The following workspace dependencies were updated
|
|
98
|
+
* dependencies
|
|
99
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.3 to 0.0.3-next.4
|
|
100
|
+
|
|
101
|
+
## [0.0.3-next.3](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.2...entity-storage-rest-client-v0.0.3-next.3) (2025-11-26)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Miscellaneous Chores
|
|
105
|
+
|
|
106
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Dependencies
|
|
110
|
+
|
|
111
|
+
* The following workspace dependencies were updated
|
|
112
|
+
* dependencies
|
|
113
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.2 to 0.0.3-next.3
|
|
114
|
+
|
|
115
|
+
## [0.0.3-next.2](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.1...entity-storage-rest-client-v0.0.3-next.2) (2025-11-13)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### Miscellaneous Chores
|
|
119
|
+
|
|
120
|
+
* **entity-storage-rest-client:** Synchronize repo versions
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### Dependencies
|
|
124
|
+
|
|
125
|
+
* The following workspace dependencies were updated
|
|
126
|
+
* dependencies
|
|
127
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
128
|
+
|
|
129
|
+
## [0.0.3-next.1](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.3-next.0...entity-storage-rest-client-v0.0.3-next.1) (2025-11-10)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
### Features
|
|
133
|
+
|
|
134
|
+
* add context id features ([#55](https://github.com/iotaledger/twin-entity-storage/issues/55)) ([99c15a2](https://github.com/iotaledger/twin-entity-storage/commit/99c15a257539b61d9da63649ce573ebf47699fc9))
|
|
135
|
+
* add production release automation ([1eb4c8e](https://github.com/iotaledger/twin-entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
|
136
|
+
* add validate-locales ([e66ef0d](https://github.com/iotaledger/twin-entity-storage/commit/e66ef0de26ca2f82b3fe89bb5c7a15a0978a9644))
|
|
137
|
+
* eslint migration to flat config ([f033b64](https://github.com/iotaledger/twin-entity-storage/commit/f033b64984c0e6a8129d929c9dd816dcc1b8dab0))
|
|
138
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
139
|
+
* update framework core ([b59a380](https://github.com/iotaledger/twin-entity-storage/commit/b59a380bb7fba2b43610f69074dcdee24a4737da))
|
|
140
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### Bug Fixes
|
|
144
|
+
|
|
145
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### Dependencies
|
|
149
|
+
|
|
150
|
+
* The following workspace dependencies were updated
|
|
151
|
+
* dependencies
|
|
152
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
153
|
+
|
|
154
|
+
## [0.0.2-next.10](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.9...entity-storage-rest-client-v0.0.2-next.10) (2025-10-09)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
### Features
|
|
158
|
+
|
|
159
|
+
* add validate-locales ([e66ef0d](https://github.com/iotaledger/twin-entity-storage/commit/e66ef0de26ca2f82b3fe89bb5c7a15a0978a9644))
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
### Dependencies
|
|
163
|
+
|
|
164
|
+
* The following workspace dependencies were updated
|
|
165
|
+
* dependencies
|
|
166
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
167
|
+
|
|
168
|
+
## [0.0.2-next.9](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.8...entity-storage-rest-client-v0.0.2-next.9) (2025-10-02)
|
|
4
169
|
|
|
5
170
|
|
|
6
171
|
### Miscellaneous Chores
|
|
@@ -14,12 +179,12 @@
|
|
|
14
179
|
* dependencies
|
|
15
180
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
16
181
|
|
|
17
|
-
## [0.0.2-next.8](https://github.com/
|
|
182
|
+
## [0.0.2-next.8](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.7...entity-storage-rest-client-v0.0.2-next.8) (2025-08-29)
|
|
18
183
|
|
|
19
184
|
|
|
20
185
|
### Features
|
|
21
186
|
|
|
22
|
-
* eslint migration to flat config ([f033b64](https://github.com/
|
|
187
|
+
* eslint migration to flat config ([f033b64](https://github.com/iotaledger/twin-entity-storage/commit/f033b64984c0e6a8129d929c9dd816dcc1b8dab0))
|
|
23
188
|
|
|
24
189
|
|
|
25
190
|
### Dependencies
|
|
@@ -28,7 +193,7 @@
|
|
|
28
193
|
* dependencies
|
|
29
194
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
30
195
|
|
|
31
|
-
## [0.0.2-next.7](https://github.com/
|
|
196
|
+
## [0.0.2-next.7](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.6...entity-storage-rest-client-v0.0.2-next.7) (2025-08-20)
|
|
32
197
|
|
|
33
198
|
|
|
34
199
|
### Miscellaneous Chores
|
|
@@ -42,12 +207,12 @@
|
|
|
42
207
|
* dependencies
|
|
43
208
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
44
209
|
|
|
45
|
-
## [0.0.2-next.6](https://github.com/
|
|
210
|
+
## [0.0.2-next.6](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.5...entity-storage-rest-client-v0.0.2-next.6) (2025-08-19)
|
|
46
211
|
|
|
47
212
|
|
|
48
213
|
### Features
|
|
49
214
|
|
|
50
|
-
* update framework core ([b59a380](https://github.com/
|
|
215
|
+
* update framework core ([b59a380](https://github.com/iotaledger/twin-entity-storage/commit/b59a380bb7fba2b43610f69074dcdee24a4737da))
|
|
51
216
|
|
|
52
217
|
|
|
53
218
|
### Dependencies
|
|
@@ -56,7 +221,7 @@
|
|
|
56
221
|
* dependencies
|
|
57
222
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
58
223
|
|
|
59
|
-
## [0.0.2-next.5](https://github.com/
|
|
224
|
+
## [0.0.2-next.5](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.4...entity-storage-rest-client-v0.0.2-next.5) (2025-08-11)
|
|
60
225
|
|
|
61
226
|
|
|
62
227
|
### Miscellaneous Chores
|
|
@@ -70,7 +235,7 @@
|
|
|
70
235
|
* dependencies
|
|
71
236
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
72
237
|
|
|
73
|
-
## [0.0.2-next.4](https://github.com/
|
|
238
|
+
## [0.0.2-next.4](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.3...entity-storage-rest-client-v0.0.2-next.4) (2025-08-08)
|
|
74
239
|
|
|
75
240
|
|
|
76
241
|
### Miscellaneous Chores
|
|
@@ -84,7 +249,7 @@
|
|
|
84
249
|
* dependencies
|
|
85
250
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
86
251
|
|
|
87
|
-
## [0.0.2-next.3](https://github.com/
|
|
252
|
+
## [0.0.2-next.3](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.2...entity-storage-rest-client-v0.0.2-next.3) (2025-07-25)
|
|
88
253
|
|
|
89
254
|
|
|
90
255
|
### Miscellaneous Chores
|
|
@@ -98,7 +263,7 @@
|
|
|
98
263
|
* dependencies
|
|
99
264
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
100
265
|
|
|
101
|
-
## [0.0.2-next.2](https://github.com/
|
|
266
|
+
## [0.0.2-next.2](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.1...entity-storage-rest-client-v0.0.2-next.2) (2025-07-24)
|
|
102
267
|
|
|
103
268
|
|
|
104
269
|
### Miscellaneous Chores
|
|
@@ -112,19 +277,19 @@
|
|
|
112
277
|
* dependencies
|
|
113
278
|
* @twin.org/entity-storage-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
114
279
|
|
|
115
|
-
## [0.0.2-next.1](https://github.com/
|
|
280
|
+
## [0.0.2-next.1](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.2-next.0...entity-storage-rest-client-v0.0.2-next.1) (2025-07-17)
|
|
116
281
|
|
|
117
282
|
|
|
118
283
|
### Features
|
|
119
284
|
|
|
120
|
-
* add production release automation ([1eb4c8e](https://github.com/
|
|
121
|
-
* update dependencies ([7ccc0c4](https://github.com/
|
|
122
|
-
* use shared store mechanism ([#34](https://github.com/
|
|
285
|
+
* add production release automation ([1eb4c8e](https://github.com/iotaledger/twin-entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
|
286
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
287
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
123
288
|
|
|
124
289
|
|
|
125
290
|
### Bug Fixes
|
|
126
291
|
|
|
127
|
-
* query params force coercion ([dd6aa87](https://github.com/
|
|
292
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
128
293
|
|
|
129
294
|
|
|
130
295
|
### Dependencies
|
|
@@ -138,15 +303,15 @@
|
|
|
138
303
|
|
|
139
304
|
### Features
|
|
140
305
|
|
|
141
|
-
* add production release automation ([1eb4c8e](https://github.com/
|
|
142
|
-
* release to production ([a309051](https://github.com/
|
|
143
|
-
* update dependencies ([7ccc0c4](https://github.com/
|
|
144
|
-
* use shared store mechanism ([#34](https://github.com/
|
|
306
|
+
* add production release automation ([1eb4c8e](https://github.com/iotaledger/twin-entity-storage/commit/1eb4c8ee3eb099defdfc2d063ae44935276dcae8))
|
|
307
|
+
* release to production ([a309051](https://github.com/iotaledger/twin-entity-storage/commit/a3090519adebf7943232b4df12e4c6bd5afe7eed))
|
|
308
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
309
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
145
310
|
|
|
146
311
|
|
|
147
312
|
### Bug Fixes
|
|
148
313
|
|
|
149
|
-
* query params force coercion ([dd6aa87](https://github.com/
|
|
314
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
150
315
|
|
|
151
316
|
|
|
152
317
|
### Dependencies
|
|
@@ -155,12 +320,12 @@
|
|
|
155
320
|
* dependencies
|
|
156
321
|
* @twin.org/entity-storage-models bumped from ^0.0.0 to ^0.0.1
|
|
157
322
|
|
|
158
|
-
## [0.0.1-next.31](https://github.com/
|
|
323
|
+
## [0.0.1-next.31](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.1-next.30...entity-storage-rest-client-v0.0.1-next.31) (2025-06-20)
|
|
159
324
|
|
|
160
325
|
|
|
161
326
|
### Bug Fixes
|
|
162
327
|
|
|
163
|
-
* query params force coercion ([dd6aa87](https://github.com/
|
|
328
|
+
* query params force coercion ([dd6aa87](https://github.com/iotaledger/twin-entity-storage/commit/dd6aa87efdfb60bab7d6756a86888863c45c51a7))
|
|
164
329
|
|
|
165
330
|
|
|
166
331
|
### Dependencies
|
|
@@ -169,12 +334,12 @@
|
|
|
169
334
|
* dependencies
|
|
170
335
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
|
|
171
336
|
|
|
172
|
-
## [0.0.1-next.30](https://github.com/
|
|
337
|
+
## [0.0.1-next.30](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.1-next.29...entity-storage-rest-client-v0.0.1-next.30) (2025-06-12)
|
|
173
338
|
|
|
174
339
|
|
|
175
340
|
### Features
|
|
176
341
|
|
|
177
|
-
* update dependencies ([7ccc0c4](https://github.com/
|
|
342
|
+
* update dependencies ([7ccc0c4](https://github.com/iotaledger/twin-entity-storage/commit/7ccc0c429125d073dc60b3de6cf101abc8cc6cba))
|
|
178
343
|
|
|
179
344
|
|
|
180
345
|
### Dependencies
|
|
@@ -183,12 +348,12 @@
|
|
|
183
348
|
* dependencies
|
|
184
349
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
|
|
185
350
|
|
|
186
|
-
## [0.0.1-next.29](https://github.com/
|
|
351
|
+
## [0.0.1-next.29](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.1-next.28...entity-storage-rest-client-v0.0.1-next.29) (2025-04-17)
|
|
187
352
|
|
|
188
353
|
|
|
189
354
|
### Features
|
|
190
355
|
|
|
191
|
-
* use shared store mechanism ([#34](https://github.com/
|
|
356
|
+
* use shared store mechanism ([#34](https://github.com/iotaledger/twin-entity-storage/issues/34)) ([68b6b71](https://github.com/iotaledger/twin-entity-storage/commit/68b6b71e7a96d7d016cd57bfff36775b56bf3f93))
|
|
192
357
|
|
|
193
358
|
|
|
194
359
|
### Dependencies
|
|
@@ -197,7 +362,7 @@
|
|
|
197
362
|
* dependencies
|
|
198
363
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.28 to 0.0.1-next.29
|
|
199
364
|
|
|
200
|
-
## [0.0.1-next.28](https://github.com/
|
|
365
|
+
## [0.0.1-next.28](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.1-next.27...entity-storage-rest-client-v0.0.1-next.28) (2025-04-09)
|
|
201
366
|
|
|
202
367
|
|
|
203
368
|
### Miscellaneous Chores
|
|
@@ -211,7 +376,7 @@
|
|
|
211
376
|
* dependencies
|
|
212
377
|
* @twin.org/entity-storage-models bumped from 0.0.1-next.27 to 0.0.1-next.28
|
|
213
378
|
|
|
214
|
-
## [0.0.1-next.27](https://github.com/
|
|
379
|
+
## [0.0.1-next.27](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.0.1-next.26...entity-storage-rest-client-v0.0.1-next.27) (2025-03-28)
|
|
215
380
|
|
|
216
381
|
|
|
217
382
|
### Miscellaneous Chores
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entity Storage REST Client Examples
|
|
2
|
+
|
|
3
|
+
These snippets show how to call the REST endpoints with typed payloads and how to shape filtered list requests.
|
|
4
|
+
|
|
5
|
+
## EntityStorageRestClient
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { EntityStorageRestClient } from '@twin.org/entity-storage-rest-client';
|
|
9
|
+
import {
|
|
10
|
+
ComparisonOperator,
|
|
11
|
+
LogicalOperator,
|
|
12
|
+
SortDirection,
|
|
13
|
+
type EntityCondition
|
|
14
|
+
} from '@twin.org/entity';
|
|
15
|
+
|
|
16
|
+
interface Profile {
|
|
17
|
+
id: string;
|
|
18
|
+
email: string;
|
|
19
|
+
status: 'active' | 'inactive';
|
|
20
|
+
createdAt: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const client = new EntityStorageRestClient<Profile>({
|
|
24
|
+
endpoint: 'http://localhost:8080'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const className = client.className();
|
|
28
|
+
|
|
29
|
+
await client.set({
|
|
30
|
+
id: 'profile-1',
|
|
31
|
+
email: 'ada@example.com',
|
|
32
|
+
status: 'active',
|
|
33
|
+
createdAt: '2026-03-09T10:30:00.000Z'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const byPrimaryKey = await client.get('profile-1');
|
|
37
|
+
const bySecondaryIndex = await client.get('ada@example.com', 'email');
|
|
38
|
+
|
|
39
|
+
const activeCondition: EntityCondition<Profile> = {
|
|
40
|
+
logicalOperator: LogicalOperator.And,
|
|
41
|
+
conditions: [
|
|
42
|
+
{
|
|
43
|
+
property: 'status',
|
|
44
|
+
comparison: ComparisonOperator.Equals,
|
|
45
|
+
value: 'active'
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const result = await client.query(
|
|
51
|
+
activeCondition,
|
|
52
|
+
'createdAt',
|
|
53
|
+
SortDirection.Descending,
|
|
54
|
+
['id', 'email', 'status'],
|
|
55
|
+
undefined,
|
|
56
|
+
25
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
await client.remove('profile-1');
|
|
60
|
+
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Class:
|
|
1
|
+
# Class: EntityStorageRestClient\<T\>
|
|
2
2
|
|
|
3
3
|
Client for performing entity storage through to REST endpoints.
|
|
4
4
|
|
|
@@ -20,9 +20,9 @@ Client for performing entity storage through to REST endpoints.
|
|
|
20
20
|
|
|
21
21
|
### Constructor
|
|
22
22
|
|
|
23
|
-
> **new
|
|
23
|
+
> **new EntityStorageRestClient**\<`T`\>(`config`): `EntityStorageRestClient`\<`T`\>
|
|
24
24
|
|
|
25
|
-
Create a new instance of
|
|
25
|
+
Create a new instance of EntityStorageRestClient.
|
|
26
26
|
|
|
27
27
|
#### Parameters
|
|
28
28
|
|
|
@@ -34,7 +34,7 @@ The configuration for the client.
|
|
|
34
34
|
|
|
35
35
|
#### Returns
|
|
36
36
|
|
|
37
|
-
`
|
|
37
|
+
`EntityStorageRestClient`\<`T`\>
|
|
38
38
|
|
|
39
39
|
#### Overrides
|
|
40
40
|
|
|
@@ -42,19 +42,33 @@ The configuration for the client.
|
|
|
42
42
|
|
|
43
43
|
## Properties
|
|
44
44
|
|
|
45
|
-
### CLASS\_NAME
|
|
45
|
+
### CLASS\_NAME {#class_name}
|
|
46
46
|
|
|
47
|
-
> `readonly` **CLASS\_NAME**: `string`
|
|
47
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
48
48
|
|
|
49
49
|
Runtime name for the class.
|
|
50
50
|
|
|
51
|
+
## Methods
|
|
52
|
+
|
|
53
|
+
### className() {#classname}
|
|
54
|
+
|
|
55
|
+
> **className**(): `string`
|
|
56
|
+
|
|
57
|
+
Returns the class name of the component.
|
|
58
|
+
|
|
59
|
+
#### Returns
|
|
60
|
+
|
|
61
|
+
`string`
|
|
62
|
+
|
|
63
|
+
The class name of the component.
|
|
64
|
+
|
|
51
65
|
#### Implementation of
|
|
52
66
|
|
|
53
|
-
`IEntityStorageComponent.
|
|
67
|
+
`IEntityStorageComponent.className`
|
|
54
68
|
|
|
55
|
-
|
|
69
|
+
***
|
|
56
70
|
|
|
57
|
-
### set()
|
|
71
|
+
### set() {#set}
|
|
58
72
|
|
|
59
73
|
> **set**(`entity`): `Promise`\<`void`\>
|
|
60
74
|
|
|
@@ -80,9 +94,35 @@ The id of the entity.
|
|
|
80
94
|
|
|
81
95
|
***
|
|
82
96
|
|
|
83
|
-
###
|
|
97
|
+
### setBatch() {#setbatch}
|
|
98
|
+
|
|
99
|
+
> **setBatch**(`entities`): `Promise`\<`void`\>
|
|
100
|
+
|
|
101
|
+
Set multiple entities in a batch.
|
|
102
|
+
|
|
103
|
+
#### Parameters
|
|
104
|
+
|
|
105
|
+
##### entities
|
|
106
|
+
|
|
107
|
+
`T`[]
|
|
108
|
+
|
|
109
|
+
The entities to set.
|
|
110
|
+
|
|
111
|
+
#### Returns
|
|
112
|
+
|
|
113
|
+
`Promise`\<`void`\>
|
|
114
|
+
|
|
115
|
+
Nothing.
|
|
116
|
+
|
|
117
|
+
#### Implementation of
|
|
118
|
+
|
|
119
|
+
`IEntityStorageComponent.setBatch`
|
|
120
|
+
|
|
121
|
+
***
|
|
122
|
+
|
|
123
|
+
### get() {#get}
|
|
84
124
|
|
|
85
|
-
> **get**(`id`, `secondaryIndex?`): `Promise`\<`
|
|
125
|
+
> **get**(`id`, `secondaryIndex?`): `Promise`\<`T` \| `undefined`\>
|
|
86
126
|
|
|
87
127
|
Get an entity.
|
|
88
128
|
|
|
@@ -102,7 +142,7 @@ Get the item using a secondary index.
|
|
|
102
142
|
|
|
103
143
|
#### Returns
|
|
104
144
|
|
|
105
|
-
`Promise`\<`
|
|
145
|
+
`Promise`\<`T` \| `undefined`\>
|
|
106
146
|
|
|
107
147
|
The object if it can be found or undefined.
|
|
108
148
|
|
|
@@ -112,7 +152,7 @@ The object if it can be found or undefined.
|
|
|
112
152
|
|
|
113
153
|
***
|
|
114
154
|
|
|
115
|
-
### remove()
|
|
155
|
+
### remove() {#remove}
|
|
116
156
|
|
|
117
157
|
> **remove**(`id`): `Promise`\<`void`\>
|
|
118
158
|
|
|
@@ -138,9 +178,71 @@ Nothing.
|
|
|
138
178
|
|
|
139
179
|
***
|
|
140
180
|
|
|
141
|
-
###
|
|
181
|
+
### removeBatch() {#removebatch}
|
|
182
|
+
|
|
183
|
+
> **removeBatch**(`ids`): `Promise`\<`void`\>
|
|
184
|
+
|
|
185
|
+
Remove multiple entities by id.
|
|
186
|
+
|
|
187
|
+
#### Parameters
|
|
188
|
+
|
|
189
|
+
##### ids
|
|
190
|
+
|
|
191
|
+
`string`[]
|
|
192
|
+
|
|
193
|
+
The ids of the entities to remove.
|
|
194
|
+
|
|
195
|
+
#### Returns
|
|
196
|
+
|
|
197
|
+
`Promise`\<`void`\>
|
|
198
|
+
|
|
199
|
+
Nothing.
|
|
200
|
+
|
|
201
|
+
#### Implementation of
|
|
202
|
+
|
|
203
|
+
`IEntityStorageComponent.removeBatch`
|
|
204
|
+
|
|
205
|
+
***
|
|
206
|
+
|
|
207
|
+
### empty() {#empty}
|
|
208
|
+
|
|
209
|
+
> **empty**(): `Promise`\<`void`\>
|
|
210
|
+
|
|
211
|
+
Remove all entities from the storage.
|
|
212
|
+
|
|
213
|
+
#### Returns
|
|
214
|
+
|
|
215
|
+
`Promise`\<`void`\>
|
|
216
|
+
|
|
217
|
+
Nothing.
|
|
218
|
+
|
|
219
|
+
#### Implementation of
|
|
220
|
+
|
|
221
|
+
`IEntityStorageComponent.empty`
|
|
222
|
+
|
|
223
|
+
***
|
|
224
|
+
|
|
225
|
+
### count() {#count}
|
|
226
|
+
|
|
227
|
+
> **count**(): `Promise`\<`number`\>
|
|
228
|
+
|
|
229
|
+
Count all the entities which match the conditions.
|
|
230
|
+
|
|
231
|
+
#### Returns
|
|
232
|
+
|
|
233
|
+
`Promise`\<`number`\>
|
|
234
|
+
|
|
235
|
+
The total count of entities in the storage.
|
|
236
|
+
|
|
237
|
+
#### Implementation of
|
|
238
|
+
|
|
239
|
+
`IEntityStorageComponent.count`
|
|
240
|
+
|
|
241
|
+
***
|
|
242
|
+
|
|
243
|
+
### query() {#query}
|
|
142
244
|
|
|
143
|
-
> **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `properties?`, `cursor?`, `
|
|
245
|
+
> **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
144
246
|
|
|
145
247
|
Query all the entities which match the conditions.
|
|
146
248
|
|
|
@@ -174,9 +276,9 @@ The optional properties to return, defaults to all.
|
|
|
174
276
|
|
|
175
277
|
`string`
|
|
176
278
|
|
|
177
|
-
The cursor to request the next
|
|
279
|
+
The cursor to request the next chunk of entities.
|
|
178
280
|
|
|
179
|
-
#####
|
|
281
|
+
##### limit?
|
|
180
282
|
|
|
181
283
|
`number`
|
|
182
284
|
|
package/docs/reference/index.md
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-rest-client",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.10",
|
|
4
|
+
"description": "REST client for calling storage services from applications and tools.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/entity-storage.git",
|
|
8
8
|
"directory": "packages/entity-storage-rest-client"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -18,24 +18,22 @@
|
|
|
18
18
|
"@twin.org/api-models": "next",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/entity": "next",
|
|
21
|
-
"@twin.org/entity-storage-models": "0.0.
|
|
21
|
+
"@twin.org/entity-storage-models": "0.0.3-next.10",
|
|
22
22
|
"@twin.org/nameof": "next",
|
|
23
23
|
"@twin.org/web": "next"
|
|
24
24
|
},
|
|
25
|
-
"main": "./dist/
|
|
26
|
-
"module": "./dist/esm/index.mjs",
|
|
25
|
+
"main": "./dist/es/index.js",
|
|
27
26
|
"types": "./dist/types/index.d.ts",
|
|
28
27
|
"exports": {
|
|
29
28
|
".": {
|
|
30
29
|
"types": "./dist/types/index.d.ts",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"import": "./dist/es/index.js",
|
|
31
|
+
"default": "./dist/es/index.js"
|
|
33
32
|
},
|
|
34
33
|
"./locales/*.json": "./locales/*.json"
|
|
35
34
|
},
|
|
36
35
|
"files": [
|
|
37
|
-
"dist/
|
|
38
|
-
"dist/esm",
|
|
36
|
+
"dist/es",
|
|
39
37
|
"dist/types",
|
|
40
38
|
"locales",
|
|
41
39
|
"docs"
|
|
@@ -51,5 +49,9 @@
|
|
|
51
49
|
"storage",
|
|
52
50
|
"persistence",
|
|
53
51
|
"database"
|
|
54
|
-
]
|
|
52
|
+
],
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "git+https://github.com/iotaledger/entity-storage/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://twindev.org"
|
|
55
57
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var apiCore = require('@twin.org/api-core');
|
|
4
|
-
var apiModels = require('@twin.org/api-models');
|
|
5
|
-
var core = require('@twin.org/core');
|
|
6
|
-
|
|
7
|
-
// Copyright 2024 IOTA Stiftung.
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
9
|
-
/**
|
|
10
|
-
* Client for performing entity storage through to REST endpoints.
|
|
11
|
-
*/
|
|
12
|
-
class EntityStorageClient extends apiCore.BaseRestClient {
|
|
13
|
-
/**
|
|
14
|
-
* Runtime name for the class.
|
|
15
|
-
*/
|
|
16
|
-
CLASS_NAME = "EntityStorageClient";
|
|
17
|
-
/**
|
|
18
|
-
* Create a new instance of EntityStorageClient.
|
|
19
|
-
* @param config The configuration for the client.
|
|
20
|
-
*/
|
|
21
|
-
constructor(config) {
|
|
22
|
-
super("EntityStorageClient", config, "entity-storage");
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Set an entity.
|
|
26
|
-
* @param entity The entity to set.
|
|
27
|
-
* @returns The id of the entity.
|
|
28
|
-
*/
|
|
29
|
-
async set(entity) {
|
|
30
|
-
core.Guards.object(this.CLASS_NAME, "entity", entity);
|
|
31
|
-
await this.fetch("/", "POST", {
|
|
32
|
-
body: entity
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Get an entity.
|
|
37
|
-
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
38
|
-
* @param secondaryIndex Get the item using a secondary index.
|
|
39
|
-
* @returns The object if it can be found or undefined.
|
|
40
|
-
*/
|
|
41
|
-
async get(id, secondaryIndex) {
|
|
42
|
-
core.Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
43
|
-
const response = await this.fetch("/:id", "GET", {
|
|
44
|
-
pathParams: {
|
|
45
|
-
id
|
|
46
|
-
},
|
|
47
|
-
query: {
|
|
48
|
-
secondaryIndex: secondaryIndex
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return response.body;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Remove the entity.
|
|
55
|
-
* @param id The id of the entity to remove.
|
|
56
|
-
* @returns Nothing.
|
|
57
|
-
*/
|
|
58
|
-
async remove(id) {
|
|
59
|
-
core.Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
60
|
-
await this.fetch("/:id", "DELETE", {
|
|
61
|
-
pathParams: {
|
|
62
|
-
id
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Query all the entities which match the conditions.
|
|
68
|
-
* @param conditions The conditions to match for the entities.
|
|
69
|
-
* @param orderBy The order for the results.
|
|
70
|
-
* @param orderByDirection The direction for the order, defaults to ascending.
|
|
71
|
-
* @param properties The optional properties to return, defaults to all.
|
|
72
|
-
* @param cursor The cursor to request the next page of entities.
|
|
73
|
-
* @param pageSize The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
74
|
-
* @returns All the entities for the storage matching the conditions,
|
|
75
|
-
* and a cursor which can be used to request more entities.
|
|
76
|
-
*/
|
|
77
|
-
async query(conditions, orderBy, orderByDirection, properties, cursor, pageSize) {
|
|
78
|
-
const result = await this.fetch("/", "GET", {
|
|
79
|
-
query: {
|
|
80
|
-
conditions: apiModels.HttpParameterHelper.objectToString(conditions),
|
|
81
|
-
orderBy: orderBy,
|
|
82
|
-
orderByDirection,
|
|
83
|
-
properties: apiModels.HttpParameterHelper.arrayToString(properties),
|
|
84
|
-
pageSize,
|
|
85
|
-
cursor
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
entities: result.body.entities,
|
|
90
|
-
cursor: result.body.cursor
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
exports.EntityStorageClient = EntityStorageClient;
|