@niscorp/moss 0.9.2 → 0.10.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 (108) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/DESIGN.md +58 -55
  3. package/DOCS.md +280 -170
  4. package/README.md +5 -5
  5. package/dist/{chunk-PVZMCEBX.cjs → chunk-3CKBKTXA.cjs} +2 -2
  6. package/dist/chunk-3CKBKTXA.cjs.map +1 -0
  7. package/dist/{chunk-FUJRIO4N.js → chunk-3PL4AH4I.js} +4 -4
  8. package/dist/{chunk-FUJRIO4N.js.map → chunk-3PL4AH4I.js.map} +1 -1
  9. package/dist/{chunk-QAHDSRPK.js → chunk-4URQHVYG.js} +2 -2
  10. package/dist/chunk-4URQHVYG.js.map +1 -0
  11. package/dist/{chunk-6ZWMC2OV.cjs → chunk-6ACVHHFK.cjs} +33 -30
  12. package/dist/chunk-6ACVHHFK.cjs.map +1 -0
  13. package/dist/{chunk-IUJ2TRNB.cjs → chunk-7MOEKAVC.cjs} +6 -6
  14. package/dist/{chunk-IUJ2TRNB.cjs.map → chunk-7MOEKAVC.cjs.map} +1 -1
  15. package/dist/{chunk-NCQBGK3E.cjs → chunk-BFA76AKR.cjs} +4 -4
  16. package/dist/chunk-BFA76AKR.cjs.map +1 -0
  17. package/dist/{chunk-T5BRTFKP.js → chunk-DSVRFAGX.js} +3 -3
  18. package/dist/{chunk-T5BRTFKP.js.map → chunk-DSVRFAGX.js.map} +1 -1
  19. package/dist/{chunk-IW3A2YIC.js → chunk-EYWD733E.js} +3 -3
  20. package/dist/{chunk-IW3A2YIC.js.map → chunk-EYWD733E.js.map} +1 -1
  21. package/dist/{chunk-IY5BOFLK.cjs → chunk-G4P3XEVM.cjs} +19 -19
  22. package/dist/chunk-G4P3XEVM.cjs.map +1 -0
  23. package/dist/{chunk-6QPTMKRE.cjs → chunk-HUP7CZ7X.cjs} +6 -6
  24. package/dist/{chunk-6QPTMKRE.cjs.map → chunk-HUP7CZ7X.cjs.map} +1 -1
  25. package/dist/{chunk-VKQPOZDJ.cjs → chunk-LTS4AM6T.cjs} +4 -4
  26. package/dist/chunk-LTS4AM6T.cjs.map +1 -0
  27. package/dist/{chunk-UTFOMFCH.js → chunk-MEHCZECW.js} +5 -5
  28. package/dist/chunk-MEHCZECW.js.map +1 -0
  29. package/dist/{chunk-WMIJU6ZZ.js → chunk-MYPK5YZR.js} +297 -206
  30. package/dist/chunk-MYPK5YZR.js.map +1 -0
  31. package/dist/{chunk-TKXYPO2Y.js → chunk-NUX5MH4I.js} +4 -4
  32. package/dist/chunk-NUX5MH4I.js.map +1 -0
  33. package/dist/{chunk-KVXP6OTW.cjs → chunk-UVY5ZPWW.cjs} +373 -282
  34. package/dist/chunk-UVY5ZPWW.cjs.map +1 -0
  35. package/dist/{chunk-5ZB7FZ2J.js → chunk-VYYDLGQ2.js} +29 -26
  36. package/dist/chunk-VYYDLGQ2.js.map +1 -0
  37. package/dist/{chunk-NRZ3Z2FF.js → chunk-WKZWSWOJ.js} +4 -4
  38. package/dist/chunk-WKZWSWOJ.js.map +1 -0
  39. package/dist/{chunk-KMZT6NVL.cjs → chunk-XH6TSWG4.cjs} +7 -7
  40. package/dist/{chunk-KMZT6NVL.cjs.map → chunk-XH6TSWG4.cjs.map} +1 -1
  41. package/dist/client.cjs +5 -5
  42. package/dist/client.js +2 -2
  43. package/dist/{document-deAs7Dre.d.cts → document-DvhT_HaJ.d.cts} +3 -2
  44. package/dist/{document-C3aS9uiW.d.ts → document-iKaRinZE.d.ts} +3 -2
  45. package/dist/{index-CSEo7Tys.d.ts → index-DWj3_0Zg.d.cts} +3 -0
  46. package/dist/{index-CSEo7Tys.d.cts → index-DWj3_0Zg.d.ts} +3 -0
  47. package/dist/index.cjs +16 -16
  48. package/dist/index.d.cts +4 -4
  49. package/dist/index.d.ts +4 -4
  50. package/dist/index.js +4 -4
  51. package/dist/integrations.cjs +27 -18
  52. package/dist/integrations.cjs.map +1 -1
  53. package/dist/integrations.d.cts +1 -1
  54. package/dist/integrations.d.ts +1 -1
  55. package/dist/integrations.js +25 -16
  56. package/dist/integrations.js.map +1 -1
  57. package/dist/node.cjs +9 -9
  58. package/dist/node.d.cts +2 -2
  59. package/dist/node.d.ts +2 -2
  60. package/dist/node.js +5 -5
  61. package/dist/protocol.cjs +5 -5
  62. package/dist/protocol.js +1 -1
  63. package/dist/terminal/dom/index.cjs +3 -3
  64. package/dist/terminal/dom/index.js +1 -1
  65. package/dist/terminal/dom/server.cjs +2 -2
  66. package/dist/terminal/dom/server.js +1 -1
  67. package/dist/terminal/index.cjs +3 -3
  68. package/dist/terminal/index.js +2 -2
  69. package/dist/terminal/ink/index.js.map +1 -1
  70. package/dist/terminal/react/index.cjs +9 -9
  71. package/dist/terminal/react/index.cjs.map +1 -1
  72. package/dist/terminal/react/index.js +4 -4
  73. package/dist/terminal/react/index.js.map +1 -1
  74. package/dist/terminal/react/server.cjs +4 -4
  75. package/dist/terminal/react/server.js +2 -2
  76. package/dist/terminal/tty/index.cjs +12 -12
  77. package/dist/terminal/tty/index.cjs.map +1 -1
  78. package/dist/terminal/tty/index.js +6 -6
  79. package/dist/terminal/tty/index.js.map +1 -1
  80. package/dist/terminal/vue/index.cjs +9 -9
  81. package/dist/terminal/vue/index.cjs.map +1 -1
  82. package/dist/terminal/vue/index.js +4 -4
  83. package/dist/terminal/vue/index.js.map +1 -1
  84. package/dist/terminal/vue/server.cjs +4 -4
  85. package/dist/terminal/vue/server.js +2 -2
  86. package/dist/tide.d.cts +1 -1
  87. package/dist/tide.d.ts +1 -1
  88. package/dist/unverified.cjs +4 -4
  89. package/dist/unverified.js +3 -3
  90. package/dist/vite.cjs +36 -10
  91. package/dist/vite.cjs.map +1 -1
  92. package/dist/vite.d.cts +2 -2
  93. package/dist/vite.d.ts +2 -2
  94. package/dist/vite.js +31 -5
  95. package/dist/vite.js.map +1 -1
  96. package/package.json +13 -13
  97. package/dist/chunk-5ZB7FZ2J.js.map +0 -1
  98. package/dist/chunk-6ZWMC2OV.cjs.map +0 -1
  99. package/dist/chunk-IY5BOFLK.cjs.map +0 -1
  100. package/dist/chunk-KVXP6OTW.cjs.map +0 -1
  101. package/dist/chunk-NCQBGK3E.cjs.map +0 -1
  102. package/dist/chunk-NRZ3Z2FF.js.map +0 -1
  103. package/dist/chunk-PVZMCEBX.cjs.map +0 -1
  104. package/dist/chunk-QAHDSRPK.js.map +0 -1
  105. package/dist/chunk-TKXYPO2Y.js.map +0 -1
  106. package/dist/chunk-UTFOMFCH.js.map +0 -1
  107. package/dist/chunk-VKQPOZDJ.cjs.map +0 -1
  108. package/dist/chunk-WMIJU6ZZ.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunk6ZWMC2OV_cjs = require('./chunk-6ZWMC2OV.cjs');
4
- var chunkPVZMCEBX_cjs = require('./chunk-PVZMCEBX.cjs');
5
- var chunkNCQBGK3E_cjs = require('./chunk-NCQBGK3E.cjs');
3
+ var chunk6ACVHHFK_cjs = require('./chunk-6ACVHHFK.cjs');
4
+ var chunk3CKBKTXA_cjs = require('./chunk-3CKBKTXA.cjs');
5
+ var chunkBFA76AKR_cjs = require('./chunk-BFA76AKR.cjs');
6
6
  var zod = require('zod');
7
7
  var crypto$1 = require('crypto');
8
8
  var vex = require('@niscorp/vex');
@@ -21,7 +21,7 @@ var nova = require('@niscorp/nova');
21
21
  var i18n = require('@niscorp/nova/i18n');
22
22
  var reflect = require('@niscorp/nova/reflect');
23
23
 
24
- var tokenFromCookie = (header, name = chunkNCQBGK3E_cjs.DEFAULT_TOKEN_KEY) => {
24
+ var tokenFromCookie = (header, name = chunkBFA76AKR_cjs.DEFAULT_TOKEN_KEY) => {
25
25
  if (header === void 0 || header === null) return null;
26
26
  const wanted = encodeURIComponent(name);
27
27
  for (const part of header.split(";")) {
@@ -39,11 +39,13 @@ var tokenFromCookie = (header, name = chunkNCQBGK3E_cjs.DEFAULT_TOKEN_KEY) => {
39
39
  var ownOriginOf = (origin, host, listed2 = []) => {
40
40
  if (origin === void 0 || origin === null || !URL.canParse(origin)) return void 0;
41
41
  const asked = new URL(origin);
42
- const own = asked.host === host?.toLowerCase() || listed2.some((entry) => URL.canParse(entry) && new URL(entry).origin === asked.origin);
42
+ const named = host?.toLowerCase();
43
+ const schemePort = asked.protocol === "https:" ? "443" : asked.protocol === "http:" ? "80" : void 0;
44
+ const own = asked.host === named || schemePort !== void 0 && asked.port === "" && `${asked.host}:${schemePort}` === named || listed2.some((entry) => URL.canParse(entry) && new URL(entry).origin === asked.origin);
43
45
  return own ? asked : void 0;
44
46
  };
45
47
  var cookiesAt = (where, key, token, lastsMs) => {
46
- const name = encodeURIComponent(chunkNCQBGK3E_cjs.sessionNameOf(key, where.port));
48
+ const name = encodeURIComponent(chunkBFA76AKR_cjs.sessionNameOf(key, where.port));
47
49
  const life = token === null ? "; Max-Age=0" : typeof lastsMs === "number" ? `; Max-Age=${Math.max(0, Math.floor(lastsMs / 1e3))}` : "";
48
50
  const kept = `Path=/; SameSite=Lax${where.secure ? "; Secure" : ""}${life}`;
49
51
  return [`${where.secure ? "__Host-" : ""}${name}=${encodeURIComponent(token ?? "")}; HttpOnly; ${kept}`, `${name}.held=${token === null ? "" : "1"}; ${kept}`];
@@ -57,10 +59,10 @@ var originOf = (request) => {
57
59
  };
58
60
  var sessionCookies = (page, token, options = {}) => {
59
61
  const at = new URL(typeof page === "string" ? page : originOf(page));
60
- return cookiesAt({ port: at.port, secure: at.protocol === "https:" }, options.key ?? chunkNCQBGK3E_cjs.DEFAULT_TOKEN_KEY, token, options.lastsMs);
62
+ return cookiesAt({ port: at.port, secure: at.protocol === "https:" }, options.key ?? chunkBFA76AKR_cjs.DEFAULT_TOKEN_KEY, token, options.lastsMs);
61
63
  };
62
- var sessionTokenOf = (cookies, where, key = chunkNCQBGK3E_cjs.DEFAULT_TOKEN_KEY) => {
63
- const name = chunkNCQBGK3E_cjs.sessionNameOf(key, where.port);
64
+ var sessionTokenOf = (cookies, where, key = chunkBFA76AKR_cjs.DEFAULT_TOKEN_KEY) => {
65
+ const name = chunkBFA76AKR_cjs.sessionNameOf(key, where.port);
64
66
  for (const secure of where.secure === void 0 ? [true, false] : [where.secure]) {
65
67
  const token = tokenFromCookie(cookies, `${secure ? "__Host-" : ""}${name}`);
66
68
  if (token !== null) return { token, clear: cookiesAt({ port: where.port, secure }, key, null) };
@@ -164,8 +166,8 @@ var devSession = (token) => {
164
166
  var DEFAULT_IDENTITY_MAX = 1e4;
165
167
  var DEFAULT_IDENTITY_IDLE_MS = 30 * 60 * 1e3;
166
168
  var SWEEP_EVERY_MS = 60 * 1e3;
167
- var createHeldRecords = (max) => {
168
- const held = /* @__PURE__ */ new Map();
169
+ var createResidentRecords = (max) => {
170
+ const resident = /* @__PURE__ */ new Map();
169
171
  const tagged = /* @__PURE__ */ new Map();
170
172
  let evicted = 0;
171
173
  const untag = (principal, record) => {
@@ -177,22 +179,22 @@ var createHeldRecords = (max) => {
177
179
  if (group.size === 0) tagged.delete(tag);
178
180
  };
179
181
  const forget = (principal) => {
180
- const entry = held.get(principal);
182
+ const entry = resident.get(principal);
181
183
  if (entry === void 0) return false;
182
184
  untag(principal, entry.record);
183
- held.delete(principal);
185
+ resident.delete(principal);
184
186
  return true;
185
187
  };
186
188
  const evictOldest = () => {
187
- const oldest = held.keys().next();
189
+ const oldest = resident.keys().next();
188
190
  if (oldest.done === true) return;
189
191
  forget(oldest.value);
190
192
  evicted += 1;
191
193
  };
192
194
  const remember = (principal, record, at) => {
193
195
  forget(principal);
194
- while (held.size >= max) evictOldest();
195
- held.set(principal, { record, since: at, lastSeen: at });
196
+ while (resident.size >= max) evictOldest();
197
+ resident.set(principal, { record, since: at, lastSeen: at });
196
198
  if (record.tag !== void 0) {
197
199
  const group = tagged.get(record.tag) ?? /* @__PURE__ */ new Set();
198
200
  group.add(principal);
@@ -200,16 +202,16 @@ var createHeldRecords = (max) => {
200
202
  }
201
203
  };
202
204
  return {
203
- of: (principal) => held.get(principal),
205
+ of: (principal) => resident.get(principal),
204
206
  touch: (principal, entry, at) => {
205
- held.delete(principal);
207
+ resident.delete(principal);
206
208
  entry.lastSeen = at;
207
- held.set(principal, entry);
209
+ resident.set(principal, entry);
208
210
  },
209
211
  forget,
210
212
  remember,
211
213
  forgetAll: () => {
212
- held.clear();
214
+ resident.clear();
213
215
  tagged.clear();
214
216
  },
215
217
  forgetTag: (tag) => {
@@ -218,15 +220,15 @@ var createHeldRecords = (max) => {
218
220
  return principals;
219
221
  },
220
222
  forgetIdle: (at, idleMs) => {
221
- for (const [principal, entry] of [...held]) {
223
+ for (const [principal, entry] of [...resident]) {
222
224
  if (at - entry.lastSeen >= idleMs) {
223
225
  forget(principal);
224
226
  evicted += 1;
225
227
  }
226
228
  }
227
229
  },
228
- list: () => [...held].map(([principal, entry]) => ({ principal, since: entry.since, lastSeen: entry.lastSeen })),
229
- size: () => held.size,
230
+ list: () => [...resident].map(([principal, entry]) => ({ principal, since: entry.since, lastSeen: entry.lastSeen })),
231
+ size: () => resident.size,
230
232
  evicted: () => evicted
231
233
  };
232
234
  };
@@ -238,17 +240,17 @@ var createIdentityCache = (ctx) => {
238
240
  const idleMs = ctx.idleMs ?? DEFAULT_IDENTITY_IDLE_MS;
239
241
  const revalidateMs = ctx.revalidateMs ?? 0;
240
242
  const now = ctx.now ?? Date.now;
241
- const held = createHeldRecords(max);
243
+ const records = createResidentRecords(max);
242
244
  const pending = /* @__PURE__ */ new Map();
243
245
  let resolved = 0;
244
246
  let expired = 0;
245
247
  const get = async (principal) => {
246
248
  const at = now();
247
- const hit = held.of(principal);
249
+ const hit = records.of(principal);
248
250
  if (hit !== void 0) {
249
251
  const stale = revalidateMs > 0 && at - hit.since >= revalidateMs;
250
252
  if (!stale) {
251
- held.touch(principal, hit, at);
253
+ records.touch(principal, hit, at);
252
254
  return hit.record;
253
255
  }
254
256
  expired += 1;
@@ -260,7 +262,7 @@ var createIdentityCache = (ctx) => {
260
262
  const work = ctx.resolve(principal).then((record) => {
261
263
  resolved += 1;
262
264
  const wearsForgottenTag = record.tag !== void 0 && forgotten.has(record.tag);
263
- if (isStillOut() && !wearsForgottenTag) held.remember(principal, record, now());
265
+ if (isStillOut() && !wearsForgottenTag) records.remember(principal, record, now());
264
266
  return record;
265
267
  }).finally(() => {
266
268
  if (isStillOut()) pending.delete(principal);
@@ -268,26 +270,26 @@ var createIdentityCache = (ctx) => {
268
270
  pending.set(principal, { work, forgotten });
269
271
  return work;
270
272
  };
271
- const sweep2 = idleMs > 0 ? setInterval(() => held.forgetIdle(now(), idleMs), Math.min(SWEEP_EVERY_MS, idleMs)) : void 0;
273
+ const sweep2 = idleMs > 0 ? setInterval(() => records.forgetIdle(now(), idleMs), Math.min(SWEEP_EVERY_MS, idleMs)) : void 0;
272
274
  sweep2?.unref?.();
273
275
  return {
274
276
  get,
275
277
  invalidate: (principal) => {
276
278
  pending.delete(principal);
277
- return held.forget(principal);
279
+ return records.forget(principal);
278
280
  },
279
281
  invalidateAll: () => {
280
- held.forgetAll();
282
+ records.forgetAll();
281
283
  pending.clear();
282
284
  },
283
285
  invalidateTag: (tag) => {
284
- const principals = held.forgetTag(tag);
286
+ const principals = records.forgetTag(tag);
285
287
  for (const principal of principals) pending.delete(principal);
286
288
  for (const flight of pending.values()) flight.forgotten.add(tag);
287
289
  return principals;
288
290
  },
289
- list: held.list,
290
- meter: () => ({ size: held.size(), max, resolved, evicted: held.evicted(), expired }),
291
+ list: records.list,
292
+ meter: () => ({ size: records.size(), max, resolved, evicted: records.evicted(), expired }),
291
293
  stop: () => {
292
294
  if (sweep2 !== void 0) clearInterval(sweep2);
293
295
  }
@@ -295,7 +297,7 @@ var createIdentityCache = (ctx) => {
295
297
  };
296
298
  var memoKey = (roles, installed) => `${[...roles].sort().join("\0")}\0\0${installed === void 0 ? "*" : [...installed].sort().join("\0")}`;
297
299
  var NOBODY_USER_ID = "anonymous";
298
- var assignedRoles = (assignments, principal) => principal === null ? ["public"] : assignments?.[principal] ?? ["public"];
300
+ var assignedRoles = (assignments, principal) => principal === null || assignments === void 0 || !Object.hasOwn(assignments, principal) ? ["public"] : assignments[principal] ?? ["public"];
299
301
  var IdentityRecordSchema = zod.z.looseObject({
300
302
  roles: zod.z.array(zod.z.string()),
301
303
  scope: zod.z.record(zod.z.string(), zod.z.unknown()),
@@ -582,10 +584,10 @@ var canonical = (value) => {
582
584
  return `{${keys.map((key) => `${JSON.stringify(key)}:${canonical(Reflect.get(value, key))}`).join(",")}}`;
583
585
  };
584
586
  var isSeededAs = async (cache, entry) => {
585
- const held = await cache.get(entry.fingerprint);
586
- if (held === void 0 || held.protected !== true) return false;
587
- if ("mutation" in entry) return held.kind === "mutation" && canonical(held.mutation) === canonical(entry.mutation);
588
- return held.kind === "ok" && canonical(held.dsl) === canonical(entry.dsl);
587
+ const cached = await cache.get(entry.fingerprint);
588
+ if (cached === void 0 || cached.protected !== true) return false;
589
+ if ("mutation" in entry) return cached.kind === "mutation" && canonical(cached.mutation) === canonical(entry.mutation);
590
+ return cached.kind === "ok" && canonical(cached.dsl) === canonical(entry.dsl);
589
591
  };
590
592
  var changesBetween = (before, after) => {
591
593
  const removed = [];
@@ -625,7 +627,7 @@ var removalsRefused = (found) => [
625
627
  ...found.retyped.map((what) => `this run changes the type of ${what}`)
626
628
  ].map((sentence) => `${sentence} \u2014 nothing removed or retyped is applied unless it is allowed (\`allowRemoval\`; \`nisc migrate --allow-removal\`)`);
627
629
  var migrateTables = async (runtime, app, options = {}) => {
628
- const entries = chunk6ZWMC2OV_cjs.entriesOf(app);
630
+ const entries = chunk6ACVHHFK_cjs.entriesOf(app);
629
631
  const cache = runtime.cache ?? vex.createPostgresCache({ pool: runtime.pool });
630
632
  const before = await vex.createPostgresAdapter({ pool: runtime.pool }).introspect();
631
633
  const misfitsBefore = misfitsOf(entries, before);
@@ -682,8 +684,10 @@ var sweepUnused = async (pool, unusedMs) => {
682
684
  return { versions, saves };
683
685
  };
684
686
  var AGING_EVERY_MS = 36e5;
685
- var startAging = (pool, unusedMs, everyMs = AGING_EVERY_MS) => {
687
+ var startAging = (pool, unusedMs, { everyMs = AGING_EVERY_MS, sinceStart = false } = {}) => {
688
+ const startedAt = Date.now();
686
689
  const sweep2 = async () => {
690
+ if (sinceStart && Date.now() - startedAt < unusedMs) return;
687
691
  try {
688
692
  const swept = await sweepUnused(pool, unusedMs);
689
693
  if (swept.versions > 0) console.log(`[moss] aging: ${swept.versions} version(s) of what was generated and unused for ${unusedMs} ms deleted, and ${swept.saves} save(s) left empty`);
@@ -693,11 +697,12 @@ var startAging = (pool, unusedMs, everyMs = AGING_EVERY_MS) => {
693
697
  };
694
698
  void sweep2();
695
699
  const timer = setInterval(() => void sweep2(), everyMs);
700
+ timer.unref?.();
696
701
  return () => clearInterval(timer);
697
702
  };
698
703
  var isWrittenForRequest = (entry) => entry.kind === "unsatisfiable" || entry.requestHash !== void 0;
699
704
  var createEntryCache = (table) => {
700
- let held;
705
+ let askedFirst;
701
706
  const fromTable = (entry) => entry !== void 0 && isWrittenForRequest(entry) ? entry : void 0;
702
707
  const tableEntries = async () => {
703
708
  const rows = table.entries !== void 0 ? await table.entries() : await Promise.all((await table.keys()).map(async (key) => ({ key, entry: await table.get(key) })));
@@ -707,16 +712,16 @@ var createEntryCache = (table) => {
707
712
  });
708
713
  };
709
714
  const entries = async () => {
710
- const first = await held?.entries() ?? [];
715
+ const first = await askedFirst?.entries() ?? [];
711
716
  const answered = new Set(first.map((row) => row.key));
712
717
  return [...first, ...(await tableEntries()).filter((row) => !answered.has(row.key))];
713
718
  };
714
719
  return {
715
- askFirst: (holder) => {
716
- held = holder;
720
+ askFirst: (first) => {
721
+ askedFirst = first;
717
722
  },
718
723
  cache: {
719
- get: async (key, scope) => await held?.get(key, scope) ?? fromTable(await table.get(key)),
724
+ get: async (key, scope) => await askedFirst?.get(key, scope) ?? fromTable(await table.get(key)),
720
725
  // Vex stamps an entry it replays by writing it back: one that was not written for a request is not the table's to keep.
721
726
  set: async (key, entry) => {
722
727
  if (isWrittenForRequest(entry)) await table.set(key, entry);
@@ -733,7 +738,12 @@ var createDataLayer = async (deps) => {
733
738
  const table = deps.cache ?? vex.createPostgresCache({ pool: deps.pool });
734
739
  await table.init?.();
735
740
  const { cache, askFirst } = createEntryCache(table);
736
- const engine = vex.createQueryEngine({ adapter, cache, ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {} });
741
+ const engine = vex.createQueryEngine({
742
+ adapter,
743
+ cache,
744
+ ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {},
745
+ ...deps.upgradedColumns !== void 0 && deps.upgrader !== void 0 ? { upgradedColumns: deps.upgradedColumns, upgrader: deps.upgrader } : {}
746
+ });
737
747
  const schema = await engine.introspect();
738
748
  return { engine, adapter, schema, grants: vex.scopeGrants(schema.entities.map((e) => e.name)), askFirst };
739
749
  };
@@ -867,7 +877,7 @@ var createExecuteAs = (deps) => async (role, fingerprint, context, scope = {}) =
867
877
  locked: true,
868
878
  scopePolicy: policy,
869
879
  policyForReach: (reach) => deps.policyAtReach(roles, reach),
870
- mutations: { client: deps.db, policy },
880
+ mutations: { client: deps.db, policy, ...deps.checkMovedRows === false ? { checkMovedRows: false } : {} },
871
881
  ...deps.onExecute !== void 0 ? { onExecute: deps.onExecute } : {}
872
882
  },
873
883
  { fingerprint, context },
@@ -970,7 +980,12 @@ var createVexRoutes = (deps) => {
970
980
  getPolicy: deps.policy,
971
981
  getPolicyForReach: deps.policyAtReach,
972
982
  ...deps.onExecute !== void 0 ? { onExecute: deps.onExecute } : {},
973
- mutations: { client: deps.db, onWrite: deps.writes.report }
983
+ mutations: {
984
+ client: deps.db,
985
+ onWrite: deps.writes.report,
986
+ ...deps.answerReadableRows === true ? { answerReadableRows: true } : {},
987
+ ...deps.checkMovedRows === false ? { checkMovedRows: false } : {}
988
+ }
974
989
  })
975
990
  );
976
991
  };
@@ -993,7 +1008,8 @@ var createIntentAnswers = (deps) => {
993
1008
  generateDsl: writers.generateDsl,
994
1009
  mapToShape: writers.mapToShape,
995
1010
  ...deps.behaviors !== void 0 ? { behaviors: deps.behaviors } : {},
996
- ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {}
1011
+ ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {},
1012
+ ...deps.upgradedColumns !== void 0 && deps.upgrader !== void 0 ? { upgradedColumns: deps.upgradedColumns, upgrader: deps.upgrader } : {}
997
1013
  });
998
1014
  await engine.introspect();
999
1015
  return engine;
@@ -1003,7 +1019,7 @@ var createIntentAnswers = (deps) => {
1003
1019
  };
1004
1020
  return async (writers, asked, caller) => (await engineFor(writers)).execute(
1005
1021
  "fingerprint" in asked ? { fingerprint: asked.fingerprint, context: asked.context ?? {} } : { intent: asked.intent, shape: asked.shape, context: asked.context ?? {} },
1006
- { scope: caller.scope, scopePolicy: caller.policy }
1022
+ { scope: caller.scope, scopePolicy: caller.policy, ...caller.policyAtReach !== void 0 ? { policyForReach: caller.policyAtReach } : {} }
1007
1023
  );
1008
1024
  };
1009
1025
 
@@ -1020,7 +1036,7 @@ var prepareEngine = async (config) => {
1020
1036
  );
1021
1037
  });
1022
1038
  const grammars = await createGrammarUpgrader({ grammars: config.grammars });
1023
- const layer = await createDataLayer(config);
1039
+ const layer = await createDataLayer({ ...config, upgrader: grammars });
1024
1040
  return {
1025
1041
  grammars,
1026
1042
  engine: layer.engine,
@@ -1044,7 +1060,8 @@ var lazyIntentAnswers = (prepared, config) => {
1044
1060
  schema,
1045
1061
  cache: engine.cache,
1046
1062
  ...config.behaviors !== void 0 ? { behaviors: config.behaviors } : {},
1047
- ...config.vexConfig !== void 0 ? { vexConfig: config.vexConfig } : {}
1063
+ ...config.vexConfig !== void 0 ? { vexConfig: config.vexConfig } : {},
1064
+ ...config.upgradedColumns !== void 0 ? { upgradedColumns: config.upgradedColumns, upgrader: prepared.grammars } : {}
1048
1065
  });
1049
1066
  return answers;
1050
1067
  };
@@ -1055,6 +1072,20 @@ var tablesByFeature = (config) => (feature) => {
1055
1072
  if (kept === void 0) throw new Error(`moss: the data module was asked for the tables of a feature it was never told of ("${feature}").`);
1056
1073
  return kept.names;
1057
1074
  };
1075
+ var refuseUpgradedOwnedTables = (config) => {
1076
+ const owners = new Map([
1077
+ ...(config.featureTables ?? []).flatMap((tables) => tables.names.map((name) => [name, `the feature "${tables.feature}"`])),
1078
+ ...ARTIFACT_TABLES.map((name) => [name, "the artifactory"]),
1079
+ ...POINTER.tables.map((name) => [name, POINTER.owner])
1080
+ ]);
1081
+ const owned = Object.keys(config.upgradedColumns ?? {}).flatMap((table) => {
1082
+ const owner = owners.get(table);
1083
+ return owner === void 0 ? [] : [`"${table}" is ${owner}'s`];
1084
+ });
1085
+ if (owned.length > 0) {
1086
+ throw new Error(`moss: the app's \`upgradedColumns\` name tables it does not own (${owned.join("; ")}). Their owner reads them as stored: name only the app's own tables.`);
1087
+ }
1088
+ };
1058
1089
  var createUpgradeStore = (prepared, tablesOf) => async (feature, store) => {
1059
1090
  const own = tablesOf(feature);
1060
1091
  if (store.schema !== void 0) {
@@ -1068,10 +1099,11 @@ var createUpgradeStore = (prepared, tablesOf) => async (feature, store) => {
1068
1099
  await prepared.upgradeStore(store);
1069
1100
  };
1070
1101
  var createDataWith = (prepared, config) => {
1102
+ refuseUpgradedOwnedTables(config);
1071
1103
  const { grammars, engine, grants } = prepared;
1072
1104
  const governed = { charter: config.charter, behaviors: { ...config.behaviors, ...config.rowRules } };
1073
1105
  const policies = createPolicies({ ...governed, grants });
1074
- const emit = chunkPVZMCEBX_cjs.emitterOf(config.telemetry);
1106
+ const emit = chunk3CKBKTXA_cjs.emitterOf(config.telemetry);
1075
1107
  const onExecute = emit === void 0 ? void 0 : (record) => emit(vexRecordToSpan(record));
1076
1108
  const writes = createWriteNotifier();
1077
1109
  const answering = lazyIntentAnswers(prepared, config);
@@ -1085,7 +1117,7 @@ var createDataWith = (prepared, config) => {
1085
1117
  return {
1086
1118
  grants,
1087
1119
  grammars,
1088
- entriesHeldBy: prepared.askFirst,
1120
+ askEntriesFirst: prepared.askFirst,
1089
1121
  fingerprints: async () => await engine.cache.keys?.() ?? [],
1090
1122
  policyOf: policies.of,
1091
1123
  // Compiled afresh and not taken from the kept ones: the caller owns its
@@ -1101,9 +1133,10 @@ var createDataWith = (prepared, config) => {
1101
1133
  db: config.db,
1102
1134
  policyFor: (roles) => policies.of(callerOfRoles(roles)),
1103
1135
  policyAtReach: (roles, reach) => policies.atReach(callerOfRoles(roles), reach),
1104
- ...onExecute !== void 0 ? { onExecute } : {}
1136
+ ...onExecute !== void 0 ? { onExecute } : {},
1137
+ ...config.checkMovedRows === false ? { checkMovedRows: false } : {}
1105
1138
  }),
1106
- answerIntent: async (writers, asked, who, scope) => answering()(writers, asked, { policy: policies.of(who), scope }),
1139
+ answerIntent: async (writers, asked, who, scope) => answering()(writers, asked, { policy: policies.of(who), policyAtReach: (reach) => policies.atReach(who, reach), scope }),
1107
1140
  ownEntries: async (feature, entries) => ownEntries({ owner: `the feature "${feature}"`, entries, tables: tablesOf(feature) }, onExecute),
1108
1141
  artifactEntries: (entries, rules) => ownEntries({ owner: "the artifactory", entries, tables: ARTIFACT_TABLES, rules }, onExecute),
1109
1142
  routes: (routing) => createVexRoutes({
@@ -1114,7 +1147,9 @@ var createDataWith = (prepared, config) => {
1114
1147
  policy: (c) => policies.of(routing.caller(c)),
1115
1148
  policyAtReach: (c, reach) => policies.atReach(routing.caller(c), reach),
1116
1149
  ...onExecute !== void 0 ? { onExecute } : {},
1117
- writes
1150
+ writes,
1151
+ ...config.answerReadableRows === true ? { answerReadableRows: true } : {},
1152
+ ...config.checkMovedRows === false ? { checkMovedRows: false } : {}
1118
1153
  }),
1119
1154
  upgradeStore: createUpgradeStore(prepared, tablesOf),
1120
1155
  onWrite: writes.subscribe,
@@ -1130,10 +1165,10 @@ var embedSnapshot = (snapshot, principal, path) => {
1130
1165
  const { frame, trees, seed, live } = snapshot;
1131
1166
  const carried = { frame, trees, principal: principal !== null, live, ...seed !== void 0 ? { seed } : {}, ...path !== void 0 ? { path } : {} };
1132
1167
  const text = JSON.stringify(carried).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
1133
- return `<script type="application/json" id="${chunkNCQBGK3E_cjs.SNAPSHOT_ELEMENT_ID}">${text}</script>`;
1168
+ return `<script type="application/json" id="${chunkBFA76AKR_cjs.SNAPSHOT_ELEMENT_ID}">${text}</script>`;
1134
1169
  };
1135
1170
  var documentHeaders = (principal) => principal === null ? { "cache-control": "no-cache", vary: "Cookie" } : { "cache-control": "private, no-store", vary: "Cookie" };
1136
- var rootHolding = (root) => {
1171
+ var screenInRoot = (root) => {
1137
1172
  const closing = root.lastIndexOf("</");
1138
1173
  if (closing <= 0 || !root.startsWith("<") || root[closing - 1] !== ">" || !root.endsWith(">")) return void 0;
1139
1174
  return (screen) => `${root.slice(0, closing)}${screen}${root.slice(closing)}`;
@@ -1141,12 +1176,12 @@ var rootHolding = (root) => {
1141
1176
  var escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
1142
1177
  var renderDocument = async (config) => {
1143
1178
  const { server, template, request, draw } = config;
1144
- const tokenKey = config.tokenKey ?? chunkNCQBGK3E_cjs.DEFAULT_TOKEN_KEY;
1179
+ const tokenKey = config.tokenKey ?? chunkBFA76AKR_cjs.DEFAULT_TOKEN_KEY;
1145
1180
  const root = config.root ?? DEFAULT_ROOT;
1146
1181
  const undrawn = { html: template, headers: documentHeaders(null), drawn: false, principal: null };
1147
1182
  if (!template.includes(root)) return undrawn;
1148
- const holding = rootHolding(root);
1149
- if (holding === void 0) {
1183
+ const inRoot = screenInRoot(root);
1184
+ if (inRoot === void 0) {
1150
1185
  console.error(`[moss/document] the root ${root} has no place for a screen \u2014 a root is an empty element, like ${DEFAULT_ROOT}. "${request.path}" is served undrawn.`);
1151
1186
  return undrawn;
1152
1187
  }
@@ -1163,7 +1198,7 @@ var renderDocument = async (config) => {
1163
1198
  });
1164
1199
  const screen = await draw(snapshot);
1165
1200
  const attributes = Object.entries(config.htmlAttributes?.(snapshot) ?? {}).map(([name, value]) => ` ${name}="${escapeAttribute(value)}"`).join("");
1166
- const placed = template.replace(root, () => `${holding(screen)}${embedSnapshot(snapshot, principal, request.path)}`).replace(/<html([^>]*)>/, (whole, existing) => attributes === "" ? whole : `<html${existing}${attributes}>`);
1201
+ const placed = template.replace(root, () => `${inRoot(screen)}${embedSnapshot(snapshot, principal, request.path)}`).replace(/<html([^>]*)>/, (whole, existing) => attributes === "" ? whole : `<html${existing}${attributes}>`);
1167
1202
  const head = document.headOf({ frame: () => snapshot.frame, canvasTree: (id) => snapshot.trees[id] ?? [] });
1168
1203
  for (const why of head?.refused ?? []) console.error(`[moss/document] "${request.path}" \u2014 ${why}`);
1169
1204
  const html = document.placeHead(placed, head?.elements, { ...config.site !== void 0 ? { site: config.site } : {}, path: request.path });
@@ -1272,15 +1307,15 @@ var isKept = (layout) => layout !== void 0 && layout !== null && typeof layout !
1272
1307
  var shellWithStoredLayouts = (shell) => {
1273
1308
  const layouts = {};
1274
1309
  const frame = shell.layout;
1275
- if (isKept(frame)) layouts[chunk6ZWMC2OV_cjs.FRAME_LAYOUT_REF] = frame;
1310
+ if (isKept(frame)) layouts[chunk6ACVHHFK_cjs.FRAME_LAYOUT_REF] = frame;
1276
1311
  const canvases = shell.canvases.map((canvas) => {
1277
1312
  const layout = canvas.actionLayout;
1278
1313
  if (!isKept(layout)) return canvas;
1279
- const ref = chunk6ZWMC2OV_cjs.canvasLayoutRef(canvas.id);
1314
+ const ref = chunk6ACVHHFK_cjs.canvasLayoutRef(canvas.id);
1280
1315
  layouts[ref] = layout;
1281
1316
  return { ...canvas, actionLayout: ref };
1282
1317
  });
1283
- return { canvases, ...isKept(frame) ? { frame: chunk6ZWMC2OV_cjs.FRAME_LAYOUT_REF } : typeof frame === "string" ? { frame } : {}, layouts };
1318
+ return { canvases, ...isKept(frame) ? { frame: chunk6ACVHHFK_cjs.FRAME_LAYOUT_REF } : typeof frame === "string" ? { frame } : {}, layouts };
1284
1319
  };
1285
1320
  var slottedIn = /* @__PURE__ */ new WeakMap();
1286
1321
  var canvasesSlottedIn = (layout) => {
@@ -1331,22 +1366,22 @@ var createComponentNames = (read2) => {
1331
1366
  var SavedLayoutSchema = zod.z.strictObject({ ref: zod.z.string(), layout: nova.LayoutNodeSchema, use: zod.z.boolean().optional() });
1332
1367
  var upgradedLayoutBody = (upgrader, body, stamp) => reflect.isRecord(body) && body["layout"] !== void 0 ? { ...body, layout: upgrader.upgrade(body["layout"], { kind: "nisc.nova/layout", stamp }).document } : body;
1333
1368
  var actionAtRef = (actions, layouts) => (ref) => {
1334
- const id = chunk6ZWMC2OV_cjs.actionOfLayoutRef(ref);
1369
+ const id = chunk6ACVHHFK_cjs.actionOfLayoutRef(ref);
1335
1370
  const action = id !== void 0 && Object.hasOwn(actions, id) ? actions[id] : void 0;
1336
1371
  const layout = Object.hasOwn(layouts, ref) ? layouts[ref] : void 0;
1337
1372
  return action === void 0 || layout === void 0 ? void 0 : { ...action, layout };
1338
1373
  };
1339
1374
  var nothingKeptUnder = (ref) => `nothing is kept under "${ref}". A saved layout takes the place of the layout of an action its holder has, under "action/<the action\u2019s id>", or of one the app\u2019s own shell declares: its own under "frame", a canvas\u2019s under "canvas/<the canvas\u2019s id>".`;
1340
- var targetAt = (ref, heldTo) => {
1341
- if (heldTo.ownShell?.refs.has(ref) === true) return { kit: heldTo.ownShell.kit };
1342
- const action = heldTo.actionAt(ref);
1343
- return action === void 0 ? void 0 : { kit: heldTo.kit, action };
1375
+ var targetAt = (ref, checks) => {
1376
+ if (checks.ownShell?.refs.has(ref) === true) return { kit: checks.ownShell.kit };
1377
+ const action = checks.actionAt(ref);
1378
+ return action === void 0 ? void 0 : { kit: checks.kit, action };
1344
1379
  };
1345
1380
  var refOf = (body) => {
1346
1381
  const ref = reflect.isRecord(body) ? body["ref"] : void 0;
1347
1382
  return typeof ref === "string" ? ref : void 0;
1348
1383
  };
1349
- var readLayout = (body, heldTo) => {
1384
+ var readLayout = (body, checks) => {
1350
1385
  if (strata.exceedsDepth(body)) return { refusal: strata.depthRefusal() };
1351
1386
  const parsed = SavedLayoutSchema.safeParse(body);
1352
1387
  if (!parsed.success) {
@@ -1354,11 +1389,11 @@ var readLayout = (body, heldTo) => {
1354
1389
  return { refusal: first === void 0 ? "no reason given" : `${first.path.join(".") || "(the body)"}: ${first.message}` };
1355
1390
  }
1356
1391
  const { ref, layout } = parsed.data;
1357
- const target = targetAt(ref, heldTo);
1392
+ const target = targetAt(ref, checks);
1358
1393
  if (target === void 0) return { refusal: nothingKeptUnder(ref) };
1359
- const misfits = chunk6ZWMC2OV_cjs.layoutMisfits(layout, target.kit);
1394
+ const misfits = chunk6ACVHHFK_cjs.layoutMisfits(layout, target.kit);
1360
1395
  if (misfits.length > 0) return { refusal: misfits.join("; ") };
1361
- const named = chunk6ZWMC2OV_cjs.layoutNameRefusal(layout);
1396
+ const named = chunk6ACVHHFK_cjs.layoutNameRefusal(layout);
1362
1397
  if (named !== void 0) return { refusal: `it ${named}` };
1363
1398
  const { action } = target;
1364
1399
  if (action === void 0) return { layout: parsed.data };
@@ -1367,10 +1402,10 @@ var readLayout = (body, heldTo) => {
1367
1402
  if (added.length > 0) return { refusal: added.join("; ") };
1368
1403
  return { layout: parsed.data };
1369
1404
  };
1370
- var loaded = (version, { whose, heldTo, say }) => {
1405
+ var loaded = (version, { whose, checks, say }) => {
1371
1406
  const ref = refOf(version.body);
1372
- if (ref === void 0 || targetAt(ref, heldTo) === void 0) return void 0;
1373
- const read2 = version.unread !== void 0 ? { refusal: version.unread } : readLayout(version.body, heldTo);
1407
+ if (ref === void 0 || targetAt(ref, checks) === void 0) return void 0;
1408
+ const read2 = version.unread !== void 0 ? { refusal: version.unread } : readLayout(version.body, checks);
1374
1409
  if ("layout" in read2) return read2.layout;
1375
1410
  (say ?? console.error)(`[moss] the layout "${version.id}" ${whose} is left out: ${read2.refusal}`);
1376
1411
  return void 0;
@@ -1382,8 +1417,8 @@ var layoutsInUse = (inForce2, drawnFor) => {
1382
1417
  for (const version of inForce2.filter(isInUse)) {
1383
1418
  const ref = refOf(version.body);
1384
1419
  if (ref === void 0) continue;
1385
- const held = marked.get(ref);
1386
- if (held === void 0 || isLater(version, held)) marked.set(ref, version);
1420
+ const latest = marked.get(ref);
1421
+ if (latest === void 0 || isLater(version, latest)) marked.set(ref, version);
1387
1422
  }
1388
1423
  const layouts = {};
1389
1424
  for (const version of marked.values()) {
@@ -1392,14 +1427,14 @@ var layoutsInUse = (inForce2, drawnFor) => {
1392
1427
  }
1393
1428
  return layouts;
1394
1429
  };
1395
- var generatedId = () => `${chunk6ZWMC2OV_cjs.GENERATED_ID_PREFIX}${crypto$1.randomUUID()}`;
1430
+ var generatedId = () => `${chunk6ACVHHFK_cjs.GENERATED_ID_PREFIX}${crypto$1.randomUUID()}`;
1396
1431
  var VEX_ROUTE = /^\/api\/(?:[A-Za-z0-9_-]+\/)?vex$/;
1397
- var endpointRefusals = async (endpoints, heldTo) => {
1432
+ var endpointRefusals = async (endpoints, checks) => {
1398
1433
  const refusals = [];
1399
1434
  for (const [name, endpoint] of Object.entries(endpoints ?? {})) {
1400
1435
  if ("fn" in endpoint) {
1401
1436
  if (endpoint.fn.includes("{{")) refusals.push(`endpoint "${name}" names a function that is worked out when it is called, and what is generated names one written out`);
1402
- else if (!heldTo.mayCall(endpoint.fn)) refusals.push(`endpoint "${name}" calls the function "${endpoint.fn}", which its owner\u2019s roles do not grant`);
1437
+ else if (!checks.mayCall(endpoint.fn)) refusals.push(`endpoint "${name}" calls the function "${endpoint.fn}", which its owner\u2019s roles do not grant`);
1403
1438
  continue;
1404
1439
  }
1405
1440
  if (endpoint.method !== "POST" || !VEX_ROUTE.test(endpoint.url)) {
@@ -1411,10 +1446,10 @@ var endpointRefusals = async (endpoints, heldTo) => {
1411
1446
  refusals.push(`endpoint "${name}" names no fingerprint`);
1412
1447
  continue;
1413
1448
  }
1414
- const entry = heldTo.entryOf(fingerprint);
1449
+ const entry = checks.entryOf(fingerprint);
1415
1450
  if (entry === void 0) refusals.push(`endpoint "${name}" replays "${fingerprint}", which is no entry the app ships or was handed, nor a read its owner saved`);
1416
1451
  else if ("mutation" in entry) refusals.push(`endpoint "${name}" replays "${fingerprint}", which is a write, and what is generated only reads`);
1417
- else if (!(await heldTo.replayable()).has(fingerprint)) refusals.push(`endpoint "${name}" replays "${fingerprint}", which its owner may not replay`);
1452
+ else if (!(await checks.replayable()).has(fingerprint)) refusals.push(`endpoint "${name}" replays "${fingerprint}", which its owner may not replay`);
1418
1453
  }
1419
1454
  return refusals;
1420
1455
  };
@@ -1429,33 +1464,33 @@ var parsedUnder = (schema, body, id, more = {}) => {
1429
1464
  return { refusal: first === void 0 ? "no reason given" : `${first.path.join(".") || "(the body)"}: ${first.message}` };
1430
1465
  };
1431
1466
  var layoutRefusals = (layout, kit) => {
1432
- const named = chunk6ZWMC2OV_cjs.layoutNameRefusal(layout);
1433
- return [...layout === void 0 || typeof layout === "string" ? [] : chunk6ZWMC2OV_cjs.layoutMisfits(layout, kit), ...named === void 0 ? [] : [`it ${named}`]];
1467
+ const named = chunk6ACVHHFK_cjs.layoutNameRefusal(layout);
1468
+ return [...layout === void 0 || typeof layout === "string" ? [] : chunk6ACVHHFK_cjs.layoutMisfits(layout, kit), ...named === void 0 ? [] : [`it ${named}`]];
1434
1469
  };
1435
1470
  var passedOrRefused = (body, refusals) => refusals.length > 0 ? { refusal: refusals.join("; ") } : { body };
1436
- var readAction = async (body, id, heldTo) => {
1471
+ var readAction = async (body, id, checks) => {
1437
1472
  const parsed = parsedUnder(nova.ActionDefinitionSchema, body, id);
1438
1473
  if ("refusal" in parsed) return parsed;
1439
1474
  const action = parsed.body;
1440
1475
  return passedOrRefused(action, [
1441
- ...layoutRefusals(action.layout, heldTo.kit),
1442
- ...await endpointRefusals(action.endpoints, heldTo),
1443
- ...nova.auditAction(action, { catalog: heldTo.catalog() }).issues
1476
+ ...layoutRefusals(action.layout, checks.kit),
1477
+ ...await endpointRefusals(action.endpoints, checks),
1478
+ ...nova.auditAction(action, { catalog: checks.catalog() }).issues
1444
1479
  ]);
1445
1480
  };
1446
- var readFragment = async (body, id, heldTo) => {
1481
+ var readFragment = async (body, id, checks) => {
1447
1482
  const parsed = parsedUnder(nova.ActionFragmentSchema, body, id, { kind: "fragment" });
1448
1483
  if ("refusal" in parsed) return parsed;
1449
1484
  const fragment = parsed.body;
1450
- return passedOrRefused(fragment, [...layoutRefusals(fragment.layout, heldTo.kit), ...await endpointRefusals(fragment.endpoints, heldTo)]);
1485
+ return passedOrRefused(fragment, [...layoutRefusals(fragment.layout, checks.kit), ...await endpointRefusals(fragment.endpoints, checks)]);
1451
1486
  };
1452
1487
  var generatedIn = (inForce2, kind) => inForce2.filter((version) => version.kind === kind && version.body !== null);
1453
1488
  var catalogOfGenerated = (inForce2) => generatedIn(inForce2, "action").map((version) => ({ id: version.id, input: reflect.isRecord(version.body) && reflect.isRecord(version.body["input"]) ? version.body["input"] : {} }));
1454
- var generatedInForce = async (inForce2, heldTo, whose) => {
1489
+ var generatedInForce = async (inForce2, checks, whose) => {
1455
1490
  const passed = async (kind, read2) => {
1456
1491
  const kept = {};
1457
1492
  for (const version of generatedIn(inForce2, kind)) {
1458
- const answered = version.unread !== void 0 ? { refusal: version.unread } : await read2(version.body, version.id, heldTo);
1493
+ const answered = version.unread !== void 0 ? { refusal: version.unread } : await read2(version.body, version.id, checks);
1459
1494
  if ("body" in answered) kept[version.id] = answered.body;
1460
1495
  else if (whose !== void 0) console.error(`[moss] the ${kind} "${version.id}" ${whose} is left out: ${answered.refusal}`);
1461
1496
  }
@@ -1463,6 +1498,19 @@ var generatedInForce = async (inForce2, heldTo, whose) => {
1463
1498
  };
1464
1499
  return { actions: await passed("action", readAction), fragments: await passed("fragment", readFragment) };
1465
1500
  };
1501
+ var refuseUnrunnable = (entries, compile2, heading) => {
1502
+ if (compile2 === void 0) return;
1503
+ const unrunnable = entries.flatMap((entry) => {
1504
+ if (!("dsl" in entry)) return [];
1505
+ try {
1506
+ compile2(entry.dsl);
1507
+ return [];
1508
+ } catch (error) {
1509
+ return [` "${entry.fingerprint}": ${error instanceof Error ? error.message : String(error)}`];
1510
+ }
1511
+ });
1512
+ if (unrunnable.length > 0) throw new Error([heading, ...unrunnable].join("\n"));
1513
+ };
1466
1514
  var compileEntries = async (entries) => {
1467
1515
  const compiled = vex.createMemoryCache();
1468
1516
  await vex.seedCache(compiled, entries);
@@ -1473,7 +1521,8 @@ var mergedEntries = (own, sets) => {
1473
1521
  for (const entry of [...own, ...[...sets.values()].flat()]) byFingerprint.set(entry.fingerprint, entry);
1474
1522
  return Object.freeze([...byFingerprint.values()]);
1475
1523
  };
1476
- var createEntriesInForce = (own) => {
1524
+ var createEntriesInForce = (own, compileRead) => {
1525
+ refuseUnrunnable(own, compileRead, "Seeded reads that do not run \u2014 refusing to serve:");
1477
1526
  let sets = /* @__PURE__ */ new Map();
1478
1527
  let list = mergedEntries(own, sets);
1479
1528
  let byFingerprint = new Map(list.map((entry) => [entry.fingerprint, entry]));
@@ -1483,9 +1532,10 @@ var createEntriesInForce = (own) => {
1483
1532
  return {
1484
1533
  list: () => list,
1485
1534
  byFingerprint: () => byFingerprint,
1486
- holdsSet: (source) => sets.has(source),
1535
+ hasSet: (source) => sets.has(source),
1487
1536
  withSet: (source, handed) => mergedEntries(own, new Map([...sets, [source, handed]])),
1488
1537
  takeSet: (source, handed, taken) => {
1538
+ refuseUnrunnable(handed, compileRead, "Refresh refused \u2014 seeded reads that do not run:");
1489
1539
  sets = new Map([...sets, [source, handed]]);
1490
1540
  list = mergedEntries(own, sets);
1491
1541
  byFingerprint = new Map(list.map((entry) => [entry.fingerprint, entry]));
@@ -1513,8 +1563,8 @@ var compiledRead = async (fingerprint, read2) => {
1513
1563
  return entry;
1514
1564
  };
1515
1565
  var shippedRefusal = (fingerprint) => `"${fingerprint}" is the fingerprint of an entry the app ships or was handed, and a read somebody generated never answers in its place`;
1516
- var readSaved = async (body, fingerprint, heldTo) => {
1517
- if (heldTo.isAppEntry(fingerprint)) return { refusal: shippedRefusal(fingerprint) };
1566
+ var readSaved = async (body, fingerprint, checks) => {
1567
+ if (checks.isAppEntry(fingerprint)) return { refusal: shippedRefusal(fingerprint) };
1518
1568
  if (strata.exceedsDepth(body)) return { refusal: strata.depthRefusal() };
1519
1569
  const parsed = SavedReadSchema.safeParse(body);
1520
1570
  if (!parsed.success) {
@@ -1522,16 +1572,16 @@ var readSaved = async (body, fingerprint, heldTo) => {
1522
1572
  return { refusal: first === void 0 ? "no reason given" : `${first.path.join(".") || "(the body)"}: ${first.message}` };
1523
1573
  }
1524
1574
  try {
1525
- heldTo.sources.compile(parsed.data.dsl);
1575
+ checks.sources.compile(parsed.data.dsl);
1526
1576
  await compiledRead(fingerprint, parsed.data);
1527
1577
  } catch (error) {
1528
1578
  return { refusal: sentenceOf(error) };
1529
1579
  }
1530
1580
  return { body: parsed.data };
1531
1581
  };
1532
- var readWritten = async (fingerprint, heldTo) => {
1533
- if (heldTo.isAppEntry(fingerprint)) return { refusal: shippedRefusal(fingerprint) };
1534
- const entry = await heldTo.sources.written(fingerprint);
1582
+ var readWritten = async (fingerprint, checks) => {
1583
+ if (checks.isAppEntry(fingerprint)) return { refusal: shippedRefusal(fingerprint) };
1584
+ const entry = await checks.sources.written(fingerprint);
1535
1585
  if (entry === void 0 || entry.requestHash === void 0) return { refusal: `vex holds no query it wrote under "${fingerprint}"` };
1536
1586
  if (entry.kind !== "ok") return { refusal: `vex found no query to answer under "${fingerprint}"` };
1537
1587
  if (entry.shape !== void 0 && entry.mapping === void 0) {
@@ -1547,7 +1597,7 @@ var readWritten = async (fingerprint, heldTo) => {
1547
1597
  ...entry.refresh !== void 0 ? { refresh: entry.refresh } : {}
1548
1598
  },
1549
1599
  fingerprint,
1550
- heldTo
1600
+ checks
1551
1601
  );
1552
1602
  };
1553
1603
  var answeredRead = async (fingerprint, body) => {
@@ -1555,11 +1605,11 @@ var answeredRead = async (fingerprint, body) => {
1555
1605
  const parsed = SavedReadSchema.safeParse(body);
1556
1606
  return parsed.success ? compiledRead(fingerprint, parsed.data) : void 0;
1557
1607
  };
1558
- var readsInForce = async (inForce2, heldTo, whose) => {
1608
+ var readsInForce = async (inForce2, checks, whose) => {
1559
1609
  const reads = /* @__PURE__ */ new Map();
1560
1610
  for (const version of inForce2) {
1561
1611
  if (version.kind !== "read" || version.body === null) continue;
1562
- const read2 = version.unread !== void 0 ? { refusal: version.unread } : await readSaved(version.body, version.id, heldTo);
1612
+ const read2 = version.unread !== void 0 ? { refusal: version.unread } : await readSaved(version.body, version.id, checks);
1563
1613
  if ("body" in read2) reads.set(version.id, read2.body);
1564
1614
  else if (whose !== void 0) console.error(`[moss] the read "${version.id}" ${whose} is left out: ${read2.refusal}`);
1565
1615
  }
@@ -1586,18 +1636,18 @@ var listed = (version, kind) => ({
1586
1636
  body: version.body
1587
1637
  });
1588
1638
  var withoutMark = ({ use: _mark, ...layout }) => layout;
1589
- var checked = async (kind, id, body, heldTo) => {
1639
+ var checked = async (kind, id, body, checks) => {
1590
1640
  if (kind === "layout") {
1591
- const read3 = readLayout(body, heldTo.layouts);
1641
+ const read3 = readLayout(body, checks.layouts);
1592
1642
  if ("refusal" in read3) throw new Error(`moss: the layout for "${refOf(body) ?? "(no ref)"}" is refused: ${read3.refusal}`);
1593
1643
  return read3.layout;
1594
1644
  }
1595
1645
  if (kind === "read") {
1596
- const read3 = heldTo.reads === void 0 ? { refusal: "no read is saved here" } : body === void 0 ? await readWritten(id, heldTo.reads) : await readSaved(body, id, heldTo.reads);
1646
+ const read3 = checks.reads === void 0 ? { refusal: "no read is saved here" } : body === void 0 ? await readWritten(id, checks.reads) : await readSaved(body, id, checks.reads);
1597
1647
  if ("refusal" in read3) throw new Error(`moss: the read "${id}" is refused: ${read3.refusal}`);
1598
1648
  return read3.body;
1599
1649
  }
1600
- const read2 = await (kind === "action" ? readAction : readFragment)(body, id, heldTo.generated);
1650
+ const read2 = await (kind === "action" ? readAction : readFragment)(body, id, checks.generated);
1601
1651
  if ("refusal" in read2) throw new Error(`moss: the ${kind} is refused: ${read2.refusal}`);
1602
1652
  return read2.body;
1603
1653
  };
@@ -1614,19 +1664,19 @@ var unmarked = (versions, inForce2) => {
1614
1664
  const layouts = versions.filter((version) => version.kind === "layout");
1615
1665
  const marked = markedRefs(layouts);
1616
1666
  const saved = new Set(layouts.map((version) => version.id));
1617
- const takenOut = inForce2.flatMap((held) => isInUse(held) && saved.has(held.id) ? [refOf(held.body)] : []);
1667
+ const takenOut = inForce2.flatMap((version) => isInUse(version) && saved.has(version.id) ? [refOf(version.body)] : []);
1618
1668
  const decided = /* @__PURE__ */ new Set([...marked, ...takenOut]);
1619
- return inForce2.flatMap((held) => {
1620
- const ref = refOf(held.body);
1621
- if (!isInUse(held) || held.unread !== void 0 || !reflect.isRecord(held.body) || ref === void 0 || !decided.has(ref) || saved.has(held.id)) return [];
1622
- return [{ kind: "layout", id: held.id, body: withoutMark(held.body), copiedFrom: held.save }];
1669
+ return inForce2.flatMap((version) => {
1670
+ const ref = refOf(version.body);
1671
+ if (!isInUse(version) || version.unread !== void 0 || !reflect.isRecord(version.body) || ref === void 0 || !decided.has(ref) || saved.has(version.id)) return [];
1672
+ return [{ kind: "layout", id: version.id, body: withoutMark(version.body), copiedFrom: version.save }];
1623
1673
  });
1624
1674
  };
1625
1675
  var idsOf = (versions) => versions.map(({ kind, id }) => ({ kind, id }));
1626
- var savingFor = ({ holder, whose, kinds, written, defaults }, nobody) => {
1627
- const requireHolder = () => {
1628
- if (holder === void 0) throw new Error(nobody);
1629
- return holder;
1676
+ var savingFor = ({ owner, whose, kinds, written, defaults }, nobody) => {
1677
+ const requireOwner = () => {
1678
+ if (owner === void 0) throw new Error(nobody);
1679
+ return owner;
1630
1680
  };
1631
1681
  const ofKind = (kind) => {
1632
1682
  const known = kinds.find((one) => one === kind);
@@ -1638,13 +1688,13 @@ var savingFor = ({ holder, whose, kinds, written, defaults }, nobody) => {
1638
1688
  if (!asked.success) throw new Error("moss: a save holds one or several artifacts, each `{ kind, id?, body }` and nothing else.");
1639
1689
  return asked.data.map((artifact) => ({ ...artifact, kind: ofKind(artifact.kind) }));
1640
1690
  };
1641
- const checkedEach = async (asked, inForce2, held) => {
1691
+ const checkedEach = async (asked, inForce2, checks) => {
1642
1692
  const versions = [];
1643
1693
  for (const { kind, id: named2, body } of asked) {
1644
1694
  if (defaults !== void 0 && named2 === void 0 && kind !== "layout" && kind !== "read") throw new Error(`moss: a published ${kind} is given its id by whoever publishes it: name it.`);
1645
1695
  const id = named2 ?? NEW_ID[kind]();
1646
1696
  if (kind === "read" && body !== void 0) throw new Error(`moss: the read "${id}" is refused: it is what vex wrote for the request. Leave the body out.`);
1647
- versions.push({ kind, id, body: await checked(kind, id, body, held), copiedFrom: null });
1697
+ versions.push({ kind, id, body: await checked(kind, id, body, checks), copiedFrom: null });
1648
1698
  }
1649
1699
  const named = (kind) => kind !== "read" && (defaults === void 0 || kind === "layout");
1650
1700
  const notTheirs = asked.find(({ kind, id }) => id !== void 0 && named(kind) && !inForce2.some((version) => version.kind === kind && version.id === id));
@@ -1661,25 +1711,25 @@ var savingFor = ({ holder, whose, kinds, written, defaults }, nobody) => {
1661
1711
  written();
1662
1712
  return save2;
1663
1713
  };
1664
- return { requireHolder, ofKind, askedOf, checkedEach, write };
1714
+ return { requireOwner, ofKind, askedOf, checkedEach, write };
1665
1715
  };
1666
1716
  var savedArtifacts = (deps) => {
1667
- const { holder, whose, kinds, defaults } = deps;
1668
- const { requireHolder, ofKind, askedOf, checkedEach, write } = savingFor(deps, "moss: nobody is signed in to this session, and a save is somebody\u2019s.");
1717
+ const { owner, whose, kinds, defaults } = deps;
1718
+ const { requireOwner, ofKind, askedOf, checkedEach, write } = savingFor(deps, "moss: nobody is signed in to this session, and a save is somebody\u2019s.");
1669
1719
  return {
1670
1720
  save: async (artifacts) => {
1671
- const holderOf = requireHolder();
1721
+ const ownerOf = requireOwner();
1672
1722
  const asked = askedOf(artifacts);
1673
- const { saved, heldTo } = await holderOf();
1723
+ const { saved, checks } = await ownerOf();
1674
1724
  const inForce2 = await saved.inForce();
1675
- const versions = await checkedEach(asked, inForce2, await heldTo(inForce2));
1725
+ const versions = await checkedEach(asked, inForce2, await checks(inForce2));
1676
1726
  await defaults?.verify(versions, inForce2);
1677
1727
  return { save: await write(saved, versions, inForce2), artifacts: idsOf(versions) };
1678
1728
  },
1679
1729
  list: async (kind) => {
1680
1730
  const only = kind === void 0 ? void 0 : ofKind(kind);
1681
- if (holder === void 0) return [];
1682
- const inForce2 = await (await holder()).saved.inForce();
1731
+ if (owner === void 0) return [];
1732
+ const inForce2 = await (await owner()).saved.inForce();
1683
1733
  return inForce2.flatMap((version) => {
1684
1734
  const known = kinds.find((one) => one === version.kind);
1685
1735
  return version.body !== null && known !== void 0 && (only === void 0 || known === only) ? [listed(version, known)] : [];
@@ -1687,26 +1737,26 @@ var savedArtifacts = (deps) => {
1687
1737
  },
1688
1738
  history: async (kind, id) => {
1689
1739
  const known = ofKind(kind);
1690
- if (holder === void 0) return [];
1691
- return (await (await holder()).saved.history(known, id)).map((version) => listed(version, known));
1740
+ if (owner === void 0) return [];
1741
+ return (await (await owner()).saved.history(known, id)).map((version) => listed(version, known));
1692
1742
  },
1693
1743
  restore: async (kind, id, save2) => {
1694
- const holderOf = requireHolder();
1744
+ const ownerOf = requireOwner();
1695
1745
  const known = ofKind(kind);
1696
- const { saved, heldTo } = await holderOf();
1746
+ const { saved, checks } = await ownerOf();
1697
1747
  const version = SaveIdSchema.safeParse(save2).success ? (await saved.history(known, id, save2))[0] : void 0;
1698
1748
  if (version === void 0) throw new Error(`moss: no ${known} "${id}" ${whose} was saved in "${save2}".`);
1699
1749
  if (version.unread !== void 0) throw new Error(`moss: the ${known} "${id}" saved in "${save2}" cannot be read: ${version.unread}`);
1700
1750
  const inForce2 = await saved.inForce();
1701
- const body = version.body === null ? null : await checked(known, id, version.body, await heldTo(inForce2));
1751
+ const body = version.body === null ? null : await checked(known, id, version.body, await checks(inForce2));
1702
1752
  const restored = { kind: known, id, body, copiedFrom: version.save };
1703
1753
  await defaults?.verify([restored], inForce2);
1704
1754
  return { save: await write(saved, [restored], inForce2) };
1705
1755
  },
1706
1756
  reset: async (kind, id) => {
1707
- const holderOf = requireHolder();
1757
+ const ownerOf = requireOwner();
1708
1758
  const known = ofKind(kind);
1709
- const { saved } = await holderOf();
1759
+ const { saved } = await ownerOf();
1710
1760
  const inForce2 = await saved.inForce();
1711
1761
  if (!inForce2.some((version) => version.kind === known && version.id === id && version.body !== null)) throw new Error(`moss: no ${known} "${id}" ${whose} is in force.`);
1712
1762
  return { save: await write(saved, [{ kind: known, id, body: null, copiedFrom: null }], inForce2) };
@@ -1721,15 +1771,15 @@ var laidOver = (inForce2, drafted = []) => drafted.length === 0 ? inForce2 : [
1721
1771
  ...drafted.map((one) => ({ ...one, save: "draft", copiedFrom: null, createdAt: LATER_THAN_ANY_SAVE }))
1722
1772
  ];
1723
1773
  var draftSaving = (deps) => {
1724
- const { requireHolder, ofKind, askedOf, checkedEach, write } = savingFor(deps, "moss: nobody is signed in to this session, and a draft is somebody\u2019s to save.");
1774
+ const { requireOwner, ofKind, askedOf, checkedEach, write } = savingFor(deps, "moss: nobody is signed in to this session, and a draft is somebody\u2019s to save.");
1725
1775
  return {
1726
- // The draft with these added to it. Each is checked beside what is in force for its holder with the draft laid over.
1776
+ // The draft with these added to it. Each is checked beside what is in force for its owner with the draft laid over.
1727
1777
  add: async (artifacts, drafted) => {
1728
- const holderOf = requireHolder();
1778
+ const ownerOf = requireOwner();
1729
1779
  const asked = askedOf(artifacts);
1730
- const { saved, heldTo } = await holderOf();
1780
+ const { saved, checks } = await ownerOf();
1731
1781
  const inForce2 = laidOver(await saved.inForce(), drafted);
1732
- const versions = await checkedEach(asked, inForce2, await heldTo(inForce2));
1782
+ const versions = await checkedEach(asked, inForce2, await checks(inForce2));
1733
1783
  const added = versions.map(({ kind, id, body }) => ({ kind, id, body }));
1734
1784
  const marked = new Set(markedRefs(added));
1735
1785
  const kept = drafted.flatMap((one) => {
@@ -1741,15 +1791,15 @@ var draftSaving = (deps) => {
1741
1791
  return { drafted: [...kept, ...added], added: idsOf(versions) };
1742
1792
  },
1743
1793
  save: async (drafted) => {
1744
- const holderOf = requireHolder();
1794
+ const ownerOf = requireOwner();
1745
1795
  if (drafted.length === 0) throw new Error("moss: the draft holds nothing to save.");
1746
- const { saved, heldTo } = await holderOf();
1796
+ const { saved, checks } = await ownerOf();
1747
1797
  const inForce2 = await saved.inForce();
1748
- const held = await heldTo(laidOver(inForce2, drafted));
1798
+ const laidOverChecks = await checks(laidOver(inForce2, drafted));
1749
1799
  const versions = [];
1750
1800
  for (const one of drafted) {
1751
1801
  const kind = ofKind(one.kind);
1752
- versions.push({ kind, id: one.id, body: await checked(kind, one.id, one.body, held), copiedFrom: null });
1802
+ versions.push({ kind, id: one.id, body: await checked(kind, one.id, one.body, laidOverChecks), copiedFrom: null });
1753
1803
  }
1754
1804
  return { save: await write(saved, versions, inForce2), artifacts: idsOf(versions) };
1755
1805
  }
@@ -1832,7 +1882,7 @@ var createGeneration = (pointer, ctx) => {
1832
1882
  var NO_DEFAULTS = { actions: {}, fragments: {}, reads: /* @__PURE__ */ new Map() };
1833
1883
  var drawableIn = (fragments, kit, say) => Object.fromEntries(
1834
1884
  Object.entries(fragments).filter(([id, fragment]) => {
1835
- const misfits = chunk6ZWMC2OV_cjs.layoutMisfits(fragment.layout, kit);
1885
+ const misfits = chunk6ACVHHFK_cjs.layoutMisfits(fragment.layout, kit);
1836
1886
  if (misfits.length > 0) say(`[moss] the fragment "${id}" published for everybody is left out of a shell that cannot draw it: ${misfits.join("; ")}`);
1837
1887
  return misfits.length === 0;
1838
1888
  })
@@ -1841,7 +1891,7 @@ var createPublishedMemo = () => {
1841
1891
  let read2;
1842
1892
  let said = /* @__PURE__ */ new Set();
1843
1893
  return {
1844
- held: () => read2,
1894
+ current: () => read2,
1845
1895
  keep: (promise) => {
1846
1896
  read2 = promise;
1847
1897
  },
@@ -1857,20 +1907,20 @@ var createPublishedMemo = () => {
1857
1907
  };
1858
1908
  };
1859
1909
  var hasDefaults = (defaults) => Object.keys(defaults.actions).length > 0 || Object.keys(defaults.fragments).length > 0 || defaults.reads.size > 0;
1860
- var checkedDefaults = async (versions, heldTo, whose) => {
1861
- const reads = heldTo.reads === void 0 ? /* @__PURE__ */ new Map() : await readsInForce(versions, heldTo.reads, whose);
1910
+ var checkedDefaults = async (versions, defaults, whose) => {
1911
+ const reads = defaults.reads === void 0 ? /* @__PURE__ */ new Map() : await readsInForce(versions, defaults.reads, whose);
1862
1912
  const checks = {
1863
- kit: heldTo.kit,
1913
+ kit: defaults.kit,
1864
1914
  entryOf: (fingerprint) => {
1865
1915
  const read2 = reads.get(fingerprint);
1866
- return heldTo.entryOf(fingerprint) ?? (read2 === void 0 ? void 0 : seedOf(fingerprint, read2));
1916
+ return defaults.entryOf(fingerprint) ?? (read2 === void 0 ? void 0 : seedOf(fingerprint, read2));
1867
1917
  },
1868
- replayable: async () => /* @__PURE__ */ new Set([...heldTo.fingerprints(), ...reads.keys()]),
1918
+ replayable: async () => /* @__PURE__ */ new Set([...defaults.fingerprints(), ...reads.keys()]),
1869
1919
  mayCall: () => true,
1870
- catalog: () => [...Object.values(heldTo.built).map((action) => ({ id: action.id, input: action.input ?? {} })), ...catalogOfGenerated(versions)]
1920
+ catalog: () => [...Object.values(defaults.built).map((action) => ({ id: action.id, input: action.input ?? {} })), ...catalogOfGenerated(versions)]
1871
1921
  };
1872
1922
  const passed = await generatedInForce(versions, checks, whose);
1873
- return { passed, reads, verified: chunk6ZWMC2OV_cjs.verifyManifest(heldTo.candidate({ ...heldTo.built, ...passed.actions }, passed.fragments)) };
1923
+ return { passed, reads, verified: chunk6ACVHHFK_cjs.verifyManifest(defaults.candidate({ ...defaults.built, ...passed.actions }, passed.fragments)) };
1874
1924
  };
1875
1925
  var narrowedBy = (filter, ids, installed) => {
1876
1926
  const answered = new Set(filter(ids, installed));
@@ -1883,9 +1933,9 @@ var catalogFor = (app, roles, installed, installedOnly) => {
1883
1933
  };
1884
1934
  var resolveVariantsForRoles = (app, roles) => {
1885
1935
  const variants = app.layouts ?? {};
1886
- return chunk6ZWMC2OV_cjs.variantLayouts(variants, charter.resolvePrincipal(app.charter, Object.keys(variants), roles, "layouts"));
1936
+ return chunk6ACVHHFK_cjs.variantLayouts(variants, charter.resolvePrincipal(app.charter, Object.keys(variants), roles, "layouts"));
1887
1937
  };
1888
- var definitionsFor = (actions, ids, variants) => Object.freeze(Object.fromEntries(chunk6ZWMC2OV_cjs.withVariants(actions, ids, variants)));
1938
+ var definitionsFor = (actions, ids, variants) => Object.freeze(Object.fromEntries(chunk6ACVHHFK_cjs.withVariants(actions, ids, variants)));
1889
1939
  var actionsWithStoredLayouts = (definitions) => {
1890
1940
  const actions = {};
1891
1941
  const layouts = {};
@@ -1895,7 +1945,7 @@ var actionsWithStoredLayouts = (definitions) => {
1895
1945
  actions[id] = definition;
1896
1946
  continue;
1897
1947
  }
1898
- const ref = chunk6ZWMC2OV_cjs.actionLayoutRef(id);
1948
+ const ref = chunk6ACVHHFK_cjs.actionLayoutRef(id);
1899
1949
  layouts[ref] = layout;
1900
1950
  actions[id] = { ...definition, layout: { ref } };
1901
1951
  }
@@ -1948,8 +1998,8 @@ var createSetOwners = () => {
1948
1998
  return {
1949
1999
  ownerRefusalOf,
1950
2000
  claim: (source, owner, handedOver) => {
1951
- const held = owners.get(source);
1952
- if (held !== void 0) throw new Error(`moss: the set "${source}" is ${held}'s, and ${owner} claims it too. A set has one writer.`);
2001
+ const claimed = owners.get(source);
2002
+ if (claimed !== void 0) throw new Error(`moss: the set "${source}" is ${claimed}'s, and ${owner} claims it too. A set has one writer.`);
1953
2003
  if (handedOver) throw new Error(`moss: the set "${source}" was handed over by the app, and ${owner} claims it. A set has one writer.`);
1954
2004
  owners.set(source, owner);
1955
2005
  },
@@ -1991,17 +2041,17 @@ var tell = (listener, ...told) => {
1991
2041
  };
1992
2042
  var createRunningManifest = (config) => {
1993
2043
  const { shipped } = config;
1994
- const entries = createEntriesInForce(chunk6ZWMC2OV_cjs.entriesOf(shipped));
2044
+ const entries = createEntriesInForce(chunk6ACVHHFK_cjs.entriesOf(shipped), config.compileSeeded);
1995
2045
  let defaults = NO_DEFAULTS;
1996
2046
  const usage = createUsage(config.touchEveryMs ?? TOUCH_EVERY_MS);
1997
2047
  let functionIds;
1998
- const candidate = (actions, held = entries.list(), fragments = defaults.fragments) => chunk6ZWMC2OV_cjs.withFragments({ ...chunk6ZWMC2OV_cjs.candidateOf(shipped, { actions, entries: held }, config.grants), ...functionIds === void 0 ? {} : { functionIds } }, fragments);
2048
+ const candidate = (actions, listed2 = entries.list(), fragments = defaults.fragments) => chunk6ACVHHFK_cjs.withFragments({ ...chunk6ACVHHFK_cjs.candidateOf(shipped, { actions, entries: listed2 }, config.grants), ...functionIds === void 0 ? {} : { functionIds } }, fragments);
1999
2049
  const own = shipped.actions;
2000
2050
  const loaders = /* @__PURE__ */ new Map();
2001
2051
  const owners = createSetOwners();
2002
2052
  let sets = /* @__PURE__ */ new Map();
2003
2053
  let inForce2 = mergedActions(own, sets);
2004
- let report = chunk6ZWMC2OV_cjs.verifiedAtBoot(candidate(inForce2));
2054
+ let report = chunk6ACVHHFK_cjs.verifiedAtBoot(candidate(inForce2));
2005
2055
  const components = createComponentNames((shell) => shellComponents({ actions: inForce2, layouts: shipped.layouts }, shell));
2006
2056
  const componentsOf2 = (shells) => {
2007
2057
  const kit = /* @__PURE__ */ new Map();
@@ -2024,7 +2074,7 @@ var createRunningManifest = (config) => {
2024
2074
  const kitOf2 = (shell) => shell === void 0 ? ofTheApp ??= componentsOf2(config.shells) : componentsOf2([shell]);
2025
2075
  const ownShell = shipped.shell;
2026
2076
  const ownShellRefs = new Set(ownShell === void 0 ? [] : Object.keys(shellWithStoredLayouts(ownShell).layouts));
2027
- const heldTo = ({ actions, layouts }, shell) => {
2077
+ const layoutChecksOf = ({ actions, layouts }, shell) => {
2028
2078
  const kit = kitOf2(shell);
2029
2079
  return {
2030
2080
  kit,
@@ -2036,14 +2086,14 @@ var createRunningManifest = (config) => {
2036
2086
  const { reads: readSources } = config;
2037
2087
  const functionsWritten = (written) => {
2038
2088
  if (functionIds !== void 0) return;
2039
- const ids = chunk6ZWMC2OV_cjs.functionsIn(written).map((definition) => definition.id);
2040
- const charter = chunk6ZWMC2OV_cjs.charterOverFunctions(shipped.charter, { actions: Object.keys(inForce2), data: config.grants, layouts: Object.keys(shipped.layouts ?? {}) }, ids);
2089
+ const ids = chunk6ACVHHFK_cjs.functionsIn(written).map((definition) => definition.id);
2090
+ const charter = chunk6ACVHHFK_cjs.charterOverFunctions(shipped.charter, { actions: Object.keys(inForce2), data: config.grants, layouts: Object.keys(shipped.layouts ?? {}) }, ids);
2041
2091
  if (charter.errors.length > 0) throw new Error(`Charter is incoherent over the app\u2019s functions \u2014 refusing to serve:
2042
2092
  ${charter.errors.join("\n ")}`);
2043
2093
  functionIds = new Set(ids);
2044
2094
  const built = mergedActions(own, sets);
2045
- const verified = chunk6ZWMC2OV_cjs.verifyManifest(candidate(built, entries.list(), {}));
2046
- const refusal = chunk6ZWMC2OV_cjs.refusalOf(verified, "boot");
2095
+ const verified = chunk6ACVHHFK_cjs.verifyManifest(candidate(built, entries.list(), {}));
2096
+ const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "boot");
2047
2097
  if (refusal !== void 0) {
2048
2098
  functionIds = void 0;
2049
2099
  throw new Error(refusal);
@@ -2054,15 +2104,15 @@ var createRunningManifest = (config) => {
2054
2104
  dropMemos();
2055
2105
  memo.drop();
2056
2106
  for (const warning2 of charter.warnings) console.warn(`[moss] charter: ${warning2}`);
2057
- const warning = chunk6ZWMC2OV_cjs.functionsWarning(written);
2107
+ const warning = chunk6ACVHHFK_cjs.functionsWarning(written);
2058
2108
  if (warning !== void 0) console.warn(warning);
2059
2109
  };
2060
2110
  const grantedFunctionsOf = (roles) => (names) => charter.resolvePrincipal(shipped.charter, names, roles, "functions");
2061
- const readsHeldTo = readSources === void 0 ? void 0 : { isAppEntry: (fingerprint) => entries.byFingerprint().has(fingerprint), sources: readSources };
2062
- const heldWithGenerated = async (held, versions, who, shell, whose) => {
2111
+ const readChecks = readSources === void 0 ? void 0 : { isAppEntry: (fingerprint) => entries.byFingerprint().has(fingerprint), sources: readSources };
2112
+ const checksWithGenerated = async (granted, versions, who, shell, whose) => {
2063
2113
  let replayable;
2064
2114
  let catalog;
2065
- const reads = new Map([...defaults.reads, ...readsHeldTo === void 0 ? [] : await readsInForce(versions, readsHeldTo, whose)]);
2115
+ const reads = new Map([...defaults.reads, ...readChecks === void 0 ? [] : await readsInForce(versions, readChecks, whose)]);
2066
2116
  const checks = {
2067
2117
  kit: kitOf2(shell),
2068
2118
  entryOf: (fingerprint) => {
@@ -2071,12 +2121,12 @@ var createRunningManifest = (config) => {
2071
2121
  },
2072
2122
  replayable: () => replayable ??= (async () => /* @__PURE__ */ new Set([...await who.replayable?.() ?? [], ...reads.keys()]))(),
2073
2123
  mayCall: (name) => who.roles !== void 0 && charter.resolvePrincipal(shipped.charter, [name], who.roles, "functions").has(name),
2074
- catalog: () => catalog ??= [...Object.values(held.actions).map((action) => ({ id: action.id, input: action.input ?? {} })), ...catalogOfGenerated(versions)]
2124
+ catalog: () => catalog ??= [...Object.values(granted.actions).map((action) => ({ id: action.id, input: action.input ?? {} })), ...catalogOfGenerated(versions)]
2075
2125
  };
2076
2126
  const passed = await generatedInForce(versions, checks, whose);
2077
2127
  const stored = actionsWithStoredLayouts(passed.actions);
2078
- const all = Object.keys(passed.actions).length === 0 ? held : { actions: { ...held.actions, ...stored.actions }, layouts: { ...held.layouts, ...stored.layouts } };
2079
- return { all, fragments: passed.fragments, heldTo: { layouts: heldTo(all, shell), generated: checks, ...readsHeldTo !== void 0 ? { reads: readsHeldTo } : {} } };
2128
+ const all = Object.keys(passed.actions).length === 0 ? granted : { actions: { ...granted.actions, ...stored.actions }, layouts: { ...granted.layouts, ...stored.layouts } };
2129
+ return { all, fragments: passed.fragments, checks: { layouts: layoutChecksOf(all, shell), generated: checks, ...readChecks !== void 0 ? { reads: readChecks } : {} } };
2080
2130
  };
2081
2131
  const listeners = /* @__PURE__ */ new Set();
2082
2132
  const listenersFor = /* @__PURE__ */ new Set();
@@ -2084,11 +2134,11 @@ var createRunningManifest = (config) => {
2084
2134
  const sessionDeps = (principal, callerOf, shell) => ({
2085
2135
  whose: "of yours",
2086
2136
  kinds,
2087
- holder: principal === null ? void 0 : async () => {
2137
+ owner: principal === null ? void 0 : async () => {
2088
2138
  await publishedNow();
2089
2139
  const caller = await callerOf();
2090
- const held = roleMemo.storedLayoutsFor(caller.roles, caller.installed);
2091
- return { saved: caller.saved, heldTo: async (inForce3) => (await heldWithGenerated(held, inForce3, caller, shell)).heldTo };
2140
+ const granted = roleMemo.storedLayoutsFor(caller.roles, caller.installed);
2141
+ return { saved: caller.saved, checks: async (inForce3) => (await checksWithGenerated(granted, inForce3, caller, shell)).checks };
2092
2142
  },
2093
2143
  written: () => {
2094
2144
  if (principal !== null) for (const listener of [...listenersFor]) tell(listener, principal);
@@ -2096,19 +2146,19 @@ var createRunningManifest = (config) => {
2096
2146
  });
2097
2147
  let pointer;
2098
2148
  const memo = createPublishedMemo();
2099
- const defaultsHeldTo = () => ({
2149
+ const defaultsChecks = () => ({
2100
2150
  kit: kitOf2(),
2101
2151
  entryOf: (fingerprint) => entries.byFingerprint().get(fingerprint),
2102
2152
  fingerprints: () => entries.byFingerprint().keys(),
2103
- reads: readsHeldTo,
2153
+ reads: readChecks,
2104
2154
  built: mergedActions(own, sets),
2105
2155
  candidate: (actions, fragments) => candidate(actions, entries.list(), fragments)
2106
2156
  });
2107
2157
  const applyPublished = async (versions) => {
2108
2158
  const over = sets;
2109
- const { passed, reads, verified } = await checkedDefaults(versions, defaultsHeldTo(), "published for everybody");
2159
+ const { passed, reads, verified } = await checkedDefaults(versions, defaultsChecks(), "published for everybody");
2110
2160
  if (sets !== over) return applyPublished(versions);
2111
- const refusal = chunk6ZWMC2OV_cjs.refusalOf(verified, "boot");
2161
+ const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "boot");
2112
2162
  if (refusal !== void 0) memo.sayOnce(`[moss] what is published for everybody is left out, and the build\u2019s copies stand: ${refusal}`);
2113
2163
  const next = refusal === void 0 ? { actions: passed.actions, fragments: passed.fragments, reads } : { ...NO_DEFAULTS, reads };
2114
2164
  if (!hasDefaults(next) && !hasDefaults(defaults)) return;
@@ -2118,8 +2168,8 @@ var createRunningManifest = (config) => {
2118
2168
  dropMemos();
2119
2169
  };
2120
2170
  const publishedNow = () => {
2121
- const held = memo.held();
2122
- if (held !== void 0) return held;
2171
+ const current = memo.current();
2172
+ if (current !== void 0) return current;
2123
2173
  const read2 = (async () => {
2124
2174
  const versions = await config.published?.() ?? [];
2125
2175
  await applyPublished(versions);
@@ -2132,10 +2182,10 @@ var createRunningManifest = (config) => {
2132
2182
  const applySets = (arrived, announce) => {
2133
2183
  const next = new Map([...sets, ...arrived]);
2134
2184
  const actions = mergedActions(own, next, defaults.actions);
2135
- const verified = chunk6ZWMC2OV_cjs.verifyManifest(candidate(actions));
2136
- const refusal = chunk6ZWMC2OV_cjs.refusalOf(verified, "refresh");
2185
+ const verified = chunk6ACVHHFK_cjs.verifyManifest(candidate(actions));
2186
+ const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "refresh");
2137
2187
  if (refusal !== void 0) throw new Error(refusal);
2138
- for (const set of arrived.values()) chunk6ZWMC2OV_cjs.freezeDeep(set);
2188
+ for (const set of arrived.values()) chunk6ACVHHFK_cjs.freezeDeep(set);
2139
2189
  sets = next;
2140
2190
  inForce2 = actions;
2141
2191
  report = verified;
@@ -2151,13 +2201,13 @@ var createRunningManifest = (config) => {
2151
2201
  };
2152
2202
  const takeEntries = async (source, handed) => {
2153
2203
  owners.assertAppOwned(source);
2154
- const misfits = chunk6ZWMC2OV_cjs.entryMisfits(handed);
2204
+ const misfits = chunk6ACVHHFK_cjs.entryMisfits(handed);
2155
2205
  if (misfits.length > 0) throw new Error(["Refresh refused \u2014 entries that do not parse:", ...misfits.map((misfit) => ` ${misfit}`)].join("\n"));
2156
2206
  const compiled = await compileEntries(handed);
2157
- const verified = chunk6ZWMC2OV_cjs.verifyManifest(candidate(inForce2, entries.withSet(source, handed)));
2158
- const refusal = chunk6ZWMC2OV_cjs.refusalOf(verified, "refresh");
2207
+ const verified = chunk6ACVHHFK_cjs.verifyManifest(candidate(inForce2, entries.withSet(source, handed)));
2208
+ const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "refresh");
2159
2209
  if (refusal !== void 0) throw new Error(refusal);
2160
- chunk6ZWMC2OV_cjs.freezeDeep(handed);
2210
+ chunk6ACVHHFK_cjs.freezeDeep(handed);
2161
2211
  entries.takeSet(source, handed, compiled);
2162
2212
  report = verified;
2163
2213
  for (const listener of [...listeners]) tell(listener);
@@ -2167,7 +2217,7 @@ var createRunningManifest = (config) => {
2167
2217
  return {
2168
2218
  actions: () => inForce2,
2169
2219
  entries: entries.list,
2170
- verify: (actions) => chunk6ZWMC2OV_cjs.verifyManifest(candidate(actions)),
2220
+ verify: (actions) => chunk6ACVHHFK_cjs.verifyManifest(candidate(actions)),
2171
2221
  report: () => report,
2172
2222
  replace: (source, actions) => applySets(/* @__PURE__ */ new Map([[owners.assertAppOwned(source), actions]]), true),
2173
2223
  // In turn: a set is compiled before it is taken, and of two handed over
@@ -2191,7 +2241,7 @@ var createRunningManifest = (config) => {
2191
2241
  },
2192
2242
  cacheEntries: async () => [...await entries.compiled()].map(([key, entry]) => ({ key, entry })),
2193
2243
  claim: (source, owner) => {
2194
- owners.claim(source, owner, sets.has(source) || entries.holdsSet(source));
2244
+ owners.claim(source, owner, sets.has(source) || entries.hasSet(source));
2195
2245
  return {
2196
2246
  replace: (actions) => applySets(/* @__PURE__ */ new Map([[source, actions]]), true),
2197
2247
  setLoader: (load) => {
@@ -2224,12 +2274,12 @@ var createRunningManifest = (config) => {
2224
2274
  const versions = own2.length === 0 && drafted === void 0 ? [] : laidOver(own2, drafted);
2225
2275
  const everybodysVersions = await publishedNow();
2226
2276
  const whose = `of ${principal ?? "nobody"}`;
2227
- const theirOwn = await heldWithGenerated(roleMemo.storedLayoutsFor(roles, installed), versions, { replayable, roles }, shell, whose);
2228
- const drawable = theirOwn.heldTo.layouts;
2229
- const theirs2 = layoutsInUse(versions, { whose, heldTo: drawable });
2277
+ const theirOwn = await checksWithGenerated(roleMemo.storedLayoutsFor(roles, installed), versions, { replayable, roles }, shell, whose);
2278
+ const drawable = theirOwn.checks.layouts;
2279
+ const theirs2 = layoutsInUse(versions, { whose, checks: drawable });
2230
2280
  const variants = roleMemo.variantsFor(roles);
2231
- const underVariants = { ...drawable, actionAt: (ref) => variants.has(chunk6ZWMC2OV_cjs.actionOfLayoutRef(ref) ?? "") ? void 0 : drawable.actionAt(ref) };
2232
- const everybodys = layoutsInUse(everybodysVersions, { whose: "published for everybody", heldTo: underVariants, say: memo.sayOnce });
2281
+ const underVariants = { ...drawable, actionAt: (ref) => variants.has(chunk6ACVHHFK_cjs.actionOfLayoutRef(ref) ?? "") ? void 0 : drawable.actionAt(ref) };
2282
+ const everybodys = layoutsInUse(everybodysVersions, { whose: "published for everybody", checks: underVariants, say: memo.sayOnce });
2233
2283
  const laidOverShell = { ...drawableIn(defaults.fragments, kitOf2(shell), memo.sayOnce), ...theirOwn.fragments };
2234
2284
  const fragments = Object.keys(laidOverShell).length === 0 ? shell.fragments : { ...shell.fragments, ...laidOverShell };
2235
2285
  const { layouts: ofShell, ...named } = shellWithStoredLayouts(shell);
@@ -2247,20 +2297,20 @@ var createRunningManifest = (config) => {
2247
2297
  },
2248
2298
  sessionArtifacts: (principal, callerOf) => savedArtifacts(sessionDeps(principal, callerOf)),
2249
2299
  draftSavingFor: (shell, principal, callerOf) => draftSaving(sessionDeps(principal, callerOf, shell)),
2250
- // Held to every action in force with the layout it is built with: who holds
2300
+ // Checked against every action in force with the layout it is built with: who has
2251
2301
  // which is asked when a shell is built for them.
2252
2302
  publishedArtifacts: (saved, publisher) => savedArtifacts({
2253
2303
  whose: "published for everybody",
2254
2304
  kinds,
2255
- holder: async () => {
2305
+ owner: async () => {
2256
2306
  const who = await publisher();
2257
- return { saved, heldTo: async (inForce3) => (await heldWithGenerated(actionsWithStoredLayouts(mergedActions(own, sets)), inForce3, who)).heldTo };
2307
+ return { saved, checks: async (inForce3) => (await checksWithGenerated(actionsWithStoredLayouts(mergedActions(own, sets)), inForce3, who)).checks };
2258
2308
  },
2259
2309
  defaults: {
2260
2310
  verify: async (versions, inForce3) => {
2261
- const kept = inForce3.filter((held) => !versions.some((version) => version.kind === held.kind && version.id === held.id));
2311
+ const kept = inForce3.filter((current) => !versions.some((version) => version.kind === current.kind && version.id === current.id));
2262
2312
  const asked = versions.map((version) => ({ ...version, save: "", createdAt: "" }));
2263
- const refusal = chunk6ZWMC2OV_cjs.refusalOf((await checkedDefaults([...kept, ...asked], defaultsHeldTo(), void 0)).verified, "publish");
2313
+ const refusal = chunk6ACVHHFK_cjs.refusalOf((await checkedDefaults([...kept, ...asked], defaultsChecks(), void 0)).verified, "publish");
2264
2314
  if (refusal !== void 0) throw new Error(refusal);
2265
2315
  }
2266
2316
  },
@@ -2306,14 +2356,14 @@ var callerScope = (scope) => {
2306
2356
  };
2307
2357
  var PAGE = 500;
2308
2358
  var VERSION_COLUMNS = ["save", "kind", "id", "body", "grammar", "copied_from", "created_at"];
2309
- var laterThanHeld = {
2359
+ var laterVersion = {
2310
2360
  and: [
2311
2361
  { eq: ["artifacts.kind", "held.kind"] },
2312
2362
  { eq: ["artifacts.id", "held.id"] },
2313
2363
  { or: [{ gt: ["artifacts.created_at", "held.created_at"] }, { and: [{ eq: ["artifacts.created_at", "held.created_at"] }, { gt: ["artifacts.save", "held.save"] }] }] }
2314
2364
  ]
2315
2365
  };
2316
- var afterHeld = {
2366
+ var afterCursor = {
2317
2367
  or: [{ gt: ["held.kind", { $context: "after_kind" }] }, { and: [{ eq: ["held.kind", { $context: "after_kind" }] }, { gt: ["held.id", { $context: "after_id" }] }] }]
2318
2368
  };
2319
2369
  var inForce = {
@@ -2322,7 +2372,7 @@ var inForce = {
2322
2372
  dsl: {
2323
2373
  from: [{ as: "held", query: { from: ["artifacts"], fields: VERSION_COLUMNS.map((column) => `artifacts.${column}`) } }],
2324
2374
  fields: VERSION_COLUMNS.map((column) => `held.${column}`),
2325
- filter: { and: [{ not: { exists: { from: ["artifacts"], filter: laterThanHeld } } }, afterHeld] },
2375
+ filter: { and: [{ not: { exists: { from: ["artifacts"], filter: laterVersion } } }, afterCursor] },
2326
2376
  sort: [
2327
2377
  { field: "held.kind", dir: "asc" },
2328
2378
  { field: "held.id", dir: "asc" }
@@ -2435,10 +2485,11 @@ var DEFAULT_REVALIDATE_MS = 60 * 1e3;
2435
2485
  var MAX_INTERVAL_MS2 = 2 ** 31 - 1;
2436
2486
  var createRevalidation = (config) => {
2437
2487
  const live = /* @__PURE__ */ new Map();
2488
+ const revalidateMs = config.revalidateMs ?? DEFAULT_REVALIDATE_MS;
2438
2489
  const expire = (connection) => {
2439
2490
  live.delete(connection);
2440
2491
  const told = () => connection.send(JSON.stringify({ type: "error", code: "invalid_token", message: "The session token no longer resolves to this principal." }));
2441
- const closed = () => connection.close(chunkNCQBGK3E_cjs.CLOSE_INVALID_TOKEN, "session expired");
2492
+ const closed = () => connection.close(chunkBFA76AKR_cjs.CLOSE_INVALID_TOKEN, "session expired");
2442
2493
  for (const step of [told, closed]) {
2443
2494
  try {
2444
2495
  step();
@@ -2447,30 +2498,59 @@ var createRevalidation = (config) => {
2447
2498
  }
2448
2499
  }
2449
2500
  };
2501
+ const asking = /* @__PURE__ */ new Set();
2502
+ const question = async (token, presenting) => {
2503
+ for (const { connection } of presenting) asking.add(connection);
2504
+ try {
2505
+ const resolved = await config.session(token);
2506
+ for (const { connection, principal } of presenting) if (resolved !== principal && live.has(connection)) expire(connection);
2507
+ } finally {
2508
+ for (const { connection } of presenting) asking.delete(connection);
2509
+ }
2510
+ };
2450
2511
  const revalidate = async () => {
2512
+ const byToken = /* @__PURE__ */ new Map();
2451
2513
  let asked = 0;
2452
- const unanswered = [];
2453
- for (const [connection, credential] of [...live]) {
2454
- if (credential === null) continue;
2514
+ for (const [connection, credential] of live) {
2515
+ if (credential === null || asking.has(connection)) continue;
2455
2516
  asked += 1;
2456
- let resolved;
2457
- try {
2458
- resolved = await config.session(credential.token);
2459
- } catch (error) {
2460
- unanswered.push(error);
2461
- continue;
2462
- }
2463
- if (resolved === credential.principal) continue;
2464
- if (!live.has(connection)) continue;
2465
- expire(connection);
2517
+ byToken.set(credential.token, [...byToken.get(credential.token) ?? [], { connection, principal: credential.principal }]);
2518
+ }
2519
+ let due;
2520
+ const passDue = new Promise((resolve2) => {
2521
+ due = setTimeout(() => resolve2(false), revalidateMs);
2522
+ due.unref?.();
2523
+ });
2524
+ const unanswered = [];
2525
+ try {
2526
+ await Promise.all(
2527
+ [...byToken].map(async ([token, presenting]) => {
2528
+ const answer = question(token, presenting);
2529
+ try {
2530
+ if (!await Promise.race([answer.then(() => true), passDue])) {
2531
+ answer.catch(
2532
+ (error) => console.error("[moss/socket] the session verifier could not be asked about a token after its pass went on. Its connections stay open and are asked again:", error)
2533
+ );
2534
+ }
2535
+ } catch (error) {
2536
+ unanswered.push(...presenting.map(() => error));
2537
+ }
2538
+ })
2539
+ );
2540
+ } finally {
2541
+ clearTimeout(due);
2466
2542
  }
2467
2543
  if (unanswered.length > 0) {
2468
2544
  console.error(`[moss/socket] the session verifier could not be asked about ${unanswered.length} of ${asked} connection(s). They stay open and are asked again:`, unanswered[0]);
2469
2545
  }
2470
2546
  };
2471
2547
  let passing = false;
2548
+ let dueWhilePassing = false;
2472
2549
  const pass = async () => {
2473
- if (passing) return;
2550
+ if (passing) {
2551
+ dueWhilePassing = true;
2552
+ return;
2553
+ }
2474
2554
  passing = true;
2475
2555
  try {
2476
2556
  await revalidate();
@@ -2478,16 +2558,19 @@ var createRevalidation = (config) => {
2478
2558
  console.error("[moss/socket] a revalidation pass failed, and the next one starts over:", error);
2479
2559
  } finally {
2480
2560
  passing = false;
2561
+ if (dueWhilePassing && sweeper !== void 0) {
2562
+ dueWhilePassing = false;
2563
+ void pass();
2564
+ }
2481
2565
  }
2482
2566
  };
2483
- const revalidateMs = config.revalidateMs ?? DEFAULT_REVALIDATE_MS;
2484
2567
  let sweeper;
2485
2568
  if (revalidateMs > 0 && revalidateMs <= MAX_INTERVAL_MS2) {
2486
2569
  sweeper = setInterval(() => void pass(), revalidateMs);
2487
2570
  sweeper.unref?.();
2488
2571
  }
2489
2572
  return {
2490
- hold: (connection, credential) => {
2573
+ track: (connection, credential) => {
2491
2574
  live.set(connection, credential);
2492
2575
  },
2493
2576
  release: (connection) => {
@@ -2516,20 +2599,20 @@ var parametersOf = (url) => {
2516
2599
  var SpokenProtocolSchema = zod.z.string().regex(/^\d{1,15}$/).transform(Number);
2517
2600
  var protocolRefusal = (parameters) => {
2518
2601
  const spoken = SpokenProtocolSchema.safeParse(parameters.protocol);
2519
- if (spoken.success && spoken.data >= chunkNCQBGK3E_cjs.PROTOCOL_MIN && spoken.data <= chunkNCQBGK3E_cjs.PROTOCOL) return void 0;
2520
- const behind = spoken.success && spoken.data > chunkNCQBGK3E_cjs.PROTOCOL ? "server" : "client";
2602
+ if (spoken.success && spoken.data >= chunkBFA76AKR_cjs.PROTOCOL_MIN && spoken.data <= chunkBFA76AKR_cjs.PROTOCOL) return void 0;
2603
+ const behind = spoken.success && spoken.data > chunkBFA76AKR_cjs.PROTOCOL ? "server" : "client";
2521
2604
  return {
2522
2605
  type: "error",
2523
2606
  code: `${behind}_too_old`,
2524
- message: `This terminal speaks protocol ${parameters.protocol}; this server speaks ${chunkNCQBGK3E_cjs.PROTOCOL_MIN}\u2013${chunkNCQBGK3E_cjs.PROTOCOL}. ` + (behind === "client" ? "Reload the terminal to get the current build." : "The server has not been updated yet.")
2607
+ message: `This terminal speaks protocol ${parameters.protocol}; this server speaks ${chunkBFA76AKR_cjs.PROTOCOL_MIN}\u2013${chunkBFA76AKR_cjs.PROTOCOL}. ` + (behind === "client" ? "Reload the terminal to get the current build." : "The server has not been updated yet.")
2525
2608
  };
2526
2609
  };
2527
2610
  var authenticateUpgrade = async (url, upgrade, config, foreignPageWarning) => {
2528
2611
  const parameters = parametersOf(url);
2529
- const key = parameters.key ?? chunkNCQBGK3E_cjs.DEFAULT_TOKEN_KEY;
2612
+ const key = parameters.key ?? chunkBFA76AKR_cjs.DEFAULT_TOKEN_KEY;
2530
2613
  const page = upgrade === void 0 ? void 0 : ownOriginOf(upgrade.origin, upgrade.host, config.origins);
2531
2614
  const secure = page?.protocol === "https:";
2532
- const held = page === void 0 ? null : sessionTokenOf(upgrade?.cookie, { port: page.port, secure }, key);
2615
+ const fromCookie = page === void 0 ? null : sessionTokenOf(upgrade?.cookie, { port: page.port, secure }, key);
2533
2616
  const sealing = page !== void 0 && parameters.sealed === "1";
2534
2617
  if (page === void 0 && parameters.sealed === "1" && typeof upgrade?.origin === "string" && !foreignPageWarning.warned) {
2535
2618
  foreignPageWarning.warned = true;
@@ -2538,16 +2621,16 @@ var authenticateUpgrade = async (url, upgrade, config, foreignPageWarning) => {
2538
2621
  );
2539
2622
  }
2540
2623
  const hadSeal = sealing ? sealOf(upgrade?.cookie, secure) : null;
2541
- const sealedOffer = chunkNCQBGK3E_cjs.offeredSealed(upgrade?.offered);
2624
+ const sealedOffer = chunkBFA76AKR_cjs.offeredSealed(upgrade?.offered);
2542
2625
  const sealLost = sealing && sealedOffer !== null && hadSeal === null;
2543
2626
  const seal = !sealing || sealLost ? null : hadSeal ?? (upgrade?.answer === void 0 ? null : newSeal());
2544
- const offered = chunkNCQBGK3E_cjs.offeredToken(upgrade?.offered) ?? (sealedOffer === null || hadSeal === null ? null : await openSealed(hadSeal, sealedOffer));
2545
- const carried = offered ?? (parameters.leave === "1" ? null : held?.token ?? null);
2627
+ const offered = chunkBFA76AKR_cjs.offeredToken(upgrade?.offered) ?? (sealedOffer === null || hadSeal === null ? null : await openSealed(hadSeal, sealedOffer));
2628
+ const carried = offered ?? (parameters.leave === "1" ? null : fromCookie?.token ?? null);
2546
2629
  const principal = carried === null ? null : await config.session(carried);
2547
2630
  if (offered !== null && principal === null) return "invalid_token";
2548
2631
  const token = principal === null ? null : carried;
2549
2632
  const cookies = [
2550
- ...page === void 0 || offered === null && (held?.token ?? null) === token ? [] : token === null ? held?.clear ?? [] : sessionCookies(page.origin, token, { key, lastsMs: await config.sessionLastsMs?.(token) ?? null }),
2633
+ ...page === void 0 || offered === null && (fromCookie?.token ?? null) === token ? [] : token === null ? fromCookie?.clear ?? [] : sessionCookies(page.origin, token, { key, lastsMs: await config.sessionLastsMs?.(token) ?? null }),
2551
2634
  ...seal !== null && hadSeal === null ? [sealCookie(seal, { secure, path: new URL(url, "http://nisc.local").pathname })] : []
2552
2635
  ];
2553
2636
  return { token, principal, cookies, seal, sealLost };
@@ -2556,13 +2639,13 @@ var authenticateUpgrade = async (url, upgrade, config, foreignPageWarning) => {
2556
2639
  // src/socket/routing.ts
2557
2640
  var messageOf2 = (text) => {
2558
2641
  try {
2559
- const parsed = chunkNCQBGK3E_cjs.ClientMessageSchema.safeParse(JSON.parse(text));
2642
+ const parsed = chunkBFA76AKR_cjs.ClientMessageSchema.safeParse(JSON.parse(text));
2560
2643
  return parsed.success ? parsed.data : void 0;
2561
2644
  } catch {
2562
2645
  return void 0;
2563
2646
  }
2564
2647
  };
2565
- var INVALID_MESSAGE = `Not a message of protocol ${chunkNCQBGK3E_cjs.PROTOCOL}: it must be JSON, name a type a terminal sends, and carry that type's fields and no others.`;
2648
+ var INVALID_MESSAGE = `Not a message of protocol ${chunkBFA76AKR_cjs.PROTOCOL}: it must be JSON, name a type a terminal sends, and carry that type's fields and no others.`;
2566
2649
  var messageHandler = (session, connection, send) => {
2567
2650
  const act = (text) => {
2568
2651
  const message = messageOf2(text);
@@ -2654,7 +2737,7 @@ var refusalOf2 = (error) => {
2654
2737
  };
2655
2738
  var spanOf = (emit) => {
2656
2739
  if (emit === void 0) return void 0;
2657
- const clock = chunkPVZMCEBX_cjs.spanClock();
2740
+ const clock = chunk3CKBKTXA_cjs.spanClock();
2658
2741
  return (name, status2, hasPrincipal) => emit({ name, startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status: status2, attributes: { hasPrincipal } });
2659
2742
  };
2660
2743
  var openingOf = (config, { seed, path }) => {
@@ -2667,7 +2750,7 @@ var AT_CAPACITY = { type: "error", code: "at_capacity", message: "This server is
2667
2750
  var served = async (config, connection, send, close, opening, who) => {
2668
2751
  const { ids, hash } = await config.catalog(who.principal);
2669
2752
  if (close.ended()) return void 0;
2670
- send({ type: "hello", protocol: chunkNCQBGK3E_cjs.PROTOCOL, principal: who.principal, catalog: { actions: ids, hash } });
2753
+ send({ type: "hello", protocol: chunkBFA76AKR_cjs.PROTOCOL, principal: who.principal, catalog: { actions: ids, hash } });
2671
2754
  const session = await opening.session?.(who.token, who.principal);
2672
2755
  if (session === void 0) {
2673
2756
  if (!close.ended()) send({ type: "frame", tree: [] });
@@ -2677,20 +2760,20 @@ var served = async (config, connection, send, close, opening, who) => {
2677
2760
  close.whenClosed(() => session.detach(connection));
2678
2761
  return session;
2679
2762
  };
2680
- var open = async (held, url, connection, send, span, found) => {
2681
- const { config, foreignPageWarning, revalidation, anonymousShells } = held;
2763
+ var open = async (state, url, connection, send, span, found) => {
2764
+ const { config, foreignPageWarning, revalidation, anonymousShells } = state;
2682
2765
  const params = parametersOf(url);
2683
2766
  const mismatch = protocolRefusal(params);
2684
2767
  if (mismatch !== void 0) {
2685
2768
  send(mismatch);
2686
- connection.close(chunkNCQBGK3E_cjs.CLOSE_PROTOCOL_MISMATCH, "protocol mismatch");
2769
+ connection.close(chunkBFA76AKR_cjs.CLOSE_PROTOCOL_MISMATCH, "protocol mismatch");
2687
2770
  return;
2688
2771
  }
2689
2772
  const asking = await authenticateUpgrade(url, connection.upgrade, config, foreignPageWarning);
2690
2773
  if (asking === "invalid_token") {
2691
2774
  span?.("socket.upgrade", "refused", false);
2692
2775
  send({ type: "error", code: "invalid_token", message: "The session token did not resolve to a principal." });
2693
- connection.close(chunkNCQBGK3E_cjs.CLOSE_INVALID_TOKEN, "invalid token");
2776
+ connection.close(chunkBFA76AKR_cjs.CLOSE_INVALID_TOKEN, "invalid token");
2694
2777
  return;
2695
2778
  }
2696
2779
  const { token, principal, seal } = asking;
@@ -2704,10 +2787,10 @@ var open = async (held, url, connection, send, span, found) => {
2704
2787
  if (principal === null && session !== void 0 && !anonymousShells.acquire(connection)) {
2705
2788
  span?.("socket.upgrade", "refused", false);
2706
2789
  send(AT_CAPACITY);
2707
- connection.close(chunkNCQBGK3E_cjs.CLOSE_AT_CAPACITY, "at capacity");
2790
+ connection.close(chunkBFA76AKR_cjs.CLOSE_AT_CAPACITY, "at capacity");
2708
2791
  return;
2709
2792
  }
2710
- revalidation.hold(connection, token !== null && token !== "" && principal !== null ? { token, principal } : null);
2793
+ revalidation.track(connection, token !== null && token !== "" && principal !== null ? { token, principal } : null);
2711
2794
  const close = closeOf(connection);
2712
2795
  close.whenClosed(() => revalidation.release(connection));
2713
2796
  close.whenClosed(() => anonymousShells.release(connection));
@@ -2717,16 +2800,16 @@ var open = async (held, url, connection, send, span, found) => {
2717
2800
  connection.onMessage(messageHandler(attached, connection, send));
2718
2801
  };
2719
2802
  var createSocket = (config) => {
2720
- const emit = chunkPVZMCEBX_cjs.emitterOf(config.telemetry);
2803
+ const emit = chunk3CKBKTXA_cjs.emitterOf(config.telemetry);
2721
2804
  const revalidation = createRevalidation(config);
2722
2805
  const anonymousShells = createAnonymousShellLimit(config.anonymousShellMax ?? DEFAULT_ANONYMOUS_SHELL_MAX);
2723
- const held = { config, foreignPageWarning: { warned: false }, revalidation, anonymousShells };
2806
+ const state = { config, foreignPageWarning: { warned: false }, revalidation, anonymousShells };
2724
2807
  const accept = async (url, connection) => {
2725
2808
  const send = (message) => connection.send(JSON.stringify(message));
2726
2809
  const span = spanOf(emit);
2727
2810
  const found = { principal: false };
2728
2811
  try {
2729
- await open(held, url, connection, send, span, found);
2812
+ await open(state, url, connection, send, span, found);
2730
2813
  } catch (error) {
2731
2814
  console.error("[moss/socket] refused a session:", error);
2732
2815
  span?.("socket.upgrade", "error", found.principal);
@@ -2734,7 +2817,7 @@ var createSocket = (config) => {
2734
2817
  anonymousShells.release(connection);
2735
2818
  try {
2736
2819
  send(refusalOf2(error));
2737
- connection.close(chunkNCQBGK3E_cjs.CLOSE_SHELL_FAILED, "session failed");
2820
+ connection.close(chunkBFA76AKR_cjs.CLOSE_SHELL_FAILED, "session failed");
2738
2821
  } catch {
2739
2822
  }
2740
2823
  }
@@ -2765,13 +2848,13 @@ var seamsFor = (feature, owned, { app, runtime, server, operator, registered, id
2765
2848
  grantedActionIds: (roles, installed) => running.catalogFor(roles, installed).ids,
2766
2849
  actions: running.actions,
2767
2850
  replaceActions: owned.replace,
2768
- refusalOf: (actions) => chunk6ZWMC2OV_cjs.refusalOf(running.verify(actions), "refresh"),
2851
+ refusalOf: (actions) => chunk6ACVHHFK_cjs.refusalOf(running.verify(actions), "refresh"),
2769
2852
  setActionsLoader: owned.setLoader,
2770
2853
  addCatalogFilter: running.addCatalogFilter,
2771
2854
  charter: app.charter,
2772
2855
  components: app.shell?.components ?? {},
2773
- layoutMisfits: (layout) => chunk6ZWMC2OV_cjs.layoutMisfits(layout, kitOf(app)),
2774
- endlessChains: chunk6ZWMC2OV_cjs.endlessChains,
2856
+ layoutMisfits: (layout) => chunk6ACVHHFK_cjs.layoutMisfits(layout, kitOf(app)),
2857
+ endlessChains: chunk6ACVHHFK_cjs.endlessChains,
2775
2858
  ownEntries: (entries) => data.ownEntries(feature.name, entries),
2776
2859
  grammars: data.grammars,
2777
2860
  upgradeStore: (store) => data.upgradeStore(feature.name, store),
@@ -2838,9 +2921,9 @@ var read = (live) => {
2838
2921
  console.error("[moss/shells] the shell frame failed to render for a snapshot \u2014 serving an empty arrangement:", error);
2839
2922
  }
2840
2923
  const trees = {};
2841
- for (const canvasId of chunk6ZWMC2OV_cjs.canvasesOf(live)) {
2924
+ for (const canvasId of chunk6ACVHHFK_cjs.canvasesOf(live)) {
2842
2925
  try {
2843
- trees[canvasId] = chunk6ZWMC2OV_cjs.treeOf(live, canvasId);
2926
+ trees[canvasId] = chunk6ACVHHFK_cjs.treeOf(live, canvasId);
2844
2927
  } catch (error) {
2845
2928
  console.error(`[moss/shells] canvas "${canvasId}" failed to render for a snapshot \u2014 leaving it out:`, error);
2846
2929
  }
@@ -2857,7 +2940,7 @@ var needOf = (live, principal, kept) => {
2857
2940
  for (const instance of canvas.stack) {
2858
2941
  const definition = live.shell.getRuntime(instance.id)?.definition;
2859
2942
  if (definition === void 0) continue;
2860
- const need = shellNeedOf(chunk6ZWMC2OV_cjs.withLayoutInPlace(definition, live.shell.layoutStore), entries);
2943
+ const need = shellNeedOf(chunk6ACVHHFK_cjs.withLayoutInPlace(definition, live.shell.layoutStore), entries);
2861
2944
  for (const reason of need.why) why.push(`${definition.id}: ${reason}`);
2862
2945
  for (const read2 of need.drawnWith) drawnWith.push(read2);
2863
2946
  }
@@ -2880,7 +2963,7 @@ var sweep = (host, idleMs) => {
2880
2963
  }
2881
2964
  if (live.connections.size > 0 || live.idleSince === null) continue;
2882
2965
  if (now - live.idleSince < idleMs) continue;
2883
- chunk6ZWMC2OV_cjs.endShell(host, live);
2966
+ chunk6ACVHHFK_cjs.endShell(host, live);
2884
2967
  live.shell.dispose();
2885
2968
  durable.delete(principal);
2886
2969
  }
@@ -2902,7 +2985,7 @@ var rosterOf = (durable) => {
2902
2985
  var sameDocument = (one, other) => one === other || JSON.stringify(one) === JSON.stringify(other);
2903
2986
  var takeLayouts = (live, made) => {
2904
2987
  const taken = live.layouts;
2905
- const answered = chunk6ZWMC2OV_cjs.layoutsOf(made);
2988
+ const answered = chunk6ACVHHFK_cjs.layoutsOf(made);
2906
2989
  for (const [ref, layout] of Object.entries(answered.layoutStore)) {
2907
2990
  if (!sameDocument(taken.layoutStore[ref], layout)) live.shell.setLayout(ref, layout);
2908
2991
  }
@@ -2932,15 +3015,15 @@ var takeComposition = (live, made) => {
2932
3015
  live.entries = made.entries;
2933
3016
  takeLayouts(live, made);
2934
3017
  takeCanvases(live, made);
2935
- chunk6ZWMC2OV_cjs.holdGranted(live.functions, made.grantedFunctions);
3018
+ chunk6ACVHHFK_cjs.keepGranted(live.functions, made.grantedFunctions);
2936
3019
  };
2937
3020
  var adoptDraft = async (host, live, next) => {
2938
3021
  for (; ; ) {
2939
3022
  const cell = host.living.get(live);
2940
- if (cell === void 0 || cell.live !== live) throw new Error(chunk6ZWMC2OV_cjs.SHELL_GONE);
3023
+ if (cell === void 0 || cell.live !== live) throw new Error(chunk6ACVHHFK_cjs.SHELL_GONE);
2941
3024
  const changes = host.changes;
2942
- const made = await host.config.composition(cell.principal, chunk6ZWMC2OV_cjs.draftedIn(next));
2943
- if (live.ended || cell.live !== live) throw new Error(chunk6ZWMC2OV_cjs.SHELL_GONE);
3025
+ const made = await host.config.composition(cell.principal, chunk6ACVHHFK_cjs.draftedIn(next));
3026
+ if (live.ended || cell.live !== live) throw new Error(chunk6ACVHHFK_cjs.SHELL_GONE);
2944
3027
  if (changes < cell.changes) continue;
2945
3028
  cell.changes = changes;
2946
3029
  live.draft = next;
@@ -2954,7 +3037,7 @@ var adopt = (host, cell) => {
2954
3037
  if (asked.ended) return;
2955
3038
  const drafted = asked.draft;
2956
3039
  const changes = host.changes;
2957
- const made = await host.config.composition(cell.principal, chunk6ZWMC2OV_cjs.draftedIn(drafted));
3040
+ const made = await host.config.composition(cell.principal, chunk6ACVHHFK_cjs.draftedIn(drafted));
2958
3041
  if (asked.ended || changes <= cell.changes) return;
2959
3042
  if (asked.draft !== drafted) {
2960
3043
  adopt(host, cell);
@@ -2985,7 +3068,7 @@ var build = (host, asked, wanted = () => true) => {
2985
3068
  reject(new Error(`moss: the shell of ${asked.principal ?? "nobody"} was not built within ${limit}ms.`));
2986
3069
  }, limit);
2987
3070
  timer.unref?.();
2988
- chunk6ZWMC2OV_cjs.buildShell(host, { ...asked, wanted: () => inTime && wanted() }).then((live) => resolve2(live === void 0 ? void 0 : { live, changes }), reject).finally(() => clearTimeout(timer));
3071
+ chunk6ACVHHFK_cjs.buildShell(host, { ...asked, wanted: () => inTime && wanted() }).then((live) => resolve2(live === void 0 ? void 0 : { live, changes }), reject).finally(() => clearTimeout(timer));
2989
3072
  });
2990
3073
  };
2991
3074
  var builtOrThrow = (built) => {
@@ -3025,18 +3108,18 @@ var replaceShell = async (host, cell) => {
3025
3108
  if (built === void 0) return;
3026
3109
  const old = cell.live;
3027
3110
  if (!stands()) {
3028
- chunk6ZWMC2OV_cjs.endShell(host, built.live);
3111
+ chunk6ACVHHFK_cjs.endShell(host, built.live);
3029
3112
  built.live.shell.dispose();
3030
3113
  return;
3031
3114
  }
3032
3115
  const carried = [...old.connections].map((connection) => ({ connection, wants: old.deltaReady.has(connection) }));
3033
- chunk6ZWMC2OV_cjs.endShell(host, old);
3116
+ chunk6ACVHHFK_cjs.endShell(host, old);
3034
3117
  old.connections.clear();
3035
3118
  old.shell.dispose();
3036
3119
  cell.live = built.live;
3037
3120
  cell.changes = built.changes;
3038
3121
  registerLiving(host, cell);
3039
- for (const { connection, wants } of carried) chunk6ZWMC2OV_cjs.attach(built.live, connection, host.delta && wants);
3122
+ for (const { connection, wants } of carried) chunk6ACVHHFK_cjs.attach(built.live, connection, host.delta && wants);
3040
3123
  };
3041
3124
  var resetCell = (host, cell) => {
3042
3125
  if (cell.hasWaitingReset === true) return;
@@ -3079,7 +3162,7 @@ var snapshotOf = (host) => async (token, principal, options) => {
3079
3162
  const settled = await settle(live, waitMs);
3080
3163
  return { ...read(live), seed, settled, ...needOf(live, principal, kept) };
3081
3164
  } finally {
3082
- chunk6ZWMC2OV_cjs.endShell(host, live);
3165
+ chunk6ACVHHFK_cjs.endShell(host, live);
3083
3166
  live.shell.dispose();
3084
3167
  }
3085
3168
  };
@@ -3098,7 +3181,7 @@ var deliverTo = (host) => (principal, channel, payload) => {
3098
3181
  var createShellHost = (config) => {
3099
3182
  const host = {
3100
3183
  config,
3101
- emit: chunkPVZMCEBX_cjs.emitterOf(config.telemetry),
3184
+ emit: chunk3CKBKTXA_cjs.emitterOf(config.telemetry),
3102
3185
  kept: config.kept ?? true,
3103
3186
  delta: config.limits?.delta ?? false,
3104
3187
  durable: /* @__PURE__ */ new Map(),
@@ -3111,9 +3194,9 @@ var createShellHost = (config) => {
3111
3194
  const handedOut = {
3112
3195
  session: async (token, principal, options) => {
3113
3196
  if (principal === null || !host.kept) {
3114
- return chunk6ZWMC2OV_cjs.sessionOn(host, await open2(host, { token, principal, ...options !== void 0 ? { opening: options } : {} }, false), true, reset);
3197
+ return chunk6ACVHHFK_cjs.sessionOn(host, await open2(host, { token, principal, ...options !== void 0 ? { opening: options } : {} }, false), true, reset);
3115
3198
  }
3116
- return chunk6ZWMC2OV_cjs.sessionOn(host, await keptCell(host, token, principal), false, reset);
3199
+ return chunk6ACVHHFK_cjs.sessionOn(host, await keptCell(host, token, principal), false, reset);
3117
3200
  },
3118
3201
  snapshot: snapshotOf(host),
3119
3202
  deliver: deliverTo(host),
@@ -3142,8 +3225,8 @@ var hostConfig = (deps, shell, kept) => {
3142
3225
  };
3143
3226
  return {
3144
3227
  composition: async (principal, drafted) => {
3145
- const { resolved, saved, ...held } = await callerOf(principal);
3146
- const who = { principal, ...held, ...principal === null ? {} : { saved, ...drafted === void 0 ? {} : { drafted } } };
3228
+ const { resolved, saved, ...caller } = await callerOf(principal);
3229
+ const who = { principal, ...caller, ...principal === null ? {} : { saved, ...drafted === void 0 ? {} : { drafted } } };
3147
3230
  return { roles: resolved.roles, scope: resolved.scope, ...await running.artifactsFor(shell, who) };
3148
3231
  },
3149
3232
  artifacts: (principal) => running.sessionArtifacts(principal, () => callerOf(principal)),
@@ -3227,11 +3310,13 @@ var buildShellHosts = (deps) => {
3227
3310
  var createInternalWire = (server) => (token) => async (url, init) => {
3228
3311
  const isVex = url.split("?")[0]?.endsWith("/vex") === true;
3229
3312
  const follower = isVex && init?.signal !== void 0 ? createWireFollower(init.signal) : void 0;
3313
+ const headers = new Headers(init?.headers);
3314
+ if (token !== null) headers.set("authorization", `Bearer ${token}`);
3230
3315
  const res = await server.request(
3231
3316
  url,
3232
3317
  {
3233
3318
  method: init?.method ?? "GET",
3234
- headers: { ...init?.headers ?? {}, ...token !== null ? { Authorization: `Bearer ${token}` } : {} },
3319
+ headers,
3235
3320
  ...init?.body !== void 0 ? { body: init.body } : {}
3236
3321
  },
3237
3322
  follower === void 0 ? void 0 : { [hono$1.VEX_LIVE_ENV]: follower.live }
@@ -3271,7 +3356,7 @@ var mountRoutes = (server, { app, session, credentials, identity, running, data
3271
3356
  var INVALID_TOKEN = { refused: { status: 401, error: "invalid_token", message: "The session token did not resolve to a principal." } };
3272
3357
  var authenticateRequest = async (deps, header, request) => {
3273
3358
  if (header === void 0) return { principal: null, resolved: await deps.resolve(null) };
3274
- const token = header.startsWith("Bearer ") ? header.slice("Bearer ".length) : header;
3359
+ const token = header.replace(/^bearer +/i, "");
3275
3360
  const credential = deps.credentials.find(({ prefix }) => token.startsWith(prefix));
3276
3361
  if (credential !== void 0) {
3277
3362
  const answer = await credential.principalOf(token, request);
@@ -3323,9 +3408,9 @@ var operatorPrefix = (runtime) => {
3323
3408
  var buildSignals = ({ fabric, identity, reset, adopt: adopt2, adoptAll: adoptAll2, deliver }) => {
3324
3409
  const origin = crypto$1.randomBytes(8).toString("hex");
3325
3410
  const applyInvalidateIdentity = (principal) => {
3326
- const held = identity.invalidate(principal);
3411
+ const forgotten = identity.invalidate(principal);
3327
3412
  reset(principal);
3328
- return held;
3413
+ return forgotten;
3329
3414
  };
3330
3415
  const applyInvalidateTag = (tag) => {
3331
3416
  const forgotten = identity.invalidateTag(tag).length;
@@ -3343,9 +3428,9 @@ var buildSignals = ({ fabric, identity, reset, adopt: adopt2, adoptAll: adoptAll
3343
3428
  });
3344
3429
  return {
3345
3430
  invalidateIdentity: (principal) => {
3346
- const held = applyInvalidateIdentity(principal);
3431
+ const forgotten = applyInvalidateIdentity(principal);
3347
3432
  publish({ kind: "invalidate-identity", principal });
3348
- return held;
3433
+ return forgotten;
3349
3434
  },
3350
3435
  invalidateTag: (tag) => {
3351
3436
  const forgotten = applyInvalidateTag(tag);
@@ -3374,7 +3459,7 @@ var wireFabric = (fabric, origin, apply) => {
3374
3459
  };
3375
3460
  let refusalSaid = false;
3376
3461
  fabric.subscribe((handed) => {
3377
- const parsed = chunkPVZMCEBX_cjs.FabricMessageSchema.safeParse(handed);
3462
+ const parsed = chunk3CKBKTXA_cjs.FabricMessageSchema.safeParse(handed);
3378
3463
  if (!parsed.success) {
3379
3464
  if (refusalSaid) return;
3380
3465
  refusalSaid = true;
@@ -3414,7 +3499,7 @@ var wireFabric = (fabric, origin, apply) => {
3414
3499
 
3415
3500
  // src/server/server.ts
3416
3501
  var createServerWith = async (app, runtime, dataOf) => {
3417
- chunk6ZWMC2OV_cjs.receiveManifest(app);
3502
+ chunk6ACVHHFK_cjs.receiveManifest(app);
3418
3503
  const session = sessionVerifierOf(runtime);
3419
3504
  const revokeSessions = sessionRevokerOf(runtime);
3420
3505
  const data = await dataOf(app, runtime);
@@ -3440,10 +3525,13 @@ var buildData = (app, runtime) => createData({
3440
3525
  featureTables: featureTablesOf(app),
3441
3526
  tables: runtime.tables,
3442
3527
  grammars: app.grammars,
3528
+ upgradedColumns: app.upgradedColumns,
3443
3529
  charter: app.charter,
3444
3530
  behaviors: app.behaviors,
3445
3531
  rowRules: rowRulesBeside(app.behaviors),
3446
- telemetry: runtime.telemetry
3532
+ telemetry: runtime.telemetry,
3533
+ answerReadableRows: runtime.answerReadableRows,
3534
+ checkMovedRows: runtime.checkMovedRows
3447
3535
  });
3448
3536
  var assembleServer = async (deps) => {
3449
3537
  const stops = [];
@@ -3464,7 +3552,7 @@ var assemble = async ({ app, runtime, session, revokeSessions, data }, stops) =>
3464
3552
  `moss: \`runtime.artifactsUnusedMs\` is how long what a person generated may go unused before it is deleted: a whole number of milliseconds, at least ${2 * TOUCH_EVERY_MS} (two hours), or left out, and nothing is deleted.`
3465
3553
  );
3466
3554
  }
3467
- stops.push(startAging(runtime.pool, runtime.artifactsUnusedMs));
3555
+ stops.push(startAging(runtime.pool, runtime.artifactsUnusedMs, { sinceStart: runtime.artifactsUnusedSinceStart === true }));
3468
3556
  }
3469
3557
  const identity = buildIdentity(app, runtime, data);
3470
3558
  stops.push(identity.stop);
@@ -3534,10 +3622,13 @@ var buildRunningManifest = async (app, runtime, data, saved) => {
3534
3622
  // Polled on the clock a socket's credential is re-verified on.
3535
3623
  pointer: { read: data.pointer.read, move: data.pointer.move, ...runtime.sessionRevalidateMs !== void 0 ? { everyMs: runtime.sessionRevalidateMs } : {} },
3536
3624
  shells: [...app.shell !== void 0 ? [app.shell] : [], ...Object.values(app.pages ?? {})],
3537
- ...saved !== void 0 ? { published: saved.published().inForce, reads: { written: data.vexEntry, compile: data.compileQuery, savedOf: saved.of } } : {}
3625
+ ...saved !== void 0 ? { published: saved.published().inForce, reads: { written: data.vexEntry, compile: data.compileQuery, savedOf: saved.of } } : {},
3626
+ // Only where the app names upgradedColumns: vex refuses some reads of those when it compiles a read, and a seeded
3627
+ // read is otherwise first compiled at its first replay. An app that names none boots as before.
3628
+ ...app.upgradedColumns !== void 0 ? { compileSeeded: data.compileQuery } : {}
3538
3629
  });
3539
3630
  data.dropOnChange(running.onChange);
3540
- data.entriesHeldBy({ get: running.cacheEntry, entries: running.cacheEntries });
3631
+ data.askEntriesFirst({ get: running.cacheEntry, entries: running.cacheEntries });
3541
3632
  await running.cacheEntries();
3542
3633
  return running;
3543
3634
  };
@@ -3601,5 +3692,5 @@ exports.renderDocument = renderDocument;
3601
3692
  exports.revokeAllFor = revokeAllFor;
3602
3693
  exports.sessionCookies = sessionCookies;
3603
3694
  exports.tableStatus = tableStatus;
3604
- //# sourceMappingURL=chunk-KVXP6OTW.cjs.map
3605
- //# sourceMappingURL=chunk-KVXP6OTW.cjs.map
3695
+ //# sourceMappingURL=chunk-UVY5ZPWW.cjs.map
3696
+ //# sourceMappingURL=chunk-UVY5ZPWW.cjs.map