@yaks/member 0.0.0-stage → 0.2.36

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 (86) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +471 -2
  3. package/_dist/asking.d.ts +4 -0
  4. package/_dist/asking.d.ts.map +1 -0
  5. package/_dist/comp.d.ts +14 -0
  6. package/_dist/comp.d.ts.map +1 -0
  7. package/_dist/deny.d.ts +19 -0
  8. package/_dist/deny.d.ts.map +1 -0
  9. package/_dist/graph.d.ts +4 -0
  10. package/_dist/graph.d.ts.map +1 -0
  11. package/_dist/guard.d.ts +45 -0
  12. package/_dist/guard.d.ts.map +1 -0
  13. package/_dist/keywords.d.ts +80 -0
  14. package/_dist/keywords.d.ts.map +1 -0
  15. package/_dist/mod.d.ts +112 -0
  16. package/_dist/mod.d.ts.map +1 -0
  17. package/_dist/owns.d.ts +18 -0
  18. package/_dist/owns.d.ts.map +1 -0
  19. package/_dist/pace.d.ts +48 -0
  20. package/_dist/pace.d.ts.map +1 -0
  21. package/_dist/personal.d.ts +46 -0
  22. package/_dist/personal.d.ts.map +1 -0
  23. package/_dist/plugin.d.ts +32 -0
  24. package/_dist/plugin.d.ts.map +1 -0
  25. package/_dist/policy.d.ts +35 -0
  26. package/_dist/policy.d.ts.map +1 -0
  27. package/_dist/privacy.d.ts +55 -0
  28. package/_dist/privacy.d.ts.map +1 -0
  29. package/_dist/roles.d.ts +20 -0
  30. package/_dist/roles.d.ts.map +1 -0
  31. package/_dist/vocab.d.ts +10 -0
  32. package/_dist/vocab.d.ts.map +1 -0
  33. package/_dist/words.d.ts +53 -0
  34. package/_dist/words.d.ts.map +1 -0
  35. package/asking.js +65 -0
  36. package/asking.js.map +1 -0
  37. package/asking.ts +77 -0
  38. package/comp.js +43 -0
  39. package/comp.js.map +1 -0
  40. package/comp.ts +52 -0
  41. package/deno.json +1 -0
  42. package/deny.js +31 -0
  43. package/deny.js.map +1 -0
  44. package/deny.ts +45 -0
  45. package/graph.js +6 -0
  46. package/graph.js.map +1 -0
  47. package/graph.ts +16 -0
  48. package/guard.js +265 -0
  49. package/guard.js.map +1 -0
  50. package/guard.ts +327 -0
  51. package/keywords.js +170 -0
  52. package/keywords.js.map +1 -0
  53. package/keywords.ts +190 -0
  54. package/meta/member.vocab.json +70 -0
  55. package/mod.js +112 -0
  56. package/mod.js.map +1 -0
  57. package/mod.ts +113 -0
  58. package/owns.js +12 -0
  59. package/owns.js.map +1 -0
  60. package/owns.ts +23 -0
  61. package/pace.js +189 -0
  62. package/pace.js.map +1 -0
  63. package/pace.ts +195 -0
  64. package/package.json +33 -4
  65. package/personal.js +448 -0
  66. package/personal.js.map +1 -0
  67. package/personal.ts +550 -0
  68. package/plugin.js +63 -0
  69. package/plugin.js.map +1 -0
  70. package/plugin.ts +62 -0
  71. package/policy.js +115 -0
  72. package/policy.js.map +1 -0
  73. package/policy.ts +176 -0
  74. package/privacy.js +293 -0
  75. package/privacy.js.map +1 -0
  76. package/privacy.ts +379 -0
  77. package/roles.js +164 -0
  78. package/roles.js.map +1 -0
  79. package/roles.ts +245 -0
  80. package/vocab.js +19 -0
  81. package/vocab.js.map +1 -0
  82. package/vocab.json +272 -0
  83. package/vocab.ts +20 -0
  84. package/words.js +75 -0
  85. package/words.js.map +1 -0
  86. package/words.ts +123 -0
package/guard.ts ADDED
@@ -0,0 +1,327 @@
1
+ // The write check, as a @yaks/graph hook.
2
+ //
3
+ // It runs at `precondition` — inside the transaction, before a single row has
4
+ // moved — for the same reason the `$was` guard does: a check that reads after
5
+ // the write is checking its own work. Throwing here rolls the whole transaction
6
+ // back, so a batch is admitted entirely or not at all, and there is
7
+ // no half-written state for the caller to reconcile.
8
+ //
9
+ // It asks four questions, in this order:
10
+ //
11
+ // 1. May this principal write this app at all? (`open` mode, or owner/editor)
12
+ // 2. Do the bundles touch a component that asks a floor of its own? The
13
+ // access rows ask owner, always; the vocabulary declares the rest
14
+ // (`floor`, keywords.ts), and so may the program installing the guard
15
+ // (`floors`).
16
+ // 3. Is the principal in only because the app is `open`? Then it adds rows,
17
+ // changes the rows it wrote, answers a stored reference's request with a
18
+ // declared companion mark (`permit`), and puts a row the program keeps
19
+ // `within` its parent only inside a parent of its own.
20
+ // 4. Does a bundle write a component sooner than its `pace` lets this writer
21
+ // (pace.ts)?
22
+ //
23
+ // None of them is a new level. They are the rules that an editor writes the
24
+ // app's data and does not hand out permissions, that a shop's prices are its
25
+ // editors' however open its guest book is, that a chat takes lines only from
26
+ // people signed in, that a visitor signs the guest book without erasing it, and
27
+ // that nobody fills it faster than the rest can read. They matter most on an
28
+ // `open` app, where the first question admits everybody: without them, a
29
+ // visitor invited to sign could rewrite the roster and lock the owner out, set
30
+ // the price of everything to a cent, delete every entry but their own, or push
31
+ // everyone else's out of sight.
32
+ //
33
+ // A row is the principal's own when its `created.by` names them, or when it is
34
+ // them. Without a `created.by`, a row belongs to the `created.via` that made
35
+ // it. A caller with neither identity owns nothing, so it only adds. A bundle
36
+ // that changes nothing — every property it names already holds that value —
37
+ // is nobody's business, which lets the same bytes be uploaded twice.
38
+ //
39
+ // The principal is whatever `$actor` the bundles carry. An HTTP layer replaces
40
+ // that field with the identity it authenticated before calling `apply()`
41
+ // (@yaks/api `signed`). Bundles with no `$actor` act as nobody — allowed on an
42
+ // `open` app, refused everywhere else — which is what an anonymous visitor
43
+ // should get.
44
+
45
+ import type { Actor, Ask, Bundle, Comp, Eid, Hook, Tx } from 'jsr:@yaks/graph@0.2.36'
46
+ import { after } from '@yaks/fp'
47
+ import { actorOf as writerOf } from '@yaks/graph/provenance'
48
+ import { comps, dead } from '@yaks/graph/bundle'
49
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
50
+ import { GOVERNED, GRANT, MEMBER } from './comp.js'
51
+ import { owns } from './owns.js'
52
+ import { levelOn, modeOn, type Viewer, type Where } from './policy.js'
53
+ import { Denied } from './deny.js'
54
+ import { floorsIn, type Permits, permitsIn } from './keywords.js'
55
+ import { type Instrument, pacesIn, pacing } from './pace.js'
56
+ import { edits, type Floors, type Level, stands, writes } from './words.js'
57
+
58
+ /** Which app a guard decides for, and whose roster governs it. */
59
+ export type Guard = Where & {
60
+ /** the app this graph holds — its `access` mode decides a write by a
61
+ * principal that holds no level */
62
+ app: Eid
63
+ /** the vocabulary the graph was loaded with, whose components' declared
64
+ * `floor` and `permit` (registered with `memberKeywords`) and `pace` hold here */
65
+ vocab: Vocab
66
+ /** components that ask a floor of their own besides the ones the vocabulary
67
+ * declares — `{ product: 'editor' }` keeps a shop's prices its editors' on
68
+ * an `open` app, and wins over a declared one. The access rows ask `owner`
69
+ * whatever either says. */
70
+ floors?: Floors
71
+ /** components a principal holding no writing level writes only inside a row
72
+ * of its own, each named with the reference to that row: `{ entry:
73
+ * 'session' }` keeps an `open` app's visitor writing lines in their own
74
+ * transcripts, where a line in someone else's would ask for a model's turn
75
+ * at the account's expense. A row created in the same batch is the
76
+ * principal's own. */
77
+ within?: Record<string, string>
78
+ /** Current standing vouched by the receiving boundary. Null is an
79
+ * authoritative absence; undefined asks the stored roster. */
80
+ level?: (who: Viewer, writer: Actor) => Level | null | undefined
81
+ /** Canonical identity of a vouched instrument, including stored identities
82
+ * retained while a host migrates its attribution. Defaults to exact eids. */
83
+ instrument?: Instrument
84
+ /** the time pace is kept by, in ms (default: `Date.now`) */
85
+ now?: () => number
86
+ }
87
+
88
+ /** The principal a signed transaction acts as: every bundle in it was signed by
89
+ * the same HTTP layer, so the first one carrying an `$actor` settles it for all
90
+ * of them. */
91
+ export let actorOf = (bundles: Bundle[]): Viewer => {
92
+ for (let b of bundles) {
93
+ let by = b.$actor?.by
94
+ if (by) return by
95
+ }
96
+ return null
97
+ }
98
+
99
+ let OWNED: Floors = Object.fromEntries(GOVERNED.map((c) => [c, 'owner']))
100
+
101
+ // Every floor a guard holds: the vocabulary's, the program's over them, and
102
+ // the access rows' over both.
103
+ let held = (where: Guard): Floors => ({
104
+ ...floorsIn(where.vocab),
105
+ ...where.floors,
106
+ ...OWNED,
107
+ })
108
+
109
+ // The first component these bundles touch whose floor this principal, holding
110
+ // this level, does not stand on.
111
+ let short = (
112
+ floors: Floors,
113
+ who: Viewer,
114
+ level: Level | null,
115
+ bundles: Bundle[],
116
+ ): string | undefined => {
117
+ for (let b of bundles) {
118
+ for (let [name] of comps(b)) {
119
+ let f = floors[name]
120
+ if (f && !stands(who, level, f)) return name
121
+ }
122
+ }
123
+ }
124
+
125
+ // Theirs: the person owns their entity and bylined rows; an unbylined row
126
+ // belongs only to the instrument that made it.
127
+ let mine = (
128
+ row: Bundle,
129
+ who: Viewer,
130
+ via: Eid | undefined,
131
+ instrument: Instrument,
132
+ ) => {
133
+ let created = row.created as Comp | undefined
134
+ return !!who && row.entity.eid == who ||
135
+ owns({
136
+ by: typeof created?.by == 'string' ? created.by : null,
137
+ via: typeof created?.via == 'string' ? instrument(created.via) : null,
138
+ }, { by: who, via: via ? instrument(via) : null })
139
+ }
140
+
141
+ // Nothing this bundle says differs from the row it names.
142
+ let idle = (b: Bundle, row: Bundle) =>
143
+ dead(b) ? dead(row) : comps(b).every(([name, comp]) => {
144
+ let held = row[name] as Comp | null | undefined
145
+ if (!comp) return held == null
146
+ return !!held && Object.entries(comp).every(([prop, v]) => held[prop] == v)
147
+ })
148
+
149
+ // The parents the bundles put a kept row in, as their patches or stored rows
150
+ // name them, must be the principal's own; one not stored yet is being made here.
151
+ let inside = (
152
+ tx: Tx,
153
+ who: Viewer,
154
+ app: Eid,
155
+ bundles: Bundle[],
156
+ via: Eid | undefined,
157
+ within: Record<string, string>,
158
+ instrument: Instrument,
159
+ ) => {
160
+ let kept = bundles.filter((b) =>
161
+ !dead(b) && Object.keys(within).some((c) => b[c] !== undefined)
162
+ )
163
+ if (!kept.length) return bundles
164
+ return after(tx.get([...new Set(kept.map((b) => b.entity.eid))]), (rows) => {
165
+ let held = new Map(rows.map((r) => [r.entity.eid, r]))
166
+ let parents = new Set(
167
+ kept.flatMap((b) =>
168
+ Object.entries(within).flatMap(([c, prop]) => {
169
+ if (b[c] === null) return []
170
+ let ref = (b[c] as Comp | undefined)?.[prop] ??
171
+ (held.get(b.entity.eid)?.[c] as Comp | undefined)?.[prop]
172
+ return typeof ref == 'string' ? [ref] : []
173
+ })
174
+ ),
175
+ )
176
+ return after(parents.size ? tx.get([...parents]) : [], (rows) => {
177
+ if (rows.some((r) => !mine(r, who, via, instrument))) {
178
+ throw new Denied(who, app, 'editor')
179
+ }
180
+ return bundles
181
+ })
182
+ })
183
+ }
184
+
185
+ // A principal the mode admits and no level does: new rows, and its own.
186
+ let adding = (
187
+ tx: Tx,
188
+ who: Viewer,
189
+ app: Eid,
190
+ bundles: Bundle[],
191
+ via: Eid | undefined,
192
+ permits: Permits,
193
+ instrument: Instrument,
194
+ ) =>
195
+ after(tx.get([...new Set(bundles.map((b) => b.entity.eid))]), (rows) => {
196
+ let held = new Map(rows.map((r) => [r.entity.eid, r]))
197
+ let foreign = bundles.filter((b) => {
198
+ let row = held.get(b.entity.eid)
199
+ if (!row || mine(row, who, via, instrument) || idle(b, row)) return false
200
+ if (dead(b) || dead(row)) throw new Denied(who, app, 'editor')
201
+ return true
202
+ })
203
+ if (!foreign.length) return bundles
204
+ // Read referenced owners once, from stored requests rather than incoming
205
+ // patches. Every bundle is still checked, so a second patch cannot rebind
206
+ // or delete a request beside its permitted mark.
207
+ let targets = new Set<Eid>()
208
+ let refs = (row: Bundle, mark: string): Eid[] =>
209
+ Object.entries(permits).flatMap(([comp, marks]) => {
210
+ let ref = (row[comp] as Comp | undefined)?.[marks[mark]]
211
+ return typeof ref == 'string' ? [ref] : []
212
+ })
213
+ for (let b of foreign) {
214
+ let row = held.get(b.entity.eid)!
215
+ for (let [name] of comps(b)) {
216
+ for (let eid of refs(row, name)) targets.add(eid)
217
+ }
218
+ }
219
+ return after(targets.size ? tx.get([...targets]) : [], (rows) => {
220
+ let owners = new Map(rows.map((r) => [r.entity.eid, r]))
221
+ for (let b of foreign) {
222
+ let row = held.get(b.entity.eid)!
223
+ let allowed = comps(b).every(([name, patch]) =>
224
+ refs(row, name).some((eid) => {
225
+ let target = owners.get(eid)
226
+ return !!target && !dead(target) &&
227
+ mine(target, who, via, instrument) &&
228
+ (patch === null || !row[name] ||
229
+ idle({ entity: b.entity, [name]: patch }, row))
230
+ })
231
+ )
232
+ if (!allowed) throw new Denied(who, app, 'editor')
233
+ }
234
+ return bundles
235
+ })
236
+ })
237
+
238
+ /**
239
+ * Everything the permission check is about to read, declared before it reads
240
+ * any of it: the app (its mode decides for a principal with no level), the
241
+ * principal's own entity (a share link's bearer is a grant), everything filed
242
+ * about the principal — their membership rows, their grants — and the rows the
243
+ * bundles name, whose byline says whose they are. @yaks/graph fetches these in
244
+ * one gather; companion permissions then read the stored reference targets in
245
+ * one additional batch.
246
+ */
247
+ export let wanting = (where: Guard) => (bundles: Bundle[]): Ask[] => {
248
+ if (!bundles.length) return []
249
+ let who = actorOf(bundles)
250
+ let level = where.level?.(who, writerOf(bundles))
251
+ let eids = bundles.map((b) => b.entity.eid)
252
+ if (!writes(level ?? null)) eids.push(where.app)
253
+ if (level !== undefined) return [{ eids }]
254
+ return who
255
+ ? [{ eids: [...eids, who] }, { about: [who], comps: [GRANT, MEMBER] }]
256
+ : [{ eids }]
257
+ }
258
+
259
+ /**
260
+ * The `precondition` hook: refuse bundles this principal may not write.
261
+ * Registered by {@link https://jsr.io/@yaks/member/doc/~/members | members};
262
+ * exported on its own for a graph that wants the check without this package's
263
+ * components.
264
+ */
265
+ export let guarding = (where: Guard): Hook => {
266
+ let floors = held(where)
267
+ let floored = Object.keys(floors).filter((name) => where.vocab.comp(name))
268
+ let permits = permitsIn(where.vocab)
269
+ let paces = pacesIn(where.vocab)
270
+ let instrument = where.instrument ?? ((via: Eid) => via)
271
+ let within = where.within ?? {}
272
+ let now = where.now ?? Date.now
273
+ if (Object.keys(paces).length && !where.vocab.comp('_pace')) {
274
+ throw new Error('stored pacing needs memberDoc in the graph vocabulary')
275
+ }
276
+ return (bundles, tx) => {
277
+ if (!bundles.length) return bundles
278
+ let who = actorOf(bundles)
279
+ let vouched = where.level?.(who, writerOf(bundles))
280
+ return after(
281
+ vouched === undefined ? levelOn(tx, who, where.app, where) : vouched,
282
+ (level) =>
283
+ after(
284
+ writes(level) ? null : modeOn(tx, where.app),
285
+ (mode) => {
286
+ if (!writes(level) && !edits(mode!, level)) {
287
+ throw new Denied(who, where.app, 'editor')
288
+ }
289
+ let comp = short(floors, who, level, bundles)
290
+ if (comp) {
291
+ throw new Denied(who, where.app, floors[comp], 'write', comp)
292
+ }
293
+ let via = writerOf(bundles).via
294
+ let deleted = bundles.filter(dead).map((b) => b.entity.eid)
295
+ let protectedComps = deleted.length
296
+ ? floored.filter((name) => !stands(who, level, floors[name]))
297
+ : []
298
+ return after(
299
+ protectedComps.length ? tx.get(deleted, protectedComps) : [],
300
+ (rows) => {
301
+ let comp = short(floors, who, level, rows)
302
+ if (comp) {
303
+ throw new Denied(who, where.app, floors[comp], 'write', comp)
304
+ }
305
+ return after(
306
+ writes(level) ? bundles : after(
307
+ inside(
308
+ tx,
309
+ who,
310
+ where.app,
311
+ bundles,
312
+ via,
313
+ within,
314
+ instrument,
315
+ ),
316
+ (b) =>
317
+ adding(tx, who, where.app, b, via, permits, instrument),
318
+ ),
319
+ (b) => pacing(paces, tx, b, now(), where.instrument),
320
+ )
321
+ },
322
+ )
323
+ },
324
+ ),
325
+ ) as Bundle[] | Promise<Bundle[]>
326
+ }
327
+ }
package/keywords.js ADDED
@@ -0,0 +1,170 @@
1
+ // The registration: the custom JSON Schema keyword @yaks/member adds to a
2
+ // component vocabulary, declared in JSON Schema's own extension form, and the
3
+ // reading of it. `meta/member.vocab.json` is the authored source; this module
4
+ // gives it a name and the shape `loadVocab(docs, [memberKeywords])` expects.
5
+ //
6
+ // `floor` is the least a component asks of whoever writes it. The
7
+ // guard's `floors` option says the same thing from outside, for a program
8
+ // holding words it did not declare; `floor` is a vocabulary saying it about its
9
+ // own, so an app that declares a word also declares who may write it.
10
+ // `readers` is the same ladder for whoever reads it: an entity wearing the
11
+ // component is seen only by readers standing on that floor, whatever the mode;
12
+ // an object of floors to queries asks a floor only of the entities it matches.
13
+ // `shown` asks a floor of whoever reads the component alone: a reader below it
14
+ // reads the entity without the component, as `personal: "entity"` keeps one
15
+ // aspect of a person's entity.
16
+ // `permit` lets the owner of a stored reference answer with a companion mark,
17
+ // without gaining the declaring row or permission to change its request.
18
+ // `personal` names the owner of a private entity or private person component.
19
+ import { marked } from "@yaks/graph/provenance";
20
+ import doc from './meta/member.vocab.json' with {
21
+ type: 'json'
22
+ };
23
+ import { askedErrors, askedOf, asking } from "./asking.js";
24
+ import { floor, isFloor } from "./words.js";
25
+ /** The URI a vocabulary file declares under `$vocabulary` to use member keywords. */ export let MEMBER_URI = 'https://yak.sh/vocab/member';
26
+ /**
27
+ * The member keyword vocabulary, ready to register:
28
+ * `loadVocab(docs, [memberKeywords])` carries each component's declaration onto
29
+ * `v.comp(name).keywords.floor`, which is where {@link floorsIn} reads it.
30
+ */ export let memberKeywords = {
31
+ uri: MEMBER_URI,
32
+ comp: [
33
+ 'floor',
34
+ 'readers',
35
+ 'shown',
36
+ 'permit',
37
+ 'personal'
38
+ ],
39
+ doc
40
+ };
41
+ // Component → what one keyword of a loaded vocabulary declares of it.
42
+ let said = (v, keyword, read)=>Object.fromEntries(v.all.flatMap((c)=>{
43
+ let said = v.comp(c)?.keywords[keyword];
44
+ return said === undefined ? [] : [
45
+ [
46
+ c,
47
+ read(said)
48
+ ]
49
+ ];
50
+ }));
51
+ /**
52
+ * The floors a loaded vocabulary declares, component → floor.
53
+ *
54
+ * ```ts
55
+ * import { assertEquals } from '@std/assert'
56
+ * import { loadVocab } from '@yaks/vocab'
57
+ * import { floorsIn, memberKeywords } from '@yaks/member'
58
+ * let v = loadVocab({
59
+ * $defs: {
60
+ * line: { component: true, type: 'object', floor: 'person' },
61
+ * note: { component: true, type: 'object' },
62
+ * },
63
+ * }, [memberKeywords])
64
+ * assertEquals(floorsIn(v), { line: 'person' })
65
+ * ```
66
+ */ export let floorsIn = (v)=>said(v, 'floor', floor);
67
+ /**
68
+ * What a loaded vocabulary asks of readers, component → a floor, or the
69
+ * queries that choose one (./asking.ts).
70
+ *
71
+ * ```ts
72
+ * import { assertEquals } from '@std/assert'
73
+ * import { loadVocab } from '@yaks/vocab'
74
+ * import { memberKeywords, readersIn } from '@yaks/member'
75
+ * let v = loadVocab({
76
+ * $defs: {
77
+ * signup: { component: true, type: 'object', readers: 'viewer' },
78
+ * note: { component: true, type: 'object' },
79
+ * },
80
+ * }, [memberKeywords])
81
+ * assertEquals(readersIn(v), { signup: 'viewer' })
82
+ * ```
83
+ */ export let readersIn = (v)=>said(v, 'readers', askedOf);
84
+ /**
85
+ * The floor each component a loaded vocabulary declares `shown` asks of
86
+ * whoever reads it, component → floor.
87
+ *
88
+ * ```ts
89
+ * import { assertEquals } from '@std/assert'
90
+ * import { loadVocab } from '@yaks/vocab'
91
+ * import { memberKeywords, shownIn } from '@yaks/member'
92
+ * let v = loadVocab({
93
+ * $defs: {
94
+ * interests: { component: true, type: 'object', shown: 'editor' },
95
+ * note: { component: true, type: 'object' },
96
+ * },
97
+ * }, [memberKeywords])
98
+ * assertEquals(shownIn(v), { interests: 'editor' })
99
+ * ```
100
+ */ export let shownIn = (v)=>said(v, 'shown', floor);
101
+ /**
102
+ * Every `floor`, `readers` or `shown` a document declares that is not a floor, or a
103
+ * `readers` condition that is no query of the component, as sentences, the way
104
+ * @yaks/vocab's `storable` answers.
105
+ *
106
+ * ```ts
107
+ * import { assertEquals } from '@std/assert'
108
+ * import { floored } from '@yaks/member'
109
+ * assertEquals(floored({ $defs: { line: { floor: 'admin', readers: 'all' } } }), [
110
+ * 'line is floored "admin" — a floor is person, viewer, editor or owner',
111
+ * 'line is read by "all" — readers is person, viewer, editor or owner',
112
+ * ])
113
+ * ```
114
+ */ export let floored = (d)=>Object.entries(d.$defs ?? {}).flatMap(([name, s])=>[
115
+ ...s?.floor === undefined || isFloor(s.floor) ? [] : [
116
+ `${name} is floored "${s.floor}" — a floor is person, viewer, editor ` + 'or owner'
117
+ ],
118
+ ...s?.readers === undefined ? [] : askedErrors(name, s.readers),
119
+ ...s?.shown === undefined || isFloor(s.shown) ? [] : [
120
+ `${name} is shown to "${s.shown}" — shown is person, viewer, editor ` + 'or owner'
121
+ ]
122
+ ]);
123
+ /** The `readers` conditions that name a property the loaded vocabulary does
124
+ * not declare, as sentences: what {@link floored} cannot see in a document
125
+ * alone. */ export let conditioned = (v)=>Object.entries(readersIn(v)).flatMap(([name, asked])=>{
126
+ try {
127
+ asking(asked, v);
128
+ return [];
129
+ } catch (e) {
130
+ return [
131
+ `${name} is read by conditions that do not apply: ${e}`
132
+ ];
133
+ }
134
+ });
135
+ let named = (v)=>typeof v == 'string' && /^[a-z][a-z0-9_]{0,39}$/.test(v);
136
+ /** Errors in `permit` declarations, checked against the whole loaded vocabulary. */ export let permitted = (v)=>v.all.flatMap((name)=>{
137
+ let said = v.comp(name)?.keywords.permit;
138
+ if (said === undefined) return [];
139
+ if (!said || typeof said != 'object' || Array.isArray(said)) {
140
+ return [
141
+ `${name}.permit maps companion marks to local reference properties`
142
+ ];
143
+ }
144
+ return Object.entries(said).flatMap(([comp, prop])=>{
145
+ let errors = [];
146
+ let mark = v.comp(comp);
147
+ if (!named(comp) || !mark?.wire || !marked(v, comp) || comp == 'tombstone' || v.props(comp).some((p)=>!v.prop(comp, p)?.stamped)) {
148
+ errors.push(`${name}.permit ${comp} is no stamp-only companion mark`);
149
+ }
150
+ let ref = named(prop) ? v.prop(name, prop) : undefined;
151
+ if (!ref?.ref || ref.computed || !v.comp(ref.ref)) {
152
+ errors.push(`${name}.permit ${String(prop)} is no stored reference property`);
153
+ }
154
+ return errors;
155
+ });
156
+ });
157
+ /** Read valid companion permissions; a malformed declaration never grants writes. */ export let permitsIn = (v)=>{
158
+ let errors = permitted(v);
159
+ if (errors.length) throw new Error(errors.join('; '));
160
+ return Object.fromEntries(v.all.flatMap((name)=>{
161
+ let said = v.comp(name)?.keywords.permit;
162
+ return said === undefined ? [] : [
163
+ [
164
+ name,
165
+ said
166
+ ]
167
+ ];
168
+ }));
169
+ };
170
+ //# sourceMappingURL=keywords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywords.js","sources":["./keywords.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,kEAAkE;AAClE,0EAA0E;AAC1E,gFAAgF;AAChF,sEAAsE;AACtE,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,+BAA+B;AAC/B,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAG9E,SAAS,MAAM,sCAA2C;AAC1D,OAAO,SAAS,gCAAgC;EAAE,MAAM;AAAO,EAAC;AAChE,SAAqB,WAAW,EAAE,OAAO,EAAE,MAAM,sBAAqB;AACtE,SAAS,KAAK,EAAe,OAAO,qBAAoB;AAExD,mFAAmF,GACnF,OAAO,IAAI,aAAa,8BAA6B;AAErD;;;;CAIC,GACD,OAAO,IAAI,iBAA2B;EACpC,KAAK;EACL,MAAM;IAAC;IAAS;IAAW;IAAS;IAAU;GAAW;EACzD;AACF,EAAC;AAED,sEAAsE;AACtE,IAAI,OAAO,CAAI,GAAU,SAAiB,OACxC,OAAO,WAAW,CAChB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACb,IAAI,OAAO,EAAE,IAAI,CAAC,IAAI,QAAQ,CAAC,QAAQ;IACvC,OAAO,SAAS,YAAY,EAAE,GAAG;MAAC;QAAC;QAAG,KAAK;OAAM;KAAC;EACpD;AAGJ;;;;;;;;;;;;;;;CAeC,GACD,OAAO,IAAI,WAAW,CAAC,IAAqB,KAAK,GAAG,SAAS,OAAM;AAEnE;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,IAAI,YAAY,CAAC,IACtB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