@voltro/plugin-search 0.54.0 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +142 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +225 -225
- package/dist/{rpc-DaYt-dP6.js → rpc-CpryHBcM.js} +10 -10
- package/dist/rpc.d.ts +12 -0
- package/dist/rpc.js +2 -2
- package/dist/web.js +13 -11
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { a as e, i as t, n, r } from "./rpc-
|
|
2
|
-
import { Cause as
|
|
3
|
-
import { and as
|
|
4
|
-
import { definePlugin as
|
|
1
|
+
import { a as e, i as t, o as n, r, t as i } from "./rpc-CpryHBcM.js";
|
|
2
|
+
import { Cause as a, Chunk as o, Data as s, Duration as c, Effect as l, Exit as u, Option as d, Schedule as f, Stream as p } from "effect";
|
|
3
|
+
import { and as m, count as h, eq as g, id as _, integer as v, streamTable as y, table as b, text as x, timestamp as S } from "@voltro/database";
|
|
4
|
+
import { definePlugin as ee, pluginInstanceName as te } from "@voltro/protocol";
|
|
5
5
|
//#region src/sanitize.ts
|
|
6
|
-
var
|
|
6
|
+
var C = /^[A-Za-z_][A-Za-z0-9_.]*$/, w = (e) => C.test(e), ne = (e, t) => {
|
|
7
7
|
let n = t ? new Set(t) : void 0;
|
|
8
8
|
for (let [t, r] of e) {
|
|
9
|
-
if (!
|
|
9
|
+
if (!w(r)) return {
|
|
10
10
|
field: r,
|
|
11
11
|
where: t,
|
|
12
12
|
reason: "not-an-identifier"
|
|
@@ -17,7 +17,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
17
17
|
reason: "not-queryable"
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
},
|
|
20
|
+
}, T = {
|
|
21
21
|
typesense: [
|
|
22
22
|
"per_page",
|
|
23
23
|
"page",
|
|
@@ -71,7 +71,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
71
71
|
"highlightPreTag",
|
|
72
72
|
"highlightPostTag"
|
|
73
73
|
]
|
|
74
|
-
},
|
|
74
|
+
}, E = {
|
|
75
75
|
typesense: [
|
|
76
76
|
"filter_by",
|
|
77
77
|
"q",
|
|
@@ -108,20 +108,20 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
108
108
|
"aroundLatLng",
|
|
109
109
|
"insideBoundingBox"
|
|
110
110
|
]
|
|
111
|
-
},
|
|
111
|
+
}, D = (e, t, n) => {
|
|
112
112
|
if (!t) return {
|
|
113
113
|
params: {},
|
|
114
114
|
appAllowed: {},
|
|
115
115
|
dropped: []
|
|
116
116
|
};
|
|
117
|
-
let r = new Set(
|
|
117
|
+
let r = new Set(E[e]), i = new Set(T[e]), a = new Set(n ?? []), o = {}, s = {}, c = [];
|
|
118
118
|
for (let [e, n] of Object.entries(t)) r.has(e) ? c.push(e) : i.has(e) ? o[e] = n : a.has(e) ? s[e] = n : c.push(e);
|
|
119
119
|
return {
|
|
120
120
|
params: o,
|
|
121
121
|
appAllowed: s,
|
|
122
122
|
dropped: c
|
|
123
123
|
};
|
|
124
|
-
},
|
|
124
|
+
}, O = (e) => T[e], k = class extends s.TaggedError("SearchBackendError") {}, A = (e) => Array.isArray(e) ? e : [e], j = (e, t, n) => {
|
|
125
125
|
if (Math.abs(e.length - t.length) > n) return !1;
|
|
126
126
|
if (e === t) return !0;
|
|
127
127
|
let r = t.length, i = Array.from({ length: r + 1 }, (e, t) => t);
|
|
@@ -137,7 +137,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
137
137
|
i = o;
|
|
138
138
|
}
|
|
139
139
|
return (i[r] ?? Infinity) <= n;
|
|
140
|
-
},
|
|
140
|
+
}, M = (e) => e.length <= 4 ? 1 : 2, N = () => {
|
|
141
141
|
let e = /* @__PURE__ */ new Map(), t = (t) => {
|
|
142
142
|
let n = e.get(t);
|
|
143
143
|
return n || (n = /* @__PURE__ */ new Map(), e.set(t, n)), n;
|
|
@@ -146,13 +146,13 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
146
146
|
switch (t.op) {
|
|
147
147
|
case "eq": return String(n) === String(t.value);
|
|
148
148
|
case "neq": return String(n) !== String(t.value);
|
|
149
|
-
case "in": return
|
|
150
|
-
case "nin": return
|
|
149
|
+
case "in": return A(t.value).some((e) => String(n) === String(e));
|
|
150
|
+
case "nin": return A(t.value).every((e) => String(n) !== String(e));
|
|
151
151
|
case "gt":
|
|
152
152
|
case "gte":
|
|
153
153
|
case "lt":
|
|
154
154
|
case "lte": {
|
|
155
|
-
let [e, r] = [
|
|
155
|
+
let [e, r] = [P(n), P(t.value)];
|
|
156
156
|
return e === void 0 || r === void 0 ? !1 : t.op === "gt" ? e > r : t.op === "gte" ? e >= r : t.op === "lt" ? e < r : e <= r;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
@@ -162,8 +162,8 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
162
162
|
let e = r.toLowerCase();
|
|
163
163
|
if (e.includes(t)) return !0;
|
|
164
164
|
if (n !== void 0 && n !== 0) {
|
|
165
|
-
let r = n === "auto" ?
|
|
166
|
-
for (let n of e.split(/\s+/)) if (
|
|
165
|
+
let r = n === "auto" ? M(t) : n;
|
|
166
|
+
for (let n of e.split(/\s+/)) if (j(n, t, r)) return !0;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
return !1;
|
|
@@ -207,7 +207,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
|
-
},
|
|
210
|
+
}, P = (e) => {
|
|
211
211
|
if (typeof e == "number") return e;
|
|
212
212
|
if (typeof e == "boolean") return +!!e;
|
|
213
213
|
if (typeof e == "string") {
|
|
@@ -216,19 +216,19 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
216
216
|
let n = Date.parse(e);
|
|
217
217
|
return Number.isNaN(n) ? void 0 : n;
|
|
218
218
|
}
|
|
219
|
-
},
|
|
219
|
+
}, F = async (e, t, n) => {
|
|
220
220
|
try {
|
|
221
221
|
return await n();
|
|
222
222
|
} catch {
|
|
223
|
-
throw new
|
|
223
|
+
throw new k({
|
|
224
224
|
engine: t,
|
|
225
225
|
op: "query",
|
|
226
226
|
message: `the '${t}' search backend requires the '${e}' optional dependency. Install it to enable it (e.g. \`npm i ${e}\`).`,
|
|
227
227
|
transient: !1
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
},
|
|
231
|
-
let { params: r, appAllowed: i, dropped: a } =
|
|
230
|
+
}, I = (e, t) => (n) => {
|
|
231
|
+
let { params: r, appAllowed: i, dropped: a } = D(e, n, t.allowEngineParams);
|
|
232
232
|
return a.length > 0 && t.onWarn?.("search dropped disallowed engineParams", {
|
|
233
233
|
engine: e,
|
|
234
234
|
keys: a
|
|
@@ -236,16 +236,16 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
236
236
|
before: r,
|
|
237
237
|
after: i
|
|
238
238
|
};
|
|
239
|
-
},
|
|
240
|
-
if (!
|
|
239
|
+
}, L = (e, t) => {
|
|
240
|
+
if (!w(t)) throw new k({
|
|
241
241
|
engine: e,
|
|
242
242
|
op: "query",
|
|
243
243
|
message: `filter field "${t}" is not a plain field path (^[A-Za-z_][A-Za-z0-9_.]*$)`,
|
|
244
244
|
transient: !1
|
|
245
245
|
});
|
|
246
246
|
return t;
|
|
247
|
-
},
|
|
248
|
-
let t = (e) => JSON.stringify(e), n =
|
|
247
|
+
}, re = (e) => {
|
|
248
|
+
let t = (e) => JSON.stringify(e), n = L("typesense", e.field);
|
|
249
249
|
switch (e.op) {
|
|
250
250
|
case "eq": return `${n}:=${t(e.value)}`;
|
|
251
251
|
case "neq": return `${n}:!=${t(e.value)}`;
|
|
@@ -253,21 +253,21 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
253
253
|
case "gte": return `${n}:>=${t(e.value)}`;
|
|
254
254
|
case "lt": return `${n}:<${t(e.value)}`;
|
|
255
255
|
case "lte": return `${n}:<=${t(e.value)}`;
|
|
256
|
-
case "in": return `${n}:[${
|
|
257
|
-
case "nin": return `${n}:!=[${
|
|
256
|
+
case "in": return `${n}:[${A(e.value).map(t).join(",")}]`;
|
|
257
|
+
case "nin": return `${n}:!=[${A(e.value).map(t).join(",")}]`;
|
|
258
258
|
}
|
|
259
|
-
},
|
|
260
|
-
let n =
|
|
259
|
+
}, ie = (e, t = {}) => {
|
|
260
|
+
let n = I("typesense", t), r, i = async () => (r ||= F("typesense", "typesense", () => import("typesense")).then((t) => {
|
|
261
261
|
let n = t.Client;
|
|
262
262
|
return new n({
|
|
263
263
|
nodes: [{ url: e.url ?? e.host ?? "http://localhost:8108" }],
|
|
264
264
|
apiKey: e.apiKey
|
|
265
265
|
});
|
|
266
|
-
}), r), a = (e) => e && e.length > 0 ? e.map(
|
|
266
|
+
}), r), a = (e) => e && e.length > 0 ? e.map(re).join(" && ") : void 0, o = async (e, t) => {
|
|
267
267
|
try {
|
|
268
268
|
return await t();
|
|
269
269
|
} catch (t) {
|
|
270
|
-
throw t instanceof
|
|
270
|
+
throw t instanceof k ? t : new k({
|
|
271
271
|
engine: "typesense",
|
|
272
272
|
op: e,
|
|
273
273
|
message: String(t?.message ?? t),
|
|
@@ -299,10 +299,10 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
299
299
|
...d !== void 0 && d !== "auto" ? { num_typos: Math.min(2, Math.max(0, d)) } : {},
|
|
300
300
|
...p.after
|
|
301
301
|
};
|
|
302
|
-
return
|
|
302
|
+
return ae(await o.collections(e).documents().search(m));
|
|
303
303
|
})
|
|
304
304
|
};
|
|
305
|
-
},
|
|
305
|
+
}, ae = (e) => {
|
|
306
306
|
let t = (e.hits ?? []).map((e) => {
|
|
307
307
|
let t = {};
|
|
308
308
|
for (let n of e.highlights ?? []) {
|
|
@@ -319,8 +319,8 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
319
319
|
hits: t,
|
|
320
320
|
facets: n
|
|
321
321
|
};
|
|
322
|
-
},
|
|
323
|
-
let t = (e) => JSON.stringify(e), n =
|
|
322
|
+
}, oe = (e) => {
|
|
323
|
+
let t = (e) => JSON.stringify(e), n = L("meilisearch", e.field);
|
|
324
324
|
switch (e.op) {
|
|
325
325
|
case "eq": return `${n} = ${t(e.value)}`;
|
|
326
326
|
case "neq": return `${n} != ${t(e.value)}`;
|
|
@@ -328,18 +328,18 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
328
328
|
case "gte": return `${n} >= ${t(e.value)}`;
|
|
329
329
|
case "lt": return `${n} < ${t(e.value)}`;
|
|
330
330
|
case "lte": return `${n} <= ${t(e.value)}`;
|
|
331
|
-
case "in": return `${n} IN [${
|
|
332
|
-
case "nin": return `${n} NOT IN [${
|
|
331
|
+
case "in": return `${n} IN [${A(e.value).map(t).join(", ")}]`;
|
|
332
|
+
case "nin": return `${n} NOT IN [${A(e.value).map(t).join(", ")}]`;
|
|
333
333
|
}
|
|
334
|
-
},
|
|
335
|
-
let n =
|
|
334
|
+
}, R = (e, t = {}) => {
|
|
335
|
+
let n = I("meilisearch", t), r, i = async () => (r ||= F("meilisearch", "meilisearch", () => import("meilisearch")).then((t) => new t.MeiliSearch({
|
|
336
336
|
host: e.host ?? e.url ?? "http://localhost:7700",
|
|
337
337
|
apiKey: e.apiKey
|
|
338
|
-
})), r), a = (e) => e && e.length > 0 ? e.map(
|
|
338
|
+
})), r), a = (e) => e && e.length > 0 ? e.map(oe) : void 0, o = async (e, t) => {
|
|
339
339
|
try {
|
|
340
340
|
return await t();
|
|
341
341
|
} catch (t) {
|
|
342
|
-
throw t instanceof
|
|
342
|
+
throw t instanceof k ? t : new k({
|
|
343
343
|
engine: "meilisearch",
|
|
344
344
|
op: e,
|
|
345
345
|
message: String(t?.message ?? t),
|
|
@@ -372,10 +372,10 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
372
372
|
} : {},
|
|
373
373
|
...o.after
|
|
374
374
|
};
|
|
375
|
-
return
|
|
375
|
+
return se(await (await i()).index(e).search(t, p), u);
|
|
376
376
|
})
|
|
377
377
|
};
|
|
378
|
-
},
|
|
378
|
+
}, se = (e, t) => ({
|
|
379
379
|
hits: e.hits.map((e) => {
|
|
380
380
|
let { _formatted: n, ...r } = e;
|
|
381
381
|
if (t && n) {
|
|
@@ -389,19 +389,19 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
389
389
|
return { doc: r };
|
|
390
390
|
}),
|
|
391
391
|
facets: e.facetDistribution ?? {}
|
|
392
|
-
}),
|
|
392
|
+
}), ce = (e) => String(e).replace(/^-/, "\\-"), le = (e, t) => {
|
|
393
393
|
let n = typeof t == "boolean" ? +!!t : Number(t);
|
|
394
|
-
if (!Number.isFinite(n)) throw new
|
|
394
|
+
if (!Number.isFinite(n)) throw new k({
|
|
395
395
|
engine: "algolia",
|
|
396
396
|
op: "query",
|
|
397
397
|
message: `range filter on "${e}" needs a numeric value (got ${JSON.stringify(t)})`,
|
|
398
398
|
transient: !1
|
|
399
399
|
});
|
|
400
400
|
return n;
|
|
401
|
-
},
|
|
401
|
+
}, ue = (e) => {
|
|
402
402
|
let t = [], n = [];
|
|
403
403
|
for (let r of e ?? []) {
|
|
404
|
-
let e =
|
|
404
|
+
let e = L("algolia", r.field), i = (e) => ce(e), a = (t) => le(e, t);
|
|
405
405
|
switch (r.op) {
|
|
406
406
|
case "eq":
|
|
407
407
|
t.push(`${e}:${i(r.value)}`);
|
|
@@ -410,10 +410,10 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
410
410
|
t.push(`${e}:-${i(r.value)}`);
|
|
411
411
|
break;
|
|
412
412
|
case "in":
|
|
413
|
-
t.push(
|
|
413
|
+
t.push(A(r.value).map((t) => `${e}:${i(t)}`));
|
|
414
414
|
break;
|
|
415
415
|
case "nin":
|
|
416
|
-
for (let n of
|
|
416
|
+
for (let n of A(r.value)) t.push(`${e}:-${i(n)}`);
|
|
417
417
|
break;
|
|
418
418
|
case "gt":
|
|
419
419
|
n.push(`${e} > ${a(r.value)}`);
|
|
@@ -431,12 +431,12 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
431
431
|
facetFilters: t,
|
|
432
432
|
numericFilters: n
|
|
433
433
|
};
|
|
434
|
-
},
|
|
435
|
-
let n =
|
|
434
|
+
}, z = (e, t = {}) => {
|
|
435
|
+
let n = I("algolia", t), r, i = async () => (r ||= F("algoliasearch", "algolia", () => import("algoliasearch")).then((t) => t.algoliasearch(e.appId ?? "", e.apiKey)), r), a = async (e, t) => {
|
|
436
436
|
try {
|
|
437
437
|
return await t();
|
|
438
438
|
} catch (t) {
|
|
439
|
-
throw t instanceof
|
|
439
|
+
throw t instanceof k ? t : new k({
|
|
440
440
|
engine: "algolia",
|
|
441
441
|
op: e,
|
|
442
442
|
message: String(t?.message ?? t),
|
|
@@ -461,7 +461,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
461
461
|
});
|
|
462
462
|
}),
|
|
463
463
|
query: (e, { q: t, limit: r, offset: o, filters: s, facets: c, highlight: l, fuzziness: u, engineParams: d }) => a("query", async () => {
|
|
464
|
-
let { facetFilters: a, numericFilters: f } =
|
|
464
|
+
let { facetFilters: a, numericFilters: f } = ue(s), p = o ? {
|
|
465
465
|
offset: o,
|
|
466
466
|
length: r ?? 20
|
|
467
467
|
} : { hitsPerPage: r ?? 20 }, m = n(d), h = {
|
|
@@ -479,13 +479,13 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
479
479
|
...u === 0 ? { typoTolerance: !1 } : {},
|
|
480
480
|
...m.after
|
|
481
481
|
};
|
|
482
|
-
return
|
|
482
|
+
return de(await (await i()).searchSingleIndex({
|
|
483
483
|
indexName: e,
|
|
484
484
|
searchParams: h
|
|
485
485
|
}), l);
|
|
486
486
|
})
|
|
487
487
|
};
|
|
488
|
-
},
|
|
488
|
+
}, de = (e, t) => ({
|
|
489
489
|
hits: e.hits.map((e) => {
|
|
490
490
|
let { _highlightResult: n, ...r } = e;
|
|
491
491
|
if (t && n) {
|
|
@@ -499,25 +499,25 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
499
499
|
return { doc: r };
|
|
500
500
|
}),
|
|
501
501
|
facets: e.facets ?? {}
|
|
502
|
-
}),
|
|
502
|
+
}), B = "_voltro_search_stats", V = () => ({
|
|
503
503
|
synced: 0,
|
|
504
504
|
removed: 0,
|
|
505
505
|
dropped: 0,
|
|
506
506
|
lastReindexAt: null,
|
|
507
507
|
lastReindexCount: 0
|
|
508
|
-
}),
|
|
509
|
-
id:
|
|
510
|
-
indexName:
|
|
511
|
-
replicaId:
|
|
512
|
-
synced:
|
|
513
|
-
removed:
|
|
514
|
-
dropped:
|
|
515
|
-
scope:
|
|
516
|
-
lastReindexAt:
|
|
517
|
-
lastReindexCount:
|
|
518
|
-
updatedAt:
|
|
519
|
-
}).unique("bySearchStatsIndexReplica", ["indexName", "replicaId"]).index("bySearchStatsIndex", ["indexName"]),
|
|
520
|
-
let e = /* @__PURE__ */ new Map(), t = (t) => e.get(t) ??
|
|
508
|
+
}), H = b(B, {
|
|
509
|
+
id: _({ prefix: "sstat" }),
|
|
510
|
+
indexName: x().maxLength(191),
|
|
511
|
+
replicaId: x().maxLength(191),
|
|
512
|
+
synced: v().default(0),
|
|
513
|
+
removed: v().default(0),
|
|
514
|
+
dropped: v().default(0),
|
|
515
|
+
scope: x().maxLength(8).default("local"),
|
|
516
|
+
lastReindexAt: S().nullable(),
|
|
517
|
+
lastReindexCount: v().default(0),
|
|
518
|
+
updatedAt: S()
|
|
519
|
+
}).unique("bySearchStatsIndexReplica", ["indexName", "replicaId"]).index("bySearchStatsIndex", ["indexName"]), U = () => [H], W = () => {
|
|
520
|
+
let e = /* @__PURE__ */ new Map(), t = (t) => e.get(t) ?? V();
|
|
521
521
|
return {
|
|
522
522
|
bump: async (n, r) => {
|
|
523
523
|
let i = t(n);
|
|
@@ -552,19 +552,19 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
552
552
|
},
|
|
553
553
|
get: async (e) => t(e)
|
|
554
554
|
};
|
|
555
|
-
},
|
|
556
|
-
table:
|
|
555
|
+
}, G = (e) => ({
|
|
556
|
+
table: B,
|
|
557
557
|
predicate: e,
|
|
558
558
|
order: [],
|
|
559
559
|
take: void 0,
|
|
560
560
|
skip: void 0,
|
|
561
561
|
projection: void 0
|
|
562
|
-
}),
|
|
563
|
-
let n = async (n) => (await e.query(
|
|
562
|
+
}), fe = () => `sstat_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`, pe = () => process.env.VOLTRO_REPLICA_ID ?? process.env.HOSTNAME ?? process.env.POD_NAME ?? `pid_${process.pid}_${Math.random().toString(36).slice(2, 8)}`, K = 32, q = (e, t = pe()) => {
|
|
563
|
+
let n = async (n) => (await e.query(G(m(g("indexName", n), g("replicaId", t)))))[0] ?? null, r = async (e) => {
|
|
564
564
|
try {
|
|
565
565
|
return await e();
|
|
566
566
|
} catch (e) {
|
|
567
|
-
throw e instanceof
|
|
567
|
+
throw e instanceof k ? e : new k({
|
|
568
568
|
engine: "stats",
|
|
569
569
|
op: "upsert",
|
|
570
570
|
message: String(e?.message ?? e),
|
|
@@ -572,7 +572,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
572
572
|
});
|
|
573
573
|
}
|
|
574
574
|
}, i = (i, a, o, s) => r(async () => {
|
|
575
|
-
for (let r = 0; r <
|
|
575
|
+
for (let r = 0; r < K; r++) {
|
|
576
576
|
r > 0 && await new Promise((e) => setTimeout(e, r));
|
|
577
577
|
let c = await n(i);
|
|
578
578
|
if (c) {
|
|
@@ -587,9 +587,9 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
587
587
|
...o(i),
|
|
588
588
|
...a ? { scope: a } : {},
|
|
589
589
|
updatedAt: /* @__PURE__ */ new Date()
|
|
590
|
-
}, { where:
|
|
590
|
+
}, { where: m(g("id", String(c.id)), g("synced", t), g("removed", n), g("dropped", r)) }) === 1) return;
|
|
591
591
|
} else {
|
|
592
|
-
let n =
|
|
592
|
+
let n = fe(), r = await e.insertIgnore(B, {
|
|
593
593
|
id: n,
|
|
594
594
|
indexName: i,
|
|
595
595
|
replicaId: t,
|
|
@@ -605,10 +605,10 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
605
605
|
if (String(r.id) === n) return;
|
|
606
606
|
}
|
|
607
607
|
}
|
|
608
|
-
throw new
|
|
608
|
+
throw new k({
|
|
609
609
|
engine: "stats",
|
|
610
610
|
op: "upsert",
|
|
611
|
-
message: `search stats: contention on (${i}, ${t}) exceeded ${
|
|
611
|
+
message: `search stats: contention on (${i}, ${t}) exceeded ${K} attempts`,
|
|
612
612
|
transient: !0
|
|
613
613
|
});
|
|
614
614
|
});
|
|
@@ -633,7 +633,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
633
633
|
lastReindexCount: t
|
|
634
634
|
}),
|
|
635
635
|
get: (t) => r(async () => {
|
|
636
|
-
let n = await e.query(
|
|
636
|
+
let n = await e.query(G(g("indexName", t))), r = n.some((e) => e.scope === "fleet"), i = (e) => {
|
|
637
637
|
let t = 0;
|
|
638
638
|
for (let i of n) {
|
|
639
639
|
let n = Number(i[e] ?? 0);
|
|
@@ -646,7 +646,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
646
646
|
t && (a === null || t > a) && (a = t, o = Number(e.lastReindexCount ?? 0));
|
|
647
647
|
}
|
|
648
648
|
return {
|
|
649
|
-
...
|
|
649
|
+
...V(),
|
|
650
650
|
synced: i("synced"),
|
|
651
651
|
removed: i("removed"),
|
|
652
652
|
dropped: i("dropped"),
|
|
@@ -655,7 +655,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
655
655
|
};
|
|
656
656
|
})
|
|
657
657
|
};
|
|
658
|
-
},
|
|
658
|
+
}, J = (e) => {
|
|
659
659
|
let t = /* @__PURE__ */ new Map(), n = 0, r = !1, i = async () => {
|
|
660
660
|
if (t.size === 0) return;
|
|
661
661
|
let r = t;
|
|
@@ -687,7 +687,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
687
687
|
},
|
|
688
688
|
pending: () => n
|
|
689
689
|
};
|
|
690
|
-
},
|
|
690
|
+
}, me = (e) => (t, n, r) => e().add(t, n, r), he = (e) => e === void 0 || e === "memory" ? "memory" : typeof e.query == "function" ? e.engineKind === "memory" ? "memory" : "custom" : "vendor", ge = class extends Error {
|
|
691
691
|
_tag = "SearchBackendNotDurable";
|
|
692
692
|
constructor(e) {
|
|
693
693
|
super(e), this.name = "SearchBackendNotDurable";
|
|
@@ -721,25 +721,25 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
721
721
|
} : {
|
|
722
722
|
level: "refuse",
|
|
723
723
|
message: _e
|
|
724
|
-
}, be = (e, t) => t ? `search: replica "${e}" joined, but this app declared \`singleProcessMemoryIndex: true\`. That declaration is now false: each replica has its own in-memory index, so search results depend on which one serves the request. Configure a durable backend (typesense / meilisearch / algolia) or run one process.` : `search: replica "${e}" joined while search is served from an in-memory index. Each replica indexes only its OWN writes, so results depend on which replica answers. Configure a durable backend (typesense / meilisearch / algolia) before relying on these results.`,
|
|
725
|
-
id:
|
|
726
|
-
indexName:
|
|
727
|
-
sourceTable:
|
|
728
|
-
rowId:
|
|
729
|
-
docId:
|
|
730
|
-
op:
|
|
731
|
-
attempts:
|
|
732
|
-
lastError:
|
|
733
|
-
firstFailedAt:
|
|
734
|
-
lastFailedAt:
|
|
724
|
+
}, be = (e, t) => t ? `search: replica "${e}" joined, but this app declared \`singleProcessMemoryIndex: true\`. That declaration is now false: each replica has its own in-memory index, so search results depend on which one serves the request. Configure a durable backend (typesense / meilisearch / algolia) or run one process.` : `search: replica "${e}" joined while search is served from an in-memory index. Each replica indexes only its OWN writes, so results depend on which replica answers. Configure a durable backend (typesense / meilisearch / algolia) before relying on these results.`, Y = "_voltro_search_drift", xe = b(Y, {
|
|
725
|
+
id: _({ prefix: "sdrft" }),
|
|
726
|
+
indexName: x().maxLength(191),
|
|
727
|
+
sourceTable: x().maxLength(191),
|
|
728
|
+
rowId: x().maxLength(191),
|
|
729
|
+
docId: x().maxLength(191),
|
|
730
|
+
op: x().maxLength(16),
|
|
731
|
+
attempts: v().default(0),
|
|
732
|
+
lastError: x().maxLength(1e3),
|
|
733
|
+
firstFailedAt: S(),
|
|
734
|
+
lastFailedAt: S()
|
|
735
735
|
}).unique("bySearchDriftIndexRow", ["indexName", "rowId"]).index("bySearchDriftIndex", ["indexName"]), Se = (e, t) => ({
|
|
736
736
|
table: e,
|
|
737
|
-
predicate:
|
|
737
|
+
predicate: g("id", t),
|
|
738
738
|
order: [],
|
|
739
739
|
take: 1,
|
|
740
740
|
skip: void 0,
|
|
741
741
|
projection: void 0
|
|
742
|
-
}),
|
|
742
|
+
}), X = (e) => e ? new Date(e).toISOString() : (/* @__PURE__ */ new Date(0)).toISOString(), Ce = (e) => ({
|
|
743
743
|
indexName: String(e.indexName),
|
|
744
744
|
sourceTable: String(e.sourceTable),
|
|
745
745
|
rowId: String(e.rowId),
|
|
@@ -747,8 +747,8 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
747
747
|
op: e.op === "remove" ? "remove" : "upsert",
|
|
748
748
|
attempts: Number(e.attempts ?? 0),
|
|
749
749
|
lastError: String(e.lastError ?? ""),
|
|
750
|
-
firstFailedAt:
|
|
751
|
-
lastFailedAt:
|
|
750
|
+
firstFailedAt: X(e.firstFailedAt),
|
|
751
|
+
lastFailedAt: X(e.lastFailedAt)
|
|
752
752
|
}), we = () => {
|
|
753
753
|
let e = /* @__PURE__ */ new Map(), t = (e, t) => `${e}\u0000${t}`;
|
|
754
754
|
return {
|
|
@@ -779,8 +779,8 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
779
779
|
e.delete(t(n, r));
|
|
780
780
|
}
|
|
781
781
|
};
|
|
782
|
-
}, Te = () => `sdrft_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
|
|
783
|
-
table:
|
|
782
|
+
}, Te = () => `sdrft_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`, Z = (e, t) => ({
|
|
783
|
+
table: Y,
|
|
784
784
|
predicate: e,
|
|
785
785
|
order: [{
|
|
786
786
|
column: "firstFailedAt",
|
|
@@ -791,7 +791,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
791
791
|
projection: void 0
|
|
792
792
|
}), Ee = (e) => ({
|
|
793
793
|
record: async (t) => {
|
|
794
|
-
let n = /* @__PURE__ */ new Date(), r = Te(), i = await e.insertIgnore(
|
|
794
|
+
let n = /* @__PURE__ */ new Date(), r = Te(), i = await e.insertIgnore(Y, {
|
|
795
795
|
id: r,
|
|
796
796
|
indexName: t.indexName,
|
|
797
797
|
sourceTable: t.sourceTable,
|
|
@@ -803,27 +803,27 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
803
803
|
firstFailedAt: n,
|
|
804
804
|
lastFailedAt: n
|
|
805
805
|
}, { conflictColumns: ["indexName", "rowId"] });
|
|
806
|
-
String(i.id) !== r && await e.updateMany(
|
|
806
|
+
String(i.id) !== r && await e.updateMany(Y, {
|
|
807
807
|
attempts: Number(i.attempts ?? 0) + 1,
|
|
808
808
|
op: t.op,
|
|
809
809
|
docId: t.docId,
|
|
810
810
|
lastError: t.error.slice(0, 1e3),
|
|
811
811
|
lastFailedAt: n
|
|
812
|
-
}, { where:
|
|
812
|
+
}, { where: g("id", String(i.id)) });
|
|
813
813
|
},
|
|
814
|
-
list: async (t) => (await e.query(
|
|
814
|
+
list: async (t) => (await e.query(Z(void 0, t))).map(Ce),
|
|
815
815
|
summary: async (t) => {
|
|
816
816
|
let n = (await e.query({
|
|
817
|
-
...
|
|
817
|
+
...Z(g("indexName", t), void 0),
|
|
818
818
|
order: [],
|
|
819
|
-
aggregations: [
|
|
819
|
+
aggregations: [h("n")]
|
|
820
820
|
}))[0], r = Number(n?.n ?? n?.count ?? 0);
|
|
821
821
|
if (r === 0) return {
|
|
822
822
|
pending: 0,
|
|
823
823
|
lastFailedAt: null
|
|
824
824
|
};
|
|
825
825
|
let i = await e.query({
|
|
826
|
-
...
|
|
826
|
+
...Z(g("indexName", t), 1),
|
|
827
827
|
order: [{
|
|
828
828
|
column: "lastFailedAt",
|
|
829
829
|
direction: "desc"
|
|
@@ -831,21 +831,21 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
831
831
|
});
|
|
832
832
|
return {
|
|
833
833
|
pending: r,
|
|
834
|
-
lastFailedAt: i[0] ?
|
|
834
|
+
lastFailedAt: i[0] ? X(i[0].lastFailedAt) : null
|
|
835
835
|
};
|
|
836
836
|
},
|
|
837
837
|
clear: async (t, n) => {
|
|
838
|
-
await e.deleteMany(
|
|
838
|
+
await e.deleteMany(Y, { where: m(g("indexName", t), g("rowId", n)) });
|
|
839
839
|
}
|
|
840
840
|
}), De = () => [xe], Oe = (e, t) => {
|
|
841
|
-
if (e === void 0 || e === "memory") return
|
|
841
|
+
if (e === void 0 || e === "memory") return N();
|
|
842
842
|
if (typeof e.query == "function") return e;
|
|
843
843
|
let n = e;
|
|
844
|
-
return n.engine === "typesense" ?
|
|
844
|
+
return n.engine === "typesense" ? ie(n, t) : n.engine === "meilisearch" ? R(n, t) : n.engine === "algolia" ? z(n, t) : N();
|
|
845
845
|
}, ke = async (e, t, n) => {
|
|
846
846
|
let r = n.map((e) => t.map(e));
|
|
847
847
|
return r.length > 0 && await e.upsert(t.index, r), r.length;
|
|
848
|
-
},
|
|
848
|
+
}, Ae = async (e, t, n) => {
|
|
849
849
|
if (n.op === "delete") {
|
|
850
850
|
let r = n.old?.id;
|
|
851
851
|
typeof r == "string" && await e.remove(t.index, [r]);
|
|
@@ -861,7 +861,7 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
861
861
|
reindexBatchSize: 1e3,
|
|
862
862
|
statsFlushIntervalMs: 5e3,
|
|
863
863
|
statsFlushMaxBuffered: 1e3
|
|
864
|
-
},
|
|
864
|
+
}, $ = (e) => ({
|
|
865
865
|
retries: Math.max(0, e?.retries ?? Q.retries),
|
|
866
866
|
retryBaseDelayMs: Math.max(1, e?.retryBaseDelayMs ?? Q.retryBaseDelayMs),
|
|
867
867
|
retryMaxDelayMs: Math.max(1, e?.retryMaxDelayMs ?? Q.retryMaxDelayMs),
|
|
@@ -870,12 +870,12 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
870
870
|
reindexBatchSize: Math.max(1, e?.reindexBatchSize ?? Q.reindexBatchSize),
|
|
871
871
|
statsFlushIntervalMs: Math.max(0, e?.statsFlushIntervalMs ?? Q.statsFlushIntervalMs),
|
|
872
872
|
statsFlushMaxBuffered: Math.max(1, e?.statsFlushMaxBuffered ?? Q.statsFlushMaxBuffered)
|
|
873
|
-
}), je = (e) => e instanceof
|
|
873
|
+
}), je = (e) => e instanceof k ? e : new k({
|
|
874
874
|
engine: "unknown",
|
|
875
875
|
op: "upsert",
|
|
876
876
|
message: String(e?.message ?? e),
|
|
877
877
|
transient: !1
|
|
878
|
-
}), Me = (e) =>
|
|
878
|
+
}), Me = (e) => f.exponential(c.millis(e.retryBaseDelayMs), 2).pipe(f.either(f.spaced(c.millis(e.retryMaxDelayMs))), f.intersect(f.recurs(e.retries)), f.whileInput((e) => e.transient)), Ne = (e) => {
|
|
879
879
|
if (!e || e === "memory" || typeof e.query == "function") return;
|
|
880
880
|
let t = e;
|
|
881
881
|
try {
|
|
@@ -894,69 +894,69 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
894
894
|
...(e.filters ?? []).map((e) => ["filter", e.field]),
|
|
895
895
|
...(e.facets ?? []).map((e) => ["facet", e]),
|
|
896
896
|
...(e.highlight?.fields ?? []).map((e) => ["highlight", e])
|
|
897
|
-
],
|
|
898
|
-
let s =
|
|
899
|
-
base:
|
|
900
|
-
alias:
|
|
901
|
-
instance:
|
|
902
|
-
}),
|
|
903
|
-
...
|
|
904
|
-
onWarn: (e, t) =>
|
|
897
|
+
], Ie = i, Le = (i) => {
|
|
898
|
+
let s = te({
|
|
899
|
+
base: Ie,
|
|
900
|
+
alias: i.alias,
|
|
901
|
+
instance: i.name
|
|
902
|
+
}), c = () => void 0, f = () => void 0, m = $(i.sync), h = Me(m), g = Oe(i.backend, {
|
|
903
|
+
...i.allowedEngineParams ? { allowEngineParams: i.allowedEngineParams } : {},
|
|
904
|
+
onWarn: (e, t) => c(e, t)
|
|
905
905
|
}), _ = /* @__PURE__ */ new Map();
|
|
906
|
-
for (let e of Object.values(
|
|
907
|
-
let v =
|
|
908
|
-
...
|
|
906
|
+
for (let e of Object.values(i.indexes)) _.set(e.index, e);
|
|
907
|
+
let v = he(i.backend), b = i.singleProcessMemoryIndex === !0, x = !1, S, C = {
|
|
908
|
+
...r,
|
|
909
909
|
description: "Full-text search an index (facets/highlight/fuzzy/filters), auto-scoped to the caller tenant.",
|
|
910
|
-
execute: (
|
|
911
|
-
let { index: i, q: a, limit: o, offset: s, filters:
|
|
912
|
-
if (!m) return
|
|
913
|
-
let h =
|
|
914
|
-
...
|
|
910
|
+
execute: (t, r) => {
|
|
911
|
+
let { index: i, q: a, limit: o, offset: s, filters: c, facets: u, highlight: d, fuzziness: f, engineParams: p } = t, m = _.get(i);
|
|
912
|
+
if (!m) return l.fail(new n({ index: i }));
|
|
913
|
+
let h = ne(Fe({
|
|
914
|
+
...c ? { filters: c } : {},
|
|
915
915
|
...u ? { facets: u } : {},
|
|
916
916
|
...d ? { highlight: d } : {}
|
|
917
917
|
}), m.queryableFields);
|
|
918
|
-
if (h) return
|
|
919
|
-
let
|
|
920
|
-
if (
|
|
918
|
+
if (h) return l.fail(new e(h));
|
|
919
|
+
let v = r.request.subject.tenantId ?? null, y = Pe(m.tenantField, v, c);
|
|
920
|
+
if (y === null) return l.succeed({
|
|
921
921
|
hits: [],
|
|
922
922
|
facets: {}
|
|
923
923
|
});
|
|
924
|
-
let
|
|
924
|
+
let b = {
|
|
925
925
|
q: a,
|
|
926
926
|
...o === void 0 ? {} : { limit: o },
|
|
927
927
|
...s === void 0 ? {} : { offset: s },
|
|
928
|
-
...
|
|
928
|
+
...y.length > 0 ? { filters: y } : {},
|
|
929
929
|
...u && u.length > 0 ? { facets: u } : {},
|
|
930
930
|
...d ? { highlight: d } : {},
|
|
931
931
|
...f === void 0 ? {} : { fuzziness: f },
|
|
932
932
|
...p ? { engineParams: p } : {}
|
|
933
933
|
};
|
|
934
|
-
return
|
|
934
|
+
return l.promise(() => g.query(i, b));
|
|
935
935
|
}
|
|
936
|
-
},
|
|
936
|
+
}, w = Ne(i.backend), T = [
|
|
937
937
|
"store:changes:read",
|
|
938
938
|
"store:write",
|
|
939
939
|
"inspect:read",
|
|
940
940
|
"inspect:write",
|
|
941
|
-
...
|
|
942
|
-
],
|
|
941
|
+
...w ? [`network:outbound:${w}`] : []
|
|
942
|
+
], E = W(), D = we(), O, k, A, j, M = (e, t, n) => j === void 0 ? l.tryPromise(() => E.bump(e, t, n)).pipe(l.catchAll((n) => l.sync(() => c("search stats bump failed", {
|
|
943
943
|
index: e,
|
|
944
944
|
kind: t,
|
|
945
945
|
error: String(n)
|
|
946
|
-
})))) :
|
|
947
|
-
let t = await
|
|
946
|
+
})))) : l.sync(() => j.bump(e, t, n)), N = async (e) => {
|
|
947
|
+
let t = await D.list(e), n = 0, r = 0;
|
|
948
948
|
for (let e of t) {
|
|
949
949
|
let t = _.get(e.indexName);
|
|
950
950
|
if (!t) {
|
|
951
|
-
await
|
|
951
|
+
await D.clear(e.indexName, e.rowId);
|
|
952
952
|
continue;
|
|
953
953
|
}
|
|
954
954
|
try {
|
|
955
|
-
if (!
|
|
956
|
-
let r = (await
|
|
957
|
-
r ? await g.upsert(t.index, [t.map(r)]) : await g.remove(t.index, [e.docId]), await
|
|
955
|
+
if (!k) throw Error("data store not bound");
|
|
956
|
+
let r = (await k.query(Se(e.sourceTable, e.rowId)))[0];
|
|
957
|
+
r ? await g.upsert(t.index, [t.map(r)]) : await g.remove(t.index, [e.docId]), await D.clear(e.indexName, e.rowId), n++;
|
|
958
958
|
} catch (t) {
|
|
959
|
-
r++, await
|
|
959
|
+
r++, await D.record({
|
|
960
960
|
...e,
|
|
961
961
|
error: String(t?.message ?? t)
|
|
962
962
|
}).catch(() => void 0);
|
|
@@ -967,30 +967,30 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
967
967
|
repaired: n,
|
|
968
968
|
failed: r
|
|
969
969
|
};
|
|
970
|
-
},
|
|
970
|
+
}, P = (e) => ({
|
|
971
971
|
kind: "json",
|
|
972
972
|
data: e
|
|
973
|
-
}),
|
|
973
|
+
}), F = (e, t) => ({
|
|
974
974
|
kind: "json",
|
|
975
975
|
status: e,
|
|
976
976
|
data: { error: t }
|
|
977
977
|
});
|
|
978
|
-
return
|
|
978
|
+
return ee({
|
|
979
979
|
name: s,
|
|
980
|
-
baseName:
|
|
980
|
+
baseName: Ie,
|
|
981
981
|
description: "External search index sync (Typesense/Meilisearch/Algolia/memory) via the ChangeEvent tap + a tenant-scoped query route.",
|
|
982
|
-
permissions:
|
|
983
|
-
routes: [
|
|
984
|
-
rpcClientDescriptors:
|
|
982
|
+
permissions: T,
|
|
983
|
+
routes: [C],
|
|
984
|
+
rpcClientDescriptors: t,
|
|
985
985
|
inspectEndpoints: [
|
|
986
986
|
{
|
|
987
987
|
method: "GET",
|
|
988
988
|
path: "/indexes",
|
|
989
989
|
description: "Configured indexes + durable, cross-replica sync stats + current index drift.",
|
|
990
|
-
handler: () =>
|
|
991
|
-
await
|
|
992
|
-
let e = await Promise.all(Object.entries(
|
|
993
|
-
let n = await
|
|
990
|
+
handler: () => l.promise(async () => {
|
|
991
|
+
await j?.flushNow();
|
|
992
|
+
let e = await Promise.all(Object.entries(i.indexes).map(async ([e, t]) => {
|
|
993
|
+
let n = await E.get(t.index), r = await D.summary(t.index);
|
|
994
994
|
return {
|
|
995
995
|
table: e,
|
|
996
996
|
index: t.index,
|
|
@@ -1001,15 +1001,15 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
1001
1001
|
drifted: r.pending > 0
|
|
1002
1002
|
};
|
|
1003
1003
|
}));
|
|
1004
|
-
return
|
|
1004
|
+
return P({
|
|
1005
1005
|
indexes: e,
|
|
1006
|
-
backend: typeof
|
|
1006
|
+
backend: typeof i.backend == "string" ? i.backend : i.backend ? "custom/vendor" : "memory",
|
|
1007
1007
|
durable: v !== "memory",
|
|
1008
|
-
singleProcessMemoryIndex:
|
|
1008
|
+
singleProcessMemoryIndex: b,
|
|
1009
1009
|
pendingDrift: e.reduce((e, t) => e + t.pendingDrift, 0),
|
|
1010
1010
|
sync: {
|
|
1011
1011
|
...m,
|
|
1012
|
-
resyncArmed:
|
|
1012
|
+
resyncArmed: O !== void 0
|
|
1013
1013
|
}
|
|
1014
1014
|
});
|
|
1015
1015
|
})
|
|
@@ -1018,31 +1018,31 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
1018
1018
|
method: "GET",
|
|
1019
1019
|
path: "/drift",
|
|
1020
1020
|
description: "The changes that did NOT reach the engine, oldest first (the repair queue).",
|
|
1021
|
-
handler: (e) =>
|
|
1022
|
-
let t = Number(new URL(e.url, "http://localhost").searchParams.get("limit") ?? 100), n = await
|
|
1023
|
-
return
|
|
1021
|
+
handler: (e) => l.promise(async () => {
|
|
1022
|
+
let t = Number(new URL(e.url, "http://localhost").searchParams.get("limit") ?? 100), n = await D.list(Number.isFinite(t) && t > 0 ? Math.min(t, 1e3) : 100);
|
|
1023
|
+
return P({ entries: n });
|
|
1024
1024
|
})
|
|
1025
1025
|
},
|
|
1026
1026
|
{
|
|
1027
1027
|
method: "POST",
|
|
1028
1028
|
path: "/resync",
|
|
1029
1029
|
description: "Repair drifted rows now — re-reads each from the DB and re-applies it.",
|
|
1030
|
-
handler: (e) =>
|
|
1030
|
+
handler: (e) => l.promise(async () => {
|
|
1031
1031
|
let t;
|
|
1032
1032
|
try {
|
|
1033
1033
|
t = JSON.parse(e.body || "{}");
|
|
1034
1034
|
} catch {
|
|
1035
|
-
return
|
|
1035
|
+
return F(400, "invalid JSON body");
|
|
1036
1036
|
}
|
|
1037
|
-
if (!
|
|
1037
|
+
if (!k) return F(503, "data store not bound yet");
|
|
1038
1038
|
try {
|
|
1039
|
-
let e = await
|
|
1040
|
-
return
|
|
1039
|
+
let e = await N(Math.min(Math.max(1, t.limit ?? m.resyncBatchSize), 1e3));
|
|
1040
|
+
return P({
|
|
1041
1041
|
ok: !0,
|
|
1042
1042
|
...e
|
|
1043
1043
|
});
|
|
1044
1044
|
} catch (e) {
|
|
1045
|
-
return
|
|
1045
|
+
return F(500, e.message);
|
|
1046
1046
|
}
|
|
1047
1047
|
})
|
|
1048
1048
|
},
|
|
@@ -1050,32 +1050,32 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
1050
1050
|
method: "POST",
|
|
1051
1051
|
path: "/reindex",
|
|
1052
1052
|
description: "Re-seed an index from the table's current rows (streamed in bounded batches).",
|
|
1053
|
-
handler: (e) =>
|
|
1053
|
+
handler: (e) => l.promise(async () => {
|
|
1054
1054
|
let t;
|
|
1055
1055
|
try {
|
|
1056
1056
|
t = JSON.parse(e.body || "{}");
|
|
1057
1057
|
} catch {
|
|
1058
|
-
return
|
|
1058
|
+
return F(400, "invalid JSON body");
|
|
1059
1059
|
}
|
|
1060
|
-
let n = t.table, r = n ?
|
|
1061
|
-
if (!n || !r) return
|
|
1062
|
-
if (!
|
|
1063
|
-
let s = 0,
|
|
1060
|
+
let n = t.table, r = n ? i.indexes[n] : void 0;
|
|
1061
|
+
if (!n || !r) return F(404, `no index configured for table "${t.table ?? ""}"`);
|
|
1062
|
+
if (!A) return F(503, "data store not bound yet");
|
|
1063
|
+
let s = 0, c = await l.runPromiseExit(y(A, {
|
|
1064
1064
|
table: n,
|
|
1065
1065
|
chunkSize: m.reindexBatchSize
|
|
1066
|
-
}).pipe(
|
|
1067
|
-
s += await ke(g, r,
|
|
1066
|
+
}).pipe(p.chunks, p.runForEach((e) => l.tryPromise(async () => {
|
|
1067
|
+
s += await ke(g, r, o.toReadonlyArray(e));
|
|
1068
1068
|
}))));
|
|
1069
|
-
if (
|
|
1070
|
-
let e =
|
|
1071
|
-
return
|
|
1069
|
+
if (u.isFailure(c)) {
|
|
1070
|
+
let e = a.failureOption(c.cause), t = d.isSome(e) ? e.value : c.cause, n = t.cause ?? t.error ?? t;
|
|
1071
|
+
return F(500, String(n?.message ?? n));
|
|
1072
1072
|
}
|
|
1073
1073
|
try {
|
|
1074
|
-
await
|
|
1074
|
+
await E.recordReindex(r.index, s, (/* @__PURE__ */ new Date()).toISOString());
|
|
1075
1075
|
} catch (e) {
|
|
1076
|
-
return
|
|
1076
|
+
return F(500, e.message);
|
|
1077
1077
|
}
|
|
1078
|
-
return
|
|
1078
|
+
return P({
|
|
1079
1079
|
ok: !0,
|
|
1080
1080
|
table: n,
|
|
1081
1081
|
index: r.index,
|
|
@@ -1084,91 +1084,91 @@ var x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
|
|
|
1084
1084
|
})
|
|
1085
1085
|
}
|
|
1086
1086
|
],
|
|
1087
|
-
extendSchema: { tables: [...
|
|
1087
|
+
extendSchema: { tables: [...U(), ...De()] },
|
|
1088
1088
|
bindDataStore: (e, t) => {
|
|
1089
|
-
|
|
1090
|
-
e.kind === "left" ||
|
|
1089
|
+
k = e, A = e, E = q(e), D = Ee(e), v === "memory" && t?.membership !== void 0 && (S = t.membership.onChange((e) => {
|
|
1090
|
+
e.kind === "left" || x || (t.instanceId === void 0 || e.instanceId !== t.instanceId) && (x = !0, c(be(e.instanceId, b), {
|
|
1091
1091
|
instanceId: t.instanceId ?? null,
|
|
1092
1092
|
peer: e.instanceId,
|
|
1093
|
-
indexes: Object.keys(
|
|
1093
|
+
indexes: Object.keys(i.indexes)
|
|
1094
1094
|
}));
|
|
1095
|
-
})), !(m.resyncIntervalMs <= 0 || t?.scheduleCoordinated === void 0) && (
|
|
1095
|
+
})), !(m.resyncIntervalMs <= 0 || t?.scheduleCoordinated === void 0) && (O = t.scheduleCoordinated("search.resync", m.resyncIntervalMs, async () => {
|
|
1096
1096
|
try {
|
|
1097
|
-
let e = await
|
|
1098
|
-
return (e.repaired > 0 || e.failed > 0) &&
|
|
1097
|
+
let e = await N(m.resyncBatchSize);
|
|
1098
|
+
return (e.repaired > 0 || e.failed > 0) && f("search: drift repair pass", e), { idle: e.scanned === 0 };
|
|
1099
1099
|
} catch (e) {
|
|
1100
|
-
return
|
|
1100
|
+
return c("search: drift repair pass failed", { error: String(e?.message ?? e) }), { idle: !1 };
|
|
1101
1101
|
}
|
|
1102
1102
|
}));
|
|
1103
1103
|
},
|
|
1104
1104
|
onChangeEvent: (e) => {
|
|
1105
|
-
let t =
|
|
1106
|
-
if (!t) return
|
|
1107
|
-
let n = e.changeScope, r = e.changeScope === "fleet" || e.origin !== "injected",
|
|
1108
|
-
if (e.op === "delete" || !e.new) return
|
|
1105
|
+
let t = i.indexes[e.table];
|
|
1106
|
+
if (!t) return l.void;
|
|
1107
|
+
let n = e.changeScope, r = e.changeScope === "fleet" || e.origin !== "injected", a = e.op === "delete" ? e.old : e.new, o = typeof a?.id == "string" ? a.id : "", s = e.op === "delete" ? "remove" : "upsert", u = () => {
|
|
1108
|
+
if (e.op === "delete" || !e.new) return o;
|
|
1109
1109
|
try {
|
|
1110
|
-
return String(t.map(e.new).id ??
|
|
1110
|
+
return String(t.map(e.new).id ?? o);
|
|
1111
1111
|
} catch {
|
|
1112
|
-
return
|
|
1112
|
+
return o;
|
|
1113
1113
|
}
|
|
1114
1114
|
};
|
|
1115
|
-
return
|
|
1116
|
-
try: () =>
|
|
1115
|
+
return l.tryPromise({
|
|
1116
|
+
try: () => Ae(g, t, e),
|
|
1117
1117
|
catch: je
|
|
1118
|
-
}).pipe(
|
|
1119
|
-
onSuccess: () => r ?
|
|
1118
|
+
}).pipe(l.retry(h)).pipe(l.matchEffect({
|
|
1119
|
+
onSuccess: () => r ? M(t.index, e.op === "delete" ? "removed" : "synced", n) : l.void,
|
|
1120
1120
|
onFailure: (r) => {
|
|
1121
1121
|
let i = {
|
|
1122
1122
|
table: e.table,
|
|
1123
1123
|
index: t.index,
|
|
1124
1124
|
op: e.op,
|
|
1125
|
-
rowId:
|
|
1125
|
+
rowId: o,
|
|
1126
1126
|
transient: r.transient,
|
|
1127
1127
|
error: r.message
|
|
1128
1128
|
};
|
|
1129
|
-
return
|
|
1129
|
+
return o === "" ? l.sync(() => c("search: change not indexed and NOT recoverable (row has no id)", i)).pipe(l.zipRight(l.fail(r))) : l.tryPromise(() => D.record({
|
|
1130
1130
|
indexName: t.index,
|
|
1131
1131
|
sourceTable: e.table,
|
|
1132
|
-
rowId:
|
|
1133
|
-
docId:
|
|
1132
|
+
rowId: o,
|
|
1133
|
+
docId: u(),
|
|
1134
1134
|
op: s,
|
|
1135
1135
|
error: r.message
|
|
1136
|
-
})).pipe(
|
|
1137
|
-
onSuccess: () =>
|
|
1138
|
-
onFailure: (e) =>
|
|
1136
|
+
})).pipe(l.matchEffect({
|
|
1137
|
+
onSuccess: () => M(t.index, "dropped", n).pipe(l.zipRight(l.sync(() => c("search: index drift recorded — will be repaired from the database", i)))),
|
|
1138
|
+
onFailure: (e) => l.sync(() => c("search: change LOST — engine failed and the drift ledger could not record it", {
|
|
1139
1139
|
...i,
|
|
1140
1140
|
ledgerError: String(e)
|
|
1141
|
-
})).pipe(
|
|
1141
|
+
})).pipe(l.zipRight(l.fail(r)))
|
|
1142
1142
|
}));
|
|
1143
1143
|
}
|
|
1144
1144
|
}));
|
|
1145
1145
|
},
|
|
1146
|
-
onActivate: (e) =>
|
|
1147
|
-
|
|
1146
|
+
onActivate: (e) => l.suspend(() => {
|
|
1147
|
+
c = (t, n) => e.logger.warn(t, n), f = (t, n) => e.logger.info(t, n);
|
|
1148
1148
|
let t = ye({
|
|
1149
1149
|
backendKind: v,
|
|
1150
1150
|
production: (e.env?.NODE_ENV ?? process.env.NODE_ENV) === "production",
|
|
1151
|
-
singleProcessDeclared:
|
|
1151
|
+
singleProcessDeclared: b
|
|
1152
1152
|
});
|
|
1153
|
-
return t.level === "refuse" ?
|
|
1154
|
-
flush:
|
|
1153
|
+
return t.level === "refuse" ? l.fail(new ge(t.message)) : (t.level === "note" && e.logger.info(t.message, { indexes: Object.keys(i.indexes) }), m.statsFlushIntervalMs > 0 && j === void 0 && (j = J({
|
|
1154
|
+
flush: me(() => E),
|
|
1155
1155
|
intervalMs: m.statsFlushIntervalMs,
|
|
1156
1156
|
maxBuffered: m.statsFlushMaxBuffered
|
|
1157
|
-
})),
|
|
1157
|
+
})), l.sync(() => {
|
|
1158
1158
|
e.logger.info("search active", {
|
|
1159
|
-
indexes: Object.keys(
|
|
1160
|
-
backend: typeof
|
|
1159
|
+
indexes: Object.keys(i.indexes),
|
|
1160
|
+
backend: typeof i.backend == "string" ? i.backend : "custom/vendor",
|
|
1161
1161
|
durable: v !== "memory",
|
|
1162
1162
|
sync: m
|
|
1163
1163
|
});
|
|
1164
1164
|
}));
|
|
1165
1165
|
}),
|
|
1166
|
-
onDeactivate: () =>
|
|
1167
|
-
|
|
1168
|
-
let e =
|
|
1169
|
-
|
|
1166
|
+
onDeactivate: () => l.promise(async () => {
|
|
1167
|
+
O?.stop(), O = void 0, S?.(), S = void 0, x = !1;
|
|
1168
|
+
let e = j;
|
|
1169
|
+
j = void 0, await e?.shutdown();
|
|
1170
1170
|
})
|
|
1171
1171
|
});
|
|
1172
1172
|
};
|
|
1173
1173
|
//#endregion
|
|
1174
|
-
export {
|
|
1174
|
+
export { C as FIELD_NAME_PATTERN, Y as SEARCH_DRIFT_TABLE, B as SEARCH_STATS_TABLE, Q as SYNC_DEFAULTS, k as SearchBackendError, ge as SearchBackendNotDurable, e as SearchFieldRejected, n as SearchIndexNotFound, z as algoliaBackend, O as allowedEngineParams, Ae as applyChange, je as asBackendError, ye as auditMemoryBackend, he as backendKindOf, ke as backfillIndex, Ee as dataStoreDriftLedger, q as dataStoreStatsStore, Se as driftSourceQuery, De as driftTables, w as isSafeFieldName, J as makeSearchStatsBuffer, R as meilisearchBackend, N as memoryBackend, we as memoryDriftLedger, W as memoryStatsStore, be as peerObservedWarning, $ as resolveSyncOptions, D as sanitizeEngineParams, Pe as scopeSearchFilters, xe as searchDriftTable, Le as searchPlugin, H as searchStatsTable, U as searchTables, me as statsStoreFlush, Me as syncRetrySchedule, ie as typesenseBackend };
|