@yaks/inspect 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 (133) hide show
  1. package/Comp.js +469 -0
  2. package/Comp.js.map +1 -0
  3. package/Comp.ts +471 -0
  4. package/Effect.js +136 -0
  5. package/Effect.js.map +1 -0
  6. package/Effect.ts +142 -0
  7. package/Entity.js +112 -0
  8. package/Entity.js.map +1 -0
  9. package/Entity.ts +137 -0
  10. package/Facts.js +143 -0
  11. package/Facts.js.map +1 -0
  12. package/Facts.ts +150 -0
  13. package/Head.js +196 -0
  14. package/Head.js.map +1 -0
  15. package/Head.ts +195 -0
  16. package/Held.js +144 -0
  17. package/Held.js.map +1 -0
  18. package/Held.ts +172 -0
  19. package/History.js +157 -0
  20. package/History.js.map +1 -0
  21. package/History.ts +215 -0
  22. package/Home.js +482 -0
  23. package/Home.js.map +1 -0
  24. package/Home.ts +550 -0
  25. package/LICENSE +202 -0
  26. package/Links.js +197 -0
  27. package/Links.js.map +1 -0
  28. package/Links.ts +212 -0
  29. package/Package.js +195 -0
  30. package/Package.js.map +1 -0
  31. package/Package.ts +191 -0
  32. package/Past.js +163 -0
  33. package/Past.js.map +1 -0
  34. package/Past.ts +181 -0
  35. package/Prop.js +225 -0
  36. package/Prop.js.map +1 -0
  37. package/Prop.ts +208 -0
  38. package/Query.js +207 -0
  39. package/Query.js.map +1 -0
  40. package/Query.ts +229 -0
  41. package/README.md +141 -2
  42. package/Words.js +43 -0
  43. package/Words.js.map +1 -0
  44. package/Words.ts +70 -0
  45. package/_dist/Entity.d.ts +7 -0
  46. package/_dist/Entity.d.ts.map +1 -0
  47. package/_dist/Facts.d.ts +7 -0
  48. package/_dist/Facts.d.ts.map +1 -0
  49. package/_dist/Head.d.ts +22 -0
  50. package/_dist/Head.d.ts.map +1 -0
  51. package/_dist/Held.d.ts +37 -0
  52. package/_dist/Held.d.ts.map +1 -0
  53. package/_dist/Links.d.ts +9 -0
  54. package/_dist/Links.d.ts.map +1 -0
  55. package/_dist/Past.d.ts +65 -0
  56. package/_dist/Past.d.ts.map +1 -0
  57. package/_dist/Words.d.ts +27 -0
  58. package/_dist/Words.d.ts.map +1 -0
  59. package/_dist/census.d.ts +10 -0
  60. package/_dist/census.d.ts.map +1 -0
  61. package/_dist/door.d.ts +28 -0
  62. package/_dist/door.d.ts.map +1 -0
  63. package/_dist/front.d.ts +4 -0
  64. package/_dist/front.d.ts.map +1 -0
  65. package/_dist/host.d.ts +94 -0
  66. package/_dist/host.d.ts.map +1 -0
  67. package/_dist/mod.d.ts +24 -0
  68. package/_dist/mod.d.ts.map +1 -0
  69. package/_dist/notes.d.ts +38 -0
  70. package/_dist/notes.d.ts.map +1 -0
  71. package/_dist/read.d.ts +59 -0
  72. package/_dist/read.d.ts.map +1 -0
  73. package/_dist/reading.d.ts +21 -0
  74. package/_dist/reading.d.ts.map +1 -0
  75. package/_dist/registry.d.ts +12 -0
  76. package/_dist/registry.d.ts.map +1 -0
  77. package/_dist/schema.d.ts +4 -0
  78. package/_dist/schema.d.ts.map +1 -0
  79. package/_dist/state.d.ts +22 -0
  80. package/_dist/state.d.ts.map +1 -0
  81. package/_dist/value.d.ts +20 -0
  82. package/_dist/value.d.ts.map +1 -0
  83. package/_dist/views.d.ts +3 -0
  84. package/_dist/views.d.ts.map +1 -0
  85. package/census.js +50 -0
  86. package/census.js.map +1 -0
  87. package/census.ts +76 -0
  88. package/deno.json +1 -0
  89. package/door.js +54 -0
  90. package/door.js.map +1 -0
  91. package/door.ts +59 -0
  92. package/front.js +12 -0
  93. package/front.js.map +1 -0
  94. package/front.json +76 -0
  95. package/front.ts +13 -0
  96. package/grid.js +249 -0
  97. package/grid.js.map +1 -0
  98. package/grid.ts +395 -0
  99. package/host.js +20 -0
  100. package/host.js.map +1 -0
  101. package/host.ts +134 -0
  102. package/mod.js +20 -0
  103. package/mod.js.map +1 -0
  104. package/mod.ts +45 -0
  105. package/notes.js +184 -0
  106. package/notes.js.map +1 -0
  107. package/notes.ts +288 -0
  108. package/package.json +35 -4
  109. package/read.js +300 -0
  110. package/read.js.map +1 -0
  111. package/read.ts +386 -0
  112. package/reading.js +64 -0
  113. package/reading.js.map +1 -0
  114. package/reading.ts +73 -0
  115. package/registry.js +89 -0
  116. package/registry.js.map +1 -0
  117. package/registry.ts +89 -0
  118. package/rows.js +12 -0
  119. package/rows.js.map +1 -0
  120. package/rows.ts +26 -0
  121. package/schema.js +47 -0
  122. package/schema.js.map +1 -0
  123. package/schema.ts +70 -0
  124. package/state.js +85 -0
  125. package/state.js.map +1 -0
  126. package/state.ts +128 -0
  127. package/terminal-links.ts +16 -0
  128. package/value.js +67 -0
  129. package/value.js.map +1 -0
  130. package/value.ts +79 -0
  131. package/views.js +4 -0
  132. package/views.js.map +1 -0
  133. package/views.ts +6 -0
package/Comp.ts ADDED
@@ -0,0 +1,471 @@
1
+ import { derivedEid } from '@yaks/graph/identity'
2
+ /**
3
+ * A component's page (`_comp`, @yaks/vocab): what it is, its package, how many
4
+ * entities carry it and how it is kept; its properties; the sets of
5
+ * components it is found with; what it refers to and what refers to it, both
6
+ * through reference properties and through edges, each relation with how many
7
+ * edges state it and what is at their far end; and the entities carrying it,
8
+ * a row each and a column per property, a page at a time, sorted by any column
9
+ * that sorts; and its recent writes, where the journal keeps its history.
10
+ *
11
+ * How many carry it, and the sets it is found in, are read off the census
12
+ * every map page shares (./census.ts); the edges, off a tally of the edges
13
+ * whose ends are made of those sets, asked once.
14
+ *
15
+ * @module
16
+ */
17
+
18
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
19
+ import { parse } from '@yaks/query'
20
+ import { Value } from '@yaks/ui'
21
+ import type { Answer, Bundle, Io, Props, View } from './host.ts'
22
+ import { type Census, useCensus, within } from './census.js'
23
+ import { type Column, Grid, paged } from './grid.js'
24
+ import { chip, chips, Described, described, relations } from './schema.js'
25
+ import { Part, useNamed, useSets } from './notes.js'
26
+ import { History } from './History.js'
27
+ import { usePageNotes } from './Entity.js'
28
+ import { comp, count, flags, line, str, tables, typed } from './read.js'
29
+ import { rows, waiting } from './rows.js'
30
+ import { edited, key } from './state.js'
31
+ import { Cell, reads } from './value.js'
32
+
33
+ /** A component's name, off its `_comp` bundle. */
34
+ export let nameOf = (e: Bundle): string => str(e, '_comp', 'name')
35
+
36
+ let HEADINGS = [
37
+ 'Properties',
38
+ 'Found with',
39
+ 'Refers to',
40
+ 'Entities',
41
+ 'Recent writes',
42
+ ]
43
+
44
+ type Part_ = { e: Bundle; io: Io; notes: Map<string, Bundle[]> }
45
+
46
+ // What the vocabulary says of how the component is kept.
47
+ let kept = (io: Io, name: string): string[] => {
48
+ let c = io.vocab.comp(name)
49
+ if (!c) return []
50
+ let prefix = io.vocab.kind(name)?.prefix
51
+ return [
52
+ c.kind && 'a kind',
53
+ typeof prefix == 'string' && `ids ${prefix}-`,
54
+ c.mark && 'a mark',
55
+ !c.wire && 'read-only to clients',
56
+ c.computed && 'computed',
57
+ c.sync != 'server' && `sync ${c.sync}`,
58
+ c.durable != 'forever' && `kept ${c.durable}`,
59
+ !c.journal && 'keeps no history',
60
+ c.keywords.edge != null && 'an edge relation',
61
+ ].filter((f): f is string => !!f)
62
+ }
63
+
64
+ // A reference property's target: a component, or any entity.
65
+ let target = (io: Io, ref: string) =>
66
+ !ref || ref == 'entity'
67
+ ? h(Value, { mod: 'nil' }, 'any entity')
68
+ : chip(io, ref)
69
+
70
+ // Its properties, in declared order.
71
+ let Properties = ({ e, io, notes, props }: Part_ & { props: Answer }) =>
72
+ h(
73
+ Part,
74
+ {
75
+ io,
76
+ eid: e.entity.eid,
77
+ subject: nameOf(e),
78
+ heading: 'Properties',
79
+ count: props.ready ? rows(props).length : undefined,
80
+ notes,
81
+ },
82
+ waiting(props) ?? h(Grid, {
83
+ io,
84
+ id: key(e.entity.eid, 'Properties'),
85
+ local: true,
86
+ rows: rows(props),
87
+ columns: [
88
+ {
89
+ name: 'name',
90
+ value: (b) => str(b, '_prop', 'name'),
91
+ cell: (b) =>
92
+ h('a', { href: io.link(b.entity.eid) }, str(b, '_prop', 'name')),
93
+ },
94
+ {
95
+ name: 'type',
96
+ cell: (b) => {
97
+ let p = comp(b, '_prop')
98
+ let ref = str(b, '_prop', 'ref')
99
+ return p.ref
100
+ ? h(
101
+ 'span',
102
+ {},
103
+ typed({ ...p, ref: null }),
104
+ ' → ',
105
+ target(io, ref),
106
+ )
107
+ : typed(p)
108
+ },
109
+ },
110
+ {
111
+ name: 'what it is',
112
+ mod: 'prose',
113
+ cell: (b) => line(str(b, 'doc', 'body'), 200),
114
+ },
115
+ { name: 'flags', cell: (b) => flags(comp(b, '_prop')).join(' ') },
116
+ ],
117
+ }),
118
+ )
119
+
120
+ // The sets of components it is found with, most entities first.
121
+ let Found = ({ e, io, notes, census }: Part_ & { census: Census }) => {
122
+ let name = nameOf(e)
123
+ let sets = within(census.sets, name, io.vocab)
124
+ return h(
125
+ Part,
126
+ {
127
+ io,
128
+ eid: e.entity.eid,
129
+ subject: name,
130
+ heading: 'Found with',
131
+ count: census.ready ? sets.length : undefined,
132
+ notes,
133
+ },
134
+ waiting({ rows: sets, ready: census.ready, error: census.error }) ??
135
+ h(Grid, {
136
+ io,
137
+ id: key(e.entity.eid, 'Found with'),
138
+ local: true,
139
+ rows: sets,
140
+ columns: [
141
+ {
142
+ name: 'with',
143
+ cell: (b) => {
144
+ let others = tables(b, io.vocab).filter((t) => t != name)
145
+ return others.length
146
+ ? chips(io, others)
147
+ : h(Value, { mod: 'nil' }, 'nothing else')
148
+ },
149
+ },
150
+ {
151
+ name: 'entities',
152
+ mod: 'num',
153
+ value: (b) => census.tally[b.entity.eid] ?? 0,
154
+ cell: (b) =>
155
+ h(
156
+ 'a',
157
+ { href: io.find(`.entity.archetype=${b.entity.eid}`) },
158
+ count(census.tally[b.entity.eid] ?? 0),
159
+ ),
160
+ },
161
+ ],
162
+ }),
163
+ )
164
+ }
165
+
166
+ /** One way a component is linked: which way, through what, to what, and
167
+ * how often where edges say it. */
168
+ type Tie = {
169
+ entity: { eid: string }
170
+ way: '→' | '←'
171
+ through: ReactNode
172
+ far: ReactNode
173
+ n?: number
174
+ }
175
+
176
+ // Each set's kind, by the set's eid: what an entity made of it shows as.
177
+ let kinds = (io: Io, census: Census, eids: string[]) => {
178
+ let of = new Map(
179
+ census.sets.map((s) => [s.entity.eid, tables(s, io.vocab)]),
180
+ )
181
+ return eids.map((eid) =>
182
+ io.vocab.kindOf(
183
+ Object.fromEntries((of.get(eid) ?? []).map((t) => [t, {}])),
184
+ ) || 'entity'
185
+ )
186
+ }
187
+
188
+ // A tally of sets read as how many of each kind: `entry 650, doc 20`.
189
+ let spread = (io: Io, census: Census, tally: Record<string, number>) => {
190
+ let eids = Object.keys(tally)
191
+ let by = new Map<string, number>()
192
+ kinds(io, census, eids).forEach((k, i) =>
193
+ by.set(k, (by.get(k) ?? 0) + tally[eids[i]])
194
+ )
195
+ let all = [...by].toSorted(([, a], [, b]) => b - a)
196
+ return all.length
197
+ ? h(
198
+ 'span',
199
+ {},
200
+ all.flatMap((
201
+ [k, n],
202
+ i,
203
+ ) => [i ? ', ' : null, chip(io, k), ` ${count(n)}`]),
204
+ )
205
+ : h(Value, { mod: 'nil' }, '…')
206
+ }
207
+
208
+ // The edges of one relation from (or to) the sets `archs`, by what their far
209
+ // end is made of: asked once.
210
+ let FarEnds = (
211
+ { io, census, relation, way, archs }: {
212
+ io: Io
213
+ census: Census
214
+ relation: string
215
+ way: 'from' | 'to'
216
+ archs: string[]
217
+ },
218
+ ) => {
219
+ let far = way == 'from' ? 'to' : 'from'
220
+ let got = io.ask({
221
+ far: {
222
+ query: `.${relation}&.edge.${way}.entity.archetype=${archs.join(',')}` +
223
+ `&.tally=edge.${far}.entity.archetype`,
224
+ once: true,
225
+ },
226
+ })
227
+ return waiting(got.far) ?? spread(io, census, got.far?.tally ?? {})
228
+ }
229
+
230
+ // What it refers to, and what refers to it: through its reference properties
231
+ // and others', and through edges whose ends carry it.
232
+ let Refers = (
233
+ { e, io, notes, props, census }: Part_ & { props: Answer; census: Census },
234
+ ) => {
235
+ let name = nameOf(e)
236
+ let eid = e.entity.eid
237
+ let archs = within(census.sets, name, io.vocab).map((s) => s.entity.eid)
238
+ let ends = (way: 'from' | 'to') =>
239
+ `.edge&.edge.${way}.entity.archetype=${archs.join(',')}` +
240
+ `&.tally=entity.archetype`
241
+ let got = io.ask({
242
+ into: `._prop&._prop.ref=${name}&?doc&?_prop`,
243
+ ...archs.length
244
+ ? {
245
+ out: { query: ends('from'), once: true },
246
+ in: { query: ends('to'), once: true },
247
+ }
248
+ : {},
249
+ })
250
+ let rels = relations(io)
251
+ // Edges by relation, off a tally of the edges' own sets.
252
+ let byRelation = (tally: Record<string, number> = {}) => {
253
+ let by = new Map<string, number>()
254
+ let of = new Map(
255
+ census.sets.map((s) => [s.entity.eid, tables(s, io.vocab)]),
256
+ )
257
+ for (let [set, n] of Object.entries(tally)) {
258
+ let rel = (of.get(set) ?? []).find((t) => rels.includes(t))
259
+ if (rel) by.set(rel, (by.get(rel) ?? 0) + n)
260
+ }
261
+ return [...by].toSorted(([, a], [, b]) => b - a)
262
+ }
263
+ let edge = (way: '→' | '←', [rel, n]: [string, number]): Tie => ({
264
+ entity: { eid: derivedEid(`relation|${way}|${rel}`) },
265
+ way,
266
+ through: chip(io, rel),
267
+ far: h(FarEnds, {
268
+ io,
269
+ census,
270
+ relation: rel,
271
+ way: way == '→' ? 'from' : 'to',
272
+ archs,
273
+ }),
274
+ n,
275
+ })
276
+ let ties: Tie[] = [
277
+ ...rows(props).filter((b) => str(b, '_prop', 'ref')).map((b): Tie => ({
278
+ entity: { eid: b.entity.eid },
279
+ way: '→',
280
+ through: h('a', { href: io.link(b.entity.eid) }, str(b, 'doc', 'title')),
281
+ far: target(io, str(b, '_prop', 'ref')),
282
+ })),
283
+ ...byRelation(got.out?.tally).map((r) => edge('→', r)),
284
+ ...rows(got.into).map((b): Tie => ({
285
+ entity: { eid: b.entity.eid },
286
+ way: '←',
287
+ through: h('a', { href: io.link(b.entity.eid) }, str(b, 'doc', 'title')),
288
+ far: chip(io, str(b, 'doc', 'title').split('.')[0]),
289
+ })),
290
+ ...byRelation(got.in?.tally).map((r) => edge('←', r)),
291
+ ]
292
+ let ready = props.ready && got.into?.ready && census.ready &&
293
+ (!archs.length || (got.out?.ready && got.in?.ready))
294
+ let tie = new Map(ties.map((t) => [t.entity.eid, t]))
295
+ let of = (b: Bundle) => tie.get(b.entity.eid)!
296
+ return h(
297
+ Part,
298
+ {
299
+ io,
300
+ eid,
301
+ subject: name,
302
+ heading: 'Refers to',
303
+ title: 'Refers to, and referred to by',
304
+ count: ready ? ties.length : undefined,
305
+ notes,
306
+ },
307
+ waiting({
308
+ rows: ties.map((t): Bundle => ({ entity: t.entity })),
309
+ ready: !!ready,
310
+ error: props.error ?? got.into?.error ?? census.error ??
311
+ got.out?.error ?? got.in?.error,
312
+ }) ?? h(Grid, {
313
+ io,
314
+ id: key(eid, 'Refers to'),
315
+ local: true,
316
+ pick: false,
317
+ rows: ties.map((t): Bundle => ({ entity: t.entity })),
318
+ columns: [
319
+ { name: 'way', cell: (b) => of(b).way },
320
+ { name: 'through', cell: (b) => of(b).through },
321
+ { name: 'at the other end', cell: (b) => of(b).far },
322
+ {
323
+ name: 'edges',
324
+ mod: 'num',
325
+ cell: (b) => of(b).n != null ? count(of(b).n!) : '',
326
+ },
327
+ ],
328
+ }),
329
+ )
330
+ }
331
+
332
+ // Whether the graph can run rows by a property: anything but JSON.
333
+ let sorts = (io: Io, name: string, prop: string) =>
334
+ io.vocab.prop(name, prop)?.scalar != 'jsonb'
335
+
336
+ // Whether a property holds a number, whose column sets right.
337
+ let numeric = (io: Io, name: string, prop: string) =>
338
+ ['number', 'priority'].includes(io.vocab.prop(name, prop)?.scalar ?? '')
339
+
340
+ // The entities carrying it, a page at a time: each value read, or, while the
341
+ // page is edited, changed where it stands.
342
+ let Entities = ({ e, io, notes, census }: Part_ & { census: Census }) => {
343
+ let eid = e.entity.eid
344
+ let name = nameOf(e)
345
+ let id = key(eid, 'Entities')
346
+ let props = io.vocab.props(name)
347
+ let got = io.ask({
348
+ rows: paged(io, id, `.${name}`),
349
+ titles: `${paged(io, id, `.${name}`)}&.fields=doc.title`,
350
+ })
351
+ let title = new Map(
352
+ rows(got.titles).map((b) => [b.entity.eid, str(b, 'doc', 'title')]),
353
+ )
354
+ let refs = props.filter((p) => io.vocab.prop(name, p)?.category == 'ref')
355
+ useSets(io, rows(got.rows))
356
+ useNamed(
357
+ io,
358
+ rows(got.rows).flatMap((b) => refs.map((p) => comp(b, name)[p] as string)),
359
+ )
360
+ let editing = edited(io, eid)
361
+ let total = census.ready ? census.carried[name] ?? 0 : undefined
362
+ return h(
363
+ Part,
364
+ {
365
+ io,
366
+ eid,
367
+ subject: name,
368
+ heading: 'Entities',
369
+ count: total,
370
+ note: h('a', { href: io.find(`.${name}`) }, `.${name}`),
371
+ notes,
372
+ },
373
+ waiting(got.rows) ?? h(Grid, {
374
+ io,
375
+ id,
376
+ rows: rows(got.rows),
377
+ total,
378
+ columns: [
379
+ {
380
+ name: 'id',
381
+ cell: (b) => io.show(b, 'Inspect.Reference.Inline'),
382
+ },
383
+ ...[...title.values()].some(Boolean)
384
+ ? [{
385
+ name: 'title',
386
+ cell: (b: Bundle) => line(title.get(b.entity.eid), 80),
387
+ }]
388
+ : [],
389
+ ...props.map((prop): Column => ({
390
+ name: prop,
391
+ sort: sorts(io, name, prop) ? `${name}.${prop}` : undefined,
392
+ mod: numeric(io, name, prop) ? 'num' : undefined,
393
+ cell: (b: Bundle) =>
394
+ editing
395
+ ? h(Cell, { io, e: b, name, prop })
396
+ : reads(io, comp(b, name)[prop], io.vocab.prop(name, prop)),
397
+ })),
398
+ ],
399
+ }),
400
+ )
401
+ }
402
+
403
+ // What a component's page says, under whichever head tops it: its words and
404
+ // facts, and its parts.
405
+ let useComp = ({ e, io }: Props) => {
406
+ let name = nameOf(e)
407
+ let notes = usePageNotes(io, e, HEADINGS)
408
+ let census = useCensus(io)
409
+ let got = io.ask({
410
+ props: `._prop&._prop.comp=${e.entity.eid}&.order=_prop.ord&*`,
411
+ })
412
+ let pkg = str(e, '_comp', 'namespace')
413
+ useNamed(io, [pkg])
414
+ let n = census.carried[name]
415
+ return {
416
+ name,
417
+ notes,
418
+ text: io.vocab.comp(name)?.description ?? str(e, 'doc', 'body'),
419
+ facts: [
420
+ pkg
421
+ ? ['from ', h('a', { href: io.link(pkg) }, io.name(pkg))]
422
+ : 'no package',
423
+ census.ready ? ` · carried by ${count(n ?? 0)} entities` : '',
424
+ ...kept(io, name).map((f) => ` · ${f}`),
425
+ ],
426
+ parts: [
427
+ h(Properties, { e, io, notes, props: got.props }),
428
+ h(Found, { e, io, notes, census }),
429
+ h(Refers, { e, io, notes, props: got.props, census }),
430
+ h(Entities, { e, io, notes, census }),
431
+ io.vocab.comp('_change') && io.vocab.comp(name)?.journal
432
+ ? h(History, {
433
+ e,
434
+ io,
435
+ notes,
436
+ heading: 'Recent writes',
437
+ where: `comp=${e.entity.eid}`,
438
+ once: true,
439
+ })
440
+ : null,
441
+ ],
442
+ }
443
+ }
444
+
445
+ /** A component's own page. */
446
+ export let CompPage = (p: Props): JSX.Element => {
447
+ let { name, notes, text, facts, parts } = useComp(p)
448
+ return h(
449
+ 'div',
450
+ { 'data-inspect': p.e.entity.eid },
451
+ p.io.show(p.e, 'Inspect.Head', {
452
+ sub: described(text, facts),
453
+ notes: notes.get(''),
454
+ subject: name,
455
+ }),
456
+ ...parts,
457
+ )
458
+ }
459
+
460
+ /** A component's page under another head: its words and facts, then its
461
+ * parts (the body of its Full page). */
462
+ export let CompBody = (p: Props): JSX.Element => {
463
+ let { text, facts, parts } = useComp(p)
464
+ return h('div', {}, h(Described, { text, facts }), ...parts)
465
+ }
466
+
467
+ /** A component's page, and its body under another head. */
468
+ export let compViews: View[] = [
469
+ { view: 'Inspect.Page', match: parse('._comp'), Render: CompPage },
470
+ { view: 'Full.Body', match: parse('.doc ._comp'), Render: CompBody },
471
+ ]
package/Effect.js ADDED
@@ -0,0 +1,136 @@
1
+ /**
2
+ * An effect's page (`_effect`, @yaks/vocab): what it does and the package
3
+ * declaring it; what owes it a run, as its declaration says: the components
4
+ * whose appearance, patch or removal on an entity does, the query a batch
5
+ * makes hold, a process starting, and the queries that narrow them; and how a
6
+ * run is tried. Its runs are the `effect` rows naming it (@yaks/effects), a
7
+ * query away.
8
+ *
9
+ * @module
10
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
11
+ import { parse } from "@yaks/query";
12
+ import { Pairs, Value } from "@yaks/ui";
13
+ import { usePageNotes } from "./Entity.js";
14
+ import { chip, Described, described, propEid } from "./schema.js";
15
+ import { Part, useNamed } from "./notes.js";
16
+ import { comp, str } from "./read.js";
17
+ import { none } from "./rows.js";
18
+ let HEADINGS = [
19
+ 'Owed by'
20
+ ];
21
+ // An effect's name, off its `_effect` bundle.
22
+ let nameOf = (e)=>str(e, '_effect', 'name');
23
+ // A component, or one property of it (`comp.prop`), linked to its page.
24
+ let named = (io, word)=>{
25
+ let [name, ...prop] = word.split('.');
26
+ return prop.length ? /*#__PURE__*/ h('a', {
27
+ href: io.link(propEid(io.vocab, name, prop.join('.')))
28
+ }, word) : chip(io, name);
29
+ };
30
+ let list = (io, words)=>/*#__PURE__*/ h('span', {}, words.flatMap((w, i)=>[
31
+ i ? ', ' : null,
32
+ named(io, w)
33
+ ]));
34
+ // A query its declaration says, opened as a search where it is one.
35
+ let query = (io, q)=>{
36
+ try {
37
+ parse(q);
38
+ return /*#__PURE__*/ h('a', {
39
+ href: io.find(q)
40
+ }, /*#__PURE__*/ h(Value, {}, q));
41
+ } catch {
42
+ return /*#__PURE__*/ h(Value, {}, q);
43
+ }
44
+ };
45
+ // What owes it a run: how each trigger its declaration can name is drawn.
46
+ let TRIGGERS = {
47
+ created: (io, v)=>list(io, v),
48
+ changed: (io, v)=>list(io, v),
49
+ removed: (io, v)=>list(io, v),
50
+ match: (io, v)=>query(io, String(v)),
51
+ target: (io, v)=>query(io, String(v)),
52
+ eligible: (io, v)=>query(io, String(v)),
53
+ active: (io, v)=>query(io, String(v)),
54
+ start: ()=>'each time a process starts working the effects'
55
+ };
56
+ // The triggers its declaration names, each beside what it names.
57
+ let owed = (io, e)=>{
58
+ let c = comp(e, '_effect');
59
+ return Object.entries(TRIGGERS).filter(([k])=>c[k] != null && c[k] !== false).map(([k, draw])=>[
60
+ k,
61
+ draw(io, c[k])
62
+ ]);
63
+ };
64
+ // What an effect's page says, under whichever head tops it.
65
+ let useEffectPage = ({ e, io })=>{
66
+ let name = nameOf(e);
67
+ let notes = usePageNotes(io, e, HEADINGS);
68
+ let c = comp(e, '_effect');
69
+ let pkg = str(e, '_effect', 'namespace');
70
+ useNamed(io, [
71
+ pkg
72
+ ]);
73
+ let triggers = owed(io, e);
74
+ return {
75
+ name,
76
+ notes,
77
+ text: str(e, 'doc', 'body'),
78
+ facts: [
79
+ pkg ? [
80
+ 'from ',
81
+ /*#__PURE__*/ h('a', {
82
+ href: io.link(pkg)
83
+ }, io.name(pkg))
84
+ ] : 'no package',
85
+ c.option ? ` · only with the option ${c.option}` : '',
86
+ c.tries ? ` · ${c.tries} tries` : '',
87
+ c.idempotent === false ? ' · not idempotent' : ''
88
+ ],
89
+ parts: [
90
+ /*#__PURE__*/ h(Part, {
91
+ io,
92
+ eid: e.entity.eid,
93
+ subject: name,
94
+ heading: 'Owed by',
95
+ note: io.vocab.comp('effect') ? /*#__PURE__*/ h('a', {
96
+ href: io.find(`.effect.handler=${name}`)
97
+ }, 'its runs') : undefined,
98
+ notes
99
+ }, triggers.length ? /*#__PURE__*/ h(Pairs, {}, triggers.flatMap(([k, v])=>[
100
+ /*#__PURE__*/ h(Pairs.Key, {}, k),
101
+ /*#__PURE__*/ h(Pairs.Value, {}, v)
102
+ ])) : none())
103
+ ]
104
+ };
105
+ };
106
+ /** An effect's own page. */ export let EffectPage = (p)=>{
107
+ let { name, notes, text, facts, parts } = useEffectPage(p);
108
+ return /*#__PURE__*/ h('div', {
109
+ 'data-inspect': p.e.entity.eid
110
+ }, p.io.show(p.e, 'Inspect.Head', {
111
+ sub: described(text, facts),
112
+ notes: notes.get(''),
113
+ subject: name
114
+ }), ...parts);
115
+ };
116
+ /** An effect's page under another head: what it does, and what owes it a
117
+ * run (the body of its Full page). */ export let EffectBody = (p)=>{
118
+ let { text, facts, parts } = useEffectPage(p);
119
+ return /*#__PURE__*/ h('div', {}, /*#__PURE__*/ h(Described, {
120
+ text,
121
+ facts
122
+ }), ...parts);
123
+ };
124
+ /** An effect's page, and its body under another head. */ export let effectViews = [
125
+ {
126
+ view: 'Inspect.Page',
127
+ match: parse('._effect'),
128
+ Render: EffectPage
129
+ },
130
+ {
131
+ view: 'Full.Body',
132
+ match: parse('.doc ._effect'),
133
+ Render: EffectBody
134
+ }
135
+ ];
136
+ //# sourceMappingURL=Effect.js.map
package/Effect.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Effect.js","sources":["./Effect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;CASC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoD;AACzH,SAAS,KAAK,2BAAgC;AAC9C,SAAS,KAAK,EAAE,KAAK,wBAA6B;AAElD,SAAS,YAAY,sBAAqB;AAC1C,SAAS,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,sBAAqB;AACjE,SAAS,IAAI,EAAE,QAAQ,qBAAoB;AAC3C,SAAS,IAAI,EAAE,GAAG,oBAAmB;AACrC,SAAS,IAAI,oBAAmB;AAEhC,IAAI,WAAW;EAAC;CAAU;AAE1B,8CAA8C;AAC9C,IAAI,SAAS,CAAC,IAAsB,IAAI,GAAG,WAAW;AAEtD,wEAAwE;AACxE,IAAI,QAAQ,CAAC,IAAQ;EACnB,IAAI,CAAC,MAAM,GAAG,KAAK,GAAG,KAAK,KAAK,CAAC;EACjC,OAAO,KAAK,MA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