@cruba/crubal 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +97 -2
  3. package/dist/bin/crubal.d.ts +2 -0
  4. package/dist/bin/crubal.js +103 -0
  5. package/dist/bin/crubal.js.map +1 -0
  6. package/dist/src/access.d.ts +126 -0
  7. package/dist/src/access.js +517 -0
  8. package/dist/src/access.js.map +1 -0
  9. package/dist/src/arrival.d.ts +55 -0
  10. package/dist/src/arrival.js +124 -0
  11. package/dist/src/arrival.js.map +1 -0
  12. package/dist/src/browser.d.ts +10 -0
  13. package/dist/src/browser.js +13 -0
  14. package/dist/src/browser.js.map +1 -0
  15. package/dist/src/bundle.d.ts +66 -0
  16. package/dist/src/bundle.js +753 -0
  17. package/dist/src/bundle.js.map +1 -0
  18. package/dist/src/canonical.d.ts +6 -0
  19. package/dist/src/canonical.js +47 -0
  20. package/dist/src/canonical.js.map +1 -0
  21. package/dist/src/conditions.d.ts +28 -0
  22. package/dist/src/conditions.js +216 -0
  23. package/dist/src/conditions.js.map +1 -0
  24. package/dist/src/corpus.d.ts +8 -0
  25. package/dist/src/corpus.js +1207 -0
  26. package/dist/src/corpus.js.map +1 -0
  27. package/dist/src/defs.d.ts +151 -0
  28. package/dist/src/defs.js +611 -0
  29. package/dist/src/defs.js.map +1 -0
  30. package/dist/src/dictionary.d.ts +65 -0
  31. package/dist/src/dictionary.js +557 -0
  32. package/dist/src/dictionary.js.map +1 -0
  33. package/dist/src/exchange.d.ts +236 -0
  34. package/dist/src/exchange.js +1035 -0
  35. package/dist/src/exchange.js.map +1 -0
  36. package/dist/src/forms.d.ts +16 -0
  37. package/dist/src/forms.js +169 -0
  38. package/dist/src/forms.js.map +1 -0
  39. package/dist/src/index.d.ts +27 -0
  40. package/dist/src/index.js +29 -0
  41. package/dist/src/index.js.map +1 -0
  42. package/dist/src/lex.d.ts +21 -0
  43. package/dist/src/lex.js +142 -0
  44. package/dist/src/lex.js.map +1 -0
  45. package/dist/src/lifecycle.d.ts +84 -0
  46. package/dist/src/lifecycle.js +415 -0
  47. package/dist/src/lifecycle.js.map +1 -0
  48. package/dist/src/log.d.ts +78 -0
  49. package/dist/src/log.js +506 -0
  50. package/dist/src/log.js.map +1 -0
  51. package/dist/src/migrate.d.ts +111 -0
  52. package/dist/src/migrate.js +286 -0
  53. package/dist/src/migrate.js.map +1 -0
  54. package/dist/src/model.d.ts +68 -0
  55. package/dist/src/model.js +188 -0
  56. package/dist/src/model.js.map +1 -0
  57. package/dist/src/packages.d.ts +69 -0
  58. package/dist/src/packages.js +232 -0
  59. package/dist/src/packages.js.map +1 -0
  60. package/dist/src/print-text.d.ts +7 -0
  61. package/dist/src/print-text.js +216 -0
  62. package/dist/src/print-text.js.map +1 -0
  63. package/dist/src/publish.d.ts +27 -0
  64. package/dist/src/publish.js +275 -0
  65. package/dist/src/publish.js.map +1 -0
  66. package/dist/src/read-text.d.ts +10 -0
  67. package/dist/src/read-text.js +385 -0
  68. package/dist/src/read-text.js.map +1 -0
  69. package/dist/src/records.d.ts +31 -0
  70. package/dist/src/records.js +72 -0
  71. package/dist/src/records.js.map +1 -0
  72. package/dist/src/review.d.ts +22 -0
  73. package/dist/src/review.js +198 -0
  74. package/dist/src/review.js.map +1 -0
  75. package/dist/src/rules.d.ts +96 -0
  76. package/dist/src/rules.js +611 -0
  77. package/dist/src/rules.js.map +1 -0
  78. package/dist/src/schedule.d.ts +24 -0
  79. package/dist/src/schedule.js +126 -0
  80. package/dist/src/schedule.js.map +1 -0
  81. package/dist/src/std-packages.d.ts +9 -0
  82. package/dist/src/std-packages.js +268 -0
  83. package/dist/src/std-packages.js.map +1 -0
  84. package/dist/src/store.d.ts +164 -0
  85. package/dist/src/store.js +538 -0
  86. package/dist/src/store.js.map +1 -0
  87. package/dist/src/tree.d.ts +35 -0
  88. package/dist/src/tree.js +159 -0
  89. package/dist/src/tree.js.map +1 -0
  90. package/dist/src/units-table.d.ts +1 -0
  91. package/dist/src/units-table.js +200 -0
  92. package/dist/src/units-table.js.map +1 -0
  93. package/dist/src/units.d.ts +42 -0
  94. package/dist/src/units.js +98 -0
  95. package/dist/src/units.js.map +1 -0
  96. package/dist/src/views.d.ts +216 -0
  97. package/dist/src/views.js +761 -0
  98. package/dist/src/views.js.map +1 -0
  99. package/package.json +60 -4
@@ -0,0 +1,517 @@
1
+ // access.ts: who may do what to which record (spec chapter 14). Owners hold the key; everything else is an
2
+ // edge: who, relation, mode, on which record (and everything within it), what it grants, granted under
3
+ // which edge. Modes nest (admin > control > consume > view > none); you grant only what you hold; an edge
4
+ // is only as good as its grantor; packages declare the permission menu, presets and relations; gated edges
5
+ // turn writes into suggestions; emergency edges are the one grant not made inside the owner.
6
+ import { compareTime, evaluate, parseCondition } from "./conditions.js";
7
+ import { resolve } from "./dictionary.js";
8
+ import { splitTop } from "./lex.js";
9
+ import { CrubalError, readTree } from "./tree.js";
10
+ import { shownAudience } from "./views.js";
11
+ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
12
+ export const MODES = ["none", "view", "consume", "control", "admin"];
13
+ export const VERBS = ["see", "edit", "run", "review", "archive", "merge", "apply", "install", "grant"];
14
+ const rank = (m) => MODES.indexOf(m);
15
+ export function emptyPermissions() {
16
+ return { menu: new Map(), presets: new Map(), relations: new Map(), ownership: new Map() };
17
+ }
18
+ const list = (v) => v.split(",").map((s) => s.trim()).filter(Boolean);
19
+ /** `run checkIn, see unit::price on: administered` → verbs and an optional scope. */
20
+ function readMenuItem(name, value, line) {
21
+ let text = value.trim();
22
+ let on;
23
+ const at = text.indexOf(" on: ");
24
+ if (at >= 0) {
25
+ on = text.slice(at + 5).trim();
26
+ text = text.slice(0, at).trim();
27
+ }
28
+ const verbs = {};
29
+ let current = null;
30
+ for (const piece of splitTop(text, ",", line)) {
31
+ const [first = "", ...rest] = piece.split(/\s+/);
32
+ if (VERBS.includes(first)) {
33
+ current = first;
34
+ verbs[current] = [...(verbs[current] ?? []), ...rest];
35
+ }
36
+ else if (current)
37
+ verbs[current] = [...(verbs[current] ?? []), ...piece.split(/\s+/)];
38
+ else
39
+ throw new CrubalError(`a menu item starts with a verb (${VERBS.join(", ")}): ${piece}`, line);
40
+ }
41
+ return { name, verbs, ...(on ? { on } : {}), line };
42
+ }
43
+ /** Read `permissions:`, `ownership:`, `emergency:` and `edge:` blocks. */
44
+ export function readAccess(source) {
45
+ const perms = emptyPermissions();
46
+ const edges = [];
47
+ for (const n of readTree(source)) {
48
+ if (n.kind !== "pair" || !n.key)
49
+ continue;
50
+ if (n.key === "permissions") {
51
+ perms.name = n.value.trim();
52
+ for (const c of n.children) {
53
+ if (c.key === "menu")
54
+ for (const m of c.children)
55
+ if (m.key)
56
+ perms.menu.set(m.key, readMenuItem(m.key, m.value, m.line));
57
+ if (c.key === "presets") {
58
+ for (const p of c.children) {
59
+ if (!p.key)
60
+ continue;
61
+ let text = p.value;
62
+ let audience = "member";
63
+ const at = text.indexOf(" audience: ");
64
+ if (at >= 0) {
65
+ audience = text.slice(at + 11).trim();
66
+ text = text.slice(0, at);
67
+ }
68
+ perms.presets.set(p.key, { name: p.key, items: list(text), audience, line: p.line });
69
+ }
70
+ }
71
+ if (c.key === "relations") {
72
+ for (const r of list(c.value)) {
73
+ const only = / only$/.test(r);
74
+ perms.relations.set(r.replace(/ only$/, ""), { only });
75
+ }
76
+ }
77
+ }
78
+ }
79
+ else if (n.key === "role") {
80
+ // The `role:` short form (12.4): one preset of that name, one menu item per verb line.
81
+ const name = n.value.trim();
82
+ const audience = n.children.find((c) => c.key === "audience")?.value.trim() ?? "member";
83
+ const items = [];
84
+ for (const v of n.children.find((c) => c.key === "may")?.children ?? []) {
85
+ if (!v.key)
86
+ continue;
87
+ const item = `${name}.${v.key}`;
88
+ perms.menu.set(item, { name: item, verbs: { [v.key]: list(v.value) }, line: v.line });
89
+ items.push(item);
90
+ }
91
+ perms.presets.set(name, { name, items, audience, line: n.line });
92
+ }
93
+ else if (n.key === "ownership") {
94
+ for (const c of n.children)
95
+ if (c.key)
96
+ perms.ownership.set(c.key, list(c.value));
97
+ }
98
+ else if (n.key === "emergency") {
99
+ const get = (k) => n.children.find((c) => c.key === k)?.value.trim();
100
+ perms.emergency = { approvers: Number(get("approvers") ?? 2), longest: get("longest") ?? "PT24H" };
101
+ }
102
+ else if (n.key === "edge") {
103
+ edges.push(readEdge(n));
104
+ }
105
+ }
106
+ return { perms, edges };
107
+ }
108
+ function readEdge(n) {
109
+ const get = (k) => n.children.find((c) => c.key === k);
110
+ const v = (k) => get(k)?.value.trim();
111
+ const e = {
112
+ edge: n.value.trim(),
113
+ who: v("who") ?? "",
114
+ relation: v("relation") ?? "",
115
+ mode: (v("mode") ?? "none"),
116
+ on: v("on") ?? "",
117
+ grants: list(v("grants") ?? ""),
118
+ by: v("by") ?? "",
119
+ line: n.line,
120
+ };
121
+ for (const k of ["where", "until", "gate", "reviewer"])
122
+ if (v(k))
123
+ e[k] = v(k);
124
+ const em = get("emergency");
125
+ if (em) {
126
+ const o = {};
127
+ for (const c of em.children)
128
+ if (c.key)
129
+ o[c.key] = c.key === "approvals" ? list(c.value) : c.value.trim();
130
+ e.emergency = o;
131
+ }
132
+ return e;
133
+ }
134
+ /** Is `who` a caller of another owner? Local callers are bare IDs; foreign ones carry their owner's domain. */
135
+ export function foreign(who, owner) {
136
+ const m = who.match(/^([a-z0-9.-]+\.[a-z]+):/);
137
+ return !!m && m[1] !== owner;
138
+ }
139
+ const ISO_DURATION = /^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?)?$/;
140
+ function durationMs(d) {
141
+ const m = d.match(ISO_DURATION);
142
+ if (!m)
143
+ return Number.NaN;
144
+ return (Number(m[1] ?? 0) * 24 * 60 + Number(m[2] ?? 0) * 60 + Number(m[3] ?? 0)) * 60_000;
145
+ }
146
+ export class Access {
147
+ /** The package's show rules (12.4), when the caller has them; without them every facet counts as public. */
148
+ views;
149
+ /**
150
+ * May the caller see a facet of a record without an item: what the show rules give their audience,
151
+ * capped at member (12.4, default deny above member: a staff facet takes an item; admin and the owner see
152
+ * everything). A rule with a `for` covering the record decides over one for everywhere.
153
+ */
154
+ visible(callerId, facet, recordId) {
155
+ if (!this.views)
156
+ return true;
157
+ const min = shownAudience(this.views, facet, recordId ? this.records.get(recordId) : undefined, this.dict);
158
+ if (!min)
159
+ return true;
160
+ const order = ["public", "member", "staff", "owner"];
161
+ return Math.min(order.indexOf(this.audienceOf(callerId)), 1) >= order.indexOf(min);
162
+ }
163
+ /** The edges; a store that journals (chapter 8.5) points this at its draft's edges. */
164
+ edges = new Map();
165
+ dict;
166
+ perms;
167
+ records;
168
+ owner;
169
+ now;
170
+ constructor(dict, perms, records, edges, owner, now) {
171
+ this.dict = dict;
172
+ this.perms = perms;
173
+ this.records = records;
174
+ this.owner = owner;
175
+ this.now = now;
176
+ for (const e of edges)
177
+ this.edges.set(e.edge, e);
178
+ }
179
+ /** The records up a record's `within` chain, nearest first (14.2). */
180
+ ancestors(id) {
181
+ const out = [];
182
+ let cur = this.records.get(id)?.within;
183
+ while (cur && !out.includes(cur) && out.length < 1000) {
184
+ out.push(cur);
185
+ cur = this.records.get(cur)?.within;
186
+ }
187
+ return out;
188
+ }
189
+ /** Refuse a `within` cycle (14.12). `lineOf` names the line a record was written at, for the refusal. */
190
+ checkWithin(lineOf) {
191
+ for (const r of this.records.all()) {
192
+ const seen = new Set([r.id]);
193
+ let cur = r.within;
194
+ while (cur) {
195
+ if (seen.has(cur))
196
+ throw new CrubalError(`${r.id} is within itself through ${cur}`, lineOf?.(r.id));
197
+ seen.add(cur);
198
+ const up = this.records.get(cur);
199
+ if (up && up.owner !== r.owner)
200
+ throw new CrubalError(`${r.id} is within ${cur}, which belongs to ${up.owner}: within never crosses owners`, lineOf?.(r.id));
201
+ cur = up?.within;
202
+ }
203
+ }
204
+ }
205
+ /** A merged record resolves through `into` (1.12), for edges on it and reaches into it. */
206
+ surviving(id) {
207
+ let cur = id;
208
+ for (let i = 0; i < 100; i++) {
209
+ const r = this.records.get(cur);
210
+ if (!r || r.status?.reason !== "merged" || !r.status.into)
211
+ return cur;
212
+ cur = r.status.into;
213
+ }
214
+ return cur;
215
+ }
216
+ covers(e, recordId) {
217
+ const on = this.surviving(e.on);
218
+ const target = this.surviving(recordId);
219
+ return on === target || this.ancestors(target).includes(on);
220
+ }
221
+ /** Does the edge's `where` hold for this record (14.4)? It narrows per record covered. */
222
+ holds(e, recordId) {
223
+ if (!e.where)
224
+ return true;
225
+ const r = this.records.get(recordId);
226
+ // A record with no status is active (1.12), so `not status is archived` holds for it.
227
+ const status = r?.status?.state ?? "active";
228
+ const vals = { id: recordId, status, "crubal:id": recordId, "crubal:status": status, ...(r?.values ?? {}) };
229
+ return evaluate(parseCondition(e.where), vals) === true;
230
+ }
231
+ /** Is an edge live (14.4, 14.5): not lapsed, and its grantor live and covering it? */
232
+ live(e, seen = new Set()) {
233
+ if (seen.has(e.edge))
234
+ return false;
235
+ seen.add(e.edge);
236
+ if (e.until && this.now) {
237
+ const c = compareTime(e.until, this.now);
238
+ if (c !== "undetermined" && c <= 0)
239
+ return false;
240
+ }
241
+ if (e.by === "owner" || e.by === "platform")
242
+ return true;
243
+ const g = this.edges.get(e.by);
244
+ return !!g && this.live(g, seen) && this.covers(g, e.on);
245
+ }
246
+ /** Does the caller hold the key to this record: the owner, or a hosted person over a record they own? */
247
+ owns(callerId, recordId) {
248
+ if (callerId === this.owner)
249
+ return true;
250
+ const owner = this.records.get(recordId)?.owner;
251
+ return !!owner && (owner === callerId || owner === `${this.owner}:${callerId}`);
252
+ }
253
+ /**
254
+ * The audience a caller belongs to (12.4, 14.4): the owner; staff for anyone with a control or admin
255
+ * edge, or an emergency edge; member for anyone the owner has admitted by any live edge; else public.
256
+ */
257
+ audienceOf(callerId) {
258
+ if (callerId === this.owner)
259
+ return "owner";
260
+ const mine = [...this.edges.values()].filter((e) => e.who === callerId && this.live(e));
261
+ if (mine.some((e) => e.mode === "control" || e.mode === "admin" || e.by === "platform" || e.relation === "emergency"))
262
+ return "staff";
263
+ return mine.length ? "member" : "public";
264
+ }
265
+ /** The menu items a list of grants expands to (presets open up). */
266
+ expand(grants) {
267
+ const out = new Set();
268
+ for (const g of grants) {
269
+ const p = this.perms.presets.get(g);
270
+ if (p)
271
+ for (const i of p.items)
272
+ out.add(i);
273
+ else
274
+ out.add(g);
275
+ }
276
+ return out;
277
+ }
278
+ /** A caller's access to a record from every live edge on it or an ancestor (14.4). */
279
+ effective(callerId, recordId) {
280
+ if (this.owns(callerId, recordId))
281
+ return { mode: "admin", items: new Set(this.perms.menu.keys()), relations: new Set(["owner"]), gated: false, edges: [] };
282
+ const mine = [...this.edges.values()].filter((e) => e.who === callerId && this.covers(e, recordId) && this.live(e) && this.holds(e, recordId));
283
+ let mode = "none";
284
+ const items = new Set();
285
+ const relations = new Set();
286
+ let gated = mine.some((e) => e.mode !== "none");
287
+ for (const e of mine) {
288
+ relations.add(e.relation);
289
+ if (rank(e.mode) > rank(mode))
290
+ mode = e.mode;
291
+ if (e.mode === "control")
292
+ for (const i of this.expand(e.grants))
293
+ items.add(i);
294
+ if (e.mode !== "none" && !e.gate)
295
+ gated = false;
296
+ }
297
+ if (mode === "admin")
298
+ for (const k of this.perms.menu.keys())
299
+ items.add(k);
300
+ return { mode, items, relations, gated, edges: mine };
301
+ }
302
+ /** Does the caller stand in a view's partition to the record (12.6, 14.10)? */
303
+ standsIn(callerId, recordId, partition) {
304
+ if (!partition || partition === "none")
305
+ return true;
306
+ const eff = this.effective(callerId, recordId);
307
+ if (partition === "owned")
308
+ return this.owns(callerId, recordId);
309
+ if (partition === "administered")
310
+ return eff.mode === "admin";
311
+ if (partition === "controlled")
312
+ return rank(eff.mode) >= rank("control");
313
+ const rel = partition.match(/^relation (\S+)$/);
314
+ if (rel)
315
+ return eff.relations.has(rel[1]);
316
+ return false;
317
+ }
318
+ scopeOk(item, callerId, recordId, eff) {
319
+ if (!item.on)
320
+ return true;
321
+ if (item.on === "owned")
322
+ return this.owns(callerId, recordId);
323
+ if (item.on === "administered")
324
+ return eff.mode === "admin";
325
+ const rel = item.on.match(/^relation (\S+)$/);
326
+ if (rel)
327
+ return eff.relations.has(rel[1]);
328
+ const r = this.records.get(recordId);
329
+ const caller = this.records.get(callerId);
330
+ const cond = item.on.replace(/caller\.(\w+)/g, (_, k) => JSON.stringify(String(caller?.values[k] ?? "")));
331
+ const vals = { ...(r?.values ?? {}), id: recordId };
332
+ return evaluate(parseCondition(cond), vals) === true;
333
+ }
334
+ /** May the caller do `verb` to `target` on the record (14.4, 14.6)? */
335
+ may(callerId, verb, target, recordId) {
336
+ const eff = this.effective(callerId, recordId);
337
+ if (eff.mode === "admin")
338
+ return true;
339
+ if (eff.mode === "control") {
340
+ for (const name of eff.items) {
341
+ const item = this.perms.menu.get(name);
342
+ if (!item)
343
+ continue;
344
+ const targets = item.verbs[verb];
345
+ if (!targets || !(targets.includes(target) || targets.includes("*")))
346
+ continue;
347
+ if (this.scopeOk(item, callerId, recordId, eff))
348
+ return true;
349
+ }
350
+ // Each mode includes the ones below it (14.4): what any admitted person may do stays theirs, and
351
+ // above member the default is deny (12.4): a staff facet needs an item.
352
+ if (verb === "see")
353
+ return this.visible(callerId, target, recordId);
354
+ return verb === "run" && eff.edges.some((e) => e.mode === "consume" && e.on === recordId);
355
+ }
356
+ if (eff.mode === "consume") {
357
+ // Take part: run what the package opens to consumers on their own part (the record the consume edge
358
+ // sits on directly), and see what the show rules let their audience see. Changing anything else is a contract's job.
359
+ if (verb === "see")
360
+ return this.visible(callerId, target, recordId);
361
+ return verb === "run" && eff.edges.some((e) => e.mode === "consume" && e.on === recordId);
362
+ }
363
+ if (eff.mode === "view")
364
+ return verb === "see" && this.visible(callerId, target, recordId);
365
+ return false;
366
+ }
367
+ /** May the caller do `verb` to `target` on any record at all: by a live admin edge, or a control edge carrying it? */
368
+ mayAnywhere(callerId, verb, target) {
369
+ if (callerId === this.owner)
370
+ return true;
371
+ for (const e of this.edges.values()) {
372
+ if (e.who !== callerId || !this.live(e))
373
+ continue;
374
+ if (e.mode === "admin")
375
+ return true;
376
+ if (e.mode !== "control")
377
+ continue;
378
+ for (const name of this.expand(e.grants)) {
379
+ const t = this.perms.menu.get(name)?.verbs[verb];
380
+ if (t && (t.includes(target) || t.includes("*")))
381
+ return true;
382
+ }
383
+ }
384
+ return false;
385
+ }
386
+ /** The live gated edge a caller's access comes through, when every granting edge is gated (14.7). */
387
+ gated(callerId, recordId) {
388
+ const eff = this.effective(callerId, recordId);
389
+ if (!eff.gated)
390
+ return null;
391
+ return eff.edges.find((e) => e.gate && e.mode !== "none") ?? null;
392
+ }
393
+ /** Refuse an edge the store may not write (14.12, 14.13). */
394
+ checkEdge(e) {
395
+ if (!MODES.includes(e.mode))
396
+ throw new CrubalError(`${e.edge}: a mode is ${MODES.join(", ")}, not ${e.mode}`, e.line);
397
+ if (e.by === "platform") {
398
+ this.checkEmergency(e);
399
+ return;
400
+ }
401
+ if (e.grants.length && e.mode !== "control")
402
+ throw new CrubalError(`${e.edge}: only a control edge carries grants`, e.line);
403
+ const rel = this.perms.relations.get(e.relation);
404
+ if (this.perms.relations.size && !rel)
405
+ throw new CrubalError(`${e.edge}: the relation ${e.relation} isn't declared`, e.line);
406
+ if (rel?.only && e.mode !== "none")
407
+ throw new CrubalError(`${e.edge}: ${e.relation} is a relation only, so its mode is none`, e.line);
408
+ for (const g of e.grants)
409
+ if (!this.perms.presets.has(g) && !this.perms.menu.has(g))
410
+ throw new CrubalError(`${e.edge}: ${g} is neither a preset nor a menu item`, e.line);
411
+ if (foreign(e.who, this.owner) && e.by !== "owner")
412
+ throw new CrubalError(`${e.edge}: only the owner may grant an edge to another owner's caller`, e.line);
413
+ if (e.by === "owner")
414
+ return;
415
+ const g = this.edges.get(e.by);
416
+ if (!g)
417
+ throw new CrubalError(`${e.edge}: granted under ${e.by}, which isn't an edge`, e.line);
418
+ if (rank(e.mode) > rank(g.mode))
419
+ throw new CrubalError(`${e.edge}: ${g.edge} holds ${g.mode}, so it can't grant ${e.mode}`, e.line);
420
+ if (!this.covers(g, e.on))
421
+ throw new CrubalError(`${e.edge}: ${e.on} is outside ${g.edge}'s reach`, e.line);
422
+ if (g.mode === "control") {
423
+ const held = this.expand(g.grants);
424
+ const grantTargets = new Set([...held].flatMap((n) => this.perms.menu.get(n)?.verbs.grant ?? []));
425
+ const mayGrant = (name) => grantTargets.has("*") || grantTargets.has(name);
426
+ for (const name of this.expand(e.grants)) {
427
+ if (!held.has(name))
428
+ throw new CrubalError(`${e.edge}: ${g.edge} doesn't hold ${name}`, e.line);
429
+ if (!mayGrant(name))
430
+ throw new CrubalError(`${e.edge}: ${g.edge} may not grant ${name}`, e.line);
431
+ }
432
+ if (e.mode !== "none" && !e.grants.length && !mayGrant(e.mode))
433
+ throw new CrubalError(`${e.edge}: ${g.edge} may not grant ${e.mode}`, e.line);
434
+ }
435
+ }
436
+ /** Refuse an emergency edge outside the platform's published terms (14.13). */
437
+ checkEmergency(e) {
438
+ const terms = this.perms.emergency;
439
+ if (!terms)
440
+ throw new CrubalError(`${e.edge}: no emergency terms are published, so no emergency edge can be made`, e.line);
441
+ const em = e.emergency;
442
+ if (!em)
443
+ throw new CrubalError(`${e.edge}: an emergency edge carries its kind, reason, reference and approvals`, e.line);
444
+ if (em.kind !== "legal" && em.kind !== "incident")
445
+ throw new CrubalError(`${e.edge}: an emergency is legal or incident`, e.line);
446
+ if (!em.reason || !em.reference)
447
+ throw new CrubalError(`${e.edge}: an emergency edge states its reason and reference`, e.line);
448
+ const approvals = Array.isArray(em.approvals) ? em.approvals.map(String) : [];
449
+ if (approvals.length < terms.approvers)
450
+ throw new CrubalError(`${e.edge}: ${approvals.length} approvals, the terms require ${terms.approvers}`, e.line);
451
+ if (approvals.includes(e.who))
452
+ throw new CrubalError(`${e.edge}: the requester can't approve their own edge`, e.line);
453
+ if (e.mode !== "view" && e.mode !== "control")
454
+ throw new CrubalError(`${e.edge}: an emergency edge is view or control, never ${e.mode}`, e.line);
455
+ for (const name of this.expand(e.grants))
456
+ if (this.perms.menu.get(name)?.verbs.grant)
457
+ throw new CrubalError(`${e.edge}: an emergency edge never grants`, e.line);
458
+ if (!e.until)
459
+ throw new CrubalError(`${e.edge}: an emergency edge has an until`, e.line);
460
+ const at = typeof em.at === "string" ? Date.parse(em.at) : Number.NaN;
461
+ if (!Number.isNaN(at) && Date.parse(e.until) - at > durationMs(terms.longest))
462
+ throw new CrubalError(`${e.edge}: outlasts the terms' longest, ${terms.longest}`, e.line);
463
+ }
464
+ /** Refuse a write that makes a record wear a class not for its kind, or classes whose meet is empty (5.5). */
465
+ checkWears(r, line) {
466
+ const worn = r.wears ?? [];
467
+ for (const w of worn) {
468
+ const c = this.dict.classes.get(w);
469
+ if (!c)
470
+ throw new CrubalError(`${r.id} wears ${w}, which isn't a class`, line);
471
+ if (c.for.length && !c.for.includes(r.kind))
472
+ throw new CrubalError(`${r.id} wears ${w}, which is for ${c.for.join(", ")}, not ${r.kind}`, line);
473
+ }
474
+ if (worn.length > 1) {
475
+ try {
476
+ resolve(this.dict, worn);
477
+ }
478
+ catch (e) {
479
+ throw new CrubalError(`${r.id} wears ${worn.join(", ")}: ${e instanceof Error ? e.message : String(e)}`, line);
480
+ }
481
+ }
482
+ }
483
+ /** Refuse a person owning a record the package doesn't let a person own (14.1, 14.12). */
484
+ checkOwnership(r, line) {
485
+ if (!foreign(r.owner, "") || r.owner.split(":")[0] !== this.owner)
486
+ return; // a domain owner, or another owner's record
487
+ const allowed = this.perms.ownership.get("person") ?? [];
488
+ const names = [r.kind, ...(r.wears ?? [])];
489
+ if (!names.some((n) => allowed.includes(n)))
490
+ throw new CrubalError(`${r.id}: a person may own ${allowed.join(", ") || "nothing"}, not a ${r.kind}`, line);
491
+ }
492
+ }
493
+ /** Publish checks for a permission block (14.6). */
494
+ export function checkPermissions(perms, dict, contracts = new Set(), views = new Set()) {
495
+ for (const item of perms.menu.values()) {
496
+ for (const [verb, targets] of Object.entries(item.verbs)) {
497
+ if (!VERBS.includes(verb))
498
+ throw new CrubalError(`${item.name}: unknown verb ${verb}`, item.line);
499
+ for (const t of targets) {
500
+ if (t === "*")
501
+ continue;
502
+ const key = t.replace(/^\w+::/, "");
503
+ const known = dict.facets.has(key) || dict.classes.has(t) || dict.levels.has(t) || contracts.has(t) || views.has(t) || perms.menu.has(t) || perms.presets.has(t) ||
504
+ ["arrivals", "vocabulary", "migrations", "gated", "unit", "product", "group"].includes(t);
505
+ if (!known && verb !== "grant")
506
+ throw new CrubalError(`${item.name}: ${verb} names ${t}, which isn't a facet, class, view, contract or queue`, item.line);
507
+ if (verb === "grant" && !perms.menu.has(t) && !perms.presets.has(t))
508
+ throw new CrubalError(`${item.name}: grant names ${t}, which isn't a menu item or preset`, item.line);
509
+ }
510
+ }
511
+ }
512
+ for (const p of perms.presets.values())
513
+ for (const i of p.items)
514
+ if (!perms.menu.has(i))
515
+ throw new CrubalError(`${p.name}: ${i} isn't a menu item`, p.line);
516
+ }
517
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../../src/access.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,uGAAuG;AACvG,0GAA0G;AAC1G,2GAA2G;AAC3G,6FAA6F;AAE7F,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAa,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAgB,MAAM,YAAY,CAAC;AAEzD,MAAM,KAAK,GAAG,CAAC,CAAmB,EAAmB,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,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AG,CAAC,CAAC,IAAI,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AAC9J,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { Dictionary } from "./defs.ts";
2
+ import type { Record, Source } from "./model.ts";
3
+ import type { RecordSet } from "./records.ts";
4
+ import { type Contract, type IntakeRecord } from "./store.ts";
5
+ export type Arrival = {
6
+ outcome: "bound" | "matched" | "held" | "new";
7
+ record?: string;
8
+ candidates?: string[];
9
+ /** The candidates that are archived (9.2a). */
10
+ archived?: string[];
11
+ /** How it was found: `binding`, `identify:<key>`, `match:<keys>`. */
12
+ by?: string;
13
+ ref?: string;
14
+ };
15
+ export type ArrivalStore = {
16
+ records: RecordSet;
17
+ bindings: Map<string, string>;
18
+ };
19
+ /** Follow a merged record to its survivor (1.12). */
20
+ export declare function surviving(store: ArrivalStore, id: string): string;
21
+ /**
22
+ * Resolve where a payload lands, fold it there (or hold it), and keep the binding. `mint` names a new
23
+ * record. The caller supplies the level the payload arrives at and, when known, its parent.
24
+ */
25
+ export declare function arrive(c: Contract, body: string, level: string, store: ArrivalStore, dict: Dictionary, opts: {
26
+ mint: () => string;
27
+ owner: string;
28
+ of?: string;
29
+ within?: string;
30
+ source?: Source;
31
+ intakeId?: string;
32
+ }): {
33
+ arrival: Arrival;
34
+ intake: IntakeRecord;
35
+ record?: Record;
36
+ };
37
+ /** A review decision for a held arrival (9.2a): bind the reference to a record, or to a new one. */
38
+ export declare function decide(c: Contract, held: {
39
+ intake: IntakeRecord;
40
+ ref?: string;
41
+ }, choice: {
42
+ record: string;
43
+ } | {
44
+ new: true;
45
+ }, store: ArrivalStore, dict: Dictionary, opts: {
46
+ mint: () => string;
47
+ owner: string;
48
+ level: string;
49
+ of?: string;
50
+ within?: string;
51
+ source?: Source;
52
+ }): {
53
+ arrival: Arrival;
54
+ record: Record;
55
+ };