@metamask-previews/storage-service 1.0.2-preview-40d5fb1e2 → 1.0.2-preview-a3e31582e
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/dist/InMemoryStorageAdapter.cjs +7 -7
- package/dist/InMemoryStorageAdapter.cjs.map +1 -1
- package/dist/InMemoryStorageAdapter.d.cts.map +1 -1
- package/dist/InMemoryStorageAdapter.d.mts.map +1 -1
- package/dist/InMemoryStorageAdapter.mjs.map +1 -1
- package/dist/StorageService-method-action-types.cjs.map +1 -1
- package/dist/StorageService-method-action-types.d.cts.map +1 -1
- package/dist/StorageService-method-action-types.d.mts.map +1 -1
- package/dist/StorageService-method-action-types.mjs.map +1 -1
- package/dist/StorageService.cjs +6 -6
- package/dist/StorageService.cjs.map +1 -1
- package/dist/StorageService.d.cts.map +1 -1
- package/dist/StorageService.d.mts.map +1 -1
- package/dist/StorageService.mjs.map +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _InMemoryStorageAdapter_storage;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.InMemoryStorageAdapter = void 0;
|
|
16
|
-
const
|
|
16
|
+
const types_js_1 = require("./types.cjs");
|
|
17
17
|
/**
|
|
18
18
|
* In-memory storage adapter (default fallback).
|
|
19
19
|
* Implements the {@link StorageAdapter} interface using a Map.
|
|
@@ -67,7 +67,7 @@ class InMemoryStorageAdapter {
|
|
|
67
67
|
if (initialData) {
|
|
68
68
|
for (const [namespace, items] of Object.entries(initialData)) {
|
|
69
69
|
for (const [key, value] of Object.entries(items)) {
|
|
70
|
-
const fullKey = `${
|
|
70
|
+
const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
71
71
|
__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(value));
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -82,7 +82,7 @@ class InMemoryStorageAdapter {
|
|
|
82
82
|
* @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.
|
|
83
83
|
*/
|
|
84
84
|
async getItem(namespace, key) {
|
|
85
|
-
const fullKey = `${
|
|
85
|
+
const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
86
86
|
const serialized = __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").get(fullKey);
|
|
87
87
|
// Key not found - return empty object
|
|
88
88
|
if (serialized === undefined) {
|
|
@@ -106,7 +106,7 @@ class InMemoryStorageAdapter {
|
|
|
106
106
|
* @param value - The JSON value to store.
|
|
107
107
|
*/
|
|
108
108
|
async setItem(namespace, key, value) {
|
|
109
|
-
const fullKey = `${
|
|
109
|
+
const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
110
110
|
__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").set(fullKey, JSON.stringify(value));
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
@@ -116,7 +116,7 @@ class InMemoryStorageAdapter {
|
|
|
116
116
|
* @param key - The data key.
|
|
117
117
|
*/
|
|
118
118
|
async removeItem(namespace, key) {
|
|
119
|
-
const fullKey = `${
|
|
119
|
+
const fullKey = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:${key}`;
|
|
120
120
|
__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(fullKey);
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -127,7 +127,7 @@ class InMemoryStorageAdapter {
|
|
|
127
127
|
* @returns Array of keys (without prefix) for this namespace.
|
|
128
128
|
*/
|
|
129
129
|
async getAllKeys(namespace) {
|
|
130
|
-
const prefix = `${
|
|
130
|
+
const prefix = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:`;
|
|
131
131
|
return Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys())
|
|
132
132
|
.filter((key) => key.startsWith(prefix))
|
|
133
133
|
.map((key) => key.slice(prefix.length));
|
|
@@ -138,7 +138,7 @@ class InMemoryStorageAdapter {
|
|
|
138
138
|
* @param namespace - The namespace to clear.
|
|
139
139
|
*/
|
|
140
140
|
async clear(namespace) {
|
|
141
|
-
const prefix = `${
|
|
141
|
+
const prefix = `${types_js_1.STORAGE_KEY_PREFIX}${namespace}:`;
|
|
142
142
|
const keysToDelete = Array.from(__classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").keys()).filter((key) => key.startsWith(prefix));
|
|
143
143
|
keysToDelete.forEach((key) => __classPrivateFieldGet(this, _InMemoryStorageAdapter_storage, "f").delete(key));
|
|
144
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryStorageAdapter.cjs","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA,
|
|
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;;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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S,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,GAAW;QAC7C,MAAM,OAAO,GAAG,GAAG,6BAAkB,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,6BAAkB,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,6BAAkB,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;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 +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,
|
|
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"}
|
|
@@ -1 +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,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryStorageAdapter.mjs","sourceRoot":"","sources":["../src/InMemoryStorageAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,OAAO,EAAE,kBAAkB,EAAE,
|
|
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;;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G,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"]}
|
|
@@ -1 +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';\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"]}
|
|
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"]}
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -1 +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';\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"]}
|
|
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"]}
|
package/dist/StorageService.cjs
CHANGED
|
@@ -13,8 +13,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _StorageService_messenger, _StorageService_storage;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.StorageService = void 0;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const InMemoryStorageAdapter_js_1 = require("./InMemoryStorageAdapter.cjs");
|
|
17
|
+
const types_js_1 = require("./types.cjs");
|
|
18
18
|
// === MESSENGER ===
|
|
19
19
|
const MESSENGER_EXPOSED_METHODS = [
|
|
20
20
|
'setItem',
|
|
@@ -116,12 +116,12 @@ class StorageService {
|
|
|
116
116
|
* The storage adapter for persisting data.
|
|
117
117
|
*/
|
|
118
118
|
_StorageService_storage.set(this, void 0);
|
|
119
|
-
this.name =
|
|
119
|
+
this.name = types_js_1.SERVICE_NAME;
|
|
120
120
|
__classPrivateFieldSet(this, _StorageService_messenger, messenger, "f");
|
|
121
|
-
__classPrivateFieldSet(this, _StorageService_storage, storage ?? new
|
|
121
|
+
__classPrivateFieldSet(this, _StorageService_storage, storage ?? new InMemoryStorageAdapter_js_1.InMemoryStorageAdapter(), "f");
|
|
122
122
|
// Warn if using in-memory storage (data won't persist)
|
|
123
123
|
if (!storage) {
|
|
124
|
-
console.warn(`${
|
|
124
|
+
console.warn(`${types_js_1.SERVICE_NAME}: No storage adapter provided. Using in-memory storage. ` +
|
|
125
125
|
'Data will be lost on restart. Provide a storage adapter for persistence.');
|
|
126
126
|
}
|
|
127
127
|
// Register messenger actions
|
|
@@ -156,7 +156,7 @@ class StorageService {
|
|
|
156
156
|
// Publish event so other controllers can react to changes
|
|
157
157
|
// Event type: StorageService:itemSet:namespace
|
|
158
158
|
// Payload: [key, value]
|
|
159
|
-
__classPrivateFieldGet(this, _StorageService_messenger, "f").publish(`${
|
|
159
|
+
__classPrivateFieldGet(this, _StorageService_messenger, "f").publish(`${types_js_1.SERVICE_NAME}:itemSet:${namespace}`, key, value);
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
162
|
* Retrieve JSON data from storage.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageService.cjs","sourceRoot":"","sources":["../src/StorageService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,
|
|
1
|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N,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,GAAW;QAC1C,iDAAiD;QACjD,OAAO,MAAM,uBAAA,IAAI,+BAAS,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,GAAW;QAC7C,iFAAiF;QACjF,MAAM,uBAAA,IAAI,+BAAS,CAAC,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB;QAChC,OAAO,MAAM,uBAAA,IAAI,+BAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,CAAC,SAAiB;QAC3B,MAAM,uBAAA,IAAI,+BAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;CACF;AA3HD,wCA2HC","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport { InMemoryStorageAdapter } from './InMemoryStorageAdapter.js';\nimport type {\n StorageAdapter,\n StorageGetResult,\n StorageServiceMessenger,\n StorageServiceOptions,\n} from './types.js';\nimport { SERVICE_NAME } from './types.js';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'setItem',\n 'getItem',\n 'removeItem',\n 'getAllKeys',\n 'clear',\n] as const;\n\n/**\n * StorageService provides a platform-agnostic way for controllers to store\n * large, infrequently accessed data outside of memory/Redux state.\n *\n * **Use cases:**\n * - Snap source code (6+ MB that's rarely accessed)\n * - Token metadata caches (4+ MB of cached data)\n * - Large cached responses from APIs\n * - Any data > 100 KB that's not frequently accessed\n *\n * **Benefits:**\n * - Reduces memory usage (data stays on disk)\n * - Faster Redux persist (less data to serialize)\n * - Faster app startup (less data to parse)\n * - Lazy loading (data loaded only when needed)\n *\n * **Platform Support:**\n * - Mobile: FilesystemStorage adapter\n * - Extension: IndexedDB adapter\n * - Tests/Dev: InMemoryStorageAdapter (default)\n *\n * @example Using the service via messenger\n *\n * ```typescript\n * // In a controller\n * type AllowedActions =\n * | StorageServiceSetItemAction\n * | StorageServiceGetItemAction;\n *\n * class SnapController extends BaseController {\n * async storeSnapSourceCode(snapId: string, sourceCode: string) {\n * await this.messenger.call(\n * 'StorageService:setItem',\n * 'SnapController',\n * `${snapId}:sourceCode`,\n * sourceCode,\n * );\n * }\n *\n * async getSnapSourceCode(snapId: string): Promise<string | undefined> {\n * const { result, error } = await this.messenger.call(\n * 'StorageService:getItem',\n * 'SnapController',\n * `${snapId}:sourceCode`,\n * );\n * if (error) {\n * throw error; // Handle error\n * }\n * return result as string | undefined; // undefined if not found\n * }\n * }\n * ```\n *\n * @example Initializing in a client\n *\n * ```typescript\n * // Mobile\n * const service = new StorageService({\n * messenger: storageServiceMessenger,\n * storage: filesystemStorageAdapter, // Platform-specific\n * });\n *\n * // Extension\n * const service = new StorageService({\n * messenger: storageServiceMessenger,\n * storage: indexedDBAdapter, // Platform-specific\n * });\n *\n * // Tests (uses in-memory by default)\n * const service = new StorageService({\n * messenger: storageServiceMessenger,\n * // No storage - uses InMemoryStorageAdapter\n * });\n * ```\n */\nexport class StorageService {\n /**\n * The name of the service.\n */\n readonly name: typeof SERVICE_NAME;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: StorageServiceMessenger;\n\n /**\n * The storage adapter for persisting data.\n */\n readonly #storage: StorageAdapter;\n\n /**\n * Constructs a new StorageService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited for this service.\n * @param options.storage - Storage adapter for persisting data.\n * If not provided, uses InMemoryStorageAdapter (data lost on restart).\n */\n constructor({ messenger, storage }: StorageServiceOptions) {\n this.name = SERVICE_NAME;\n this.#messenger = messenger;\n this.#storage = storage ?? new InMemoryStorageAdapter();\n\n // Warn if using in-memory storage (data won't persist)\n if (!storage) {\n console.warn(\n `${SERVICE_NAME}: No storage adapter provided. Using in-memory storage. ` +\n 'Data will be lost on restart. Provide a storage adapter for persistence.',\n );\n }\n\n // Register messenger actions\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\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 */\n async setItem(namespace: string, key: string, value: Json): Promise<void> {\n // Adapter handles serialization and wrapping with metadata\n await this.#storage.setItem(namespace, key, value);\n\n // Publish event so other controllers can react to changes\n // Event type: StorageService:itemSet:namespace\n // Payload: [key, value]\n this.#messenger.publish(\n `${SERVICE_NAME}:itemSet:${namespace}` as const,\n key,\n value,\n );\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 */\n async getItem(namespace: string, key: string): Promise<StorageGetResult> {\n // Adapter handles deserialization and unwrapping\n return await this.#storage.getItem(namespace, key);\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 */\n async removeItem(namespace: string, key: string): Promise<void> {\n // Adapter builds full storage key (e.g., mobile: 'storageService:namespace:key')\n await this.#storage.removeItem(namespace, key);\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 */\n async getAllKeys(namespace: string): Promise<string[]> {\n return await this.#storage.getAllKeys(namespace);\n }\n\n /**\n * Clear all data for a namespace.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n */\n async clear(namespace: string): Promise<void> {\n await this.#storage.clear(namespace);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageService.d.cts","sourceRoot":"","sources":["../src/StorageService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAEV,gBAAgB,EAEhB,qBAAqB,EACtB,
|
|
1
|
+
{"version":3,"file":"StorageService.d.cts","sourceRoot":"","sources":["../src/StorageService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAEV,gBAAgB,EAEhB,qBAAqB,EACtB,oBAAmB;AACpB,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAY1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,qBAAa,cAAc;;IACzB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,YAAY,CAAC;IAYnC;;;;;;;OAOG;gBACS,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,qBAAqB;IAoBzD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAczE;;;;;;OAMG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKxE;;;;;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;IAItD;;;;OAIG;IACG,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageService.d.mts","sourceRoot":"","sources":["../src/StorageService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAEV,gBAAgB,EAEhB,qBAAqB,EACtB,
|
|
1
|
+
{"version":3,"file":"StorageService.d.mts","sourceRoot":"","sources":["../src/StorageService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAEV,gBAAgB,EAEhB,qBAAqB,EACtB,oBAAmB;AACpB,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAY1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,qBAAa,cAAc;;IACzB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,YAAY,CAAC;IAYnC;;;;;;;OAOG;gBACS,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,qBAAqB;IAoBzD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAczE;;;;;;OAMG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKxE;;;;;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;IAItD;;;;OAIG;IACG,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageService.mjs","sourceRoot":"","sources":["../src/StorageService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"StorageService.mjs","sourceRoot":"","sources":["../src/StorageService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAOrE,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAE1C,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,SAAS;IACT,SAAS;IACT,YAAY;IACZ,YAAY;IACZ,OAAO;CACC,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,MAAM,OAAO,cAAc;IAgBzB;;;;;;;OAOG;IACH,YAAY,EAAE,SAAS,EAAE,OAAO,EAAyB;QAlBzD;;WAEG;QACM,4CAAoC;QAE7C;;WAEG;QACM,0CAAyB;QAWhC,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,uBAAA,IAAI,6BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2BAAY,OAAO,IAAI,IAAI,sBAAsB,EAAE,MAAA,CAAC;QAExD,uDAAuD;QACvD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,IA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} from './InMemoryStorageAdapter.js';\nimport type {\n StorageAdapter,\n StorageGetResult,\n StorageServiceMessenger,\n StorageServiceOptions,\n} from './types.js';\nimport { SERVICE_NAME } from './types.js';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'setItem',\n 'getItem',\n 'removeItem',\n 'getAllKeys',\n 'clear',\n] as const;\n\n/**\n * StorageService provides a platform-agnostic way for controllers to store\n * large, infrequently accessed data outside of memory/Redux state.\n *\n * **Use cases:**\n * - Snap source code (6+ MB that's rarely accessed)\n * - Token metadata caches (4+ MB of cached data)\n * - Large cached responses from APIs\n * - Any data > 100 KB that's not frequently accessed\n *\n * **Benefits:**\n * - Reduces memory usage (data stays on disk)\n * - Faster Redux persist (less data to serialize)\n * - Faster app startup (less data to parse)\n * - Lazy loading (data loaded only when needed)\n *\n * **Platform Support:**\n * - Mobile: FilesystemStorage adapter\n * - Extension: IndexedDB adapter\n * - Tests/Dev: InMemoryStorageAdapter (default)\n *\n * @example Using the service via messenger\n *\n * ```typescript\n * // In a controller\n * type AllowedActions =\n * | StorageServiceSetItemAction\n * | StorageServiceGetItemAction;\n *\n * class SnapController extends BaseController {\n * async storeSnapSourceCode(snapId: string, sourceCode: string) {\n * await this.messenger.call(\n * 'StorageService:setItem',\n * 'SnapController',\n * `${snapId}:sourceCode`,\n * sourceCode,\n * );\n * }\n *\n * async getSnapSourceCode(snapId: string): Promise<string | undefined> {\n * const { result, error } = await this.messenger.call(\n * 'StorageService:getItem',\n * 'SnapController',\n * `${snapId}:sourceCode`,\n * );\n * if (error) {\n * throw error; // Handle error\n * }\n * return result as string | undefined; // undefined if not found\n * }\n * }\n * ```\n *\n * @example Initializing in a client\n *\n * ```typescript\n * // Mobile\n * const service = new StorageService({\n * messenger: storageServiceMessenger,\n * storage: filesystemStorageAdapter, // Platform-specific\n * });\n *\n * // Extension\n * const service = new StorageService({\n * messenger: storageServiceMessenger,\n * storage: indexedDBAdapter, // Platform-specific\n * });\n *\n * // Tests (uses in-memory by default)\n * const service = new StorageService({\n * messenger: storageServiceMessenger,\n * // No storage - uses InMemoryStorageAdapter\n * });\n * ```\n */\nexport class StorageService {\n /**\n * The name of the service.\n */\n readonly name: typeof SERVICE_NAME;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: StorageServiceMessenger;\n\n /**\n * The storage adapter for persisting data.\n */\n readonly #storage: StorageAdapter;\n\n /**\n * Constructs a new StorageService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited for this service.\n * @param options.storage - Storage adapter for persisting data.\n * If not provided, uses InMemoryStorageAdapter (data lost on restart).\n */\n constructor({ messenger, storage }: StorageServiceOptions) {\n this.name = SERVICE_NAME;\n this.#messenger = messenger;\n this.#storage = storage ?? new InMemoryStorageAdapter();\n\n // Warn if using in-memory storage (data won't persist)\n if (!storage) {\n console.warn(\n `${SERVICE_NAME}: No storage adapter provided. Using in-memory storage. ` +\n 'Data will be lost on restart. Provide a storage adapter for persistence.',\n );\n }\n\n // Register messenger actions\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\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 */\n async setItem(namespace: string, key: string, value: Json): Promise<void> {\n // Adapter handles serialization and wrapping with metadata\n await this.#storage.setItem(namespace, key, value);\n\n // Publish event so other controllers can react to changes\n // Event type: StorageService:itemSet:namespace\n // Payload: [key, value]\n this.#messenger.publish(\n `${SERVICE_NAME}:itemSet:${namespace}` as const,\n key,\n value,\n );\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 */\n async getItem(namespace: string, key: string): Promise<StorageGetResult> {\n // Adapter handles deserialization and unwrapping\n return await this.#storage.getItem(namespace, key);\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 */\n async removeItem(namespace: string, key: string): Promise<void> {\n // Adapter builds full storage key (e.g., mobile: 'storageService:namespace:key')\n await this.#storage.removeItem(namespace, key);\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 */\n async getAllKeys(namespace: string): Promise<string[]> {\n return await this.#storage.getAllKeys(namespace);\n }\n\n /**\n * Clear all data for a namespace.\n *\n * @param namespace - Controller namespace (e.g., 'SnapController').\n */\n async clear(namespace: string): Promise<void> {\n await this.#storage.clear(namespace);\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.STORAGE_KEY_PREFIX = exports.SERVICE_NAME = exports.InMemoryStorageAdapter = exports.StorageService = void 0;
|
|
4
4
|
// Export service class
|
|
5
|
-
var
|
|
6
|
-
Object.defineProperty(exports, "StorageService", { enumerable: true, get: function () { return
|
|
5
|
+
var StorageService_js_1 = require("./StorageService.cjs");
|
|
6
|
+
Object.defineProperty(exports, "StorageService", { enumerable: true, get: function () { return StorageService_js_1.StorageService; } });
|
|
7
7
|
// Export adapters
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "InMemoryStorageAdapter", { enumerable: true, get: function () { return
|
|
8
|
+
var InMemoryStorageAdapter_js_1 = require("./InMemoryStorageAdapter.cjs");
|
|
9
|
+
Object.defineProperty(exports, "InMemoryStorageAdapter", { enumerable: true, get: function () { return InMemoryStorageAdapter_js_1.InMemoryStorageAdapter; } });
|
|
10
10
|
// Export service name and storage key prefix constants
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "SERVICE_NAME", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "STORAGE_KEY_PREFIX", { enumerable: true, get: function () { return
|
|
11
|
+
var types_js_1 = require("./types.cjs");
|
|
12
|
+
Object.defineProperty(exports, "SERVICE_NAME", { enumerable: true, get: function () { return types_js_1.SERVICE_NAME; } });
|
|
13
|
+
Object.defineProperty(exports, "STORAGE_KEY_PREFIX", { enumerable: true, get: function () { return types_js_1.STORAGE_KEY_PREFIX; } });
|
|
14
14
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uBAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uBAAuB;AACvB,0DAAqD;AAA5C,mHAAA,cAAc,OAAA;AAEvB,kBAAkB;AAClB,0EAAqE;AAA5D,mIAAA,sBAAsB,OAAA;AAuB/B,uDAAuD;AACvD,wCAA8D;AAArD,wGAAA,YAAY,OAAA;AAAE,8GAAA,kBAAkB,OAAA","sourcesContent":["// Export service class\nexport { StorageService } from './StorageService.js';\n\n// Export adapters\nexport { InMemoryStorageAdapter } from './InMemoryStorageAdapter.js';\n\n// Export types from types.ts\nexport type {\n InitialStorageData,\n StorageAdapter,\n StorageGetResult,\n StorageServiceOptions,\n StorageServiceActions,\n StorageServiceEvents,\n StorageServiceMessenger,\n StorageServiceItemSetEvent,\n} from './types.js';\n\n// Export individual action types from generated file\nexport type {\n StorageServiceSetItemAction,\n StorageServiceGetItemAction,\n StorageServiceRemoveItemAction,\n StorageServiceGetAllKeysAction,\n StorageServiceClearAction,\n} from './StorageService-method-action-types.js';\n\n// Export service name and storage key prefix constants\nexport { SERVICE_NAME, STORAGE_KEY_PREFIX } from './types.js';\n"]}
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,6BAA4B;AAGrD,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAGrE,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,GAC3B,oBAAmB;AAGpB,YAAY,EACV,2BAA2B,EAC3B,2BAA2B,EAC3B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,GAC1B,iDAAgD;AAGjD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAmB"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,6BAA4B;AAGrD,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAGrE,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,GAC3B,oBAAmB;AAGpB,YAAY,EACV,2BAA2B,EAC3B,2BAA2B,EAC3B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,GAC1B,iDAAgD;AAGjD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAmB"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,OAAO,EAAE,cAAc,EAAE,6BAA4B;AAErD,kBAAkB;AAClB,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAuBrE,uDAAuD;AACvD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAmB","sourcesContent":["// Export service class\nexport { StorageService } from './StorageService.js';\n\n// Export adapters\nexport { InMemoryStorageAdapter } from './InMemoryStorageAdapter.js';\n\n// Export types from types.ts\nexport type {\n InitialStorageData,\n StorageAdapter,\n StorageGetResult,\n StorageServiceOptions,\n StorageServiceActions,\n StorageServiceEvents,\n StorageServiceMessenger,\n StorageServiceItemSetEvent,\n} from './types.js';\n\n// Export individual action types from generated file\nexport type {\n StorageServiceSetItemAction,\n StorageServiceGetItemAction,\n StorageServiceRemoveItemAction,\n StorageServiceGetAllKeysAction,\n StorageServiceClearAction,\n} from './StorageService-method-action-types.js';\n\n// Export service name and storage key prefix constants\nexport { SERVICE_NAME, STORAGE_KEY_PREFIX } from './types.js';\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAgJA,wBAAwB;AACX,QAAA,YAAY,GAAG,gBAAgB,CAAC;AAE7C;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,iBAAiB,CAAC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { StorageServiceMethodActions } from './StorageService-method-action-types';\n\n/**\n * Initial data structure for populating InMemoryStorageAdapter.\n * Useful for setting up test fixtures.\n *\n * @example\n * ```typescript\n * const initialData: InitialStorageData = {\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 * const adapter = new InMemoryStorageAdapter(initialData);\n * ```\n */\nexport type InitialStorageData = {\n [namespace: string]: {\n [key: string]: Json;\n };\n};\n\n/**\n * Result type for getItem operations.\n * Distinguishes between: found data, not found, and error conditions.\n *\n * - `{ result: Json }` - Data was found and successfully retrieved\n * - `{}` (empty object) - No data stored with that key\n * - `{ error: Error }` - Error occurred during retrieval\n */\nexport type StorageGetResult =\n | { result: Json; error?: never }\n | { result?: never; error: Error }\n | Record<string, never>;\n\n/**\n * Platform-agnostic storage adapter interface.\n * Each client (mobile, extension) implements this interface\n * with their preferred storage mechanism.\n *\n * ⚠️ **Designed for large, infrequently accessed data (100KB+)**\n *\n * ✅ **Use for:**\n * - Snap source code (~6 MB per snap)\n * - Token metadata caches (~4 MB)\n * - Large API response caches\n *\n * ❌ **Avoid for:**\n * - Small values (< 10 KB) - use controller state instead\n * - Frequently accessed data - use controller state instead\n * - Many small key-value pairs - use a single large object instead\n *\n * @example Mobile implementation using FilesystemStorage\n * @example Extension implementation using IndexedDB\n * @example Tests using InMemoryStorageAdapter\n */\nexport type StorageAdapter = {\n /**\n * Retrieve an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\n getItem(namespace: string, key: string): Promise<StorageGetResult>;\n\n /**\n * Store a large JSON value in storage.\n *\n * ⚠️ **Store large values, 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 * - Minimum recommended size: 100 KB per value\n *\n * Adapter is responsible for:\n * - Building the full storage key\n * - Serializing to string (JSON.stringify)\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @param value - The JSON value to store.\n */\n setItem(namespace: string, key: string, value: Json): Promise<void>;\n\n /**\n * Remove an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n */\n removeItem(namespace: string, key: string): Promise<void>;\n\n /**\n * Get all keys for a specific namespace.\n * Should return keys without the 'storage:namespace:' prefix.\n *\n * Adapter is responsible for:\n * - Filtering keys by prefix: 'storage:{namespace}:'\n * - Stripping the prefix from returned keys\n * - Returning only the key portion after the prefix\n *\n * @param namespace - The namespace to get keys for (e.g., 'SnapController').\n * @returns Array of keys without prefix (e.g., ['snap1:sourceCode', 'snap2:sourceCode']).\n */\n getAllKeys(namespace: string): Promise<string[]>;\n\n /**\n * Clear all items for a specific namespace.\n *\n * Adapter is responsible for:\n * - Finding all keys with prefix: 'storageService:{namespace}:'\n * - Removing all matching keys\n *\n * @param namespace - The namespace to clear (e.g., 'SnapController').\n */\n clear(namespace: string): Promise<void>;\n};\n\n/**\n * Options for constructing a {@link StorageService}.\n */\nexport type StorageServiceOptions = {\n /**\n * The messenger suited for this service.\n */\n messenger: StorageServiceMessenger;\n\n /**\n * Storage adapter for persisting data.\n * If not provided, uses in-memory storage (data lost on restart).\n * Production clients MUST provide a persistent storage adapter.\n */\n storage?: StorageAdapter;\n};\n\n// Service name constant\nexport const SERVICE_NAME = 'StorageService';\n\n/**\n * Storage key prefix for all keys managed by StorageService.\n * Keys are formatted as: {STORAGE_KEY_PREFIX}{namespace}:{key}\n * Example: 'storageService:SnapController:snap-id:sourceCode'\n */\nexport const STORAGE_KEY_PREFIX = 'storageService:';\n\n/**\n * All actions that {@link StorageService} exposes to other consumers.\n * Action types are auto-generated from the service methods.\n */\nexport type StorageServiceActions = StorageServiceMethodActions;\n\n/**\n * Event published when a storage item is set.\n * Event type includes namespace only, key passed in payload.\n *\n * @example\n * Subscribe to all changes in TokenListController:\n * messenger.subscribe('StorageService:itemSet:TokenListController', (key, value) => {\n * // key = 'cache:0x1', 'cache:0x38', etc.\n * // value = the data that was set\n * if (key.startsWith('cache:')) {\n * const chainId = key.replace('cache:', '');\n * // React to cache change for specific chain\n * }\n * });\n */\nexport type StorageServiceItemSetEvent = {\n type: `${typeof SERVICE_NAME}:itemSet:${string}`;\n payload: [key: string, value: Json];\n};\n\n/**\n * All events that {@link StorageService} publishes.\n */\nexport type StorageServiceEvents = StorageServiceItemSetEvent;\n\n/**\n * Actions from other messengers that {@link StorageService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events from other messengers that {@link StorageService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link StorageService} needs to access.\n */\nexport type StorageServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n StorageServiceActions | AllowedActions,\n StorageServiceEvents | AllowedEvents\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAgJA,wBAAwB;AACX,QAAA,YAAY,GAAG,gBAAgB,CAAC;AAE7C;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,iBAAiB,CAAC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { StorageServiceMethodActions } from './StorageService-method-action-types.js';\n\n/**\n * Initial data structure for populating InMemoryStorageAdapter.\n * Useful for setting up test fixtures.\n *\n * @example\n * ```typescript\n * const initialData: InitialStorageData = {\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 * const adapter = new InMemoryStorageAdapter(initialData);\n * ```\n */\nexport type InitialStorageData = {\n [namespace: string]: {\n [key: string]: Json;\n };\n};\n\n/**\n * Result type for getItem operations.\n * Distinguishes between: found data, not found, and error conditions.\n *\n * - `{ result: Json }` - Data was found and successfully retrieved\n * - `{}` (empty object) - No data stored with that key\n * - `{ error: Error }` - Error occurred during retrieval\n */\nexport type StorageGetResult =\n | { result: Json; error?: never }\n | { result?: never; error: Error }\n | Record<string, never>;\n\n/**\n * Platform-agnostic storage adapter interface.\n * Each client (mobile, extension) implements this interface\n * with their preferred storage mechanism.\n *\n * ⚠️ **Designed for large, infrequently accessed data (100KB+)**\n *\n * ✅ **Use for:**\n * - Snap source code (~6 MB per snap)\n * - Token metadata caches (~4 MB)\n * - Large API response caches\n *\n * ❌ **Avoid for:**\n * - Small values (< 10 KB) - use controller state instead\n * - Frequently accessed data - use controller state instead\n * - Many small key-value pairs - use a single large object instead\n *\n * @example Mobile implementation using FilesystemStorage\n * @example Extension implementation using IndexedDB\n * @example Tests using InMemoryStorageAdapter\n */\nexport type StorageAdapter = {\n /**\n * Retrieve an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\n getItem(namespace: string, key: string): Promise<StorageGetResult>;\n\n /**\n * Store a large JSON value in storage.\n *\n * ⚠️ **Store large values, 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 * - Minimum recommended size: 100 KB per value\n *\n * Adapter is responsible for:\n * - Building the full storage key\n * - Serializing to string (JSON.stringify)\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @param value - The JSON value to store.\n */\n setItem(namespace: string, key: string, value: Json): Promise<void>;\n\n /**\n * Remove an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n */\n removeItem(namespace: string, key: string): Promise<void>;\n\n /**\n * Get all keys for a specific namespace.\n * Should return keys without the 'storage:namespace:' prefix.\n *\n * Adapter is responsible for:\n * - Filtering keys by prefix: 'storage:{namespace}:'\n * - Stripping the prefix from returned keys\n * - Returning only the key portion after the prefix\n *\n * @param namespace - The namespace to get keys for (e.g., 'SnapController').\n * @returns Array of keys without prefix (e.g., ['snap1:sourceCode', 'snap2:sourceCode']).\n */\n getAllKeys(namespace: string): Promise<string[]>;\n\n /**\n * Clear all items for a specific namespace.\n *\n * Adapter is responsible for:\n * - Finding all keys with prefix: 'storageService:{namespace}:'\n * - Removing all matching keys\n *\n * @param namespace - The namespace to clear (e.g., 'SnapController').\n */\n clear(namespace: string): Promise<void>;\n};\n\n/**\n * Options for constructing a {@link StorageService}.\n */\nexport type StorageServiceOptions = {\n /**\n * The messenger suited for this service.\n */\n messenger: StorageServiceMessenger;\n\n /**\n * Storage adapter for persisting data.\n * If not provided, uses in-memory storage (data lost on restart).\n * Production clients MUST provide a persistent storage adapter.\n */\n storage?: StorageAdapter;\n};\n\n// Service name constant\nexport const SERVICE_NAME = 'StorageService';\n\n/**\n * Storage key prefix for all keys managed by StorageService.\n * Keys are formatted as: {STORAGE_KEY_PREFIX}{namespace}:{key}\n * Example: 'storageService:SnapController:snap-id:sourceCode'\n */\nexport const STORAGE_KEY_PREFIX = 'storageService:';\n\n/**\n * All actions that {@link StorageService} exposes to other consumers.\n * Action types are auto-generated from the service methods.\n */\nexport type StorageServiceActions = StorageServiceMethodActions;\n\n/**\n * Event published when a storage item is set.\n * Event type includes namespace only, key passed in payload.\n *\n * @example\n * Subscribe to all changes in TokenListController:\n * messenger.subscribe('StorageService:itemSet:TokenListController', (key, value) => {\n * // key = 'cache:0x1', 'cache:0x38', etc.\n * // value = the data that was set\n * if (key.startsWith('cache:')) {\n * const chainId = key.replace('cache:', '');\n * // React to cache change for specific chain\n * }\n * });\n */\nexport type StorageServiceItemSetEvent = {\n type: `${typeof SERVICE_NAME}:itemSet:${string}`;\n payload: [key: string, value: Json];\n};\n\n/**\n * All events that {@link StorageService} publishes.\n */\nexport type StorageServiceEvents = StorageServiceItemSetEvent;\n\n/**\n * Actions from other messengers that {@link StorageService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events from other messengers that {@link StorageService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link StorageService} needs to access.\n */\nexport type StorageServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n StorageServiceActions | AllowedActions,\n StorageServiceEvents | AllowedEvents\n>;\n"]}
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,2BAA2B,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,2BAA2B,EAAE,iDAAgD;AAE3F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,CAAC,SAAS,EAAE,MAAM,GAAG;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;CACH,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,gB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AAG;IACvC,IAAI,EAAE,GAAG,OAAO,YAAY,YAAY,MAAM,EAAE,CAAC;IACjD,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE9D;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAC7C,OAAO,YAAY,EACnB,qBAAqB,GAAG,cAAc,EACtC,oBAAoB,GAAG,aAAa,CACrC,CAAC"}
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,2BAA2B,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,2BAA2B,EAAE,iDAAgD;AAE3F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,CAAC,SAAS,EAAE,MAAM,GAAG;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;CACH,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAC/B;IAAE,MAAM,CAAC,E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E,KAAK,EAAE,IAAI,CAAC,CAAC;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE9D;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAC7C,OAAO,YAAY,EACnB,qBAAqB,GAAG,cAAc,EACtC,oBAAoB,GAAG,aAAa,CACrC,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAgJA,wBAAwB;AACxB,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { StorageServiceMethodActions } from './StorageService-method-action-types';\n\n/**\n * Initial data structure for populating InMemoryStorageAdapter.\n * Useful for setting up test fixtures.\n *\n * @example\n * ```typescript\n * const initialData: InitialStorageData = {\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 * const adapter = new InMemoryStorageAdapter(initialData);\n * ```\n */\nexport type InitialStorageData = {\n [namespace: string]: {\n [key: string]: Json;\n };\n};\n\n/**\n * Result type for getItem operations.\n * Distinguishes between: found data, not found, and error conditions.\n *\n * - `{ result: Json }` - Data was found and successfully retrieved\n * - `{}` (empty object) - No data stored with that key\n * - `{ error: Error }` - Error occurred during retrieval\n */\nexport type StorageGetResult =\n | { result: Json; error?: never }\n | { result?: never; error: Error }\n | Record<string, never>;\n\n/**\n * Platform-agnostic storage adapter interface.\n * Each client (mobile, extension) implements this interface\n * with their preferred storage mechanism.\n *\n * ⚠️ **Designed for large, infrequently accessed data (100KB+)**\n *\n * ✅ **Use for:**\n * - Snap source code (~6 MB per snap)\n * - Token metadata caches (~4 MB)\n * - Large API response caches\n *\n * ❌ **Avoid for:**\n * - Small values (< 10 KB) - use controller state instead\n * - Frequently accessed data - use controller state instead\n * - Many small key-value pairs - use a single large object instead\n *\n * @example Mobile implementation using FilesystemStorage\n * @example Extension implementation using IndexedDB\n * @example Tests using InMemoryStorageAdapter\n */\nexport type StorageAdapter = {\n /**\n * Retrieve an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\n getItem(namespace: string, key: string): Promise<StorageGetResult>;\n\n /**\n * Store a large JSON value in storage.\n *\n * ⚠️ **Store large values, 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 * - Minimum recommended size: 100 KB per value\n *\n * Adapter is responsible for:\n * - Building the full storage key\n * - Serializing to string (JSON.stringify)\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @param value - The JSON value to store.\n */\n setItem(namespace: string, key: string, value: Json): Promise<void>;\n\n /**\n * Remove an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n */\n removeItem(namespace: string, key: string): Promise<void>;\n\n /**\n * Get all keys for a specific namespace.\n * Should return keys without the 'storage:namespace:' prefix.\n *\n * Adapter is responsible for:\n * - Filtering keys by prefix: 'storage:{namespace}:'\n * - Stripping the prefix from returned keys\n * - Returning only the key portion after the prefix\n *\n * @param namespace - The namespace to get keys for (e.g., 'SnapController').\n * @returns Array of keys without prefix (e.g., ['snap1:sourceCode', 'snap2:sourceCode']).\n */\n getAllKeys(namespace: string): Promise<string[]>;\n\n /**\n * Clear all items for a specific namespace.\n *\n * Adapter is responsible for:\n * - Finding all keys with prefix: 'storageService:{namespace}:'\n * - Removing all matching keys\n *\n * @param namespace - The namespace to clear (e.g., 'SnapController').\n */\n clear(namespace: string): Promise<void>;\n};\n\n/**\n * Options for constructing a {@link StorageService}.\n */\nexport type StorageServiceOptions = {\n /**\n * The messenger suited for this service.\n */\n messenger: StorageServiceMessenger;\n\n /**\n * Storage adapter for persisting data.\n * If not provided, uses in-memory storage (data lost on restart).\n * Production clients MUST provide a persistent storage adapter.\n */\n storage?: StorageAdapter;\n};\n\n// Service name constant\nexport const SERVICE_NAME = 'StorageService';\n\n/**\n * Storage key prefix for all keys managed by StorageService.\n * Keys are formatted as: {STORAGE_KEY_PREFIX}{namespace}:{key}\n * Example: 'storageService:SnapController:snap-id:sourceCode'\n */\nexport const STORAGE_KEY_PREFIX = 'storageService:';\n\n/**\n * All actions that {@link StorageService} exposes to other consumers.\n * Action types are auto-generated from the service methods.\n */\nexport type StorageServiceActions = StorageServiceMethodActions;\n\n/**\n * Event published when a storage item is set.\n * Event type includes namespace only, key passed in payload.\n *\n * @example\n * Subscribe to all changes in TokenListController:\n * messenger.subscribe('StorageService:itemSet:TokenListController', (key, value) => {\n * // key = 'cache:0x1', 'cache:0x38', etc.\n * // value = the data that was set\n * if (key.startsWith('cache:')) {\n * const chainId = key.replace('cache:', '');\n * // React to cache change for specific chain\n * }\n * });\n */\nexport type StorageServiceItemSetEvent = {\n type: `${typeof SERVICE_NAME}:itemSet:${string}`;\n payload: [key: string, value: Json];\n};\n\n/**\n * All events that {@link StorageService} publishes.\n */\nexport type StorageServiceEvents = StorageServiceItemSetEvent;\n\n/**\n * Actions from other messengers that {@link StorageService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events from other messengers that {@link StorageService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link StorageService} needs to access.\n */\nexport type StorageServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n StorageServiceActions | AllowedActions,\n StorageServiceEvents | AllowedEvents\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAgJA,wBAAwB;AACxB,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { StorageServiceMethodActions } from './StorageService-method-action-types.js';\n\n/**\n * Initial data structure for populating InMemoryStorageAdapter.\n * Useful for setting up test fixtures.\n *\n * @example\n * ```typescript\n * const initialData: InitialStorageData = {\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 * const adapter = new InMemoryStorageAdapter(initialData);\n * ```\n */\nexport type InitialStorageData = {\n [namespace: string]: {\n [key: string]: Json;\n };\n};\n\n/**\n * Result type for getItem operations.\n * Distinguishes between: found data, not found, and error conditions.\n *\n * - `{ result: Json }` - Data was found and successfully retrieved\n * - `{}` (empty object) - No data stored with that key\n * - `{ error: Error }` - Error occurred during retrieval\n */\nexport type StorageGetResult =\n | { result: Json; error?: never }\n | { result?: never; error: Error }\n | Record<string, never>;\n\n/**\n * Platform-agnostic storage adapter interface.\n * Each client (mobile, extension) implements this interface\n * with their preferred storage mechanism.\n *\n * ⚠️ **Designed for large, infrequently accessed data (100KB+)**\n *\n * ✅ **Use for:**\n * - Snap source code (~6 MB per snap)\n * - Token metadata caches (~4 MB)\n * - Large API response caches\n *\n * ❌ **Avoid for:**\n * - Small values (< 10 KB) - use controller state instead\n * - Frequently accessed data - use controller state instead\n * - Many small key-value pairs - use a single large object instead\n *\n * @example Mobile implementation using FilesystemStorage\n * @example Extension implementation using IndexedDB\n * @example Tests using InMemoryStorageAdapter\n */\nexport type StorageAdapter = {\n /**\n * Retrieve an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @returns StorageGetResult: { result } if found, {} if not found, { error } on failure.\n */\n getItem(namespace: string, key: string): Promise<StorageGetResult>;\n\n /**\n * Store a large JSON value in storage.\n *\n * ⚠️ **Store large values, 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 * - Minimum recommended size: 100 KB per value\n *\n * Adapter is responsible for:\n * - Building the full storage key\n * - Serializing to string (JSON.stringify)\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n * @param value - The JSON value to store.\n */\n setItem(namespace: string, key: string, value: Json): Promise<void>;\n\n /**\n * Remove an item from storage.\n * Adapter is responsible for building the full storage key.\n *\n * @param namespace - The controller namespace (e.g., 'SnapController').\n * @param key - The data key (e.g., 'snap-id:sourceCode').\n */\n removeItem(namespace: string, key: string): Promise<void>;\n\n /**\n * Get all keys for a specific namespace.\n * Should return keys without the 'storage:namespace:' prefix.\n *\n * Adapter is responsible for:\n * - Filtering keys by prefix: 'storage:{namespace}:'\n * - Stripping the prefix from returned keys\n * - Returning only the key portion after the prefix\n *\n * @param namespace - The namespace to get keys for (e.g., 'SnapController').\n * @returns Array of keys without prefix (e.g., ['snap1:sourceCode', 'snap2:sourceCode']).\n */\n getAllKeys(namespace: string): Promise<string[]>;\n\n /**\n * Clear all items for a specific namespace.\n *\n * Adapter is responsible for:\n * - Finding all keys with prefix: 'storageService:{namespace}:'\n * - Removing all matching keys\n *\n * @param namespace - The namespace to clear (e.g., 'SnapController').\n */\n clear(namespace: string): Promise<void>;\n};\n\n/**\n * Options for constructing a {@link StorageService}.\n */\nexport type StorageServiceOptions = {\n /**\n * The messenger suited for this service.\n */\n messenger: StorageServiceMessenger;\n\n /**\n * Storage adapter for persisting data.\n * If not provided, uses in-memory storage (data lost on restart).\n * Production clients MUST provide a persistent storage adapter.\n */\n storage?: StorageAdapter;\n};\n\n// Service name constant\nexport const SERVICE_NAME = 'StorageService';\n\n/**\n * Storage key prefix for all keys managed by StorageService.\n * Keys are formatted as: {STORAGE_KEY_PREFIX}{namespace}:{key}\n * Example: 'storageService:SnapController:snap-id:sourceCode'\n */\nexport const STORAGE_KEY_PREFIX = 'storageService:';\n\n/**\n * All actions that {@link StorageService} exposes to other consumers.\n * Action types are auto-generated from the service methods.\n */\nexport type StorageServiceActions = StorageServiceMethodActions;\n\n/**\n * Event published when a storage item is set.\n * Event type includes namespace only, key passed in payload.\n *\n * @example\n * Subscribe to all changes in TokenListController:\n * messenger.subscribe('StorageService:itemSet:TokenListController', (key, value) => {\n * // key = 'cache:0x1', 'cache:0x38', etc.\n * // value = the data that was set\n * if (key.startsWith('cache:')) {\n * const chainId = key.replace('cache:', '');\n * // React to cache change for specific chain\n * }\n * });\n */\nexport type StorageServiceItemSetEvent = {\n type: `${typeof SERVICE_NAME}:itemSet:${string}`;\n payload: [key: string, value: Json];\n};\n\n/**\n * All events that {@link StorageService} publishes.\n */\nexport type StorageServiceEvents = StorageServiceItemSetEvent;\n\n/**\n * Actions from other messengers that {@link StorageService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events from other messengers that {@link StorageService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link StorageService} needs to access.\n */\nexport type StorageServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n StorageServiceActions | AllowedActions,\n StorageServiceEvents | AllowedEvents\n>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/storage-service",
|
|
3
|
-
"version": "1.0.2-preview-
|
|
3
|
+
"version": "1.0.2-preview-a3e31582e",
|
|
4
4
|
"description": "Platform-agnostic service for storing large, infrequently accessed controller data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/storage-service",
|
|
47
47
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
48
48
|
"lint:tsconfigs:fix": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts --fix",
|
|
49
|
-
"messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --check",
|
|
50
|
-
"messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --generate",
|
|
49
|
+
"messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
|
|
50
|
+
"messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
|
|
51
51
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
52
52
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
53
53
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@metamask/auto-changelog": "^6.1.0",
|
|
63
63
|
"@ts-bridge/cli": "^0.6.4",
|
|
64
|
-
"@types/jest": "^
|
|
64
|
+
"@types/jest": "^30.0.0",
|
|
65
65
|
"deepmerge": "^4.2.2",
|
|
66
|
-
"jest": "^
|
|
67
|
-
"ts-jest": "^29.
|
|
66
|
+
"jest": "^30.4.2",
|
|
67
|
+
"ts-jest": "^29.4.11",
|
|
68
68
|
"tsx": "^4.20.5",
|
|
69
69
|
"typedoc": "^0.25.13",
|
|
70
70
|
"typedoc-plugin-missing-exports": "^2.0.0",
|