@twin.org/blob-storage-connector-memory 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.
@@ -0,0 +1,5 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./memoryBlobStorageConnector.js";
4
+ export * from "./models/IMemoryStorageConnectorConstructorOptions.js";
5
+ //# 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,iCAAiC,CAAC;AAChD,cAAc,uDAAuD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./memoryBlobStorageConnector.js\";\nexport * from \"./models/IMemoryStorageConnectorConstructorOptions.js\";\n"]}
@@ -0,0 +1,107 @@
1
+ import { ContextIdHelper, ContextIdStore } from "@twin.org/context";
2
+ import { Converter, GeneralError, Guards, Urn } from "@twin.org/core";
3
+ import { Sha256 } from "@twin.org/crypto";
4
+ /**
5
+ * Class for performing blob storage operations in-memory.
6
+ */
7
+ export class MemoryBlobStorageConnector {
8
+ /**
9
+ * The namespace for the items.
10
+ */
11
+ static NAMESPACE = "memory";
12
+ /**
13
+ * Runtime name for the class.
14
+ */
15
+ static CLASS_NAME = "MemoryBlobStorageConnector";
16
+ /**
17
+ * The keys to use from the context ids to create partitions.
18
+ * @internal
19
+ */
20
+ _partitionContextIds;
21
+ /**
22
+ * The storage for the in-memory items.
23
+ * @internal
24
+ */
25
+ _store;
26
+ /**
27
+ * Create a new instance of MemoryBlobStorageConnector.
28
+ * @param options The options for the connector.
29
+ */
30
+ constructor(options) {
31
+ this._partitionContextIds = options?.partitionContextIds;
32
+ this._store = {};
33
+ }
34
+ /**
35
+ * Returns the class name of the component.
36
+ * @returns The class name of the component.
37
+ */
38
+ className() {
39
+ return MemoryBlobStorageConnector.CLASS_NAME;
40
+ }
41
+ /**
42
+ * Set the blob.
43
+ * @param blob The data for the blob.
44
+ * @returns The id of the stored blob in urn format.
45
+ */
46
+ async set(blob) {
47
+ Guards.uint8Array(MemoryBlobStorageConnector.CLASS_NAME, "blob", blob);
48
+ const contextIds = await ContextIdStore.getContextIds();
49
+ const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
50
+ const id = Converter.bytesToHex(Sha256.sum256(blob));
51
+ const fullKey = `${partitionKey ?? "root"}/${id}`;
52
+ this._store[fullKey] = blob;
53
+ return `blob:${new Urn(MemoryBlobStorageConnector.NAMESPACE, id).toString()}`;
54
+ }
55
+ /**
56
+ * Get the blob.
57
+ * @param id The id of the blob to get in urn format.
58
+ * @returns The data for the blob if it can be found or undefined.
59
+ */
60
+ async get(id) {
61
+ Urn.guard(MemoryBlobStorageConnector.CLASS_NAME, "id", id);
62
+ const contextIds = await ContextIdStore.getContextIds();
63
+ const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
64
+ const urnParsed = Urn.fromValidString(id);
65
+ if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
66
+ throw new GeneralError(MemoryBlobStorageConnector.CLASS_NAME, "namespaceMismatch", {
67
+ namespace: MemoryBlobStorageConnector.NAMESPACE,
68
+ id
69
+ });
70
+ }
71
+ const namespaceId = urnParsed.namespaceSpecific(1);
72
+ const fullKey = `${partitionKey ?? "root"}/${namespaceId}`;
73
+ return this._store[fullKey];
74
+ }
75
+ /**
76
+ * Remove the blob.
77
+ * @param id The id of the blob to remove in urn format.
78
+ * @returns True if the blob was found.
79
+ */
80
+ async remove(id) {
81
+ Urn.guard(MemoryBlobStorageConnector.CLASS_NAME, "id", id);
82
+ const contextIds = await ContextIdStore.getContextIds();
83
+ const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
84
+ const urnParsed = Urn.fromValidString(id);
85
+ if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
86
+ throw new GeneralError(MemoryBlobStorageConnector.CLASS_NAME, "namespaceMismatch", {
87
+ namespace: MemoryBlobStorageConnector.NAMESPACE,
88
+ id
89
+ });
90
+ }
91
+ const namespaceId = urnParsed.namespaceSpecific(1);
92
+ const fullKey = `${partitionKey ?? "root"}/${namespaceId}`;
93
+ if (this._store[fullKey]) {
94
+ delete this._store[fullKey];
95
+ return true;
96
+ }
97
+ return false;
98
+ }
99
+ /**
100
+ * Get the memory store.
101
+ * @returns The store.
102
+ */
103
+ getStore() {
104
+ return this._store;
105
+ }
106
+ }
107
+ //# sourceMappingURL=memoryBlobStorageConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryBlobStorageConnector.js","sourceRoot":"","sources":["../../src/memoryBlobStorageConnector.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1C;;GAEG;AACH,MAAM,OAAO,0BAA0B;IACtC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,QAAQ,CAAC;IAEpD;;OAEG;IACI,MAAM,CAAU,UAAU,gCAAgD;IAEjF;;;OAGG;IACc,oBAAoB,CAAY;IAEjD;;;OAGG;IACc,MAAM,CAA+B;IAEtD;;;OAGG;IACH,YAAY,OAAmD;QAC9D,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,mBAAmB,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IAClB,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,0BAA0B,CAAC,UAAU,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,GAAG,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";\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport { Converter, GeneralError, Guards, Urn } from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IMemoryStorageConnectorConstructorOptions } from \"./models/IMemoryStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing blob storage operations in-memory.\n */\nexport class MemoryBlobStorageConnector implements IBlobStorageConnector {\n\t/**\n\t * The namespace for the items.\n\t */\n\tpublic static readonly NAMESPACE: string = \"memory\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MemoryBlobStorageConnector>();\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 * The storage for the in-memory items.\n\t * @internal\n\t */\n\tprivate readonly _store: { [id: string]: Uint8Array };\n\n\t/**\n\t * Create a new instance of MemoryBlobStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: IMemoryStorageConnectorConstructorOptions) {\n\t\tthis._partitionContextIds = options?.partitionContextIds;\n\t\tthis._store = {};\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 MemoryBlobStorageConnector.CLASS_NAME;\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(MemoryBlobStorageConnector.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\tconst id = Converter.bytesToHex(Sha256.sum256(blob));\n\n\t\tconst fullKey = `${partitionKey ?? \"root\"}/${id}`;\n\t\tthis._store[fullKey] = blob;\n\n\t\treturn `blob:${new Urn(MemoryBlobStorageConnector.NAMESPACE, id).toString()}`;\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(MemoryBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(MemoryBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: MemoryBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\tconst namespaceId = urnParsed.namespaceSpecific(1);\n\t\tconst fullKey = `${partitionKey ?? \"root\"}/${namespaceId}`;\n\t\treturn this._store[fullKey];\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(MemoryBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(MemoryBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: MemoryBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\tconst namespaceId = urnParsed.namespaceSpecific(1);\n\t\tconst fullKey = `${partitionKey ?? \"root\"}/${namespaceId}`;\n\t\tif (this._store[fullKey]) {\n\t\t\tdelete this._store[fullKey];\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Get the memory store.\n\t * @returns The store.\n\t */\n\tpublic getStore(): { [id: string]: Uint8Array } {\n\t\treturn this._store;\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IMemoryStorageConnectorConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IMemoryStorageConnectorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IMemoryStorageConnectorConstructorOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Options for the Memory Blob Storage Connector constructor.\n */\nexport interface IMemoryStorageConnectorConstructorOptions {\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t */\n\tpartitionContextIds?: string[];\n}\n"]}
@@ -1 +1,2 @@
1
- export * from "./memoryBlobStorageConnector";
1
+ export * from "./memoryBlobStorageConnector.js";
2
+ export * from "./models/IMemoryStorageConnectorConstructorOptions.js";
@@ -1,4 +1,5 @@
1
1
  import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
2
+ import type { IMemoryStorageConnectorConstructorOptions } from "./models/IMemoryStorageConnectorConstructorOptions.js";
2
3
  /**
3
4
  * Class for performing blob storage operations in-memory.
4
5
  */
@@ -10,11 +11,17 @@ export declare class MemoryBlobStorageConnector implements IBlobStorageConnector
10
11
  /**
11
12
  * Runtime name for the class.
12
13
  */
13
- readonly CLASS_NAME: string;
14
+ static readonly CLASS_NAME: string;
14
15
  /**
15
16
  * Create a new instance of MemoryBlobStorageConnector.
17
+ * @param options The options for the connector.
16
18
  */
17
- constructor();
19
+ constructor(options?: IMemoryStorageConnectorConstructorOptions);
20
+ /**
21
+ * Returns the class name of the component.
22
+ * @returns The class name of the component.
23
+ */
24
+ className(): string;
18
25
  /**
19
26
  * Set the blob.
20
27
  * @param blob The data for the blob.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Options for the Memory Blob Storage Connector constructor.
3
+ */
4
+ export interface IMemoryStorageConnectorConstructorOptions {
5
+ /**
6
+ * The keys to use from the context ids to create partitions.
7
+ */
8
+ partitionContextIds?: string[];
9
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @twin.org/blob-storage-connector-memory - Changelog
2
2
 
3
+ ## [0.0.3-next.1](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-memory-v0.0.3-next.0...blob-storage-connector-memory-v0.0.3-next.1) (2025-11-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * add context id features ([#30](https://github.com/twinfoundation/blob-storage/issues/30)) ([fbf1c92](https://github.com/twinfoundation/blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
9
+ * add validate-locales ([f20fcec](https://github.com/twinfoundation/blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
10
+ * eslint migration to flat config ([e4239dd](https://github.com/twinfoundation/blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
11
+ * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
12
+ * update framework core ([ff339fe](https://github.com/twinfoundation/blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
13
+ * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * The following workspace dependencies were updated
19
+ * dependencies
20
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
21
+
22
+ ## [0.0.2-next.5](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-memory-v0.0.2-next.4...blob-storage-connector-memory-v0.0.2-next.5) (2025-10-09)
23
+
24
+
25
+ ### Features
26
+
27
+ * add validate-locales ([f20fcec](https://github.com/twinfoundation/blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/blob-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
35
+
3
36
  ## [0.0.2-next.4](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-memory-v0.0.2-next.3...blob-storage-connector-memory-v0.0.2-next.4) (2025-10-02)
4
37
 
5
38
 
@@ -10,10 +10,18 @@ Class for performing blob storage operations in-memory.
10
10
 
11
11
  ### Constructor
12
12
 
13
- > **new MemoryBlobStorageConnector**(): `MemoryBlobStorageConnector`
13
+ > **new MemoryBlobStorageConnector**(`options?`): `MemoryBlobStorageConnector`
14
14
 
15
15
  Create a new instance of MemoryBlobStorageConnector.
16
16
 
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`IMemoryStorageConnectorConstructorOptions`](../interfaces/IMemoryStorageConnectorConstructorOptions.md)
22
+
23
+ The options for the connector.
24
+
17
25
  #### Returns
18
26
 
19
27
  `MemoryBlobStorageConnector`
@@ -30,15 +38,29 @@ The namespace for the items.
30
38
 
31
39
  ### CLASS\_NAME
32
40
 
33
- > `readonly` **CLASS\_NAME**: `string`
41
+ > `readonly` `static` **CLASS\_NAME**: `string`
34
42
 
35
43
  Runtime name for the class.
36
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
+
37
59
  #### Implementation of
38
60
 
39
- `IBlobStorageConnector.CLASS_NAME`
61
+ `IBlobStorageConnector.className`
40
62
 
41
- ## Methods
63
+ ***
42
64
 
43
65
  ### set()
44
66
 
@@ -68,7 +90,7 @@ The id of the stored blob in urn format.
68
90
 
69
91
  ### get()
70
92
 
71
- > **get**(`id`): `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
93
+ > **get**(`id`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
72
94
 
73
95
  Get the blob.
74
96
 
@@ -82,7 +104,7 @@ The id of the blob to get in urn format.
82
104
 
83
105
  #### Returns
84
106
 
85
- `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
107
+ `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
86
108
 
87
109
  The data for the blob if it can be found or undefined.
88
110
 
@@ -3,3 +3,7 @@
3
3
  ## Classes
4
4
 
5
5
  - [MemoryBlobStorageConnector](classes/MemoryBlobStorageConnector.md)
6
+
7
+ ## Interfaces
8
+
9
+ - [IMemoryStorageConnectorConstructorOptions](interfaces/IMemoryStorageConnectorConstructorOptions.md)
@@ -0,0 +1,11 @@
1
+ # Interface: IMemoryStorageConnectorConstructorOptions
2
+
3
+ Options for the Memory Blob Storage Connector constructor.
4
+
5
+ ## Properties
6
+
7
+ ### partitionContextIds?
8
+
9
+ > `optional` **partitionContextIds**: `string`[]
10
+
11
+ The keys to use from the context ids to create partitions.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/blob-storage-connector-memory",
3
- "version": "0.0.2-next.4",
3
+ "version": "0.0.3-next.1",
4
4
  "description": "Blob Storage connector implementation using in-memory storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,25 +14,24 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/blob-storage-models": "0.0.2-next.4",
17
+ "@twin.org/blob-storage-models": "0.0.3-next.1",
18
+ "@twin.org/context": "next",
18
19
  "@twin.org/core": "next",
19
20
  "@twin.org/crypto": "next",
20
21
  "@twin.org/nameof": "next"
21
22
  },
22
- "main": "./dist/cjs/index.cjs",
23
- "module": "./dist/esm/index.mjs",
23
+ "main": "./dist/es/index.js",
24
24
  "types": "./dist/types/index.d.ts",
25
25
  "exports": {
26
26
  ".": {
27
27
  "types": "./dist/types/index.d.ts",
28
- "require": "./dist/cjs/index.cjs",
29
- "import": "./dist/esm/index.mjs"
28
+ "import": "./dist/es/index.js",
29
+ "default": "./dist/es/index.js"
30
30
  },
31
31
  "./locales/*.json": "./locales/*.json"
32
32
  },
33
33
  "files": [
34
- "dist/cjs",
35
- "dist/esm",
34
+ "dist/es",
36
35
  "dist/types",
37
36
  "locales",
38
37
  "docs"
@@ -54,5 +53,9 @@
54
53
  "memory",
55
54
  "in-memory",
56
55
  "testing"
57
- ]
56
+ ],
57
+ "bugs": {
58
+ "url": "git+https://github.com/twinfoundation/blob-storage/issues"
59
+ },
60
+ "homepage": "https://twindev.org"
58
61
  }
@@ -1,86 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@twin.org/core');
4
- var crypto = require('@twin.org/crypto');
5
-
6
- /**
7
- * Class for performing blob storage operations in-memory.
8
- */
9
- class MemoryBlobStorageConnector {
10
- /**
11
- * The namespace for the items.
12
- */
13
- static NAMESPACE = "memory";
14
- /**
15
- * Runtime name for the class.
16
- */
17
- CLASS_NAME = "MemoryBlobStorageConnector";
18
- /**
19
- * The storage for the in-memory items.
20
- * @internal
21
- */
22
- _store;
23
- /**
24
- * Create a new instance of MemoryBlobStorageConnector.
25
- */
26
- constructor() {
27
- this._store = {};
28
- }
29
- /**
30
- * Set the blob.
31
- * @param blob The data for the blob.
32
- * @returns The id of the stored blob in urn format.
33
- */
34
- async set(blob) {
35
- core.Guards.uint8Array(this.CLASS_NAME, "blob", blob);
36
- const id = core.Converter.bytesToHex(crypto.Sha256.sum256(blob));
37
- this._store[id] = blob;
38
- return `blob:${new core.Urn(MemoryBlobStorageConnector.NAMESPACE, id).toString()}`;
39
- }
40
- /**
41
- * Get the blob.
42
- * @param id The id of the blob to get in urn format.
43
- * @returns The data for the blob if it can be found or undefined.
44
- */
45
- async get(id) {
46
- core.Urn.guard(this.CLASS_NAME, "id", id);
47
- const urnParsed = core.Urn.fromValidString(id);
48
- if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
49
- throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
50
- namespace: MemoryBlobStorageConnector.NAMESPACE,
51
- id
52
- });
53
- }
54
- return this._store[urnParsed.namespaceSpecific(1)];
55
- }
56
- /**
57
- * Remove the blob.
58
- * @param id The id of the blob to remove in urn format.
59
- * @returns True if the blob was found.
60
- */
61
- async remove(id) {
62
- core.Urn.guard(this.CLASS_NAME, "id", id);
63
- const urnParsed = core.Urn.fromValidString(id);
64
- if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
65
- throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
66
- namespace: MemoryBlobStorageConnector.NAMESPACE,
67
- id
68
- });
69
- }
70
- const namespaceId = urnParsed.namespaceSpecific(1);
71
- if (this._store[namespaceId]) {
72
- delete this._store[namespaceId];
73
- return true;
74
- }
75
- return false;
76
- }
77
- /**
78
- * Get the memory store.
79
- * @returns The store.
80
- */
81
- getStore() {
82
- return this._store;
83
- }
84
- }
85
-
86
- exports.MemoryBlobStorageConnector = MemoryBlobStorageConnector;
@@ -1,84 +0,0 @@
1
- import { Guards, Converter, Urn, GeneralError } from '@twin.org/core';
2
- import { Sha256 } from '@twin.org/crypto';
3
-
4
- /**
5
- * Class for performing blob storage operations in-memory.
6
- */
7
- class MemoryBlobStorageConnector {
8
- /**
9
- * The namespace for the items.
10
- */
11
- static NAMESPACE = "memory";
12
- /**
13
- * Runtime name for the class.
14
- */
15
- CLASS_NAME = "MemoryBlobStorageConnector";
16
- /**
17
- * The storage for the in-memory items.
18
- * @internal
19
- */
20
- _store;
21
- /**
22
- * Create a new instance of MemoryBlobStorageConnector.
23
- */
24
- constructor() {
25
- this._store = {};
26
- }
27
- /**
28
- * Set the blob.
29
- * @param blob The data for the blob.
30
- * @returns The id of the stored blob in urn format.
31
- */
32
- async set(blob) {
33
- Guards.uint8Array(this.CLASS_NAME, "blob", blob);
34
- const id = Converter.bytesToHex(Sha256.sum256(blob));
35
- this._store[id] = blob;
36
- return `blob:${new Urn(MemoryBlobStorageConnector.NAMESPACE, id).toString()}`;
37
- }
38
- /**
39
- * Get the blob.
40
- * @param id The id of the blob to get in urn format.
41
- * @returns The data for the blob if it can be found or undefined.
42
- */
43
- async get(id) {
44
- Urn.guard(this.CLASS_NAME, "id", id);
45
- const urnParsed = Urn.fromValidString(id);
46
- if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
47
- throw new GeneralError(this.CLASS_NAME, "namespaceMismatch", {
48
- namespace: MemoryBlobStorageConnector.NAMESPACE,
49
- id
50
- });
51
- }
52
- return this._store[urnParsed.namespaceSpecific(1)];
53
- }
54
- /**
55
- * Remove the blob.
56
- * @param id The id of the blob to remove in urn format.
57
- * @returns True if the blob was found.
58
- */
59
- async remove(id) {
60
- Urn.guard(this.CLASS_NAME, "id", id);
61
- const urnParsed = Urn.fromValidString(id);
62
- if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
63
- throw new GeneralError(this.CLASS_NAME, "namespaceMismatch", {
64
- namespace: MemoryBlobStorageConnector.NAMESPACE,
65
- id
66
- });
67
- }
68
- const namespaceId = urnParsed.namespaceSpecific(1);
69
- if (this._store[namespaceId]) {
70
- delete this._store[namespaceId];
71
- return true;
72
- }
73
- return false;
74
- }
75
- /**
76
- * Get the memory store.
77
- * @returns The store.
78
- */
79
- getStore() {
80
- return this._store;
81
- }
82
- }
83
-
84
- export { MemoryBlobStorageConnector };