gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchticket-10a557ac53jukebox#10 review fixes: README file map names lib/background.hl, on Error(Hybrid e) per L10mreticket-10/plugins/web/WebFramework.hl

301.0 KB

  1. // The framework's server half — the SERVER REALM's entrypoint, and the EDGE
  2. // MODULE for the carriers the manifest declares.
  3. // Its jobs: answer a URL with the HTML of a constructed component (SSR), ship
  4. // the browser the client, the View tree and the state to continue from, carry
  5. // the boundary in both directions (a websocket on the same port, a POST for a
  6. // peer that has none), and run the server faces an inbound emit names.
  7. import { NativeWebSocketServer, Response, randomToken } from 'hl:http1'
  8. import HlwView from './view.hl'
  9. import HlwViewServer from './viewserver.hl'
  10. import HlwRouter from './router.hl'
  11. // Reachable for explicit browser projection and native baking; never constructed on the server.
  12. import HlwOffline from './offline.hl'
  13. import HlwUploads from './uploads.hl'
  14. import HlwSessions from './sessions.hl'
  15. import HlwSession from './session.hl'
  16. // the Style walk — named Css here because `Style` is a well-known MEMBER name
  17. import HlwCss from './css.hl'
  18. import HlwCompile from './compile.hl'
  19. import { readFile, exists, watch } from 'hl:fs'
  20. import { file, env, setEnv, args, writeStderr } from 'hl:proc'
  21. import { now } from 'hl:time'
  22. import { sha256, base64urlDecode, base64urlEncode, p256PublicKey } from 'hl:crypto'
  23. // the statics of push.hl that server.hl (the app's import of sendPush) and the app use are named here: a package
  24. // file's statics are live only for the names the framework's own import selects
  25. import { configure as configurePush, sendPush as pushSender } from './push.hl'
  26. import { newline, tab } from './view.hl'
  27. // #360: document language default; null leaves <html lang> absent.
  28. String lang = null
  29. Hybrid routes = [] // bound by `new WebFrameworkServer(routes = …)`
  30. // THE PROJECT'S STYLES FILE, declared by the app as a property of the framework:
  31. // `new WebFrameworkServer(…, styles = './styles.hl')`. A file of statics and one
  32. // `Style { }` root member (COMPONENTS §4) — the design tokens and the global
  33. // rules, under every component's own Style in the one stylesheet. null: none.
  34. styles = null // the app's styles file: the class it imported, or a path
  35. // WHO AN OUTWARD EVENT IS FOR (creator, 2026-09-12): per event, a function the app
  36. // declares — `audience = { postCreated = (p, session) => … }` — called for every
  37. // connection that has a listener for the event mounted, with the event's
  38. // arguments and that connection's session; a true answer sends the frame. An
  39. // event with no entry reaches the emitting connection only. Only the app knows
  40. // who is entitled; the face stays pure; the framework applies the answer.
  41. Hybrid audience = {}
  42. coalesce = {}
  43. // THE SESSION STORE (the archive's manifest members, mission 252/255): nothing said →
  44. // `<project>/.sessions`; a path → that path; `false` → memory only. The three clocks
  45. // are seconds; null takes the layer's defaults (14 days valid, 15 min resident, sweep
  46. // every 5 min).
  47. // THE DEV WATCHER (the archive's `watch`): every save under the project arrives as an
  48. // event; a save that changes the analysis re-reads the graph, drops every cache and tells
  49. // every open tab to reload. Off by default — a deploy never re-analyses itself.
  50. Boolean minify = false // production: one-line HTML, compact JavaScript modules
  51. Boolean watchMode = true
  52. lastChange = 0 // epoch ms of the last save acted on (the debounce)
  53. String | Boolean sessionDir = null
  54. Number sessionMaxAge = null
  55. Number sessionIdle = null
  56. Number sweepInterval = null
  57. // THE SESSION COOKIE'S NAME (ticket #10). Cookies ignore the port, so two apps on one
  58. // host that both answered `hlsid` overwrote each other's sessions; an app names its own.
  59. // null: `hlsid`.
  60. String sessionCookie = null
  61. // THE COOKIE'S `Secure` FLAG (ticket #27): true when the app is reached over https —
  62. // behind a TLS proxy the server itself speaks plain http and cannot tell, so the app
  63. // says so. The browser then never sends the session over plain http. null (W124): `Secure` when THE REQUEST
  64. // came over https (X-Forwarded-Proto: https from the proxy); true: always; false: never.
  65. Boolean sessionSecure = null
  66. // THE MOST ANONYMOUS SESSIONS KEPT (W124): a visitor gets a session (and a file) only when something is stored
  67. // in it; the ones nobody logged in to are capped, the oldest evicted first.
  68. Number sessionAnonMax = 10000
  69. Number sessionAnonKeep = 86400
  70. // THE COOKIE'S `Domain` (ticket #44): 'example.org' shares one session with every
  71. // <sub>.example.org, which a host-only cookie cannot. null: host-only, no attribute.
  72. String sessionDomain = null
  73. \* THE PORT: the app's own `--port=N` argument (hybriel hands every argument
  74. after the entry to the program, creator ruling 2026-09-27), else the
  75. constructor's, else HL_PORT (hybriel resolves PORT and `.env` into it),
  76. else 8080. *\
  77. Number port = null
  78. // THE OFFLINE ALLOW-LIST (COMPONENTS §10, D38): the pages this app promises with the
  79. // network down, named as the route table names them — the imported class or a path
  80. // string. null: no service worker, no cache, no IndexedDB, nothing on the device.
  81. offline = null
  82. // THE OFFLINE FALLBACK PAGE (ticket #120): a data-free page — a route component with no
  83. // parameters, the class or its path string — the service worker keeps once, fetched with
  84. // NO credentials, and shows for any page it has nothing for while the network is down.
  85. // null: the "Unavailable offline" page, as before. Needs `offline`.
  86. offlineFallback = null
  87. // THE APP'S OWN FILES KEPT OFFLINE (ticket #170): a list of urls — each a path the app's
  88. // `file` routes answer (`/md-editor.js`, or one file under a directory route) — the worker
  89. // precaches at install and serves cache-first. Only the urls listed: a directory route is
  90. // never kept as a tree. Needs `offline`. null: none beyond the files a kept page's View
  91. // loads through a literal `<script src>` or `<link href>`.
  92. offlineFiles = null
  93. // WEB PUSH (ticket #173): the app's VAPID PUBLIC key, base64url (the 65-byte uncompressed P-256
  94. // point). Setting it serves the service worker — which then shows a pushed notification and
  95. // focuses the app on a click — and lets a component call `subscribePush()` (hl:web). null: no push.
  96. pushKey = null
  97. // …and the SERVER'S half: the VAPID PRIVATE key (base64url, the 32-byte P-256 scalar of `pushKey`) and the
  98. // contact `pushSubject` ('mailto:…' or 'https://…', the push service may write to it). Both set: the app can
  99. // `import { sendPush } from 'hl:web/push'` and send. A key that is not the private half of `pushKey` is refused at boot.
  100. pushPrivateKey = null
  101. pushSubject = null
  102. // THE DEAD-SOCKET CLOCK (COMPONENTS §10), in seconds. The browser pings every `pingEvery`,
  103. // and a socket whose pong has not come back within `pongWithin` is taken for dead: it is
  104. // closed, and the reconnect and the queue's replay start. A network that drops without a
  105. // close frame is noticed within pingEvery + pongWithin (35 s by default). null: 25 and 10.
  106. Number pingEvery = null
  107. Number pongWithin = null
  108. // AN UPLOAD THAT GOES SILENT — no progress, no answer — is read as dropped after this
  109. // many seconds (COMPONENTS §10, an emit's file). null: 15.
  110. Number uploadStall = null
  111. // THE LARGEST FILE AN EMIT MAY CARRY (ticket #94), in bytes: a bigger one is refused
  112. // at its first request, and the emit ends with that error. 1 GiB.
  113. Number uploadMax = 67108864
  114. // THE UPLOAD BUDGETS (W115): the bytes announced by the unfinished uploads of ONE session,
  115. // and of ALL sessions together (a part is held in memory until its emit claims it). 256 MiB, 1 GiB.
  116. Number uploadSessionMax = 268435456
  117. Number uploadHeldMax = 1073741824
  118. // THE LARGEST BODY `POST /__hl/emit` takes, in bytes (W115): a bigger one is answered 413. 16 MiB.
  119. // (hl:http1 reads a request's body whole before hl:web sees it, so this refuses the answer, not the read.)
  120. Number emitMax = 16777216
  121. // ONE PART OF AN UPLOAD, at most (the client half sends 1 MiB): 8 MiB.
  122. Number uploadPartMax = 8388608
  123. // THE HEADERS EVERY ANSWER CARRIES (W115, COMPONENTS §7): the safe defaults are nosniff,
  124. // Referrer-Policy strict-origin-when-cross-origin, X-Frame-Options SAMEORIGIN and a CSP of
  125. // `frame-ancestors 'self'`. `pageHeaders = { 'Content-Security-Policy' = "…" }` adds to or replaces
  126. // them on every answer (a header set to null is removed); a route's own header wins over both.
  127. Hybrid pageHeaders = {}
  128. // ORIGINS BESIDES THE REQUEST'S OWN HOST that may call `/__hl/emit`, `/__hl/upload` and open the
  129. // socket (W115): `['https://app.example.org']`. A request whose Origin is another is refused 403.
  130. trustedOrigins = []
  131. // THE PUSH LOG (ticket #143). A push is addressed to the TAB, not to its socket: each tab
  132. // keeps the last `pushKept` pushes it was sent (and no more than `pushKeptBytes` of them),
  133. // numbered, and a tab whose socket comes back gets what it missed again, in order. A tab
  134. // whose socket left is kept `tabKept` seconds, and pushed to and logged meanwhile; a gap
  135. // longer than the log (or a server restart) resyncs the tab's server-derived state instead.
  136. // THE BYTES BOUND IS THE ONE THAT GOVERNS (ticket #160): a push is small (a streamed delta is some
  137. // 150 bytes), and a count of 500 ran out within a 15-second gap on a server streaming several
  138. // chats to the tab while 1 MiB was far off. The count is the guard for the degenerate case only.
  139. Number pushKept = 10000
  140. Number pushKeptBytes = 1048576
  141. Number tabKept = 600
  142. // THE PUSHES SINCE A RENDER (W181): a page's tab does not exist until its first hello, so every fan-out push is also
  143. // kept here, numbered, for `recentKept` seconds (and within `pushKeptBytes`). The seed names the number the render stood at
  144. // (`pushed`), and the first hello is replayed what was sent since, exactly like a reconnect. Older than that, it is not.
  145. Number recentKept = 30
  146. recent = []
  147. recentBytes = 0
  148. pushCount = 0
  149. String host = null // the interface to bind; null → HL_HOST/HOST, the manifest's `host`, 0.0.0.0
  150. // THE ONE RUNTIME URL, and the reason it is a member and not a literal in two
  151. // places: a module's `import … from "./hl-runtime.js"` resolves against the
  152. // MODULE's own url, so a server answering modules at two directory depths hands
  153. // the browser two runtime urls — two ES-module instances, two `globalEvents`
  154. // buses, two `__hlRealm` variables, and a crossing emit announced on a bus the
  155. // edge module never taps. Every module this server compiles is handed this one
  156. // specifier (hlJs's third argument).
  157. // THE DIRECTORY THE FRAMEWORK ANSWERS FROM, and the reason it is its own member:
  158. // a package's browser half is served BESIDE THE RUNTIME, and the compiler derives
  159. // that url from the runtime's own (`js_module.zig browserHalfUrl`:
  160. // `<dirname(runtime)>/<pkg>/client.js`). Two sides deriving one url from one
  161. // directory is what keeps the module's `import` and this server's route table
  162. // from drifting apart.
  163. static halfDir = '/__hl'
  164. // Browser keys are module paths without the leading slash. Outside graph keys are
  165. // absolute disk paths: only their opaque module key crosses the boundary. This ONE
  166. // mapping also supplies imports, live routes and the native bake.
  167. static graphModuleKey = (moduleKey) => {
  168. if (moduleKey.startsWith('/')) { return halfDir.slice(1) + '/modules/' + sha256(moduleKey) + '.hl' }
  169. return moduleKey
  170. }
  171. static graphModulePath = (moduleKey) => { return '/' + graphModuleKey(moduleKey) }
  172. // The inverse is a lookup in this generation's graph, never a path decoded from a
  173. // browser's input. Internal absolute keys are not accepted on the wire.
  174. browserKeys = null
  175. graphKeyOf(key) {
  176. if (key == null || key.startsWith('/')) { return null }
  177. if (graph.files[key] != null) { return key }
  178. if (browserKeys == null) {
  179. out = {}
  180. for (k of graph.files.keys()) { if (k.startsWith('/')) { out[graphModuleKey(k)] = k } }
  181. browserKeys = out
  182. }
  183. return browserKeys[key]
  184. }
  185. graphKeysOf(keys) {
  186. if (keys == null) { return null }
  187. out = []
  188. for (key of keys) {
  189. internal = graphKeyOf(key)
  190. if (internal != null) { out.push(internal) }
  191. }
  192. return out
  193. }
  194. graphParamsOf(params) {
  195. if (params == null) { return null }
  196. out = {}
  197. for (key of params.keys()) {
  198. internal = graphKeyOf(key)
  199. if (internal != null) { out[internal] = params[key] }
  200. }
  201. return out
  202. }
  203. static runtimeUrl = halfDir + '/hl-runtime.js'
  204. clientUrl = halfUrl('web')
  205. styleUrl = halfDir + '/app.css'
  206. // THE BUILD'S VERSION IS IN EVERY URL THE BROWSER CACHES (after ticket #82): the
  207. // runtime, the package halves, the component modules and the stylesheet were served
  208. // at fixed urls, and a browser or Cloudflare kept the old client against a new
  209. // deploy's pages. Each is now asked for as `<url>?v=<hash>`, the hash of everything
  210. // this build serves, and answered with a year's `immutable` caching — a new build is
  211. // a new url. The modules are COMPILED against this mark and it is replaced with the
  212. // hash when they are served: the hash is of the compiled texts, so it cannot be in
  213. // them while they are compiled, and a binary's baked modules carry the mark too (the
  214. // one form both paths share). The route patterns stay the bare paths.
  215. static buildMark = '?v=__hlbuild__'
  216. static runtimeSpec = runtimeUrl + buildMark
  217. // the web app manifest and the service worker's entry script (COMPONENTS §10)
  218. static manifestUrl = halfDir + '/manifest.webmanifest'
  219. static workerUrl = halfDir + '/sw.js'
  220. // THE FRAMEWORK'S OWN DEFAULT LOOK for the two waiting marks (#434, #435), first in the sheet and all inside `:where()` (specificity 0),
  221. // so any rule of the app's Style wins whatever its order. Nothing shows for the first 300 ms (a transition delay, no timer).
  222. // `<html data-hl-busy>` a navigation or an emit answer is open: a thin indeterminate bar (html::after) after 300 ms
  223. // `aria-busy="true"` + `data-hl-waiting` on a button whose handler's emit has no answer yet: dimmed, cursor progress after 300 ms
  224. // An app restyles `html[data-hl-busy]::after` / `button[aria-busy="true"]`, hides the bar with `html::after { display = 'none' }`,
  225. // and keeps one button quiet with the attribute `data-hl-quiet`.
  226. static busyCss = ':where(html)::after{content:"";position:fixed;z-index:2147483647;top:0;left:0;width:100%;height:3px;pointer-events:none;opacity:0;background:currentColor;transform-origin:0 50%;transform:scaleX(0)}' +
  227. ':where(html[data-hl-busy])::after{opacity:.7;transition:opacity .1s 300ms;animation:hl-busy 1.4s ease-in-out infinite}' +
  228. '@keyframes hl-busy{0%{transform:translateX(-100%) scaleX(.3)}50%{transform:translateX(30%) scaleX(.6)}100%{transform:translateX(100%) scaleX(.3)}}' +
  229. ':where(button[aria-busy="true"],input[aria-busy="true"],[role=button][aria-busy="true"]){opacity:.6;cursor:progress;transition:opacity .15s 300ms,cursor 0s 300ms;transition-behavior:allow-discrete}' +
  230. '@media (prefers-reduced-motion:reduce){:where(html[data-hl-busy])::after{animation:none;transform:none;opacity:.35}}'
  231. // TEST-ONLY CONSTRUCTION COUNTER (mission 343, W133). Only with HL_WEB_COUNT=1: `construct` counts every server
  232. // construction by component file, and GET /__hl/constructs answers the counts. Without the flag nothing is
  233. // counted and the route does not exist.
  234. countConstructs = env('HL_WEB_COUNT') == '1'
  235. constructTotal = { n = 0 }
  236. constructByFile = {}
  237. // W159: the same switch also counts page builds (`mounts`), level renders (`renderOf`), documents and resyncs, as `calls`
  238. countCalls = {}
  239. tally(name) {
  240. if (countConstructs) { countCalls[name] = (countCalls[name] == null ? 0 : countCalls[name]) + 1 }
  241. return null
  242. }
  243. // THE FRAMEWORK'S OWN URLS ARE ROUTES (creator: "just use routes"), appended to
  244. // the app's table with `routes[] = …` — the append that takes on a caller's
  245. // pinned argument during construction, where `routes = routes + […]` is dropped.
  246. // Three of them here — the runtime, the REST carrier and the app's one
  247. // stylesheet — and then one per PACKAGE BROWSER HALF the app's graph holds,
  248. // appended below where the graph is known. There is no catch-all that compiles
  249. // any graph file a url names.
  250. routes[] = { pattern = runtimeUrl framework = true function = (route, req) => {
  251. return new Response(runtime, { headers = cached(req, 'text/javascript; charset=utf-8') })
  252. } }
  253. // THE REST CARRIER, the same emit/ack pair for a peer that cannot hold a socket
  254. // (SPEC: `POST /__hl/emit`).
  255. // ITS SESSION IS THE COOKIE'S (creator, 2026-09-14): this is an HTTP request like
  256. // the page request, so it resolves the SAME session the page route would for that
  257. // cookie — a `session.user` a face writes here is what the next document reads.
  258. // Before this the face was handed null and a login over the fallback was lost.
  259. // AN OUTWARD EMIT RAISED UNDER IT RIDES BACK IN THE ANSWER: there is no
  260. // connection to push to, so the frames a face raised for the CALLER are
  261. // collected while it runs and shipped in the ack as `emits`, which the client
  262. // half delivers before it resolves the emit. The audience fan-out to the other
  263. // connections of that user is the same walk it always was.
  264. routes[] = { pattern = '/__hl/emit' framework = true function = (route, req) => {
  265. if (req.method != 'POST') { return notFound(req.path) }
  266. if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }
  267. if (req.body != null && req.body.length > emitMax) { return refused(413, 'the emit is longer than ' + emitMax + ' bytes (`emitMax`)') }
  268. // NO COOKIE, NO SESSION (W124): a face that stores something in the session it was handed makes one,
  269. // `inbound` leaves it in `postAdopted`, and the answer sets the cookie
  270. let s = sessions.resolve(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'])
  271. let idBefore = s != null ? s.id : null
  272. // the session travels in a MEMBER, not an argument: a call argument is a copy,
  273. // an instance inside it included, and a copied session loses the face's write
  274. postSession = s
  275. postHost = hostOf(req.headers['host'])
  276. postHeaders = requestHeaders(req.headers)
  277. postReq = requestInfo(req.headers, req.remoteAddress, req.secure)
  278. postAdopted = null
  279. let res = new Response(inbound(null, JSON.parse(req.body)), { headers = { 'Content-Type' = 'application/json; charset=utf-8' } })
  280. // the session a face made (W124), or the one a face's `session.rotate()` moved to a new id (W120): this answer carries the cookie
  281. if (postAdopted != null) { res.headers['Set-Cookie'] = sessions.cookieHeader(postAdopted.id, isHttps(req.headers, req.secure)) } else if (s != null && s.id != idBefore) { res.headers['Set-Cookie'] = sessions.cookieHeader(s.id, isHttps(req.headers, req.secure)) }
  282. // W137: several cookies of the session's name: the answer re-issues the chosen one and expires the host-only stray
  283. let fx = sessions.repair(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], s, isHttps(req.headers, req.secure))
  284. for (k of fx.keys()) { if (res.headers[k] == null) { res.headers[k] = fx[k] } }
  285. postAdopted = null
  286. postReq = null
  287. return res
  288. } }
  289. // THE SOCKET CARRIER'S HALF OF `session.rotate()` (W120): a frame cannot set a cookie, so the server pushed the
  290. // tab `{ t: 'rotate', token }` and the client half POSTs it here. Origin-checked, authenticated twice — by the
  291. // token only that socket was given (one-shot) and by the cookie it still holds (the OLD id the rotation
  292. // recorded) — and the answer carries the Set-Cookie of the new id. A planted id has no token: nothing to claim.
  293. routes[] = { pattern = '/__hl/rotate' framework = true function = (route, req) => {
  294. if (req.method != 'POST') { return notFound(req.path) }
  295. if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }
  296. let sent = req.body != null && req.body != '' ? JSON.parse(req.body) : null
  297. let token = sent != null ? sent.token : null
  298. let rec = token != null ? pendingRotate['r' + token] : null
  299. let cks = sessions.cookieValues(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'])
  300. if (rec == null || !cks.includes(rec.old) || now() - rec.at > 300000) { return refused(403, 'no rotation to claim') }
  301. pendingRotate['r' + token] = null
  302. let res = new Response('', { status = 204 headers = { 'Cache-Control' = 'no-store' } })
  303. res.headers['Set-Cookie'] = sessions.cookieHeader(rec.id, isHttps(req.headers, req.secure))
  304. return res
  305. } }
  306. // A FILE IN AN EMIT TRAVELS OVER HTTP (ticket #94, creator 2026-09-25): the client half
  307. // sends each file of an `emit server …` here, in parts, before the emit itself; the emit's
  308. // frame then names the upload, and `inbound` hands the face the file in its place.
  309. // POST /__hl/upload { name, type, size, q, n } → { id, have } (an upload; see uploadRequest)
  310. // POST /__hl/upload?id=&at= one part, raw → { have } (appended when `at` is what arrived so far)
  311. // GET /__hl/upload?id= → { have } (after a dropped connection)
  312. // An upload belongs to the session of the cookie that started it, and only an emit
  313. // of that session can claim it. A part cut short by a dropped connection keeps what
  314. // arrived; the client asks for `have` and goes on from there.
  315. routes[] = { pattern = '/__hl/upload' framework = true function = (route, req) => {
  316. if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }
  317. // W124: sessions are lazy (a page mints none), so the START of an upload is what makes one for a
  318. // visitor with no cookie; the answer sets it. A part or a question about `id` needs the session
  319. // that started it. The caps (uploadMax, uploadSessionMax, uploadHeldMax) still hold the memory.
  320. let s = sessions.resolve(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'])
  321. if (s == null && req.query != null && req.query.id != null) { return uploadAnswer(404, { error = 'no upload ' + req.query.id + ' in this session' }) }
  322. let made = s == null
  323. if (made) {
  324. if (req.method != 'POST') { return notFound(req.path) }
  325. s = sessions.fresh()
  326. }
  327. postAdopted = null
  328. let out = uploadRequest(&s, req)
  329. // a visitor whose start was refused (too big, bad body) keeps no session: `uploadRequest` adopts it
  330. // only when the upload is accepted
  331. if (postAdopted != null) { out.headers['Set-Cookie'] = sessions.cookieHeader(postAdopted.id, isHttps(req.headers, req.secure)) }
  332. // W137: several cookies of the session's name: re-issue the chosen session's id, expire the host-only stray
  333. let fx = made ? sessions.strays(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], isHttps(req.headers, req.secure)) : sessions.repair(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], s, isHttps(req.headers, req.secure))
  334. for (k of fx.keys()) { if (out.headers[k] == null) { out.headers[k] = fx[k] } }
  335. postAdopted = null
  336. return out
  337. } }
  338. // A SESSION MADE OVER THE SOCKET GETS ITS COOKIE HERE (W124): a socket cannot set one, so the ack of the
  339. // face that made the session carries a one-time token and the page POSTs it here; the answer sets the cookie.
  340. routes[] = { pattern = '/__hl/adopt' framework = true function = (route, req) => {
  341. if (req.method != 'POST') { return notFound(req.path) }
  342. if (crossSite(req.headers)) { return refused(403, 'cross-site request refused') }
  343. let t = req.query != null ? req.query.t : null
  344. let a = t != null ? adoptTokens[t] : null
  345. if (a == null || now() - a.at > 60000) { return refused(404, 'no such token') }
  346. adoptTokens[t] = null
  347. let res = new Response('', { status = 204 headers = { 'Cache-Control' = 'no-store' 'Set-Cookie' = sessions.cookieHeader(a.sid, isHttps(req.headers, req.secure)) } })
  348. // W137: the new cookie must be the only one of its name: a host-only stray is expired
  349. let fx = sessions.strays(req.headers['cookie'] != null ? req.headers['cookie'] : req.headers['Cookie'], isHttps(req.headers, req.secure))
  350. for (k of fx.keys()) { res.headers[k] = fx[k] }
  351. return res
  352. } }
  353. if (countConstructs) {
  354. routes[] = { pattern = '/__hl/constructs' framework = true function = (route, req) => {
  355. return new Response(JSON.stringify({ total = constructTotal.n; byFile = constructByFile; calls = countCalls; }), { headers = { 'Content-Type' = 'application/json; charset=utf-8' 'Cache-Control' = 'no-store' } })
  356. } }
  357. }
  358. // THE SERVER IS UP (ticket #153): an empty answer the client half asks for while its socket
  359. // waits to reconnect, so a tab is back within about a second of a restarted server listening
  360. routes[] = { pattern = '/__hl/up' framework = true function = (route, req) => {
  361. return new Response('', { status = 204 headers = { 'Cache-Control' = 'no-store' } })
  362. } }
  363. // THE APP'S ONE STYLESHEET — the `styles` file's rules and every mounted
  364. // component's `Style { }`, walked in style.hl and cached after the first ask.
  365. routes[] = { pattern = styleUrl framework = true function = (route, req) => {
  366. return new Response(stylesheet(), { headers = cached(req, 'text/css; charset=utf-8') })
  367. } }
  368. // THE COMPONENT MODULES ARE ROUTES TOO — the framework's, not the app's: one per
  369. // file a page route mounts and per wrapper above it (the graph's `parent`
  370. // chain), served at the file's own `.hl` url as the browser's projection. A
  371. // browser executes a module by its MIME type, so `text/javascript` at
  372. // `/components/home.hl` is a module, and the url is the path the author wrote.
  373. // Nothing else is served as a module: a file no page route reaches has no url.
  374. // THE LANGUAGE GRAPH, AND THE REALMS ARE THIS PACKAGE'S (creator, 2026-09-12: "the project.hl
  375. // defines no realms so the framework just fills them itself"). This file is the server
  376. // realm's entrypoint, client.hl beside it the browser's; the app reaches both by
  377. // importing hl:web, and the graph follows that reference into the package.
  378. graph = hlProject(
  379. realms = {
  380. server = { entrypoint = './WebFramework.hl' }
  381. client = { entrypoint = './client.hl' }
  382. }
  383. transports = [
  384. ['websocket' 'client' 'server']
  385. ['websocket' 'server' 'client']
  386. ['rest' 'client' 'server']
  387. ]
  388. )
  389. gen = graph.analysisGen // the syntax reflection's handle: the routes below read Views
  390. // TWO WEB FRAMEWORKS IN ONE APP IS NOT AN APP (creator, 15 Sep: project.hl switched
  391. // to the other framework the repo had then while styles.hl still said 'hl:web/css').
  392. // Both packages load, both `on server page` faces answer the same navigation, and
  393. // the second answers on a blank instance — a NotCallable deep inside the other framework's dispatch, which
  394. // says nothing about the two import rows that caused it. So it is refused HERE,
  395. // before anything is served, naming both rows.
  396. oneFrameworkOnly()
  397. // A VALUE-FORM EMIT HAS ONE ANSWERER (SPEC "An emit ANSWERS", ticket #20): checked here,
  398. // before anything is served, because the wire does not say which form an emit was
  399. oneAnswererEach()
  400. // THE APP'S SETTINGS come from the file that constructed this one when they were not
  401. // passed (the archive's `configure()`): `styles`, `audience`, `sessionDir`, the clocks,
  402. // `watchMode`, `minify`, `port`
  403. cfg = hlConstructor()
  404. if (cfg != null) {
  405. if (lang == null && cfg.lang != null) { lang = cfg.lang }
  406. if (styles == null && cfg.styles != null) { styles = cfg.styles }
  407. if (cfg.audience != null && audience.keys().length == 0) { audience = cfg.audience }
  408. if (cfg.coalesce != null && coalesce.keys().length == 0) { coalesce = cfg.coalesce }
  409. if (sessionDir == null && cfg.sessionDir != null) { sessionDir = cfg.sessionDir }
  410. if (sessionMaxAge == null && cfg.sessionMaxAge != null) { sessionMaxAge = cfg.sessionMaxAge }
  411. if (sessionIdle == null && cfg.sessionIdle != null) { sessionIdle = cfg.sessionIdle }
  412. if (sweepInterval == null && cfg.sweepInterval != null) { sweepInterval = cfg.sweepInterval }
  413. if (sessionCookie == null && cfg.sessionCookie != null) { sessionCookie = cfg.sessionCookie }
  414. if (sessionSecure == null && cfg.sessionSecure != null) { sessionSecure = cfg.sessionSecure }
  415. if (cfg.sessionAnonMax != null) { sessionAnonMax = cfg.sessionAnonMax }
  416. if (cfg.sessionAnonKeep != null) { sessionAnonKeep = cfg.sessionAnonKeep }
  417. if (sessionDomain == null && cfg.sessionDomain != null) { sessionDomain = cfg.sessionDomain }
  418. if (cfg.watchMode != null) { watchMode = cfg.watchMode }
  419. if (cfg.minify != null) { minify = cfg.minify }
  420. if (cfg.port != null) { port = cfg.port }
  421. if (offline == null && cfg.offline != null) { offline = cfg.offline }
  422. if (offlineFallback == null && cfg.offlineFallback != null) { offlineFallback = cfg.offlineFallback }
  423. if (offlineFiles == null && cfg.offlineFiles != null) { offlineFiles = cfg.offlineFiles }
  424. if (pushKey == null && cfg.pushKey != null) { pushKey = cfg.pushKey }
  425. if (pushPrivateKey == null && cfg.pushPrivateKey != null) { pushPrivateKey = cfg.pushPrivateKey }
  426. if (pushSubject == null && cfg.pushSubject != null) { pushSubject = cfg.pushSubject }
  427. if (pingEvery == null && cfg.pingEvery != null) { pingEvery = cfg.pingEvery }
  428. if (pongWithin == null && cfg.pongWithin != null) { pongWithin = cfg.pongWithin }
  429. if (uploadStall == null && cfg.uploadStall != null) { uploadStall = cfg.uploadStall }
  430. if (cfg.uploadMax != null) { uploadMax = cfg.uploadMax }
  431. if (cfg.uploadSessionMax != null) { uploadSessionMax = cfg.uploadSessionMax }
  432. if (cfg.uploadHeldMax != null) { uploadHeldMax = cfg.uploadHeldMax }
  433. if (cfg.emitMax != null) { emitMax = cfg.emitMax }
  434. if (cfg.pageHeaders != null && pageHeaders.keys().length == 0) { pageHeaders = cfg.pageHeaders }
  435. if (cfg.trustedOrigins != null && trustedOrigins.length == 0) { trustedOrigins = cfg.trustedOrigins }
  436. if (cfg.pushKept != null) { pushKept = cfg.pushKept }
  437. if (cfg.pushKeptBytes != null) { pushKeptBytes = cfg.pushKeptBytes }
  438. if (cfg.tabKept != null) { tabKept = cfg.tabKept }
  439. if (cfg.recentKept != null) { recentKept = cfg.recentKept }
  440. }
  441. // MISSION 511: `import { a, b } from './counter.hl'` of an app file (not a package's): the statics it takes live ONCE, in that
  442. // file's own module, which every importing module imports. A static function so the build and the boot agree.
  443. // The app's own entry (the manifest, which builds the server) is never one: it is no browser module.
  444. // MISSION 516: and not one the browser module leaves out: the graph says `unreadIn` for the realms whose module reads none of the
  445. // names (they are used only in a `Style {}` or in handlers of another realm), and that file is no module of the page then.
  446. static isBracedFileImport = (imp, entryKey, realm) => {
  447. if (imp.unreadIn != null && imp.unreadIn.includes(realm)) { return false }
  448. return imp.key != entryKey && imp.default == null && imp.key != null && !imp.key.startsWith('hl:') && imp.key.endsWith('.hl') && imp.names != null && imp.names.length > 0
  449. }
  450. // does the file at `key` declare a View? (a component, as opposed to a plain class)
  451. static hasViewMember = (gen, key) => {
  452. for (m of hlMembers(gen, key)) {
  453. if (m.name == 'View') { return true }
  454. }
  455. return false
  456. }
  457. // Every statically imported component can be rendered by a function route's server.page call.
  458. static componentImports = (&graph) => {
  459. out = []
  460. for (key of graph.files.keys()) {
  461. for (imp of graph.files[key].imports) {
  462. if (imp.default != null && imp.key != null && graph.files[imp.key] != null && hasViewMember(graph.analysisGen, imp.key) && !out.includes(imp.key)) { out.push(imp.key) }
  463. }
  464. }
  465. return out
  466. }
  467. served = {}
  468. mounted = []
  469. for (r of routes) { if (r.component != null) { mounted[] = keyOf(r.component) } }
  470. // Function routes may import their pages through helpers (#358), not just the manifest (#249).
  471. // Use the same project import closure for CSS, live modules and the static module map.
  472. for (ck of componentImports(&graph)) {
  473. if (!mounted.includes(ck)) { mounted[] = ck }
  474. }
  475. for (k of mounted) {
  476. let key = k
  477. // a file the graph does not hold is refused at its route row, below (servedKeys
  478. // → routeComponentKey: this walk reads the evaluated table, which has no lines)
  479. if (graph.files[key] == null) { key = null }
  480. while (key != null) {
  481. serveComponent(key)
  482. let child = key
  483. key = graph.files[key].parent
  484. // A PARENT IS A COMPONENT (COMPONENTS §5): one without a View wraps nothing, and
  485. // every page under it answered a 500 while the boot said nothing (322 row 13)
  486. if (key != null && viewHandle(key) == 0) {
  487. hlError("hl:web: the `parent` clause of " + child + " names " + key + ", which declares no View: a parent is a component whose View places `slot` where the page renders")
  488. }
  489. }
  490. }
  491. // EVERY PACKAGE'S BROWSER HALF IS SERVED, BY ONE RULE. A package whose browser
  492. // side is written in this language ships it as `client.hl` beside its
  493. // plugin.json; the compiler compiles it like any other file and writes the
  494. // importing module `import { … } from "<halfDir>/<pkg>/client.js"`
  495. // (js_module.zig browserHalf / browserHalfUrl). Something has to answer that url,
  496. // and this is it — for EVERY such package the graph holds, because the rule
  497. // belongs to the language and not to one package. hl:web's own half is the first
  498. // case of it and no longer a hard-coded route of its own; hl:dnd is the second.
  499. //
  500. // The graph is the whole guard: a key is here only because the entry's closure
  501. // REACHED that package's half through an import, which is the same reason a
  502. // component has a module url. A package nothing imports is served nothing.
  503. for (gk of graph.files.keys()) {
  504. if (gk.startsWith('hl:') && gk.endsWith('/client.hl')) { serveHalf(gk) }
  505. }
  506. // ---- INSTALLABLE, AND OFFLINE (COMPONENTS §10, tickets #95–#97) ------------------
  507. // Two declarations in the app's manifest, and nothing written by hand in the app:
  508. // · `appIcons` (with `appTitle`, and optionally `appShortName`, `appThemeColor`,
  509. // `appBackgroundColor`, `appManifest`) makes the app INSTALLABLE — the web app
  510. // manifest below, linked from every page's head with its apple-touch-icon;
  511. // · `offline = [ … ]` makes the pages it names work OFFLINE — the service worker
  512. // (worker.hl) that keeps the shell and those pages, and in the client half the
  513. // IndexedDB copy of their state and the queue of the emits they make.
  514. // An app that declares neither is served nothing of either.
  515. routes[] = { pattern = '/__hl/uploads.js' framework = true function = (route, req) => { return serveHl('hl:web/uploads.hl', req) } }
  516. offlineKeys = offlinePages()
  517. if (offlineKeys != null) {
  518. routes[] = { pattern = '/__hl/offline.js' framework = true function = (route, req) => { return serveHl('hl:web/offline.hl', req) } }
  519. }
  520. fallbackPattern = offlineFallbackPattern()
  521. dataFreeKeys = dataFreePages()
  522. queueEvents = offlineKeys != null ? queueable() : []
  523. if (installable()) {
  524. routes[] = { pattern = manifestUrl framework = true function = (route, req) => {
  525. return new Response(JSON.stringify(webManifest()), { headers = { 'Content-Type' = 'application/manifest+json; charset=utf-8' 'Cache-Control' = 'no-cache' } })
  526. } }
  527. }
  528. validateCoalesce()
  529. if (pushKey != null && hlTypeName(pushKey) != 'String') { refuseAtSetting('pushKey', 'hl:web: pushKey is the VAPID public key as a base64url string, and this one is a ' + hlTypeName(pushKey)) }
  530. if (pushPrivateKey != null || pushSubject != null) {
  531. if (pushKey == null || pushPrivateKey == null || pushSubject == null) { refuseAtSetting('pushPrivateKey', 'hl:web: sending a push needs pushKey, pushPrivateKey and pushSubject together') }
  532. if (hlTypeName(pushPrivateKey) != 'String' || hlTypeName(pushSubject) != 'String') { refuseAtSetting('pushPrivateKey', 'hl:web: pushPrivateKey is a base64url string and pushSubject a string (mailto:… or https://…)') }
  533. if (!pushSubject.startsWith('mailto:') && !pushSubject.startsWith('https://')) { refuseAtSetting('pushSubject', 'hl:web: pushSubject is a mailto: or https:// contact, and this one is ' + pushSubject) }
  534. let vapidPriv = base64urlDecode(pushPrivateKey)
  535. let vapidPub = vapidPriv != null && vapidPriv.length == 32 ? p256PublicKey(vapidPriv) : null
  536. if (vapidPub == null || base64urlEncode(vapidPub) != pushKey) { refuseAtSetting('pushPrivateKey', 'hl:web: pushPrivateKey is not the private half of pushKey (32 bytes, base64url)') }
  537. configurePush(pushKey, vapidPriv, pushSubject)
  538. }
  539. if (offlineKeys != null || pushKey != null) {
  540. // the ENTRY SCRIPT is served at the framework's directory, and its scope is the
  541. // whole app: `Service-Worker-Allowed` is what lets a script under /__hl/ say so
  542. routes[] = { pattern = workerUrl framework = true function = (route, req) => {
  543. return new Response(workerEntry(), { headers = { 'Content-Type' = 'text/javascript; charset=utf-8' 'Cache-Control' = 'no-cache' 'Service-Worker-Allowed' = '/' } })
  544. } }
  545. routes[] = { pattern = halfDir + '/web/worker.js' framework = true function = (route, req) => {
  546. return new Response(workerModule(), { headers = cached(req, 'text/javascript; charset=utf-8') })
  547. } }
  548. }
  549. // ---- WHAT THIS APP SERVES, OFF THE ANALYSIS ALONE (mission 315) ----------------
  550. // These four are STATIC, so they answer with no instance and without constructing
  551. // anything: the compiler evaluates `servedModulesOf(&graph)` at BUILD time to bake
  552. // each module's text, and this file's own root uses the very same functions at
  553. // boot. One definition, two callers — a second derivation would drift, and a
  554. // compiled binary would then serve text generated against different urls.
  555. //
  556. // The seed is the entry's route table AS WRITTEN, read through `hlSyntax`, not
  557. // the evaluated `routes` member: evaluating it means constructing the app, and
  558. // constructing this class binds a socket. The graph carries the entry's record
  559. // since 2026-09-16, which is what makes that readable at all.
  560. // A ROUTE'S COMPONENT IS A PAGE: a file without a View answered every request with a 500
  561. // ("declares no View", raised without a span) while the boot said nothing (mission 322
  562. // row 13). Refused at the row instead.
  563. static routePage = (gen, entryKey, valueNode, key) => {
  564. if (!hasViewMember(gen, key)) { hlSourceError(gen, entryKey, valueNode, key + " declares no View, so it is no page: a route's component is a file whose View renders") }
  565. return key
  566. }
  567. // The key a route row's `component` names: an imported class, or a path string.
  568. // Anything else is a located refusal AT THE ROW — never silently unserved.
  569. static routeComponentKey = (&graph, gen, entryKey, imports, valueNode) => {
  570. let v = hlSyntax(gen, entryKey, valueNode)
  571. if (v == null) { return null }
  572. if (v.tag == 'literal' && v.kind == 'string') {
  573. let t = v.text
  574. let k = t.startsWith('./') ? t.slice(2) : t
  575. // A PATH NO FILE OF THE APP IMPORTS IS NOT IN THE GRAPH: the analysis never read
  576. // it, so nothing can be served for it — refused here, at the row, instead of a
  577. // null deep in the framework once the server is already up (STATUS §2 item 0)
  578. if (graph.files[k] == null) { hlSourceError(gen, entryKey, valueNode, "the app never imports " + t + ", so the analysis never read it and the app would serve no module for it: import it in this file (`import Page from '" + t + "'`) and write `component = Page`") }
  579. return routePage(gen, entryKey, valueNode, k)
  580. }
  581. if (v.tag == 'identifier') {
  582. for (imp of imports) {
  583. if (imp.default == v.name && imp.key != null) { return routePage(gen, entryKey, valueNode, imp.key) }
  584. }
  585. }
  586. hlSourceError(gen, entryKey, valueNode, "a route's component must be an imported component class or a path string — this one the analysis cannot resolve to a file, so the app would serve no module for it")
  587. return null
  588. }
  589. // `key` and every component it composes, once each — the same walk
  590. // `serveComponent` performs, as a function of the graph.
  591. static collectServed = (&graph, gen, &out, key) => {
  592. if (key == null || graph.files[key] == null) { return null }
  593. for (k of out) { if (k == key) { return null } }
  594. out[] = key
  595. for (imp of graph.files[key].imports) {
  596. if (imp.default != null && imp.key != null && hasViewMember(gen, imp.key)) {
  597. collectServed(&graph, gen, &out, imp.key)
  598. }
  599. // MISSION 511: the same for a file imported by braces (its statics are shared through its module)
  600. if (isBracedFileImport(imp, graph.manifest.file, clientRealmOf(&graph)) && graph.files[imp.key] != null) {
  601. collectServed(&graph, gen, &out, imp.key)
  602. }
  603. }
  604. return null
  605. }
  606. // Every key this app answers a module for: each route's component and the wrapper
  607. // chain above it, the components those compose, and every package's browser half.
  608. static servedKeys = (&graph) => {
  609. let gen = graph.analysisGen
  610. let entryKey = graph.manifest.file
  611. let out = []
  612. if (entryKey != null && graph.files[entryKey] != null) {
  613. let imports = graph.files[entryKey].imports
  614. let routesNode = 0
  615. for (m of hlMembers(gen, entryKey)) {
  616. if (m.name == 'routes') { routesNode = m.node }
  617. }
  618. // Function-route pages anywhere in the import closure, with their wrappers.
  619. for (key of componentImports(&graph)) {
  620. let k = key
  621. while (k != null) {
  622. collectServed(&graph, gen, &out, k)
  623. k = graph.files[k] != null ? graph.files[k].parent : null
  624. }
  625. }
  626. if (routesNode != 0) {
  627. let arr = hlSyntax(gen, entryKey, routesNode)
  628. if (arr != null && arr.tag == 'array_expression') {
  629. for (e of arr.elements) {
  630. let row = hlSyntax(gen, entryKey, e)
  631. if (row != null && row.tag == 'object_expression') {
  632. let hasSocket = false
  633. let hasOther = false
  634. for (entry of row.entries) {
  635. property = hlSyntax(gen, entryKey, entry)
  636. if (property != null && property.tag == 'object_property') {
  637. if (property.key == 'socket') { hasSocket = true }
  638. if (property.key == 'component' || property.key == 'function') { hasOther = true }
  639. }
  640. }
  641. if (hasSocket && hasOther) { hlSourceError(gen, entryKey, e, 'a socket route cannot also have component or function') }
  642. for (pe of row.entries) {
  643. let prop = hlSyntax(gen, entryKey, pe)
  644. if (prop != null && prop.tag == 'object_property' && prop.key == 'component') {
  645. let key = routeComponentKey(&graph, gen, entryKey, imports, prop.value)
  646. // the wrapper chain above it, deepest last — a page is
  647. // served inside whatever wraps it
  648. let k = key
  649. while (k != null) {
  650. collectServed(&graph, gen, &out, k)
  651. k = graph.files[k] != null ? graph.files[k].parent : null
  652. }
  653. }
  654. }
  655. }
  656. }
  657. }
  658. }
  659. }
  660. return out
  661. }
  662. // EVERY PACKAGE'S BROWSER HALF, BY ONE RULE — a package whose browser side is
  663. // written in this language ships it as `client.hl`, the compiler writes
  664. // `<halfDir>/<pkg>/client.js` into every importing module, and something has to
  665. // answer that url. The graph is the whole guard: a key is here only because the
  666. // entry's closure reached that package.
  667. //
  668. // SEPARATE FROM `servedKeys` ON PURPOSE: a half gets a ROUTE but is not a module
  669. // url of this app, so it is not in the map `hlJs` is handed. That asymmetry is
  670. // the existing `serveHalf`/`serveComponent` split, stated rather than inherited
  671. // by accident — measured 2026-09-16, when folding the two together made the
  672. // analysis set one key wider than the route walk's.
  673. static packageHalfKeys = (&graph) => {
  674. let out = []
  675. for (gk of graph.files.keys()) {
  676. if (gk.startsWith('hl:') && gk.endsWith('/client.hl')) { out[] = gk }
  677. }
  678. return out
  679. }
  680. // The browser realm's NAME, off the graph — the declared realm whose entrypoint
  681. // is this framework's client half. Static, so the compiler can ask it too.
  682. static clientRealmOf = (&graph) => {
  683. for (name of graph.realms.keys()) {
  684. if (graph.realms[name].entrypoint == 'hl:web/client.hl') { return name }
  685. }
  686. return null
  687. }
  688. // EVERY MODULE THIS APP SERVES, COMPILED — what a native binary answers `hlJs`
  689. // with (mission 315). The emitter needs the runtime specifier, the browser
  690. // realm and the served-url map; all three are functions of the analysis, so the
  691. // whole map is, and the COMPILER can build it without an instance.
  692. //
  693. // `minify` is NOT: it is an app setting bound at construction, and the analysis
  694. // cannot evaluate a construction. The value used is recorded beside each
  695. // module so a binary asked for a different one refuses at the call instead of
  696. // answering text generated the other way.
  697. // HOW THE APP ASKED FOR ITS MODULES. A build bakes ONE form of every module and
  698. // a binary answering the other form would be different bytes, so the build must
  699. // read the app's own answer — and the app writes it where it configures the
  700. // framework: `new WebFramework(… minify = true …)` in the manifest. The analysis
  701. // carries a construction's named arguments, so this is a READ of the same syntax
  702. // `servedKeys` reads for the routes, not a second declaration.
  703. //
  704. // A COMPUTED `minify` IS NOT READ HERE, and nothing is guessed from it: a build
  705. // cannot evaluate an expression the running app has not reached yet. Such an app
  706. // bakes the unminified form, exactly as every app did before this, and if it
  707. // then asks for the other form at run time the binary says so at the request —
  708. // "this binary carries the module compiled the other way", located, which is
  709. // the refusal that already exists and the one measured on the creator's social
  710. // app (2026-09-17). Writing the literal in the manifest is what removes it.
  711. static manifestMinify = (&graph) => {
  712. let gen = graph.analysisGen
  713. let key = graph.manifest.file
  714. if (key == null || graph.files[key] == null) { return false }
  715. for (m of hlMembers(gen, key)) {
  716. let s = hlSyntax(gen, key, m.node)
  717. if (s != null && s.tag == 'new_expression' && s.named != null) {
  718. for (h of s.named) {
  719. let p = hlSyntax(gen, key, h)
  720. if (p != null && p.tag == 'object_property' && p.key == 'minify') {
  721. let v = hlSyntax(gen, key, p.value)
  722. if (v != null && v.tag == 'literal' && v.kind == 'boolean') { return v.text == 'true' }
  723. }
  724. }
  725. }
  726. }
  727. return false
  728. }
  729. // THE PACKAGES WHOSE BROWSER HALF MAY BE ONE PLAIN `client.js`: each `hl:<pkg>` a served module (or a package's own
  730. // browser half) imports, that has no `client.hl` in the graph. Whether the package really has a `client.js` is
  731. // the compiler's to say (`hlJs('hl:<pkg>/client.js')` answers the empty text when it has none).
  732. static plainHalfPackages = (&graph) => {
  733. let out = []
  734. let keys = servedKeys(&graph)
  735. for (hk of packageHalfKeys(&graph)) { keys[] = hk }
  736. // the files those import, and theirs: a module reaches `hl:time` through a plain `.hl` file it imports (a static helper)
  737. let at = 0
  738. while (at < keys.length) {
  739. let k = keys[at]
  740. at = at + 1
  741. if (graph.files[k] != null) {
  742. for (imp of graph.files[k].imports) {
  743. if (imp.key != null && graph.files[imp.key] != null && !keys.includes(imp.key)) { keys[] = imp.key }
  744. if (imp.source.startsWith('hl:') && !imp.source.includes('/')) {
  745. let pkg = imp.source.slice(3, imp.source.length)
  746. if (graph.files['hl:' + pkg + '/client.hl'] == null && !out.includes(pkg)) { out[] = pkg }
  747. }
  748. }
  749. }
  750. }
  751. return out
  752. }
  753. // AND A PACKAGE WHOSE BROWSER HALF IS ONE PLAIN `client.js` (hl:time) THE SAME WAY (mission 509): the compiler
  754. // writes the same `import … from "<halfDir>/<pkg>/client.js"` for it, so the browser fetches it once and every
  755. // page module shares that one instance, instead of each module carrying a private copy of the half's text.
  756. plainHalves = {} // package name → the half's text, for the packages the served modules import
  757. for (pkg of plainHalfPackages(&graph)) { servePlainHalf(pkg) }
  758. static bakeModules = (graph) => {
  759. let realm = clientRealmOf(&graph)
  760. let served = servedModulesOf(&graph)
  761. let min = manifestMinify(&graph)
  762. let out = {}
  763. for (k of servedKeys(&graph)) {
  764. if (graph.files[k] != null) {
  765. let p = graph.files[k].path
  766. out[p] = {
  767. text = hlJs(p, k == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : min, runtimeSpec, realm, served)
  768. minify = k == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : min
  769. runtime = runtimeSpec
  770. realm = realm
  771. }
  772. }
  773. }
  774. // EVERY PACKAGE HALF TOO. The root walk above serves `<halfDir>/<pkg>/client.js`
  775. // for every `hl:<pkg>/client.hl` the graph holds, and a compiled binary answers
  776. // from BAKED text alone — so a bake that skipped them served the page and then
  777. // 404'd on the module the page imports, leaving the client half of the app
  778. // dead with nothing reported (measured on projects/framework, 2026-09-16).
  779. // Same rule, same list, one loop later: what the server routes, the build bakes.
  780. // AN OFFLINE APP'S SERVICE WORKER MODULE (COMPONENTS §10), under its own path
  781. if (manifestOffline(graph)) {
  782. let wp = workerPathOf(graph)
  783. out[wp] = {
  784. text = hlJs(wp, min, runtimeSpec, realm, served)
  785. minify = min
  786. runtime = runtimeSpec
  787. realm = realm
  788. }
  789. }
  790. if (graph.files['hl:web/uploads.hl'] != null) {
  791. p = graph.files['hl:web/uploads.hl'].path
  792. out[p] = { text = hlJs(p, min, runtimeSpec, realm, served); minify = min; runtime = runtimeSpec; realm = realm; }
  793. }
  794. if (manifestFeature(&graph, 'offline')) {
  795. p = graph.files['hl:web/offline.hl'].path
  796. out[p] = { text = hlJs(p, min, runtimeSpec, realm, served); minify = min; runtime = runtimeSpec; realm = realm; }
  797. }
  798. // AND EACH PLAIN PACKAGE HALF (mission 509), under its pseudo path `hl:<pkg>/client.js`
  799. for (pkg of plainHalfPackages(&graph)) {
  800. let pp = 'hl:' + pkg + '/client.js'
  801. out[pp] = {
  802. text = hlJs(pp, min, runtimeSpec, realm, served)
  803. minify = min
  804. runtime = runtimeSpec
  805. realm = realm
  806. }
  807. }
  808. for (gk of graph.files.keys()) {
  809. if (gk.startsWith('hl:') && gk.endsWith('/client.hl') && graph.files[gk] != null) {
  810. let hp = graph.files[gk].path
  811. if (out[hp] == null) {
  812. out[hp] = {
  813. text = hlJs(hp, gk == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : min, runtimeSpec, realm, served)
  814. minify = gk == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : min
  815. runtime = runtimeSpec
  816. realm = realm
  817. }
  818. }
  819. }
  820. }
  821. return out
  822. }
  823. // file path → the url this server answers its module at. What `hlJs` is handed,
  824. // and what the compiler bakes against.
  825. static servedModulesOf = (&graph) => {
  826. let out = {}
  827. // An extension's Client reference must reuse the package half's own module.
  828. if (graph.files['hl:web/client.hl'] != null) { out[graph.files['hl:web/client.hl'].path] = halfDir + '/web/client.js' + buildMark }
  829. if (graph.files['hl:web/offline.hl'] != null) { out[graph.files['hl:web/offline.hl'].path] = '/__hl/offline.js' + buildMark }
  830. if (graph.files['hl:web/uploads.hl'] != null) { out[graph.files['hl:web/uploads.hl'].path] = '/__hl/uploads.js' + buildMark }
  831. for (k of servedKeys(&graph)) {
  832. if (graph.files[k] != null) { out[graph.files[k].path] = graphModulePath(k) + buildMark }
  833. }
  834. return out
  835. }
  836. // ONE PACKAGE HALF'S ROUTE. It is a FUNCTION and not the body of the loop above
  837. // because the url's route closure must hold THIS key: a `let` in a loop body is
  838. // one binding the closures share, so every route built that way would serve the
  839. // last package's half (measured 2026-09-14 — both /__hl/web/client.js and
  840. // /__hl/dnd/client.js answered with hl:web's module). A parameter is a fresh
  841. // binding per call, which is the same reason serveComponent below is a function.
  842. serveHalf(key) {
  843. routes[] = { pattern = halfUrl(key.slice(3, key.length - 10)) framework = true function = (route, req) => { return serveHl(key, req) } }
  844. return null
  845. }
  846. // ONE PLAIN PACKAGE HALF'S ROUTE (mission 509): the text comes from `hlJs` as `hl:<pkg>/client.js` (the compiler
  847. // reads it beside the package, a binary carries it baked); a package that has no such half answers the empty text
  848. // and gets no route. Cached by the build version exactly like the other halves (`cached`).
  849. servePlainHalf(pkg) {
  850. let text = hlJs('hl:' + pkg + '/client.js', minify, runtimeSpec, clientRealm(), servedModules())
  851. if (text == null || text == '') { return null }
  852. plainHalves[pkg] = text
  853. routes[] = { pattern = halfUrl(pkg) framework = true function = (route, req) => {
  854. return new Response(plainHalves[pkg], { headers = cached(req, 'text/javascript; charset=utf-8') })
  855. } }
  856. return null
  857. }
  858. // a mounted file's module route, and the routes of the components it composes
  859. // (an import with a View), recursively — off the graph, once each
  860. serveComponent(key) {
  861. if (served[key] != null) { return null }
  862. served[key] = true
  863. routes[] = { pattern = modulePath(key) framework = true function = (route, req) => { return serveHl(key, req) } }
  864. for (imp of graph.files[key].imports) {
  865. if (imp.default != null && imp.key != null && viewHandle(imp.key) != 0) { serveComponent(imp.key) }
  866. // MISSION 511: a file a served module imports statics from by braces is a module of its own too, so its statics exist once;
  867. // a braced import of a file outside the graph is skipped, as collectServed skips it, so it cannot crash the boot
  868. if (isBracedFileImport(imp, graph.manifest.file, clientRealm()) && graph.files[imp.key] != null) { serveComponent(imp.key) }
  869. }
  870. return null
  871. }
  872. // THE PROJECT DIRECTORY: this file lives in a package, so the app's directory is read
  873. // off a file that is the app's — the first route component's key against its path
  874. root = projectRoot()
  875. view = new HlwViewServer
  876. viewRead = new HlwView
  877. css = new HlwCss(minify = minify, view = view)
  878. compiler = new HlwCompile(browserKeyOf = graphModuleKey)
  879. sessions = new HlwSessions(dir = sessionDirPath(), maxAge = sessionMaxAge != null ? sessionMaxAge : 1209600, idle = sessionIdle != null ? sessionIdle : 900, sweepEvery = sweepInterval != null ? sweepInterval : 300, cookie = cookieName(), secure = sessionSecure, anonMax = sessionAnonMax, anonKeep = sessionAnonKeep, domain = sessionDomain != null ? sessionDomain : '')
  880. sessions.open()
  881. // THE STYLES FILE IS NAMED AT BOOT, not at the first request for the stylesheet: a value
  882. // that names no file, or a file the graph does not hold, is the app's mistake and the
  883. // app does not start with it (ticket #12)
  884. if (styles != null) {
  885. if (hlTypeName(styles) != 'String' && hlTypeName(styles) != 'Class') { refuseAtSetting('styles', "hl:web: styles is the styles file — the class the app imported (`styles = Styles`) or a path string ('./styles.hl') — and this one is a " + hlTypeName(styles)) }
  886. if (graph.files[keyOf(styles)] == null) { refuseAtSetting('styles', "hl:web: styles names " + keyOf(styles) + ", which is not in the project graph — import it from the app's entry (`import Styles from './styles.hl'`) and write `styles = Styles`") }
  887. }
  888. // the whole tree, nothing excluded: dot directories (the session store) are skipped by
  889. // the walker's own rule, and a custom store inside the tree is the app's choice to pay for
  890. if (watchMode) { __native("eventloop.register", watch(root), "hlFileChanged") }
  891. sheetText = null // the stylesheet, walked once at the first request for it
  892. // hl:web's OWN urls (/__hl/*, /components/*.hl) win over the app's routes whatever the
  893. // app's table ends in (ticket #129: a last `/:slug/:n` answered /__hl/app.css with HTML):
  894. // the framework's routes first, the app's after them in their own order
  895. let ownFirst = []
  896. for (r of routes) { if (r.framework == true) { ownFirst[] = r } }
  897. for (r of routes) { if (r.framework != true) { ownFirst[] = r } }
  898. let oi = 0
  899. for (r of ownFirst) {
  900. routes[oi] = r
  901. oi = oi + 1
  902. }
  903. router = new HlwRouter(routes = routes)
  904. trees = {} // key → the View tree, built once
  905. preloaded = {} // key → true: the closure of the Views it reaches is loaded (preload)
  906. declared = {} // key → { member name → true } of its non-static members (declares)
  907. setters = {} // key → { member name → true } of its setters (setterOf)
  908. reach = {} // key → the component keys its View reaches, in the order preload walks them
  909. less = {} // key → { skipped, kids }: the server-only members the first load's seed leaves out (lessFor)
  910. needed = {} // key → { sites, names, reads }: the members only the server computes (serverNeeds)
  911. kidWants = {} // key → the host members the View's references, conditions and lists read (kidWanted); cleared with `needed`
  912. srvBelow = {} // key → 'yes' / 'no': does a component below (or this one) have server-realm members (srvBelow)
  913. kidless = {} // key → 'yes' / 'no': does its View reference a component (holdsKids)
  914. fillsOf = {} // key → the named-region fills its View root writes (`side { … }`), lifted out of the tree
  915. slotAt = {} // key → where its View places its one `slot`
  916. styleNames = {} // key → the rule names of the file's Style, off the syntax
  917. styleRefs = {} // key → [{ tag rule }] the View wrote
  918. fillTags = {} // key → the element names (DOM tags) callers write into this component's slot (hybriel#270)
  919. styleTags = {} // key → the element names this file's View renders
  920. styleIds = {} // key → the literal `id` values this file's View writes (R3)
  921. staticHolders = {} // key → an instance of a file whose statics another file imports
  922. modules = {} // key → the browser module (JavaScript text), compiled once at boot
  923. buildHash = null // the hash of everything this build serves, in every cached url (build())
  924. workerCompiled = null // the service worker's module as compiled (offline apps only, workerText())
  925. shipped = {} // key → the module as served: its build marks replaced with the hash
  926. sitesOf = {} // key → the position tables cut out of a deploy build's module, as the JSON `?sites=1` answers
  927. servedUrls = null // file path → the url this server answers its module at, for hlJs
  928. // MISSION 505: the paint helpers every component module used to carry (compile.hl `paintHelpers`, 699 bytes in each of the 25
  929. // modules of the reference app's start page) ride once, at the end of the runtime text every module imports first
  930. runtime = (minify ? hlJsRuntimeMin() : hlJsRuntime()) + newline + compiler.paintHelpers() // the runtime library every module imports as "./hl-runtime.js"
  931. peers = {} // connection key → the WsClient, while it is open
  932. peerSession = {} // connection key → its session, from the tab's `hello` (null = anonymous)
  933. peerHost = {} // connection key → the host its upgrade request named (null = none sent)
  934. peerHeaders = {} // connection key → its upgrade request's headers (requestHeaders)
  935. peerMounts = {} // connection key → the component keys the tab has mounted
  936. // A TAB OUTLIVES ITS SOCKET (ticket #143): 't' + the tab's id → { id, n, log, bytes, conn,
  937. // session, mounts, params, host, headers, left }. `n` counts the pushes sent to it, `log`
  938. // keeps the last of them as sent ([{ n, text }], bounded by pushKept/pushKeptBytes),
  939. // `conn` is its open socket's key or null, `left` when that socket went (tabKept)
  940. tabs = {}
  941. peerTab = {} // connection key → the id of the tab its `hello` named
  942. // SESSIONS (web/sessions.hl): named by the cookie, at the page request and at the
  943. // socket's handshake alike. Nothing about a session ever reaches page script.
  944. sending = null // the WsClient whose inbound emit is being handled — the peer
  945. // an outward emit reaches, and null under the POST fallback
  946. // THE POST FALLBACK'S PEER IS ITS OWN ANSWER. While a face dispatched over
  947. // `POST /__hl/emit` runs, or a socket face has a transient session (W214), `posting` is true. Every outward emit meant for the
  948. // CALLER is appended here instead of pushed; `inbound` ships the list in the ack.
  949. Boolean posting = false
  950. postEmits = []
  951. // …AND ITS TAB (#143): the tab a POST named (`tab` in its frame, of the same session) has
  952. // what is raised for it numbered and logged like a push, so the replay on its next socket
  953. // does not run it a second time
  954. postTab = null
  955. // A PAGE ANSWER'S OWN PUSHES (hybriel#410): what building a navigation answer (the `page` face) raises for the NAVIGATING tab is
  956. // numbered and logged like any push (#143) but rides in the page ack as `late`, in order, not sent ahead of it: the browser
  957. // places the new page first and then applies them, so the page it is leaving never shows the effect of the page's build.
  958. lateOn = false
  959. lateTab = null
  960. lateEmits = []
  961. postSession = null // the cookie's session of the POST being dispatched
  962. pendingRotate = {} // 'r' + token → { old, id, at }: a socket-carrier rotation waiting for its browser's POST /__hl/rotate (W120)
  963. postAdopted = null // the session a POST's face (or an upload start) just made: its answer sets the cookie (W124)
  964. postReq = null // the request context of the POST being dispatched (requestInfo)
  965. faceReq = null // the request context of the carrier whose inbound emit is being dispatched
  966. peerReq = {} // connection key → its upgrade request's context (requestInfo)
  967. adoptTokens = {} // one-time token → { sid, at }: a socket cannot set a cookie, so the page asks for it (/__hl/adopt)
  968. postHost = null // the host of the POST being dispatched
  969. faceInst = null // the BLANK instance the running face writes on (step 2 of #201): read back as the tab's delta
  970. faceKey = null
  971. faceSent = {} // name -> JSON of what the delta already carried, so a later flush sends only the change
  972. faceHost = null // the host of the carrier whose inbound emit is being dispatched
  973. postHeaders = null // the headers of the POST being dispatched (requestHeaders)
  974. faceHeaders = null // the headers of the carrier whose inbound emit is being dispatched
  975. // EXACTLY ONCE (COMPONENTS §10): a queued emit carries a stable id `q`, and the ids handled
  976. // are kept per session, the last `handledKept` of them (Session.handled). A connection
  977. // with no session keeps its ids here, in one list under the same bound.
  978. Number handledKept = 200
  979. anonHandled = []
  980. // WHAT A KEPT ID WAS ANSWERED (ticket #107). An emit in flight when its socket closed
  981. // is sent again with its id, and its caller is still waiting — for a page, say. The
  982. // first delivery's ack went out on the dead socket, so the repeat is answered from
  983. // here: `answers[session id + ' ' + q]` is that ack as sent (its `i` replaced), or
  984. // `running` while the first delivery has not finished, which answers the repeat
  985. // `later` and the client asks again. In memory, the last `handledKept` of them: a
  986. // repeat comes seconds after the first try, and a restart loses nothing a live peer
  987. // still waits for but the ack, which is then plain `ok`, as before.
  988. answers = {}
  989. answerKeys = []
  990. uploads = {} // 'u' + upload id → { sid, name, type, size, have, parts, at, key }: a file on its way in (ticket #94)
  991. uploadKeys = {} // 'k' + session id + ' ' + q + ' ' + n → the upload id the n-th file of emit q went up under
  992. uploadParts = {} // 'u' + id + ':' + n → the n-th part as it arrived, a Bytes
  993. // ONE PORT, TWO CARRIERS. hl:http1's WebSocket engine answers the Upgrade
  994. // inline on the port this server already bound, so `websocket` and `rest` are
  995. // the same listener — which is why the manifest can declare both for the same
  996. // direction and this file needs no second server.
  997. // EVERY VIEW IS BUILT AT BOOT, not at the first request for its route: a View that
  998. // reads a name its file declares nowhere (checkRead) is the app's mistake, and the
  999. // app does not start with it — the port is bound on the line below this pass.
  1000. // THE TWO DERIVATIONS MUST AGREE (mission 315). `served` is built above from the
  1001. // EVALUATED route table; `servedKeys(&graph)` derives the same set from the
  1002. // analysis alone, and the compiler bakes each module's text against the second.
  1003. // If they ever disagree the binary would serve modules generated against urls
  1004. // this server does not answer, so the disagreement is a refusal, here, at boot.
  1005. analysedKeys = servedKeys(&graph)
  1006. for (k of analysedKeys) {
  1007. if (served[k] == null) {
  1008. hlError('hl:web: the analysis says this app serves ' + k + ', the route walk did not — the two derivations of the served set disagree')
  1009. }
  1010. }
  1011. for (k of served.keys()) {
  1012. let seen = false
  1013. for (a of analysedKeys) { if (a == k) { seen = true } }
  1014. if (seen == false) {
  1015. let why = ''
  1016. for (imp of graph.files[k] != null ? [] : []) { why = why }
  1017. hlError('hl:web: the route walk serves ' + k + ', the analysis did not — the two derivations of the served set disagree')
  1018. }
  1019. }
  1020. routeNow = null
  1021. anon = null
  1022. for (k of served.keys()) { if (viewHandle(k) != 0) { tree(k) } }
  1023. // the compiler reads a kid mount's View through this (a mount no longer carries a copy of it)
  1024. compiler.treeOf = (key) => { return tree(key) }
  1025. // A COMPONENT-REFERENCE CYCLE IS REFUSED HERE (COMPONENTS §12): a View that renders
  1026. // itself, directly or through another, is a mount that never ends — it overflowed the
  1027. // stack at the first request and the server died of a segfault with nothing said
  1028. // (mission 322 row 1).
  1029. acyclic = {}
  1030. for (k of served.keys()) { if (viewHandle(k) != 0) { referenceCycle(k, [], []) } }
  1031. // …and a page a shell wraps is placed at the shell's slot, inside its body: a page whose
  1032. // root is `body` there emitted a second, nested <body> (mission 322 row 5)
  1033. for (k of mounted) {
  1034. if (graph.files[k] != null && graph.files[k].parent != null && viewHandle(k) != 0 && bodyRooted(k)) {
  1035. hlError("hl:web: " + k + " is wrapped by " + graph.files[k].parent + " (its `parent` clause), but its View's root is `body { … }`, the page's body: the shell owns the body, so write the page's root as an element (`main { … }`, `section { … }`)")
  1036. }
  1037. }
  1038. // THE SHEET IS WALKED AT BOOT, so the rules it drops are listed at boot (COMPONENTS §4,
  1039. // css.hl's own header): walked at the first request for it, a dead rule was listed only
  1040. // once some browser had asked, and a boot log said nothing (mission 322 row 11)
  1041. stylesheet()
  1042. // EVERY SERVED MODULE IS COMPILED AT BOOT: a free name in a View handler is a located
  1043. // compile error (COMPONENTS §6b), and compiled at the first request for the module it
  1044. // was a 500 behind a page that had already answered 200 (mission 322 row 14)
  1045. for (k of served.keys()) { module(k) }
  1046. // THE INTERFACE IS THE OPERATOR'S (ticket #24), on the ladder graph.zig's OperatorBind
  1047. // states: the constructor's `host` > HL_HOST (the binary fills it from HOST) > the
  1048. // manifest's > 0.0.0.0. Binding the default regardless put an app meant to sit behind
  1049. // a proxy on every interface of the machine.
  1050. if (host == null) { host = env('HL_HOST') }
  1051. if (host == null && cfg != null && cfg.host != null) { host = cfg.host }
  1052. if (host == null) { host = '0.0.0.0' }
  1053. // A --PORT AFTER THE ENTRY OUTRANKS THE APP'S OWN PORT (creator ruling
  1054. // 2026-09-27), but `port` ITSELF CANNOT SAY SO: the reference app passes an
  1055. // explicit `port = …` to `new WebFramework(…)` (server.hl, computed from
  1056. // HL_FW_PORT so a test run can sit beside a developer's own instance), which
  1057. // PINS the member for the whole construction (SPEC.md "The file root is the
  1058. // constructor" — "a root assignment to [a pinned] property… is a no-op").
  1059. // `port = port_arg` below was exactly that no-op: `hybriel server.hl
  1060. // --port=11499` still bound 44333, server.hl's own default, because this
  1061. // line's write never landed. `boundPort`, a plain local nothing ever pins,
  1062. // carries the actual ladder instead — CLI argument, else the (possibly
  1063. // pinned) member, else HL_PORT, else 8080 — and IS what binds and what the
  1064. // boot line names.
  1065. warnRemovedCaches()
  1066. let port_arg = portArgument()
  1067. let boundPort = port_arg
  1068. if (boundPort == null) { boundPort = port }
  1069. if (boundPort == null && env('HL_PORT') != null) { boundPort = toNumber(env('HL_PORT')) }
  1070. if (boundPort == null) { boundPort = 8080 }
  1071. http = new NativeWebSocketServer(port = boundPort, host = host)
  1072. echo 'framework listening on ' + boundPort
  1073. module('web/client.hl')
  1074. // ---- the browser's modules: compiled IN PROCESS, served from memory --------------
  1075. // The JavaScript target is this binary's own function (hlJs), the same one `--js`
  1076. // runs from the command line. No child process, no build directory.
  1077. //
  1078. // THE CLIENT is compiled at boot — every page needs it, and it carries the View
  1079. // and the Router with it (one module, three classes). A COMPONENT is compiled ON
  1080. // DEMAND, at the request for its own `.hl` url, and kept: a route nobody visits
  1081. // costs nothing, and the browser asks for a component's module the first time it
  1082. // mounts one.
  1083. //
  1084. // THE TABLE THE EMITTER WRITES IS DROPPED. `hlJs` puts each file's members,
  1085. // handlers and methods — every node of every initializer, with the names it reads —
  1086. // into the module, because the old hl:web's browser half reduces that table on every boot.
  1087. // This framework asked the same questions at COMPILE time and wrote the answers into
  1088. // the component's own statements, so the table is dead weight in the page: 58 KB of
  1089. // syntax on the reference app's home page alone. What the framework SERVES is its own
  1090. // text, so it leaves that statement out; the language is not asked to change, and
  1091. // The old hl:web kept its table untouched.
  1092. // THE TABLE STATEMENT'S NAME in this module: `hlTablesDef`, or in a compact module the
  1093. // alias its import clause gives it (`hlTablesDef as _51`). Each statement stands at the
  1094. // start of its own line, which is how it is found — an alias alone is a suffix of other
  1095. // names (`$_51(` is a compiler temporary).
  1096. tablesCall(text) {
  1097. let alias = text.indexOf('hlTablesDef as ')
  1098. if (alias < 0) { return newline + 'hlTablesDef(' }
  1099. let first = alias + 15
  1100. let stop = first
  1101. while (stop < text.length && text[stop] != ',' && text[stop] != '}') { stop = stop + 1 }
  1102. return newline + text.slice(first, stop) + '('
  1103. }
  1104. // the `fns` of the file's own table — the first table statement the module carries is
  1105. // the file's; the ones after it are the classes it bundles
  1106. tableFns(text) {
  1107. let at = text.indexOf(tablesCall(text))
  1108. if (at < 0) { return [] }
  1109. let open = text.indexOf('{', at)
  1110. let end = text.indexOf(');', at)
  1111. if (open < 0 || end < 0) { return [] }
  1112. let t = JSON.parse(text.slice(open, end))
  1113. return t.fns == null ? [] : t.fns
  1114. }
  1115. withoutTables(text) {
  1116. // one per FILE the module carries — the client half bundles three classes. A compact
  1117. // module calls it by its alias, and was served with every table until ticket #98's
  1118. // follow-up: 50 KB and more of syntax on a minified app's page
  1119. let call = tablesCall(text)
  1120. let out = text
  1121. let at = out.indexOf(call)
  1122. while (at >= 0) {
  1123. let end = out.indexOf(');', at)
  1124. if (end < 0) { return out }
  1125. // the newline before it stays: it ends the statement above
  1126. out = out.slice(0, at + 1) + out.slice(end + 2)
  1127. at = out.indexOf(call)
  1128. }
  1129. return out
  1130. }
  1131. // THE APP RUNS ON ONE WEB FRAMEWORK. Which packages are frameworks is READ OFF THE
  1132. // GRAPH and not off a list this file keeps: a package the app's entry reached that
  1133. // holds a `WebFramework.hl` is one. hl:dnd, hl:http1 and every other package an app
  1134. // imports hold none and are untouched by this.
  1135. //
  1136. // The refusal names the ROW of each import, because the mistake IS an import line —
  1137. // a sub-file import (`'hl:web/css'`) counts as much as the package itself, which is
  1138. // exactly the case that made it: a lone braced import of a stylesheet helper puts the
  1139. // whole package into the graph, and with it a second navigation face.
  1140. oneFrameworkOnly() {
  1141. let frameworks = {}
  1142. for (gk of graph.files.keys()) {
  1143. if (gk.startsWith('hl:') && gk.endsWith('/WebFramework.hl')) { frameworks[gk.slice(0, gk.length - 16)] = true }
  1144. }
  1145. if (frameworks.keys().length < 2) { return null }
  1146. // the first row of the app's OWN files that reached each package
  1147. let sites = {}
  1148. for (k of graph.files.keys()) {
  1149. if (!k.startsWith('hl:')) {
  1150. for (imp of graph.files[k].imports) {
  1151. for (pkg of frameworks.keys()) {
  1152. if (sites[pkg] == null && (imp.source == pkg || imp.source.startsWith(pkg + '/'))) {
  1153. sites[pkg] = { key = k; node = imp.node; where = k + ':' + imp.line + ':' + imp.col + " imports '" + imp.source + "'" }
  1154. }
  1155. }
  1156. }
  1157. }
  1158. }
  1159. let said = ''
  1160. for (pkg of frameworks.keys()) {
  1161. if (said != '') { said = said + ', and ' }
  1162. if (sites[pkg] == null) { said = said + "'" + pkg + "' (reached through a package, not from a file of the app)" }
  1163. else { said = said + sites[pkg].where }
  1164. }
  1165. let msg = 'this app imports TWO web frameworks: ' + said + '. Both packages load, both answer a page navigation, and the second one answers on a blank instance. An app runs on ONE of them — switch EVERY hl: import in EVERY file of the app to the same package, a sub-file import like \'/css\' included. Switching one line is not switching the app.'
  1166. // THE CARET GOES ON ONE OF THE ROWS, and the sentence names them all: two
  1167. // import lines are equally the mistake, and a diagnostic can only underline one.
  1168. for (pkg of frameworks.keys()) {
  1169. if (sites[pkg] != null) { hlSourceError(gen, sites[pkg].key, sites[pkg].node, msg) }
  1170. }
  1171. hlError(msg)
  1172. return null
  1173. }
  1174. // ONE ANSWERER PER VALUE-FORM EMIT. SPEC: "if more than one class in the destination
  1175. // realm declares a non-tap handler for the event, the VALUE form is refused at the emit
  1176. // site naming both. As a statement it stays a broadcast and every handler still fires."
  1177. // The statement form is what `inbound` does — every face runs. The value form cannot be
  1178. // told apart on the wire, so every `x = emit server ev()` the app's files hold is read
  1179. // off the analysis here, and one whose event two files answer is refused at its site,
  1180. // naming both, before anything is served. Until ticket #20 both faces ran and the first
  1181. // answer was taken in silence.
  1182. oneAnswererEach() {
  1183. let realm = serverRealm()
  1184. for (k of graph.files.keys()) {
  1185. if (!k.startsWith('hl:')) {
  1186. for (e of hlEvents(gen, k).emits) {
  1187. if (e.value == true && e.realm == realm) {
  1188. let owners = facesOf(e.event)
  1189. if (owners.length > 1) {
  1190. let named = ''
  1191. for (o of owners) { named = named == '' ? o : named + ' and ' + o }
  1192. let msg = "hl:web: " + k + ':' + e.line + ':' + e.col + " — this emit waits for the answer of '" + e.event + "', and " + owners.length + " files answer it in the '" + realm + "' realm: " + named + ". A value-form emit has ONE answerer — rename the event in one of them, or emit it as a statement (a broadcast every handler receives)"
  1193. hlSourceError(gen, k, e.node, msg)
  1194. hlError(msg)
  1195. }
  1196. }
  1197. }
  1198. }
  1199. }
  1200. return null
  1201. }
  1202. // WHAT THIS SERVER SERVES AS A MODULE OF ITS OWN, by the file's path (mission 314
  1203. // rule 0). Handed to `hlJs`, it is what turns `import PostCard from './post_card.hl'`
  1204. // into an ES import of `/components/post_card.hl` instead of PostCard's whole class
  1205. // text copied into the importing module — EditHistory's class shipped three times on
  1206. // the social demo's home page before this. The urls are THIS file's (`moduleUrl`);
  1207. // the compiler invents none, and a file this server does not answer for is inlined
  1208. // exactly as it always was.
  1209. servedModules() {
  1210. if (servedUrls == null) {
  1211. out = servedModulesOf(&graph)
  1212. for (k of served.keys()) { out[pathOf(k)] = modulePath(k) + buildMark }
  1213. servedUrls = out
  1214. }
  1215. return servedUrls
  1216. }
  1217. // A key the graph holds no file for is answered `null`, and the caller makes
  1218. // that a 404: a file the entry's closure never referenced is not part of this
  1219. // app, which is what keeps this from being a read of any path a url asks for.
  1220. module(key) {
  1221. if (modules[key] == null) {
  1222. let f = graph.files[key]
  1223. if (f == null) { return null }
  1224. // THE BROWSER GETS THE BROWSER'S PROJECTION, and nothing else. hlJs's
  1225. // fourth argument is the realm the module is produced for: a handler
  1226. // written `on server …` is not emitted at all, and a member whose
  1227. // initializer reaches a name the browser does not have is declared
  1228. // without one, for this server to lay over the instance with the state
  1229. // it already ships. The realm NAME comes off the manifest (clientRealm()
  1230. // above), never a literal — a project names its own realms.
  1231. // Coverage uses one unminified browser half; other modules retain app settings.
  1232. clientMin = key == 'hl:web/client.hl' && env('HL_TK_COVERAGE') != null ? false : minify
  1233. let text = hlJs(f.path, clientMin, runtimeSpec, clientRealm(), servedModules())
  1234. // AND THE COMPILE STEP'S OWN OUTPUT BESIDE IT (mission 313): a component with a
  1235. // View carries, after its class, the paint statements this framework compiled
  1236. // from that View — one per bound spot, with its read written in (compile.hl).
  1237. // The browser calls them instead of walking the tree at paint time. Text
  1238. // produced here and served from memory like the module itself; nothing is
  1239. // written to disk and no JavaScript file lives under plugins/.
  1240. // THE FUNCTION VALUES' SITES are the one part of that table the browser still
  1241. // needs (tickets #98, #99): the compile step turns them into write sets
  1242. let fns = tableFns(text)
  1243. text = withoutTables(text)
  1244. // Run registration only when this ES module is evaluated in the browser.
  1245. // A static initializer would also run while the server loads its graph.
  1246. if (key == 'hl:web/offline.hl') { text = text + newline + 'await Offline.register();' + newline }
  1247. if (key == 'hl:web/uploads.hl') { text = text + newline + 'await Uploads.register();' + newline }
  1248. if (viewHandle(key) != 0) {
  1249. let nodes = tree(key)
  1250. text = text + newline + compiler.module(gen, key, nodes, fns, fillsOf[key])
  1251. // THE COMPONENT'S BLUEPRINT COMES WITH ITS MODULE (W195): the structure the browser reads (`skeleton`), whether the
  1252. // component takes the route and which members the server computes. Not in the seed, so a page carries only the plans of
  1253. // components it uses. The elements, texts and attributes are not in it: the paint code above already holds them (W199).
  1254. let need = serverNeeds(key)
  1255. plan = { view = skeleton(&nodes); route = declares(key, 'route'); srv = need.sites.length > 0 ? need.reads : null; setters = setterNames(key); styleHandles = styleHandles(key); }
  1256. // Offline construction follows the same parent chain; it belongs to the module, not every seed.
  1257. if (offlineKeys != null && graph.files[key].parent != null) { plan.parent = graphModuleKey(graph.files[key].parent) }
  1258. text = text + ';(globalThis.__hlB=globalThis.__hlB||{})[' + JSON.stringify(graphModuleKey(key)) + ']=' + JSON.stringify(plan) + ';' + newline
  1259. }
  1260. modules[key] = text
  1261. }
  1262. return modules[key]
  1263. }
  1264. // WHAT THE BROWSER READS OF A VIEW TREE besides the paint code (W199): the composed children with their bindings and fill (it
  1265. // mints and re-binds them), the `for`s (their site and the list they iterate, which decides whether a child is repainted or
  1266. // composed anew) and the `if`s that hold one of those. An element stands for nothing but the place of its children, so the
  1267. // elements go and their children move up; texts, attributes, handlers and styles are in the compiled paint code and not here.
  1268. skeleton(&nodes) {
  1269. let out = []
  1270. for (n of nodes) {
  1271. if (n.k == 'el') { for (c of skeleton(&n.children)) { out.push(c) } }
  1272. else if (n.k == 'component') { out.push({ k = 'component'; path = n.path; bindings = n.bindings; fill = skeleton(&n.fill); }) }
  1273. else if (n.k == 'for') { out.push({ k = 'for'; site = n.site; list = n.list; body = skeleton(&n.body); }) }
  1274. else if (n.k == 'if') {
  1275. let t = skeleton(&n.then)
  1276. let o = skeleton(&n.other)
  1277. if (t.length > 0 || o.length > 0) { out.push({ k = 'if'; site = n.site; then = t; other = o; }) }
  1278. }
  1279. }
  1280. return out
  1281. }
  1282. // the file the graph knows under this key — the graph carries every file's own path
  1283. pathOf(key) {
  1284. let f = graph.files[key]
  1285. if (f == null) { hlError('the graph holds no file ' + key + ' — nothing referenced it from the entry') }
  1286. return f.path
  1287. }
  1288. // THE BROWSER'S REALM, off the manifest: the realm whose declared entrypoint is
  1289. // this framework's client half. The framework's own two files ARE the two
  1290. // realms' entrypoints, so this is a lookup and never a guess.
  1291. clientRealm() {
  1292. for (name of graph.realms.keys()) {
  1293. if (graph.realms[name].entrypoint == 'hl:web/client.hl') { return name }
  1294. }
  1295. hlError('the manifest declares no realm whose entrypoint is ./client.hl — the browser half of this framework IS a realm, and a page cannot say which realm it is running in until the manifest names it')
  1296. }
  1297. // THIS realm, off the graph: the declared realm whose entrypoint REACHES this
  1298. // file (the app's entry imports it). A face names it, and so does the refusal
  1299. // when nothing answers.
  1300. serverRealm() {
  1301. let mine = graph.files['hl:web/WebFramework.hl'].realms
  1302. if (mine.length == 1) { return mine[0] }
  1303. hlError('the manifest declares no realm whose entrypoint reaches hl:web/WebFramework.hl — this file cannot dispatch a face without knowing which realm it is')
  1304. }
  1305. // the app's directory: a route component is the app's file, its key project-relative
  1306. projectRoot() {
  1307. for (r of routes) {
  1308. if (r.component != null) { return rootOf(keyOf(r.component)) }
  1309. }
  1310. // AN APP OF FUNCTION ROUTES ONLY (ticket #19) has no component to read it off, and
  1311. // needs no other: the manifest is the app's file too, and the graph knows its key
  1312. if (graph.manifest.file != null && graph.files[graph.manifest.file] != null) { return rootOf(graph.manifest.file) }
  1313. hlError('hl:web: the route table names no component and the graph names no manifest file, so the app\'s directory cannot be read off either')
  1314. }
  1315. // a project-relative key against its absolute path: what is left is the project's directory
  1316. rootOf(key) {
  1317. let path = pathOf(key)
  1318. // A COMPILED BINARY'S PATH IS ITS KEY (mission 318): it carries no
  1319. // build directory, so the file's path and its key are the same
  1320. // string and the root is the process's own directory. The
  1321. // interpreter's path is the script's absolute one, and the key is
  1322. // its tail — the root is what stands before it.
  1323. if (path == key) { return '.' }
  1324. return path.slice(0, path.length - key.length - 1)
  1325. }
  1326. // THE KEY OF A FILE THE APP NAMED — as the class it imported (`component = SortList`,
  1327. // `styles = Styles`: the import is the guarantee the graph reached it) or as a path
  1328. // ('./components/home.hl'). A class knows its file (`file(cls)`), and the graph knows
  1329. // the file's key.
  1330. keyOf(named) {
  1331. if (hlTypeName(named) == 'Class') {
  1332. let path = file(named)
  1333. for (k of graph.files.keys()) {
  1334. if (graph.files[k].path == path) { return k }
  1335. }
  1336. hlError('hl:web: the class at ' + path + ' is not in the project graph — import it from the app\'s entry')
  1337. }
  1338. // ANYTHING ELSE NAMES NO FILE (ticket #12): `styles = {}` booted and every request
  1339. // for the stylesheet was then a NotCallable on this line, with no line of the app's
  1340. if (hlTypeName(named) != 'String') { hlError("hl:web: a file the app names — a route's component, or `styles` — is the class it imported or a path string ('./styles.hl'), and this one is a " + hlTypeName(named)) }
  1341. if (named.startsWith('./')) { return named.slice(2) }
  1342. return named
  1343. }
  1344. // ---- the View tree: the member's syntax, reflected into plain hybrids ----------
  1345. viewHandle(key) {
  1346. for (m of hlMembers(gen, key)) {
  1347. if (m.name == 'View') { return m.node }
  1348. }
  1349. return 0
  1350. }
  1351. tree(key) {
  1352. treeLoad(key)
  1353. return trees[key]
  1354. }
  1355. // THE TREE IS BUILT ONCE PER KEY and read in place afterwards (`&trees[key]`): `tree(key)` hands out a COPY of the whole
  1356. // View tree on each call, and a mount, a render and a seed each asked for one (W116)
  1357. treeLoad(key) {
  1358. if (trees[key] != null) { return null }
  1359. let handle = viewHandle(key)
  1360. if (handle == 0) { hlError('component ' + key + ' declares no View') }
  1361. let v = hlSyntax(gen, key, handle)
  1362. let nodes = []
  1363. let fills = []
  1364. for (h of v.entries) {
  1365. let n = node(key, h, [], false, [])
  1366. // A NAMED REGION'S FILL (D-CHAIN addendum): `side { … }` at this View's root, where a level
  1367. // above declares `slot { name = 'side' … }`, is the content of THAT region and not of this
  1368. // page's own column: the region renders it, in this page's frame (compile.hl skips it here)
  1369. if (n != null && n.k == 'if' && n.regionfill != null) { fills.push({ name = n.regionfill; site = n.site; children = n.then; cond = null; }) }
  1370. // A CONDITIONAL FILL: `if (x) { side { … } }` at the View root fills while x holds (the default
  1371. // stands otherwise); the `if` itself stays in the page's tree (its branch holds the fill's
  1372. // components for the mounts, and the browser's `if` site is what hears x change)
  1373. else if (n != null && n.k == 'if' && n.region == null) {
  1374. for (c of n.then) {
  1375. if (c.k == 'if' && c.regionfill != null) { fills.push({ name = c.regionfill; site = c.site; children = c.then; cond = n.cond; }) }
  1376. }
  1377. }
  1378. if (n != null) { nodes.push(n) }
  1379. }
  1380. for (n of nodes) {
  1381. if (n.k == 'if' && n.regionfill == null && n.region == null) {
  1382. strayFill(key, n.then, true)
  1383. strayFill(key, n.other, false)
  1384. } else if (n.regionfill == null) { strayFill(key, [n], false) }
  1385. }
  1386. fillsOf[key] = fills
  1387. trees[key] = nodes
  1388. return null
  1389. }
  1390. // a fill standing anywhere but a View's root (or the root-level `if` that makes it conditional) is
  1391. // refused where it stands, rather than left to render nothing
  1392. strayFill(key, nodes, direct) {
  1393. for (n of nodes) {
  1394. if (n.k == 'if' && n.regionfill != null) {
  1395. if (!direct) { hlError('hl:web: ' + n.site + " — a region's fill (`" + n.regionfill + " { … }`) stands at a View's root or directly inside a root-level `if`; this one stands deeper (inside a nested `if`, an `else` or an element)") }
  1396. }
  1397. else if (n.k == 'if') { strayFill(key, n.then, false) strayFill(key, n.other, false) }
  1398. else if (n.k == 'el') { strayFill(key, n.children, false) }
  1399. else if (n.k == 'for') { strayFill(key, n.body, false) }
  1400. else if (n.k == 'component' && n.fill != null) { strayFill(key, n.fill, false) }
  1401. }
  1402. return null
  1403. }
  1404. // whether a node list holds a component anywhere (a region default that does is mounted late)
  1405. holdsComponent(nodes) {
  1406. for (n of nodes) {
  1407. if (n.k == 'component') { return true }
  1408. if (n.k == 'el' && holdsComponent(n.children)) { return true }
  1409. if (n.k == 'if' && (holdsComponent(n.then) || holdsComponent(n.other))) { return true }
  1410. if (n.k == 'for' && holdsComponent(n.body)) { return true }
  1411. }
  1412. return false
  1413. }
  1414. // the named regions the levels ABOVE this file declare (`slot { name = 'side' … }`)
  1415. regionsAbove(key) {
  1416. let out = []
  1417. let w = hlFile(gen, key).wrapper
  1418. let guard = 0
  1419. while (w != null && guard < 64) {
  1420. regionNamesIn(&out, tree(w))
  1421. w = hlFile(gen, w).wrapper
  1422. guard = guard + 1
  1423. }
  1424. return out
  1425. }
  1426. regionNamesIn(&out, nodes) {
  1427. for (n of nodes) {
  1428. if (n.k == 'if') {
  1429. if (n.region != null) { out.push(n.region) }
  1430. regionNamesIn(&out, n.then)
  1431. regionNamesIn(&out, n.other)
  1432. }
  1433. else if (n.k == 'el') { regionNamesIn(&out, n.children) }
  1434. else if (n.k == 'for') { regionNamesIn(&out, n.body) }
  1435. else if (n.k == 'component' && n.fill != null) { regionNamesIn(&out, n.fill) }
  1436. }
  1437. return null
  1438. }
  1439. // one entry of a hybrid literal → a tree node (null for an attribute: the
  1440. // element that owns it reads it)
  1441. node(key, handle, path, inFor, rows) {
  1442. let n = hlSyntax(gen, key, handle)
  1443. if (n == null) { return null }
  1444. if (n.tag == 'object_property') {
  1445. let v = hlSyntax(gen, key, n.value)
  1446. if (v.tag == 'object_expression') {
  1447. // A NAMED REGION: `slot { name = 'side' <default> }` is a region a lower level may fill
  1448. // (an `if` that always stands, carrying its name: the walkers already know the shape);
  1449. // `side { … }` at a View's root where a level above declares it is that region's fill
  1450. if (n.key == 'slot') {
  1451. let rname = regionName(key, v)
  1452. if (rname != null) {
  1453. let el = element(key, 'slot', v, path, inFor, rows)
  1454. let kids = []
  1455. for (c of el.children) { kids.push(c) }
  1456. return { k = 'if'; region = rname; deferred = holdsComponent(kids); cond = { k = 'text'; text = 'true'; kind = 'boolean'; }; then = kids; other = []; site = el.site; }
  1457. }
  1458. }
  1459. if (inFor && path.length == 0 && componentKeyOf(key, n.key) == null && regionsAbove(key).includes(n.key)) {
  1460. hlError('hl:web: ' + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — a region's fill (`" + n.key + " { … }`) cannot stand inside a `for`: a fill stands at a View's root, or directly inside a root-level `if`")
  1461. }
  1462. if (path.length == 0 && !inFor && componentKeyOf(key, n.key) == null && regionsAbove(key).includes(n.key)) {
  1463. let el = element(key, n.key, v, path, inFor, rows)
  1464. // (an `if` that never renders in this column, so every walk of the tree that finds the
  1465. // components standing in it — mounts, seed, browser — sees them as it does an `if`'s)
  1466. return { k = 'if'; regionfill = n.key; cond = { k = 'text'; text = 'true'; kind = 'boolean'; }; then = el.children; other = []; site = el.site; }
  1467. }
  1468. let childKey = componentKeyOf(key, n.key)
  1469. if (childKey != null) { return component(key, n.key, childKey, v, v, path, inFor, rows) }
  1470. return element(key, n.key, v, path, inFor, rows)
  1471. }
  1472. return null
  1473. }
  1474. if (n.tag == 'literal') { return { k = 'text'; text = n.text; kind = n.kind; } }
  1475. if (n.tag == 'identifier') {
  1476. // A BARE CAPITALISED REFERENCE IS A COMPOSITION WITH AN EMPTY FILL (§12:
  1477. // "`Name { }` is the same reference as bare `Name`"). It is not a read, so it
  1478. // is answered before the read rules below refuse the name.
  1479. let bareKey = componentKeyOf(key, n.name)
  1480. if (bareKey != null) { return component(key, n.name, bareKey, null, n, path, inFor, rows) }
  1481. if (n.name == 'slot') { oneSlot(key, n) }
  1482. // AN IMPORTED STATIC IN A VIEW IS FOLDED (the archive did the same at build):
  1483. // `h1 { siteTitle }` with `import { siteTitle } from '../store.hl'` is not a
  1484. // member of this class, it is a constant of another file — read off that
  1485. // file's class once, here, and written into the tree as text
  1486. return nameRead(key, n.name, rows, n)
  1487. }
  1488. if (n.tag == 'view_for') {
  1489. // `for (row of list) { … }` — the list is a member (or a row field), the
  1490. // body's entries are rendered once per entry with `row` bound to it
  1491. let body = hlSyntax(gen, key, n.body)
  1492. let children = []
  1493. // THE ROW VARIABLE IS IN SCOPE INSIDE THE BODY, and nowhere else: the list is
  1494. // read in the scope that stands around the `for`
  1495. let list = ref(key, n.list, rows)
  1496. let inner = rows.slice(0)
  1497. inner.push(n.varName)
  1498. for (h of body.entries) {
  1499. let c = node(key, h, path, true, inner)
  1500. if (c != null) { children.push(c) }
  1501. }
  1502. // THE SITE, as every element node carries one: the id the module's tables
  1503. // file this `for`'s row under, so the browser reads what the list depends
  1504. // on from the compiler instead of guessing it off `list.name`.
  1505. return { k = 'for'; row = n.varName; list = list; body = children; site = baseName(pathOf(key)) + ':' + n.line + ':' + n.col; }
  1506. }
  1507. if (n.tag == 'view_if') {
  1508. let then = []
  1509. let cons = hlSyntax(gen, key, n.consequent)
  1510. for (h of cons.entries) {
  1511. let c = node(key, h, path, inFor, rows)
  1512. if (c != null) { then.push(c) }
  1513. }
  1514. let other = []
  1515. let alt = hlSyntax(gen, key, n.alternate) // null when there is no else
  1516. if (alt != null) {
  1517. if (alt.tag == 'view_if') {
  1518. other.push(node(key, n.alternate, path, inFor, rows))
  1519. } else {
  1520. for (h of alt.entries) {
  1521. let c = node(key, h, path, inFor, rows)
  1522. if (c != null) { other.push(c) }
  1523. }
  1524. }
  1525. }
  1526. // A BRANCH CONDITION IS A READ (COMPONENTS: a member or a loop path).
  1527. // Anything else came back null here and the branch rendered nothing, on the
  1528. // server and after hydration, with no word said (ticket #17: `if (!flag)`).
  1529. let cond = ref(key, n.condition, rows)
  1530. // …or a COMPARISON of such a read with a literal (`x != ''`, `row.state == 'open'`,
  1531. // `count > 3`), or a `!` of a read or of one (hybriel#287): the same expression
  1532. // tree a View text holds, so the server and the browser evaluate one thing
  1533. if (cond == null && simpleCondition(key, n.condition, rows)) {
  1534. let names = []
  1535. cond = { k = 'expr'; x = exprTree(key, n.condition, rows, &names); names = names; }
  1536. }
  1537. if (cond == null) {
  1538. let c = hlSyntax(gen, key, n.condition)
  1539. hlError("hl:web: " + baseName(pathOf(key)) + ':' + c.line + ':' + c.col + " — a View `if` takes a member, a field path or a `for` row variable as its condition, and this one is an expression: declare it at the root of " + baseName(pathOf(key)) + " (`showIt = !flag`) and write `if (showIt)`")
  1540. }
  1541. return { k = 'if'; cond = cond; then = then; other = other; site = baseName(pathOf(key)) + ':' + n.line + ':' + n.col; }
  1542. }
  1543. if (n.tag == 'member_expression') {
  1544. // `p.title` — a field path off a member or a row variable
  1545. let r = ref(key, handle, rows)
  1546. if (r != null) { return r }
  1547. }
  1548. if (n.tag == 'binary_expression' || n.tag == 'unary_expression' || n.tag == 'conditional_expression') {
  1549. // AN EXPRESSION IN A VIEW: its tree, and the names it reads (what repaints it)
  1550. let names = []
  1551. let x = exprTree(key, handle, rows, &names)
  1552. return { k = 'expr'; x = x; names = names; }
  1553. }
  1554. if (n.tag == 'on_statement') {
  1555. // a DOM event handled by the literal that carries it: the browser finds the
  1556. // literal in the instance's View by the path of keys and fires the event at it
  1557. // THE SITE IS THE HANDLER'S ID: the tables file this handler's write set
  1558. // under it, and the browser repaints exactly those members when it runs.
  1559. return { k = 'on'; event = n.event; site = baseName(pathOf(key)) + ':' + n.line + ':' + n.col; }
  1560. }
  1561. return { k = 'other'; tag = n.tag; }
  1562. }
  1563. // the literal name of a `slot { name = 'side' … }` region, null for anything else
  1564. regionName(key, v) {
  1565. for (h of v.entries) {
  1566. let e = hlSyntax(gen, key, h)
  1567. if (e.tag == 'object_property' && e.key == 'name') {
  1568. let val = hlSyntax(gen, key, e.value)
  1569. if (val.tag == 'literal' && val.kind == 'string') { return val.text }
  1570. }
  1571. }
  1572. return null
  1573. }
  1574. // A COMPONENT HAS EXACTLY ONE SLOT (COMPONENTS §2 table, §12): a second one rendered the
  1575. // child a second time, with no word said (mission 322 row 4)
  1576. oneSlot(key, n) {
  1577. let here = baseName(pathOf(key)) + ':' + n.line + ':' + n.col
  1578. if (slotAt[key] != null) {
  1579. hlError("hl:web: " + here + " — a second `slot` in this View (the first is at " + slotAt[key] + "): a component has exactly one slot, where the page it wraps or the fill it is given renders")
  1580. }
  1581. slotAt[key] = here
  1582. return null
  1583. }
  1584. isMember(key, name) {
  1585. for (m of hlMembers(gen, key)) { if (m.name == name) { return true } }
  1586. return false
  1587. }
  1588. // THE READ OF A BARE NAME IN A VIEW — wherever the name stands. A text child, an
  1589. // attribute's value and a reference-site binding are ONE lookup with ONE refusal:
  1590. //
  1591. // a `for` row variable standing around the read → read at render, from the row
  1592. // a member of this file → read at render, from the instance
  1593. // a name this file imports by BRACE → a STATIC of another file:
  1594. // constant-folded here, at build
  1595. // anything else → the located refusal (checkRead)
  1596. //
  1597. // An ATTRIBUTE used to skip the middle two and record every name as a member read,
  1598. // so `a { href = brandHref }` on a braced import asked the instance for a member it
  1599. // does not have and the renderer raised error.UndefinedProperty with view.hl's line
  1600. // and nothing of the app's — while the same name as a TEXT CHILD rendered fine
  1601. // (creator, routger migration W8). A read is a read; where it stands decides
  1602. // nothing about what it names.
  1603. nameRead(key, name, rows, at) {
  1604. if (rows != null && rows.includes(name)) { return { k = 'member'; name = name; } }
  1605. if (isMember(key, name)) { return { k = 'member'; name = name; } }
  1606. // A BRACED IMPORT FOLDS EVEN WHEN ITS VALUE IS NULL: the name resolved, so the
  1607. // read is answered here and never reaches the instance (a null static used to
  1608. // fall through to a member read and raise the same UndefinedProperty).
  1609. if (importsName(key, name)) {
  1610. let folded = importedStatic(key, name)
  1611. // THE VALUE AS WELL AS THE TEXT: an attribute and a text child want the text,
  1612. // and a reference binding wants the value the author's file declared (§12)
  1613. return { k = 'text'; text = folded == null ? '' : '' + folded; kind = 'folded'; value = folded; }
  1614. }
  1615. checkRead(key, name, rows, at)
  1616. return { k = 'member'; name = name; }
  1617. }
  1618. // A VIEW READS ONLY WHAT ITS FILE DECLARES. A name that is neither a member of
  1619. // this class, nor a static it imports by brace, nor a `for` row variable standing
  1620. // around this read, is a typo or a missing declaration — refused HERE, at the
  1621. // build of the tree (boot), naming the file and the line, instead of a 500 out of
  1622. // the renderer with the language's UndefinedProperty and no line of the app's.
  1623. checkRead(key, name, rows, n) {
  1624. if (name == '$parent') { return null }
  1625. if (rows != null && rows.includes(name)) { return null }
  1626. if (isMember(key, name)) { return null }
  1627. if (importsName(key, name)) { return null }
  1628. let hint = name == 'session' ? "`session = null` to receive the connection's session" : name == 'host' ? "`host = null` to receive the request's host" : name == 'headers' ? "`headers = null` to receive the request's headers" : name == 'route' ? "`route = null` to receive the matched route" : "`" + name + " = null`"
  1629. hlError("hl:web: " + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — the View reads '" + name + "', which this file declares nowhere: declare it at the file's root (" + hint + "), or write the name it was meant to be")
  1630. }
  1631. // does this file import that name by brace from another file?
  1632. \* `--port=N` or `--port N` among the program's arguments, or null. *\
  1633. portArgument() {
  1634. let given = args()
  1635. let i = 0
  1636. while (i < given.length) {
  1637. let a = given[i]
  1638. let text = null
  1639. if (a.startsWith('--port=')) {
  1640. text = a.slice(7)
  1641. } else if (a == '--port' && i + 1 < given.length) {
  1642. text = given[i + 1]
  1643. }
  1644. if (text != null) {
  1645. let digits = text.length > 0 && text.length <= 5
  1646. let b = toBytes(text)
  1647. let k = 0
  1648. while (k < b.length) {
  1649. if (b[k] < 48 || b[k] > 57) { digits = false }
  1650. k = k + 1
  1651. }
  1652. if (!digits || toNumber(text) > 65535) {
  1653. hlError("hl:web: invalid --port value '" + text + "' — a port is a number 0-65535")
  1654. }
  1655. return toNumber(text)
  1656. }
  1657. i = i + 1
  1658. }
  1659. return null
  1660. }
  1661. importsName(key, name) {
  1662. for (imp of graph.files[key].imports) {
  1663. if (imp.key != null && memberOfImport(imp, name) != null) { return true }
  1664. }
  1665. return false
  1666. }
  1667. // the member of the imported file that the name `name` is bound to here, or null:
  1668. // the name itself, or what `import { a as name }` selected (#142)
  1669. memberOfImport(imp, name) {
  1670. if (imp.locals == null) { return imp.names.includes(name) ? name : null }
  1671. let i = 0
  1672. while (i < imp.locals.length) {
  1673. if (imp.locals[i] == name) { return imp.names[i] }
  1674. i = i + 1
  1675. }
  1676. return null
  1677. }
  1678. // the value of a static this file imports by brace from another .hl file, or null —
  1679. // read off an instance of that file (a class value takes no computed index, an
  1680. // instance does; the file is constructed once, its statics were evaluated at load)
  1681. importedStatic(key, name) {
  1682. for (imp of graph.files[key].imports) {
  1683. let member = imp.key != null ? memberOfImport(imp, name) : null
  1684. if (member != null) {
  1685. if (staticHolders[imp.key] == null) { staticHolders[imp.key] = construct(imp.key, constructionArgs(imp.key, {}, anonSession(), null, null)) }
  1686. return staticHolders[imp.key][member]
  1687. }
  1688. }
  1689. return null
  1690. }
  1691. // THE TREE OF A VIEW EXPRESSION: operators, literals and reads — evaluated by view.hl's
  1692. // `evalExpr`, with the language's own operators. `names` collects the members it reads.
  1693. exprTree(key, handle, rows, &names) {
  1694. let n = hlSyntax(gen, key, handle)
  1695. if (n.tag == 'literal') { return { k = 'text'; text = n.text; kind = n.kind; } }
  1696. if (n.tag == 'identifier') {
  1697. let r = nameRead(key, n.name, rows, n)
  1698. if (r.k == 'member' && !names.includes(r.name)) { names.push(r.name) }
  1699. return r
  1700. }
  1701. if (n.tag == 'member_expression' && !n.computed) {
  1702. let r = ref(key, handle, rows)
  1703. if (r != null) {
  1704. if (!names.includes(r.name)) { names.push(r.name) }
  1705. return r
  1706. }
  1707. }
  1708. if (n.tag == 'binary_expression') {
  1709. return { k = 'bin'; op = n.operator; l = exprTree(key, n.left, rows, &names); r = exprTree(key, n.right, rows, &names); }
  1710. }
  1711. if (n.tag == 'unary_expression') {
  1712. return { k = 'un'; op = n.operator; x = exprTree(key, n.operand, rows, &names); }
  1713. }
  1714. if (n.tag == 'conditional_expression') {
  1715. return { k = 'cond'; c = exprTree(key, n.condition, rows, &names); a = exprTree(key, n.consequent, rows, &names); b = exprTree(key, n.alternate, rows, &names); }
  1716. }
  1717. hlError("hl:web: " + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — a View expression holds names, literals, member paths and operators; a " + n.tag + " is none of those — declare it at the root of " + baseName(pathOf(key)) + " and write its name")
  1718. }
  1719. // is this a View `if` condition beyond a plain read that is still allowed (hybriel#287): a
  1720. // comparison of a read (member, field path, row variable) with a literal, either side, or
  1721. // a `!` of a read or of such a comparison
  1722. simpleCondition(key, handle, rows) {
  1723. let n = hlSyntax(gen, key, handle)
  1724. if (n == null) { return false }
  1725. if (n.tag == 'unary_expression') {
  1726. if (n.operator != 'logical_not') { return false }
  1727. return ref(key, n.operand, rows) != null || simpleCondition(key, n.operand, rows)
  1728. }
  1729. if (n.tag != 'binary_expression') { return false }
  1730. if (!['equal', 'not_equal', 'less_than', 'less_equal', 'greater_than', 'greater_equal'].includes(n.operator)) { return false }
  1731. let l = hlSyntax(gen, key, n.left)
  1732. let r = hlSyntax(gen, key, n.right)
  1733. if (l == null || r == null) { return false }
  1734. if (l.tag == 'literal') { return r.tag != 'literal' && ref(key, n.right, rows) != null }
  1735. if (r.tag == 'literal') { return ref(key, n.left, rows) != null }
  1736. return false
  1737. }
  1738. // a READ in the View: a member (`title`), or a field path (`p.title`) whose root
  1739. // is a member or a `for` row variable — the client decides which at render time
  1740. ref(key, handle, rows) {
  1741. let n = hlSyntax(gen, key, handle)
  1742. if (n.tag == 'identifier') { checkRead(key, n.name, rows, n) return { k = 'member'; name = n.name; } }
  1743. // A LIST WRITTEN IN PLACE (`for (n of [1, 2])`) is a literal, read as its value: the
  1744. // same folded 'text' node a folded static is, so every reader takes it the way it takes
  1745. // that one. Its entries are literals — anything else has no value before a read.
  1746. if (n.tag == 'array_expression') {
  1747. let items = []
  1748. for (e of n.elements) {
  1749. let el = hlSyntax(gen, key, e)
  1750. if (el == null || el.tag != 'literal') {
  1751. hlError("hl:web: " + baseName(pathOf(key)) + ':' + n.line + ':' + n.col + " — a list written in a View can hold literals only; declare it as a member to loop over anything else")
  1752. }
  1753. items.push(viewRead.literalValue(el.kind, el.text))
  1754. }
  1755. return { k = 'text'; text = ''; kind = 'folded'; value = items; }
  1756. }
  1757. if (n.tag == 'member_expression' && !n.computed) {
  1758. let obj = hlSyntax(gen, key, n.object)
  1759. let prop = hlSyntax(gen, key, n.property)
  1760. if (obj.tag == 'identifier') { checkRead(key, obj.name, rows, obj) return { k = 'field'; name = obj.name; path = [prop.name]; } }
  1761. let inner = ref(key, n.object, rows)
  1762. if (inner != null && inner.k == 'field') {
  1763. let path = inner.path.slice(0)
  1764. path.push(prop.name)
  1765. return { k = 'field'; name = inner.name; path = path; }
  1766. }
  1767. }
  1768. return null
  1769. }
  1770. // THE COMPOSED CHILD: an entry named after a class the file imports, whose file
  1771. // has a View. `Child { count = count on done(v) { … } }` — the entries are the
  1772. // BINDINGS (host values handed to the child's construction as named arguments)
  1773. // and the reference-site handlers. The graph says which name is which file.
  1774. componentKeyOf(key, name) {
  1775. for (imp of graph.files[key].imports) {
  1776. if (imp.default == name && imp.key != null && viewHandle(imp.key) != 0) { return imp.key }
  1777. }
  1778. return null
  1779. }
  1780. // THE REFERENCE'S SITE IS IN ITS PATH. A path of class names alone made two
  1781. // references of one class under one parent (`body/Card` twice) the SAME node key,
  1782. // so both collapsed onto one mount and one of the two fills was lost. A reference
  1783. // is a construction: each one is its own mount, so each one is its own path.
  1784. componentStep(cls, at) {
  1785. return cls + '@' + at.line + ':' + at.col
  1786. }
  1787. // is this entry a `Style.rule` reference? (the `Style` of THIS file, by name)
  1788. styleRef(key, e) {
  1789. let obj = hlSyntax(gen, key, e.object)
  1790. return obj.tag == 'identifier' && obj.name == 'Style'
  1791. }
  1792. // THE REFERENCE'S POSITIONAL SIGNATURE (§12: "a reference is a construction, so its
  1793. // POSITIONAL entries bind to the class's declared properties in declaration order —
  1794. // the same rule `new X(a, b)` follows").
  1795. //
  1796. // MEASURED, not guessed (2026-09-13, this worker): `new X(a, b, …)` fills the class's
  1797. // root PROPERTY DECLARATIONS in SOURCE ORDER, one slot each — `on` handlers and
  1798. // methods take no slot, and `hlMembers` returns exactly that list in exactly that
  1799. // order, so the tree builder reads the signature straight off it. Three of those
  1800. // declarations are not properties of the COMPOSITION and are left out here:
  1801. //
  1802. // `View` and `Style` — what the component renders and paints WITH, not what it is
  1803. // constructed from. The language does give them a slot (a
  1804. // bare `new` binds them), but §12 says `Card { "text" }` with
  1805. // no declared property takes its text as FILL, and a
  1806. // component always declares a View: counting it would make
  1807. // the positional-literal fill unreachable in every component
  1808. // there is.
  1809. // `slot` — the late-bound child, not state (§12); and with the fill
  1810. // rendered where the child places it the two readings emit
  1811. // the same HTML anyway.
  1812. // every `static` — a static belongs to the CLASS (§12 build-time constants), so
  1813. // a reference cannot seed one for every other reference.
  1814. //
  1815. // A NAMED assignment does NOT free its slot — measured: `new Q('n1', beta = 'B', 'n2')`
  1816. // puts 'n2' in the SECOND declaration and 'B' in beta. It is applied AFTER the
  1817. // positional ones and wins, which is why the positional bindings are emitted first
  1818. // below. (COMPONENTS.md:711 reads "a property the reference also assigns by name is
  1819. // not in the signature"; the interpreter says otherwise and the parenthetical in the
  1820. // same line — "named is applied after positional; the name wins, as in `new`" — is
  1821. // what this follows.)
  1822. positionalSignature(key) {
  1823. let out = []
  1824. for (m of hlMembers(gen, key)) {
  1825. if (!m.isStatic && m.name != 'View' && m.name != 'Style' && m.name != 'slot') { out.push(m.name) }
  1826. }
  1827. return out
  1828. }
  1829. component(key, cls, childKey, v, at, path, inFor, rows) {
  1830. let bindings = []
  1831. let positional = []
  1832. let ons = []
  1833. let fill = []
  1834. let here = path.slice(0)
  1835. here.push(componentStep(cls, at))
  1836. let sig = positionalSignature(childKey)
  1837. let taken = 0
  1838. if (v != null) {
  1839. for (h of v.entries) {
  1840. let e = hlSyntax(gen, key, h)
  1841. if (e.tag == 'object_property') {
  1842. let val = hlSyntax(gen, key, e.value)
  1843. // A BINDING NAMES A DECLARED MEMBER OF THE CHILD (COMPONENTS §12): the value
  1844. // otherwise went into the construction and nowhere, with no word said
  1845. // (mission 322 row 12). An element entry is the fill, not a binding.
  1846. if (val.tag != 'object_expression' && !isMember(childKey, e.key)) {
  1847. hlError("hl:web: " + baseName(pathOf(key)) + ':' + e.line + ':' + e.col + " — " + cls + " has no member '" + e.key + "' to bind: " + baseName(pathOf(childKey)) + " declares " + positionalSignature(childKey).join(', '))
  1848. }
  1849. // A LITERAL ON A REFERENCE KEEPS ITS TYPE (§12 "typed, not stringified"):
  1850. // the binding carries the literal's KIND, and `view.refValue` turns the
  1851. // pair into the value the child's member is given. Written as text alone,
  1852. // `Level2 { n = 1 }` handed the child the String "1" and `n * 97` refused
  1853. // (measured 2026-09-14, demo-nested wall 3).
  1854. if (val.tag == 'literal') { bindings.push({ name = e.key; text = val.text; kind = val.kind; }) }
  1855. else if (val.tag == 'identifier') {
  1856. // a binding is a read at the reference site, so it is the same lookup
  1857. let r = nameRead(key, val.name, rows, val)
  1858. // …and a folded static crosses as its VALUE, for the same reason
  1859. if (r.k == 'text') { bindings.push({ name = e.key; text = r.text; kind = 'folded'; value = r.value; }) }
  1860. else { bindings.push({ name = e.key; member = val.name; }) }
  1861. }
  1862. else if (val.tag == 'member_expression') { bindings.push({ name = e.key; ref = ref(key, e.value, rows); }) }
  1863. else {
  1864. // `Card { span { … } }` — an element entry is not a binding, it is the FILL
  1865. let c = node(key, h, here, inFor, rows)
  1866. // …and an EXPRESSION is neither, so it is refused rather than dropped:
  1867. // the same rule an attribute follows (mission 312 wall 4).
  1868. if (c == null) {
  1869. hlError("hl:web: " + baseName(pathOf(key)) + ':' + val.line + ':' + val.col + " — '" + e.key + "' is bound to an expression on the reference " + cls + ", and a binding is a literal, a member or a field path: declare the expression at the root of " + baseName(pathOf(key)) + " (`" + e.key + "Value = …`) and write `" + e.key + " = " + e.key + "Value`")
  1870. }
  1871. fill.push(c)
  1872. }
  1873. } else if (e.tag == 'on_statement') {
  1874. // A HANDLER WRITTEN ON A REFERENCE IS THE HOST'S, bound on the child's ROOT
  1875. // element. The reference is a literal of THIS file's View, so its behaviour
  1876. // is minted from THIS file's site and its body reaches this file through the
  1877. // owner rule — the same path an element's own handler takes. The child's own
  1878. // handler on that element is not replaced: both are listeners on one element
  1879. // and both run, the child's first, because it was bound when the child's tree
  1880. // was claimed. (Until 2026-09-13 the event was collected here and dropped: a
  1881. // reference with `on submit` never bound, and a form submitted natively.)
  1882. // …AND ITS SITE, because the tables file this handler's write set
  1883. // under it: the browser repaints exactly what it wrote (mission 309).
  1884. ons.push({ event = e.event; site = baseName(pathOf(key)) + ':' + e.line + ':' + e.col; })
  1885. } else if (e.tag == 'member_expression' && !e.computed && styleRef(key, e)) {
  1886. // a `Style.rule` written on a reference: the reference renders no element
  1887. // of its own, so there is nothing for the class to land on (§12)
  1888. hlError("hl:web: " + baseName(pathOf(key)) + ':' + at.line + ':' + at.col + " — a Style rule cannot be written on the component reference '" + cls + "': a reference renders no element of its own. Write the rule on an element inside " + baseName(pathOf(childKey)) + ", or name a '#" + cls + "' local rule in this file")
  1889. } else {
  1890. // AN ORDERED ENTRY. A literal or a read is the next declared property's
  1891. // value while the signature has room — `Button { "SD" }` is `Button
  1892. // { label = "SD" }` — and everything else, plus everything that EXCEEDS
  1893. // the signature, is the FILL: a fragment of THIS file's View, with its
  1894. // reads, its handlers and its `for` rows (§12 "host content").
  1895. let c = node(key, h, here, inFor, rows)
  1896. if (c != null) {
  1897. if (taken < sig.length && (c.k == 'text' || c.k == 'member' || c.k == 'field')) {
  1898. // the same rule as the named form above: a literal keeps its kind and a
  1899. // folded static crosses as its value
  1900. if (c.k == 'text') { positional.push({ name = sig[taken]; text = c.text; kind = c.kind; value = c.value; }) }
  1901. else if (c.k == 'member') { positional.push({ name = sig[taken]; member = c.name; }) }
  1902. else { positional.push({ name = sig[taken]; ref = c; }) }
  1903. taken = taken + 1
  1904. } else { fill.push(c) }
  1905. }
  1906. }
  1907. }
  1908. }
  1909. // THE NAMED ASSIGNMENTS COME LAST, so the name wins over the positional entry that
  1910. // landed on the same property (measured: that is what `new` does)
  1911. let allBindings = []
  1912. for (b of positional) { allBindings.push(b) }
  1913. for (b of bindings) { allBindings.push(b) }
  1914. bindings = allBindings
  1915. // FILLING WHAT PLACES NO SLOT IS A LOCATED ERROR (§12): the child would drop the
  1916. // content silently, which is exactly the bug this rule was written for.
  1917. if (fill.length > 0 && !isMember(childKey, 'slot')) {
  1918. hlError("hl:web: " + baseName(pathOf(key)) + ':' + at.line + ':' + at.col + " — " + cls + " is filled here, but " + baseName(pathOf(childKey)) + " declares no 'slot' to fill: declare `slot = null` there and place `slot` in its View, or write the content outside the reference")
  1919. }
  1920. if (fill.length > 0) {
  1921. if (fillTags[childKey] == null) { fillTags[childKey] = [] }
  1922. noteFillTags(childKey, fill)
  1923. }
  1924. let classes = []
  1925. if (styleRules(key).includes('#' + cls) && !viewIds(key).includes(view.kebab(cls))) {
  1926. classes.push(view.localClass(key))
  1927. for (t of rootTags(childKey)) { noteRef(key, t, '#' + cls) }
  1928. }

Only the first lines are shown.

Branches

Latest commits

  • a557ac53jukebox#10 review fixes: README file map names lib/background.hl, on Error(Hybrid e) per L10mre
  • 3503b648|||PR jukebox#10: move startup and scan wiring out of project.hl into lib/background.hlmre
  • 536d7c58Merge branch 'playing-row' into mainJukebox
  • 05c3578c|||PR Keep each playing row bound to the shell song on day76mre
  • eaa7e6d6Vendor Hybriel day76 for live parent member readsmre
  • 0923398bMerge branch 'records-1124d' into mainJukebox
  • 78f0cc86|||PR records 2026-11-24: inbox-thread rule, "Not playing" confirmed and closedmre
  • c1b153c4Merge branch 'records-1124c' into mainJukebox
  • d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
  • 43b564dbMerge branch 'records-1124b' into mainJukebox
  • fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
  • 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
  • 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
  • 170d3735Merge branch 'code-order-2' into mainJukebox
  • 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
  • 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
  • 0ba85799Merge branch 'reset-classes' into mainJukebox
  • 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
  • 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre