@metamask-previews/storage-service 1.0.2-preview-3866c0ff1 → 1.0.2-preview-e3275932a

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/InMemoryStorageAdapter.cjs +148 -0
  3. package/dist/InMemoryStorageAdapter.cjs.map +1 -0
  4. package/dist/{InMemoryStorageAdapter.d.ts → InMemoryStorageAdapter.d.cts} +3 -3
  5. package/dist/InMemoryStorageAdapter.d.cts.map +1 -0
  6. package/dist/InMemoryStorageAdapter.d.mts +88 -0
  7. package/dist/InMemoryStorageAdapter.d.mts.map +1 -0
  8. package/dist/{InMemoryStorageAdapter.js → InMemoryStorageAdapter.mjs} +28 -15
  9. package/dist/InMemoryStorageAdapter.mjs.map +1 -0
  10. package/dist/StorageService-method-action-types.cjs +7 -0
  11. package/dist/StorageService-method-action-types.cjs.map +1 -0
  12. package/dist/{StorageService-method-action-types.d.ts → StorageService-method-action-types.d.cts} +2 -2
  13. package/dist/StorageService-method-action-types.d.cts.map +1 -0
  14. package/dist/StorageService-method-action-types.d.mts +78 -0
  15. package/dist/StorageService-method-action-types.d.mts.map +1 -0
  16. package/dist/{StorageService-method-action-types.js → StorageService-method-action-types.mjs} +1 -1
  17. package/dist/StorageService-method-action-types.mjs.map +1 -0
  18. package/dist/StorageService.cjs +203 -0
  19. package/dist/StorageService.cjs.map +1 -0
  20. package/dist/{StorageService.d.ts → StorageService.d.cts} +4 -4
  21. package/dist/StorageService.d.cts.map +1 -0
  22. package/dist/{StorageService.js → StorageService.d.mts} +13 -55
  23. package/dist/StorageService.d.mts.map +1 -0
  24. package/dist/StorageService.mjs +199 -0
  25. package/dist/StorageService.mjs.map +1 -0
  26. package/dist/index.cjs +14 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.cts +6 -0
  29. package/dist/index.d.cts.map +1 -0
  30. package/dist/index.d.mts +6 -0
  31. package/dist/index.d.mts.map +1 -0
  32. package/dist/index.mjs +7 -0
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/types.cjs +12 -0
  35. package/dist/types.cjs.map +1 -0
  36. package/dist/{types.d.ts → types.d.cts} +4 -4
  37. package/dist/types.d.cts.map +1 -0
  38. package/dist/types.d.mts +186 -0
  39. package/dist/types.d.mts.map +1 -0
  40. package/dist/{types.js → types.mjs} +1 -1
  41. package/dist/types.mjs.map +1 -0
  42. package/package.json +16 -12
  43. package/dist/InMemoryStorageAdapter.d.ts.map +0 -1
  44. package/dist/InMemoryStorageAdapter.js.map +0 -1
  45. package/dist/StorageService-method-action-types.d.ts.map +0 -1
  46. package/dist/StorageService-method-action-types.js.map +0 -1
  47. package/dist/StorageService.d.ts.map +0 -1
  48. package/dist/StorageService.js.map +0 -1
  49. package/dist/index.d.ts +0 -6
  50. package/dist/index.d.ts.map +0 -1
  51. package/dist/index.js +0 -7
  52. package/dist/index.js.map +0 -1
  53. package/dist/types.d.ts.map +0 -1
  54. package/dist/types.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
- - **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
13
12
  - Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
14
13
  - Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))
15
14
 
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _InMemoryStorageAdapter_storage;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.InMemoryStorageAdapter = void 0;
16
+ const types_js_1 = require("./types.cjs");
17
+ /**
18
+ * In-memory storage adapter (default fallback).
19
+ * Implements the {@link StorageAdapter} interface using a Map.
20
+ *
21
+ * ⚠️ **Warning**: Data is NOT persisted - lost on restart.
22
+ *
23
+ * **Suitable for:**
24
+ * - Testing (isolated, no mocking needed)
25
+ * - Development (quick start, zero config)
26
+ * - Temporary/ephemeral data
27
+ *
28
+ * **Not suitable for:**
29
+ * - Production (unless data is truly ephemeral)
30
+ * - Data that needs to persist across restarts
31
+ *
32
+ * @example Basic usage
33
+ * ```typescript
34
+ * const adapter = new InMemoryStorageAdapter();
35
+ * await adapter.setItem('SnapController', 'snap-id:sourceCode', 'const x = 1;');
36
+ * const value = await adapter.getItem('SnapController', 'snap-id:sourceCode'); // 'const x = 1;'
37
+ * // After restart: data is lost
38
+ * ```
39
+ *
40
+ * @example Initialize with data (useful for testing)
41
+ * ```typescript
42
+ * const adapter = new InMemoryStorageAdapter({
43
+ * SnapController: {
44
+ * 'snap-id:sourceCode': 'const x = 1;',
45
+ * 'snap-id:manifest': { name: 'My Snap' },
46
+ * },
47
+ * TokenListController: {
48
+ * cache: { '0x1': ['token1', 'token2'] },
49
+ * },
50
+ * });
51
+ * ```
52
+ */
53
+ class InMemoryStorageAdapter {
54
+ /**
55
+ * Constructs a new InMemoryStorageAdapter.
56
+ *
57
+ * @param initialData - Optional initial data to populate the storage.
58
+ * Useful for setting up test fixtures without calling setItem multiple times.
59
+ */
60
+ constructor(initialData) {
61
+ // Explicitly implement StorageAdapter interface
62
+ /**
63
+ * Internal storage map.
64
+ */
65
+ _InMemoryStorageAdapter_storage.set(this, void 0);
66
+ __classPrivateFieldSet(this, _InMemoryStorageAdapter_storage, new Map(), "f");
67
+ if (initialData) {
68
+ for (const [namespace, items] of Object.entries(initialData)) {
69
+ for (const [key, value] of Object.entries(items)) {
70
+ const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
71
+ __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(value));
72
+ }
73
+ }
74
+ }
75
+ }
76
+ /**
77
+ * Retrieve an item from in-memory storage.
78
+ * Deserializes JSON data from storage.
79
+ *
80
+ * @param namespace - The controller namespace.
81
+ * @param key - The data key.
82
+ * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.
83
+ */
84
+ async getItem(namespace, key) {
85
+ const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
86
+ const serialized = __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").get(fullKey);
87
+ // Key not found - return empty object
88
+ if (serialized === undefined) {
89
+ return {};
90
+ }
91
+ try {
92
+ const result = JSON.parse(serialized);
93
+ return { result };
94
+ }
95
+ catch (error) {
96
+ console.error(`Failed to parse stored data for ${fullKey}:`, error);
97
+ return { error: error };
98
+ }
99
+ }
100
+ /**
101
+ * Store an item in in-memory storage.
102
+ * Serializes JSON data to string.
103
+ *
104
+ * @param namespace - The controller namespace.
105
+ * @param key - The data key.
106
+ * @param value - The JSON value to store.
107
+ */
108
+ async setItem(namespace, key, value) {
109
+ const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
110
+ __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(value));
111
+ }
112
+ /**
113
+ * Remove an item from in-memory storage.
114
+ *
115
+ * @param namespace - The controller namespace.
116
+ * @param key - The data key.
117
+ */
118
+ async removeItem(namespace, key) {
119
+ const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
120
+ __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(fullKey);
121
+ }
122
+ /**
123
+ * Get all keys for a namespace.
124
+ * Returns keys without the 'storage:namespace:' prefix.
125
+ *
126
+ * @param namespace - The namespace to get keys for.
127
+ * @returns Array of keys (without prefix) for this namespace.
128
+ */
129
+ async getAllKeys(namespace) {
130
+ const prefix = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:`;
131
+ return Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys())
132
+ .filter((key) => key.startsWith(prefix))
133
+ .map((key) => key.slice(prefix.length));
134
+ }
135
+ /**
136
+ * Clear all items for a namespace.
137
+ *
138
+ * @param namespace - The namespace to clear.
139
+ */
140
+ async clear(namespace) {
141
+ const prefix = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:`;
142
+ const keysToDelete = Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys()).filter((key) => key.startsWith(prefix));
143
+ keysToDelete.forEach((key) => __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(key));
144
+ }
145
+ }
146
+ exports.InMemoryStorageAdapter = InMemoryStorageAdapter;
147
+ _InMemoryStorageAdapter_storage = new WeakMap();
148
+ //# sourceMappingURL=InMemoryStorageAdapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryStorageAdapter.cjs","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA,0CAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAa,sBAAsB;IAOjC;;;;;OAKG;IACH,YAAY,WAAgC;QAZ5C,gDAAgD;QAChD;;WA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CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AAtGD,wDAsGC","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type {\n InitialStorageData,\n StorageAdapter,\n StorageGetResult,\n} from './types.js';\nimport { STORAGE_KEY_PREFIX } from './types.js';\n\n/**\n * In-memory storage adapter (default fallback).\n * Implements the {@link StorageAdapter} interface using a Map.\n *\n * ⚠️ **Warning**: Data is NOT persisted - lost on restart.\n *\n * **Suitable for:**\n * - Testing (isolated, no mocking needed)\n * - Development (quick start, zero config)\n * - Temporary/ephemeral data\n *\n * **Not suitable for:**\n * - Production (unless data is truly ephemeral)\n * - Data that needs to persist across restarts\n *\n * @example Basic usage\n * ```typescript\n * const adapter = new InMemoryStorageAdapter();\n * await adapter.setItem('SnapController', 'snap-id:sourceCode', 'const x = 1;');\n * const value = await adapter.getItem('SnapController', 'snap-id:sourceCode'); // 'const x = 1;'\n * // After restart: data is lost\n * ```\n *\n * @example Initialize with data (useful for testing)\n * ```typescript\n * const adapter = new InMemoryStorageAdapter({\n * SnapController: {\n * 'snap-id:sourceCode': 'const x = 1;',\n * 'snap-id:manifest': { name: 'My Snap' },\n * },\n * TokenListController: {\n * cache: { '0x1': ['token1', 'token2'] },\n * },\n * });\n * ```\n */\nexport class InMemoryStorageAdapter implements StorageAdapter {\n // Explicitly implement StorageAdapter interface\n /**\n * Internal storage map.\n */\n readonly #storage: Map<string, string>;\n\n /**\n * Constructs a new InMemoryStorageAdapter.\n *\n * @param initialData - Optional initial data to populate the storage.\n * Useful for setting up test fixtures without calling setItem multiple times.\n */\n constructor(initialData?: InitialStorageData) {\n this.#storage = new Map();\n\n if (initialData) {\n for (const [namespace, items] of Object.entries(initialData)) {\n for (const [key, value] of Object.entries(items)) {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n this.#storage.set(fullKey, JSON.stringify(value));\n }\n }\n }\n }\n\n /**\n * Retrieve an item from in-memory storage.\n * Deserializes JSON data from storage.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\n async getItem(namespace: string, key: string): Promise<StorageGetResult> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n const serialized = this.#storage.get(fullKey);\n\n // Key not found - return empty object\n if (serialized === undefined) {\n return {};\n }\n\n try {\n const result = JSON.parse(serialized);\n return { result };\n } catch (error) {\n console.error(`Failed to parse stored data for ${fullKey}:`, error);\n return { error: error as Error };\n }\n }\n\n /**\n * Store an item in in-memory storage.\n * Serializes JSON data to string.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @param value - The JSON value to store.\n */\n async setItem(namespace: string, key: string, value: Json): Promise<void> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n this.#storage.set(fullKey, JSON.stringify(value));\n }\n\n /**\n * Remove an item from in-memory storage.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n */\n async removeItem(namespace: string, key: string): Promise<void> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n this.#storage.delete(fullKey);\n }\n\n /**\n * Get all keys for a namespace.\n * Returns keys without the 'storage:namespace:' prefix.\n *\n * @param namespace - The namespace to get keys for.\n * @returns Array of keys (without prefix) for this namespace.\n */\n async getAllKeys(namespace: string): Promise<string[]> {\n const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;\n return Array.from(this.#storage.keys())\n .filter((key) => key.startsWith(prefix))\n .map((key) => key.slice(prefix.length));\n }\n\n /**\n * Clear all items for a namespace.\n *\n * @param namespace - The namespace to clear.\n */\n async clear(namespace: string): Promise<void> {\n const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;\n const keysToDelete = Array.from(this.#storage.keys()).filter((key) =>\n key.startsWith(prefix),\n );\n keysToDelete.forEach((key) => this.#storage.delete(key));\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { Json } from '@metamask/utils';
2
- import type { InitialStorageData, StorageAdapter, StorageGetResult } from './types.js';
1
+ import type { Json } from "@metamask/utils";
2
+ import type { InitialStorageData, StorageAdapter, StorageGetResult } from "./types.cjs";
3
3
  /**
4
4
  * In-memory storage adapter (default fallback).
5
5
  * Implements the {@link StorageAdapter} interface using a Map.
@@ -85,4 +85,4 @@ export declare class InMemoryStorageAdapter implements StorageAdapter {
85
85
  */
86
86
  clear(namespace: string): Promise<void>;
87
87
  }
88
- //# sourceMappingURL=InMemoryStorageAdapter.d.ts.map
88
+ //# sourceMappingURL=InMemoryStorageAdapter.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryStorageAdapter.d.cts","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EACjB,oBAAmB;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,sBAAuB,YAAW,cAAc;;IAO3D;;;;;OAKG;gBACS,WAAW,CAAC,EAAE,kBAAkB;IAa5C;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkBxE;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE;;;;;OAKG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/D;;;;;;OAMG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOtD;;;;OAIG;IACG,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAO9C"}
@@ -0,0 +1,88 @@
1
+ import type { Json } from "@metamask/utils";
2
+ import type { InitialStorageData, StorageAdapter, StorageGetResult } from "./types.mjs";
3
+ /**
4
+ * In-memory storage adapter (default fallback).
5
+ * Implements the {@link StorageAdapter} interface using a Map.
6
+ *
7
+ * ⚠️ **Warning**: Data is NOT persisted - lost on restart.
8
+ *
9
+ * **Suitable for:**
10
+ * - Testing (isolated, no mocking needed)
11
+ * - Development (quick start, zero config)
12
+ * - Temporary/ephemeral data
13
+ *
14
+ * **Not suitable for:**
15
+ * - Production (unless data is truly ephemeral)
16
+ * - Data that needs to persist across restarts
17
+ *
18
+ * @example Basic usage
19
+ * ```typescript
20
+ * const adapter = new InMemoryStorageAdapter();
21
+ * await adapter.setItem('SnapController', 'snap-id:sourceCode', 'const x = 1;');
22
+ * const value = await adapter.getItem('SnapController', 'snap-id:sourceCode'); // 'const x = 1;'
23
+ * // After restart: data is lost
24
+ * ```
25
+ *
26
+ * @example Initialize with data (useful for testing)
27
+ * ```typescript
28
+ * const adapter = new InMemoryStorageAdapter({
29
+ * SnapController: {
30
+ * 'snap-id:sourceCode': 'const x = 1;',
31
+ * 'snap-id:manifest': { name: 'My Snap' },
32
+ * },
33
+ * TokenListController: {
34
+ * cache: { '0x1': ['token1', 'token2'] },
35
+ * },
36
+ * });
37
+ * ```
38
+ */
39
+ export declare class InMemoryStorageAdapter implements StorageAdapter {
40
+ #private;
41
+ /**
42
+ * Constructs a new InMemoryStorageAdapter.
43
+ *
44
+ * @param initialData - Optional initial data to populate the storage.
45
+ * Useful for setting up test fixtures without calling setItem multiple times.
46
+ */
47
+ constructor(initialData?: InitialStorageData);
48
+ /**
49
+ * Retrieve an item from in-memory storage.
50
+ * Deserializes JSON data from storage.
51
+ *
52
+ * @param namespace - The controller namespace.
53
+ * @param key - The data key.
54
+ * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.
55
+ */
56
+ getItem(namespace: string, key: string): Promise<StorageGetResult>;
57
+ /**
58
+ * Store an item in in-memory storage.
59
+ * Serializes JSON data to string.
60
+ *
61
+ * @param namespace - The controller namespace.
62
+ * @param key - The data key.
63
+ * @param value - The JSON value to store.
64
+ */
65
+ setItem(namespace: string, key: string, value: Json): Promise<void>;
66
+ /**
67
+ * Remove an item from in-memory storage.
68
+ *
69
+ * @param namespace - The controller namespace.
70
+ * @param key - The data key.
71
+ */
72
+ removeItem(namespace: string, key: string): Promise<void>;
73
+ /**
74
+ * Get all keys for a namespace.
75
+ * Returns keys without the 'storage:namespace:' prefix.
76
+ *
77
+ * @param namespace - The namespace to get keys for.
78
+ * @returns Array of keys (without prefix) for this namespace.
79
+ */
80
+ getAllKeys(namespace: string): Promise<string[]>;
81
+ /**
82
+ * Clear all items for a namespace.
83
+ *
84
+ * @param namespace - The namespace to clear.
85
+ */
86
+ clear(namespace: string): Promise<void>;
87
+ }
88
+ //# sourceMappingURL=InMemoryStorageAdapter.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryStorageAdapter.d.mts","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EACjB,oBAAmB;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,sBAAuB,YAAW,cAAc;;IAO3D;;;;;OAKG;gBACS,WAAW,CAAC,EAAE,kBAAkB;IAa5C;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkBxE;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE;;;;;OAKG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/D;;;;;;OAMG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOtD;;;;OAIG;IACG,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAO9C"}
@@ -1,4 +1,16 @@
1
- import { STORAGE_KEY_PREFIX } from './types.js';
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _InMemoryStorageAdapter_storage;
13
+ import { STORAGE_KEY_PREFIX } from "./types.mjs";
2
14
  /**
3
15
  * In-memory storage adapter (default fallback).
4
16
  * Implements the {@link StorageAdapter} interface using a Map.
@@ -36,11 +48,6 @@ import { STORAGE_KEY_PREFIX } from './types.js';
36
48
  * ```
37
49
  */
38
50
  export class InMemoryStorageAdapter {
39
- // Explicitly implement StorageAdapter interface
40
- /**
41
- * Internal storage map.
42
- */
43
- #storage;
44
51
  /**
45
52
  * Constructs a new InMemoryStorageAdapter.
46
53
  *
@@ -48,12 +55,17 @@ export class InMemoryStorageAdapter {
48
55
  * Useful for setting up test fixtures without calling setItem multiple times.
49
56
  */
50
57
  constructor(initialData) {
51
- this.#storage = new Map();
58
+ // Explicitly implement StorageAdapter interface
59
+ /**
60
+ * Internal storage map.
61
+ */
62
+ _InMemoryStorageAdapter_storage.set(this, void 0);
63
+ __classPrivateFieldSet(this, _InMemoryStorageAdapter_storage, new Map(), "f");
52
64
  if (initialData) {
53
65
  for (const [namespace, items] of Object.entries(initialData)) {
54
66
  for (const [key, value] of Object.entries(items)) {
55
67
  const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;
56
- this.#storage.set(fullKey, JSON.stringify(value));
68
+ __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(value));
57
69
  }
58
70
  }
59
71
  }
@@ -68,7 +80,7 @@ export class InMemoryStorageAdapter {
68
80
  */
69
81
  async getItem(namespace, key) {
70
82
  const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;
71
- const serialized = this.#storage.get(fullKey);
83
+ const serialized = __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").get(fullKey);
72
84
  // Key not found - return empty object
73
85
  if (serialized === undefined) {
74
86
  return {};
@@ -92,7 +104,7 @@ export class InMemoryStorageAdapter {
92
104
  */
93
105
  async setItem(namespace, key, value) {
94
106
  const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;
95
- this.#storage.set(fullKey, JSON.stringify(value));
107
+ __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(value));
96
108
  }
97
109
  /**
98
110
  * Remove an item from in-memory storage.
@@ -102,7 +114,7 @@ export class InMemoryStorageAdapter {
102
114
  */
103
115
  async removeItem(namespace, key) {
104
116
  const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;
105
- this.#storage.delete(fullKey);
117
+ __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(fullKey);
106
118
  }
107
119
  /**
108
120
  * Get all keys for a namespace.
@@ -113,7 +125,7 @@ export class InMemoryStorageAdapter {
113
125
  */
114
126
  async getAllKeys(namespace) {
115
127
  const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;
116
- return Array.from(this.#storage.keys())
128
+ return Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys())
117
129
  .filter((key) => key.startsWith(prefix))
118
130
  .map((key) => key.slice(prefix.length));
119
131
  }
@@ -124,8 +136,9 @@ export class InMemoryStorageAdapter {
124
136
  */
125
137
  async clear(namespace) {
126
138
  const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;
127
- const keysToDelete = Array.from(this.#storage.keys()).filter((key) => key.startsWith(prefix));
128
- keysToDelete.forEach((key) => this.#storage.delete(key));
139
+ const keysToDelete = Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys()).filter((key) => key.startsWith(prefix));
140
+ keysToDelete.forEach((key) => __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(key));
129
141
  }
130
142
  }
131
- //# sourceMappingURL=InMemoryStorageAdapter.js.map
143
+ _InMemoryStorageAdapter_storage = new WeakMap();
144
+ //# sourceMappingURL=InMemoryStorageAdapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryStorageAdapter.mjs","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,OAAO,EAAE,kBAAkB,EAAE,oBAAmB;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,sBAAsB;IAOjC;;;;;OAKG;IACH,YAAY,WAAgC;QAZ5C,gDAAgD;QAChD;;WAEG;QACM,kDAA8B;QASrC,uBAAA,IAAI,mCAAY,IAAI,GAAG,EAAE,MAAA,CAAC;QAE1B,IAAI,WAAW,EAAE,CAAC;YAChB,KAAK,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAA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ED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,GAAW;QAC7C,MAAM,OAAO,GAAG,GAAG,kBAAkB,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC;QAC3D,uBAAA,IAAI,uCAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB;QAChC,MAAM,MAAM,GAAG,GAAG,kBAAkB,GAAG,SAAS,GAAG,CAAC;QACpD,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,uCAAS,CAAC,IAAI,EAAE,CAAC;aACpC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;aACvC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,CAAC,SAAiB;QAC3B,MAAM,MAAM,GAAG,GAAG,kBAAkB,GAAG,SAAS,GAAG,CAAC;QACpD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,uCAAS,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CACnE,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CACvB,CAAC;QACF,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,uBAAA,IAAI,uCAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type {\n InitialStorageData,\n StorageAdapter,\n StorageGetResult,\n} from './types.js';\nimport { STORAGE_KEY_PREFIX } from './types.js';\n\n/**\n * In-memory storage adapter (default fallback).\n * Implements the {@link StorageAdapter} interface using a Map.\n *\n * ⚠️ **Warning**: Data is NOT persisted - lost on restart.\n *\n * **Suitable for:**\n * - Testing (isolated, no mocking needed)\n * - Development (quick start, zero config)\n * - Temporary/ephemeral data\n *\n * **Not suitable for:**\n * - Production (unless data is truly ephemeral)\n * - Data that needs to persist across restarts\n *\n * @example Basic usage\n * ```typescript\n * const adapter = new InMemoryStorageAdapter();\n * await adapter.setItem('SnapController', 'snap-id:sourceCode', 'const x = 1;');\n * const value = await adapter.getItem('SnapController', 'snap-id:sourceCode'); // 'const x = 1;'\n * // After restart: data is lost\n * ```\n *\n * @example Initialize with data (useful for testing)\n * ```typescript\n * const adapter = new InMemoryStorageAdapter({\n * SnapController: {\n * 'snap-id:sourceCode': 'const x = 1;',\n * 'snap-id:manifest': { name: 'My Snap' },\n * },\n * TokenListController: {\n * cache: { '0x1': ['token1', 'token2'] },\n * },\n * });\n * ```\n */\nexport class InMemoryStorageAdapter implements StorageAdapter {\n // Explicitly implement StorageAdapter interface\n /**\n * Internal storage map.\n */\n readonly #storage: Map<string, string>;\n\n /**\n * Constructs a new InMemoryStorageAdapter.\n *\n * @param initialData - Optional initial data to populate the storage.\n * Useful for setting up test fixtures without calling setItem multiple times.\n */\n constructor(initialData?: InitialStorageData) {\n this.#storage = new Map();\n\n if (initialData) {\n for (const [namespace, items] of Object.entries(initialData)) {\n for (const [key, value] of Object.entries(items)) {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n this.#storage.set(fullKey, JSON.stringify(value));\n }\n }\n }\n }\n\n /**\n * Retrieve an item from in-memory storage.\n * Deserializes JSON data from storage.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\n async getItem(namespace: string, key: string): Promise<StorageGetResult> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n const serialized = this.#storage.get(fullKey);\n\n // Key not found - return empty object\n if (serialized === undefined) {\n return {};\n }\n\n try {\n const result = JSON.parse(serialized);\n return { result };\n } catch (error) {\n console.error(`Failed to parse stored data for ${fullKey}:`, error);\n return { error: error as Error };\n }\n }\n\n /**\n * Store an item in in-memory storage.\n * Serializes JSON data to string.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @param value - The JSON value to store.\n */\n async setItem(namespace: string, key: string, value: Json): Promise<void> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n this.#storage.set(fullKey, JSON.stringify(value));\n }\n\n /**\n * Remove an item from in-memory storage.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n */\n async removeItem(namespace: string, key: string): Promise<void> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n this.#storage.delete(fullKey);\n }\n\n /**\n * Get all keys for a namespace.\n * Returns keys without the 'storage:namespace:' prefix.\n *\n * @param namespace - The namespace to get keys for.\n * @returns Array of keys (without prefix) for this namespace.\n */\n async getAllKeys(namespace: string): Promise<string[]> {\n const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;\n return Array.from(this.#storage.keys())\n .filter((key) => key.startsWith(prefix))\n .map((key) => key.slice(prefix.length));\n }\n\n /**\n * Clear all items for a namespace.\n *\n * @param namespace - The namespace to clear.\n */\n async clear(namespace: string): Promise<void> {\n const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;\n const keysToDelete = Array.from(this.#storage.keys()).filter((key) =>\n key.startsWith(prefix),\n );\n keysToDelete.forEach((key) => this.#storage.delete(key));\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=StorageService-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageService-method-action-types.cjs","sourceRoot":"","sources":["../src/StorageService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { StorageService } from './StorageService.js';\n\n/**\n * Store large JSON data in storage.\n *\n * ⚠️ **Designed for large values (100KB+), not many small ones.**\n * Each storage operation has I/O overhead. For best performance,\n * store one large object rather than many small key-value pairs.\n *\n * @example Good: Store entire cache as one value\n * ```typescript\n * await service.setItem('TokenList', 'cache', { '0x1': [...], '0x38': [...] });\n * ```\n *\n * @example Avoid: Many small values\n * ```typescript\n * // ❌ Don't do this - too many small writes\n * await service.setItem('TokenList', 'cache:0x1', [...]);\n * await service.setItem('TokenList', 'cache:0x38', [...]);\n * ```\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n * @param value - JSON data to store (should be 100KB+ for optimal use).\n */\nexport type StorageServiceSetItemAction = {\n type: `StorageService:setItem`;\n handler: StorageService['setItem'];\n};\n\n/**\n * Retrieve JSON data from storage.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\nexport type StorageServiceGetItemAction = {\n type: `StorageService:getItem`;\n handler: StorageService['getItem'];\n};\n\n/**\n * Remove data from storage.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n */\nexport type StorageServiceRemoveItemAction = {\n type: `StorageService:removeItem`;\n handler: StorageService['removeItem'];\n};\n\n/**\n * Get all keys for a namespace.\n * Delegates to storage adapter which handles filtering.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @returns Array of keys (without prefix) for this namespace.\n */\nexport type StorageServiceGetAllKeysAction = {\n type: `StorageService:getAllKeys`;\n handler: StorageService['getAllKeys'];\n};\n\n/**\n * Clear all data for a namespace.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n */\nexport type StorageServiceClearAction = {\n type: `StorageService:clear`;\n handler: StorageService['clear'];\n};\n\n/**\n * Union of all StorageService action types.\n */\nexport type StorageServiceMethodActions =\n | StorageServiceSetItemAction\n | StorageServiceGetItemAction\n | StorageServiceRemoveItemAction\n | StorageServiceGetAllKeysAction\n | StorageServiceClearAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { StorageService } from './StorageService.js';
5
+ import type { StorageService } from "./StorageService.cjs";
6
6
  /**
7
7
  * Store large JSON data in storage.
8
8
  *
@@ -75,4 +75,4 @@ export type StorageServiceClearAction = {
75
75
  * Union of all StorageService action types.
76
76
  */
77
77
  export type StorageServiceMethodActions = StorageServiceSetItemAction | StorageServiceGetItemAction | StorageServiceRemoveItemAction | StorageServiceGetAllKeysAction | StorageServiceClearAction;
78
- //# sourceMappingURL=StorageService-method-action-types.d.ts.map
78
+ //# sourceMappingURL=StorageService-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageService-method-action-types.d.cts","sourceRoot":"","sources":["../src/StorageService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,6BAA4B;AAE1D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,2BAA2B,GAC3B,2BAA2B,GAC3B,8BAA8B,GAC9B,8BAA8B,GAC9B,yBAAyB,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { StorageService } from "./StorageService.mjs";
6
+ /**
7
+ * Store large JSON data in storage.
8
+ *
9
+ * ⚠️ **Designed for large values (100KB+), not many small ones.**
10
+ * Each storage operation has I/O overhead. For best performance,
11
+ * store one large object rather than many small key-value pairs.
12
+ *
13
+ * @example Good: Store entire cache as one value
14
+ * ```typescript
15
+ * await service.setItem('TokenList', 'cache', { '0x1': [...], '0x38': [...] });
16
+ * ```
17
+ *
18
+ * @example Avoid: Many small values
19
+ * ```typescript
20
+ * // ❌ Don't do this - too many small writes
21
+ * await service.setItem('TokenList', 'cache:0x1', [...]);
22
+ * await service.setItem('TokenList', 'cache:0x38', [...]);
23
+ * ```
24
+ *
25
+ * @param namespace - Controller namespace (e.g., 'SnapController').
26
+ * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
27
+ * @param value - JSON data to store (should be 100KB+ for optimal use).
28
+ */
29
+ export type StorageServiceSetItemAction = {
30
+ type: `StorageService:setItem`;
31
+ handler: StorageService['setItem'];
32
+ };
33
+ /**
34
+ * Retrieve JSON data from storage.
35
+ *
36
+ * @param namespace - Controller namespace (e.g., 'SnapController').
37
+ * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
38
+ * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.
39
+ */
40
+ export type StorageServiceGetItemAction = {
41
+ type: `StorageService:getItem`;
42
+ handler: StorageService['getItem'];
43
+ };
44
+ /**
45
+ * Remove data from storage.
46
+ *
47
+ * @param namespace - Controller namespace (e.g., 'SnapController').
48
+ * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
49
+ */
50
+ export type StorageServiceRemoveItemAction = {
51
+ type: `StorageService:removeItem`;
52
+ handler: StorageService['removeItem'];
53
+ };
54
+ /**
55
+ * Get all keys for a namespace.
56
+ * Delegates to storage adapter which handles filtering.
57
+ *
58
+ * @param namespace - Controller namespace (e.g., 'SnapController').
59
+ * @returns Array of keys (without prefix) for this namespace.
60
+ */
61
+ export type StorageServiceGetAllKeysAction = {
62
+ type: `StorageService:getAllKeys`;
63
+ handler: StorageService['getAllKeys'];
64
+ };
65
+ /**
66
+ * Clear all data for a namespace.
67
+ *
68
+ * @param namespace - Controller namespace (e.g., 'SnapController').
69
+ */
70
+ export type StorageServiceClearAction = {
71
+ type: `StorageService:clear`;
72
+ handler: StorageService['clear'];
73
+ };
74
+ /**
75
+ * Union of all StorageService action types.
76
+ */
77
+ export type StorageServiceMethodActions = StorageServiceSetItemAction | StorageServiceGetItemAction | StorageServiceRemoveItemAction | StorageServiceGetAllKeysAction | StorageServiceClearAction;
78
+ //# sourceMappingURL=StorageService-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageService-method-action-types.d.mts","sourceRoot":"","sources":["../src/StorageService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,6BAA4B;AAE1D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,2BAA2B,GAC3B,2BAA2B,GAC3B,8BAA8B,GAC9B,8BAA8B,GAC9B,yBAAyB,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=StorageService-method-action-types.js.map
6
+ //# sourceMappingURL=StorageService-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageService-method-action-types.mjs","sourceRoot":"","sources":["../src/StorageService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { StorageService } from './StorageService.js';\n\n/**\n * Store large JSON data in storage.\n *\n * ⚠️ **Designed for large values (100KB+), not many small ones.**\n * Each storage operation has I/O overhead. For best performance,\n * store one large object rather than many small key-value pairs.\n *\n * @example Good: Store entire cache as one value\n * ```typescript\n * await service.setItem('TokenList', 'cache', { '0x1': [...], '0x38': [...] });\n * ```\n *\n * @example Avoid: Many small values\n * ```typescript\n * // ❌ Don't do this - too many small writes\n * await service.setItem('TokenList', 'cache:0x1', [...]);\n * await service.setItem('TokenList', 'cache:0x38', [...]);\n * ```\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n * @param value - JSON data to store (should be 100KB+ for optimal use).\n */\nexport type StorageServiceSetItemAction = {\n type: `StorageService:setItem`;\n handler: StorageService['setItem'];\n};\n\n/**\n * Retrieve JSON data from storage.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\nexport type StorageServiceGetItemAction = {\n type: `StorageService:getItem`;\n handler: StorageService['getItem'];\n};\n\n/**\n * Remove data from storage.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n */\nexport type StorageServiceRemoveItemAction = {\n type: `StorageService:removeItem`;\n handler: StorageService['removeItem'];\n};\n\n/**\n * Get all keys for a namespace.\n * Delegates to storage adapter which handles filtering.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @returns Array of keys (without prefix) for this namespace.\n */\nexport type StorageServiceGetAllKeysAction = {\n type: `StorageService:getAllKeys`;\n handler: StorageService['getAllKeys'];\n};\n\n/**\n * Clear all data for a namespace.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n */\nexport type StorageServiceClearAction = {\n type: `StorageService:clear`;\n handler: StorageService['clear'];\n};\n\n/**\n * Union of all StorageService action types.\n */\nexport type StorageServiceMethodActions =\n | StorageServiceSetItemAction\n | StorageServiceGetItemAction\n | StorageServiceRemoveItemAction\n | StorageServiceGetAllKeysAction\n | StorageServiceClearAction;\n"]}