@rozenite/storage-plugin 2.2.0 → 2.3.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 +16 -0
- package/dist/devtools/assets/panel-CcThj-0Z.js +32 -0
- package/dist/devtools/assets/panel-DTYbHqnH.css +1 -0
- package/dist/devtools/panel.html +2 -2
- package/dist/react-native/cjs/package.json +3 -0
- package/dist/react-native/cjs/react-native.js +38 -0
- package/dist/react-native/cjs/src/react-native/adapters/async-storage.js +60 -0
- package/dist/react-native/cjs/src/react-native/adapters/index.js +10 -0
- package/dist/react-native/cjs/src/react-native/adapters/mmkv.js +143 -0
- package/dist/react-native/cjs/src/react-native/adapters/secure-storage.js +51 -0
- package/dist/react-native/cjs/src/react-native/entry-preview-pagination.js +198 -0
- package/dist/react-native/cjs/src/react-native/export-snapshot.js +70 -0
- package/dist/react-native/cjs/src/react-native/full-entry-request.js +72 -0
- package/dist/react-native/cjs/src/react-native/import.js +185 -0
- package/dist/react-native/cjs/src/react-native/storage-discovery.js +69 -0
- package/dist/react-native/cjs/src/react-native/storage-view.js +128 -0
- package/dist/react-native/cjs/src/react-native/useRozeniteStoragePlugin.js +145 -0
- package/dist/react-native/cjs/src/react-native/useStorageAgentTools.js +228 -0
- package/dist/react-native/cjs/src/shared/agent-tools.js +119 -0
- package/dist/react-native/cjs/src/shared/entry-preview.js +48 -0
- package/dist/react-native/cjs/src/shared/messaging.js +2 -0
- package/dist/react-native/cjs/src/shared/snapshot.js +185 -0
- package/dist/react-native/cjs/src/shared/types.js +13 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/react-native.d.ts +7 -0
- package/dist/react-native/react-native.js +40 -0
- package/dist/react-native/src/react-native/adapters/async-storage.d.ts +34 -0
- package/dist/react-native/src/react-native/adapters/async-storage.js +56 -0
- package/dist/react-native/src/react-native/adapters/index.d.ts +6 -0
- package/dist/react-native/src/react-native/adapters/index.js +3 -0
- package/dist/react-native/src/react-native/adapters/mmkv.d.ts +13 -0
- package/dist/react-native/src/react-native/adapters/mmkv.js +139 -0
- package/dist/react-native/src/react-native/adapters/secure-storage.d.ts +18 -0
- package/dist/react-native/src/react-native/adapters/secure-storage.js +47 -0
- package/dist/react-native/src/react-native/entry-preview-pagination.d.ts +7 -0
- package/dist/react-native/src/react-native/entry-preview-pagination.js +194 -0
- package/dist/react-native/src/react-native/export-snapshot.d.ts +5 -0
- package/dist/react-native/src/react-native/export-snapshot.js +66 -0
- package/dist/react-native/src/react-native/full-entry-request.d.ts +5 -0
- package/dist/react-native/src/react-native/full-entry-request.js +68 -0
- package/dist/react-native/src/react-native/import.d.ts +7 -0
- package/dist/react-native/src/react-native/import.js +180 -0
- package/dist/react-native/src/react-native/storage-discovery.d.ts +5 -0
- package/dist/react-native/src/react-native/storage-discovery.js +65 -0
- package/dist/react-native/src/react-native/storage-view.d.ts +19 -0
- package/dist/react-native/src/react-native/storage-view.js +123 -0
- package/dist/react-native/src/react-native/useRozeniteStoragePlugin.d.ts +6 -0
- package/dist/react-native/src/react-native/useRozeniteStoragePlugin.js +141 -0
- package/dist/react-native/src/react-native/useStorageAgentTools.d.ts +37 -0
- package/dist/react-native/src/react-native/useStorageAgentTools.js +223 -0
- package/dist/react-native/src/shared/agent-tools.d.ts +76 -0
- package/dist/react-native/src/shared/agent-tools.js +116 -0
- package/dist/react-native/src/shared/entry-preview.d.ts +4 -0
- package/dist/react-native/src/shared/entry-preview.js +44 -0
- package/dist/react-native/src/shared/messaging.d.ts +134 -0
- package/dist/react-native/src/shared/messaging.js +1 -0
- package/dist/react-native/src/shared/snapshot.d.ts +53 -0
- package/dist/react-native/src/shared/snapshot.js +179 -0
- package/dist/react-native/src/shared/types.d.ts +78 -0
- package/dist/react-native/src/shared/types.js +8 -0
- package/dist/rozenite.json +1 -1
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/sdk.d.ts +44 -0
- package/dist/sdk/sdk.js +9 -0
- package/dist/sdk/src/shared/agent-tools.d.ts +76 -0
- package/dist/sdk/src/shared/agent-tools.js +119 -0
- package/dist/sdk/src/shared/types.d.ts +78 -0
- package/dist/sdk/src/shared/types.js +13 -0
- package/package.json +16 -16
- package/react-native.ts +8 -1
- package/rozenite.config.ts +1 -0
- package/src/__tests__/release-bundle.test.ts +32 -0
- package/dist/devtools/assets/panel-D5z1BY8U.js +0 -32
- package/dist/devtools/assets/panel-DVlWRg6d.css +0 -1
- package/dist/react-native/chunks/async-storage.require.cjs +0 -1
- package/dist/react-native/chunks/async-storage.require.js +0 -53
- package/dist/react-native/chunks/index.require.cjs +0 -1
- package/dist/react-native/chunks/index.require.js +0 -103
- package/dist/react-native/chunks/secure-storage.require.cjs +0 -1
- package/dist/react-native/chunks/secure-storage.require.js +0 -46
- package/dist/react-native/chunks/types.cjs +0 -1
- package/dist/react-native/chunks/types.js +0 -11
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.cjs +0 -1
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.js +0 -1037
- package/dist/react-native/index.cjs +0 -1
- package/dist/react-native/index.d.ts +0 -365
- package/dist/react-native/index.js +0 -28
- package/dist/sdk/index.cjs +0 -1
- package/dist/sdk/index.d.ts +0 -206
- package/dist/sdk/index.js +0 -122
|
@@ -1,1037 +0,0 @@
|
|
|
1
|
-
import { useRozeniteDevToolsClient as V } from "@rozenite/plugin-bridge";
|
|
2
|
-
import { useMemo as z, useEffect as G } from "react";
|
|
3
|
-
import { s as $, D as N, g as B } from "./types.js";
|
|
4
|
-
import { useRozenitePluginAgentTool as I } from "@rozenite/agent-bridge";
|
|
5
|
-
import { defineAgentToolContract as b, definePaginatedAgentToolContract as Y, DEFAULT_PAGE_LIMIT as Q, MAX_PAGE_LIMIT as J } from "@rozenite/agent-shared";
|
|
6
|
-
const W = "@rozenite/storage-plugin", T = 1;
|
|
7
|
-
class p extends Error {
|
|
8
|
-
constructor(t, r) {
|
|
9
|
-
super(r), this.path = t;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
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
|
-
if (!X(e))
|
|
14
|
-
throw new p(t, `Expected object, got ${y(e)}`);
|
|
15
|
-
return e;
|
|
16
|
-
}, f = (e, t) => {
|
|
17
|
-
if (typeof e != "string")
|
|
18
|
-
throw new p(t, `Expected string, got ${y(e)}`);
|
|
19
|
-
return e;
|
|
20
|
-
}, C = (e, t) => {
|
|
21
|
-
if (!Array.isArray(e))
|
|
22
|
-
throw new p(t, `Expected array, got ${y(e)}`);
|
|
23
|
-
return e;
|
|
24
|
-
}, K = (e, t) => {
|
|
25
|
-
if (typeof e != "string" || !N.includes(e))
|
|
26
|
-
throw new p(
|
|
27
|
-
t,
|
|
28
|
-
`Expected one of ${N.join(", ")}, got ${y(e)}`
|
|
29
|
-
);
|
|
30
|
-
return e;
|
|
31
|
-
}, H = (e, t) => {
|
|
32
|
-
const r = S(e, t);
|
|
33
|
-
return { supportedTypes: C(r.supportedTypes, `${t}.supportedTypes`).map(
|
|
34
|
-
(a, i) => K(a, `${t}.supportedTypes[${i}]`)
|
|
35
|
-
) };
|
|
36
|
-
}, Z = (e) => {
|
|
37
|
-
const t = S(e, "storage");
|
|
38
|
-
return {
|
|
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
|
-
capabilities: H(t.capabilities, "storage.capabilities")
|
|
44
|
-
};
|
|
45
|
-
}, ee = (e, t) => {
|
|
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
|
-
case "string": {
|
|
49
|
-
const i = r.value;
|
|
50
|
-
if (typeof i != "string")
|
|
51
|
-
throw new p(
|
|
52
|
-
a,
|
|
53
|
-
`Expected string for type "string", got ${y(i)}`
|
|
54
|
-
);
|
|
55
|
-
return { key: o, type: "string", value: i };
|
|
56
|
-
}
|
|
57
|
-
case "number": {
|
|
58
|
-
const i = r.value;
|
|
59
|
-
if (typeof i != "number" || !Number.isFinite(i))
|
|
60
|
-
throw new p(
|
|
61
|
-
a,
|
|
62
|
-
`Expected finite number for type "number", got ${y(i)}`
|
|
63
|
-
);
|
|
64
|
-
return { key: o, type: "number", value: i };
|
|
65
|
-
}
|
|
66
|
-
case "boolean": {
|
|
67
|
-
const i = r.value;
|
|
68
|
-
if (typeof i != "boolean")
|
|
69
|
-
throw new p(
|
|
70
|
-
a,
|
|
71
|
-
`Expected boolean for type "boolean", got ${y(i)}`
|
|
72
|
-
);
|
|
73
|
-
return { key: o, type: "boolean", value: i };
|
|
74
|
-
}
|
|
75
|
-
case "buffer": {
|
|
76
|
-
const i = r.value;
|
|
77
|
-
if (!Array.isArray(i))
|
|
78
|
-
throw new p(
|
|
79
|
-
a,
|
|
80
|
-
`Expected number[] for type "buffer", got ${y(i)}`
|
|
81
|
-
);
|
|
82
|
-
const s = i.map((c, d) => {
|
|
83
|
-
if (typeof c != "number" || !Number.isInteger(c) || c < 0 || c > 255)
|
|
84
|
-
throw new p(
|
|
85
|
-
`${a}[${d}]`,
|
|
86
|
-
`Expected uint8 (integer 0-255), got ${y(c)}`
|
|
87
|
-
);
|
|
88
|
-
return c;
|
|
89
|
-
});
|
|
90
|
-
return { key: o, type: "buffer", value: s };
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}, te = (e) => {
|
|
94
|
-
try {
|
|
95
|
-
const t = S(e, "$"), r = t.version;
|
|
96
|
-
if (r !== T)
|
|
97
|
-
throw new p(
|
|
98
|
-
"version",
|
|
99
|
-
`Unsupported snapshot version: ${y(r)} (this build supports version ${T})`
|
|
100
|
-
);
|
|
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}]`));
|
|
102
|
-
return {
|
|
103
|
-
ok: !0,
|
|
104
|
-
snapshot: {
|
|
105
|
-
version: T,
|
|
106
|
-
plugin: o,
|
|
107
|
-
createdAt: n,
|
|
108
|
-
storage: a,
|
|
109
|
-
entries: s
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
} catch (t) {
|
|
113
|
-
if (t instanceof p)
|
|
114
|
-
return { ok: !1, error: { path: t.path, message: t.message } };
|
|
115
|
-
throw t;
|
|
116
|
-
}
|
|
117
|
-
}, re = (e) => ({
|
|
118
|
-
version: 1,
|
|
119
|
-
plugin: W,
|
|
120
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
121
|
-
storage: {
|
|
122
|
-
adapterId: e.target.adapterId,
|
|
123
|
-
storageId: e.target.storageId,
|
|
124
|
-
adapterName: e.adapterName,
|
|
125
|
-
storageName: e.storageName,
|
|
126
|
-
capabilities: e.capabilities
|
|
127
|
-
},
|
|
128
|
-
entries: e.entries
|
|
129
|
-
}), se = (e, t) => {
|
|
130
|
-
const r = [], o = [], n = [], a = [], i = [];
|
|
131
|
-
for (const [c, d] of e.entries.entries()) {
|
|
132
|
-
if (!$(t.capabilities, d.type)) {
|
|
133
|
-
a.push({ key: d.key, type: d.type });
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
if (t.isBlacklisted(d.key)) {
|
|
137
|
-
n.push({ key: d.key, reason: "blacklist" });
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
t.entryKeys.has(d.key) ? o.push(d.key) : r.push(d.key), i.push(c), t.entryKeys.add(d.key);
|
|
141
|
-
}
|
|
142
|
-
const s = e.storage.adapterId !== t.target.adapterId || e.storage.storageId !== t.target.storageId;
|
|
143
|
-
return {
|
|
144
|
-
newKeys: r,
|
|
145
|
-
overwriteKeys: o,
|
|
146
|
-
skippedKeys: n,
|
|
147
|
-
unsupportedTypes: a,
|
|
148
|
-
acceptedEntryIndexes: i,
|
|
149
|
-
metadataMismatch: s
|
|
150
|
-
};
|
|
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) => {
|
|
152
|
-
if (typeof e != "object" || e == null || Array.isArray(e))
|
|
153
|
-
return !1;
|
|
154
|
-
const t = e;
|
|
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(
|
|
156
|
-
(r) => typeof r == "number" && Number.isInteger(r) && r >= 0 && r <= 255
|
|
157
|
-
);
|
|
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)
|
|
161
|
-
return {
|
|
162
|
-
type: "storage-request-error",
|
|
163
|
-
requestId: r,
|
|
164
|
-
code: "INVALID_REQUEST",
|
|
165
|
-
message: "Import preview requests require a valid target, request ID, and snapshot."
|
|
166
|
-
};
|
|
167
|
-
const a = U(e, o.target);
|
|
168
|
-
if (!a)
|
|
169
|
-
return {
|
|
170
|
-
type: "storage-request-error",
|
|
171
|
-
requestId: r,
|
|
172
|
-
code: "TARGET_NOT_FOUND",
|
|
173
|
-
message: "The requested storage target was not found."
|
|
174
|
-
};
|
|
175
|
-
try {
|
|
176
|
-
const i = new Set(await a.getAllKeys());
|
|
177
|
-
return {
|
|
178
|
-
type: "import-preview",
|
|
179
|
-
requestId: r,
|
|
180
|
-
target: a.target,
|
|
181
|
-
preview: se(n.snapshot, {
|
|
182
|
-
target: a.target,
|
|
183
|
-
capabilities: a.capabilities,
|
|
184
|
-
entryKeys: i,
|
|
185
|
-
isBlacklisted: (s) => O(a, s)
|
|
186
|
-
})
|
|
187
|
-
};
|
|
188
|
-
} catch {
|
|
189
|
-
return {
|
|
190
|
-
type: "storage-request-error",
|
|
191
|
-
requestId: r,
|
|
192
|
-
code: "READ_FAILED",
|
|
193
|
-
message: "Failed to inspect the requested storage for import."
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}, ie = async (e, t, r) => {
|
|
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)) {
|
|
199
|
-
r({
|
|
200
|
-
type: "import-result",
|
|
201
|
-
requestId: o,
|
|
202
|
-
target: R(n.target) ? n.target : { adapterId: "", storageId: "" },
|
|
203
|
-
ok: !1,
|
|
204
|
-
written: 0,
|
|
205
|
-
total: 0,
|
|
206
|
-
error: "Import requests require a valid target, request ID, and entries."
|
|
207
|
-
});
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const a = U(e, n.target);
|
|
211
|
-
if (!a) {
|
|
212
|
-
r({
|
|
213
|
-
type: "import-result",
|
|
214
|
-
requestId: n.requestId,
|
|
215
|
-
target: n.target,
|
|
216
|
-
ok: !1,
|
|
217
|
-
written: 0,
|
|
218
|
-
total: n.entries.length,
|
|
219
|
-
error: "Target storage not found"
|
|
220
|
-
});
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const i = n.entries.filter(
|
|
224
|
-
(s) => $(a.capabilities, s.type) && !O(a, s.key)
|
|
225
|
-
);
|
|
226
|
-
for (let s = 0; s < i.length; s++) {
|
|
227
|
-
const c = i[s];
|
|
228
|
-
try {
|
|
229
|
-
await a.set(c);
|
|
230
|
-
} catch (d) {
|
|
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({
|
|
241
|
-
type: "import-result",
|
|
242
|
-
requestId: n.requestId,
|
|
243
|
-
target: n.target,
|
|
244
|
-
ok: !1,
|
|
245
|
-
written: s,
|
|
246
|
-
total: i.length,
|
|
247
|
-
failedKey: c.key,
|
|
248
|
-
error: d instanceof Error ? d.message : String(d)
|
|
249
|
-
});
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
r({
|
|
253
|
-
type: "import-progress",
|
|
254
|
-
requestId: n.requestId,
|
|
255
|
-
target: n.target,
|
|
256
|
-
written: s + 1,
|
|
257
|
-
total: i.length
|
|
258
|
-
});
|
|
259
|
-
}
|
|
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({
|
|
270
|
-
type: "import-result",
|
|
271
|
-
requestId: n.requestId,
|
|
272
|
-
target: n.target,
|
|
273
|
-
ok: !0,
|
|
274
|
-
written: i.length,
|
|
275
|
-
total: i.length
|
|
276
|
-
});
|
|
277
|
-
}, ce = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.requestId == "string" ? e.requestId : "", de = (e) => typeof e == "object" && e != null && !Array.isArray(e) && e.type === "discover-storages" && typeof e.requestId == "string" && e.requestId.trim().length > 0, ge = async (e) => ({
|
|
278
|
-
target: e.target,
|
|
279
|
-
adapterName: e.adapterName,
|
|
280
|
-
storageName: e.storageName,
|
|
281
|
-
entryCount: (await e.getAllKeys()).length,
|
|
282
|
-
capabilities: e.capabilities,
|
|
283
|
-
supportsSubscriptions: e.supportsSubscriptions
|
|
284
|
-
}), pe = (e) => {
|
|
285
|
-
const t = /* @__PURE__ */ new Set();
|
|
286
|
-
return e.some(({ target: r }) => {
|
|
287
|
-
const o = `${r.adapterId}:${r.storageId}`;
|
|
288
|
-
return t.has(o) ? !0 : (t.add(o), !1);
|
|
289
|
-
});
|
|
290
|
-
}, ue = async (e, t) => {
|
|
291
|
-
const r = ce(t);
|
|
292
|
-
if (!de(t))
|
|
293
|
-
return {
|
|
294
|
-
type: "storage-request-error",
|
|
295
|
-
requestId: r,
|
|
296
|
-
code: "INVALID_REQUEST",
|
|
297
|
-
message: "Storage discovery requires a non-empty request ID."
|
|
298
|
-
};
|
|
299
|
-
try {
|
|
300
|
-
if (pe(e))
|
|
301
|
-
return {
|
|
302
|
-
type: "storage-request-error",
|
|
303
|
-
requestId: r,
|
|
304
|
-
code: "INVALID_REQUEST",
|
|
305
|
-
message: "Configured storages must have unique targets."
|
|
306
|
-
};
|
|
307
|
-
const o = await Promise.all(e.map(ge));
|
|
308
|
-
return { type: "storage-descriptors", requestId: r, storages: o };
|
|
309
|
-
} catch {
|
|
310
|
-
return {
|
|
311
|
-
type: "storage-request-error",
|
|
312
|
-
requestId: r,
|
|
313
|
-
code: "READ_FAILED",
|
|
314
|
-
message: "Failed to discover configured storages."
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
}, ye = 256, k = 16, le = (e) => e.toString(16).toUpperCase().padStart(2, "0"), fe = (e) => {
|
|
318
|
-
let t = "", r = 0;
|
|
319
|
-
for (const o of e) {
|
|
320
|
-
if (r === ye)
|
|
321
|
-
return { preview: t, isTruncated: !0 };
|
|
322
|
-
t += o, r += 1;
|
|
323
|
-
}
|
|
324
|
-
return { preview: t, isTruncated: !1 };
|
|
325
|
-
}, Ie = (e) => {
|
|
326
|
-
if (e.type === "string")
|
|
327
|
-
return {
|
|
328
|
-
key: e.key,
|
|
329
|
-
type: e.type,
|
|
330
|
-
...fe(e.value),
|
|
331
|
-
// JavaScript strings expose their length in UTF-16 code units.
|
|
332
|
-
valueSize: e.value.length
|
|
333
|
-
};
|
|
334
|
-
if (e.type === "buffer") {
|
|
335
|
-
const r = e.value.slice(0, k);
|
|
336
|
-
return {
|
|
337
|
-
key: e.key,
|
|
338
|
-
type: e.type,
|
|
339
|
-
preview: r.map(le).join(" "),
|
|
340
|
-
valueSize: e.value.length,
|
|
341
|
-
isTruncated: e.value.length > k
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
const t = String(e.value);
|
|
345
|
-
return {
|
|
346
|
-
key: e.key,
|
|
347
|
-
type: e.type,
|
|
348
|
-
preview: t,
|
|
349
|
-
valueSize: t.length,
|
|
350
|
-
isTruncated: !1
|
|
351
|
-
};
|
|
352
|
-
}, me = 100, he = 4, we = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.requestId == "string" ? e.requestId : "", L = (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, be = (e) => (e ?? "").trim().toLowerCase(), Ee = (e) => {
|
|
353
|
-
if (typeof e != "object" || e == null || Array.isArray(e) || e.type !== "list-entry-previews" || typeof e.requestId != "string" || e.requestId.trim().length === 0 || !L(e.target) || e.search !== void 0 && typeof e.search != "string" || e.cursor !== void 0 && typeof e.cursor != "string" || !Number.isFinite(e.limit) || !Number.isInteger(e.limit) || e.limit < 1)
|
|
354
|
-
return;
|
|
355
|
-
const t = e.keySortDirection;
|
|
356
|
-
if (t !== void 0 && t !== "ascending" && t !== "descending")
|
|
357
|
-
return;
|
|
358
|
-
const r = e;
|
|
359
|
-
return {
|
|
360
|
-
...r,
|
|
361
|
-
search: be(r.search),
|
|
362
|
-
keySortDirection: t ?? "ascending",
|
|
363
|
-
limit: Math.min(r.limit, me)
|
|
364
|
-
};
|
|
365
|
-
}, D = (e) => btoa(encodeURIComponent(JSON.stringify(e))), Ae = (e) => {
|
|
366
|
-
try {
|
|
367
|
-
const t = JSON.parse(decodeURIComponent(atob(e)));
|
|
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;
|
|
369
|
-
} catch {
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
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) => {
|
|
373
|
-
const r = new Array(t.length);
|
|
374
|
-
let o = 0;
|
|
375
|
-
const n = async () => {
|
|
376
|
-
for (; o < t.length; ) {
|
|
377
|
-
const a = o;
|
|
378
|
-
o += 1;
|
|
379
|
-
const i = await e.get(t[a]);
|
|
380
|
-
i && (r[a] = Ie(i));
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
return await Promise.all(
|
|
384
|
-
Array.from({ length: Math.min(he, t.length) }, n)
|
|
385
|
-
), r.filter((a) => a != null);
|
|
386
|
-
}, ve = async (e, t) => {
|
|
387
|
-
const r = we(t), o = Ee(t);
|
|
388
|
-
if (!o)
|
|
389
|
-
return {
|
|
390
|
-
type: "storage-request-error",
|
|
391
|
-
requestId: r,
|
|
392
|
-
code: "INVALID_REQUEST",
|
|
393
|
-
message: "Entry preview requests require a valid target, request ID, and positive integer limit."
|
|
394
|
-
};
|
|
395
|
-
const n = e.find((i) => x(i.target, o.target));
|
|
396
|
-
if (!n)
|
|
397
|
-
return {
|
|
398
|
-
type: "storage-request-error",
|
|
399
|
-
requestId: r,
|
|
400
|
-
code: "TARGET_NOT_FOUND",
|
|
401
|
-
message: "The requested storage target was not found."
|
|
402
|
-
};
|
|
403
|
-
let 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))
|
|
405
|
-
return {
|
|
406
|
-
type: "storage-request-error",
|
|
407
|
-
requestId: r,
|
|
408
|
-
code: "INVALID_CURSOR",
|
|
409
|
-
message: "The entry preview cursor is invalid or belongs to a different query.",
|
|
410
|
-
resetPagination: !0
|
|
411
|
-
};
|
|
412
|
-
try {
|
|
413
|
-
const i = (await n.getAllKeys()).filter((l) => l.toLowerCase().includes(o.search)).sort(qe);
|
|
414
|
-
o.keySortDirection === "descending" && i.reverse();
|
|
415
|
-
let s = 0;
|
|
416
|
-
if (a) {
|
|
417
|
-
const l = i.indexOf(a.boundaryKey);
|
|
418
|
-
if (l === -1)
|
|
419
|
-
return {
|
|
420
|
-
type: "storage-request-error",
|
|
421
|
-
requestId: r,
|
|
422
|
-
code: "INVALID_CURSOR",
|
|
423
|
-
message: "The entry preview cursor is stale after storage changes.",
|
|
424
|
-
resetPagination: !0
|
|
425
|
-
};
|
|
426
|
-
s = a.direction === "next" ? l + 1 : Math.max(0, l - o.limit);
|
|
427
|
-
}
|
|
428
|
-
const c = i.slice(s, s + o.limit), d = await Se(n, c), g = s + c.length, u = {
|
|
429
|
-
version: 1,
|
|
430
|
-
target: o.target,
|
|
431
|
-
search: o.search,
|
|
432
|
-
keySortDirection: o.keySortDirection
|
|
433
|
-
};
|
|
434
|
-
return {
|
|
435
|
-
type: "entry-previews",
|
|
436
|
-
requestId: r,
|
|
437
|
-
target: o.target,
|
|
438
|
-
items: d,
|
|
439
|
-
...g < i.length && c.length > 0 ? {
|
|
440
|
-
nextCursor: D({
|
|
441
|
-
...u,
|
|
442
|
-
boundaryKey: c.at(-1),
|
|
443
|
-
direction: "next"
|
|
444
|
-
})
|
|
445
|
-
} : {},
|
|
446
|
-
...s > 0 && c.length > 0 ? {
|
|
447
|
-
previousCursor: D({
|
|
448
|
-
...u,
|
|
449
|
-
boundaryKey: c[0],
|
|
450
|
-
direction: "previous"
|
|
451
|
-
})
|
|
452
|
-
} : {}
|
|
453
|
-
};
|
|
454
|
-
} catch {
|
|
455
|
-
return {
|
|
456
|
-
type: "storage-request-error",
|
|
457
|
-
requestId: r,
|
|
458
|
-
code: "READ_FAILED",
|
|
459
|
-
message: "Failed to read entry previews from the requested storage."
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
}, Te = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.requestId == "string" ? e.requestId : "", Re = (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, $e = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, Ne = (e) => typeof e == "object" && e != null && !Array.isArray(e) && e.type === "get-entry" && typeof e.requestId == "string" && e.requestId.trim().length > 0 && Re(e.target) && typeof e.key == "string", ke = async (e, t) => {
|
|
463
|
-
const r = Te(t);
|
|
464
|
-
if (!Ne(t))
|
|
465
|
-
return {
|
|
466
|
-
type: "storage-request-error",
|
|
467
|
-
requestId: r,
|
|
468
|
-
code: "INVALID_REQUEST",
|
|
469
|
-
message: "Full entry requests require a valid target, request ID, and string key."
|
|
470
|
-
};
|
|
471
|
-
const o = e.find((n) => $e(n.target, t.target));
|
|
472
|
-
if (!o)
|
|
473
|
-
return {
|
|
474
|
-
type: "storage-request-error",
|
|
475
|
-
requestId: r,
|
|
476
|
-
code: "TARGET_NOT_FOUND",
|
|
477
|
-
message: "The requested storage target was not found."
|
|
478
|
-
};
|
|
479
|
-
try {
|
|
480
|
-
const n = await o.get(t.key);
|
|
481
|
-
return n ? {
|
|
482
|
-
type: "entry",
|
|
483
|
-
requestId: r,
|
|
484
|
-
target: o.target,
|
|
485
|
-
entry: n
|
|
486
|
-
} : {
|
|
487
|
-
type: "storage-request-error",
|
|
488
|
-
requestId: r,
|
|
489
|
-
code: "ENTRY_NOT_FOUND",
|
|
490
|
-
message: "The requested storage entry was not found."
|
|
491
|
-
};
|
|
492
|
-
} catch {
|
|
493
|
-
return {
|
|
494
|
-
type: "storage-request-error",
|
|
495
|
-
requestId: r,
|
|
496
|
-
code: "READ_FAILED",
|
|
497
|
-
message: "Failed to read the requested storage entry."
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
}, De = (e) => typeof e == "object" && e != null && !Array.isArray(e) && typeof e.requestId == "string" ? e.requestId : "", xe = (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, _e = (e, t) => e.adapterId === t.adapterId && e.storageId === t.storageId, Pe = (e) => typeof e == "object" && e != null && !Array.isArray(e) && e.type === "export-snapshot" && typeof e.requestId == "string" && e.requestId.trim().length > 0 && xe(e.target), je = async (e, t) => {
|
|
501
|
-
const r = De(t);
|
|
502
|
-
if (!Pe(t))
|
|
503
|
-
return {
|
|
504
|
-
type: "storage-request-error",
|
|
505
|
-
requestId: r,
|
|
506
|
-
code: "INVALID_REQUEST",
|
|
507
|
-
message: "Export requests require a valid target and request ID."
|
|
508
|
-
};
|
|
509
|
-
const o = e.find((n) => _e(n.target, t.target));
|
|
510
|
-
if (!o)
|
|
511
|
-
return {
|
|
512
|
-
type: "storage-request-error",
|
|
513
|
-
requestId: r,
|
|
514
|
-
code: "TARGET_NOT_FOUND",
|
|
515
|
-
message: "The requested storage target was not found."
|
|
516
|
-
};
|
|
517
|
-
try {
|
|
518
|
-
const n = await o.getAllEntries();
|
|
519
|
-
return {
|
|
520
|
-
type: "export-snapshot-result",
|
|
521
|
-
requestId: r,
|
|
522
|
-
target: o.target,
|
|
523
|
-
snapshot: re({
|
|
524
|
-
target: o.target,
|
|
525
|
-
adapterName: o.adapterName,
|
|
526
|
-
storageName: o.storageName,
|
|
527
|
-
capabilities: o.capabilities,
|
|
528
|
-
entries: n
|
|
529
|
-
})
|
|
530
|
-
};
|
|
531
|
-
} catch {
|
|
532
|
-
return {
|
|
533
|
-
type: "storage-request-error",
|
|
534
|
-
requestId: r,
|
|
535
|
-
code: "READ_FAILED",
|
|
536
|
-
message: "Failed to export the requested storage."
|
|
537
|
-
};
|
|
538
|
-
}
|
|
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) => {
|
|
540
|
-
if (!$(e, t))
|
|
541
|
-
throw new Error(
|
|
542
|
-
`Type "${t}" is not supported by storage "${r.storageId}" in adapter "${r.adapterId}".`
|
|
543
|
-
);
|
|
544
|
-
}, _ = async (e) => (v(e), e.getAllKeys()), P = async (e, t) => (v(e), e.get(t)), Ce = async (e, t) => {
|
|
545
|
-
if (v(e)) {
|
|
546
|
-
await e.set(t);
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
e.set(t);
|
|
550
|
-
}, Ke = async (e, t) => {
|
|
551
|
-
if (v(e)) {
|
|
552
|
-
await e.delete(t);
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
e.delete(t);
|
|
556
|
-
}, Me = async (e) => {
|
|
557
|
-
await e.clear();
|
|
558
|
-
}, Oe = (e, t) => {
|
|
559
|
-
const r = t.storage, o = r.subscribe, n = /* @__PURE__ */ new Set();
|
|
560
|
-
let a = !1;
|
|
561
|
-
const i = {
|
|
562
|
-
adapterId: e.id,
|
|
563
|
-
storageId: t.id
|
|
564
|
-
}, s = async (d) => {
|
|
565
|
-
if (!q(t, d))
|
|
566
|
-
return P(r, d);
|
|
567
|
-
}, c = async () => {
|
|
568
|
-
const d = await _(r);
|
|
569
|
-
return (await Promise.all(
|
|
570
|
-
d.filter((u) => !q(t, u)).map((u) => P(r, u))
|
|
571
|
-
)).filter((u) => !!u);
|
|
572
|
-
};
|
|
573
|
-
return {
|
|
574
|
-
id: B(i),
|
|
575
|
-
target: i,
|
|
576
|
-
adapterName: e.name,
|
|
577
|
-
storageName: t.name,
|
|
578
|
-
capabilities: t.capabilities,
|
|
579
|
-
supportsSubscriptions: o != null,
|
|
580
|
-
blacklist: t.blacklist,
|
|
581
|
-
get: s,
|
|
582
|
-
set: async (d) => {
|
|
583
|
-
Fe(t.capabilities, d.type, i), n.add(d.key);
|
|
584
|
-
try {
|
|
585
|
-
await Ce(r, d);
|
|
586
|
-
} finally {
|
|
587
|
-
n.delete(d.key);
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
delete: async (d) => {
|
|
591
|
-
n.add(d);
|
|
592
|
-
try {
|
|
593
|
-
await Ke(r, d);
|
|
594
|
-
} finally {
|
|
595
|
-
n.delete(d);
|
|
596
|
-
}
|
|
597
|
-
},
|
|
598
|
-
purge: async () => {
|
|
599
|
-
a = !0;
|
|
600
|
-
try {
|
|
601
|
-
await Me(r);
|
|
602
|
-
} finally {
|
|
603
|
-
a = !1;
|
|
604
|
-
}
|
|
605
|
-
},
|
|
606
|
-
getAllKeys: async () => (await _(r)).filter((g) => !q(t, g)),
|
|
607
|
-
getAllEntries: c,
|
|
608
|
-
...o ? {
|
|
609
|
-
watch: async (d) => o((g) => {
|
|
610
|
-
!a && !n.has(g) && !q(t, g) && d(g);
|
|
611
|
-
})
|
|
612
|
-
} : {}
|
|
613
|
-
};
|
|
614
|
-
}, Ue = (e) => e.flatMap(
|
|
615
|
-
(t) => t.storages.map((r) => Oe(t, r))
|
|
616
|
-
), E = {
|
|
617
|
-
adapterId: {
|
|
618
|
-
type: "string",
|
|
619
|
-
description: "Storage adapter ID. Required when multiple adapters are configured."
|
|
620
|
-
},
|
|
621
|
-
storageId: {
|
|
622
|
-
type: "string",
|
|
623
|
-
description: "Storage node ID within the adapter. Required when multiple storages are configured."
|
|
624
|
-
}
|
|
625
|
-
}, m = "@rozenite/storage-plugin", j = [
|
|
626
|
-
"string",
|
|
627
|
-
"number",
|
|
628
|
-
"boolean",
|
|
629
|
-
"buffer"
|
|
630
|
-
], h = {
|
|
631
|
-
listStorages: b({
|
|
632
|
-
name: "list-storages",
|
|
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.",
|
|
634
|
-
inputSchema: { type: "object", properties: {} }
|
|
635
|
-
}),
|
|
636
|
-
listEntries: Y({
|
|
637
|
-
name: "list-entries",
|
|
638
|
-
description: "List keys in a storage. This call intentionally does not return entry values to keep responses token-efficient.",
|
|
639
|
-
inputSchema: {
|
|
640
|
-
type: "object",
|
|
641
|
-
properties: {
|
|
642
|
-
...E,
|
|
643
|
-
limit: {
|
|
644
|
-
type: "number",
|
|
645
|
-
description: "Pagination size. Defaults to 20 and is capped at 100."
|
|
646
|
-
},
|
|
647
|
-
cursor: {
|
|
648
|
-
type: "string",
|
|
649
|
-
description: "Opaque pagination cursor from a previous list-entries call."
|
|
650
|
-
},
|
|
651
|
-
offset: {
|
|
652
|
-
type: "number",
|
|
653
|
-
description: "Deprecated initial pagination offset. Must be a non-negative integer and cannot be combined with cursor."
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
|
-
pagination: {
|
|
658
|
-
kind: "cursor",
|
|
659
|
-
fields: ["key"],
|
|
660
|
-
defaultFields: ["key"]
|
|
661
|
-
}
|
|
662
|
-
}),
|
|
663
|
-
readEntry: b({
|
|
664
|
-
name: "read-entry",
|
|
665
|
-
description: "Read a single storage entry value by key.",
|
|
666
|
-
inputSchema: {
|
|
667
|
-
type: "object",
|
|
668
|
-
properties: {
|
|
669
|
-
...E,
|
|
670
|
-
key: { type: "string", description: "Entry key." }
|
|
671
|
-
},
|
|
672
|
-
required: ["key"]
|
|
673
|
-
}
|
|
674
|
-
}),
|
|
675
|
-
createEntry: b({
|
|
676
|
-
name: "create-entry",
|
|
677
|
-
description: "Create a new storage entry. Fails if the key already exists.",
|
|
678
|
-
inputSchema: {
|
|
679
|
-
type: "object",
|
|
680
|
-
properties: {
|
|
681
|
-
...E,
|
|
682
|
-
key: { type: "string", description: "Entry key." },
|
|
683
|
-
type: {
|
|
684
|
-
type: "string",
|
|
685
|
-
enum: [...j],
|
|
686
|
-
description: "Entry value type. Must be one of the supported types for the target storage (see list-storages)."
|
|
687
|
-
},
|
|
688
|
-
value: {
|
|
689
|
-
description: "Entry value matching the provided type."
|
|
690
|
-
}
|
|
691
|
-
},
|
|
692
|
-
required: ["key", "type", "value"]
|
|
693
|
-
}
|
|
694
|
-
}),
|
|
695
|
-
editEntry: b({
|
|
696
|
-
name: "edit-entry",
|
|
697
|
-
description: "Edit an existing storage entry. Fails if the key does not exist.",
|
|
698
|
-
inputSchema: {
|
|
699
|
-
type: "object",
|
|
700
|
-
properties: {
|
|
701
|
-
...E,
|
|
702
|
-
key: { type: "string", description: "Entry key." },
|
|
703
|
-
type: {
|
|
704
|
-
type: "string",
|
|
705
|
-
enum: [...j],
|
|
706
|
-
description: "Entry value type. Must be one of the supported types for the target storage (see list-storages)."
|
|
707
|
-
},
|
|
708
|
-
value: {
|
|
709
|
-
description: "Entry value matching the provided type."
|
|
710
|
-
}
|
|
711
|
-
},
|
|
712
|
-
required: ["key", "type", "value"]
|
|
713
|
-
}
|
|
714
|
-
}),
|
|
715
|
-
removeEntry: b({
|
|
716
|
-
name: "remove-entry",
|
|
717
|
-
description: "Remove a storage entry by key.",
|
|
718
|
-
inputSchema: {
|
|
719
|
-
type: "object",
|
|
720
|
-
properties: {
|
|
721
|
-
...E,
|
|
722
|
-
key: { type: "string", description: "Entry key." }
|
|
723
|
-
},
|
|
724
|
-
required: ["key"]
|
|
725
|
-
}
|
|
726
|
-
})
|
|
727
|
-
}, F = (e, t) => {
|
|
728
|
-
if (e === "string") {
|
|
729
|
-
if (typeof t != "string")
|
|
730
|
-
throw new Error("Expected string value for type=string");
|
|
731
|
-
return t;
|
|
732
|
-
}
|
|
733
|
-
if (e === "number") {
|
|
734
|
-
if (typeof t != "number" || Number.isNaN(t))
|
|
735
|
-
throw new Error("Expected number value for type=number");
|
|
736
|
-
return t;
|
|
737
|
-
}
|
|
738
|
-
if (e === "boolean") {
|
|
739
|
-
if (typeof t != "boolean")
|
|
740
|
-
throw new Error("Expected boolean value for type=boolean");
|
|
741
|
-
return t;
|
|
742
|
-
}
|
|
743
|
-
if (!Array.isArray(t) || !t.every((r) => Number.isInteger(r)))
|
|
744
|
-
throw new Error("Expected number[] value for type=buffer");
|
|
745
|
-
return t;
|
|
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) => {
|
|
747
|
-
try {
|
|
748
|
-
const t = JSON.parse(decodeURIComponent(atob(e)));
|
|
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)
|
|
750
|
-
throw new Error("Invalid cursor");
|
|
751
|
-
return t;
|
|
752
|
-
} catch {
|
|
753
|
-
throw new Error(
|
|
754
|
-
"Invalid cursor. Run list-entries again without a cursor to restart pagination."
|
|
755
|
-
);
|
|
756
|
-
}
|
|
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) => {
|
|
758
|
-
if (e.length === 0)
|
|
759
|
-
throw new Error("No storages are registered.");
|
|
760
|
-
if (t !== void 0 || r !== void 0) {
|
|
761
|
-
const o = e.filter(
|
|
762
|
-
(a) => (t === void 0 || a.target.adapterId === t) && (r === void 0 || a.target.storageId === r)
|
|
763
|
-
), n = [
|
|
764
|
-
t !== void 0 && `adapterId="${t}"`,
|
|
765
|
-
r !== void 0 && `storageId="${r}"`
|
|
766
|
-
].filter(Boolean).join(", ");
|
|
767
|
-
if (o.length === 0)
|
|
768
|
-
throw new Error(
|
|
769
|
-
`No storage matched ${n}. Available: ${e.map(w).join(", ")}`
|
|
770
|
-
);
|
|
771
|
-
if (o.length > 1)
|
|
772
|
-
throw new Error(
|
|
773
|
-
`Multiple storages matched ${n}. Provide both adapterId and storageId. Available: ${o.map(w).join(", ")}`
|
|
774
|
-
);
|
|
775
|
-
return o[0];
|
|
776
|
-
}
|
|
777
|
-
if (e.length > 1)
|
|
778
|
-
throw new Error(
|
|
779
|
-
`Multiple storages detected. Provide adapterId and/or storageId. Available: ${e.map(w).join(", ")}`
|
|
780
|
-
);
|
|
781
|
-
return e[0];
|
|
782
|
-
}, Ye = async (e, t) => {
|
|
783
|
-
const r = Ge(t.limit);
|
|
784
|
-
if (t.cursor !== void 0 && t.offset !== void 0)
|
|
785
|
-
throw new Error("Provide either cursor or offset, not both.");
|
|
786
|
-
const o = t.cursor === void 0 ? void 0 : ze(t.cursor);
|
|
787
|
-
if (o && !Le(o.target, e.target))
|
|
788
|
-
throw new Error(
|
|
789
|
-
"Cursor does not match the requested storage. Run list-entries again without a cursor to restart pagination."
|
|
790
|
-
);
|
|
791
|
-
const n = await e.getAllKeys(), a = o?.offset ?? Be(t.offset), i = Math.min(a + r, n.length);
|
|
792
|
-
return {
|
|
793
|
-
adapterId: e.target.adapterId,
|
|
794
|
-
storageId: e.target.storageId,
|
|
795
|
-
total: n.length,
|
|
796
|
-
items: n.slice(a, i).map((s) => ({ key: s })),
|
|
797
|
-
page: {
|
|
798
|
-
limit: r,
|
|
799
|
-
hasMore: i < n.length,
|
|
800
|
-
...i < n.length ? {
|
|
801
|
-
nextCursor: Ve({
|
|
802
|
-
version: 1,
|
|
803
|
-
target: e.target,
|
|
804
|
-
offset: i
|
|
805
|
-
})
|
|
806
|
-
} : {}
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
}, Qe = (e) => ({
|
|
810
|
-
listStorages: async () => ({
|
|
811
|
-
storages: e.map((t) => ({
|
|
812
|
-
adapterId: t.target.adapterId,
|
|
813
|
-
storageId: t.target.storageId,
|
|
814
|
-
adapterName: t.adapterName,
|
|
815
|
-
storageName: t.storageName,
|
|
816
|
-
supportedTypes: t.capabilities.supportedTypes
|
|
817
|
-
}))
|
|
818
|
-
}),
|
|
819
|
-
listEntries: async (t) => {
|
|
820
|
-
const r = A(e, t.adapterId, t.storageId);
|
|
821
|
-
return Ye(r, t);
|
|
822
|
-
},
|
|
823
|
-
readEntry: async ({
|
|
824
|
-
adapterId: t,
|
|
825
|
-
storageId: r,
|
|
826
|
-
key: o
|
|
827
|
-
}) => {
|
|
828
|
-
const n = A(e, t, r), a = await n.get(o);
|
|
829
|
-
if (!a)
|
|
830
|
-
throw new Error(`Key "${o}" not found in storage "${w(n)}".`);
|
|
831
|
-
return {
|
|
832
|
-
adapterId: n.target.adapterId,
|
|
833
|
-
storageId: n.target.storageId,
|
|
834
|
-
entry: a
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
}), Je = (e) => {
|
|
838
|
-
const t = Qe(e);
|
|
839
|
-
I({
|
|
840
|
-
pluginId: m,
|
|
841
|
-
tool: h.listStorages,
|
|
842
|
-
handler: t.listStorages
|
|
843
|
-
}), I({
|
|
844
|
-
pluginId: m,
|
|
845
|
-
tool: h.listEntries,
|
|
846
|
-
handler: t.listEntries
|
|
847
|
-
}), I({
|
|
848
|
-
pluginId: m,
|
|
849
|
-
tool: h.readEntry,
|
|
850
|
-
handler: t.readEntry
|
|
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))
|
|
857
|
-
throw new Error(
|
|
858
|
-
`Key "${n}" already exists in storage "${w(s)}". Use edit-entry instead.`
|
|
859
|
-
);
|
|
860
|
-
const d = F(a, i);
|
|
861
|
-
return await s.set({ key: n, type: a, value: d }), {
|
|
862
|
-
adapterId: s.target.adapterId,
|
|
863
|
-
storageId: s.target.storageId,
|
|
864
|
-
created: !0,
|
|
865
|
-
key: n
|
|
866
|
-
};
|
|
867
|
-
}
|
|
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))
|
|
874
|
-
throw new Error(
|
|
875
|
-
`Key "${n}" not found in storage "${w(s)}". Use create-entry instead.`
|
|
876
|
-
);
|
|
877
|
-
const d = F(a, i);
|
|
878
|
-
return await s.set({ key: n, type: a, value: d }), {
|
|
879
|
-
adapterId: s.target.adapterId,
|
|
880
|
-
storageId: s.target.storageId,
|
|
881
|
-
edited: !0,
|
|
882
|
-
key: n
|
|
883
|
-
};
|
|
884
|
-
}
|
|
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), {
|
|
891
|
-
adapterId: a.target.adapterId,
|
|
892
|
-
storageId: a.target.storageId,
|
|
893
|
-
removed: i,
|
|
894
|
-
key: n
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
});
|
|
898
|
-
}, tt = ({ storages: e }) => {
|
|
899
|
-
const t = z(() => Ue(e), [e]);
|
|
900
|
-
Je(t);
|
|
901
|
-
const r = V({
|
|
902
|
-
pluginId: "@rozenite/storage-plugin"
|
|
903
|
-
});
|
|
904
|
-
return G(() => {
|
|
905
|
-
if (!r)
|
|
906
|
-
return;
|
|
907
|
-
const o = [];
|
|
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;
|
|
913
|
-
r.send("storage-invalidated", {
|
|
914
|
-
type: "storage-invalidated",
|
|
915
|
-
target: s,
|
|
916
|
-
key: c,
|
|
917
|
-
operation: d,
|
|
918
|
-
entryCount: u
|
|
919
|
-
});
|
|
920
|
-
};
|
|
921
|
-
Promise.all(
|
|
922
|
-
t.filter((s) => s.supportsSubscriptions && s.watch).map(async (s) => {
|
|
923
|
-
try {
|
|
924
|
-
const c = s.watch;
|
|
925
|
-
if (!c)
|
|
926
|
-
return;
|
|
927
|
-
const d = await c((g) => {
|
|
928
|
-
a(s.target, g);
|
|
929
|
-
});
|
|
930
|
-
if (n) {
|
|
931
|
-
d.remove();
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
o.push(d);
|
|
935
|
-
} catch (c) {
|
|
936
|
-
console.warn(
|
|
937
|
-
`[Rozenite] Storage Plugin: Failed to attach watcher for ${s.target.adapterId}/${s.target.storageId}.`,
|
|
938
|
-
c
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
})
|
|
942
|
-
);
|
|
943
|
-
const i = [
|
|
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}`
|
|
951
|
-
);
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
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
|
|
960
|
-
);
|
|
961
|
-
}
|
|
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}`
|
|
970
|
-
);
|
|
971
|
-
return;
|
|
972
|
-
}
|
|
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
|
-
);
|
|
980
|
-
}
|
|
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;
|
|
991
|
-
}
|
|
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
|
-
);
|
|
999
|
-
}
|
|
1000
|
-
}),
|
|
1001
|
-
r.onMessage("discover-storages", async (s) => {
|
|
1002
|
-
const c = await ue(t, s);
|
|
1003
|
-
r.send(c.type, c);
|
|
1004
|
-
}),
|
|
1005
|
-
r.onMessage(
|
|
1006
|
-
"list-entry-previews",
|
|
1007
|
-
async (s) => {
|
|
1008
|
-
const c = await ve(t, s);
|
|
1009
|
-
r.send(c.type, c);
|
|
1010
|
-
}
|
|
1011
|
-
),
|
|
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) => {
|
|
1026
|
-
r.send(c.type, c);
|
|
1027
|
-
});
|
|
1028
|
-
})
|
|
1029
|
-
];
|
|
1030
|
-
return r.send("device-ready", { type: "device-ready" }), () => {
|
|
1031
|
-
n = !0, o.forEach((s) => s.remove()), i.forEach((s) => s.remove());
|
|
1032
|
-
};
|
|
1033
|
-
}, [r, t]), r;
|
|
1034
|
-
};
|
|
1035
|
-
export {
|
|
1036
|
-
tt as useRozeniteStoragePlugin
|
|
1037
|
-
};
|