@niscorp/moss 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @niscorp/moss
2
2
 
3
+ ## 0.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - af903c6: A page's head is its screen's own. `nisc export` wrote every path with the built `index.html`'s `<head>`, so a site with more than one page shipped each of them under the front page's title, description, preview card and canonical address.
8
+
9
+ What a screen says about itself is now a node in a layout: nova's `nova:head`, with `title`, `description`, `image`, `kind` and `structured` bound to the action's data like any other node's props. It draws nothing — no adapter builds an element for it, no registry has to hold it, and a component is never handed one as a child — and it rides in the render tree, so it reaches a shell in the page, a snapshot a server drew and the trees on a wire alike. `headOf(api)` reads it off any of them; with more than one on the screen the last one speaks.
10
+ - **nova** — `HEAD_NAME`, `HeadPropsSchema`, `HEAD_META`, `headOf`, `isHeadNode`; and `@niscorp/nova/document`: `placeHead` writes a head into an HTML document (the tag that said the same thing is replaced, a missing one is added before `</head>`, everything else is left as it was; values are escaped) and `createTitleKeeper` keeps a tab's title on it. The DOM, React and Vue adapters keep the title on the head as the screen moves, and give the page's own back when the screen has none.
11
+ - **cli** — `build`, `export` and `start` write each path's document with its screen's head. "Same twice" also fails a boot that says a different head the second time, and the route table says whose head each path goes out with once an app has one. New config field `site`: the address the site is served at. With it every path says its own canonical address (`<link rel="canonical">`, `og:url`) and a head's picture gets a whole address; a build with several paths, a canonical tag in `index.html` and no `site` says so.
12
+ - **moss** — `renderDocument` and `exportDocuments` do the same from the snapshot (`site` on the config, `head` on the result), and the terminal keeps the tab's title off the wire for every render target.
13
+ - **create-nisc** — the two own-shell templates say their welcome screen's head.
14
+
15
+ **What to change:** nothing. An app with no `nova:head` node and no `site` is built, served and drawn exactly as before. An app that rewrote its exported files to give each page a head can delete that step: put the node in the layout and set `site`.
16
+
17
+ ## 0.2.3
18
+
19
+ ### Patch Changes
20
+
21
+ - 48da7db: `mountSite` answers a missing file with 404. A name with an extension that is neither a file in `dist` nor a page of the manifest used to fall through to the catch-all and come back as the drawn page with a 200 — so a browser holding a page from before a deploy asked for its old script and was handed a document. A page whose own path has a dot in it (`/docs/v1.2`) is still that page.
22
+ - 80e1ee8: Documentation: the packages are live, and releases are compatible. `STYLE_GUIDE.md` gains "The packages are live" — a release does not break an app that works on the one before it; what should go is deprecated and stays; a breaking change is a last resort that needs the maintainer's approval before it is written — and `AGENTS.md` points every agent changing nisc itself to it. The status lines that said "pre-1.0, breaking changes expected" (nova), "API is pre-1.0 and moves" (moss) and "everything else may move" (tide) now say the same. moss's deprecated `installedIntegrations` is no longer described as scheduled for removal: it stays on the type. The style guide's Node floor is corrected to 22.12, what every package's `engines` already says. No code changes.
23
+
3
24
  ## 0.2.2
4
25
 
5
26
  ### Patch Changes
package/DESIGN.md CHANGED
@@ -361,6 +361,16 @@ drawing a signed-in screen to a string is 0.4–0.7 ms; a whole anonymous docume
361
361
  — build a shell, read it, draw it — about 0.65 ms, some 1,500 a second. The
362
362
  page carries its screen twice (markup and snapshot), 3–5 KB compressed.
363
363
 
364
+ **The head of the page is part of the screen.** A title, a description and a
365
+ preview card are facts about what the screen shows, so they are a node in a
366
+ layout (nova's `nova:head`) and ride in the same trees as everything else:
367
+ `renderDocument` reads the node off the snapshot and writes it into the
368
+ template's `<head>`, and the terminal reads it off the wire to keep the tab's
369
+ title. Nothing was added to the snapshot, the wire or the manifest for it. The
370
+ one thing a head cannot say is where the page lives — a layout never holds its
371
+ own address — so the canonical address is the `site` plus the path the
372
+ document was drawn at, both of which the writer already holds.
373
+
364
374
  Six things had to be true, and each is a small, separate decision:
365
375
 
366
376
  - **The read does not disturb anybody.** A snapshot renders, and rendering can
package/DOCS.md CHANGED
@@ -5,8 +5,9 @@ Node listener and the built site), `@niscorp/moss/vite` (the dev plugin),
5
5
  `@niscorp/moss/client` and `@niscorp/moss/client/node` (the wire and its Node
6
6
  host), `@niscorp/moss/terminal` (the terminal), and the render targets:
7
7
  `terminal/react`, `terminal/vue`, `terminal/dom` (each with a `/server` entry
8
- that draws to a string), `terminal/tty` and `terminal/ink`. API is pre-1.0 and
9
- moves.
8
+ that draws to a string), `terminal/tty` and `terminal/ink`. The version is below 1.0 and
9
+ the package is live on npm all the same: what is documented here keeps working
10
+ from one release to the next, and what should go is deprecated, not removed.
10
11
 
11
12
  The nisc packages (`charter`, `nova`, `prism`, `strata`, `tide`, `vex`) and
12
13
  `zod` are required peers. `react`/`react-dom`, `vue`, `ink` and `vite` are
@@ -452,8 +453,9 @@ const page = await renderDocument({
452
453
  request: { path, cookie }, // what the request named and carried
453
454
  draw: (snapshot) => renderSnapshot({ snapshot, registry, slotWrapper }),
454
455
  htmlAttributes: (snapshot) => ({ 'data-accent': … }), // optional
456
+ site: 'https://example.com', // optional
455
457
  });
456
- // → { html, headers, drawn, principal, page?, live?, why?, drawnWith?, settled? }
458
+ // → { html, headers, drawn, principal, page?, head?, live?, why?, drawnWith?, settled? }
457
459
  ```
458
460
 
459
461
  - **Which shell**: the page `server.page(path)` names, else the app's.
@@ -468,6 +470,19 @@ const page = await renderDocument({
468
470
  - **`htmlAttributes`** is for what a kit would otherwise set on `<html>` from an
469
471
  effect, which never runs on a server: a palette, a colour scheme. Read it off
470
472
  the same node the effect reads it from. Values are escaped.
473
+ - **The page's head is its screen's own.** What a screen says about itself is
474
+ a node in a layout — nova's `nova:head`, with `title`, `description`,
475
+ `image`, `kind` and `structured` bound to the action's data. It is in the
476
+ snapshot's trees like everything else on the screen, so it is read off them
477
+ and written into the template's `<head>`: what it says takes the place of
478
+ the tag that said the same thing, and the rest of the head is left as the
479
+ template has it. `head` in the result is what was read (`{ head, action? }`);
480
+ absent, the page went out with the template's. In the browser the terminal
481
+ keeps the tab's title on the same node as the screen moves.
482
+ - **`site`** is the address the site is served at. A layout never holds its
483
+ own page's address: with `site`, every path's document says its own
484
+ canonical address (`<link rel="canonical">`, `og:url`) and a picture a head
485
+ names is given a whole one. Without it the template's is left as it is.
471
486
  - **`template`** must hold the empty root (`root`, default
472
487
  `<div id="root"></div>`). The screen goes inside it, the snapshot element
473
488
  straight after.
@@ -879,14 +894,22 @@ Correctness, which matters more than the saving:
879
894
  the runtime's through for you, so only a host running its own listener (a
880
895
  vite plugin, a dev check) ever needs it.
881
896
 
882
- - `mountSite(server, { dist, draw, htmlAttributes?, tokenKey?, waitMs?, owned? })`
897
+ - `mountSite(server, { dist, draw, htmlAttributes?, site?, tokenKey?, waitMs?, owned? })`
883
898
  — the built terminal, served by the same process as the app. Every GET that
884
899
  nothing registered earlier answers is a file from `dist`, or a page:
885
900
  `index.html` with the caller's screen drawn into it (`renderDocument`) — the
886
901
  app's own for `/`, one of the manifest's pages for a path that leads to one.
887
902
  `index.html` itself never goes out as a file. Register the app's own routes
888
903
  first; this is the catch-all. `owned` (default: moss's own prefixes) names
889
- what is never a page — an unknown path under one is a 404, not a screen.
904
+ what is never a page — an unknown path under one is a 404, not a screen. So is
905
+ a **missing file**: a name with an extension that is neither a file in `dist`
906
+ nor a page of the manifest is answered 404 (a browser holding a page from
907
+ before a deploy asks for its script by the old name, and needs "gone" back,
908
+ not a document). A page's own path may have a dot in it (`/docs/v1.2`).
909
+ What a browser may keep of these files, and compressing what goes out, is not
910
+ said here: `nisc start` puts both around the whole server (`@niscorp/cli`,
911
+ "`nisc start`"). A host running its own listener over `mountSite` says them
912
+ itself.
890
913
  - `MOSS_PATHS` — the prefixes the app server answers itself:
891
914
  `/^\/(api|catalog|socket|operator|integrations)(\/|$)/`. The default `owned`
892
915
  here and in the dev plugin.
@@ -905,7 +928,7 @@ Requires the optional `vite` peer.
905
928
  keeps it.
906
929
  - `options.app(load): Promise<DevApp>` — stand the app up. `load` is vite's
907
930
  `ssrLoadModule`. `DevApp = { server, close?, draw?, htmlAttributes?,
908
- tokenKey?, signIn? }`; absent `draw`, pages go out undrawn.
931
+ site?, tokenKey?, signIn? }`; absent `draw`, pages go out undrawn.
909
932
  - `signIn(who)` enables `/dev/as/<who>`: it stores the returned token (and
910
933
  its cookie copy) and goes to `/`. `null` is nobody of that name.
911
934
  - `watch?: RegExp` (default: `src/app`, `src/server`, `src/db`, `src/ui` and
package/README.md CHANGED
@@ -85,6 +85,12 @@ Who may keep the page follows from who asked: drawn for nobody it is the same
85
85
  for everybody; drawn for somebody it is `private, no-store`. A page that cannot
86
86
  be drawn goes out undrawn.
87
87
 
88
+ The page's `<head>` is its screen's own: a `nova:head` node in a layout — a
89
+ title, a description, a preview picture, bound to the action's data — is read
90
+ off the snapshot and written into the template, and the terminal keeps the
91
+ tab's title on it as the screen moves. With `site`, every path says its own
92
+ canonical address.
93
+
88
94
  `pages` are the other thing a path can lead to: a shell manifest drawn for
89
95
  whoever asks and then let go — a welcome, the docs. A page with nothing left to
90
96
  happen opens no socket, and `exportDocuments` writes pages as files. See
@@ -1,6 +1,6 @@
1
- import { renderDocument, createServer } from './chunk-2AHJ6VDR.js';
1
+ import { renderDocument, createServer } from './chunk-D6E4SV6F.js';
2
2
  import { readFile } from 'fs/promises';
3
- import { relative, join } from 'path';
3
+ import { relative, extname, join } from 'path';
4
4
  import { serve as serve$1 } from '@hono/node-server';
5
5
  import { serveStatic } from '@hono/node-server/serve-static';
6
6
  import { WebSocketServer } from 'ws';
@@ -38,6 +38,7 @@ var mountSite = (server, config) => {
38
38
  });
39
39
  server.get("*", async (c) => {
40
40
  if (owned.test(c.req.path)) return c.notFound();
41
+ if (extname(c.req.path) !== "" && c.req.path !== "/index.html" && server.page(c.req.path) === void 0) return c.notFound();
41
42
  const template = await readFile(join(dist, "index.html"), "utf8");
42
43
  const page = await renderDocument({
43
44
  ...drawing,
@@ -59,5 +60,5 @@ var serve = async (app, runtime) => {
59
60
  };
60
61
 
61
62
  export { MOSS_PATHS, attachSocket, mountSite, serve };
62
- //# sourceMappingURL=chunk-5S7TBULB.js.map
63
- //# sourceMappingURL=chunk-5S7TBULB.js.map
63
+ //# sourceMappingURL=chunk-CDNJ2CBA.js.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serve as listen } from '@hono/node-server';\nimport { serveStatic } from '@hono/node-server/serve-static';\nimport { WebSocketServer } from 'ws';\nimport type { IncomingMessage } from 'node:http';\nimport type { Duplex } from 'node:stream';\nimport { createServer } from './server';\nimport type { MossServer } from './server';\nimport type { NiscApp } from './app';\nimport type { NiscRuntime } from './runtime';\nimport type { SocketAccept } from './socket';\nimport { renderDocument } from './document';\nimport type { DocumentConfig } from './document';\n\n// ═══════════════════════════════════════════════════════════════\n// The Node entry — runtime-specific by design: the transport is a seam, so\n// the Bun flip swaps this file, never the app. Two exports: the\n// websocket transport for hosts that run their own listener (the dev\n// checks, vite), and the batteries-included `serve`.\n// ═══════════════════════════════════════════════════════════════\n\n// Anything that emits Node upgrade events — http.Server structurally, so\n// the @hono/node-server return type needs no narrowing.\ntype Upgradeable = {\n on: (event: 'upgrade', handler: (req: IncomingMessage, socket: Duplex, head: Buffer) => void) => unknown;\n};\n\n// The `ws` half of the transport seam: RFC 6455 stays library-handled\n// (permessage-deflate on by default — see `runtime.socketCompression`); the\n// protocol above the seam is nisc's own (../socket.ts) and identical on every\n// runtime.\nexport const attachSocket = (\n httpServer: Upgradeable,\n accept: SocketAccept,\n path = '/socket',\n options?: { compression?: boolean | Record<string, unknown> },\n): void => {\n const wss = new WebSocketServer({ noServer: true, perMessageDeflate: options?.compression ?? true });\n httpServer.on('upgrade', (req, socket, head) => {\n const url = req.url ?? '/';\n // Not ours: leave it for whichever other listener owns it (vite's HMR\n // upgrade rides the same server in dev).\n if (new URL(url, 'http://nisc.local').pathname !== path) return;\n wss.handleUpgrade(req, socket, head, (ws) => {\n // accept promises to handle its own failures (see socket.ts). This is\n // the floor under that promise: an await added there without a guard\n // degrades to one logged close here instead of an unhandled rejection\n // taking every session on the box down with it.\n accept(url, {\n send: (text) => ws.send(text),\n close: (code, reason) => ws.close(code, reason),\n onMessage: (fn) => ws.on('message', (data) => fn(String(data))),\n onClose: (fn) => ws.on('close', () => fn()),\n }).catch((error: unknown) => {\n console.error('[moss/node] a connection escaped accept:', error);\n try {\n ws.close(1011, 'accept failed');\n } catch {\n // already gone\n }\n });\n });\n });\n};\n\n// THE BUILT TERMINAL, served by the same process as the app — one origin, so the\n// socket is `/socket` wherever the page came from.\n//\n// `dist` is what the app's bundler wrote: index.html and its assets. Every GET\n// that nothing registered earlier answers is a file from it, or a PAGE:\n// index.html with the caller's screen drawn into it (./document) — the app's own\n// for `/`, one of the manifest's pages for a path that leads to one. index.html\n// itself is never served as a file: it is the template, and goes out drawn.\n//\n// A name with an extension that is neither a file in `dist` nor a page of the\n// manifest is a MISSING FILE, and is answered 404 — not with a screen. A browser\n// holding a page from before a deploy asks for that page's script by its old\n// name; what it needs back is \"gone\", not a document that is not a script.\n//\n// Register the app's own routes FIRST; this is the catch-all. `owned` names the\n// prefixes that are never a page (default: moss's own surfaces) — an unknown\n// path under one is a 404, not a screen.\nexport type SiteConfig = Pick<DocumentConfig, 'draw' | 'htmlAttributes' | 'site' | 'tokenKey' | 'waitMs'> & {\n dist: string;\n owned?: RegExp;\n};\n\n// The paths the app server answers itself; everything else is the site's.\nexport const MOSS_PATHS = /^\\/(api|catalog|socket|operator|integrations)(\\/|$)/;\n\nexport const mountSite = (server: MossServer, config: SiteConfig): void => {\n const { dist, owned = MOSS_PATHS, ...drawing } = config;\n // serveStatic resolves `root` against the working directory.\n const root = relative(process.cwd(), dist) || '.';\n const files = serveStatic({ root });\n server.use('/*', async (c, next) => {\n const path = c.req.path;\n if (owned.test(path) || path === '/' || path === '/index.html' || server.page(path) !== undefined) return next();\n return files(c, next);\n });\n server.get('*', async (c) => {\n if (owned.test(c.req.path)) return c.notFound();\n // the static server above found no such file, and no page is at this path\n if (extname(c.req.path) !== '' && c.req.path !== '/index.html' && server.page(c.req.path) === undefined) return c.notFound();\n const template = await readFile(join(dist, 'index.html'), 'utf8');\n const page = await renderDocument({\n ...drawing,\n server,\n template,\n request: { path: c.req.path === '/index.html' ? '/' : c.req.path, cookie: c.req.header('cookie') ?? null },\n });\n return c.html(page.html, 200, page.headers);\n });\n};\n\nexport const serve = async (app: NiscApp, runtime: NiscRuntime & { port?: number }): Promise<MossServer> => {\n const server = await createServer(app, runtime);\n const port = runtime.port ?? 8787;\n const httpServer = listen({ fetch: server.fetch, port });\n attachSocket(httpServer, server.socket, '/socket', { ...(runtime.socketCompression !== undefined ? { compression: runtime.socketCompression } : {}) });\n console.log(`moss serving http://localhost:${port}`);\n console.log(`surfaces: GET /catalog · GET|POST /api/vex · GET|POST /api/<resource>/vex · ws://localhost:${port}/socket`);\n return server;\n};\n"]}
@@ -15,6 +15,7 @@ import { Hono } from 'hono';
15
15
  import { vex, VEX_LIVE_ENV } from '@niscorp/vex/hono';
16
16
  import { NOVA_SEQUENCE } from '@niscorp/nova/migrations';
17
17
  import { prismTransform, PRISM_SEQUENCE } from '@niscorp/prism/migrations';
18
+ import { headOf, placeHead } from '@niscorp/nova/document';
18
19
 
19
20
  // src/runtime.ts
20
21
  var mintDevToken = (sub, claims = {}) => btoa(JSON.stringify({ sub, ...claims, iat: Date.now() })).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
@@ -3224,8 +3225,6 @@ ${nextVariantErrors.map((e) => ` ${e}`).join("\n")}`);
3224
3225
  ...identities !== void 0 ? { identities: { list: identities.list, meter: identities.meter } } : {}
3225
3226
  });
3226
3227
  };
3227
-
3228
- // src/document.ts
3229
3228
  var SNAPSHOT_ELEMENT_ID = "nisc-snapshot";
3230
3229
  var DEFAULT_TOKEN_KEY = "nisc.token";
3231
3230
  var DEFAULT_ROOT = '<div id="root"></div>';
@@ -3269,9 +3268,12 @@ var renderDocument = async (config) => {
3269
3268
  });
3270
3269
  const screen = await draw(snapshot);
3271
3270
  const attributes = Object.entries(config.htmlAttributes?.(snapshot) ?? {}).map(([name, value]) => ` ${name}="${escapeAttribute(value)}"`).join("");
3272
- const html = template.replace(root, () => `${root.replace("></div>", () => `>${screen}</div>`)}${embedSnapshot(snapshot, principal, request.path)}`).replace(/<html([^>]*)>/, (whole, existing) => attributes === "" ? whole : `<html${existing}${attributes}>`);
3271
+ const placed = template.replace(root, () => `${root.replace("></div>", () => `>${screen}</div>`)}${embedSnapshot(snapshot, principal, request.path)}`).replace(/<html([^>]*)>/, (whole, existing) => attributes === "" ? whole : `<html${existing}${attributes}>`);
3272
+ const head = headOf({ frame: () => snapshot.frame, canvasTree: (id) => snapshot.trees[id] ?? [] });
3273
+ const html = placeHead(placed, head?.head, { ...config.site !== void 0 ? { site: config.site } : {}, path: request.path });
3273
3274
  return {
3274
3275
  html,
3276
+ ...head !== void 0 ? { head } : {},
3275
3277
  headers: {
3276
3278
  ...documentHeaders(principal),
3277
3279
  ...token !== null && principal === null ? { "set-cookie": `${encodeURIComponent(tokenKey)}=; Path=/; Max-Age=0; SameSite=Lax` } : {}
@@ -3298,6 +3300,7 @@ var exportDocuments = async (config) => {
3298
3300
  path,
3299
3301
  html: page.html,
3300
3302
  ...page.page !== void 0 ? { page: page.page } : {},
3303
+ ...page.head !== void 0 ? { head: page.head } : {},
3301
3304
  drawn: page.drawn,
3302
3305
  // undrawn is not concluded finished
3303
3306
  live: page.live ?? true,
@@ -3310,5 +3313,5 @@ var exportDocuments = async (config) => {
3310
3313
  };
3311
3314
 
3312
3315
  export { DEFAULT_GENERATION_POLL_MS, DEFAULT_IDENTITY_IDLE_MS, DEFAULT_IDENTITY_MAX, DEFAULT_IDLE_MS, GENERATION_DDL, MOSS_SEQUENCE, SESSIONS_SEQUENCE, SNAPSHOT_ELEMENT_ID, TIDE_DDL, TIDE_SEQUENCE, TIDE_TABLES, auditClosure, buildContract, callIntegrationWith, contractAsMarkdown, copyPress, createAssertionSigner, createDataLayer, createGeneration, createIdentityCache, createPageRouter, createServer, createShellHost, createTideStore, describePlacements, devSession, documentHeaders, embedSnapshot, exportDocuments, filterInstalled, hashIntegrationKey, initIntegrations, initSessions, integrationByKey, integrationOfAction, listAttachments, listIntegrations, listPlacements, loadIntegrationActions, memoKeyOf, mintDevToken, mintIntegrationKey, mintSession, mintWrites, renderDocument, resolveCatalog, resolveCatalogForRoles, resolvePolicy, resolvePolicyAtReach, resolvePolicyForRoles, resolveRoles, resolveVariants, resolveVariantsForRoles, revokeAllFor, revokeSession, runIntake, sessionOf, sessionVerifierOf, shellNeedOf, tokenFromCookie, verifyAssertion, verifyVariants, wearableOf, wireFabric };
3313
- //# sourceMappingURL=chunk-2AHJ6VDR.js.map
3314
- //# sourceMappingURL=chunk-2AHJ6VDR.js.map
3316
+ //# sourceMappingURL=chunk-D6E4SV6F.js.map
3317
+ //# sourceMappingURL=chunk-D6E4SV6F.js.map