@codemem/core 0.26.0 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/better-sqlite-coordinator-store.d.ts +4 -1
  2. package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
  3. package/dist/coordinator-actions.d.ts +32 -0
  4. package/dist/coordinator-actions.d.ts.map +1 -1
  5. package/dist/{coordinator-api-tVUvKt0u.js → coordinator-api-YsLNyP4R.js} +213 -108
  6. package/dist/{coordinator-api-tVUvKt0u.js.map → coordinator-api-YsLNyP4R.js.map} +1 -1
  7. package/dist/coordinator-api.d.ts.map +1 -1
  8. package/dist/coordinator-runtime.d.ts +12 -1
  9. package/dist/coordinator-runtime.d.ts.map +1 -1
  10. package/dist/coordinator-store-contract.d.ts +5 -1
  11. package/dist/coordinator-store-contract.d.ts.map +1 -1
  12. package/dist/coordinator-store-test-harness.d.ts.map +1 -1
  13. package/dist/d1-coordinator-store.d.ts +4 -1
  14. package/dist/d1-coordinator-store.d.ts.map +1 -1
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3003 -2682
  18. package/dist/index.js.map +1 -1
  19. package/dist/internal/cloudflare-coordinator.js +15 -5
  20. package/dist/internal/cloudflare-coordinator.js.map +1 -1
  21. package/dist/observer-client.d.ts +7 -1
  22. package/dist/observer-client.d.ts.map +1 -1
  23. package/dist/ref-backfill.d.ts +0 -5
  24. package/dist/ref-backfill.d.ts.map +1 -1
  25. package/dist/sync-daemon.d.ts +3 -2
  26. package/dist/sync-daemon.d.ts.map +1 -1
  27. package/dist/sync-replication.d.ts +5 -0
  28. package/dist/sync-replication.d.ts.map +1 -1
  29. package/dist/vector-migration.d.ts.map +1 -1
  30. package/dist/vectors.d.ts +4 -1
  31. package/dist/vectors.d.ts.map +1 -1
  32. package/package.json +1 -1
@@ -17,7 +17,7 @@ var t = (e, t, n) => (r, i) => {
17
17
  return c && (r.finalized === !1 || l) && (r.res = c), r;
18
18
  }
19
19
  }, n = /* @__PURE__ */ Symbol(), r = async (e, t = /* @__PURE__ */ Object.create(null)) => {
20
- let { all: n = !1, dot: r = !1 } = t, a = (e instanceof T ? e.raw.headers : e.headers).get("Content-Type");
20
+ let { all: n = !1, dot: r = !1 } = t, a = (e instanceof w ? e.raw.headers : e.headers).get("Content-Type");
21
21
  return a?.startsWith("multipart/form-data") || a?.startsWith("application/x-www-form-urlencoded") ? i(e, {
22
22
  all: n,
23
23
  dot: r
@@ -123,7 +123,7 @@ var o = (e, t, n) => {
123
123
  r += "/" + t, n.push(r);
124
124
  } else r += "/" + e;
125
125
  }), n.filter((e, t, n) => n.indexOf(e) === t);
126
- }, b = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : m(e, C)) : e, x = (e, t, n) => {
126
+ }, b = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : m(e, S)) : e, x = (e, t, n) => {
127
127
  let r;
128
128
  if (!n && t && !/[%+]/.test(t)) {
129
129
  let n = e.indexOf("?", 8);
@@ -150,7 +150,7 @@ var o = (e, t, n) => {
150
150
  o === -1 ? c = "" : (c = e.slice(o + 1, t === -1 ? void 0 : t), r && (c = b(c))), n ? (i[s] && Array.isArray(i[s]) || (i[s] = []), i[s].push(c)) : i[s] ??= c;
151
151
  }
152
152
  return t ? i[t] : i;
153
- }, ee = x, S = (e, t) => x(e, t, !0), C = decodeURIComponent, w = (e) => m(e, C), T = class {
153
+ }, ee = x, te = (e, t) => x(e, t, !0), S = decodeURIComponent, C = (e) => m(e, S), w = class {
154
154
  raw;
155
155
  #e;
156
156
  #t;
@@ -165,13 +165,13 @@ var o = (e, t, n) => {
165
165
  }
166
166
  #n(e) {
167
167
  let t = this.#t[0][this.routeIndex][1][e], n = this.#i(t);
168
- return n && /\%/.test(n) ? w(n) : n;
168
+ return n && /\%/.test(n) ? C(n) : n;
169
169
  }
170
170
  #r() {
171
171
  let e = {}, t = Object.keys(this.#t[0][this.routeIndex][1]);
172
172
  for (let n of t) {
173
173
  let t = this.#i(this.#t[0][this.routeIndex][1][n]);
174
- t !== void 0 && (e[n] = /\%/.test(t) ? w(t) : t);
174
+ t !== void 0 && (e[n] = /\%/.test(t) ? C(t) : t);
175
175
  }
176
176
  return e;
177
177
  }
@@ -182,7 +182,7 @@ var o = (e, t, n) => {
182
182
  return ee(this.url, e);
183
183
  }
184
184
  queries(e) {
185
- return S(this.url, e);
185
+ return te(this.url, e);
186
186
  }
187
187
  header(e) {
188
188
  if (e) return this.raw.headers.get(e) ?? void 0;
@@ -236,14 +236,14 @@ var o = (e, t, n) => {
236
236
  get routePath() {
237
237
  return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
238
238
  }
239
- }, te = {
239
+ }, ne = {
240
240
  Stringify: 1,
241
241
  BeforeStream: 2,
242
242
  Stream: 3
243
- }, ne = (e, t) => {
243
+ }, re = (e, t) => {
244
244
  let n = new String(e);
245
245
  return n.isEscaped = !0, n.callbacks = t, n;
246
- }, E = async (e, t, n, r, i) => {
246
+ }, T = async (e, t, n, r, i) => {
247
247
  typeof e == "object" && !(e instanceof String) && (e instanceof Promise || (e = e.toString()), e instanceof Promise && (e = await e));
248
248
  let a = e.callbacks;
249
249
  if (!a?.length) return Promise.resolve(e);
@@ -252,12 +252,12 @@ var o = (e, t, n) => {
252
252
  phase: t,
253
253
  buffer: i,
254
254
  context: r
255
- }))).then((e) => Promise.all(e.filter(Boolean).map((e) => E(e, t, !1, r, i))).then(() => i[0]));
256
- return n ? ne(await o, a) : o;
257
- }, re = "text/plain; charset=UTF-8", D = (e, t) => ({
255
+ }))).then((e) => Promise.all(e.filter(Boolean).map((e) => T(e, t, !1, r, i))).then(() => i[0]));
256
+ return n ? re(await o, a) : o;
257
+ }, ie = "text/plain; charset=UTF-8", E = (e, t) => ({
258
258
  "Content-Type": e,
259
259
  ...t
260
- }), O = (e, t) => new Response(e, t), k = class {
260
+ }), D = (e, t) => new Response(e, t), ae = class {
261
261
  #e;
262
262
  #t;
263
263
  env = {};
@@ -277,7 +277,7 @@ var o = (e, t, n) => {
277
277
  this.#e = e, t && (this.#i = t.executionCtx, this.env = t.env, this.#c = t.notFoundHandler, this.#d = t.path, this.#u = t.matchResult);
278
278
  }
279
279
  get req() {
280
- return this.#t ??= new T(this.#e, this.#d, this.#u), this.#t;
280
+ return this.#t ??= new w(this.#e, this.#d, this.#u), this.#t;
281
281
  }
282
282
  get event() {
283
283
  if (this.#i && "respondWith" in this.#i) return this.#i;
@@ -288,11 +288,11 @@ var o = (e, t, n) => {
288
288
  throw Error("This context has no ExecutionContext");
289
289
  }
290
290
  get res() {
291
- return this.#a ||= O(null, { headers: this.#l ??= new Headers() });
291
+ return this.#a ||= D(null, { headers: this.#l ??= new Headers() });
292
292
  }
293
293
  set res(e) {
294
294
  if (this.#a && e) {
295
- e = O(e.body, e);
295
+ e = D(e.body, e);
296
296
  for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") if (t === "set-cookie") {
297
297
  let t = this.#a.headers.getSetCookie();
298
298
  e.headers.delete("set-cookie");
@@ -308,7 +308,7 @@ var o = (e, t, n) => {
308
308
  this.#s = e;
309
309
  };
310
310
  header = (e, t, n) => {
311
- this.finalized && (this.#a = O(this.#a.body, this.#a));
311
+ this.finalized && (this.#a = D(this.#a.body, this.#a));
312
312
  let r = this.#a ? this.#a.headers : this.#l ??= new Headers();
313
313
  t === void 0 ? r.delete(e) : n?.append ? r.append(e, t) : r.set(e, t);
314
314
  };
@@ -333,38 +333,38 @@ var o = (e, t, n) => {
333
333
  r.delete(e);
334
334
  for (let n of t) r.append(e, n);
335
335
  }
336
- return O(e, {
336
+ return D(e, {
337
337
  status: typeof t == "number" ? t : t?.status ?? this.#r,
338
338
  headers: r
339
339
  });
340
340
  }
341
341
  newResponse = (...e) => this.#f(...e);
342
342
  body = (e, t, n) => this.#f(e, t, n);
343
- text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, D(re, n));
344
- json = (e, t, n) => this.#f(JSON.stringify(e), t, D("application/json", n));
343
+ text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, E(ie, n));
344
+ json = (e, t, n) => this.#f(JSON.stringify(e), t, E("application/json", n));
345
345
  html = (e, t, n) => {
346
- let r = (e) => this.#f(e, t, D("text/html; charset=UTF-8", n));
347
- return typeof e == "object" ? E(e, te.Stringify, !1, {}).then(r) : r(e);
346
+ let r = (e) => this.#f(e, t, E("text/html; charset=UTF-8", n));
347
+ return typeof e == "object" ? T(e, ne.Stringify, !1, {}).then(r) : r(e);
348
348
  };
349
349
  redirect = (e, t) => {
350
350
  let n = String(e);
351
351
  return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
352
352
  };
353
- notFound = () => (this.#c ??= () => O(), this.#c(this));
354
- }, ie = [
353
+ notFound = () => (this.#c ??= () => D(), this.#c(this));
354
+ }, oe = [
355
355
  "get",
356
356
  "post",
357
357
  "put",
358
358
  "delete",
359
359
  "options",
360
360
  "patch"
361
- ], A = "Can not add a route since the matcher is already built.", j = class extends Error {}, ae = "__COMPOSED_HANDLER", oe = (e) => e.text("404 Not Found", 404), M = (e, t) => {
361
+ ], O = "Can not add a route since the matcher is already built.", k = class extends Error {}, se = "__COMPOSED_HANDLER", A = (e) => e.text("404 Not Found", 404), j = (e, t) => {
362
362
  if ("getResponse" in e) {
363
363
  let n = e.getResponse();
364
364
  return t.newResponse(n.body, n);
365
365
  }
366
366
  return console.error(e), t.text("Internal Server Error", 500);
367
- }, se = class e {
367
+ }, ce = class e {
368
368
  get;
369
369
  post;
370
370
  put;
@@ -380,7 +380,7 @@ var o = (e, t, n) => {
380
380
  #e = "/";
381
381
  routes = [];
382
382
  constructor(e = {}) {
383
- [...ie, "all"].forEach((e) => {
383
+ [...oe, "all"].forEach((e) => {
384
384
  this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
385
385
  this.#r(e, this.#e, t);
386
386
  }), this);
@@ -405,13 +405,13 @@ var o = (e, t, n) => {
405
405
  });
406
406
  return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
407
407
  }
408
- #n = oe;
409
- errorHandler = M;
408
+ #n = A;
409
+ errorHandler = j;
410
410
  route(e, n) {
411
411
  let r = this.basePath(e);
412
412
  return n.routes.map((e) => {
413
413
  let i;
414
- n.errorHandler === M ? i = e.handler : (i = async (r, i) => (await t([], n.errorHandler)(r, () => e.handler(r, i))).res, i[ae] = e.handler), r.#r(e.method, e.path, i);
414
+ n.errorHandler === j ? i = e.handler : (i = async (r, i) => (await t([], n.errorHandler)(r, () => e.handler(r, i))).res, i[se] = e.handler), r.#r(e.method, e.path, i);
415
415
  }), this;
416
416
  }
417
417
  basePath(e) {
@@ -461,7 +461,7 @@ var o = (e, t, n) => {
461
461
  }
462
462
  #a(e, n, r, i) {
463
463
  if (i === "HEAD") return (async () => new Response(null, await this.#a(e, n, r, "GET")))();
464
- let a = this.getPath(e, { env: r }), o = this.router.match(i, a), s = new k(e, {
464
+ let a = this.getPath(e, { env: r }), o = this.router.match(i, a), s = new ae(e, {
465
465
  path: a,
466
466
  matchResult: o,
467
467
  env: r,
@@ -497,13 +497,13 @@ var o = (e, t, n) => {
497
497
  e.respondWith(this.#a(e.request, e, void 0, e.request.method));
498
498
  });
499
499
  };
500
- }, N = [];
501
- function P(e, t) {
500
+ }, M = [];
501
+ function N(e, t) {
502
502
  let n = this.buildAllMatchers(), r = ((e, t) => {
503
503
  let r = n[e] || n.ALL, i = r[2][t];
504
504
  if (i) return i;
505
505
  let a = t.match(r[0]);
506
- if (!a) return [[], N];
506
+ if (!a) return [[], M];
507
507
  let o = a.indexOf("", 1);
508
508
  return [r[1][o], a];
509
509
  });
@@ -511,17 +511,17 @@ function P(e, t) {
511
511
  }
512
512
  //#endregion
513
513
  //#region ../../node_modules/.pnpm/hono@4.12.11/node_modules/hono/dist/router/reg-exp-router/node.js
514
- var F = "[^/]+", I = ".*", L = "(?:|/.*)", R = /* @__PURE__ */ Symbol(), ce = /* @__PURE__ */ new Set(".\\+*[^]$()");
515
- function le(e, t) {
516
- return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e === I || e === L ? 1 : t === I || t === L ? -1 : e === F ? 1 : t === F ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
514
+ var P = "[^/]+", F = ".*", I = "(?:|/.*)", L = /* @__PURE__ */ Symbol(), le = /* @__PURE__ */ new Set(".\\+*[^]$()");
515
+ function ue(e, t) {
516
+ return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e === F || e === I ? 1 : t === F || t === I ? -1 : e === P ? 1 : t === P ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
517
517
  }
518
- var ue = class e {
518
+ var de = class e {
519
519
  #e;
520
520
  #t;
521
521
  #n = /* @__PURE__ */ Object.create(null);
522
522
  insert(t, n, r, i, a) {
523
523
  if (t.length === 0) {
524
- if (this.#e !== void 0) throw R;
524
+ if (this.#e !== void 0) throw L;
525
525
  if (a) return;
526
526
  this.#e = n;
527
527
  return;
@@ -529,42 +529,42 @@ var ue = class e {
529
529
  let [o, ...s] = t, c = o === "*" ? s.length === 0 ? [
530
530
  "",
531
531
  "",
532
- I
532
+ F
533
533
  ] : [
534
534
  "",
535
535
  "",
536
- F
536
+ P
537
537
  ] : o === "/*" ? [
538
538
  "",
539
539
  "",
540
- L
540
+ I
541
541
  ] : o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
542
542
  if (c) {
543
- let t = c[1], n = c[2] || F;
544
- if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw R;
543
+ let t = c[1], n = c[2] || P;
544
+ if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw L;
545
545
  if (l = this.#n[n], !l) {
546
- if (Object.keys(this.#n).some((e) => e !== I && e !== L)) throw R;
546
+ if (Object.keys(this.#n).some((e) => e !== F && e !== I)) throw L;
547
547
  if (a) return;
548
548
  l = this.#n[n] = new e(), t !== "" && (l.#t = i.varIndex++);
549
549
  }
550
550
  !a && t !== "" && r.push([t, l.#t]);
551
551
  } else if (l = this.#n[o], !l) {
552
- if (Object.keys(this.#n).some((e) => e.length > 1 && e !== I && e !== L)) throw R;
552
+ if (Object.keys(this.#n).some((e) => e.length > 1 && e !== F && e !== I)) throw L;
553
553
  if (a) return;
554
554
  l = this.#n[o] = new e();
555
555
  }
556
556
  l.insert(s, n, r, i, a);
557
557
  }
558
558
  buildRegExpStr() {
559
- let e = Object.keys(this.#n).sort(le).map((e) => {
559
+ let e = Object.keys(this.#n).sort(ue).map((e) => {
560
560
  let t = this.#n[e];
561
- return (typeof t.#t == "number" ? `(${e})@${t.#t}` : ce.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
561
+ return (typeof t.#t == "number" ? `(${e})@${t.#t}` : le.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
562
562
  });
563
563
  return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
564
564
  }
565
- }, de = class {
565
+ }, fe = class {
566
566
  #e = { varIndex: 0 };
567
- #t = new ue();
567
+ #t = new de();
568
568
  insert(e, t, n) {
569
569
  let r = [], i = [];
570
570
  for (let t = 0;;) {
@@ -598,29 +598,29 @@ var ue = class e {
598
598
  r
599
599
  ];
600
600
  }
601
- }, fe = [
601
+ }, pe = [
602
602
  /^$/,
603
603
  [],
604
604
  /* @__PURE__ */ Object.create(null)
605
- ], z = /* @__PURE__ */ Object.create(null);
606
- function B(e) {
607
- return z[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
605
+ ], R = /* @__PURE__ */ Object.create(null);
606
+ function z(e) {
607
+ return R[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
608
608
  }
609
- function V() {
610
- z = /* @__PURE__ */ Object.create(null);
609
+ function B() {
610
+ R = /* @__PURE__ */ Object.create(null);
611
611
  }
612
- function pe(e) {
613
- let t = new de(), n = [];
614
- if (e.length === 0) return fe;
612
+ function me(e) {
613
+ let t = new fe(), n = [];
614
+ if (e.length === 0) return pe;
615
615
  let r = e.map((e) => [!/\*|\/:/.test(e[0]), ...e]).sort(([e, t], [n, r]) => e ? 1 : n ? -1 : t.length - r.length), i = /* @__PURE__ */ Object.create(null);
616
616
  for (let e = 0, a = -1, o = r.length; e < o; e++) {
617
617
  let [o, s, c] = r[e];
618
- o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), N] : a++;
618
+ o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), M] : a++;
619
619
  let l;
620
620
  try {
621
621
  l = t.insert(s, a, o);
622
622
  } catch (e) {
623
- throw e === R ? new j(s) : e;
623
+ throw e === L ? new k(s) : e;
624
624
  }
625
625
  o || (n[a] = c.map(([e, t]) => {
626
626
  let n = /* @__PURE__ */ Object.create(null);
@@ -646,12 +646,12 @@ function pe(e) {
646
646
  i
647
647
  ];
648
648
  }
649
- function H(e, t) {
649
+ function V(e, t) {
650
650
  if (e) {
651
- for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (B(n).test(t)) return [...e[n]];
651
+ for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (z(n).test(t)) return [...e[n]];
652
652
  }
653
653
  }
654
- var me = class {
654
+ var he = class {
655
655
  name = "RegExpRouter";
656
656
  #e;
657
657
  #t;
@@ -660,7 +660,7 @@ var me = class {
660
660
  }
661
661
  add(e, t, n) {
662
662
  let r = this.#e, i = this.#t;
663
- if (!r || !i) throw Error(A);
663
+ if (!r || !i) throw Error(O);
664
664
  r[e] || [r, i].forEach((t) => {
665
665
  t[e] = /* @__PURE__ */ Object.create(null), Object.keys(t.ALL).forEach((n) => {
666
666
  t[e][n] = [...t.ALL[n]];
@@ -668,10 +668,10 @@ var me = class {
668
668
  }), t === "/*" && (t = "*");
669
669
  let a = (t.match(/\/:/g) || []).length;
670
670
  if (/\*$/.test(t)) {
671
- let o = B(t);
671
+ let o = z(t);
672
672
  e === "ALL" ? Object.keys(r).forEach((e) => {
673
- r[e][t] ||= H(r[e], t) || H(r.ALL, t) || [];
674
- }) : r[e][t] ||= H(r[e], t) || H(r.ALL, t) || [], Object.keys(r).forEach((t) => {
673
+ r[e][t] ||= V(r[e], t) || V(r.ALL, t) || [];
674
+ }) : r[e][t] ||= V(r[e], t) || V(r.ALL, t) || [], Object.keys(r).forEach((t) => {
675
675
  (e === "ALL" || e === t) && Object.keys(r[t]).forEach((e) => {
676
676
  o.test(e) && r[t][e].push([n, a]);
677
677
  });
@@ -684,25 +684,25 @@ var me = class {
684
684
  for (let t = 0, s = o.length; t < s; t++) {
685
685
  let c = o[t];
686
686
  Object.keys(i).forEach((o) => {
687
- (e === "ALL" || e === o) && (i[o][c] ||= [...H(r[o], c) || H(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
687
+ (e === "ALL" || e === o) && (i[o][c] ||= [...V(r[o], c) || V(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
688
688
  });
689
689
  }
690
690
  }
691
- match = P;
691
+ match = N;
692
692
  buildAllMatchers() {
693
693
  let e = /* @__PURE__ */ Object.create(null);
694
694
  return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t) => {
695
695
  e[t] ||= this.#n(t);
696
- }), this.#e = this.#t = void 0, V(), e;
696
+ }), this.#e = this.#t = void 0, B(), e;
697
697
  }
698
698
  #n(e) {
699
699
  let t = [], n = e === "ALL";
700
700
  return [this.#e, this.#t].forEach((r) => {
701
701
  let i = r[e] ? Object.keys(r[e]).map((t) => [t, r[e][t]]) : [];
702
702
  i.length === 0 ? e !== "ALL" && t.push(...Object.keys(r.ALL).map((e) => [e, r.ALL[e]])) : (n ||= !0, t.push(...i));
703
- }), n ? pe(t) : null;
703
+ }), n ? me(t) : null;
704
704
  }
705
- }, he = class {
705
+ }, ge = class {
706
706
  name = "SmartRouter";
707
707
  #e = [];
708
708
  #t = [];
@@ -710,7 +710,7 @@ var me = class {
710
710
  this.#e = e.routers;
711
711
  }
712
712
  add(e, t, n) {
713
- if (!this.#t) throw Error(A);
713
+ if (!this.#t) throw Error(O);
714
714
  this.#t.push([
715
715
  e,
716
716
  t,
@@ -726,7 +726,7 @@ var me = class {
726
726
  for (let e = 0, t = r.length; e < t; e++) i.add(...r[e]);
727
727
  o = i.match(e, t);
728
728
  } catch (e) {
729
- if (e instanceof j) continue;
729
+ if (e instanceof k) continue;
730
730
  throw e;
731
731
  }
732
732
  this.match = i.match.bind(i), this.#e = [i], this.#t = void 0;
@@ -739,15 +739,15 @@ var me = class {
739
739
  if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
740
740
  return this.#e[0];
741
741
  }
742
- }, U = /* @__PURE__ */ Object.create(null), ge = (e) => {
742
+ }, H = /* @__PURE__ */ Object.create(null), _e = (e) => {
743
743
  for (let t in e) return !0;
744
744
  return !1;
745
- }, _e = class e {
745
+ }, ve = class e {
746
746
  #e;
747
747
  #t;
748
748
  #n;
749
749
  #r = 0;
750
- #i = U;
750
+ #i = H;
751
751
  constructor(e, t, n) {
752
752
  if (this.#t = n || /* @__PURE__ */ Object.create(null), this.#e = [], e && t) {
753
753
  let n = /* @__PURE__ */ Object.create(null);
@@ -779,7 +779,7 @@ var me = class {
779
779
  #a(e, t, n, r, i) {
780
780
  for (let a = 0, o = t.#e.length; a < o; a++) {
781
781
  let o = t.#e[a], s = o[n] || o.ALL, c = {};
782
- if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !== U || i && i !== U)) for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
782
+ if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !== H || i && i !== H)) for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
783
783
  let t = s.possibleKeys[e], n = c[s.score];
784
784
  s.params[t] = i?.[t] && !n ? i[t] : r[t] ?? i?.[t], c[s.score] = !0;
785
785
  }
@@ -787,7 +787,7 @@ var me = class {
787
787
  }
788
788
  search(e, t) {
789
789
  let n = [];
790
- this.#i = U;
790
+ this.#i = H;
791
791
  let r = [this], i = c(t), a = [], o = i.length, s = null;
792
792
  for (let c = 0; c < o; c++) {
793
793
  let l = i[c], u = c === o - 1, d = [];
@@ -795,7 +795,7 @@ var me = class {
795
795
  let p = r[f], m = p.#t[l];
796
796
  m && (m.#i = p.#i, u ? (m.#t["*"] && this.#a(n, m.#t["*"], e, p.#i), this.#a(n, m, e, p.#i)) : d.push(m));
797
797
  for (let r = 0, f = p.#n.length; r < f; r++) {
798
- let f = p.#n[r], m = p.#i === U ? {} : { ...p.#i };
798
+ let f = p.#n[r], m = p.#i === H ? {} : { ...p.#i };
799
799
  if (f === "*") {
800
800
  let t = p.#t["*"];
801
801
  t && (this.#a(n, t, e, p.#i), t.#i = m, d.push(t));
@@ -812,7 +812,7 @@ var me = class {
812
812
  }
813
813
  let r = t.substring(s[c]), l = _.exec(r);
814
814
  if (l) {
815
- if (m[g] = l[0], this.#a(n, v, e, p.#i, m), ge(v.#t)) {
815
+ if (m[g] = l[0], this.#a(n, v, e, p.#i, m), _e(v.#t)) {
816
816
  v.#i = m;
817
817
  let e = l[0].match(/\//)?.length ?? 0;
818
818
  (a[e] ||= []).push(v);
@@ -828,11 +828,11 @@ var me = class {
828
828
  }
829
829
  return n.length > 1 && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
830
830
  }
831
- }, ve = class {
831
+ }, ye = class {
832
832
  name = "TrieRouter";
833
833
  #e;
834
834
  constructor() {
835
- this.#e = new _e();
835
+ this.#e = new ve();
836
836
  }
837
837
  add(e, t, n) {
838
838
  let r = y(t);
@@ -845,9 +845,9 @@ var me = class {
845
845
  match(e, t) {
846
846
  return this.#e.search(e, t);
847
847
  }
848
- }, ye = class extends se {
848
+ }, U = class extends ce {
849
849
  constructor(e = {}) {
850
- super(e), this.router = e.router ?? new he({ routers: [new me(), new ve()] });
850
+ super(e), this.router = e.router ?? new ge({ routers: [new he(), new ye()] });
851
851
  }
852
852
  };
853
853
  //#endregion
@@ -1118,7 +1118,7 @@ async function Q(e, t, n, r) {
1118
1118
  }
1119
1119
  function Ie(e) {
1120
1120
  if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
1121
- let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? ke(), o = Math.max(1, Math.trunc(i.readLimit ?? je)), s = Math.max(1, Math.trunc(i.mutationLimit ?? Me)), c = Math.max(1, Math.trunc(i.unauthenticatedReadLimit ?? Math.min(20, o))), l = Math.max(1, Math.trunc(i.unauthenticatedMutationLimit ?? Math.min(10, s))), u = new ye(), d = new TextDecoder();
1121
+ let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? ke(), o = Math.max(1, Math.trunc(i.readLimit ?? je)), s = Math.max(1, Math.trunc(i.mutationLimit ?? Me)), c = Math.max(1, Math.trunc(i.unauthenticatedReadLimit ?? Math.min(20, o))), l = Math.max(1, Math.trunc(i.unauthenticatedMutationLimit ?? Math.min(10, s))), u = new U(), d = new TextDecoder();
1122
1122
  function f(e, t, n) {
1123
1123
  let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i = a.check(`${e.req.method}:${n ? "auth" : "anon"}:${t}`, n ? r ? o : s : r ? c : l);
1124
1124
  return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
@@ -1313,6 +1313,101 @@ function Ie(e) {
1313
1313
  await h.close();
1314
1314
  }
1315
1315
  return e.json({ ok: !0 });
1316
+ }), u.get("/v1/admin/groups", async (e) => {
1317
+ let r = Z(e.req.header(X), t);
1318
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
1319
+ let i = f(e, "admin", !0);
1320
+ if (i) return i;
1321
+ let a = [
1322
+ "1",
1323
+ "true",
1324
+ "yes"
1325
+ ].includes((e.req.query("include_archived") ?? "0").trim().toLowerCase()), o = n();
1326
+ try {
1327
+ return e.json({ items: await o.listGroups(a) });
1328
+ } finally {
1329
+ await o.close();
1330
+ }
1331
+ }), u.post("/v1/admin/groups", async (e) => {
1332
+ let r = Z(e.req.header(X), t);
1333
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
1334
+ let i = f(e, "admin", !0);
1335
+ if (i) return i;
1336
+ let a = await p(e);
1337
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
1338
+ let o = m(a);
1339
+ if (!o) return e.json({ error: "invalid_json" }, 400);
1340
+ let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim() || null;
1341
+ if (!s) return e.json({ error: "group_id_required" }, 400);
1342
+ let l = n();
1343
+ try {
1344
+ return await l.createGroup(s, c), e.json({
1345
+ ok: !0,
1346
+ group: await l.getGroup(s)
1347
+ });
1348
+ } finally {
1349
+ await l.close();
1350
+ }
1351
+ }), u.post("/v1/admin/groups/rename", async (e) => {
1352
+ let r = Z(e.req.header(X), t);
1353
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
1354
+ let i = f(e, "admin", !0);
1355
+ if (i) return i;
1356
+ let a = await p(e);
1357
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
1358
+ let o = m(a);
1359
+ if (!o) return e.json({ error: "invalid_json" }, 400);
1360
+ let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim();
1361
+ if (!s || !c) return e.json({ error: "group_id_and_display_name_required" }, 400);
1362
+ let l = n();
1363
+ try {
1364
+ return await l.renameGroup(s, c) ? e.json({
1365
+ ok: !0,
1366
+ group: await l.getGroup(s)
1367
+ }) : e.json({ error: "group_not_found" }, 404);
1368
+ } finally {
1369
+ await l.close();
1370
+ }
1371
+ }), u.post("/v1/admin/groups/archive", async (e) => {
1372
+ let r = Z(e.req.header(X), t);
1373
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
1374
+ let i = f(e, "admin", !0);
1375
+ if (i) return i;
1376
+ let a = await p(e);
1377
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
1378
+ let o = m(a);
1379
+ if (!o) return e.json({ error: "invalid_json" }, 400);
1380
+ let s = String(o.group_id ?? "").trim();
1381
+ if (!s) return e.json({ error: "group_id_required" }, 400);
1382
+ let c = n();
1383
+ try {
1384
+ return await c.archiveGroup(s, t.now()) ? e.json({
1385
+ ok: !0,
1386
+ group: await c.getGroup(s)
1387
+ }) : e.json({ error: "group_not_found_or_already_archived" }, 404);
1388
+ } finally {
1389
+ await c.close();
1390
+ }
1391
+ }), u.post("/v1/admin/groups/unarchive", async (e) => {
1392
+ let r = Z(e.req.header(X), t);
1393
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
1394
+ let i = f(e, "admin", !0);
1395
+ if (i) return i;
1396
+ let a = await p(e);
1397
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
1398
+ let o = m(a);
1399
+ if (!o) return e.json({ error: "invalid_json" }, 400);
1400
+ let s = String(o.group_id ?? "").trim();
1401
+ if (!s) return e.json({ error: "group_id_required" }, 400);
1402
+ let c = n();
1403
+ try {
1404
+ return await c.unarchiveGroup(s) ? e.json({
1405
+ ok: !0,
1406
+ group: await c.getGroup(s)
1407
+ }) : e.json({ error: "group_not_found_or_not_archived" }, 404);
1408
+ } finally {
1409
+ await c.close();
1410
+ }
1316
1411
  }), u.get("/v1/admin/devices", async (e) => {
1317
1412
  let r = Z(e.req.header(X), t);
1318
1413
  if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
@@ -1344,7 +1439,12 @@ function Ie(e) {
1344
1439
  if (!l) return e.json({ error: "display_name_required" }, 400);
1345
1440
  let u = n();
1346
1441
  try {
1347
- return await u.renameDevice(s, c, l) ? e.json({ ok: !0 }) : e.json({ error: "device_not_found" }, 404);
1442
+ if (!await u.renameDevice(s, c, l)) return e.json({ error: "device_not_found" }, 404);
1443
+ let t = await u.getEnrollment(s, c);
1444
+ return e.json({
1445
+ ok: !0,
1446
+ device: t
1447
+ });
1348
1448
  } finally {
1349
1449
  await u.close();
1350
1450
  }
@@ -1395,28 +1495,30 @@ function Ie(e) {
1395
1495
  if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
1396
1496
  let d = n();
1397
1497
  try {
1398
- if (!await d.getGroup(s)) return e.json({ error: "group_not_found" }, 404);
1399
- let t = await d.createInvite({
1498
+ let t = await d.getGroup(s);
1499
+ if (!t) return e.json({ error: "group_not_found" }, 404);
1500
+ if (t.archived_at) return e.json({ error: "group_archived" }, 409);
1501
+ let n = await d.createInvite({
1400
1502
  groupId: s,
1401
1503
  policy: c,
1402
1504
  expiresAt: l,
1403
1505
  createdBy: u
1404
- }), n = {
1506
+ }), r = {
1405
1507
  v: 1,
1406
1508
  kind: "coordinator_team_invite",
1407
1509
  coordinator_url: String(o.coordinator_url ?? "").trim(),
1408
1510
  group_id: s,
1409
1511
  policy: c,
1410
- token: String(t.token ?? ""),
1512
+ token: String(n.token ?? ""),
1411
1513
  expires_at: l,
1412
- team_name: t.team_name_snapshot ?? null
1413
- }, r = W(n), { token: i, ...a } = t;
1514
+ team_name: n.team_name_snapshot ?? null
1515
+ }, i = W(r), { token: a, ...f } = n;
1414
1516
  return e.json({
1415
1517
  ok: !0,
1416
- invite: a,
1417
- payload: n,
1418
- encoded: r,
1419
- link: G(r)
1518
+ invite: f,
1519
+ payload: r,
1520
+ encoded: i,
1521
+ link: G(i)
1420
1522
  });
1421
1523
  } finally {
1422
1524
  await d.close();
@@ -1522,21 +1624,24 @@ function Ie(e) {
1522
1624
  try {
1523
1625
  let n = await u.getInviteByToken(a);
1524
1626
  if (!n) return e.json({ error: "invalid_token" }, 404);
1627
+ let r = await u.getGroup(String(n.group_id));
1628
+ if (!r) return e.json({ error: "group_not_found" }, 404);
1629
+ if (r.archived_at) return e.json({ error: "group_archived" }, 409);
1525
1630
  if (n.revoked_at) return e.json({ error: "revoked_token" }, 400);
1526
- let r = String(n.expires_at ?? "");
1527
- if (r && new Date(r.replace("Z", "+00:00")) <= new Date(t.now())) return e.json({ error: "expired_token" }, 400);
1528
- let i = String(n.group_id);
1529
- if (await u.getEnrollment(i, o)) return e.json({
1631
+ let i = String(n.expires_at ?? "");
1632
+ if (i && new Date(i.replace("Z", "+00:00")) <= new Date(t.now())) return e.json({ error: "expired_token" }, 400);
1633
+ let d = String(n.group_id);
1634
+ if (await u.getEnrollment(d, o)) return e.json({
1530
1635
  ok: !0,
1531
1636
  status: "already_enrolled",
1532
1637
  group_id: n.group_id,
1533
1638
  policy: n.policy
1534
1639
  });
1535
- let d = String(n.policy);
1536
- if (!["auto_admit", "approval_required"].includes(d)) return e.json({ error: `unknown invite policy: ${d}` }, 400);
1537
- if (d === "approval_required") {
1640
+ let f = String(n.policy);
1641
+ if (!["auto_admit", "approval_required"].includes(f)) return e.json({ error: `unknown invite policy: ${f}` }, 400);
1642
+ if (f === "approval_required") {
1538
1643
  let t = await u.createJoinRequest({
1539
- groupId: i,
1644
+ groupId: d,
1540
1645
  deviceId: o,
1541
1646
  publicKey: c,
1542
1647
  fingerprint: s,
@@ -1551,7 +1656,7 @@ function Ie(e) {
1551
1656
  request_id: t.request_id
1552
1657
  });
1553
1658
  }
1554
- return await u.enrollDevice(i, {
1659
+ return await u.enrollDevice(d, {
1555
1660
  deviceId: o,
1556
1661
  fingerprint: s,
1557
1662
  publicKey: c,
@@ -1633,4 +1738,4 @@ async function $(e, t, n) {
1633
1738
  //#endregion
1634
1739
  export { W as a, we as i, J as n, Te as o, Ae as r, G as s, Ie as t };
1635
1740
 
1636
- //# sourceMappingURL=coordinator-api-tVUvKt0u.js.map
1741
+ //# sourceMappingURL=coordinator-api-YsLNyP4R.js.map