@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/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { a as e, i as t, n, r } from "./rpc-DaYt-dP6.js";
2
- import { Cause as i, Chunk as a, Data as o, Duration as s, Effect as c, Exit as l, Option as u, Schedule as d, Stream as f } from "effect";
3
- import { and as p, count as m, eq as h, id as g, integer as _, streamTable as ee, table as v, text as y, timestamp as b } from "@voltro/database";
4
- import { definePlugin as te, pluginInstanceName as ne } from "@voltro/protocol";
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 x = /^[A-Za-z_][A-Za-z0-9_.]*$/, S = (e) => x.test(e), re = (e, t) => {
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 (!S(r)) return {
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
- }, C = {
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
- }, ie = {
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
- }, w = (e, t, n) => {
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(ie[e]), i = new Set(C[e]), a = new Set(n ?? []), o = {}, s = {}, c = [];
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
- }, T = (e) => C[e], E = class extends o.TaggedError("SearchBackendError") {}, D = (e) => Array.isArray(e) ? e : [e], O = (e, t, n) => {
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
- }, k = (e) => e.length <= 4 ? 1 : 2, A = () => {
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 D(t.value).some((e) => String(n) === String(e));
150
- case "nin": return D(t.value).every((e) => String(n) !== String(e));
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] = [j(n), j(t.value)];
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" ? k(t) : n;
166
- for (let n of e.split(/\s+/)) if (O(n, t, r)) return !0;
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
- }, j = (e) => {
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
- }, M = async (e, t, n) => {
219
+ }, F = async (e, t, n) => {
220
220
  try {
221
221
  return await n();
222
222
  } catch {
223
- throw new E({
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
- }, N = (e, t) => (n) => {
231
- let { params: r, appAllowed: i, dropped: a } = w(e, n, t.allowEngineParams);
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
- }, P = (e, t) => {
240
- if (!S(t)) throw new E({
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
- }, ae = (e) => {
248
- let t = (e) => JSON.stringify(e), n = P("typesense", e.field);
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}:[${D(e.value).map(t).join(",")}]`;
257
- case "nin": return `${n}:!=[${D(e.value).map(t).join(",")}]`;
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
- }, oe = (e, t = {}) => {
260
- let n = N("typesense", t), r, i = async () => (r ||= M("typesense", "typesense", () => import("typesense")).then((t) => {
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(ae).join(" && ") : void 0, o = async (e, t) => {
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 E ? t : new E({
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 se(await o.collections(e).documents().search(m));
302
+ return ae(await o.collections(e).documents().search(m));
303
303
  })
304
304
  };
305
- }, se = (e) => {
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
- }, ce = (e) => {
323
- let t = (e) => JSON.stringify(e), n = P("meilisearch", e.field);
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 [${D(e.value).map(t).join(", ")}]`;
332
- case "nin": return `${n} NOT IN [${D(e.value).map(t).join(", ")}]`;
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
- }, F = (e, t = {}) => {
335
- let n = N("meilisearch", t), r, i = async () => (r ||= M("meilisearch", "meilisearch", () => import("meilisearch")).then((t) => new t.MeiliSearch({
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(ce) : void 0, o = async (e, t) => {
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 E ? t : new E({
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 le(await (await i()).index(e).search(t, p), u);
375
+ return se(await (await i()).index(e).search(t, p), u);
376
376
  })
377
377
  };
378
- }, le = (e, t) => ({
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
- }), ue = (e) => String(e).replace(/^-/, "\\-"), de = (e, t) => {
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 E({
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
- }, fe = (e) => {
401
+ }, ue = (e) => {
402
402
  let t = [], n = [];
403
403
  for (let r of e ?? []) {
404
- let e = P("algolia", r.field), i = (e) => ue(e), a = (t) => de(e, t);
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(D(r.value).map((t) => `${e}:${i(t)}`));
413
+ t.push(A(r.value).map((t) => `${e}:${i(t)}`));
414
414
  break;
415
415
  case "nin":
416
- for (let n of D(r.value)) t.push(`${e}:-${i(n)}`);
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
- }, I = (e, t = {}) => {
435
- let n = N("algolia", t), r, i = async () => (r ||= M("algoliasearch", "algolia", () => import("algoliasearch")).then((t) => t.algoliasearch(e.appId ?? "", e.apiKey)), r), a = async (e, t) => {
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 E ? t : new E({
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 } = fe(s), p = o ? {
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 pe(await (await i()).searchSingleIndex({
482
+ return de(await (await i()).searchSingleIndex({
483
483
  indexName: e,
484
484
  searchParams: h
485
485
  }), l);
486
486
  })
487
487
  };
488
- }, pe = (e, t) => ({
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
- }), L = "_voltro_search_stats", R = () => ({
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
- }), z = v(L, {
509
- id: g({ prefix: "sstat" }),
510
- indexName: y().maxLength(191),
511
- replicaId: y().maxLength(191),
512
- synced: _().default(0),
513
- removed: _().default(0),
514
- dropped: _().default(0),
515
- scope: y().maxLength(8).default("local"),
516
- lastReindexAt: b().nullable(),
517
- lastReindexCount: _().default(0),
518
- updatedAt: b()
519
- }).unique("bySearchStatsIndexReplica", ["indexName", "replicaId"]).index("bySearchStatsIndex", ["indexName"]), B = () => [z], V = () => {
520
- let e = /* @__PURE__ */ new Map(), t = (t) => e.get(t) ?? R();
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
- }, H = (e) => ({
556
- table: L,
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
- }), me = () => `sstat_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`, he = () => process.env.VOLTRO_REPLICA_ID ?? process.env.HOSTNAME ?? process.env.POD_NAME ?? `pid_${process.pid}_${Math.random().toString(36).slice(2, 8)}`, U = 32, W = (e, t = he()) => {
563
- let n = async (n) => (await e.query(H(p(h("indexName", n), h("replicaId", t)))))[0] ?? null, r = async (e) => {
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 E ? e : new E({
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 < U; 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: p(h("id", String(c.id)), h("synced", t), h("removed", n), h("dropped", r)) }) === 1) return;
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 = me(), r = await e.insertIgnore(L, {
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 E({
608
+ throw new k({
609
609
  engine: "stats",
610
610
  op: "upsert",
611
- message: `search stats: contention on (${i}, ${t}) exceeded ${U} attempts`,
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(H(h("indexName", t))), r = n.some((e) => e.scope === "fleet"), i = (e) => {
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
- ...R(),
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
- }, G = (e) => {
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
- }, K = (e) => (t, n, r) => e().add(t, n, r), q = (e) => e === void 0 || e === "memory" ? "memory" : typeof e.query == "function" ? e.engineKind === "memory" ? "memory" : "custom" : "vendor", ge = class extends Error {
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.`, J = "_voltro_search_drift", xe = v(J, {
725
- id: g({ prefix: "sdrft" }),
726
- indexName: y().maxLength(191),
727
- sourceTable: y().maxLength(191),
728
- rowId: y().maxLength(191),
729
- docId: y().maxLength(191),
730
- op: y().maxLength(16),
731
- attempts: _().default(0),
732
- lastError: y().maxLength(1e3),
733
- firstFailedAt: b(),
734
- lastFailedAt: b()
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: h("id", t),
737
+ predicate: g("id", t),
738
738
  order: [],
739
739
  take: 1,
740
740
  skip: void 0,
741
741
  projection: void 0
742
- }), Y = (e) => e ? new Date(e).toISOString() : (/* @__PURE__ */ new Date(0)).toISOString(), Ce = (e) => ({
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: Y(e.firstFailedAt),
751
- lastFailedAt: Y(e.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)}`, X = (e, t) => ({
783
- table: J,
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(J, {
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(J, {
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: h("id", String(i.id)) });
812
+ }, { where: g("id", String(i.id)) });
813
813
  },
814
- list: async (t) => (await e.query(X(void 0, t))).map(Ce),
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
- ...X(h("indexName", t), void 0),
817
+ ...Z(g("indexName", t), void 0),
818
818
  order: [],
819
- aggregations: [m("n")]
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
- ...X(h("indexName", t), 1),
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] ? Y(i[0].lastFailedAt) : null
834
+ lastFailedAt: i[0] ? X(i[0].lastFailedAt) : null
835
835
  };
836
836
  },
837
837
  clear: async (t, n) => {
838
- await e.deleteMany(J, { where: p(h("indexName", t), h("rowId", n)) });
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 A();
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" ? oe(n, t) : n.engine === "meilisearch" ? F(n, t) : n.engine === "algolia" ? I(n, t) : A();
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
- }, Z = async (e, t, n) => {
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
- }, Ae = (e) => ({
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 E ? e : new E({
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) => d.exponential(s.millis(e.retryBaseDelayMs), 2).pipe(d.either(d.spaced(s.millis(e.retryMaxDelayMs))), d.intersect(d.recurs(e.retries)), d.whileInput((e) => e.transient)), Ne = (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
- ], $ = "@voltro/plugin-search", Ie = (o) => {
898
- let s = ne({
899
- base: $,
900
- alias: o.alias,
901
- instance: o.name
902
- }), d = () => void 0, p = () => void 0, m = Ae(o.sync), h = Me(m), g = Oe(o.backend, {
903
- ...o.allowedEngineParams ? { allowEngineParams: o.allowedEngineParams } : {},
904
- onWarn: (e, t) => d(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(o.indexes)) _.set(e.index, e);
907
- let v = q(o.backend), y = o.singleProcessMemoryIndex === !0, b = !1, x, S = {
908
- ...n,
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: (n, r) => {
911
- let { index: i, q: a, limit: o, offset: s, filters: l, facets: u, highlight: d, fuzziness: f, engineParams: p } = n, m = _.get(i);
912
- if (!m) return c.fail(new e({ index: i }));
913
- let h = re(Fe({
914
- ...l ? { filters: l } : {},
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 c.fail(new t(h));
919
- let ee = r.request.subject.tenantId ?? null, v = Pe(m.tenantField, ee, l);
920
- if (v === null) return c.succeed({
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 y = {
924
+ let b = {
925
925
  q: a,
926
926
  ...o === void 0 ? {} : { limit: o },
927
927
  ...s === void 0 ? {} : { offset: s },
928
- ...v.length > 0 ? { filters: v } : {},
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 c.promise(() => g.query(i, y));
934
+ return l.promise(() => g.query(i, b));
935
935
  }
936
- }, C = Ne(o.backend), ie = [
936
+ }, w = Ne(i.backend), T = [
937
937
  "store:changes:read",
938
938
  "store:write",
939
939
  "inspect:read",
940
940
  "inspect:write",
941
- ...C ? [`network:outbound:${C}`] : []
942
- ], w = V(), T = we(), E, D, O, k, A = (e, t, n) => k === void 0 ? c.tryPromise(() => w.bump(e, t, n)).pipe(c.catchAll((n) => c.sync(() => d("search stats bump failed", {
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
- })))) : c.sync(() => k.bump(e, t, n)), j = async (e) => {
947
- let t = await T.list(e), n = 0, r = 0;
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 T.clear(e.indexName, e.rowId);
951
+ await D.clear(e.indexName, e.rowId);
952
952
  continue;
953
953
  }
954
954
  try {
955
- if (!D) throw Error("data store not bound");
956
- let r = (await D.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 T.clear(e.indexName, e.rowId), n++;
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 T.record({
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
- }, M = (e) => ({
970
+ }, P = (e) => ({
971
971
  kind: "json",
972
972
  data: e
973
- }), N = (e, t) => ({
973
+ }), F = (e, t) => ({
974
974
  kind: "json",
975
975
  status: e,
976
976
  data: { error: t }
977
977
  });
978
- return te({
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: ie,
983
- routes: [S],
984
- rpcClientDescriptors: r,
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: () => c.promise(async () => {
991
- await k?.flushNow();
992
- let e = await Promise.all(Object.entries(o.indexes).map(async ([e, t]) => {
993
- let n = await w.get(t.index), r = await T.summary(t.index);
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 M({
1004
+ return P({
1005
1005
  indexes: e,
1006
- backend: typeof o.backend == "string" ? o.backend : o.backend ? "custom/vendor" : "memory",
1006
+ backend: typeof i.backend == "string" ? i.backend : i.backend ? "custom/vendor" : "memory",
1007
1007
  durable: v !== "memory",
1008
- singleProcessMemoryIndex: y,
1008
+ singleProcessMemoryIndex: b,
1009
1009
  pendingDrift: e.reduce((e, t) => e + t.pendingDrift, 0),
1010
1010
  sync: {
1011
1011
  ...m,
1012
- resyncArmed: E !== void 0
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) => c.promise(async () => {
1022
- let t = Number(new URL(e.url, "http://localhost").searchParams.get("limit") ?? 100), n = await T.list(Number.isFinite(t) && t > 0 ? Math.min(t, 1e3) : 100);
1023
- return M({ entries: n });
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) => c.promise(async () => {
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 N(400, "invalid JSON body");
1035
+ return F(400, "invalid JSON body");
1036
1036
  }
1037
- if (!D) return N(503, "data store not bound yet");
1037
+ if (!k) return F(503, "data store not bound yet");
1038
1038
  try {
1039
- let e = await j(Math.min(Math.max(1, t.limit ?? m.resyncBatchSize), 1e3));
1040
- return M({
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 N(500, e.message);
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) => c.promise(async () => {
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 N(400, "invalid JSON body");
1058
+ return F(400, "invalid JSON body");
1059
1059
  }
1060
- let n = t.table, r = n ? o.indexes[n] : void 0;
1061
- if (!n || !r) return N(404, `no index configured for table "${t.table ?? ""}"`);
1062
- if (!O) return N(503, "data store not bound yet");
1063
- let s = 0, d = await c.runPromiseExit(ee(O, {
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(f.chunks, f.runForEach((e) => c.tryPromise(async () => {
1067
- s += await ke(g, r, a.toReadonlyArray(e));
1066
+ }).pipe(p.chunks, p.runForEach((e) => l.tryPromise(async () => {
1067
+ s += await ke(g, r, o.toReadonlyArray(e));
1068
1068
  }))));
1069
- if (l.isFailure(d)) {
1070
- let e = i.failureOption(d.cause), t = u.isSome(e) ? e.value : d.cause, n = t.cause ?? t.error ?? t;
1071
- return N(500, String(n?.message ?? n));
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 w.recordReindex(r.index, s, (/* @__PURE__ */ new Date()).toISOString());
1074
+ await E.recordReindex(r.index, s, (/* @__PURE__ */ new Date()).toISOString());
1075
1075
  } catch (e) {
1076
- return N(500, e.message);
1076
+ return F(500, e.message);
1077
1077
  }
1078
- return M({
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: [...B(), ...De()] },
1087
+ extendSchema: { tables: [...U(), ...De()] },
1088
1088
  bindDataStore: (e, t) => {
1089
- D = e, O = e, w = W(e), T = Ee(e), v === "memory" && t?.membership !== void 0 && (x = t.membership.onChange((e) => {
1090
- e.kind === "left" || b || (t.instanceId === void 0 || e.instanceId !== t.instanceId) && (b = !0, d(be(e.instanceId, y), {
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(o.indexes)
1093
+ indexes: Object.keys(i.indexes)
1094
1094
  }));
1095
- })), !(m.resyncIntervalMs <= 0 || t?.scheduleCoordinated === void 0) && (E = t.scheduleCoordinated("search.resync", m.resyncIntervalMs, async () => {
1095
+ })), !(m.resyncIntervalMs <= 0 || t?.scheduleCoordinated === void 0) && (O = t.scheduleCoordinated("search.resync", m.resyncIntervalMs, async () => {
1096
1096
  try {
1097
- let e = await j(m.resyncBatchSize);
1098
- return (e.repaired > 0 || e.failed > 0) && p("search: drift repair pass", e), { idle: e.scanned === 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 d("search: drift repair pass failed", { error: String(e?.message ?? e) }), { idle: !1 };
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 = o.indexes[e.table];
1106
- if (!t) return c.void;
1107
- let n = e.changeScope, r = e.changeScope === "fleet" || e.origin !== "injected", i = e.op === "delete" ? e.old : e.new, a = typeof i?.id == "string" ? i.id : "", s = e.op === "delete" ? "remove" : "upsert", l = () => {
1108
- if (e.op === "delete" || !e.new) return a;
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 ?? a);
1110
+ return String(t.map(e.new).id ?? o);
1111
1111
  } catch {
1112
- return a;
1112
+ return o;
1113
1113
  }
1114
1114
  };
1115
- return c.tryPromise({
1116
- try: () => Z(g, t, e),
1115
+ return l.tryPromise({
1116
+ try: () => Ae(g, t, e),
1117
1117
  catch: je
1118
- }).pipe(c.retry(h)).pipe(c.matchEffect({
1119
- onSuccess: () => r ? A(t.index, e.op === "delete" ? "removed" : "synced", n) : c.void,
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: a,
1125
+ rowId: o,
1126
1126
  transient: r.transient,
1127
1127
  error: r.message
1128
1128
  };
1129
- return a === "" ? c.sync(() => d("search: change not indexed and NOT recoverable (row has no id)", i)).pipe(c.zipRight(c.fail(r))) : c.tryPromise(() => T.record({
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: a,
1133
- docId: l(),
1132
+ rowId: o,
1133
+ docId: u(),
1134
1134
  op: s,
1135
1135
  error: r.message
1136
- })).pipe(c.matchEffect({
1137
- onSuccess: () => A(t.index, "dropped", n).pipe(c.zipRight(c.sync(() => d("search: index drift recorded — will be repaired from the database", i)))),
1138
- onFailure: (e) => c.sync(() => d("search: change LOST — engine failed and the drift ledger could not record it", {
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(c.zipRight(c.fail(r)))
1141
+ })).pipe(l.zipRight(l.fail(r)))
1142
1142
  }));
1143
1143
  }
1144
1144
  }));
1145
1145
  },
1146
- onActivate: (e) => c.suspend(() => {
1147
- d = (t, n) => e.logger.warn(t, n), p = (t, n) => e.logger.info(t, n);
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: y
1151
+ singleProcessDeclared: b
1152
1152
  });
1153
- return t.level === "refuse" ? c.fail(new ge(t.message)) : (t.level === "note" && e.logger.info(t.message, { indexes: Object.keys(o.indexes) }), m.statsFlushIntervalMs > 0 && k === void 0 && (k = G({
1154
- flush: K(() => w),
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
- })), c.sync(() => {
1157
+ })), l.sync(() => {
1158
1158
  e.logger.info("search active", {
1159
- indexes: Object.keys(o.indexes),
1160
- backend: typeof o.backend == "string" ? o.backend : "custom/vendor",
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: () => c.promise(async () => {
1167
- E?.stop(), E = void 0, x?.(), x = void 0, b = !1;
1168
- let e = k;
1169
- k = void 0, await e?.shutdown();
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 { x as FIELD_NAME_PATTERN, J as SEARCH_DRIFT_TABLE, L as SEARCH_STATS_TABLE, Q as SYNC_DEFAULTS, E as SearchBackendError, ge as SearchBackendNotDurable, t as SearchFieldRejected, e as SearchIndexNotFound, I as algoliaBackend, T as allowedEngineParams, Z as applyChange, je as asBackendError, ye as auditMemoryBackend, q as backendKindOf, ke as backfillIndex, Ee as dataStoreDriftLedger, W as dataStoreStatsStore, Se as driftSourceQuery, De as driftTables, S as isSafeFieldName, G as makeSearchStatsBuffer, F as meilisearchBackend, A as memoryBackend, we as memoryDriftLedger, V as memoryStatsStore, be as peerObservedWarning, Ae as resolveSyncOptions, w as sanitizeEngineParams, Pe as scopeSearchFilters, xe as searchDriftTable, Ie as searchPlugin, z as searchStatsTable, B as searchTables, K as statsStoreFlush, Me as syncRetrySchedule, oe as typesenseBackend };
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 };