@swelte/create 0.0.0-stage → 0.2.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/LICENSE-MIT +21 -0
- package/README.md +21 -2
- package/bin/create.js +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +132 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.d.ts +9 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +45 -0
- package/dist/prompts.js.map +1 -0
- package/dist/scaffold.d.ts +16 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +149 -0
- package/dist/scaffold.js.map +1 -0
- package/package.json +64 -4
- package/templates/base/README.md +65 -0
- package/templates/base/assets/README.md +12 -0
- package/templates/base/gitignore +8 -0
- package/templates/base/index.html +12 -0
- package/templates/base/package.json +51 -0
- package/templates/base/src/lib/README.md +10 -0
- package/templates/base/src/lib/index.ts +2 -0
- package/templates/base/src/routes/+error.svelte +14 -0
- package/templates/base/src/routes/+page.svelte +12 -0
- package/templates/base/src/routes/+page.v +7 -0
- package/templates/base/svelte.config.js +34 -0
- package/templates/base/tsconfig.json +27 -0
- package/templates/base/vite.config.ts +28 -0
- package/templates/lib/src/lib/hello/api.v +15 -0
- package/templates/lib/src/lib/hello.d.ts +4 -0
- package/templates/lib/src/routes/+page.svelte +36 -0
- package/templates/lib/src/routes/+page.v +9 -0
- package/templates/sample/src/lib/backend/secrets.v +12 -0
- package/templates/sample/src/lib/crypto/hash.v +13 -0
- package/templates/sample/src/routes/+page.svelte +179 -0
- package/templates/sample/src/routes/+page.v +22 -0
- package/templates/sample/src/routes/admin/+page.svelte +23 -0
- package/templates/sample/src/routes/admin/+page.v +8 -0
- package/templates/sample/src/routes/admin/+route.svelte +10 -0
- package/templates/sample/src/routes/admin/+route.v +15 -0
- package/templates/sample/src/routes/api/greet.v +127 -0
- package/templates/sample/src/routes/api/sibling.v +14 -0
- package/templates/sample/src/routes/files/[...rest].v +8 -0
- package/templates/sample/src/routes/users/[id].v +8 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "swelte dev",
|
|
8
|
+
"build": "swelte build",
|
|
9
|
+
"build:local": "swelte build --local",
|
|
10
|
+
"preview": "swelte preview",
|
|
11
|
+
"check": "swelte check",
|
|
12
|
+
"check:svelte": "svelte-check --compiler-warnings \"a11y:ignore\"",
|
|
13
|
+
"postinstall": "npm-skills extract --skip-production --override",
|
|
14
|
+
"package": "swelte package"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"svelte": "^5.0.0",
|
|
18
|
+
"@swelte/core": "^__SWELTE_VERSION_core__"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
22
|
+
"typescript": "^5.0.0",
|
|
23
|
+
"vite": "^6.0.0",
|
|
24
|
+
"@swelte/vvm": "^__SWELTE_VERSION_vvm__",
|
|
25
|
+
"npm-skills": "^0.5.1"
|
|
26
|
+
},
|
|
27
|
+
"allowScripts": {
|
|
28
|
+
"@swelte/vvm": true,
|
|
29
|
+
"esbuild": true
|
|
30
|
+
},
|
|
31
|
+
"npmSkills": {
|
|
32
|
+
"consume": {
|
|
33
|
+
"only": [
|
|
34
|
+
"@swelte/*"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"package",
|
|
40
|
+
"src/lib/**/*.v"
|
|
41
|
+
],
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./package/index.d.ts",
|
|
45
|
+
"svelte": "./package/index.js",
|
|
46
|
+
"default": "./package/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"svelte": "./package/index.js"
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Isomorphic V library (`#lib/*` → WASM/dev-fallback + native).
|
|
2
|
+
//
|
|
3
|
+
// Put shared, backend-independent logic here: `src/lib/crypto/hash.v`
|
|
4
|
+
// (`@[rpc]`, same V compiles native + WASM). Backend-only code goes in
|
|
5
|
+
// `src/lib/backend/*.v` (or `*_backend.v`) — the physical boundary: it is
|
|
6
|
+
// a build error from browser/`#lib/` WASM imports.
|
|
7
|
+
//
|
|
8
|
+
// Svelte components and TypeScript helpers live here too. Export the public
|
|
9
|
+
// API from index.ts. `swelte package` builds this directory into package/;
|
|
10
|
+
// src/routes stays local application/demo code. See `openspec/specs/library-packaging/reference.md`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
let { status = 500, message = 'Something went wrong' }: { status?: number; message?: string } =
|
|
3
|
+
$props()
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<main>
|
|
7
|
+
<h1>{status}</h1>
|
|
8
|
+
<p>{message}</p>
|
|
9
|
+
{#if status === 400 || status === 401 || status === 403}
|
|
10
|
+
<p><a href="/login">Log in</a> · <a href="/">Home</a></p>
|
|
11
|
+
{:else}
|
|
12
|
+
<p><a href="/">Home</a></p>
|
|
13
|
+
{/if}
|
|
14
|
+
</main>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
2
|
+
import { defineConfig } from '@swelte/core/config';
|
|
3
|
+
|
|
4
|
+
/** @type {import('@swelte/core/config').SwelteConfig} */
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
// Required by the VS Code Svelte extension (svelte-language-server) to
|
|
7
|
+
// preprocess <script lang="ts"> blocks. Without this file the extension
|
|
8
|
+
// falls back to loading vite.config.ts via @sveltejs/load-config, which
|
|
9
|
+
// currently looks for a plugin named 'vite-plugin-svelte:config' while the
|
|
10
|
+
// installed @sveltejs/vite-plugin-svelte@5 exposes 'vite-plugin-svelte' —
|
|
11
|
+
// hence "No Svelte configuration found in vite config".
|
|
12
|
+
// See: node_modules/@sveltejs/vite-plugin-svelte/src/index.js (name) vs
|
|
13
|
+
// ~/.vscode/extensions/svelte.svelte-vscode-*/node_modules/@sveltejs/load-config/dist/src/index.js
|
|
14
|
+
preprocess: vitePreprocess(),
|
|
15
|
+
// Client <await> (Svelte 5 experimental.async) lives here — NOT only in
|
|
16
|
+
// vite.config.ts. The VS Code Svelte extension / svelte-language-server
|
|
17
|
+
// reads svelte.config.js directly and never sees vite.config.ts, so an
|
|
18
|
+
// await in markup reports `experimental_async_missing` in the editor even
|
|
19
|
+
// when `vite build` passes. vite.config.ts spreads this file, so the Vite
|
|
20
|
+
// build picks it up from here too (its own merge is just a fallback).
|
|
21
|
+
compilerOptions: { experimental: { async: true } },
|
|
22
|
+
// Illustrative only — all defaults. defineConfig() keeps this key
|
|
23
|
+
// non-enumerable: invisible to svelte() (no "invalid plugin options"
|
|
24
|
+
// warning) but still readable by @swelte/core's loadConfig.
|
|
25
|
+
swelte: {
|
|
26
|
+
// name: '__NAME__',
|
|
27
|
+
// routesDir: 'src/routes',
|
|
28
|
+
// libDir: 'src/lib',
|
|
29
|
+
// outDir: '.swelte',
|
|
30
|
+
// distDir: 'dist',
|
|
31
|
+
// port: 8131, // V backend ($PORT wins)
|
|
32
|
+
// corsOrigin: '', // e.g. 'https://example.com' or '*' ($SWELTE_CORS_ORIGIN wins)
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"allowJs": true,
|
|
9
|
+
"checkJs": false,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
// Trick for *.test.ts / *.spec.ts importing `node:*`: keep `node` listed
|
|
14
|
+
// so editors resolving a test file against this app config still see
|
|
15
|
+
// @types/node (types-only, never bundled).
|
|
16
|
+
"types": ["vite/client", "svelte", "node"],
|
|
17
|
+
"paths": {
|
|
18
|
+
"#routes/*.v": ["./.swelte/types/routes/*.d.ts"],
|
|
19
|
+
"#lib/*.v": ["./.swelte/types/lib/*.d.ts"],
|
|
20
|
+
"#routes/*": ["./src/routes/*"],
|
|
21
|
+
"#lib/*": ["./src/lib/*"],
|
|
22
|
+
"$app/*": ["./.swelte/app/*"],
|
|
23
|
+
"#app/*": ["./.swelte/app/*", "./.swelte/*.d.ts"]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"include": ["src", "vite.config.ts", ".swelte/types", ".swelte/v-shim.d.ts", ".swelte/app/*.d.ts", ".swelte/paths.d.ts", ".swelte/environment.d.ts"]
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
3
|
+
import { swelte } from '@swelte/core/vite'
|
|
4
|
+
import svelteConfig from './svelte.config.js'
|
|
5
|
+
|
|
6
|
+
// section 1.3 streaming: client <await> needs Svelte experimental.async.
|
|
7
|
+
// The SSR bundle is composed by adapters (generate:'server', always sync),
|
|
8
|
+
// so this flag never reaches sync renderRoute.
|
|
9
|
+
const svelteOptions = {
|
|
10
|
+
...svelteConfig,
|
|
11
|
+
compilerOptions: { ...((svelteConfig as { compilerOptions?: Record<string, unknown> }).compilerOptions ?? {}), experimental: { ...((((svelteConfig as { compilerOptions?: { experimental?: Record<string, unknown> } }).compilerOptions ?? {}).experimental ?? {}) as Record<string, unknown>), async: true } },
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const vBackendUrl =
|
|
15
|
+
process.env.SWELTE_V_BACKEND_URL ??
|
|
16
|
+
process.env.VITE_SWELTE_V_BACKEND_URL ??
|
|
17
|
+
'http://localhost:8131'
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [
|
|
21
|
+
svelte(svelteOptions as Parameters<typeof svelte>[0]),
|
|
22
|
+
// Dirs come from svelte.config.js `swelte` key; plugin falls back to
|
|
23
|
+
// the unified config for any option not passed here.
|
|
24
|
+
swelte({
|
|
25
|
+
vBackendUrl,
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Public Swelte library module (universal): same V compiles native +
|
|
2
|
+
// `v -b wasm`. Consumers import it as `my-lib/v/hello.v` (TS) and
|
|
3
|
+
// `npm_my_lib.hello` (V); the dogfood `.svelte` demo imports it as
|
|
4
|
+
// `#lib/hello/api.v` (local WASM, same module file).
|
|
5
|
+
module hello
|
|
6
|
+
|
|
7
|
+
pub struct HelloArgs {
|
|
8
|
+
pub:
|
|
9
|
+
name string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@[rpc]
|
|
13
|
+
pub fn hello(args HelloArgs) string {
|
|
14
|
+
return 'hello ' + args.name
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { HelloResult } from '#lib/hello/api.v'
|
|
3
|
+
import { hello } from '#lib/hello/api.v'
|
|
4
|
+
|
|
5
|
+
let name = $state('world')
|
|
6
|
+
let greeting: HelloResult = $state('')
|
|
7
|
+
let error = $state('')
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<main>
|
|
11
|
+
<h1>__NAME__ (library dogfood)</h1>
|
|
12
|
+
<p>
|
|
13
|
+
This demo route is local only — it is never published. It exercises the public
|
|
14
|
+
<code>src/lib</code>
|
|
15
|
+
surface exactly like a consumer would.
|
|
16
|
+
</p>
|
|
17
|
+
<input bind:value={name} placeholder="your name">
|
|
18
|
+
<button
|
|
19
|
+
onclick={async () => {
|
|
20
|
+
error = ''
|
|
21
|
+
try {
|
|
22
|
+
greeting = await hello({ name })
|
|
23
|
+
} catch (e) {
|
|
24
|
+
error = String(e)
|
|
25
|
+
}
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
Say hello (#lib WASM)
|
|
29
|
+
</button>
|
|
30
|
+
{#if greeting}
|
|
31
|
+
<p>{greeting}</p>
|
|
32
|
+
{/if}
|
|
33
|
+
{#if error}
|
|
34
|
+
<pre style="color:crimson">{error}</pre>
|
|
35
|
+
{/if}
|
|
36
|
+
</main>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Library dogfood route for `/`: minimal GET probe. The `.svelte` twin
|
|
2
|
+
// exercises the public src/lib surface via `#lib/...` exactly like a
|
|
3
|
+
// consumer would. Never published.
|
|
4
|
+
module plus_page
|
|
5
|
+
|
|
6
|
+
@[get]
|
|
7
|
+
pub fn hello(req SwelteRequest) string {
|
|
8
|
+
return 'hello dogfood'
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Swelte isomorphic lib. Same V compiles to native + `v -b wasm`.
|
|
2
|
+
// Importable from `#lib/crypto/hash.v`; local WASM call, no fetch.
|
|
3
|
+
module crypto
|
|
4
|
+
|
|
5
|
+
pub struct HashArgs {
|
|
6
|
+
pub:
|
|
7
|
+
input string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@[rpc]
|
|
11
|
+
pub fn hash_string(args HashArgs) string {
|
|
12
|
+
return 'hash(' + args.input + ')'
|
|
13
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { SwelteRpcError } from '@swelte/core'
|
|
3
|
+
import { tick } from 'svelte'
|
|
4
|
+
import type { HashStringResult } from '#lib/crypto/hash.v'
|
|
5
|
+
import { hash_string } from '#lib/crypto/hash.v'
|
|
6
|
+
import type {
|
|
7
|
+
GetGreetingResult,
|
|
8
|
+
GreetNarrowResult,
|
|
9
|
+
SaveNameResult,
|
|
10
|
+
SwelteRequest,
|
|
11
|
+
} from '#routes/+page.v'
|
|
12
|
+
import { get_greeting, greet_narrow, save_name } from '#routes/+page.v'
|
|
13
|
+
import type { Session, SwelteResponse } from '#routes/api/greet.v'
|
|
14
|
+
import { greet_pure, login, make_created, serve_pdf, tick_stream } from '#routes/api/greet.v'
|
|
15
|
+
|
|
16
|
+
let name = $state('world')
|
|
17
|
+
let greeting: GetGreetingResult = $state('')
|
|
18
|
+
let saved: SaveNameResult = $state('')
|
|
19
|
+
let session: Session | null = $state(null)
|
|
20
|
+
let pureSession: Session | null = $state(null)
|
|
21
|
+
let pdfInfo = $state('')
|
|
22
|
+
let createdInfo = $state('')
|
|
23
|
+
let hashed: HashStringResult = $state('')
|
|
24
|
+
let narrow: GreetNarrowResult = $state('')
|
|
25
|
+
let lastError = $state('')
|
|
26
|
+
let ticks: string[] = $state([])
|
|
27
|
+
|
|
28
|
+
function showError(e: unknown) {
|
|
29
|
+
console.error(e)
|
|
30
|
+
if (e instanceof SwelteRpcError) {
|
|
31
|
+
lastError = e.message
|
|
32
|
+
} else {
|
|
33
|
+
lastError = String(e)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function loadGreeting() {
|
|
38
|
+
lastError = ''
|
|
39
|
+
try {
|
|
40
|
+
greeting = await get_greeting({ payload: name })
|
|
41
|
+
} catch (e) {
|
|
42
|
+
showError(e)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function saveName() {
|
|
46
|
+
lastError = ''
|
|
47
|
+
try {
|
|
48
|
+
saved = await save_name({ payload: name })
|
|
49
|
+
} catch (e) {
|
|
50
|
+
showError(e)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function hashName() {
|
|
54
|
+
lastError = ''
|
|
55
|
+
try {
|
|
56
|
+
hashed = await hash_string({ input: name })
|
|
57
|
+
} catch (e) {
|
|
58
|
+
showError(e)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function doLogin() {
|
|
62
|
+
lastError = ''
|
|
63
|
+
try {
|
|
64
|
+
{
|
|
65
|
+
const res: SwelteResponse = await login({ payload: name })
|
|
66
|
+
session = JSON.parse(
|
|
67
|
+
typeof res.body === 'string' ? res.body : await (res.body as Blob).text()
|
|
68
|
+
) as Session
|
|
69
|
+
} // SwelteResponse envelope: body is raw text for JSON (Blob only on binary CT)
|
|
70
|
+
} catch (e) {
|
|
71
|
+
showError(e)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function loadPure() {
|
|
75
|
+
lastError = ''
|
|
76
|
+
try {
|
|
77
|
+
pureSession = await greet_pure({ payload: name })
|
|
78
|
+
} catch (e) {
|
|
79
|
+
showError(e)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function loadPdf() {
|
|
83
|
+
lastError = ''
|
|
84
|
+
try {
|
|
85
|
+
const res = await serve_pdf({})
|
|
86
|
+
const blob = res.body as Blob
|
|
87
|
+
pdfInfo = `pdf ${blob.size}B ${blob.type}`
|
|
88
|
+
} catch (e) {
|
|
89
|
+
showError(e)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function loadCreated() {
|
|
93
|
+
lastError = ''
|
|
94
|
+
try {
|
|
95
|
+
const res = await make_created({})
|
|
96
|
+
createdInfo = `created ${res.status}: ${typeof res.body === 'string' ? res.body : '(binary)'}`
|
|
97
|
+
} catch (e) {
|
|
98
|
+
showError(e)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function loadNarrow() {
|
|
102
|
+
lastError = ''
|
|
103
|
+
try {
|
|
104
|
+
// Narrow-args verb: NOT rpc (no {fn,args} JSON body) — GET query
|
|
105
|
+
// ?q=narrow&name=..&age=.. ; numbers JSON-stringified on the wire.
|
|
106
|
+
narrow = await greet_narrow({ name, age: 42, nick: 'al' })
|
|
107
|
+
} catch (e) {
|
|
108
|
+
showError(e)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function streamTicks() {
|
|
112
|
+
lastError = ''
|
|
113
|
+
ticks = []
|
|
114
|
+
try {
|
|
115
|
+
for await (const t of tick_stream({ n: '3', wait_ms: '500' })) {
|
|
116
|
+
ticks = [...ticks, t]
|
|
117
|
+
await tick()
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
showError(e)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<main>
|
|
126
|
+
<h1>Swelte example: __NAME__</h1>
|
|
127
|
+
<input bind:value={name} placeholder="your name">
|
|
128
|
+
<div style="display:flex; gap:0.5rem; margin-top:0.5rem; flex-wrap:wrap;">
|
|
129
|
+
<button onclick={loadGreeting}>Greet (#routes GET)</button>
|
|
130
|
+
<button onclick={saveName}>Save (#routes POST)</button>
|
|
131
|
+
<button onclick={hashName}>Hash (#lib WASM)</button>
|
|
132
|
+
<button onclick={doLogin}>Login (POST verb + cookie)</button>
|
|
133
|
+
<button onclick={loadPure}>Pure (rpc typed)</button>
|
|
134
|
+
<button onclick={loadPdf}>PDF (verb binary)</button>
|
|
135
|
+
<button onclick={loadCreated}>Created (verb 201)</button>
|
|
136
|
+
<button onclick={streamTicks}>Stream (#routes SSE)</button>
|
|
137
|
+
<button onclick={loadNarrow}>Narrow (#routes GET narrow-args)</button>
|
|
138
|
+
</div>
|
|
139
|
+
{#if greeting}
|
|
140
|
+
<p>{greeting}</p>
|
|
141
|
+
{/if}
|
|
142
|
+
{#if saved}
|
|
143
|
+
<p>{saved}</p>
|
|
144
|
+
{/if}
|
|
145
|
+
{#if hashed}
|
|
146
|
+
<p>{hashed}</p>
|
|
147
|
+
{/if}
|
|
148
|
+
{#if session}
|
|
149
|
+
<p>session {session.id} for {session.user} (remember={session.remember})</p>
|
|
150
|
+
{/if}
|
|
151
|
+
{#if pureSession}
|
|
152
|
+
<p>pure {pureSession.id} for {pureSession.user}</p>
|
|
153
|
+
{/if}
|
|
154
|
+
{#if pdfInfo}
|
|
155
|
+
<p>{pdfInfo}</p>
|
|
156
|
+
{/if}
|
|
157
|
+
{#if createdInfo}
|
|
158
|
+
<p>{createdInfo}</p>
|
|
159
|
+
{/if}
|
|
160
|
+
{#if ticks.length}
|
|
161
|
+
<p>stream: {ticks.join(' | ')}</p>
|
|
162
|
+
{/if}
|
|
163
|
+
{#if narrow}
|
|
164
|
+
<p>{narrow}</p>
|
|
165
|
+
{/if}
|
|
166
|
+
{#if lastError}
|
|
167
|
+
<pre style="color:crimson; white-space:pre-wrap;">{lastError}</pre>
|
|
168
|
+
{/if}
|
|
169
|
+
<hr>
|
|
170
|
+
<h2>No-JS proof (plain forms, no fetch)</h2>
|
|
171
|
+
<form method="post" action="/">
|
|
172
|
+
<input type="hidden" name="payload" value="nojs-alice">
|
|
173
|
+
<button type="submit">Save via plain form (→ 303 → /)</button>
|
|
174
|
+
</form>
|
|
175
|
+
<form method="post" action="/api/greet?upload" enctype="multipart/form-data">
|
|
176
|
+
<input type="file" name="file">
|
|
177
|
+
<button type="submit">Upload via plain form (→ 303)</button>
|
|
178
|
+
</form>
|
|
179
|
+
</main>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Swelte route handler for `/`. Named fns importable from `#routes/+page.v`.
|
|
2
|
+
module plus_page
|
|
3
|
+
|
|
4
|
+
@[get]
|
|
5
|
+
pub fn get_greeting(req SwelteRequest) string {
|
|
6
|
+
name := req.query['payload'] or { '""' }
|
|
7
|
+
return 'Hello, ' + name.trim('"') + '!'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@[post]
|
|
11
|
+
pub fn save_name(req SwelteRequest) string {
|
|
12
|
+
name := req.form['payload'] or { '' }
|
|
13
|
+
return 'saved:' + name
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Narrow-args probe: typed verb fn (form → query → params). Projects inline as
|
|
17
|
+
// `args: { name: string; age: number; nick?: string | null }` — retrievable via
|
|
18
|
+
// `Parameters<typeof greet_narrow>[0]`, numbers JSON-stringified on the wire.
|
|
19
|
+
@[get('narrow')]
|
|
20
|
+
pub fn greet_narrow(name string, age int, nick ?string) string {
|
|
21
|
+
return 'hi ' + name + ' age=' + age.str() + ' nick=' + (nick or { '<none>' })
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { loadPage, type SwelteLoadResult } from '@swelte/core'
|
|
3
|
+
import { admin_whoami } from '#routes/admin/+page.v'
|
|
4
|
+
import ErrorPage from '../+error.svelte'
|
|
5
|
+
|
|
6
|
+
let result: SwelteLoadResult<string> | null = $state(null)
|
|
7
|
+
|
|
8
|
+
async function load() {
|
|
9
|
+
result = await loadPage(() => admin_whoami({}))
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<main>
|
|
14
|
+
<h1>admin</h1>
|
|
15
|
+
{#if result?.error}
|
|
16
|
+
<ErrorPage status={result.error.status} message={result.error.message} />
|
|
17
|
+
{:else}
|
|
18
|
+
<button onclick={load}>Who am I (guarded GET)</button>
|
|
19
|
+
{#if result?.data}
|
|
20
|
+
<p>{result.data}</p>
|
|
21
|
+
{/if}
|
|
22
|
+
{/if}
|
|
23
|
+
</main>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Swelte admin wrapper: nav chrome (svelte) + subtree guard (V middleware).
|
|
2
|
+
module admin_route
|
|
3
|
+
|
|
4
|
+
@[before]
|
|
5
|
+
pub fn require_session(req SwelteRequest) !SwelteRequest {
|
|
6
|
+
token := req.cookies['sess'] or { return error('missing session') }
|
|
7
|
+
mut r := req
|
|
8
|
+
r.headers['x-user'] = token
|
|
9
|
+
return r
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@[after]
|
|
13
|
+
pub fn stamp_admin(req SwelteRequest, res SwelteResponse) !SwelteResponse {
|
|
14
|
+
return res
|
|
15
|
+
}
|