@niscorp/moss 0.1.0 → 0.2.1
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 +13 -0
- package/README.md +1 -0
- package/dist/chunk-5S7TBULB.js +63 -0
- package/dist/chunk-5S7TBULB.js.map +1 -0
- package/dist/node.cjs +1 -0
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +2 -1
- package/dist/node.d.ts +2 -1
- package/dist/node.js +2 -61
- package/dist/node.js.map +1 -1
- package/dist/terminal/dom/index.cjs +6 -3
- package/dist/terminal/dom/index.cjs.map +1 -1
- package/dist/terminal/dom/index.js +6 -3
- package/dist/terminal/dom/index.js.map +1 -1
- package/dist/vite.cjs +211 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +29 -0
- package/dist/vite.d.ts +29 -0
- package/dist/vite.js +120 -0
- package/dist/vite.js.map +1 -0
- package/package.json +23 -8
- package/dist/chunk-HF6IGQ74.js +0 -3342
- package/dist/chunk-HF6IGQ74.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @niscorp/moss
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2548e43: `domTarget({ root, registry })` with an app's own registry no longer injects nova's reference stylesheet or puts its class on the root — both restyled the app's kit over the app's own CSS. With no registry (the reference kit) nothing changes.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 3a9866e: `@niscorp/moss/vite` — `mossDev({ app })`, the app server inside vite's dev process: loaded through vite so an edit re-boots it (the old server answers until the new one is up, then is let go with its timers), the socket attached once and delegating to whichever server is current, `/` and every page's path answered with its first screen drawn into vite's transformed index.html, moss's paths answered by the app server, and a dev-only `/dev/as/<who>` when the app can mint a token. `vite` is an optional peer. `MOSS_PATHS` is exported from `@niscorp/moss/node`.
|
package/README.md
CHANGED
|
@@ -126,6 +126,7 @@ never in moss core.
|
|
|
126
126
|
|
|
127
127
|
- **`@niscorp/moss`** — the server: `defineApp`, `createServer`, the resolution and shell-host internals, the socket protocol types.
|
|
128
128
|
- **`@niscorp/moss/node`** — the Node listener: `serve` + `attachSocket` (raw `ws`). Bun swaps this file, never the app.
|
|
129
|
+
- **`@niscorp/moss/vite`** — `mossDev({ app })`: the app server inside vite's dev process — loaded through vite (an edit re-boots it), the socket attached once, pages drawn, moss's paths answered, a dev-only `/dev/as/<who>`. `nisc dev` adds it for an app behind moss; `vite` is an optional peer.
|
|
129
130
|
- **`@niscorp/moss/client`** — the wire: `createWire()`, the app end of the socket. Plain TypeScript, zero React, zero globals — the host comes in as a `WireEnv` (default: `browserEnv()`, localStorage + location).
|
|
130
131
|
- **`@niscorp/moss/client/node`** — the Node host env: `nodeEnv({ url, tokenFile? })` runs the same wire on a plain Node (or Bun) process — token in a file, the runtime's WHATWG WebSocket.
|
|
131
132
|
- **`@niscorp/moss/terminal`** — the terminal: `createTerminal` (one target, one wire) and `mountTerminal` (hot-swaps render targets on a hotkey over one wire; the session survives the swap). Framework-blind, surface-blind.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { renderDocument, createServer } from './chunk-2AHJ6VDR.js';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { relative, join } from 'path';
|
|
4
|
+
import { serve as serve$1 } from '@hono/node-server';
|
|
5
|
+
import { serveStatic } from '@hono/node-server/serve-static';
|
|
6
|
+
import { WebSocketServer } from 'ws';
|
|
7
|
+
|
|
8
|
+
var attachSocket = (httpServer, accept, path = "/socket", options) => {
|
|
9
|
+
const wss = new WebSocketServer({ noServer: true, perMessageDeflate: options?.compression ?? true });
|
|
10
|
+
httpServer.on("upgrade", (req, socket, head) => {
|
|
11
|
+
const url = req.url ?? "/";
|
|
12
|
+
if (new URL(url, "http://nisc.local").pathname !== path) return;
|
|
13
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
14
|
+
accept(url, {
|
|
15
|
+
send: (text) => ws.send(text),
|
|
16
|
+
close: (code, reason) => ws.close(code, reason),
|
|
17
|
+
onMessage: (fn) => ws.on("message", (data) => fn(String(data))),
|
|
18
|
+
onClose: (fn) => ws.on("close", () => fn())
|
|
19
|
+
}).catch((error) => {
|
|
20
|
+
console.error("[moss/node] a connection escaped accept:", error);
|
|
21
|
+
try {
|
|
22
|
+
ws.close(1011, "accept failed");
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var MOSS_PATHS = /^\/(api|catalog|socket|operator|integrations)(\/|$)/;
|
|
30
|
+
var mountSite = (server, config) => {
|
|
31
|
+
const { dist, owned = MOSS_PATHS, ...drawing } = config;
|
|
32
|
+
const root = relative(process.cwd(), dist) || ".";
|
|
33
|
+
const files = serveStatic({ root });
|
|
34
|
+
server.use("/*", async (c, next) => {
|
|
35
|
+
const path = c.req.path;
|
|
36
|
+
if (owned.test(path) || path === "/" || path === "/index.html" || server.page(path) !== void 0) return next();
|
|
37
|
+
return files(c, next);
|
|
38
|
+
});
|
|
39
|
+
server.get("*", async (c) => {
|
|
40
|
+
if (owned.test(c.req.path)) return c.notFound();
|
|
41
|
+
const template = await readFile(join(dist, "index.html"), "utf8");
|
|
42
|
+
const page = await renderDocument({
|
|
43
|
+
...drawing,
|
|
44
|
+
server,
|
|
45
|
+
template,
|
|
46
|
+
request: { path: c.req.path === "/index.html" ? "/" : c.req.path, cookie: c.req.header("cookie") ?? null }
|
|
47
|
+
});
|
|
48
|
+
return c.html(page.html, 200, page.headers);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var serve = async (app, runtime) => {
|
|
52
|
+
const server = await createServer(app, runtime);
|
|
53
|
+
const port = runtime.port ?? 8787;
|
|
54
|
+
const httpServer = serve$1({ fetch: server.fetch, port });
|
|
55
|
+
attachSocket(httpServer, server.socket, "/socket", { ...runtime.socketCompression !== void 0 ? { compression: runtime.socketCompression } : {} });
|
|
56
|
+
console.log(`moss serving http://localhost:${port}`);
|
|
57
|
+
console.log(`surfaces: GET /catalog \xB7 GET|POST /api/vex \xB7 GET|POST /api/<resource>/vex \xB7 ws://localhost:${port}/socket`);
|
|
58
|
+
return server;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { MOSS_PATHS, attachSocket, mountSite, serve };
|
|
62
|
+
//# sourceMappingURL=chunk-5S7TBULB.js.map
|
|
63
|
+
//# sourceMappingURL=chunk-5S7TBULB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node.ts"],"names":["listen"],"mappings":";;;;;;;AAgCO,IAAM,eAAe,CAC1B,UAAA,EACA,MAAA,EACA,IAAA,GAAO,WACP,OAAA,KACS;AACT,EAAA,MAAM,GAAA,GAAM,IAAI,eAAA,CAAgB,EAAE,QAAA,EAAU,MAAM,iBAAA,EAAmB,OAAA,EAAS,WAAA,IAAe,IAAA,EAAM,CAAA;AACnG,EAAA,UAAA,CAAW,EAAA,CAAG,SAAA,EAAW,CAAC,GAAA,EAAK,QAAQ,IAAA,KAAS;AAC9C,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,IAAO,GAAA;AAGvB,IAAA,IAAI,IAAI,GAAA,CAAI,GAAA,EAAK,mBAAmB,CAAA,CAAE,aAAa,IAAA,EAAM;AACzD,IAAA,GAAA,CAAI,aAAA,CAAc,GAAA,EAAK,MAAA,EAAQ,IAAA,EAAM,CAAC,EAAA,KAAO;AAK3C,MAAA,MAAA,CAAO,GAAA,EAAK;AAAA,QACV,IAAA,EAAM,CAAC,IAAA,KAAS,EAAA,CAAG,KAAK,IAAI,CAAA;AAAA,QAC5B,OAAO,CAAC,IAAA,EAAM,WAAW,EAAA,CAAG,KAAA,CAAM,MAAM,MAAM,CAAA;AAAA,QAC9C,SAAA,EAAW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CAAI,CAAA,oGAAA,EAA8F,IAAI,CAAA,OAAA,CAAS,CAAA;AACvH,EAAA,OAAO,MAAA;AACT","file":"chunk-5S7TBULB.js","sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { 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// 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' | '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 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"]}
|