@tschk/moonshine-framework 0.3.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/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # `@tschk/moonshine-framework`
2
+
3
+ Public framework contracts shared by the router, compiler, server, renderers,
4
+ and deployment adapters.
5
+
6
+ ```ts
7
+ import {
8
+ defineConfig,
9
+ defineRoute,
10
+ MANIFEST_VERSION,
11
+ } from "@tschk/moonshine-framework";
12
+
13
+ const route = defineRoute({
14
+ id: "home",
15
+ path: "/",
16
+ file: "src/routes/index.tsx",
17
+ });
18
+
19
+ const config = defineConfig({ runtime: "bun", mode: "auto" });
20
+ ```
21
+
22
+ Exports include:
23
+
24
+ - `RouteDefinition`, `RenderMode`, `RuntimeTarget`
25
+ - `MoonshineManifest`, `RouteArtifact`, `MANIFEST_VERSION`
26
+ - `Renderer`, `RenderContext`, `DeploymentAdapter`
27
+ - `defineConfig`, `defineRoute`
28
+
29
+ See [docs/MANIFEST.md](../../docs/MANIFEST.md) and
30
+ [DESIGN.md](../../DESIGN.md).
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@tschk/moonshine-framework",
3
+ "version": "0.3.1",
4
+ "license": "ISC",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ ".": "./src/index.ts"
10
+ },
11
+ "scripts": {
12
+ "format": "bunx prettier --check .",
13
+ "lint": "bunx oxlint .",
14
+ "typecheck": "bunx tsc --noEmit",
15
+ "test": "bun test"
16
+ },
17
+ "dependencies": {
18
+ "@tschk/moonshine": "^0.3.1"
19
+ },
20
+ "devDependencies": {
21
+ "@types/bun": "1.3.14",
22
+ "typescript": "7.0.2"
23
+ }
24
+ }
package/src/adapter.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { MoonshineManifest } from "./manifest";
2
+ import type { RouteDefinition, RuntimeTarget } from "./routes";
3
+
4
+ export type DeploymentAdapter = {
5
+ name: string;
6
+ runtimes: RuntimeTarget[];
7
+ capabilities: MoonshineManifest["capabilities"];
8
+ build(manifest: MoonshineManifest, outDir: string): Promise<void>;
9
+ };
10
+
11
+ export function defineRoute<T extends RouteDefinition>(route: T): T {
12
+ return route;
13
+ }
package/src/config.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { RenderMode, RuntimeTarget } from "./routes";
2
+
3
+ export type MoonshineConfig = {
4
+ mode?: RenderMode;
5
+ runtime?: RuntimeTarget;
6
+ };
7
+
8
+ export function defineConfig<T extends MoonshineConfig>(config: T): T {
9
+ return config;
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./adapter";
2
+ export * from "./config";
3
+ export * from "./manifest";
4
+ export * from "./renderer";
5
+ export * from "./routes";
@@ -0,0 +1,23 @@
1
+ import type { RenderMode, RouteDefinition, RuntimeTarget } from "./routes";
2
+
3
+ export const MANIFEST_VERSION = 1 as const;
4
+
5
+ export type RouteArtifact = RouteDefinition & {
6
+ mode: Exclude<RenderMode, "auto">;
7
+ runtime: RuntimeTarget;
8
+ decision: string;
9
+ serverEntry?: string;
10
+ clientEntries: string[];
11
+ staticOutput?: string;
12
+ cache?: { control?: string; revalidate?: number };
13
+ headers?: Record<string, string>;
14
+ };
15
+
16
+ export type MoonshineManifest = {
17
+ version: typeof MANIFEST_VERSION;
18
+ frameworkVersion: string;
19
+ routes: RouteArtifact[];
20
+ assets: Array<{ path: string; file: string; integrity?: string }>;
21
+ entries: { server?: string; client?: string };
22
+ capabilities: Array<"streaming" | "islands" | "edge" | "revalidation">;
23
+ };
@@ -0,0 +1,15 @@
1
+ import type { RouteArtifact } from "./manifest";
2
+
3
+ export type RenderContext = {
4
+ request: Request;
5
+ route: RouteArtifact;
6
+ params: Record<string, string>;
7
+ data: unknown;
8
+ signal: AbortSignal;
9
+ };
10
+
11
+ export type Renderer = {
12
+ name: string;
13
+ render(context: RenderContext): Promise<Response>;
14
+ prerender(context: RenderContext): Promise<string>;
15
+ };
package/src/routes.ts ADDED
@@ -0,0 +1,14 @@
1
+ export type RenderMode = "auto" | "static" | "ssr" | "island" | "spa" | "api";
2
+ export type RuntimeTarget = "bun" | "node" | "cloudflare" | "vercel-edge";
3
+
4
+ export type RouteDefinition = {
5
+ id: string;
6
+ path: string;
7
+ file: string;
8
+ mode?: RenderMode;
9
+ runtime?: RuntimeTarget;
10
+ layouts?: string[];
11
+ middleware?: string[];
12
+ errorBoundary?: string;
13
+ dataFile?: string;
14
+ };
@@ -0,0 +1,13 @@
1
+ import { expect, test } from "bun:test";
2
+ import { defineConfig, defineRoute, MANIFEST_VERSION } from "../src";
3
+
4
+ test("contracts preserve exact input and version one", () => {
5
+ const route = defineRoute({
6
+ id: "home",
7
+ path: "/",
8
+ file: "src/routes/index.tsx",
9
+ });
10
+ expect(route.path).toBe("/");
11
+ expect(defineConfig({ mode: "auto" }).mode).toBe("auto");
12
+ expect(MANIFEST_VERSION).toBe(1);
13
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "include": ["src/**/*", "test/**/*"]
4
+ }