@niscorp/moss 0.9.3 → 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.
- package/CHANGELOG.md +110 -0
- package/DESIGN.md +58 -55
- package/DOCS.md +259 -168
- package/README.md +5 -5
- package/dist/{chunk-PVZMCEBX.cjs → chunk-3CKBKTXA.cjs} +2 -2
- package/dist/chunk-3CKBKTXA.cjs.map +1 -0
- package/dist/{chunk-TAAKHW3U.js → chunk-3PL4AH4I.js} +4 -4
- package/dist/{chunk-TAAKHW3U.js.map → chunk-3PL4AH4I.js.map} +1 -1
- package/dist/{chunk-QAHDSRPK.js → chunk-4URQHVYG.js} +2 -2
- package/dist/chunk-4URQHVYG.js.map +1 -0
- package/dist/{chunk-U43CBKKE.cjs → chunk-6ACVHHFK.cjs} +32 -30
- package/dist/chunk-6ACVHHFK.cjs.map +1 -0
- package/dist/{chunk-IUJ2TRNB.cjs → chunk-7MOEKAVC.cjs} +6 -6
- package/dist/{chunk-IUJ2TRNB.cjs.map → chunk-7MOEKAVC.cjs.map} +1 -1
- package/dist/{chunk-NCQBGK3E.cjs → chunk-BFA76AKR.cjs} +4 -4
- package/dist/chunk-BFA76AKR.cjs.map +1 -0
- package/dist/{chunk-T5BRTFKP.js → chunk-DSVRFAGX.js} +3 -3
- package/dist/{chunk-T5BRTFKP.js.map → chunk-DSVRFAGX.js.map} +1 -1
- package/dist/{chunk-IW3A2YIC.js → chunk-EYWD733E.js} +3 -3
- package/dist/{chunk-IW3A2YIC.js.map → chunk-EYWD733E.js.map} +1 -1
- package/dist/{chunk-IY5BOFLK.cjs → chunk-G4P3XEVM.cjs} +19 -19
- package/dist/chunk-G4P3XEVM.cjs.map +1 -0
- package/dist/{chunk-6QPTMKRE.cjs → chunk-HUP7CZ7X.cjs} +6 -6
- package/dist/{chunk-6QPTMKRE.cjs.map → chunk-HUP7CZ7X.cjs.map} +1 -1
- package/dist/{chunk-VKQPOZDJ.cjs → chunk-LTS4AM6T.cjs} +4 -4
- package/dist/chunk-LTS4AM6T.cjs.map +1 -0
- package/dist/{chunk-UTFOMFCH.js → chunk-MEHCZECW.js} +5 -5
- package/dist/chunk-MEHCZECW.js.map +1 -0
- package/dist/{chunk-6MZPY4X6.js → chunk-MYPK5YZR.js} +249 -199
- package/dist/chunk-MYPK5YZR.js.map +1 -0
- package/dist/{chunk-TKXYPO2Y.js → chunk-NUX5MH4I.js} +4 -4
- package/dist/chunk-NUX5MH4I.js.map +1 -0
- package/dist/{chunk-EXMOO7ZR.cjs → chunk-UVY5ZPWW.cjs} +326 -276
- package/dist/chunk-UVY5ZPWW.cjs.map +1 -0
- package/dist/{chunk-MVG333UF.js → chunk-VYYDLGQ2.js} +27 -25
- package/dist/chunk-VYYDLGQ2.js.map +1 -0
- package/dist/{chunk-NRZ3Z2FF.js → chunk-WKZWSWOJ.js} +4 -4
- package/dist/chunk-WKZWSWOJ.js.map +1 -0
- package/dist/{chunk-YGZS5B2U.cjs → chunk-XH6TSWG4.cjs} +7 -7
- package/dist/{chunk-YGZS5B2U.cjs.map → chunk-XH6TSWG4.cjs.map} +1 -1
- package/dist/client.cjs +5 -5
- package/dist/client.js +2 -2
- package/dist/{document-CuF4JqzJ.d.cts → document-DvhT_HaJ.d.cts} +1 -1
- package/dist/{document-BzXQvEc1.d.ts → document-iKaRinZE.d.ts} +1 -1
- package/dist/{index-CSEo7Tys.d.cts → index-DWj3_0Zg.d.cts} +3 -0
- package/dist/{index-CSEo7Tys.d.ts → index-DWj3_0Zg.d.ts} +3 -0
- package/dist/index.cjs +16 -16
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/integrations.cjs +27 -18
- package/dist/integrations.cjs.map +1 -1
- package/dist/integrations.d.cts +1 -1
- package/dist/integrations.d.ts +1 -1
- package/dist/integrations.js +25 -16
- package/dist/integrations.js.map +1 -1
- package/dist/node.cjs +9 -9
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +5 -5
- package/dist/protocol.cjs +5 -5
- package/dist/protocol.js +1 -1
- package/dist/terminal/dom/index.cjs +3 -3
- package/dist/terminal/dom/index.js +1 -1
- package/dist/terminal/dom/server.cjs +2 -2
- package/dist/terminal/dom/server.js +1 -1
- package/dist/terminal/index.cjs +3 -3
- package/dist/terminal/index.js +2 -2
- package/dist/terminal/ink/index.js.map +1 -1
- package/dist/terminal/react/index.cjs +9 -9
- package/dist/terminal/react/index.cjs.map +1 -1
- package/dist/terminal/react/index.js +4 -4
- package/dist/terminal/react/index.js.map +1 -1
- package/dist/terminal/react/server.cjs +4 -4
- package/dist/terminal/react/server.js +2 -2
- package/dist/terminal/tty/index.cjs +12 -12
- package/dist/terminal/tty/index.cjs.map +1 -1
- package/dist/terminal/tty/index.js +6 -6
- package/dist/terminal/tty/index.js.map +1 -1
- package/dist/terminal/vue/index.cjs +9 -9
- package/dist/terminal/vue/index.cjs.map +1 -1
- package/dist/terminal/vue/index.js +4 -4
- package/dist/terminal/vue/index.js.map +1 -1
- package/dist/terminal/vue/server.cjs +4 -4
- package/dist/terminal/vue/server.js +2 -2
- package/dist/tide.d.cts +1 -1
- package/dist/tide.d.ts +1 -1
- package/dist/unverified.cjs +4 -4
- package/dist/unverified.js +3 -3
- package/dist/vite.cjs +36 -10
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +31 -5
- package/dist/vite.js.map +1 -1
- package/package.json +13 -13
- package/dist/chunk-6MZPY4X6.js.map +0 -1
- package/dist/chunk-EXMOO7ZR.cjs.map +0 -1
- package/dist/chunk-IY5BOFLK.cjs.map +0 -1
- package/dist/chunk-MVG333UF.js.map +0 -1
- package/dist/chunk-NCQBGK3E.cjs.map +0 -1
- package/dist/chunk-NRZ3Z2FF.js.map +0 -1
- package/dist/chunk-PVZMCEBX.cjs.map +0 -1
- package/dist/chunk-QAHDSRPK.js.map +0 -1
- package/dist/chunk-TKXYPO2Y.js.map +0 -1
- package/dist/chunk-U43CBKKE.cjs.map +0 -1
- package/dist/chunk-UTFOMFCH.js.map +0 -1
- package/dist/chunk-VKQPOZDJ.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
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 =
|
|
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
|
|
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(
|
|
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 ??
|
|
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 =
|
|
63
|
-
const name =
|
|
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
|
|
168
|
-
const
|
|
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 =
|
|
182
|
+
const entry = resident.get(principal);
|
|
181
183
|
if (entry === void 0) return false;
|
|
182
184
|
untag(principal, entry.record);
|
|
183
|
-
|
|
185
|
+
resident.delete(principal);
|
|
184
186
|
return true;
|
|
185
187
|
};
|
|
186
188
|
const evictOldest = () => {
|
|
187
|
-
const oldest =
|
|
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 (
|
|
195
|
-
|
|
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) =>
|
|
205
|
+
of: (principal) => resident.get(principal),
|
|
204
206
|
touch: (principal, entry, at) => {
|
|
205
|
-
|
|
207
|
+
resident.delete(principal);
|
|
206
208
|
entry.lastSeen = at;
|
|
207
|
-
|
|
209
|
+
resident.set(principal, entry);
|
|
208
210
|
},
|
|
209
211
|
forget,
|
|
210
212
|
remember,
|
|
211
213
|
forgetAll: () => {
|
|
212
|
-
|
|
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 [...
|
|
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: () => [...
|
|
229
|
-
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
|
|
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 =
|
|
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
|
-
|
|
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)
|
|
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(() =>
|
|
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
|
|
279
|
+
return records.forget(principal);
|
|
278
280
|
},
|
|
279
281
|
invalidateAll: () => {
|
|
280
|
-
|
|
282
|
+
records.forgetAll();
|
|
281
283
|
pending.clear();
|
|
282
284
|
},
|
|
283
285
|
invalidateTag: (tag) => {
|
|
284
|
-
const principals =
|
|
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:
|
|
290
|
-
meter: () => ({ size:
|
|
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
|
|
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
|
|
586
|
-
if (
|
|
587
|
-
if ("mutation" in entry) return
|
|
588
|
-
return
|
|
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 =
|
|
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
|
|
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
|
|
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: (
|
|
716
|
-
|
|
720
|
+
askFirst: (first) => {
|
|
721
|
+
askedFirst = first;
|
|
717
722
|
},
|
|
718
723
|
cache: {
|
|
719
|
-
get: async (key, scope) => await
|
|
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);
|
|
@@ -872,7 +877,7 @@ var createExecuteAs = (deps) => async (role, fingerprint, context, scope = {}) =
|
|
|
872
877
|
locked: true,
|
|
873
878
|
scopePolicy: policy,
|
|
874
879
|
policyForReach: (reach) => deps.policyAtReach(roles, reach),
|
|
875
|
-
mutations: { client: deps.db, policy },
|
|
880
|
+
mutations: { client: deps.db, policy, ...deps.checkMovedRows === false ? { checkMovedRows: false } : {} },
|
|
876
881
|
...deps.onExecute !== void 0 ? { onExecute: deps.onExecute } : {}
|
|
877
882
|
},
|
|
878
883
|
{ fingerprint, context },
|
|
@@ -975,7 +980,12 @@ var createVexRoutes = (deps) => {
|
|
|
975
980
|
getPolicy: deps.policy,
|
|
976
981
|
getPolicyForReach: deps.policyAtReach,
|
|
977
982
|
...deps.onExecute !== void 0 ? { onExecute: deps.onExecute } : {},
|
|
978
|
-
mutations: {
|
|
983
|
+
mutations: {
|
|
984
|
+
client: deps.db,
|
|
985
|
+
onWrite: deps.writes.report,
|
|
986
|
+
...deps.answerReadableRows === true ? { answerReadableRows: true } : {},
|
|
987
|
+
...deps.checkMovedRows === false ? { checkMovedRows: false } : {}
|
|
988
|
+
}
|
|
979
989
|
})
|
|
980
990
|
);
|
|
981
991
|
};
|
|
@@ -1009,7 +1019,7 @@ var createIntentAnswers = (deps) => {
|
|
|
1009
1019
|
};
|
|
1010
1020
|
return async (writers, asked, caller) => (await engineFor(writers)).execute(
|
|
1011
1021
|
"fingerprint" in asked ? { fingerprint: asked.fingerprint, context: asked.context ?? {} } : { intent: asked.intent, shape: asked.shape, context: asked.context ?? {} },
|
|
1012
|
-
{ scope: caller.scope, scopePolicy: caller.policy }
|
|
1022
|
+
{ scope: caller.scope, scopePolicy: caller.policy, ...caller.policyAtReach !== void 0 ? { policyForReach: caller.policyAtReach } : {} }
|
|
1013
1023
|
);
|
|
1014
1024
|
};
|
|
1015
1025
|
|
|
@@ -1093,7 +1103,7 @@ var createDataWith = (prepared, config) => {
|
|
|
1093
1103
|
const { grammars, engine, grants } = prepared;
|
|
1094
1104
|
const governed = { charter: config.charter, behaviors: { ...config.behaviors, ...config.rowRules } };
|
|
1095
1105
|
const policies = createPolicies({ ...governed, grants });
|
|
1096
|
-
const emit =
|
|
1106
|
+
const emit = chunk3CKBKTXA_cjs.emitterOf(config.telemetry);
|
|
1097
1107
|
const onExecute = emit === void 0 ? void 0 : (record) => emit(vexRecordToSpan(record));
|
|
1098
1108
|
const writes = createWriteNotifier();
|
|
1099
1109
|
const answering = lazyIntentAnswers(prepared, config);
|
|
@@ -1107,7 +1117,7 @@ var createDataWith = (prepared, config) => {
|
|
|
1107
1117
|
return {
|
|
1108
1118
|
grants,
|
|
1109
1119
|
grammars,
|
|
1110
|
-
|
|
1120
|
+
askEntriesFirst: prepared.askFirst,
|
|
1111
1121
|
fingerprints: async () => await engine.cache.keys?.() ?? [],
|
|
1112
1122
|
policyOf: policies.of,
|
|
1113
1123
|
// Compiled afresh and not taken from the kept ones: the caller owns its
|
|
@@ -1123,9 +1133,10 @@ var createDataWith = (prepared, config) => {
|
|
|
1123
1133
|
db: config.db,
|
|
1124
1134
|
policyFor: (roles) => policies.of(callerOfRoles(roles)),
|
|
1125
1135
|
policyAtReach: (roles, reach) => policies.atReach(callerOfRoles(roles), reach),
|
|
1126
|
-
...onExecute !== void 0 ? { onExecute } : {}
|
|
1136
|
+
...onExecute !== void 0 ? { onExecute } : {},
|
|
1137
|
+
...config.checkMovedRows === false ? { checkMovedRows: false } : {}
|
|
1127
1138
|
}),
|
|
1128
|
-
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 }),
|
|
1129
1140
|
ownEntries: async (feature, entries) => ownEntries({ owner: `the feature "${feature}"`, entries, tables: tablesOf(feature) }, onExecute),
|
|
1130
1141
|
artifactEntries: (entries, rules) => ownEntries({ owner: "the artifactory", entries, tables: ARTIFACT_TABLES, rules }, onExecute),
|
|
1131
1142
|
routes: (routing) => createVexRoutes({
|
|
@@ -1136,7 +1147,9 @@ var createDataWith = (prepared, config) => {
|
|
|
1136
1147
|
policy: (c) => policies.of(routing.caller(c)),
|
|
1137
1148
|
policyAtReach: (c, reach) => policies.atReach(routing.caller(c), reach),
|
|
1138
1149
|
...onExecute !== void 0 ? { onExecute } : {},
|
|
1139
|
-
writes
|
|
1150
|
+
writes,
|
|
1151
|
+
...config.answerReadableRows === true ? { answerReadableRows: true } : {},
|
|
1152
|
+
...config.checkMovedRows === false ? { checkMovedRows: false } : {}
|
|
1140
1153
|
}),
|
|
1141
1154
|
upgradeStore: createUpgradeStore(prepared, tablesOf),
|
|
1142
1155
|
onWrite: writes.subscribe,
|
|
@@ -1152,10 +1165,10 @@ var embedSnapshot = (snapshot, principal, path) => {
|
|
|
1152
1165
|
const { frame, trees, seed, live } = snapshot;
|
|
1153
1166
|
const carried = { frame, trees, principal: principal !== null, live, ...seed !== void 0 ? { seed } : {}, ...path !== void 0 ? { path } : {} };
|
|
1154
1167
|
const text = JSON.stringify(carried).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
1155
|
-
return `<script type="application/json" id="${
|
|
1168
|
+
return `<script type="application/json" id="${chunkBFA76AKR_cjs.SNAPSHOT_ELEMENT_ID}">${text}</script>`;
|
|
1156
1169
|
};
|
|
1157
1170
|
var documentHeaders = (principal) => principal === null ? { "cache-control": "no-cache", vary: "Cookie" } : { "cache-control": "private, no-store", vary: "Cookie" };
|
|
1158
|
-
var
|
|
1171
|
+
var screenInRoot = (root) => {
|
|
1159
1172
|
const closing = root.lastIndexOf("</");
|
|
1160
1173
|
if (closing <= 0 || !root.startsWith("<") || root[closing - 1] !== ">" || !root.endsWith(">")) return void 0;
|
|
1161
1174
|
return (screen) => `${root.slice(0, closing)}${screen}${root.slice(closing)}`;
|
|
@@ -1163,12 +1176,12 @@ var rootHolding = (root) => {
|
|
|
1163
1176
|
var escapeAttribute = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
1164
1177
|
var renderDocument = async (config) => {
|
|
1165
1178
|
const { server, template, request, draw } = config;
|
|
1166
|
-
const tokenKey = config.tokenKey ??
|
|
1179
|
+
const tokenKey = config.tokenKey ?? chunkBFA76AKR_cjs.DEFAULT_TOKEN_KEY;
|
|
1167
1180
|
const root = config.root ?? DEFAULT_ROOT;
|
|
1168
1181
|
const undrawn = { html: template, headers: documentHeaders(null), drawn: false, principal: null };
|
|
1169
1182
|
if (!template.includes(root)) return undrawn;
|
|
1170
|
-
const
|
|
1171
|
-
if (
|
|
1183
|
+
const inRoot = screenInRoot(root);
|
|
1184
|
+
if (inRoot === void 0) {
|
|
1172
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.`);
|
|
1173
1186
|
return undrawn;
|
|
1174
1187
|
}
|
|
@@ -1185,7 +1198,7 @@ var renderDocument = async (config) => {
|
|
|
1185
1198
|
});
|
|
1186
1199
|
const screen = await draw(snapshot);
|
|
1187
1200
|
const attributes = Object.entries(config.htmlAttributes?.(snapshot) ?? {}).map(([name, value]) => ` ${name}="${escapeAttribute(value)}"`).join("");
|
|
1188
|
-
const placed = template.replace(root, () => `${
|
|
1201
|
+
const placed = template.replace(root, () => `${inRoot(screen)}${embedSnapshot(snapshot, principal, request.path)}`).replace(/<html([^>]*)>/, (whole, existing) => attributes === "" ? whole : `<html${existing}${attributes}>`);
|
|
1189
1202
|
const head = document.headOf({ frame: () => snapshot.frame, canvasTree: (id) => snapshot.trees[id] ?? [] });
|
|
1190
1203
|
for (const why of head?.refused ?? []) console.error(`[moss/document] "${request.path}" \u2014 ${why}`);
|
|
1191
1204
|
const html = document.placeHead(placed, head?.elements, { ...config.site !== void 0 ? { site: config.site } : {}, path: request.path });
|
|
@@ -1294,15 +1307,15 @@ var isKept = (layout) => layout !== void 0 && layout !== null && typeof layout !
|
|
|
1294
1307
|
var shellWithStoredLayouts = (shell) => {
|
|
1295
1308
|
const layouts = {};
|
|
1296
1309
|
const frame = shell.layout;
|
|
1297
|
-
if (isKept(frame)) layouts[
|
|
1310
|
+
if (isKept(frame)) layouts[chunk6ACVHHFK_cjs.FRAME_LAYOUT_REF] = frame;
|
|
1298
1311
|
const canvases = shell.canvases.map((canvas) => {
|
|
1299
1312
|
const layout = canvas.actionLayout;
|
|
1300
1313
|
if (!isKept(layout)) return canvas;
|
|
1301
|
-
const ref =
|
|
1314
|
+
const ref = chunk6ACVHHFK_cjs.canvasLayoutRef(canvas.id);
|
|
1302
1315
|
layouts[ref] = layout;
|
|
1303
1316
|
return { ...canvas, actionLayout: ref };
|
|
1304
1317
|
});
|
|
1305
|
-
return { canvases, ...isKept(frame) ? { frame:
|
|
1318
|
+
return { canvases, ...isKept(frame) ? { frame: chunk6ACVHHFK_cjs.FRAME_LAYOUT_REF } : typeof frame === "string" ? { frame } : {}, layouts };
|
|
1306
1319
|
};
|
|
1307
1320
|
var slottedIn = /* @__PURE__ */ new WeakMap();
|
|
1308
1321
|
var canvasesSlottedIn = (layout) => {
|
|
@@ -1353,22 +1366,22 @@ var createComponentNames = (read2) => {
|
|
|
1353
1366
|
var SavedLayoutSchema = zod.z.strictObject({ ref: zod.z.string(), layout: nova.LayoutNodeSchema, use: zod.z.boolean().optional() });
|
|
1354
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;
|
|
1355
1368
|
var actionAtRef = (actions, layouts) => (ref) => {
|
|
1356
|
-
const id =
|
|
1369
|
+
const id = chunk6ACVHHFK_cjs.actionOfLayoutRef(ref);
|
|
1357
1370
|
const action = id !== void 0 && Object.hasOwn(actions, id) ? actions[id] : void 0;
|
|
1358
1371
|
const layout = Object.hasOwn(layouts, ref) ? layouts[ref] : void 0;
|
|
1359
1372
|
return action === void 0 || layout === void 0 ? void 0 : { ...action, layout };
|
|
1360
1373
|
};
|
|
1361
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>".`;
|
|
1362
|
-
var targetAt = (ref,
|
|
1363
|
-
if (
|
|
1364
|
-
const action =
|
|
1365
|
-
return action === void 0 ? void 0 : { kit:
|
|
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 };
|
|
1366
1379
|
};
|
|
1367
1380
|
var refOf = (body) => {
|
|
1368
1381
|
const ref = reflect.isRecord(body) ? body["ref"] : void 0;
|
|
1369
1382
|
return typeof ref === "string" ? ref : void 0;
|
|
1370
1383
|
};
|
|
1371
|
-
var readLayout = (body,
|
|
1384
|
+
var readLayout = (body, checks) => {
|
|
1372
1385
|
if (strata.exceedsDepth(body)) return { refusal: strata.depthRefusal() };
|
|
1373
1386
|
const parsed = SavedLayoutSchema.safeParse(body);
|
|
1374
1387
|
if (!parsed.success) {
|
|
@@ -1376,11 +1389,11 @@ var readLayout = (body, heldTo) => {
|
|
|
1376
1389
|
return { refusal: first === void 0 ? "no reason given" : `${first.path.join(".") || "(the body)"}: ${first.message}` };
|
|
1377
1390
|
}
|
|
1378
1391
|
const { ref, layout } = parsed.data;
|
|
1379
|
-
const target = targetAt(ref,
|
|
1392
|
+
const target = targetAt(ref, checks);
|
|
1380
1393
|
if (target === void 0) return { refusal: nothingKeptUnder(ref) };
|
|
1381
|
-
const misfits =
|
|
1394
|
+
const misfits = chunk6ACVHHFK_cjs.layoutMisfits(layout, target.kit);
|
|
1382
1395
|
if (misfits.length > 0) return { refusal: misfits.join("; ") };
|
|
1383
|
-
const named =
|
|
1396
|
+
const named = chunk6ACVHHFK_cjs.layoutNameRefusal(layout);
|
|
1384
1397
|
if (named !== void 0) return { refusal: `it ${named}` };
|
|
1385
1398
|
const { action } = target;
|
|
1386
1399
|
if (action === void 0) return { layout: parsed.data };
|
|
@@ -1389,10 +1402,10 @@ var readLayout = (body, heldTo) => {
|
|
|
1389
1402
|
if (added.length > 0) return { refusal: added.join("; ") };
|
|
1390
1403
|
return { layout: parsed.data };
|
|
1391
1404
|
};
|
|
1392
|
-
var loaded = (version, { whose,
|
|
1405
|
+
var loaded = (version, { whose, checks, say }) => {
|
|
1393
1406
|
const ref = refOf(version.body);
|
|
1394
|
-
if (ref === void 0 || targetAt(ref,
|
|
1395
|
-
const read2 = version.unread !== void 0 ? { refusal: version.unread } : readLayout(version.body,
|
|
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);
|
|
1396
1409
|
if ("layout" in read2) return read2.layout;
|
|
1397
1410
|
(say ?? console.error)(`[moss] the layout "${version.id}" ${whose} is left out: ${read2.refusal}`);
|
|
1398
1411
|
return void 0;
|
|
@@ -1404,8 +1417,8 @@ var layoutsInUse = (inForce2, drawnFor) => {
|
|
|
1404
1417
|
for (const version of inForce2.filter(isInUse)) {
|
|
1405
1418
|
const ref = refOf(version.body);
|
|
1406
1419
|
if (ref === void 0) continue;
|
|
1407
|
-
const
|
|
1408
|
-
if (
|
|
1420
|
+
const latest = marked.get(ref);
|
|
1421
|
+
if (latest === void 0 || isLater(version, latest)) marked.set(ref, version);
|
|
1409
1422
|
}
|
|
1410
1423
|
const layouts = {};
|
|
1411
1424
|
for (const version of marked.values()) {
|
|
@@ -1414,14 +1427,14 @@ var layoutsInUse = (inForce2, drawnFor) => {
|
|
|
1414
1427
|
}
|
|
1415
1428
|
return layouts;
|
|
1416
1429
|
};
|
|
1417
|
-
var generatedId = () => `${
|
|
1430
|
+
var generatedId = () => `${chunk6ACVHHFK_cjs.GENERATED_ID_PREFIX}${crypto$1.randomUUID()}`;
|
|
1418
1431
|
var VEX_ROUTE = /^\/api\/(?:[A-Za-z0-9_-]+\/)?vex$/;
|
|
1419
|
-
var endpointRefusals = async (endpoints,
|
|
1432
|
+
var endpointRefusals = async (endpoints, checks) => {
|
|
1420
1433
|
const refusals = [];
|
|
1421
1434
|
for (const [name, endpoint] of Object.entries(endpoints ?? {})) {
|
|
1422
1435
|
if ("fn" in endpoint) {
|
|
1423
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`);
|
|
1424
|
-
else if (!
|
|
1437
|
+
else if (!checks.mayCall(endpoint.fn)) refusals.push(`endpoint "${name}" calls the function "${endpoint.fn}", which its owner\u2019s roles do not grant`);
|
|
1425
1438
|
continue;
|
|
1426
1439
|
}
|
|
1427
1440
|
if (endpoint.method !== "POST" || !VEX_ROUTE.test(endpoint.url)) {
|
|
@@ -1433,10 +1446,10 @@ var endpointRefusals = async (endpoints, heldTo) => {
|
|
|
1433
1446
|
refusals.push(`endpoint "${name}" names no fingerprint`);
|
|
1434
1447
|
continue;
|
|
1435
1448
|
}
|
|
1436
|
-
const entry =
|
|
1449
|
+
const entry = checks.entryOf(fingerprint);
|
|
1437
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`);
|
|
1438
1451
|
else if ("mutation" in entry) refusals.push(`endpoint "${name}" replays "${fingerprint}", which is a write, and what is generated only reads`);
|
|
1439
|
-
else if (!(await
|
|
1452
|
+
else if (!(await checks.replayable()).has(fingerprint)) refusals.push(`endpoint "${name}" replays "${fingerprint}", which its owner may not replay`);
|
|
1440
1453
|
}
|
|
1441
1454
|
return refusals;
|
|
1442
1455
|
};
|
|
@@ -1451,33 +1464,33 @@ var parsedUnder = (schema, body, id, more = {}) => {
|
|
|
1451
1464
|
return { refusal: first === void 0 ? "no reason given" : `${first.path.join(".") || "(the body)"}: ${first.message}` };
|
|
1452
1465
|
};
|
|
1453
1466
|
var layoutRefusals = (layout, kit) => {
|
|
1454
|
-
const named =
|
|
1455
|
-
return [...layout === void 0 || typeof layout === "string" ? [] :
|
|
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}`]];
|
|
1456
1469
|
};
|
|
1457
1470
|
var passedOrRefused = (body, refusals) => refusals.length > 0 ? { refusal: refusals.join("; ") } : { body };
|
|
1458
|
-
var readAction = async (body, id,
|
|
1471
|
+
var readAction = async (body, id, checks) => {
|
|
1459
1472
|
const parsed = parsedUnder(nova.ActionDefinitionSchema, body, id);
|
|
1460
1473
|
if ("refusal" in parsed) return parsed;
|
|
1461
1474
|
const action = parsed.body;
|
|
1462
1475
|
return passedOrRefused(action, [
|
|
1463
|
-
...layoutRefusals(action.layout,
|
|
1464
|
-
...await endpointRefusals(action.endpoints,
|
|
1465
|
-
...nova.auditAction(action, { catalog:
|
|
1476
|
+
...layoutRefusals(action.layout, checks.kit),
|
|
1477
|
+
...await endpointRefusals(action.endpoints, checks),
|
|
1478
|
+
...nova.auditAction(action, { catalog: checks.catalog() }).issues
|
|
1466
1479
|
]);
|
|
1467
1480
|
};
|
|
1468
|
-
var readFragment = async (body, id,
|
|
1481
|
+
var readFragment = async (body, id, checks) => {
|
|
1469
1482
|
const parsed = parsedUnder(nova.ActionFragmentSchema, body, id, { kind: "fragment" });
|
|
1470
1483
|
if ("refusal" in parsed) return parsed;
|
|
1471
1484
|
const fragment = parsed.body;
|
|
1472
|
-
return passedOrRefused(fragment, [...layoutRefusals(fragment.layout,
|
|
1485
|
+
return passedOrRefused(fragment, [...layoutRefusals(fragment.layout, checks.kit), ...await endpointRefusals(fragment.endpoints, checks)]);
|
|
1473
1486
|
};
|
|
1474
1487
|
var generatedIn = (inForce2, kind) => inForce2.filter((version) => version.kind === kind && version.body !== null);
|
|
1475
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"] : {} }));
|
|
1476
|
-
var generatedInForce = async (inForce2,
|
|
1489
|
+
var generatedInForce = async (inForce2, checks, whose) => {
|
|
1477
1490
|
const passed = async (kind, read2) => {
|
|
1478
1491
|
const kept = {};
|
|
1479
1492
|
for (const version of generatedIn(inForce2, kind)) {
|
|
1480
|
-
const answered = version.unread !== void 0 ? { refusal: version.unread } : await read2(version.body, version.id,
|
|
1493
|
+
const answered = version.unread !== void 0 ? { refusal: version.unread } : await read2(version.body, version.id, checks);
|
|
1481
1494
|
if ("body" in answered) kept[version.id] = answered.body;
|
|
1482
1495
|
else if (whose !== void 0) console.error(`[moss] the ${kind} "${version.id}" ${whose} is left out: ${answered.refusal}`);
|
|
1483
1496
|
}
|
|
@@ -1519,7 +1532,7 @@ var createEntriesInForce = (own, compileRead) => {
|
|
|
1519
1532
|
return {
|
|
1520
1533
|
list: () => list,
|
|
1521
1534
|
byFingerprint: () => byFingerprint,
|
|
1522
|
-
|
|
1535
|
+
hasSet: (source) => sets.has(source),
|
|
1523
1536
|
withSet: (source, handed) => mergedEntries(own, new Map([...sets, [source, handed]])),
|
|
1524
1537
|
takeSet: (source, handed, taken) => {
|
|
1525
1538
|
refuseUnrunnable(handed, compileRead, "Refresh refused \u2014 seeded reads that do not run:");
|
|
@@ -1550,8 +1563,8 @@ var compiledRead = async (fingerprint, read2) => {
|
|
|
1550
1563
|
return entry;
|
|
1551
1564
|
};
|
|
1552
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`;
|
|
1553
|
-
var readSaved = async (body, fingerprint,
|
|
1554
|
-
if (
|
|
1566
|
+
var readSaved = async (body, fingerprint, checks) => {
|
|
1567
|
+
if (checks.isAppEntry(fingerprint)) return { refusal: shippedRefusal(fingerprint) };
|
|
1555
1568
|
if (strata.exceedsDepth(body)) return { refusal: strata.depthRefusal() };
|
|
1556
1569
|
const parsed = SavedReadSchema.safeParse(body);
|
|
1557
1570
|
if (!parsed.success) {
|
|
@@ -1559,16 +1572,16 @@ var readSaved = async (body, fingerprint, heldTo) => {
|
|
|
1559
1572
|
return { refusal: first === void 0 ? "no reason given" : `${first.path.join(".") || "(the body)"}: ${first.message}` };
|
|
1560
1573
|
}
|
|
1561
1574
|
try {
|
|
1562
|
-
|
|
1575
|
+
checks.sources.compile(parsed.data.dsl);
|
|
1563
1576
|
await compiledRead(fingerprint, parsed.data);
|
|
1564
1577
|
} catch (error) {
|
|
1565
1578
|
return { refusal: sentenceOf(error) };
|
|
1566
1579
|
}
|
|
1567
1580
|
return { body: parsed.data };
|
|
1568
1581
|
};
|
|
1569
|
-
var readWritten = async (fingerprint,
|
|
1570
|
-
if (
|
|
1571
|
-
const entry = await
|
|
1582
|
+
var readWritten = async (fingerprint, checks) => {
|
|
1583
|
+
if (checks.isAppEntry(fingerprint)) return { refusal: shippedRefusal(fingerprint) };
|
|
1584
|
+
const entry = await checks.sources.written(fingerprint);
|
|
1572
1585
|
if (entry === void 0 || entry.requestHash === void 0) return { refusal: `vex holds no query it wrote under "${fingerprint}"` };
|
|
1573
1586
|
if (entry.kind !== "ok") return { refusal: `vex found no query to answer under "${fingerprint}"` };
|
|
1574
1587
|
if (entry.shape !== void 0 && entry.mapping === void 0) {
|
|
@@ -1584,7 +1597,7 @@ var readWritten = async (fingerprint, heldTo) => {
|
|
|
1584
1597
|
...entry.refresh !== void 0 ? { refresh: entry.refresh } : {}
|
|
1585
1598
|
},
|
|
1586
1599
|
fingerprint,
|
|
1587
|
-
|
|
1600
|
+
checks
|
|
1588
1601
|
);
|
|
1589
1602
|
};
|
|
1590
1603
|
var answeredRead = async (fingerprint, body) => {
|
|
@@ -1592,11 +1605,11 @@ var answeredRead = async (fingerprint, body) => {
|
|
|
1592
1605
|
const parsed = SavedReadSchema.safeParse(body);
|
|
1593
1606
|
return parsed.success ? compiledRead(fingerprint, parsed.data) : void 0;
|
|
1594
1607
|
};
|
|
1595
|
-
var readsInForce = async (inForce2,
|
|
1608
|
+
var readsInForce = async (inForce2, checks, whose) => {
|
|
1596
1609
|
const reads = /* @__PURE__ */ new Map();
|
|
1597
1610
|
for (const version of inForce2) {
|
|
1598
1611
|
if (version.kind !== "read" || version.body === null) continue;
|
|
1599
|
-
const read2 = version.unread !== void 0 ? { refusal: version.unread } : await readSaved(version.body, version.id,
|
|
1612
|
+
const read2 = version.unread !== void 0 ? { refusal: version.unread } : await readSaved(version.body, version.id, checks);
|
|
1600
1613
|
if ("body" in read2) reads.set(version.id, read2.body);
|
|
1601
1614
|
else if (whose !== void 0) console.error(`[moss] the read "${version.id}" ${whose} is left out: ${read2.refusal}`);
|
|
1602
1615
|
}
|
|
@@ -1623,18 +1636,18 @@ var listed = (version, kind) => ({
|
|
|
1623
1636
|
body: version.body
|
|
1624
1637
|
});
|
|
1625
1638
|
var withoutMark = ({ use: _mark, ...layout }) => layout;
|
|
1626
|
-
var checked = async (kind, id, body,
|
|
1639
|
+
var checked = async (kind, id, body, checks) => {
|
|
1627
1640
|
if (kind === "layout") {
|
|
1628
|
-
const read3 = readLayout(body,
|
|
1641
|
+
const read3 = readLayout(body, checks.layouts);
|
|
1629
1642
|
if ("refusal" in read3) throw new Error(`moss: the layout for "${refOf(body) ?? "(no ref)"}" is refused: ${read3.refusal}`);
|
|
1630
1643
|
return read3.layout;
|
|
1631
1644
|
}
|
|
1632
1645
|
if (kind === "read") {
|
|
1633
|
-
const read3 =
|
|
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);
|
|
1634
1647
|
if ("refusal" in read3) throw new Error(`moss: the read "${id}" is refused: ${read3.refusal}`);
|
|
1635
1648
|
return read3.body;
|
|
1636
1649
|
}
|
|
1637
|
-
const read2 = await (kind === "action" ? readAction : readFragment)(body, id,
|
|
1650
|
+
const read2 = await (kind === "action" ? readAction : readFragment)(body, id, checks.generated);
|
|
1638
1651
|
if ("refusal" in read2) throw new Error(`moss: the ${kind} is refused: ${read2.refusal}`);
|
|
1639
1652
|
return read2.body;
|
|
1640
1653
|
};
|
|
@@ -1651,19 +1664,19 @@ var unmarked = (versions, inForce2) => {
|
|
|
1651
1664
|
const layouts = versions.filter((version) => version.kind === "layout");
|
|
1652
1665
|
const marked = markedRefs(layouts);
|
|
1653
1666
|
const saved = new Set(layouts.map((version) => version.id));
|
|
1654
|
-
const takenOut = inForce2.flatMap((
|
|
1667
|
+
const takenOut = inForce2.flatMap((version) => isInUse(version) && saved.has(version.id) ? [refOf(version.body)] : []);
|
|
1655
1668
|
const decided = /* @__PURE__ */ new Set([...marked, ...takenOut]);
|
|
1656
|
-
return inForce2.flatMap((
|
|
1657
|
-
const ref = refOf(
|
|
1658
|
-
if (!isInUse(
|
|
1659
|
-
return [{ kind: "layout", id:
|
|
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 }];
|
|
1660
1673
|
});
|
|
1661
1674
|
};
|
|
1662
1675
|
var idsOf = (versions) => versions.map(({ kind, id }) => ({ kind, id }));
|
|
1663
|
-
var savingFor = ({
|
|
1664
|
-
const
|
|
1665
|
-
if (
|
|
1666
|
-
return
|
|
1676
|
+
var savingFor = ({ owner, whose, kinds, written, defaults }, nobody) => {
|
|
1677
|
+
const requireOwner = () => {
|
|
1678
|
+
if (owner === void 0) throw new Error(nobody);
|
|
1679
|
+
return owner;
|
|
1667
1680
|
};
|
|
1668
1681
|
const ofKind = (kind) => {
|
|
1669
1682
|
const known = kinds.find((one) => one === kind);
|
|
@@ -1675,13 +1688,13 @@ var savingFor = ({ holder, whose, kinds, written, defaults }, nobody) => {
|
|
|
1675
1688
|
if (!asked.success) throw new Error("moss: a save holds one or several artifacts, each `{ kind, id?, body }` and nothing else.");
|
|
1676
1689
|
return asked.data.map((artifact) => ({ ...artifact, kind: ofKind(artifact.kind) }));
|
|
1677
1690
|
};
|
|
1678
|
-
const checkedEach = async (asked, inForce2,
|
|
1691
|
+
const checkedEach = async (asked, inForce2, checks) => {
|
|
1679
1692
|
const versions = [];
|
|
1680
1693
|
for (const { kind, id: named2, body } of asked) {
|
|
1681
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.`);
|
|
1682
1695
|
const id = named2 ?? NEW_ID[kind]();
|
|
1683
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.`);
|
|
1684
|
-
versions.push({ kind, id, body: await checked(kind, id, body,
|
|
1697
|
+
versions.push({ kind, id, body: await checked(kind, id, body, checks), copiedFrom: null });
|
|
1685
1698
|
}
|
|
1686
1699
|
const named = (kind) => kind !== "read" && (defaults === void 0 || kind === "layout");
|
|
1687
1700
|
const notTheirs = asked.find(({ kind, id }) => id !== void 0 && named(kind) && !inForce2.some((version) => version.kind === kind && version.id === id));
|
|
@@ -1698,25 +1711,25 @@ var savingFor = ({ holder, whose, kinds, written, defaults }, nobody) => {
|
|
|
1698
1711
|
written();
|
|
1699
1712
|
return save2;
|
|
1700
1713
|
};
|
|
1701
|
-
return {
|
|
1714
|
+
return { requireOwner, ofKind, askedOf, checkedEach, write };
|
|
1702
1715
|
};
|
|
1703
1716
|
var savedArtifacts = (deps) => {
|
|
1704
|
-
const {
|
|
1705
|
-
const {
|
|
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.");
|
|
1706
1719
|
return {
|
|
1707
1720
|
save: async (artifacts) => {
|
|
1708
|
-
const
|
|
1721
|
+
const ownerOf = requireOwner();
|
|
1709
1722
|
const asked = askedOf(artifacts);
|
|
1710
|
-
const { saved,
|
|
1723
|
+
const { saved, checks } = await ownerOf();
|
|
1711
1724
|
const inForce2 = await saved.inForce();
|
|
1712
|
-
const versions = await checkedEach(asked, inForce2, await
|
|
1725
|
+
const versions = await checkedEach(asked, inForce2, await checks(inForce2));
|
|
1713
1726
|
await defaults?.verify(versions, inForce2);
|
|
1714
1727
|
return { save: await write(saved, versions, inForce2), artifacts: idsOf(versions) };
|
|
1715
1728
|
},
|
|
1716
1729
|
list: async (kind) => {
|
|
1717
1730
|
const only = kind === void 0 ? void 0 : ofKind(kind);
|
|
1718
|
-
if (
|
|
1719
|
-
const inForce2 = await (await
|
|
1731
|
+
if (owner === void 0) return [];
|
|
1732
|
+
const inForce2 = await (await owner()).saved.inForce();
|
|
1720
1733
|
return inForce2.flatMap((version) => {
|
|
1721
1734
|
const known = kinds.find((one) => one === version.kind);
|
|
1722
1735
|
return version.body !== null && known !== void 0 && (only === void 0 || known === only) ? [listed(version, known)] : [];
|
|
@@ -1724,26 +1737,26 @@ var savedArtifacts = (deps) => {
|
|
|
1724
1737
|
},
|
|
1725
1738
|
history: async (kind, id) => {
|
|
1726
1739
|
const known = ofKind(kind);
|
|
1727
|
-
if (
|
|
1728
|
-
return (await (await
|
|
1740
|
+
if (owner === void 0) return [];
|
|
1741
|
+
return (await (await owner()).saved.history(known, id)).map((version) => listed(version, known));
|
|
1729
1742
|
},
|
|
1730
1743
|
restore: async (kind, id, save2) => {
|
|
1731
|
-
const
|
|
1744
|
+
const ownerOf = requireOwner();
|
|
1732
1745
|
const known = ofKind(kind);
|
|
1733
|
-
const { saved,
|
|
1746
|
+
const { saved, checks } = await ownerOf();
|
|
1734
1747
|
const version = SaveIdSchema.safeParse(save2).success ? (await saved.history(known, id, save2))[0] : void 0;
|
|
1735
1748
|
if (version === void 0) throw new Error(`moss: no ${known} "${id}" ${whose} was saved in "${save2}".`);
|
|
1736
1749
|
if (version.unread !== void 0) throw new Error(`moss: the ${known} "${id}" saved in "${save2}" cannot be read: ${version.unread}`);
|
|
1737
1750
|
const inForce2 = await saved.inForce();
|
|
1738
|
-
const body = version.body === null ? null : await checked(known, id, version.body, await
|
|
1751
|
+
const body = version.body === null ? null : await checked(known, id, version.body, await checks(inForce2));
|
|
1739
1752
|
const restored = { kind: known, id, body, copiedFrom: version.save };
|
|
1740
1753
|
await defaults?.verify([restored], inForce2);
|
|
1741
1754
|
return { save: await write(saved, [restored], inForce2) };
|
|
1742
1755
|
},
|
|
1743
1756
|
reset: async (kind, id) => {
|
|
1744
|
-
const
|
|
1757
|
+
const ownerOf = requireOwner();
|
|
1745
1758
|
const known = ofKind(kind);
|
|
1746
|
-
const { saved } = await
|
|
1759
|
+
const { saved } = await ownerOf();
|
|
1747
1760
|
const inForce2 = await saved.inForce();
|
|
1748
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.`);
|
|
1749
1762
|
return { save: await write(saved, [{ kind: known, id, body: null, copiedFrom: null }], inForce2) };
|
|
@@ -1758,15 +1771,15 @@ var laidOver = (inForce2, drafted = []) => drafted.length === 0 ? inForce2 : [
|
|
|
1758
1771
|
...drafted.map((one) => ({ ...one, save: "draft", copiedFrom: null, createdAt: LATER_THAN_ANY_SAVE }))
|
|
1759
1772
|
];
|
|
1760
1773
|
var draftSaving = (deps) => {
|
|
1761
|
-
const {
|
|
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.");
|
|
1762
1775
|
return {
|
|
1763
|
-
// The draft with these added to it. Each is checked beside what is in force for its
|
|
1776
|
+
// The draft with these added to it. Each is checked beside what is in force for its owner with the draft laid over.
|
|
1764
1777
|
add: async (artifacts, drafted) => {
|
|
1765
|
-
const
|
|
1778
|
+
const ownerOf = requireOwner();
|
|
1766
1779
|
const asked = askedOf(artifacts);
|
|
1767
|
-
const { saved,
|
|
1780
|
+
const { saved, checks } = await ownerOf();
|
|
1768
1781
|
const inForce2 = laidOver(await saved.inForce(), drafted);
|
|
1769
|
-
const versions = await checkedEach(asked, inForce2, await
|
|
1782
|
+
const versions = await checkedEach(asked, inForce2, await checks(inForce2));
|
|
1770
1783
|
const added = versions.map(({ kind, id, body }) => ({ kind, id, body }));
|
|
1771
1784
|
const marked = new Set(markedRefs(added));
|
|
1772
1785
|
const kept = drafted.flatMap((one) => {
|
|
@@ -1778,15 +1791,15 @@ var draftSaving = (deps) => {
|
|
|
1778
1791
|
return { drafted: [...kept, ...added], added: idsOf(versions) };
|
|
1779
1792
|
},
|
|
1780
1793
|
save: async (drafted) => {
|
|
1781
|
-
const
|
|
1794
|
+
const ownerOf = requireOwner();
|
|
1782
1795
|
if (drafted.length === 0) throw new Error("moss: the draft holds nothing to save.");
|
|
1783
|
-
const { saved,
|
|
1796
|
+
const { saved, checks } = await ownerOf();
|
|
1784
1797
|
const inForce2 = await saved.inForce();
|
|
1785
|
-
const
|
|
1798
|
+
const laidOverChecks = await checks(laidOver(inForce2, drafted));
|
|
1786
1799
|
const versions = [];
|
|
1787
1800
|
for (const one of drafted) {
|
|
1788
1801
|
const kind = ofKind(one.kind);
|
|
1789
|
-
versions.push({ kind, id: one.id, body: await checked(kind, one.id, one.body,
|
|
1802
|
+
versions.push({ kind, id: one.id, body: await checked(kind, one.id, one.body, laidOverChecks), copiedFrom: null });
|
|
1790
1803
|
}
|
|
1791
1804
|
return { save: await write(saved, versions, inForce2), artifacts: idsOf(versions) };
|
|
1792
1805
|
}
|
|
@@ -1869,7 +1882,7 @@ var createGeneration = (pointer, ctx) => {
|
|
|
1869
1882
|
var NO_DEFAULTS = { actions: {}, fragments: {}, reads: /* @__PURE__ */ new Map() };
|
|
1870
1883
|
var drawableIn = (fragments, kit, say) => Object.fromEntries(
|
|
1871
1884
|
Object.entries(fragments).filter(([id, fragment]) => {
|
|
1872
|
-
const misfits =
|
|
1885
|
+
const misfits = chunk6ACVHHFK_cjs.layoutMisfits(fragment.layout, kit);
|
|
1873
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("; ")}`);
|
|
1874
1887
|
return misfits.length === 0;
|
|
1875
1888
|
})
|
|
@@ -1878,7 +1891,7 @@ var createPublishedMemo = () => {
|
|
|
1878
1891
|
let read2;
|
|
1879
1892
|
let said = /* @__PURE__ */ new Set();
|
|
1880
1893
|
return {
|
|
1881
|
-
|
|
1894
|
+
current: () => read2,
|
|
1882
1895
|
keep: (promise) => {
|
|
1883
1896
|
read2 = promise;
|
|
1884
1897
|
},
|
|
@@ -1894,20 +1907,20 @@ var createPublishedMemo = () => {
|
|
|
1894
1907
|
};
|
|
1895
1908
|
};
|
|
1896
1909
|
var hasDefaults = (defaults) => Object.keys(defaults.actions).length > 0 || Object.keys(defaults.fragments).length > 0 || defaults.reads.size > 0;
|
|
1897
|
-
var checkedDefaults = async (versions,
|
|
1898
|
-
const reads =
|
|
1910
|
+
var checkedDefaults = async (versions, defaults, whose) => {
|
|
1911
|
+
const reads = defaults.reads === void 0 ? /* @__PURE__ */ new Map() : await readsInForce(versions, defaults.reads, whose);
|
|
1899
1912
|
const checks = {
|
|
1900
|
-
kit:
|
|
1913
|
+
kit: defaults.kit,
|
|
1901
1914
|
entryOf: (fingerprint) => {
|
|
1902
1915
|
const read2 = reads.get(fingerprint);
|
|
1903
|
-
return
|
|
1916
|
+
return defaults.entryOf(fingerprint) ?? (read2 === void 0 ? void 0 : seedOf(fingerprint, read2));
|
|
1904
1917
|
},
|
|
1905
|
-
replayable: async () => /* @__PURE__ */ new Set([...
|
|
1918
|
+
replayable: async () => /* @__PURE__ */ new Set([...defaults.fingerprints(), ...reads.keys()]),
|
|
1906
1919
|
mayCall: () => true,
|
|
1907
|
-
catalog: () => [...Object.values(
|
|
1920
|
+
catalog: () => [...Object.values(defaults.built).map((action) => ({ id: action.id, input: action.input ?? {} })), ...catalogOfGenerated(versions)]
|
|
1908
1921
|
};
|
|
1909
1922
|
const passed = await generatedInForce(versions, checks, whose);
|
|
1910
|
-
return { passed, reads, verified:
|
|
1923
|
+
return { passed, reads, verified: chunk6ACVHHFK_cjs.verifyManifest(defaults.candidate({ ...defaults.built, ...passed.actions }, passed.fragments)) };
|
|
1911
1924
|
};
|
|
1912
1925
|
var narrowedBy = (filter, ids, installed) => {
|
|
1913
1926
|
const answered = new Set(filter(ids, installed));
|
|
@@ -1920,9 +1933,9 @@ var catalogFor = (app, roles, installed, installedOnly) => {
|
|
|
1920
1933
|
};
|
|
1921
1934
|
var resolveVariantsForRoles = (app, roles) => {
|
|
1922
1935
|
const variants = app.layouts ?? {};
|
|
1923
|
-
return
|
|
1936
|
+
return chunk6ACVHHFK_cjs.variantLayouts(variants, charter.resolvePrincipal(app.charter, Object.keys(variants), roles, "layouts"));
|
|
1924
1937
|
};
|
|
1925
|
-
var definitionsFor = (actions, ids, variants) => Object.freeze(Object.fromEntries(
|
|
1938
|
+
var definitionsFor = (actions, ids, variants) => Object.freeze(Object.fromEntries(chunk6ACVHHFK_cjs.withVariants(actions, ids, variants)));
|
|
1926
1939
|
var actionsWithStoredLayouts = (definitions) => {
|
|
1927
1940
|
const actions = {};
|
|
1928
1941
|
const layouts = {};
|
|
@@ -1932,7 +1945,7 @@ var actionsWithStoredLayouts = (definitions) => {
|
|
|
1932
1945
|
actions[id] = definition;
|
|
1933
1946
|
continue;
|
|
1934
1947
|
}
|
|
1935
|
-
const ref =
|
|
1948
|
+
const ref = chunk6ACVHHFK_cjs.actionLayoutRef(id);
|
|
1936
1949
|
layouts[ref] = layout;
|
|
1937
1950
|
actions[id] = { ...definition, layout: { ref } };
|
|
1938
1951
|
}
|
|
@@ -1985,8 +1998,8 @@ var createSetOwners = () => {
|
|
|
1985
1998
|
return {
|
|
1986
1999
|
ownerRefusalOf,
|
|
1987
2000
|
claim: (source, owner, handedOver) => {
|
|
1988
|
-
const
|
|
1989
|
-
if (
|
|
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.`);
|
|
1990
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.`);
|
|
1991
2004
|
owners.set(source, owner);
|
|
1992
2005
|
},
|
|
@@ -2028,17 +2041,17 @@ var tell = (listener, ...told) => {
|
|
|
2028
2041
|
};
|
|
2029
2042
|
var createRunningManifest = (config) => {
|
|
2030
2043
|
const { shipped } = config;
|
|
2031
|
-
const entries = createEntriesInForce(
|
|
2044
|
+
const entries = createEntriesInForce(chunk6ACVHHFK_cjs.entriesOf(shipped), config.compileSeeded);
|
|
2032
2045
|
let defaults = NO_DEFAULTS;
|
|
2033
2046
|
const usage = createUsage(config.touchEveryMs ?? TOUCH_EVERY_MS);
|
|
2034
2047
|
let functionIds;
|
|
2035
|
-
const candidate = (actions,
|
|
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);
|
|
2036
2049
|
const own = shipped.actions;
|
|
2037
2050
|
const loaders = /* @__PURE__ */ new Map();
|
|
2038
2051
|
const owners = createSetOwners();
|
|
2039
2052
|
let sets = /* @__PURE__ */ new Map();
|
|
2040
2053
|
let inForce2 = mergedActions(own, sets);
|
|
2041
|
-
let report =
|
|
2054
|
+
let report = chunk6ACVHHFK_cjs.verifiedAtBoot(candidate(inForce2));
|
|
2042
2055
|
const components = createComponentNames((shell) => shellComponents({ actions: inForce2, layouts: shipped.layouts }, shell));
|
|
2043
2056
|
const componentsOf2 = (shells) => {
|
|
2044
2057
|
const kit = /* @__PURE__ */ new Map();
|
|
@@ -2061,7 +2074,7 @@ var createRunningManifest = (config) => {
|
|
|
2061
2074
|
const kitOf2 = (shell) => shell === void 0 ? ofTheApp ??= componentsOf2(config.shells) : componentsOf2([shell]);
|
|
2062
2075
|
const ownShell = shipped.shell;
|
|
2063
2076
|
const ownShellRefs = new Set(ownShell === void 0 ? [] : Object.keys(shellWithStoredLayouts(ownShell).layouts));
|
|
2064
|
-
const
|
|
2077
|
+
const layoutChecksOf = ({ actions, layouts }, shell) => {
|
|
2065
2078
|
const kit = kitOf2(shell);
|
|
2066
2079
|
return {
|
|
2067
2080
|
kit,
|
|
@@ -2073,14 +2086,14 @@ var createRunningManifest = (config) => {
|
|
|
2073
2086
|
const { reads: readSources } = config;
|
|
2074
2087
|
const functionsWritten = (written) => {
|
|
2075
2088
|
if (functionIds !== void 0) return;
|
|
2076
|
-
const ids =
|
|
2077
|
-
const charter =
|
|
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);
|
|
2078
2091
|
if (charter.errors.length > 0) throw new Error(`Charter is incoherent over the app\u2019s functions \u2014 refusing to serve:
|
|
2079
2092
|
${charter.errors.join("\n ")}`);
|
|
2080
2093
|
functionIds = new Set(ids);
|
|
2081
2094
|
const built = mergedActions(own, sets);
|
|
2082
|
-
const verified =
|
|
2083
|
-
const refusal =
|
|
2095
|
+
const verified = chunk6ACVHHFK_cjs.verifyManifest(candidate(built, entries.list(), {}));
|
|
2096
|
+
const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "boot");
|
|
2084
2097
|
if (refusal !== void 0) {
|
|
2085
2098
|
functionIds = void 0;
|
|
2086
2099
|
throw new Error(refusal);
|
|
@@ -2091,15 +2104,15 @@ var createRunningManifest = (config) => {
|
|
|
2091
2104
|
dropMemos();
|
|
2092
2105
|
memo.drop();
|
|
2093
2106
|
for (const warning2 of charter.warnings) console.warn(`[moss] charter: ${warning2}`);
|
|
2094
|
-
const warning =
|
|
2107
|
+
const warning = chunk6ACVHHFK_cjs.functionsWarning(written);
|
|
2095
2108
|
if (warning !== void 0) console.warn(warning);
|
|
2096
2109
|
};
|
|
2097
2110
|
const grantedFunctionsOf = (roles) => (names) => charter.resolvePrincipal(shipped.charter, names, roles, "functions");
|
|
2098
|
-
const
|
|
2099
|
-
const
|
|
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) => {
|
|
2100
2113
|
let replayable;
|
|
2101
2114
|
let catalog;
|
|
2102
|
-
const reads = new Map([...defaults.reads, ...
|
|
2115
|
+
const reads = new Map([...defaults.reads, ...readChecks === void 0 ? [] : await readsInForce(versions, readChecks, whose)]);
|
|
2103
2116
|
const checks = {
|
|
2104
2117
|
kit: kitOf2(shell),
|
|
2105
2118
|
entryOf: (fingerprint) => {
|
|
@@ -2108,12 +2121,12 @@ var createRunningManifest = (config) => {
|
|
|
2108
2121
|
},
|
|
2109
2122
|
replayable: () => replayable ??= (async () => /* @__PURE__ */ new Set([...await who.replayable?.() ?? [], ...reads.keys()]))(),
|
|
2110
2123
|
mayCall: (name) => who.roles !== void 0 && charter.resolvePrincipal(shipped.charter, [name], who.roles, "functions").has(name),
|
|
2111
|
-
catalog: () => catalog ??= [...Object.values(
|
|
2124
|
+
catalog: () => catalog ??= [...Object.values(granted.actions).map((action) => ({ id: action.id, input: action.input ?? {} })), ...catalogOfGenerated(versions)]
|
|
2112
2125
|
};
|
|
2113
2126
|
const passed = await generatedInForce(versions, checks, whose);
|
|
2114
2127
|
const stored = actionsWithStoredLayouts(passed.actions);
|
|
2115
|
-
const all = Object.keys(passed.actions).length === 0 ?
|
|
2116
|
-
return { all, fragments: passed.fragments,
|
|
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 } : {} } };
|
|
2117
2130
|
};
|
|
2118
2131
|
const listeners = /* @__PURE__ */ new Set();
|
|
2119
2132
|
const listenersFor = /* @__PURE__ */ new Set();
|
|
@@ -2121,11 +2134,11 @@ var createRunningManifest = (config) => {
|
|
|
2121
2134
|
const sessionDeps = (principal, callerOf, shell) => ({
|
|
2122
2135
|
whose: "of yours",
|
|
2123
2136
|
kinds,
|
|
2124
|
-
|
|
2137
|
+
owner: principal === null ? void 0 : async () => {
|
|
2125
2138
|
await publishedNow();
|
|
2126
2139
|
const caller = await callerOf();
|
|
2127
|
-
const
|
|
2128
|
-
return { saved: caller.saved,
|
|
2140
|
+
const granted = roleMemo.storedLayoutsFor(caller.roles, caller.installed);
|
|
2141
|
+
return { saved: caller.saved, checks: async (inForce3) => (await checksWithGenerated(granted, inForce3, caller, shell)).checks };
|
|
2129
2142
|
},
|
|
2130
2143
|
written: () => {
|
|
2131
2144
|
if (principal !== null) for (const listener of [...listenersFor]) tell(listener, principal);
|
|
@@ -2133,19 +2146,19 @@ var createRunningManifest = (config) => {
|
|
|
2133
2146
|
});
|
|
2134
2147
|
let pointer;
|
|
2135
2148
|
const memo = createPublishedMemo();
|
|
2136
|
-
const
|
|
2149
|
+
const defaultsChecks = () => ({
|
|
2137
2150
|
kit: kitOf2(),
|
|
2138
2151
|
entryOf: (fingerprint) => entries.byFingerprint().get(fingerprint),
|
|
2139
2152
|
fingerprints: () => entries.byFingerprint().keys(),
|
|
2140
|
-
reads:
|
|
2153
|
+
reads: readChecks,
|
|
2141
2154
|
built: mergedActions(own, sets),
|
|
2142
2155
|
candidate: (actions, fragments) => candidate(actions, entries.list(), fragments)
|
|
2143
2156
|
});
|
|
2144
2157
|
const applyPublished = async (versions) => {
|
|
2145
2158
|
const over = sets;
|
|
2146
|
-
const { passed, reads, verified } = await checkedDefaults(versions,
|
|
2159
|
+
const { passed, reads, verified } = await checkedDefaults(versions, defaultsChecks(), "published for everybody");
|
|
2147
2160
|
if (sets !== over) return applyPublished(versions);
|
|
2148
|
-
const refusal =
|
|
2161
|
+
const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "boot");
|
|
2149
2162
|
if (refusal !== void 0) memo.sayOnce(`[moss] what is published for everybody is left out, and the build\u2019s copies stand: ${refusal}`);
|
|
2150
2163
|
const next = refusal === void 0 ? { actions: passed.actions, fragments: passed.fragments, reads } : { ...NO_DEFAULTS, reads };
|
|
2151
2164
|
if (!hasDefaults(next) && !hasDefaults(defaults)) return;
|
|
@@ -2155,8 +2168,8 @@ var createRunningManifest = (config) => {
|
|
|
2155
2168
|
dropMemos();
|
|
2156
2169
|
};
|
|
2157
2170
|
const publishedNow = () => {
|
|
2158
|
-
const
|
|
2159
|
-
if (
|
|
2171
|
+
const current = memo.current();
|
|
2172
|
+
if (current !== void 0) return current;
|
|
2160
2173
|
const read2 = (async () => {
|
|
2161
2174
|
const versions = await config.published?.() ?? [];
|
|
2162
2175
|
await applyPublished(versions);
|
|
@@ -2169,10 +2182,10 @@ var createRunningManifest = (config) => {
|
|
|
2169
2182
|
const applySets = (arrived, announce) => {
|
|
2170
2183
|
const next = new Map([...sets, ...arrived]);
|
|
2171
2184
|
const actions = mergedActions(own, next, defaults.actions);
|
|
2172
|
-
const verified =
|
|
2173
|
-
const refusal =
|
|
2185
|
+
const verified = chunk6ACVHHFK_cjs.verifyManifest(candidate(actions));
|
|
2186
|
+
const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "refresh");
|
|
2174
2187
|
if (refusal !== void 0) throw new Error(refusal);
|
|
2175
|
-
for (const set of arrived.values())
|
|
2188
|
+
for (const set of arrived.values()) chunk6ACVHHFK_cjs.freezeDeep(set);
|
|
2176
2189
|
sets = next;
|
|
2177
2190
|
inForce2 = actions;
|
|
2178
2191
|
report = verified;
|
|
@@ -2188,13 +2201,13 @@ var createRunningManifest = (config) => {
|
|
|
2188
2201
|
};
|
|
2189
2202
|
const takeEntries = async (source, handed) => {
|
|
2190
2203
|
owners.assertAppOwned(source);
|
|
2191
|
-
const misfits =
|
|
2204
|
+
const misfits = chunk6ACVHHFK_cjs.entryMisfits(handed);
|
|
2192
2205
|
if (misfits.length > 0) throw new Error(["Refresh refused \u2014 entries that do not parse:", ...misfits.map((misfit) => ` ${misfit}`)].join("\n"));
|
|
2193
2206
|
const compiled = await compileEntries(handed);
|
|
2194
|
-
const verified =
|
|
2195
|
-
const refusal =
|
|
2207
|
+
const verified = chunk6ACVHHFK_cjs.verifyManifest(candidate(inForce2, entries.withSet(source, handed)));
|
|
2208
|
+
const refusal = chunk6ACVHHFK_cjs.refusalOf(verified, "refresh");
|
|
2196
2209
|
if (refusal !== void 0) throw new Error(refusal);
|
|
2197
|
-
|
|
2210
|
+
chunk6ACVHHFK_cjs.freezeDeep(handed);
|
|
2198
2211
|
entries.takeSet(source, handed, compiled);
|
|
2199
2212
|
report = verified;
|
|
2200
2213
|
for (const listener of [...listeners]) tell(listener);
|
|
@@ -2204,7 +2217,7 @@ var createRunningManifest = (config) => {
|
|
|
2204
2217
|
return {
|
|
2205
2218
|
actions: () => inForce2,
|
|
2206
2219
|
entries: entries.list,
|
|
2207
|
-
verify: (actions) =>
|
|
2220
|
+
verify: (actions) => chunk6ACVHHFK_cjs.verifyManifest(candidate(actions)),
|
|
2208
2221
|
report: () => report,
|
|
2209
2222
|
replace: (source, actions) => applySets(/* @__PURE__ */ new Map([[owners.assertAppOwned(source), actions]]), true),
|
|
2210
2223
|
// In turn: a set is compiled before it is taken, and of two handed over
|
|
@@ -2228,7 +2241,7 @@ var createRunningManifest = (config) => {
|
|
|
2228
2241
|
},
|
|
2229
2242
|
cacheEntries: async () => [...await entries.compiled()].map(([key, entry]) => ({ key, entry })),
|
|
2230
2243
|
claim: (source, owner) => {
|
|
2231
|
-
owners.claim(source, owner, sets.has(source) || entries.
|
|
2244
|
+
owners.claim(source, owner, sets.has(source) || entries.hasSet(source));
|
|
2232
2245
|
return {
|
|
2233
2246
|
replace: (actions) => applySets(/* @__PURE__ */ new Map([[source, actions]]), true),
|
|
2234
2247
|
setLoader: (load) => {
|
|
@@ -2261,12 +2274,12 @@ var createRunningManifest = (config) => {
|
|
|
2261
2274
|
const versions = own2.length === 0 && drafted === void 0 ? [] : laidOver(own2, drafted);
|
|
2262
2275
|
const everybodysVersions = await publishedNow();
|
|
2263
2276
|
const whose = `of ${principal ?? "nobody"}`;
|
|
2264
|
-
const theirOwn = await
|
|
2265
|
-
const drawable = theirOwn.
|
|
2266
|
-
const theirs2 = layoutsInUse(versions, { whose,
|
|
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 });
|
|
2267
2280
|
const variants = roleMemo.variantsFor(roles);
|
|
2268
|
-
const underVariants = { ...drawable, actionAt: (ref) => variants.has(
|
|
2269
|
-
const everybodys = layoutsInUse(everybodysVersions, { whose: "published for everybody",
|
|
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 });
|
|
2270
2283
|
const laidOverShell = { ...drawableIn(defaults.fragments, kitOf2(shell), memo.sayOnce), ...theirOwn.fragments };
|
|
2271
2284
|
const fragments = Object.keys(laidOverShell).length === 0 ? shell.fragments : { ...shell.fragments, ...laidOverShell };
|
|
2272
2285
|
const { layouts: ofShell, ...named } = shellWithStoredLayouts(shell);
|
|
@@ -2284,20 +2297,20 @@ var createRunningManifest = (config) => {
|
|
|
2284
2297
|
},
|
|
2285
2298
|
sessionArtifacts: (principal, callerOf) => savedArtifacts(sessionDeps(principal, callerOf)),
|
|
2286
2299
|
draftSavingFor: (shell, principal, callerOf) => draftSaving(sessionDeps(principal, callerOf, shell)),
|
|
2287
|
-
//
|
|
2300
|
+
// Checked against every action in force with the layout it is built with: who has
|
|
2288
2301
|
// which is asked when a shell is built for them.
|
|
2289
2302
|
publishedArtifacts: (saved, publisher) => savedArtifacts({
|
|
2290
2303
|
whose: "published for everybody",
|
|
2291
2304
|
kinds,
|
|
2292
|
-
|
|
2305
|
+
owner: async () => {
|
|
2293
2306
|
const who = await publisher();
|
|
2294
|
-
return { saved,
|
|
2307
|
+
return { saved, checks: async (inForce3) => (await checksWithGenerated(actionsWithStoredLayouts(mergedActions(own, sets)), inForce3, who)).checks };
|
|
2295
2308
|
},
|
|
2296
2309
|
defaults: {
|
|
2297
2310
|
verify: async (versions, inForce3) => {
|
|
2298
|
-
const kept = inForce3.filter((
|
|
2311
|
+
const kept = inForce3.filter((current) => !versions.some((version) => version.kind === current.kind && version.id === current.id));
|
|
2299
2312
|
const asked = versions.map((version) => ({ ...version, save: "", createdAt: "" }));
|
|
2300
|
-
const refusal =
|
|
2313
|
+
const refusal = chunk6ACVHHFK_cjs.refusalOf((await checkedDefaults([...kept, ...asked], defaultsChecks(), void 0)).verified, "publish");
|
|
2301
2314
|
if (refusal !== void 0) throw new Error(refusal);
|
|
2302
2315
|
}
|
|
2303
2316
|
},
|
|
@@ -2343,14 +2356,14 @@ var callerScope = (scope) => {
|
|
|
2343
2356
|
};
|
|
2344
2357
|
var PAGE = 500;
|
|
2345
2358
|
var VERSION_COLUMNS = ["save", "kind", "id", "body", "grammar", "copied_from", "created_at"];
|
|
2346
|
-
var
|
|
2359
|
+
var laterVersion = {
|
|
2347
2360
|
and: [
|
|
2348
2361
|
{ eq: ["artifacts.kind", "held.kind"] },
|
|
2349
2362
|
{ eq: ["artifacts.id", "held.id"] },
|
|
2350
2363
|
{ or: [{ gt: ["artifacts.created_at", "held.created_at"] }, { and: [{ eq: ["artifacts.created_at", "held.created_at"] }, { gt: ["artifacts.save", "held.save"] }] }] }
|
|
2351
2364
|
]
|
|
2352
2365
|
};
|
|
2353
|
-
var
|
|
2366
|
+
var afterCursor = {
|
|
2354
2367
|
or: [{ gt: ["held.kind", { $context: "after_kind" }] }, { and: [{ eq: ["held.kind", { $context: "after_kind" }] }, { gt: ["held.id", { $context: "after_id" }] }] }]
|
|
2355
2368
|
};
|
|
2356
2369
|
var inForce = {
|
|
@@ -2359,7 +2372,7 @@ var inForce = {
|
|
|
2359
2372
|
dsl: {
|
|
2360
2373
|
from: [{ as: "held", query: { from: ["artifacts"], fields: VERSION_COLUMNS.map((column) => `artifacts.${column}`) } }],
|
|
2361
2374
|
fields: VERSION_COLUMNS.map((column) => `held.${column}`),
|
|
2362
|
-
filter: { and: [{ not: { exists: { from: ["artifacts"], filter:
|
|
2375
|
+
filter: { and: [{ not: { exists: { from: ["artifacts"], filter: laterVersion } } }, afterCursor] },
|
|
2363
2376
|
sort: [
|
|
2364
2377
|
{ field: "held.kind", dir: "asc" },
|
|
2365
2378
|
{ field: "held.id", dir: "asc" }
|
|
@@ -2472,10 +2485,11 @@ var DEFAULT_REVALIDATE_MS = 60 * 1e3;
|
|
|
2472
2485
|
var MAX_INTERVAL_MS2 = 2 ** 31 - 1;
|
|
2473
2486
|
var createRevalidation = (config) => {
|
|
2474
2487
|
const live = /* @__PURE__ */ new Map();
|
|
2488
|
+
const revalidateMs = config.revalidateMs ?? DEFAULT_REVALIDATE_MS;
|
|
2475
2489
|
const expire = (connection) => {
|
|
2476
2490
|
live.delete(connection);
|
|
2477
2491
|
const told = () => connection.send(JSON.stringify({ type: "error", code: "invalid_token", message: "The session token no longer resolves to this principal." }));
|
|
2478
|
-
const closed = () => connection.close(
|
|
2492
|
+
const closed = () => connection.close(chunkBFA76AKR_cjs.CLOSE_INVALID_TOKEN, "session expired");
|
|
2479
2493
|
for (const step of [told, closed]) {
|
|
2480
2494
|
try {
|
|
2481
2495
|
step();
|
|
@@ -2484,30 +2498,59 @@ var createRevalidation = (config) => {
|
|
|
2484
2498
|
}
|
|
2485
2499
|
}
|
|
2486
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
|
+
};
|
|
2487
2511
|
const revalidate = async () => {
|
|
2512
|
+
const byToken = /* @__PURE__ */ new Map();
|
|
2488
2513
|
let asked = 0;
|
|
2489
|
-
const
|
|
2490
|
-
|
|
2491
|
-
if (credential === null) continue;
|
|
2514
|
+
for (const [connection, credential] of live) {
|
|
2515
|
+
if (credential === null || asking.has(connection)) continue;
|
|
2492
2516
|
asked += 1;
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
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);
|
|
2503
2542
|
}
|
|
2504
2543
|
if (unanswered.length > 0) {
|
|
2505
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]);
|
|
2506
2545
|
}
|
|
2507
2546
|
};
|
|
2508
2547
|
let passing = false;
|
|
2548
|
+
let dueWhilePassing = false;
|
|
2509
2549
|
const pass = async () => {
|
|
2510
|
-
if (passing)
|
|
2550
|
+
if (passing) {
|
|
2551
|
+
dueWhilePassing = true;
|
|
2552
|
+
return;
|
|
2553
|
+
}
|
|
2511
2554
|
passing = true;
|
|
2512
2555
|
try {
|
|
2513
2556
|
await revalidate();
|
|
@@ -2515,16 +2558,19 @@ var createRevalidation = (config) => {
|
|
|
2515
2558
|
console.error("[moss/socket] a revalidation pass failed, and the next one starts over:", error);
|
|
2516
2559
|
} finally {
|
|
2517
2560
|
passing = false;
|
|
2561
|
+
if (dueWhilePassing && sweeper !== void 0) {
|
|
2562
|
+
dueWhilePassing = false;
|
|
2563
|
+
void pass();
|
|
2564
|
+
}
|
|
2518
2565
|
}
|
|
2519
2566
|
};
|
|
2520
|
-
const revalidateMs = config.revalidateMs ?? DEFAULT_REVALIDATE_MS;
|
|
2521
2567
|
let sweeper;
|
|
2522
2568
|
if (revalidateMs > 0 && revalidateMs <= MAX_INTERVAL_MS2) {
|
|
2523
2569
|
sweeper = setInterval(() => void pass(), revalidateMs);
|
|
2524
2570
|
sweeper.unref?.();
|
|
2525
2571
|
}
|
|
2526
2572
|
return {
|
|
2527
|
-
|
|
2573
|
+
track: (connection, credential) => {
|
|
2528
2574
|
live.set(connection, credential);
|
|
2529
2575
|
},
|
|
2530
2576
|
release: (connection) => {
|
|
@@ -2553,20 +2599,20 @@ var parametersOf = (url) => {
|
|
|
2553
2599
|
var SpokenProtocolSchema = zod.z.string().regex(/^\d{1,15}$/).transform(Number);
|
|
2554
2600
|
var protocolRefusal = (parameters) => {
|
|
2555
2601
|
const spoken = SpokenProtocolSchema.safeParse(parameters.protocol);
|
|
2556
|
-
if (spoken.success && spoken.data >=
|
|
2557
|
-
const behind = spoken.success && spoken.data >
|
|
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";
|
|
2558
2604
|
return {
|
|
2559
2605
|
type: "error",
|
|
2560
2606
|
code: `${behind}_too_old`,
|
|
2561
|
-
message: `This terminal speaks protocol ${parameters.protocol}; this server speaks ${
|
|
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.")
|
|
2562
2608
|
};
|
|
2563
2609
|
};
|
|
2564
2610
|
var authenticateUpgrade = async (url, upgrade, config, foreignPageWarning) => {
|
|
2565
2611
|
const parameters = parametersOf(url);
|
|
2566
|
-
const key = parameters.key ??
|
|
2612
|
+
const key = parameters.key ?? chunkBFA76AKR_cjs.DEFAULT_TOKEN_KEY;
|
|
2567
2613
|
const page = upgrade === void 0 ? void 0 : ownOriginOf(upgrade.origin, upgrade.host, config.origins);
|
|
2568
2614
|
const secure = page?.protocol === "https:";
|
|
2569
|
-
const
|
|
2615
|
+
const fromCookie = page === void 0 ? null : sessionTokenOf(upgrade?.cookie, { port: page.port, secure }, key);
|
|
2570
2616
|
const sealing = page !== void 0 && parameters.sealed === "1";
|
|
2571
2617
|
if (page === void 0 && parameters.sealed === "1" && typeof upgrade?.origin === "string" && !foreignPageWarning.warned) {
|
|
2572
2618
|
foreignPageWarning.warned = true;
|
|
@@ -2575,16 +2621,16 @@ var authenticateUpgrade = async (url, upgrade, config, foreignPageWarning) => {
|
|
|
2575
2621
|
);
|
|
2576
2622
|
}
|
|
2577
2623
|
const hadSeal = sealing ? sealOf(upgrade?.cookie, secure) : null;
|
|
2578
|
-
const sealedOffer =
|
|
2624
|
+
const sealedOffer = chunkBFA76AKR_cjs.offeredSealed(upgrade?.offered);
|
|
2579
2625
|
const sealLost = sealing && sealedOffer !== null && hadSeal === null;
|
|
2580
2626
|
const seal = !sealing || sealLost ? null : hadSeal ?? (upgrade?.answer === void 0 ? null : newSeal());
|
|
2581
|
-
const offered =
|
|
2582
|
-
const carried = offered ?? (parameters.leave === "1" ? 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);
|
|
2583
2629
|
const principal = carried === null ? null : await config.session(carried);
|
|
2584
2630
|
if (offered !== null && principal === null) return "invalid_token";
|
|
2585
2631
|
const token = principal === null ? null : carried;
|
|
2586
2632
|
const cookies = [
|
|
2587
|
-
...page === void 0 || offered === 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 }),
|
|
2588
2634
|
...seal !== null && hadSeal === null ? [sealCookie(seal, { secure, path: new URL(url, "http://nisc.local").pathname })] : []
|
|
2589
2635
|
];
|
|
2590
2636
|
return { token, principal, cookies, seal, sealLost };
|
|
@@ -2593,13 +2639,13 @@ var authenticateUpgrade = async (url, upgrade, config, foreignPageWarning) => {
|
|
|
2593
2639
|
// src/socket/routing.ts
|
|
2594
2640
|
var messageOf2 = (text) => {
|
|
2595
2641
|
try {
|
|
2596
|
-
const parsed =
|
|
2642
|
+
const parsed = chunkBFA76AKR_cjs.ClientMessageSchema.safeParse(JSON.parse(text));
|
|
2597
2643
|
return parsed.success ? parsed.data : void 0;
|
|
2598
2644
|
} catch {
|
|
2599
2645
|
return void 0;
|
|
2600
2646
|
}
|
|
2601
2647
|
};
|
|
2602
|
-
var INVALID_MESSAGE = `Not a message of protocol ${
|
|
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.`;
|
|
2603
2649
|
var messageHandler = (session, connection, send) => {
|
|
2604
2650
|
const act = (text) => {
|
|
2605
2651
|
const message = messageOf2(text);
|
|
@@ -2691,7 +2737,7 @@ var refusalOf2 = (error) => {
|
|
|
2691
2737
|
};
|
|
2692
2738
|
var spanOf = (emit) => {
|
|
2693
2739
|
if (emit === void 0) return void 0;
|
|
2694
|
-
const clock =
|
|
2740
|
+
const clock = chunk3CKBKTXA_cjs.spanClock();
|
|
2695
2741
|
return (name, status2, hasPrincipal) => emit({ name, startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status: status2, attributes: { hasPrincipal } });
|
|
2696
2742
|
};
|
|
2697
2743
|
var openingOf = (config, { seed, path }) => {
|
|
@@ -2704,7 +2750,7 @@ var AT_CAPACITY = { type: "error", code: "at_capacity", message: "This server is
|
|
|
2704
2750
|
var served = async (config, connection, send, close, opening, who) => {
|
|
2705
2751
|
const { ids, hash } = await config.catalog(who.principal);
|
|
2706
2752
|
if (close.ended()) return void 0;
|
|
2707
|
-
send({ type: "hello", protocol:
|
|
2753
|
+
send({ type: "hello", protocol: chunkBFA76AKR_cjs.PROTOCOL, principal: who.principal, catalog: { actions: ids, hash } });
|
|
2708
2754
|
const session = await opening.session?.(who.token, who.principal);
|
|
2709
2755
|
if (session === void 0) {
|
|
2710
2756
|
if (!close.ended()) send({ type: "frame", tree: [] });
|
|
@@ -2714,20 +2760,20 @@ var served = async (config, connection, send, close, opening, who) => {
|
|
|
2714
2760
|
close.whenClosed(() => session.detach(connection));
|
|
2715
2761
|
return session;
|
|
2716
2762
|
};
|
|
2717
|
-
var open = async (
|
|
2718
|
-
const { config, foreignPageWarning, revalidation, anonymousShells } =
|
|
2763
|
+
var open = async (state, url, connection, send, span, found) => {
|
|
2764
|
+
const { config, foreignPageWarning, revalidation, anonymousShells } = state;
|
|
2719
2765
|
const params = parametersOf(url);
|
|
2720
2766
|
const mismatch = protocolRefusal(params);
|
|
2721
2767
|
if (mismatch !== void 0) {
|
|
2722
2768
|
send(mismatch);
|
|
2723
|
-
connection.close(
|
|
2769
|
+
connection.close(chunkBFA76AKR_cjs.CLOSE_PROTOCOL_MISMATCH, "protocol mismatch");
|
|
2724
2770
|
return;
|
|
2725
2771
|
}
|
|
2726
2772
|
const asking = await authenticateUpgrade(url, connection.upgrade, config, foreignPageWarning);
|
|
2727
2773
|
if (asking === "invalid_token") {
|
|
2728
2774
|
span?.("socket.upgrade", "refused", false);
|
|
2729
2775
|
send({ type: "error", code: "invalid_token", message: "The session token did not resolve to a principal." });
|
|
2730
|
-
connection.close(
|
|
2776
|
+
connection.close(chunkBFA76AKR_cjs.CLOSE_INVALID_TOKEN, "invalid token");
|
|
2731
2777
|
return;
|
|
2732
2778
|
}
|
|
2733
2779
|
const { token, principal, seal } = asking;
|
|
@@ -2741,10 +2787,10 @@ var open = async (held, url, connection, send, span, found) => {
|
|
|
2741
2787
|
if (principal === null && session !== void 0 && !anonymousShells.acquire(connection)) {
|
|
2742
2788
|
span?.("socket.upgrade", "refused", false);
|
|
2743
2789
|
send(AT_CAPACITY);
|
|
2744
|
-
connection.close(
|
|
2790
|
+
connection.close(chunkBFA76AKR_cjs.CLOSE_AT_CAPACITY, "at capacity");
|
|
2745
2791
|
return;
|
|
2746
2792
|
}
|
|
2747
|
-
revalidation.
|
|
2793
|
+
revalidation.track(connection, token !== null && token !== "" && principal !== null ? { token, principal } : null);
|
|
2748
2794
|
const close = closeOf(connection);
|
|
2749
2795
|
close.whenClosed(() => revalidation.release(connection));
|
|
2750
2796
|
close.whenClosed(() => anonymousShells.release(connection));
|
|
@@ -2754,16 +2800,16 @@ var open = async (held, url, connection, send, span, found) => {
|
|
|
2754
2800
|
connection.onMessage(messageHandler(attached, connection, send));
|
|
2755
2801
|
};
|
|
2756
2802
|
var createSocket = (config) => {
|
|
2757
|
-
const emit =
|
|
2803
|
+
const emit = chunk3CKBKTXA_cjs.emitterOf(config.telemetry);
|
|
2758
2804
|
const revalidation = createRevalidation(config);
|
|
2759
2805
|
const anonymousShells = createAnonymousShellLimit(config.anonymousShellMax ?? DEFAULT_ANONYMOUS_SHELL_MAX);
|
|
2760
|
-
const
|
|
2806
|
+
const state = { config, foreignPageWarning: { warned: false }, revalidation, anonymousShells };
|
|
2761
2807
|
const accept = async (url, connection) => {
|
|
2762
2808
|
const send = (message) => connection.send(JSON.stringify(message));
|
|
2763
2809
|
const span = spanOf(emit);
|
|
2764
2810
|
const found = { principal: false };
|
|
2765
2811
|
try {
|
|
2766
|
-
await open(
|
|
2812
|
+
await open(state, url, connection, send, span, found);
|
|
2767
2813
|
} catch (error) {
|
|
2768
2814
|
console.error("[moss/socket] refused a session:", error);
|
|
2769
2815
|
span?.("socket.upgrade", "error", found.principal);
|
|
@@ -2771,7 +2817,7 @@ var createSocket = (config) => {
|
|
|
2771
2817
|
anonymousShells.release(connection);
|
|
2772
2818
|
try {
|
|
2773
2819
|
send(refusalOf2(error));
|
|
2774
|
-
connection.close(
|
|
2820
|
+
connection.close(chunkBFA76AKR_cjs.CLOSE_SHELL_FAILED, "session failed");
|
|
2775
2821
|
} catch {
|
|
2776
2822
|
}
|
|
2777
2823
|
}
|
|
@@ -2802,13 +2848,13 @@ var seamsFor = (feature, owned, { app, runtime, server, operator, registered, id
|
|
|
2802
2848
|
grantedActionIds: (roles, installed) => running.catalogFor(roles, installed).ids,
|
|
2803
2849
|
actions: running.actions,
|
|
2804
2850
|
replaceActions: owned.replace,
|
|
2805
|
-
refusalOf: (actions) =>
|
|
2851
|
+
refusalOf: (actions) => chunk6ACVHHFK_cjs.refusalOf(running.verify(actions), "refresh"),
|
|
2806
2852
|
setActionsLoader: owned.setLoader,
|
|
2807
2853
|
addCatalogFilter: running.addCatalogFilter,
|
|
2808
2854
|
charter: app.charter,
|
|
2809
2855
|
components: app.shell?.components ?? {},
|
|
2810
|
-
layoutMisfits: (layout) =>
|
|
2811
|
-
endlessChains:
|
|
2856
|
+
layoutMisfits: (layout) => chunk6ACVHHFK_cjs.layoutMisfits(layout, kitOf(app)),
|
|
2857
|
+
endlessChains: chunk6ACVHHFK_cjs.endlessChains,
|
|
2812
2858
|
ownEntries: (entries) => data.ownEntries(feature.name, entries),
|
|
2813
2859
|
grammars: data.grammars,
|
|
2814
2860
|
upgradeStore: (store) => data.upgradeStore(feature.name, store),
|
|
@@ -2875,9 +2921,9 @@ var read = (live) => {
|
|
|
2875
2921
|
console.error("[moss/shells] the shell frame failed to render for a snapshot \u2014 serving an empty arrangement:", error);
|
|
2876
2922
|
}
|
|
2877
2923
|
const trees = {};
|
|
2878
|
-
for (const canvasId of
|
|
2924
|
+
for (const canvasId of chunk6ACVHHFK_cjs.canvasesOf(live)) {
|
|
2879
2925
|
try {
|
|
2880
|
-
trees[canvasId] =
|
|
2926
|
+
trees[canvasId] = chunk6ACVHHFK_cjs.treeOf(live, canvasId);
|
|
2881
2927
|
} catch (error) {
|
|
2882
2928
|
console.error(`[moss/shells] canvas "${canvasId}" failed to render for a snapshot \u2014 leaving it out:`, error);
|
|
2883
2929
|
}
|
|
@@ -2894,7 +2940,7 @@ var needOf = (live, principal, kept) => {
|
|
|
2894
2940
|
for (const instance of canvas.stack) {
|
|
2895
2941
|
const definition = live.shell.getRuntime(instance.id)?.definition;
|
|
2896
2942
|
if (definition === void 0) continue;
|
|
2897
|
-
const need = shellNeedOf(
|
|
2943
|
+
const need = shellNeedOf(chunk6ACVHHFK_cjs.withLayoutInPlace(definition, live.shell.layoutStore), entries);
|
|
2898
2944
|
for (const reason of need.why) why.push(`${definition.id}: ${reason}`);
|
|
2899
2945
|
for (const read2 of need.drawnWith) drawnWith.push(read2);
|
|
2900
2946
|
}
|
|
@@ -2917,7 +2963,7 @@ var sweep = (host, idleMs) => {
|
|
|
2917
2963
|
}
|
|
2918
2964
|
if (live.connections.size > 0 || live.idleSince === null) continue;
|
|
2919
2965
|
if (now - live.idleSince < idleMs) continue;
|
|
2920
|
-
|
|
2966
|
+
chunk6ACVHHFK_cjs.endShell(host, live);
|
|
2921
2967
|
live.shell.dispose();
|
|
2922
2968
|
durable.delete(principal);
|
|
2923
2969
|
}
|
|
@@ -2939,7 +2985,7 @@ var rosterOf = (durable) => {
|
|
|
2939
2985
|
var sameDocument = (one, other) => one === other || JSON.stringify(one) === JSON.stringify(other);
|
|
2940
2986
|
var takeLayouts = (live, made) => {
|
|
2941
2987
|
const taken = live.layouts;
|
|
2942
|
-
const answered =
|
|
2988
|
+
const answered = chunk6ACVHHFK_cjs.layoutsOf(made);
|
|
2943
2989
|
for (const [ref, layout] of Object.entries(answered.layoutStore)) {
|
|
2944
2990
|
if (!sameDocument(taken.layoutStore[ref], layout)) live.shell.setLayout(ref, layout);
|
|
2945
2991
|
}
|
|
@@ -2969,15 +3015,15 @@ var takeComposition = (live, made) => {
|
|
|
2969
3015
|
live.entries = made.entries;
|
|
2970
3016
|
takeLayouts(live, made);
|
|
2971
3017
|
takeCanvases(live, made);
|
|
2972
|
-
|
|
3018
|
+
chunk6ACVHHFK_cjs.keepGranted(live.functions, made.grantedFunctions);
|
|
2973
3019
|
};
|
|
2974
3020
|
var adoptDraft = async (host, live, next) => {
|
|
2975
3021
|
for (; ; ) {
|
|
2976
3022
|
const cell = host.living.get(live);
|
|
2977
|
-
if (cell === void 0 || cell.live !== live) throw new Error(
|
|
3023
|
+
if (cell === void 0 || cell.live !== live) throw new Error(chunk6ACVHHFK_cjs.SHELL_GONE);
|
|
2978
3024
|
const changes = host.changes;
|
|
2979
|
-
const made = await host.config.composition(cell.principal,
|
|
2980
|
-
if (live.ended || cell.live !== live) throw new Error(
|
|
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);
|
|
2981
3027
|
if (changes < cell.changes) continue;
|
|
2982
3028
|
cell.changes = changes;
|
|
2983
3029
|
live.draft = next;
|
|
@@ -2991,7 +3037,7 @@ var adopt = (host, cell) => {
|
|
|
2991
3037
|
if (asked.ended) return;
|
|
2992
3038
|
const drafted = asked.draft;
|
|
2993
3039
|
const changes = host.changes;
|
|
2994
|
-
const made = await host.config.composition(cell.principal,
|
|
3040
|
+
const made = await host.config.composition(cell.principal, chunk6ACVHHFK_cjs.draftedIn(drafted));
|
|
2995
3041
|
if (asked.ended || changes <= cell.changes) return;
|
|
2996
3042
|
if (asked.draft !== drafted) {
|
|
2997
3043
|
adopt(host, cell);
|
|
@@ -3022,7 +3068,7 @@ var build = (host, asked, wanted = () => true) => {
|
|
|
3022
3068
|
reject(new Error(`moss: the shell of ${asked.principal ?? "nobody"} was not built within ${limit}ms.`));
|
|
3023
3069
|
}, limit);
|
|
3024
3070
|
timer.unref?.();
|
|
3025
|
-
|
|
3071
|
+
chunk6ACVHHFK_cjs.buildShell(host, { ...asked, wanted: () => inTime && wanted() }).then((live) => resolve2(live === void 0 ? void 0 : { live, changes }), reject).finally(() => clearTimeout(timer));
|
|
3026
3072
|
});
|
|
3027
3073
|
};
|
|
3028
3074
|
var builtOrThrow = (built) => {
|
|
@@ -3062,18 +3108,18 @@ var replaceShell = async (host, cell) => {
|
|
|
3062
3108
|
if (built === void 0) return;
|
|
3063
3109
|
const old = cell.live;
|
|
3064
3110
|
if (!stands()) {
|
|
3065
|
-
|
|
3111
|
+
chunk6ACVHHFK_cjs.endShell(host, built.live);
|
|
3066
3112
|
built.live.shell.dispose();
|
|
3067
3113
|
return;
|
|
3068
3114
|
}
|
|
3069
3115
|
const carried = [...old.connections].map((connection) => ({ connection, wants: old.deltaReady.has(connection) }));
|
|
3070
|
-
|
|
3116
|
+
chunk6ACVHHFK_cjs.endShell(host, old);
|
|
3071
3117
|
old.connections.clear();
|
|
3072
3118
|
old.shell.dispose();
|
|
3073
3119
|
cell.live = built.live;
|
|
3074
3120
|
cell.changes = built.changes;
|
|
3075
3121
|
registerLiving(host, cell);
|
|
3076
|
-
for (const { connection, wants } of carried)
|
|
3122
|
+
for (const { connection, wants } of carried) chunk6ACVHHFK_cjs.attach(built.live, connection, host.delta && wants);
|
|
3077
3123
|
};
|
|
3078
3124
|
var resetCell = (host, cell) => {
|
|
3079
3125
|
if (cell.hasWaitingReset === true) return;
|
|
@@ -3116,7 +3162,7 @@ var snapshotOf = (host) => async (token, principal, options) => {
|
|
|
3116
3162
|
const settled = await settle(live, waitMs);
|
|
3117
3163
|
return { ...read(live), seed, settled, ...needOf(live, principal, kept) };
|
|
3118
3164
|
} finally {
|
|
3119
|
-
|
|
3165
|
+
chunk6ACVHHFK_cjs.endShell(host, live);
|
|
3120
3166
|
live.shell.dispose();
|
|
3121
3167
|
}
|
|
3122
3168
|
};
|
|
@@ -3135,7 +3181,7 @@ var deliverTo = (host) => (principal, channel, payload) => {
|
|
|
3135
3181
|
var createShellHost = (config) => {
|
|
3136
3182
|
const host = {
|
|
3137
3183
|
config,
|
|
3138
|
-
emit:
|
|
3184
|
+
emit: chunk3CKBKTXA_cjs.emitterOf(config.telemetry),
|
|
3139
3185
|
kept: config.kept ?? true,
|
|
3140
3186
|
delta: config.limits?.delta ?? false,
|
|
3141
3187
|
durable: /* @__PURE__ */ new Map(),
|
|
@@ -3148,9 +3194,9 @@ var createShellHost = (config) => {
|
|
|
3148
3194
|
const handedOut = {
|
|
3149
3195
|
session: async (token, principal, options) => {
|
|
3150
3196
|
if (principal === null || !host.kept) {
|
|
3151
|
-
return
|
|
3197
|
+
return chunk6ACVHHFK_cjs.sessionOn(host, await open2(host, { token, principal, ...options !== void 0 ? { opening: options } : {} }, false), true, reset);
|
|
3152
3198
|
}
|
|
3153
|
-
return
|
|
3199
|
+
return chunk6ACVHHFK_cjs.sessionOn(host, await keptCell(host, token, principal), false, reset);
|
|
3154
3200
|
},
|
|
3155
3201
|
snapshot: snapshotOf(host),
|
|
3156
3202
|
deliver: deliverTo(host),
|
|
@@ -3179,8 +3225,8 @@ var hostConfig = (deps, shell, kept) => {
|
|
|
3179
3225
|
};
|
|
3180
3226
|
return {
|
|
3181
3227
|
composition: async (principal, drafted) => {
|
|
3182
|
-
const { resolved, saved, ...
|
|
3183
|
-
const who = { principal, ...
|
|
3228
|
+
const { resolved, saved, ...caller } = await callerOf(principal);
|
|
3229
|
+
const who = { principal, ...caller, ...principal === null ? {} : { saved, ...drafted === void 0 ? {} : { drafted } } };
|
|
3184
3230
|
return { roles: resolved.roles, scope: resolved.scope, ...await running.artifactsFor(shell, who) };
|
|
3185
3231
|
},
|
|
3186
3232
|
artifacts: (principal) => running.sessionArtifacts(principal, () => callerOf(principal)),
|
|
@@ -3264,11 +3310,13 @@ var buildShellHosts = (deps) => {
|
|
|
3264
3310
|
var createInternalWire = (server) => (token) => async (url, init) => {
|
|
3265
3311
|
const isVex = url.split("?")[0]?.endsWith("/vex") === true;
|
|
3266
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}`);
|
|
3267
3315
|
const res = await server.request(
|
|
3268
3316
|
url,
|
|
3269
3317
|
{
|
|
3270
3318
|
method: init?.method ?? "GET",
|
|
3271
|
-
headers
|
|
3319
|
+
headers,
|
|
3272
3320
|
...init?.body !== void 0 ? { body: init.body } : {}
|
|
3273
3321
|
},
|
|
3274
3322
|
follower === void 0 ? void 0 : { [hono$1.VEX_LIVE_ENV]: follower.live }
|
|
@@ -3308,7 +3356,7 @@ var mountRoutes = (server, { app, session, credentials, identity, running, data
|
|
|
3308
3356
|
var INVALID_TOKEN = { refused: { status: 401, error: "invalid_token", message: "The session token did not resolve to a principal." } };
|
|
3309
3357
|
var authenticateRequest = async (deps, header, request) => {
|
|
3310
3358
|
if (header === void 0) return { principal: null, resolved: await deps.resolve(null) };
|
|
3311
|
-
const token = header.
|
|
3359
|
+
const token = header.replace(/^bearer +/i, "");
|
|
3312
3360
|
const credential = deps.credentials.find(({ prefix }) => token.startsWith(prefix));
|
|
3313
3361
|
if (credential !== void 0) {
|
|
3314
3362
|
const answer = await credential.principalOf(token, request);
|
|
@@ -3360,9 +3408,9 @@ var operatorPrefix = (runtime) => {
|
|
|
3360
3408
|
var buildSignals = ({ fabric, identity, reset, adopt: adopt2, adoptAll: adoptAll2, deliver }) => {
|
|
3361
3409
|
const origin = crypto$1.randomBytes(8).toString("hex");
|
|
3362
3410
|
const applyInvalidateIdentity = (principal) => {
|
|
3363
|
-
const
|
|
3411
|
+
const forgotten = identity.invalidate(principal);
|
|
3364
3412
|
reset(principal);
|
|
3365
|
-
return
|
|
3413
|
+
return forgotten;
|
|
3366
3414
|
};
|
|
3367
3415
|
const applyInvalidateTag = (tag) => {
|
|
3368
3416
|
const forgotten = identity.invalidateTag(tag).length;
|
|
@@ -3380,9 +3428,9 @@ var buildSignals = ({ fabric, identity, reset, adopt: adopt2, adoptAll: adoptAll
|
|
|
3380
3428
|
});
|
|
3381
3429
|
return {
|
|
3382
3430
|
invalidateIdentity: (principal) => {
|
|
3383
|
-
const
|
|
3431
|
+
const forgotten = applyInvalidateIdentity(principal);
|
|
3384
3432
|
publish({ kind: "invalidate-identity", principal });
|
|
3385
|
-
return
|
|
3433
|
+
return forgotten;
|
|
3386
3434
|
},
|
|
3387
3435
|
invalidateTag: (tag) => {
|
|
3388
3436
|
const forgotten = applyInvalidateTag(tag);
|
|
@@ -3411,7 +3459,7 @@ var wireFabric = (fabric, origin, apply) => {
|
|
|
3411
3459
|
};
|
|
3412
3460
|
let refusalSaid = false;
|
|
3413
3461
|
fabric.subscribe((handed) => {
|
|
3414
|
-
const parsed =
|
|
3462
|
+
const parsed = chunk3CKBKTXA_cjs.FabricMessageSchema.safeParse(handed);
|
|
3415
3463
|
if (!parsed.success) {
|
|
3416
3464
|
if (refusalSaid) return;
|
|
3417
3465
|
refusalSaid = true;
|
|
@@ -3451,7 +3499,7 @@ var wireFabric = (fabric, origin, apply) => {
|
|
|
3451
3499
|
|
|
3452
3500
|
// src/server/server.ts
|
|
3453
3501
|
var createServerWith = async (app, runtime, dataOf) => {
|
|
3454
|
-
|
|
3502
|
+
chunk6ACVHHFK_cjs.receiveManifest(app);
|
|
3455
3503
|
const session = sessionVerifierOf(runtime);
|
|
3456
3504
|
const revokeSessions = sessionRevokerOf(runtime);
|
|
3457
3505
|
const data = await dataOf(app, runtime);
|
|
@@ -3481,7 +3529,9 @@ var buildData = (app, runtime) => createData({
|
|
|
3481
3529
|
charter: app.charter,
|
|
3482
3530
|
behaviors: app.behaviors,
|
|
3483
3531
|
rowRules: rowRulesBeside(app.behaviors),
|
|
3484
|
-
telemetry: runtime.telemetry
|
|
3532
|
+
telemetry: runtime.telemetry,
|
|
3533
|
+
answerReadableRows: runtime.answerReadableRows,
|
|
3534
|
+
checkMovedRows: runtime.checkMovedRows
|
|
3485
3535
|
});
|
|
3486
3536
|
var assembleServer = async (deps) => {
|
|
3487
3537
|
const stops = [];
|
|
@@ -3502,7 +3552,7 @@ var assemble = async ({ app, runtime, session, revokeSessions, data }, stops) =>
|
|
|
3502
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.`
|
|
3503
3553
|
);
|
|
3504
3554
|
}
|
|
3505
|
-
stops.push(startAging(runtime.pool, runtime.artifactsUnusedMs));
|
|
3555
|
+
stops.push(startAging(runtime.pool, runtime.artifactsUnusedMs, { sinceStart: runtime.artifactsUnusedSinceStart === true }));
|
|
3506
3556
|
}
|
|
3507
3557
|
const identity = buildIdentity(app, runtime, data);
|
|
3508
3558
|
stops.push(identity.stop);
|
|
@@ -3578,7 +3628,7 @@ var buildRunningManifest = async (app, runtime, data, saved) => {
|
|
|
3578
3628
|
...app.upgradedColumns !== void 0 ? { compileSeeded: data.compileQuery } : {}
|
|
3579
3629
|
});
|
|
3580
3630
|
data.dropOnChange(running.onChange);
|
|
3581
|
-
data.
|
|
3631
|
+
data.askEntriesFirst({ get: running.cacheEntry, entries: running.cacheEntries });
|
|
3582
3632
|
await running.cacheEntries();
|
|
3583
3633
|
return running;
|
|
3584
3634
|
};
|
|
@@ -3642,5 +3692,5 @@ exports.renderDocument = renderDocument;
|
|
|
3642
3692
|
exports.revokeAllFor = revokeAllFor;
|
|
3643
3693
|
exports.sessionCookies = sessionCookies;
|
|
3644
3694
|
exports.tableStatus = tableStatus;
|
|
3645
|
-
//# sourceMappingURL=chunk-
|
|
3646
|
-
//# sourceMappingURL=chunk-
|
|
3695
|
+
//# sourceMappingURL=chunk-UVY5ZPWW.cjs.map
|
|
3696
|
+
//# sourceMappingURL=chunk-UVY5ZPWW.cjs.map
|