@vielzeug/vault 2.5.0 → 3.0.1
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/README.md +25 -32
- package/dist/adapter-core.cjs +1 -1
- package/dist/adapter-core.cjs.map +1 -1
- package/dist/adapter-core.d.ts +32 -7
- package/dist/adapter-core.d.ts.map +1 -1
- package/dist/adapter-core.js +204 -120
- package/dist/adapter-core.js.map +1 -1
- package/dist/adapters/indexeddb.cjs +1 -1
- package/dist/adapters/indexeddb.cjs.map +1 -1
- package/dist/adapters/indexeddb.d.ts +7 -4
- package/dist/adapters/indexeddb.d.ts.map +1 -1
- package/dist/adapters/indexeddb.js +204 -172
- package/dist/adapters/indexeddb.js.map +1 -1
- package/dist/adapters/memory.cjs +1 -1
- package/dist/adapters/memory.cjs.map +1 -1
- package/dist/adapters/memory.d.ts +2 -4
- package/dist/adapters/memory.d.ts.map +1 -1
- package/dist/adapters/memory.js +30 -52
- package/dist/adapters/memory.js.map +1 -1
- package/dist/adapters/sqlite.cjs +21 -21
- package/dist/adapters/sqlite.cjs.map +1 -1
- package/dist/adapters/sqlite.d.ts +4 -4
- package/dist/adapters/sqlite.d.ts.map +1 -1
- package/dist/adapters/sqlite.js +246 -248
- package/dist/adapters/sqlite.js.map +1 -1
- package/dist/adapters/webstorage.cjs +1 -1
- package/dist/adapters/webstorage.cjs.map +1 -1
- package/dist/adapters/webstorage.d.ts +4 -4
- package/dist/adapters/webstorage.d.ts.map +1 -1
- package/dist/adapters/webstorage.js +100 -119
- package/dist/adapters/webstorage.js.map +1 -1
- package/dist/codec.cjs +2 -0
- package/dist/codec.cjs.map +1 -0
- package/dist/codec.d.ts +5 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +6 -0
- package/dist/codec.js.map +1 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +10 -2
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/internal.cjs +1 -1
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +16 -13
- package/dist/internal.js.map +1 -1
- package/dist/query.cjs +1 -1
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.ts +8 -24
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +23 -35
- package/dist/query.js.map +1 -1
- package/dist/ttl.cjs +1 -1
- package/dist/ttl.cjs.map +1 -1
- package/dist/ttl.js +1 -1
- package/dist/ttl.js.map +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +46 -33
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -2
- package/dist/types.js.map +1 -1
- package/dist/vault.cjs +1 -1
- package/dist/vault.cjs.map +1 -1
- package/dist/vault.iife.js +1 -1
- package/dist/vault.iife.js.map +1 -1
- package/dist/vault.js +1 -1
- package/dist/vault.js.map +1 -1
- package/package.json +11 -9
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { decodeRecord as e, encodeRecord as t } from "../codec.js";
|
|
2
|
+
import { VaultDisposedError as n, VaultError as r, VaultMigrationError as i } from "../errors.js";
|
|
3
3
|
import { encodeVaultKey as a, getRecordKey as o } from "../internal.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isExpired as s, parseStored as c } from "../ttl.js";
|
|
5
|
+
import { assertBatchTables as l, buildDocumentStore as u, buildTxContext as d, withBatch as f } from "../adapter-core.js";
|
|
5
6
|
//#region src/adapters/indexeddb.ts
|
|
6
|
-
function
|
|
7
|
+
function p(e) {
|
|
7
8
|
return ({ db: t, tx: n }) => {
|
|
8
9
|
for (let r of e) switch (r.type) {
|
|
9
10
|
case "addIndex": {
|
|
@@ -23,16 +24,16 @@ function d(e) {
|
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
function
|
|
27
|
-
return new Promise((
|
|
28
|
-
e.onsuccess = () =>
|
|
27
|
+
function m(e) {
|
|
28
|
+
return new Promise((t, n) => {
|
|
29
|
+
e.onsuccess = () => t(e.result), e.onerror = () => n(e.error ?? new r("IndexedDB request failed"));
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
function
|
|
32
|
-
let i =
|
|
33
|
-
return new
|
|
32
|
+
function h(e, t, n) {
|
|
33
|
+
let i = n instanceof Error && n.message ? `: ${n.message}` : "";
|
|
34
|
+
return new r(`${t} on "${e}"${i}`, { cause: n });
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function g(e, t, n) {
|
|
36
37
|
return new Promise((r, i) => {
|
|
37
38
|
let a, o;
|
|
38
39
|
Promise.resolve().then(n).then((e) => {
|
|
@@ -44,7 +45,7 @@ function m(e, t, n) {
|
|
|
44
45
|
} catch {}
|
|
45
46
|
});
|
|
46
47
|
let s = (e, n = "transaction failed") => {
|
|
47
|
-
o instanceof Error ? i(o) : i(
|
|
48
|
+
o instanceof Error ? i(o) : i(h(t, n, o ?? e));
|
|
48
49
|
};
|
|
49
50
|
e.oncomplete = () => {
|
|
50
51
|
if (o) {
|
|
@@ -52,61 +53,55 @@ function m(e, t, n) {
|
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
55
|
r(a);
|
|
55
|
-
}, e.onerror = () => i(
|
|
56
|
+
}, e.onerror = () => i(h(t, "transaction error", e.error)), e.onabort = () => s(e.error, "transaction aborted");
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
|
-
async function
|
|
59
|
-
let
|
|
60
|
-
for (let e of
|
|
59
|
+
async function _(e, t, n) {
|
|
60
|
+
let r = await m(e.getAll(n)), i = [];
|
|
61
|
+
for (let e of r) {
|
|
61
62
|
let n = t(e);
|
|
62
|
-
n !== void 0 &&
|
|
63
|
+
n !== void 0 && i.push(n);
|
|
63
64
|
}
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
async function g(e, t, n) {
|
|
67
|
-
let r = await f(e.get(t));
|
|
68
|
-
if (r != null) return n(r);
|
|
69
|
-
}
|
|
70
|
-
async function _(e, t, n) {
|
|
71
|
-
return await g(e, t, n) !== void 0;
|
|
65
|
+
return i;
|
|
72
66
|
}
|
|
73
67
|
async function v(e, t, n) {
|
|
74
|
-
let r = await
|
|
75
|
-
|
|
68
|
+
let r = await m(e.get(t));
|
|
69
|
+
if (r != null) return n(r);
|
|
76
70
|
}
|
|
77
71
|
async function y(e, t, n) {
|
|
78
|
-
|
|
72
|
+
let r = await v(e, t, n) !== void 0;
|
|
73
|
+
return await m(e.delete(t)), r;
|
|
79
74
|
}
|
|
80
|
-
async function b(e, t, n
|
|
81
|
-
await
|
|
75
|
+
async function b(e, t, n) {
|
|
76
|
+
return (await Promise.all(t.map((t) => y(e, t, n)))).filter(Boolean).length;
|
|
82
77
|
}
|
|
83
78
|
function x(e) {
|
|
84
|
-
return new Promise((
|
|
85
|
-
let
|
|
86
|
-
|
|
87
|
-
let e =
|
|
79
|
+
return new Promise((t, n) => {
|
|
80
|
+
let i = 0, a = e.openCursor();
|
|
81
|
+
a.onerror = () => n(a.error ?? new r("IndexedDB cursor failed during prune")), a.onsuccess = () => {
|
|
82
|
+
let e = a.result;
|
|
88
83
|
if (!e) {
|
|
89
|
-
|
|
84
|
+
t(i);
|
|
90
85
|
return;
|
|
91
86
|
}
|
|
92
|
-
let
|
|
93
|
-
(!
|
|
87
|
+
let n = c(e.value);
|
|
88
|
+
(!n || s(n.expiresAt)) && (e.delete(), i += 1), e.continue();
|
|
94
89
|
};
|
|
95
90
|
});
|
|
96
91
|
}
|
|
97
|
-
function S(e,
|
|
92
|
+
function S(e, t) {
|
|
98
93
|
return { [Symbol.asyncIterator]() {
|
|
99
|
-
let
|
|
94
|
+
let n = e.openCursor(), i = { type: "idle" }, a = (e) => {
|
|
100
95
|
if (i.type === "waiting") {
|
|
101
96
|
let { resolve: t } = i;
|
|
102
97
|
i = e.done ? { type: "done" } : { type: "idle" }, t(e);
|
|
103
|
-
} else i = {
|
|
104
|
-
|
|
98
|
+
} else i.type === "buffered" ? i.results.push(e) : i = {
|
|
99
|
+
results: [e],
|
|
105
100
|
type: "buffered"
|
|
106
101
|
};
|
|
107
102
|
};
|
|
108
|
-
return
|
|
109
|
-
let e =
|
|
103
|
+
return n.onerror = () => {
|
|
104
|
+
let e = n.error ?? new r("IndexedDB cursor iteration failed");
|
|
110
105
|
if (i.type === "waiting") {
|
|
111
106
|
let { reject: t } = i;
|
|
112
107
|
i = { type: "done" }, t(e);
|
|
@@ -114,8 +109,9 @@ function S(e, n) {
|
|
|
114
109
|
error: e,
|
|
115
110
|
type: "error"
|
|
116
111
|
};
|
|
117
|
-
},
|
|
118
|
-
|
|
112
|
+
}, n.onsuccess = () => {
|
|
113
|
+
if (i.type === "done") return;
|
|
114
|
+
let e = n.result;
|
|
119
115
|
if (!e) {
|
|
120
116
|
a({
|
|
121
117
|
done: !0,
|
|
@@ -123,10 +119,22 @@ function S(e, n) {
|
|
|
123
119
|
});
|
|
124
120
|
return;
|
|
125
121
|
}
|
|
126
|
-
let
|
|
127
|
-
|
|
122
|
+
let r;
|
|
123
|
+
try {
|
|
124
|
+
r = t(e.value);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
if (i.type === "waiting") {
|
|
127
|
+
let { reject: t } = i;
|
|
128
|
+
i = { type: "done" }, t(e);
|
|
129
|
+
} else i = {
|
|
130
|
+
error: e,
|
|
131
|
+
type: "error"
|
|
132
|
+
};
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
e.continue(), r !== void 0 && a({
|
|
128
136
|
done: !1,
|
|
129
|
-
value:
|
|
137
|
+
value: r
|
|
130
138
|
});
|
|
131
139
|
}, {
|
|
132
140
|
next() {
|
|
@@ -135,8 +143,11 @@ function S(e, n) {
|
|
|
135
143
|
return i = { type: "done" }, Promise.reject(e);
|
|
136
144
|
}
|
|
137
145
|
if (i.type === "buffered") {
|
|
138
|
-
let
|
|
139
|
-
return i = e.done ? { type: "done" } :
|
|
146
|
+
let [e, ...t] = i.results;
|
|
147
|
+
return i = e.done ? { type: "done" } : t.length > 0 ? {
|
|
148
|
+
results: t,
|
|
149
|
+
type: "buffered"
|
|
150
|
+
} : { type: "idle" }, Promise.resolve(e);
|
|
140
151
|
}
|
|
141
152
|
return i.type === "done" ? Promise.resolve({
|
|
142
153
|
done: !0,
|
|
@@ -164,51 +175,24 @@ function S(e, n) {
|
|
|
164
175
|
};
|
|
165
176
|
} };
|
|
166
177
|
}
|
|
167
|
-
function C(
|
|
168
|
-
let
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
count: async (e) => (await f(i(e).getAll())).filter((e) => n(e) !== void 0).length,
|
|
174
|
-
delete: (e, t) => v(i(e), a(t), n),
|
|
175
|
-
deleteMany: (e, t) => y(i(e), t.map(a), n),
|
|
176
|
-
get: (e, t) => g(i(e), a(t), n),
|
|
177
|
-
getAll: (e) => h(i(e), n),
|
|
178
|
-
getMany: (e, t) => Promise.all(t.map((t) => g(i(e), a(t), n))),
|
|
179
|
-
has: (e, t) => _(i(e), a(t), n),
|
|
180
|
-
pruneExpiredInTable: (e) => x(i(e)),
|
|
181
|
-
put(t, n, s) {
|
|
182
|
-
return b(i(t), a(o(e, t, n)), n, r, s);
|
|
183
|
-
},
|
|
184
|
-
putAll(t, n, s) {
|
|
185
|
-
return Promise.all(n.map((n) => b(i(t), a(o(e, t, n)), n, r, s))).then(() => void 0);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function w(d) {
|
|
190
|
-
let { migrate: p, name: w, schema: T, validators: E, version: D = 1 } = d;
|
|
191
|
-
if (!Number.isInteger(D) || D < 1) throw new t(`createIndexedDB: version must be a positive integer, got ${String(D)}`);
|
|
192
|
-
let O = (e) => {
|
|
193
|
-
let t = i(e);
|
|
194
|
-
return !t || r(t.expiresAt) ? void 0 : t.value;
|
|
195
|
-
}, k = (e, t) => t === void 0 ? { value: e } : {
|
|
196
|
-
expiresAt: Date.now() + t,
|
|
197
|
-
value: e
|
|
198
|
-
}, A = typeof BroadcastChannel < "u" ? new BroadcastChannel(`vault:${w}`) : void 0, j = null, M = null, N = !1, P = (e, t) => {
|
|
199
|
-
for (let [n, r] of Object.entries(T)) {
|
|
178
|
+
function C(p) {
|
|
179
|
+
let { migrate: h, name: C, schema: w, codecs: T, version: E = 1 } = p;
|
|
180
|
+
if (!T) throw new r("createIndexedDB: codecs are required for durable persistence");
|
|
181
|
+
if (!Number.isInteger(E) || E < 1) throw new r(`createIndexedDB: version must be a positive integer, got ${String(E)}`);
|
|
182
|
+
let D = typeof BroadcastChannel < "u" ? new BroadcastChannel(`vault:${C}`) : void 0, O = null, k = null, A = !1, j = (e, t) => {
|
|
183
|
+
for (let [n, r] of Object.entries(w)) {
|
|
200
184
|
let i;
|
|
201
185
|
i = e.objectStoreNames.contains(n) ? t.objectStore(n) : e.createObjectStore(n);
|
|
202
186
|
let a = r.indexes ?? [];
|
|
203
187
|
for (let e of a) i.indexNames.contains(e) || i.createIndex(e, `value.${e}`);
|
|
204
188
|
}
|
|
205
|
-
},
|
|
206
|
-
let
|
|
207
|
-
|
|
208
|
-
let
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
db:
|
|
189
|
+
}, M = async () => (k ||= new Promise((e, t) => {
|
|
190
|
+
let n = indexedDB.open(C, E);
|
|
191
|
+
n.onupgradeneeded = (e) => {
|
|
192
|
+
let r = n.result, a = n.transaction;
|
|
193
|
+
if (h) try {
|
|
194
|
+
h({
|
|
195
|
+
db: r,
|
|
212
196
|
newVersion: e.newVersion ?? null,
|
|
213
197
|
oldVersion: e.oldVersion,
|
|
214
198
|
tx: a
|
|
@@ -217,93 +201,66 @@ function w(d) {
|
|
|
217
201
|
try {
|
|
218
202
|
a.abort();
|
|
219
203
|
} catch {}
|
|
220
|
-
|
|
204
|
+
t(new i(`migration failed for "${C}"`, { cause: e }));
|
|
221
205
|
return;
|
|
222
206
|
}
|
|
223
|
-
|
|
224
|
-
},
|
|
225
|
-
if (
|
|
226
|
-
|
|
207
|
+
j(r, a);
|
|
208
|
+
}, n.onsuccess = () => {
|
|
209
|
+
if (A) {
|
|
210
|
+
n.result.close(), e();
|
|
227
211
|
return;
|
|
228
212
|
}
|
|
229
|
-
let t =
|
|
213
|
+
let t = n.result;
|
|
230
214
|
t.onversionchange = () => {
|
|
231
|
-
t.close(),
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
|
|
215
|
+
t.close(), O = null, k = null;
|
|
216
|
+
}, O = t, e();
|
|
217
|
+
}, n.onerror = () => {
|
|
218
|
+
k = null, t(new r(`failed to open "${C}"`, { cause: n.error }));
|
|
219
|
+
};
|
|
220
|
+
}), k), N = async (e, t, r) => {
|
|
221
|
+
if (A || (O || await M(), !O)) throw new n(`"${C}" is disposed`);
|
|
222
|
+
let i = String(e), a = O.transaction(i, t);
|
|
223
|
+
return g(a, `${C}/${i}`, () => r(a.objectStore(i)));
|
|
224
|
+
}, P = async () => {
|
|
225
|
+
if (A || (O || await M(), !O)) throw new n(`"${C}" is disposed`);
|
|
226
|
+
return O;
|
|
227
|
+
}, F = (e) => {
|
|
228
|
+
D?.postMessage({ table: String(e) });
|
|
229
|
+
}, I = (t, n) => {
|
|
230
|
+
let i = c(n);
|
|
231
|
+
if (i && !s(i.expiresAt)) try {
|
|
232
|
+
return e(T[t], i.value);
|
|
233
|
+
} catch (e) {
|
|
234
|
+
throw new r(`validation failed for table "${String(t)}"`, { cause: e });
|
|
235
|
+
}
|
|
236
|
+
}, L = (e, n, i) => {
|
|
237
|
+
let a = n, o = t(T[e], a);
|
|
238
|
+
for (let t of w[e].indexes ?? []) {
|
|
239
|
+
let n = a[t];
|
|
240
|
+
if (n !== void 0 && (typeof o != "object" || !o || !Object.hasOwn(o, t) || !Object.is(o[t], n))) throw new r(`codec output for table "${String(e)}" must preserve indexed field "${t}"`);
|
|
241
|
+
}
|
|
242
|
+
return i === void 0 ? { value: o } : {
|
|
243
|
+
expiresAt: Date.now() + i,
|
|
244
|
+
value: o
|
|
235
245
|
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}, L = async () => {
|
|
241
|
-
if (N || (j || await F(), !j)) throw new e(`"${w}" is disposed`);
|
|
242
|
-
return j;
|
|
243
|
-
}, R = (e) => {
|
|
244
|
-
A?.postMessage({ table: String(e) });
|
|
245
|
-
}, z = {
|
|
246
|
-
clear: (e) => I(e, "readwrite", (e) => f(e.clear()).then(() => void 0)),
|
|
247
|
-
count: (e) => I(e, "readonly", async (e) => (await f(e.getAll())).filter((e) => O(e) !== void 0).length),
|
|
248
|
-
delete: (e, t) => I(e, "readwrite", (e) => v(e, a(t), O)),
|
|
249
|
-
deleteMany: (e, t) => t.length === 0 ? Promise.resolve(0) : I(e, "readwrite", (e) => y(e, t.map(a), O)),
|
|
246
|
+
}, R = {
|
|
247
|
+
clear: (e) => N(e, "readwrite", (e) => m(e.clear()).then(() => void 0)),
|
|
248
|
+
delete: (e, t) => N(e, "readwrite", (n) => y(n, a(t), (t) => I(e, t))),
|
|
249
|
+
deleteMany: (e, t) => N(e, "readwrite", (n) => b(n, t.map(a), (t) => I(e, t))),
|
|
250
250
|
async dispose() {
|
|
251
|
-
|
|
251
|
+
A = !0, D?.close(), k && await k.catch(() => {}), O?.close(), O = null, k = null;
|
|
252
252
|
},
|
|
253
|
-
get: (e, t) =>
|
|
254
|
-
getAll: (e) =>
|
|
255
|
-
|
|
256
|
-
let
|
|
257
|
-
return
|
|
253
|
+
get: (e, t) => N(e, "readonly", (n) => v(n, a(t), (t) => I(e, t))),
|
|
254
|
+
getAll: (e) => N(e, "readonly", (t) => _(t, (t) => I(e, t))),
|
|
255
|
+
getMany: (e, t) => N(e, "readonly", (n) => {
|
|
256
|
+
let r = (t) => I(e, t);
|
|
257
|
+
return Promise.all(t.map((e) => v(n, a(e), r)));
|
|
258
258
|
}),
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
},
|
|
265
|
-
pruneExpiredInTable: (e) => I(e, "readwrite", (e) => x(e)),
|
|
266
|
-
put(e, t, n) {
|
|
267
|
-
let r = a(o(T, e, t));
|
|
268
|
-
return I(e, "readwrite", (e) => b(e, r, t, k, n));
|
|
269
|
-
},
|
|
270
|
-
putAll(e, t, n) {
|
|
271
|
-
return I(e, "readwrite", (r) => Promise.all(t.map((t) => b(r, a(o(T, e, t)), t, k, n))).then(() => void 0));
|
|
272
|
-
}
|
|
273
|
-
}, B = async (e, t, n, r) => {
|
|
274
|
-
s(e);
|
|
275
|
-
let i = (await L()).transaction([...e], "readwrite"), a = /* @__PURE__ */ new Set(), o = C(T, i, O, k), c = new Set(e), u = l(T, o, (e) => a.add(e), r, c), d = await m(i, w, () => t(u));
|
|
276
|
-
for (let e of a) n(e);
|
|
277
|
-
return d;
|
|
278
|
-
}, V, H = c(T, z, {
|
|
279
|
-
onCrossTabMessage(e) {
|
|
280
|
-
if (A) return A.onmessage = (t) => {
|
|
281
|
-
let n = t.data?.table;
|
|
282
|
-
!n || !Object.hasOwn(T, n) || e(n);
|
|
283
|
-
}, () => {
|
|
284
|
-
A.onmessage = null;
|
|
285
|
-
};
|
|
286
|
-
},
|
|
287
|
-
onMutation: R,
|
|
288
|
-
onTransactions: (e) => {
|
|
289
|
-
V = (t, n) => B(t, n, e.notifyMutation, e.validate);
|
|
290
|
-
},
|
|
291
|
-
schema: T,
|
|
292
|
-
validators: E
|
|
293
|
-
}), U = {
|
|
294
|
-
...H,
|
|
295
|
-
get disposalSignal() {
|
|
296
|
-
return H.disposalSignal;
|
|
297
|
-
},
|
|
298
|
-
get disposed() {
|
|
299
|
-
return H.disposed;
|
|
300
|
-
},
|
|
301
|
-
iterate(t) {
|
|
302
|
-
if (N) throw new e(`"${w}" is disposed`);
|
|
303
|
-
let n = async () => {
|
|
304
|
-
if (j || await F(), !j || N) throw new e(`"${w}" is disposed`);
|
|
305
|
-
return S(j.transaction(String(t), "readonly").objectStore(String(t)), O);
|
|
306
|
-
}, r, i = () => n().then((e) => (r = e[Symbol.asyncIterator](), r));
|
|
259
|
+
iterate: (e) => {
|
|
260
|
+
let t = async () => {
|
|
261
|
+
if (A || (O || await M(), !O || A)) throw new n(`"${C}" is disposed`);
|
|
262
|
+
return S(O.transaction(String(e), "readonly").objectStore(String(e)), (t) => I(e, t));
|
|
263
|
+
}, r, i = () => t().then((e) => (r = e[Symbol.asyncIterator](), r));
|
|
307
264
|
return { [Symbol.asyncIterator]() {
|
|
308
265
|
return {
|
|
309
266
|
next() {
|
|
@@ -323,12 +280,87 @@ function w(d) {
|
|
|
323
280
|
}
|
|
324
281
|
};
|
|
325
282
|
} };
|
|
283
|
+
},
|
|
284
|
+
async pruneAllExpired() {
|
|
285
|
+
let e = await P(), t = Object.keys(w), n = e.transaction(t, "readwrite"), r = await g(n, `${C}/pruneAll`, () => Promise.all(t.map(async (e) => [e, await x(n.objectStore(e))])));
|
|
286
|
+
return Object.fromEntries(r);
|
|
287
|
+
},
|
|
288
|
+
pruneExpiredInTable: (e) => N(e, "readwrite", (e) => x(e)),
|
|
289
|
+
put(e, t, n) {
|
|
290
|
+
let r = a(o(w, e, t)), i = L(e, t, n);
|
|
291
|
+
return N(e, "readwrite", (e) => m(e.put(i, r)).then(() => void 0));
|
|
292
|
+
},
|
|
293
|
+
putAll(e, t, n) {
|
|
294
|
+
let r = t.map((t) => {
|
|
295
|
+
let r = a(o(w, e, t));
|
|
296
|
+
return {
|
|
297
|
+
encoded: L(e, t, n),
|
|
298
|
+
key: r
|
|
299
|
+
};
|
|
300
|
+
});
|
|
301
|
+
return N(e, "readwrite", (e) => Promise.all(r.map(({ encoded: t, key: n }) => m(e.put(t, n)))).then(() => void 0));
|
|
326
302
|
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
303
|
+
}, z = async (e, t, n, r) => {
|
|
304
|
+
l(e);
|
|
305
|
+
let i = (await P()).transaction([...e], "readwrite"), s = /* @__PURE__ */ new Set(), c = (e) => i.objectStore(e), u = {
|
|
306
|
+
clear: async (e) => {
|
|
307
|
+
await m(c(e).clear());
|
|
308
|
+
},
|
|
309
|
+
delete: (e, t) => y(c(e), a(t), (t) => I(e, t)),
|
|
310
|
+
deleteMany: (e, t) => b(c(e), t.map(a), (t) => I(e, t)),
|
|
311
|
+
get: (e, t) => v(c(e), a(t), (t) => I(e, t)),
|
|
312
|
+
getAll: (e) => _(c(e), (t) => I(e, t)),
|
|
313
|
+
getMany: (e, t) => {
|
|
314
|
+
let n = (t) => I(e, t), r = c(e);
|
|
315
|
+
return Promise.all(t.map((e) => v(r, a(e), n)));
|
|
316
|
+
},
|
|
317
|
+
iterate(e) {
|
|
318
|
+
return S(c(e), (t) => I(e, t));
|
|
319
|
+
},
|
|
320
|
+
pruneExpiredInTable: (e) => x(c(e)),
|
|
321
|
+
put(e, t, n) {
|
|
322
|
+
let r = a(o(w, e, t)), i = L(e, t, n);
|
|
323
|
+
return m(c(e).put(i, r)).then(() => void 0);
|
|
324
|
+
},
|
|
325
|
+
putAll(e, t, n) {
|
|
326
|
+
return Promise.all(t.map((t) => {
|
|
327
|
+
let r = a(o(w, e, t)), i = L(e, t, n);
|
|
328
|
+
return m(c(e).put(i, r));
|
|
329
|
+
})).then(() => void 0);
|
|
330
|
+
}
|
|
331
|
+
}, f = new Set(e), p = !0, h = d(w, u, (e) => s.add(e), r, f, () => p);
|
|
332
|
+
try {
|
|
333
|
+
let e = await g(i, C, () => t(h));
|
|
334
|
+
for (let e of s) n(e);
|
|
335
|
+
return e;
|
|
336
|
+
} finally {
|
|
337
|
+
p = !1;
|
|
338
|
+
}
|
|
339
|
+
}, B, V = u(w, R, {
|
|
340
|
+
codecs: T,
|
|
341
|
+
onCrossTabMessage(e) {
|
|
342
|
+
if (D) return D.onmessage = (t) => {
|
|
343
|
+
let n = t.data?.table;
|
|
344
|
+
n && Object.hasOwn(w, n) && e(n);
|
|
345
|
+
}, () => {
|
|
346
|
+
D.onmessage = null;
|
|
347
|
+
};
|
|
348
|
+
},
|
|
349
|
+
onMutation: F,
|
|
350
|
+
onTransactions: (e) => {
|
|
351
|
+
B = (t, n) => z(t, n, e.notifyMutation, e.validate);
|
|
352
|
+
},
|
|
353
|
+
schema: w
|
|
354
|
+
});
|
|
355
|
+
if (!B) throw new r("IndexedDB transaction capability was not initialized");
|
|
356
|
+
return Object.assign(f(V, B, w), { getAllByIndex(e, t, n) {
|
|
357
|
+
return N(e, "readonly", (i) => {
|
|
358
|
+
if (!i.indexNames.contains(t)) throw new r(`Table "${e}" has no index "${t}"`);
|
|
359
|
+
return _(i.index(t), (t) => I(e, t), n);
|
|
360
|
+
});
|
|
361
|
+
} });
|
|
330
362
|
}
|
|
331
363
|
//#endregion
|
|
332
|
-
export {
|
|
364
|
+
export { C as createIndexedDB, p as defineMigration };
|
|
333
365
|
|
|
334
366
|
//# sourceMappingURL=indexeddb.js.map
|