@twin.org/blob-storage-rest-client 0.0.2-next.4 → 0.0.3-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.
@@ -1,29 +1,30 @@
1
- import { BaseRestClient } from '@twin.org/api-core';
2
- import { HttpParameterHelper } from '@twin.org/api-models';
3
- import { Guards, Urn, Coerce, StringHelper, Is } from '@twin.org/core';
4
- import { HeaderTypes, MimeTypes } from '@twin.org/web';
5
-
6
1
  // Copyright 2024 IOTA Stiftung.
7
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, Is, StringHelper, Urn } from "@twin.org/core";
6
+ import { HeaderTypes, MimeTypes } from "@twin.org/web";
8
7
  /**
9
8
  * Client for performing blob storage through to REST endpoints.
10
9
  */
11
- class BlobStorageClient extends BaseRestClient {
10
+ export class BlobStorageRestClient extends BaseRestClient {
12
11
  /**
13
12
  * Runtime name for the class.
14
- * @internal
15
13
  */
16
- static _CLASS_NAME = "BlobStorageClient";
14
+ static CLASS_NAME = "BlobStorageRestClient";
17
15
  /**
18
- * Runtime name for the class.
19
- */
20
- CLASS_NAME = BlobStorageClient._CLASS_NAME;
21
- /**
22
- * Create a new instance of BlobStorageClient.
16
+ * Create a new instance of BlobStorageRestClient.
23
17
  * @param config The configuration for the client.
24
18
  */
25
19
  constructor(config) {
26
- super(BlobStorageClient._CLASS_NAME, config, "blob");
20
+ super(BlobStorageRestClient.CLASS_NAME, config, "blob");
21
+ }
22
+ /**
23
+ * Returns the class name of the component.
24
+ * @returns The class name of the component.
25
+ */
26
+ className() {
27
+ return BlobStorageRestClient.CLASS_NAME;
27
28
  }
28
29
  /**
29
30
  * Create the blob with some metadata.
@@ -38,7 +39,7 @@ class BlobStorageClient extends BaseRestClient {
38
39
  * @returns The id of the stored blob in urn format.
39
40
  */
40
41
  async create(blob, encodingFormat, fileExtension, metadata, options) {
41
- Guards.stringBase64(this.CLASS_NAME, "blob", blob);
42
+ Guards.stringBase64(BlobStorageRestClient.CLASS_NAME, "blob", blob);
42
43
  const response = await this.fetch("/", "POST", {
43
44
  body: {
44
45
  blob,
@@ -63,7 +64,7 @@ class BlobStorageClient extends BaseRestClient {
63
64
  * @throws Not found error if the blob cannot be found.
64
65
  */
65
66
  async get(id, options) {
66
- Urn.guard(this.CLASS_NAME, "id", id);
67
+ Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
67
68
  const response = await this.fetch("/:id", "GET", {
68
69
  headers: {
69
70
  [HeaderTypes.Accept]: MimeTypes.JsonLd
@@ -89,7 +90,7 @@ class BlobStorageClient extends BaseRestClient {
89
90
  * @throws Not found error if the blob cannot be found.
90
91
  */
91
92
  async update(id, encodingFormat, fileExtension, metadata) {
92
- Urn.guard(this.CLASS_NAME, "id", id);
93
+ Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
93
94
  await this.fetch("/:id", "PUT", {
94
95
  pathParams: {
95
96
  id
@@ -107,7 +108,7 @@ class BlobStorageClient extends BaseRestClient {
107
108
  * @returns Nothing.
108
109
  */
109
110
  async remove(id) {
110
- Urn.guard(this.CLASS_NAME, "id", id);
111
+ Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
111
112
  await this.fetch("/:id", "DELETE", {
112
113
  pathParams: {
113
114
  id
@@ -120,11 +121,11 @@ class BlobStorageClient extends BaseRestClient {
120
121
  * @param orderBy The order for the results, defaults to created.
121
122
  * @param orderByDirection The direction for the order, defaults to descending.
122
123
  * @param cursor The cursor to request the next page of entries.
123
- * @param pageSize The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
124
+ * @param limit The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
124
125
  * @returns All the entries for the storage matching the conditions,
125
126
  * and a cursor which can be used to request more entities.
126
127
  */
127
- async query(conditions, orderBy, orderByDirection, cursor, pageSize) {
128
+ async query(conditions, orderBy, orderByDirection, cursor, limit) {
128
129
  const response = await this.fetch("/", "GET", {
129
130
  headers: {
130
131
  [HeaderTypes.Accept]: MimeTypes.JsonLd
@@ -133,7 +134,7 @@ class BlobStorageClient extends BaseRestClient {
133
134
  conditions: HttpParameterHelper.objectToString(conditions),
134
135
  orderBy,
135
136
  orderByDirection,
136
- pageSize,
137
+ limit: Coerce.string(limit),
137
138
  cursor
138
139
  }
139
140
  });
@@ -147,7 +148,7 @@ class BlobStorageClient extends BaseRestClient {
147
148
  * @returns The download link.
148
149
  */
149
150
  createDownloadLink(id, download, filename) {
150
- Urn.guard(this.CLASS_NAME, "id", id);
151
+ Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
151
152
  let link = StringHelper.trimTrailingSlashes(this.getEndpointWithPrefix());
152
153
  link += `/${id}/content`;
153
154
  const downloadQuery = [];
@@ -163,5 +164,4 @@ class BlobStorageClient extends BaseRestClient {
163
164
  return link;
164
165
  }
165
166
  }
166
-
167
- export { BlobStorageClient };
167
+ //# sourceMappingURL=blobStorageRestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blobStorageRestClient.js","sourceRoot":"","sources":["../../src/blobStorageRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACN,mBAAmB,EAInB,MAAM,sBAAsB,CAAC;AAa9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAIvE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,cAAc;IACxD;;OAEG;IACI,MAAM,CAAU,UAAU,2BAA2C;IAE5E;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CA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AAK,CAAC,qBAAqB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAE5D,IAAI,IAAI,GAAG,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;QAC1E,IAAI,IAAI,IAAI,EAAE,UAAU,CAAC;QAEzB,MAAM,aAAa,GAAa,EAAE,CAAC;QACnC,IAAI,QAAQ,EAAE,CAAC;YACd,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9B,aAAa,CAAC,IAAI,CAAC,YAAY,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,IAAI,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACvC,CAAC;QAED,OAAO,IAAI,CAAC;IACb,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 ICreatedResponse,\n\ttype INoContentResponse\n} from \"@twin.org/api-models\";\nimport type {\n\tIBlobStorageComponent,\n\tIBlobStorageCreateRequest,\n\tIBlobStorageEntry,\n\tIBlobStorageEntryList,\n\tIBlobStorageGetRequest,\n\tIBlobStorageGetResponse,\n\tIBlobStorageListRequest,\n\tIBlobStorageListResponse,\n\tIBlobStorageRemoveRequest,\n\tIBlobStorageUpdateRequest\n} from \"@twin.org/blob-storage-models\";\nimport { Coerce, Guards, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { EntityCondition, SortDirection } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing blob storage through to REST endpoints.\n */\nexport class BlobStorageRestClient extends BaseRestClient implements IBlobStorageComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<BlobStorageRestClient>();\n\n\t/**\n\t * Create a new instance of BlobStorageRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(BlobStorageRestClient.CLASS_NAME, config, \"blob\");\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 BlobStorageRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create the blob with some metadata.\n\t * @param blob The data for the blob in base64 format.\n\t * @param encodingFormat Mime type for the blob, will be detected if left undefined.\n\t * @param fileExtension Extension for the blob, will be detected if left undefined.\n\t * @param metadata Data for the custom metadata as JSON-LD.\n\t * @param options Optional options for the creation of the blob.\n\t * @param options.disableEncryption Disables encryption if enabled by default.\n\t * @param options.overrideVaultKeyId Use a different vault key id for encryption, if not provided the default vault key id will be used.\n\t * @param options.namespace The namespace to use for storing, defaults to component configured namespace.\n\t * @returns The id of the stored blob in urn format.\n\t */\n\tpublic async create(\n\t\tblob: string,\n\t\tencodingFormat?: string,\n\t\tfileExtension?: string,\n\t\tmetadata?: IJsonLdNodeObject,\n\t\toptions?: {\n\t\t\tdisableEncryption?: boolean;\n\t\t\toverrideVaultKeyId?: string;\n\t\t\tnamespace?: string;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.stringBase64(BlobStorageRestClient.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst response = await this.fetch<IBlobStorageCreateRequest, ICreatedResponse>(\"/\", \"POST\", {\n\t\t\tbody: {\n\t\t\t\tblob,\n\t\t\t\tencodingFormat,\n\t\t\t\tfileExtension,\n\t\t\t\tmetadata,\n\t\t\t\tdisableEncryption: options?.disableEncryption,\n\t\t\t\toverrideVaultKeyId: options?.overrideVaultKeyId,\n\t\t\t\tnamespace: options?.namespace\n\t\t\t}\n\t\t});\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get the blob and metadata.\n\t * @param id The id of the blob to get in urn format.\n\t * @param options Optional options for the retrieval of the blob.\n\t * @param options.includeContent Include the content, or just get the metadata.\n\t * @param options.overrideVaultKeyId Use a different vault key id for decryption, if not provided the default vault key id will be used.\n\t * @param options.decompress If the content should be decompressed, if it was compressed when stored, defaults to true.\n\t * @returns The metadata and data for the blob if it can be found.\n\t * @throws Not found error if the blob cannot be found.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\toptions?: {\n\t\t\tincludeContent?: boolean;\n\t\t\tdecompress?: boolean;\n\t\t\toverrideVaultKeyId?: string;\n\t\t}\n\t): Promise<IBlobStorageEntry> {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<IBlobStorageGetRequest, IBlobStorageGetResponse>(\n\t\t\t\"/:id\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\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\tincludeContent: Coerce.string(options?.includeContent),\n\t\t\t\t\tdecompress: Coerce.string(options?.decompress),\n\t\t\t\t\toverrideVaultKeyId: options?.overrideVaultKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update the blob with metadata.\n\t * @param id The id of the blob metadata to update.\n\t * @param encodingFormat Mime type for the blob, will be detected if left undefined.\n\t * @param fileExtension Extension for the blob, will be detected if left undefined.\n\t * @param metadata Data for the custom metadata as JSON-LD.\n\t * @returns Nothing.\n\t * @throws Not found error if the blob cannot be found.\n\t */\n\tpublic async update(\n\t\tid: string,\n\t\tencodingFormat?: string,\n\t\tfileExtension?: string,\n\t\tmetadata?: IJsonLdNodeObject\n\t): Promise<void> {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IBlobStorageUpdateRequest, INoContentResponse>(\"/:id\", \"PUT\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tbody: {\n\t\t\t\tencodingFormat,\n\t\t\t\tfileExtension,\n\t\t\t\tmetadata\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Remove the blob.\n\t * @param id The id of the blob to remove in urn format.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(id: string): Promise<void> {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IBlobStorageRemoveRequest, 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 * Query all the blob storage entries which match the conditions.\n\t * @param conditions The conditions to match for the entries.\n\t * @param orderBy The order for the results, defaults to created.\n\t * @param orderByDirection The direction for the order, defaults to descending.\n\t * @param cursor The cursor to request the next page of entries.\n\t * @param limit The suggested number of entries to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entries 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<IBlobStorageEntry>,\n\t\torderBy?: keyof Pick<IBlobStorageEntry, \"dateCreated\" | \"dateModified\">,\n\t\torderByDirection?: SortDirection,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<IBlobStorageEntryList> {\n\t\tconst response = await this.fetch<IBlobStorageListRequest, IBlobStorageListResponse>(\n\t\t\t\"/\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions),\n\t\t\t\t\torderBy,\n\t\t\t\t\torderByDirection,\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 response.body;\n\t}\n\n\t/**\n\t * Create a download link for the blob.\n\t * @param id The id of the blob to get in urn format.\n\t * @param download Should the content disposition be set to download.\n\t * @param filename The filename to use for the download.\n\t * @returns The download link.\n\t */\n\tpublic createDownloadLink(id: string, download?: boolean, filename?: string): string {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tlet link = StringHelper.trimTrailingSlashes(this.getEndpointWithPrefix());\n\t\tlink += `/${id}/content`;\n\n\t\tconst downloadQuery: string[] = [];\n\t\tif (download) {\n\t\t\tdownloadQuery.push(\"download=true\");\n\t\t}\n\t\tif (Is.stringValue(filename)) {\n\t\t\tdownloadQuery.push(`filename=${encodeURIComponent(filename)}`);\n\t\t}\n\t\tif (downloadQuery.length > 0) {\n\t\t\tlink += `?${downloadQuery.join(\"&\")}`;\n\t\t}\n\n\t\treturn link;\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./blobStorageRestClient.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,4BAA4B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./blobStorageRestClient.js\";\n"]}
@@ -6,16 +6,21 @@ import type { EntityCondition, SortDirection } from "@twin.org/entity";
6
6
  /**
7
7
  * Client for performing blob storage through to REST endpoints.
8
8
  */
9
- export declare class BlobStorageClient extends BaseRestClient implements IBlobStorageComponent {
9
+ export declare class BlobStorageRestClient extends BaseRestClient implements IBlobStorageComponent {
10
10
  /**
11
11
  * Runtime name for the class.
12
12
  */
13
- readonly CLASS_NAME: string;
13
+ static readonly CLASS_NAME: string;
14
14
  /**
15
- * Create a new instance of BlobStorageClient.
15
+ * Create a new instance of BlobStorageRestClient.
16
16
  * @param config The configuration for the client.
17
17
  */
18
18
  constructor(config: IBaseRestClientConfig);
19
+ /**
20
+ * Returns the class name of the component.
21
+ * @returns The class name of the component.
22
+ */
23
+ className(): string;
19
24
  /**
20
25
  * Create the blob with some metadata.
21
26
  * @param blob The data for the blob in base64 format.
@@ -70,11 +75,11 @@ export declare class BlobStorageClient extends BaseRestClient implements IBlobSt
70
75
  * @param orderBy The order for the results, defaults to created.
71
76
  * @param orderByDirection The direction for the order, defaults to descending.
72
77
  * @param cursor The cursor to request the next page of entries.
73
- * @param pageSize The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
78
+ * @param limit The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
74
79
  * @returns All the entries for the storage matching the conditions,
75
80
  * and a cursor which can be used to request more entities.
76
81
  */
77
- query(conditions?: EntityCondition<IBlobStorageEntry>, orderBy?: keyof Pick<IBlobStorageEntry, "dateCreated" | "dateModified">, orderByDirection?: SortDirection, cursor?: string, pageSize?: number): Promise<IBlobStorageEntryList>;
82
+ query(conditions?: EntityCondition<IBlobStorageEntry>, orderBy?: keyof Pick<IBlobStorageEntry, "dateCreated" | "dateModified">, orderByDirection?: SortDirection, cursor?: string, limit?: number): Promise<IBlobStorageEntryList>;
78
83
  /**
79
84
  * Create a download link for the blob.
80
85
  * @param id The id of the blob to get in urn format.
@@ -1 +1 @@
1
- export * from "./blobStorageClient";
1
+ export * from "./blobStorageRestClient.js";
package/docs/changelog.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # @twin.org/blob-storage-rest-client - Changelog
2
2
 
3
+ ## [0.0.3-next.1](https://github.com/twinfoundation/blob-storage/compare/blob-storage-rest-client-v0.0.3-next.0...blob-storage-rest-client-v0.0.3-next.1) (2025-11-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * add compression support ([67d239b](https://github.com/twinfoundation/blob-storage/commit/67d239bca8321bd90bf4ff93167c564130309730))
9
+ * add context id features ([#30](https://github.com/twinfoundation/blob-storage/issues/30)) ([fbf1c92](https://github.com/twinfoundation/blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
10
+ * add validate-locales ([f20fcec](https://github.com/twinfoundation/blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
11
+ * additional encryption options on per item basis ([4b95a65](https://github.com/twinfoundation/blob-storage/commit/4b95a656d19e3b571cea905e36f29b679b13e1e8))
12
+ * eslint migration to flat config ([e4239dd](https://github.com/twinfoundation/blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
13
+ * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
14
+ * update framework core ([ff339fe](https://github.com/twinfoundation/blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
15
+ * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * The following workspace dependencies were updated
21
+ * dependencies
22
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
23
+
24
+ ## [0.0.2-next.5](https://github.com/twinfoundation/blob-storage/compare/blob-storage-rest-client-v0.0.2-next.4...blob-storage-rest-client-v0.0.2-next.5) (2025-10-09)
25
+
26
+
27
+ ### Features
28
+
29
+ * add validate-locales ([f20fcec](https://github.com/twinfoundation/blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
30
+
31
+
32
+ ### Dependencies
33
+
34
+ * The following workspace dependencies were updated
35
+ * dependencies
36
+ * @twin.org/blob-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
37
+
3
38
  ## [0.0.2-next.4](https://github.com/twinfoundation/blob-storage/compare/blob-storage-rest-client-v0.0.2-next.3...blob-storage-rest-client-v0.0.2-next.4) (2025-10-02)
4
39
 
5
40
 
@@ -1,4 +1,4 @@
1
- # Class: BlobStorageClient
1
+ # Class: BlobStorageRestClient
2
2
 
3
3
  Client for performing blob storage through to REST endpoints.
4
4
 
@@ -14,9 +14,9 @@ Client for performing blob storage through to REST endpoints.
14
14
 
15
15
  ### Constructor
16
16
 
17
- > **new BlobStorageClient**(`config`): `BlobStorageClient`
17
+ > **new BlobStorageRestClient**(`config`): `BlobStorageRestClient`
18
18
 
19
- Create a new instance of BlobStorageClient.
19
+ Create a new instance of BlobStorageRestClient.
20
20
 
21
21
  #### Parameters
22
22
 
@@ -28,7 +28,7 @@ The configuration for the client.
28
28
 
29
29
  #### Returns
30
30
 
31
- `BlobStorageClient`
31
+ `BlobStorageRestClient`
32
32
 
33
33
  #### Overrides
34
34
 
@@ -38,15 +38,29 @@ The configuration for the client.
38
38
 
39
39
  ### CLASS\_NAME
40
40
 
41
- > `readonly` **CLASS\_NAME**: `string` = `BlobStorageClient._CLASS_NAME`
41
+ > `readonly` `static` **CLASS\_NAME**: `string`
42
42
 
43
43
  Runtime name for the class.
44
44
 
45
+ ## Methods
46
+
47
+ ### className()
48
+
49
+ > **className**(): `string`
50
+
51
+ Returns the class name of the component.
52
+
53
+ #### Returns
54
+
55
+ `string`
56
+
57
+ The class name of the component.
58
+
45
59
  #### Implementation of
46
60
 
47
- `IBlobStorageComponent.CLASS_NAME`
61
+ `IBlobStorageComponent.className`
48
62
 
49
- ## Methods
63
+ ***
50
64
 
51
65
  ### create()
52
66
 
@@ -242,7 +256,7 @@ Nothing.
242
256
 
243
257
  ### query()
244
258
 
245
- > **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `cursor?`, `pageSize?`): `Promise`\<`IBlobStorageEntryList`\>
259
+ > **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `cursor?`, `limit?`): `Promise`\<`IBlobStorageEntryList`\>
246
260
 
247
261
  Query all the blob storage entries which match the conditions.
248
262
 
@@ -272,7 +286,7 @@ The direction for the order, defaults to descending.
272
286
 
273
287
  The cursor to request the next page of entries.
274
288
 
275
- ##### pageSize?
289
+ ##### limit?
276
290
 
277
291
  `number`
278
292
 
@@ -2,4 +2,4 @@
2
2
 
3
3
  ## Classes
4
4
 
5
- - [BlobStorageClient](classes/BlobStorageClient.md)
5
+ - [BlobStorageRestClient](classes/BlobStorageRestClient.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/blob-storage-rest-client",
3
- "version": "0.0.2-next.4",
3
+ "version": "0.0.3-next.1",
4
4
  "description": "Blob storage implementation which can connect to REST endpoints",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,27 +16,25 @@
16
16
  "dependencies": {
17
17
  "@twin.org/api-core": "next",
18
18
  "@twin.org/api-models": "next",
19
- "@twin.org/blob-storage-models": "0.0.2-next.4",
19
+ "@twin.org/blob-storage-models": "0.0.3-next.1",
20
20
  "@twin.org/core": "next",
21
21
  "@twin.org/data-json-ld": "next",
22
22
  "@twin.org/entity": "next",
23
23
  "@twin.org/nameof": "next",
24
24
  "@twin.org/web": "next"
25
25
  },
26
- "main": "./dist/cjs/index.cjs",
27
- "module": "./dist/esm/index.mjs",
26
+ "main": "./dist/es/index.js",
28
27
  "types": "./dist/types/index.d.ts",
29
28
  "exports": {
30
29
  ".": {
31
30
  "types": "./dist/types/index.d.ts",
32
- "require": "./dist/cjs/index.cjs",
33
- "import": "./dist/esm/index.mjs"
31
+ "import": "./dist/es/index.js",
32
+ "default": "./dist/es/index.js"
34
33
  },
35
34
  "./locales/*.json": "./locales/*.json"
36
35
  },
37
36
  "files": [
38
- "dist/cjs",
39
- "dist/esm",
37
+ "dist/es",
40
38
  "dist/types",
41
39
  "locales",
42
40
  "docs"
@@ -52,5 +50,9 @@
52
50
  "storage",
53
51
  "files",
54
52
  "binary"
55
- ]
53
+ ],
54
+ "bugs": {
55
+ "url": "git+https://github.com/twinfoundation/blob-storage/issues"
56
+ },
57
+ "homepage": "https://twindev.org"
56
58
  }
@@ -1,169 +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
- var web = require('@twin.org/web');
7
-
8
- // Copyright 2024 IOTA Stiftung.
9
- // SPDX-License-Identifier: Apache-2.0.
10
- /**
11
- * Client for performing blob storage through to REST endpoints.
12
- */
13
- class BlobStorageClient extends apiCore.BaseRestClient {
14
- /**
15
- * Runtime name for the class.
16
- * @internal
17
- */
18
- static _CLASS_NAME = "BlobStorageClient";
19
- /**
20
- * Runtime name for the class.
21
- */
22
- CLASS_NAME = BlobStorageClient._CLASS_NAME;
23
- /**
24
- * Create a new instance of BlobStorageClient.
25
- * @param config The configuration for the client.
26
- */
27
- constructor(config) {
28
- super(BlobStorageClient._CLASS_NAME, config, "blob");
29
- }
30
- /**
31
- * Create the blob with some metadata.
32
- * @param blob The data for the blob in base64 format.
33
- * @param encodingFormat Mime type for the blob, will be detected if left undefined.
34
- * @param fileExtension Extension for the blob, will be detected if left undefined.
35
- * @param metadata Data for the custom metadata as JSON-LD.
36
- * @param options Optional options for the creation of the blob.
37
- * @param options.disableEncryption Disables encryption if enabled by default.
38
- * @param options.overrideVaultKeyId Use a different vault key id for encryption, if not provided the default vault key id will be used.
39
- * @param options.namespace The namespace to use for storing, defaults to component configured namespace.
40
- * @returns The id of the stored blob in urn format.
41
- */
42
- async create(blob, encodingFormat, fileExtension, metadata, options) {
43
- core.Guards.stringBase64(this.CLASS_NAME, "blob", blob);
44
- const response = await this.fetch("/", "POST", {
45
- body: {
46
- blob,
47
- encodingFormat,
48
- fileExtension,
49
- metadata,
50
- disableEncryption: options?.disableEncryption,
51
- overrideVaultKeyId: options?.overrideVaultKeyId,
52
- namespace: options?.namespace
53
- }
54
- });
55
- return response.headers[web.HeaderTypes.Location];
56
- }
57
- /**
58
- * Get the blob and metadata.
59
- * @param id The id of the blob to get in urn format.
60
- * @param options Optional options for the retrieval of the blob.
61
- * @param options.includeContent Include the content, or just get the metadata.
62
- * @param options.overrideVaultKeyId Use a different vault key id for decryption, if not provided the default vault key id will be used.
63
- * @param options.decompress If the content should be decompressed, if it was compressed when stored, defaults to true.
64
- * @returns The metadata and data for the blob if it can be found.
65
- * @throws Not found error if the blob cannot be found.
66
- */
67
- async get(id, options) {
68
- core.Urn.guard(this.CLASS_NAME, "id", id);
69
- const response = await this.fetch("/:id", "GET", {
70
- headers: {
71
- [web.HeaderTypes.Accept]: web.MimeTypes.JsonLd
72
- },
73
- pathParams: {
74
- id
75
- },
76
- query: {
77
- includeContent: core.Coerce.string(options?.includeContent),
78
- decompress: core.Coerce.string(options?.decompress),
79
- overrideVaultKeyId: options?.overrideVaultKeyId
80
- }
81
- });
82
- return response.body;
83
- }
84
- /**
85
- * Update the blob with metadata.
86
- * @param id The id of the blob metadata to update.
87
- * @param encodingFormat Mime type for the blob, will be detected if left undefined.
88
- * @param fileExtension Extension for the blob, will be detected if left undefined.
89
- * @param metadata Data for the custom metadata as JSON-LD.
90
- * @returns Nothing.
91
- * @throws Not found error if the blob cannot be found.
92
- */
93
- async update(id, encodingFormat, fileExtension, metadata) {
94
- core.Urn.guard(this.CLASS_NAME, "id", id);
95
- await this.fetch("/:id", "PUT", {
96
- pathParams: {
97
- id
98
- },
99
- body: {
100
- encodingFormat,
101
- fileExtension,
102
- metadata
103
- }
104
- });
105
- }
106
- /**
107
- * Remove the blob.
108
- * @param id The id of the blob to remove in urn format.
109
- * @returns Nothing.
110
- */
111
- async remove(id) {
112
- core.Urn.guard(this.CLASS_NAME, "id", id);
113
- await this.fetch("/:id", "DELETE", {
114
- pathParams: {
115
- id
116
- }
117
- });
118
- }
119
- /**
120
- * Query all the blob storage entries which match the conditions.
121
- * @param conditions The conditions to match for the entries.
122
- * @param orderBy The order for the results, defaults to created.
123
- * @param orderByDirection The direction for the order, defaults to descending.
124
- * @param cursor The cursor to request the next page of entries.
125
- * @param pageSize The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
126
- * @returns All the entries for the storage matching the conditions,
127
- * and a cursor which can be used to request more entities.
128
- */
129
- async query(conditions, orderBy, orderByDirection, cursor, pageSize) {
130
- const response = await this.fetch("/", "GET", {
131
- headers: {
132
- [web.HeaderTypes.Accept]: web.MimeTypes.JsonLd
133
- },
134
- query: {
135
- conditions: apiModels.HttpParameterHelper.objectToString(conditions),
136
- orderBy,
137
- orderByDirection,
138
- pageSize,
139
- cursor
140
- }
141
- });
142
- return response.body;
143
- }
144
- /**
145
- * Create a download link for the blob.
146
- * @param id The id of the blob to get in urn format.
147
- * @param download Should the content disposition be set to download.
148
- * @param filename The filename to use for the download.
149
- * @returns The download link.
150
- */
151
- createDownloadLink(id, download, filename) {
152
- core.Urn.guard(this.CLASS_NAME, "id", id);
153
- let link = core.StringHelper.trimTrailingSlashes(this.getEndpointWithPrefix());
154
- link += `/${id}/content`;
155
- const downloadQuery = [];
156
- if (download) {
157
- downloadQuery.push("download=true");
158
- }
159
- if (core.Is.stringValue(filename)) {
160
- downloadQuery.push(`filename=${encodeURIComponent(filename)}`);
161
- }
162
- if (downloadQuery.length > 0) {
163
- link += `?${downloadQuery.join("&")}`;
164
- }
165
- return link;
166
- }
167
- }
168
-
169
- exports.BlobStorageClient = BlobStorageClient;