@rozenite/storage-plugin 1.8.0 → 1.9.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 +28 -0
- package/README.md +23 -0
- package/dist/devtools/assets/panel-DVxtKLI9.css +1 -0
- package/dist/devtools/assets/panel-DnjbFMGo.js +22 -0
- package/dist/devtools/panel.html +2 -2
- package/dist/react-native/chunks/index.require.cjs +1 -1
- package/dist/react-native/chunks/index.require.js +9 -5
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.cjs +1 -1
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.js +253 -191
- package/dist/react-native/index.d.ts +29 -6
- package/dist/rozenite.json +1 -1
- package/dist/sdk/index.d.ts +1 -0
- package/package.json +6 -6
- package/src/react-native/__tests__/import.test.ts +182 -0
- package/src/react-native/adapters/__tests__/mmkv.test.ts +141 -0
- package/src/react-native/adapters/mmkv.ts +15 -0
- package/src/react-native/import.ts +67 -0
- package/src/react-native/storage-view.ts +16 -8
- package/src/react-native/useRozeniteStoragePlugin.ts +61 -36
- package/src/shared/__tests__/snapshot.test.ts +361 -0
- package/src/shared/messaging.ts +25 -1
- package/src/shared/snapshot.ts +276 -0
- package/src/shared/types.ts +1 -0
- package/src/ui/import-dialog.tsx +261 -0
- package/src/ui/panel.tsx +257 -57
- package/src/ui/utils.ts +30 -0
- package/dist/devtools/assets/panel-DMhXYHH4.css +0 -1
- package/dist/devtools/assets/panel-eGOuOVos.js +0 -22
|
@@ -1,95 +1,142 @@
|
|
|
1
|
-
import { useRozeniteDevToolsClient as
|
|
2
|
-
import { useCallback as
|
|
3
|
-
import { g as
|
|
4
|
-
import { useRozenitePluginAgentTool as
|
|
1
|
+
import { useRozeniteDevToolsClient as v } from "@rozenite/plugin-bridge";
|
|
2
|
+
import { useCallback as A, useMemo as T, useEffect as P } from "react";
|
|
3
|
+
import { g as R, s as M } from "./types.js";
|
|
4
|
+
import { useRozenitePluginAgentTool as p } from "@rozenite/agent-bridge";
|
|
5
5
|
import { defineAgentToolContract as g } from "@rozenite/agent-shared";
|
|
6
|
-
const x =
|
|
7
|
-
|
|
6
|
+
const x = async (t, e, r) => {
|
|
7
|
+
const o = t.find(
|
|
8
|
+
(n) => n.target.adapterId === e.target.adapterId && n.target.storageId === e.target.storageId
|
|
9
|
+
);
|
|
10
|
+
if (!o) {
|
|
11
|
+
r({
|
|
12
|
+
type: "import-result",
|
|
13
|
+
target: e.target,
|
|
14
|
+
ok: !1,
|
|
15
|
+
written: 0,
|
|
16
|
+
total: e.entries.length,
|
|
17
|
+
error: "Target storage not found"
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (let n = 0; n < e.entries.length; n++) {
|
|
22
|
+
const s = e.entries[n];
|
|
23
|
+
try {
|
|
24
|
+
await o.set(s);
|
|
25
|
+
} catch (i) {
|
|
26
|
+
r({
|
|
27
|
+
type: "import-result",
|
|
28
|
+
target: e.target,
|
|
29
|
+
ok: !1,
|
|
30
|
+
written: n,
|
|
31
|
+
total: e.entries.length,
|
|
32
|
+
failedKey: s.key,
|
|
33
|
+
error: i instanceof Error ? i.message : String(i)
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
r({
|
|
38
|
+
type: "set-entry",
|
|
39
|
+
target: e.target,
|
|
40
|
+
entry: s
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
r({
|
|
44
|
+
type: "import-result",
|
|
45
|
+
target: e.target,
|
|
46
|
+
ok: !0,
|
|
47
|
+
written: e.entries.length,
|
|
48
|
+
total: e.entries.length
|
|
49
|
+
});
|
|
50
|
+
}, N = 1500, m = (t) => t.kind === "async", w = (t) => t.type === "buffer" ? `${t.type}:${t.value.join(",")}` : `${t.type}:${String(t.value)}`, K = (t) => new Map(t.map((e) => [e.key, e])), I = (t, e) => t.shouldFilterKey?.(e) ? !0 : t.blacklist ? (t.blacklist.lastIndex = 0, t.blacklist.test(e)) : !1, z = (t, e, r) => {
|
|
51
|
+
if (!M(t, e))
|
|
8
52
|
throw new Error(
|
|
9
|
-
`Type "${
|
|
53
|
+
`Type "${e}" is not supported by storage "${r.storageId}" in adapter "${r.adapterId}".`
|
|
10
54
|
);
|
|
11
|
-
}, b = async (
|
|
12
|
-
if (
|
|
13
|
-
await
|
|
55
|
+
}, b = async (t) => (m(t), t.getAllKeys()), E = async (t, e) => (m(t), t.get(e)), j = async (t, e) => {
|
|
56
|
+
if (m(t)) {
|
|
57
|
+
await t.set(e);
|
|
14
58
|
return;
|
|
15
59
|
}
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
if (
|
|
19
|
-
await
|
|
60
|
+
t.set(e);
|
|
61
|
+
}, F = async (t, e) => {
|
|
62
|
+
if (m(t)) {
|
|
63
|
+
await t.delete(e);
|
|
20
64
|
return;
|
|
21
65
|
}
|
|
22
|
-
|
|
23
|
-
}, S = async (
|
|
24
|
-
const
|
|
25
|
-
return
|
|
26
|
-
}, V = (
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
if (!
|
|
30
|
-
r.onSet(
|
|
66
|
+
t.delete(e);
|
|
67
|
+
}, S = async (t) => {
|
|
68
|
+
const e = await t();
|
|
69
|
+
return K(e);
|
|
70
|
+
}, V = (t, e, r) => {
|
|
71
|
+
e.forEach((o, n) => {
|
|
72
|
+
const s = t.get(n);
|
|
73
|
+
if (!s) {
|
|
74
|
+
r.onSet(o);
|
|
31
75
|
return;
|
|
32
76
|
}
|
|
33
|
-
w(
|
|
34
|
-
}),
|
|
35
|
-
|
|
77
|
+
w(s) !== w(o) && r.onSet(o);
|
|
78
|
+
}), t.forEach((o, n) => {
|
|
79
|
+
e.has(n) || r.onDelete(n);
|
|
36
80
|
});
|
|
37
|
-
}, _ = async (
|
|
38
|
-
let r = await S(
|
|
39
|
-
const
|
|
81
|
+
}, _ = async (t, e) => {
|
|
82
|
+
let r = await S(t);
|
|
83
|
+
const o = setInterval(async () => {
|
|
40
84
|
try {
|
|
41
|
-
const n = await S(
|
|
42
|
-
V(r, n,
|
|
85
|
+
const n = await S(t);
|
|
86
|
+
V(r, n, e), r = n;
|
|
43
87
|
} catch {
|
|
44
88
|
}
|
|
45
|
-
},
|
|
89
|
+
}, N);
|
|
46
90
|
return {
|
|
47
91
|
remove: () => {
|
|
48
|
-
clearInterval(
|
|
92
|
+
clearInterval(o);
|
|
49
93
|
}
|
|
50
94
|
};
|
|
51
|
-
}, D = (
|
|
52
|
-
const r =
|
|
53
|
-
adapterId:
|
|
54
|
-
storageId:
|
|
55
|
-
}, n = async (
|
|
56
|
-
if (!I(
|
|
57
|
-
return E(r,
|
|
58
|
-
},
|
|
59
|
-
const
|
|
95
|
+
}, D = (t, e) => {
|
|
96
|
+
const r = e.storage, o = {
|
|
97
|
+
adapterId: t.id,
|
|
98
|
+
storageId: e.id
|
|
99
|
+
}, n = async (i) => {
|
|
100
|
+
if (!I(e, i))
|
|
101
|
+
return E(r, i);
|
|
102
|
+
}, s = async () => {
|
|
103
|
+
const i = await b(r);
|
|
60
104
|
return (await Promise.all(
|
|
61
|
-
|
|
62
|
-
)).filter((
|
|
105
|
+
i.filter((l) => !I(e, l)).map((l) => E(r, l))
|
|
106
|
+
)).filter((l) => !!l);
|
|
63
107
|
};
|
|
64
108
|
return {
|
|
65
|
-
id:
|
|
66
|
-
target:
|
|
67
|
-
adapterName:
|
|
68
|
-
storageName:
|
|
69
|
-
capabilities:
|
|
109
|
+
id: R(o),
|
|
110
|
+
target: o,
|
|
111
|
+
adapterName: t.name,
|
|
112
|
+
storageName: e.name,
|
|
113
|
+
capabilities: e.capabilities,
|
|
114
|
+
blacklist: e.blacklist,
|
|
70
115
|
get: n,
|
|
71
|
-
set: async (
|
|
72
|
-
z(
|
|
116
|
+
set: async (i) => {
|
|
117
|
+
z(e.capabilities, i.type, o), await j(r, i);
|
|
73
118
|
},
|
|
74
|
-
delete: async (
|
|
75
|
-
await
|
|
119
|
+
delete: async (i) => {
|
|
120
|
+
await F(r, i);
|
|
76
121
|
},
|
|
77
|
-
getAllKeys: async () => (await b(r)).filter((a) => !I(
|
|
78
|
-
getAllEntries:
|
|
79
|
-
watch: async ({ onSet:
|
|
122
|
+
getAllKeys: async () => (await b(r)).filter((a) => !I(e, a)),
|
|
123
|
+
getAllEntries: s,
|
|
124
|
+
watch: async ({ onSet: i, onDelete: a }) => r.subscribe ? r.subscribe(async (l) => {
|
|
80
125
|
try {
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
83
|
-
a(
|
|
126
|
+
const d = await n(l);
|
|
127
|
+
if (!d) {
|
|
128
|
+
a(l);
|
|
84
129
|
return;
|
|
85
130
|
}
|
|
86
|
-
d
|
|
131
|
+
i(d);
|
|
87
132
|
} catch {
|
|
88
133
|
}
|
|
89
|
-
}) : _(
|
|
134
|
+
}) : _(s, { onSet: i, onDelete: a })
|
|
90
135
|
};
|
|
91
|
-
},
|
|
92
|
-
(
|
|
136
|
+
}, q = (t) => t.flatMap(
|
|
137
|
+
(e) => e.storages.map(
|
|
138
|
+
(r) => D(e, r)
|
|
139
|
+
)
|
|
93
140
|
), f = {
|
|
94
141
|
adapterId: {
|
|
95
142
|
type: "string",
|
|
@@ -192,59 +239,59 @@ const x = 1500, h = (e) => e.kind === "async", w = (e) => e.type === "buffer" ?
|
|
|
192
239
|
required: ["key"]
|
|
193
240
|
}
|
|
194
241
|
})
|
|
195
|
-
},
|
|
196
|
-
if (
|
|
197
|
-
if (typeof
|
|
242
|
+
}, k = (t, e) => {
|
|
243
|
+
if (t === "string") {
|
|
244
|
+
if (typeof e != "string")
|
|
198
245
|
throw new Error("Expected string value for type=string");
|
|
199
|
-
return
|
|
246
|
+
return e;
|
|
200
247
|
}
|
|
201
|
-
if (
|
|
202
|
-
if (typeof
|
|
248
|
+
if (t === "number") {
|
|
249
|
+
if (typeof e != "number" || Number.isNaN(e))
|
|
203
250
|
throw new Error("Expected number value for type=number");
|
|
204
|
-
return
|
|
251
|
+
return e;
|
|
205
252
|
}
|
|
206
|
-
if (
|
|
207
|
-
if (typeof
|
|
253
|
+
if (t === "boolean") {
|
|
254
|
+
if (typeof e != "boolean")
|
|
208
255
|
throw new Error("Expected boolean value for type=boolean");
|
|
209
|
-
return
|
|
256
|
+
return e;
|
|
210
257
|
}
|
|
211
|
-
if (!Array.isArray(
|
|
258
|
+
if (!Array.isArray(e) || !e.every((r) => Number.isInteger(r)))
|
|
212
259
|
throw new Error("Expected number[] value for type=buffer");
|
|
213
|
-
return
|
|
214
|
-
},
|
|
215
|
-
const
|
|
216
|
-
(r,
|
|
217
|
-
if (
|
|
260
|
+
return e;
|
|
261
|
+
}, h = (t) => `${t.target.adapterId}/${t.target.storageId}`, L = (t) => {
|
|
262
|
+
const e = A(
|
|
263
|
+
(r, o) => {
|
|
264
|
+
if (t.length === 0)
|
|
218
265
|
throw new Error("No storages are registered.");
|
|
219
|
-
if (r !== void 0 ||
|
|
220
|
-
const n =
|
|
221
|
-
(
|
|
266
|
+
if (r !== void 0 || o !== void 0) {
|
|
267
|
+
const n = t.find(
|
|
268
|
+
(s) => (r === void 0 || s.target.adapterId === r) && (o === void 0 || s.target.storageId === o)
|
|
222
269
|
);
|
|
223
270
|
if (!n) {
|
|
224
|
-
const
|
|
271
|
+
const s = [
|
|
225
272
|
r && `adapterId="${r}"`,
|
|
226
|
-
|
|
273
|
+
o && `storageId="${o}"`
|
|
227
274
|
].filter(Boolean).join(", ");
|
|
228
275
|
throw new Error(
|
|
229
|
-
`No storage matched ${
|
|
276
|
+
`No storage matched ${s}. Available: ${t.map(h).join(", ")}`
|
|
230
277
|
);
|
|
231
278
|
}
|
|
232
279
|
return n;
|
|
233
280
|
}
|
|
234
|
-
if (
|
|
281
|
+
if (t.length > 1)
|
|
235
282
|
throw new Error(
|
|
236
|
-
`Multiple storages detected. Provide adapterId and/or storageId. Available: ${
|
|
283
|
+
`Multiple storages detected. Provide adapterId and/or storageId. Available: ${t.map(h).join(", ")}`
|
|
237
284
|
);
|
|
238
|
-
return
|
|
285
|
+
return t[0];
|
|
239
286
|
},
|
|
240
|
-
[
|
|
287
|
+
[t]
|
|
241
288
|
);
|
|
242
|
-
|
|
289
|
+
p({
|
|
243
290
|
pluginId: u,
|
|
244
291
|
tool: y.listStorages,
|
|
245
292
|
handler: async () => ({
|
|
246
293
|
storages: await Promise.all(
|
|
247
|
-
|
|
294
|
+
t.map(async (r) => ({
|
|
248
295
|
adapterId: r.target.adapterId,
|
|
249
296
|
storageId: r.target.storageId,
|
|
250
297
|
adapterName: r.adapterName,
|
|
@@ -254,203 +301,218 @@ const x = 1500, h = (e) => e.kind === "async", w = (e) => e.type === "buffer" ?
|
|
|
254
301
|
}))
|
|
255
302
|
)
|
|
256
303
|
})
|
|
257
|
-
}),
|
|
304
|
+
}), p({
|
|
258
305
|
pluginId: u,
|
|
259
306
|
tool: y.listEntries,
|
|
260
|
-
handler: async ({ adapterId: r, storageId:
|
|
261
|
-
const
|
|
307
|
+
handler: async ({ adapterId: r, storageId: o, offset: n = 0, limit: s = 100 }) => {
|
|
308
|
+
const i = e(r, o), a = await i.getAllKeys(), l = Math.max(0, Math.floor(n)), d = Math.max(1, Math.floor(s)), c = a.slice(l, l + d);
|
|
262
309
|
return {
|
|
263
|
-
adapterId:
|
|
264
|
-
storageId:
|
|
310
|
+
adapterId: i.target.adapterId,
|
|
311
|
+
storageId: i.target.storageId,
|
|
265
312
|
total: a.length,
|
|
266
|
-
offset:
|
|
267
|
-
limit:
|
|
268
|
-
keys:
|
|
313
|
+
offset: l,
|
|
314
|
+
limit: d,
|
|
315
|
+
keys: c
|
|
269
316
|
};
|
|
270
317
|
}
|
|
271
|
-
}),
|
|
318
|
+
}), p({
|
|
272
319
|
pluginId: u,
|
|
273
320
|
tool: y.readEntry,
|
|
274
|
-
handler: async ({ adapterId: r, storageId:
|
|
275
|
-
const
|
|
276
|
-
if (!
|
|
321
|
+
handler: async ({ adapterId: r, storageId: o, key: n }) => {
|
|
322
|
+
const s = e(r, o), i = await s.get(n);
|
|
323
|
+
if (!i)
|
|
277
324
|
throw new Error(
|
|
278
|
-
`Key "${n}" not found in storage "${
|
|
325
|
+
`Key "${n}" not found in storage "${h(s)}".`
|
|
279
326
|
);
|
|
280
327
|
return {
|
|
281
|
-
adapterId:
|
|
282
|
-
storageId:
|
|
283
|
-
entry:
|
|
328
|
+
adapterId: s.target.adapterId,
|
|
329
|
+
storageId: s.target.storageId,
|
|
330
|
+
entry: i
|
|
284
331
|
};
|
|
285
332
|
}
|
|
286
|
-
}),
|
|
333
|
+
}), p({
|
|
287
334
|
pluginId: u,
|
|
288
335
|
tool: y.createEntry,
|
|
289
|
-
handler: async ({ adapterId: r, storageId:
|
|
290
|
-
const a =
|
|
336
|
+
handler: async ({ adapterId: r, storageId: o, key: n, type: s, value: i }) => {
|
|
337
|
+
const a = e(r, o);
|
|
291
338
|
if (await a.get(n))
|
|
292
339
|
throw new Error(
|
|
293
|
-
`Key "${n}" already exists in storage "${
|
|
340
|
+
`Key "${n}" already exists in storage "${h(a)}". Use edit-entry instead.`
|
|
294
341
|
);
|
|
295
|
-
const
|
|
296
|
-
return await a.set({ key: n, type:
|
|
342
|
+
const d = k(s, i);
|
|
343
|
+
return await a.set({ key: n, type: s, value: d }), {
|
|
297
344
|
adapterId: a.target.adapterId,
|
|
298
345
|
storageId: a.target.storageId,
|
|
299
346
|
created: !0,
|
|
300
347
|
key: n
|
|
301
348
|
};
|
|
302
349
|
}
|
|
303
|
-
}),
|
|
350
|
+
}), p({
|
|
304
351
|
pluginId: u,
|
|
305
352
|
tool: y.editEntry,
|
|
306
|
-
handler: async ({ adapterId: r, storageId:
|
|
307
|
-
const a =
|
|
353
|
+
handler: async ({ adapterId: r, storageId: o, key: n, type: s, value: i }) => {
|
|
354
|
+
const a = e(r, o);
|
|
308
355
|
if (!await a.get(n))
|
|
309
356
|
throw new Error(
|
|
310
|
-
`Key "${n}" not found in storage "${
|
|
357
|
+
`Key "${n}" not found in storage "${h(a)}". Use create-entry instead.`
|
|
311
358
|
);
|
|
312
|
-
const
|
|
313
|
-
return await a.set({ key: n, type:
|
|
359
|
+
const d = k(s, i);
|
|
360
|
+
return await a.set({ key: n, type: s, value: d }), {
|
|
314
361
|
adapterId: a.target.adapterId,
|
|
315
362
|
storageId: a.target.storageId,
|
|
316
363
|
edited: !0,
|
|
317
364
|
key: n
|
|
318
365
|
};
|
|
319
366
|
}
|
|
320
|
-
}),
|
|
367
|
+
}), p({
|
|
321
368
|
pluginId: u,
|
|
322
369
|
tool: y.removeEntry,
|
|
323
|
-
handler: async ({ adapterId: r, storageId:
|
|
324
|
-
const
|
|
325
|
-
return await
|
|
326
|
-
adapterId:
|
|
327
|
-
storageId:
|
|
328
|
-
removed:
|
|
370
|
+
handler: async ({ adapterId: r, storageId: o, key: n }) => {
|
|
371
|
+
const s = e(r, o), i = !!await s.get(n);
|
|
372
|
+
return await s.delete(n), {
|
|
373
|
+
adapterId: s.target.adapterId,
|
|
374
|
+
storageId: s.target.storageId,
|
|
375
|
+
removed: i,
|
|
329
376
|
key: n
|
|
330
377
|
};
|
|
331
378
|
}
|
|
332
379
|
});
|
|
333
|
-
},
|
|
334
|
-
storages:
|
|
380
|
+
}, B = ({
|
|
381
|
+
storages: t
|
|
335
382
|
}) => {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
const r =
|
|
383
|
+
const e = T(() => q(t), [t]);
|
|
384
|
+
L(e);
|
|
385
|
+
const r = v({
|
|
339
386
|
pluginId: "@rozenite/storage-plugin"
|
|
340
387
|
});
|
|
341
|
-
return
|
|
388
|
+
return P(() => {
|
|
342
389
|
if (!r)
|
|
343
390
|
return;
|
|
344
|
-
const
|
|
345
|
-
const
|
|
346
|
-
for (const
|
|
391
|
+
const o = async (a) => {
|
|
392
|
+
const l = a ? e.filter((d) => d.id === a) : e;
|
|
393
|
+
for (const d of l)
|
|
347
394
|
try {
|
|
348
|
-
const
|
|
395
|
+
const c = await d.getAllEntries();
|
|
349
396
|
r.send("snapshot", {
|
|
350
397
|
type: "snapshot",
|
|
351
|
-
target:
|
|
352
|
-
adapterName:
|
|
353
|
-
storageName:
|
|
354
|
-
capabilities:
|
|
355
|
-
|
|
398
|
+
target: d.target,
|
|
399
|
+
adapterName: d.adapterName,
|
|
400
|
+
storageName: d.storageName,
|
|
401
|
+
capabilities: d.capabilities,
|
|
402
|
+
blacklist: d.blacklist ? { source: d.blacklist.source, flags: d.blacklist.flags } : void 0,
|
|
403
|
+
entries: c
|
|
356
404
|
});
|
|
357
|
-
} catch (
|
|
405
|
+
} catch (c) {
|
|
358
406
|
console.warn(
|
|
359
|
-
`[Rozenite] Storage Plugin: Failed to snapshot ${
|
|
360
|
-
|
|
407
|
+
`[Rozenite] Storage Plugin: Failed to snapshot ${d.target.adapterId}/${d.target.storageId}.`,
|
|
408
|
+
c
|
|
361
409
|
);
|
|
362
410
|
}
|
|
363
411
|
};
|
|
364
|
-
|
|
412
|
+
o();
|
|
365
413
|
const n = [];
|
|
366
|
-
let
|
|
414
|
+
let s = !1;
|
|
367
415
|
Promise.all(
|
|
368
|
-
|
|
416
|
+
e.map(async (a) => {
|
|
369
417
|
try {
|
|
370
|
-
const
|
|
371
|
-
onSet: (
|
|
418
|
+
const l = await a.watch({
|
|
419
|
+
onSet: (d) => {
|
|
372
420
|
r.send("set-entry", {
|
|
373
421
|
type: "set-entry",
|
|
374
422
|
target: a.target,
|
|
375
|
-
entry:
|
|
423
|
+
entry: d
|
|
376
424
|
});
|
|
377
425
|
},
|
|
378
|
-
onDelete: (
|
|
426
|
+
onDelete: (d) => {
|
|
379
427
|
r.send("delete-entry", {
|
|
380
428
|
type: "delete-entry",
|
|
381
429
|
target: a.target,
|
|
382
|
-
key:
|
|
430
|
+
key: d
|
|
383
431
|
});
|
|
384
432
|
}
|
|
385
433
|
});
|
|
386
|
-
if (
|
|
387
|
-
|
|
434
|
+
if (s) {
|
|
435
|
+
l.remove();
|
|
388
436
|
return;
|
|
389
437
|
}
|
|
390
|
-
n.push(
|
|
391
|
-
} catch (
|
|
438
|
+
n.push(l);
|
|
439
|
+
} catch (l) {
|
|
392
440
|
console.warn(
|
|
393
441
|
`[Rozenite] Storage Plugin: Failed to attach watcher for ${a.target.adapterId}/${a.target.storageId}.`,
|
|
394
|
-
|
|
442
|
+
l
|
|
395
443
|
);
|
|
396
444
|
}
|
|
397
445
|
})
|
|
398
446
|
);
|
|
399
|
-
const
|
|
400
|
-
r.onMessage(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
console.warn(
|
|
406
|
-
`[Rozenite] Storage Plugin: Storage target not found for ${a.adapterId}/${a.storageId}`
|
|
407
|
-
);
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
try {
|
|
411
|
-
await i.set(c);
|
|
412
|
-
} catch (p) {
|
|
413
|
-
console.warn(
|
|
414
|
-
`[Rozenite] Storage Plugin: Failed to set entry in ${a.adapterId}/${a.storageId}.`,
|
|
415
|
-
p
|
|
447
|
+
const i = [
|
|
448
|
+
r.onMessage(
|
|
449
|
+
"set-entry",
|
|
450
|
+
async ({ target: a, entry: l }) => {
|
|
451
|
+
const d = e.find(
|
|
452
|
+
(c) => c.target.adapterId === a.adapterId && c.target.storageId === a.storageId
|
|
416
453
|
);
|
|
454
|
+
if (!d) {
|
|
455
|
+
console.warn(
|
|
456
|
+
`[Rozenite] Storage Plugin: Storage target not found for ${a.adapterId}/${a.storageId}`
|
|
457
|
+
);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
await d.set(l);
|
|
462
|
+
} catch (c) {
|
|
463
|
+
console.warn(
|
|
464
|
+
`[Rozenite] Storage Plugin: Failed to set entry in ${a.adapterId}/${a.storageId}.`,
|
|
465
|
+
c
|
|
466
|
+
);
|
|
467
|
+
}
|
|
417
468
|
}
|
|
418
|
-
|
|
469
|
+
),
|
|
419
470
|
r.onMessage(
|
|
420
471
|
"delete-entry",
|
|
421
|
-
async ({ target: a, key:
|
|
422
|
-
const
|
|
423
|
-
(
|
|
472
|
+
async ({ target: a, key: l }) => {
|
|
473
|
+
const d = e.find(
|
|
474
|
+
(c) => c.target.adapterId === a.adapterId && c.target.storageId === a.storageId
|
|
424
475
|
);
|
|
425
|
-
if (!
|
|
476
|
+
if (!d) {
|
|
426
477
|
console.warn(
|
|
427
478
|
`[Rozenite] Storage Plugin: Storage target not found for ${a.adapterId}/${a.storageId}`
|
|
428
479
|
);
|
|
429
480
|
return;
|
|
430
481
|
}
|
|
431
482
|
try {
|
|
432
|
-
await
|
|
433
|
-
} catch (
|
|
483
|
+
await d.delete(l);
|
|
484
|
+
} catch (c) {
|
|
434
485
|
console.warn(
|
|
435
486
|
`[Rozenite] Storage Plugin: Failed to delete entry in ${a.adapterId}/${a.storageId}.`,
|
|
436
|
-
|
|
487
|
+
c
|
|
437
488
|
);
|
|
438
489
|
}
|
|
439
490
|
}
|
|
440
491
|
),
|
|
441
|
-
r.onMessage(
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
492
|
+
r.onMessage(
|
|
493
|
+
"get-snapshot",
|
|
494
|
+
async ({ target: a }) => {
|
|
495
|
+
if (a === "all") {
|
|
496
|
+
await o();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
await o(`${a.adapterId}:${a.storageId}`);
|
|
445
500
|
}
|
|
446
|
-
|
|
447
|
-
|
|
501
|
+
),
|
|
502
|
+
r.onMessage(
|
|
503
|
+
"import-entries",
|
|
504
|
+
async (a) => {
|
|
505
|
+
await x(e, a, (l) => {
|
|
506
|
+
l.type === "set-entry" ? r.send("set-entry", l) : r.send("import-result", l);
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
)
|
|
448
510
|
];
|
|
449
511
|
return () => {
|
|
450
|
-
|
|
512
|
+
s = !0, n.forEach((a) => a.remove()), i.forEach((a) => a.remove());
|
|
451
513
|
};
|
|
452
|
-
}, [r,
|
|
514
|
+
}, [r, e]), r;
|
|
453
515
|
};
|
|
454
516
|
export {
|
|
455
|
-
|
|
517
|
+
B as useRozeniteStoragePlugin
|
|
456
518
|
};
|