@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/url.js ADDED
@@ -0,0 +1,77 @@
1
+ import { localPath, pagePath, webOrigin } from "./hosting.js";
2
+ // Human-facing graph addresses. Transport stays local through TASKS_HOST;
3
+ // anything handed to a person uses the board's stable public door.
4
+ import { addressId, HUMAN, SHORT } from "@yaks/id";
5
+ import { EID } from "./types.js";
6
+ import { queryAt, querySearch } from "@yaks/query";
7
+ let origin = webOrigin;
8
+ // The # belongs to the prose handle, not the entity path.
9
+ export let entityPath = (id)=>pagePath(`/${encodeURIComponent(SHORT.test(id) ? id.slice(1) : id)}`);
10
+ export let entityUrl = (id)=>`${origin()}${entityPath(id)}`;
11
+ export { addressId } from "@yaks/id";
12
+ // entityUrl's inverse: the id token a graph entity link names — undefined for
13
+ // any other address. Only id-shaped path segments count (prefix-num, short
14
+ // eid, uuid): every other path is a capability (/query, /telemetry), and handing
15
+ // one to the id resolver would let a slug or alias match something.
16
+ export let entityId = (raw)=>{
17
+ let u;
18
+ try {
19
+ u = new URL(raw.trim());
20
+ } catch {
21
+ return undefined;
22
+ }
23
+ if (u.origin != origin()) return undefined;
24
+ let id;
25
+ try {
26
+ id = addressId(decodeURIComponent(localPath(u.pathname).slice(1))) || (SHORT.test(u.hash) ? u.hash : '');
27
+ } catch {
28
+ return undefined;
29
+ }
30
+ return HUMAN.test(id) || SHORT.test(id) || EID.test(id) ? id : undefined;
31
+ };
32
+ // ONE canonical spelling for a page address. A page filed from a browser
33
+ // and the same page asked about later must produce the same string, or a
34
+ // "what references this?" badge lies by omission — so this is the only
35
+ // place that decides, and it runs from the TYPE (props.ts `url`), which
36
+ // means every door normalizes: writes through parseProp, filters through
37
+ // query.ts atom(). Nothing else may spell it.
38
+ //
39
+ // What carries no identity goes: a fragment names a spot INSIDE a page,
40
+ // campaign params name the trip rather than the destination, credentials
41
+ // are never part of a page's name, and a trailing slash is a server's
42
+ // habit. What might: query params stay (and keep their order — sorting
43
+ // re-encodes, and no site sends them shuffled between visits).
44
+ //
45
+ // Anything that isn't an http(s) URL is left exactly as it came: the same
46
+ // type carries `repo.url`, where a git remote (git@host:owner/repo.git)
47
+ // is the value and mangling it would be the bug.
48
+ let JUNK = /^(?:utm_|ga_|mc_|pk_|piwik_|hsa_|_hs|vero_)|^(?:gclid|dclid|gbraid|wbraid|fbclid|msclkid|yclid|twclid|mkt_tok|igshid|ref_src|ref_url|s_cid|si|scid|spm|cmpid)$/i;
49
+ export let normalize = (raw)=>{
50
+ let text = raw.trim();
51
+ let u;
52
+ try {
53
+ u = new URL(text);
54
+ } catch {
55
+ return text;
56
+ }
57
+ if (u.protocol != 'http:' && u.protocol != 'https:') return text;
58
+ u.hash = '';
59
+ u.username = u.password = '';
60
+ for (let k of [
61
+ ...u.searchParams.keys()
62
+ ]){
63
+ if (JUNK.test(k)) u.searchParams.delete(k);
64
+ }
65
+ // The root keeps its slash (that IS the canonical root); every deeper
66
+ // path drops one, since /a and /a/ are one page everywhere it matters
67
+ // and a refetch follows the redirect either way.
68
+ if (u.pathname != '/') u.pathname = u.pathname.replace(/\/+$/, '');
69
+ return u.href.replace(/\?$/, '');
70
+ };
71
+ // A search is a view of the store, not a saved entity.
72
+ export let searchPath = (q)=>`/${querySearch(q)}`;
73
+ export let searchAt = (at)=>{
74
+ let url = new URL(at, 'http://x');
75
+ return url.pathname == '/' ? queryAt(url.search).query : null;
76
+ };
77
+ //# sourceMappingURL=url.js.map
package/url.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sources":["./url.ts"],"names":[],"mappings":"AAAA,SAAS,SAAS,EAAE,QAAQ,EAAE,SAAS,uBAAsB;AAC7D,0EAA0E;AAC1E,mEAAmE;AAEnE,SAAS,SAAS,EAAE,KAAK,EAAE,KAAK,wBAA6B;AAC7D,SAAS,GAAG,qBAAoB;AAChC,SAAS,OAAO,EAAE,WAAW,2BAAgC;AAE7D,IAAI,SAAS;AAEb,0DAA0D;AAC1D,OAAO,IAAI,aAAa,CAAC,KACvB,SAAS,CAAC,CAAC,EAAE,mBAAmB,MAAM,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,KAAK,EAAC;AACvE,OAAO,IAAI,YAAY,CAAC,KAAe,GAAG,WAAW,WAAW,KAAK,CAAA;AAErE,SAAS,SAAS,wBAA6B;AAE/C,8EAA8E;AAC9E,2EAA2E;AAC3E,iFAAiF;AACjF,oEAAoE;AACpE,OAAO,IAAI,WAAW,CAAC;EACrB,IAAI;EACJ,IAAI;IACF,IAAI,IAAI,IAAI,IAAI,IAAI;EACtB,EAAE,OAAM;IACN,OAAO;EACT;EACA,IAAI,EAAE,MAAM,IAAI,UAAU,OAAO;EACjC,IAAI;EACJ,IAAI;IACF,KAAK,UAAU,mBAAmB,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,QAC5D,CAAC,MAAM,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE,IAAI,GAAG,EAAE;EACrC,EAAE,OAAM;IACN,OAAO;EACT;EACA,OAAO,MAAM,IAAI,CAAC,OAAO,MAAM,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,KAAK;AACjE,EAAC;AAED,yEAAyE;AACzE,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,yEAAyE;AACzE,8CAA8C;AAC9C,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,sEAAsE;AACtE,uEAAuE;AACvE,+DAA+D;AAC/D,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,iDAAiD;AACjD,IAAI,OACF;AAEF,OAAO,IAAI,YAAY,CAAC;EACtB,IAAI,OAAO,IAAI,IAAI;EACnB,IAAI;EACJ,IAAI;IACF,IAAI,IAAI,IAAI;EACd,EAAE,OAAM;IACN,OAAO;EACT;EACA,IAAI,EAAE,QAAQ,IAAI,WAAW,EAAE,QAAQ,IAAI,UAAU,OAAO;EAC5D,EAAE,IAAI,GAAG;EACT,EAAE,QAAQ,GAAG,EAAE,QAAQ,GAAG;EAC1B,KAAK,IAAI,KAAK;OAAI,EAAE,YAAY,CAAC,IAAI;GAAG,CAAE;IACxC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC;EAC1C;EACA,sEAAsE;EACtE,sEAAsE;EACtE,iDAAiD;EACjD,IAAI,EAAE,QAAQ,IAAI,KAAK,EAAE,QAAQ,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ;EAC/D,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;AAC/B,EAAC;AAED,uDAAuD;AACvD,OAAO,IAAI,aAAa,CAAC,IAAc,CAAC,CAAC,EAAE,YAAY,IAAI,CAAA;AAC3D,OAAO,IAAI,WAAW,CAAC;EACrB,IAAI,MAAM,IAAI,IAAI,IAAI;EACtB,OAAO,IAAI,QAAQ,IAAI,MAAM,QAAQ,IAAI,MAAM,EAAE,KAAK,GAAG;AAC3D,EAAC"}
package/url.ts ADDED
@@ -0,0 +1,85 @@
1
+ import { localPath, pagePath, webOrigin } from './hosting.js'
2
+ // Human-facing graph addresses. Transport stays local through TASKS_HOST;
3
+ // anything handed to a person uses the board's stable public door.
4
+
5
+ import { addressId, HUMAN, SHORT } from '@yaks/id'
6
+ import { EID } from './types.js'
7
+ import { queryAt, querySearch } from '@yaks/query'
8
+
9
+ let origin = webOrigin
10
+
11
+ // The # belongs to the prose handle, not the entity path.
12
+ export let entityPath = (id: string) =>
13
+ pagePath(`/${encodeURIComponent(SHORT.test(id) ? id.slice(1) : id)}`)
14
+ export let entityUrl = (id: string) => `${origin()}${entityPath(id)}`
15
+
16
+ export { addressId } from '@yaks/id'
17
+
18
+ // entityUrl's inverse: the id token a graph entity link names — undefined for
19
+ // any other address. Only id-shaped path segments count (prefix-num, short
20
+ // eid, uuid): every other path is a capability (/query, /telemetry), and handing
21
+ // one to the id resolver would let a slug or alias match something.
22
+ export let entityId = (raw: string): string | undefined => {
23
+ let u: URL
24
+ try {
25
+ u = new URL(raw.trim())
26
+ } catch {
27
+ return undefined
28
+ }
29
+ if (u.origin != origin()) return undefined
30
+ let id: string
31
+ try {
32
+ id = addressId(decodeURIComponent(localPath(u.pathname).slice(1))) ||
33
+ (SHORT.test(u.hash) ? u.hash : '')
34
+ } catch {
35
+ return undefined
36
+ }
37
+ return HUMAN.test(id) || SHORT.test(id) || EID.test(id) ? id : undefined
38
+ }
39
+
40
+ // ONE canonical spelling for a page address. A page filed from a browser
41
+ // and the same page asked about later must produce the same string, or a
42
+ // "what references this?" badge lies by omission — so this is the only
43
+ // place that decides, and it runs from the TYPE (props.ts `url`), which
44
+ // means every door normalizes: writes through parseProp, filters through
45
+ // query.ts atom(). Nothing else may spell it.
46
+ //
47
+ // What carries no identity goes: a fragment names a spot INSIDE a page,
48
+ // campaign params name the trip rather than the destination, credentials
49
+ // are never part of a page's name, and a trailing slash is a server's
50
+ // habit. What might: query params stay (and keep their order — sorting
51
+ // re-encodes, and no site sends them shuffled between visits).
52
+ //
53
+ // Anything that isn't an http(s) URL is left exactly as it came: the same
54
+ // type carries `repo.url`, where a git remote (git@host:owner/repo.git)
55
+ // is the value and mangling it would be the bug.
56
+ let JUNK =
57
+ /^(?:utm_|ga_|mc_|pk_|piwik_|hsa_|_hs|vero_)|^(?:gclid|dclid|gbraid|wbraid|fbclid|msclkid|yclid|twclid|mkt_tok|igshid|ref_src|ref_url|s_cid|si|scid|spm|cmpid)$/i
58
+
59
+ export let normalize = (raw: string) => {
60
+ let text = raw.trim()
61
+ let u: URL
62
+ try {
63
+ u = new URL(text)
64
+ } catch {
65
+ return text
66
+ }
67
+ if (u.protocol != 'http:' && u.protocol != 'https:') return text
68
+ u.hash = ''
69
+ u.username = u.password = ''
70
+ for (let k of [...u.searchParams.keys()]) {
71
+ if (JUNK.test(k)) u.searchParams.delete(k)
72
+ }
73
+ // The root keeps its slash (that IS the canonical root); every deeper
74
+ // path drops one, since /a and /a/ are one page everywhere it matters
75
+ // and a refetch follows the redirect either way.
76
+ if (u.pathname != '/') u.pathname = u.pathname.replace(/\/+$/, '')
77
+ return u.href.replace(/\?$/, '')
78
+ }
79
+
80
+ // A search is a view of the store, not a saved entity.
81
+ export let searchPath = (q: string) => `/${querySearch(q)}`
82
+ export let searchAt = (at: string): string | null => {
83
+ let url = new URL(at, 'http://x')
84
+ return url.pathname == '/' ? queryAt(url.search).query : null
85
+ }
package/verb.js ADDED
@@ -0,0 +1,82 @@
1
+ // The shell verb vocabulary: one declaration of positional arguments,
2
+ // options and dot-param policy, rendered by the manual and parsed by the CLI.
3
+ export let text = {
4
+ name: 'text',
5
+ test: /.+/
6
+ };
7
+ export let id = {
8
+ name: 'id',
9
+ test: /.+/,
10
+ id: true
11
+ };
12
+ export let path = {
13
+ name: 'dir',
14
+ test: /.+/
15
+ };
16
+ export let body = {
17
+ name: 'body',
18
+ test: /.+/,
19
+ read: true
20
+ };
21
+ export let file = {
22
+ name: 'file',
23
+ test: /.+/,
24
+ read: 'file'
25
+ };
26
+ export let num = {
27
+ name: 'n',
28
+ test: /^[1-9]\d*$/
29
+ };
30
+ // Bare durations retain the CLI's seconds convention.
31
+ export let duration = {
32
+ name: 'duration',
33
+ test: /^[1-9]\d*[smh]?$/
34
+ };
35
+ export let of = (name, values)=>({
36
+ name,
37
+ of: values,
38
+ // A remote catalog may be unknown, but an empty value is still missing.
39
+ test: /.+/
40
+ });
41
+ export let enumOf = (type, name = 'value')=>{
42
+ if (typeof type != 'object' || !('enum' in type)) return {
43
+ name
44
+ };
45
+ return of(name, ()=>[
46
+ ...type.enum,
47
+ ...Object.keys(type.aliases ?? {})
48
+ ]);
49
+ };
50
+ let slot = (arg)=>`${arg.name}${arg.rest ? '…' : ''}`;
51
+ let positional = (arg)=>arg.need === false ? `[${slot(arg)}]` : `<${slot(arg)}>`;
52
+ // The positional shape of an argument list, `<name>`/`[name…]` — the usage
53
+ // half of the vocabulary, shared by CLI verbs (usageOf) and the `:` commands
54
+ // (commands.ts). The ghost paints the concrete `eg` instead; this paints the
55
+ // metavar name, the reference shape.
56
+ export let slotsOf = (args = [])=>args.map(positional).join(' ');
57
+ let meta = (kind)=>{
58
+ let values = kind.of?.()?.join('|');
59
+ return values && values.length <= 24 ? values : kind.name.toUpperCase();
60
+ };
61
+ let option = (opt, verb)=>{
62
+ let value = opt.kind ? `=${opt.or ?? meta(opt.kind)}` : '';
63
+ if (opt.optionalValue) value = `[${value}]`;
64
+ let shape = `${opt.name}${value}`;
65
+ return verb.some?.length == 1 && verb.some[0] == opt.name ? shape : `[${shape}]`;
66
+ };
67
+ export let usageOf = (verb)=>verb.syntax ?? [
68
+ verb.name,
69
+ slotsOf(verb.args),
70
+ ...(verb.opts ?? []).map((opt)=>option(opt, verb))
71
+ ].filter(Boolean).join(' ');
72
+ export let wordsOf = (verb)=>{
73
+ let args = verb.args ?? [];
74
+ let min = args.filter((arg)=>arg.need !== false).length;
75
+ return args.some((arg)=>arg.rest) ? [
76
+ min
77
+ ] : [
78
+ min,
79
+ args.length
80
+ ];
81
+ };
82
+ //# sourceMappingURL=verb.js.map
package/verb.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verb.js","sources":["./verb.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,8EAA8E;AAwE9E,OAAO,IAAI,OAAa;EAAE,MAAM;EAAQ,MAAM;AAAK,EAAC;AACpD,OAAO,IAAI,KAAW;EAAE,MAAM;EAAM,MAAM;EAAM,IAAI;AAAK,EAAC;AAC1D,OAAO,IAAI,OAAa;EAAE,MAAM;EAAO,MAAM;AAAK,EAAC;AACnD,OAAO,IAAI,OAAa;EAAE,MAAM;EAAQ,MAAM;EAAM,MAAM;AAAK,EAAC;AAChE,OAAO,IAAI,OAAa;EAAE,MAAM;EAAQ,MAAM;EAAM,MAAM;AAAO,EAAC;AAClE,OAAO,IAAI,MAAY;EAAE,MAAM;EAAK,MAAM;AAAa,EAAC;AACxD,sDAAsD;AACtD,OAAO,IAAI,WAAiB;EAAE,MAAM;EAAY,MAAM;AAAmB,EAAC;AAE1E,OAAO,IAAI,KAAK,CACd,MACA,SACS,CAAC;IACV;IACA,IAAI;IACJ,wEAAwE;IACxE,MAAM;EACR,CAAC,EAAC;AAEF,OAAO,IAAI,SAAS,CAAC,MAAgB,OAAO,OAAO;EACjD,IAAI,OAAO,QAAQ,YAAY,CAAC,CAAC,UAAU,IAAI,GAAG,OAAO;IAAE;EAAK;EAChE,OAAO,GAAG,MAAM,IAAM;SACjB,KAAK,IAAI;SACT,OAAO,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC;KACjC;AACH,EAAC;AAED,IAAI,OAAO,CAAC,MAAa,GAAG,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,MAAM,IAAI;AAE5D,IAAI,aAAa,CAAC,MAChB,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;AAE1D,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,qCAAqC;AACrC,OAAO,IAAI,UAAU,CAAC,OAAc,EAAE,GAAK,KAAK,GAAG,CAAC,YAAY,IAAI,CAAC,KAAI;AAEzE,IAAI,OAAO,CAAC;EACV,IAAI,SAAS,KAAK,EAAE,MAAM,KAAK;EAC/B,OAAO,UAAU,OAAO,MAAM,IAAI,KAAK,SAAS,KAAK,IAAI,CAAC,WAAW;AACvE;AAEA,IAAI,SAAS,CAAC,KAAU;EACtB,IAAI,QAAQ,IAAI,IAAI,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,IAAI,GAAG,GAAG;EACxD,IAAI,IAAI,aAAa,EAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;EAC3C,IAAI,QAAQ,GAAG,IAAI,IAAI,GAAG,OAAO;EACjC,OAAO,KAAK,IAAI,EAAE,UAAU,KAAK,KAAK,IAAI,CAAC,EAAE,IAAI,IAAI,IAAI,GACrD,QACA,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAClB;AAEA,OAAO,IAAI,UAAU,CAAC,OACpB,KAAK,MAAM,IAAI;IACb,KAAK,IAAI;IACT,QAAQ,KAAK,IAAI;OACd,CAAC,KAAK,IAAI,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,MAAQ,OAAO,KAAK;GAC/C,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,KAAI;AAE7B,OAAO,IAAI,UAAU,CAAC;EACpB,IAAI,OAAO,KAAK,IAAI,IAAI,EAAE;EAC1B,IAAI,MAAM,KAAK,MAAM,CAAC,CAAC,MAAQ,IAAI,IAAI,KAAK,OAAO,MAAM;EACzD,OAAO,KAAK,IAAI,CAAC,CAAC,MAAQ,IAAI,IAAI,IAAI;IAAC;GAAI,GAAG;IAAC;IAAK,KAAK,MAAM;GAAC;AAClE,EAAC"}
package/verb.ts ADDED
@@ -0,0 +1,137 @@
1
+ // The shell verb vocabulary: one declaration of positional arguments,
2
+ // options and dot-param policy, rendered by the manual and parsed by the CLI.
3
+
4
+ import type { Param } from './client.ts'
5
+ import type { PropType } from './types.ts'
6
+
7
+ export type Kind = {
8
+ name: string
9
+ // The finite candidate set, when one is knowable HERE. `undefined` means
10
+ // "this process cannot say" — a catalog that lives in the graph, read by a
11
+ // CLI with no graph beside it — and every reader must then fall back to the
12
+ // metavar name and to accepting the value, never to rejecting everything.
13
+ of?: () => string[] | undefined
14
+ test?: RegExp
15
+ id?: boolean
16
+ read?: boolean | 'file'
17
+ }
18
+
19
+ export type Arg = {
20
+ name: string
21
+ kind: Kind
22
+ eg?: string
23
+ rest?: boolean
24
+ need?: boolean
25
+ }
26
+
27
+ export type Opt = {
28
+ name: string
29
+ kind?: Kind
30
+ or?: string
31
+ /** A bare flag or an attached =value; never consumes the next argument. */
32
+ optionalValue?: boolean
33
+ alias?: string
34
+ }
35
+
36
+ export type Dots = 'filters' | 'params' | string[] | undefined
37
+
38
+ // String values stay faithful to argv. `many` preserves token boundaries for
39
+ // a trailing slot whose grammar cares about them (filters and passthrough),
40
+ // while `args` gives ordinary handlers the named value they asked for.
41
+ export type Got = {
42
+ args: Record<string, string>
43
+ many: Record<string, string[]>
44
+ opts: Record<string, string>
45
+ flags: Set<string>
46
+ params: Param[]
47
+ words: string[]
48
+ body?: string
49
+ }
50
+
51
+ export type Run = (got: Got) => unknown
52
+
53
+ export type Decl = {
54
+ name: string
55
+ about: string
56
+ args?: Arg[]
57
+ opts?: Opt[]
58
+ dots?: Dots
59
+ body?: 'body' | 'text'
60
+ door: ('cli' | 'palette')[]
61
+ some?: string[]
62
+ examples?: string[]
63
+ detail?: string
64
+ retired?: Record<string, string>
65
+ root?: boolean
66
+ alias?: boolean
67
+ passthrough?: boolean
68
+ // Subject-first and colon syntax are routers rather than ordinary verbs.
69
+ syntax?: string
70
+ }
71
+
72
+ export type Verb = Decl & { run: Run }
73
+
74
+ export let text: Kind = { name: 'text', test: /.+/ }
75
+ export let id: Kind = { name: 'id', test: /.+/, id: true }
76
+ export let path: Kind = { name: 'dir', test: /.+/ }
77
+ export let body: Kind = { name: 'body', test: /.+/, read: true }
78
+ export let file: Kind = { name: 'file', test: /.+/, read: 'file' }
79
+ export let num: Kind = { name: 'n', test: /^[1-9]\d*$/ }
80
+ // Bare durations retain the CLI's seconds convention.
81
+ export let duration: Kind = { name: 'duration', test: /^[1-9]\d*[smh]?$/ }
82
+
83
+ export let of = (
84
+ name: string,
85
+ values: () => string[] | undefined,
86
+ ): Kind => ({
87
+ name,
88
+ of: values,
89
+ // A remote catalog may be unknown, but an empty value is still missing.
90
+ test: /.+/,
91
+ })
92
+
93
+ export let enumOf = (type: PropType, name = 'value'): Kind => {
94
+ if (typeof type != 'object' || !('enum' in type)) return { name }
95
+ return of(name, () => [
96
+ ...type.enum,
97
+ ...Object.keys(type.aliases ?? {}),
98
+ ])
99
+ }
100
+
101
+ let slot = (arg: Arg) => `${arg.name}${arg.rest ? '…' : ''}`
102
+
103
+ let positional = (arg: Arg) =>
104
+ arg.need === false ? `[${slot(arg)}]` : `<${slot(arg)}>`
105
+
106
+ // The positional shape of an argument list, `<name>`/`[name…]` — the usage
107
+ // half of the vocabulary, shared by CLI verbs (usageOf) and the `:` commands
108
+ // (commands.ts). The ghost paints the concrete `eg` instead; this paints the
109
+ // metavar name, the reference shape.
110
+ export let slotsOf = (args: Arg[] = []) => args.map(positional).join(' ')
111
+
112
+ let meta = (kind: Kind) => {
113
+ let values = kind.of?.()?.join('|')
114
+ return values && values.length <= 24 ? values : kind.name.toUpperCase()
115
+ }
116
+
117
+ let option = (opt: Opt, verb: Decl) => {
118
+ let value = opt.kind ? `=${opt.or ?? meta(opt.kind)}` : ''
119
+ if (opt.optionalValue) value = `[${value}]`
120
+ let shape = `${opt.name}${value}`
121
+ return verb.some?.length == 1 && verb.some[0] == opt.name
122
+ ? shape
123
+ : `[${shape}]`
124
+ }
125
+
126
+ export let usageOf = (verb: Decl) =>
127
+ verb.syntax ?? [
128
+ verb.name,
129
+ slotsOf(verb.args),
130
+ ...(verb.opts ?? []).map((opt) => option(opt, verb)),
131
+ ].filter(Boolean).join(' ')
132
+
133
+ export let wordsOf = (verb: Decl): [number, number?] => {
134
+ let args = verb.args ?? []
135
+ let min = args.filter((arg) => arg.need !== false).length
136
+ return args.some((arg) => arg.rest) ? [min] : [min, args.length]
137
+ }
package/warmth.js ADDED
@@ -0,0 +1,41 @@
1
+ // The warmth of an entity: the recall-decay rank behind `.order=hot`, and the
2
+ // retirement damper that sinks a dead venture beneath live work.
3
+ // The warmth of an entity, on (0,1] — the rank behind '.order=hot'.
4
+ // Recall aggregates (count, first_at, last_at) are the whole model:
5
+ // every recall earns a day of STABILITY, and spacing multiplies it —
6
+ // the same count spread over months buys more durability than an
7
+ // afternoon of cramming (mean interval, in weeks, is the multiplier).
8
+ // The score decays exponentially past last_at against that stability,
9
+ // so top-of-mind-for-hours / recallable-for-days / rings-a-bell-for-
10
+ // months fall out of one curve. No recall row yet: the entity's own last
11
+ // touch (updated.at, else created.at) counts as a single touch — new
12
+ // things start hot and fade
13
+ // unless used. The clock rides in as a parameter (tests fix it), and no
14
+ // stored score exists anywhere to sweep.
15
+ let DAY = 86_400_000;
16
+ export let hot = (c, now)=>{
17
+ let r = c.recall;
18
+ let count = Number(r?.count ?? 0);
19
+ let last = Date.parse(String(r?.last_at ?? ''));
20
+ if (!count || Number.isNaN(last)) {
21
+ count = 1;
22
+ last = Date.parse(String(c.updated?.at ?? c.created?.at ?? ''));
23
+ if (Number.isNaN(last)) return 0;
24
+ }
25
+ let first = Date.parse(String(r?.first_at ?? ''));
26
+ if (Number.isNaN(first)) first = last;
27
+ let mean = count > 1 ? Math.max(0, last - first) / (count - 1) : 0;
28
+ let stability = DAY * count * (1 + mean / (7 * DAY));
29
+ return Math.exp(-Math.max(0, now - last) / stability);
30
+ };
31
+ // Retirement is a damper, not an eraser: a retired project — and every
32
+ // task filed under it — keeps its whole recall curve but sinks beneath
33
+ // live work wherever warmth ranks (.order=hot, the digest). The lookup
34
+ // is the same comps fetcher matchQuery's path preds ride, so every
35
+ // caller already holds one.
36
+ export let SUNK = 0.1;
37
+ // The far arm follows the one project reference through the caller's reader.
38
+ // No schema is needed to rank data: apps without tasks have no filed project.
39
+ export let sunk = (c, ent)=>!!c.project && !!c.archived || !!(c.filed?.project && ent?.(String(c.filed.project))?.archived?.at);
40
+ export let warm = (c, now, ent)=>hot(c, now) * (sunk(c, ent) ? SUNK : 1);
41
+ //# sourceMappingURL=warmth.js.map
package/warmth.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warmth.js","sources":["./warmth.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,iEAAiE;AAGjE,oEAAoE;AACpE,oEAAoE;AACpE,qEAAqE;AACrE,iEAAiE;AACjE,sEAAsE;AACtE,sEAAsE;AACtE,qEAAqE;AACrE,yEAAyE;AACzE,qEAAqE;AACrE,4BAA4B;AAC5B,wEAAwE;AACxE,yCAAyC;AACzC,IAAI,MAAM;AACV,OAAO,IAAI,MAAM,CAAC,GAAU;EAC1B,IAAI,IAAI,EAAE,MAAM;EAChB,IAAI,QAAQ,OAAO,GAAG,SAAS;EAC/B,IAAI,OAAO,KAAK,KAAK,CAAC,OAAO,GAAG,WAAW;EAC3C,IAAI,CAAC,SAAS,OAAO,KAAK,CAAC,OAAO;IAChC,QAAQ;IACR,OAAO,KAAK,KAAK,CACf,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAE3C,IAAI,OAAO,KAAK,CAAC,OAAO,OAAO;EACjC;EACA,IAAI,QAAQ,KAAK,KAAK,CAAC,OAAO,GAAG,YAAY;EAC7C,IAAI,OAAO,KAAK,CAAC,QAAQ,QAAQ;EACjC,IAAI,OAAO,QAAQ,IAAI,KAAK,GAAG,CAAC,GAAG,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI;EACjE,IAAI,YAAY,MAAM,QAAQ,CAAC,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC;EACnD,OAAO,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM,QAAQ;AAC7C,EAAC;AAED,uEAAuE;AACvE,uEAAuE;AACvE,uEAAuE;AACvE,mEAAmE;AACnE,4BAA4B;AAC5B,OAAO,IAAI,OAAO,IAAG;AACrB,6EAA6E;AAC7E,8EAA8E;AAC9E,OAAO,IAAI,OAAO,CAChB,GACA,MAEA,AAAC,CAAC,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,EAAE,QAAQ,IAC5B,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,MAAM,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,UAAU,EAAE,EAAC;AACtE,OAAO,IAAI,OAAO,CAChB,GACA,KACA,MACG,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,OAAO,CAAC,EAAC"}
package/warmth.ts ADDED
@@ -0,0 +1,54 @@
1
+ // The warmth of an entity: the recall-decay rank behind `.order=hot`, and the
2
+ // retirement damper that sinks a dead venture beneath live work.
3
+ import type { Comps } from './query.ts'
4
+
5
+ // The warmth of an entity, on (0,1] — the rank behind '.order=hot'.
6
+ // Recall aggregates (count, first_at, last_at) are the whole model:
7
+ // every recall earns a day of STABILITY, and spacing multiplies it —
8
+ // the same count spread over months buys more durability than an
9
+ // afternoon of cramming (mean interval, in weeks, is the multiplier).
10
+ // The score decays exponentially past last_at against that stability,
11
+ // so top-of-mind-for-hours / recallable-for-days / rings-a-bell-for-
12
+ // months fall out of one curve. No recall row yet: the entity's own last
13
+ // touch (updated.at, else created.at) counts as a single touch — new
14
+ // things start hot and fade
15
+ // unless used. The clock rides in as a parameter (tests fix it), and no
16
+ // stored score exists anywhere to sweep.
17
+ let DAY = 86_400_000
18
+ export let hot = (c: Comps, now: number): number => {
19
+ let r = c.recall
20
+ let count = Number(r?.count ?? 0)
21
+ let last = Date.parse(String(r?.last_at ?? ''))
22
+ if (!count || Number.isNaN(last)) {
23
+ count = 1
24
+ last = Date.parse(
25
+ String(c.updated?.at ?? c.created?.at ?? ''),
26
+ )
27
+ if (Number.isNaN(last)) return 0
28
+ }
29
+ let first = Date.parse(String(r?.first_at ?? ''))
30
+ if (Number.isNaN(first)) first = last
31
+ let mean = count > 1 ? Math.max(0, last - first) / (count - 1) : 0
32
+ let stability = DAY * count * (1 + mean / (7 * DAY))
33
+ return Math.exp(-Math.max(0, now - last) / stability)
34
+ }
35
+
36
+ // Retirement is a damper, not an eraser: a retired project — and every
37
+ // task filed under it — keeps its whole recall curve but sinks beneath
38
+ // live work wherever warmth ranks (.order=hot, the digest). The lookup
39
+ // is the same comps fetcher matchQuery's path preds ride, so every
40
+ // caller already holds one.
41
+ export let SUNK = 0.1
42
+ // The far arm follows the one project reference through the caller's reader.
43
+ // No schema is needed to rank data: apps without tasks have no filed project.
44
+ export let sunk = (
45
+ c: Comps,
46
+ ent?: (eid: string) => Comps | undefined,
47
+ ): boolean =>
48
+ (!!c.project && !!c.archived) ||
49
+ !!(c.filed?.project && ent?.(String(c.filed.project))?.archived?.at)
50
+ export let warm = (
51
+ c: Comps,
52
+ now: number,
53
+ ent?: (eid: string) => Comps | undefined,
54
+ ) => hot(c, now) * (sunk(c, ent) ? SUNK : 1)
package/wire.js ADDED
@@ -0,0 +1,86 @@
1
+ // The wire to the host (@yaks/api): its bundles, and the Change rows the views
2
+ // speak, each read as the other; and the query line a subscription sends.
3
+ /** Changes as /apply bundles. Plain patches coalesce; removing then adding
4
+ * a component stays ordered, because it replaces the held component. */ export let bundlesOf = (changes)=>{
5
+ let rows = new Map();
6
+ for (let { eid, name, comp, was } of changes){
7
+ let parts = rows.get(eid);
8
+ if (!parts) rows.set(eid, parts = [
9
+ {
10
+ entity: {
11
+ eid
12
+ }
13
+ }
14
+ ]);
15
+ let row = parts.at(-1);
16
+ if (name == 'entity') {
17
+ if (was) row.$was = {
18
+ ...row.$was,
19
+ entity: was
20
+ };
21
+ if (comp === null) {
22
+ rows.set(eid, [
23
+ {
24
+ entity: {
25
+ eid
26
+ },
27
+ tombstone: {},
28
+ ...row.$was ? {
29
+ $was: row.$was
30
+ } : {}
31
+ }
32
+ ]);
33
+ }
34
+ continue;
35
+ }
36
+ if (row.tombstone) continue;
37
+ if (row[name] === null && comp !== null) {
38
+ parts.push(row = {
39
+ entity: {
40
+ eid
41
+ }
42
+ });
43
+ }
44
+ if (was) row.$was = {
45
+ ...row.$was,
46
+ [name]: {
47
+ ...row.$was?.[name],
48
+ ...was
49
+ }
50
+ };
51
+ let { eid: _, ...cols } = comp ?? {};
52
+ row[name] = comp === null ? null : {
53
+ ...row[name],
54
+ ...cols
55
+ };
56
+ }
57
+ return [
58
+ ...rows.values()
59
+ ].flat();
60
+ };
61
+ /** Bundles as changes: the spine as the `entity` row, each component as its
62
+ * own, a removed one as null, and a tombstone as the entity's death. */ export let changesOf = (rows)=>rows.flatMap((b)=>{
63
+ let eid = b.entity.eid;
64
+ if (b.tombstone) return [
65
+ {
66
+ eid,
67
+ name: 'entity',
68
+ comp: null
69
+ }
70
+ ];
71
+ let { eid: _, ...spine } = b.entity;
72
+ return [
73
+ {
74
+ eid,
75
+ name: 'entity',
76
+ comp: spine
77
+ },
78
+ ...Object.entries(b).filter(([name])=>name != 'entity' && !name.startsWith('$')).map(([name, comp])=>({
79
+ eid,
80
+ name,
81
+ comp: comp
82
+ }))
83
+ ];
84
+ });
85
+ /** A view's query line as the host reads it: an id list is `.entity.eid=`. */ export let yakLine = (q)=>q.split('&').map((term)=>term.startsWith('id=') ? `.entity.eid=${term.slice(3)}` : term).join('&');
86
+ //# sourceMappingURL=wire.js.map
package/wire.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.js","sources":["./wire.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,0EAA0E;AAI1E;sEACsE,GACtE,OAAO,IAAI,YAAY,CAAC;EACtB,IAAI,OAAO,IAAI;EACf,KAAK,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,QAAS;IAC5C,IAAI,QAAQ,KAAK,GAAG,CAAC;IACrB,IAAI,CAAC,OAAO,KAAK,GAAG,CAAC,KAAK,QAAQ;MAAC;QAAE,QAAQ;UAAE;QAAI;MAAE;KAAE;IACvD,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC;IACpB,IAAI,QAAQ,UAAU;MACpB,IAAI,KAAK,IAAI,IAAI,GAAG;QAAE,GAAG,IAAI,IAAI;QAAE,QAAQ;MAAI;MAC/C,IAAI,SAAS,MAAM;QACjB,KAAK,GAAG,CAAC,KAAK;UAAC;YACb,QAAQ;cAAE;YAAI;YACd,WAAW,CAAC;YACZ,GAAG,IAAI,IAAI,GAAG;cAAE,MAAM,IAAI,IAAI;YAAC,IAAI,CAAC,CAAC;UACvC;SAAE;MACJ;MACA;IACF;IACA,IAAI,IAAI,SAAS,EAAE;IACnB,IAAI,GAAG,CAAC,KAAK,KAAK,QAAQ,SAAS,MAAM;MACvC,MAAM,IAAI,CAAC,MAAM;QAAE,QAAQ;UAAE;QAAI;MAAE;IACrC;IACA,IAAI,KAAK,IAAI,IAAI,GAAG;MAAE,GAAG,IAAI,IAAI;MAAE,CAAC,KAAK,EAAE;QAAE,GAAG,IAAI,IAAI,EAAE,CAAC,KAAK;QAAE,GAAG,GAAG;MAAC;IAAE;IAC3E,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,MAAM,GAAG,QAAQ,CAAC;IACnC,GAAG,CAAC,KAAK,GAAG,SAAS,OACjB,OACA;MAAE,GAAI,GAAG,CAAC,KAAK;MAAqC,GAAG,IAAI;IAAC;EAClE;EACA,OAAO;OAAI,KAAK,MAAM;GAAG,CAAC,IAAI;AAChC,EAAC;AAED;sEACsE,GACtE,OAAO,IAAI,YAAY,CAAC,OACtB,KAAK,OAAO,CAAC,CAAC;IACZ,IAAI,MAAM,EAAE,MAAM,CAAC,GAAG;IACtB,IAAI,EAAE,SAAS,EAAE,OAAO;MAAC;QAAE;QAAK,MAAM;QAAU,MAAM;MAAK;KAAE;IAC7D,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,OAAO,GAAG,EAAE,MAAM;IACnC,OAAO;MACL;QAAE;QAAK,MAAM;QAAU,MAAM;MAAM;SAChC,OAAO,OAAO,CAAC,GACf,MAAM,CAAC,CAAC,CAAC,KAAK,GAAK,QAAQ,YAAY,CAAC,KAAK,UAAU,CAAC,MACxD,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,GAAK,CAAC;UACtB;UACA;UACA,MAAM;QACR,CAAC;KACJ;EACH,GAAE;AAEJ,4EAA4E,GAC5E,OAAO,IAAI,UAAU,CAAC,IACpB,EAAE,KAAK,CAAC,KACL,GAAG,CAAC,CAAC,OACJ,KAAK,UAAU,CAAC,SAAS,CAAC,YAAY,EAAE,KAAK,KAAK,CAAC,IAAI,GAAG,MAE3D,IAAI,CAAC,KAAI"}
package/wire.ts ADDED
@@ -0,0 +1,63 @@
1
+ // The wire to the host (@yaks/api): its bundles, and the Change rows the views
2
+ // speak, each read as the other; and the query line a subscription sends.
3
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
4
+ import type { Change } from './types.ts'
5
+
6
+ /** Changes as /apply bundles. Plain patches coalesce; removing then adding
7
+ * a component stays ordered, because it replaces the held component. */
8
+ export let bundlesOf = (changes: Change[]): Bundle[] => {
9
+ let rows = new Map<string, Bundle[]>()
10
+ for (let { eid, name, comp, was } of changes) {
11
+ let parts = rows.get(eid)
12
+ if (!parts) rows.set(eid, parts = [{ entity: { eid } }])
13
+ let row = parts.at(-1)!
14
+ if (name == 'entity') {
15
+ if (was) row.$was = { ...row.$was, entity: was }
16
+ if (comp === null) {
17
+ rows.set(eid, [{
18
+ entity: { eid },
19
+ tombstone: {},
20
+ ...row.$was ? { $was: row.$was } : {},
21
+ }])
22
+ }
23
+ continue
24
+ }
25
+ if (row.tombstone) continue
26
+ if (row[name] === null && comp !== null) {
27
+ parts.push(row = { entity: { eid } })
28
+ }
29
+ if (was) row.$was = { ...row.$was, [name]: { ...row.$was?.[name], ...was } }
30
+ let { eid: _, ...cols } = comp ?? {}
31
+ row[name] = comp === null
32
+ ? null
33
+ : { ...(row[name] as Record<string, unknown> | null), ...cols }
34
+ }
35
+ return [...rows.values()].flat()
36
+ }
37
+
38
+ /** Bundles as changes: the spine as the `entity` row, each component as its
39
+ * own, a removed one as null, and a tombstone as the entity's death. */
40
+ export let changesOf = (rows: Bundle[]): Change[] =>
41
+ rows.flatMap((b): Change[] => {
42
+ let eid = b.entity.eid
43
+ if (b.tombstone) return [{ eid, name: 'entity', comp: null }]
44
+ let { eid: _, ...spine } = b.entity
45
+ return [
46
+ { eid, name: 'entity', comp: spine },
47
+ ...Object.entries(b)
48
+ .filter(([name]) => name != 'entity' && !name.startsWith('$'))
49
+ .map(([name, comp]) => ({
50
+ eid,
51
+ name,
52
+ comp: comp as Record<string, unknown> | null,
53
+ })),
54
+ ]
55
+ })
56
+
57
+ /** A view's query line as the host reads it: an id list is `.entity.eid=`. */
58
+ export let yakLine = (q: string): string =>
59
+ q.split('&')
60
+ .map((term) =>
61
+ term.startsWith('id=') ? `.entity.eid=${term.slice(3)}` : term
62
+ )
63
+ .join('&')