@alecsibilia/ui-kit 0.0.0-stage → 0.1.0-alpha.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.
- package/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +233 -2
- package/bin/ui-kit.js +12 -0
- package/dist/alchemy/app.d.ts +34 -0
- package/dist/alchemy/app.js +88 -0
- package/dist/alchemy/index.d.ts +11 -0
- package/dist/alchemy/index.js +11 -0
- package/dist/alchemy/live-rooms.d.ts +21 -0
- package/dist/alchemy/live-rooms.js +31 -0
- package/dist/alchemy/migrations.d.ts +28 -0
- package/dist/alchemy/migrations.js +56 -0
- package/dist/alchemy/stage.d.ts +20 -0
- package/dist/alchemy/stage.js +20 -0
- package/dist/alchemy/wrangler-config.d.ts +76 -0
- package/dist/alchemy/wrangler-config.js +82 -0
- package/dist/build/app-modules.d.ts +11 -0
- package/dist/build/app-modules.js +40 -0
- package/dist/build/check.d.ts +4 -0
- package/dist/build/check.js +170 -0
- package/dist/build/cli.d.ts +1 -0
- package/dist/build/cli.js +79 -0
- package/dist/build/feature.d.ts +8 -0
- package/dist/build/feature.js +24 -0
- package/dist/build/index.d.ts +13 -0
- package/dist/build/index.js +13 -0
- package/dist/build/measure-cpu.d.ts +2 -0
- package/dist/build/measure-cpu.js +196 -0
- package/dist/build/prerender.d.ts +5 -0
- package/dist/build/prerender.js +109 -0
- package/dist/build/preview.d.ts +7 -0
- package/dist/build/preview.js +41 -0
- package/dist/build/seo-files.d.ts +27 -0
- package/dist/build/seo-files.js +24 -0
- package/dist/client/head-swap.d.ts +45 -0
- package/dist/client/head-swap.js +183 -0
- package/dist/client/hydration-pass.d.ts +56 -0
- package/dist/client/hydration-pass.js +186 -0
- package/dist/client/hydration-reset.d.ts +82 -0
- package/dist/client/hydration-reset.js +154 -0
- package/dist/client/index.d.ts +37 -0
- package/dist/client/index.js +65 -0
- package/dist/client/nav-client.d.ts +35 -0
- package/dist/client/nav-client.js +371 -0
- package/dist/live/collab/doc-provider.d.ts +74 -0
- package/dist/live/collab/doc-provider.js +412 -0
- package/dist/live/collab/index.d.ts +51 -0
- package/dist/live/collab/index.jsx +142 -0
- package/dist/live/collab-status.d.ts +25 -0
- package/dist/live/collab-status.js +17 -0
- package/dist/live/cursors/cursor-engine.d.ts +57 -0
- package/dist/live/cursors/cursor-engine.js +243 -0
- package/dist/live/cursors/index.d.ts +46 -0
- package/dist/live/cursors/index.jsx +110 -0
- package/dist/live/declaration.d.ts +113 -0
- package/dist/live/declaration.js +94 -0
- package/dist/live/index.d.ts +8 -0
- package/dist/live/index.js +8 -0
- package/dist/live/protocol.d.ts +224 -0
- package/dist/live/protocol.js +272 -0
- package/dist/live/server/doc-store.d.ts +68 -0
- package/dist/live/server/doc-store.js +187 -0
- package/dist/live/server/index.d.ts +60 -0
- package/dist/live/server/index.js +77 -0
- package/dist/live/server/room-presence.d.ts +24 -0
- package/dist/live/server/room-presence.js +123 -0
- package/dist/live/server/room-sockets.d.ts +65 -0
- package/dist/live/server/room-sockets.js +97 -0
- package/dist/live/server/room.d.ts +20 -0
- package/dist/live/server/room.js +348 -0
- package/dist/live/server/route.d.ts +56 -0
- package/dist/live/server/route.js +159 -0
- package/dist/live/server/types.d.ts +163 -0
- package/dist/live/server/types.js +2 -0
- package/dist/logic/agent-actions.d.ts +133 -0
- package/dist/logic/agent-actions.js +150 -0
- package/dist/logic/command-types.d.ts +53 -0
- package/dist/logic/command-types.js +0 -0
- package/dist/logic/dev.d.ts +9 -0
- package/dist/logic/dev.js +10 -0
- package/dist/logic/draft-rebase.d.ts +59 -0
- package/dist/logic/draft-rebase.js +71 -0
- package/dist/logic/form-state.d.ts +105 -0
- package/dist/logic/form-state.js +93 -0
- package/dist/logic/head.d.ts +145 -0
- package/dist/logic/head.js +140 -0
- package/dist/logic/index.d.ts +27 -0
- package/dist/logic/index.js +25 -0
- package/dist/logic/island-def.d.ts +89 -0
- package/dist/logic/island-def.js +59 -0
- package/dist/logic/kit-commands.d.ts +104 -0
- package/dist/logic/kit-commands.js +72 -0
- package/dist/logic/kit-errors.d.ts +25 -0
- package/dist/logic/kit-errors.js +6 -0
- package/dist/logic/listen.d.ts +99 -0
- package/dist/logic/listen.js +92 -0
- package/dist/logic/mutation-def.d.ts +65 -0
- package/dist/logic/mutation-def.js +43 -0
- package/dist/logic/navigation-data.d.ts +50 -0
- package/dist/logic/navigation-data.js +55 -0
- package/dist/logic/navigation-policy.d.ts +74 -0
- package/dist/logic/navigation-policy.js +127 -0
- package/dist/logic/page-model-def.d.ts +108 -0
- package/dist/logic/page-model-def.js +31 -0
- package/dist/logic/path.d.ts +31 -0
- package/dist/logic/path.js +48 -0
- package/dist/logic/query-def.d.ts +56 -0
- package/dist/logic/query-def.js +37 -0
- package/dist/logic/query-key.d.ts +24 -0
- package/dist/logic/query-key.js +35 -0
- package/dist/logic/query-types.d.ts +28 -0
- package/dist/logic/query-types.js +2 -0
- package/dist/logic/resources.d.ts +163 -0
- package/dist/logic/resources.js +62 -0
- package/dist/logic/result.d.ts +30 -0
- package/dist/logic/result.js +23 -0
- package/dist/logic/route-model.d.ts +139 -0
- package/dist/logic/route-model.js +207 -0
- package/dist/logic/route-params.d.ts +80 -0
- package/dist/logic/route-params.js +114 -0
- package/dist/logic/route-table.d.ts +308 -0
- package/dist/logic/route-table.js +206 -0
- package/dist/logic/seo.d.ts +61 -0
- package/dist/logic/seo.js +101 -0
- package/dist/logic/site.d.ts +12 -0
- package/dist/logic/site.js +0 -0
- package/dist/logic/subscriptions.d.ts +177 -0
- package/dist/logic/subscriptions.js +152 -0
- package/dist/render/index.d.ts +32 -0
- package/dist/render/index.js +52 -0
- package/dist/runtime/island-wake.d.ts +38 -0
- package/dist/runtime/island-wake.js +147 -0
- package/dist/runtime/query-scope.d.ts +224 -0
- package/dist/runtime/query-scope.js +222 -0
- package/dist/runtime/room-hub.d.ts +107 -0
- package/dist/runtime/room-hub.js +307 -0
- package/dist/runtime/subscription-runner.d.ts +71 -0
- package/dist/runtime/subscription-runner.js +240 -0
- package/dist/server/bindings.d.ts +41 -0
- package/dist/server/bindings.js +74 -0
- package/dist/server/browser.d.ts +9 -0
- package/dist/server/browser.js +9 -0
- package/dist/server/edge-cache.d.ts +28 -0
- package/dist/server/edge-cache.js +35 -0
- package/dist/server/errors.d.ts +45 -0
- package/dist/server/errors.js +36 -0
- package/dist/server/form-actions-setup.d.ts +1 -0
- package/dist/server/form-actions-setup.js +15 -0
- package/dist/server/form-actions.d.ts +121 -0
- package/dist/server/form-actions.js +211 -0
- package/dist/server/index.d.ts +36 -0
- package/dist/server/index.js +35 -0
- package/dist/server/inputs.d.ts +45 -0
- package/dist/server/inputs.js +77 -0
- package/dist/server/rate-limit.d.ts +29 -0
- package/dist/server/rate-limit.js +32 -0
- package/dist/server/read-cache.d.ts +74 -0
- package/dist/server/read-cache.js +58 -0
- package/dist/server/request-info.d.ts +17 -0
- package/dist/server/request-info.js +11 -0
- package/dist/server/request.d.ts +52 -0
- package/dist/server/request.js +73 -0
- package/dist/server/response-cookies.d.ts +23 -0
- package/dist/server/response-cookies.js +24 -0
- package/dist/server/run-effect.d.ts +42 -0
- package/dist/server/run-effect.js +92 -0
- package/dist/server/run.d.ts +63 -0
- package/dist/server/run.js +66 -0
- package/dist/server/session.d.ts +125 -0
- package/dist/server/session.js +247 -0
- package/dist/test/fake-bindings.d.ts +32 -0
- package/dist/test/fake-bindings.js +108 -0
- package/dist/test/fake-room.d.ts +66 -0
- package/dist/test/fake-room.js +216 -0
- package/dist/test/index.d.ts +19 -0
- package/dist/test/index.js +44 -0
- package/dist/test/probe.d.ts +11 -0
- package/dist/test/probe.js +11 -0
- package/dist/test/solid-jsx.d.ts +23 -0
- package/dist/test/solid-jsx.js +28 -0
- package/dist/test/solid-preload.d.ts +1 -0
- package/dist/test/solid-preload.js +29 -0
- package/dist/ui/code-editor/index.d.ts +21 -0
- package/dist/ui/code-editor/index.jsx +286 -0
- package/dist/ui/collab-text/index.d.ts +29 -0
- package/dist/ui/collab-text/index.jsx +96 -0
- package/dist/ui/components/controls.d.ts +69 -0
- package/dist/ui/components/controls.jsx +81 -0
- package/dist/ui/components/feedback.d.ts +26 -0
- package/dist/ui/components/feedback.jsx +80 -0
- package/dist/ui/components/layout.d.ts +74 -0
- package/dist/ui/components/layout.jsx +146 -0
- package/dist/ui/components/lists.d.ts +69 -0
- package/dist/ui/components/lists.jsx +133 -0
- package/dist/ui/components/navigation.d.ts +73 -0
- package/dist/ui/components/navigation.jsx +112 -0
- package/dist/ui/components/text.d.ts +34 -0
- package/dist/ui/components/text.jsx +163 -0
- package/dist/ui/index.d.ts +7 -0
- package/dist/ui/index.js +7 -0
- package/dist/ui/jsx-runtime.d.ts +19 -0
- package/dist/ui/jsx-runtime.js +0 -0
- package/dist/ui/list-keys.d.ts +31 -0
- package/dist/ui/list-keys.js +45 -0
- package/dist/ui/styles/base.css +38 -0
- package/dist/ui/styles/components.css +608 -0
- package/dist/ui/styles/tokens.css +27 -0
- package/dist/ui/styles/transitions.css +23 -0
- package/dist/ui/styles/workbench.css +428 -0
- package/dist/ui/styles.css +9 -0
- package/dist/view/agent-actions-view.d.ts +30 -0
- package/dist/view/agent-actions-view.js +27 -0
- package/dist/view/agent-surface.d.ts +42 -0
- package/dist/view/agent-surface.js +123 -0
- package/dist/view/app-scope.d.ts +51 -0
- package/dist/view/app-scope.js +75 -0
- package/dist/view/boundary.d.ts +18 -0
- package/dist/view/boundary.jsx +26 -0
- package/dist/view/command-runner.d.ts +16 -0
- package/dist/view/command-runner.js +245 -0
- package/dist/view/form.d.ts +82 -0
- package/dist/view/form.jsx +109 -0
- package/dist/view/head-view.d.ts +31 -0
- package/dist/view/head-view.js +46 -0
- package/dist/view/index.d.ts +41 -0
- package/dist/view/index.js +40 -0
- package/dist/view/island-root.d.ts +30 -0
- package/dist/view/island-root.js +36 -0
- package/dist/view/island.d.ts +102 -0
- package/dist/view/island.jsx +154 -0
- package/dist/view/match.d.ts +41 -0
- package/dist/view/match.js +111 -0
- package/dist/view/model.d.ts +92 -0
- package/dist/view/model.js +162 -0
- package/dist/view/navigation-head.d.ts +29 -0
- package/dist/view/navigation-head.jsx +38 -0
- package/dist/view/page-model.d.ts +46 -0
- package/dist/view/page-model.js +146 -0
- package/dist/view/query-effects.d.ts +87 -0
- package/dist/view/query-effects.js +147 -0
- package/dist/view/query-ok.d.ts +45 -0
- package/dist/view/query-ok.js +96 -0
- package/dist/view/query.d.ts +115 -0
- package/dist/view/query.jsx +179 -0
- package/dist/view/result-view.d.ts +14 -0
- package/dist/view/result-view.jsx +15 -0
- package/dist/view/route-pages.d.ts +43 -0
- package/dist/view/route-pages.js +59 -0
- package/dist/view/router.d.ts +44 -0
- package/dist/view/router.js +123 -0
- package/dist/vite/dev-middleware.d.ts +12 -0
- package/dist/vite/dev-middleware.js +39 -0
- package/dist/vite/dev-objects.d.ts +25 -0
- package/dist/vite/dev-objects.js +127 -0
- package/dist/vite/dev-platform.d.ts +19 -0
- package/dist/vite/dev-platform.js +77 -0
- package/dist/vite/dev-seo-files.d.ts +11 -0
- package/dist/vite/dev-seo-files.js +40 -0
- package/dist/vite/index.d.ts +53 -0
- package/dist/vite/index.js +148 -0
- package/dist/vite/local-config.d.ts +34 -0
- package/dist/vite/local-config.js +72 -0
- package/dist/vite/worker-build.d.ts +24 -0
- package/dist/vite/worker-build.js +84 -0
- package/dist/worker/create-worker.d.ts +52 -0
- package/dist/worker/create-worker.js +90 -0
- package/dist/worker/index.d.ts +12 -0
- package/dist/worker/index.js +12 -0
- package/dist/worker/page-routes.d.ts +88 -0
- package/dist/worker/page-routes.js +100 -0
- package/dist/worker/page-status.d.ts +41 -0
- package/dist/worker/page-status.js +23 -0
- package/dist/worker/request-prelude.d.ts +69 -0
- package/dist/worker/request-prelude.js +107 -0
- package/dist/worker/security.d.ts +76 -0
- package/dist/worker/security.js +137 -0
- package/dist/worker/server-app.d.ts +54 -0
- package/dist/worker/server-app.js +76 -0
- package/guards/browser-only.js +5 -0
- package/guards/node-only.js +6 -0
- package/guards/server-only.js +5 -0
- package/migrations/0001-sessions.sql +22 -0
- package/package.json +233 -5
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import solidPlugin from '@solidjs/vite-plugin';
|
|
5
|
+
import { devObjects, devObjectsProxy, devProxyLogger } from './dev-objects.js';
|
|
6
|
+
import { devSeoFiles } from './dev-seo-files.js';
|
|
7
|
+
import { writeLocalConfig } from './local-config.js';
|
|
8
|
+
import { serverStubs, workerServerBuild } from './worker-build.js';
|
|
9
|
+
import { GENERATED_DIR } from '../alchemy/migrations.js';
|
|
10
|
+
import { bindingSpecsOf } from '../logic/resources.js';
|
|
11
|
+
const DEFAULTS = {
|
|
12
|
+
serverApp: 'worker/server-app.ts',
|
|
13
|
+
worker: 'worker/index.ts',
|
|
14
|
+
objects: 'worker/objects.ts',
|
|
15
|
+
live: 'worker/live.ts',
|
|
16
|
+
livePrefix: '/live',
|
|
17
|
+
devObjectsPort: 5450,
|
|
18
|
+
tables: {
|
|
19
|
+
routes: '/src/routes.ts',
|
|
20
|
+
site: '/src/site.ts',
|
|
21
|
+
sitemapSources: '/src/sitemap-sources.ts',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
const kitModule = (name) => fileURLToPath(new URL(`./${name}${import.meta.url.endsWith('.ts') ? '.ts' : '.js'}`, import.meta.url));
|
|
25
|
+
/**
|
|
26
|
+
* A one-line module under the app's `.ui-kit/` that re-exports a kit
|
|
27
|
+
* module: the Solid plugin wants its middleware and server setup inside
|
|
28
|
+
* the Vite root.
|
|
29
|
+
*/
|
|
30
|
+
function middlewareStub(appDir) {
|
|
31
|
+
const dir = resolve(appDir, GENERATED_DIR);
|
|
32
|
+
mkdirSync(dir, { recursive: true });
|
|
33
|
+
const file = join(dir, 'dev-middleware.ts');
|
|
34
|
+
// One content for dev and build alike (a dev server and a build may run
|
|
35
|
+
// at once): the virtual module decides, by command.
|
|
36
|
+
writeFileSync(file, `// Generated by the ui-kit Vite plugin. Do not edit.\nexport { default } from ${JSON.stringify(MIDDLEWARE_ID)}\n`);
|
|
37
|
+
return file;
|
|
38
|
+
}
|
|
39
|
+
/** `vite dev`: the kit's dev middleware; a build: a pass-through (the Worker owns the request). */
|
|
40
|
+
const MIDDLEWARE_ID = 'virtual:ui-kit/middleware';
|
|
41
|
+
const SERVER_APP_ID = 'virtual:ui-kit/server-app';
|
|
42
|
+
const DEV_CONFIG_ID = 'virtual:ui-kit/dev-config';
|
|
43
|
+
/** The no-JS form protocol's setup, as a module in the app (side effect only). */
|
|
44
|
+
function setupStub(appDir) {
|
|
45
|
+
const dir = resolve(appDir, GENERATED_DIR);
|
|
46
|
+
mkdirSync(dir, { recursive: true });
|
|
47
|
+
const file = join(dir, 'form-actions-setup.ts');
|
|
48
|
+
const target = fileURLToPath(new URL(`../server/form-actions-setup${import.meta.url.endsWith('.ts') ? '.ts' : '.js'}`, import.meta.url));
|
|
49
|
+
writeFileSync(file, `// Generated by the ui-kit Vite plugin. Do not edit.\nimport ${JSON.stringify(target)}\n`);
|
|
50
|
+
return file;
|
|
51
|
+
}
|
|
52
|
+
export function uiKit(options) {
|
|
53
|
+
const resources = options.resources;
|
|
54
|
+
const serverApp = options.serverApp ?? DEFAULTS.serverApp;
|
|
55
|
+
const livePrefix = options.livePrefix ?? DEFAULTS.livePrefix;
|
|
56
|
+
const port = options.devObjectsPort ?? DEFAULTS.devObjectsPort;
|
|
57
|
+
let local;
|
|
58
|
+
let root = process.cwd();
|
|
59
|
+
let command = 'build';
|
|
60
|
+
const localConfig = () => {
|
|
61
|
+
local ??= writeLocalConfig({ appDir: root, resources });
|
|
62
|
+
return local;
|
|
63
|
+
};
|
|
64
|
+
const hasObjects = Object.keys(resources.durableObjects ?? {}).length > 0 ||
|
|
65
|
+
resources.liveRooms !== undefined;
|
|
66
|
+
const core = {
|
|
67
|
+
name: 'ui-kit',
|
|
68
|
+
enforce: 'pre',
|
|
69
|
+
config(config, env) {
|
|
70
|
+
root = config.root ?? process.cwd();
|
|
71
|
+
command = env.command;
|
|
72
|
+
return {
|
|
73
|
+
customLogger: env.command === 'serve' ? devProxyLogger() : undefined,
|
|
74
|
+
environments: {
|
|
75
|
+
// Kept for `ui-kit prerender`, which maps the prerender
|
|
76
|
+
// build's asset names to the deployed ones.
|
|
77
|
+
client: { build: { manifest: true } },
|
|
78
|
+
},
|
|
79
|
+
server: {
|
|
80
|
+
proxy: env.command === 'serve' && hasObjects
|
|
81
|
+
? devObjectsProxy(livePrefix, port)
|
|
82
|
+
: undefined,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
configResolved(config) {
|
|
87
|
+
root = config.root;
|
|
88
|
+
localConfig();
|
|
89
|
+
},
|
|
90
|
+
resolveId(id) {
|
|
91
|
+
if (id === SERVER_APP_ID ||
|
|
92
|
+
id === DEV_CONFIG_ID ||
|
|
93
|
+
id === MIDDLEWARE_ID)
|
|
94
|
+
return `\0${id}`;
|
|
95
|
+
return null;
|
|
96
|
+
},
|
|
97
|
+
load(id) {
|
|
98
|
+
if (id === `\0${MIDDLEWARE_ID}`) {
|
|
99
|
+
return command === 'serve'
|
|
100
|
+
? `export { default } from ${JSON.stringify(kitModule('dev-middleware'))}`
|
|
101
|
+
: 'export default (_event, next) => next()';
|
|
102
|
+
}
|
|
103
|
+
if (id === `\0${SERVER_APP_ID}`) {
|
|
104
|
+
return `export { serverApp } from ${JSON.stringify(`/${serverApp}`)}`;
|
|
105
|
+
}
|
|
106
|
+
if (id === `\0${DEV_CONFIG_ID}`) {
|
|
107
|
+
return `export default ${JSON.stringify({
|
|
108
|
+
local: localConfig(),
|
|
109
|
+
// The platform proxy has every binding but the Durable Objects
|
|
110
|
+
// (the dev side Worker runs those).
|
|
111
|
+
names: Object.entries(bindingSpecsOf(resources))
|
|
112
|
+
.filter(([, spec]) => spec.kind !== 'Durable Object namespace')
|
|
113
|
+
.map(([name]) => name),
|
|
114
|
+
})}`;
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
return [
|
|
120
|
+
core,
|
|
121
|
+
...solidPlugin({
|
|
122
|
+
start: {
|
|
123
|
+
middleware: middlewareStub(process.cwd()),
|
|
124
|
+
},
|
|
125
|
+
ssr: true,
|
|
126
|
+
serverFunctions: {
|
|
127
|
+
serverSetup: setupStub(process.cwd()),
|
|
128
|
+
},
|
|
129
|
+
css: { devInline: { include: /ui-kit/ } },
|
|
130
|
+
}),
|
|
131
|
+
workerServerBuild(options.worker ?? DEFAULTS.worker),
|
|
132
|
+
serverStubs(options.prerenderOnly),
|
|
133
|
+
...(hasObjects
|
|
134
|
+
? [
|
|
135
|
+
devObjects({
|
|
136
|
+
resources,
|
|
137
|
+
local: localConfig,
|
|
138
|
+
objects: options.objects ?? DEFAULTS.objects,
|
|
139
|
+
live: options.live ?? DEFAULTS.live,
|
|
140
|
+
port,
|
|
141
|
+
}),
|
|
142
|
+
]
|
|
143
|
+
: []),
|
|
144
|
+
devSeoFiles(options.tables ?? DEFAULTS.tables),
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
export { PRERENDER_BUILD_ENV } from './worker-build.js';
|
|
148
|
+
export { LOCAL_STATE_DIR, migrateLocalD1, writeLocalConfig, } from './local-config.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ResourcesDecl } from '../logic/resources.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The local workerd files an app's tooling writes under `.ui-kit/` (never
|
|
4
|
+
* committed): the assembled D1 migrations and `wrangler.json`, made from
|
|
5
|
+
* the resource declaration. `vite dev` (platform proxy), `ui-kit preview`
|
|
6
|
+
* (`wrangler dev`) and the dev Durable Object Worker read them.
|
|
7
|
+
*/
|
|
8
|
+
/** Where local workerd keeps its state (D1, R2, Durable Objects), under the app. */
|
|
9
|
+
export declare const LOCAL_STATE_DIR = ".wrangler/state";
|
|
10
|
+
/** The paths `writeLocalConfig` wrote. */
|
|
11
|
+
export interface LocalConfig {
|
|
12
|
+
readonly appDir: string;
|
|
13
|
+
/** `.ui-kit/wrangler.json` (the main Worker: built `main`, static assets). */
|
|
14
|
+
readonly wranglerPath: string;
|
|
15
|
+
/**
|
|
16
|
+
* `.ui-kit/wrangler.platform.json`: the same bindings without the
|
|
17
|
+
* Durable Objects, for `vite dev`'s platform proxy (it can't run an
|
|
18
|
+
* object that lives in the main Worker; the dev side Worker runs them).
|
|
19
|
+
*/
|
|
20
|
+
readonly platformPath: string;
|
|
21
|
+
/** `wrangler dev --persist-to` / `getPlatformProxy` persist path. */
|
|
22
|
+
readonly stateDir: string;
|
|
23
|
+
/** The D1 bindings, to migrate locally. */
|
|
24
|
+
readonly d1: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
/** Writes `.ui-kit/migrations/<binding>/` and `.ui-kit/wrangler.json` for the app. */
|
|
27
|
+
export declare function writeLocalConfig({ appDir, resources, }: {
|
|
28
|
+
appDir: string;
|
|
29
|
+
resources: ResourcesDecl;
|
|
30
|
+
}): LocalConfig;
|
|
31
|
+
/** The `wrangler` command in the app (its own dependency). */
|
|
32
|
+
export declare function wranglerBin(appDir: string): string;
|
|
33
|
+
/** Applies pending migrations to every local D1 database (no-op when up to date). */
|
|
34
|
+
export declare function migrateLocalD1(config: LocalConfig): Promise<void>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join, relative, resolve } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { assembleMigrations, GENERATED_DIR } from '../alchemy/migrations.js';
|
|
6
|
+
import { wranglerConfig } from '../alchemy/wrangler-config.js';
|
|
7
|
+
import { resourceProblems } from '../logic/resources.js';
|
|
8
|
+
/**
|
|
9
|
+
* The local workerd files an app's tooling writes under `.ui-kit/` (never
|
|
10
|
+
* committed): the assembled D1 migrations and `wrangler.json`, made from
|
|
11
|
+
* the resource declaration. `vite dev` (platform proxy), `ui-kit preview`
|
|
12
|
+
* (`wrangler dev`) and the dev Durable Object Worker read them.
|
|
13
|
+
*/
|
|
14
|
+
/** Where local workerd keeps its state (D1, R2, Durable Objects), under the app. */
|
|
15
|
+
export const LOCAL_STATE_DIR = '.wrangler/state';
|
|
16
|
+
/** Writes `.ui-kit/migrations/<binding>/` and `.ui-kit/wrangler.json` for the app. */
|
|
17
|
+
export function writeLocalConfig({ appDir, resources, }) {
|
|
18
|
+
const problems = resourceProblems(resources);
|
|
19
|
+
if (problems.length > 0) {
|
|
20
|
+
throw new Error(`ui-kit resources: ${problems.join('; ')}`);
|
|
21
|
+
}
|
|
22
|
+
const outDir = resolve(appDir, GENERATED_DIR);
|
|
23
|
+
mkdirSync(outDir, { recursive: true });
|
|
24
|
+
const migrations = assembleMigrations({ appDir, resources });
|
|
25
|
+
const rel = (path) => relative(outDir, path);
|
|
26
|
+
const config = wranglerConfig({
|
|
27
|
+
resources,
|
|
28
|
+
name: `${resources.name}-local`,
|
|
29
|
+
main: rel(resolve(appDir, 'dist/server/server.js')),
|
|
30
|
+
assets: rel(resolve(appDir, 'dist/client')),
|
|
31
|
+
migrations: Object.fromEntries(Object.entries(migrations).map(([b, dir]) => [b, rel(dir)])),
|
|
32
|
+
});
|
|
33
|
+
const wranglerPath = join(outDir, 'wrangler.json');
|
|
34
|
+
writeFileSync(wranglerPath, `${JSON.stringify(config, null, 4)}\n`);
|
|
35
|
+
const { durable_objects: _objects, migrations: _classes, ...platform } = config;
|
|
36
|
+
const platformPath = join(outDir, 'wrangler.platform.json');
|
|
37
|
+
writeFileSync(platformPath, `${JSON.stringify(platform, null, 4)}\n`);
|
|
38
|
+
return {
|
|
39
|
+
appDir,
|
|
40
|
+
wranglerPath,
|
|
41
|
+
platformPath,
|
|
42
|
+
stateDir: resolve(appDir, LOCAL_STATE_DIR),
|
|
43
|
+
d1: Object.keys(resources.d1 ?? {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** The `wrangler` command in the app (its own dependency). */
|
|
47
|
+
export function wranglerBin(appDir) {
|
|
48
|
+
return resolve(appDir, 'node_modules/.bin/wrangler');
|
|
49
|
+
}
|
|
50
|
+
/** Applies pending migrations to every local D1 database (no-op when up to date). */
|
|
51
|
+
export async function migrateLocalD1(config) {
|
|
52
|
+
for (const binding of config.d1) {
|
|
53
|
+
await promisify(execFile)(wranglerBin(config.appDir), [
|
|
54
|
+
'd1',
|
|
55
|
+
'migrations',
|
|
56
|
+
'apply',
|
|
57
|
+
binding,
|
|
58
|
+
'--local',
|
|
59
|
+
'-c',
|
|
60
|
+
config.wranglerPath,
|
|
61
|
+
'--persist-to',
|
|
62
|
+
config.stateDir,
|
|
63
|
+
], {
|
|
64
|
+
cwd: config.appDir,
|
|
65
|
+
env: {
|
|
66
|
+
...process.env,
|
|
67
|
+
CI: '1',
|
|
68
|
+
WRANGLER_SEND_METRICS: 'false',
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* The Vite build steps that make the app's Worker (`uiKit` adds them):
|
|
4
|
+
*
|
|
5
|
+
* - `workerServerBuild`: the ssr build's only input is the app's Worker
|
|
6
|
+
* entry (which imports `virtual:solid-ssr-handler`), and every dependency
|
|
7
|
+
* is bundled in: `server.js` is one self-contained, minified file (only
|
|
8
|
+
* `node:*` builtins stay external, served by `nodejs_compat`). workerd
|
|
9
|
+
* rejects a main module whose named exports are not handlers, and a split
|
|
10
|
+
* build exports shared bindings to its chunks. In the prerender build
|
|
11
|
+
* (`UI_KIT_BUILD=prerender`) both environments go to `dist/prerender/`.
|
|
12
|
+
* - `serverStubs`: modules the Worker never runs are stubs in the ssr
|
|
13
|
+
* build: client-only lazy islands (`*-island.lazy.tsx`: the server
|
|
14
|
+
* renders their fallback) and, outside the prerender build, the
|
|
15
|
+
* `prerenderOnly` modules (prerendered pages are static assets). A stub
|
|
16
|
+
* throws if it is ever run.
|
|
17
|
+
*/
|
|
18
|
+
/** `UI_KIT_BUILD=prerender`: the build `ui-kit prerender` runs (never deployed). */
|
|
19
|
+
export declare const PRERENDER_BUILD_ENV = "UI_KIT_BUILD";
|
|
20
|
+
export declare function isPrerenderBuild(): boolean;
|
|
21
|
+
export declare function workerServerBuild(workerEntry: string): Plugin;
|
|
22
|
+
/** A lazy island: client-only, never in the server bundle. */
|
|
23
|
+
export declare const LAZY_ISLAND: RegExp;
|
|
24
|
+
export declare function serverStubs(prerenderOnly: RegExp | undefined): Plugin;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Vite build steps that make the app's Worker (`uiKit` adds them):
|
|
3
|
+
*
|
|
4
|
+
* - `workerServerBuild`: the ssr build's only input is the app's Worker
|
|
5
|
+
* entry (which imports `virtual:solid-ssr-handler`), and every dependency
|
|
6
|
+
* is bundled in: `server.js` is one self-contained, minified file (only
|
|
7
|
+
* `node:*` builtins stay external, served by `nodejs_compat`). workerd
|
|
8
|
+
* rejects a main module whose named exports are not handlers, and a split
|
|
9
|
+
* build exports shared bindings to its chunks. In the prerender build
|
|
10
|
+
* (`UI_KIT_BUILD=prerender`) both environments go to `dist/prerender/`.
|
|
11
|
+
* - `serverStubs`: modules the Worker never runs are stubs in the ssr
|
|
12
|
+
* build: client-only lazy islands (`*-island.lazy.tsx`: the server
|
|
13
|
+
* renders their fallback) and, outside the prerender build, the
|
|
14
|
+
* `prerenderOnly` modules (prerendered pages are static assets). A stub
|
|
15
|
+
* throws if it is ever run.
|
|
16
|
+
*/
|
|
17
|
+
/** `UI_KIT_BUILD=prerender`: the build `ui-kit prerender` runs (never deployed). */
|
|
18
|
+
export const PRERENDER_BUILD_ENV = 'UI_KIT_BUILD';
|
|
19
|
+
export function isPrerenderBuild() {
|
|
20
|
+
return process.env[PRERENDER_BUILD_ENV] === 'prerender';
|
|
21
|
+
}
|
|
22
|
+
export function workerServerBuild(workerEntry) {
|
|
23
|
+
return {
|
|
24
|
+
name: 'ui-kit:worker-server-build',
|
|
25
|
+
apply: 'build',
|
|
26
|
+
configEnvironment(name, config) {
|
|
27
|
+
config.build ??= {};
|
|
28
|
+
if (isPrerenderBuild()) {
|
|
29
|
+
config.build.outDir =
|
|
30
|
+
name === 'ssr'
|
|
31
|
+
? 'dist/prerender/server'
|
|
32
|
+
: 'dist/prerender/client';
|
|
33
|
+
}
|
|
34
|
+
if (name !== 'ssr')
|
|
35
|
+
return;
|
|
36
|
+
config.build.rollupOptions ??= {};
|
|
37
|
+
config.build.rollupOptions.input = { index: workerEntry };
|
|
38
|
+
// One chunk (Rolldown's `codeSplitting: false`, which replaced
|
|
39
|
+
// `inlineDynamicImports`).
|
|
40
|
+
config.build.rollupOptions.output = {
|
|
41
|
+
...config.build.rollupOptions.output,
|
|
42
|
+
codeSplitting: false,
|
|
43
|
+
};
|
|
44
|
+
// Smaller upload and faster cold start (parse time counts as CPU).
|
|
45
|
+
config.build.minify = true;
|
|
46
|
+
config.resolve ??= {};
|
|
47
|
+
config.resolve.noExternal = true;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const SERVER_STUB = '\0ui-kit:server-stub:';
|
|
52
|
+
/** A lazy island: client-only, never in the server bundle. */
|
|
53
|
+
export const LAZY_ISLAND = /-island\.lazy\.tsx$/;
|
|
54
|
+
export function serverStubs(prerenderOnly) {
|
|
55
|
+
const stubs = [
|
|
56
|
+
{
|
|
57
|
+
test: LAZY_ISLAND,
|
|
58
|
+
code: 'export default function ClientOnlyIsland() { throw new Error("client-only island loaded on the server"); }',
|
|
59
|
+
},
|
|
60
|
+
...(prerenderOnly === undefined || isPrerenderBuild()
|
|
61
|
+
? []
|
|
62
|
+
: [
|
|
63
|
+
{
|
|
64
|
+
test: prerenderOnly,
|
|
65
|
+
code: 'export default function PrerenderedPage() { throw new Error("a prerendered page: the Worker never renders it"); }',
|
|
66
|
+
},
|
|
67
|
+
]),
|
|
68
|
+
];
|
|
69
|
+
return {
|
|
70
|
+
name: 'ui-kit:server-stubs',
|
|
71
|
+
apply: 'build',
|
|
72
|
+
enforce: 'pre',
|
|
73
|
+
applyToEnvironment: (environment) => environment.name === 'ssr',
|
|
74
|
+
resolveId(source) {
|
|
75
|
+
const index = stubs.findIndex((stub) => stub.test.test(source));
|
|
76
|
+
return index === -1 ? null : `${SERVER_STUB}${index}`;
|
|
77
|
+
},
|
|
78
|
+
load(id) {
|
|
79
|
+
if (!id.startsWith(SERVER_STUB))
|
|
80
|
+
return null;
|
|
81
|
+
return stubs[Number(id.slice(SERVER_STUB.length))]?.code ?? null;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ServerApp } from './server-app.ts';
|
|
2
|
+
/** The slice of the Workers `ExecutionContext` the kit passes along. */
|
|
3
|
+
export interface WorkerContext {
|
|
4
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
5
|
+
/** Workers Cache purge API (present when Workers Cache is on). */
|
|
6
|
+
readonly cache?: unknown;
|
|
7
|
+
}
|
|
8
|
+
/** Solid's request handler (`handleRequest` from `virtual:solid-ssr-handler`). */
|
|
9
|
+
export type RenderHandler = (request: Request, options: {
|
|
10
|
+
readonly event: {
|
|
11
|
+
readonly locals: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
readonly nonce: string | null;
|
|
14
|
+
readonly renderMode: 'stream' | 'async';
|
|
15
|
+
}) => Promise<Response>;
|
|
16
|
+
/** Routes the Worker hands to Durable Objects (WebSocket upgrades): an answer, or `undefined` to go on. */
|
|
17
|
+
export type LiveRouter = (request: Request, env: unknown) => Promise<Response> | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The app's Worker (`worker/index.ts`'s default export). It owns the
|
|
20
|
+
* request: it passes `env` / `ctx` into Solid's request event (`locals`),
|
|
21
|
+
* makes the CSP nonce and sets the security headers.
|
|
22
|
+
*
|
|
23
|
+
* Static assets (the client build, prerendered pages) are served before
|
|
24
|
+
* the Worker runs; their headers come from `_headers`. What reaches it, in
|
|
25
|
+
* order:
|
|
26
|
+
* 1. `live`: the app's Durable Object routes (live rooms, channels);
|
|
27
|
+
* 2. `/_server`: Solid's server functions (`Server-Timing` stripped);
|
|
28
|
+
* 3. a page in the route table: rendered (whole by default, streamed when
|
|
29
|
+
* the route opts in); `auth: "required"` without a session redirects to
|
|
30
|
+
* sign-in first; a page whose primary record is missing is a 404;
|
|
31
|
+
* 4. an unknown page path (GET/HEAD): the table's `NotFound` page, 404;
|
|
32
|
+
* 5. anything else: a short static 404.
|
|
33
|
+
*
|
|
34
|
+
* `scheduled` runs the sessions cleanup and the app's jobs on their crons.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { handleRequest } from 'virtual:solid-ssr-handler'
|
|
39
|
+
* export { FeedChannel, LiveRoom } from './objects.ts'
|
|
40
|
+
* export default createWorker({ app: serverApp, render: handleRequest, live: routeLive })
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function createWorker<R>({ app, render, live, }: {
|
|
44
|
+
app: ServerApp<R>;
|
|
45
|
+
render: RenderHandler;
|
|
46
|
+
live?: LiveRouter;
|
|
47
|
+
}): {
|
|
48
|
+
fetch(request: Request, env: unknown, ctx: WorkerContext): Promise<Response>;
|
|
49
|
+
scheduled(controller: {
|
|
50
|
+
readonly cron: string;
|
|
51
|
+
}, env: unknown): Promise<void>;
|
|
52
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { RenderMode, renderModeFor } from './page-routes.js';
|
|
2
|
+
import { ensureCacheControl, finishPage } from './request-prelude.js';
|
|
3
|
+
import { BASE_HEADERS, contentSecurityPolicy, makeNonce, notFoundResponse, scriptHashes, stripDevHeaders, withHeaders, withStatus, } from './security.js';
|
|
4
|
+
import { prepareAppRequest, runScheduled, } from './server-app.js';
|
|
5
|
+
/**
|
|
6
|
+
* The app's Worker (`worker/index.ts`'s default export). It owns the
|
|
7
|
+
* request: it passes `env` / `ctx` into Solid's request event (`locals`),
|
|
8
|
+
* makes the CSP nonce and sets the security headers.
|
|
9
|
+
*
|
|
10
|
+
* Static assets (the client build, prerendered pages) are served before
|
|
11
|
+
* the Worker runs; their headers come from `_headers`. What reaches it, in
|
|
12
|
+
* order:
|
|
13
|
+
* 1. `live`: the app's Durable Object routes (live rooms, channels);
|
|
14
|
+
* 2. `/_server`: Solid's server functions (`Server-Timing` stripped);
|
|
15
|
+
* 3. a page in the route table: rendered (whole by default, streamed when
|
|
16
|
+
* the route opts in); `auth: "required"` without a session redirects to
|
|
17
|
+
* sign-in first; a page whose primary record is missing is a 404;
|
|
18
|
+
* 4. an unknown page path (GET/HEAD): the table's `NotFound` page, 404;
|
|
19
|
+
* 5. anything else: a short static 404.
|
|
20
|
+
*
|
|
21
|
+
* `scheduled` runs the sessions cleanup and the app's jobs on their crons.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { handleRequest } from 'virtual:solid-ssr-handler'
|
|
26
|
+
* export { FeedChannel, LiveRoom } from './objects.ts'
|
|
27
|
+
* export default createWorker({ app: serverApp, render: handleRequest, live: routeLive })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function createWorker({ app, render, live, }) {
|
|
31
|
+
/**
|
|
32
|
+
* A prerendered page (only in the prerender build: the deployed Worker
|
|
33
|
+
* stubs these pages out and static assets serve them), rendered whole
|
|
34
|
+
* with no nonce and a CSP of its inline scripts' hashes.
|
|
35
|
+
*/
|
|
36
|
+
const renderPrerendered = async (request, locals) => {
|
|
37
|
+
const response = await render(request, {
|
|
38
|
+
event: { locals },
|
|
39
|
+
renderMode: 'async',
|
|
40
|
+
nonce: null,
|
|
41
|
+
});
|
|
42
|
+
const html = await response.text();
|
|
43
|
+
const csp = contentSecurityPolicy({ _tag: 'Hashes', scriptHashes: await scriptHashes(html) }, app.cspHosts);
|
|
44
|
+
return withHeaders(new Response(html, response), {
|
|
45
|
+
...BASE_HEADERS,
|
|
46
|
+
'Content-Security-Policy': csp,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
async fetch(request, env, ctx) {
|
|
51
|
+
const routed = live?.(request, env);
|
|
52
|
+
if (routed)
|
|
53
|
+
return routed;
|
|
54
|
+
const { kind, prelude, status } = await prepareAppRequest(app, request, env);
|
|
55
|
+
if (kind._tag === 'NotFoundStatic')
|
|
56
|
+
return notFoundResponse();
|
|
57
|
+
if (kind._tag === 'Page' &&
|
|
58
|
+
kind.route.mode === RenderMode.Prerender) {
|
|
59
|
+
return renderPrerendered(request, { env, ctx });
|
|
60
|
+
}
|
|
61
|
+
if (prelude._tag === 'Respond')
|
|
62
|
+
return prelude.response;
|
|
63
|
+
const locals = {
|
|
64
|
+
env,
|
|
65
|
+
ctx,
|
|
66
|
+
session: prelude.session,
|
|
67
|
+
formFlash: prelude.formFlash,
|
|
68
|
+
};
|
|
69
|
+
const nonce = makeNonce();
|
|
70
|
+
const response = await render(request, {
|
|
71
|
+
event: { locals },
|
|
72
|
+
nonce,
|
|
73
|
+
renderMode: renderModeFor(kind),
|
|
74
|
+
});
|
|
75
|
+
const answered = stripDevHeaders(withHeaders(response, {
|
|
76
|
+
...BASE_HEADERS,
|
|
77
|
+
'Content-Security-Policy': contentSecurityPolicy({ _tag: 'Nonce', nonce }, app.cspHosts),
|
|
78
|
+
}));
|
|
79
|
+
if (kind._tag === 'ServerFunction')
|
|
80
|
+
return ensureCacheControl(answered);
|
|
81
|
+
const page = finishPage(answered, prelude);
|
|
82
|
+
return kind._tag === 'NotFoundPage' || status === 404
|
|
83
|
+
? withStatus(page, 404)
|
|
84
|
+
: page;
|
|
85
|
+
},
|
|
86
|
+
async scheduled(controller, env) {
|
|
87
|
+
await runScheduled(app, controller.cron, env);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@alecsibilia/ui-kit/worker`: the app's Worker. `createWorker` serves the
|
|
3
|
+
* app's server side (`defineServerApp`): the request prelude, security
|
|
4
|
+
* headers and CSP, the page classifier, page status probes and the 404
|
|
5
|
+
* split, and the scheduled jobs.
|
|
6
|
+
*/
|
|
7
|
+
export * from './create-worker.ts';
|
|
8
|
+
export * from './page-routes.ts';
|
|
9
|
+
export * from './page-status.ts';
|
|
10
|
+
export * from './request-prelude.ts';
|
|
11
|
+
export * from './security.ts';
|
|
12
|
+
export * from './server-app.ts';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@alecsibilia/ui-kit/worker`: the app's Worker. `createWorker` serves the
|
|
3
|
+
* app's server side (`defineServerApp`): the request prelude, security
|
|
4
|
+
* headers and CSP, the page classifier, page status probes and the 404
|
|
5
|
+
* split, and the scheduled jobs.
|
|
6
|
+
*/
|
|
7
|
+
export * from './create-worker.js';
|
|
8
|
+
export * from './page-routes.js';
|
|
9
|
+
export * from './page-status.js';
|
|
10
|
+
export * from './request-prelude.js';
|
|
11
|
+
export * from './security.js';
|
|
12
|
+
export * from './server-app.js';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type RouteTable } from '../logic/route-table.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Which paths the Worker renders, and how: read from the app's route table
|
|
4
|
+
* (path, render mode, lazy page, NotFound). The Worker, `ui-kit prerender`
|
|
5
|
+
* and the router all read that one table.
|
|
6
|
+
*
|
|
7
|
+
* Unknown paths are a 404 two ways (`classifyPath`): a page-shaped path
|
|
8
|
+
* renders the table's `NotFound` page with status 404 (the app's own page,
|
|
9
|
+
* no data queries); an asset-shaped path (a file extension, `/assets/`), a
|
|
10
|
+
* non-GET request, or an unknown `/_server/*` id gets a short static 404
|
|
11
|
+
* with no render. The dev server uses the same function, so `/nope`
|
|
12
|
+
* behaves the same on `vite dev` and workerd.
|
|
13
|
+
*/
|
|
14
|
+
/** How a page is produced (the table's `render`). */
|
|
15
|
+
export declare const RenderMode: {
|
|
16
|
+
/** Rendered once at build time into a static asset (`ui-kit prerender`). */
|
|
17
|
+
readonly Prerender: 'prerender';
|
|
18
|
+
/** Rendered per request by the Worker (whole by default, streamed when the route opts in; nonce CSP). */
|
|
19
|
+
readonly Ssr: 'ssr';
|
|
20
|
+
};
|
|
21
|
+
export type RenderMode = (typeof RenderMode)[keyof typeof RenderMode];
|
|
22
|
+
export interface PageRoute {
|
|
23
|
+
/** The route table tag (`"Account"`). */
|
|
24
|
+
readonly tag: string;
|
|
25
|
+
readonly mode: RenderMode;
|
|
26
|
+
/** `"required"`: the Worker redirects to sign-in, before any render, when there is no session. */
|
|
27
|
+
readonly auth: 'required' | 'public';
|
|
28
|
+
/** `"whole"` (the default: one complete document) or `"stream"` (opt-in). */
|
|
29
|
+
readonly ssr: 'stream' | 'whole';
|
|
30
|
+
}
|
|
31
|
+
/** Solid's server-function endpoint (`/_server`, and its data paths). */
|
|
32
|
+
export declare const SERVER_FUNCTION_PATH = "/_server";
|
|
33
|
+
/** The page at `pathname`, or `undefined` (the table's NotFound: a 404). */
|
|
34
|
+
export declare function pageRoute(routes: RouteTable, pathname: string): PageRoute | undefined;
|
|
35
|
+
/** The app's sign-in page: its route tag and its "where to go after" search param. */
|
|
36
|
+
export interface SignInSpec {
|
|
37
|
+
readonly route: string;
|
|
38
|
+
readonly nextParam: string;
|
|
39
|
+
}
|
|
40
|
+
/** What `signIn` defaults to: the `SignIn` route and `?next=`. */
|
|
41
|
+
export declare const DEFAULT_SIGN_IN: SignInSpec;
|
|
42
|
+
/**
|
|
43
|
+
* Where an unauthenticated request for `url` goes: the sign-in page with
|
|
44
|
+
* the original path and search as `?next=` (same-origin path only).
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* signInLocation(routes, DEFAULT_SIGN_IN, new URL('https://x.example/account?tab=1'))
|
|
49
|
+
* // "/sign-in?next=%2Faccount%3Ftab%3D1"
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function signInLocation(routes: RouteTable, signIn: SignInSpec, url: URL): string;
|
|
53
|
+
/** Whether `pathname` is Solid's server-function endpoint. */
|
|
54
|
+
export declare function isServerFunctionPath(pathname: string): boolean;
|
|
55
|
+
/** What the Worker (and the dev server) does with a request path. */
|
|
56
|
+
export type PathKind =
|
|
57
|
+
/** Solid's server functions (`/_server`); Solid answers unknown ids with its own short 404. */
|
|
58
|
+
{
|
|
59
|
+
readonly _tag: 'ServerFunction';
|
|
60
|
+
}
|
|
61
|
+
/** A page in the route table. */
|
|
62
|
+
| {
|
|
63
|
+
readonly _tag: 'Page';
|
|
64
|
+
readonly route: PageRoute;
|
|
65
|
+
}
|
|
66
|
+
/** An unknown page-shaped path: the table's `NotFound` page, SSR, status 404. */
|
|
67
|
+
| {
|
|
68
|
+
readonly _tag: 'NotFoundPage';
|
|
69
|
+
}
|
|
70
|
+
/** An unknown asset path or a non-GET to an unknown path: a short static 404, no render. */
|
|
71
|
+
| {
|
|
72
|
+
readonly _tag: 'NotFoundStatic';
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Classifies a request path for the Worker and the dev server.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* classifyPath(routes, '/nope', 'GET') // { _tag: "NotFoundPage" }
|
|
80
|
+
* classifyPath(routes, '/assets/x.js', 'GET') // { _tag: "NotFoundStatic" }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function classifyPath(routes: RouteTable, pathname: string, method: string): PathKind;
|
|
84
|
+
/**
|
|
85
|
+
* Solid's render mode for a classified request: streaming only for pages
|
|
86
|
+
* that opt into `ssr: "stream"`; everything else is sent whole (`"async"`).
|
|
87
|
+
*/
|
|
88
|
+
export declare function renderModeFor(kind: PathKind): 'stream' | 'async';
|