@twin.org/blob-storage-connector-memory 0.0.2-next.5 → 0.0.3-next.2

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"]}
@@ -1,10 +1,10 @@
1
- import { Guards, Converter, Urn, GeneralError } from '@twin.org/core';
2
- import { Sha256 } from '@twin.org/crypto';
3
-
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
4
  /**
5
5
  * Class for performing blob storage operations in-memory.
6
6
  */
7
- class MemoryBlobStorageConnector {
7
+ export class MemoryBlobStorageConnector {
8
8
  /**
9
9
  * The namespace for the items.
10
10
  */
@@ -13,6 +13,11 @@ class MemoryBlobStorageConnector {
13
13
  * Runtime name for the class.
14
14
  */
15
15
  static CLASS_NAME = "MemoryBlobStorageConnector";
16
+ /**
17
+ * The keys to use from the context ids to create partitions.
18
+ * @internal
19
+ */
20
+ _partitionContextIds;
16
21
  /**
17
22
  * The storage for the in-memory items.
18
23
  * @internal
@@ -20,10 +25,19 @@ class MemoryBlobStorageConnector {
20
25
  _store;
21
26
  /**
22
27
  * Create a new instance of MemoryBlobStorageConnector.
28
+ * @param options The options for the connector.
23
29
  */
24
- constructor() {
30
+ constructor(options) {
31
+ this._partitionContextIds = options?.partitionContextIds;
25
32
  this._store = {};
26
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
+ }
27
41
  /**
28
42
  * Set the blob.
29
43
  * @param blob The data for the blob.
@@ -31,8 +45,11 @@ class MemoryBlobStorageConnector {
31
45
  */
32
46
  async set(blob) {
33
47
  Guards.uint8Array(MemoryBlobStorageConnector.CLASS_NAME, "blob", blob);
48
+ const contextIds = await ContextIdStore.getContextIds();
49
+ const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
34
50
  const id = Converter.bytesToHex(Sha256.sum256(blob));
35
- this._store[id] = blob;
51
+ const fullKey = `${partitionKey ?? "root"}/${id}`;
52
+ this._store[fullKey] = blob;
36
53
  return `blob:${new Urn(MemoryBlobStorageConnector.NAMESPACE, id).toString()}`;
37
54
  }
38
55
  /**
@@ -42,6 +59,8 @@ class MemoryBlobStorageConnector {
42
59
  */
43
60
  async get(id) {
44
61
  Urn.guard(MemoryBlobStorageConnector.CLASS_NAME, "id", id);
62
+ const contextIds = await ContextIdStore.getContextIds();
63
+ const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
45
64
  const urnParsed = Urn.fromValidString(id);
46
65
  if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
47
66
  throw new GeneralError(MemoryBlobStorageConnector.CLASS_NAME, "namespaceMismatch", {
@@ -49,7 +68,9 @@ class MemoryBlobStorageConnector {
49
68
  id
50
69
  });
51
70
  }
52
- return this._store[urnParsed.namespaceSpecific(1)];
71
+ const namespaceId = urnParsed.namespaceSpecific(1);
72
+ const fullKey = `${partitionKey ?? "root"}/${namespaceId}`;
73
+ return this._store[fullKey];
53
74
  }
54
75
  /**
55
76
  * Remove the blob.
@@ -58,6 +79,8 @@ class MemoryBlobStorageConnector {
58
79
  */
59
80
  async remove(id) {
60
81
  Urn.guard(MemoryBlobStorageConnector.CLASS_NAME, "id", id);
82
+ const contextIds = await ContextIdStore.getContextIds();
83
+ const partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);
61
84
  const urnParsed = Urn.fromValidString(id);
62
85
  if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
63
86
  throw new GeneralError(MemoryBlobStorageConnector.CLASS_NAME, "namespaceMismatch", {
@@ -66,8 +89,9 @@ class MemoryBlobStorageConnector {
66
89
  });
67
90
  }
68
91
  const namespaceId = urnParsed.namespaceSpecific(1);
69
- if (this._store[namespaceId]) {
70
- delete this._store[namespaceId];
92
+ const fullKey = `${partitionKey ?? "root"}/${namespaceId}`;
93
+ if (this._store[fullKey]) {
94
+ delete this._store[fullKey];
71
95
  return true;
72
96
  }
73
97
  return false;
@@ -80,5 +104,4 @@ class MemoryBlobStorageConnector {
80
104
  return this._store;
81
105
  }
82
106
  }
83
-
84
- export { MemoryBlobStorageConnector };
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,M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AAM,CAAC,OAAO,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,QAAQ;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBlobStorageConnector } from \"@twin.org/blob-storage-models\";\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
  */
@@ -13,8 +14,14 @@ export declare class MemoryBlobStorageConnector implements IBlobStorageConnector
13
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.2](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-memory-v0.0.3-next.1...blob-storage-connector-memory-v0.0.3-next.2) (2026-01-14)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **blob-storage-connector-memory:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
16
+
17
+ ## [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * add context id features ([#30](https://github.com/twinfoundation/blob-storage/issues/30)) ([fbf1c92](https://github.com/twinfoundation/blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
23
+ * add validate-locales ([f20fcec](https://github.com/twinfoundation/blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
24
+ * eslint migration to flat config ([e4239dd](https://github.com/twinfoundation/blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
25
+ * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
26
+ * update framework core ([ff339fe](https://github.com/twinfoundation/blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
27
+ * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
35
+
3
36
  ## [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)
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`
@@ -36,6 +44,24 @@ Runtime name for the class.
36
44
 
37
45
  ## Methods
38
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
+
59
+ #### Implementation of
60
+
61
+ `IBlobStorageConnector.className`
62
+
63
+ ***
64
+
39
65
  ### set()
40
66
 
41
67
  > **set**(`blob`): `Promise`\<`string`\>
@@ -64,7 +90,7 @@ The id of the stored blob in urn format.
64
90
 
65
91
  ### get()
66
92
 
67
- > **get**(`id`): `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
93
+ > **get**(`id`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
68
94
 
69
95
  Get the blob.
70
96
 
@@ -78,7 +104,7 @@ The id of the blob to get in urn format.
78
104
 
79
105
  #### Returns
80
106
 
81
- `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
107
+ `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
82
108
 
83
109
  The data for the blob if it can be found or undefined.
84
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.5",
3
+ "version": "0.0.3-next.2",
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.5",
17
+ "@twin.org/blob-storage-models": "0.0.3-next.2",
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"
@@ -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
- static 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(MemoryBlobStorageConnector.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(MemoryBlobStorageConnector.CLASS_NAME, "id", id);
47
- const urnParsed = core.Urn.fromValidString(id);
48
- if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
49
- throw new core.GeneralError(MemoryBlobStorageConnector.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(MemoryBlobStorageConnector.CLASS_NAME, "id", id);
63
- const urnParsed = core.Urn.fromValidString(id);
64
- if (urnParsed.namespaceMethod() !== MemoryBlobStorageConnector.NAMESPACE) {
65
- throw new core.GeneralError(MemoryBlobStorageConnector.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;