@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/Query.js ADDED
@@ -0,0 +1,207 @@
1
+ /**
2
+ * A query's page: the line, run, and its answer. Rows show as a table whose
3
+ * columns are the components the rows share, each cell what that component
4
+ * holds, a page at a time (unless the line names its own window) with how
5
+ * many there are in all; a press on a row picks it, and a press on a heading
6
+ * has the graph run the rows by the property that column shows first, the
7
+ * rows with no value last either way. The order is the line's own
8
+ * `.order[last]=`, so the page's address keeps it through a reload or a
9
+ * shared link; a line typed with a plain `.order=` runs as it was written
10
+ * until a heading is pressed. An aggregate shows as what it counts: a number, or
11
+ * each value beside how many hold it.
12
+ *
13
+ * @module
14
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
15
+ import { conjoin, order as ordered, parse, stringify, tokens, windowOf } from "@yaks/query";
16
+ import { Head, Rows, Value } from "@yaks/ui";
17
+ import { Grid, paged, SIZE } from "./grid.js";
18
+ import { comp, comps, count, line, named } from "./read.js";
19
+ import { rows, waiting } from "./rows.js";
20
+ import { useNamed, useSets } from "./notes.js";
21
+ import { grid, key } from "./state.js";
22
+ import { mention, reads } from "./value.js";
23
+ let AGGREGATES = new Set([
24
+ 'count',
25
+ 'tally',
26
+ 'distinct'
27
+ ]);
28
+ /** A query as typed: its tree, the aggregate it asks for, or why it does not
29
+ * parse. */ export let read = (text)=>{
30
+ try {
31
+ let ast = parse(text);
32
+ let agg = ast.clauses.find((c)=>AGGREGATES.has(c.kind))?.kind;
33
+ return {
34
+ ast,
35
+ agg
36
+ };
37
+ } catch (e) {
38
+ return {
39
+ error: e instanceof Error ? e.message : String(e)
40
+ };
41
+ }
42
+ };
43
+ // Every component each row brings, unless the line says what it brings.
44
+ let whole = (text)=>/(^|&)(\*|\.fields=[^&]*|\?[\w]+)(&|$)/.test(text) ? text : conjoin(text, '*');
45
+ /**
46
+ * The components every row carries, in the order the first row carries them.
47
+ *
48
+ * ```ts
49
+ * import { shared } from './Query.ts'
50
+ * shared([
51
+ * { entity: { eid: 'a' }, doc: {}, task: {}, created: {} },
52
+ * { entity: { eid: 'b' }, task: {}, doc: {} },
53
+ * ]) // ['doc', 'task']
54
+ * ```
55
+ */ export let shared = (rows)=>rows.length ? comps(rows[0]).map(([n])=>n).filter((n)=>rows.every((b)=>b[n])) : [];
56
+ // The values a component holds that are there, in the order it holds them.
57
+ let held = (b, name)=>Object.entries(comp(b, name)).filter(([, v])=>v != null && v !== '');
58
+ /**
59
+ * The property a component's column runs by: the first one the rows show.
60
+ *
61
+ * ```ts
62
+ * import { leads } from './Query.ts'
63
+ * leads([
64
+ * { entity: { eid: 'a' }, created: { by: null, at: '2026-11-10' } },
65
+ * ], 'created') // 'created.at'
66
+ * ```
67
+ */ export let leads = (rows, name)=>{
68
+ let prop = rows.map((b)=>held(b, name)[0]?.[0]).find(Boolean);
69
+ return prop && `${name}.${prop}`;
70
+ };
71
+ /**
72
+ * A query line run by `order` in place of any order it names, the rows with no
73
+ * value last, or as it comes without one.
74
+ *
75
+ * ```ts
76
+ * import { runBy } from './Query.ts'
77
+ * runBy('.task .order=doc.title', '-task.status') // '.task&.order[last]=-task.status'
78
+ * runBy('.a|.b&.order[last]=x') // '.a | .b'
79
+ * ```
80
+ */ export let runBy = (text, order)=>conjoin(tokens(text).filter((t)=>!/^\.order[=[]/.test(t)).join(' '), order ? stringify(ordered(order, true)) : '');
81
+ // What a component holds, in a cell: its first few values that are there,
82
+ // each as a person reads it.
83
+ let summed = (io, b, name)=>{
84
+ let set = held(b, name);
85
+ return set.length ? set.slice(0, 3).flatMap(([k, v], i)=>[
86
+ i ? ' ' : null,
87
+ /*#__PURE__*/ h(Value, {
88
+ mod: 'id'
89
+ }, k),
90
+ ' ',
91
+ reads(io, v, io.vocab.prop(name, k))
92
+ ]) : /*#__PURE__*/ h(Value, {
93
+ mod: 'nil'
94
+ }, 'present');
95
+ };
96
+ // Every entity the rows' values name, so each reads by its name.
97
+ let mentioned = (rows, names)=>rows.flatMap((b)=>names.flatMap((n)=>Object.values(comp(b, n)).filter(named)));
98
+ // A tally, or a distinct list read as one: each value beside its count, an
99
+ // entity by its name.
100
+ let Tallied = ({ io, id, tally })=>{
101
+ let values = Object.keys(tally).toSorted((a, b)=>tally[b] - tally[a]);
102
+ let page = grid(io, id).after?.length ?? 0;
103
+ useNamed(io, values.slice(page * SIZE, (page + 1) * SIZE).filter(named));
104
+ return /*#__PURE__*/ h(Grid, {
105
+ io,
106
+ id,
107
+ local: true,
108
+ pick: (b)=>named(b.entity.eid) ? b.entity.eid : undefined,
109
+ rows: values.map((v)=>({
110
+ entity: {
111
+ eid: v
112
+ }
113
+ })),
114
+ columns: [
115
+ {
116
+ name: 'value',
117
+ value: (b)=>b.entity.eid || null,
118
+ cell: (b)=>named(b.entity.eid) ? mention(io, b.entity.eid) : line(b.entity.eid, 120) || '""'
119
+ },
120
+ {
121
+ name: 'entities',
122
+ mod: 'num',
123
+ value: (b)=>tally[b.entity.eid] ?? 0,
124
+ cell: (b)=>count(tally[b.entity.eid] ?? 0)
125
+ }
126
+ ]
127
+ });
128
+ };
129
+ /** The rows a query answers, a page at a time. */ let Answered = ({ io, text, ast })=>{
130
+ let id = key('query', text);
131
+ let own = windowOf(ast).limit != null;
132
+ let run = ast.clauses.find((c)=>c.kind == 'order');
133
+ let order = run?.value;
134
+ let base = runBy(text);
135
+ let got = io.ask(own ? {
136
+ rows: {
137
+ query: whole(text),
138
+ typed: true
139
+ }
140
+ } : {
141
+ rows: {
142
+ query: whole(paged(io, id, base, {
143
+ order,
144
+ last: run?.last
145
+ })),
146
+ typed: true
147
+ },
148
+ total: {
149
+ query: conjoin(base, '.count'),
150
+ once: true,
151
+ typed: true
152
+ }
153
+ });
154
+ let all = rows(got.rows);
155
+ useSets(io, all);
156
+ let cols = shared(all);
157
+ useNamed(io, mentioned(all, cols));
158
+ // A column the rows run by keeps its property, whichever rows came back.
159
+ let by = order?.replace(/^-/, '');
160
+ return waiting(got.rows) ?? /*#__PURE__*/ h(Grid, {
161
+ io,
162
+ id,
163
+ rows: all,
164
+ total: own ? all.length : got.total?.count,
165
+ sorts: {
166
+ order,
167
+ to: (o)=>io.go(io.find(runBy(text, o)))
168
+ },
169
+ columns: [
170
+ {
171
+ name: 'id',
172
+ cell: (b)=>io.show(b, 'Inspect.Reference.Inline')
173
+ },
174
+ ...cols.map((n)=>({
175
+ name: n,
176
+ sort: by?.startsWith(`${n}.`) ? by : leads(all, n),
177
+ cell: (b)=>summed(io, b, n)
178
+ }))
179
+ ]
180
+ });
181
+ };
182
+ /** A query's own page. */ export let QueryPage = ({ io, text })=>{
183
+ let { ast, agg, error } = read(text);
184
+ let got = io.ask(agg ? {
185
+ answer: {
186
+ query: text,
187
+ typed: true
188
+ }
189
+ } : {});
190
+ let a = got.answer;
191
+ return /*#__PURE__*/ h('div', {
192
+ 'data-query': text
193
+ }, /*#__PURE__*/ h(Head, {}, /*#__PURE__*/ h(Head.Title, {}, 'query', /*#__PURE__*/ h(Head.Kind, {}, agg ?? 'rows')), /*#__PURE__*/ h(Head.Sub, {}, /*#__PURE__*/ h(Value, {
194
+ mod: 'id'
195
+ }, text))), error ? /*#__PURE__*/ h(Rows.More, {}, error) : agg == 'count' ? waiting(a) ?? /*#__PURE__*/ h(Value, {
196
+ mod: 'num'
197
+ }, count(a?.count ?? 0)) : agg ? waiting(a) ?? /*#__PURE__*/ h(Tallied, {
198
+ io,
199
+ id: key('query', text),
200
+ tally: a?.tally ?? {}
201
+ }) : /*#__PURE__*/ h(Answered, {
202
+ io,
203
+ text,
204
+ ast: ast
205
+ }));
206
+ };
207
+ //# sourceMappingURL=Query.js.map
package/Query.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Query.js","sources":["./Query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoC;AACzG,SACE,OAAO,EAEP,SAAS,OAAO,EAChB,KAAK,EAEL,SAAS,EACT,MAAM,EACN,QAAQ,2BACqB;AAC/B,SAAS,IAAI,EAAE,IAAI,EAAE,KAAK,wBAA6B;AAEvD,SAAS,IAAI,EAAE,KAAK,EAAE,IAAI,oBAAmB;AAC7C,SAAS,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,oBAAmB;AAC3D,SAAS,IAAI,EAAE,OAAO,oBAAmB;AACzC,SAAS,QAAQ,EAAE,OAAO,qBAAoB;AAC9C,SAAS,IAAI,EAAE,GAAG,qBAAoB;AACtC,SAAS,OAAO,EAAE,KAAK,qBAAoB;AAE3C,IAAI,aAAa,IAAI,IAAI;EAAC;EAAS;EAAS;CAAW;AAEvD;UACU,GACV,OAAO,IAAI,OAAO,CAChB;EAEA,IAAI;IACF,IAAI,MAAM,MAAM;IAChB,IAAI,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,IAAM,WAAW,GAAG,CAAC,EAAE,IAAI,IAAI;IAC3D,OAAO;MAAE;MAAK;IAAI;EACpB,EAAE,OAAO,GAAG;IACV,OAAO;MAAE,OAAO,aAAa,QAAQ,EAAE,OAAO,GAAG,OAAO;IAAG;EAC7D;AACF,EAAC;AAED,wEAAwE;AACxE,IAAI,QAAQ,CAAC,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E,IAAI,EAA4B;EAEtC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,KAAK;EAC/B,IAAI,MAAM,GAAG,GAAG,CAAC,MAAM;IAAE,QAAQ;MAAE,OAAO;MAAM,OAAO;IAAK;EAAE,IAAI,CAAC;EACnE,IAAI,IAAI,IAAI,MAAM;EAClB,qBAAO,EACL,OACA;IAAE,cAAc;EAAK,iBACrB,EACE,MACA,CAAC,iBACD,EAAE,KAAK,KAAK,EAAE,CAAC,GAAG,uBAAS,EAAE,KAAK,IAAI,EAAE,CAAC,GAAG,OAAO,wBACnD,EAAE,KAAK,GAAG,EAAE,CAAC,iBAAG,EAAE,OAAO;IAAE,KAAK;EAAK,GAAG,SAE1C,sBACI,EAAE,KAAK,IAAI,EAAE,CAAC,GAAG,SACjB,OAAO,UACP,QAAQ,oBAAM,EAAE,OAAO;IAAE,KAAK;EAAM,GAAG,MAAM,GAAG,SAAS,MACzD,MACA,QAAQ,oBACR,EAAE,SAAS;IAAE;IAAI,IAAI,IAAI,SAAS;IAAO,OAAO,GAAG,SAAS,CAAC;EAAE,mBAC/D,EAAE,UAAU;IAAE;IAAI;IAAM,KAAK;EAAK;AAE1C,EAAC"}
package/Query.ts ADDED
@@ -0,0 +1,229 @@
1
+ /**
2
+ * A query's page: the line, run, and its answer. Rows show as a table whose
3
+ * columns are the components the rows share, each cell what that component
4
+ * holds, a page at a time (unless the line names its own window) with how
5
+ * many there are in all; a press on a row picks it, and a press on a heading
6
+ * has the graph run the rows by the property that column shows first, the
7
+ * rows with no value last either way. The order is the line's own
8
+ * `.order[last]=`, so the page's address keeps it through a reload or a
9
+ * shared link; a line typed with a plain `.order=` runs as it was written
10
+ * until a heading is pressed. An aggregate shows as what it counts: a number, or
11
+ * each value beside how many hold it.
12
+ *
13
+ * @module
14
+ */
15
+
16
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX } from 'react'
17
+ import {
18
+ conjoin,
19
+ type Order,
20
+ order as ordered,
21
+ parse,
22
+ type Query,
23
+ stringify,
24
+ tokens,
25
+ windowOf,
26
+ } from '@yaks/query'
27
+ import { Head, Rows, Value } from '@yaks/ui'
28
+ import type { Bundle, Io } from './host.ts'
29
+ import { Grid, paged, SIZE } from './grid.js'
30
+ import { comp, comps, count, line, named } from './read.js'
31
+ import { rows, waiting } from './rows.js'
32
+ import { useNamed, useSets } from './notes.js'
33
+ import { grid, key } from './state.js'
34
+ import { mention, reads } from './value.js'
35
+
36
+ let AGGREGATES = new Set(['count', 'tally', 'distinct'])
37
+
38
+ /** A query as typed: its tree, the aggregate it asks for, or why it does not
39
+ * parse. */
40
+ export let read = (
41
+ text: string,
42
+ ): { ast?: Query; agg?: string; error?: string } => {
43
+ try {
44
+ let ast = parse(text)
45
+ let agg = ast.clauses.find((c) => AGGREGATES.has(c.kind))?.kind
46
+ return { ast, agg }
47
+ } catch (e) {
48
+ return { error: e instanceof Error ? e.message : String(e) }
49
+ }
50
+ }
51
+
52
+ // Every component each row brings, unless the line says what it brings.
53
+ let whole = (text: string) =>
54
+ /(^|&)(\*|\.fields=[^&]*|\?[\w]+)(&|$)/.test(text) ? text : conjoin(text, '*')
55
+
56
+ /**
57
+ * The components every row carries, in the order the first row carries them.
58
+ *
59
+ * ```ts
60
+ * import { shared } from './Query.ts'
61
+ * shared([
62
+ * { entity: { eid: 'a' }, doc: {}, task: {}, created: {} },
63
+ * { entity: { eid: 'b' }, task: {}, doc: {} },
64
+ * ]) // ['doc', 'task']
65
+ * ```
66
+ */
67
+ export let shared = (rows: Bundle[]): string[] =>
68
+ rows.length
69
+ ? comps(rows[0]).map(([n]) => n).filter((n) => rows.every((b) => b[n]))
70
+ : []
71
+
72
+ // The values a component holds that are there, in the order it holds them.
73
+ let held = (b: Bundle, name: string) =>
74
+ Object.entries(comp(b, name)).filter(([, v]) => v != null && v !== '')
75
+
76
+ /**
77
+ * The property a component's column runs by: the first one the rows show.
78
+ *
79
+ * ```ts
80
+ * import { leads } from './Query.ts'
81
+ * leads([
82
+ * { entity: { eid: 'a' }, created: { by: null, at: '2026-11-10' } },
83
+ * ], 'created') // 'created.at'
84
+ * ```
85
+ */
86
+ export let leads = (rows: Bundle[], name: string): string | undefined => {
87
+ let prop = rows.map((b) => held(b, name)[0]?.[0]).find(Boolean)
88
+ return prop && `${name}.${prop}`
89
+ }
90
+
91
+ /**
92
+ * A query line run by `order` in place of any order it names, the rows with no
93
+ * value last, or as it comes without one.
94
+ *
95
+ * ```ts
96
+ * import { runBy } from './Query.ts'
97
+ * runBy('.task .order=doc.title', '-task.status') // '.task&.order[last]=-task.status'
98
+ * runBy('.a|.b&.order[last]=x') // '.a | .b'
99
+ * ```
100
+ */
101
+ export let runBy = (text: string, order?: string): string =>
102
+ conjoin(
103
+ tokens(text).filter((t) => !/^\.order[=[]/.test(t)).join(' '),
104
+ order ? stringify(ordered(order, true)) : '',
105
+ )
106
+
107
+ // What a component holds, in a cell: its first few values that are there,
108
+ // each as a person reads it.
109
+ let summed = (io: Io, b: Bundle, name: string) => {
110
+ let set = held(b, name)
111
+ return set.length
112
+ ? set.slice(0, 3).flatMap(([k, v], i) => [
113
+ i ? ' ' : null,
114
+ h(Value, { mod: 'id' }, k),
115
+ ' ',
116
+ reads(io, v, io.vocab.prop(name, k)),
117
+ ])
118
+ : h(Value, { mod: 'nil' }, 'present')
119
+ }
120
+
121
+ // Every entity the rows' values name, so each reads by its name.
122
+ let mentioned = (rows: Bundle[], names: string[]) =>
123
+ rows.flatMap((b) =>
124
+ names.flatMap((n) => Object.values(comp(b, n)).filter(named))
125
+ )
126
+
127
+ // A tally, or a distinct list read as one: each value beside its count, an
128
+ // entity by its name.
129
+ let Tallied = ({ io, id, tally }: {
130
+ io: Io
131
+ id: string
132
+ tally: Record<string, number>
133
+ }) => {
134
+ let values = Object.keys(tally).toSorted((a, b) => tally[b] - tally[a])
135
+ let page = grid(io, id).after?.length ?? 0
136
+ useNamed(io, values.slice(page * SIZE, (page + 1) * SIZE).filter(named))
137
+ return h(Grid, {
138
+ io,
139
+ id,
140
+ local: true,
141
+ pick: (b) => named(b.entity.eid) ? b.entity.eid : undefined,
142
+ rows: values.map((v): Bundle => ({ entity: { eid: v } })),
143
+ columns: [
144
+ {
145
+ name: 'value',
146
+ value: (b) => b.entity.eid || null,
147
+ cell: (b) =>
148
+ named(b.entity.eid)
149
+ ? mention(io, b.entity.eid)
150
+ : line(b.entity.eid, 120) || '""',
151
+ },
152
+ {
153
+ name: 'entities',
154
+ mod: 'num',
155
+ value: (b) => tally[b.entity.eid] ?? 0,
156
+ cell: (b) => count(tally[b.entity.eid] ?? 0),
157
+ },
158
+ ],
159
+ })
160
+ }
161
+
162
+ /** The rows a query answers, a page at a time. */
163
+ let Answered = ({ io, text, ast }: { io: Io; text: string; ast: Query }) => {
164
+ let id = key('query', text)
165
+ let own = windowOf(ast).limit != null
166
+ let run = ast.clauses.find((c): c is Order => c.kind == 'order')
167
+ let order = run?.value
168
+ let base = runBy(text)
169
+ let got = io.ask(
170
+ own ? { rows: { query: whole(text), typed: true } } : {
171
+ rows: {
172
+ query: whole(paged(io, id, base, { order, last: run?.last })),
173
+ typed: true,
174
+ },
175
+ total: { query: conjoin(base, '.count'), once: true, typed: true },
176
+ },
177
+ )
178
+ let all = rows(got.rows)
179
+ useSets(io, all)
180
+ let cols = shared(all)
181
+ useNamed(io, mentioned(all, cols))
182
+ // A column the rows run by keeps its property, whichever rows came back.
183
+ let by = order?.replace(/^-/, '')
184
+ return waiting(got.rows) ?? h(Grid, {
185
+ io,
186
+ id,
187
+ rows: all,
188
+ total: own ? all.length : got.total?.count,
189
+ sorts: { order, to: (o) => io.go(io.find(runBy(text, o))) },
190
+ columns: [
191
+ {
192
+ name: 'id',
193
+ cell: (b) => io.show(b, 'Inspect.Reference.Inline'),
194
+ },
195
+ ...cols.map((n) => ({
196
+ name: n,
197
+ sort: by?.startsWith(`${n}.`) ? by : leads(all, n),
198
+ cell: (b: Bundle) => summed(io, b, n),
199
+ })),
200
+ ],
201
+ })
202
+ }
203
+
204
+ /** A query's own page. */
205
+ export let QueryPage = (
206
+ { io, text }: { io: Io; text: string },
207
+ ): JSX.Element => {
208
+ let { ast, agg, error } = read(text)
209
+ let got = io.ask(agg ? { answer: { query: text, typed: true } } : {})
210
+ let a = got.answer
211
+ return h(
212
+ 'div',
213
+ { 'data-query': text },
214
+ h(
215
+ Head,
216
+ {},
217
+ h(Head.Title, {}, 'query', h(Head.Kind, {}, agg ?? 'rows')),
218
+ h(Head.Sub, {}, h(Value, { mod: 'id' }, text)),
219
+ ),
220
+ error
221
+ ? h(Rows.More, {}, error)
222
+ : agg == 'count'
223
+ ? waiting(a) ?? h(Value, { mod: 'num' }, count(a?.count ?? 0))
224
+ : agg
225
+ ? waiting(a) ??
226
+ h(Tallied, { io, id: key('query', text), tally: a?.tally ?? {} })
227
+ : h(Answered, { io, text, ast: ast! }),
228
+ )
229
+ }
package/README.md CHANGED
@@ -1,3 +1,142 @@
1
- # Temporary Holding Version
1
+ # @yaks/inspect
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Inspect views show how a graph is made: its entities, vocabulary components,
4
+ packages, properties, query rows and map. They draw through the host's shared
5
+ [@yaks/render](../render) registry, in browsers and terminals.
6
+
7
+ A **view** is a registration selected for a bundle, with declared queries and a
8
+ renderer. The host supplies `Io`: answers, edits, references, page state and
9
+ navigation. Inspect owns the reading; [@yaks/browse](../browse) owns the app,
10
+ sidebar and history stack.
11
+
12
+ ## Views
13
+
14
+ | name | draws |
15
+ | ----------------------------------------------- | ------------------------------------------------------------------------------------------ |
16
+ | `Inspect.Page` | a `_comp`, `_namespace`, `_prop` or `_effect` vocabulary entity |
17
+ | `Full.Body` | the same page under another head (a Full page's): its words, facts and parts |
18
+ | `Inspect.Head`, `Inspect.Body`, `Inspect.Facts` | name, provenance, words and component values |
19
+ | `Inspect.Links`, `Inspect.History` | references both ways and recorded changes |
20
+ | `Inspect.Query` | query rows with shared component columns, count or tally |
21
+ | `Inspect.Map` | the schema: a package tree, components, kinds, relations and archetypes, with their counts |
22
+ | `Inspect.Note` | a note under a heading, selected through the registry |
23
+ | `Tile`, `Inline` | vocabulary entities (`_kind` among them) in any screen that asks for them |
24
+
25
+ The `/views` facet contributes `inspectViews()`, which loads `all` when a host
26
+ asks for inspector views. Hosts adapt `View.Render` to their query and edit
27
+ interfaces; `asks` declares which answers the renderer needs.
28
+
29
+ ```ts
30
+ import { inspectViews } from '@yaks/inspect/views'
31
+ let all = await inspectViews()
32
+ import { equal } from '@yaks/testing'
33
+ equal(all.some((v) => v.view === 'Inspect.Query'), true)
34
+ equal(all.some((v) => v.view === 'Inspect.Map'), true)
35
+ ```
36
+
37
+ `Past` reads an entity as it was: what it held just after one of its
38
+ transactions, rebuilt from its history, or, for a deleted entity, what it held
39
+ last, with when and by whom it was deleted. It is never edited, and its history
40
+ opens each moment's version through the host's `past(eid, tx)` door, as an
41
+ entity's own History does wherever the host has one.
42
+
43
+ Inspect pages are read until the reader asks to edit. Values use @yaks/ux
44
+ editing; changes are emitted as bundles. Notes are comments and tasks about the
45
+ entity and heading where they were left. Page-only table order, paging, editing
46
+ and refusal state use the `/front` vocabulary.
47
+
48
+ A table's sortable heading is a button: pressing it runs the rows by that
49
+ column, again the other way, then as they came, and `aria-sort` and an arrow say
50
+ which. A query's rows are run by the graph (`.order[last]=`, the rows with no
51
+ value last either way), each component's column by the first property it shows,
52
+ and the order is the query line's own, so the page's address keeps it through a
53
+ reload or a shared link. A line typed with a plain `.order=` runs as written
54
+ until a heading is pressed. A table holding every row sorts it through @yaks/ux
55
+ `sortRows`: numbers as numbers, an empty value last.
56
+
57
+ ## What an entity holds, in order
58
+
59
+ `Held` draws what an entity holds by its links as an ordered list edited in
60
+ place, for any package's page: each row is the entity a link leads to, drawn by
61
+ the view the caller names (`tile`), in the order the caller gives the links.
62
+ Where the host takes edits, a row dragged between two others is put there, which
63
+ writes the links' positions (`edge.ord`, @yaks/edge's `placed`), and an entity
64
+ dragged from elsewhere (@yaks/ux's `drag`) joins the list where it is dropped,
65
+ linked by `tag`; `join` says what else that writes, or refuses it. Each row
66
+ opens in place on the title and body of what it leads to, typed over where they
67
+ stand (@yaks/ux's `Edit.Text`). An open row is no drag handle: selecting its
68
+ text, clicking into it and typing never pick it up. @yaks/topic's page draws its
69
+ lists with it.
70
+
71
+ ```ts ignore
72
+ h(Held, {
73
+ io,
74
+ from,
75
+ links,
76
+ ends,
77
+ tile: 'Topic.List.Tile',
78
+ tag: 'contains',
79
+ empty: 'nothing yet',
80
+ })
81
+ ```
82
+
83
+ ## What an entity says, where it stands
84
+
85
+ `Words` draws a body (`comp.prop`, markdown) the way browse draws every body:
86
+ read as markdown, and typed over in its source on a double-click (@yaks/ux's
87
+ `Edit.Text`), written when the person leaves it. Where the host takes no edits
88
+ it is only read. Where typing is what a page is for (`click`), one click types
89
+ into it and it says so under the pointer. `Held`'s rows and @yaks/persona's
90
+ pages draw their documents' bodies with it.
91
+
92
+ ```ts ignore
93
+ h(Words, { io, e, comp: 'doc', prop: 'body' })
94
+ ```
95
+
96
+ ## Code written for a storage, in a view
97
+
98
+ A view can run a function written for a storage, such as a package's composer,
99
+ over what the view holds. `useReading(io, read)` hands `read` a **reader**, a
100
+ storage that only reads (`read` a query, `get` some entities), whose every read
101
+ is one of the view's asks, kept live while the view is mounted. A read not
102
+ answered yet reads as nothing; as each answer lands the function runs again and
103
+ reads on, and when a write moves anything it read, it runs again with that. It
104
+ returns the function's value and whether every read was answered (`ready`).
105
+ @yaks/persona's Markdown view composes a persona this way, with the code the
106
+ server composes it with.
107
+
108
+ ```ts ignore
109
+ let { value, ready } = useReading(io, (r) => voice(vocab)(wear(r, vocab)(eid)))
110
+ ```
111
+
112
+ The function must stay synchronous over synchronous input, as @yaks/fp's `after`
113
+ and `each` do.
114
+
115
+ ## Exports
116
+
117
+ | export | provides |
118
+ | --------- | --------------------------------------------------------------- |
119
+ | `.` | host/view contracts, helpers, notes and inspector registrations |
120
+ | `./views` | `inspectViews()` loads query-backed registrations |
121
+ | `./front` | page-only state vocabulary |
122
+
123
+ The `inspector(registry, host)` adapter mounts registrations supplied by a host.
124
+ Browse uses its own shared registry instead; it never creates a second registry
125
+ for Inspect.
126
+
127
+ ## Limits
128
+
129
+ Inspect serves no page or terminal app, and owns no stack or URL. Browse
130
+ integrates these views into its app.
131
+
132
+ The schema map shows one slice at a time: a tree of packages, the components and
133
+ effects each declares, and the properties of each component; every component;
134
+ every kind; the relations; or the archetypes. Names and what each is come from
135
+ the loaded vocabulary, so the map paints before any count, except the kinds,
136
+ which are listed from the `_kind` rows the graph describes them in; the slice,
137
+ open rows and table order stay in the page graph.
138
+
139
+ The map and the detail pages share a census of archetype rows and populations
140
+ rather than running a count for each component. SQLite and the Cloudflare Store
141
+ answer the unfiltered population tally and component counts from maintained
142
+ metadata; filtered counts still run their candidate query.
package/Words.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * What an entity says, where it stands: `Words`. A body (`comp.prop`, its
3
+ * markdown) reads as markdown, and a double-click types over its source in
4
+ * place (@yaks/ux `Edit.Text`), as every body in browse is edited; leaving it
5
+ * writes what was typed. Where the host takes no edits it is only read. One
6
+ * with nothing written says so, so a double-click has somewhere to land.
7
+ * Where typing is what a page is for (`click`), one click types into it, a
8
+ * link in it still opens, and it says so under the pointer.
9
+ *
10
+ * ```ts ignore
11
+ * h(Words, { io, e, comp: 'doc', prop: 'body' })
12
+ * ```
13
+ *
14
+ * @module
15
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
16
+ import { Markdown } from "@yaks/markdown";
17
+ import * as ui from "@yaks/ui";
18
+ import { Edit, useEdit } from "@yaks/ux";
19
+ import { str } from "./read.js";
20
+ /** A body read as markdown, typed over where it stands. */ export let Words = ({ io, e, comp, prop, at, empty = 'nothing is written yet', click })=>{
21
+ let text = str(e, comp, prop);
22
+ let edit = useEdit(e.entity.eid, comp, prop, {
23
+ at,
24
+ value: text
25
+ });
26
+ let open = io.edits && edit.open;
27
+ let typed = io.edits && !open;
28
+ return /*#__PURE__*/ h(ui.Body, {
29
+ 'data-words': `${comp}.${prop}`,
30
+ mod: io.edits && click ? 'typed' : undefined,
31
+ onDoubleClick: typed ? edit.begin : undefined,
32
+ onClick: typed && click ? (ev)=>ev.target.closest?.('a') || edit.begin() : undefined
33
+ }, open ? /*#__PURE__*/ h(Edit.Text, {
34
+ e,
35
+ comp,
36
+ prop,
37
+ at: edit.at,
38
+ multi: true
39
+ }) : text ? /*#__PURE__*/ h(Markdown, {
40
+ source: text
41
+ }) : /*#__PURE__*/ h(ui.Rows.More, {}, io.edits ? `${empty}: ${click ? 'click' : 'double-click'} to write` : empty));
42
+ };
43
+ //# sourceMappingURL=Words.js.map
package/Words.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Words.js","sources":["./Words.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;CAcC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoC;AACzG,SAAS,QAAQ,8BAAmC;AACpD,YAAY,wBAA6B;AACzC,SAAS,IAAI,EAAE,OAAO,wBAA6B;AAEnD,SAAS,GAAG,oBAAmB;AAgB/B,yDAAyD,GACzD,OAAO,IAAI,QAAQ,CACjB,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,wBAAwB,EAAE,KAAK,EACpD;EAEZ,IAAI,OAAO,IAAI,GAAG,MAAM;EACxB,IAAI,OAAO,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,MAAM;IAAE;IAAI,OAAO;EAAK;EAC/D,IAAI,OAAO,GAAG,KAAK,IAAI,KAAK,IAAI;EAChC,IAAI,QAAQ,GAAG,KAAK,IAAI,CAAC;EACzB,qBAAO,EACL,GAAG,IAAI,EACP;IACE,cAAc,GAAG,KAAK,CAAC,EAAE,MAAM;IAC/B,KAAK,GAAG,KAAK,IAAI,QAAQ,UAAU;I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