@seedprotocol/query 0.7.1 → 0.7.2
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 +14 -5
- package/dist/{FileCache-BZ2cHsU3.js → FileCache-CQuj0MeF.js} +21 -16
- package/dist/FileCache-CQuj0MeF.js.map +1 -0
- package/dist/api.d.ts +5 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/assembleSeeds.d.ts +21 -0
- package/dist/assembleSeeds.d.ts.map +1 -1
- package/dist/cache/CacheManager.d.ts +12 -14
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/FileCache.d.ts +4 -2
- package/dist/cache/FileCache.d.ts.map +1 -1
- package/dist/cache/MemoryCache.d.ts +12 -6
- package/dist/cache/MemoryCache.d.ts.map +1 -1
- package/dist/cache/changes.d.ts +28 -0
- package/dist/cache/changes.d.ts.map +1 -0
- package/dist/cache/config.d.ts +9 -0
- package/dist/cache/config.d.ts.map +1 -1
- package/dist/cache/etag.d.ts +7 -4
- package/dist/cache/etag.d.ts.map +1 -1
- package/dist/cache/freeze.d.ts +7 -0
- package/dist/cache/freeze.d.ts.map +1 -0
- package/dist/cache/types.d.ts +34 -7
- package/dist/cache/types.d.ts.map +1 -1
- package/dist/hydrateArweaveRichText.d.ts +3 -0
- package/dist/hydrateArweaveRichText.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.node.js +4 -4
- package/dist/index.node.js.map +1 -1
- package/dist/node.js +1 -1
- package/dist/source/remote.d.ts.map +1 -1
- package/dist/source/types.d.ts +19 -1
- package/dist/source/types.d.ts.map +1 -1
- package/dist/src-CBgjwvGT.js +1207 -0
- package/dist/src-CBgjwvGT.js.map +1 -0
- package/dist/types-DHRoT30t.js.map +1 -1
- package/dist/types.d.ts +30 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -3
- package/dist/FileCache-BZ2cHsU3.js.map +0 -1
- package/dist/src-BV0eFNvW.js +0 -993
- package/dist/src-BV0eFNvW.js.map +0 -1
package/dist/src-BV0eFNvW.js
DELETED
|
@@ -1,993 +0,0 @@
|
|
|
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: i ? t.endsWith("s") ? t : f(t) : t,
|
|
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, t) {
|
|
241
|
-
return e.length === 0 ? [] : await s({
|
|
242
|
-
seedUids: e,
|
|
243
|
-
excludeRevoked: !t?.includeRevoked
|
|
244
|
-
});
|
|
245
|
-
},
|
|
246
|
-
async getPropertiesForVersionUids(e) {
|
|
247
|
-
return e.length === 0 ? [] : await o({ versionUids: e });
|
|
248
|
-
},
|
|
249
|
-
async getSeedsByUids(e) {
|
|
250
|
-
if (e.length === 0) return [];
|
|
251
|
-
let { itemSeeds: t } = await i.getEasClient().request(a, {
|
|
252
|
-
where: d({ id: { in: e } }),
|
|
253
|
-
take: e.length || 1,
|
|
254
|
-
skip: 0
|
|
255
|
-
});
|
|
256
|
-
return t ?? [];
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
var F = null;
|
|
261
|
-
function I() {
|
|
262
|
-
return F ||= P(), F;
|
|
263
|
-
}
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/assembleSeeds.ts
|
|
266
|
-
var L = "image", R = ["0x0000000000000000000000000000000000000000000000000000000000000020"], z = /* @__PURE__ */ new Set([
|
|
267
|
-
"seedUid",
|
|
268
|
-
"SeedUid",
|
|
269
|
-
"timeCreated",
|
|
270
|
-
"attester",
|
|
271
|
-
"Attester",
|
|
272
|
-
"storage_transaction_id",
|
|
273
|
-
"storage_provider_transaction_id",
|
|
274
|
-
"storageTransactionId",
|
|
275
|
-
"storageProviderTransactionId",
|
|
276
|
-
"versionUid"
|
|
277
|
-
]), B = (e) => e.replace(/_([a-z])/g, (e, t) => t.toUpperCase());
|
|
278
|
-
function ve() {
|
|
279
|
-
return {
|
|
280
|
-
seedUidToModelType: /* @__PURE__ */ new Map(),
|
|
281
|
-
relatedSeedUids: /* @__PURE__ */ new Set(),
|
|
282
|
-
versionUidToSeedUid: /* @__PURE__ */ new Map(),
|
|
283
|
-
assembledItems: /* @__PURE__ */ new Map(),
|
|
284
|
-
versionsBySeedUid: /* @__PURE__ */ new Map(),
|
|
285
|
-
latestVersionUidsBySeedUid: /* @__PURE__ */ new Map(),
|
|
286
|
-
droppedSeedUids: /* @__PURE__ */ new Set()
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function V(e, t) {
|
|
290
|
-
!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);
|
|
291
|
-
}
|
|
292
|
-
async function ye(e, t) {
|
|
293
|
-
let n = M(t.decodedDataJson);
|
|
294
|
-
if (!n.ok) {
|
|
295
|
-
let { id: e, refUID: r, schemaId: i } = t;
|
|
296
|
-
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);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
let r = n.metadata, i = r.name;
|
|
300
|
-
if (!i) return;
|
|
301
|
-
let a = t.schemaId;
|
|
302
|
-
u({
|
|
303
|
-
text: i,
|
|
304
|
-
schemaUid: a
|
|
305
|
-
});
|
|
306
|
-
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";
|
|
307
|
-
if (l || d) {
|
|
308
|
-
if (o = !0, Array.isArray(r.value)) {
|
|
309
|
-
if (s = !0, d) {
|
|
310
|
-
let e = N(i);
|
|
311
|
-
e && (i = e.propertyName);
|
|
312
|
-
}
|
|
313
|
-
r.value.forEach((t) => {
|
|
314
|
-
R.includes(t) || e.relatedSeedUids.add(t);
|
|
315
|
-
});
|
|
316
|
-
} else R.includes(r.value) || e.relatedSeedUids.add(r.value);
|
|
317
|
-
}
|
|
318
|
-
let f = r.value;
|
|
319
|
-
o && s && Array.isArray(f) ? f = f.map((e) => String(e)) : typeof f != "string" && (f = JSON.stringify(f));
|
|
320
|
-
let p = e.versionUidToSeedUid.get(t.refUID);
|
|
321
|
-
if (!p) return;
|
|
322
|
-
let m = e.assembledItems.get(p) || {};
|
|
323
|
-
m[i] = f;
|
|
324
|
-
let h = B(i);
|
|
325
|
-
h !== i && (m[h] = f), e.assembledItems.set(p, m);
|
|
326
|
-
}
|
|
327
|
-
async function be(e, t, n, r = {}) {
|
|
328
|
-
let i = [];
|
|
329
|
-
for (let n = 0; n < t.length; n++) {
|
|
330
|
-
let r = t[n];
|
|
331
|
-
if (!r) continue;
|
|
332
|
-
i.push(r.id);
|
|
333
|
-
let a = r.schema?.schemaNames?.[0]?.name ?? "unknown";
|
|
334
|
-
e.seedUidToModelType.set(r.id, a), e.assembledItems.has(r.id) || e.assembledItems.set(r.id, {
|
|
335
|
-
seedUid: r.id,
|
|
336
|
-
timeCreated: r.timeCreated,
|
|
337
|
-
attester: r.attester
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
if (i.length === 0) return;
|
|
341
|
-
let a = await n.getVersionsForSeeds(i, { includeRevoked: !0 }), o = a.filter((e) => e.revoked !== !0);
|
|
342
|
-
if (r.dropSeedsWithOnlyRevokedVersions) {
|
|
343
|
-
let t = new Set(i), n = new Set(o.map((e) => e.refUID));
|
|
344
|
-
for (let r of a) {
|
|
345
|
-
let i = r.refUID;
|
|
346
|
-
!n.has(i) && t.has(i) && (e.assembledItems.delete(i), e.seedUidToModelType.delete(i), e.droppedSeedUids.add(i));
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
for (let t = 0; t < o.length; t++) {
|
|
350
|
-
let n = o[t], r = n.refUID;
|
|
351
|
-
e.versionUidToSeedUid.set(n.id, r);
|
|
352
|
-
let i = e.versionsBySeedUid.get(r) || [];
|
|
353
|
-
e.versionsBySeedUid.set(r, [...i, n]);
|
|
354
|
-
}
|
|
355
|
-
let s = [];
|
|
356
|
-
for (let [t, n] of e.versionsBySeedUid.entries()) {
|
|
357
|
-
if (e.latestVersionUidsBySeedUid.has(t)) continue;
|
|
358
|
-
let r = [...n].sort((e, t) => t.timeCreated - e.timeCreated)[0];
|
|
359
|
-
r && (s.push(r.id), e.latestVersionUidsBySeedUid.set(t, r.id));
|
|
360
|
-
}
|
|
361
|
-
if (s.length === 0) return;
|
|
362
|
-
let c = await n.getPropertiesForVersionUids(s), u = l(c);
|
|
363
|
-
for (let t = 0; t < u.length; t++) await ye(e, u[t]);
|
|
364
|
-
}
|
|
365
|
-
function xe(e, t) {
|
|
366
|
-
let n = Array.from(e.assembledItems.entries()).filter(([n]) => e.seedUidToModelType.get(n) === t);
|
|
367
|
-
for (let [, t] of n) {
|
|
368
|
-
let n = Object.keys(t).filter((e) => !e.startsWith("_") && !z.has(e));
|
|
369
|
-
for (let r of n) {
|
|
370
|
-
let n = t[r], i = y(n);
|
|
371
|
-
if (i !== n && Array.isArray(i) && (t[r] = i, n = i), Array.isArray(n)) {
|
|
372
|
-
let i = n;
|
|
373
|
-
if (!i.some((t) => typeof t == "string" && !R.includes(t) && e.assembledItems.has(t))) continue;
|
|
374
|
-
let a = [], o = [], s = !1;
|
|
375
|
-
for (let t of i) {
|
|
376
|
-
if (typeof t != "string" || R.includes(t)) {
|
|
377
|
-
a.push(String(t)), o.push("unknown");
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
let n = e.seedUidToModelType.get(t) ?? "unknown";
|
|
381
|
-
if (n === L) {
|
|
382
|
-
a.push(t), o.push(L);
|
|
383
|
-
continue;
|
|
384
|
-
}
|
|
385
|
-
let r = e.assembledItems.get(t), i = r?.storageTransactionId ?? r?.storage_transaction_id;
|
|
386
|
-
if (i && typeof i == "string" && i.trim()) try {
|
|
387
|
-
a.push(g(i)), o.push(n), s = !0;
|
|
388
|
-
} catch {
|
|
389
|
-
a.push(t), o.push(n);
|
|
390
|
-
}
|
|
391
|
-
else a.push(t), o.push(n);
|
|
392
|
-
}
|
|
393
|
-
if (s) {
|
|
394
|
-
let e = _(r);
|
|
395
|
-
if (t[e] = a, A(t, e, o), v(t, e), e !== r) {
|
|
396
|
-
delete t[r];
|
|
397
|
-
let e = B(r);
|
|
398
|
-
e !== r && delete t[e];
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
} else if (typeof n == "string") {
|
|
402
|
-
if (R.includes(n) || !e.assembledItems.has(n)) continue;
|
|
403
|
-
let i = e.assembledItems.get(n);
|
|
404
|
-
if (e.seedUidToModelType.get(n) === L) continue;
|
|
405
|
-
let a = i?.storageTransactionId ?? i?.storage_transaction_id;
|
|
406
|
-
if (a && typeof a == "string" && a.trim()) try {
|
|
407
|
-
let i = r.endsWith("_id") ? r.replace(/_id$/, "") : r;
|
|
408
|
-
t[i] = g(a);
|
|
409
|
-
let o = e.seedUidToModelType.get(n) ?? "unknown";
|
|
410
|
-
k(t, i, o);
|
|
411
|
-
let s = B(i);
|
|
412
|
-
if (s !== i && k(t, s, o), i !== r) {
|
|
413
|
-
delete t[r];
|
|
414
|
-
let e = B(r);
|
|
415
|
-
e !== r && delete t[e];
|
|
416
|
-
}
|
|
417
|
-
} catch {}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
function Se(e, t, n) {
|
|
423
|
-
if (!n) return;
|
|
424
|
-
let r = Array.from(e.assembledItems.entries()).filter(([n]) => e.seedUidToModelType.get(n) === t);
|
|
425
|
-
for (let [, t] of r) {
|
|
426
|
-
let n = Object.keys(t).filter((e) => !e.startsWith("_") && !z.has(e));
|
|
427
|
-
for (let r of n) {
|
|
428
|
-
let n = t[r], i = y(n);
|
|
429
|
-
i !== n && Array.isArray(i) && (t[r] = i, n = i);
|
|
430
|
-
let a = Array.isArray(n), o = a ? n : [n], s = [], c = !1;
|
|
431
|
-
for (let t of o) {
|
|
432
|
-
if (typeof t != "string" || R.includes(t)) {
|
|
433
|
-
s.push(t);
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
let n = e.assembledItems.get(t);
|
|
437
|
-
if (!n) {
|
|
438
|
-
s.push(t);
|
|
439
|
-
continue;
|
|
440
|
-
}
|
|
441
|
-
let r = n?.storageTransactionId ?? n?.storage_transaction_id;
|
|
442
|
-
if (e.seedUidToModelType.get(t) === L) {
|
|
443
|
-
let e = { ...n };
|
|
444
|
-
V(e, t), e.schemaName = L, b(e), s.push(e), c = !0;
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
if (r && typeof r == "string" && r.trim()) {
|
|
448
|
-
s.push(t);
|
|
449
|
-
continue;
|
|
450
|
-
}
|
|
451
|
-
let i = { ...n };
|
|
452
|
-
V(i, t), s.push(i), c = !0;
|
|
453
|
-
}
|
|
454
|
-
if (c) {
|
|
455
|
-
let e = a ? _(r) : r.endsWith("_id") ? r.replace(/_id$/, "") : r;
|
|
456
|
-
if (t[e] = a ? s : s[0], v(t, e), e !== r) {
|
|
457
|
-
delete t[r];
|
|
458
|
-
let e = B(r);
|
|
459
|
-
e !== r && delete t[e];
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
function Ce(e, t) {
|
|
466
|
-
return Array.from(e.assembledItems.entries()).filter(([n]) => e.seedUidToModelType.get(n) === t).map(([n, r]) => {
|
|
467
|
-
let i = e.latestVersionUidsBySeedUid.get(n) ?? "";
|
|
468
|
-
i && (r.versionUid = i), V(r, n);
|
|
469
|
-
let a = typeof r.timeCreated == "number" ? r.timeCreated : 0;
|
|
470
|
-
return {
|
|
471
|
-
seedUid: n,
|
|
472
|
-
schemaName: t,
|
|
473
|
-
attester: typeof r.attester == "string" ? r.attester : typeof r.Attester == "string" ? r.Attester : void 0,
|
|
474
|
-
timeCreated: a,
|
|
475
|
-
versionUid: i,
|
|
476
|
-
data: r
|
|
477
|
-
};
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
async function H(e, t, n, r = I()) {
|
|
481
|
-
let i = n?.expandRelations !== !1, a = n?.hydrateStorage !== !1, o = ve();
|
|
482
|
-
await be(o, t, r, { dropSeedsWithOnlyRevokedVersions: !0 });
|
|
483
|
-
let s = Array.from(o.relatedSeedUids).filter((e) => !o.assembledItems.has(e) && !o.droppedSeedUids.has(e));
|
|
484
|
-
s.length > 0 && await be(o, await r.getSeedsByUids(s), r), xe(o, e), Se(o, e, i);
|
|
485
|
-
let c = Ce(o, e);
|
|
486
|
-
return a && await j(c.map((e) => e.data), r.readStorageBody ? { readStorageBody: r.readStorageBody.bind(r) } : void 0), c;
|
|
487
|
-
}
|
|
488
|
-
//#endregion
|
|
489
|
-
//#region src/changelog.ts
|
|
490
|
-
var we = (e) => e.replace(/_([a-z])/g, (e, t) => t.toUpperCase());
|
|
491
|
-
function U(e, t) {
|
|
492
|
-
if (Object.is(e, t)) return !0;
|
|
493
|
-
if (e === void 0 || t === void 0) return !1;
|
|
494
|
-
if (e === null || t === null) return e === t;
|
|
495
|
-
if (typeof e != typeof t || typeof e != "object") return !1;
|
|
496
|
-
try {
|
|
497
|
-
return JSON.stringify(e) === JSON.stringify(t);
|
|
498
|
-
} catch {
|
|
499
|
-
return !1;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
function W(e) {
|
|
503
|
-
let t = M(e.decodedDataJson);
|
|
504
|
-
if (!t.ok) return null;
|
|
505
|
-
let n = t.metadata, r = n.name;
|
|
506
|
-
if (!r) return null;
|
|
507
|
-
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;
|
|
508
|
-
if ((a || o) && (s = !0, Array.isArray(n.value) && (c = !0, o))) {
|
|
509
|
-
let e = N(r);
|
|
510
|
-
e?.isList && (r = e.propertyName);
|
|
511
|
-
}
|
|
512
|
-
let l = n.value;
|
|
513
|
-
s && c && Array.isArray(l) ? l = l.map((e) => String(e)) : typeof l != "string" && (l = JSON.stringify(l));
|
|
514
|
-
let u = we(r);
|
|
515
|
-
return {
|
|
516
|
-
propertyName: r,
|
|
517
|
-
value: l,
|
|
518
|
-
camelName: u === r ? void 0 : u
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
function Te(e) {
|
|
522
|
-
let t = {};
|
|
523
|
-
for (let n of e) {
|
|
524
|
-
let e = W(n);
|
|
525
|
-
e && (t[e.propertyName] = e.value, e.camelName && (t[e.camelName] = e.value));
|
|
526
|
-
}
|
|
527
|
-
return t;
|
|
528
|
-
}
|
|
529
|
-
function Ee(e) {
|
|
530
|
-
let t = [], n = {};
|
|
531
|
-
for (let r of e) {
|
|
532
|
-
let e = r.data, i = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(e)]), a = [];
|
|
533
|
-
for (let t of i) U(n[t], e[t]) || a.push(t);
|
|
534
|
-
a.sort(), t.push({
|
|
535
|
-
type: "version",
|
|
536
|
-
at: r.at,
|
|
537
|
-
versionUid: r.versionUid,
|
|
538
|
-
before: { ...n },
|
|
539
|
-
after: { ...e },
|
|
540
|
-
changedKeys: a
|
|
541
|
-
}), n = e;
|
|
542
|
-
}
|
|
543
|
-
return t;
|
|
544
|
-
}
|
|
545
|
-
function De(e) {
|
|
546
|
-
let t = [...e].sort((e, t) => e.timeCreated === t.timeCreated ? e.id.localeCompare(t.id) : e.timeCreated - t.timeCreated), n = /* @__PURE__ */ new Map(), r = [];
|
|
547
|
-
for (let e of t) {
|
|
548
|
-
let t = W(e);
|
|
549
|
-
if (!t) continue;
|
|
550
|
-
let i = [t.propertyName];
|
|
551
|
-
t.camelName && i.push(t.camelName);
|
|
552
|
-
let a = n.has(t.propertyName) ? n.get(t.propertyName) : void 0, o = t.value;
|
|
553
|
-
U(a, o) || r.push({
|
|
554
|
-
type: "property",
|
|
555
|
-
at: e.timeCreated,
|
|
556
|
-
versionUid: e.refUID,
|
|
557
|
-
property: t.propertyName,
|
|
558
|
-
attestationUid: e.id,
|
|
559
|
-
previousValue: a,
|
|
560
|
-
nextValue: o
|
|
561
|
-
}), n.set(t.propertyName, o), t.camelName && n.set(t.camelName, o);
|
|
562
|
-
}
|
|
563
|
-
return r;
|
|
564
|
-
}
|
|
565
|
-
function Oe(e, t) {
|
|
566
|
-
let n = e;
|
|
567
|
-
if (typeof t?.since == "number") {
|
|
568
|
-
let e = t.since;
|
|
569
|
-
n = n.filter((t) => t.at >= e);
|
|
570
|
-
}
|
|
571
|
-
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;
|
|
572
|
-
}
|
|
573
|
-
//#endregion
|
|
574
|
-
//#region src/assembleChangelog.ts
|
|
575
|
-
async function ke(e, t, n = I()) {
|
|
576
|
-
let r = t?.changelog ?? {}, i = r.granularity ?? "version", a = [...await n.getVersionsForSeed(e)].sort((e, t) => e.timeCreated - t.timeCreated);
|
|
577
|
-
if (a.length === 0) return {
|
|
578
|
-
latestVersionUid: "",
|
|
579
|
-
changelog: []
|
|
580
|
-
};
|
|
581
|
-
let o = a[a.length - 1].id, s = a.map((e) => e.id), c = await n.getPropertiesForVersionUids(s), u;
|
|
582
|
-
if (i === "property") u = De(c);
|
|
583
|
-
else {
|
|
584
|
-
let e = /* @__PURE__ */ new Map();
|
|
585
|
-
for (let t of c) {
|
|
586
|
-
let n = e.get(t.refUID) ?? [];
|
|
587
|
-
n.push(t), e.set(t.refUID, n);
|
|
588
|
-
}
|
|
589
|
-
let t = [];
|
|
590
|
-
for (let n of a) {
|
|
591
|
-
let r = e.get(n.id) ?? [], i = l(r);
|
|
592
|
-
t.push({
|
|
593
|
-
versionUid: n.id,
|
|
594
|
-
at: n.timeCreated,
|
|
595
|
-
data: Te(i)
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
u = Ee(t);
|
|
599
|
-
}
|
|
600
|
-
return {
|
|
601
|
-
latestVersionUid: o,
|
|
602
|
-
changelog: Oe(u, r)
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
//#endregion
|
|
606
|
-
//#region src/cache/etag.ts
|
|
607
|
-
function Ae(e) {
|
|
608
|
-
return `"${m(p(h(e))).substring(0, 16)}"`;
|
|
609
|
-
}
|
|
610
|
-
function je(e, t, n) {
|
|
611
|
-
return Ae(`${e}-data-${t}-${n}`);
|
|
612
|
-
}
|
|
613
|
-
function Me(e, t, n, r) {
|
|
614
|
-
return Ae(`${e}-${t}-${n}-${r}`);
|
|
615
|
-
}
|
|
616
|
-
//#endregion
|
|
617
|
-
//#region src/cache/MemoryCache.ts
|
|
618
|
-
var Ne = class {
|
|
619
|
-
collectionCache = /* @__PURE__ */ new Map();
|
|
620
|
-
itemCache = /* @__PURE__ */ new Map();
|
|
621
|
-
config;
|
|
622
|
-
refreshLocks = /* @__PURE__ */ new Map();
|
|
623
|
-
constructor(e) {
|
|
624
|
-
this.config = e;
|
|
625
|
-
}
|
|
626
|
-
itemKey(e, t) {
|
|
627
|
-
return `${e}:${t}`;
|
|
628
|
-
}
|
|
629
|
-
getCollection(e) {
|
|
630
|
-
let t = this.collectionCache.get(e);
|
|
631
|
-
return t ? Math.floor(Date.now() / 1e3) - t.lastUpdated > this.config.ttl ? (this.collectionCache.delete(e), null) : t : null;
|
|
632
|
-
}
|
|
633
|
-
setCollection(e, t) {
|
|
634
|
-
let n = Math.floor(Date.now() / 1e3), r = 0, i = "";
|
|
635
|
-
for (let e of t) e.timeCreated && e.timeCreated > r && (r = e.timeCreated, i = e.seedUid);
|
|
636
|
-
r === 0 && (r = n);
|
|
637
|
-
let a = je(e, r, t.length), o = {
|
|
638
|
-
items: t.map((e) => ({
|
|
639
|
-
...e,
|
|
640
|
-
data: { ...e.data }
|
|
641
|
-
})),
|
|
642
|
-
lastProcessedTimestamp: r,
|
|
643
|
-
lastProcessedItemId: i,
|
|
644
|
-
lastUpdated: n,
|
|
645
|
-
etag: a
|
|
646
|
-
};
|
|
647
|
-
return this.collectionCache.set(e, o), o;
|
|
648
|
-
}
|
|
649
|
-
getItem(e, t) {
|
|
650
|
-
let n = this.itemCache.get(this.itemKey(e, t));
|
|
651
|
-
return n ? Math.floor(Date.now() / 1e3) - n.lastUpdated > this.config.ttl ? (this.itemCache.delete(this.itemKey(e, t)), null) : n : null;
|
|
652
|
-
}
|
|
653
|
-
setItem(e, t) {
|
|
654
|
-
let n = Math.floor(Date.now() / 1e3), r = Me(e.seedUid, e.versionUid, e.timeCreated, t), i = {
|
|
655
|
-
...e,
|
|
656
|
-
data: { ...e.data }
|
|
657
|
-
};
|
|
658
|
-
e.changelog && (i.changelog = [...e.changelog]);
|
|
659
|
-
let a = {
|
|
660
|
-
record: i,
|
|
661
|
-
lastUpdated: n,
|
|
662
|
-
etag: r,
|
|
663
|
-
optionsKey: t
|
|
664
|
-
};
|
|
665
|
-
return this.itemCache.set(this.itemKey(e.seedUid, t), a), a;
|
|
666
|
-
}
|
|
667
|
-
clearCollection(e) {
|
|
668
|
-
this.collectionCache.delete(e);
|
|
669
|
-
}
|
|
670
|
-
clearItem(e, t) {
|
|
671
|
-
if (t) this.itemCache.delete(this.itemKey(e, t));
|
|
672
|
-
else for (let t of this.itemCache.keys()) t.startsWith(`${e}:`) && this.itemCache.delete(t);
|
|
673
|
-
}
|
|
674
|
-
clearAll() {
|
|
675
|
-
this.collectionCache.clear(), this.itemCache.clear();
|
|
676
|
-
}
|
|
677
|
-
async withRefreshLock(e, t) {
|
|
678
|
-
let n = this.refreshLocks.get(e);
|
|
679
|
-
if (n) return n;
|
|
680
|
-
let r = (async () => {
|
|
681
|
-
try {
|
|
682
|
-
return await t();
|
|
683
|
-
} finally {
|
|
684
|
-
this.refreshLocks.delete(e);
|
|
685
|
-
}
|
|
686
|
-
})();
|
|
687
|
-
return this.refreshLocks.set(e, r), r;
|
|
688
|
-
}
|
|
689
|
-
updateConfig(e) {
|
|
690
|
-
this.config = {
|
|
691
|
-
...this.config,
|
|
692
|
-
...e
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
getStats() {
|
|
696
|
-
return {
|
|
697
|
-
collectionCount: this.collectionCache.size,
|
|
698
|
-
itemCount: this.itemCache.size,
|
|
699
|
-
activeLocks: this.refreshLocks.size
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
}, Pe = () => null;
|
|
703
|
-
function Fe(e) {
|
|
704
|
-
Pe = e;
|
|
705
|
-
}
|
|
706
|
-
var G = class {
|
|
707
|
-
memoryCache;
|
|
708
|
-
persistent;
|
|
709
|
-
config;
|
|
710
|
-
stats = {
|
|
711
|
-
hits: 0,
|
|
712
|
-
misses: 0,
|
|
713
|
-
refreshes: 0,
|
|
714
|
-
errors: 0
|
|
715
|
-
};
|
|
716
|
-
constructor(e, t) {
|
|
717
|
-
this.config = e, this.memoryCache = new Ne(e), this.persistent = t === void 0 ? Pe(e) : t;
|
|
718
|
-
}
|
|
719
|
-
get enabled() {
|
|
720
|
-
return this.config.enabled;
|
|
721
|
-
}
|
|
722
|
-
getConfig() {
|
|
723
|
-
return { ...this.config };
|
|
724
|
-
}
|
|
725
|
-
async getCollection(e) {
|
|
726
|
-
if (!this.config.enabled) return null;
|
|
727
|
-
try {
|
|
728
|
-
let t = this.memoryCache.getCollection(e);
|
|
729
|
-
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));
|
|
730
|
-
} catch (t) {
|
|
731
|
-
return console.error(`Error getting query collection cache for ${e}:`, t), this.stats.errors++, null;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
async setCollection(e, t) {
|
|
735
|
-
if (!this.config.enabled) return null;
|
|
736
|
-
try {
|
|
737
|
-
let n = this.memoryCache.setCollection(e, t);
|
|
738
|
-
return await this.persistent?.setCollection(e, n), n;
|
|
739
|
-
} catch (t) {
|
|
740
|
-
return console.error(`Error setting query collection cache for ${e}:`, t), this.stats.errors++, null;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
async getItem(e, t) {
|
|
744
|
-
if (!this.config.enabled) return null;
|
|
745
|
-
try {
|
|
746
|
-
let n = this.memoryCache.getItem(e, t);
|
|
747
|
-
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));
|
|
748
|
-
} catch (t) {
|
|
749
|
-
return console.error(`Error getting query item cache for ${e}:`, t), this.stats.errors++, null;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
async setItem(e, t) {
|
|
753
|
-
if (!this.config.enabled) return null;
|
|
754
|
-
try {
|
|
755
|
-
let n = this.memoryCache.setItem(e, t);
|
|
756
|
-
return await this.persistent?.setItem(n), n;
|
|
757
|
-
} catch (t) {
|
|
758
|
-
return console.error(`Error setting query item cache for ${e.seedUid}:`, t), this.stats.errors++, null;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
async writeThroughItems(e, t) {
|
|
762
|
-
if (this.config.enabled) for (let n of e) await this.setItem(n, t);
|
|
763
|
-
}
|
|
764
|
-
async clearCollection(e) {
|
|
765
|
-
this.memoryCache.clearCollection(e), await this.persistent?.clearCollection(e);
|
|
766
|
-
}
|
|
767
|
-
async clearAll() {
|
|
768
|
-
this.memoryCache.clearAll(), await this.persistent?.clearAll();
|
|
769
|
-
}
|
|
770
|
-
async withRefreshLock(e, t) {
|
|
771
|
-
return this.memoryCache.withRefreshLock(e, t);
|
|
772
|
-
}
|
|
773
|
-
mergeRecords(e, t) {
|
|
774
|
-
let n = /* @__PURE__ */ new Map();
|
|
775
|
-
for (let t of e) t.seedUid && n.set(t.seedUid, t);
|
|
776
|
-
for (let e of t) e.seedUid ? n.set(e.seedUid, e) : n.set(`temp-${Date.now()}-${Math.random()}`, e);
|
|
777
|
-
let r = Array.from(n.values());
|
|
778
|
-
return r.sort((e, t) => (t.timeCreated || 0) - (e.timeCreated || 0)), r;
|
|
779
|
-
}
|
|
780
|
-
filterNewRecords(e, t) {
|
|
781
|
-
return e.filter((e) => e.timeCreated && e.timeCreated > t);
|
|
782
|
-
}
|
|
783
|
-
updateConfig(e) {
|
|
784
|
-
this.config = {
|
|
785
|
-
...this.config,
|
|
786
|
-
...e
|
|
787
|
-
}, this.memoryCache.updateConfig(this.config);
|
|
788
|
-
}
|
|
789
|
-
getStats() {
|
|
790
|
-
return {
|
|
791
|
-
...this.stats,
|
|
792
|
-
memoryStats: this.memoryCache.getStats()
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
resetStats() {
|
|
796
|
-
this.stats = {
|
|
797
|
-
hits: 0,
|
|
798
|
-
misses: 0,
|
|
799
|
-
refreshes: 0,
|
|
800
|
-
errors: 0
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
};
|
|
804
|
-
//#endregion
|
|
805
|
-
//#region src/cache/config.ts
|
|
806
|
-
function Ie() {
|
|
807
|
-
return globalThis.process?.env ?? {};
|
|
808
|
-
}
|
|
809
|
-
function K() {
|
|
810
|
-
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;
|
|
811
|
-
o = r ? !1 : i ? !0 : !a;
|
|
812
|
-
let s = e.CACHE_BACKGROUND_REFRESH === "true", c = parseInt(e.CACHE_REFRESH_INTERVAL || "300", 10);
|
|
813
|
-
return {
|
|
814
|
-
ttl: t,
|
|
815
|
-
cacheDir: n,
|
|
816
|
-
enabled: o,
|
|
817
|
-
backgroundRefresh: s,
|
|
818
|
-
refreshInterval: c
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
//#endregion
|
|
822
|
-
//#region src/cache/index.ts
|
|
823
|
-
var q = null;
|
|
824
|
-
function J() {
|
|
825
|
-
return q ||= new G(K()), q;
|
|
826
|
-
}
|
|
827
|
-
function Le() {
|
|
828
|
-
q = null;
|
|
829
|
-
}
|
|
830
|
-
function Re(e, t) {
|
|
831
|
-
return new G({
|
|
832
|
-
...K(),
|
|
833
|
-
...e
|
|
834
|
-
}, t);
|
|
835
|
-
}
|
|
836
|
-
//#endregion
|
|
837
|
-
//#region src/source/registry.ts
|
|
838
|
-
var Y = null;
|
|
839
|
-
function ze(e) {
|
|
840
|
-
if (e.kind !== "local") throw Error("[query] registerLocalQuerySource expects a source with kind: \"local\"");
|
|
841
|
-
Y = e;
|
|
842
|
-
}
|
|
843
|
-
function Be() {
|
|
844
|
-
Y = null;
|
|
845
|
-
}
|
|
846
|
-
function Ve() {
|
|
847
|
-
return Y;
|
|
848
|
-
}
|
|
849
|
-
function He() {
|
|
850
|
-
return Y != null;
|
|
851
|
-
}
|
|
852
|
-
//#endregion
|
|
853
|
-
//#region src/source/resolve.ts
|
|
854
|
-
function X(e = "remote") {
|
|
855
|
-
if (e === "remote") return {
|
|
856
|
-
mode: "remote",
|
|
857
|
-
dataSource: I(),
|
|
858
|
-
useQueryCache: !0
|
|
859
|
-
};
|
|
860
|
-
let t = Ve();
|
|
861
|
-
if (e === "local") {
|
|
862
|
-
if (!t) throw Error("[query] source: \"local\" requires registerLocalQuerySource(...) (e.g. SDK DB ready)");
|
|
863
|
-
return {
|
|
864
|
-
mode: "local",
|
|
865
|
-
dataSource: t,
|
|
866
|
-
useQueryCache: !1
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
return t ? {
|
|
870
|
-
mode: "auto",
|
|
871
|
-
dataSource: t,
|
|
872
|
-
useQueryCache: !1
|
|
873
|
-
} : {
|
|
874
|
-
mode: "auto",
|
|
875
|
-
dataSource: I(),
|
|
876
|
-
useQueryCache: !0
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
function Z(e) {
|
|
880
|
-
return e ?? "remote";
|
|
881
|
-
}
|
|
882
|
-
//#endregion
|
|
883
|
-
//#region src/api.ts
|
|
884
|
-
function Q(e, t) {
|
|
885
|
-
return !t || e?.cache === !1 ? !1 : J().enabled;
|
|
886
|
-
}
|
|
887
|
-
function Ue(e) {
|
|
888
|
-
return e === "data+changelog" || e === "changelog";
|
|
889
|
-
}
|
|
890
|
-
function We(e) {
|
|
891
|
-
return e !== "changelog";
|
|
892
|
-
}
|
|
893
|
-
async function $(e, t, n, r, i) {
|
|
894
|
-
return H(e, await i.listSeedsBySchemaName(e, {
|
|
895
|
-
limit: t,
|
|
896
|
-
skip: n
|
|
897
|
-
}), r, i);
|
|
898
|
-
}
|
|
899
|
-
async function Ge(e, t, n) {
|
|
900
|
-
let r = await n(t);
|
|
901
|
-
if (e !== "auto" || t.kind !== "local") return {
|
|
902
|
-
items: r,
|
|
903
|
-
dataSource: t,
|
|
904
|
-
useQueryCache: t.kind === "remote"
|
|
905
|
-
};
|
|
906
|
-
if (r.length > 0) return {
|
|
907
|
-
items: r,
|
|
908
|
-
dataSource: t,
|
|
909
|
-
useQueryCache: !1
|
|
910
|
-
};
|
|
911
|
-
let i = I();
|
|
912
|
-
return {
|
|
913
|
-
items: await n(i),
|
|
914
|
-
dataSource: i,
|
|
915
|
-
useQueryCache: !0
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
async function Ke(n, r) {
|
|
919
|
-
await e();
|
|
920
|
-
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);
|
|
921
|
-
if (Q(r, s.useQueryCache) && a === 0 && s.dataSource.kind === "remote") {
|
|
922
|
-
let e = J();
|
|
923
|
-
return e.withRefreshLock(n, async () => {
|
|
924
|
-
let t = await e.getCollection(n), o, l;
|
|
925
|
-
if (t) {
|
|
926
|
-
let a = await $(n, i, 0, r, s.dataSource), c = e.filterNewRecords(a, t.lastProcessedTimestamp);
|
|
927
|
-
o = c.length > 0 ? e.mergeRecords(t.items, c).slice(0, i) : t.items.slice(0, i);
|
|
928
|
-
} else o = await $(n, i, 0, r, s.dataSource);
|
|
929
|
-
return l = (await e.setCollection(n, o))?.etag, await e.writeThroughItems(o, c), {
|
|
930
|
-
items: o,
|
|
931
|
-
limit: i,
|
|
932
|
-
skip: a,
|
|
933
|
-
etag: l
|
|
934
|
-
};
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
let { items: u, dataSource: d, useQueryCache: f } = await Ge(o, s.dataSource, (e) => l(e));
|
|
938
|
-
return Q(r, f) && d.kind === "remote" && await J().writeThroughItems(u, c), {
|
|
939
|
-
items: u,
|
|
940
|
-
limit: i,
|
|
941
|
-
skip: a
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
async function qe(n, r) {
|
|
945
|
-
if (await e(), !n || typeof n != "string" || n.trim() === "") return null;
|
|
946
|
-
let i = n.trim(), a = r?.include ?? "data", o = Z(r?.source), s = X(o), c = t(r), l = s.dataSource, u = s.useQueryCache;
|
|
947
|
-
if (Q(r, u) && l.kind === "remote") {
|
|
948
|
-
let e = await J().getItem(i, c);
|
|
949
|
-
if (e) return e.record;
|
|
950
|
-
}
|
|
951
|
-
let d = await l.getSeedByUid(i);
|
|
952
|
-
if (!d && o === "auto" && l.kind === "local" && (l = I(), u = !0, d = await l.getSeedByUid(i), Q(r, u))) {
|
|
953
|
-
let e = await J().getItem(i, c);
|
|
954
|
-
if (e) return e.record;
|
|
955
|
-
}
|
|
956
|
-
if (!d) return null;
|
|
957
|
-
let f = d.schema?.schemaNames?.[0]?.name;
|
|
958
|
-
if (!f) return null;
|
|
959
|
-
let p = null;
|
|
960
|
-
if (!Ue(a)) p = (await H(f, [d], r, l))[0] ?? null;
|
|
961
|
-
else {
|
|
962
|
-
let { latestVersionUid: e, changelog: t } = await ke(i, r, l);
|
|
963
|
-
if (We(a)) {
|
|
964
|
-
let e = (await H(f, [d], r, l))[0];
|
|
965
|
-
p = e ? {
|
|
966
|
-
...e,
|
|
967
|
-
changelog: t
|
|
968
|
-
} : null;
|
|
969
|
-
} else p = {
|
|
970
|
-
seedUid: i,
|
|
971
|
-
schemaName: f,
|
|
972
|
-
attester: d.attester,
|
|
973
|
-
timeCreated: d.timeCreated,
|
|
974
|
-
versionUid: e,
|
|
975
|
-
data: {},
|
|
976
|
-
changelog: t
|
|
977
|
-
};
|
|
978
|
-
}
|
|
979
|
-
return p && Q(r, u) && l.kind === "remote" && await J().setItem(p, c), p;
|
|
980
|
-
}
|
|
981
|
-
async function Je(n, r, i, a) {
|
|
982
|
-
await e();
|
|
983
|
-
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));
|
|
984
|
-
if (Q(a, l) && c.kind === "remote") {
|
|
985
|
-
let e = t(a);
|
|
986
|
-
await J().writeThroughItems(s, e);
|
|
987
|
-
}
|
|
988
|
-
return s;
|
|
989
|
-
}
|
|
990
|
-
//#endregion
|
|
991
|
-
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 };
|
|
992
|
-
|
|
993
|
-
//# sourceMappingURL=src-BV0eFNvW.js.map
|