@seedprotocol/query 0.6.6 → 0.6.7
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/dist/FileCache-BZ2cHsU3.js +95 -0
- package/dist/FileCache-BZ2cHsU3.js.map +1 -0
- package/dist/cache/CacheManager.d.ts +11 -4
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/config.d.ts.map +1 -1
- package/dist/cache/etag.d.ts +1 -1
- package/dist/cache/etag.d.ts.map +1 -1
- package/dist/cache/index.d.ts +6 -5
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/types.d.ts +9 -0
- package/dist/cache/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1080
- package/dist/index.node.d.ts +3 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +9 -0
- package/dist/index.node.js.map +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node.js +3 -2
- package/dist/src-BoSE9m_G.js +985 -0
- package/dist/src-BoSE9m_G.js.map +1 -0
- package/dist/{bootstrap-DQZ8ehyx.js → types-DHRoT30t.js} +14 -2
- package/dist/types-DHRoT30t.js.map +1 -0
- package/package.json +11 -6
- package/dist/bootstrap-DQZ8ehyx.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,985 @@
|
|
|
1
|
+
import { i as e, t } from "./types-DHRoT30t.js";
|
|
2
|
+
import { BaseArweaveClient as n, isKnownArweaveGatewayHostname as r } from "@seedprotocol/arweave";
|
|
3
|
+
import { EasClient as i, GET_SEEDS as a, getItemPropertiesFromEas as o, getItemVersionsFromEas as s, getSeedsBySchemaName as c, pickLatestPropertyAttestationsByRefAndSchema as l, setSchemaUidForSchemaDefinition as u, withExcludeRevokedFilter as d } from "@seedprotocol/eas";
|
|
4
|
+
import f from "pluralize";
|
|
5
|
+
import { sha256 as p } from "@noble/hashes/sha256";
|
|
6
|
+
import { bytesToHex as m, utf8ToBytes as h } from "@noble/hashes/utils";
|
|
7
|
+
//#region src/arweaveUrl.ts
|
|
8
|
+
function g(e) {
|
|
9
|
+
return `https://${n.getHost()}/${e}`;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/listRelationKey.ts
|
|
13
|
+
var ee = /^(.+?)([A-Z][a-zA-Z]+)Ids$/;
|
|
14
|
+
function _(e) {
|
|
15
|
+
let t = ee.exec(e);
|
|
16
|
+
if (t) {
|
|
17
|
+
let e = t[1];
|
|
18
|
+
if (e) return f(e);
|
|
19
|
+
}
|
|
20
|
+
if (e.endsWith("_ids")) {
|
|
21
|
+
let t = e.slice(0, -4), n = t.split("_").filter(Boolean);
|
|
22
|
+
if (n.length >= 2) {
|
|
23
|
+
let e = n[0];
|
|
24
|
+
return e.endsWith("s") ? e : f(e);
|
|
25
|
+
}
|
|
26
|
+
return f(t);
|
|
27
|
+
}
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
function v(e, t) {
|
|
31
|
+
for (let n of Object.keys(e)) n !== t && _(n) === t && delete e[n];
|
|
32
|
+
}
|
|
33
|
+
function y(e) {
|
|
34
|
+
if (Array.isArray(e) || typeof e != "string") return e;
|
|
35
|
+
let t = e.trim();
|
|
36
|
+
if (!t.startsWith("[")) return e;
|
|
37
|
+
try {
|
|
38
|
+
let e = JSON.parse(t);
|
|
39
|
+
if (Array.isArray(e)) return e;
|
|
40
|
+
} catch {}
|
|
41
|
+
return e;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/imageRelationEnrichment.ts
|
|
45
|
+
function b(e) {
|
|
46
|
+
let t = e.storageTransactionId ?? e.storage_transaction_id;
|
|
47
|
+
if (t && typeof t == "string" && t.trim()) try {
|
|
48
|
+
e.arweaveUrl = g(t.trim());
|
|
49
|
+
} catch {}
|
|
50
|
+
}
|
|
51
|
+
var te = b, x = /* @__PURE__ */ new Set([
|
|
52
|
+
"html",
|
|
53
|
+
"file",
|
|
54
|
+
"json"
|
|
55
|
+
]), ne = x, S = "_feedFieldStorageModels", C = "_feedListElementStorageModels";
|
|
56
|
+
function w(e) {
|
|
57
|
+
return e.trim().toLowerCase();
|
|
58
|
+
}
|
|
59
|
+
function T(e) {
|
|
60
|
+
return x.has(w(e));
|
|
61
|
+
}
|
|
62
|
+
var re = T;
|
|
63
|
+
function E(e) {
|
|
64
|
+
let t = w(e);
|
|
65
|
+
return t === "html" ? 0 : t === "file" ? 1 : t === "json" ? 2 : 99;
|
|
66
|
+
}
|
|
67
|
+
var ie = E;
|
|
68
|
+
function D(e) {
|
|
69
|
+
let t = e[S];
|
|
70
|
+
if (typeof t == "object" && t && !Array.isArray(t)) return t;
|
|
71
|
+
}
|
|
72
|
+
var ae = D;
|
|
73
|
+
function O(e) {
|
|
74
|
+
let t = e[C];
|
|
75
|
+
if (typeof t == "object" && t && !Array.isArray(t)) return t;
|
|
76
|
+
}
|
|
77
|
+
var oe = O;
|
|
78
|
+
function k(e, t, n) {
|
|
79
|
+
let r = w(n), i = D(e);
|
|
80
|
+
i || (i = {}, e[S] = i), i[t] = r;
|
|
81
|
+
}
|
|
82
|
+
var se = k;
|
|
83
|
+
function A(e, t, n) {
|
|
84
|
+
let r = O(e);
|
|
85
|
+
r || (r = {}, e[C] = r), r[t] = n.map(w);
|
|
86
|
+
}
|
|
87
|
+
var ce = A, le = [
|
|
88
|
+
"html",
|
|
89
|
+
"Html",
|
|
90
|
+
"body",
|
|
91
|
+
"Body",
|
|
92
|
+
"content",
|
|
93
|
+
"Content"
|
|
94
|
+
], ue = 8e6;
|
|
95
|
+
function de(e) {
|
|
96
|
+
let t = e.trim();
|
|
97
|
+
if (!t.startsWith("http://") && !t.startsWith("https://")) return !1;
|
|
98
|
+
try {
|
|
99
|
+
let e = new URL(t), i = e.hostname.toLowerCase();
|
|
100
|
+
if (i !== n.getHost().toLowerCase() && !r(i)) return !1;
|
|
101
|
+
let a = e.pathname.replace(/^\//, "").split("/").filter(Boolean);
|
|
102
|
+
if (a.length !== 1) return !1;
|
|
103
|
+
let o = a[0];
|
|
104
|
+
return /^[A-Za-z0-9_-]{43}$/.test(o);
|
|
105
|
+
} catch {
|
|
106
|
+
return !1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function fe(e) {
|
|
110
|
+
try {
|
|
111
|
+
let t = await fetch(e, {
|
|
112
|
+
headers: { Accept: "text/html, text/plain, text/markdown, application/json, */*" },
|
|
113
|
+
signal: AbortSignal.timeout(15e3)
|
|
114
|
+
});
|
|
115
|
+
if (!t.ok) return null;
|
|
116
|
+
let n = t.headers.get("content-type") ?? "";
|
|
117
|
+
if (/^(image|video|audio)\//i.test(n)) return null;
|
|
118
|
+
let r = await t.arrayBuffer();
|
|
119
|
+
if (r.byteLength > ue) return null;
|
|
120
|
+
let i = new TextDecoder("utf-8", { fatal: !1 }).decode(r);
|
|
121
|
+
return i.length === 0 || i.includes("\0") ? null : i;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function pe(e, t, n) {
|
|
127
|
+
if (n) try {
|
|
128
|
+
let r = await n({
|
|
129
|
+
propertyName: e,
|
|
130
|
+
value: t
|
|
131
|
+
});
|
|
132
|
+
if (r != null && r.length > 0) return r;
|
|
133
|
+
} catch {}
|
|
134
|
+
return de(t) ? fe(t) : null;
|
|
135
|
+
}
|
|
136
|
+
async function me(e, t, n) {
|
|
137
|
+
let r = e[t];
|
|
138
|
+
if (typeof r != "string" || r.trim() === "") return;
|
|
139
|
+
let i = await pe(t, r, n);
|
|
140
|
+
i !== null && (e[t] = i);
|
|
141
|
+
}
|
|
142
|
+
async function j(e, t) {
|
|
143
|
+
let n = t?.readStorageBody;
|
|
144
|
+
for (let t of e) {
|
|
145
|
+
let e = /* @__PURE__ */ new Set([...le]), r = D(t);
|
|
146
|
+
if (r) for (let [t, n] of Object.entries(r)) T(n) && e.add(t);
|
|
147
|
+
for (let r of e) await me(t, r, n);
|
|
148
|
+
let i = O(t);
|
|
149
|
+
if (i) for (let [e, r] of Object.entries(i)) {
|
|
150
|
+
let i = t[e];
|
|
151
|
+
if (!Array.isArray(i)) continue;
|
|
152
|
+
let a = Math.min(r.length, i.length);
|
|
153
|
+
for (let t = 0; t < a; t++) {
|
|
154
|
+
if (!T(r[t])) continue;
|
|
155
|
+
let a = i[t];
|
|
156
|
+
if (typeof a != "string") continue;
|
|
157
|
+
let o = await pe(e, a, n);
|
|
158
|
+
o !== null && (i[t] = o);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
var he = j;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/parseEasPropertyMetadata.ts
|
|
166
|
+
function M(e) {
|
|
167
|
+
let t = typeof e == "string" ? e.trim() : "";
|
|
168
|
+
if (!t) return {
|
|
169
|
+
ok: !1,
|
|
170
|
+
reason: "empty"
|
|
171
|
+
};
|
|
172
|
+
let n;
|
|
173
|
+
try {
|
|
174
|
+
n = JSON.parse(t);
|
|
175
|
+
} catch (e) {
|
|
176
|
+
return {
|
|
177
|
+
ok: !1,
|
|
178
|
+
reason: "parse",
|
|
179
|
+
error: e
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return !Array.isArray(n) || n.length === 0 || !n[0]?.value ? {
|
|
183
|
+
ok: !1,
|
|
184
|
+
reason: "shape"
|
|
185
|
+
} : {
|
|
186
|
+
ok: !0,
|
|
187
|
+
metadata: n[0].value
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
var ge = M;
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/parseEasRelationPropertyName.ts
|
|
193
|
+
function N(e) {
|
|
194
|
+
let [t, n, r] = e.split("_");
|
|
195
|
+
if (!t || !n) return null;
|
|
196
|
+
let i = r === "ids";
|
|
197
|
+
return {
|
|
198
|
+
propertyName: t.endsWith("s") ? t : t + "s",
|
|
199
|
+
modelName: n,
|
|
200
|
+
isList: i
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/source/remote.ts
|
|
205
|
+
function _e(e, t) {
|
|
206
|
+
let n = new Date(e, t - 1, 1), r = new Date(e, t, 0, 23, 59, 59);
|
|
207
|
+
return {
|
|
208
|
+
startTs: Math.floor(n.getTime() / 1e3),
|
|
209
|
+
endTs: Math.floor(r.getTime() / 1e3) + 1
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function P() {
|
|
213
|
+
return {
|
|
214
|
+
kind: "remote",
|
|
215
|
+
async getSeedByUid(e) {
|
|
216
|
+
let { itemSeeds: t } = await i.getEasClient().request(a, {
|
|
217
|
+
where: d({ id: { equals: e } }),
|
|
218
|
+
take: 1,
|
|
219
|
+
skip: 0
|
|
220
|
+
});
|
|
221
|
+
return (t ?? [])[0] ?? null;
|
|
222
|
+
},
|
|
223
|
+
async listSeedsBySchemaName(e, t) {
|
|
224
|
+
return await c(e, t.limit, t.skip);
|
|
225
|
+
},
|
|
226
|
+
async listSeedsBySchemaNameForMonth(e, t, n) {
|
|
227
|
+
let { startTs: r, endTs: o } = _e(t, n), s = d({ AND: [{ schema: { is: { schemaNames: { some: { name: { equals: e } } } } } }, { timeCreated: {
|
|
228
|
+
gte: r,
|
|
229
|
+
lt: o
|
|
230
|
+
} }] }), { itemSeeds: c } = await i.getEasClient().request(a, {
|
|
231
|
+
where: s,
|
|
232
|
+
take: 1e3,
|
|
233
|
+
skip: 0
|
|
234
|
+
});
|
|
235
|
+
return c ?? [];
|
|
236
|
+
},
|
|
237
|
+
async getVersionsForSeed(e) {
|
|
238
|
+
return await s({ seedUids: [e] });
|
|
239
|
+
},
|
|
240
|
+
async getVersionsForSeeds(e) {
|
|
241
|
+
return e.length === 0 ? [] : await s({ seedUids: e });
|
|
242
|
+
},
|
|
243
|
+
async getPropertiesForVersionUids(e) {
|
|
244
|
+
return e.length === 0 ? [] : await o({ versionUids: e });
|
|
245
|
+
},
|
|
246
|
+
async getSeedsByUids(e) {
|
|
247
|
+
if (e.length === 0) return [];
|
|
248
|
+
let { itemSeeds: t } = await i.getEasClient().request(a, {
|
|
249
|
+
where: d({ id: { in: e } }),
|
|
250
|
+
take: e.length || 1,
|
|
251
|
+
skip: 0
|
|
252
|
+
});
|
|
253
|
+
return t ?? [];
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
var F = null;
|
|
258
|
+
function I() {
|
|
259
|
+
return F ||= P(), F;
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/assembleSeeds.ts
|
|
263
|
+
var L = "image", R = ["0x0000000000000000000000000000000000000000000000000000000000000020"], z = /* @__PURE__ */ new Set([
|
|
264
|
+
"seedUid",
|
|
265
|
+
"SeedUid",
|
|
266
|
+
"timeCreated",
|
|
267
|
+
"attester",
|
|
268
|
+
"Attester",
|
|
269
|
+
"storage_transaction_id",
|
|
270
|
+
"storage_provider_transaction_id",
|
|
271
|
+
"storageTransactionId",
|
|
272
|
+
"storageProviderTransactionId",
|
|
273
|
+
"versionUid"
|
|
274
|
+
]), B = (e) => e.replace(/_([a-z])/g, (e, t) => t.toUpperCase());
|
|
275
|
+
function ve() {
|
|
276
|
+
return {
|
|
277
|
+
seedUidToModelType: /* @__PURE__ */ new Map(),
|
|
278
|
+
relatedSeedUids: /* @__PURE__ */ new Set(),
|
|
279
|
+
versionUidToSeedUid: /* @__PURE__ */ new Map(),
|
|
280
|
+
assembledItems: /* @__PURE__ */ new Map(),
|
|
281
|
+
versionsBySeedUid: /* @__PURE__ */ new Map(),
|
|
282
|
+
latestVersionUidsBySeedUid: /* @__PURE__ */ new Map()
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function V(e, t) {
|
|
286
|
+
!e.seedUid && !e.SeedUid ? (e.seedUid = t, e.SeedUid = t) : e.seedUid && !e.SeedUid ? e.SeedUid = e.seedUid : e.SeedUid && !e.seedUid && (e.seedUid = e.SeedUid), e.attester && !e.Attester ? e.Attester = e.attester : e.Attester && !e.attester && (e.attester = e.Attester);
|
|
287
|
+
}
|
|
288
|
+
async function ye(e, t) {
|
|
289
|
+
let n = M(t.decodedDataJson);
|
|
290
|
+
if (!n.ok) {
|
|
291
|
+
let { id: e, refUID: r, schemaId: i } = t;
|
|
292
|
+
n.reason === "empty" ? console.warn("[query] [processItemProperty] empty decodedDataJson for property:", e, r, i) : n.reason === "parse" ? console.warn("[query] [processItemProperty] failed to parse decodedDataJson for property:", e, r, i, n.error) : console.warn("[query] [processItemProperty] invalid decodedDataJson structure for property:", e, r, i);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
let r = n.metadata, i = r.name;
|
|
296
|
+
if (!i) return;
|
|
297
|
+
let a = t.schemaId;
|
|
298
|
+
u({
|
|
299
|
+
text: i,
|
|
300
|
+
schemaUid: a
|
|
301
|
+
});
|
|
302
|
+
let o = !1, s = !1, c = r.type, l = (c === "bytes32" || c === "bytes32[]") && i !== "storage_transaction_id" && i !== "storage_provider_transaction_id", d = !l && (i.endsWith("_id") || i.endsWith("_ids")) && i !== "storage_transaction_id" && i !== "storage_provider_transaction_id";
|
|
303
|
+
if (l || d) {
|
|
304
|
+
if (o = !0, Array.isArray(r.value)) {
|
|
305
|
+
if (s = !0, d) {
|
|
306
|
+
let e = N(i);
|
|
307
|
+
e && (i = e.propertyName);
|
|
308
|
+
}
|
|
309
|
+
r.value.forEach((t) => {
|
|
310
|
+
R.includes(t) || e.relatedSeedUids.add(t);
|
|
311
|
+
});
|
|
312
|
+
} else R.includes(r.value) || e.relatedSeedUids.add(r.value);
|
|
313
|
+
}
|
|
314
|
+
let f = r.value;
|
|
315
|
+
o && s && Array.isArray(f) ? f = f.map((e) => String(e)) : typeof f != "string" && (f = JSON.stringify(f));
|
|
316
|
+
let p = e.versionUidToSeedUid.get(t.refUID);
|
|
317
|
+
if (!p) return;
|
|
318
|
+
let m = e.assembledItems.get(p) || {};
|
|
319
|
+
m[i] = f;
|
|
320
|
+
let h = B(i);
|
|
321
|
+
h !== i && (m[h] = f), e.assembledItems.set(p, m);
|
|
322
|
+
}
|
|
323
|
+
async function be(e, t, n) {
|
|
324
|
+
let r = [];
|
|
325
|
+
for (let n = 0; n < t.length; n++) {
|
|
326
|
+
let i = t[n];
|
|
327
|
+
if (!i) continue;
|
|
328
|
+
r.push(i.id);
|
|
329
|
+
let a = i.schema?.schemaNames?.[0]?.name ?? "unknown";
|
|
330
|
+
e.seedUidToModelType.set(i.id, a), e.assembledItems.has(i.id) || e.assembledItems.set(i.id, {
|
|
331
|
+
seedUid: i.id,
|
|
332
|
+
timeCreated: i.timeCreated,
|
|
333
|
+
attester: i.attester
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
if (r.length === 0) return;
|
|
337
|
+
let i = await n.getVersionsForSeeds(r);
|
|
338
|
+
for (let t = 0; t < i.length; t++) {
|
|
339
|
+
let n = i[t], r = n.refUID;
|
|
340
|
+
e.versionUidToSeedUid.set(n.id, r);
|
|
341
|
+
let a = e.versionsBySeedUid.get(r) || [];
|
|
342
|
+
e.versionsBySeedUid.set(r, [...a, n]);
|
|
343
|
+
}
|
|
344
|
+
let a = [];
|
|
345
|
+
for (let [t, n] of e.versionsBySeedUid.entries()) {
|
|
346
|
+
if (e.latestVersionUidsBySeedUid.has(t)) continue;
|
|
347
|
+
let r = [...n].sort((e, t) => t.timeCreated - e.timeCreated)[0];
|
|
348
|
+
r && (a.push(r.id), e.latestVersionUidsBySeedUid.set(t, r.id));
|
|
349
|
+
}
|
|
350
|
+
if (a.length === 0) return;
|
|
351
|
+
let o = await n.getPropertiesForVersionUids(a), s = l(o);
|
|
352
|
+
for (let t = 0; t < s.length; t++) await ye(e, s[t]);
|
|
353
|
+
}
|
|
354
|
+
function xe(e, t) {
|
|
355
|
+
let n = Array.from(e.assembledItems.entries()).filter(([n]) => e.seedUidToModelType.get(n) === t);
|
|
356
|
+
for (let [, t] of n) {
|
|
357
|
+
let n = Object.keys(t).filter((e) => !e.startsWith("_") && !z.has(e));
|
|
358
|
+
for (let r of n) {
|
|
359
|
+
let n = t[r], i = y(n);
|
|
360
|
+
if (i !== n && Array.isArray(i) && (t[r] = i, n = i), Array.isArray(n)) {
|
|
361
|
+
let i = n;
|
|
362
|
+
if (!i.some((t) => typeof t == "string" && !R.includes(t) && e.assembledItems.has(t))) continue;
|
|
363
|
+
let a = [], o = [], s = !1;
|
|
364
|
+
for (let t of i) {
|
|
365
|
+
if (typeof t != "string" || R.includes(t)) {
|
|
366
|
+
a.push(String(t)), o.push("unknown");
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
let n = e.seedUidToModelType.get(t) ?? "unknown";
|
|
370
|
+
if (n === L) {
|
|
371
|
+
a.push(t), o.push(L);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
let r = e.assembledItems.get(t), i = r?.storageTransactionId ?? r?.storage_transaction_id;
|
|
375
|
+
if (i && typeof i == "string" && i.trim()) try {
|
|
376
|
+
a.push(g(i)), o.push(n), s = !0;
|
|
377
|
+
} catch {
|
|
378
|
+
a.push(t), o.push(n);
|
|
379
|
+
}
|
|
380
|
+
else a.push(t), o.push(n);
|
|
381
|
+
}
|
|
382
|
+
if (s) {
|
|
383
|
+
let e = _(r);
|
|
384
|
+
if (t[e] = a, A(t, e, o), v(t, e), e !== r) {
|
|
385
|
+
delete t[r];
|
|
386
|
+
let e = B(r);
|
|
387
|
+
e !== r && delete t[e];
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} else if (typeof n == "string") {
|
|
391
|
+
if (R.includes(n) || !e.assembledItems.has(n)) continue;
|
|
392
|
+
let i = e.assembledItems.get(n);
|
|
393
|
+
if (e.seedUidToModelType.get(n) === L) continue;
|
|
394
|
+
let a = i?.storageTransactionId ?? i?.storage_transaction_id;
|
|
395
|
+
if (a && typeof a == "string" && a.trim()) try {
|
|
396
|
+
let i = r.endsWith("_id") ? r.replace(/_id$/, "") : r;
|
|
397
|
+
t[i] = g(a);
|
|
398
|
+
let o = e.seedUidToModelType.get(n) ?? "unknown";
|
|
399
|
+
k(t, i, o);
|
|
400
|
+
let s = B(i);
|
|
401
|
+
if (s !== i && k(t, s, o), i !== r) {
|
|
402
|
+
delete t[r];
|
|
403
|
+
let e = B(r);
|
|
404
|
+
e !== r && delete t[e];
|
|
405
|
+
}
|
|
406
|
+
} catch {}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function Se(e, t, n) {
|
|
412
|
+
if (!n) return;
|
|
413
|
+
let r = Array.from(e.assembledItems.entries()).filter(([n]) => e.seedUidToModelType.get(n) === t);
|
|
414
|
+
for (let [, t] of r) {
|
|
415
|
+
let n = Object.keys(t).filter((e) => !e.startsWith("_") && !z.has(e));
|
|
416
|
+
for (let r of n) {
|
|
417
|
+
let n = t[r], i = y(n);
|
|
418
|
+
i !== n && Array.isArray(i) && (t[r] = i, n = i);
|
|
419
|
+
let a = Array.isArray(n), o = a ? n : [n], s = [], c = !1;
|
|
420
|
+
for (let t of o) {
|
|
421
|
+
if (typeof t != "string" || R.includes(t)) {
|
|
422
|
+
s.push(t);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
let n = e.assembledItems.get(t);
|
|
426
|
+
if (!n) {
|
|
427
|
+
s.push(t);
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
let r = n?.storageTransactionId ?? n?.storage_transaction_id;
|
|
431
|
+
if (e.seedUidToModelType.get(t) === L) {
|
|
432
|
+
let e = { ...n };
|
|
433
|
+
V(e, t), e.schemaName = L, b(e), s.push(e), c = !0;
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (r && typeof r == "string" && r.trim()) {
|
|
437
|
+
s.push(t);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
let i = { ...n };
|
|
441
|
+
V(i, t), s.push(i), c = !0;
|
|
442
|
+
}
|
|
443
|
+
if (c) {
|
|
444
|
+
let e = a ? _(r) : r.endsWith("_id") ? r.replace(/_id$/, "") : r;
|
|
445
|
+
if (t[e] = a ? s : s[0], v(t, e), e !== r) {
|
|
446
|
+
delete t[r];
|
|
447
|
+
let e = B(r);
|
|
448
|
+
e !== r && delete t[e];
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function Ce(e, t) {
|
|
455
|
+
return Array.from(e.assembledItems.entries()).filter(([n]) => e.seedUidToModelType.get(n) === t).map(([n, r]) => {
|
|
456
|
+
let i = e.latestVersionUidsBySeedUid.get(n) ?? "";
|
|
457
|
+
i && (r.versionUid = i), V(r, n);
|
|
458
|
+
let a = typeof r.timeCreated == "number" ? r.timeCreated : 0;
|
|
459
|
+
return {
|
|
460
|
+
seedUid: n,
|
|
461
|
+
schemaName: t,
|
|
462
|
+
attester: typeof r.attester == "string" ? r.attester : typeof r.Attester == "string" ? r.Attester : void 0,
|
|
463
|
+
timeCreated: a,
|
|
464
|
+
versionUid: i,
|
|
465
|
+
data: r
|
|
466
|
+
};
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
async function H(e, t, n, r = I()) {
|
|
470
|
+
let i = n?.expandRelations !== !1, a = n?.hydrateStorage !== !1, o = ve();
|
|
471
|
+
await be(o, t, r);
|
|
472
|
+
let s = Array.from(o.relatedSeedUids).filter((e) => !o.assembledItems.has(e));
|
|
473
|
+
s.length > 0 && await be(o, await r.getSeedsByUids(s), r), xe(o, e), Se(o, e, i);
|
|
474
|
+
let c = Ce(o, e);
|
|
475
|
+
return a && await j(c.map((e) => e.data), r.readStorageBody ? { readStorageBody: r.readStorageBody.bind(r) } : void 0), c;
|
|
476
|
+
}
|
|
477
|
+
//#endregion
|
|
478
|
+
//#region src/changelog.ts
|
|
479
|
+
var we = (e) => e.replace(/_([a-z])/g, (e, t) => t.toUpperCase());
|
|
480
|
+
function U(e, t) {
|
|
481
|
+
if (Object.is(e, t)) return !0;
|
|
482
|
+
if (e === void 0 || t === void 0) return !1;
|
|
483
|
+
if (e === null || t === null) return e === t;
|
|
484
|
+
if (typeof e != typeof t || typeof e != "object") return !1;
|
|
485
|
+
try {
|
|
486
|
+
return JSON.stringify(e) === JSON.stringify(t);
|
|
487
|
+
} catch {
|
|
488
|
+
return !1;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function W(e) {
|
|
492
|
+
let t = M(e.decodedDataJson);
|
|
493
|
+
if (!t.ok) return null;
|
|
494
|
+
let n = t.metadata, r = n.name;
|
|
495
|
+
if (!r) return null;
|
|
496
|
+
let i = n.type, a = (i === "bytes32" || i === "bytes32[]") && r !== "storage_transaction_id" && r !== "storage_provider_transaction_id", o = !a && (r.endsWith("_id") || r.endsWith("_ids")) && r !== "storage_transaction_id" && r !== "storage_provider_transaction_id", s = !1, c = !1;
|
|
497
|
+
if ((a || o) && (s = !0, Array.isArray(n.value) && (c = !0, o))) {
|
|
498
|
+
let e = N(r);
|
|
499
|
+
e?.isList && (r = e.propertyName);
|
|
500
|
+
}
|
|
501
|
+
let l = n.value;
|
|
502
|
+
s && c && Array.isArray(l) ? l = l.map((e) => String(e)) : typeof l != "string" && (l = JSON.stringify(l));
|
|
503
|
+
let u = we(r);
|
|
504
|
+
return {
|
|
505
|
+
propertyName: r,
|
|
506
|
+
value: l,
|
|
507
|
+
camelName: u === r ? void 0 : u
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function Te(e) {
|
|
511
|
+
let t = {};
|
|
512
|
+
for (let n of e) {
|
|
513
|
+
let e = W(n);
|
|
514
|
+
e && (t[e.propertyName] = e.value, e.camelName && (t[e.camelName] = e.value));
|
|
515
|
+
}
|
|
516
|
+
return t;
|
|
517
|
+
}
|
|
518
|
+
function Ee(e) {
|
|
519
|
+
let t = [], n = {};
|
|
520
|
+
for (let r of e) {
|
|
521
|
+
let e = r.data, i = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(e)]), a = [];
|
|
522
|
+
for (let t of i) U(n[t], e[t]) || a.push(t);
|
|
523
|
+
a.sort(), t.push({
|
|
524
|
+
type: "version",
|
|
525
|
+
at: r.at,
|
|
526
|
+
versionUid: r.versionUid,
|
|
527
|
+
before: { ...n },
|
|
528
|
+
after: { ...e },
|
|
529
|
+
changedKeys: a
|
|
530
|
+
}), n = e;
|
|
531
|
+
}
|
|
532
|
+
return t;
|
|
533
|
+
}
|
|
534
|
+
function De(e) {
|
|
535
|
+
let t = [...e].sort((e, t) => e.timeCreated === t.timeCreated ? e.id.localeCompare(t.id) : e.timeCreated - t.timeCreated), n = /* @__PURE__ */ new Map(), r = [];
|
|
536
|
+
for (let e of t) {
|
|
537
|
+
let t = W(e);
|
|
538
|
+
if (!t) continue;
|
|
539
|
+
let i = [t.propertyName];
|
|
540
|
+
t.camelName && i.push(t.camelName);
|
|
541
|
+
let a = n.has(t.propertyName) ? n.get(t.propertyName) : void 0, o = t.value;
|
|
542
|
+
U(a, o) || r.push({
|
|
543
|
+
type: "property",
|
|
544
|
+
at: e.timeCreated,
|
|
545
|
+
versionUid: e.refUID,
|
|
546
|
+
property: t.propertyName,
|
|
547
|
+
attestationUid: e.id,
|
|
548
|
+
previousValue: a,
|
|
549
|
+
nextValue: o
|
|
550
|
+
}), n.set(t.propertyName, o), t.camelName && n.set(t.camelName, o);
|
|
551
|
+
}
|
|
552
|
+
return r;
|
|
553
|
+
}
|
|
554
|
+
function Oe(e, t) {
|
|
555
|
+
let n = e;
|
|
556
|
+
if (typeof t?.since == "number") {
|
|
557
|
+
let e = t.since;
|
|
558
|
+
n = n.filter((t) => t.at >= e);
|
|
559
|
+
}
|
|
560
|
+
return typeof t?.limit == "number" && t.limit >= 0 && (n = [...n].sort((e, t) => t.at === e.at ? 0 : t.at - e.at).slice(0, t.limit).reverse()), n;
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/assembleChangelog.ts
|
|
564
|
+
async function ke(e, t, n = I()) {
|
|
565
|
+
let r = t?.changelog ?? {}, i = r.granularity ?? "version", a = [...await n.getVersionsForSeed(e)].sort((e, t) => e.timeCreated - t.timeCreated);
|
|
566
|
+
if (a.length === 0) return {
|
|
567
|
+
latestVersionUid: "",
|
|
568
|
+
changelog: []
|
|
569
|
+
};
|
|
570
|
+
let o = a[a.length - 1].id, s = a.map((e) => e.id), c = await n.getPropertiesForVersionUids(s), u;
|
|
571
|
+
if (i === "property") u = De(c);
|
|
572
|
+
else {
|
|
573
|
+
let e = /* @__PURE__ */ new Map();
|
|
574
|
+
for (let t of c) {
|
|
575
|
+
let n = e.get(t.refUID) ?? [];
|
|
576
|
+
n.push(t), e.set(t.refUID, n);
|
|
577
|
+
}
|
|
578
|
+
let t = [];
|
|
579
|
+
for (let n of a) {
|
|
580
|
+
let r = e.get(n.id) ?? [], i = l(r);
|
|
581
|
+
t.push({
|
|
582
|
+
versionUid: n.id,
|
|
583
|
+
at: n.timeCreated,
|
|
584
|
+
data: Te(i)
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
u = Ee(t);
|
|
588
|
+
}
|
|
589
|
+
return {
|
|
590
|
+
latestVersionUid: o,
|
|
591
|
+
changelog: Oe(u, r)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region src/cache/etag.ts
|
|
596
|
+
function Ae(e) {
|
|
597
|
+
return `"${m(p(h(e))).substring(0, 16)}"`;
|
|
598
|
+
}
|
|
599
|
+
function je(e, t, n) {
|
|
600
|
+
return Ae(`${e}-data-${t}-${n}`);
|
|
601
|
+
}
|
|
602
|
+
function Me(e, t, n, r) {
|
|
603
|
+
return Ae(`${e}-${t}-${n}-${r}`);
|
|
604
|
+
}
|
|
605
|
+
//#endregion
|
|
606
|
+
//#region src/cache/MemoryCache.ts
|
|
607
|
+
var Ne = class {
|
|
608
|
+
collectionCache = /* @__PURE__ */ new Map();
|
|
609
|
+
itemCache = /* @__PURE__ */ new Map();
|
|
610
|
+
config;
|
|
611
|
+
refreshLocks = /* @__PURE__ */ new Map();
|
|
612
|
+
constructor(e) {
|
|
613
|
+
this.config = e;
|
|
614
|
+
}
|
|
615
|
+
itemKey(e, t) {
|
|
616
|
+
return `${e}:${t}`;
|
|
617
|
+
}
|
|
618
|
+
getCollection(e) {
|
|
619
|
+
let t = this.collectionCache.get(e);
|
|
620
|
+
return t ? Math.floor(Date.now() / 1e3) - t.lastUpdated > this.config.ttl ? (this.collectionCache.delete(e), null) : t : null;
|
|
621
|
+
}
|
|
622
|
+
setCollection(e, t) {
|
|
623
|
+
let n = Math.floor(Date.now() / 1e3), r = 0, i = "";
|
|
624
|
+
for (let e of t) e.timeCreated && e.timeCreated > r && (r = e.timeCreated, i = e.seedUid);
|
|
625
|
+
r === 0 && (r = n);
|
|
626
|
+
let a = je(e, r, t.length), o = {
|
|
627
|
+
items: t.map((e) => ({
|
|
628
|
+
...e,
|
|
629
|
+
data: { ...e.data }
|
|
630
|
+
})),
|
|
631
|
+
lastProcessedTimestamp: r,
|
|
632
|
+
lastProcessedItemId: i,
|
|
633
|
+
lastUpdated: n,
|
|
634
|
+
etag: a
|
|
635
|
+
};
|
|
636
|
+
return this.collectionCache.set(e, o), o;
|
|
637
|
+
}
|
|
638
|
+
getItem(e, t) {
|
|
639
|
+
let n = this.itemCache.get(this.itemKey(e, t));
|
|
640
|
+
return n ? Math.floor(Date.now() / 1e3) - n.lastUpdated > this.config.ttl ? (this.itemCache.delete(this.itemKey(e, t)), null) : n : null;
|
|
641
|
+
}
|
|
642
|
+
setItem(e, t) {
|
|
643
|
+
let n = Math.floor(Date.now() / 1e3), r = Me(e.seedUid, e.versionUid, e.timeCreated, t), i = {
|
|
644
|
+
...e,
|
|
645
|
+
data: { ...e.data }
|
|
646
|
+
};
|
|
647
|
+
e.changelog && (i.changelog = [...e.changelog]);
|
|
648
|
+
let a = {
|
|
649
|
+
record: i,
|
|
650
|
+
lastUpdated: n,
|
|
651
|
+
etag: r,
|
|
652
|
+
optionsKey: t
|
|
653
|
+
};
|
|
654
|
+
return this.itemCache.set(this.itemKey(e.seedUid, t), a), a;
|
|
655
|
+
}
|
|
656
|
+
clearCollection(e) {
|
|
657
|
+
this.collectionCache.delete(e);
|
|
658
|
+
}
|
|
659
|
+
clearItem(e, t) {
|
|
660
|
+
if (t) {
|
|
661
|
+
this.itemCache.delete(this.itemKey(e, t));
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
for (let t of this.itemCache.keys()) t.startsWith(`${e}:`) && this.itemCache.delete(t);
|
|
665
|
+
}
|
|
666
|
+
clearAll() {
|
|
667
|
+
this.collectionCache.clear(), this.itemCache.clear();
|
|
668
|
+
}
|
|
669
|
+
async withRefreshLock(e, t) {
|
|
670
|
+
let n = this.refreshLocks.get(e);
|
|
671
|
+
if (n) return n;
|
|
672
|
+
let r = (async () => {
|
|
673
|
+
try {
|
|
674
|
+
return await t();
|
|
675
|
+
} finally {
|
|
676
|
+
this.refreshLocks.delete(e);
|
|
677
|
+
}
|
|
678
|
+
})();
|
|
679
|
+
return this.refreshLocks.set(e, r), r;
|
|
680
|
+
}
|
|
681
|
+
updateConfig(e) {
|
|
682
|
+
this.config = {
|
|
683
|
+
...this.config,
|
|
684
|
+
...e
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
getStats() {
|
|
688
|
+
return {
|
|
689
|
+
collectionCount: this.collectionCache.size,
|
|
690
|
+
itemCount: this.itemCache.size,
|
|
691
|
+
activeLocks: this.refreshLocks.size
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
}, Pe = () => null;
|
|
695
|
+
function Fe(e) {
|
|
696
|
+
Pe = e;
|
|
697
|
+
}
|
|
698
|
+
var G = class {
|
|
699
|
+
memoryCache;
|
|
700
|
+
persistent;
|
|
701
|
+
config;
|
|
702
|
+
stats = {
|
|
703
|
+
hits: 0,
|
|
704
|
+
misses: 0,
|
|
705
|
+
refreshes: 0,
|
|
706
|
+
errors: 0
|
|
707
|
+
};
|
|
708
|
+
constructor(e, t) {
|
|
709
|
+
this.config = e, this.memoryCache = new Ne(e), this.persistent = t === void 0 ? Pe(e) : t;
|
|
710
|
+
}
|
|
711
|
+
get enabled() {
|
|
712
|
+
return this.config.enabled;
|
|
713
|
+
}
|
|
714
|
+
getConfig() {
|
|
715
|
+
return { ...this.config };
|
|
716
|
+
}
|
|
717
|
+
async getCollection(e) {
|
|
718
|
+
if (!this.config.enabled) return null;
|
|
719
|
+
try {
|
|
720
|
+
let t = this.memoryCache.getCollection(e);
|
|
721
|
+
return t ? (this.stats.hits++, t) : (t = await this.persistent?.getCollection(e) ?? null, t ? (this.memoryCache.setCollection(e, t.items), this.stats.hits++, t) : (this.stats.misses++, null));
|
|
722
|
+
} catch (t) {
|
|
723
|
+
return console.error(`Error getting query collection cache for ${e}:`, t), this.stats.errors++, null;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
async setCollection(e, t) {
|
|
727
|
+
if (!this.config.enabled) return null;
|
|
728
|
+
try {
|
|
729
|
+
let n = this.memoryCache.setCollection(e, t);
|
|
730
|
+
return await this.persistent?.setCollection(e, n), n;
|
|
731
|
+
} catch (t) {
|
|
732
|
+
return console.error(`Error setting query collection cache for ${e}:`, t), this.stats.errors++, null;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
async getItem(e, t) {
|
|
736
|
+
if (!this.config.enabled) return null;
|
|
737
|
+
try {
|
|
738
|
+
let n = this.memoryCache.getItem(e, t);
|
|
739
|
+
return n ? (this.stats.hits++, n) : (n = await this.persistent?.getItem(e, t) ?? null, n ? (this.memoryCache.setItem(n.record, t), this.stats.hits++, n) : (this.stats.misses++, null));
|
|
740
|
+
} catch (t) {
|
|
741
|
+
return console.error(`Error getting query item cache for ${e}:`, t), this.stats.errors++, null;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
async setItem(e, t) {
|
|
745
|
+
if (!this.config.enabled) return null;
|
|
746
|
+
try {
|
|
747
|
+
let n = this.memoryCache.setItem(e, t);
|
|
748
|
+
return await this.persistent?.setItem(n), n;
|
|
749
|
+
} catch (t) {
|
|
750
|
+
return console.error(`Error setting query item cache for ${e.seedUid}:`, t), this.stats.errors++, null;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
async writeThroughItems(e, t) {
|
|
754
|
+
if (this.config.enabled) for (let n of e) await this.setItem(n, t);
|
|
755
|
+
}
|
|
756
|
+
async clearCollection(e) {
|
|
757
|
+
this.memoryCache.clearCollection(e), await this.persistent?.clearCollection(e);
|
|
758
|
+
}
|
|
759
|
+
async clearAll() {
|
|
760
|
+
this.memoryCache.clearAll(), await this.persistent?.clearAll();
|
|
761
|
+
}
|
|
762
|
+
async withRefreshLock(e, t) {
|
|
763
|
+
return this.memoryCache.withRefreshLock(e, t);
|
|
764
|
+
}
|
|
765
|
+
mergeRecords(e, t) {
|
|
766
|
+
let n = /* @__PURE__ */ new Map();
|
|
767
|
+
for (let t of e) t.seedUid && n.set(t.seedUid, t);
|
|
768
|
+
for (let e of t) e.seedUid ? n.set(e.seedUid, e) : n.set(`temp-${Date.now()}-${Math.random()}`, e);
|
|
769
|
+
let r = Array.from(n.values());
|
|
770
|
+
return r.sort((e, t) => (t.timeCreated || 0) - (e.timeCreated || 0)), r;
|
|
771
|
+
}
|
|
772
|
+
filterNewRecords(e, t) {
|
|
773
|
+
return e.filter((e) => e.timeCreated && e.timeCreated > t);
|
|
774
|
+
}
|
|
775
|
+
updateConfig(e) {
|
|
776
|
+
this.config = {
|
|
777
|
+
...this.config,
|
|
778
|
+
...e
|
|
779
|
+
}, this.memoryCache.updateConfig(this.config);
|
|
780
|
+
}
|
|
781
|
+
getStats() {
|
|
782
|
+
return {
|
|
783
|
+
...this.stats,
|
|
784
|
+
memoryStats: this.memoryCache.getStats()
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
resetStats() {
|
|
788
|
+
this.stats = {
|
|
789
|
+
hits: 0,
|
|
790
|
+
misses: 0,
|
|
791
|
+
refreshes: 0,
|
|
792
|
+
errors: 0
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/cache/config.ts
|
|
798
|
+
function Ie() {
|
|
799
|
+
return globalThis.process?.env ?? {};
|
|
800
|
+
}
|
|
801
|
+
function K() {
|
|
802
|
+
let e = Ie(), t = parseInt(e.CACHE_TTL || "3600", 10), n = e.CACHE_DIR || "./cache", r = e.CACHE_ENABLED === "false" || e.CACHE_ENABLED === "0" || e.CACHE_ENABLED === "no" || e.CACHE_ENABLED === "off", i = e.CACHE_ENABLED === "true" || e.CACHE_ENABLED === "1" || e.CACHE_ENABLED === "yes", a = e.NODE_ENV === "development", o;
|
|
803
|
+
o = r ? !1 : i ? !0 : !a;
|
|
804
|
+
let s = e.CACHE_BACKGROUND_REFRESH === "true", c = parseInt(e.CACHE_REFRESH_INTERVAL || "300", 10);
|
|
805
|
+
return {
|
|
806
|
+
ttl: t,
|
|
807
|
+
cacheDir: n,
|
|
808
|
+
enabled: o,
|
|
809
|
+
backgroundRefresh: s,
|
|
810
|
+
refreshInterval: c
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
//#endregion
|
|
814
|
+
//#region src/cache/index.ts
|
|
815
|
+
var q = null;
|
|
816
|
+
function J() {
|
|
817
|
+
return q ||= new G(K()), q;
|
|
818
|
+
}
|
|
819
|
+
function Le() {
|
|
820
|
+
q = null;
|
|
821
|
+
}
|
|
822
|
+
function Re(e, t) {
|
|
823
|
+
return new G({
|
|
824
|
+
...K(),
|
|
825
|
+
...e
|
|
826
|
+
}, t);
|
|
827
|
+
}
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/source/registry.ts
|
|
830
|
+
var Y = null;
|
|
831
|
+
function ze(e) {
|
|
832
|
+
if (e.kind !== "local") throw Error("[query] registerLocalQuerySource expects a source with kind: \"local\"");
|
|
833
|
+
Y = e;
|
|
834
|
+
}
|
|
835
|
+
function Be() {
|
|
836
|
+
Y = null;
|
|
837
|
+
}
|
|
838
|
+
function Ve() {
|
|
839
|
+
return Y;
|
|
840
|
+
}
|
|
841
|
+
function He() {
|
|
842
|
+
return Y != null;
|
|
843
|
+
}
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region src/source/resolve.ts
|
|
846
|
+
function X(e = "remote") {
|
|
847
|
+
if (e === "remote") return {
|
|
848
|
+
mode: "remote",
|
|
849
|
+
dataSource: I(),
|
|
850
|
+
useQueryCache: !0
|
|
851
|
+
};
|
|
852
|
+
let t = Ve();
|
|
853
|
+
if (e === "local") {
|
|
854
|
+
if (!t) throw Error("[query] source: \"local\" requires registerLocalQuerySource(...) (e.g. SDK DB ready)");
|
|
855
|
+
return {
|
|
856
|
+
mode: "local",
|
|
857
|
+
dataSource: t,
|
|
858
|
+
useQueryCache: !1
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
return t ? {
|
|
862
|
+
mode: "auto",
|
|
863
|
+
dataSource: t,
|
|
864
|
+
useQueryCache: !1
|
|
865
|
+
} : {
|
|
866
|
+
mode: "auto",
|
|
867
|
+
dataSource: I(),
|
|
868
|
+
useQueryCache: !0
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
function Z(e) {
|
|
872
|
+
return e ?? "remote";
|
|
873
|
+
}
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region src/api.ts
|
|
876
|
+
function Q(e, t) {
|
|
877
|
+
return !t || e?.cache === !1 ? !1 : J().enabled;
|
|
878
|
+
}
|
|
879
|
+
function Ue(e) {
|
|
880
|
+
return e === "data+changelog" || e === "changelog";
|
|
881
|
+
}
|
|
882
|
+
function We(e) {
|
|
883
|
+
return e !== "changelog";
|
|
884
|
+
}
|
|
885
|
+
async function $(e, t, n, r, i) {
|
|
886
|
+
return H(e, await i.listSeedsBySchemaName(e, {
|
|
887
|
+
limit: t,
|
|
888
|
+
skip: n
|
|
889
|
+
}), r, i);
|
|
890
|
+
}
|
|
891
|
+
async function Ge(e, t, n) {
|
|
892
|
+
let r = await n(t);
|
|
893
|
+
if (e !== "auto" || t.kind !== "local") return {
|
|
894
|
+
items: r,
|
|
895
|
+
dataSource: t,
|
|
896
|
+
useQueryCache: t.kind === "remote"
|
|
897
|
+
};
|
|
898
|
+
if (r.length > 0) return {
|
|
899
|
+
items: r,
|
|
900
|
+
dataSource: t,
|
|
901
|
+
useQueryCache: !1
|
|
902
|
+
};
|
|
903
|
+
let i = I();
|
|
904
|
+
return {
|
|
905
|
+
items: await n(i),
|
|
906
|
+
dataSource: i,
|
|
907
|
+
useQueryCache: !0
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
async function Ke(n, r) {
|
|
911
|
+
await e();
|
|
912
|
+
let i = r?.limit ?? 100, a = r?.skip ?? 0, o = Z(r?.source), s = X(o), c = t(r), l = (e) => $(n, i, a, r, e);
|
|
913
|
+
if (Q(r, s.useQueryCache) && a === 0 && s.dataSource.kind === "remote") {
|
|
914
|
+
let e = J();
|
|
915
|
+
return e.withRefreshLock(n, async () => {
|
|
916
|
+
let t = await e.getCollection(n), o, l;
|
|
917
|
+
if (t) {
|
|
918
|
+
let a = await $(n, i, 0, r, s.dataSource), c = e.filterNewRecords(a, t.lastProcessedTimestamp);
|
|
919
|
+
o = c.length > 0 ? e.mergeRecords(t.items, c).slice(0, i) : t.items.slice(0, i);
|
|
920
|
+
} else o = await $(n, i, 0, r, s.dataSource);
|
|
921
|
+
return l = (await e.setCollection(n, o))?.etag, await e.writeThroughItems(o, c), {
|
|
922
|
+
items: o,
|
|
923
|
+
limit: i,
|
|
924
|
+
skip: a,
|
|
925
|
+
etag: l
|
|
926
|
+
};
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
let { items: u, dataSource: d, useQueryCache: f } = await Ge(o, s.dataSource, (e) => l(e));
|
|
930
|
+
return Q(r, f) && d.kind === "remote" && await J().writeThroughItems(u, c), {
|
|
931
|
+
items: u,
|
|
932
|
+
limit: i,
|
|
933
|
+
skip: a
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
async function qe(n, r) {
|
|
937
|
+
if (await e(), !n || typeof n != "string" || n.trim() === "") return null;
|
|
938
|
+
let i = n.trim(), a = r?.include ?? "data", o = Z(r?.source), s = X(o), c = t(r), l = s.dataSource, u = s.useQueryCache;
|
|
939
|
+
if (Q(r, u) && l.kind === "remote") {
|
|
940
|
+
let e = await J().getItem(i, c);
|
|
941
|
+
if (e) return e.record;
|
|
942
|
+
}
|
|
943
|
+
let d = await l.getSeedByUid(i);
|
|
944
|
+
if (!d && o === "auto" && l.kind === "local" && (l = I(), u = !0, d = await l.getSeedByUid(i), Q(r, u))) {
|
|
945
|
+
let e = await J().getItem(i, c);
|
|
946
|
+
if (e) return e.record;
|
|
947
|
+
}
|
|
948
|
+
if (!d) return null;
|
|
949
|
+
let f = d.schema?.schemaNames?.[0]?.name;
|
|
950
|
+
if (!f) return null;
|
|
951
|
+
let p = null;
|
|
952
|
+
if (!Ue(a)) p = (await H(f, [d], r, l))[0] ?? null;
|
|
953
|
+
else {
|
|
954
|
+
let { latestVersionUid: e, changelog: t } = await ke(i, r, l);
|
|
955
|
+
if (We(a)) {
|
|
956
|
+
let e = (await H(f, [d], r, l))[0];
|
|
957
|
+
p = e ? {
|
|
958
|
+
...e,
|
|
959
|
+
changelog: t
|
|
960
|
+
} : null;
|
|
961
|
+
} else p = {
|
|
962
|
+
seedUid: i,
|
|
963
|
+
schemaName: f,
|
|
964
|
+
attester: d.attester,
|
|
965
|
+
timeCreated: d.timeCreated,
|
|
966
|
+
versionUid: e,
|
|
967
|
+
data: {},
|
|
968
|
+
changelog: t
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
return p && Q(r, u) && l.kind === "remote" && await J().setItem(p, c), p;
|
|
972
|
+
}
|
|
973
|
+
async function Je(n, r, i, a) {
|
|
974
|
+
await e();
|
|
975
|
+
let o = Z(a?.source), { items: s, dataSource: c, useQueryCache: l } = await Ge(o, X(o).dataSource, async (e) => H(n, await e.listSeedsBySchemaNameForMonth(n, r, i), a, e));
|
|
976
|
+
if (Q(a, l) && c.kind === "remote") {
|
|
977
|
+
let e = t(a);
|
|
978
|
+
await J().writeThroughItems(s, e);
|
|
979
|
+
}
|
|
980
|
+
return s;
|
|
981
|
+
}
|
|
982
|
+
//#endregion
|
|
983
|
+
export { j as A, T as B, H as C, M as D, N as E, ae as F, A as G, se as H, oe as I, _ as J, b as K, D as L, ne as M, x as N, ge as O, ie as P, O as R, Ee as S, I as T, ce as U, E as V, k as W, y as X, v as Y, g as Z, Oe as _, X as a, W as b, He as c, J as d, Le as f, ke as g, Fe as h, Z as i, de as j, he as k, ze as l, G as m, Ke as n, Be as o, K as p, te as q, Je as r, Ve as s, qe as t, Re as u, Te as v, P as w, De as x, U as y, re as z };
|
|
984
|
+
|
|
985
|
+
//# sourceMappingURL=src-BoSE9m_G.js.map
|