@niscorp/moss 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/DESIGN.md +77 -40
  3. package/DOCS.md +673 -78
  4. package/README.md +2 -2
  5. package/dist/chunk-3DCTQKPQ.cjs +943 -0
  6. package/dist/chunk-3DCTQKPQ.cjs.map +1 -0
  7. package/dist/{chunk-WKBH3UMB.js → chunk-3T422CCN.js} +9 -3
  8. package/dist/chunk-3T422CCN.js.map +1 -0
  9. package/dist/chunk-6XC2MD7S.js +906 -0
  10. package/dist/chunk-6XC2MD7S.js.map +1 -0
  11. package/dist/{chunk-D3YZIAYV.cjs → chunk-I4UOWER3.cjs} +11 -5
  12. package/dist/chunk-I4UOWER3.cjs.map +1 -0
  13. package/dist/{chunk-VBWNHF4H.cjs → chunk-PVZMCEBX.cjs} +4 -3
  14. package/dist/chunk-PVZMCEBX.cjs.map +1 -0
  15. package/dist/{chunk-NSK7QSSG.js → chunk-QAHDSRPK.js} +4 -3
  16. package/dist/chunk-QAHDSRPK.js.map +1 -0
  17. package/dist/{chunk-R66WUKGC.cjs → chunk-TMDKNZYL.cjs} +2169 -1319
  18. package/dist/chunk-TMDKNZYL.cjs.map +1 -0
  19. package/dist/{chunk-V5YMJL7Z.js → chunk-YZILOVCR.js} +2147 -1295
  20. package/dist/chunk-YZILOVCR.js.map +1 -0
  21. package/dist/document-BYAY-Qle.d.ts +381 -0
  22. package/dist/document-DAE71J27.d.cts +381 -0
  23. package/dist/{index-B411sK9M.d.cts → index-CSEo7Tys.d.cts} +5 -0
  24. package/dist/{index-B411sK9M.d.ts → index-CSEo7Tys.d.ts} +5 -0
  25. package/dist/index.cjs +17 -17
  26. package/dist/index.d.cts +8 -10
  27. package/dist/index.d.ts +8 -10
  28. package/dist/index.js +3 -3
  29. package/dist/integrations.cjs +3 -3
  30. package/dist/integrations.d.cts +1 -1
  31. package/dist/integrations.d.ts +1 -1
  32. package/dist/integrations.js +1 -1
  33. package/dist/node.cjs +8 -8
  34. package/dist/node.d.cts +3 -4
  35. package/dist/node.d.ts +3 -4
  36. package/dist/node.js +4 -4
  37. package/dist/tide.d.cts +1 -1
  38. package/dist/tide.d.ts +1 -1
  39. package/dist/unverified.cjs +3 -3
  40. package/dist/unverified.js +2 -2
  41. package/dist/vite.cjs +9 -9
  42. package/dist/vite.d.cts +6 -1
  43. package/dist/vite.d.ts +6 -1
  44. package/dist/vite.js +4 -4
  45. package/package.json +13 -13
  46. package/dist/app-CUnDcXQu.d.ts +0 -143
  47. package/dist/app-CdANzi2q.d.cts +0 -143
  48. package/dist/chunk-D3YZIAYV.cjs.map +0 -1
  49. package/dist/chunk-NSK7QSSG.js.map +0 -1
  50. package/dist/chunk-PWUO4RET.js +0 -374
  51. package/dist/chunk-PWUO4RET.js.map +0 -1
  52. package/dist/chunk-R2YPQHQH.cjs +0 -383
  53. package/dist/chunk-R2YPQHQH.cjs.map +0 -1
  54. package/dist/chunk-R66WUKGC.cjs.map +0 -1
  55. package/dist/chunk-V5YMJL7Z.js.map +0 -1
  56. package/dist/chunk-VBWNHF4H.cjs.map +0 -1
  57. package/dist/chunk-WKBH3UMB.js.map +0 -1
  58. package/dist/document-D7nroBww.d.cts +0 -169
  59. package/dist/document-DeTPGBil.d.ts +0 -169
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/runtime/runtime.ts"],"names":["z"],"mappings":";;;;;AAsDO,IAAM,YAAY,CAAC,SAAA,KACxB,cAAc,MAAA,GACV,MAAA,GACA,CAAC,IAAA,KAAS;AACR,EAAA,IAAI;AACF,IAAA,SAAA,CAAU,KAAK,IAAI,CAAA;AAAA,EACrB,SAAS,GAAA,EAAK;AACZ,IAAA,OAAA,CAAQ,KAAA,CAAM,oBAAoB,GAAG,CAAA;AAAA,EACvC;AACF;AAIN,IAAM,YAAA,GAAe,MAAe,OAAO,WAAA,KAAgB,cAAc,WAAA,CAAY,GAAA,EAAI,GAAI,IAAA,CAAK,GAAA,EAAI;AAE/F,IAAM,YAAY,MAAiB;AACxC,EAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,GAAA,EAAI,GAAI,GAAA;AACnC,EAAA,MAAM,KAAK,YAAA,EAAa;AACxB,EAAA,OAAO,EAAE,eAAe,WAAA,EAAa,MAAM,iBAAiB,YAAA,EAAa,GAAI,MAAM,GAAA,EAAI;AACzF;AAEA,IAAM,KAAA,GAAQ,EAAE,MAAA,EAAQA,KAAA,CAAE,QAAO,EAAE;AAE5B,IAAM,mBAAA,GAAsBA,KAAA,CAAE,kBAAA,CAAmB,MAAA,EAAQ;AAAA,EAC9DA,KAAA,CAAE,YAAA,CAAa,EAAE,IAAA,EAAMA,MAAE,OAAA,CAAQ,qBAAqB,CAAA,EAAG,SAAA,EAAWA,KAAA,CAAE,MAAA,EAAO,EAAG,GAAG,OAAO,CAAA;AAAA,EAC1FA,KAAA,CAAE,YAAA,CAAa,EAAE,IAAA,EAAMA,MAAE,OAAA,CAAQ,gBAAgB,CAAA,EAAG,GAAA,EAAKA,KAAA,CAAE,MAAA,EAAO,EAAG,GAAG,OAAO,CAAA;AAAA,EAC/EA,MAAE,YAAA,CAAa,EAAE,MAAMA,KAAA,CAAE,OAAA,CAAQ,OAAO,CAAA,EAAG,SAAA,EAAWA,KAAA,CAAE,MAAA,IAAU,OAAA,EAASA,KAAA,CAAE,QAAO,EAAG,GAAG,OAAO;AACnG,CAAC","file":"chunk-VBWNHF4H.cjs","sourcesContent":["import type { Context, Next } from 'hono';\nimport type { CacheBackend, MutationClient, PgPool, QueryEngineConfig } from '@niscorp/vex';\nimport type { Sequence } from '@niscorp/strata';\nimport { z } from 'zod';\n\nexport type SessionVerifier = (token: string) => string | null | Promise<string | null>;\n\nexport type NiscRuntime = {\n pool: PgPool;\n db: MutationClient;\n cache?: CacheBackend;\n vexConfig?: QueryEngineConfig['config'];\n session: SessionVerifier | 'sessions' | 'dev-open';\n origins?: readonly string[];\n migrations?: 'apply' | 'verify';\n tables?: readonly Sequence[];\n shellIdleMs?: number;\n anonymousShellMax?: number;\n endpointTimeoutMs?: number;\n sessionRevalidateMs?: number;\n identityMax?: number;\n identityIdleMs?: number;\n shellFrameDelta?: boolean;\n socketCompression?: boolean | Record<string, unknown>;\n socketMaxMessageBytes?: number;\n operatorKey?: string;\n\n operatorGate?: (c: Context, next: Next) => Response | void | Promise<Response | void>;\n\n fabric?: Fabric;\n\n telemetry?: Telemetry;\n};\n\nexport type TelemetrySpan = {\n name: string;\n // A JS number cannot hold epoch nanoseconds exactly: the loss is far below\n // the milliseconds measured here.\n startUnixNano: number;\n endUnixNano: number;\n status: 'ok' | 'error' | 'refused';\n // Identifiers and measurements only: never a payload, a name, or who a principal is.\n attributes: Record<string, string | number | boolean>;\n traceId?: string;\n spanId?: string;\n parentSpanId?: string;\n};\n\nexport type Telemetry = {\n emit: (span: TelemetrySpan) => void;\n};\n\nexport type Emit = (span: TelemetrySpan) => void;\n\nexport const emitterOf = (telemetry: Telemetry | undefined): Emit | undefined =>\n telemetry === undefined\n ? undefined\n : (span) => {\n try {\n telemetry.emit(span);\n } catch (err) {\n console.error('[moss:telemetry]', err);\n }\n };\n\nexport type SpanClock = { startUnixNano: number; endUnixNano: () => number };\n\nconst elapsedClock = (): number => (typeof performance !== 'undefined' ? performance.now() : Date.now());\n\nexport const spanClock = (): SpanClock => {\n const startUnixNano = Date.now() * 1e6;\n const t0 = elapsedClock();\n return { startUnixNano, endUnixNano: () => startUnixNano + (elapsedClock() - t0) * 1e6 };\n};\n\nconst stamp = { origin: z.string() };\n\nexport const FabricMessageSchema = z.discriminatedUnion('kind', [\n z.strictObject({ kind: z.literal('invalidate-identity'), principal: z.string(), ...stamp }),\n z.strictObject({ kind: z.literal('invalidate-tag'), tag: z.string(), ...stamp }),\n z.strictObject({ kind: z.literal('nudge'), principal: z.string(), channel: z.string(), ...stamp }),\n]);\n\nexport type FabricMessage = z.infer<typeof FabricMessageSchema>;\n\ntype Unstamped<Message> = Message extends unknown ? Omit<Message, 'origin'> : never;\nexport type FabricSignal = Unstamped<FabricMessage>;\n\nexport type Fabric = {\n publish: (message: FabricMessage) => void;\n subscribe: (apply: (message: unknown) => void) => void;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/node/transport.ts","../src/node/index.ts"],"names":["listen"],"mappings":";;;;;;;;AAWA,IAAM,oBAAoB,GAAA,GAAM,IAAA;AAOzB,IAAM,eAAA,GAAkB,CAAC,MAAA,EAAsB,IAAA,KAAwC;AAC5F,EAAA,MAAM,WAA8B,EAAE,GAAG,MAAA,CAAO,SAAA,EAAW,GAAG,IAAA,EAAK;AACnE,EAAA,MAAM,GAAA,GAAM,IAAI,eAAA,CAAgB;AAAA,IAC9B,QAAA,EAAU,IAAA;AAAA,IACV,iBAAA,EAAmB,SAAS,WAAA,IAAe,IAAA;AAAA,IAC3C,UAAA,EAAY,SAAS,eAAA,IAAmB,iBAAA;AAAA;AAAA;AAAA,IAGxC,iBAAiB,CAAC,OAAA,KAAa,QAAQ,GAAA,CAAI,WAAW,IAAI,WAAA,GAAc;AAAA,GACzE,CAAA;AACD,EAAA,MAAM,OAAA,uBAAc,OAAA,EAA4C;AAChE,EAAA,GAAA,CAAI,EAAA,CAAG,SAAA,EAAW,CAAC,OAAA,EAAS,GAAA,KAAQ;AAClC,IAAA,KAAA,MAAW,MAAA,IAAU,OAAA,CAAQ,GAAA,CAAI,GAAG,CAAA,IAAK,EAAC,EAAG,OAAA,CAAQ,IAAA,CAAK,CAAA,YAAA,EAAe,MAAM,CAAA,CAAE,CAAA;AAAA,EACnF,CAAC,CAAA;AACD,EAAA,MAAM,OAAA,GAAgC,CAAC,GAAA,EAAK,MAAA,EAAQ,IAAA,KAAS;AAC3D,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,IAAO,GAAA;AACvB,IAAA,IAAI,EAAA;AACJ,IAAA,IAAI,QAAA,GAAW,KAAA;AACf,IAAA,IAAI,UAA6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AE,CAAA;AACnD,EAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,oGAAA,EAA8F,IAAI,CAAA,OAAA,CAAS,CAAA;AACvH,EAAA,MAAM,SAAS,MAAA,CAAO,KAAA;AACtB,EAAA,OAAO,MAAA,CAAO,OAAO,MAAA,EAAQ;AAAA,IAC3B,OAAO,MAAY;AACjB,MAAA,MAAA,EAAO;AACP,MAAA,OAAA,CAAQ,KAAA,EAAM;AACd,MAAA,UAAA,CAAW,KAAA,EAAM;AAAA,IACnB;AAAA,GACD,CAAA;AACH","file":"chunk-WKBH3UMB.js","sourcesContent":["import { WebSocketServer } from 'ws';\nimport type { WebSocket as ServerSocket } from 'ws';\nimport type { IncomingMessage } from 'node:http';\nimport type { Duplex } from 'node:stream';\nimport { SUBPROTOCOL } from '../protocol';\nimport type { SocketAccept, TransportSettings } from '../socket';\n\nexport type Upgradeable = {\n on: (event: 'upgrade', handler: (req: IncomingMessage, socket: Duplex, head: Buffer) => void) => unknown;\n};\n\nconst MAX_MESSAGE_BYTES = 256 * 1024;\n\nexport type Transport = {\n upgrade: (req: IncomingMessage, socket: Duplex, head: Buffer) => void;\n close: () => void;\n};\n\nexport const createTransport = (accept: SocketAccept, told?: TransportSettings): Transport => {\n const settings: TransportSettings = { ...accept.transport, ...told };\n const wss = new WebSocketServer({\n noServer: true,\n perMessageDeflate: settings.compression ?? true,\n maxPayload: settings.maxMessageBytes ?? MAX_MESSAGE_BYTES,\n // Only `nisc` is answered: the other entry a terminal offers is its token,\n // which is not said back.\n handleProtocols: (offered) => (offered.has(SUBPROTOCOL) ? SUBPROTOCOL : false),\n });\n const answers = new WeakMap<IncomingMessage, readonly string[]>();\n wss.on('headers', (headers, req) => {\n for (const cookie of answers.get(req) ?? []) headers.push(`Set-Cookie: ${cookie}`);\n });\n const upgrade: Transport['upgrade'] = (req, socket, head) => {\n const url = req.url ?? '/';\n let ws: ServerSocket | undefined;\n let answered = false;\n let cookies: readonly string[] = [];\n // The request is answered at the first use of the connection: by then moss\n // has named the cookies the 101 carries. One `ws` will not upgrade leaves\n // `ws` undefined.\n const answer = (): ServerSocket | undefined => {\n if (answered) return ws;\n answered = true;\n answers.set(req, cookies);\n wss.handleUpgrade(req, socket, head, (opened) => {\n ws = opened;\n // An 'error' nobody listens for is thrown by Node and ends the process.\n // `ws` has already closed the connection with the status that says why.\n opened.on('error', (error) => {\n console.warn(`[moss/node] a connection was closed on what it sent: ${error.message}`);\n });\n });\n return ws;\n };\n accept(url, {\n send: (text) => void answer()?.send(text),\n close: (code, reason) => void answer()?.close(code, reason),\n onMessage: (fn) => void answer()?.on('message', (data) => fn(String(data))),\n onClose: (fn) => {\n const opened = answer();\n if (opened === undefined) queueMicrotask(fn);\n else opened.on('close', () => fn());\n },\n upgrade: {\n offered: String(req.headers['sec-websocket-protocol'] ?? '').split(',').map((entry) => entry.trim()),\n origin: req.headers.origin ?? null,\n host: req.headers.host ?? null,\n cookie: req.headers.cookie ?? null,\n answer: (given) => void (cookies = given),\n },\n }).catch((error: unknown) => {\n console.error('[moss/node] a connection escaped accept:', error);\n try {\n answer()?.close(1011, 'accept failed');\n } catch {\n // Already gone.\n }\n });\n };\n return {\n upgrade,\n close: () => {\n for (const client of wss.clients) client.close(1001, 'server closing');\n wss.close();\n },\n };\n};\n\nexport const listenForUpgrades = (httpServer: Upgradeable, path: string, upgrade: Transport['upgrade']): void => {\n httpServer.on('upgrade', (req, socket, head) => {\n // Any other is left for the listener that owns it (vite's HMR in dev).\n if (new URL(req.url ?? '/', 'http://nisc.local').pathname !== path) return;\n // Until moss answers the request, a peer that resets the raw socket would\n // be an 'error' nobody hears, which ends the process.\n socket.on('error', () => {});\n upgrade(req, socket, head);\n });\n};\n","import { readFile } from 'node:fs/promises';\nimport { extname, join, relative } from 'node:path';\nimport { serve as listen } from '@hono/node-server';\nimport { serveStatic } from '@hono/node-server/serve-static';\nimport type { Context } from 'hono';\nimport { renderDocument } from '../documents';\nimport type { DocumentConfig } from '../documents';\nimport type { NiscApp } from '../manifest';\nimport type { NiscRuntime } from '../runtime';\nimport type { SocketAccept, TransportSettings } from '../socket';\nimport type { Env, MossServer } from '../server';\nimport { createServer } from '../server';\nimport { createTransport, listenForUpgrades } from './transport';\nimport type { Upgradeable } from './transport';\n\nexport const attachSocket = (\n httpServer: Upgradeable,\n accept: SocketAccept,\n path = '/socket',\n options?: TransportSettings,\n): { close: () => void } => {\n const transport = createTransport(accept, options);\n listenForUpgrades(httpServer, path, transport.upgrade);\n return { close: transport.close };\n};\n\nexport type SiteConfig = Pick<DocumentConfig, 'draw' | 'htmlAttributes' | 'site' | 'tokenKey' | 'waitMs'> & {\n dist: string;\n owned?: RegExp;\n};\n\n// Names a feature's prefix (`integrations`) on purpose: the dev plugin answers\n// an owned path 503 when the app did not boot, and a server that did not boot\n// cannot say what it owns.\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: Context<Env, string>, 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 // A name with an extension that the static server did not find is a missing\n // file, not a page: a browser holding a page from before a deploy asks for\n // its old script, and needs a 404.\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, host: c.req.header('host') ?? 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 const sockets = attachSocket(httpServer, server.socket);\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 const retire = server.close;\n return Object.assign(server, {\n close: (): void => {\n retire();\n sockets.close();\n httpServer.close();\n },\n });\n};\n"]}
@@ -1,169 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { VerifyReport } from '@niscorp/charter';
3
- import { Shell, RenderNode, ActionDefinition } from '@niscorp/nova';
4
- import { ScopePolicy } from '@niscorp/vex';
5
- import { S as SocketAccept } from './socket-D90h1xSV.cjs';
6
- import { ScreenHead } from '@niscorp/nova/document';
7
-
8
- type IdentityReport = {
9
- principal: string;
10
- since: number;
11
- lastSeen: number;
12
- };
13
- type IdentityRecord = {
14
- roles: readonly string[];
15
- scope: Record<string, unknown>;
16
- installed?: readonly string[];
17
- tag?: string;
18
- };
19
-
20
- type ResolvedIdentity = {
21
- roles: readonly string[];
22
- scope: Record<string, unknown>;
23
- installed: readonly string[] | undefined;
24
- memoKey: string;
25
- record?: IdentityRecord;
26
- };
27
-
28
- type Catalog = {
29
- ids: readonly string[];
30
- hash: string;
31
- };
32
-
33
- type ExecuteAs = (role: string, fingerprint: string, context: Record<string, unknown>, scope?: Record<string, unknown>) => Promise<unknown>;
34
-
35
- type ShellConnection = {
36
- send: (text: string) => void;
37
- close: (code?: number, reason?: string) => void;
38
- seal?: (token: string) => Promise<string>;
39
- };
40
- type ShellSession = {
41
- readonly shell: Shell;
42
- attach: (connection: ShellConnection, options?: {
43
- delta?: boolean;
44
- }) => void;
45
- detach: (connection: ShellConnection) => void;
46
- resync: (connection: ShellConnection) => void;
47
- dispatch: (canvas: string, event: Record<string, unknown>) => void;
48
- publish: (channel: string, payload?: unknown) => void;
49
- back: () => boolean;
50
- popTo: (canvas: string, instance: string) => void;
51
- reset: () => void;
52
- };
53
- type ShellReport = {
54
- principal: string;
55
- connections: number;
56
- since: number;
57
- idleSince: number | null;
58
- canvases: {
59
- id: string;
60
- actions: readonly string[];
61
- }[];
62
- };
63
- type ShellSnapshot = {
64
- frame: RenderNode[];
65
- trees: Record<string, RenderNode[]>;
66
- seed?: string;
67
- settled: boolean;
68
- live: boolean;
69
- why: string[];
70
- drawnWith: string[];
71
- };
72
- type ShellOpening = {
73
- seed?: string;
74
- inputs?: Record<string, Record<string, unknown>>;
75
- };
76
- type ShellHost = {
77
- session: (token: string | null, principal: string | null, options?: ShellOpening) => Promise<ShellSession>;
78
- snapshot: (token: string | null, principal: string | null, options?: {
79
- waitMs?: number;
80
- inputs?: ShellOpening['inputs'];
81
- }) => Promise<ShellSnapshot>;
82
- deliver: (principal: string, channel: string, payload?: unknown) => boolean;
83
- list: () => ShellReport[];
84
- reset: (principal: string) => boolean;
85
- };
86
-
87
- type Env = {
88
- Variables: {
89
- principal: string | null;
90
- resolved: ResolvedIdentity;
91
- };
92
- };
93
- type MossServer = Hono<Env> & {
94
- socket: SocketAccept;
95
- shells?: ShellHost;
96
- principalOf: (token: string) => Promise<string | null>;
97
- page: (path: string) => {
98
- name: string;
99
- host: ShellHost;
100
- inputs: Record<string, Record<string, unknown>>;
101
- } | undefined;
102
- pages: readonly {
103
- name: string;
104
- path: string;
105
- }[];
106
- refresh: () => void;
107
- replaceActions: (source: string, actions: Record<string, ActionDefinition>) => void;
108
- actions: () => Readonly<Record<string, ActionDefinition>>;
109
- catalogOf: (principal: string | null) => Promise<Catalog>;
110
- policyForRoles: (roles: readonly string[]) => ScopePolicy;
111
- charterReport: () => VerifyReport;
112
- invalidateIdentity: (principal: string) => boolean;
113
- identity: (principal: string | null) => Promise<IdentityRecord>;
114
- executeAs: ExecuteAs;
115
- invalidateTag: (tag: string) => number;
116
- nudge: (principal: string, channel: string) => void;
117
- close: () => void;
118
- identities?: {
119
- list: () => IdentityReport[];
120
- meter: () => {
121
- size: number;
122
- max: number;
123
- resolved: number;
124
- evicted: number;
125
- expired: number;
126
- };
127
- };
128
- };
129
-
130
- type DocumentHost = Pick<ShellHost, 'snapshot'>;
131
- type DocumentSource = {
132
- principalOf: (token: string) => Promise<string | null>;
133
- page: (path: string) => {
134
- name: string;
135
- host: DocumentHost;
136
- inputs: Record<string, Record<string, unknown>>;
137
- } | undefined;
138
- shells?: DocumentHost;
139
- };
140
- type DocumentConfig = {
141
- server: DocumentSource;
142
- template: string;
143
- request: {
144
- path: string;
145
- cookie?: string | null;
146
- host?: string | null;
147
- };
148
- draw: (snapshot: ShellSnapshot) => string | Promise<string>;
149
- htmlAttributes?: (snapshot: ShellSnapshot) => Record<string, string>;
150
- site?: string;
151
- tokenKey?: string;
152
- waitMs?: number;
153
- root?: string;
154
- };
155
- type DrawnDocument = {
156
- html: string;
157
- headers: Record<string, string>;
158
- drawn: boolean;
159
- principal: string | null;
160
- page?: string;
161
- head?: ScreenHead;
162
- live?: boolean;
163
- why?: string[];
164
- drawnWith?: string[];
165
- settled?: boolean;
166
- };
167
- declare const renderDocument: (config: DocumentConfig) => Promise<DrawnDocument>;
168
-
169
- export { type DocumentConfig as D, type ExecuteAs as E, type IdentityRecord as I, type MossServer as M, type ShellHost as S, type DrawnDocument as a, type ShellSnapshot as b, renderDocument as r };
@@ -1,169 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { VerifyReport } from '@niscorp/charter';
3
- import { Shell, RenderNode, ActionDefinition } from '@niscorp/nova';
4
- import { ScopePolicy } from '@niscorp/vex';
5
- import { S as SocketAccept } from './socket-D90h1xSV.js';
6
- import { ScreenHead } from '@niscorp/nova/document';
7
-
8
- type IdentityReport = {
9
- principal: string;
10
- since: number;
11
- lastSeen: number;
12
- };
13
- type IdentityRecord = {
14
- roles: readonly string[];
15
- scope: Record<string, unknown>;
16
- installed?: readonly string[];
17
- tag?: string;
18
- };
19
-
20
- type ResolvedIdentity = {
21
- roles: readonly string[];
22
- scope: Record<string, unknown>;
23
- installed: readonly string[] | undefined;
24
- memoKey: string;
25
- record?: IdentityRecord;
26
- };
27
-
28
- type Catalog = {
29
- ids: readonly string[];
30
- hash: string;
31
- };
32
-
33
- type ExecuteAs = (role: string, fingerprint: string, context: Record<string, unknown>, scope?: Record<string, unknown>) => Promise<unknown>;
34
-
35
- type ShellConnection = {
36
- send: (text: string) => void;
37
- close: (code?: number, reason?: string) => void;
38
- seal?: (token: string) => Promise<string>;
39
- };
40
- type ShellSession = {
41
- readonly shell: Shell;
42
- attach: (connection: ShellConnection, options?: {
43
- delta?: boolean;
44
- }) => void;
45
- detach: (connection: ShellConnection) => void;
46
- resync: (connection: ShellConnection) => void;
47
- dispatch: (canvas: string, event: Record<string, unknown>) => void;
48
- publish: (channel: string, payload?: unknown) => void;
49
- back: () => boolean;
50
- popTo: (canvas: string, instance: string) => void;
51
- reset: () => void;
52
- };
53
- type ShellReport = {
54
- principal: string;
55
- connections: number;
56
- since: number;
57
- idleSince: number | null;
58
- canvases: {
59
- id: string;
60
- actions: readonly string[];
61
- }[];
62
- };
63
- type ShellSnapshot = {
64
- frame: RenderNode[];
65
- trees: Record<string, RenderNode[]>;
66
- seed?: string;
67
- settled: boolean;
68
- live: boolean;
69
- why: string[];
70
- drawnWith: string[];
71
- };
72
- type ShellOpening = {
73
- seed?: string;
74
- inputs?: Record<string, Record<string, unknown>>;
75
- };
76
- type ShellHost = {
77
- session: (token: string | null, principal: string | null, options?: ShellOpening) => Promise<ShellSession>;
78
- snapshot: (token: string | null, principal: string | null, options?: {
79
- waitMs?: number;
80
- inputs?: ShellOpening['inputs'];
81
- }) => Promise<ShellSnapshot>;
82
- deliver: (principal: string, channel: string, payload?: unknown) => boolean;
83
- list: () => ShellReport[];
84
- reset: (principal: string) => boolean;
85
- };
86
-
87
- type Env = {
88
- Variables: {
89
- principal: string | null;
90
- resolved: ResolvedIdentity;
91
- };
92
- };
93
- type MossServer = Hono<Env> & {
94
- socket: SocketAccept;
95
- shells?: ShellHost;
96
- principalOf: (token: string) => Promise<string | null>;
97
- page: (path: string) => {
98
- name: string;
99
- host: ShellHost;
100
- inputs: Record<string, Record<string, unknown>>;
101
- } | undefined;
102
- pages: readonly {
103
- name: string;
104
- path: string;
105
- }[];
106
- refresh: () => void;
107
- replaceActions: (source: string, actions: Record<string, ActionDefinition>) => void;
108
- actions: () => Readonly<Record<string, ActionDefinition>>;
109
- catalogOf: (principal: string | null) => Promise<Catalog>;
110
- policyForRoles: (roles: readonly string[]) => ScopePolicy;
111
- charterReport: () => VerifyReport;
112
- invalidateIdentity: (principal: string) => boolean;
113
- identity: (principal: string | null) => Promise<IdentityRecord>;
114
- executeAs: ExecuteAs;
115
- invalidateTag: (tag: string) => number;
116
- nudge: (principal: string, channel: string) => void;
117
- close: () => void;
118
- identities?: {
119
- list: () => IdentityReport[];
120
- meter: () => {
121
- size: number;
122
- max: number;
123
- resolved: number;
124
- evicted: number;
125
- expired: number;
126
- };
127
- };
128
- };
129
-
130
- type DocumentHost = Pick<ShellHost, 'snapshot'>;
131
- type DocumentSource = {
132
- principalOf: (token: string) => Promise<string | null>;
133
- page: (path: string) => {
134
- name: string;
135
- host: DocumentHost;
136
- inputs: Record<string, Record<string, unknown>>;
137
- } | undefined;
138
- shells?: DocumentHost;
139
- };
140
- type DocumentConfig = {
141
- server: DocumentSource;
142
- template: string;
143
- request: {
144
- path: string;
145
- cookie?: string | null;
146
- host?: string | null;
147
- };
148
- draw: (snapshot: ShellSnapshot) => string | Promise<string>;
149
- htmlAttributes?: (snapshot: ShellSnapshot) => Record<string, string>;
150
- site?: string;
151
- tokenKey?: string;
152
- waitMs?: number;
153
- root?: string;
154
- };
155
- type DrawnDocument = {
156
- html: string;
157
- headers: Record<string, string>;
158
- drawn: boolean;
159
- principal: string | null;
160
- page?: string;
161
- head?: ScreenHead;
162
- live?: boolean;
163
- why?: string[];
164
- drawnWith?: string[];
165
- settled?: boolean;
166
- };
167
- declare const renderDocument: (config: DocumentConfig) => Promise<DrawnDocument>;
168
-
169
- export { type DocumentConfig as D, type ExecuteAs as E, type IdentityRecord as I, type MossServer as M, type ShellHost as S, type DrawnDocument as a, type ShellSnapshot as b, renderDocument as r };