@yaks/browse 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 (271) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +324 -2
  3. package/_dist/app.d.ts +8 -0
  4. package/_dist/app.d.ts.map +1 -0
  5. package/_dist/cli.d.ts +16 -0
  6. package/_dist/cli.d.ts.map +1 -0
  7. package/_dist/hosting.d.ts +24 -0
  8. package/_dist/hosting.d.ts.map +1 -0
  9. package/_dist/mod.d.ts +7 -0
  10. package/_dist/mod.d.ts.map +1 -0
  11. package/_dist/types.d.ts +5 -0
  12. package/_dist/types.d.ts.map +1 -0
  13. package/_dist/url.d.ts +2 -0
  14. package/_dist/url.d.ts.map +1 -0
  15. package/app.js +10 -0
  16. package/app.js.map +1 -0
  17. package/app.ts +10 -0
  18. package/browser-links.js +22 -0
  19. package/browser-links.js.map +1 -0
  20. package/browser-links.ts +28 -0
  21. package/cli.js +172 -0
  22. package/cli.js.map +1 -0
  23. package/cli.ts +168 -0
  24. package/client.js +748 -0
  25. package/client.js.map +1 -0
  26. package/client.ts +734 -0
  27. package/clipboard.js +18 -0
  28. package/clipboard.js.map +1 -0
  29. package/clipboard.ts +17 -0
  30. package/commands.js +1157 -0
  31. package/commands.js.map +1 -0
  32. package/commands.ts +1108 -0
  33. package/components/Ansi.tsx +160 -0
  34. package/components/App.tsx +446 -0
  35. package/components/Canvas.tsx +625 -0
  36. package/components/Card.tsx +276 -0
  37. package/components/Chat.tsx +205 -0
  38. package/components/Configuration.tsx +218 -0
  39. package/components/Decision.tsx +49 -0
  40. package/components/Dot.tsx +52 -0
  41. package/components/Entity.tsx +609 -0
  42. package/components/Fault.tsx +43 -0
  43. package/components/Filter.tsx +103 -0
  44. package/components/Keybindings.tsx +100 -0
  45. package/components/Keys.tsx +67 -0
  46. package/components/Markdown.tsx +90 -0
  47. package/components/Navigation.tsx +161 -0
  48. package/components/New.tsx +490 -0
  49. package/components/Peek.tsx +168 -0
  50. package/components/Prio.tsx +20 -0
  51. package/components/Run.tsx +263 -0
  52. package/components/Search.tsx +280 -0
  53. package/components/Stamp.tsx +44 -0
  54. package/components/Status.tsx +514 -0
  55. package/components/Sync.tsx +173 -0
  56. package/components/Tile.tsx +50 -0
  57. package/components/answered.js +23 -0
  58. package/components/answered.js.map +1 -0
  59. package/components/answered.ts +25 -0
  60. package/components/comp.js +11 -0
  61. package/components/comp.js.map +1 -0
  62. package/components/comp.ts +10 -0
  63. package/components/drag.js +173 -0
  64. package/components/drag.js.map +1 -0
  65. package/components/drag.ts +198 -0
  66. package/components/fields.tsx +90 -0
  67. package/components/fixtures/README.md +10 -0
  68. package/components/fixtures/archetypes.json +3646 -0
  69. package/components/hits.js +63 -0
  70. package/components/hits.js.map +1 -0
  71. package/components/hits.ts +84 -0
  72. package/components/icons.tsx +177 -0
  73. package/components/inspect.tsx +331 -0
  74. package/components/mount.ts +79 -0
  75. package/components/nav.tsx +479 -0
  76. package/components/offers.js +26 -0
  77. package/components/offers.js.map +1 -0
  78. package/components/offers.ts +54 -0
  79. package/components/page.js +21 -0
  80. package/components/page.js.map +1 -0
  81. package/components/page.ts +18 -0
  82. package/components/read.js +5 -0
  83. package/components/read.js.map +1 -0
  84. package/components/read.ts +7 -0
  85. package/components/registry.js +285 -0
  86. package/components/registry.js.map +1 -0
  87. package/components/registry.ts +317 -0
  88. package/components/session_status.tsx +115 -0
  89. package/components/subscriptions.js +149 -0
  90. package/components/subscriptions.js.map +1 -0
  91. package/components/subscriptions.ts +161 -0
  92. package/components/title.tsx +21 -0
  93. package/components/useQuery.js +166 -0
  94. package/components/useQuery.js.map +1 -0
  95. package/components/useQuery.ts +211 -0
  96. package/components/views/Board.tsx +450 -0
  97. package/components/views/BoardTile.tsx +65 -0
  98. package/components/views/Dashboard.tsx +148 -0
  99. package/components/views/Debug.tsx +445 -0
  100. package/components/views/Dependency.tsx +51 -0
  101. package/components/views/Entry.tsx +500 -0
  102. package/components/views/Gist.tsx +28 -0
  103. package/components/views/Inline.tsx +54 -0
  104. package/components/views/Json.tsx +19 -0
  105. package/components/views/Layout.tsx +211 -0
  106. package/components/views/List.tsx +238 -0
  107. package/components/views/Md.tsx +43 -0
  108. package/components/views/Media.tsx +48 -0
  109. package/components/views/Memory.tsx +32 -0
  110. package/components/views/Relate.tsx +205 -0
  111. package/components/views/Search.tsx +42 -0
  112. package/components/views/Session.tsx +850 -0
  113. package/components/views/SessionManage.tsx +127 -0
  114. package/components/views/Show.tsx +758 -0
  115. package/components/views/Shown.tsx +72 -0
  116. package/components/views/Split.tsx +58 -0
  117. package/components/views/TaskTile.tsx +37 -0
  118. package/components/views/Title.tsx +105 -0
  119. package/components/views/Wake.tsx +77 -0
  120. package/components/views/Web.tsx +49 -0
  121. package/components/wells.js +30 -0
  122. package/components/wells.js.map +1 -0
  123. package/components/wells.ts +33 -0
  124. package/configuration.js +38 -0
  125. package/configuration.js.map +1 -0
  126. package/configuration.ts +41 -0
  127. package/decision_sync.js +88 -0
  128. package/decision_sync.js.map +1 -0
  129. package/decision_sync.ts +93 -0
  130. package/deno.json +1 -0
  131. package/domain-host.tsx +108 -0
  132. package/edge.js +193 -0
  133. package/edge.js.map +1 -0
  134. package/edge.ts +196 -0
  135. package/entry_log.js +241 -0
  136. package/entry_log.js.map +1 -0
  137. package/entry_log.ts +214 -0
  138. package/failure.js +22 -0
  139. package/failure.js.map +1 -0
  140. package/failure.ts +34 -0
  141. package/front.json +61 -0
  142. package/highlight.js +143 -0
  143. package/highlight.js.map +1 -0
  144. package/highlight.ts +149 -0
  145. package/history.js +68 -0
  146. package/history.js.map +1 -0
  147. package/history.ts +72 -0
  148. package/host_commands.js +107 -0
  149. package/host_commands.js.map +1 -0
  150. package/host_commands.ts +38 -0
  151. package/hosting.js +53 -0
  152. package/hosting.js.map +1 -0
  153. package/hosting.ts +72 -0
  154. package/idb.js +14 -0
  155. package/idb.js.map +1 -0
  156. package/idb.ts +15 -0
  157. package/index.js +232 -0
  158. package/index.js.map +1 -0
  159. package/index.ts +252 -0
  160. package/keybindings.js +136 -0
  161. package/keybindings.js.map +1 -0
  162. package/keybindings.ts +37 -0
  163. package/kit.js +103 -0
  164. package/kit.js.map +1 -0
  165. package/kit.ts +119 -0
  166. package/layout.js +254 -0
  167. package/layout.js.map +1 -0
  168. package/layout.ts +210 -0
  169. package/legacy_outbox.js +53 -0
  170. package/legacy_outbox.js.map +1 -0
  171. package/legacy_outbox.ts +63 -0
  172. package/live.js +2883 -0
  173. package/live.js.map +1 -0
  174. package/live.ts +3334 -0
  175. package/live_archetypes.js +92 -0
  176. package/live_archetypes.js.map +1 -0
  177. package/live_archetypes.ts +113 -0
  178. package/live_client.js +145 -0
  179. package/live_client.js.map +1 -0
  180. package/live_client.ts +120 -0
  181. package/main.tsx +5 -0
  182. package/mod.js +7 -0
  183. package/mod.js.map +1 -0
  184. package/mod.ts +7 -0
  185. package/mount.tsx +50 -0
  186. package/navigation.js +120 -0
  187. package/navigation.js.map +1 -0
  188. package/navigation.ts +152 -0
  189. package/near.js +83 -0
  190. package/near.js.map +1 -0
  191. package/near.ts +83 -0
  192. package/new.js +295 -0
  193. package/new.js.map +1 -0
  194. package/new.ts +361 -0
  195. package/outbox.js +112 -0
  196. package/outbox.js.map +1 -0
  197. package/outbox.ts +129 -0
  198. package/owner.js +39 -0
  199. package/owner.js.map +1 -0
  200. package/owner.ts +37 -0
  201. package/package.json +81 -4
  202. package/paste.js +157 -0
  203. package/paste.js.map +1 -0
  204. package/paste.ts +122 -0
  205. package/props.js +303 -0
  206. package/props.js.map +1 -0
  207. package/props.ts +358 -0
  208. package/providers.js +136 -0
  209. package/providers.js.map +1 -0
  210. package/providers.ts +194 -0
  211. package/query.js +987 -0
  212. package/query.js.map +1 -0
  213. package/query.ts +1113 -0
  214. package/remote.js +37 -0
  215. package/remote.js.map +1 -0
  216. package/remote.ts +46 -0
  217. package/resolver.js +149 -0
  218. package/resolver.js.map +1 -0
  219. package/resolver.ts +213 -0
  220. package/rfc2047.js +37 -0
  221. package/rfc2047.js.map +1 -0
  222. package/rfc2047.ts +40 -0
  223. package/row_holds.js +107 -0
  224. package/row_holds.js.map +1 -0
  225. package/row_holds.ts +93 -0
  226. package/served.ts +42 -0
  227. package/session_worktree.js +7 -0
  228. package/session_worktree.js.map +1 -0
  229. package/session_worktree.ts +16 -0
  230. package/sessions.js +57 -0
  231. package/sessions.js.map +1 -0
  232. package/sessions.ts +53 -0
  233. package/sha.js +161 -0
  234. package/sha.js.map +1 -0
  235. package/sha.ts +164 -0
  236. package/styles.css +2823 -0
  237. package/subs.js +36 -0
  238. package/subs.js.map +1 -0
  239. package/subs.ts +40 -0
  240. package/terminal-route.js +13 -0
  241. package/terminal-route.js.map +1 -0
  242. package/terminal-route.ts +17 -0
  243. package/terminal.js +251 -0
  244. package/terminal.js.map +1 -0
  245. package/terminal.ts +186 -0
  246. package/time.js +142 -0
  247. package/time.js.map +1 -0
  248. package/time.ts +133 -0
  249. package/title.js +25 -0
  250. package/title.js.map +1 -0
  251. package/title.ts +50 -0
  252. package/tui/doc.ts +6 -0
  253. package/tui/testing.ts +19 -0
  254. package/twin.js +11 -0
  255. package/twin.js.map +1 -0
  256. package/twin.ts +13 -0
  257. package/types.js +456 -0
  258. package/types.js.map +1 -0
  259. package/types.ts +1370 -0
  260. package/url.js +77 -0
  261. package/url.js.map +1 -0
  262. package/url.ts +85 -0
  263. package/verb.js +82 -0
  264. package/verb.js.map +1 -0
  265. package/verb.ts +137 -0
  266. package/warmth.js +41 -0
  267. package/warmth.js.map +1 -0
  268. package/warmth.ts +54 -0
  269. package/wire.js +86 -0
  270. package/wire.js.map +1 -0
  271. package/wire.ts +63 -0
package/remote.js ADDED
@@ -0,0 +1,37 @@
1
+ // An app's store as a terminal client: resolve the CLI's app selector at the
2
+ // account door, then use the same HTTP and subscription wire as a local host.
3
+ // The login token stays in headers, including the socket handshake — never
4
+ // in an address, a query string, or a socket protocol.
5
+ import { doorUrl, tokenFor } from "@yaks/cli";
6
+ // The terminal runtime accepts headers on the WebSocket constructor. DOM
7
+ // typings omit that extension; this seam stays out of browser-facing exports.
8
+ let Socket = WebSocket;
9
+ /** The store URL and authenticated wire for an app the login account reaches. */ export let remote = async (app, host, state, go = fetch, account = {})=>{
10
+ let token = await tokenFor(host, state, account);
11
+ if (!token) throw new Error('not signed in — run yak auth yaks.app first');
12
+ let headers = {
13
+ authorization: `Bearer ${token}`
14
+ };
15
+ let at = new URL('/api/app', doorUrl(host));
16
+ at.searchParams.set('app', app);
17
+ let response = await go(at, {
18
+ headers
19
+ });
20
+ let answer = await response.json();
21
+ if (!response.ok) {
22
+ throw new Error(answer.error?.message ?? `app resolution refused (${response.status})`);
23
+ }
24
+ return {
25
+ url: answer.url,
26
+ wire: {
27
+ headers,
28
+ fetch: go,
29
+ // Deno's terminal WebSocket takes headers; browser clients authenticate
30
+ // with their own cookie instead. Reconnects use this same handshake.
31
+ connect: (url)=>new Socket(url, {
32
+ headers
33
+ })
34
+ }
35
+ };
36
+ };
37
+ //# sourceMappingURL=remote.js.map
package/remote.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sources":["./remote.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,uDAAuD;AACvD,SAAS,OAAO,EAAE,QAAQ,yBAA8B;AAGxD,yEAAyE;AACzE,8EAA8E;AAC9E,IAAI,SAAS;AAMb,+EAA+E,GAC/E,OAAO,IAAI,SAAS,OAClB,KACA,MACA,OACA,KAAmB,KAAK,EACxB,UAA4C,CAAC,CAAC;EAE9C,IAAI,QAAQ,MAAM,SAAS,MAAM,OAAO;EACxC,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM;EAC5B,IAAI,UAAU;IAAE,eAAe,CAAC,OAAO,EAAE,OAAO;EAAC;EACjD,IAAI,KAAK,IAAI,IAAI,YAAY,QAAQ;EACrC,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO;EAC3B,IAAI,WAAW,MAAM,GAAG,IAAI;IAAE;EAAQ;EACtC,IAAI,SAAS,MAAM,SAAS,IAAI;EAChC,IAAI,CAAC,SAAS,EAAE,EAAE;IAChB,MAAM,IAAI,MACR,OAAO,KAAK,EAAE,WAAW,CAAC,wBAAwB,EAAE,SAAS,MAAM,CAAC,CAAC,CAAC;EAE1E;EACA,OAAO;IACL,KAAK,OAAO,GAAG;IACf,MAAM;MACJ;MACA,OAAO;MACP,wEAAwE;MACxE,qEAAqE;MACrE,SAAS,CAAC,MAAQ,IAAI,OAAO,KAAK;UAAE;QAAQ;IAC9C;EACF;AACF,EAAC"}
package/remote.ts ADDED
@@ -0,0 +1,46 @@
1
+ // An app's store as a terminal client: resolve the CLI's app selector at the
2
+ // account door, then use the same HTTP and subscription wire as a local host.
3
+ // The login token stays in headers, including the socket handshake — never
4
+ // in an address, a query string, or a socket protocol.
5
+ import { doorUrl, tokenFor } from '@yaks/cli'
6
+ import type { ClientOpts } from 'jsr:@yaks/client@0.2.36'
7
+
8
+ // The terminal runtime accepts headers on the WebSocket constructor. DOM
9
+ // typings omit that extension; this seam stays out of browser-facing exports.
10
+ let Socket = WebSocket as unknown as {
11
+ new (url: string, options: { headers: Record<string, string> }): WebSocket
12
+ }
13
+
14
+ export type Connection = Pick<ClientOpts, 'headers' | 'fetch' | 'connect'>
15
+
16
+ /** The store URL and authenticated wire for an app the login account reaches. */
17
+ export let remote = async (
18
+ app: string,
19
+ host: string,
20
+ state?: string,
21
+ go: typeof fetch = fetch,
22
+ account: { config?: string; as?: string } = {},
23
+ ): Promise<{ url: string; wire: Connection }> => {
24
+ let token = await tokenFor(host, state, account)
25
+ if (!token) throw new Error('not signed in — run yak auth yaks.app first')
26
+ let headers = { authorization: `Bearer ${token}` }
27
+ let at = new URL('/api/app', doorUrl(host))
28
+ at.searchParams.set('app', app)
29
+ let response = await go(at, { headers })
30
+ let answer = await response.json()
31
+ if (!response.ok) {
32
+ throw new Error(
33
+ answer.error?.message ?? `app resolution refused (${response.status})`,
34
+ )
35
+ }
36
+ return {
37
+ url: answer.url,
38
+ wire: {
39
+ headers,
40
+ fetch: go,
41
+ // Deno's terminal WebSocket takes headers; browser clients authenticate
42
+ // with their own cookie instead. Reconnects use this same handshake.
43
+ connect: (url) => new Socket(url, { headers }),
44
+ },
45
+ }
46
+ }
package/resolver.js ADDED
@@ -0,0 +1,149 @@
1
+ // The store-agnostic resolver seam — the door "which entities match this query"
2
+ // opens through. A query is a value (Pred[], the query.ts grammar boards and
3
+ // graph_query already speak), resolved to a set of eids either one-shot
4
+ // (`resolve`) or as a NARROW live signal (`subscribe`) that fires only when the
5
+ // RESULT changes, never on an unrelated patch. The BACKING is swappable: this
6
+ // file ships the IN-MEMORY realization (index anchor + matchQuery over the live
7
+ // cache), the near-term backing D-17120 keeps; T-17125 drops an IndexedDB
8
+ // implementation behind the SAME interface with zero call-site churn — live.ts
9
+ // (queryEids) and useQuery call the seam, never a concrete cache.
10
+ import { signal, untracked } from "@preact/signals-core";
11
+ import { fieldsOf, matchQuery, selected, textual } from "./query.js";
12
+ let queryKey = (preds)=>JSON.stringify(preds);
13
+ let wakeFields = (preds)=>(fieldsOf(preds) ?? []).filter((f)=>f.wake);
14
+ export let memoryResolver = (store)=>{
15
+ let sets = new Map();
16
+ // Membership is row-local: this one row tested against the live cache. peek,
17
+ // never .value — resolving a query must not subscribe the caller to the cache.
18
+ let matches = (eid, preds)=>{
19
+ let r = store.read(eid);
20
+ return !!r && selected(r, preds) && matchQuery(r, preds, store.read, undefined, store.kids);
21
+ };
22
+ // The value signature of one member's waking projected columns — what a
23
+ // re-fire compares against to tell a move (x/y/w/h) from a mute z-bump.
24
+ let sig = (eid, fields)=>{
25
+ let r = store.read(eid);
26
+ return JSON.stringify(fields.map((f)=>f.prop ? r?.[f.comp]?.[f.prop] ?? null : !!r?.[f.comp]));
27
+ };
28
+ let seed = (s, ids)=>{
29
+ if (!s.wake.length) return;
30
+ s.vals.clear();
31
+ for (let e of ids)s.vals.set(e, sig(e, s.wake));
32
+ };
33
+ // One resolution pass: the index narrows to a candidate set (or the whole
34
+ // cache when no pred anchors — the board fallback), then listed + matchQuery
35
+ // filter. O(result), never O(graph).
36
+ let scan = (preds)=>{
37
+ if (textual(preds)) return [];
38
+ let cand = store.anchor(preds);
39
+ let pool = cand ?? store.keys();
40
+ let out = [];
41
+ for (let eid of pool)if (matches(eid, preds)) out.push(eid);
42
+ return out;
43
+ };
44
+ let resolve = (preds)=>untracked(()=>scan(preds));
45
+ let set = (preds)=>{
46
+ let key = queryKey(preds);
47
+ let found = sets.get(key);
48
+ if (!found) {
49
+ let ids = resolve(preds);
50
+ found = {
51
+ preds,
52
+ ids: signal(ids),
53
+ n: 0,
54
+ wake: wakeFields(preds),
55
+ vals: new Map()
56
+ };
57
+ seed(found, ids);
58
+ sets.set(key, found);
59
+ }
60
+ return found;
61
+ };
62
+ let subscribe = (preds)=>set(preds).ids;
63
+ let hold = (preds)=>{
64
+ let s = set(preds);
65
+ s.n++;
66
+ return s.ids;
67
+ };
68
+ let drop = (preds)=>{
69
+ let key = queryKey(preds);
70
+ let s = sets.get(key);
71
+ if (!s || --s.n > 0) return;
72
+ sets.delete(key);
73
+ };
74
+ // The parents a touched CHILD moves: a reverse hop makes a parent's membership
75
+ // depend on its children, so a new/edited comment must re-test its target. Read
76
+ // the child's ref column back to the parent — the forward complement of the hop.
77
+ let revParents = (preds, eids)=>{
78
+ let out = [];
79
+ for (let p of preds){
80
+ if (!p.rev) continue;
81
+ for (let e of eids){
82
+ let v = store.read(e)?.[p.rev.comp]?.[p.rev.prop];
83
+ if (v != null) out.push(String(v));
84
+ }
85
+ }
86
+ return out;
87
+ };
88
+ // A patch tests only its touched rows — a stable result keeps its subscribers
89
+ // asleep while an unrelated entity changes. A reverse-hop query also re-tests
90
+ // the parents of any touched child, since their membership turns on it.
91
+ let refresh = (eids)=>{
92
+ for (let s of sets.values()){
93
+ let serverOwned = textual(s.preds);
94
+ let extra = revParents(s.preds, eids);
95
+ let test = extra.length ? new Set([
96
+ ...eids,
97
+ ...extra
98
+ ]) : eids;
99
+ let ids = s.ids.peek();
100
+ let next = ids;
101
+ let moved = false // a waking projected field of a standing member changed
102
+ ;
103
+ for (let eid of test){
104
+ let had = next.includes(eid);
105
+ let wants = serverOwned ? had : matches(eid, s.preds);
106
+ if (had != wants) {
107
+ next = wants ? [
108
+ ...next,
109
+ eid
110
+ ] : next.filter((x)=>x != eid);
111
+ if (s.wake.length) {
112
+ if (wants) s.vals.set(eid, sig(eid, s.wake));
113
+ else s.vals.delete(eid);
114
+ }
115
+ } else if (had && s.wake.length) {
116
+ let now = sig(eid, s.wake);
117
+ if (s.vals.get(eid) !== now) {
118
+ s.vals.set(eid, now);
119
+ moved = true;
120
+ }
121
+ }
122
+ }
123
+ // A membership change publishes the new set; a pure move republishes the
124
+ // same members as a fresh array so the view re-reads their boxes.
125
+ if (next != ids) s.ids.value = next;
126
+ else if (moved) s.ids.value = [
127
+ ...next
128
+ ];
129
+ }
130
+ };
131
+ // A wholesale cache replacement (seed/reset) re-scans every held query.
132
+ let reset = ()=>{
133
+ for (let s of sets.values()){
134
+ if (textual(s.preds)) continue;
135
+ let ids = resolve(s.preds);
136
+ seed(s, ids);
137
+ s.ids.value = ids;
138
+ }
139
+ };
140
+ return {
141
+ resolve,
142
+ subscribe,
143
+ hold,
144
+ drop,
145
+ refresh,
146
+ reset
147
+ };
148
+ };
149
+ //# sourceMappingURL=resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.js","sources":["./resolver.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6EAA6E;AAC7E,wEAAwE;AACxE,gFAAgF;AAChF,8EAA8E;AAC9E,gFAAgF;AAChF,0EAA0E;AAC1E,+EAA+E;AAC/E,kEAAkE;AAClE,SAAsB,MAAM,EAAE,SAAS,+BAAyC;AAChF,SAEE,QAAQ,EAER,UAAU,EAEV,QAAQ,EACR,OAAO,qBACU;AA0DnB,IAAI,WAAW,C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am — the door "which entities match this query"
2
+ // opens through. A query is a value (Pred[], the query.ts grammar boards and
3
+ // graph_query already speak), resolved to a set of eids either one-shot
4
+ // (`resolve`) or as a NARROW live signal (`subscribe`) that fires only when the
5
+ // RESULT changes, never on an unrelated patch. The BACKING is swappable: this
6
+ // file ships the IN-MEMORY realization (index anchor + matchQuery over the live
7
+ // cache), the near-term backing D-17120 keeps; T-17125 drops an IndexedDB
8
+ // implementation behind the SAME interface with zero call-site churn — live.ts
9
+ // (queryEids) and useQuery call the seam, never a concrete cache.
10
+ import { type Signal, signal, untracked } from '@preact/signals-core'
11
+ import {
12
+ type Field,
13
+ fieldsOf,
14
+ type Kids,
15
+ matchQuery,
16
+ type Pred,
17
+ selected,
18
+ textual,
19
+ } from './query.js'
20
+
21
+ // A row as the resolver reads it — the merged-components bag both the live cache
22
+ // and a client Row speak (the same structural shape index.ts and query.ts use,
23
+ // so this file carries no cycle back to live.ts's `Comps`).
24
+ type Row = Record<string, Record<string, unknown> | undefined>
25
+
26
+ // The seam every backend implements: `resolve` is a one-shot GET, `subscribe`
27
+ // returns a live signal of the matching eids. An IndexedDB or SQLite backend
28
+ // satisfies this shape too — the whole point of the extraction.
29
+ export type Resolver = {
30
+ resolve: (preds: Pred[]) => string[]
31
+ subscribe: (preds: Pred[]) => Signal<string[]>
32
+ }
33
+
34
+ // What the in-memory resolver reads the world through: a cache row accessor, the
35
+ // whole-cache key pool (the anchorless board fallback), and the derived index's
36
+ // narrowing (index.ts `anchor`, bound to the live Index and healed before each
37
+ // read). Passed in rather than imported so the resolver stays store-shaped and
38
+ // cycle-free — the same discipline index.ts keeps.
39
+ export type Store = {
40
+ read: (eid: string) => Row | undefined
41
+ keys: () => Iterable<string>
42
+ anchor: (preds: Pred[]) => Set<string> | undefined
43
+ // The reverse-hop accessor: the children pointing back at an entity through a
44
+ // ref column (index.ts `children`, bound to the live Index). Absent leaves a
45
+ // reverse hop matching nothing, the same graceful absence a missing forward
46
+ // deref gives — a store without a reverse index simply cannot answer one.
47
+ kids?: Kids
48
+ }
49
+
50
+ // The in-memory resolver adds the maintenance the live cache drives it with:
51
+ // `refresh` re-tests the eids one patch touched, `reset` re-scans after a
52
+ // wholesale cache replacement, and `hold`/`drop` refcount a query for a
53
+ // component's lifetime so distinct queries don't accumulate. These stay OFF the
54
+ // Resolver seam on purpose — an IDB backend maintains itself from its own change
55
+ // stream and needs none of them; they belong to this concrete realization.
56
+ export type MemoryResolver = Resolver & {
57
+ hold: (preds: Pred[]) => Signal<string[]>
58
+ drop: (preds: Pred[]) => void
59
+ refresh: (eids: Set<string>) => void
60
+ reset: () => void
61
+ }
62
+
63
+ // A query set also carries its projection's WAKING fields (`.fields=…`, minus
64
+ // the `~`-volatile ones) and, per member, a signature of those columns' values.
65
+ // Membership drives the signal; on top of it, a change to a waking projected
66
+ // field of a STANDING member re-fires the set too, while a volatile column (a
67
+ // pin's z) changes its value in the cache without ever waking the list. `wake`
68
+ // is empty for a plain membership query, so the whole mechanism costs nothing
69
+ // there — the reverse-index helpers stay membership-only.
70
+ type QuerySet = {
71
+ preds: Pred[]
72
+ ids: Signal<string[]>
73
+ n: number
74
+ wake: Field[]
75
+ vals: Map<string, string>
76
+ }
77
+ let queryKey = (preds: Pred[]) => JSON.stringify(preds)
78
+ let wakeFields = (preds: Pred[]): Field[] =>
79
+ (fieldsOf(preds) ?? []).filter((f) => f.wake)
80
+
81
+ export let memoryResolver = (store: Store): MemoryResolver => {
82
+ let sets = new Map<string, QuerySet>()
83
+
84
+ // Membership is row-local: this one row tested against the live cache. peek,
85
+ // never .value — resolving a query must not subscribe the caller to the cache.
86
+ let matches = (eid: string, preds: Pred[]) => {
87
+ let r = store.read(eid)
88
+ return !!r && selected(r, preds) &&
89
+ matchQuery(r, preds, store.read, undefined, store.kids)
90
+ }
91
+
92
+ // The value signature of one member's waking projected columns — what a
93
+ // re-fire compares against to tell a move (x/y/w/h) from a mute z-bump.
94
+ let sig = (eid: string, fields: Field[]): string => {
95
+ let r = store.read(eid)
96
+ return JSON.stringify(
97
+ fields.map((f) => f.prop ? r?.[f.comp]?.[f.prop] ?? null : !!r?.[f.comp]),
98
+ )
99
+ }
100
+ let seed = (s: QuerySet, ids: Iterable<string>) => {
101
+ if (!s.wake.length) return
102
+ s.vals.clear()
103
+ for (let e of ids) s.vals.set(e, sig(e, s.wake))
104
+ }
105
+
106
+ // One resolution pass: the index narrows to a candidate set (or the whole
107
+ // cache when no pred anchors — the board fallback), then listed + matchQuery
108
+ // filter. O(result), never O(graph).
109
+ let scan = (preds: Pred[]): string[] => {
110
+ if (textual(preds)) return []
111
+ let cand = store.anchor(preds)
112
+ let pool = cand ?? store.keys()
113
+ let out: string[] = []
114
+ for (let eid of pool) if (matches(eid, preds)) out.push(eid)
115
+ return out
116
+ }
117
+
118
+ let resolve = (preds: Pred[]): string[] => untracked(() => scan(preds))
119
+
120
+ let set = (preds: Pred[]): QuerySet => {
121
+ let key = queryKey(preds)
122
+ let found = sets.get(key)
123
+ if (!found) {
124
+ let ids = resolve(preds)
125
+ found = {
126
+ preds,
127
+ ids: signal(ids),
128
+ n: 0,
129
+ wake: wakeFields(preds),
130
+ vals: new Map(),
131
+ }
132
+ seed(found, ids)
133
+ sets.set(key, found)
134
+ }
135
+ return found
136
+ }
137
+
138
+ let subscribe = (preds: Pred[]): Signal<string[]> => set(preds).ids
139
+
140
+ let hold = (preds: Pred[]): Signal<string[]> => {
141
+ let s = set(preds)
142
+ s.n++
143
+ return s.ids
144
+ }
145
+ let drop = (preds: Pred[]) => {
146
+ let key = queryKey(preds)
147
+ let s = sets.get(key)
148
+ if (!s || --s.n > 0) return
149
+ sets.delete(key)
150
+ }
151
+
152
+ // The parents a touched CHILD moves: a reverse hop makes a parent's membership
153
+ // depend on its children, so a new/edited comment must re-test its target. Read
154
+ // the child's ref column back to the parent — the forward complement of the hop.
155
+ let revParents = (preds: Pred[], eids: Set<string>): string[] => {
156
+ let out: string[] = []
157
+ for (let p of preds) {
158
+ if (!p.rev) continue
159
+ for (let e of eids) {
160
+ let v = store.read(e)?.[p.rev.comp]?.[p.rev.prop]
161
+ if (v != null) out.push(String(v))
162
+ }
163
+ }
164
+ return out
165
+ }
166
+
167
+ // A patch tests only its touched rows — a stable result keeps its subscribers
168
+ // asleep while an unrelated entity changes. A reverse-hop query also re-tests
169
+ // the parents of any touched child, since their membership turns on it.
170
+ let refresh = (eids: Set<string>) => {
171
+ for (let s of sets.values()) {
172
+ let serverOwned = textual(s.preds)
173
+ let extra = revParents(s.preds, eids)
174
+ let test = extra.length ? new Set([...eids, ...extra]) : eids
175
+ let ids = s.ids.peek()
176
+ let next = ids
177
+ let moved = false // a waking projected field of a standing member changed
178
+ for (let eid of test) {
179
+ let had = next.includes(eid)
180
+ let wants = serverOwned ? had : matches(eid, s.preds)
181
+ if (had != wants) {
182
+ next = wants ? [...next, eid] : next.filter((x) => x != eid)
183
+ if (s.wake.length) {
184
+ if (wants) s.vals.set(eid, sig(eid, s.wake))
185
+ else s.vals.delete(eid)
186
+ }
187
+ } else if (had && s.wake.length) {
188
+ let now = sig(eid, s.wake)
189
+ if (s.vals.get(eid) !== now) {
190
+ s.vals.set(eid, now)
191
+ moved = true
192
+ }
193
+ }
194
+ }
195
+ // A membership change publishes the new set; a pure move republishes the
196
+ // same members as a fresh array so the view re-reads their boxes.
197
+ if (next != ids) s.ids.value = next
198
+ else if (moved) s.ids.value = [...next]
199
+ }
200
+ }
201
+
202
+ // A wholesale cache replacement (seed/reset) re-scans every held query.
203
+ let reset = () => {
204
+ for (let s of sets.values()) {
205
+ if (textual(s.preds)) continue
206
+ let ids = resolve(s.preds)
207
+ seed(s, ids)
208
+ s.ids.value = ids
209
+ }
210
+ }
211
+
212
+ return { resolve, subscribe, hold, drop, refresh, reset }
213
+ }
package/rfc2047.js ADDED
@@ -0,0 +1,37 @@
1
+ // RFC 2047 encoded-words, decoded for DISPLAY. Inbound mail subjects are
2
+ // stored exactly as received (`=?UTF-8?Q?...?=`); this is the read-side
3
+ // seam that turns them back into text. Q and B encodings, adjacent words
4
+ // joined with the separating whitespace dropped (the RFC's fold rule),
5
+ // and any word that won't decode — unknown charset, bad bytes, bad
6
+ // base64 — degrades to its raw token: a subject line never throws.
7
+ // Deliberately not a MIME library; only the display concern lives here.
8
+ let WORD = '=\\?([^?\\s]+)\\?([bq])\\?([^?\\s]*)\\?=';
9
+ // Q: `_` is a space, =XX a hex byte, everything else rides through as
10
+ // the ASCII it already is.
11
+ let qBytes = (s)=>{
12
+ let out = [];
13
+ for(let i = 0; i < s.length; i++){
14
+ let hex = s[i] == '=' ? s.slice(i + 1, i + 3) : '';
15
+ if (s[i] == '_') out.push(32);
16
+ else if (/^[0-9a-f]{2}$/i.test(hex)) {
17
+ out.push(parseInt(hex, 16));
18
+ i += 2;
19
+ } else out.push(s.charCodeAt(i));
20
+ }
21
+ return new Uint8Array(out);
22
+ };
23
+ let bBytes = (s)=>Uint8Array.from(atob(s), (c)=>c.charCodeAt(0));
24
+ /// unmime('=?UTF-8?Q?caf=C3=A9?=') -> 'café'
25
+ /// unmime('plain subject') -> 'plain subject'
26
+ export let unmime = (s)=>s.replace(new RegExp(`(${WORD})\\s+(?==\\?)`, 'gi'), '$1').replace(new RegExp(WORD, 'gi'), (raw, cs, enc, text)=>{
27
+ try {
28
+ let bytes = /b/i.test(enc) ? bBytes(text) : qBytes(text);
29
+ return new TextDecoder(cs.split('*')[0], {
30
+ fatal: true
31
+ }).decode(bytes);
32
+ } catch {
33
+ return raw // unknown charset / bad bytes: the token stands as-is
34
+ ;
35
+ }
36
+ });
37
+ //# sourceMappingURL=rfc2047.js.map
package/rfc2047.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rfc2047.js","sources":["./rfc2047.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wEAAwE;AACxE,yEAAyE;AACzE,uEAAuE;AACvE,mEAAmE;AACnE,mEAAmE;AACnE,wEAAwE;AAExE,IAAI,OAAO;AAEX,sEAAsE;AACtE,2BAA2B;AAC3B,IAAI,SAAS,CAAC;EACZ,IAAI,MAAgB,EAAE;EACtB,IAAK,IAAI,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,IAAK;IACjC,IAAI,MAAM,CAAC,CAAC,EAAE,IAAI,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,IAAI,KAAK;IAChD,IAAI,CAAC,CAAC,EAAE,IAAI,KAAK,IAAI,IAAI,CAAC;SACrB,IAAI,iBAAiB,IAAI,CAAC,MAAM;MACnC,IAAI,IAAI,CAAC,SAAS,KAAK;MACvB,KAAK;IACP,OAAO,IAAI,IAAI,CAAC,EAAE,UAAU,CAAC;EAC/B;EACA,OAAO,IAAI,WAAW;AACxB;AAEA,IAAI,SAAS,CAAC,IAAc,WAAW,IAAI,CAAC,KAAK,IAAI,CAAC,IAAM,EAAE,UAAU,CAAC;AAEzE,6CAA6C;AAC7C,8CAA8C;AAC9C,OAAO,IAAI,SAAS,CAAC,IACnB,EACG,OAAO,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,aAAa,CAAC,EAAE,OAAO,MACnD,OAAO,CAAC,IAAI,OAAO,MAAM,OAAO,CAAC,KAAK,IAAI,KAAK;IAC9C,IAAI;MACF,IAAI,QAAQ,KAAK,IAAI,CAAC,OAAO,OAAO,QAAQ,OAAO;MACnD,OAAO,IAAI,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE;QAAE,OAAO;MAAK,GAAG,MAAM,CAAC;IACnE,EAAE,OAAM;MACN,OAAO,IAAI,sDAAsD;;IACnE;EACF,GAAE"}
package/rfc2047.ts ADDED
@@ -0,0 +1,40 @@
1
+ // RFC 2047 encoded-words, decoded for DISPLAY. Inbound mail subjects are
2
+ // stored exactly as received (`=?UTF-8?Q?...?=`); this is the read-side
3
+ // seam that turns them back into text. Q and B encodings, adjacent words
4
+ // joined with the separating whitespace dropped (the RFC's fold rule),
5
+ // and any word that won't decode — unknown charset, bad bytes, bad
6
+ // base64 — degrades to its raw token: a subject line never throws.
7
+ // Deliberately not a MIME library; only the display concern lives here.
8
+
9
+ let WORD = '=\\?([^?\\s]+)\\?([bq])\\?([^?\\s]*)\\?='
10
+
11
+ // Q: `_` is a space, =XX a hex byte, everything else rides through as
12
+ // the ASCII it already is.
13
+ let qBytes = (s: string) => {
14
+ let out: number[] = []
15
+ for (let i = 0; i < s.length; i++) {
16
+ let hex = s[i] == '=' ? s.slice(i + 1, i + 3) : ''
17
+ if (s[i] == '_') out.push(32)
18
+ else if (/^[0-9a-f]{2}$/i.test(hex)) {
19
+ out.push(parseInt(hex, 16))
20
+ i += 2
21
+ } else out.push(s.charCodeAt(i))
22
+ }
23
+ return new Uint8Array(out)
24
+ }
25
+
26
+ let bBytes = (s: string) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0))
27
+
28
+ /// unmime('=?UTF-8?Q?caf=C3=A9?=') -> 'café'
29
+ /// unmime('plain subject') -> 'plain subject'
30
+ export let unmime = (s: string) =>
31
+ s
32
+ .replace(new RegExp(`(${WORD})\\s+(?==\\?)`, 'gi'), '$1')
33
+ .replace(new RegExp(WORD, 'gi'), (raw, cs, enc, text) => {
34
+ try {
35
+ let bytes = /b/i.test(enc) ? bBytes(text) : qBytes(text)
36
+ return new TextDecoder(cs.split('*')[0], { fatal: true }).decode(bytes)
37
+ } catch {
38
+ return raw // unknown charset / bad bytes: the token stands as-is
39
+ }
40
+ })
package/row_holds.js ADDED
@@ -0,0 +1,107 @@
1
+ // Concurrent row readers share a bounded immutable request. Each reader keeps
2
+ // its own lifetime; the request closes only after its last reader leaves.
3
+ export let rowHolds = (open, close, later = queueMicrotask)=>{
4
+ let groups = new Map();
5
+ let held = new Map();
6
+ let pending = new Set();
7
+ let queued = false;
8
+ let generation = 0;
9
+ let start = (names, ids)=>{
10
+ let key = `rows:${ids.join(',')}`;
11
+ let group = groups.get(key);
12
+ if (!group) {
13
+ groups.set(key, group = {
14
+ name: key,
15
+ readers: new Set()
16
+ });
17
+ open(key, `id=${ids.join(',')}`);
18
+ }
19
+ for (let name of names){
20
+ let reader = held.get(name);
21
+ if (reader) {
22
+ group.readers.add(name);
23
+ reader.group = group;
24
+ }
25
+ }
26
+ };
27
+ let flush = ()=>{
28
+ queued = false;
29
+ let wave = [];
30
+ for (let name of pending){
31
+ let reader = held.get(name);
32
+ if (!reader) continue;
33
+ let group = wave.at(-1);
34
+ let ids = new Set([
35
+ ...group?.ids ?? [],
36
+ ...reader.ids
37
+ ]);
38
+ if (!group || ids.size > 60) {
39
+ group = {
40
+ names: [],
41
+ ids: new Set(reader.ids)
42
+ };
43
+ wave.push(group);
44
+ } else group.ids = ids;
45
+ group.names.push(name);
46
+ }
47
+ pending.clear();
48
+ for (let group of wave)start(group.names, [
49
+ ...group.ids
50
+ ]);
51
+ };
52
+ let hold = (ids)=>{
53
+ if (!ids.length) return ()=>{};
54
+ let name = `rows:${ids.join(',')}`;
55
+ let reader = held.get(name);
56
+ if (reader) reader.uses++;
57
+ else {
58
+ reader = {
59
+ ids: [
60
+ ...ids
61
+ ],
62
+ uses: 1
63
+ };
64
+ held.set(name, reader);
65
+ if (ids.length > 60) start([
66
+ name
67
+ ], ids);
68
+ else {
69
+ pending.add(name);
70
+ if (!queued) {
71
+ queued = true;
72
+ let epoch = generation;
73
+ later(()=>{
74
+ if (epoch == generation) flush();
75
+ });
76
+ }
77
+ }
78
+ }
79
+ let owned = reader;
80
+ let active = true;
81
+ return ()=>{
82
+ if (!active) return;
83
+ active = false;
84
+ let reader = held.get(name);
85
+ if (reader != owned || --reader.uses) return;
86
+ held.delete(name);
87
+ pending.delete(name);
88
+ let group = reader.group;
89
+ if (!group) return;
90
+ group.readers.delete(name);
91
+ if (!group.readers.size) {
92
+ groups.delete(group.name);
93
+ close(group.name);
94
+ }
95
+ };
96
+ };
97
+ return Object.assign(hold, {
98
+ clear: ()=>{
99
+ generation++;
100
+ queued = false;
101
+ pending.clear();
102
+ held.clear();
103
+ groups.clear();
104
+ }
105
+ });
106
+ };
107
+ //# sourceMappingURL=row_holds.js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