@rozenite/storage-plugin 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/devtools/assets/panel-BlDRXgVW.js +32 -0
  3. package/dist/devtools/assets/panel-DBweZnW5.css +1 -0
  4. package/dist/devtools/panel.html +2 -2
  5. package/dist/react-native/chunks/index.require.js +1 -3
  6. package/dist/react-native/chunks/secure-storage.require.js +2 -6
  7. package/dist/react-native/chunks/useRozeniteStoragePlugin.require.cjs +1 -1
  8. package/dist/react-native/chunks/useRozeniteStoragePlugin.require.js +266 -295
  9. package/dist/react-native/index.d.ts +14 -2
  10. package/dist/react-native/index.js +2 -10
  11. package/dist/rozenite.json +1 -1
  12. package/package.json +29 -29
  13. package/react-native.ts +11 -36
  14. package/rozenite.config.ts +2 -6
  15. package/sdk.ts +1 -5
  16. package/src/react-native/__tests__/entry-preview-pagination.test.ts +12 -40
  17. package/src/react-native/__tests__/export-snapshot.test.ts +2 -6
  18. package/src/react-native/__tests__/full-entry-request.test.ts +5 -17
  19. package/src/react-native/__tests__/import.test.ts +9 -8
  20. package/src/react-native/__tests__/storage-discovery.test.ts +7 -18
  21. package/src/react-native/__tests__/stress-verification.test.ts +5 -18
  22. package/src/react-native/__tests__/use-storage-agent-tools.test.ts +25 -35
  23. package/src/react-native/adapters/__tests__/mmkv.test.ts +20 -30
  24. package/src/react-native/adapters/async-storage.ts +2 -5
  25. package/src/react-native/adapters/index.ts +2 -8
  26. package/src/react-native/adapters/mmkv.ts +7 -24
  27. package/src/react-native/adapters/secure-storage.ts +2 -6
  28. package/src/react-native/entry-preview-pagination.ts +11 -27
  29. package/src/react-native/export-snapshot.ts +3 -9
  30. package/src/react-native/full-entry-request.ts +3 -8
  31. package/src/react-native/import.ts +10 -21
  32. package/src/react-native/storage-discovery.ts +2 -6
  33. package/src/react-native/storage-view.ts +2 -6
  34. package/src/react-native/useRozeniteStoragePlugin.ts +107 -119
  35. package/src/react-native/useStorageAgentTools.ts +8 -24
  36. package/src/shared/__tests__/entry-preview.test.ts +9 -27
  37. package/src/shared/__tests__/snapshot.test.ts +10 -32
  38. package/src/shared/agent-tools.ts +9 -30
  39. package/src/shared/entry-preview.ts +3 -8
  40. package/src/shared/messaging.ts +15 -11
  41. package/src/shared/snapshot.ts +4 -17
  42. package/src/shared/types.ts +2 -4
  43. package/src/ui/__tests__/binary-value-editor-state.test.ts +6 -16
  44. package/src/ui/__tests__/binary.test.ts +13 -33
  45. package/src/ui/__tests__/large-value-viewer.test.tsx +4 -13
  46. package/src/ui/__tests__/panel.test.tsx +41 -68
  47. package/src/ui/__tests__/storage-groups.test.ts +1 -4
  48. package/src/ui/__tests__/type-conversion.test.ts +8 -24
  49. package/src/ui/__tests__/use-storage-entries.test.tsx +18 -34
  50. package/src/ui/add-entry-dialog.tsx +4 -15
  51. package/src/ui/binary-value-editor-state.ts +6 -24
  52. package/src/ui/binary-value-editor.tsx +5 -17
  53. package/src/ui/binary.ts +6 -19
  54. package/src/ui/edit-entry-dialog.tsx +3 -11
  55. package/src/ui/editor-switcher.tsx +2 -11
  56. package/src/ui/entry-detail-dialog.tsx +5 -14
  57. package/src/ui/format-value.tsx +2 -9
  58. package/src/ui/import-dialog.tsx +7 -19
  59. package/src/ui/large-value-viewer-state.ts +2 -9
  60. package/src/ui/large-value-viewer.tsx +3 -9
  61. package/src/ui/panel.tsx +65 -153
  62. package/src/ui/query-client.tsx +4 -15
  63. package/src/ui/type-conversion.ts +2 -5
  64. package/src/ui/typed-value-editor.tsx +1 -5
  65. package/src/ui/use-storage-entries.ts +6 -21
  66. package/src/ui/utils.ts +1 -4
  67. package/dist/devtools/assets/panel-B6Wp0eie.css +0 -1
  68. package/dist/devtools/assets/panel-D7MFc4HG.js +0 -32
@@ -1,7 +1,7 @@
1
1
  import { useRozeniteDevToolsClient as V } from "@rozenite/plugin-bridge";
2
2
  import { useMemo as z, useEffect as G } from "react";
3
3
  import { s as $, D as N, g as B } from "./types.js";
4
- import { useRozenitePluginAgentTool as f } from "@rozenite/agent-bridge";
4
+ import { useRozenitePluginAgentTool as I } from "@rozenite/agent-bridge";
5
5
  import { defineAgentToolContract as b, definePaginatedAgentToolContract as Y, DEFAULT_PAGE_LIMIT as Q, MAX_PAGE_LIMIT as J } from "@rozenite/agent-shared";
6
6
  const W = "@rozenite/storage-plugin", T = 1;
7
7
  class p extends Error {
@@ -9,48 +9,48 @@ class p extends Error {
9
9
  super(r), this.path = t;
10
10
  }
11
11
  }
12
- const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X = (e) => typeof e == "object" && e !== null && !Array.isArray(e), S = (e, t) => {
12
+ const y = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X = (e) => typeof e == "object" && e !== null && !Array.isArray(e), S = (e, t) => {
13
13
  if (!X(e))
14
- throw new p(t, `Expected object, got ${u(e)}`);
14
+ throw new p(t, `Expected object, got ${y(e)}`);
15
15
  return e;
16
- }, l = (e, t) => {
16
+ }, f = (e, t) => {
17
17
  if (typeof e != "string")
18
- throw new p(t, `Expected string, got ${u(e)}`);
18
+ throw new p(t, `Expected string, got ${y(e)}`);
19
19
  return e;
20
- }, M = (e, t) => {
20
+ }, C = (e, t) => {
21
21
  if (!Array.isArray(e))
22
- throw new p(t, `Expected array, got ${u(e)}`);
22
+ throw new p(t, `Expected array, got ${y(e)}`);
23
23
  return e;
24
- }, O = (e, t) => {
24
+ }, K = (e, t) => {
25
25
  if (typeof e != "string" || !N.includes(e))
26
26
  throw new p(
27
27
  t,
28
- `Expected one of ${N.join(", ")}, got ${u(e)}`
28
+ `Expected one of ${N.join(", ")}, got ${y(e)}`
29
29
  );
30
30
  return e;
31
31
  }, H = (e, t) => {
32
32
  const r = S(e, t);
33
- return { supportedTypes: M(r.supportedTypes, `${t}.supportedTypes`).map(
34
- (a, i) => O(a, `${t}.supportedTypes[${i}]`)
33
+ return { supportedTypes: C(r.supportedTypes, `${t}.supportedTypes`).map(
34
+ (a, i) => K(a, `${t}.supportedTypes[${i}]`)
35
35
  ) };
36
36
  }, Z = (e) => {
37
37
  const t = S(e, "storage");
38
38
  return {
39
- adapterId: l(t.adapterId, "storage.adapterId"),
40
- storageId: l(t.storageId, "storage.storageId"),
41
- adapterName: l(t.adapterName, "storage.adapterName"),
42
- storageName: l(t.storageName, "storage.storageName"),
39
+ adapterId: f(t.adapterId, "storage.adapterId"),
40
+ storageId: f(t.storageId, "storage.storageId"),
41
+ adapterName: f(t.adapterName, "storage.adapterName"),
42
+ storageName: f(t.storageName, "storage.storageName"),
43
43
  capabilities: H(t.capabilities, "storage.capabilities")
44
44
  };
45
45
  }, ee = (e, t) => {
46
- const r = S(e, t), o = l(r.key, `${t}.key`), s = O(r.type, `${t}.type`), a = `${t}.value`;
47
- switch (s) {
46
+ const r = S(e, t), o = f(r.key, `${t}.key`), n = K(r.type, `${t}.type`), a = `${t}.value`;
47
+ switch (n) {
48
48
  case "string": {
49
49
  const i = r.value;
50
50
  if (typeof i != "string")
51
51
  throw new p(
52
52
  a,
53
- `Expected string for type "string", got ${u(i)}`
53
+ `Expected string for type "string", got ${y(i)}`
54
54
  );
55
55
  return { key: o, type: "string", value: i };
56
56
  }
@@ -59,7 +59,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
59
59
  if (typeof i != "number" || !Number.isFinite(i))
60
60
  throw new p(
61
61
  a,
62
- `Expected finite number for type "number", got ${u(i)}`
62
+ `Expected finite number for type "number", got ${y(i)}`
63
63
  );
64
64
  return { key: o, type: "number", value: i };
65
65
  }
@@ -68,7 +68,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
68
68
  if (typeof i != "boolean")
69
69
  throw new p(
70
70
  a,
71
- `Expected boolean for type "boolean", got ${u(i)}`
71
+ `Expected boolean for type "boolean", got ${y(i)}`
72
72
  );
73
73
  return { key: o, type: "boolean", value: i };
74
74
  }
@@ -77,17 +77,17 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
77
77
  if (!Array.isArray(i))
78
78
  throw new p(
79
79
  a,
80
- `Expected number[] for type "buffer", got ${u(i)}`
80
+ `Expected number[] for type "buffer", got ${y(i)}`
81
81
  );
82
- const n = i.map((c, d) => {
82
+ const s = i.map((c, d) => {
83
83
  if (typeof c != "number" || !Number.isInteger(c) || c < 0 || c > 255)
84
84
  throw new p(
85
85
  `${a}[${d}]`,
86
- `Expected uint8 (integer 0-255), got ${u(c)}`
86
+ `Expected uint8 (integer 0-255), got ${y(c)}`
87
87
  );
88
88
  return c;
89
89
  });
90
- return { key: o, type: "buffer", value: n };
90
+ return { key: o, type: "buffer", value: s };
91
91
  }
92
92
  }
93
93
  }, te = (e) => {
@@ -96,19 +96,17 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
96
96
  if (r !== T)
97
97
  throw new p(
98
98
  "version",
99
- `Unsupported snapshot version: ${u(r)} (this build supports version ${T})`
99
+ `Unsupported snapshot version: ${y(r)} (this build supports version ${T})`
100
100
  );
101
- const o = l(t.plugin, "plugin"), s = l(t.createdAt, "createdAt"), a = Z(t.storage), n = M(t.entries, "entries").map(
102
- (c, d) => ee(c, `entries[${d}]`)
103
- );
101
+ const o = f(t.plugin, "plugin"), n = f(t.createdAt, "createdAt"), a = Z(t.storage), s = C(t.entries, "entries").map((c, d) => ee(c, `entries[${d}]`));
104
102
  return {
105
103
  ok: !0,
106
104
  snapshot: {
107
105
  version: T,
108
106
  plugin: o,
109
- createdAt: s,
107
+ createdAt: n,
110
108
  storage: a,
111
- entries: n
109
+ entries: s
112
110
  }
113
111
  };
114
112
  } catch (t) {
@@ -129,37 +127,37 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
129
127
  },
130
128
  entries: e.entries
131
129
  }), se = (e, t) => {
132
- const r = [], o = [], s = [], a = [], i = [];
130
+ const r = [], o = [], n = [], a = [], i = [];
133
131
  for (const [c, d] of e.entries.entries()) {
134
132
  if (!$(t.capabilities, d.type)) {
135
133
  a.push({ key: d.key, type: d.type });
136
134
  continue;
137
135
  }
138
136
  if (t.isBlacklisted(d.key)) {
139
- s.push({ key: d.key, reason: "blacklist" });
137
+ n.push({ key: d.key, reason: "blacklist" });
140
138
  continue;
141
139
  }
142
140
  t.entryKeys.has(d.key) ? o.push(d.key) : r.push(d.key), i.push(c), t.entryKeys.add(d.key);
143
141
  }
144
- const n = e.storage.adapterId !== t.target.adapterId || e.storage.storageId !== t.target.storageId;
142
+ const s = e.storage.adapterId !== t.target.adapterId || e.storage.storageId !== t.target.storageId;
145
143
  return {
146
144
  newKeys: r,
147
145
  overwriteKeys: o,
148
- skippedKeys: s,
146
+ skippedKeys: n,
149
147
  unsupportedTypes: a,
150
148
  acceptedEntryIndexes: i,
151
- metadataMismatch: n
149
+ metadataMismatch: s
152
150
  };
153
- }, ne = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, R = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.adapterId == "string" && e.adapterId.trim().length > 0 && typeof e.storageId == "string" && e.storageId.trim().length > 0, C = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.requestId == "string" ? e.requestId : "", oe = (e) => {
151
+ }, ne = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, R = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.adapterId == "string" && e.adapterId.trim().length > 0 && typeof e.storageId == "string" && e.storageId.trim().length > 0, M = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.requestId == "string" ? e.requestId : "", oe = (e) => {
154
152
  if (typeof e != "object" || e == null || Array.isArray(e))
155
153
  return !1;
156
154
  const t = e;
157
155
  return typeof t.key != "string" ? !1 : t.type === "string" ? typeof t.value == "string" : t.type === "number" ? typeof t.value == "number" : t.type === "boolean" ? typeof t.value == "boolean" : t.type === "buffer" && Array.isArray(t.value) && t.value.every(
158
156
  (r) => typeof r == "number" && Number.isInteger(r) && r >= 0 && r <= 255
159
157
  );
160
- }, K = (e, t) => e.blacklist ? (e.blacklist.lastIndex = 0, e.blacklist.test(t)) : !1, U = (e, t) => e.find((r) => ne(r.target, t)), ae = async (e, t) => {
161
- const r = C(t), o = t, s = te(o.snapshot);
162
- if (typeof o != "object" || o == null || o.type !== "preview-import" || typeof o.requestId != "string" || o.requestId.trim().length === 0 || !R(o.target) || !s.ok)
158
+ }, O = (e, t) => e.blacklist ? (e.blacklist.lastIndex = 0, e.blacklist.test(t)) : !1, U = (e, t) => e.find((r) => ne(r.target, t)), ae = async (e, t) => {
159
+ const r = M(t), o = t, n = te(o.snapshot);
160
+ if (typeof o != "object" || o == null || o.type !== "preview-import" || typeof o.requestId != "string" || o.requestId.trim().length === 0 || !R(o.target) || !n.ok)
163
161
  return {
164
162
  type: "storage-request-error",
165
163
  requestId: r,
@@ -180,11 +178,11 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
180
178
  type: "import-preview",
181
179
  requestId: r,
182
180
  target: a.target,
183
- preview: se(s.snapshot, {
181
+ preview: se(n.snapshot, {
184
182
  target: a.target,
185
183
  capabilities: a.capabilities,
186
184
  entryKeys: i,
187
- isBlacklisted: (n) => K(a, n)
185
+ isBlacklisted: (s) => O(a, s)
188
186
  })
189
187
  };
190
188
  } catch {
@@ -196,12 +194,12 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
196
194
  };
197
195
  }
198
196
  }, ie = async (e, t, r) => {
199
- const o = C(t), s = t;
200
- if (typeof s != "object" || s == null || s.type !== "import-entries" || typeof s.requestId != "string" || s.requestId.trim().length === 0 || !R(s.target) || !Array.isArray(s.entries) || !s.entries.every(oe)) {
197
+ const o = M(t), n = t;
198
+ if (typeof n != "object" || n == null || n.type !== "import-entries" || typeof n.requestId != "string" || n.requestId.trim().length === 0 || !R(n.target) || !Array.isArray(n.entries) || !n.entries.every(oe)) {
201
199
  r({
202
200
  type: "import-result",
203
201
  requestId: o,
204
- target: R(s.target) ? s.target : { adapterId: "", storageId: "" },
202
+ target: R(n.target) ? n.target : { adapterId: "", storageId: "" },
205
203
  ok: !1,
206
204
  written: 0,
207
205
  total: 0,
@@ -209,37 +207,42 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
209
207
  });
210
208
  return;
211
209
  }
212
- const a = U(e, s.target);
210
+ const a = U(e, n.target);
213
211
  if (!a) {
214
212
  r({
215
213
  type: "import-result",
216
- requestId: s.requestId,
217
- target: s.target,
214
+ requestId: n.requestId,
215
+ target: n.target,
218
216
  ok: !1,
219
217
  written: 0,
220
- total: s.entries.length,
218
+ total: n.entries.length,
221
219
  error: "Target storage not found"
222
220
  });
223
221
  return;
224
222
  }
225
- const i = s.entries.filter(
226
- (n) => $(a.capabilities, n.type) && !K(a, n.key)
223
+ const i = n.entries.filter(
224
+ (s) => $(a.capabilities, s.type) && !O(a, s.key)
227
225
  );
228
- for (let n = 0; n < i.length; n++) {
229
- const c = i[n];
226
+ for (let s = 0; s < i.length; s++) {
227
+ const c = i[s];
230
228
  try {
231
229
  await a.set(c);
232
230
  } catch (d) {
233
- n > 0 && r({
234
- type: "storage-invalidated",
235
- target: s.target,
236
- operation: "import"
237
- }), r({
231
+ if (s > 0) {
232
+ const g = (await a.getAllKeys()).length;
233
+ r({
234
+ type: "storage-invalidated",
235
+ target: n.target,
236
+ operation: "import",
237
+ entryCount: g
238
+ });
239
+ }
240
+ r({
238
241
  type: "import-result",
239
- requestId: s.requestId,
240
- target: s.target,
242
+ requestId: n.requestId,
243
+ target: n.target,
241
244
  ok: !1,
242
- written: n,
245
+ written: s,
243
246
  total: i.length,
244
247
  failedKey: c.key,
245
248
  error: d instanceof Error ? d.message : String(d)
@@ -248,20 +251,25 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
248
251
  }
249
252
  r({
250
253
  type: "import-progress",
251
- requestId: s.requestId,
252
- target: s.target,
253
- written: n + 1,
254
+ requestId: n.requestId,
255
+ target: n.target,
256
+ written: s + 1,
254
257
  total: i.length
255
258
  });
256
259
  }
257
- i.length > 0 && r({
258
- type: "storage-invalidated",
259
- target: s.target,
260
- operation: "import"
261
- }), r({
260
+ if (i.length > 0) {
261
+ const s = (await a.getAllKeys()).length;
262
+ r({
263
+ type: "storage-invalidated",
264
+ target: n.target,
265
+ operation: "import",
266
+ entryCount: s
267
+ });
268
+ }
269
+ r({
262
270
  type: "import-result",
263
- requestId: s.requestId,
264
- target: s.target,
271
+ requestId: n.requestId,
272
+ target: n.target,
265
273
  ok: !0,
266
274
  written: i.length,
267
275
  total: i.length
@@ -354,17 +362,17 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
354
362
  keySortDirection: t ?? "ascending",
355
363
  limit: Math.min(r.limit, me)
356
364
  };
357
- }, D = (e) => btoa(encodeURIComponent(JSON.stringify(e))), qe = (e) => {
365
+ }, D = (e) => btoa(encodeURIComponent(JSON.stringify(e))), Ae = (e) => {
358
366
  try {
359
367
  const t = JSON.parse(decodeURIComponent(atob(e)));
360
368
  return typeof t != "object" || t == null || Array.isArray(t) || t.version !== 1 || !L(t.target) || typeof t.search != "string" || t.keySortDirection !== "ascending" && t.keySortDirection !== "descending" || typeof t.boundaryKey != "string" || t.direction !== "next" && t.direction !== "previous" ? void 0 : t;
361
369
  } catch {
362
370
  return;
363
371
  }
364
- }, x = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, Ae = (e, t) => e < t ? -1 : e > t ? 1 : 0, Se = async (e, t) => {
372
+ }, x = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, qe = (e, t) => e < t ? -1 : e > t ? 1 : 0, Se = async (e, t) => {
365
373
  const r = new Array(t.length);
366
374
  let o = 0;
367
- const s = async () => {
375
+ const n = async () => {
368
376
  for (; o < t.length; ) {
369
377
  const a = o;
370
378
  o += 1;
@@ -373,13 +381,8 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
373
381
  }
374
382
  };
375
383
  return await Promise.all(
376
- Array.from(
377
- { length: Math.min(he, t.length) },
378
- s
379
- )
380
- ), r.filter(
381
- (a) => a != null
382
- );
384
+ Array.from({ length: Math.min(he, t.length) }, n)
385
+ ), r.filter((a) => a != null);
383
386
  }, ve = async (e, t) => {
384
387
  const r = we(t), o = Ee(t);
385
388
  if (!o)
@@ -389,10 +392,8 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
389
392
  code: "INVALID_REQUEST",
390
393
  message: "Entry preview requests require a valid target, request ID, and positive integer limit."
391
394
  };
392
- const s = e.find(
393
- (i) => x(i.target, o.target)
394
- );
395
- if (!s)
395
+ const n = e.find((i) => x(i.target, o.target));
396
+ if (!n)
396
397
  return {
397
398
  type: "storage-request-error",
398
399
  requestId: r,
@@ -400,7 +401,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
400
401
  message: "The requested storage target was not found."
401
402
  };
402
403
  let a;
403
- if (o.cursor !== void 0 && (a = qe(o.cursor), !a || !x(a.target, o.target) || a.search !== o.search || a.keySortDirection !== o.keySortDirection))
404
+ if (o.cursor !== void 0 && (a = Ae(o.cursor), !a || !x(a.target, o.target) || a.search !== o.search || a.keySortDirection !== o.keySortDirection))
404
405
  return {
405
406
  type: "storage-request-error",
406
407
  requestId: r,
@@ -409,12 +410,12 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
409
410
  resetPagination: !0
410
411
  };
411
412
  try {
412
- const i = (await s.getAllKeys()).filter((w) => w.toLowerCase().includes(o.search)).sort(Ae);
413
+ const i = (await n.getAllKeys()).filter((l) => l.toLowerCase().includes(o.search)).sort(qe);
413
414
  o.keySortDirection === "descending" && i.reverse();
414
- let n = 0;
415
+ let s = 0;
415
416
  if (a) {
416
- const w = i.indexOf(a.boundaryKey);
417
- if (w === -1)
417
+ const l = i.indexOf(a.boundaryKey);
418
+ if (l === -1)
418
419
  return {
419
420
  type: "storage-request-error",
420
421
  requestId: r,
@@ -422,9 +423,9 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
422
423
  message: "The entry preview cursor is stale after storage changes.",
423
424
  resetPagination: !0
424
425
  };
425
- n = a.direction === "next" ? w + 1 : Math.max(0, w - o.limit);
426
+ s = a.direction === "next" ? l + 1 : Math.max(0, l - o.limit);
426
427
  }
427
- const c = i.slice(n, n + o.limit), d = await Se(s, c), g = n + c.length, y = {
428
+ const c = i.slice(s, s + o.limit), d = await Se(n, c), g = s + c.length, u = {
428
429
  version: 1,
429
430
  target: o.target,
430
431
  search: o.search,
@@ -437,14 +438,14 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
437
438
  items: d,
438
439
  ...g < i.length && c.length > 0 ? {
439
440
  nextCursor: D({
440
- ...y,
441
+ ...u,
441
442
  boundaryKey: c.at(-1),
442
443
  direction: "next"
443
444
  })
444
445
  } : {},
445
- ...n > 0 && c.length > 0 ? {
446
+ ...s > 0 && c.length > 0 ? {
446
447
  previousCursor: D({
447
- ...y,
448
+ ...u,
448
449
  boundaryKey: c[0],
449
450
  direction: "previous"
450
451
  })
@@ -467,9 +468,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
467
468
  code: "INVALID_REQUEST",
468
469
  message: "Full entry requests require a valid target, request ID, and string key."
469
470
  };
470
- const o = e.find(
471
- (s) => $e(s.target, t.target)
472
- );
471
+ const o = e.find((n) => $e(n.target, t.target));
473
472
  if (!o)
474
473
  return {
475
474
  type: "storage-request-error",
@@ -478,12 +477,12 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
478
477
  message: "The requested storage target was not found."
479
478
  };
480
479
  try {
481
- const s = await o.get(t.key);
482
- return s ? {
480
+ const n = await o.get(t.key);
481
+ return n ? {
483
482
  type: "entry",
484
483
  requestId: r,
485
484
  target: o.target,
486
- entry: s
485
+ entry: n
487
486
  } : {
488
487
  type: "storage-request-error",
489
488
  requestId: r,
@@ -507,9 +506,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
507
506
  code: "INVALID_REQUEST",
508
507
  message: "Export requests require a valid target and request ID."
509
508
  };
510
- const o = e.find(
511
- (s) => _e(s.target, t.target)
512
- );
509
+ const o = e.find((n) => _e(n.target, t.target));
513
510
  if (!o)
514
511
  return {
515
512
  type: "storage-request-error",
@@ -518,7 +515,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
518
515
  message: "The requested storage target was not found."
519
516
  };
520
517
  try {
521
- const s = await o.getAllEntries();
518
+ const n = await o.getAllEntries();
522
519
  return {
523
520
  type: "export-snapshot-result",
524
521
  requestId: r,
@@ -528,7 +525,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
528
525
  adapterName: o.adapterName,
529
526
  storageName: o.storageName,
530
527
  capabilities: o.capabilities,
531
- entries: s
528
+ entries: n
532
529
  })
533
530
  };
534
531
  } catch {
@@ -539,39 +536,39 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
539
536
  message: "Failed to export the requested storage."
540
537
  };
541
538
  }
542
- }, v = (e) => e.kind === "async", A = (e, t) => e.shouldFilterKey?.(t) ? !0 : e.blacklist ? (e.blacklist.lastIndex = 0, e.blacklist.test(t)) : !1, Fe = (e, t, r) => {
539
+ }, v = (e) => e.kind === "async", q = (e, t) => e.shouldFilterKey?.(t) ? !0 : e.blacklist ? (e.blacklist.lastIndex = 0, e.blacklist.test(t)) : !1, Fe = (e, t, r) => {
543
540
  if (!$(e, t))
544
541
  throw new Error(
545
542
  `Type "${t}" is not supported by storage "${r.storageId}" in adapter "${r.adapterId}".`
546
543
  );
547
- }, _ = async (e) => (v(e), e.getAllKeys()), P = async (e, t) => (v(e), e.get(t)), Me = async (e, t) => {
544
+ }, _ = async (e) => (v(e), e.getAllKeys()), P = async (e, t) => (v(e), e.get(t)), Ce = async (e, t) => {
548
545
  if (v(e)) {
549
546
  await e.set(t);
550
547
  return;
551
548
  }
552
549
  e.set(t);
553
- }, Oe = async (e, t) => {
550
+ }, Ke = async (e, t) => {
554
551
  if (v(e)) {
555
552
  await e.delete(t);
556
553
  return;
557
554
  }
558
555
  e.delete(t);
559
- }, Ce = async (e) => {
556
+ }, Me = async (e) => {
560
557
  await e.clear();
561
- }, Ke = (e, t) => {
562
- const r = t.storage, o = r.subscribe, s = /* @__PURE__ */ new Set();
558
+ }, Oe = (e, t) => {
559
+ const r = t.storage, o = r.subscribe, n = /* @__PURE__ */ new Set();
563
560
  let a = !1;
564
561
  const i = {
565
562
  adapterId: e.id,
566
563
  storageId: t.id
567
- }, n = async (d) => {
568
- if (!A(t, d))
564
+ }, s = async (d) => {
565
+ if (!q(t, d))
569
566
  return P(r, d);
570
567
  }, c = async () => {
571
568
  const d = await _(r);
572
569
  return (await Promise.all(
573
- d.filter((y) => !A(t, y)).map((y) => P(r, y))
574
- )).filter((y) => !!y);
570
+ d.filter((u) => !q(t, u)).map((u) => P(r, u))
571
+ )).filter((u) => !!u);
575
572
  };
576
573
  return {
577
574
  id: B(i),
@@ -581,43 +578,41 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
581
578
  capabilities: t.capabilities,
582
579
  supportsSubscriptions: o != null,
583
580
  blacklist: t.blacklist,
584
- get: n,
581
+ get: s,
585
582
  set: async (d) => {
586
- Fe(t.capabilities, d.type, i), s.add(d.key);
583
+ Fe(t.capabilities, d.type, i), n.add(d.key);
587
584
  try {
588
- await Me(r, d);
585
+ await Ce(r, d);
589
586
  } finally {
590
- s.delete(d.key);
587
+ n.delete(d.key);
591
588
  }
592
589
  },
593
590
  delete: async (d) => {
594
- s.add(d);
591
+ n.add(d);
595
592
  try {
596
- await Oe(r, d);
593
+ await Ke(r, d);
597
594
  } finally {
598
- s.delete(d);
595
+ n.delete(d);
599
596
  }
600
597
  },
601
598
  purge: async () => {
602
599
  a = !0;
603
600
  try {
604
- await Ce(r);
601
+ await Me(r);
605
602
  } finally {
606
603
  a = !1;
607
604
  }
608
605
  },
609
- getAllKeys: async () => (await _(r)).filter((g) => !A(t, g)),
606
+ getAllKeys: async () => (await _(r)).filter((g) => !q(t, g)),
610
607
  getAllEntries: c,
611
608
  ...o ? {
612
609
  watch: async (d) => o((g) => {
613
- !a && !s.has(g) && !A(t, g) && d(g);
610
+ !a && !n.has(g) && !q(t, g) && d(g);
614
611
  })
615
612
  } : {}
616
613
  };
617
614
  }, Ue = (e) => e.flatMap(
618
- (t) => t.storages.map(
619
- (r) => Ke(t, r)
620
- )
615
+ (t) => t.storages.map((r) => Oe(t, r))
621
616
  ), E = {
622
617
  adapterId: {
623
618
  type: "string",
@@ -627,12 +622,12 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
627
622
  type: "string",
628
623
  description: "Storage node ID within the adapter. Required when multiple storages are configured."
629
624
  }
630
- }, I = "@rozenite/storage-plugin", j = [
625
+ }, m = "@rozenite/storage-plugin", j = [
631
626
  "string",
632
627
  "number",
633
628
  "boolean",
634
629
  "buffer"
635
- ], m = {
630
+ ], h = {
636
631
  listStorages: b({
637
632
  name: "list-storages",
638
633
  description: "List all storage adapters and their storage nodes currently available on the device, including supported entry types. Entry counts are omitted to avoid enumerating every storage.",
@@ -748,7 +743,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
748
743
  if (!Array.isArray(t) || !t.every((r) => Number.isInteger(r)))
749
744
  throw new Error("Expected number[] value for type=buffer");
750
745
  return t;
751
- }, h = (e) => `${e.target.adapterId}/${e.target.storageId}`, Le = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, Ve = (e) => btoa(encodeURIComponent(JSON.stringify(e))), ze = (e) => {
746
+ }, w = (e) => `${e.target.adapterId}/${e.target.storageId}`, Le = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, Ve = (e) => btoa(encodeURIComponent(JSON.stringify(e))), ze = (e) => {
752
747
  try {
753
748
  const t = JSON.parse(decodeURIComponent(atob(e)));
754
749
  if (typeof t != "object" || t == null || Array.isArray(t) || t.version !== 1 || typeof t.target?.adapterId != "string" || typeof t.target?.storageId != "string" || !Number.isSafeInteger(t.offset) || t.offset < 0)
@@ -759,29 +754,29 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
759
754
  "Invalid cursor. Run list-entries again without a cursor to restart pagination."
760
755
  );
761
756
  }
762
- }, Ge = (e) => typeof e != "number" || !Number.isFinite(e) || !Number.isInteger(e) || e < 1 ? Q : Math.min(e, J), Be = (e) => typeof e != "number" || !Number.isFinite(e) || !Number.isSafeInteger(e) || e < 0 ? 0 : e, q = (e, t, r) => {
757
+ }, Ge = (e) => typeof e != "number" || !Number.isFinite(e) || !Number.isInteger(e) || e < 1 ? Q : Math.min(e, J), Be = (e) => typeof e != "number" || !Number.isFinite(e) || !Number.isSafeInteger(e) || e < 0 ? 0 : e, A = (e, t, r) => {
763
758
  if (e.length === 0)
764
759
  throw new Error("No storages are registered.");
765
760
  if (t !== void 0 || r !== void 0) {
766
761
  const o = e.filter(
767
762
  (a) => (t === void 0 || a.target.adapterId === t) && (r === void 0 || a.target.storageId === r)
768
- ), s = [
763
+ ), n = [
769
764
  t !== void 0 && `adapterId="${t}"`,
770
765
  r !== void 0 && `storageId="${r}"`
771
766
  ].filter(Boolean).join(", ");
772
767
  if (o.length === 0)
773
768
  throw new Error(
774
- `No storage matched ${s}. Available: ${e.map(h).join(", ")}`
769
+ `No storage matched ${n}. Available: ${e.map(w).join(", ")}`
775
770
  );
776
771
  if (o.length > 1)
777
772
  throw new Error(
778
- `Multiple storages matched ${s}. Provide both adapterId and storageId. Available: ${o.map(h).join(", ")}`
773
+ `Multiple storages matched ${n}. Provide both adapterId and storageId. Available: ${o.map(w).join(", ")}`
779
774
  );
780
775
  return o[0];
781
776
  }
782
777
  if (e.length > 1)
783
778
  throw new Error(
784
- `Multiple storages detected. Provide adapterId and/or storageId. Available: ${e.map(h).join(", ")}`
779
+ `Multiple storages detected. Provide adapterId and/or storageId. Available: ${e.map(w).join(", ")}`
785
780
  );
786
781
  return e[0];
787
782
  }, Ye = async (e, t) => {
@@ -793,16 +788,16 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
793
788
  throw new Error(
794
789
  "Cursor does not match the requested storage. Run list-entries again without a cursor to restart pagination."
795
790
  );
796
- const s = await e.getAllKeys(), a = o?.offset ?? Be(t.offset), i = Math.min(a + r, s.length);
791
+ const n = await e.getAllKeys(), a = o?.offset ?? Be(t.offset), i = Math.min(a + r, n.length);
797
792
  return {
798
793
  adapterId: e.target.adapterId,
799
794
  storageId: e.target.storageId,
800
- total: s.length,
801
- items: s.slice(a, i).map((n) => ({ key: n })),
795
+ total: n.length,
796
+ items: n.slice(a, i).map((s) => ({ key: s })),
802
797
  page: {
803
798
  limit: r,
804
- hasMore: i < s.length,
805
- ...i < s.length ? {
799
+ hasMore: i < n.length,
800
+ ...i < n.length ? {
806
801
  nextCursor: Ve({
807
802
  version: 1,
808
803
  target: e.target,
@@ -822,7 +817,7 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
822
817
  }))
823
818
  }),
824
819
  listEntries: async (t) => {
825
- const r = q(e, t.adapterId, t.storageId);
820
+ const r = A(e, t.adapterId, t.storageId);
826
821
  return Ye(r, t);
827
822
  },
828
823
  readEntry: async ({
@@ -830,81 +825,77 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
830
825
  storageId: r,
831
826
  key: o
832
827
  }) => {
833
- const s = q(e, t, r), a = await s.get(o);
828
+ const n = A(e, t, r), a = await n.get(o);
834
829
  if (!a)
835
- throw new Error(
836
- `Key "${o}" not found in storage "${h(s)}".`
837
- );
830
+ throw new Error(`Key "${o}" not found in storage "${w(n)}".`);
838
831
  return {
839
- adapterId: s.target.adapterId,
840
- storageId: s.target.storageId,
832
+ adapterId: n.target.adapterId,
833
+ storageId: n.target.storageId,
841
834
  entry: a
842
835
  };
843
836
  }
844
837
  }), Je = (e) => {
845
838
  const t = Qe(e);
846
- f({
847
- pluginId: I,
848
- tool: m.listStorages,
839
+ I({
840
+ pluginId: m,
841
+ tool: h.listStorages,
849
842
  handler: t.listStorages
850
- }), f({
851
- pluginId: I,
852
- tool: m.listEntries,
843
+ }), I({
844
+ pluginId: m,
845
+ tool: h.listEntries,
853
846
  handler: t.listEntries
854
- }), f({
855
- pluginId: I,
856
- tool: m.readEntry,
847
+ }), I({
848
+ pluginId: m,
849
+ tool: h.readEntry,
857
850
  handler: t.readEntry
858
- }), f({
859
- pluginId: I,
860
- tool: m.createEntry,
861
- handler: async ({ adapterId: r, storageId: o, key: s, type: a, value: i }) => {
862
- const n = q(e, r, o);
863
- if (await n.get(s))
851
+ }), I({
852
+ pluginId: m,
853
+ tool: h.createEntry,
854
+ handler: async ({ adapterId: r, storageId: o, key: n, type: a, value: i }) => {
855
+ const s = A(e, r, o);
856
+ if (await s.get(n))
864
857
  throw new Error(
865
- `Key "${s}" already exists in storage "${h(n)}". Use edit-entry instead.`
858
+ `Key "${n}" already exists in storage "${w(s)}". Use edit-entry instead.`
866
859
  );
867
860
  const d = F(a, i);
868
- return await n.set({ key: s, type: a, value: d }), {
869
- adapterId: n.target.adapterId,
870
- storageId: n.target.storageId,
861
+ return await s.set({ key: n, type: a, value: d }), {
862
+ adapterId: s.target.adapterId,
863
+ storageId: s.target.storageId,
871
864
  created: !0,
872
- key: s
865
+ key: n
873
866
  };
874
867
  }
875
- }), f({
876
- pluginId: I,
877
- tool: m.editEntry,
878
- handler: async ({ adapterId: r, storageId: o, key: s, type: a, value: i }) => {
879
- const n = q(e, r, o);
880
- if (!await n.get(s))
868
+ }), I({
869
+ pluginId: m,
870
+ tool: h.editEntry,
871
+ handler: async ({ adapterId: r, storageId: o, key: n, type: a, value: i }) => {
872
+ const s = A(e, r, o);
873
+ if (!await s.get(n))
881
874
  throw new Error(
882
- `Key "${s}" not found in storage "${h(n)}". Use create-entry instead.`
875
+ `Key "${n}" not found in storage "${w(s)}". Use create-entry instead.`
883
876
  );
884
877
  const d = F(a, i);
885
- return await n.set({ key: s, type: a, value: d }), {
886
- adapterId: n.target.adapterId,
887
- storageId: n.target.storageId,
878
+ return await s.set({ key: n, type: a, value: d }), {
879
+ adapterId: s.target.adapterId,
880
+ storageId: s.target.storageId,
888
881
  edited: !0,
889
- key: s
882
+ key: n
890
883
  };
891
884
  }
892
- }), f({
893
- pluginId: I,
894
- tool: m.removeEntry,
895
- handler: async ({ adapterId: r, storageId: o, key: s }) => {
896
- const a = q(e, r, o), i = !!await a.get(s);
897
- return await a.delete(s), {
885
+ }), I({
886
+ pluginId: m,
887
+ tool: h.removeEntry,
888
+ handler: async ({ adapterId: r, storageId: o, key: n }) => {
889
+ const a = A(e, r, o), i = !!await a.get(n);
890
+ return await a.delete(n), {
898
891
  adapterId: a.target.adapterId,
899
892
  storageId: a.target.storageId,
900
893
  removed: i,
901
- key: s
894
+ key: n
902
895
  };
903
896
  }
904
897
  });
905
- }, tt = ({
906
- storages: e
907
- }) => {
898
+ }, tt = ({ storages: e }) => {
908
899
  const t = z(() => Ue(e), [e]);
909
900
  Je(t);
910
901
  const r = V({
@@ -914,150 +905,130 @@ const u = (e) => e === null ? "null" : Array.isArray(e) ? "array" : typeof e, X
914
905
  if (!r)
915
906
  return;
916
907
  const o = [];
917
- let s = !1;
918
- const a = (n, c, d) => {
908
+ let n = !1;
909
+ const a = async (s, c, d) => {
910
+ const g = t.find(
911
+ (l) => l.target.adapterId === s.adapterId && l.target.storageId === s.storageId
912
+ ), u = g ? (await g.getAllKeys()).length : 0;
919
913
  r.send("storage-invalidated", {
920
914
  type: "storage-invalidated",
921
- target: n,
915
+ target: s,
922
916
  key: c,
923
- operation: d
917
+ operation: d,
918
+ entryCount: u
924
919
  });
925
920
  };
926
921
  Promise.all(
927
- t.filter((n) => n.supportsSubscriptions && n.watch).map(async (n) => {
922
+ t.filter((s) => s.supportsSubscriptions && s.watch).map(async (s) => {
928
923
  try {
929
- const c = n.watch;
924
+ const c = s.watch;
930
925
  if (!c)
931
926
  return;
932
927
  const d = await c((g) => {
933
- a(n.target, g);
928
+ a(s.target, g);
934
929
  });
935
- if (s) {
930
+ if (n) {
936
931
  d.remove();
937
932
  return;
938
933
  }
939
934
  o.push(d);
940
935
  } catch (c) {
941
936
  console.warn(
942
- `[Rozenite] Storage Plugin: Failed to attach watcher for ${n.target.adapterId}/${n.target.storageId}.`,
937
+ `[Rozenite] Storage Plugin: Failed to attach watcher for ${s.target.adapterId}/${s.target.storageId}.`,
943
938
  c
944
939
  );
945
940
  }
946
941
  })
947
942
  );
948
943
  const i = [
949
- r.onMessage(
950
- "set-entry",
951
- async ({ target: n, entry: c }) => {
952
- const d = t.find(
953
- (g) => g.target.adapterId === n.adapterId && g.target.storageId === n.storageId
944
+ r.onMessage("set-entry", async ({ target: s, entry: c }) => {
945
+ const d = t.find(
946
+ (g) => g.target.adapterId === s.adapterId && g.target.storageId === s.storageId
947
+ );
948
+ if (!d) {
949
+ console.warn(
950
+ `[Rozenite] Storage Plugin: Storage target not found for ${s.adapterId}/${s.storageId}`
954
951
  );
955
- if (!d) {
956
- console.warn(
957
- `[Rozenite] Storage Plugin: Storage target not found for ${n.adapterId}/${n.storageId}`
958
- );
959
- return;
960
- }
961
- try {
962
- await d.set(c), a(d.target, c.key, "set");
963
- } catch (g) {
964
- console.warn(
965
- `[Rozenite] Storage Plugin: Failed to set entry in ${n.adapterId}/${n.storageId}.`,
966
- g
967
- );
968
- }
952
+ return;
969
953
  }
970
- ),
971
- r.onMessage(
972
- "delete-entry",
973
- async ({ target: n, key: c }) => {
974
- const d = t.find(
975
- (g) => g.target.adapterId === n.adapterId && g.target.storageId === n.storageId
954
+ try {
955
+ await d.set(c), await a(d.target, c.key, "set");
956
+ } catch (g) {
957
+ console.warn(
958
+ `[Rozenite] Storage Plugin: Failed to set entry in ${s.adapterId}/${s.storageId}.`,
959
+ g
976
960
  );
977
- if (!d) {
978
- console.warn(
979
- `[Rozenite] Storage Plugin: Storage target not found for ${n.adapterId}/${n.storageId}`
980
- );
981
- return;
982
- }
983
- try {
984
- await d.delete(c), a(d.target, c, "delete");
985
- } catch (g) {
986
- console.warn(
987
- `[Rozenite] Storage Plugin: Failed to delete entry in ${n.adapterId}/${n.storageId}.`,
988
- g
989
- );
990
- }
991
961
  }
992
- ),
993
- r.onMessage(
994
- "purge-storage",
995
- async ({ target: n }) => {
996
- const c = t.find(
997
- (d) => d.target.adapterId === n.adapterId && d.target.storageId === n.storageId
962
+ }),
963
+ r.onMessage("delete-entry", async ({ target: s, key: c }) => {
964
+ const d = t.find(
965
+ (g) => g.target.adapterId === s.adapterId && g.target.storageId === s.storageId
966
+ );
967
+ if (!d) {
968
+ console.warn(
969
+ `[Rozenite] Storage Plugin: Storage target not found for ${s.adapterId}/${s.storageId}`
998
970
  );
999
- if (!c) {
1000
- console.warn(
1001
- `[Rozenite] Storage Plugin: Storage target not found for ${n.adapterId}/${n.storageId}`
1002
- );
1003
- return;
1004
- }
1005
- try {
1006
- await c.purge(), a(c.target, void 0, "purge");
1007
- } catch (d) {
1008
- console.warn(
1009
- `[Rozenite] Storage Plugin: Failed to purge storage in ${n.adapterId}/${n.storageId}.`,
1010
- d
1011
- );
1012
- }
971
+ return;
1013
972
  }
1014
- ),
1015
- r.onMessage(
1016
- "discover-storages",
1017
- async (n) => {
1018
- const c = await ue(t, n);
1019
- r.send(c.type, c);
973
+ try {
974
+ await d.delete(c), await a(d.target, c, "delete");
975
+ } catch (g) {
976
+ console.warn(
977
+ `[Rozenite] Storage Plugin: Failed to delete entry in ${s.adapterId}/${s.storageId}.`,
978
+ g
979
+ );
1020
980
  }
1021
- ),
1022
- r.onMessage(
1023
- "list-entry-previews",
1024
- async (n) => {
1025
- const c = await ve(t, n);
1026
- r.send(c.type, c);
981
+ }),
982
+ r.onMessage("purge-storage", async ({ target: s }) => {
983
+ const c = t.find(
984
+ (d) => d.target.adapterId === s.adapterId && d.target.storageId === s.storageId
985
+ );
986
+ if (!c) {
987
+ console.warn(
988
+ `[Rozenite] Storage Plugin: Storage target not found for ${s.adapterId}/${s.storageId}`
989
+ );
990
+ return;
1027
991
  }
1028
- ),
1029
- r.onMessage(
1030
- "get-entry",
1031
- async (n) => {
1032
- const c = await ke(t, n);
1033
- r.send(c.type, c);
992
+ try {
993
+ await c.purge(), await a(c.target, void 0, "purge");
994
+ } catch (d) {
995
+ console.warn(
996
+ `[Rozenite] Storage Plugin: Failed to purge storage in ${s.adapterId}/${s.storageId}.`,
997
+ d
998
+ );
1034
999
  }
1035
- ),
1000
+ }),
1001
+ r.onMessage("discover-storages", async (s) => {
1002
+ const c = await ue(t, s);
1003
+ r.send(c.type, c);
1004
+ }),
1036
1005
  r.onMessage(
1037
- "export-snapshot",
1038
- async (n) => {
1039
- const c = await je(t, n);
1006
+ "list-entry-previews",
1007
+ async (s) => {
1008
+ const c = await ve(t, s);
1040
1009
  r.send(c.type, c);
1041
1010
  }
1042
1011
  ),
1043
- r.onMessage(
1044
- "preview-import",
1045
- async (n) => {
1046
- const c = await ae(t, n);
1012
+ r.onMessage("get-entry", async (s) => {
1013
+ const c = await ke(t, s);
1014
+ r.send(c.type, c);
1015
+ }),
1016
+ r.onMessage("export-snapshot", async (s) => {
1017
+ const c = await je(t, s);
1018
+ r.send(c.type, c);
1019
+ }),
1020
+ r.onMessage("preview-import", async (s) => {
1021
+ const c = await ae(t, s);
1022
+ r.send(c.type, c);
1023
+ }),
1024
+ r.onMessage("import-entries", async (s) => {
1025
+ await ie(t, s, (c) => {
1047
1026
  r.send(c.type, c);
1048
- }
1049
- ),
1050
- r.onMessage(
1051
- "import-entries",
1052
- async (n) => {
1053
- await ie(t, n, (c) => {
1054
- r.send(c.type, c);
1055
- });
1056
- }
1057
- )
1027
+ });
1028
+ })
1058
1029
  ];
1059
- return () => {
1060
- s = !0, o.forEach((n) => n.remove()), i.forEach((n) => n.remove());
1030
+ return r.send("device-ready", { type: "device-ready" }), () => {
1031
+ n = !0, o.forEach((s) => s.remove()), i.forEach((s) => s.remove());
1061
1032
  };
1062
1033
  }, [r, t]), r;
1063
1034
  };