@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/dist/vite.js ADDED
@@ -0,0 +1,120 @@
1
+ import { MOSS_PATHS, attachSocket } from './chunk-5S7TBULB.js';
2
+ import { renderDocument } from './chunk-2AHJ6VDR.js';
3
+ import './chunk-ZOEUEMDX.js';
4
+ import { readFile } from 'fs/promises';
5
+ import { resolve } from 'path';
6
+ import { getRequestListener } from '@hono/node-server';
7
+
8
+ var DEFAULT_WATCH = /([\\/]src[\\/](app|server|db|ui)[\\/])|([\\/]nisc\.config\.[cm]?[jt]s$)/;
9
+ var REBOOT_DEBOUNCE_MS = 200;
10
+ var retire = async (booted) => {
11
+ booted.app.server.socket.stop();
12
+ await (booted.app.close ?? (() => booted.app.server.close()))();
13
+ };
14
+ var said = (error) => error instanceof Error ? error.message : String(error);
15
+ var mossDev = (options) => ({
16
+ name: "moss-dev",
17
+ apply: "serve",
18
+ configureServer: (vite) => {
19
+ const label = options.label ?? "moss";
20
+ const watch = options.watch ?? DEFAULT_WATCH;
21
+ const owned = options.owned ?? MOSS_PATHS;
22
+ const load = (id) => vite.ssrLoadModule(id);
23
+ const boot = async () => {
24
+ const app = await options.app(load);
25
+ return { app, listener: getRequestListener(app.server.fetch) };
26
+ };
27
+ let current = boot();
28
+ current.catch((error) => vite.config.logger.error(`[${label}] the app did not boot: ${said(error)}`, { timestamp: true }));
29
+ if (vite.httpServer !== null) {
30
+ attachSocket(
31
+ vite.httpServer,
32
+ Object.assign(async (url, connection) => (await current).app.server.socket(url, connection), {
33
+ // whichever server is current owns the revalidation timer; this handler owns none
34
+ stop: () => void current.then(({ app }) => app.server.socket.stop(), () => void 0)
35
+ })
36
+ );
37
+ }
38
+ let timer;
39
+ const reboot = (file) => {
40
+ if (!watch.test(file)) return;
41
+ clearTimeout(timer);
42
+ timer = setTimeout(() => {
43
+ const outgoing = current;
44
+ current = boot();
45
+ current.then(
46
+ () => {
47
+ void outgoing.then(retire, () => void 0);
48
+ vite.config.logger.info(`[${label}] app server re-booted`, { timestamp: true });
49
+ vite.ws.send({ type: "full-reload" });
50
+ },
51
+ (error) => {
52
+ current = outgoing;
53
+ vite.config.logger.error(`[${label}] re-boot failed: ${said(error)}`, { timestamp: true });
54
+ }
55
+ );
56
+ }, REBOOT_DEBOUNCE_MS);
57
+ };
58
+ vite.watcher.on("change", reboot);
59
+ vite.watcher.on("add", reboot);
60
+ vite.watcher.on("unlink", reboot);
61
+ vite.httpServer?.once("close", () => void current.then(retire, () => void 0));
62
+ vite.middlewares.use((req, res, next) => {
63
+ const url = req.url ?? "/";
64
+ const path = url.split("?")[0] ?? "/";
65
+ const who = /^\/dev\/as\/([\w.@%-]+)$/.exec(path)?.[1];
66
+ if (who !== void 0) {
67
+ void current.then(async ({ app }) => {
68
+ if (app.signIn === void 0) {
69
+ next();
70
+ return;
71
+ }
72
+ const token = await app.signIn(decodeURIComponent(who));
73
+ const key = JSON.stringify(app.tokenKey ?? "nisc.token");
74
+ res.setHeader("content-type", "text/html; charset=utf-8");
75
+ res.end(
76
+ token === null ? `<p>nobody called ${who.replace(/[<&"]/g, "")}</p>` : `<script>localStorage.setItem(${key},${JSON.stringify(token)});document.cookie=encodeURIComponent(${key})+'='+encodeURIComponent(${JSON.stringify(token)})+'; Path=/; SameSite=Lax';location.replace('/')</script>`
77
+ );
78
+ }).catch(() => {
79
+ res.statusCode = 500;
80
+ res.end("the dev sign-in failed");
81
+ });
82
+ return;
83
+ }
84
+ if (owned.test(path)) {
85
+ void current.then(({ listener }) => listener(req, res)).catch(() => {
86
+ res.statusCode = 503;
87
+ res.end("the app server did not boot \u2014 see the dev server\u2019s log");
88
+ });
89
+ return;
90
+ }
91
+ if (req.method !== "GET") {
92
+ next();
93
+ return;
94
+ }
95
+ void current.then(async ({ app }) => {
96
+ if (app.draw === void 0 || path !== "/" && path !== "/index.html" && app.server.page(path) === void 0) {
97
+ next();
98
+ return;
99
+ }
100
+ const template = await vite.transformIndexHtml(url, await readFile(resolve(vite.config.root, options.index ?? "index.html"), "utf8"));
101
+ const page = await renderDocument({
102
+ server: app.server,
103
+ template,
104
+ request: { path: path === "/index.html" ? "/" : path, cookie: req.headers.cookie ?? null },
105
+ draw: app.draw,
106
+ ...app.htmlAttributes !== void 0 ? { htmlAttributes: app.htmlAttributes } : {},
107
+ ...app.tokenKey !== void 0 ? { tokenKey: app.tokenKey } : {}
108
+ });
109
+ res.statusCode = 200;
110
+ res.setHeader("content-type", "text/html; charset=utf-8");
111
+ for (const [name, value] of Object.entries(page.headers)) res.setHeader(name, value);
112
+ res.end(page.html);
113
+ }).catch(() => next());
114
+ });
115
+ }
116
+ });
117
+
118
+ export { mossDev };
119
+ //# sourceMappingURL=vite.js.map
120
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vite.ts"],"names":[],"mappings":";;;;;;;AAiEA,IAAM,aAAA,GAAgB,yEAAA;AACtB,IAAM,kBAAA,GAAqB,GAAA;AAI3B,IAAM,MAAA,GAAS,OAAO,MAAA,KAAkC;AACtD,EAAA,MAAA,CAAO,GAAA,CAAI,MAAA,CAAO,MAAA,CAAO,IAAA,EAAK;AAC9B,EAAA,MAAA,CAAO,MAAA,CAAO,IAAI,KAAA,KAAU,MAAY,OAAO,GAAA,CAAI,MAAA,CAAO,OAAM,CAAA,GAAI;AACtE,CAAA;AAEA,IAAM,IAAA,GAAO,CAAC,KAAA,KAA4B,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAExF,IAAM,OAAA,GAAU,CAAC,OAAA,MAAqC;AAAA,EAC3D,IAAA,EAAM,UAAA;AAAA,EACN,KAAA,EAAO,OAAA;AAAA,EACP,eAAA,EAAiB,CAAC,IAAA,KAAwB;AACxC,IAAA,MAAM,KAAA,GAAQ,QAAQ,KAAA,IAAS,MAAA;AAC/B,IAAA,MAAM,KAAA,GAAQ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AI,IAAI,QAAA,KAAa,MAAA,GAAY,EAAE,QAAA,EAAU,GAAA,CAAI,QAAA,EAAS,GAAI;AAAC,SAChE,CAAA;AACD,QAAA,GAAA,CAAI,UAAA,GAAa,GAAA;AACjB,QAAA,GAAA,CAAI,SAAA,CAAU,gBAAgB,0BAA0B,CAAA;AACxD,QAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,CAAA,IAAK,MAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,OAAO,CAAA,EAAG,GAAA,CAAI,SAAA,CAAU,IAAA,EAAM,KAAK,CAAA;AACnF,QAAA,GAAA,CAAI,GAAA,CAAI,KAAK,IAAI,CAAA;AAAA,MACnB,CAAC,CAAA,CAEA,KAAA,CAAM,MAAM,MAAM,CAAA;AAAA,IACvB,CAAC,CAAA;AAAA,EACH;AACF,CAAA","file":"vite.js","sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport type { Plugin, ViteDevServer } from 'vite';\nimport { getRequestListener } from '@hono/node-server';\nimport { renderDocument } from './document';\nimport type { DocumentConfig } from './document';\nimport { attachSocket, MOSS_PATHS } from './node';\nimport type { MossServer } from './server';\n\n// ═══════════════════════════════════════════════════════════════\n// @niscorp/moss/vite — the app server inside vite's dev process.\n//\n// One `nisc dev`, no proxy, no second terminal: the app boots in vite's own\n// process, through vite's own module loading (`ssrLoadModule`), so the boot it\n// runs is the source on disk and an edit is a fresh boot. What it does, in the\n// order a request meets it:\n//\n// the socket attached ONCE, delegating to whichever server is current —\n// a re-boot swaps what it delegates to, never the handler\n// /dev/as/:who a signed-in URL, when the app can mint a dev token\n// a page `/`, or a path one of the manifest's pages answers: index.html\n// through vite first (its client, the framework's refresh\n// preamble), then the screen drawn into it (`renderDocument`)\n// moss's paths /api, /catalog, /operator, /integrations — the app server's\n// the rest vite's: source files, assets, its own urls\n//\n// A change under one of the watched directories re-boots the whole app — a\n// fresh database, fresh seed, fresh shells — then reloads the page so the\n// browser reconnects to the new server. The outgoing server keeps answering\n// until the new one is up, so a broken edit does not take the dev server down,\n// and is then let go, timers included.\n// ═══════════════════════════════════════════════════════════════\n\nexport type DevApp = {\n server: MossServer;\n // how to let it go (default: `server.close()`)\n close?: () => void | Promise<void>;\n // How one of its screens is drawn. Absent: pages go out as vite's index.html,\n // undrawn, and the terminal paints them as it always did.\n draw?: DocumentConfig['draw'];\n htmlAttributes?: DocumentConfig['htmlAttributes'];\n tokenKey?: string;\n // A dev-only signed-in URL: `/dev/as/<who>` stores the token this returns —\n // where the wire keeps it and in the cookie copy a page is drawn by — and\n // goes to `/`. `null` is nobody of that name. It lives in vite's middleware\n // and nowhere else, so it cannot ship.\n signIn?: (who: string) => string | null | Promise<string | null>;\n};\n\nexport type MossDevOptions = {\n // Stand the app up. `load` is vite's own module loader: what it loads is the\n // source as it is on disk now, with the app's aliases resolved.\n app: (load: (id: string) => Promise<Record<string, unknown>>) => Promise<DevApp>;\n // Which edits re-boot the app (default: anything under src/app, src/server,\n // src/db or src/ui — the kit is in it because the SERVER holds the component\n // registry too — and the nisc config).\n watch?: RegExp;\n // The page template, relative to vite's root (default `index.html`).\n index?: string;\n // The paths the app server answers (default: moss's own).\n owned?: RegExp;\n // The name in vite's log (default `moss`).\n label?: string;\n};\n\nconst DEFAULT_WATCH = /([\\\\/]src[\\\\/](app|server|db|ui)[\\\\/])|([\\\\/]nisc\\.config\\.[cm]?[jt]s$)/;\nconst REBOOT_DEBOUNCE_MS = 200;\n\ntype Booted = { app: DevApp; listener: ReturnType<typeof getRequestListener> };\n\nconst retire = async (booted: Booted): Promise<void> => {\n booted.app.server.socket.stop();\n await (booted.app.close ?? ((): void => booted.app.server.close()))();\n};\n\nconst said = (error: unknown): string => (error instanceof Error ? error.message : String(error));\n\nexport const mossDev = (options: MossDevOptions): Plugin => ({\n name: 'moss-dev',\n apply: 'serve',\n configureServer: (vite: ViteDevServer) => {\n const label = options.label ?? 'moss';\n const watch = options.watch ?? DEFAULT_WATCH;\n const owned = options.owned ?? MOSS_PATHS;\n const load = (id: string): Promise<Record<string, unknown>> => vite.ssrLoadModule(id);\n\n const boot = async (): Promise<Booted> => {\n const app = await options.app(load);\n return { app, listener: getRequestListener(app.server.fetch) };\n };\n let current = boot();\n current.catch((error: unknown) => vite.config.logger.error(`[${label}] the app did not boot: ${said(error)}`, { timestamp: true }));\n\n if (vite.httpServer !== null) {\n attachSocket(\n vite.httpServer,\n Object.assign(async (url: string, connection: Parameters<MossServer['socket']>[1]) => (await current).app.server.socket(url, connection), {\n // whichever server is current owns the revalidation timer; this handler owns none\n stop: (): void => void current.then(({ app }) => app.server.socket.stop(), () => undefined),\n }),\n );\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const reboot = (file: string): void => {\n if (!watch.test(file)) return;\n clearTimeout(timer);\n timer = setTimeout(() => {\n const outgoing = current;\n current = boot();\n current.then(\n () => {\n void outgoing.then(retire, () => undefined);\n vite.config.logger.info(`[${label}] app server re-booted`, { timestamp: true });\n vite.ws.send({ type: 'full-reload' });\n },\n (error: unknown) => {\n // the old server goes on answering until an edit boots\n current = outgoing;\n vite.config.logger.error(`[${label}] re-boot failed: ${said(error)}`, { timestamp: true });\n },\n );\n }, REBOOT_DEBOUNCE_MS);\n };\n vite.watcher.on('change', reboot);\n vite.watcher.on('add', reboot);\n vite.watcher.on('unlink', reboot);\n vite.httpServer?.once('close', () => void current.then(retire, () => undefined));\n\n vite.middlewares.use((req, res, next) => {\n const url = req.url ?? '/';\n const path = url.split('?')[0] ?? '/';\n\n const who = /^\\/dev\\/as\\/([\\w.@%-]+)$/.exec(path)?.[1];\n if (who !== undefined) {\n void current\n .then(async ({ app }) => {\n if (app.signIn === undefined) {\n next();\n return;\n }\n const token = await app.signIn(decodeURIComponent(who));\n const key = JSON.stringify(app.tokenKey ?? 'nisc.token');\n res.setHeader('content-type', 'text/html; charset=utf-8');\n res.end(\n token === null\n ? `<p>nobody called ${who.replace(/[<&\"]/g, '')}</p>`\n : `<script>localStorage.setItem(${key},${JSON.stringify(token)});document.cookie=encodeURIComponent(${key})+'='+encodeURIComponent(${JSON.stringify(token)})+'; Path=/; SameSite=Lax';location.replace('/')</script>`,\n );\n })\n .catch(() => {\n res.statusCode = 500;\n res.end('the dev sign-in failed');\n });\n return;\n }\n\n if (owned.test(path)) {\n void current.then(({ listener }) => listener(req, res)).catch(() => {\n res.statusCode = 503;\n res.end('the app server did not boot — see the dev server’s log');\n });\n return;\n }\n\n if (req.method !== 'GET') {\n next();\n return;\n }\n void current\n .then(async ({ app }) => {\n if (app.draw === undefined || (path !== '/' && path !== '/index.html' && app.server.page(path) === undefined)) {\n next();\n return;\n }\n const template = await vite.transformIndexHtml(url, await readFile(resolve(vite.config.root, options.index ?? 'index.html'), 'utf8'));\n const page = await renderDocument({\n server: app.server,\n template,\n request: { path: path === '/index.html' ? '/' : path, cookie: req.headers.cookie ?? null },\n draw: app.draw,\n ...(app.htmlAttributes !== undefined ? { htmlAttributes: app.htmlAttributes } : {}),\n ...(app.tokenKey !== undefined ? { tokenKey: app.tokenKey } : {}),\n });\n res.statusCode = 200;\n res.setHeader('content-type', 'text/html; charset=utf-8');\n for (const [name, value] of Object.entries(page.headers)) res.setHeader(name, value);\n res.end(page.html);\n })\n // not drawn is not broken: vite serves index.html as it always did\n .catch(() => next());\n });\n },\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niscorp/moss",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "moss — the nisc app server: serves existence (catalog, scoped vex, the socket), derived from artifacts",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -21,6 +21,16 @@
21
21
  "default": "./dist/index.cjs"
22
22
  }
23
23
  },
24
+ "./vite": {
25
+ "import": {
26
+ "types": "./dist/vite.d.ts",
27
+ "default": "./dist/vite.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/vite.d.cts",
31
+ "default": "./dist/vite.cjs"
32
+ }
33
+ },
24
34
  "./node": {
25
35
  "import": {
26
36
  "types": "./dist/node.d.ts",
@@ -160,14 +170,18 @@
160
170
  "react-dom": "^19.2.4",
161
171
  "zod": "^4.2.0",
162
172
  "vue": "^3.5.0",
173
+ "vite": ">=6",
163
174
  "@niscorp/charter": "^0.1.0",
164
- "@niscorp/nova": "^0.1.0",
165
- "@niscorp/prism": "^0.1.0",
175
+ "@niscorp/nova": "^0.1.1",
166
176
  "@niscorp/strata": "^0.1.0",
167
177
  "@niscorp/tide": "^0.1.0",
168
- "@niscorp/vex": "^0.1.0"
178
+ "@niscorp/vex": "^0.1.0",
179
+ "@niscorp/prism": "^0.1.1"
169
180
  },
170
181
  "peerDependenciesMeta": {
182
+ "vite": {
183
+ "optional": true
184
+ },
171
185
  "ink": {
172
186
  "optional": true
173
187
  },
@@ -193,15 +207,16 @@
193
207
  "react-dom": "^19.2.4",
194
208
  "tsup": "^8.5.1",
195
209
  "typescript": "^6.0.2",
210
+ "vite": "^7.1.12",
196
211
  "vitest": "^4.1.2",
197
212
  "vue": "^3.5.43",
198
213
  "zod": "^4.6.5",
199
- "@niscorp/nova": "^0.1.0",
214
+ "@niscorp/charter": "^0.1.0",
215
+ "@niscorp/prism": "^0.1.1",
200
216
  "@niscorp/strata": "^0.1.0",
217
+ "@niscorp/nova": "^0.1.1",
201
218
  "@niscorp/tide": "^0.1.0",
202
- "@niscorp/vex": "^0.1.0",
203
- "@niscorp/prism": "^0.1.0",
204
- "@niscorp/charter": "^0.1.0"
219
+ "@niscorp/vex": "^0.1.0"
205
220
  },
206
221
  "scripts": {
207
222
  "build": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\" && tsup",