@twin.org/blob-storage-connector-file 0.0.3-next.7 → 0.0.3-next.9
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 +1 -1
- package/dist/es/fileBlobStorageConnector.js +24 -1
- package/dist/es/fileBlobStorageConnector.js.map +1 -1
- package/dist/types/fileBlobStorageConnector.d.ts +6 -0
- package/docs/changelog.md +70 -36
- package/docs/examples.md +42 -1
- package/docs/reference/classes/FileBlobStorageConnector.md +25 -7
- package/docs/reference/interfaces/IFileBlobStorageConnectorConfig.md +3 -3
- package/docs/reference/interfaces/IFileBlobStorageConnectorConstructorOptions.md +3 -3
- package/locales/en.json +6 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TWIN Blob Storage Connector File
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package stores and retrieves blobs using local file system directories or mounted volumes. It is useful for straightforward deployments and development environments that rely on direct disk-backed storage.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { access, mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { ContextIdHelper, ContextIdStore } from "@twin.org/context";
|
|
6
|
-
import { BaseError, ComponentFactory, Converter, GeneralError, Guards, Is, Urn } from "@twin.org/core";
|
|
6
|
+
import { BaseError, ComponentFactory, Converter, GeneralError, Guards, HealthStatus, Is, Urn } from "@twin.org/core";
|
|
7
7
|
import { Sha256 } from "@twin.org/crypto";
|
|
8
8
|
/**
|
|
9
9
|
* Class for performing blob storage operations in file.
|
|
@@ -51,6 +51,29 @@ export class FileBlobStorageConnector {
|
|
|
51
51
|
className() {
|
|
52
52
|
return FileBlobStorageConnector.CLASS_NAME;
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the health status of the component.
|
|
56
|
+
* @returns The health status of the component.
|
|
57
|
+
*/
|
|
58
|
+
async health() {
|
|
59
|
+
if (await this.dirExists(this._directory)) {
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
source: FileBlobStorageConnector.CLASS_NAME,
|
|
63
|
+
status: HealthStatus.Ok,
|
|
64
|
+
description: "healthDescription"
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
source: FileBlobStorageConnector.CLASS_NAME,
|
|
71
|
+
status: HealthStatus.Error,
|
|
72
|
+
description: "healthDescription",
|
|
73
|
+
message: "healthCheckFailed"
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
}
|
|
54
77
|
/**
|
|
55
78
|
* Bootstrap the component by creating and initializing any resources it needs.
|
|
56
79
|
* @param nodeLoggingComponentType The node logging component type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileBlobStorageConnector.js","sourceRoot":"","sources":["../../src/fileBlobStorageConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,GAAG,EACH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,MAAM,CAAC;IAElD;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACc,UAAU,CAAS;IAEpC;;;OAGG;IACc,UA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,EAAE,GAAG,CAAC,CAAC;QAC9F,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,SAAS,CAAC,GAAW;QAClC,IAAI,CAAC;YACJ,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,IAAI,CAAC;QACb,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACK,cAAc,CAAC,EAAU,EAAE,YAAqB;QACvD,MAAM,aAAa,GAAG,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtF,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACzE,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { access, mkdir, readFile, unlink, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { IBlobStorageConnector } from \"@twin.org/blob-storage-models\";\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tUrn\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IFileBlobStorageConnectorConstructorOptions } from \"./models/IFileBlobStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing blob storage operations in file.\n */\nexport class FileBlobStorageConnector implements IBlobStorageConnector {\n\t/**\n\t * The namespace for the items.\n\t */\n\tpublic static readonly NAMESPACE: string = \"file\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<FileBlobStorageConnector>();\n\n\t/**\n\t * The directory to use for storage.\n\t * @internal\n\t */\n\tprivate readonly _directory: string;\n\n\t/**\n\t * The extension to use for storage.\n\t * @internal\n\t */\n\tprivate readonly _extension: string;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t * @internal\n\t */\n\tprivate readonly _partitionContextIds?: string[];\n\n\t/**\n\t * Create a new instance of FileBlobStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IFileBlobStorageConnectorConstructorOptions) {\n\t\tGuards.object(FileBlobStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.object(FileBlobStorageConnector.CLASS_NAME, nameof(options.config), options.config);\n\t\tGuards.stringValue(\n\t\t\tFileBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.directory),\n\t\t\toptions.config.directory\n\t\t);\n\t\tthis._directory = path.resolve(options.config.directory);\n\t\tthis._extension = options.config.extension ?? \".blob\";\n\t\tthis._partitionContextIds = options.partitionContextIds;\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 FileBlobStorageConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\tif (!(await this.dirExists(this._directory))) {\n\t\t\ttry {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"directoryCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdirectory: this._directory\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tawait mkdir(this._directory, { recursive: true });\n\t\t\t} catch (err) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"directoryCreateFailed\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdirectory: this._directory\n\t\t\t\t\t},\n\t\t\t\t\terror: BaseError.fromError(err)\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} else {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"directoryExists\",\n\t\t\t\tdata: {\n\t\t\t\t\tdirectory: this._directory\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Set the blob.\n\t * @param blob The data for the blob.\n\t * @returns The id of the stored blob in urn format.\n\t */\n\tpublic async set(blob: Uint8Array): Promise<string> {\n\t\tGuards.uint8Array(FileBlobStorageConnector.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst id = Converter.bytesToHex(Sha256.sum256(blob));\n\n\t\t\tconst fullPath = this.createFullPath(id, partitionKey);\n\n\t\t\tconst dir = path.dirname(fullPath);\n\t\t\tif (!(await this.dirExists(dir))) {\n\t\t\t\tawait mkdir(dir, { recursive: true });\n\t\t\t}\n\n\t\t\tawait writeFile(fullPath, blob);\n\n\t\t\treturn `blob:${new Urn(FileBlobStorageConnector.NAMESPACE, id).toString()}`;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"setBlobFailed\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Get the blob.\n\t * @param id The id of the blob to get in urn format.\n\t * @returns The data for the blob if it can be found or undefined.\n\t */\n\tpublic async get(id: string): Promise<Uint8Array | undefined> {\n\t\tUrn.guard(FileBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== FileBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: FileBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst fullPath = this.createFullPath(urnParsed.namespaceSpecific(1), partitionKey);\n\n\t\t\treturn await readFile(fullPath);\n\t\t} catch (err) {\n\t\t\tif (BaseError.isErrorCode(err, \"ENOENT\")) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"getBlobFailed\", { id }, err);\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 True if the blob was found.\n\t */\n\tpublic async remove(id: string): Promise<boolean> {\n\t\tUrn.guard(FileBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== FileBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: FileBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst fullPath = this.createFullPath(urnParsed.namespaceSpecific(1), partitionKey);\n\n\t\t\tawait unlink(fullPath);\n\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tif (BaseError.isErrorCode(err, \"ENOENT\")) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"removeBlobFailed\", { id }, err);\n\t\t}\n\t}\n\n\t/**\n\t * Check if the dir exists.\n\t * @param dir The directory to check.\n\t * @returns True if the dir exists.\n\t * @internal\n\t */\n\tprivate async dirExists(dir: string): Promise<boolean> {\n\t\ttry {\n\t\t\tawait access(dir);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Create the full path for the blob.\n\t * @param id The id of the blob.\n\t * @param partitionKey The partition key.\n\t * @returns The full path for the blob.\n\t * @internal\n\t */\n\tprivate createFullPath(id: string, partitionKey?: string): string {\n\t\tconst partitionPath = Is.stringValue(partitionKey) ? path.join(partitionKey, id) : id;\n\t\treturn path.join(this._directory, `${partitionPath}${this._extension}`);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fileBlobStorageConnector.js","sourceRoot":"","sources":["../../src/fileBlobStorageConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,EAAE,EACF,GAAG,EAEH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,MAAM,CAAC;IA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fs/promises\";\nimport path from \"node:path\";\nimport type { IBlobStorageConnector } from \"@twin.org/blob-storage-models\";\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tHealthStatus,\n\tIs,\n\tUrn,\n\ttype IHealth\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IFileBlobStorageConnectorConstructorOptions } from \"./models/IFileBlobStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing blob storage operations in file.\n */\nexport class FileBlobStorageConnector implements IBlobStorageConnector {\n\t/**\n\t * The namespace for the items.\n\t */\n\tpublic static readonly NAMESPACE: string = \"file\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<FileBlobStorageConnector>();\n\n\t/**\n\t * The directory to use for storage.\n\t * @internal\n\t */\n\tprivate readonly _directory: string;\n\n\t/**\n\t * The extension to use for storage.\n\t * @internal\n\t */\n\tprivate readonly _extension: string;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t * @internal\n\t */\n\tprivate readonly _partitionContextIds?: string[];\n\n\t/**\n\t * Create a new instance of FileBlobStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IFileBlobStorageConnectorConstructorOptions) {\n\t\tGuards.object(FileBlobStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.object(FileBlobStorageConnector.CLASS_NAME, nameof(options.config), options.config);\n\t\tGuards.stringValue(\n\t\t\tFileBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.directory),\n\t\t\toptions.config.directory\n\t\t);\n\t\tthis._directory = path.resolve(options.config.directory);\n\t\tthis._extension = options.config.extension ?? \".blob\";\n\t\tthis._partitionContextIds = options.partitionContextIds;\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 FileBlobStorageConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Returns the health status of the component.\n\t * @returns The health status of the component.\n\t */\n\tpublic async health(): Promise<IHealth[]> {\n\t\tif (await this.dirExists(this._directory)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tstatus: HealthStatus.Ok,\n\t\t\t\t\tdescription: \"healthDescription\"\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\tstatus: HealthStatus.Error,\n\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\tmessage: \"healthCheckFailed\"\n\t\t\t}\n\t\t];\n\t}\n\n\t/**\n\t * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\tif (!(await this.dirExists(this._directory))) {\n\t\t\ttry {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"directoryCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdirectory: this._directory\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tawait mkdir(this._directory, { recursive: true });\n\t\t\t} catch (err) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"directoryCreateFailed\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tdirectory: this._directory\n\t\t\t\t\t},\n\t\t\t\t\terror: BaseError.fromError(err)\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} else {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: FileBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"directoryExists\",\n\t\t\t\tdata: {\n\t\t\t\t\tdirectory: this._directory\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Set the blob.\n\t * @param blob The data for the blob.\n\t * @returns The id of the stored blob in urn format.\n\t */\n\tpublic async set(blob: Uint8Array): Promise<string> {\n\t\tGuards.uint8Array(FileBlobStorageConnector.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst id = Converter.bytesToHex(Sha256.sum256(blob));\n\n\t\t\tconst fullPath = this.createFullPath(id, partitionKey);\n\n\t\t\tconst dir = path.dirname(fullPath);\n\t\t\tif (!(await this.dirExists(dir))) {\n\t\t\t\tawait mkdir(dir, { recursive: true });\n\t\t\t}\n\n\t\t\tawait writeFile(fullPath, blob);\n\n\t\t\treturn `blob:${new Urn(FileBlobStorageConnector.NAMESPACE, id).toString()}`;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"setBlobFailed\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Get the blob.\n\t * @param id The id of the blob to get in urn format.\n\t * @returns The data for the blob if it can be found or undefined.\n\t */\n\tpublic async get(id: string): Promise<Uint8Array | undefined> {\n\t\tUrn.guard(FileBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== FileBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: FileBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst fullPath = this.createFullPath(urnParsed.namespaceSpecific(1), partitionKey);\n\n\t\t\treturn await readFile(fullPath);\n\t\t} catch (err) {\n\t\t\tif (BaseError.isErrorCode(err, \"ENOENT\")) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"getBlobFailed\", { id }, err);\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 True if the blob was found.\n\t */\n\tpublic async remove(id: string): Promise<boolean> {\n\t\tUrn.guard(FileBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== FileBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: FileBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst fullPath = this.createFullPath(urnParsed.namespaceSpecific(1), partitionKey);\n\n\t\t\tawait unlink(fullPath);\n\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tif (BaseError.isErrorCode(err, \"ENOENT\")) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthrow new GeneralError(FileBlobStorageConnector.CLASS_NAME, \"removeBlobFailed\", { id }, err);\n\t\t}\n\t}\n\n\t/**\n\t * Check if the dir exists.\n\t * @param dir The directory to check.\n\t * @returns True if the dir exists.\n\t * @internal\n\t */\n\tprivate async dirExists(dir: string): Promise<boolean> {\n\t\ttry {\n\t\t\tawait access(dir);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Create the full path for the blob.\n\t * @param id The id of the blob.\n\t * @param partitionKey The partition key.\n\t * @returns The full path for the blob.\n\t * @internal\n\t */\n\tprivate createFullPath(id: string, partitionKey?: string): string {\n\t\tconst partitionPath = Is.stringValue(partitionKey) ? path.join(partitionKey, id) : id;\n\t\treturn path.join(this._directory, `${partitionPath}${this._extension}`);\n\t}\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
|
|
2
|
+
import { type IHealth } from "@twin.org/core";
|
|
2
3
|
import type { IFileBlobStorageConnectorConstructorOptions } from "./models/IFileBlobStorageConnectorConstructorOptions.js";
|
|
3
4
|
/**
|
|
4
5
|
* Class for performing blob storage operations in file.
|
|
@@ -22,6 +23,11 @@ export declare class FileBlobStorageConnector implements IBlobStorageConnector {
|
|
|
22
23
|
* @returns The class name of the component.
|
|
23
24
|
*/
|
|
24
25
|
className(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the health status of the component.
|
|
28
|
+
* @returns The health status of the component.
|
|
29
|
+
*/
|
|
30
|
+
health(): Promise<IHealth[]>;
|
|
25
31
|
/**
|
|
26
32
|
* Bootstrap the component by creating and initializing any resources it needs.
|
|
27
33
|
* @param nodeLoggingComponentType The node logging component type.
|
package/docs/changelog.md
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.0.3-next.
|
|
3
|
+
## [0.0.3-next.9](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.8...blob-storage-connector-file-v0.0.3-next.9) (2026-05-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add context id features ([#30](https://github.com/iotaledger/twin-blob-storage/issues/30)) ([fbf1c92](https://github.com/iotaledger/twin-blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
|
|
9
|
+
* add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
|
|
10
|
+
* eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
|
|
11
|
+
* health checks ([#44](https://github.com/iotaledger/twin-blob-storage/issues/44)) ([4a4041c](https://github.com/iotaledger/twin-blob-storage/commit/4a4041c19b68c40ed1aba6d1cdb4318ac4208b7d))
|
|
12
|
+
* update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
|
|
13
|
+
* update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
|
|
14
|
+
* use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Dependencies
|
|
18
|
+
|
|
19
|
+
* The following workspace dependencies were updated
|
|
20
|
+
* dependencies
|
|
21
|
+
* @twin.org/blob-storage-models bumped from 0.0.3-next.8 to 0.0.3-next.9
|
|
22
|
+
|
|
23
|
+
## [0.0.3-next.8](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.7...blob-storage-connector-file-v0.0.3-next.8) (2026-05-07)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* health checks ([#44](https://github.com/iotaledger/twin-blob-storage/issues/44)) ([4a4041c](https://github.com/iotaledger/twin-blob-storage/commit/4a4041c19b68c40ed1aba6d1cdb4318ac4208b7d))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Dependencies
|
|
32
|
+
|
|
33
|
+
* The following workspace dependencies were updated
|
|
34
|
+
* dependencies
|
|
35
|
+
* @twin.org/blob-storage-models bumped from 0.0.3-next.7 to 0.0.3-next.8
|
|
36
|
+
|
|
37
|
+
## [0.0.3-next.7](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.6...blob-storage-connector-file-v0.0.3-next.7) (2026-02-25)
|
|
4
38
|
|
|
5
39
|
|
|
6
40
|
### Miscellaneous Chores
|
|
@@ -14,7 +48,7 @@
|
|
|
14
48
|
* dependencies
|
|
15
49
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
16
50
|
|
|
17
|
-
## [0.0.3-next.6](https://github.com/
|
|
51
|
+
## [0.0.3-next.6](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.5...blob-storage-connector-file-v0.0.3-next.6) (2026-02-09)
|
|
18
52
|
|
|
19
53
|
|
|
20
54
|
### Miscellaneous Chores
|
|
@@ -28,7 +62,7 @@
|
|
|
28
62
|
* dependencies
|
|
29
63
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.5 to 0.0.3-next.6
|
|
30
64
|
|
|
31
|
-
## [0.0.3-next.5](https://github.com/
|
|
65
|
+
## [0.0.3-next.5](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.4...blob-storage-connector-file-v0.0.3-next.5) (2026-01-26)
|
|
32
66
|
|
|
33
67
|
|
|
34
68
|
### Miscellaneous Chores
|
|
@@ -42,7 +76,7 @@
|
|
|
42
76
|
* dependencies
|
|
43
77
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.4 to 0.0.3-next.5
|
|
44
78
|
|
|
45
|
-
## [0.0.3-next.4](https://github.com/
|
|
79
|
+
## [0.0.3-next.4](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.3...blob-storage-connector-file-v0.0.3-next.4) (2026-01-23)
|
|
46
80
|
|
|
47
81
|
|
|
48
82
|
### Miscellaneous Chores
|
|
@@ -56,7 +90,7 @@
|
|
|
56
90
|
* dependencies
|
|
57
91
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.3 to 0.0.3-next.4
|
|
58
92
|
|
|
59
|
-
## [0.0.3-next.3](https://github.com/
|
|
93
|
+
## [0.0.3-next.3](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.2...blob-storage-connector-file-v0.0.3-next.3) (2026-01-21)
|
|
60
94
|
|
|
61
95
|
|
|
62
96
|
### Miscellaneous Chores
|
|
@@ -70,7 +104,7 @@
|
|
|
70
104
|
* dependencies
|
|
71
105
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.2 to 0.0.3-next.3
|
|
72
106
|
|
|
73
|
-
## [0.0.3-next.2](https://github.com/
|
|
107
|
+
## [0.0.3-next.2](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.1...blob-storage-connector-file-v0.0.3-next.2) (2026-01-14)
|
|
74
108
|
|
|
75
109
|
|
|
76
110
|
### Miscellaneous Chores
|
|
@@ -84,17 +118,17 @@
|
|
|
84
118
|
* dependencies
|
|
85
119
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
86
120
|
|
|
87
|
-
## [0.0.3-next.1](https://github.com/
|
|
121
|
+
## [0.0.3-next.1](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.3-next.0...blob-storage-connector-file-v0.0.3-next.1) (2025-11-11)
|
|
88
122
|
|
|
89
123
|
|
|
90
124
|
### Features
|
|
91
125
|
|
|
92
|
-
* add context id features ([#30](https://github.com/
|
|
93
|
-
* add validate-locales ([f20fcec](https://github.com/
|
|
94
|
-
* eslint migration to flat config ([e4239dd](https://github.com/
|
|
95
|
-
* update dependencies ([56f0094](https://github.com/
|
|
96
|
-
* update framework core ([ff339fe](https://github.com/
|
|
97
|
-
* use shared store mechanism ([#12](https://github.com/
|
|
126
|
+
* add context id features ([#30](https://github.com/iotaledger/twin-blob-storage/issues/30)) ([fbf1c92](https://github.com/iotaledger/twin-blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
|
|
127
|
+
* add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
|
|
128
|
+
* eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
|
|
129
|
+
* update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
|
|
130
|
+
* update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
|
|
131
|
+
* use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
|
|
98
132
|
|
|
99
133
|
|
|
100
134
|
### Dependencies
|
|
@@ -103,12 +137,12 @@
|
|
|
103
137
|
* dependencies
|
|
104
138
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
105
139
|
|
|
106
|
-
## [0.0.2-next.5](https://github.com/
|
|
140
|
+
## [0.0.2-next.5](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.2-next.4...blob-storage-connector-file-v0.0.2-next.5) (2025-10-09)
|
|
107
141
|
|
|
108
142
|
|
|
109
143
|
### Features
|
|
110
144
|
|
|
111
|
-
* add validate-locales ([f20fcec](https://github.com/
|
|
145
|
+
* add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
|
|
112
146
|
|
|
113
147
|
|
|
114
148
|
### Dependencies
|
|
@@ -117,7 +151,7 @@
|
|
|
117
151
|
* dependencies
|
|
118
152
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
119
153
|
|
|
120
|
-
## [0.0.2-next.4](https://github.com/
|
|
154
|
+
## [0.0.2-next.4](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.2-next.3...blob-storage-connector-file-v0.0.2-next.4) (2025-10-02)
|
|
121
155
|
|
|
122
156
|
|
|
123
157
|
### Miscellaneous Chores
|
|
@@ -131,12 +165,12 @@
|
|
|
131
165
|
* dependencies
|
|
132
166
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
133
167
|
|
|
134
|
-
## [0.0.2-next.3](https://github.com/
|
|
168
|
+
## [0.0.2-next.3](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.2-next.2...blob-storage-connector-file-v0.0.2-next.3) (2025-08-29)
|
|
135
169
|
|
|
136
170
|
|
|
137
171
|
### Features
|
|
138
172
|
|
|
139
|
-
* eslint migration to flat config ([e4239dd](https://github.com/
|
|
173
|
+
* eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
|
|
140
174
|
|
|
141
175
|
|
|
142
176
|
### Dependencies
|
|
@@ -145,12 +179,12 @@
|
|
|
145
179
|
* dependencies
|
|
146
180
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
147
181
|
|
|
148
|
-
## [0.0.2-next.2](https://github.com/
|
|
182
|
+
## [0.0.2-next.2](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.2-next.1...blob-storage-connector-file-v0.0.2-next.2) (2025-08-20)
|
|
149
183
|
|
|
150
184
|
|
|
151
185
|
### Features
|
|
152
186
|
|
|
153
|
-
* update framework core ([ff339fe](https://github.com/
|
|
187
|
+
* update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
|
|
154
188
|
|
|
155
189
|
|
|
156
190
|
### Dependencies
|
|
@@ -159,13 +193,13 @@
|
|
|
159
193
|
* dependencies
|
|
160
194
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
161
195
|
|
|
162
|
-
## [0.0.2-next.1](https://github.com/
|
|
196
|
+
## [0.0.2-next.1](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.2-next.0...blob-storage-connector-file-v0.0.2-next.1) (2025-07-24)
|
|
163
197
|
|
|
164
198
|
|
|
165
199
|
### Features
|
|
166
200
|
|
|
167
|
-
* update dependencies ([56f0094](https://github.com/
|
|
168
|
-
* use shared store mechanism ([#12](https://github.com/
|
|
201
|
+
* update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
|
|
202
|
+
* use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
|
|
169
203
|
|
|
170
204
|
|
|
171
205
|
### Dependencies
|
|
@@ -179,7 +213,7 @@
|
|
|
179
213
|
|
|
180
214
|
### Features
|
|
181
215
|
|
|
182
|
-
* release to production ([eacfe75](https://github.com/
|
|
216
|
+
* release to production ([eacfe75](https://github.com/iotaledger/twin-blob-storage/commit/eacfe754a0dcd9243d9e13d86422327d0a605164))
|
|
183
217
|
|
|
184
218
|
|
|
185
219
|
### Dependencies
|
|
@@ -188,7 +222,7 @@
|
|
|
188
222
|
* dependencies
|
|
189
223
|
* @twin.org/blob-storage-models bumped from ^0.0.0 to ^0.0.1
|
|
190
224
|
|
|
191
|
-
## [0.0.1-next.37](https://github.com/
|
|
225
|
+
## [0.0.1-next.37](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.36...blob-storage-connector-file-v0.0.1-next.37) (2025-06-20)
|
|
192
226
|
|
|
193
227
|
|
|
194
228
|
### Miscellaneous Chores
|
|
@@ -202,7 +236,7 @@
|
|
|
202
236
|
* dependencies
|
|
203
237
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.36 to 0.0.1-next.37
|
|
204
238
|
|
|
205
|
-
## [0.0.1-next.36](https://github.com/
|
|
239
|
+
## [0.0.1-next.36](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.35...blob-storage-connector-file-v0.0.1-next.36) (2025-06-19)
|
|
206
240
|
|
|
207
241
|
|
|
208
242
|
### Miscellaneous Chores
|
|
@@ -216,7 +250,7 @@
|
|
|
216
250
|
* dependencies
|
|
217
251
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.35 to 0.0.1-next.36
|
|
218
252
|
|
|
219
|
-
## [0.0.1-next.35](https://github.com/
|
|
253
|
+
## [0.0.1-next.35](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.34...blob-storage-connector-file-v0.0.1-next.35) (2025-06-17)
|
|
220
254
|
|
|
221
255
|
|
|
222
256
|
### Miscellaneous Chores
|
|
@@ -230,12 +264,12 @@
|
|
|
230
264
|
* dependencies
|
|
231
265
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.34 to 0.0.1-next.35
|
|
232
266
|
|
|
233
|
-
## [0.0.1-next.34](https://github.com/
|
|
267
|
+
## [0.0.1-next.34](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.33...blob-storage-connector-file-v0.0.1-next.34) (2025-06-12)
|
|
234
268
|
|
|
235
269
|
|
|
236
270
|
### Features
|
|
237
271
|
|
|
238
|
-
* update dependencies ([56f0094](https://github.com/
|
|
272
|
+
* update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
|
|
239
273
|
|
|
240
274
|
|
|
241
275
|
### Dependencies
|
|
@@ -244,7 +278,7 @@
|
|
|
244
278
|
* dependencies
|
|
245
279
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.33 to 0.0.1-next.34
|
|
246
280
|
|
|
247
|
-
## [0.0.1-next.33](https://github.com/
|
|
281
|
+
## [0.0.1-next.33](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.32...blob-storage-connector-file-v0.0.1-next.33) (2025-06-03)
|
|
248
282
|
|
|
249
283
|
|
|
250
284
|
### Miscellaneous Chores
|
|
@@ -258,7 +292,7 @@
|
|
|
258
292
|
* dependencies
|
|
259
293
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.32 to 0.0.1-next.33
|
|
260
294
|
|
|
261
|
-
## [0.0.1-next.32](https://github.com/
|
|
295
|
+
## [0.0.1-next.32](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.31...blob-storage-connector-file-v0.0.1-next.32) (2025-05-28)
|
|
262
296
|
|
|
263
297
|
|
|
264
298
|
### Miscellaneous Chores
|
|
@@ -272,7 +306,7 @@
|
|
|
272
306
|
* dependencies
|
|
273
307
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.31 to 0.0.1-next.32
|
|
274
308
|
|
|
275
|
-
## [0.0.1-next.31](https://github.com/
|
|
309
|
+
## [0.0.1-next.31](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.30...blob-storage-connector-file-v0.0.1-next.31) (2025-05-08)
|
|
276
310
|
|
|
277
311
|
|
|
278
312
|
### Miscellaneous Chores
|
|
@@ -286,12 +320,12 @@
|
|
|
286
320
|
* dependencies
|
|
287
321
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
|
|
288
322
|
|
|
289
|
-
## [0.0.1-next.30](https://github.com/
|
|
323
|
+
## [0.0.1-next.30](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.29...blob-storage-connector-file-v0.0.1-next.30) (2025-04-17)
|
|
290
324
|
|
|
291
325
|
|
|
292
326
|
### Features
|
|
293
327
|
|
|
294
|
-
* use shared store mechanism ([#12](https://github.com/
|
|
328
|
+
* use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
|
|
295
329
|
|
|
296
330
|
|
|
297
331
|
### Dependencies
|
|
@@ -300,7 +334,7 @@
|
|
|
300
334
|
* dependencies
|
|
301
335
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
|
|
302
336
|
|
|
303
|
-
## [0.0.1-next.29](https://github.com/
|
|
337
|
+
## [0.0.1-next.29](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-file-v0.0.1-next.28...blob-storage-connector-file-v0.0.1-next.29) (2025-03-28)
|
|
304
338
|
|
|
305
339
|
|
|
306
340
|
### Miscellaneous Chores
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# File Connector Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to store blobs on local disk for development, integration testing, or offline processing pipelines.
|
|
4
|
+
|
|
5
|
+
## FileBlobStorageConnector
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { FileBlobStorageConnector } from '@twin.org/blob-storage-connector-file';
|
|
9
|
+
|
|
10
|
+
const connector = new FileBlobStorageConnector({
|
|
11
|
+
config: {
|
|
12
|
+
directory: './local-blob-store',
|
|
13
|
+
extension: '.bin'
|
|
14
|
+
},
|
|
15
|
+
partitionContextIds: ['tenant', 'environment']
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const bootstrapped = await connector.bootstrap();
|
|
19
|
+
console.log(bootstrapped); // true
|
|
20
|
+
console.log(connector.className()); // FileBlobStorageConnector
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Converter } from '@twin.org/core';
|
|
25
|
+
import { FileBlobStorageConnector } from '@twin.org/blob-storage-connector-file';
|
|
26
|
+
|
|
27
|
+
const connector = new FileBlobStorageConnector({
|
|
28
|
+
config: {
|
|
29
|
+
directory: './local-blob-store'
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const blobData = Converter.utf8ToBytes('Local connector payload');
|
|
34
|
+
const blobId = await connector.set(blobData);
|
|
35
|
+
console.log(blobId); // blob:urn:blob:file:...
|
|
36
|
+
|
|
37
|
+
const storedBlob = await connector.get(blobId);
|
|
38
|
+
console.log(storedBlob?.length); // 23
|
|
39
|
+
|
|
40
|
+
const removed = await connector.remove(blobId);
|
|
41
|
+
console.log(removed); // true
|
|
42
|
+
```
|
|
@@ -28,7 +28,7 @@ The options for the connector.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
-
### NAMESPACE
|
|
31
|
+
### NAMESPACE {#namespace}
|
|
32
32
|
|
|
33
33
|
> `readonly` `static` **NAMESPACE**: `string` = `"file"`
|
|
34
34
|
|
|
@@ -36,7 +36,7 @@ The namespace for the items.
|
|
|
36
36
|
|
|
37
37
|
***
|
|
38
38
|
|
|
39
|
-
### CLASS\_NAME
|
|
39
|
+
### CLASS\_NAME {#class_name}
|
|
40
40
|
|
|
41
41
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
42
42
|
|
|
@@ -44,7 +44,7 @@ Runtime name for the class.
|
|
|
44
44
|
|
|
45
45
|
## Methods
|
|
46
46
|
|
|
47
|
-
### className()
|
|
47
|
+
### className() {#classname}
|
|
48
48
|
|
|
49
49
|
> **className**(): `string`
|
|
50
50
|
|
|
@@ -62,7 +62,25 @@ The class name of the component.
|
|
|
62
62
|
|
|
63
63
|
***
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### health() {#health}
|
|
66
|
+
|
|
67
|
+
> **health**(): `Promise`\<`IHealth`[]\>
|
|
68
|
+
|
|
69
|
+
Returns the health status of the component.
|
|
70
|
+
|
|
71
|
+
#### Returns
|
|
72
|
+
|
|
73
|
+
`Promise`\<`IHealth`[]\>
|
|
74
|
+
|
|
75
|
+
The health status of the component.
|
|
76
|
+
|
|
77
|
+
#### Implementation of
|
|
78
|
+
|
|
79
|
+
`IBlobStorageConnector.health`
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### bootstrap() {#bootstrap}
|
|
66
84
|
|
|
67
85
|
> **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
|
|
68
86
|
|
|
@@ -88,7 +106,7 @@ True if the bootstrapping process was successful.
|
|
|
88
106
|
|
|
89
107
|
***
|
|
90
108
|
|
|
91
|
-
### set()
|
|
109
|
+
### set() {#set}
|
|
92
110
|
|
|
93
111
|
> **set**(`blob`): `Promise`\<`string`\>
|
|
94
112
|
|
|
@@ -114,7 +132,7 @@ The id of the stored blob in urn format.
|
|
|
114
132
|
|
|
115
133
|
***
|
|
116
134
|
|
|
117
|
-
### get()
|
|
135
|
+
### get() {#get}
|
|
118
136
|
|
|
119
137
|
> **get**(`id`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
|
|
120
138
|
|
|
@@ -140,7 +158,7 @@ The data for the blob if it can be found or undefined.
|
|
|
140
158
|
|
|
141
159
|
***
|
|
142
160
|
|
|
143
|
-
### remove()
|
|
161
|
+
### remove() {#remove}
|
|
144
162
|
|
|
145
163
|
> **remove**(`id`): `Promise`\<`boolean`\>
|
|
146
164
|
|
|
@@ -4,7 +4,7 @@ Configuration for the File Blob Storage Connector.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### directory
|
|
7
|
+
### directory {#directory}
|
|
8
8
|
|
|
9
9
|
> **directory**: `string`
|
|
10
10
|
|
|
@@ -12,8 +12,8 @@ The directory to use for storage.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### extension?
|
|
15
|
+
### extension? {#extension}
|
|
16
16
|
|
|
17
|
-
> `optional` **extension
|
|
17
|
+
> `optional` **extension?**: `string`
|
|
18
18
|
|
|
19
19
|
The extension to add to files when they are stored.
|
|
@@ -4,15 +4,15 @@ Options for the File Blob Storage Connector constructor.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### partitionContextIds?
|
|
7
|
+
### partitionContextIds? {#partitioncontextids}
|
|
8
8
|
|
|
9
|
-
> `optional` **partitionContextIds
|
|
9
|
+
> `optional` **partitionContextIds?**: `string`[]
|
|
10
10
|
|
|
11
11
|
The keys to use from the context ids to create partitions.
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### config
|
|
15
|
+
### config {#config}
|
|
16
16
|
|
|
17
17
|
> **config**: [`IFileBlobStorageConnectorConfig`](IFileBlobStorageConnectorConfig.md)
|
|
18
18
|
|
package/locales/en.json
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
"directoryExists": "Skipping create directory \"{directory}\" as it already exists"
|
|
6
6
|
}
|
|
7
7
|
},
|
|
8
|
+
"health": {
|
|
9
|
+
"fileBlobStorageConnector": {
|
|
10
|
+
"healthDescription": "File blob storage connector is healthy",
|
|
11
|
+
"healthCheckFailed": "Failed to access the storage directory"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
8
14
|
"error": {
|
|
9
15
|
"fileBlobStorageConnector": {
|
|
10
16
|
"directoryCreateFailed": "Creating directory \"{directory}\" failed",
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/blob-storage-connector-file",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.9",
|
|
4
|
+
"description": "Persists blobs to local directories or mounted volumes through a file system connector.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/blob-storage.git",
|
|
8
8
|
"directory": "packages/blob-storage-connector-file"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/blob-storage-models": "0.0.3-next.
|
|
17
|
+
"@twin.org/blob-storage-models": "0.0.3-next.9",
|
|
18
18
|
"@twin.org/context": "next",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/crypto": "next",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"integration"
|
|
54
54
|
],
|
|
55
55
|
"bugs": {
|
|
56
|
-
"url": "git+https://github.com/
|
|
56
|
+
"url": "git+https://github.com/iotaledger/blob-storage/issues"
|
|
57
57
|
},
|
|
58
58
|
"homepage": "https://twindev.org"
|
|
59
59
|
}
|