@asaidimu/utils-persistence 1.0.0 → 2.0.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/README.md +70 -64
- package/package.json +3 -3
- package/LICENSE.md +0 -21
- package/index.d.mts +0 -82
- package/index.d.ts +0 -82
- package/index.js +0 -2290
- package/index.mjs +0 -2282
package/index.mjs
DELETED
@@ -1,2282 +0,0 @@
|
|
1
|
-
var __create = Object.create;
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
9
|
-
}) : x)(function(x) {
|
10
|
-
if (typeof require !== "undefined")
|
11
|
-
return require.apply(this, arguments);
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
13
|
-
});
|
14
|
-
var __commonJS = (cb, mod) => function __require2() {
|
15
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
16
|
-
};
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
19
|
-
for (let key of __getOwnPropNames(from))
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
21
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
22
|
-
}
|
23
|
-
return to;
|
24
|
-
};
|
25
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
26
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
27
|
-
// file that has been converted to a CommonJS file using a Babel-
|
28
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
29
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
30
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
31
|
-
mod
|
32
|
-
));
|
33
|
-
|
34
|
-
// node_modules/@asaidimu/events/index.js
|
35
|
-
var require_events = __commonJS({
|
36
|
-
"node_modules/@asaidimu/events/index.js"(exports, module) {
|
37
|
-
"use strict";
|
38
|
-
var __defProp2 = Object.defineProperty;
|
39
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
40
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
41
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
42
|
-
var __export = (target, all) => {
|
43
|
-
for (var name in all)
|
44
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
45
|
-
};
|
46
|
-
var __copyProps2 = (to, from, except, desc) => {
|
47
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
48
|
-
for (let key of __getOwnPropNames2(from))
|
49
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
50
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
51
|
-
}
|
52
|
-
return to;
|
53
|
-
};
|
54
|
-
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
55
|
-
var events_exports = {};
|
56
|
-
__export(events_exports, {
|
57
|
-
createEventBus: () => createEventBus3
|
58
|
-
});
|
59
|
-
module.exports = __toCommonJS(events_exports);
|
60
|
-
var createEventBus3 = (options = {
|
61
|
-
async: false,
|
62
|
-
batchSize: 1e3,
|
63
|
-
batchDelay: 16,
|
64
|
-
errorHandler: (error) => console.error("EventBus Error:", error),
|
65
|
-
crossTab: false,
|
66
|
-
channelName: "event-bus-channel"
|
67
|
-
// Unique channel name
|
68
|
-
}) => {
|
69
|
-
const subscribers = /* @__PURE__ */ new Map();
|
70
|
-
let eventQueue = [];
|
71
|
-
let totalEvents = 0;
|
72
|
-
let totalDuration = 0;
|
73
|
-
const eventCounts = /* @__PURE__ */ new Map();
|
74
|
-
const cachedArrays = /* @__PURE__ */ new Map();
|
75
|
-
let broadcastChannel = null;
|
76
|
-
if (options.crossTab && typeof BroadcastChannel !== "undefined") {
|
77
|
-
broadcastChannel = new BroadcastChannel(options.channelName);
|
78
|
-
} else if (options.crossTab) {
|
79
|
-
console.warn("BroadcastChannel is not supported in this browser. Cross-tab notifications are disabled.");
|
80
|
-
}
|
81
|
-
const updateMetrics = (eventName, duration) => {
|
82
|
-
totalEvents++;
|
83
|
-
totalDuration += duration;
|
84
|
-
eventCounts.set(
|
85
|
-
eventName,
|
86
|
-
(eventCounts.get(eventName) || 0) + 1
|
87
|
-
);
|
88
|
-
};
|
89
|
-
const processBatch = () => {
|
90
|
-
const batchToProcess = eventQueue;
|
91
|
-
eventQueue = [];
|
92
|
-
batchToProcess.forEach(({ name, payload }) => {
|
93
|
-
const start = performance.now();
|
94
|
-
try {
|
95
|
-
const callbacks = cachedArrays.get(name) || [];
|
96
|
-
callbacks.forEach((callback) => callback(payload));
|
97
|
-
} catch (error) {
|
98
|
-
options.errorHandler({
|
99
|
-
...error,
|
100
|
-
eventName: name,
|
101
|
-
payload
|
102
|
-
});
|
103
|
-
}
|
104
|
-
updateMetrics(name, performance.now() - start);
|
105
|
-
});
|
106
|
-
};
|
107
|
-
const debouncedProcess = /* @__PURE__ */ (() => {
|
108
|
-
let timeoutId;
|
109
|
-
return () => {
|
110
|
-
clearTimeout(timeoutId);
|
111
|
-
timeoutId = setTimeout(processBatch, options.batchDelay);
|
112
|
-
};
|
113
|
-
})();
|
114
|
-
const updateCachedArray = (eventName) => {
|
115
|
-
const callbackSet = subscribers.get(eventName);
|
116
|
-
if (callbackSet) {
|
117
|
-
cachedArrays.set(eventName, Array.from(callbackSet));
|
118
|
-
} else {
|
119
|
-
cachedArrays.delete(eventName);
|
120
|
-
}
|
121
|
-
};
|
122
|
-
if (broadcastChannel) {
|
123
|
-
broadcastChannel.onmessage = (event) => {
|
124
|
-
const { name, payload } = event.data;
|
125
|
-
const callbacks = cachedArrays.get(name) || [];
|
126
|
-
callbacks.forEach((callback) => callback(payload));
|
127
|
-
};
|
128
|
-
}
|
129
|
-
return {
|
130
|
-
subscribe: (eventName, callback) => {
|
131
|
-
if (!subscribers.has(eventName)) {
|
132
|
-
subscribers.set(eventName, /* @__PURE__ */ new Set());
|
133
|
-
}
|
134
|
-
const callbacks = subscribers.get(eventName);
|
135
|
-
callbacks.add(callback);
|
136
|
-
updateCachedArray(eventName);
|
137
|
-
return () => {
|
138
|
-
callbacks.delete(callback);
|
139
|
-
if (callbacks.size === 0) {
|
140
|
-
subscribers.delete(eventName);
|
141
|
-
cachedArrays.delete(eventName);
|
142
|
-
} else {
|
143
|
-
updateCachedArray(eventName);
|
144
|
-
}
|
145
|
-
};
|
146
|
-
},
|
147
|
-
emit: ({ name, payload }) => {
|
148
|
-
if (options.async) {
|
149
|
-
eventQueue.push({ name, payload });
|
150
|
-
if (eventQueue.length >= options.batchSize) {
|
151
|
-
processBatch();
|
152
|
-
} else {
|
153
|
-
debouncedProcess();
|
154
|
-
}
|
155
|
-
if (broadcastChannel) {
|
156
|
-
broadcastChannel.postMessage({ name, payload });
|
157
|
-
}
|
158
|
-
return;
|
159
|
-
}
|
160
|
-
const start = performance.now();
|
161
|
-
try {
|
162
|
-
const callbacks = cachedArrays.get(name) || [];
|
163
|
-
callbacks.forEach((callback) => callback(payload));
|
164
|
-
if (broadcastChannel) {
|
165
|
-
broadcastChannel.postMessage({ name, payload });
|
166
|
-
}
|
167
|
-
} catch (error) {
|
168
|
-
options.errorHandler({
|
169
|
-
...error,
|
170
|
-
eventName: name,
|
171
|
-
payload
|
172
|
-
});
|
173
|
-
}
|
174
|
-
updateMetrics(name, performance.now() - start);
|
175
|
-
},
|
176
|
-
getMetrics: () => ({
|
177
|
-
totalEvents,
|
178
|
-
activeSubscriptions: Array.from(subscribers.values()).reduce((acc, set) => acc + set.size, 0),
|
179
|
-
eventCounts,
|
180
|
-
averageEmitDuration: totalEvents > 0 ? totalDuration / totalEvents : 0
|
181
|
-
}),
|
182
|
-
clear: () => {
|
183
|
-
subscribers.clear();
|
184
|
-
cachedArrays.clear();
|
185
|
-
eventQueue = [];
|
186
|
-
totalEvents = 0;
|
187
|
-
totalDuration = 0;
|
188
|
-
eventCounts.clear();
|
189
|
-
if (broadcastChannel) {
|
190
|
-
broadcastChannel.close();
|
191
|
-
broadcastChannel = null;
|
192
|
-
}
|
193
|
-
}
|
194
|
-
};
|
195
|
-
};
|
196
|
-
}
|
197
|
-
});
|
198
|
-
|
199
|
-
// node_modules/@asaidimu/query/index.js
|
200
|
-
var require_query = __commonJS({
|
201
|
-
"node_modules/@asaidimu/query/index.js"(exports, module) {
|
202
|
-
"use strict";
|
203
|
-
var m = Object.defineProperty;
|
204
|
-
var I = Object.getOwnPropertyDescriptor;
|
205
|
-
var E = Object.getOwnPropertyNames;
|
206
|
-
var b = Object.prototype.hasOwnProperty;
|
207
|
-
var O = (e, r) => {
|
208
|
-
for (var n in r)
|
209
|
-
m(e, n, { get: r[n], enumerable: true });
|
210
|
-
};
|
211
|
-
var S = (e, r, n, s) => {
|
212
|
-
if (r && typeof r == "object" || typeof r == "function")
|
213
|
-
for (let u of E(r))
|
214
|
-
!b.call(e, u) && u !== n && m(e, u, { get: () => r[u], enumerable: !(s = I(r, u)) || s.enumerable });
|
215
|
-
return e;
|
216
|
-
};
|
217
|
-
var J = (e) => S(m({}, "__esModule", { value: true }), e);
|
218
|
-
var ne = {};
|
219
|
-
O(ne, { QueryBuilder: () => w, createJoiner: () => P, createMatcher: () => C, createPaginator: () => k, createProjector: () => Q, createSorter: () => j });
|
220
|
-
module.exports = J(ne);
|
221
|
-
var w = class {
|
222
|
-
query;
|
223
|
-
constructor() {
|
224
|
-
this.query = {};
|
225
|
-
}
|
226
|
-
where(r) {
|
227
|
-
return this.query.filters = r, this;
|
228
|
-
}
|
229
|
-
orderBy(r, n) {
|
230
|
-
return this.query.sort || (this.query.sort = []), this.query.sort.push({ field: r, direction: n }), this;
|
231
|
-
}
|
232
|
-
offset(r, n) {
|
233
|
-
return this.query.pagination = { type: "offset", offset: r, limit: n }, this;
|
234
|
-
}
|
235
|
-
cursor(r, n, s) {
|
236
|
-
return this.query.pagination = { type: "cursor", cursor: r, limit: n, direction: s }, this;
|
237
|
-
}
|
238
|
-
include(r) {
|
239
|
-
return this.query.projection || (this.query.projection = {}), this.query.projection.include = r, this;
|
240
|
-
}
|
241
|
-
exclude(r) {
|
242
|
-
return this.query.projection || (this.query.projection = {}), this.query.projection.exclude = r, this;
|
243
|
-
}
|
244
|
-
computed(r, n) {
|
245
|
-
return this.query.projection || (this.query.projection = {}), this.query.projection.computed || (this.query.projection.computed = []), this.query.projection.computed.push({ type: "computed", expression: r, alias: n }), this;
|
246
|
-
}
|
247
|
-
case(r, n, s) {
|
248
|
-
return this.query.projection || (this.query.projection = {}), this.query.projection.computed || (this.query.projection.computed = []), this.query.projection.computed.push({ type: "case", conditions: r, else: n, alias: s }), this;
|
249
|
-
}
|
250
|
-
join(r, n, s) {
|
251
|
-
return this.query.joins || (this.query.joins = []), this.query.joins.push({ relation: r, alias: s, query: n }), this;
|
252
|
-
}
|
253
|
-
aggregate(r, n) {
|
254
|
-
return this.query.aggregations = { groupBy: r, metrics: n }, this;
|
255
|
-
}
|
256
|
-
window(r) {
|
257
|
-
return this.query.window || (this.query.window = []), this.query.window.push(r), this;
|
258
|
-
}
|
259
|
-
hint(r) {
|
260
|
-
return this.query.hints || (this.query.hints = []), this.query.hints.push(r), this;
|
261
|
-
}
|
262
|
-
build() {
|
263
|
-
return this.query;
|
264
|
-
}
|
265
|
-
};
|
266
|
-
function g(e) {
|
267
|
-
function r(i, t) {
|
268
|
-
return D(t) ? i[t.field] : V(t) ? t.value : M(t) ? u(t, i) : L(t) ? u(t.expression, i) : G(t) ? p(i, t) : t;
|
269
|
-
}
|
270
|
-
let n = /* @__PURE__ */ new Map([["and", (i, t) => t.every((a) => o(i, a))], ["or", (i, t) => t.some((a) => o(i, a))], ["not", (i, t) => !t.every((a) => o(i, a))], ["nor", (i, t) => !t.some((a) => o(i, a))], ["xor", (i, t) => t.filter((a) => o(i, a)).length === 1]]);
|
271
|
-
function s(i, t) {
|
272
|
-
let { operator: a, conditions: c } = t, y = n.get(a);
|
273
|
-
if (y)
|
274
|
-
return y(i, c);
|
275
|
-
throw new Error(`Unsupported logical operator: ${a}`);
|
276
|
-
}
|
277
|
-
function u(i, t) {
|
278
|
-
let a = i.arguments.map((c) => r(t, c));
|
279
|
-
if (e[i.function])
|
280
|
-
return e[i.function](...a);
|
281
|
-
throw new Error(`Function ${i.function} not found!`);
|
282
|
-
}
|
283
|
-
function p(i, t) {
|
284
|
-
for (let a of t.conditions)
|
285
|
-
if (o(i, a.when))
|
286
|
-
return a.then;
|
287
|
-
return t.else;
|
288
|
-
}
|
289
|
-
function o(i, t) {
|
290
|
-
if (B(t))
|
291
|
-
return s(i, t);
|
292
|
-
if (!t || !t.field)
|
293
|
-
return false;
|
294
|
-
let { field: a, operator: c, value: y } = t, d = i[a], v = r(i, y), A = /* @__PURE__ */ new Map([["eq", (l, f) => l === f], ["neq", (l, f) => l !== f], ["lt", (l, f) => l < f], ["lte", (l, f) => l <= f], ["gt", (l, f) => l > f], ["gte", (l, f) => l >= f], ["in", (l, f) => Array.isArray(f) && f.includes(l)], ["nin", (l, f) => Array.isArray(f) && !f.includes(l)], ["contains", (l, f) => typeof l == "string" ? l.includes(f) : Array.isArray(l) ? l.includes(y) : false], ["ncontains", (l, f) => typeof l == "string" && !l.includes(f)], ["startswith", (l, f) => typeof l == "string" && l.startsWith(f)], ["endswith", (l, f) => typeof l == "string" && l.endsWith(f)], ["exists", (l) => l != null], ["nexists", (l) => l == null]]), x = e[c] || A.get(c);
|
295
|
-
if (x)
|
296
|
-
return x(d, v);
|
297
|
-
throw new Error(`Unsupported comparison operator: ${c}`);
|
298
|
-
}
|
299
|
-
return { resolve: r, evaluate: o };
|
300
|
-
}
|
301
|
-
function D(e) {
|
302
|
-
return e?.type === "field";
|
303
|
-
}
|
304
|
-
function V(e) {
|
305
|
-
return e?.type === "value";
|
306
|
-
}
|
307
|
-
function L(e) {
|
308
|
-
return e?.type === "computed";
|
309
|
-
}
|
310
|
-
function G(e) {
|
311
|
-
return e?.type === "case";
|
312
|
-
}
|
313
|
-
function M(e) {
|
314
|
-
return e?.type === "function";
|
315
|
-
}
|
316
|
-
function B(e) {
|
317
|
-
return e ? e.conditions !== void 0 : false;
|
318
|
-
}
|
319
|
-
function C(e) {
|
320
|
-
let { evaluate: r } = g(e), n = /* @__PURE__ */ new WeakMap();
|
321
|
-
function s(u, p) {
|
322
|
-
let o = n.get(u);
|
323
|
-
o || (o = /* @__PURE__ */ new Map(), n.set(u, o));
|
324
|
-
let i = JSON.stringify(p);
|
325
|
-
if (o.has(i))
|
326
|
-
return o.get(i);
|
327
|
-
let t = r(u, p);
|
328
|
-
return o.set(i, t), t;
|
329
|
-
}
|
330
|
-
return { matcher: s, match: s };
|
331
|
-
}
|
332
|
-
var T = class extends Error {
|
333
|
-
constructor(n, s) {
|
334
|
-
super(n);
|
335
|
-
this.code = s;
|
336
|
-
this.name = "JoinError";
|
337
|
-
}
|
338
|
-
};
|
339
|
-
var R = (e) => e && "field" in e && "operator" in e && "value" in e;
|
340
|
-
var N = (e) => "operator" in e && "conditions" in e;
|
341
|
-
var $ = (e) => typeof e == "object" && e !== null && "type" in e && e.type === "field";
|
342
|
-
var _ = (e, r) => {
|
343
|
-
if (!e.relation)
|
344
|
-
throw new T("Join configuration must specify a relation", "INVALID_CONFIG");
|
345
|
-
if (!r[e.relation])
|
346
|
-
throw new T(`Collection "${e.relation}" not found in database`, "COLLECTION_NOT_FOUND");
|
347
|
-
if (e.alias && typeof e.alias != "string")
|
348
|
-
throw new T("Join alias must be a string", "INVALID_ALIAS");
|
349
|
-
};
|
350
|
-
var U = (e, r) => r.split(".").reduce((s, u) => s?.[u], e);
|
351
|
-
var q = (e, r) => {
|
352
|
-
if (e) {
|
353
|
-
if (R(e) && e) {
|
354
|
-
let n = $(e.value) ? U(r, e.value.field) : e.value;
|
355
|
-
return { ...e, value: n };
|
356
|
-
}
|
357
|
-
if (N(e)) {
|
358
|
-
let n = { ...e };
|
359
|
-
return e.conditions && (n.conditions = e.conditions.map((s) => q(s, r))), n;
|
360
|
-
}
|
361
|
-
return e;
|
362
|
-
}
|
363
|
-
};
|
364
|
-
var K = (e, r) => {
|
365
|
-
if (!e)
|
366
|
-
return {};
|
367
|
-
let n = q(e.filters, r);
|
368
|
-
return { ...e, filters: n };
|
369
|
-
};
|
370
|
-
var W = (e, r, n) => {
|
371
|
-
let s = n.alias || n.relation;
|
372
|
-
return [{ ...e, [s]: r }];
|
373
|
-
};
|
374
|
-
var H = (e, r) => {
|
375
|
-
let n = /* @__PURE__ */ new Map();
|
376
|
-
return e.forEach((s) => {
|
377
|
-
let u = s[r];
|
378
|
-
n.has(u) || n.set(u, []), n.get(u).push(s);
|
379
|
-
}), n;
|
380
|
-
};
|
381
|
-
var X = async (e, r, n, s) => {
|
382
|
-
try {
|
383
|
-
if (_(n, e), !Array.isArray(r))
|
384
|
-
throw new T("Source data must be an array", "INVALID_SOURCE_DATA");
|
385
|
-
let u = e[n.relation], p;
|
386
|
-
return n.query?.filters && R(n.query.filters) && (p = H(u, n.query.filters.field)), (await Promise.all(r.map(async (i) => {
|
387
|
-
let t = K(n.query, i), a;
|
388
|
-
t.filters && R(t.filters) && p?.has(t.filters.value) ? a = p.get(t.filters.value) || [] : a = u.filter((y) => s.matcher(y, t.filters));
|
389
|
-
let c = await [(y) => t.sort ? s.sorter(y, t.sort) : y, (y) => t.projection ? s.projector(y, t.projection) : y, async (y) => t.pagination ? await s.paginator(y, t.pagination) : y].reduce(async (y, d) => d(await y), Promise.resolve(a));
|
390
|
-
return W(i, c, n);
|
391
|
-
}))).flat();
|
392
|
-
} catch (u) {
|
393
|
-
throw u instanceof T ? u : new T(`Join operation failed: ${u.message}`, "JOIN_EXECUTION_ERROR");
|
394
|
-
}
|
395
|
-
};
|
396
|
-
var z = async (e, r, n, s) => n.reduce(async (u, p) => X(e, await u, p, s), Promise.resolve(r));
|
397
|
-
function P() {
|
398
|
-
return { join: z };
|
399
|
-
}
|
400
|
-
var h = class extends Error {
|
401
|
-
constructor(r, n) {
|
402
|
-
super(`Unsupported comparison between ${typeof r} and ${typeof n}`), this.name = "UnsupportedComparisonError";
|
403
|
-
}
|
404
|
-
};
|
405
|
-
var F = class extends Error {
|
406
|
-
constructor(r) {
|
407
|
-
super(`Unsupported sort direction: ${r}`), this.name = "InvalidSortDirectionError";
|
408
|
-
}
|
409
|
-
};
|
410
|
-
function Y(e, r, n) {
|
411
|
-
if (e === r)
|
412
|
-
return 0;
|
413
|
-
if (e == null || r == null)
|
414
|
-
return e == null ? n === "asc" ? -1 : 1 : n === "asc" ? 1 : -1;
|
415
|
-
if (typeof e == "string" && typeof r == "string")
|
416
|
-
return n === "asc" ? e.localeCompare(r) : r.localeCompare(e);
|
417
|
-
if (typeof e == "number" && typeof r == "number")
|
418
|
-
return n === "asc" ? e - r : r - e;
|
419
|
-
throw new h(e, r);
|
420
|
-
}
|
421
|
-
function Z(e, r) {
|
422
|
-
let n = Array.from(e);
|
423
|
-
return r.length === 0 ? n : n.sort((s, u) => {
|
424
|
-
for (let p of r) {
|
425
|
-
let { field: o, direction: i } = p, t = s[o], a = u[o];
|
426
|
-
try {
|
427
|
-
if (i !== "asc" && i !== "desc")
|
428
|
-
throw new F(i);
|
429
|
-
let c = Y(t, a, i);
|
430
|
-
if (c !== 0)
|
431
|
-
return c;
|
432
|
-
} catch (c) {
|
433
|
-
throw c instanceof h || c instanceof F ? c : new Error(`Error comparing field '${o}': ${c.message}`);
|
434
|
-
}
|
435
|
-
}
|
436
|
-
return 0;
|
437
|
-
});
|
438
|
-
}
|
439
|
-
function j() {
|
440
|
-
return { sort: Z };
|
441
|
-
}
|
442
|
-
function Q(e) {
|
443
|
-
let { resolve: r } = g(e);
|
444
|
-
function n(o, i, t) {
|
445
|
-
for (let a of i) {
|
446
|
-
if (typeof a == "string") {
|
447
|
-
let c = a;
|
448
|
-
t[c] = o[c];
|
449
|
-
continue;
|
450
|
-
}
|
451
|
-
for (let [c, y] of Object.entries(a))
|
452
|
-
if (Object.prototype.hasOwnProperty.call(o, c)) {
|
453
|
-
let d = p(o[c], y);
|
454
|
-
t[c] = d;
|
455
|
-
}
|
456
|
-
}
|
457
|
-
}
|
458
|
-
function s(o, i, t) {
|
459
|
-
Object.keys(t).length === 0 && Object.assign(t, o);
|
460
|
-
for (let a of i) {
|
461
|
-
if (typeof a == "string") {
|
462
|
-
let c = a;
|
463
|
-
delete t[c];
|
464
|
-
continue;
|
465
|
-
}
|
466
|
-
for (let [c, y] of Object.entries(a)) {
|
467
|
-
if (!Object.prototype.hasOwnProperty.call(t, c))
|
468
|
-
continue;
|
469
|
-
let d = t[c];
|
470
|
-
d && typeof d == "object" ? t[c] = p(d, y) : delete t[c];
|
471
|
-
}
|
472
|
-
}
|
473
|
-
}
|
474
|
-
function u(o, i, t) {
|
475
|
-
for (let a of i)
|
476
|
-
t[a.alias] = r(o, a);
|
477
|
-
}
|
478
|
-
function p(o, i) {
|
479
|
-
let t = {};
|
480
|
-
return i.include?.length && n(o, i.include, t), i.exclude?.length && s(o, i.exclude, t), i.computed?.length && u(o, i.computed, t), t;
|
481
|
-
}
|
482
|
-
return { project: p };
|
483
|
-
}
|
484
|
-
async function* ee(e, r, n = (s) => String(s)) {
|
485
|
-
r.type === "offset" ? yield* re(e, r) : yield* te(e, r, n);
|
486
|
-
}
|
487
|
-
function k() {
|
488
|
-
return { paginate: ee };
|
489
|
-
}
|
490
|
-
async function* re(e, r) {
|
491
|
-
let { offset: n, limit: s } = r, u = 0, p = s, o = [];
|
492
|
-
for await (let i of e) {
|
493
|
-
if (p <= 0 && (yield o, o = [], p = s), u < n) {
|
494
|
-
u++;
|
495
|
-
continue;
|
496
|
-
}
|
497
|
-
o.push(i), p--;
|
498
|
-
}
|
499
|
-
o.length > 0 && (yield o);
|
500
|
-
}
|
501
|
-
async function* te(e, r, n) {
|
502
|
-
let { cursor: s, limit: u, direction: p } = r, o = u, i = s === void 0, t = [];
|
503
|
-
if (p === "forward")
|
504
|
-
for await (let a of e) {
|
505
|
-
if (o <= 0 && (yield t, t = [], o = u), !i) {
|
506
|
-
i = n(a) === s;
|
507
|
-
continue;
|
508
|
-
}
|
509
|
-
t.push(a), o--;
|
510
|
-
}
|
511
|
-
else {
|
512
|
-
let a = [];
|
513
|
-
for await (let c of e)
|
514
|
-
a.push(c);
|
515
|
-
for (let c = a.length - 1; c >= 0; c--) {
|
516
|
-
let y = a[c];
|
517
|
-
if (!i) {
|
518
|
-
i = n(y) === s;
|
519
|
-
continue;
|
520
|
-
}
|
521
|
-
t.push(y), o--, o <= 0 && (yield t, t = [], o = u);
|
522
|
-
}
|
523
|
-
}
|
524
|
-
t.length > 0 && (yield t);
|
525
|
-
}
|
526
|
-
}
|
527
|
-
});
|
528
|
-
|
529
|
-
// node_modules/uuid/dist/cjs/max.js
|
530
|
-
var require_max = __commonJS({
|
531
|
-
"node_modules/uuid/dist/cjs/max.js"(exports) {
|
532
|
-
"use strict";
|
533
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
534
|
-
exports.default = "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
535
|
-
}
|
536
|
-
});
|
537
|
-
|
538
|
-
// node_modules/uuid/dist/cjs/nil.js
|
539
|
-
var require_nil = __commonJS({
|
540
|
-
"node_modules/uuid/dist/cjs/nil.js"(exports) {
|
541
|
-
"use strict";
|
542
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
543
|
-
exports.default = "00000000-0000-0000-0000-000000000000";
|
544
|
-
}
|
545
|
-
});
|
546
|
-
|
547
|
-
// node_modules/uuid/dist/cjs/regex.js
|
548
|
-
var require_regex = __commonJS({
|
549
|
-
"node_modules/uuid/dist/cjs/regex.js"(exports) {
|
550
|
-
"use strict";
|
551
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
552
|
-
exports.default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
553
|
-
}
|
554
|
-
});
|
555
|
-
|
556
|
-
// node_modules/uuid/dist/cjs/validate.js
|
557
|
-
var require_validate = __commonJS({
|
558
|
-
"node_modules/uuid/dist/cjs/validate.js"(exports) {
|
559
|
-
"use strict";
|
560
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
561
|
-
var regex_js_1 = require_regex();
|
562
|
-
function validate(uuid) {
|
563
|
-
return typeof uuid === "string" && regex_js_1.default.test(uuid);
|
564
|
-
}
|
565
|
-
exports.default = validate;
|
566
|
-
}
|
567
|
-
});
|
568
|
-
|
569
|
-
// node_modules/uuid/dist/cjs/parse.js
|
570
|
-
var require_parse = __commonJS({
|
571
|
-
"node_modules/uuid/dist/cjs/parse.js"(exports) {
|
572
|
-
"use strict";
|
573
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
574
|
-
var validate_js_1 = require_validate();
|
575
|
-
function parse(uuid) {
|
576
|
-
if (!(0, validate_js_1.default)(uuid)) {
|
577
|
-
throw TypeError("Invalid UUID");
|
578
|
-
}
|
579
|
-
let v;
|
580
|
-
return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, v >>> 16 & 255, v >>> 8 & 255, v & 255, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255, v / 4294967296 & 255, v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255);
|
581
|
-
}
|
582
|
-
exports.default = parse;
|
583
|
-
}
|
584
|
-
});
|
585
|
-
|
586
|
-
// node_modules/uuid/dist/cjs/stringify.js
|
587
|
-
var require_stringify = __commonJS({
|
588
|
-
"node_modules/uuid/dist/cjs/stringify.js"(exports) {
|
589
|
-
"use strict";
|
590
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
591
|
-
exports.unsafeStringify = void 0;
|
592
|
-
var validate_js_1 = require_validate();
|
593
|
-
var byteToHex = [];
|
594
|
-
for (let i = 0; i < 256; ++i) {
|
595
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
596
|
-
}
|
597
|
-
function unsafeStringify(arr, offset = 0) {
|
598
|
-
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
599
|
-
}
|
600
|
-
exports.unsafeStringify = unsafeStringify;
|
601
|
-
function stringify(arr, offset = 0) {
|
602
|
-
const uuid = unsafeStringify(arr, offset);
|
603
|
-
if (!(0, validate_js_1.default)(uuid)) {
|
604
|
-
throw TypeError("Stringified UUID is invalid");
|
605
|
-
}
|
606
|
-
return uuid;
|
607
|
-
}
|
608
|
-
exports.default = stringify;
|
609
|
-
}
|
610
|
-
});
|
611
|
-
|
612
|
-
// node_modules/uuid/dist/cjs/rng.js
|
613
|
-
var require_rng = __commonJS({
|
614
|
-
"node_modules/uuid/dist/cjs/rng.js"(exports) {
|
615
|
-
"use strict";
|
616
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
617
|
-
var crypto_1 = __require("crypto");
|
618
|
-
var rnds8Pool = new Uint8Array(256);
|
619
|
-
var poolPtr = rnds8Pool.length;
|
620
|
-
function rng() {
|
621
|
-
if (poolPtr > rnds8Pool.length - 16) {
|
622
|
-
(0, crypto_1.randomFillSync)(rnds8Pool);
|
623
|
-
poolPtr = 0;
|
624
|
-
}
|
625
|
-
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
626
|
-
}
|
627
|
-
exports.default = rng;
|
628
|
-
}
|
629
|
-
});
|
630
|
-
|
631
|
-
// node_modules/uuid/dist/cjs/v1.js
|
632
|
-
var require_v1 = __commonJS({
|
633
|
-
"node_modules/uuid/dist/cjs/v1.js"(exports) {
|
634
|
-
"use strict";
|
635
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
636
|
-
exports.updateV1State = void 0;
|
637
|
-
var rng_js_1 = require_rng();
|
638
|
-
var stringify_js_1 = require_stringify();
|
639
|
-
var _state = {};
|
640
|
-
function v1(options, buf, offset) {
|
641
|
-
let bytes;
|
642
|
-
const isV6 = options?._v6 ?? false;
|
643
|
-
if (options) {
|
644
|
-
const optionsKeys = Object.keys(options);
|
645
|
-
if (optionsKeys.length === 1 && optionsKeys[0] === "_v6") {
|
646
|
-
options = void 0;
|
647
|
-
}
|
648
|
-
}
|
649
|
-
if (options) {
|
650
|
-
bytes = v1Bytes(options.random ?? options.rng?.() ?? (0, rng_js_1.default)(), options.msecs, options.nsecs, options.clockseq, options.node, buf, offset);
|
651
|
-
} else {
|
652
|
-
const now = Date.now();
|
653
|
-
const rnds = (0, rng_js_1.default)();
|
654
|
-
updateV1State(_state, now, rnds);
|
655
|
-
bytes = v1Bytes(rnds, _state.msecs, _state.nsecs, isV6 ? void 0 : _state.clockseq, isV6 ? void 0 : _state.node, buf, offset);
|
656
|
-
}
|
657
|
-
return buf ?? (0, stringify_js_1.unsafeStringify)(bytes);
|
658
|
-
}
|
659
|
-
function updateV1State(state, now, rnds) {
|
660
|
-
state.msecs ??= -Infinity;
|
661
|
-
state.nsecs ??= 0;
|
662
|
-
if (now === state.msecs) {
|
663
|
-
state.nsecs++;
|
664
|
-
if (state.nsecs >= 1e4) {
|
665
|
-
state.node = void 0;
|
666
|
-
state.nsecs = 0;
|
667
|
-
}
|
668
|
-
} else if (now > state.msecs) {
|
669
|
-
state.nsecs = 0;
|
670
|
-
} else if (now < state.msecs) {
|
671
|
-
state.node = void 0;
|
672
|
-
}
|
673
|
-
if (!state.node) {
|
674
|
-
state.node = rnds.slice(10, 16);
|
675
|
-
state.node[0] |= 1;
|
676
|
-
state.clockseq = (rnds[8] << 8 | rnds[9]) & 16383;
|
677
|
-
}
|
678
|
-
state.msecs = now;
|
679
|
-
return state;
|
680
|
-
}
|
681
|
-
exports.updateV1State = updateV1State;
|
682
|
-
function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
|
683
|
-
if (rnds.length < 16) {
|
684
|
-
throw new Error("Random bytes length must be >= 16");
|
685
|
-
}
|
686
|
-
if (!buf) {
|
687
|
-
buf = new Uint8Array(16);
|
688
|
-
offset = 0;
|
689
|
-
} else {
|
690
|
-
if (offset < 0 || offset + 16 > buf.length) {
|
691
|
-
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
692
|
-
}
|
693
|
-
}
|
694
|
-
msecs ??= Date.now();
|
695
|
-
nsecs ??= 0;
|
696
|
-
clockseq ??= (rnds[8] << 8 | rnds[9]) & 16383;
|
697
|
-
node ??= rnds.slice(10, 16);
|
698
|
-
msecs += 122192928e5;
|
699
|
-
const tl = ((msecs & 268435455) * 1e4 + nsecs) % 4294967296;
|
700
|
-
buf[offset++] = tl >>> 24 & 255;
|
701
|
-
buf[offset++] = tl >>> 16 & 255;
|
702
|
-
buf[offset++] = tl >>> 8 & 255;
|
703
|
-
buf[offset++] = tl & 255;
|
704
|
-
const tmh = msecs / 4294967296 * 1e4 & 268435455;
|
705
|
-
buf[offset++] = tmh >>> 8 & 255;
|
706
|
-
buf[offset++] = tmh & 255;
|
707
|
-
buf[offset++] = tmh >>> 24 & 15 | 16;
|
708
|
-
buf[offset++] = tmh >>> 16 & 255;
|
709
|
-
buf[offset++] = clockseq >>> 8 | 128;
|
710
|
-
buf[offset++] = clockseq & 255;
|
711
|
-
for (let n = 0; n < 6; ++n) {
|
712
|
-
buf[offset++] = node[n];
|
713
|
-
}
|
714
|
-
return buf;
|
715
|
-
}
|
716
|
-
exports.default = v1;
|
717
|
-
}
|
718
|
-
});
|
719
|
-
|
720
|
-
// node_modules/uuid/dist/cjs/v1ToV6.js
|
721
|
-
var require_v1ToV6 = __commonJS({
|
722
|
-
"node_modules/uuid/dist/cjs/v1ToV6.js"(exports) {
|
723
|
-
"use strict";
|
724
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
725
|
-
var parse_js_1 = require_parse();
|
726
|
-
var stringify_js_1 = require_stringify();
|
727
|
-
function v1ToV6(uuid) {
|
728
|
-
const v1Bytes = typeof uuid === "string" ? (0, parse_js_1.default)(uuid) : uuid;
|
729
|
-
const v6Bytes = _v1ToV6(v1Bytes);
|
730
|
-
return typeof uuid === "string" ? (0, stringify_js_1.unsafeStringify)(v6Bytes) : v6Bytes;
|
731
|
-
}
|
732
|
-
exports.default = v1ToV6;
|
733
|
-
function _v1ToV6(v1Bytes) {
|
734
|
-
return Uint8Array.of((v1Bytes[6] & 15) << 4 | v1Bytes[7] >> 4 & 15, (v1Bytes[7] & 15) << 4 | (v1Bytes[4] & 240) >> 4, (v1Bytes[4] & 15) << 4 | (v1Bytes[5] & 240) >> 4, (v1Bytes[5] & 15) << 4 | (v1Bytes[0] & 240) >> 4, (v1Bytes[0] & 15) << 4 | (v1Bytes[1] & 240) >> 4, (v1Bytes[1] & 15) << 4 | (v1Bytes[2] & 240) >> 4, 96 | v1Bytes[2] & 15, v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
|
735
|
-
}
|
736
|
-
}
|
737
|
-
});
|
738
|
-
|
739
|
-
// node_modules/uuid/dist/cjs/md5.js
|
740
|
-
var require_md5 = __commonJS({
|
741
|
-
"node_modules/uuid/dist/cjs/md5.js"(exports) {
|
742
|
-
"use strict";
|
743
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
744
|
-
var crypto_1 = __require("crypto");
|
745
|
-
function md5(bytes) {
|
746
|
-
if (Array.isArray(bytes)) {
|
747
|
-
bytes = Buffer.from(bytes);
|
748
|
-
} else if (typeof bytes === "string") {
|
749
|
-
bytes = Buffer.from(bytes, "utf8");
|
750
|
-
}
|
751
|
-
return (0, crypto_1.createHash)("md5").update(bytes).digest();
|
752
|
-
}
|
753
|
-
exports.default = md5;
|
754
|
-
}
|
755
|
-
});
|
756
|
-
|
757
|
-
// node_modules/uuid/dist/cjs/v35.js
|
758
|
-
var require_v35 = __commonJS({
|
759
|
-
"node_modules/uuid/dist/cjs/v35.js"(exports) {
|
760
|
-
"use strict";
|
761
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
762
|
-
exports.URL = exports.DNS = exports.stringToBytes = void 0;
|
763
|
-
var parse_js_1 = require_parse();
|
764
|
-
var stringify_js_1 = require_stringify();
|
765
|
-
function stringToBytes(str) {
|
766
|
-
str = unescape(encodeURIComponent(str));
|
767
|
-
const bytes = new Uint8Array(str.length);
|
768
|
-
for (let i = 0; i < str.length; ++i) {
|
769
|
-
bytes[i] = str.charCodeAt(i);
|
770
|
-
}
|
771
|
-
return bytes;
|
772
|
-
}
|
773
|
-
exports.stringToBytes = stringToBytes;
|
774
|
-
exports.DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
775
|
-
exports.URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
|
776
|
-
function v35(version, hash, value, namespace, buf, offset) {
|
777
|
-
const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
|
778
|
-
const namespaceBytes = typeof namespace === "string" ? (0, parse_js_1.default)(namespace) : namespace;
|
779
|
-
if (typeof namespace === "string") {
|
780
|
-
namespace = (0, parse_js_1.default)(namespace);
|
781
|
-
}
|
782
|
-
if (namespace?.length !== 16) {
|
783
|
-
throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
|
784
|
-
}
|
785
|
-
let bytes = new Uint8Array(16 + valueBytes.length);
|
786
|
-
bytes.set(namespaceBytes);
|
787
|
-
bytes.set(valueBytes, namespaceBytes.length);
|
788
|
-
bytes = hash(bytes);
|
789
|
-
bytes[6] = bytes[6] & 15 | version;
|
790
|
-
bytes[8] = bytes[8] & 63 | 128;
|
791
|
-
if (buf) {
|
792
|
-
offset = offset || 0;
|
793
|
-
for (let i = 0; i < 16; ++i) {
|
794
|
-
buf[offset + i] = bytes[i];
|
795
|
-
}
|
796
|
-
return buf;
|
797
|
-
}
|
798
|
-
return (0, stringify_js_1.unsafeStringify)(bytes);
|
799
|
-
}
|
800
|
-
exports.default = v35;
|
801
|
-
}
|
802
|
-
});
|
803
|
-
|
804
|
-
// node_modules/uuid/dist/cjs/v3.js
|
805
|
-
var require_v3 = __commonJS({
|
806
|
-
"node_modules/uuid/dist/cjs/v3.js"(exports) {
|
807
|
-
"use strict";
|
808
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
809
|
-
exports.URL = exports.DNS = void 0;
|
810
|
-
var md5_js_1 = require_md5();
|
811
|
-
var v35_js_1 = require_v35();
|
812
|
-
var v35_js_2 = require_v35();
|
813
|
-
Object.defineProperty(exports, "DNS", { enumerable: true, get: function() {
|
814
|
-
return v35_js_2.DNS;
|
815
|
-
} });
|
816
|
-
Object.defineProperty(exports, "URL", { enumerable: true, get: function() {
|
817
|
-
return v35_js_2.URL;
|
818
|
-
} });
|
819
|
-
function v3(value, namespace, buf, offset) {
|
820
|
-
return (0, v35_js_1.default)(48, md5_js_1.default, value, namespace, buf, offset);
|
821
|
-
}
|
822
|
-
v3.DNS = v35_js_1.DNS;
|
823
|
-
v3.URL = v35_js_1.URL;
|
824
|
-
exports.default = v3;
|
825
|
-
}
|
826
|
-
});
|
827
|
-
|
828
|
-
// node_modules/uuid/dist/cjs/native.js
|
829
|
-
var require_native = __commonJS({
|
830
|
-
"node_modules/uuid/dist/cjs/native.js"(exports) {
|
831
|
-
"use strict";
|
832
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
833
|
-
var crypto_1 = __require("crypto");
|
834
|
-
exports.default = { randomUUID: crypto_1.randomUUID };
|
835
|
-
}
|
836
|
-
});
|
837
|
-
|
838
|
-
// node_modules/uuid/dist/cjs/v4.js
|
839
|
-
var require_v4 = __commonJS({
|
840
|
-
"node_modules/uuid/dist/cjs/v4.js"(exports) {
|
841
|
-
"use strict";
|
842
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
843
|
-
var native_js_1 = require_native();
|
844
|
-
var rng_js_1 = require_rng();
|
845
|
-
var stringify_js_1 = require_stringify();
|
846
|
-
function v4(options, buf, offset) {
|
847
|
-
if (native_js_1.default.randomUUID && !buf && !options) {
|
848
|
-
return native_js_1.default.randomUUID();
|
849
|
-
}
|
850
|
-
options = options || {};
|
851
|
-
const rnds = options.random ?? options.rng?.() ?? (0, rng_js_1.default)();
|
852
|
-
if (rnds.length < 16) {
|
853
|
-
throw new Error("Random bytes length must be >= 16");
|
854
|
-
}
|
855
|
-
rnds[6] = rnds[6] & 15 | 64;
|
856
|
-
rnds[8] = rnds[8] & 63 | 128;
|
857
|
-
if (buf) {
|
858
|
-
offset = offset || 0;
|
859
|
-
if (offset < 0 || offset + 16 > buf.length) {
|
860
|
-
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
861
|
-
}
|
862
|
-
for (let i = 0; i < 16; ++i) {
|
863
|
-
buf[offset + i] = rnds[i];
|
864
|
-
}
|
865
|
-
return buf;
|
866
|
-
}
|
867
|
-
return (0, stringify_js_1.unsafeStringify)(rnds);
|
868
|
-
}
|
869
|
-
exports.default = v4;
|
870
|
-
}
|
871
|
-
});
|
872
|
-
|
873
|
-
// node_modules/uuid/dist/cjs/sha1.js
|
874
|
-
var require_sha1 = __commonJS({
|
875
|
-
"node_modules/uuid/dist/cjs/sha1.js"(exports) {
|
876
|
-
"use strict";
|
877
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
878
|
-
var crypto_1 = __require("crypto");
|
879
|
-
function sha1(bytes) {
|
880
|
-
if (Array.isArray(bytes)) {
|
881
|
-
bytes = Buffer.from(bytes);
|
882
|
-
} else if (typeof bytes === "string") {
|
883
|
-
bytes = Buffer.from(bytes, "utf8");
|
884
|
-
}
|
885
|
-
return (0, crypto_1.createHash)("sha1").update(bytes).digest();
|
886
|
-
}
|
887
|
-
exports.default = sha1;
|
888
|
-
}
|
889
|
-
});
|
890
|
-
|
891
|
-
// node_modules/uuid/dist/cjs/v5.js
|
892
|
-
var require_v5 = __commonJS({
|
893
|
-
"node_modules/uuid/dist/cjs/v5.js"(exports) {
|
894
|
-
"use strict";
|
895
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
896
|
-
exports.URL = exports.DNS = void 0;
|
897
|
-
var sha1_js_1 = require_sha1();
|
898
|
-
var v35_js_1 = require_v35();
|
899
|
-
var v35_js_2 = require_v35();
|
900
|
-
Object.defineProperty(exports, "DNS", { enumerable: true, get: function() {
|
901
|
-
return v35_js_2.DNS;
|
902
|
-
} });
|
903
|
-
Object.defineProperty(exports, "URL", { enumerable: true, get: function() {
|
904
|
-
return v35_js_2.URL;
|
905
|
-
} });
|
906
|
-
function v5(value, namespace, buf, offset) {
|
907
|
-
return (0, v35_js_1.default)(80, sha1_js_1.default, value, namespace, buf, offset);
|
908
|
-
}
|
909
|
-
v5.DNS = v35_js_1.DNS;
|
910
|
-
v5.URL = v35_js_1.URL;
|
911
|
-
exports.default = v5;
|
912
|
-
}
|
913
|
-
});
|
914
|
-
|
915
|
-
// node_modules/uuid/dist/cjs/v6.js
|
916
|
-
var require_v6 = __commonJS({
|
917
|
-
"node_modules/uuid/dist/cjs/v6.js"(exports) {
|
918
|
-
"use strict";
|
919
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
920
|
-
var stringify_js_1 = require_stringify();
|
921
|
-
var v1_js_1 = require_v1();
|
922
|
-
var v1ToV6_js_1 = require_v1ToV6();
|
923
|
-
function v6(options, buf, offset) {
|
924
|
-
options ??= {};
|
925
|
-
offset ??= 0;
|
926
|
-
let bytes = (0, v1_js_1.default)({ ...options, _v6: true }, new Uint8Array(16));
|
927
|
-
bytes = (0, v1ToV6_js_1.default)(bytes);
|
928
|
-
if (buf) {
|
929
|
-
for (let i = 0; i < 16; i++) {
|
930
|
-
buf[offset + i] = bytes[i];
|
931
|
-
}
|
932
|
-
return buf;
|
933
|
-
}
|
934
|
-
return (0, stringify_js_1.unsafeStringify)(bytes);
|
935
|
-
}
|
936
|
-
exports.default = v6;
|
937
|
-
}
|
938
|
-
});
|
939
|
-
|
940
|
-
// node_modules/uuid/dist/cjs/v6ToV1.js
|
941
|
-
var require_v6ToV1 = __commonJS({
|
942
|
-
"node_modules/uuid/dist/cjs/v6ToV1.js"(exports) {
|
943
|
-
"use strict";
|
944
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
945
|
-
var parse_js_1 = require_parse();
|
946
|
-
var stringify_js_1 = require_stringify();
|
947
|
-
function v6ToV1(uuid) {
|
948
|
-
const v6Bytes = typeof uuid === "string" ? (0, parse_js_1.default)(uuid) : uuid;
|
949
|
-
const v1Bytes = _v6ToV1(v6Bytes);
|
950
|
-
return typeof uuid === "string" ? (0, stringify_js_1.unsafeStringify)(v1Bytes) : v1Bytes;
|
951
|
-
}
|
952
|
-
exports.default = v6ToV1;
|
953
|
-
function _v6ToV1(v6Bytes) {
|
954
|
-
return Uint8Array.of((v6Bytes[3] & 15) << 4 | v6Bytes[4] >> 4 & 15, (v6Bytes[4] & 15) << 4 | (v6Bytes[5] & 240) >> 4, (v6Bytes[5] & 15) << 4 | v6Bytes[6] & 15, v6Bytes[7], (v6Bytes[1] & 15) << 4 | (v6Bytes[2] & 240) >> 4, (v6Bytes[2] & 15) << 4 | (v6Bytes[3] & 240) >> 4, 16 | (v6Bytes[0] & 240) >> 4, (v6Bytes[0] & 15) << 4 | (v6Bytes[1] & 240) >> 4, v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
|
955
|
-
}
|
956
|
-
}
|
957
|
-
});
|
958
|
-
|
959
|
-
// node_modules/uuid/dist/cjs/v7.js
|
960
|
-
var require_v7 = __commonJS({
|
961
|
-
"node_modules/uuid/dist/cjs/v7.js"(exports) {
|
962
|
-
"use strict";
|
963
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
964
|
-
exports.updateV7State = void 0;
|
965
|
-
var rng_js_1 = require_rng();
|
966
|
-
var stringify_js_1 = require_stringify();
|
967
|
-
var _state = {};
|
968
|
-
function v7(options, buf, offset) {
|
969
|
-
let bytes;
|
970
|
-
if (options) {
|
971
|
-
bytes = v7Bytes(options.random ?? options.rng?.() ?? (0, rng_js_1.default)(), options.msecs, options.seq, buf, offset);
|
972
|
-
} else {
|
973
|
-
const now = Date.now();
|
974
|
-
const rnds = (0, rng_js_1.default)();
|
975
|
-
updateV7State(_state, now, rnds);
|
976
|
-
bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset);
|
977
|
-
}
|
978
|
-
return buf ?? (0, stringify_js_1.unsafeStringify)(bytes);
|
979
|
-
}
|
980
|
-
function updateV7State(state, now, rnds) {
|
981
|
-
state.msecs ??= -Infinity;
|
982
|
-
state.seq ??= 0;
|
983
|
-
if (now > state.msecs) {
|
984
|
-
state.seq = rnds[6] << 23 | rnds[7] << 16 | rnds[8] << 8 | rnds[9];
|
985
|
-
state.msecs = now;
|
986
|
-
} else {
|
987
|
-
state.seq = state.seq + 1 | 0;
|
988
|
-
if (state.seq === 0) {
|
989
|
-
state.msecs++;
|
990
|
-
}
|
991
|
-
}
|
992
|
-
return state;
|
993
|
-
}
|
994
|
-
exports.updateV7State = updateV7State;
|
995
|
-
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
996
|
-
if (rnds.length < 16) {
|
997
|
-
throw new Error("Random bytes length must be >= 16");
|
998
|
-
}
|
999
|
-
if (!buf) {
|
1000
|
-
buf = new Uint8Array(16);
|
1001
|
-
offset = 0;
|
1002
|
-
} else {
|
1003
|
-
if (offset < 0 || offset + 16 > buf.length) {
|
1004
|
-
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
1005
|
-
}
|
1006
|
-
}
|
1007
|
-
msecs ??= Date.now();
|
1008
|
-
seq ??= rnds[6] * 127 << 24 | rnds[7] << 16 | rnds[8] << 8 | rnds[9];
|
1009
|
-
buf[offset++] = msecs / 1099511627776 & 255;
|
1010
|
-
buf[offset++] = msecs / 4294967296 & 255;
|
1011
|
-
buf[offset++] = msecs / 16777216 & 255;
|
1012
|
-
buf[offset++] = msecs / 65536 & 255;
|
1013
|
-
buf[offset++] = msecs / 256 & 255;
|
1014
|
-
buf[offset++] = msecs & 255;
|
1015
|
-
buf[offset++] = 112 | seq >>> 28 & 15;
|
1016
|
-
buf[offset++] = seq >>> 20 & 255;
|
1017
|
-
buf[offset++] = 128 | seq >>> 14 & 63;
|
1018
|
-
buf[offset++] = seq >>> 6 & 255;
|
1019
|
-
buf[offset++] = seq << 2 & 255 | rnds[10] & 3;
|
1020
|
-
buf[offset++] = rnds[11];
|
1021
|
-
buf[offset++] = rnds[12];
|
1022
|
-
buf[offset++] = rnds[13];
|
1023
|
-
buf[offset++] = rnds[14];
|
1024
|
-
buf[offset++] = rnds[15];
|
1025
|
-
return buf;
|
1026
|
-
}
|
1027
|
-
exports.default = v7;
|
1028
|
-
}
|
1029
|
-
});
|
1030
|
-
|
1031
|
-
// node_modules/uuid/dist/cjs/version.js
|
1032
|
-
var require_version = __commonJS({
|
1033
|
-
"node_modules/uuid/dist/cjs/version.js"(exports) {
|
1034
|
-
"use strict";
|
1035
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
1036
|
-
var validate_js_1 = require_validate();
|
1037
|
-
function version(uuid) {
|
1038
|
-
if (!(0, validate_js_1.default)(uuid)) {
|
1039
|
-
throw TypeError("Invalid UUID");
|
1040
|
-
}
|
1041
|
-
return parseInt(uuid.slice(14, 15), 16);
|
1042
|
-
}
|
1043
|
-
exports.default = version;
|
1044
|
-
}
|
1045
|
-
});
|
1046
|
-
|
1047
|
-
// node_modules/uuid/dist/cjs/index.js
|
1048
|
-
var require_cjs = __commonJS({
|
1049
|
-
"node_modules/uuid/dist/cjs/index.js"(exports) {
|
1050
|
-
"use strict";
|
1051
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
1052
|
-
exports.version = exports.validate = exports.v7 = exports.v6ToV1 = exports.v6 = exports.v5 = exports.v4 = exports.v3 = exports.v1ToV6 = exports.v1 = exports.stringify = exports.parse = exports.NIL = exports.MAX = void 0;
|
1053
|
-
var max_js_1 = require_max();
|
1054
|
-
Object.defineProperty(exports, "MAX", { enumerable: true, get: function() {
|
1055
|
-
return max_js_1.default;
|
1056
|
-
} });
|
1057
|
-
var nil_js_1 = require_nil();
|
1058
|
-
Object.defineProperty(exports, "NIL", { enumerable: true, get: function() {
|
1059
|
-
return nil_js_1.default;
|
1060
|
-
} });
|
1061
|
-
var parse_js_1 = require_parse();
|
1062
|
-
Object.defineProperty(exports, "parse", { enumerable: true, get: function() {
|
1063
|
-
return parse_js_1.default;
|
1064
|
-
} });
|
1065
|
-
var stringify_js_1 = require_stringify();
|
1066
|
-
Object.defineProperty(exports, "stringify", { enumerable: true, get: function() {
|
1067
|
-
return stringify_js_1.default;
|
1068
|
-
} });
|
1069
|
-
var v1_js_1 = require_v1();
|
1070
|
-
Object.defineProperty(exports, "v1", { enumerable: true, get: function() {
|
1071
|
-
return v1_js_1.default;
|
1072
|
-
} });
|
1073
|
-
var v1ToV6_js_1 = require_v1ToV6();
|
1074
|
-
Object.defineProperty(exports, "v1ToV6", { enumerable: true, get: function() {
|
1075
|
-
return v1ToV6_js_1.default;
|
1076
|
-
} });
|
1077
|
-
var v3_js_1 = require_v3();
|
1078
|
-
Object.defineProperty(exports, "v3", { enumerable: true, get: function() {
|
1079
|
-
return v3_js_1.default;
|
1080
|
-
} });
|
1081
|
-
var v4_js_1 = require_v4();
|
1082
|
-
Object.defineProperty(exports, "v4", { enumerable: true, get: function() {
|
1083
|
-
return v4_js_1.default;
|
1084
|
-
} });
|
1085
|
-
var v5_js_1 = require_v5();
|
1086
|
-
Object.defineProperty(exports, "v5", { enumerable: true, get: function() {
|
1087
|
-
return v5_js_1.default;
|
1088
|
-
} });
|
1089
|
-
var v6_js_1 = require_v6();
|
1090
|
-
Object.defineProperty(exports, "v6", { enumerable: true, get: function() {
|
1091
|
-
return v6_js_1.default;
|
1092
|
-
} });
|
1093
|
-
var v6ToV1_js_1 = require_v6ToV1();
|
1094
|
-
Object.defineProperty(exports, "v6ToV1", { enumerable: true, get: function() {
|
1095
|
-
return v6ToV1_js_1.default;
|
1096
|
-
} });
|
1097
|
-
var v7_js_1 = require_v7();
|
1098
|
-
Object.defineProperty(exports, "v7", { enumerable: true, get: function() {
|
1099
|
-
return v7_js_1.default;
|
1100
|
-
} });
|
1101
|
-
var validate_js_1 = require_validate();
|
1102
|
-
Object.defineProperty(exports, "validate", { enumerable: true, get: function() {
|
1103
|
-
return validate_js_1.default;
|
1104
|
-
} });
|
1105
|
-
var version_js_1 = require_version();
|
1106
|
-
Object.defineProperty(exports, "version", { enumerable: true, get: function() {
|
1107
|
-
return version_js_1.default;
|
1108
|
-
} });
|
1109
|
-
}
|
1110
|
-
});
|
1111
|
-
|
1112
|
-
// node_modules/@asaidimu/indexed/index.js
|
1113
|
-
var require_indexed = __commonJS({
|
1114
|
-
"node_modules/@asaidimu/indexed/index.js"(exports, module) {
|
1115
|
-
"use strict";
|
1116
|
-
var __defProp2 = Object.defineProperty;
|
1117
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
1118
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
1119
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
1120
|
-
var __export = (target, all) => {
|
1121
|
-
for (var name in all)
|
1122
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
1123
|
-
};
|
1124
|
-
var __copyProps2 = (to, from, except, desc) => {
|
1125
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
1126
|
-
for (let key of __getOwnPropNames2(from))
|
1127
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
1128
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
1129
|
-
}
|
1130
|
-
return to;
|
1131
|
-
};
|
1132
|
-
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
1133
|
-
var index_exports = {};
|
1134
|
-
__export(index_exports, {
|
1135
|
-
DatabaseConnection: () => DatabaseConnection2,
|
1136
|
-
DatabaseError: () => DatabaseError2,
|
1137
|
-
DatabaseErrorType: () => DatabaseErrorType
|
1138
|
-
});
|
1139
|
-
module.exports = __toCommonJS(index_exports);
|
1140
|
-
var import_events3 = require_events();
|
1141
|
-
var import_query2 = require_query();
|
1142
|
-
async function offsetPaginate(cursor, pagination) {
|
1143
|
-
const { offset, limit } = pagination;
|
1144
|
-
const result = [];
|
1145
|
-
let offsetCount = 0;
|
1146
|
-
let done = false;
|
1147
|
-
while (!done) {
|
1148
|
-
await cursor(async (value) => {
|
1149
|
-
if (offsetCount < offset) {
|
1150
|
-
offsetCount++;
|
1151
|
-
return { value, done: false, offset: 1 };
|
1152
|
-
}
|
1153
|
-
result.push(value);
|
1154
|
-
offsetCount++;
|
1155
|
-
if (offsetCount >= offset + limit) {
|
1156
|
-
done = true;
|
1157
|
-
return { value, done: true, offset: 1 };
|
1158
|
-
}
|
1159
|
-
return { value, done: false, offset: 1 };
|
1160
|
-
});
|
1161
|
-
if (result.length >= limit)
|
1162
|
-
break;
|
1163
|
-
}
|
1164
|
-
return result;
|
1165
|
-
}
|
1166
|
-
async function cursorPaginate(cursor, pagination) {
|
1167
|
-
const { limit, direction } = pagination;
|
1168
|
-
const result = [];
|
1169
|
-
let done = false;
|
1170
|
-
while (!done) {
|
1171
|
-
await cursor(async (value) => {
|
1172
|
-
result.push(value);
|
1173
|
-
if (result.length >= limit) {
|
1174
|
-
done = true;
|
1175
|
-
return { value, done: true, offset: 1 };
|
1176
|
-
}
|
1177
|
-
return { value, done: false, offset: 1 };
|
1178
|
-
}, direction);
|
1179
|
-
}
|
1180
|
-
return result;
|
1181
|
-
}
|
1182
|
-
var StoreError = class extends Error {
|
1183
|
-
constructor(message, cause) {
|
1184
|
-
super(message);
|
1185
|
-
this.cause = cause;
|
1186
|
-
this.name = "StoreError";
|
1187
|
-
if (cause && cause.stack) {
|
1188
|
-
this.stack = `${this.stack}
|
1189
|
-
Caused by: ${cause.stack}`;
|
1190
|
-
}
|
1191
|
-
}
|
1192
|
-
};
|
1193
|
-
var createStore = async (conn, { name: storeName, keyPath: storeKey = "$id" }, getTransaction) => {
|
1194
|
-
if (!storeName || typeof storeName !== "string") {
|
1195
|
-
throw new StoreError("Invalid store name");
|
1196
|
-
}
|
1197
|
-
if (!storeKey || typeof storeKey !== "string") {
|
1198
|
-
throw new StoreError("Invalid store key path");
|
1199
|
-
}
|
1200
|
-
const validIndexes = new Set(
|
1201
|
-
Array.from(
|
1202
|
-
(await conn()).transaction([storeName]).objectStore(storeName).indexNames
|
1203
|
-
)
|
1204
|
-
);
|
1205
|
-
const createTransaction = (mode) => {
|
1206
|
-
if (getTransaction) {
|
1207
|
-
const transaction = getTransaction();
|
1208
|
-
const store2 = transaction.objectStore(storeName);
|
1209
|
-
return Promise.resolve({ transaction, store: store2 });
|
1210
|
-
}
|
1211
|
-
return new Promise(async (resolve, reject) => {
|
1212
|
-
const transaction = (await conn()).transaction([storeName], mode);
|
1213
|
-
const store2 = transaction.objectStore(storeName);
|
1214
|
-
transaction.onerror = () => {
|
1215
|
-
reject(
|
1216
|
-
new StoreError(
|
1217
|
-
`Transaction failed: ${transaction.error?.message || "Unknown error"}`,
|
1218
|
-
transaction.error
|
1219
|
-
)
|
1220
|
-
);
|
1221
|
-
};
|
1222
|
-
resolve({ transaction, store: store2 });
|
1223
|
-
});
|
1224
|
-
};
|
1225
|
-
const getTarget = (store2, indexName) => {
|
1226
|
-
if (!indexName)
|
1227
|
-
return store2;
|
1228
|
-
if (!validIndexes.has(indexName)) {
|
1229
|
-
throw new StoreError(
|
1230
|
-
`Index '${indexName}' does not exist in store '${storeName}'`
|
1231
|
-
);
|
1232
|
-
}
|
1233
|
-
return store2.index(indexName);
|
1234
|
-
};
|
1235
|
-
const handleCursorOperation = (request, callback) => {
|
1236
|
-
return new Promise((resolve, reject) => {
|
1237
|
-
let lastValue = null;
|
1238
|
-
request.onsuccess = async (event) => {
|
1239
|
-
const cursor = event.target.result;
|
1240
|
-
if (!cursor) {
|
1241
|
-
resolve(lastValue);
|
1242
|
-
return;
|
1243
|
-
}
|
1244
|
-
try {
|
1245
|
-
const { value, done, offset } = await callback(
|
1246
|
-
cursor.value,
|
1247
|
-
cursor.key,
|
1248
|
-
cursor
|
1249
|
-
);
|
1250
|
-
lastValue = value;
|
1251
|
-
if (offset && offset <= 0) {
|
1252
|
-
throw new StoreError("Offset must be positive");
|
1253
|
-
}
|
1254
|
-
if (done) {
|
1255
|
-
resolve(value);
|
1256
|
-
return;
|
1257
|
-
}
|
1258
|
-
if (offset && offset > 0) {
|
1259
|
-
cursor.advance(offset);
|
1260
|
-
} else {
|
1261
|
-
cursor.continue();
|
1262
|
-
}
|
1263
|
-
} catch (error) {
|
1264
|
-
reject(
|
1265
|
-
error instanceof Error ? error : new StoreError("Cursor callback failed", error)
|
1266
|
-
);
|
1267
|
-
}
|
1268
|
-
};
|
1269
|
-
request.onerror = () => {
|
1270
|
-
reject(
|
1271
|
-
new StoreError(
|
1272
|
-
`Cursor request failed: ${request.error?.message || "Unknown error"}`,
|
1273
|
-
request.error
|
1274
|
-
)
|
1275
|
-
);
|
1276
|
-
};
|
1277
|
-
});
|
1278
|
-
};
|
1279
|
-
const handleSingleRequest = (request) => {
|
1280
|
-
return new Promise((resolve, reject) => {
|
1281
|
-
request.onsuccess = () => resolve(request.result);
|
1282
|
-
request.onerror = () => {
|
1283
|
-
reject(
|
1284
|
-
new StoreError(
|
1285
|
-
`Operation failed: ${request.error?.message || "Unknown error"}`,
|
1286
|
-
request.error
|
1287
|
-
)
|
1288
|
-
);
|
1289
|
-
};
|
1290
|
-
});
|
1291
|
-
};
|
1292
|
-
const handleMultipleRequests = (requests) => {
|
1293
|
-
const promises = requests.map(
|
1294
|
-
(req) => new Promise((resolve, reject) => {
|
1295
|
-
req.onsuccess = () => resolve(req.result);
|
1296
|
-
req.onerror = () => {
|
1297
|
-
reject(
|
1298
|
-
new StoreError(
|
1299
|
-
`Request failed: ${req.error?.message || "Unknown error"}`,
|
1300
|
-
req.error
|
1301
|
-
)
|
1302
|
-
);
|
1303
|
-
};
|
1304
|
-
})
|
1305
|
-
);
|
1306
|
-
return Promise.all(promises);
|
1307
|
-
};
|
1308
|
-
const executeTransaction = async (mode, operation, options) => {
|
1309
|
-
const { store: store2 } = await createTransaction(mode);
|
1310
|
-
const target = getTarget(store2, options?.indexName);
|
1311
|
-
const result = operation(store2, target);
|
1312
|
-
if (options?.cursorCallback) {
|
1313
|
-
const request = result;
|
1314
|
-
return handleCursorOperation(request, options.cursorCallback);
|
1315
|
-
}
|
1316
|
-
const opResult = result;
|
1317
|
-
if (opResult.type === "single") {
|
1318
|
-
return handleSingleRequest(opResult.request);
|
1319
|
-
}
|
1320
|
-
return handleMultipleRequests(opResult.requests);
|
1321
|
-
};
|
1322
|
-
const store = {
|
1323
|
-
add: async (data) => {
|
1324
|
-
const all = Array.isArray(data) ? data : [data];
|
1325
|
-
all.forEach((item) => {
|
1326
|
-
if (!item[storeKey])
|
1327
|
-
throw new StoreError(`Record must have a ${storeKey} property`);
|
1328
|
-
});
|
1329
|
-
const keys = await executeTransaction(
|
1330
|
-
"readwrite",
|
1331
|
-
(store2) => ({
|
1332
|
-
type: "multiple",
|
1333
|
-
requests: all.map((item) => store2.add(item))
|
1334
|
-
})
|
1335
|
-
);
|
1336
|
-
return Array.isArray(data) ? keys : keys[0];
|
1337
|
-
},
|
1338
|
-
clear: () => executeTransaction("readwrite", (store2) => ({
|
1339
|
-
type: "single",
|
1340
|
-
request: store2.clear()
|
1341
|
-
})),
|
1342
|
-
count: () => executeTransaction("readonly", (store2) => ({
|
1343
|
-
type: "single",
|
1344
|
-
request: store2.count()
|
1345
|
-
})),
|
1346
|
-
delete: async (id) => {
|
1347
|
-
const allIds = Array.isArray(id) ? id : [id];
|
1348
|
-
if (allIds.some((id2) => id2 === void 0)) {
|
1349
|
-
throw new StoreError("ID cannot be undefined");
|
1350
|
-
}
|
1351
|
-
return executeTransaction("readwrite", (store2) => ({
|
1352
|
-
type: "multiple",
|
1353
|
-
requests: allIds.map((key) => store2.delete(key))
|
1354
|
-
}));
|
1355
|
-
},
|
1356
|
-
getById: (id) => {
|
1357
|
-
if (id === void 0)
|
1358
|
-
throw new StoreError("ID cannot be undefined");
|
1359
|
-
return executeTransaction("readonly", (store2) => ({
|
1360
|
-
type: "single",
|
1361
|
-
request: store2.get(id)
|
1362
|
-
}));
|
1363
|
-
},
|
1364
|
-
getByIndex: (index, key) => {
|
1365
|
-
if (key === void 0)
|
1366
|
-
throw new StoreError("Key cannot be undefined for index query");
|
1367
|
-
return executeTransaction(
|
1368
|
-
"readonly",
|
1369
|
-
(_, index2) => ({
|
1370
|
-
type: "single",
|
1371
|
-
request: index2.get(key)
|
1372
|
-
}),
|
1373
|
-
{ indexName: index }
|
1374
|
-
);
|
1375
|
-
},
|
1376
|
-
getByKeyRange: (index, keyRange) => executeTransaction(
|
1377
|
-
"readonly",
|
1378
|
-
(_, index2) => ({
|
1379
|
-
type: "single",
|
1380
|
-
request: index2.getAll(keyRange)
|
1381
|
-
}),
|
1382
|
-
{ indexName: index }
|
1383
|
-
),
|
1384
|
-
getAll: () => executeTransaction("readonly", (store2) => ({
|
1385
|
-
type: "single",
|
1386
|
-
request: store2.getAll()
|
1387
|
-
})),
|
1388
|
-
put: (data) => {
|
1389
|
-
if (!data[storeKey])
|
1390
|
-
throw new StoreError(`Record must have a ${storeKey} property`);
|
1391
|
-
return executeTransaction("readwrite", (store2) => ({
|
1392
|
-
type: "single",
|
1393
|
-
request: store2.put(data)
|
1394
|
-
}));
|
1395
|
-
},
|
1396
|
-
cursor: (callback, direction = "forward") => {
|
1397
|
-
const cursorDirection = direction === "forward" ? "next" : "prev";
|
1398
|
-
return executeTransaction(
|
1399
|
-
"readonly",
|
1400
|
-
(store2) => store2.openCursor(void 0, cursorDirection),
|
1401
|
-
{ cursorCallback: callback, cursorDirection }
|
1402
|
-
);
|
1403
|
-
},
|
1404
|
-
batch: async (operations) => {
|
1405
|
-
if (!operations.length) {
|
1406
|
-
throw new StoreError("Batch operations array cannot be empty");
|
1407
|
-
}
|
1408
|
-
return executeTransaction("readwrite", (store2) => {
|
1409
|
-
const requests = [];
|
1410
|
-
for (const op of operations) {
|
1411
|
-
if (op.type === "add" || op.type === "put") {
|
1412
|
-
const data = Array.isArray(op.data) ? op.data : [op.data];
|
1413
|
-
data.forEach((item) => {
|
1414
|
-
if (!item[storeKey])
|
1415
|
-
throw new StoreError(`Record must have a ${storeKey} property`);
|
1416
|
-
requests.push(store2[op.type](item));
|
1417
|
-
});
|
1418
|
-
} else if (op.type === "delete") {
|
1419
|
-
const ids = Array.isArray(op.data) ? op.data : [op.data];
|
1420
|
-
if (ids.some((id) => id === void 0)) {
|
1421
|
-
throw new StoreError("ID cannot be undefined");
|
1422
|
-
}
|
1423
|
-
ids.forEach((id) => requests.push(store2.delete(id)));
|
1424
|
-
}
|
1425
|
-
}
|
1426
|
-
return { type: "multiple", requests };
|
1427
|
-
});
|
1428
|
-
}
|
1429
|
-
};
|
1430
|
-
return store;
|
1431
|
-
};
|
1432
|
-
function createTelemetryProxy(target, source, eventBus) {
|
1433
|
-
return new Proxy(target, {
|
1434
|
-
get(target2, prop) {
|
1435
|
-
const originalMethod = target2[prop];
|
1436
|
-
if (typeof originalMethod === "function") {
|
1437
|
-
return async function(...args) {
|
1438
|
-
const startTime = Date.now();
|
1439
|
-
let error = null;
|
1440
|
-
let result;
|
1441
|
-
try {
|
1442
|
-
result = await originalMethod.apply(target2, args);
|
1443
|
-
return result;
|
1444
|
-
} catch (e) {
|
1445
|
-
error = e;
|
1446
|
-
throw e;
|
1447
|
-
} finally {
|
1448
|
-
eventBus.emit({
|
1449
|
-
name: "telemetry",
|
1450
|
-
payload: {
|
1451
|
-
type: "telemetry",
|
1452
|
-
method: prop.toString(),
|
1453
|
-
timestamp: Date.now(),
|
1454
|
-
metadata: {
|
1455
|
-
args,
|
1456
|
-
performance: {
|
1457
|
-
durationMs: Date.now() - startTime
|
1458
|
-
},
|
1459
|
-
source,
|
1460
|
-
context: {
|
1461
|
-
userAgent: globalThis.navigator?.userAgent
|
1462
|
-
},
|
1463
|
-
result: error ? void 0 : {
|
1464
|
-
type: Array.isArray(result) ? "array" : typeof result,
|
1465
|
-
size: Array.isArray(result) ? result.length : void 0
|
1466
|
-
},
|
1467
|
-
error: error ? {
|
1468
|
-
message: error.message,
|
1469
|
-
name: error.name,
|
1470
|
-
stack: error.stack
|
1471
|
-
} : null
|
1472
|
-
}
|
1473
|
-
}
|
1474
|
-
});
|
1475
|
-
}
|
1476
|
-
};
|
1477
|
-
}
|
1478
|
-
return originalMethod;
|
1479
|
-
}
|
1480
|
-
});
|
1481
|
-
}
|
1482
|
-
var import_uuid = require_cjs();
|
1483
|
-
var { matcher: match } = (0, import_query2.createMatcher)({});
|
1484
|
-
async function createDocument({
|
1485
|
-
connection,
|
1486
|
-
collection: schema,
|
1487
|
-
initial,
|
1488
|
-
enableTelemetry = false,
|
1489
|
-
bus
|
1490
|
-
}) {
|
1491
|
-
const store = await createStore(connection, { name: schema });
|
1492
|
-
const state = {
|
1493
|
-
current: structuredClone(initial)
|
1494
|
-
};
|
1495
|
-
if (state.current.$id === void 0) {
|
1496
|
-
const meta = Object.assign(state.current, {
|
1497
|
-
$id: (0, import_uuid.v4)(),
|
1498
|
-
$created: (/* @__PURE__ */ new Date()).toJSON(),
|
1499
|
-
$version: 1
|
1500
|
-
});
|
1501
|
-
await store.put(meta);
|
1502
|
-
state.current = meta;
|
1503
|
-
bus.emit({
|
1504
|
-
name: "document:create",
|
1505
|
-
payload: {
|
1506
|
-
type: "document:create",
|
1507
|
-
data: state.current,
|
1508
|
-
timestamp: Date.now()
|
1509
|
-
}
|
1510
|
-
});
|
1511
|
-
}
|
1512
|
-
const operations = {
|
1513
|
-
save: async (update) => {
|
1514
|
-
const { $id } = state.current;
|
1515
|
-
if (!$id)
|
1516
|
-
throw new Error("Document ID is missing.");
|
1517
|
-
state.current.$version = (state.current.$version || 0) + 1;
|
1518
|
-
state.current.$updated = (/* @__PURE__ */ new Date()).toJSON();
|
1519
|
-
await store.put(state.current);
|
1520
|
-
if (!update) {
|
1521
|
-
bus.emit({
|
1522
|
-
name: "document:write",
|
1523
|
-
payload: {
|
1524
|
-
type: "document:write",
|
1525
|
-
data: state.current,
|
1526
|
-
timestamp: Date.now()
|
1527
|
-
}
|
1528
|
-
});
|
1529
|
-
}
|
1530
|
-
return true;
|
1531
|
-
},
|
1532
|
-
update: async (data) => {
|
1533
|
-
state.current = Object.assign(state.current, data);
|
1534
|
-
const saved = await operations.save(true);
|
1535
|
-
if (saved) {
|
1536
|
-
bus.emit({
|
1537
|
-
name: "document:update",
|
1538
|
-
payload: {
|
1539
|
-
type: "document:update",
|
1540
|
-
data: state.current,
|
1541
|
-
timestamp: Date.now()
|
1542
|
-
}
|
1543
|
-
});
|
1544
|
-
}
|
1545
|
-
return saved;
|
1546
|
-
},
|
1547
|
-
delete: async () => {
|
1548
|
-
const { $id } = state.current;
|
1549
|
-
if (!$id)
|
1550
|
-
throw new Error("Document ID is missing.");
|
1551
|
-
await store.delete($id);
|
1552
|
-
bus.emit({
|
1553
|
-
name: "document:delete",
|
1554
|
-
payload: {
|
1555
|
-
type: "document:delete",
|
1556
|
-
data: state.current,
|
1557
|
-
timestamp: Date.now()
|
1558
|
-
}
|
1559
|
-
});
|
1560
|
-
return true;
|
1561
|
-
},
|
1562
|
-
read: async () => {
|
1563
|
-
const id = state.current.$id;
|
1564
|
-
if (!id)
|
1565
|
-
throw new Error("Document ID is missing.");
|
1566
|
-
const storedDoc = await store.getById(id);
|
1567
|
-
if (!storedDoc)
|
1568
|
-
throw new Error("Document not found.");
|
1569
|
-
state.current = structuredClone(storedDoc);
|
1570
|
-
bus.emit({
|
1571
|
-
name: "document:read",
|
1572
|
-
payload: {
|
1573
|
-
type: "document:read",
|
1574
|
-
data: state.current,
|
1575
|
-
timestamp: Date.now()
|
1576
|
-
}
|
1577
|
-
});
|
1578
|
-
return true;
|
1579
|
-
},
|
1580
|
-
subscribe: bus.subscribe
|
1581
|
-
};
|
1582
|
-
const wrappedOperations = enableTelemetry ? createTelemetryProxy(
|
1583
|
-
operations,
|
1584
|
-
{ level: "document", collection: schema, document: state.current.$id },
|
1585
|
-
bus
|
1586
|
-
) : operations;
|
1587
|
-
bus.emit({
|
1588
|
-
name: "document:read",
|
1589
|
-
payload: {
|
1590
|
-
type: "document:read",
|
1591
|
-
data: state.current,
|
1592
|
-
timestamp: Date.now()
|
1593
|
-
}
|
1594
|
-
});
|
1595
|
-
return new Proxy(
|
1596
|
-
{},
|
1597
|
-
{
|
1598
|
-
get(_, prop) {
|
1599
|
-
if (["update", "delete", "subscribe", "read"].includes(prop)) {
|
1600
|
-
return wrappedOperations[prop];
|
1601
|
-
}
|
1602
|
-
return Reflect.get(state.current, prop);
|
1603
|
-
}
|
1604
|
-
}
|
1605
|
-
);
|
1606
|
-
}
|
1607
|
-
async function createDocumentCursor({
|
1608
|
-
connection,
|
1609
|
-
collection: schema,
|
1610
|
-
enableTelemetry = false,
|
1611
|
-
bus
|
1612
|
-
}) {
|
1613
|
-
const store = await createStore(connection, { name: schema });
|
1614
|
-
const operations = {
|
1615
|
-
create: async (initial) => {
|
1616
|
-
const result = await createDocument({
|
1617
|
-
connection,
|
1618
|
-
collection: schema,
|
1619
|
-
initial,
|
1620
|
-
enableTelemetry,
|
1621
|
-
bus
|
1622
|
-
});
|
1623
|
-
bus.emit({
|
1624
|
-
name: "collection:read",
|
1625
|
-
payload: {
|
1626
|
-
type: "collection:read",
|
1627
|
-
model: schema,
|
1628
|
-
timestamp: Date.now()
|
1629
|
-
}
|
1630
|
-
});
|
1631
|
-
return result;
|
1632
|
-
},
|
1633
|
-
find: async (query) => {
|
1634
|
-
const result = await store.cursor(async (value) => {
|
1635
|
-
if (value && match(value, query)) {
|
1636
|
-
return { value, done: true };
|
1637
|
-
}
|
1638
|
-
return { value: null, done: false };
|
1639
|
-
});
|
1640
|
-
if (result) {
|
1641
|
-
const value = await createDocument({
|
1642
|
-
connection,
|
1643
|
-
collection: schema,
|
1644
|
-
initial: result,
|
1645
|
-
enableTelemetry,
|
1646
|
-
bus
|
1647
|
-
});
|
1648
|
-
bus.emit({
|
1649
|
-
name: "collection:read",
|
1650
|
-
payload: {
|
1651
|
-
type: "collection:read",
|
1652
|
-
method: "find",
|
1653
|
-
model: schema,
|
1654
|
-
timestamp: Date.now()
|
1655
|
-
}
|
1656
|
-
});
|
1657
|
-
return value;
|
1658
|
-
}
|
1659
|
-
return null;
|
1660
|
-
},
|
1661
|
-
list: async (query) => {
|
1662
|
-
const state = {
|
1663
|
-
total: await store.count(),
|
1664
|
-
offset: query.type === "offset" ? query.offset : 0,
|
1665
|
-
limit: query.limit,
|
1666
|
-
cursor: query.type === "cursor" ? query.cursor : void 0,
|
1667
|
-
direction: query.type === "cursor" ? query.direction : "forward",
|
1668
|
-
count: 0,
|
1669
|
-
done: false
|
1670
|
-
};
|
1671
|
-
return {
|
1672
|
-
async next() {
|
1673
|
-
const result = query.type === "offset" ? await offsetPaginate(store.cursor, {
|
1674
|
-
...query,
|
1675
|
-
offset: state.offset
|
1676
|
-
}) : await cursorPaginate(store.cursor, {
|
1677
|
-
...query,
|
1678
|
-
cursor: state.cursor
|
1679
|
-
});
|
1680
|
-
state.offset += state.limit;
|
1681
|
-
state.count += result.length;
|
1682
|
-
const value = await Promise.all(
|
1683
|
-
result.map(
|
1684
|
-
(initial) => createDocument({
|
1685
|
-
collection: schema,
|
1686
|
-
connection,
|
1687
|
-
initial,
|
1688
|
-
enableTelemetry,
|
1689
|
-
bus
|
1690
|
-
})
|
1691
|
-
)
|
1692
|
-
);
|
1693
|
-
bus.emit({
|
1694
|
-
name: "collection:read",
|
1695
|
-
payload: {
|
1696
|
-
type: "collection:read",
|
1697
|
-
method: "list",
|
1698
|
-
model: schema,
|
1699
|
-
timestamp: Date.now()
|
1700
|
-
}
|
1701
|
-
});
|
1702
|
-
return {
|
1703
|
-
value,
|
1704
|
-
done: state.count === state.total
|
1705
|
-
};
|
1706
|
-
}
|
1707
|
-
};
|
1708
|
-
},
|
1709
|
-
filter: async (query) => {
|
1710
|
-
const data = [];
|
1711
|
-
await store.cursor(async (value) => {
|
1712
|
-
if (value && match(value, query)) {
|
1713
|
-
data.push(
|
1714
|
-
await createDocument({
|
1715
|
-
connection,
|
1716
|
-
collection: schema,
|
1717
|
-
initial: value,
|
1718
|
-
enableTelemetry,
|
1719
|
-
bus
|
1720
|
-
})
|
1721
|
-
);
|
1722
|
-
}
|
1723
|
-
return { value: null, done: false };
|
1724
|
-
});
|
1725
|
-
bus.emit({
|
1726
|
-
name: "collection:read",
|
1727
|
-
payload: {
|
1728
|
-
type: "collection:read",
|
1729
|
-
method: "filter",
|
1730
|
-
model: schema,
|
1731
|
-
timestamp: Date.now()
|
1732
|
-
}
|
1733
|
-
});
|
1734
|
-
return data;
|
1735
|
-
},
|
1736
|
-
subscribe: bus.subscribe
|
1737
|
-
};
|
1738
|
-
return enableTelemetry ? createTelemetryProxy(
|
1739
|
-
operations,
|
1740
|
-
{ level: "collection", collection: schema },
|
1741
|
-
bus
|
1742
|
-
) : operations;
|
1743
|
-
}
|
1744
|
-
var DatabaseErrorType = /* @__PURE__ */ ((DatabaseErrorType2) => {
|
1745
|
-
DatabaseErrorType2["SCHEMA_NOT_FOUND"] = "SCHEMA_NOT_FOUND";
|
1746
|
-
DatabaseErrorType2["SCHEMA_ALREADY_EXISTS"] = "SCHEMA_ALREADY_EXISTS";
|
1747
|
-
DatabaseErrorType2["INVALID_SCHEMA_NAME"] = "INVALID_SCHEMA_NAME";
|
1748
|
-
DatabaseErrorType2["INVALID_SCHEMA_DEFINITION"] = "INVALID_SCHEMA_DEFINITION";
|
1749
|
-
DatabaseErrorType2["SUBSCRIPTION_FAILED"] = "SUBSCRIPTION_FAILED";
|
1750
|
-
DatabaseErrorType2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
1751
|
-
return DatabaseErrorType2;
|
1752
|
-
})(DatabaseErrorType || {});
|
1753
|
-
var DatabaseError2 = class extends Error {
|
1754
|
-
/**
|
1755
|
-
* The type of error that occurred.
|
1756
|
-
*/
|
1757
|
-
type;
|
1758
|
-
/**
|
1759
|
-
* The schema associated with the error, if applicable.
|
1760
|
-
*/
|
1761
|
-
schema;
|
1762
|
-
/**
|
1763
|
-
* Constructs a new DatabaseErrorClass instance.
|
1764
|
-
* @param type - The type of error that occurred.
|
1765
|
-
* @param message - A human-readable message describing the error.
|
1766
|
-
* @param schema - The schema associated with the error, if applicable.
|
1767
|
-
*/
|
1768
|
-
constructor(type, message, schema) {
|
1769
|
-
super(message);
|
1770
|
-
this.type = type;
|
1771
|
-
this.schema = schema;
|
1772
|
-
}
|
1773
|
-
};
|
1774
|
-
async function DatabaseConnection2(config) {
|
1775
|
-
const bus = (0, import_events3.createEventBus)();
|
1776
|
-
const $index = config.indexSchema || "$schema";
|
1777
|
-
const keyPath = config.keyPath || "$id";
|
1778
|
-
const cache = /* @__PURE__ */ new Map();
|
1779
|
-
if (cache.has(config.name)) {
|
1780
|
-
return cache.get(config.name);
|
1781
|
-
}
|
1782
|
-
let connection = null;
|
1783
|
-
async function getConnection() {
|
1784
|
-
if (!connection) {
|
1785
|
-
connection = await new Promise((resolve, reject) => {
|
1786
|
-
const request = indexedDB.open(config.name);
|
1787
|
-
request.onerror = () => reject(new Error(`Failed to open database: ${request.error}`));
|
1788
|
-
request.onupgradeneeded = (event) => {
|
1789
|
-
const db2 = event.target.result;
|
1790
|
-
if (!db2.objectStoreNames.contains($index)) {
|
1791
|
-
db2.createObjectStore($index, { keyPath });
|
1792
|
-
}
|
1793
|
-
};
|
1794
|
-
request.onsuccess = () => resolve(request.result);
|
1795
|
-
});
|
1796
|
-
}
|
1797
|
-
return connection;
|
1798
|
-
}
|
1799
|
-
const operations = {
|
1800
|
-
collection: async function(name) {
|
1801
|
-
const conn = await getConnection();
|
1802
|
-
if (!conn.objectStoreNames.contains(name)) {
|
1803
|
-
throw new DatabaseError2("SCHEMA_NOT_FOUND", `Collection with name ${name} does not exist`);
|
1804
|
-
}
|
1805
|
-
bus.emit({
|
1806
|
-
name: "collection:read",
|
1807
|
-
payload: {
|
1808
|
-
type: "collection:read",
|
1809
|
-
schema: { name },
|
1810
|
-
timestamp: Date.now()
|
1811
|
-
}
|
1812
|
-
});
|
1813
|
-
return createDocumentCursor({
|
1814
|
-
connection: getConnection,
|
1815
|
-
collection: name,
|
1816
|
-
bus,
|
1817
|
-
enableTelemetry: config.enableTelemetry
|
1818
|
-
});
|
1819
|
-
},
|
1820
|
-
createCollection: async function(schema) {
|
1821
|
-
const con = await getConnection();
|
1822
|
-
if (con.objectStoreNames.contains(schema.name)) {
|
1823
|
-
throw new DatabaseError2("SCHEMA_ALREADY_EXISTS", `Collection with name ${schema.name} exists`);
|
1824
|
-
}
|
1825
|
-
const version = structuredClone(con.version);
|
1826
|
-
con.close();
|
1827
|
-
connection = await new Promise((resolve, reject) => {
|
1828
|
-
const request = indexedDB.open(config.name, version + 1);
|
1829
|
-
request.onerror = () => reject(new Error(`Failed to open database: ${request.error}`));
|
1830
|
-
request.onupgradeneeded = (event) => {
|
1831
|
-
const db2 = event.target.result;
|
1832
|
-
if (!db2.objectStoreNames.contains(schema.name)) {
|
1833
|
-
db2.createObjectStore(schema.name, { keyPath: "$id" });
|
1834
|
-
}
|
1835
|
-
};
|
1836
|
-
request.onsuccess = () => resolve(request.result);
|
1837
|
-
});
|
1838
|
-
const result = await createDocumentCursor({
|
1839
|
-
connection: getConnection,
|
1840
|
-
collection: $index,
|
1841
|
-
bus,
|
1842
|
-
enableTelemetry: config.enableTelemetry
|
1843
|
-
});
|
1844
|
-
await result.create(schema);
|
1845
|
-
bus.emit({
|
1846
|
-
name: "collection:create",
|
1847
|
-
payload: {
|
1848
|
-
type: "collection:create",
|
1849
|
-
schema,
|
1850
|
-
timestamp: Date.now()
|
1851
|
-
}
|
1852
|
-
});
|
1853
|
-
return result;
|
1854
|
-
},
|
1855
|
-
deleteCollection: async function(name) {
|
1856
|
-
const con = await getConnection();
|
1857
|
-
if (!con.objectStoreNames.contains(name)) {
|
1858
|
-
throw new DatabaseError2("SCHEMA_NOT_FOUND", `Collection with name ${name} does not exist`);
|
1859
|
-
}
|
1860
|
-
const version = structuredClone(con.version);
|
1861
|
-
con.close();
|
1862
|
-
connection = await new Promise((resolve, reject) => {
|
1863
|
-
const request = indexedDB.open(config.name, version + 1);
|
1864
|
-
request.onerror = () => reject(new Error(`Failed to open database: ${request.error}`));
|
1865
|
-
request.onupgradeneeded = (event) => {
|
1866
|
-
const db2 = event.target.result;
|
1867
|
-
if (db2.objectStoreNames.contains(name)) {
|
1868
|
-
db2.deleteObjectStore(name);
|
1869
|
-
}
|
1870
|
-
};
|
1871
|
-
request.onsuccess = () => resolve(request.result);
|
1872
|
-
});
|
1873
|
-
const cursor = await createDocumentCursor({
|
1874
|
-
connection: getConnection,
|
1875
|
-
collection: $index,
|
1876
|
-
bus,
|
1877
|
-
enableTelemetry: config.enableTelemetry
|
1878
|
-
});
|
1879
|
-
const model = await cursor.find({
|
1880
|
-
field: "name",
|
1881
|
-
operator: "eq",
|
1882
|
-
value: name
|
1883
|
-
});
|
1884
|
-
try {
|
1885
|
-
await model?.delete();
|
1886
|
-
} catch (error) {
|
1887
|
-
throw new DatabaseError2("INTERNAL_ERROR", error.message);
|
1888
|
-
}
|
1889
|
-
bus.emit({
|
1890
|
-
name: "collection:delete",
|
1891
|
-
payload: {
|
1892
|
-
type: "collection:delete",
|
1893
|
-
schema: model,
|
1894
|
-
timestamp: Date.now()
|
1895
|
-
}
|
1896
|
-
});
|
1897
|
-
return true;
|
1898
|
-
},
|
1899
|
-
updateCollection: async function(schema) {
|
1900
|
-
const con = await getConnection();
|
1901
|
-
if (!con.objectStoreNames.contains(schema.name)) {
|
1902
|
-
throw new DatabaseError2("SCHEMA_NOT_FOUND", `Collection with name ${schema.name} does not exist`);
|
1903
|
-
}
|
1904
|
-
const cursor = await createDocumentCursor({
|
1905
|
-
connection: getConnection,
|
1906
|
-
collection: $index,
|
1907
|
-
enableTelemetry: config.enableTelemetry,
|
1908
|
-
bus
|
1909
|
-
});
|
1910
|
-
const model = await cursor.find({
|
1911
|
-
field: "name",
|
1912
|
-
operator: "eq",
|
1913
|
-
value: schema.name
|
1914
|
-
});
|
1915
|
-
if (!model)
|
1916
|
-
return false;
|
1917
|
-
await model.update(schema);
|
1918
|
-
bus.emit({
|
1919
|
-
name: "collection:update",
|
1920
|
-
payload: {
|
1921
|
-
type: "collection:update",
|
1922
|
-
schema,
|
1923
|
-
timestamp: Date.now()
|
1924
|
-
}
|
1925
|
-
});
|
1926
|
-
return true;
|
1927
|
-
},
|
1928
|
-
subscribe: bus.subscribe,
|
1929
|
-
close: () => {
|
1930
|
-
if (connection) {
|
1931
|
-
connection.close();
|
1932
|
-
}
|
1933
|
-
}
|
1934
|
-
};
|
1935
|
-
const db = config.enableTelemetry ? createTelemetryProxy(operations, { level: "database" }, bus) : operations;
|
1936
|
-
cache.set(config.name, db);
|
1937
|
-
return db;
|
1938
|
-
}
|
1939
|
-
}
|
1940
|
-
});
|
1941
|
-
|
1942
|
-
// src/persistence/webstorage.ts
|
1943
|
-
var import_events = __toESM(require_events());
|
1944
|
-
var WebStoragePersistence = class {
|
1945
|
-
storageKey;
|
1946
|
-
eventBus;
|
1947
|
-
storage;
|
1948
|
-
// Either localStorage or sessionStorage
|
1949
|
-
/**
|
1950
|
-
* Initializes a new instance of WebStoragePersistence.
|
1951
|
-
* @param storageKey The key under which data is stored in web storage (e.g., 'user-profile').
|
1952
|
-
* @param session Optional flag; if true, uses sessionStorage instead of localStorage (default: false).
|
1953
|
-
*/
|
1954
|
-
constructor(storageKey, session = false) {
|
1955
|
-
this.storageKey = storageKey;
|
1956
|
-
this.storage = session ? sessionStorage : localStorage;
|
1957
|
-
this.eventBus = this.initializeEventBus();
|
1958
|
-
if (!session) {
|
1959
|
-
this.setupStorageEventListener();
|
1960
|
-
}
|
1961
|
-
}
|
1962
|
-
/**
|
1963
|
-
* Initializes the event bus with configured settings.
|
1964
|
-
* @returns Configured event bus instance.
|
1965
|
-
*/
|
1966
|
-
initializeEventBus() {
|
1967
|
-
const config = {
|
1968
|
-
async: true,
|
1969
|
-
batchSize: 5,
|
1970
|
-
batchDelay: 16,
|
1971
|
-
errorHandler: (error) => console.error(`Event bus error for ${this.storageKey}:`, error),
|
1972
|
-
crossTab: true,
|
1973
|
-
channelName: `storage_${this.storageKey}`
|
1974
|
-
};
|
1975
|
-
return (0, import_events.createEventBus)(config);
|
1976
|
-
}
|
1977
|
-
/**
|
1978
|
-
* Sets up a listener for native storage events to synchronize across tabs (localStorage only).
|
1979
|
-
*/
|
1980
|
-
setupStorageEventListener() {
|
1981
|
-
window.addEventListener("storage", (event) => {
|
1982
|
-
if (event.key !== this.storageKey || !event.newValue)
|
1983
|
-
return;
|
1984
|
-
try {
|
1985
|
-
const updatedState = JSON.parse(event.newValue);
|
1986
|
-
this.eventBus.emit({
|
1987
|
-
name: "store:updated",
|
1988
|
-
payload: {
|
1989
|
-
storageKey: this.storageKey,
|
1990
|
-
instanceId: "external",
|
1991
|
-
// Placeholder for external updates
|
1992
|
-
state: updatedState
|
1993
|
-
}
|
1994
|
-
});
|
1995
|
-
} catch (error) {
|
1996
|
-
console.error("Failed to parse storage event data:", error);
|
1997
|
-
}
|
1998
|
-
});
|
1999
|
-
}
|
2000
|
-
/**
|
2001
|
-
* Persists the provided state to web storage and notifies subscribers.
|
2002
|
-
* @param instanceId Unique identifier of the instance making the update.
|
2003
|
-
* @param state The state to persist.
|
2004
|
-
* @returns True if successful, false if an error occurs.
|
2005
|
-
*/
|
2006
|
-
set(instanceId, state) {
|
2007
|
-
try {
|
2008
|
-
const serializedState = JSON.stringify(state);
|
2009
|
-
this.storage.setItem(this.storageKey, serializedState);
|
2010
|
-
this.eventBus.emit({
|
2011
|
-
name: "store:updated",
|
2012
|
-
payload: { storageKey: this.storageKey, instanceId, state }
|
2013
|
-
});
|
2014
|
-
return true;
|
2015
|
-
} catch (error) {
|
2016
|
-
console.error(`Failed to persist state to web storage for ${this.storageKey}:`, error);
|
2017
|
-
return false;
|
2018
|
-
}
|
2019
|
-
}
|
2020
|
-
/**
|
2021
|
-
* Retrieves the current state from web storage.
|
2022
|
-
* @returns The persisted state, or null if not found or invalid.
|
2023
|
-
*/
|
2024
|
-
get() {
|
2025
|
-
try {
|
2026
|
-
const serializedData = this.storage.getItem(this.storageKey);
|
2027
|
-
if (!serializedData)
|
2028
|
-
return null;
|
2029
|
-
return JSON.parse(serializedData);
|
2030
|
-
} catch (error) {
|
2031
|
-
console.error(`Failed to retrieve state from web storage for ${this.storageKey}:`, error);
|
2032
|
-
return null;
|
2033
|
-
}
|
2034
|
-
}
|
2035
|
-
/**
|
2036
|
-
* Subscribes to updates in the persisted state, excluding the instance’s own changes.
|
2037
|
-
* @param instanceId Unique identifier of the subscribing instance.
|
2038
|
-
* @param onStateChange Callback to invoke with the updated state.
|
2039
|
-
* @returns Function to unsubscribe from updates.
|
2040
|
-
*/
|
2041
|
-
subscribe(instanceId, onStateChange) {
|
2042
|
-
return this.eventBus.subscribe("store:updated", ({ storageKey, instanceId: sourceId, state }) => {
|
2043
|
-
if (storageKey === this.storageKey && sourceId !== instanceId) {
|
2044
|
-
onStateChange(state);
|
2045
|
-
}
|
2046
|
-
});
|
2047
|
-
}
|
2048
|
-
/**
|
2049
|
-
* Removes the persisted state from web storage.
|
2050
|
-
* @returns True if successful, false if an error occurs.
|
2051
|
-
*/
|
2052
|
-
clear() {
|
2053
|
-
try {
|
2054
|
-
this.storage.removeItem(this.storageKey);
|
2055
|
-
return true;
|
2056
|
-
} catch (error) {
|
2057
|
-
console.error(`Failed to clear persisted state for ${this.storageKey}:`, error);
|
2058
|
-
return false;
|
2059
|
-
}
|
2060
|
-
}
|
2061
|
-
};
|
2062
|
-
|
2063
|
-
// src/persistence/indexedb.ts
|
2064
|
-
var import_events2 = __toESM(require_events());
|
2065
|
-
var import_indexed = __toESM(require_indexed());
|
2066
|
-
var import_query = __toESM(require_query());
|
2067
|
-
var SharedResources = class _SharedResources {
|
2068
|
-
static dbInstances = /* @__PURE__ */ new Map();
|
2069
|
-
static collectionInstances = /* @__PURE__ */ new Map();
|
2070
|
-
static eventBusMap = /* @__PURE__ */ new Map();
|
2071
|
-
static defaultModelName = "stores";
|
2072
|
-
/**
|
2073
|
-
* Get or create a database connection for the specified database name
|
2074
|
-
*/
|
2075
|
-
static getDatabase(config) {
|
2076
|
-
const { database: name, enableTelemetry = false, collection: modelName = _SharedResources.defaultModelName } = config;
|
2077
|
-
if (!_SharedResources.dbInstances.has(name)) {
|
2078
|
-
const dbPromise = (0, import_indexed.DatabaseConnection)({
|
2079
|
-
name,
|
2080
|
-
enableTelemetry
|
2081
|
-
}).then(async (db) => {
|
2082
|
-
try {
|
2083
|
-
await db.createCollection({
|
2084
|
-
name: modelName,
|
2085
|
-
version: "1.0.0",
|
2086
|
-
nestedSchemas: {},
|
2087
|
-
fields: {
|
2088
|
-
store: { name: "store", type: "string", required: true },
|
2089
|
-
// Identifies the store
|
2090
|
-
data: { name: "data", type: "object", required: true }
|
2091
|
-
// Store state
|
2092
|
-
}
|
2093
|
-
});
|
2094
|
-
} catch (error) {
|
2095
|
-
if (error instanceof import_indexed.DatabaseError && error.type !== "SCHEMA_ALREADY_EXISTS") {
|
2096
|
-
throw error;
|
2097
|
-
}
|
2098
|
-
}
|
2099
|
-
return db;
|
2100
|
-
});
|
2101
|
-
_SharedResources.dbInstances.set(name, dbPromise);
|
2102
|
-
}
|
2103
|
-
return _SharedResources.dbInstances.get(name);
|
2104
|
-
}
|
2105
|
-
/**
|
2106
|
-
* Get event bus for a specific store within a database
|
2107
|
-
*/
|
2108
|
-
static getEventBus(dbName, store) {
|
2109
|
-
const channelName = `${dbName}_store_${store}`;
|
2110
|
-
if (!_SharedResources.eventBusMap.has(channelName)) {
|
2111
|
-
_SharedResources.eventBusMap.set(
|
2112
|
-
channelName,
|
2113
|
-
(0, import_events2.createEventBus)({
|
2114
|
-
batchSize: 5,
|
2115
|
-
async: true,
|
2116
|
-
batchDelay: 16,
|
2117
|
-
errorHandler: (error) => console.error(`Event bus error for ${dbName}:${store}:`, error),
|
2118
|
-
crossTab: true,
|
2119
|
-
channelName
|
2120
|
-
})
|
2121
|
-
);
|
2122
|
-
}
|
2123
|
-
return _SharedResources.eventBusMap.get(channelName);
|
2124
|
-
}
|
2125
|
-
/**
|
2126
|
-
* Get collection for a specific database and model (cached)
|
2127
|
-
*/
|
2128
|
-
static getCollection(config) {
|
2129
|
-
const { database: name, collection: modelName = _SharedResources.defaultModelName } = config;
|
2130
|
-
const collectionKey = `${name}:${modelName}`;
|
2131
|
-
if (!_SharedResources.collectionInstances.has(collectionKey)) {
|
2132
|
-
const collectionPromise = _SharedResources.getDatabase(config).then(
|
2133
|
-
(db) => db.collection(modelName)
|
2134
|
-
);
|
2135
|
-
_SharedResources.collectionInstances.set(collectionKey, collectionPromise);
|
2136
|
-
}
|
2137
|
-
return _SharedResources.collectionInstances.get(collectionKey);
|
2138
|
-
}
|
2139
|
-
/**
|
2140
|
-
* Close a specific database connection
|
2141
|
-
*/
|
2142
|
-
static async closeDatabase(dbName) {
|
2143
|
-
const dbPromise = _SharedResources.dbInstances.get(dbName);
|
2144
|
-
if (dbPromise) {
|
2145
|
-
const db = await dbPromise;
|
2146
|
-
db.close();
|
2147
|
-
_SharedResources.dbInstances.delete(dbName);
|
2148
|
-
const collectionKeysToDelete = [];
|
2149
|
-
_SharedResources.collectionInstances.forEach((_, key) => {
|
2150
|
-
if (key.startsWith(`${dbName}:`)) {
|
2151
|
-
collectionKeysToDelete.push(key);
|
2152
|
-
}
|
2153
|
-
});
|
2154
|
-
collectionKeysToDelete.forEach((key) => _SharedResources.collectionInstances.delete(key));
|
2155
|
-
const eventKeysToDelete = [];
|
2156
|
-
_SharedResources.eventBusMap.forEach((bus, key) => {
|
2157
|
-
if (key.startsWith(`${dbName}_store_`)) {
|
2158
|
-
bus.clear();
|
2159
|
-
eventKeysToDelete.push(key);
|
2160
|
-
}
|
2161
|
-
});
|
2162
|
-
eventKeysToDelete.forEach((key) => _SharedResources.eventBusMap.delete(key));
|
2163
|
-
}
|
2164
|
-
}
|
2165
|
-
/**
|
2166
|
-
* Close all database connections
|
2167
|
-
*/
|
2168
|
-
static async closeAll() {
|
2169
|
-
const closePromises = Array.from(_SharedResources.dbInstances.keys()).map(
|
2170
|
-
(dbName) => _SharedResources.closeDatabase(dbName)
|
2171
|
-
);
|
2172
|
-
await Promise.all(closePromises);
|
2173
|
-
}
|
2174
|
-
/**
|
2175
|
-
* Get list of active database connections
|
2176
|
-
*/
|
2177
|
-
static getActiveDatabases() {
|
2178
|
-
return Array.from(_SharedResources.dbInstances.keys());
|
2179
|
-
}
|
2180
|
-
};
|
2181
|
-
var IndexedDBPersistence = class {
|
2182
|
-
collection = null;
|
2183
|
-
collectionPromise;
|
2184
|
-
config;
|
2185
|
-
eventBus;
|
2186
|
-
constructor(config) {
|
2187
|
-
this.config = config;
|
2188
|
-
this.collectionPromise = SharedResources.getCollection(this.config);
|
2189
|
-
this.collectionPromise.then((collection) => {
|
2190
|
-
this.collection = collection;
|
2191
|
-
}).catch((error) => {
|
2192
|
-
console.error(`Failed to initialize collection for store ${this.config.store}:`, error);
|
2193
|
-
});
|
2194
|
-
this.eventBus = SharedResources.getEventBus(this.config.database, this.config.store);
|
2195
|
-
}
|
2196
|
-
async getCollection() {
|
2197
|
-
if (this.collection) {
|
2198
|
-
return this.collection;
|
2199
|
-
}
|
2200
|
-
return this.collectionPromise;
|
2201
|
-
}
|
2202
|
-
async set(id, state) {
|
2203
|
-
try {
|
2204
|
-
const collection = await this.getCollection();
|
2205
|
-
const query = new import_query.QueryBuilder().where({ field: "store", operator: "eq", value: this.config.store }).build();
|
2206
|
-
const existing = await collection.find(query.filters);
|
2207
|
-
const updatedDoc = { store: this.config.store, data: state };
|
2208
|
-
let success;
|
2209
|
-
if (existing) {
|
2210
|
-
success = await existing.update(updatedDoc);
|
2211
|
-
} else {
|
2212
|
-
await collection.create(updatedDoc);
|
2213
|
-
success = true;
|
2214
|
-
}
|
2215
|
-
if (success) {
|
2216
|
-
this.eventBus.emit({
|
2217
|
-
name: "store:updated",
|
2218
|
-
payload: { storageKey: this.config.store, instanceId: id, state }
|
2219
|
-
});
|
2220
|
-
}
|
2221
|
-
return success;
|
2222
|
-
} catch (error) {
|
2223
|
-
console.error(
|
2224
|
-
`Failed to set state for store ${this.config.store} in database ${this.config.database} by instance ${id}:`,
|
2225
|
-
error
|
2226
|
-
);
|
2227
|
-
return false;
|
2228
|
-
}
|
2229
|
-
}
|
2230
|
-
async get() {
|
2231
|
-
try {
|
2232
|
-
const collection = await this.getCollection();
|
2233
|
-
const query = new import_query.QueryBuilder().where({ field: "store", operator: "eq", value: this.config.store }).build();
|
2234
|
-
const document = await collection.find(query.filters);
|
2235
|
-
return document ? document.read().then(() => document.data) : null;
|
2236
|
-
} catch (error) {
|
2237
|
-
console.error(
|
2238
|
-
`Failed to get state for store ${this.config.store} in database ${this.config.database}:`,
|
2239
|
-
error
|
2240
|
-
);
|
2241
|
-
return null;
|
2242
|
-
}
|
2243
|
-
}
|
2244
|
-
subscribe(id, callback) {
|
2245
|
-
const unsubscribe = this.eventBus.subscribe(
|
2246
|
-
"store:updated",
|
2247
|
-
({ storageKey: store, instanceId, state }) => {
|
2248
|
-
if (store === this.config.store && instanceId !== id) {
|
2249
|
-
callback(state);
|
2250
|
-
}
|
2251
|
-
}
|
2252
|
-
);
|
2253
|
-
return unsubscribe;
|
2254
|
-
}
|
2255
|
-
async clear() {
|
2256
|
-
try {
|
2257
|
-
const collection = await this.collectionPromise;
|
2258
|
-
const query = new import_query.QueryBuilder().where({ field: "store", operator: "eq", value: this.config.store }).build();
|
2259
|
-
const document = await collection.find(query.filters);
|
2260
|
-
if (document) {
|
2261
|
-
return await document.delete();
|
2262
|
-
}
|
2263
|
-
return true;
|
2264
|
-
} catch (error) {
|
2265
|
-
console.error(
|
2266
|
-
`Failed to clear state for store ${this.config.store} in database ${this.config.database}:`,
|
2267
|
-
error
|
2268
|
-
);
|
2269
|
-
return false;
|
2270
|
-
}
|
2271
|
-
}
|
2272
|
-
/**
|
2273
|
-
* Close a specific database
|
2274
|
-
*/
|
2275
|
-
async close() {
|
2276
|
-
await SharedResources.closeDatabase(this.config.database);
|
2277
|
-
}
|
2278
|
-
};
|
2279
|
-
export {
|
2280
|
-
IndexedDBPersistence,
|
2281
|
-
WebStoragePersistence
|
2282
|
-
};
|