@metamask-previews/storage-service 1.0.0-preview-e493d3e8 → 1.0.0-preview-81c9cf83
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/CHANGELOG.md +0 -8
- package/LICENSE +4 -18
- package/LICENSE.APACHE2 +201 -0
- package/LICENSE.MIT +21 -0
- package/README.md +41 -303
- package/dist/InMemoryStorageAdapter.cjs +129 -0
- package/dist/InMemoryStorageAdapter.cjs.map +1 -0
- package/dist/InMemoryStorageAdapter.d.cts +71 -0
- package/dist/InMemoryStorageAdapter.d.cts.map +1 -0
- package/dist/InMemoryStorageAdapter.d.mts +71 -0
- package/dist/InMemoryStorageAdapter.d.mts.map +1 -0
- package/dist/InMemoryStorageAdapter.mjs +125 -0
- package/dist/InMemoryStorageAdapter.mjs.map +1 -0
- package/dist/StorageService-method-action-types.cjs +7 -0
- package/dist/StorageService-method-action-types.cjs.map +1 -0
- package/dist/StorageService-method-action-types.d.cts +81 -0
- package/dist/StorageService-method-action-types.d.cts.map +1 -0
- package/dist/StorageService-method-action-types.d.mts +81 -0
- package/dist/StorageService-method-action-types.d.mts.map +1 -0
- package/dist/StorageService-method-action-types.mjs +6 -0
- package/dist/StorageService-method-action-types.mjs.map +1 -0
- package/dist/StorageService.cjs +203 -0
- package/dist/StorageService.cjs.map +1 -0
- package/dist/StorageService.d.cts +147 -0
- package/dist/StorageService.d.cts.map +1 -0
- package/dist/StorageService.d.mts +147 -0
- package/dist/StorageService.d.mts.map +1 -0
- package/dist/StorageService.mjs +199 -0
- package/dist/StorageService.mjs.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +7 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +12 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +148 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +148 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +9 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,129 @@
|
|
|
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_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
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const adapter = new InMemoryStorageAdapter();
|
|
35
|
+
* await adapter.setItem('key', 'value');
|
|
36
|
+
* const value = await adapter.getItem('key'); // Returns 'value'
|
|
37
|
+
* // After restart: data is lost
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
class InMemoryStorageAdapter {
|
|
41
|
+
/**
|
|
42
|
+
* Constructs a new InMemoryStorageAdapter.
|
|
43
|
+
*/
|
|
44
|
+
constructor() {
|
|
45
|
+
// Explicitly implement StorageAdapter interface
|
|
46
|
+
/**
|
|
47
|
+
* Internal storage map.
|
|
48
|
+
*/
|
|
49
|
+
_InMemoryStorageAdapter_storage.set(this, void 0);
|
|
50
|
+
__classPrivateFieldSet(this, _InMemoryStorageAdapter_storage, new Map(), "f");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieve an item from in-memory storage.
|
|
54
|
+
* Deserializes and unwraps the stored data.
|
|
55
|
+
*
|
|
56
|
+
* @param namespace - The controller namespace.
|
|
57
|
+
* @param key - The data key.
|
|
58
|
+
* @returns The unwrapped data, or null if not found.
|
|
59
|
+
*/
|
|
60
|
+
async getItem(namespace, key) {
|
|
61
|
+
const fullKey = `${types_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
62
|
+
const serialized = __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").get(fullKey);
|
|
63
|
+
if (!serialized) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const wrapper = JSON.parse(serialized);
|
|
68
|
+
return wrapper.data;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
// istanbul ignore next - defensive error handling for corrupted data
|
|
72
|
+
console.error(`Failed to parse stored data for ${fullKey}:`, error);
|
|
73
|
+
// istanbul ignore next
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Store an item in in-memory storage.
|
|
79
|
+
* Wraps with metadata and serializes to string.
|
|
80
|
+
*
|
|
81
|
+
* @param namespace - The controller namespace.
|
|
82
|
+
* @param key - The data key.
|
|
83
|
+
* @param value - The value to store (will be wrapped and serialized).
|
|
84
|
+
*/
|
|
85
|
+
async setItem(namespace, key, value) {
|
|
86
|
+
const fullKey = `${types_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
87
|
+
const wrapper = {
|
|
88
|
+
timestamp: Date.now(),
|
|
89
|
+
data: value,
|
|
90
|
+
};
|
|
91
|
+
__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(wrapper));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Remove an item from in-memory storage.
|
|
95
|
+
*
|
|
96
|
+
* @param namespace - The controller namespace.
|
|
97
|
+
* @param key - The data key.
|
|
98
|
+
*/
|
|
99
|
+
async removeItem(namespace, key) {
|
|
100
|
+
const fullKey = `${types_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
101
|
+
__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(fullKey);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get all keys for a namespace.
|
|
105
|
+
* Returns keys without the 'storage:namespace:' prefix.
|
|
106
|
+
*
|
|
107
|
+
* @param namespace - The namespace to get keys for.
|
|
108
|
+
* @returns Array of keys (without prefix) for this namespace.
|
|
109
|
+
*/
|
|
110
|
+
async getAllKeys(namespace) {
|
|
111
|
+
const prefix = `${types_1.STORAGE_KEY_PREFIX}${namespace}:`;
|
|
112
|
+
return Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys())
|
|
113
|
+
.filter((key) => key.startsWith(prefix))
|
|
114
|
+
.map((key) => key.slice(prefix.length));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Clear all items for a namespace.
|
|
118
|
+
*
|
|
119
|
+
* @param namespace - The namespace to clear.
|
|
120
|
+
*/
|
|
121
|
+
async clear(namespace) {
|
|
122
|
+
const prefix = `${types_1.STORAGE_KEY_PREFIX}${namespace}:`;
|
|
123
|
+
const keysToDelete = Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys()).filter((key) => key.startsWith(prefix));
|
|
124
|
+
keysToDelete.forEach((key) => __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(key));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.InMemoryStorageAdapter = InMemoryStorageAdapter;
|
|
128
|
+
_InMemoryStorageAdapter_storage = new WeakMap();
|
|
129
|
+
//# sourceMappingURL=InMemoryStorageAdapter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryStorageAdapter.cjs","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uCAA6C;AAa7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,sBAAsB;IAOjC;;OAEG;IACH;QATA,gDAAgD;QAChD;;WAEG;QACM,kDAA8B;QAMrC,uBAAA,IAAI,mCAAY,IAAI,GAAG,EAAE,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,GAAW;QAC1C,MAAM,OAAO,GAAG,GAAG,0BAAkB,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC;QAC3D,MAAM,UAAU,GAAG,uBAAA,IAAI,uCAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE9C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAsB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC1D,OAAO,OAAO,CAAC,IAAI,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qEAAqE;YACrE,OAAO,CAAC,KAAK,CAAC,mCAAmC,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC;YACpE,uBAAuB;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,GAAW,EAAE,KAAc;QAC1D,MAAM,OAAO,GAAG,GAAG,0BAAkB,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC;QAC3D,MAAM,OAAO,GAAsB;YACjC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,IAAI,EAAE,KAAK;SACZ,CAAC;QACF,uBAAA,IAAI,uCAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,GAAW;QAC7C,MAAM,OAAO,GAAG,GAAG,0BAAkB,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,0BAAkB,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,0BAAkB,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;AA/FD,wDA+FC","sourcesContent":["import type { StorageAdapter } from './types';\nimport { STORAGE_KEY_PREFIX } from './types';\n\n/**\n * Wrapper for stored data with metadata.\n * Each adapter can define its own wrapper structure.\n */\ntype StoredDataWrapper<T = unknown> = {\n /** Timestamp when data was stored (milliseconds since epoch). */\n timestamp: number;\n /** The actual data being stored. */\n data: T;\n};\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\n * ```typescript\n * const adapter = new InMemoryStorageAdapter();\n * await adapter.setItem('key', 'value');\n * const value = await adapter.getItem('key'); // Returns 'value'\n * // After restart: data is lost\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 constructor() {\n this.#storage = new Map();\n }\n\n /**\n * Retrieve an item from in-memory storage.\n * Deserializes and unwraps the stored data.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @returns The unwrapped data, or null if not found.\n */\n async getItem(namespace: string, key: string): Promise<unknown> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n const serialized = this.#storage.get(fullKey);\n\n if (!serialized) {\n return null;\n }\n\n try {\n const wrapper: StoredDataWrapper = JSON.parse(serialized);\n return wrapper.data;\n } catch (error) {\n // istanbul ignore next - defensive error handling for corrupted data\n console.error(`Failed to parse stored data for ${fullKey}:`, error);\n // istanbul ignore next\n return null;\n }\n }\n\n /**\n * Store an item in in-memory storage.\n * Wraps with metadata and serializes to string.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @param value - The value to store (will be wrapped and serialized).\n */\n async setItem(namespace: string, key: string, value: unknown): Promise<void> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n const wrapper: StoredDataWrapper = {\n timestamp: Date.now(),\n data: value,\n };\n this.#storage.set(fullKey, JSON.stringify(wrapper));\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,71 @@
|
|
|
1
|
+
import type { StorageAdapter } from "./types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory storage adapter (default fallback).
|
|
4
|
+
* Implements the {@link StorageAdapter} interface using a Map.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ **Warning**: Data is NOT persisted - lost on restart.
|
|
7
|
+
*
|
|
8
|
+
* **Suitable for:**
|
|
9
|
+
* - Testing (isolated, no mocking needed)
|
|
10
|
+
* - Development (quick start, zero config)
|
|
11
|
+
* - Temporary/ephemeral data
|
|
12
|
+
*
|
|
13
|
+
* **Not suitable for:**
|
|
14
|
+
* - Production (unless data is truly ephemeral)
|
|
15
|
+
* - Data that needs to persist across restarts
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const adapter = new InMemoryStorageAdapter();
|
|
20
|
+
* await adapter.setItem('key', 'value');
|
|
21
|
+
* const value = await adapter.getItem('key'); // Returns 'value'
|
|
22
|
+
* // After restart: data is lost
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class InMemoryStorageAdapter implements StorageAdapter {
|
|
26
|
+
#private;
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a new InMemoryStorageAdapter.
|
|
29
|
+
*/
|
|
30
|
+
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Retrieve an item from in-memory storage.
|
|
33
|
+
* Deserializes and unwraps the stored data.
|
|
34
|
+
*
|
|
35
|
+
* @param namespace - The controller namespace.
|
|
36
|
+
* @param key - The data key.
|
|
37
|
+
* @returns The unwrapped data, or null if not found.
|
|
38
|
+
*/
|
|
39
|
+
getItem(namespace: string, key: string): Promise<unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Store an item in in-memory storage.
|
|
42
|
+
* Wraps with metadata and serializes to string.
|
|
43
|
+
*
|
|
44
|
+
* @param namespace - The controller namespace.
|
|
45
|
+
* @param key - The data key.
|
|
46
|
+
* @param value - The value to store (will be wrapped and serialized).
|
|
47
|
+
*/
|
|
48
|
+
setItem(namespace: string, key: string, value: unknown): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Remove an item from in-memory storage.
|
|
51
|
+
*
|
|
52
|
+
* @param namespace - The controller namespace.
|
|
53
|
+
* @param key - The data key.
|
|
54
|
+
*/
|
|
55
|
+
removeItem(namespace: string, key: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Get all keys for a namespace.
|
|
58
|
+
* Returns keys without the 'storage:namespace:' prefix.
|
|
59
|
+
*
|
|
60
|
+
* @param namespace - The namespace to get keys for.
|
|
61
|
+
* @returns Array of keys (without prefix) for this namespace.
|
|
62
|
+
*/
|
|
63
|
+
getAllKeys(namespace: string): Promise<string[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Clear all items for a namespace.
|
|
66
|
+
*
|
|
67
|
+
* @param namespace - The namespace to clear.
|
|
68
|
+
*/
|
|
69
|
+
clear(namespace: string): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
//# 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,cAAc,EAAE,oBAAgB;AAc9C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,sBAAuB,YAAW,cAAc;;IAO3D;;OAEG;;IAKH;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB/D;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5E;;;;;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,71 @@
|
|
|
1
|
+
import type { StorageAdapter } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory storage adapter (default fallback).
|
|
4
|
+
* Implements the {@link StorageAdapter} interface using a Map.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ **Warning**: Data is NOT persisted - lost on restart.
|
|
7
|
+
*
|
|
8
|
+
* **Suitable for:**
|
|
9
|
+
* - Testing (isolated, no mocking needed)
|
|
10
|
+
* - Development (quick start, zero config)
|
|
11
|
+
* - Temporary/ephemeral data
|
|
12
|
+
*
|
|
13
|
+
* **Not suitable for:**
|
|
14
|
+
* - Production (unless data is truly ephemeral)
|
|
15
|
+
* - Data that needs to persist across restarts
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const adapter = new InMemoryStorageAdapter();
|
|
20
|
+
* await adapter.setItem('key', 'value');
|
|
21
|
+
* const value = await adapter.getItem('key'); // Returns 'value'
|
|
22
|
+
* // After restart: data is lost
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class InMemoryStorageAdapter implements StorageAdapter {
|
|
26
|
+
#private;
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a new InMemoryStorageAdapter.
|
|
29
|
+
*/
|
|
30
|
+
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Retrieve an item from in-memory storage.
|
|
33
|
+
* Deserializes and unwraps the stored data.
|
|
34
|
+
*
|
|
35
|
+
* @param namespace - The controller namespace.
|
|
36
|
+
* @param key - The data key.
|
|
37
|
+
* @returns The unwrapped data, or null if not found.
|
|
38
|
+
*/
|
|
39
|
+
getItem(namespace: string, key: string): Promise<unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Store an item in in-memory storage.
|
|
42
|
+
* Wraps with metadata and serializes to string.
|
|
43
|
+
*
|
|
44
|
+
* @param namespace - The controller namespace.
|
|
45
|
+
* @param key - The data key.
|
|
46
|
+
* @param value - The value to store (will be wrapped and serialized).
|
|
47
|
+
*/
|
|
48
|
+
setItem(namespace: string, key: string, value: unknown): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Remove an item from in-memory storage.
|
|
51
|
+
*
|
|
52
|
+
* @param namespace - The controller namespace.
|
|
53
|
+
* @param key - The data key.
|
|
54
|
+
*/
|
|
55
|
+
removeItem(namespace: string, key: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Get all keys for a namespace.
|
|
58
|
+
* Returns keys without the 'storage:namespace:' prefix.
|
|
59
|
+
*
|
|
60
|
+
* @param namespace - The namespace to get keys for.
|
|
61
|
+
* @returns Array of keys (without prefix) for this namespace.
|
|
62
|
+
*/
|
|
63
|
+
getAllKeys(namespace: string): Promise<string[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Clear all items for a namespace.
|
|
66
|
+
*
|
|
67
|
+
* @param namespace - The namespace to clear.
|
|
68
|
+
*/
|
|
69
|
+
clear(namespace: string): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
//# 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,cAAc,EAAE,oBAAgB;AAc9C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,sBAAuB,YAAW,cAAc;;IAO3D;;OAEG;;IAKH;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB/D;;;;;;;OAOG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5E;;;;;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,125 @@
|
|
|
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";
|
|
14
|
+
/**
|
|
15
|
+
* In-memory storage adapter (default fallback).
|
|
16
|
+
* Implements the {@link StorageAdapter} interface using a Map.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ **Warning**: Data is NOT persisted - lost on restart.
|
|
19
|
+
*
|
|
20
|
+
* **Suitable for:**
|
|
21
|
+
* - Testing (isolated, no mocking needed)
|
|
22
|
+
* - Development (quick start, zero config)
|
|
23
|
+
* - Temporary/ephemeral data
|
|
24
|
+
*
|
|
25
|
+
* **Not suitable for:**
|
|
26
|
+
* - Production (unless data is truly ephemeral)
|
|
27
|
+
* - Data that needs to persist across restarts
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const adapter = new InMemoryStorageAdapter();
|
|
32
|
+
* await adapter.setItem('key', 'value');
|
|
33
|
+
* const value = await adapter.getItem('key'); // Returns 'value'
|
|
34
|
+
* // After restart: data is lost
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export class InMemoryStorageAdapter {
|
|
38
|
+
/**
|
|
39
|
+
* Constructs a new InMemoryStorageAdapter.
|
|
40
|
+
*/
|
|
41
|
+
constructor() {
|
|
42
|
+
// Explicitly implement StorageAdapter interface
|
|
43
|
+
/**
|
|
44
|
+
* Internal storage map.
|
|
45
|
+
*/
|
|
46
|
+
_InMemoryStorageAdapter_storage.set(this, void 0);
|
|
47
|
+
__classPrivateFieldSet(this, _InMemoryStorageAdapter_storage, new Map(), "f");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Retrieve an item from in-memory storage.
|
|
51
|
+
* Deserializes and unwraps the stored data.
|
|
52
|
+
*
|
|
53
|
+
* @param namespace - The controller namespace.
|
|
54
|
+
* @param key - The data key.
|
|
55
|
+
* @returns The unwrapped data, or null if not found.
|
|
56
|
+
*/
|
|
57
|
+
async getItem(namespace, key) {
|
|
58
|
+
const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
59
|
+
const serialized = __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").get(fullKey);
|
|
60
|
+
if (!serialized) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const wrapper = JSON.parse(serialized);
|
|
65
|
+
return wrapper.data;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// istanbul ignore next - defensive error handling for corrupted data
|
|
69
|
+
console.error(`Failed to parse stored data for ${fullKey}:`, error);
|
|
70
|
+
// istanbul ignore next
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Store an item in in-memory storage.
|
|
76
|
+
* Wraps with metadata and serializes to string.
|
|
77
|
+
*
|
|
78
|
+
* @param namespace - The controller namespace.
|
|
79
|
+
* @param key - The data key.
|
|
80
|
+
* @param value - The value to store (will be wrapped and serialized).
|
|
81
|
+
*/
|
|
82
|
+
async setItem(namespace, key, value) {
|
|
83
|
+
const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
84
|
+
const wrapper = {
|
|
85
|
+
timestamp: Date.now(),
|
|
86
|
+
data: value,
|
|
87
|
+
};
|
|
88
|
+
__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(wrapper));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Remove an item from in-memory storage.
|
|
92
|
+
*
|
|
93
|
+
* @param namespace - The controller namespace.
|
|
94
|
+
* @param key - The data key.
|
|
95
|
+
*/
|
|
96
|
+
async removeItem(namespace, key) {
|
|
97
|
+
const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
98
|
+
__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(fullKey);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get all keys for a namespace.
|
|
102
|
+
* Returns keys without the 'storage:namespace:' prefix.
|
|
103
|
+
*
|
|
104
|
+
* @param namespace - The namespace to get keys for.
|
|
105
|
+
* @returns Array of keys (without prefix) for this namespace.
|
|
106
|
+
*/
|
|
107
|
+
async getAllKeys(namespace) {
|
|
108
|
+
const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;
|
|
109
|
+
return Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys())
|
|
110
|
+
.filter((key) => key.startsWith(prefix))
|
|
111
|
+
.map((key) => key.slice(prefix.length));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Clear all items for a namespace.
|
|
115
|
+
*
|
|
116
|
+
* @param namespace - The namespace to clear.
|
|
117
|
+
*/
|
|
118
|
+
async clear(namespace) {
|
|
119
|
+
const prefix = `${STORAGE_KEY_PREFIX}${namespace}:`;
|
|
120
|
+
const keysToDelete = Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys()).filter((key) => key.startsWith(prefix));
|
|
121
|
+
keysToDelete.forEach((key) => __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(key));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
_InMemoryStorageAdapter_storage = new WeakMap();
|
|
125
|
+
//# sourceMappingURL=InMemoryStorageAdapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryStorageAdapter.mjs","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,oBAAgB;AAa7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,sBAAsB;IAOjC;;OAEG;IACH;QATA,gDAAgD;QAChD;;WAEG;QACM,kDAA8B;QAMrC,uBAAA,IAAI,mCAAY,IAAI,GAAG,EAAE,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,GAAW;QAC1C,MAAM,OAAO,GAAG,GAAG,kBAAkB,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC;QAC3D,MAAM,UAAU,GAAG,uBAAA,IAAI,uCAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE9C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAsB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC1D,OAAO,OAAO,CAAC,IAAI,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qEAAqE;YACrE,OAAO,CAAC,KAAK,CAAC,mCAAmC,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC;YACpE,uBAAuB;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,GAAW,EAAE,KAAc;QAC1D,MAAM,OAAO,GAAG,GAAG,kBAAkB,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC;QAC3D,MAAM,OAAO,GAAsB;YACjC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,IAAI,EAAE,KAAK;SACZ,CAAC;QACF,uBAAA,IAAI,uCAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;;;;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 { StorageAdapter } from './types';\nimport { STORAGE_KEY_PREFIX } from './types';\n\n/**\n * Wrapper for stored data with metadata.\n * Each adapter can define its own wrapper structure.\n */\ntype StoredDataWrapper<T = unknown> = {\n /** Timestamp when data was stored (milliseconds since epoch). */\n timestamp: number;\n /** The actual data being stored. */\n data: T;\n};\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\n * ```typescript\n * const adapter = new InMemoryStorageAdapter();\n * await adapter.setItem('key', 'value');\n * const value = await adapter.getItem('key'); // Returns 'value'\n * // After restart: data is lost\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 constructor() {\n this.#storage = new Map();\n }\n\n /**\n * Retrieve an item from in-memory storage.\n * Deserializes and unwraps the stored data.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @returns The unwrapped data, or null if not found.\n */\n async getItem(namespace: string, key: string): Promise<unknown> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n const serialized = this.#storage.get(fullKey);\n\n if (!serialized) {\n return null;\n }\n\n try {\n const wrapper: StoredDataWrapper = JSON.parse(serialized);\n return wrapper.data;\n } catch (error) {\n // istanbul ignore next - defensive error handling for corrupted data\n console.error(`Failed to parse stored data for ${fullKey}:`, error);\n // istanbul ignore next\n return null;\n }\n }\n\n /**\n * Store an item in in-memory storage.\n * Wraps with metadata and serializes to string.\n *\n * @param namespace - The controller namespace.\n * @param key - The data key.\n * @param value - The value to store (will be wrapped and serialized).\n */\n async setItem(namespace: string, key: string, value: unknown): Promise<void> {\n const fullKey = `${STORAGE_KEY_PREFIX}${namespace}:${key}`;\n const wrapper: StoredDataWrapper = {\n timestamp: Date.now(),\n data: value,\n };\n this.#storage.set(fullKey, JSON.stringify(wrapper));\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 @@
|
|
|
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { StorageService } from './StorageService';\n\n/**\n * Store large 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 - 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 data from storage.\n *\n * Returns `unknown` since there's no schema validation.\n * Callers should validate or cast the result to the expected type.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n * @returns Parsed data or null if not found. Type is `unknown` - caller must validate.\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"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { StorageService } from "./StorageService.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Store large 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 - 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 data from storage.
|
|
35
|
+
*
|
|
36
|
+
* Returns `unknown` since there's no schema validation.
|
|
37
|
+
* Callers should validate or cast the result to the expected type.
|
|
38
|
+
*
|
|
39
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
40
|
+
* @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
|
|
41
|
+
* @returns Parsed data or null if not found. Type is `unknown` - caller must validate.
|
|
42
|
+
*/
|
|
43
|
+
export type StorageServiceGetItemAction = {
|
|
44
|
+
type: `StorageService:getItem`;
|
|
45
|
+
handler: StorageService['getItem'];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Remove data from storage.
|
|
49
|
+
*
|
|
50
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
51
|
+
* @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
|
|
52
|
+
*/
|
|
53
|
+
export type StorageServiceRemoveItemAction = {
|
|
54
|
+
type: `StorageService:removeItem`;
|
|
55
|
+
handler: StorageService['removeItem'];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Get all keys for a namespace.
|
|
59
|
+
* Delegates to storage adapter which handles filtering.
|
|
60
|
+
*
|
|
61
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
62
|
+
* @returns Array of keys (without prefix) for this namespace.
|
|
63
|
+
*/
|
|
64
|
+
export type StorageServiceGetAllKeysAction = {
|
|
65
|
+
type: `StorageService:getAllKeys`;
|
|
66
|
+
handler: StorageService['getAllKeys'];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Clear all data for a namespace.
|
|
70
|
+
*
|
|
71
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
72
|
+
*/
|
|
73
|
+
export type StorageServiceClearAction = {
|
|
74
|
+
type: `StorageService:clear`;
|
|
75
|
+
handler: StorageService['clear'];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Union of all StorageService action types.
|
|
79
|
+
*/
|
|
80
|
+
export type StorageServiceMethodActions = StorageServiceSetItemAction | StorageServiceGetItemAction | StorageServiceRemoveItemAction | StorageServiceGetAllKeysAction | StorageServiceClearAction;
|
|
81
|
+
//# 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,6BAAyB;AAEvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;;;;;GASG;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,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { StorageService } from "./StorageService.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Store large 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 - 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 data from storage.
|
|
35
|
+
*
|
|
36
|
+
* Returns `unknown` since there's no schema validation.
|
|
37
|
+
* Callers should validate or cast the result to the expected type.
|
|
38
|
+
*
|
|
39
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
40
|
+
* @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
|
|
41
|
+
* @returns Parsed data or null if not found. Type is `unknown` - caller must validate.
|
|
42
|
+
*/
|
|
43
|
+
export type StorageServiceGetItemAction = {
|
|
44
|
+
type: `StorageService:getItem`;
|
|
45
|
+
handler: StorageService['getItem'];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Remove data from storage.
|
|
49
|
+
*
|
|
50
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
51
|
+
* @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
|
|
52
|
+
*/
|
|
53
|
+
export type StorageServiceRemoveItemAction = {
|
|
54
|
+
type: `StorageService:removeItem`;
|
|
55
|
+
handler: StorageService['removeItem'];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Get all keys for a namespace.
|
|
59
|
+
* Delegates to storage adapter which handles filtering.
|
|
60
|
+
*
|
|
61
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
62
|
+
* @returns Array of keys (without prefix) for this namespace.
|
|
63
|
+
*/
|
|
64
|
+
export type StorageServiceGetAllKeysAction = {
|
|
65
|
+
type: `StorageService:getAllKeys`;
|
|
66
|
+
handler: StorageService['getAllKeys'];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Clear all data for a namespace.
|
|
70
|
+
*
|
|
71
|
+
* @param namespace - Controller namespace (e.g., 'SnapController').
|
|
72
|
+
*/
|
|
73
|
+
export type StorageServiceClearAction = {
|
|
74
|
+
type: `StorageService:clear`;
|
|
75
|
+
handler: StorageService['clear'];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Union of all StorageService action types.
|
|
79
|
+
*/
|
|
80
|
+
export type StorageServiceMethodActions = StorageServiceSetItemAction | StorageServiceGetItemAction | StorageServiceRemoveItemAction | StorageServiceGetAllKeysAction | StorageServiceClearAction;
|
|
81
|
+
//# 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,6BAAyB;AAEvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;;;;;GASG;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 @@
|
|
|
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { StorageService } from './StorageService';\n\n/**\n * Store large 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 - 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 data from storage.\n *\n * Returns `unknown` since there's no schema validation.\n * Callers should validate or cast the result to the expected type.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n * @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').\n * @returns Parsed data or null if not found. Type is `unknown` - caller must validate.\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"]}
|