@rozenite/storage-plugin 2.0.0 → 2.2.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.
- package/CHANGELOG.md +36 -0
- package/dist/devtools/assets/panel-D5z1BY8U.js +32 -0
- package/dist/devtools/assets/panel-DVlWRg6d.css +1 -0
- package/dist/devtools/panel.html +2 -2
- package/dist/react-native/chunks/index.require.js +1 -3
- package/dist/react-native/chunks/secure-storage.require.js +2 -6
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.cjs +1 -1
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.js +266 -295
- package/dist/react-native/index.d.ts +14 -2
- package/dist/react-native/index.js +2 -10
- package/dist/rozenite.json +1 -1
- package/package.json +29 -29
- package/react-native.ts +11 -36
- package/rozenite.config.ts +2 -6
- package/sdk.ts +1 -5
- package/src/react-native/__tests__/entry-preview-pagination.test.ts +12 -40
- package/src/react-native/__tests__/export-snapshot.test.ts +2 -6
- package/src/react-native/__tests__/full-entry-request.test.ts +5 -17
- package/src/react-native/__tests__/import.test.ts +9 -8
- package/src/react-native/__tests__/storage-discovery.test.ts +7 -18
- package/src/react-native/__tests__/stress-verification.test.ts +5 -18
- package/src/react-native/__tests__/use-storage-agent-tools.test.ts +25 -35
- package/src/react-native/adapters/__tests__/mmkv.test.ts +20 -30
- package/src/react-native/adapters/async-storage.ts +2 -5
- package/src/react-native/adapters/index.ts +2 -8
- package/src/react-native/adapters/mmkv.ts +7 -24
- package/src/react-native/adapters/secure-storage.ts +2 -6
- package/src/react-native/entry-preview-pagination.ts +11 -27
- package/src/react-native/export-snapshot.ts +3 -9
- package/src/react-native/full-entry-request.ts +3 -8
- package/src/react-native/import.ts +10 -21
- package/src/react-native/storage-discovery.ts +2 -6
- package/src/react-native/storage-view.ts +2 -6
- package/src/react-native/useRozeniteStoragePlugin.ts +107 -119
- package/src/react-native/useStorageAgentTools.ts +8 -24
- package/src/shared/__tests__/entry-preview.test.ts +9 -27
- package/src/shared/__tests__/snapshot.test.ts +10 -32
- package/src/shared/agent-tools.ts +9 -30
- package/src/shared/entry-preview.ts +3 -8
- package/src/shared/messaging.ts +15 -11
- package/src/shared/snapshot.ts +4 -17
- package/src/shared/types.ts +2 -4
- package/src/ui/__tests__/binary-value-editor-state.test.ts +6 -16
- package/src/ui/__tests__/binary.test.ts +13 -33
- package/src/ui/__tests__/large-value-viewer.test.tsx +4 -13
- package/src/ui/__tests__/panel.test.tsx +50 -63
- package/src/ui/__tests__/storage-groups.test.ts +1 -4
- package/src/ui/__tests__/type-conversion.test.ts +8 -24
- package/src/ui/__tests__/use-storage-entries.test.tsx +18 -34
- package/src/ui/add-entry-dialog.tsx +66 -87
- package/src/ui/binary-value-editor-state.ts +6 -24
- package/src/ui/binary-value-editor.tsx +6 -18
- package/src/ui/binary.ts +6 -19
- package/src/ui/edit-entry-dialog.tsx +59 -78
- package/src/ui/editor-switcher.tsx +2 -11
- package/src/ui/entry-detail-dialog.tsx +9 -16
- package/src/ui/format-value.tsx +2 -9
- package/src/ui/import-dialog.tsx +12 -24
- package/src/ui/large-value-viewer-state.ts +2 -9
- package/src/ui/large-value-viewer.tsx +3 -9
- package/src/ui/panel.tsx +129 -235
- package/src/ui/query-client.tsx +4 -15
- package/src/ui/type-conversion.ts +2 -5
- package/src/ui/typed-value-editor.tsx +1 -5
- package/src/ui/use-storage-entries.ts +6 -21
- package/src/ui/utils.ts +1 -4
- package/tsconfig.json +4 -7
- package/dist/devtools/assets/panel-B6Wp0eie.css +0 -1
- 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
|
|
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
|
|
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 ${
|
|
14
|
+
throw new p(t, `Expected object, got ${y(e)}`);
|
|
15
15
|
return e;
|
|
16
|
-
},
|
|
16
|
+
}, f = (e, t) => {
|
|
17
17
|
if (typeof e != "string")
|
|
18
|
-
throw new p(t, `Expected string, got ${
|
|
18
|
+
throw new p(t, `Expected string, got ${y(e)}`);
|
|
19
19
|
return e;
|
|
20
|
-
},
|
|
20
|
+
}, C = (e, t) => {
|
|
21
21
|
if (!Array.isArray(e))
|
|
22
|
-
throw new p(t, `Expected array, got ${
|
|
22
|
+
throw new p(t, `Expected array, got ${y(e)}`);
|
|
23
23
|
return e;
|
|
24
|
-
},
|
|
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 ${
|
|
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:
|
|
34
|
-
(a, 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:
|
|
40
|
-
storageId:
|
|
41
|
-
adapterName:
|
|
42
|
-
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 =
|
|
47
|
-
switch (
|
|
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 ${
|
|
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 ${
|
|
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 ${
|
|
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 ${
|
|
80
|
+
`Expected number[] for type "buffer", got ${y(i)}`
|
|
81
81
|
);
|
|
82
|
-
const
|
|
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 ${
|
|
86
|
+
`Expected uint8 (integer 0-255), got ${y(c)}`
|
|
87
87
|
);
|
|
88
88
|
return c;
|
|
89
89
|
});
|
|
90
|
-
return { key: o, type: "buffer", value:
|
|
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: ${
|
|
99
|
+
`Unsupported snapshot version: ${y(r)} (this build supports version ${T})`
|
|
100
100
|
);
|
|
101
|
-
const o =
|
|
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:
|
|
107
|
+
createdAt: n,
|
|
110
108
|
storage: a,
|
|
111
|
-
entries:
|
|
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 = [],
|
|
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
|
-
|
|
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
|
|
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:
|
|
146
|
+
skippedKeys: n,
|
|
149
147
|
unsupportedTypes: a,
|
|
150
148
|
acceptedEntryIndexes: i,
|
|
151
|
-
metadataMismatch:
|
|
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,
|
|
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
|
-
},
|
|
161
|
-
const r =
|
|
162
|
-
if (typeof o != "object" || o == null || o.type !== "preview-import" || typeof o.requestId != "string" || o.requestId.trim().length === 0 || !R(o.target) || !
|
|
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(
|
|
181
|
+
preview: se(n.snapshot, {
|
|
184
182
|
target: a.target,
|
|
185
183
|
capabilities: a.capabilities,
|
|
186
184
|
entryKeys: i,
|
|
187
|
-
isBlacklisted: (
|
|
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 =
|
|
200
|
-
if (typeof
|
|
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(
|
|
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,
|
|
210
|
+
const a = U(e, n.target);
|
|
213
211
|
if (!a) {
|
|
214
212
|
r({
|
|
215
213
|
type: "import-result",
|
|
216
|
-
requestId:
|
|
217
|
-
target:
|
|
214
|
+
requestId: n.requestId,
|
|
215
|
+
target: n.target,
|
|
218
216
|
ok: !1,
|
|
219
217
|
written: 0,
|
|
220
|
-
total:
|
|
218
|
+
total: n.entries.length,
|
|
221
219
|
error: "Target storage not found"
|
|
222
220
|
});
|
|
223
221
|
return;
|
|
224
222
|
}
|
|
225
|
-
const i =
|
|
226
|
-
(
|
|
223
|
+
const i = n.entries.filter(
|
|
224
|
+
(s) => $(a.capabilities, s.type) && !O(a, s.key)
|
|
227
225
|
);
|
|
228
|
-
for (let
|
|
229
|
-
const c = i[
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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:
|
|
240
|
-
target:
|
|
242
|
+
requestId: n.requestId,
|
|
243
|
+
target: n.target,
|
|
241
244
|
ok: !1,
|
|
242
|
-
written:
|
|
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:
|
|
252
|
-
target:
|
|
253
|
-
written:
|
|
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
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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:
|
|
264
|
-
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))),
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
|
393
|
-
|
|
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 =
|
|
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
|
|
413
|
+
const i = (await n.getAllKeys()).filter((l) => l.toLowerCase().includes(o.search)).sort(qe);
|
|
413
414
|
o.keySortDirection === "descending" && i.reverse();
|
|
414
|
-
let
|
|
415
|
+
let s = 0;
|
|
415
416
|
if (a) {
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
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
|
-
|
|
426
|
+
s = a.direction === "next" ? l + 1 : Math.max(0, l - o.limit);
|
|
426
427
|
}
|
|
427
|
-
const c = i.slice(
|
|
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
|
-
...
|
|
441
|
+
...u,
|
|
441
442
|
boundaryKey: c.at(-1),
|
|
442
443
|
direction: "next"
|
|
443
444
|
})
|
|
444
445
|
} : {},
|
|
445
|
-
...
|
|
446
|
+
...s > 0 && c.length > 0 ? {
|
|
446
447
|
previousCursor: D({
|
|
447
|
-
...
|
|
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
|
|
482
|
-
return
|
|
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:
|
|
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
|
|
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:
|
|
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",
|
|
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)),
|
|
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
|
-
},
|
|
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
|
-
},
|
|
556
|
+
}, Me = async (e) => {
|
|
560
557
|
await e.clear();
|
|
561
|
-
},
|
|
562
|
-
const r = t.storage, o = r.subscribe,
|
|
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
|
-
},
|
|
568
|
-
if (!
|
|
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((
|
|
574
|
-
)).filter((
|
|
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:
|
|
581
|
+
get: s,
|
|
585
582
|
set: async (d) => {
|
|
586
|
-
Fe(t.capabilities, d.type, i),
|
|
583
|
+
Fe(t.capabilities, d.type, i), n.add(d.key);
|
|
587
584
|
try {
|
|
588
|
-
await
|
|
585
|
+
await Ce(r, d);
|
|
589
586
|
} finally {
|
|
590
|
-
|
|
587
|
+
n.delete(d.key);
|
|
591
588
|
}
|
|
592
589
|
},
|
|
593
590
|
delete: async (d) => {
|
|
594
|
-
|
|
591
|
+
n.add(d);
|
|
595
592
|
try {
|
|
596
|
-
await
|
|
593
|
+
await Ke(r, d);
|
|
597
594
|
} finally {
|
|
598
|
-
|
|
595
|
+
n.delete(d);
|
|
599
596
|
}
|
|
600
597
|
},
|
|
601
598
|
purge: async () => {
|
|
602
599
|
a = !0;
|
|
603
600
|
try {
|
|
604
|
-
await
|
|
601
|
+
await Me(r);
|
|
605
602
|
} finally {
|
|
606
603
|
a = !1;
|
|
607
604
|
}
|
|
608
605
|
},
|
|
609
|
-
getAllKeys: async () => (await _(r)).filter((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 && !
|
|
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
|
-
},
|
|
625
|
+
}, m = "@rozenite/storage-plugin", j = [
|
|
631
626
|
"string",
|
|
632
627
|
"number",
|
|
633
628
|
"boolean",
|
|
634
629
|
"buffer"
|
|
635
|
-
],
|
|
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
|
-
},
|
|
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,
|
|
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
|
-
),
|
|
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 ${
|
|
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 ${
|
|
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(
|
|
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
|
|
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:
|
|
801
|
-
items:
|
|
795
|
+
total: n.length,
|
|
796
|
+
items: n.slice(a, i).map((s) => ({ key: s })),
|
|
802
797
|
page: {
|
|
803
798
|
limit: r,
|
|
804
|
-
hasMore: i <
|
|
805
|
-
...i <
|
|
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 =
|
|
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
|
|
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:
|
|
840
|
-
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
|
-
|
|
847
|
-
pluginId:
|
|
848
|
-
tool:
|
|
839
|
+
I({
|
|
840
|
+
pluginId: m,
|
|
841
|
+
tool: h.listStorages,
|
|
849
842
|
handler: t.listStorages
|
|
850
|
-
}),
|
|
851
|
-
pluginId:
|
|
852
|
-
tool:
|
|
843
|
+
}), I({
|
|
844
|
+
pluginId: m,
|
|
845
|
+
tool: h.listEntries,
|
|
853
846
|
handler: t.listEntries
|
|
854
|
-
}),
|
|
855
|
-
pluginId:
|
|
856
|
-
tool:
|
|
847
|
+
}), I({
|
|
848
|
+
pluginId: m,
|
|
849
|
+
tool: h.readEntry,
|
|
857
850
|
handler: t.readEntry
|
|
858
|
-
}),
|
|
859
|
-
pluginId:
|
|
860
|
-
tool:
|
|
861
|
-
handler: async ({ adapterId: r, storageId: o, key:
|
|
862
|
-
const
|
|
863
|
-
if (await
|
|
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 "${
|
|
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
|
|
869
|
-
adapterId:
|
|
870
|
-
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:
|
|
865
|
+
key: n
|
|
873
866
|
};
|
|
874
867
|
}
|
|
875
|
-
}),
|
|
876
|
-
pluginId:
|
|
877
|
-
tool:
|
|
878
|
-
handler: async ({ adapterId: r, storageId: o, key:
|
|
879
|
-
const
|
|
880
|
-
if (!await
|
|
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 "${
|
|
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
|
|
886
|
-
adapterId:
|
|
887
|
-
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:
|
|
882
|
+
key: n
|
|
890
883
|
};
|
|
891
884
|
}
|
|
892
|
-
}),
|
|
893
|
-
pluginId:
|
|
894
|
-
tool:
|
|
895
|
-
handler: async ({ adapterId: r, storageId: o, key:
|
|
896
|
-
const a =
|
|
897
|
-
return await a.delete(
|
|
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:
|
|
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
|
|
918
|
-
const a = (
|
|
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:
|
|
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((
|
|
922
|
+
t.filter((s) => s.supportsSubscriptions && s.watch).map(async (s) => {
|
|
928
923
|
try {
|
|
929
|
-
const c =
|
|
924
|
+
const c = s.watch;
|
|
930
925
|
if (!c)
|
|
931
926
|
return;
|
|
932
927
|
const d = await c((g) => {
|
|
933
|
-
a(
|
|
928
|
+
a(s.target, g);
|
|
934
929
|
});
|
|
935
|
-
if (
|
|
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 ${
|
|
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
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
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
|
-
|
|
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
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
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
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
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
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
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
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
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
|
-
"
|
|
1038
|
-
async (
|
|
1039
|
-
const c = await
|
|
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
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
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
|
-
|
|
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
|
};
|