@twin.org/entity-storage-rest-client 0.9.1-next.2 → 0.9.1-next.4

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.
@@ -3,6 +3,7 @@
3
3
  import { BaseRestClient } from "@twin.org/api-core";
4
4
  import { HttpParameterHelper } from "@twin.org/api-models";
5
5
  import { Coerce, Guards } from "@twin.org/core";
6
+ import { HttpMethod } from "@twin.org/web";
6
7
  /**
7
8
  * Client for performing entity storage through to REST endpoints.
8
9
  */
@@ -33,7 +34,7 @@ export class EntityStorageRestClient extends BaseRestClient {
33
34
  */
34
35
  async set(entity, conditions) {
35
36
  Guards.object(EntityStorageRestClient.CLASS_NAME, "entity", entity);
36
- await this.fetch("/", "POST", {
37
+ await this.fetch("/", HttpMethod.POST, {
37
38
  body: entity,
38
39
  query: {
39
40
  conditions: HttpParameterHelper.objectToString(conditions)
@@ -47,7 +48,7 @@ export class EntityStorageRestClient extends BaseRestClient {
47
48
  */
48
49
  async setBatch(entities) {
49
50
  Guards.arrayValue(EntityStorageRestClient.CLASS_NAME, "entities", entities);
50
- await this.fetch("/batch", "POST", {
51
+ await this.fetch("/batch", HttpMethod.POST, {
51
52
  body: entities
52
53
  });
53
54
  }
@@ -60,7 +61,7 @@ export class EntityStorageRestClient extends BaseRestClient {
60
61
  */
61
62
  async get(id, secondaryIndex, conditions) {
62
63
  Guards.stringValue(EntityStorageRestClient.CLASS_NAME, "id", id);
63
- const response = await this.fetch("/:id", "GET", {
64
+ const response = await this.fetch("/:id", HttpMethod.GET, {
64
65
  pathParams: {
65
66
  id
66
67
  },
@@ -79,7 +80,7 @@ export class EntityStorageRestClient extends BaseRestClient {
79
80
  */
80
81
  async remove(id, conditions) {
81
82
  Guards.stringValue(EntityStorageRestClient.CLASS_NAME, "id", id);
82
- await this.fetch("/:id", "DELETE", {
83
+ await this.fetch("/:id", HttpMethod.DELETE, {
83
84
  pathParams: {
84
85
  id
85
86
  },
@@ -95,7 +96,7 @@ export class EntityStorageRestClient extends BaseRestClient {
95
96
  */
96
97
  async removeBatch(ids) {
97
98
  Guards.arrayValue(EntityStorageRestClient.CLASS_NAME, "ids", ids);
98
- await this.fetch("/batch", "DELETE", {
99
+ await this.fetch("/batch", HttpMethod.DELETE, {
99
100
  body: ids
100
101
  });
101
102
  }
@@ -104,7 +105,7 @@ export class EntityStorageRestClient extends BaseRestClient {
104
105
  * @returns Nothing.
105
106
  */
106
107
  async empty() {
107
- await this.fetch("/", "DELETE", {});
108
+ await this.fetch("/", HttpMethod.DELETE, {});
108
109
  }
109
110
  /**
110
111
  * Count all the entities which match the conditions.
@@ -112,7 +113,7 @@ export class EntityStorageRestClient extends BaseRestClient {
112
113
  * @returns The total count of entities in the storage.
113
114
  */
114
115
  async count(conditions) {
115
- const result = await this.fetch("/count", "GET", {
116
+ const result = await this.fetch("/count", HttpMethod.GET, {
116
117
  query: {
117
118
  conditions: HttpParameterHelper.objectToString(conditions)
118
119
  }
@@ -131,7 +132,7 @@ export class EntityStorageRestClient extends BaseRestClient {
131
132
  * and a cursor which can be used to request more entities.
132
133
  */
133
134
  async query(conditions, orderBy, orderByDirection, properties, cursor, limit) {
134
- const result = await this.fetch("/", "GET", {
135
+ const result = await this.fetch("/", HttpMethod.GET, {
135
136
  query: {
136
137
  conditions: HttpParameterHelper.objectToString(conditions),
137
138
  orderBy: orderBy,
@@ -1 +1 @@
1
- {"version":3,"file":"entityStorageRestClient.js","sourceRoot":"","sources":["../../src/entityStorageRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACN,mBAAmB,EAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAkBhD;;GAEG;AACH,MAAM,OAAO,uBACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAA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AC,UAAU,CAAC;gBAC1D,OAAO,EAAE,OAAiB;gBAC1B,gBAAgB;gBAChB,UAAU,EAAE,mBAAmB,CAAC,aAAa,CAAC,UAAU,CAAC;gBACzD,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC3B,MAAM;aACN;SACD,CACD,CAAC;QAEF,OAAO;YACN,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,QAAwB;YAC9C,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM;SAC1B,CAAC;IACH,CAAC","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 * @param conditions The optional conditions to match for the entities.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T, conditions?: { property: keyof T; value: unknown }[]): 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\tquery: {\n\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions)\n\t\t\t}\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\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\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\tconditions: HttpParameterHelper.objectToString(conditions)\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(\n\t\tid: string,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): 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\tquery: {\n\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions)\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns The total count of entities in the storage.\n\t */\n\tpublic async count(conditions?: EntityCondition<T>): 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\t\tquery: {\n\t\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions)\n\t\t\t\t}\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"]}
1
+ {"version":3,"file":"entityStorageRestClient.js","sourceRoot":"","sources":["../../src/entityStorageRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACN,mBAAmB,EAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MA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OAUG;IACI,KAAK,CAAC,KAAK,CACjB,UAA+B,EAC/B,OAAiB,EACjB,gBAAgC,EAChC,UAAwB,EACxB,MAAe,EACf,KAAc;QAWd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAC9B,GAAG,EACH,UAAU,CAAC,GAAG,EACd;YACC,KAAK,EAAE;gBACN,UAAU,EAAE,mBAAmB,CAAC,cAAc,CAAC,UAAU,CAAC;gBAC1D,OAAO,EAAE,OAAiB;gBAC1B,gBAAgB;gBAChB,UAAU,EAAE,mBAAmB,CAAC,aAAa,CAAC,UAAU,CAAC;gBACzD,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC3B,MAAM;aACN;SACD,CACD,CAAC;QAEF,OAAO;YACN,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,QAAwB;YAC9C,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM;SAC1B,CAAC;IACH,CAAC","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\";\nimport { HttpMethod } from \"@twin.org/web\";\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T, conditions?: { property: keyof T; value: unknown }[]): Promise<void> {\n\t\tGuards.object(EntityStorageRestClient.CLASS_NAME, nameof(entity), entity);\n\n\t\tawait this.fetch<IEntityStorageSetRequest, INoContentResponse>(\"/\", HttpMethod.POST, {\n\t\t\tbody: entity,\n\t\t\tquery: {\n\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions)\n\t\t\t}\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\", HttpMethod.POST, {\n\t\t\tbody: entities\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\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\tHttpMethod.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\tconditions: HttpParameterHelper.objectToString(conditions)\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 * @param conditions The optional conditions to match for the entities.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(\n\t\tid: string,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<void> {\n\t\tGuards.stringValue(EntityStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IEntityStorageRemoveRequest, INoContentResponse>(\"/:id\", HttpMethod.DELETE, {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions)\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>(\n\t\t\t\"/batch\",\n\t\t\tHttpMethod.DELETE,\n\t\t\t{\n\t\t\t\tbody: ids\n\t\t\t}\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>(\"/\", HttpMethod.DELETE, {});\n\t}\n\n\t/**\n\t * Count all the entities which match the conditions.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The total count of entities in the storage.\n\t */\n\tpublic async count(conditions?: EntityCondition<T>): Promise<number> {\n\t\tconst result = await this.fetch<IEntityStorageCountRequest, IEntityStorageCountResponse>(\n\t\t\t\"/count\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tquery: {\n\t\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions)\n\t\t\t\t}\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\tHttpMethod.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/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.1-next.4](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.9.1-next.3...entity-storage-rest-client-v0.9.1-next.4) (2026-06-29)
4
+
5
+
6
+ ### Features
7
+
8
+ * enhanced rest testing ([#156](https://github.com/iotaledger/twin-entity-storage/issues/156)) ([f6d3e0c](https://github.com/iotaledger/twin-entity-storage/commit/f6d3e0c03c2e773aed58a26aa221d15ac702577a))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/entity-storage-models bumped from 0.9.1-next.3 to 0.9.1-next.4
16
+
17
+ ## [0.9.1-next.3](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.9.1-next.2...entity-storage-rest-client-v0.9.1-next.3) (2026-06-26)
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.9.1-next.2 to 0.9.1-next.3
30
+
3
31
  ## [0.9.1-next.2](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-rest-client-v0.9.1-next.1...entity-storage-rest-client-v0.9.1-next.2) (2026-06-26)
4
32
 
5
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-rest-client",
3
- "version": "0.9.1-next.2",
3
+ "version": "0.9.1-next.4",
4
4
  "description": "REST client for calling storage services from applications and tools.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
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.9.1-next.2",
21
+ "@twin.org/entity-storage-models": "0.9.1-next.4",
22
22
  "@twin.org/nameof": "next",
23
23
  "@twin.org/web": "next"
24
24
  },