@codemem/core 0.36.1 → 0.37.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.
Files changed (37) hide show
  1. package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
  2. package/dist/{coordinator-api-CbONcz8J.js → coordinator-api-hZ1RVJUN.js} +132 -124
  3. package/dist/coordinator-api-hZ1RVJUN.js.map +1 -0
  4. package/dist/coordinator-api.d.ts.map +1 -1
  5. package/dist/coordinator-runtime.d.ts +5 -0
  6. package/dist/coordinator-runtime.d.ts.map +1 -1
  7. package/dist/coordinator-store-contract.d.ts +8 -0
  8. package/dist/coordinator-store-contract.d.ts.map +1 -1
  9. package/dist/d1-coordinator-store.d.ts.map +1 -1
  10. package/dist/db.d.ts +10 -0
  11. package/dist/db.d.ts.map +1 -1
  12. package/dist/filters.d.ts +9 -0
  13. package/dist/filters.d.ts.map +1 -1
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +4362 -4267
  17. package/dist/index.js.map +1 -1
  18. package/dist/internal/cloudflare-coordinator.js +193 -188
  19. package/dist/internal/cloudflare-coordinator.js.map +1 -1
  20. package/dist/observer-config.d.ts.map +1 -1
  21. package/dist/raw-event-sweeper.d.ts.map +1 -1
  22. package/dist/request-rate-limit.d.ts +11 -0
  23. package/dist/request-rate-limit.d.ts.map +1 -1
  24. package/dist/scope-backfill.d.ts +2 -1
  25. package/dist/scope-backfill.d.ts.map +1 -1
  26. package/dist/scope-resolution.d.ts +34 -0
  27. package/dist/scope-resolution.d.ts.map +1 -1
  28. package/dist/search.d.ts.map +1 -1
  29. package/dist/store.d.ts +32 -0
  30. package/dist/store.d.ts.map +1 -1
  31. package/dist/sync-pass.d.ts.map +1 -1
  32. package/dist/sync-replication.d.ts.map +1 -1
  33. package/dist/sync-retention-runner.d.ts +1 -0
  34. package/dist/sync-retention-runner.d.ts.map +1 -1
  35. package/dist/vectors.d.ts.map +1 -1
  36. package/package.json +3 -3
  37. package/dist/coordinator-api-CbONcz8J.js.map +0 -1
@@ -1,6 +1,13 @@
1
1
  import { createHash as e } from "node:crypto";
2
- //#region ../../node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/compose.js
3
- var t = (e, t, n) => (r, i) => {
2
+ //#region src/coordinator-store-contract.ts
3
+ function t(e) {
4
+ let t = e.trim(), n = new Date(t);
5
+ if (!t || Number.isNaN(n.getTime())) throw Error("expiresAt must be a valid date.");
6
+ return n.toISOString();
7
+ }
8
+ //#endregion
9
+ //#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/compose.js
10
+ var n = (e, t, n) => (r, i) => {
4
11
  let a = -1;
5
12
  return o(0);
6
13
  async function o(s) {
@@ -16,40 +23,40 @@ var t = (e, t, n) => (r, i) => {
16
23
  else r.finalized === !1 && n && (c = await n(r));
17
24
  return c && (r.finalized === !1 || l) && (r.res = c), r;
18
25
  }
19
- }, n = /* @__PURE__ */ Symbol(), r = async (e, t = /* @__PURE__ */ Object.create(null)) => {
20
- let { all: n = !1, dot: r = !1 } = t, a = (e instanceof E ? e.raw.headers : e.headers).get("Content-Type");
21
- return a?.startsWith("multipart/form-data") || a?.startsWith("application/x-www-form-urlencoded") ? i(e, {
26
+ }, r = /* @__PURE__ */ Symbol(), i = async (e, t = /* @__PURE__ */ Object.create(null)) => {
27
+ let { all: n = !1, dot: r = !1 } = t, i = (e instanceof E ? e.raw.headers : e.headers).get("Content-Type");
28
+ return i?.startsWith("multipart/form-data") || i?.startsWith("application/x-www-form-urlencoded") ? a(e, {
22
29
  all: n,
23
30
  dot: r
24
31
  }) : {};
25
32
  };
26
- async function i(e, t) {
33
+ async function a(e, t) {
27
34
  let n = await e.formData();
28
- return n ? a(n, t) : {};
35
+ return n ? o(n, t) : {};
29
36
  }
30
- function a(e, t) {
37
+ function o(e, t) {
31
38
  let n = /* @__PURE__ */ Object.create(null);
32
39
  return e.forEach((e, r) => {
33
- t.all || r.endsWith("[]") ? o(n, r, e) : n[r] = e;
40
+ t.all || r.endsWith("[]") ? s(n, r, e) : n[r] = e;
34
41
  }), t.dot && Object.entries(n).forEach(([e, t]) => {
35
- e.includes(".") && (s(n, e, t), delete n[e]);
42
+ e.includes(".") && (c(n, e, t), delete n[e]);
36
43
  }), n;
37
44
  }
38
- var o = (e, t, n) => {
45
+ var s = (e, t, n) => {
39
46
  e[t] === void 0 ? t.endsWith("[]") ? e[t] = [n] : e[t] = n : Array.isArray(e[t]) ? e[t].push(n) : e[t] = [e[t], n];
40
- }, s = (e, t, n) => {
47
+ }, c = (e, t, n) => {
41
48
  if (/(?:^|\.)__proto__\./.test(t)) return;
42
49
  let r = e, i = t.split(".");
43
50
  i.forEach((e, t) => {
44
51
  t === i.length - 1 ? r[e] = n : ((!r[e] || typeof r[e] != "object" || Array.isArray(r[e]) || r[e] instanceof File) && (r[e] = /* @__PURE__ */ Object.create(null)), r = r[e]);
45
52
  });
46
- }, c = (e) => {
53
+ }, l = (e) => {
47
54
  let t = e.split("/");
48
55
  return t[0] === "" && t.shift(), t;
49
- }, l = (e) => {
50
- let { groups: t, path: n } = u(e);
51
- return d(c(n), t);
52
56
  }, u = (e) => {
57
+ let { groups: t, path: n } = d(e);
58
+ return f(l(n), t);
59
+ }, d = (e) => {
53
60
  let t = [];
54
61
  return e = e.replace(/\{[^}]+\}/g, (e, n) => {
55
62
  let r = `@${n}`;
@@ -58,7 +65,7 @@ var o = (e, t, n) => {
58
65
  groups: t,
59
66
  path: e
60
67
  };
61
- }, d = (e, t) => {
68
+ }, f = (e, t) => {
62
69
  for (let n = t.length - 1; n >= 0; n--) {
63
70
  let [r] = t[n];
64
71
  for (let i = e.length - 1; i >= 0; i--) if (e[i].includes(r)) {
@@ -67,12 +74,12 @@ var o = (e, t, n) => {
67
74
  }
68
75
  }
69
76
  return e;
70
- }, f = {}, p = (e, t) => {
77
+ }, p = {}, m = (e, t) => {
71
78
  if (e === "*") return "*";
72
79
  let n = e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
73
80
  if (n) {
74
81
  let r = `${e}#${t}`;
75
- return f[r] || (n[2] ? f[r] = t && t[0] !== ":" && t[0] !== "*" ? [
82
+ return p[r] || (n[2] ? p[r] = t && t[0] !== ":" && t[0] !== "*" ? [
76
83
  r,
77
84
  n[1],
78
85
  RegExp(`^${n[2]}(?=/${t})`)
@@ -80,14 +87,14 @@ var o = (e, t, n) => {
80
87
  e,
81
88
  n[1],
82
89
  RegExp(`^${n[2]}$`)
83
- ] : f[r] = [
90
+ ] : p[r] = [
84
91
  e,
85
92
  n[1],
86
93
  !0
87
- ]), f[r];
94
+ ]), p[r];
88
95
  }
89
96
  return null;
90
- }, m = (e, t) => {
97
+ }, h = (e, t) => {
91
98
  try {
92
99
  return t(e);
93
100
  } catch {
@@ -99,20 +106,20 @@ var o = (e, t, n) => {
99
106
  }
100
107
  });
101
108
  }
102
- }, h = (e) => m(e, decodeURI), g = (e) => {
109
+ }, g = (e) => h(e, decodeURI), _ = (e) => {
103
110
  let t = e.url, n = t.indexOf("/", t.indexOf(":") + 4), r = n;
104
111
  for (; r < t.length; r++) {
105
112
  let e = t.charCodeAt(r);
106
113
  if (e === 37) {
107
114
  let e = t.indexOf("?", r), i = t.indexOf("#", r), a = e === -1 ? i === -1 ? void 0 : i : i === -1 ? e : Math.min(e, i), o = t.slice(n, a);
108
- return h(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
115
+ return g(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
109
116
  } else if (e === 63 || e === 35) break;
110
117
  }
111
118
  return t.slice(n, r);
112
- }, _ = (e) => {
113
- let t = g(e);
119
+ }, v = (e) => {
120
+ let t = _(e);
114
121
  return t.length > 1 && t.at(-1) === "/" ? t.slice(0, -1) : t;
115
- }, v = (e, t, ...n) => (n.length && (t = v(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), y = (e) => {
122
+ }, y = (e, t, ...n) => (n.length && (t = y(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), b = (e) => {
116
123
  if (e.charCodeAt(e.length - 1) !== 63 || !e.includes(":")) return null;
117
124
  let t = e.split("/"), n = [], r = "";
118
125
  return t.forEach((e) => {
@@ -123,7 +130,7 @@ var o = (e, t, n) => {
123
130
  r += "/" + t, n.push(r);
124
131
  } else r += "/" + e;
125
132
  }), 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, w)) : e, x = (e, t, n) => {
133
+ }, x = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : h(e, w)) : e, S = (e, t, n) => {
127
134
  let r;
128
135
  if (!n && t && !/[%+]/.test(t)) {
129
136
  let n = e.indexOf("?", 8);
@@ -132,7 +139,7 @@ var o = (e, t, n) => {
132
139
  let r = e.charCodeAt(n + t.length + 1);
133
140
  if (r === 61) {
134
141
  let r = n + t.length + 2, i = e.indexOf("&", r);
135
- return b(e.slice(r, i === -1 ? void 0 : i));
142
+ return x(e.slice(r, i === -1 ? void 0 : i));
136
143
  } else if (r == 38 || isNaN(r)) return "";
137
144
  n = e.indexOf(`&${t}`, n + 1);
138
145
  }
@@ -145,12 +152,12 @@ var o = (e, t, n) => {
145
152
  let t = e.indexOf("&", a + 1), o = e.indexOf("=", a);
146
153
  o > t && t !== -1 && (o = -1);
147
154
  let s = e.slice(a + 1, o === -1 ? t === -1 ? void 0 : t : o);
148
- if (r && (s = b(s)), a = t, s === "") continue;
155
+ if (r && (s = x(s)), a = t, s === "") continue;
149
156
  let c;
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;
157
+ o === -1 ? c = "" : (c = e.slice(o + 1, t === -1 ? void 0 : t), r && (c = x(c))), n ? (i[s] && Array.isArray(i[s]) || (i[s] = []), i[s].push(c)) : i[s] ??= c;
151
158
  }
152
159
  return t ? i[t] : i;
153
- }, S = x, C = (e, t) => x(e, t, !0), w = decodeURIComponent, T = (e) => m(e, w), E = class {
160
+ }, C = S, ee = (e, t) => S(e, t, !0), w = decodeURIComponent, T = (e) => h(e, w), E = class {
154
161
  raw;
155
162
  #e;
156
163
  #t;
@@ -179,10 +186,10 @@ var o = (e, t, n) => {
179
186
  return this.#t[1] ? this.#t[1][e] : e;
180
187
  }
181
188
  query(e) {
182
- return S(this.url, e);
189
+ return C(this.url, e);
183
190
  }
184
191
  queries(e) {
185
- return C(this.url, e);
192
+ return ee(this.url, e);
186
193
  }
187
194
  header(e) {
188
195
  if (e) return this.raw.headers.get(e) ?? void 0;
@@ -192,7 +199,7 @@ var o = (e, t, n) => {
192
199
  }), t;
193
200
  }
194
201
  async parseBody(e) {
195
- return r(this, e);
202
+ return i(this, e);
196
203
  }
197
204
  #a = (e) => {
198
205
  let { bodyCache: t, raw: n } = this, r = t[e];
@@ -230,7 +237,7 @@ var o = (e, t, n) => {
230
237
  get method() {
231
238
  return this.raw.method;
232
239
  }
233
- get [n]() {
240
+ get [r]() {
234
241
  return this.#t;
235
242
  }
236
243
  get matchedRoutes() {
@@ -239,11 +246,11 @@ var o = (e, t, n) => {
239
246
  get routePath() {
240
247
  return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
241
248
  }
242
- }, ee = {
249
+ }, te = {
243
250
  Stringify: 1,
244
251
  BeforeStream: 2,
245
252
  Stream: 3
246
- }, te = (e, t) => {
253
+ }, ne = (e, t) => {
247
254
  let n = new String(e);
248
255
  return n.isEscaped = !0, n.callbacks = t, n;
249
256
  }, D = async (e, t, n, r, i) => {
@@ -256,11 +263,11 @@ var o = (e, t, n) => {
256
263
  buffer: i,
257
264
  context: r
258
265
  }))).then((e) => Promise.all(e.filter(Boolean).map((e) => D(e, t, !1, r, i))).then(() => i[0]));
259
- return n ? te(await o, a) : o;
260
- }, ne = "text/plain; charset=UTF-8", O = (e, t) => ({
266
+ return n ? ne(await o, a) : o;
267
+ }, re = "text/plain; charset=UTF-8", O = (e, t) => ({
261
268
  "Content-Type": e,
262
269
  ...t
263
- }), k = (e, t) => new Response(e, t), re = class {
270
+ }), k = (e, t) => new Response(e, t), ie = class {
264
271
  #e;
265
272
  #t;
266
273
  env = {};
@@ -343,31 +350,31 @@ var o = (e, t, n) => {
343
350
  }
344
351
  newResponse = (...e) => this.#f(...e);
345
352
  body = (e, t, n) => this.#f(e, t, n);
346
- text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, O(ne, n));
353
+ text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, O(re, n));
347
354
  json = (e, t, n) => this.#f(JSON.stringify(e), t, O("application/json", n));
348
355
  html = (e, t, n) => {
349
356
  let r = (e) => this.#f(e, t, O("text/html; charset=UTF-8", n));
350
- return typeof e == "object" ? D(e, ee.Stringify, !1, {}).then(r) : r(e);
357
+ return typeof e == "object" ? D(e, te.Stringify, !1, {}).then(r) : r(e);
351
358
  };
352
359
  redirect = (e, t) => {
353
360
  let n = String(e);
354
361
  return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
355
362
  };
356
363
  notFound = () => (this.#c ??= () => k(), this.#c(this));
357
- }, ie = [
364
+ }, ae = [
358
365
  "get",
359
366
  "post",
360
367
  "put",
361
368
  "delete",
362
369
  "options",
363
370
  "patch"
364
- ], 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) => {
371
+ ], A = "Can not add a route since the matcher is already built.", j = class extends Error {}, oe = "__COMPOSED_HANDLER", se = (e) => e.text("404 Not Found", 404), M = (e, t) => {
365
372
  if ("getResponse" in e) {
366
373
  let n = e.getResponse();
367
374
  return t.newResponse(n.body, n);
368
375
  }
369
376
  return console.error(e), t.text("Internal Server Error", 500);
370
- }, se = class e {
377
+ }, ce = class e {
371
378
  get;
372
379
  post;
373
380
  put;
@@ -383,7 +390,7 @@ var o = (e, t, n) => {
383
390
  #e = "/";
384
391
  routes = [];
385
392
  constructor(e = {}) {
386
- [...ie, "all"].forEach((e) => {
393
+ [...ae, "all"].forEach((e) => {
387
394
  this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
388
395
  this.#r(e, this.#e, t);
389
396
  }), this);
@@ -399,7 +406,7 @@ var o = (e, t, n) => {
399
406
  this.#r("ALL", this.#e, e);
400
407
  }), this);
401
408
  let { strict: t, ...n } = e;
402
- Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? g : _;
409
+ Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? _ : v;
403
410
  }
404
411
  #t() {
405
412
  let t = new e({
@@ -408,18 +415,18 @@ var o = (e, t, n) => {
408
415
  });
409
416
  return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
410
417
  }
411
- #n = oe;
418
+ #n = se;
412
419
  errorHandler = M;
413
- route(e, n) {
420
+ route(e, t) {
414
421
  let r = this.basePath(e);
415
- return n.routes.map((e) => {
422
+ return t.routes.map((e) => {
416
423
  let i;
417
- 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, e.basePath);
424
+ t.errorHandler === M ? i = e.handler : (i = async (r, i) => (await n([], t.errorHandler)(r, () => e.handler(r, i))).res, i[oe] = e.handler), r.#r(e.method, e.path, i, e.basePath);
418
425
  }), this;
419
426
  }
420
427
  basePath(e) {
421
428
  let t = this.#t();
422
- return t._basePath = v(this._basePath, e), t;
429
+ return t._basePath = y(this._basePath, e), t;
423
430
  }
424
431
  onError = (e) => (this.errorHandler = e, this);
425
432
  notFound = (e) => (this.#n = e, this);
@@ -437,21 +444,21 @@ var o = (e, t, n) => {
437
444
  return [e.env, t];
438
445
  };
439
446
  return r ||= (() => {
440
- let t = v(this._basePath, e), n = t === "/" ? 0 : t.length;
447
+ let t = y(this._basePath, e), n = t === "/" ? 0 : t.length;
441
448
  return (e) => {
442
449
  let t = new URL(e.url);
443
450
  return t.pathname = this.getPath(e).slice(n) || "/", new Request(t, e);
444
451
  };
445
- })(), this.#r("ALL", v(e, "*"), async (e, n) => {
452
+ })(), this.#r("ALL", y(e, "*"), async (e, n) => {
446
453
  let i = await t(r(e.req.raw), ...a(e));
447
454
  if (i) return i;
448
455
  await n();
449
456
  }), this;
450
457
  }
451
458
  #r(e, t, n, r) {
452
- e = e.toUpperCase(), t = v(this._basePath, t);
459
+ e = e.toUpperCase(), t = y(this._basePath, t);
453
460
  let i = {
454
- basePath: r === void 0 ? this._basePath : v(this._basePath, r),
461
+ basePath: r === void 0 ? this._basePath : y(this._basePath, r),
455
462
  path: t,
456
463
  method: e,
457
464
  handler: n
@@ -462,13 +469,13 @@ var o = (e, t, n) => {
462
469
  if (e instanceof Error) return this.errorHandler(e, t);
463
470
  throw e;
464
471
  }
465
- #a(e, n, r, i) {
466
- if (i === "HEAD") return (async () => new Response(null, await this.#a(e, n, r, "GET")))();
467
- let a = this.getPath(e, { env: r }), o = this.router.match(i, a), s = new re(e, {
472
+ #a(e, t, r, i) {
473
+ if (i === "HEAD") return (async () => new Response(null, await this.#a(e, t, r, "GET")))();
474
+ let a = this.getPath(e, { env: r }), o = this.router.match(i, a), s = new ie(e, {
468
475
  path: a,
469
476
  matchResult: o,
470
477
  env: r,
471
- executionCtx: n,
478
+ executionCtx: t,
472
479
  notFoundHandler: this.#n
473
480
  });
474
481
  if (o[0].length === 1) {
@@ -482,7 +489,7 @@ var o = (e, t, n) => {
482
489
  }
483
490
  return e instanceof Promise ? e.then((e) => e || (s.finalized ? s.res : this.#n(s))).catch((e) => this.#i(e, s)) : e ?? this.#n(s);
484
491
  }
485
- let c = t(o[0], this.errorHandler, this.#n);
492
+ let c = n(o[0], this.errorHandler, this.#n);
486
493
  return (async () => {
487
494
  try {
488
495
  let e = await c(s);
@@ -494,14 +501,14 @@ var o = (e, t, n) => {
494
501
  })();
495
502
  }
496
503
  fetch = (e, ...t) => this.#a(e, t[1], t[0], e.method);
497
- request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${v("/", e)}`, t), n, r));
504
+ request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${y("/", e)}`, t), n, r));
498
505
  fire = () => {
499
506
  addEventListener("fetch", (e) => {
500
507
  e.respondWith(this.#a(e.request, e, void 0, e.request.method));
501
508
  });
502
509
  };
503
510
  }, N = [];
504
- function ce(e, t) {
511
+ function le(e, t) {
505
512
  let n = this.buildAllMatchers(), r = ((e, t) => {
506
513
  let r = n[e] || n.ALL, i = r[2][t];
507
514
  if (i) return i;
@@ -513,12 +520,12 @@ function ce(e, t) {
513
520
  return this.match = r, r(e, t);
514
521
  }
515
522
  //#endregion
516
- //#region ../../node_modules/.pnpm/hono@4.12.23/node_modules/hono/dist/router/reg-exp-router/node.js
517
- var P = "[^/]+", F = ".*", I = "(?:|/.*)", L = /* @__PURE__ */ Symbol(), le = /* @__PURE__ */ new Set(".\\+*[^]$()");
518
- function ue(e, t) {
523
+ //#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/router/reg-exp-router/node.js
524
+ var P = "[^/]+", F = ".*", I = "(?:|/.*)", L = /* @__PURE__ */ Symbol(), ue = /* @__PURE__ */ new Set(".\\+*[^]$()");
525
+ function de(e, t) {
519
526
  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;
520
527
  }
521
- var de = class e {
528
+ var fe = class e {
522
529
  #e;
523
530
  #t;
524
531
  #n = /* @__PURE__ */ Object.create(null);
@@ -559,15 +566,15 @@ var de = class e {
559
566
  l.insert(s, n, r, i, a);
560
567
  }
561
568
  buildRegExpStr() {
562
- let e = Object.keys(this.#n).sort(ue).map((e) => {
569
+ let e = Object.keys(this.#n).sort(de).map((e) => {
563
570
  let t = this.#n[e];
564
- return (typeof t.#t == "number" ? `(${e})@${t.#t}` : le.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
571
+ return (typeof t.#t == "number" ? `(${e})@${t.#t}` : ue.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
565
572
  });
566
573
  return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
567
574
  }
568
- }, fe = class {
575
+ }, pe = class {
569
576
  #e = { varIndex: 0 };
570
- #t = new de();
577
+ #t = new fe();
571
578
  insert(e, t, n) {
572
579
  let r = [], i = [];
573
580
  for (let t = 0;;) {
@@ -601,7 +608,7 @@ var de = class e {
601
608
  r
602
609
  ];
603
610
  }
604
- }, pe = [
611
+ }, me = [
605
612
  /^$/,
606
613
  [],
607
614
  /* @__PURE__ */ Object.create(null)
@@ -609,12 +616,12 @@ var de = class e {
609
616
  function z(e) {
610
617
  return R[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
611
618
  }
612
- function me() {
619
+ function he() {
613
620
  R = /* @__PURE__ */ Object.create(null);
614
621
  }
615
- function he(e) {
616
- let t = new fe(), n = [];
617
- if (e.length === 0) return pe;
622
+ function ge(e) {
623
+ let t = new pe(), n = [];
624
+ if (e.length === 0) return me;
618
625
  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);
619
626
  for (let e = 0, a = -1, o = r.length; e < o; e++) {
620
627
  let [o, s, c] = r[e];
@@ -654,7 +661,7 @@ function B(e, t) {
654
661
  for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (z(n).test(t)) return [...e[n]];
655
662
  }
656
663
  }
657
- var ge = class {
664
+ var _e = class {
658
665
  name = "RegExpRouter";
659
666
  #e;
660
667
  #t;
@@ -683,7 +690,7 @@ var ge = class {
683
690
  });
684
691
  return;
685
692
  }
686
- let o = y(t) || [t];
693
+ let o = b(t) || [t];
687
694
  for (let t = 0, s = o.length; t < s; t++) {
688
695
  let c = o[t];
689
696
  Object.keys(i).forEach((o) => {
@@ -691,21 +698,21 @@ var ge = class {
691
698
  });
692
699
  }
693
700
  }
694
- match = ce;
701
+ match = le;
695
702
  buildAllMatchers() {
696
703
  let e = /* @__PURE__ */ Object.create(null);
697
704
  return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t) => {
698
705
  e[t] ||= this.#n(t);
699
- }), this.#e = this.#t = void 0, me(), e;
706
+ }), this.#e = this.#t = void 0, he(), e;
700
707
  }
701
708
  #n(e) {
702
709
  let t = [], n = e === "ALL";
703
710
  return [this.#e, this.#t].forEach((r) => {
704
711
  let i = r[e] ? Object.keys(r[e]).map((t) => [t, r[e][t]]) : [];
705
712
  i.length === 0 ? e !== "ALL" && t.push(...Object.keys(r.ALL).map((e) => [e, r.ALL[e]])) : (n ||= !0, t.push(...i));
706
- }), n ? he(t) : null;
713
+ }), n ? ge(t) : null;
707
714
  }
708
- }, _e = class {
715
+ }, ve = class {
709
716
  name = "SmartRouter";
710
717
  #e = [];
711
718
  #t = [];
@@ -742,10 +749,10 @@ var ge = class {
742
749
  if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
743
750
  return this.#e[0];
744
751
  }
745
- }, V = /* @__PURE__ */ Object.create(null), ve = (e) => {
752
+ }, V = /* @__PURE__ */ Object.create(null), ye = (e) => {
746
753
  for (let t in e) return !0;
747
754
  return !1;
748
- }, ye = class e {
755
+ }, be = class e {
749
756
  #e;
750
757
  #t;
751
758
  #n;
@@ -764,9 +771,9 @@ var ge = class {
764
771
  }
765
772
  insert(t, n, r) {
766
773
  this.#r = ++this.#r;
767
- let i = this, a = l(n), o = [];
774
+ let i = this, a = u(n), o = [];
768
775
  for (let t = 0, n = a.length; t < n; t++) {
769
- let n = a[t], r = a[t + 1], s = p(n, r), c = Array.isArray(s) ? s[0] : n;
776
+ let n = a[t], r = a[t + 1], s = m(n, r), c = Array.isArray(s) ? s[0] : n;
770
777
  if (c in i.#t) {
771
778
  i = i.#t[c], s && o.push(s[1]);
772
779
  continue;
@@ -791,7 +798,7 @@ var ge = class {
791
798
  search(e, t) {
792
799
  let n = [];
793
800
  this.#i = V;
794
- let r = [this], i = c(t), a = [], o = i.length, s = null;
801
+ let r = [this], i = l(t), a = [], o = i.length, s = null;
795
802
  for (let c = 0; c < o; c++) {
796
803
  let l = i[c], u = c === o - 1, d = [];
797
804
  for (let f = 0, p = r.length; f < p; f++) {
@@ -815,7 +822,7 @@ var ge = class {
815
822
  }
816
823
  let r = t.substring(s[c]), l = _.exec(r);
817
824
  if (l) {
818
- if (m[g] = l[0], this.#a(n, v, e, p.#i, m), ve(v.#t)) {
825
+ if (m[g] = l[0], this.#a(n, v, e, p.#i, m), ye(v.#t)) {
819
826
  v.#i = m;
820
827
  let e = l[0].match(/\//)?.length ?? 0;
821
828
  (a[e] ||= []).push(v);
@@ -831,14 +838,14 @@ var ge = class {
831
838
  }
832
839
  return n.length > 1 && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
833
840
  }
834
- }, be = class {
841
+ }, xe = class {
835
842
  name = "TrieRouter";
836
843
  #e;
837
844
  constructor() {
838
- this.#e = new ye();
845
+ this.#e = new be();
839
846
  }
840
847
  add(e, t, n) {
841
- let r = y(t);
848
+ let r = b(t);
842
849
  if (r) {
843
850
  for (let t = 0, i = r.length; t < i; t++) this.#e.insert(e, r[t], n);
844
851
  return;
@@ -848,43 +855,43 @@ var ge = class {
848
855
  match(e, t) {
849
856
  return this.#e.search(e, t);
850
857
  }
851
- }, xe = class extends se {
858
+ }, Se = class extends ce {
852
859
  constructor(e = {}) {
853
- super(e), this.router = e.router ?? new _e({ routers: [new ge(), new be()] });
860
+ super(e), this.router = e.router ?? new ve({ routers: [new _e(), new xe()] });
854
861
  }
855
862
  };
856
863
  //#endregion
857
864
  //#region src/coordinator-invites.ts
858
- function Se(e) {
865
+ function Ce(e) {
859
866
  let t = "";
860
867
  for (let n of e) t += String.fromCharCode(n);
861
868
  return btoa(t);
862
869
  }
863
- function Ce(e) {
870
+ function we(e) {
864
871
  let t = atob(e), n = new Uint8Array(t.length);
865
872
  for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
866
873
  return n;
867
874
  }
868
- function we(e) {
875
+ function Te(e) {
869
876
  return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
870
877
  }
871
- function Te(e) {
878
+ function Ee(e) {
872
879
  let t = e.replace(/-/g, "+").replace(/_/g, "/");
873
880
  return t + "=".repeat((4 - t.length % 4) % 4);
874
881
  }
875
882
  function H(e) {
876
883
  let t = JSON.stringify(e);
877
- return we(Se(new TextEncoder().encode(t)));
884
+ return Te(Ce(new TextEncoder().encode(t)));
878
885
  }
879
- function Ee(e) {
880
- let t = new TextDecoder().decode(Ce(Te(e))), n = JSON.parse(t);
886
+ function De(e) {
887
+ let t = new TextDecoder().decode(we(Ee(e))), n = JSON.parse(t);
881
888
  if (typeof n != "object" || !n) throw Error("invalid invite payload");
882
889
  return n;
883
890
  }
884
891
  function U(e) {
885
892
  return `codemem://join?invite=${encodeURIComponent(e)}`;
886
893
  }
887
- function De(e) {
894
+ function Oe(e) {
888
895
  let t = e.trim();
889
896
  if (t.startsWith("codemem://")) {
890
897
  let e = new URL(t).searchParams.get("invite") ?? "";
@@ -895,12 +902,12 @@ function De(e) {
895
902
  }
896
903
  //#endregion
897
904
  //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
898
- function Oe(e) {
905
+ function ke(e) {
899
906
  let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
900
907
  return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
901
908
  }
902
909
  function W() {
903
- let [e, t] = Oe();
910
+ let [e, t] = ke();
904
911
  return e * 1e3 + Math.floor(t / 1e6);
905
912
  }
906
913
  function G(e) {
@@ -908,7 +915,7 @@ function G(e) {
908
915
  }
909
916
  //#endregion
910
917
  //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
911
- var ke = class {
918
+ var Ae = class {
912
919
  bucketSize;
913
920
  tokensPerInterval;
914
921
  interval;
@@ -961,13 +968,13 @@ var ke = class {
961
968
  let n = t * (this.tokensPerInterval / this.interval), r = this.content;
962
969
  return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
963
970
  }
964
- }, Ae = class {
971
+ }, je = class {
965
972
  tokenBucket;
966
973
  curIntervalStart;
967
974
  tokensThisInterval;
968
975
  fireImmediately;
969
976
  constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
970
- this.tokenBucket = new ke({
977
+ this.tokenBucket = new Ae({
971
978
  bucketSize: e,
972
979
  tokensPerInterval: e,
973
980
  interval: t
@@ -1000,7 +1007,7 @@ var ke = class {
1000
1007
  };
1001
1008
  //#endregion
1002
1009
  //#region src/request-rate-limit.ts
1003
- function je(e = {}) {
1010
+ function Me(e = {}) {
1004
1011
  let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
1005
1012
  function a(e) {
1006
1013
  return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
@@ -1017,7 +1024,7 @@ function je(e = {}) {
1017
1024
  o(l);
1018
1025
  let u = `${c}:${e}`, d = r.get(u);
1019
1026
  return d || (d = {
1020
- limiter: new Ae({
1027
+ limiter: new je({
1021
1028
  tokensPerInterval: c,
1022
1029
  interval: t,
1023
1030
  fireImmediately: !0
@@ -1035,7 +1042,7 @@ function je(e = {}) {
1035
1042
  //#endregion
1036
1043
  //#region src/scope-membership-semantics.ts
1037
1044
  var K = "Revocation blocks future sync for this Space. It does not remove data already copied to the revoked device; offline devices, backups, copied databases, malicious peers, or old versions may retain data.";
1038
- function Me(e) {
1045
+ function Ne(e) {
1039
1046
  let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
1040
1047
  return t == null || n == null ? {
1041
1048
  membership_epoch: t,
@@ -1061,7 +1068,7 @@ function q(e) {
1061
1068
  }
1062
1069
  //#endregion
1063
1070
  //#region src/sync-auth-constants.ts
1064
- var Ne = 300;
1071
+ var Pe = 300;
1065
1072
  //#endregion
1066
1073
  //#region src/sync-fingerprint.ts
1067
1074
  function J(t) {
@@ -1069,7 +1076,7 @@ function J(t) {
1069
1076
  }
1070
1077
  //#endregion
1071
1078
  //#region src/coordinator-api.ts
1072
- var Y = 64 * 1024, X = "X-Codemem-Coordinator-Admin", Z = "X-Codemem-Coordinator-Admin-Actor", Pe = 120, Fe = 30;
1079
+ var Y = 64 * 1024, X = "X-Codemem-Coordinator-Admin", Z = "X-Codemem-Coordinator-Admin-Actor", Fe = 120, Ie = 30;
1073
1080
  function Q(e, t) {
1074
1081
  let n = t.adminSecret();
1075
1082
  if (!n) return {
@@ -1088,14 +1095,14 @@ function Q(e, t) {
1088
1095
  error: "missing_admin_header"
1089
1096
  };
1090
1097
  }
1091
- function Ie(e) {
1098
+ function Le(e) {
1092
1099
  let t = new URL(e);
1093
1100
  return t.search ? `${t.pathname}${t.search}` : t.pathname;
1094
1101
  }
1095
- async function Le(e, t, n, r) {
1102
+ async function Re(e, t, n, r) {
1096
1103
  return await e.recordNonce(t, n, r);
1097
1104
  }
1098
- async function Re(e, t) {
1105
+ async function ze(e, t) {
1099
1106
  await e.cleanupNonces(t);
1100
1107
  }
1101
1108
  async function $(e, t, n, r) {
@@ -1126,7 +1133,7 @@ async function $(e, t, n, r) {
1126
1133
  try {
1127
1134
  u = await n({
1128
1135
  method: r.method,
1129
- pathWithQuery: Ie(r.url),
1136
+ pathWithQuery: Le(r.url),
1130
1137
  bodyBytes: r.body,
1131
1138
  timestamp: o,
1132
1139
  nonce: s,
@@ -1147,7 +1154,7 @@ async function $(e, t, n, r) {
1147
1154
  enrollment: null
1148
1155
  };
1149
1156
  let d = t.now();
1150
- return await Le(e, i, s, d) ? (await Re(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 300 * 2 * 1e3)).toISOString()), {
1157
+ return await Re(e, i, s, d) ? (await ze(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 300 * 2 * 1e3)).toISOString()), {
1151
1158
  ok: !0,
1152
1159
  error: "ok",
1153
1160
  enrollment: c
@@ -1157,9 +1164,9 @@ async function $(e, t, n, r) {
1157
1164
  enrollment: null
1158
1165
  };
1159
1166
  }
1160
- function ze(e) {
1167
+ function Be(e) {
1161
1168
  if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
1162
- let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? je(), o = Math.max(1, Math.trunc(i.readLimit ?? Pe)), s = Math.max(1, Math.trunc(i.mutationLimit ?? Fe)), 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 xe(), d = new TextDecoder();
1169
+ let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? Me(), o = Math.max(1, Math.trunc(i.readLimit ?? Fe)), s = Math.max(1, Math.trunc(i.mutationLimit ?? Ie)), 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 Se(), d = new TextDecoder();
1163
1170
  function f(e, t, n) {
1164
1171
  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);
1165
1172
  return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
@@ -1855,6 +1862,7 @@ function ze(e) {
1855
1862
  if (!o) return e.json({ error: "invalid_json" }, 400);
1856
1863
  let s = String(o.group_id ?? "").trim(), c = String(o.policy ?? "auto_admit").trim(), l = String(o.expires_at ?? "").trim(), u = String(o.created_by ?? "").trim() || null;
1857
1864
  if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
1865
+ if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
1858
1866
  let d = n();
1859
1867
  try {
1860
1868
  let t = await d.getGroup(s);
@@ -1953,11 +1961,11 @@ function ze(e) {
1953
1961
  } finally {
1954
1962
  await c.close();
1955
1963
  }
1956
- }), u.post("/v1/admin/join-requests/approve", async (e) => Be(e, !0, {
1964
+ }), u.post("/v1/admin/join-requests/approve", async (e) => Ve(e, !0, {
1957
1965
  createStore: n,
1958
1966
  runtime: t,
1959
1967
  rateLimitedResponse: f
1960
- })), u.post("/v1/admin/join-requests/deny", async (e) => Be(e, !1, {
1968
+ })), u.post("/v1/admin/join-requests/deny", async (e) => Ve(e, !1, {
1961
1969
  createStore: n,
1962
1970
  runtime: t,
1963
1971
  rateLimitedResponse: f
@@ -2034,7 +2042,7 @@ function ze(e) {
2034
2042
  }
2035
2043
  }), u;
2036
2044
  }
2037
- async function Be(e, t, n) {
2045
+ async function Ve(e, t, n) {
2038
2046
  let r = Q(e.req.header(X), n.runtime);
2039
2047
  if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2040
2048
  let i = n.rateLimitedResponse(e, "admin", !0);
@@ -2098,6 +2106,6 @@ async function Be(e, t, n) {
2098
2106
  }
2099
2107
  }
2100
2108
  //#endregion
2101
- export { q as a, H as c, K as i, De as l, J as n, Me as o, Ne as r, Ee as s, ze as t, U as u };
2109
+ export { q as a, H as c, t as d, K as i, Oe as l, J as n, Ne as o, Pe as r, De as s, Be as t, U as u };
2102
2110
 
2103
- //# sourceMappingURL=coordinator-api-CbONcz8J.js.map
2111
+ //# sourceMappingURL=coordinator-api-hZ1RVJUN.js.map