@briancray/belte 0.1.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 +21 -0
- package/README.md +49 -0
- package/bin/belte.ts +136 -0
- package/package.json +80 -0
- package/src/App.svelte +31 -0
- package/src/assets/app.html +14 -0
- package/src/belteResolverPlugin.ts +832 -0
- package/src/build.ts +144 -0
- package/src/buildCli.ts +160 -0
- package/src/cliEntry.ts +31 -0
- package/src/clientEntry.ts +7 -0
- package/src/compile.ts +64 -0
- package/src/devEntry.ts +33 -0
- package/src/discoveryEntry.ts +33 -0
- package/src/lib/browser/cache.ts +191 -0
- package/src/lib/browser/page.svelte.ts +215 -0
- package/src/lib/browser/remoteProxy.ts +44 -0
- package/src/lib/browser/socketChannel.ts +182 -0
- package/src/lib/browser/socketProxy.ts +64 -0
- package/src/lib/browser/startClient.ts +132 -0
- package/src/lib/browser/subscribe.ts +131 -0
- package/src/lib/browser/types/Layouts.ts +7 -0
- package/src/lib/browser/types/Pages.ts +7 -0
- package/src/lib/cli/createClient.ts +126 -0
- package/src/lib/cli/loadEnvFromBinaryDir.ts +44 -0
- package/src/lib/cli/parseArgvForRpc.ts +97 -0
- package/src/lib/cli/printHelp.ts +70 -0
- package/src/lib/cli/runCli.ts +88 -0
- package/src/lib/cli/types/CliManifest.ts +9 -0
- package/src/lib/cli/types/CliManifestEntry.ts +12 -0
- package/src/lib/mcp/createMcpResourceServer.ts +101 -0
- package/src/lib/mcp/createMcpServer.ts +40 -0
- package/src/lib/mcp/dispatchMcpRequest.ts +294 -0
- package/src/lib/mcp/mcpResourceServerSlot.ts +18 -0
- package/src/lib/mcp/types/JsonRpcRequest.ts +12 -0
- package/src/lib/mcp/types/JsonRpcResponse.ts +20 -0
- package/src/lib/mcp/types/McpResourceContents.ts +10 -0
- package/src/lib/mcp/types/McpResourceDescriptor.ts +6 -0
- package/src/lib/mcp/types/McpResourceServer.ts +12 -0
- package/src/lib/mcp/types/McpServer.ts +9 -0
- package/src/lib/mcp/types/McpServerOptions.ts +16 -0
- package/src/lib/server/AppModule.ts +25 -0
- package/src/lib/server/DELETE.ts +9 -0
- package/src/lib/server/GET.ts +9 -0
- package/src/lib/server/HEAD.ts +9 -0
- package/src/lib/server/HttpError.ts +19 -0
- package/src/lib/server/PATCH.ts +9 -0
- package/src/lib/server/POST.ts +9 -0
- package/src/lib/server/PUT.ts +9 -0
- package/src/lib/server/cli/buildEnvContent.ts +18 -0
- package/src/lib/server/cli/createTarGz.ts +76 -0
- package/src/lib/server/cli/handleCliDownload.ts +124 -0
- package/src/lib/server/cli/handleCliInstall.ts +20 -0
- package/src/lib/server/cli/installScript.ts +29 -0
- package/src/lib/server/cli/maxSourceMtime.ts +27 -0
- package/src/lib/server/error.ts +56 -0
- package/src/lib/server/json.ts +28 -0
- package/src/lib/server/jsonl.ts +40 -0
- package/src/lib/server/prompt.ts +30 -0
- package/src/lib/server/prompts/definePrompt.ts +20 -0
- package/src/lib/server/prompts/promptRegistry.ts +9 -0
- package/src/lib/server/prompts/registerPrompt.ts +6 -0
- package/src/lib/server/prompts/types/Prompt.ts +14 -0
- package/src/lib/server/prompts/types/PromptMessage.ts +10 -0
- package/src/lib/server/prompts/types/PromptOptions.ts +17 -0
- package/src/lib/server/prompts/types/PromptRegistryEntry.ts +15 -0
- package/src/lib/server/prompts/types/PromptRoutes.ts +10 -0
- package/src/lib/server/redirect.ts +37 -0
- package/src/lib/server/request.ts +18 -0
- package/src/lib/server/rpc/defineVerb.ts +103 -0
- package/src/lib/server/rpc/parseArgs.ts +60 -0
- package/src/lib/server/rpc/registerVerb.ts +6 -0
- package/src/lib/server/rpc/types/HttpVerb.ts +1 -0
- package/src/lib/server/rpc/types/RawRemoteFunction.ts +13 -0
- package/src/lib/server/rpc/types/RemoteFunction.ts +35 -0
- package/src/lib/server/rpc/types/RemoteHandler.ts +22 -0
- package/src/lib/server/rpc/types/RemoteRoutes.ts +13 -0
- package/src/lib/server/rpc/types/StandardSchemaV1.ts +57 -0
- package/src/lib/server/rpc/types/TypedResponse.ts +18 -0
- package/src/lib/server/rpc/types/VerbHelper.ts +39 -0
- package/src/lib/server/rpc/types/VerbRegistryEntry.ts +17 -0
- package/src/lib/server/rpc/unprocessed.ts +14 -0
- package/src/lib/server/rpc/verbRegistry.ts +11 -0
- package/src/lib/server/runtime/buildOpenApiSpec.ts +66 -0
- package/src/lib/server/runtime/cacheControlForAsset.ts +17 -0
- package/src/lib/server/runtime/containsTraversal.ts +37 -0
- package/src/lib/server/runtime/createPublicAssetServer.ts +66 -0
- package/src/lib/server/runtime/createServer.ts +555 -0
- package/src/lib/server/runtime/getActiveServer.ts +6 -0
- package/src/lib/server/runtime/mimeForExtension.ts +20 -0
- package/src/lib/server/runtime/registryManifests.ts +48 -0
- package/src/lib/server/runtime/requestContext.ts +5 -0
- package/src/lib/server/runtime/safeJsonForScript.ts +17 -0
- package/src/lib/server/runtime/serializeCacheSnapshot.ts +84 -0
- package/src/lib/server/runtime/serverSlot.ts +13 -0
- package/src/lib/server/runtime/setActiveServer.ts +6 -0
- package/src/lib/server/runtime/streamFromIterator.ts +76 -0
- package/src/lib/server/runtime/types/Assets.ts +1 -0
- package/src/lib/server/runtime/types/CompileTarget.ts +6 -0
- package/src/lib/server/runtime/types/RequestStore.ts +15 -0
- package/src/lib/server/runtime/types/SvelteConfig.ts +5 -0
- package/src/lib/server/server.ts +19 -0
- package/src/lib/server/socket.ts +31 -0
- package/src/lib/server/sockets/createSocketDispatcher.ts +267 -0
- package/src/lib/server/sockets/defineSocket.ts +160 -0
- package/src/lib/server/sockets/lookupSocket.ts +6 -0
- package/src/lib/server/sockets/registerSocket.ts +6 -0
- package/src/lib/server/sockets/socketRegistry.ts +9 -0
- package/src/lib/server/sockets/types/Socket.ts +21 -0
- package/src/lib/server/sockets/types/SocketClientFrame.ts +18 -0
- package/src/lib/server/sockets/types/SocketOptions.ts +22 -0
- package/src/lib/server/sockets/types/SocketRegistryEntry.ts +18 -0
- package/src/lib/server/sockets/types/SocketRoutes.ts +10 -0
- package/src/lib/server/sockets/types/SocketServerFrame.ts +15 -0
- package/src/lib/server/sse.ts +47 -0
- package/src/lib/shared/activeCacheStore.ts +20 -0
- package/src/lib/shared/buildRpcRequest.ts +61 -0
- package/src/lib/shared/cacheControlValues.ts +8 -0
- package/src/lib/shared/cacheStoreSlot.ts +16 -0
- package/src/lib/shared/canonicalJson.ts +24 -0
- package/src/lib/shared/commandNameForUrl.ts +17 -0
- package/src/lib/shared/createCacheStore.ts +42 -0
- package/src/lib/shared/createPushIterator.ts +77 -0
- package/src/lib/shared/createRemoteFunction.ts +89 -0
- package/src/lib/shared/decodeResponse.ts +47 -0
- package/src/lib/shared/detectTarget.ts +27 -0
- package/src/lib/shared/findExportCallSite.ts +479 -0
- package/src/lib/shared/forwardHeaders.ts +28 -0
- package/src/lib/shared/getRemoteMeta.ts +5 -0
- package/src/lib/shared/isDebugEnabled.ts +23 -0
- package/src/lib/shared/jsonSchemaForSchema.ts +38 -0
- package/src/lib/shared/keyForRemoteCall.ts +38 -0
- package/src/lib/shared/loadSvelteConfig.ts +18 -0
- package/src/lib/shared/log.ts +104 -0
- package/src/lib/shared/nearestLayoutPrefix.ts +36 -0
- package/src/lib/shared/normalizeTarget.ts +10 -0
- package/src/lib/shared/pageUrlForFile.ts +14 -0
- package/src/lib/shared/parseRouteSegments.ts +22 -0
- package/src/lib/shared/preparePromptModule.ts +36 -0
- package/src/lib/shared/prepareRpcModule.ts +51 -0
- package/src/lib/shared/prepareSocketModule.ts +37 -0
- package/src/lib/shared/programNameForPackage.ts +14 -0
- package/src/lib/shared/promptNameForFile.ts +10 -0
- package/src/lib/shared/recordRemoteMeta.ts +5 -0
- package/src/lib/shared/remoteMetaStore.ts +16 -0
- package/src/lib/shared/resolveClientFlags.ts +18 -0
- package/src/lib/shared/rpcUrlForFile.ts +19 -0
- package/src/lib/shared/setCacheStoreResolver.ts +6 -0
- package/src/lib/shared/socketNameForFile.ts +11 -0
- package/src/lib/shared/streamingContentTypes.ts +11 -0
- package/src/lib/shared/stripImport.ts +27 -0
- package/src/lib/shared/subscribableFromResponse.ts +333 -0
- package/src/lib/shared/toBunRoutePattern.ts +28 -0
- package/src/lib/shared/types/CacheEntry.ts +16 -0
- package/src/lib/shared/types/CacheOptions.ts +10 -0
- package/src/lib/shared/types/CacheSnapshotEntry.ts +15 -0
- package/src/lib/shared/types/CacheStore.ts +15 -0
- package/src/lib/shared/types/ClientFlags.ts +11 -0
- package/src/lib/shared/types/Subscribable.ts +15 -0
- package/src/lib/shared/writeRoutesDts.ts +64 -0
- package/src/preload.ts +20 -0
- package/src/scaffold.ts +92 -0
- package/src/serverEntry.ts +47 -0
- package/src/sveltePlugin.ts +58 -0
- package/src/tailwindStylePreprocessor.ts +62 -0
- package/template/package.json +16 -0
- package/template/src/app.ts +23 -0
- package/template/src/browser/app.css +21 -0
- package/template/src/browser/app.html +24 -0
- package/template/src/browser/pages/about/page.svelte +5 -0
- package/template/src/browser/pages/layout.svelte +26 -0
- package/template/src/browser/pages/page.svelte +20 -0
- package/template/src/cli/banner.txt +3 -0
- package/template/src/cli/footer.txt +1 -0
- package/template/src/server/rpc/getHello.ts +33 -0
- package/template/svelte.config.js +12 -0
- package/template/tsconfig.json +18 -0
- package/tsconfig.app.json +16 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BunPlugin } from 'bun'
|
|
2
|
+
import { compile, compileModule, preprocess } from 'svelte/compiler'
|
|
3
|
+
import type { SvelteConfig } from './lib/server/runtime/types/SvelteConfig.ts'
|
|
4
|
+
import { log } from './lib/shared/log.ts'
|
|
5
|
+
import { tailwindStylePreprocessor } from './tailwindStylePreprocessor.ts'
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
Bun plugin that compiles `.svelte` components (with CSS injected at runtime)
|
|
9
|
+
and `.svelte.{js,ts}` rune modules via the svelte compiler. `.svelte.ts`
|
|
10
|
+
modules are first transpiled by Bun.Transpiler so the svelte compiler only
|
|
11
|
+
sees stripped JS. `generate` chooses 'server' (SSR) or 'client' (hydration);
|
|
12
|
+
the build pipeline constructs a separate plugin instance per target.
|
|
13
|
+
*/
|
|
14
|
+
export function sveltePlugin(options: {
|
|
15
|
+
generate: 'server' | 'client'
|
|
16
|
+
svelteConfig?: SvelteConfig
|
|
17
|
+
}): BunPlugin {
|
|
18
|
+
return {
|
|
19
|
+
name: 'svelte-loader',
|
|
20
|
+
async setup(build) {
|
|
21
|
+
const compileOptions = options.svelteConfig?.compilerOptions ?? {}
|
|
22
|
+
const tsTranspiler = new Bun.Transpiler({ loader: 'ts' })
|
|
23
|
+
const tailwindPreprocessor = await tailwindStylePreprocessor()
|
|
24
|
+
build.onLoad({ filter: /\.svelte\.(js|ts)$/ }, async (args) => {
|
|
25
|
+
const raw = await Bun.file(args.path).text()
|
|
26
|
+
const source = args.path.endsWith('.ts') ? tsTranspiler.transformSync(raw) : raw
|
|
27
|
+
const { js, warnings } = compileModule(source, {
|
|
28
|
+
...compileOptions,
|
|
29
|
+
filename: args.path,
|
|
30
|
+
generate: options.generate,
|
|
31
|
+
dev: false,
|
|
32
|
+
})
|
|
33
|
+
for (const warning of warnings) {
|
|
34
|
+
log.warn(`svelte ${args.path}: ${warning.message}`)
|
|
35
|
+
}
|
|
36
|
+
return { contents: js.code, loader: 'js' }
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
build.onLoad({ filter: /\.svelte$/ }, async (args) => {
|
|
40
|
+
const raw = await Bun.file(args.path).text()
|
|
41
|
+
const source = tailwindPreprocessor
|
|
42
|
+
? (await preprocess(raw, tailwindPreprocessor, { filename: args.path })).code
|
|
43
|
+
: raw
|
|
44
|
+
const { js, warnings } = compile(source, {
|
|
45
|
+
...compileOptions,
|
|
46
|
+
filename: args.path,
|
|
47
|
+
generate: options.generate,
|
|
48
|
+
css: 'injected',
|
|
49
|
+
dev: false,
|
|
50
|
+
})
|
|
51
|
+
for (const warning of warnings) {
|
|
52
|
+
log.warn(`svelte ${args.path}: ${warning.message}`)
|
|
53
|
+
}
|
|
54
|
+
return { contents: js.code, loader: 'js' }
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PreprocessorGroup } from 'svelte/compiler'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Svelte preprocessor that runs Tailwind v4 over each component `<style>` block.
|
|
5
|
+
Without this, directives like `@apply` and `@import "tailwindcss/theme" reference;`
|
|
6
|
+
pass straight through the Svelte compiler into the bundle — the `@import` becomes
|
|
7
|
+
a runtime fetch and `@apply` is dropped silently. `bun-plugin-tailwind` only
|
|
8
|
+
processes `.css` files, so scoped styles need this hook instead.
|
|
9
|
+
|
|
10
|
+
Returns undefined when `tailwindcss` isn't installed, so consumers without
|
|
11
|
+
Tailwind get the same behaviour as before.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
function dirname(filepath: string): string {
|
|
15
|
+
const lastSlash = filepath.lastIndexOf('/')
|
|
16
|
+
return lastSlash === -1 ? '' : filepath.slice(0, lastSlash)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function fileUrlToPath(href: string): string {
|
|
20
|
+
return new URL(href).pathname
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function pathToFileUrl(path: string): string {
|
|
24
|
+
return new URL(path, 'file://').href
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function tailwindStylePreprocessor(): Promise<PreprocessorGroup | undefined> {
|
|
28
|
+
let tailwind: typeof import('tailwindcss')
|
|
29
|
+
try {
|
|
30
|
+
tailwind = await import('tailwindcss')
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
const TAILWIND_DIRECTIVE = /@(?:apply|reference|tailwind|import\s+["']tailwindcss)/
|
|
35
|
+
return {
|
|
36
|
+
name: 'belte-tailwind-style',
|
|
37
|
+
async style({ content, filename }) {
|
|
38
|
+
if (!TAILWIND_DIRECTIVE.test(content)) {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
const base = filename ? dirname(filename) : process.cwd()
|
|
42
|
+
const result = await tailwind.compile(content, {
|
|
43
|
+
base,
|
|
44
|
+
loadStylesheet: async (uri, fromBase) => {
|
|
45
|
+
const fromUrl = pathToFileUrl(`${fromBase}/`)
|
|
46
|
+
const resolved = fileUrlToPath(import.meta.resolve(uri, fromUrl))
|
|
47
|
+
return {
|
|
48
|
+
path: resolved,
|
|
49
|
+
base: dirname(resolved),
|
|
50
|
+
content: await Bun.file(resolved).text(),
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
loadModule: async () => {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'Tailwind plugins/configs in component <style> blocks are not supported',
|
|
56
|
+
)
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
return { code: result.build([]) }
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "belte-app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "belte dev",
|
|
8
|
+
"build": "belte build",
|
|
9
|
+
"start": "belte start",
|
|
10
|
+
"compile": "belte compile"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@briancray/belte": "^0.1.0",
|
|
14
|
+
"svelte": "^5.0.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Optional application hooks. Every export is optional; delete the ones you
|
|
3
|
+
don't need. Belte resolves this file at build time via the belte:app virtual
|
|
4
|
+
module — no import is needed from your own code.
|
|
5
|
+
|
|
6
|
+
init runs once after Bun.serve is up; return a cleanup for SIGINT/SIGTERM
|
|
7
|
+
handle middleware wrapping the default request pipeline
|
|
8
|
+
handleError custom 500 fallback
|
|
9
|
+
*/
|
|
10
|
+
import type { AppModule } from 'belte/server/AppModule'
|
|
11
|
+
|
|
12
|
+
export const init: AppModule['init'] = ({ server }) => {
|
|
13
|
+
console.log(`server listening on http://localhost:${server.port}`)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const handle: AppModule['handle'] = async (request, next) => {
|
|
17
|
+
return next(request)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const handleError: AppModule['handleError'] = (error) => {
|
|
21
|
+
console.error(error)
|
|
22
|
+
return new Response('something went wrong', { status: 500 })
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Global stylesheet. Imported once from src/browser/pages/layout.svelte so it ships
|
|
3
|
+
with every page. To enable Tailwind v4, add `bun-plugin-tailwind` and
|
|
4
|
+
`tailwindcss` as devDependencies and replace this file with:
|
|
5
|
+
|
|
6
|
+
@import "tailwindcss";
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
:root {
|
|
10
|
+
font-family: system-ui, sans-serif;
|
|
11
|
+
color: #1f2937;
|
|
12
|
+
background: #f8fafc;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
body {
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
a {
|
|
20
|
+
color: inherit;
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Optional HTML shell. If present at src/browser/app.html, belte uses this as the SSR
|
|
3
|
+
template; otherwise a default shell is used. The three comment markers below
|
|
4
|
+
are replaced at render time:
|
|
5
|
+
ssr:head rendered <head> from Svelte (title, meta, link tags)
|
|
6
|
+
ssr:body rendered page body
|
|
7
|
+
ssr:state cache snapshot + route info for hydration
|
|
8
|
+
See their usage further down (wrapped as HTML comments).
|
|
9
|
+
Delete this file to use the default shell.
|
|
10
|
+
-->
|
|
11
|
+
<!doctype html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="UTF-8" />
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
16
|
+
<link rel="stylesheet" href="/_app/client.css" />
|
|
17
|
+
<!--ssr:head-->
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<div id="app"><!--ssr:body--></div>
|
|
21
|
+
<!--ssr:state-->
|
|
22
|
+
<script type="module" src="/_app/client.js"></script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Root layout. Wraps every page below src/browser/pages/. Layouts are nearest-only:
|
|
3
|
+
the deepest matching layout.svelte runs and replaces ancestors — they don't
|
|
4
|
+
stack. To inherit chrome in a nested layout, extract a snippet and
|
|
5
|
+
{@render} it from each layout. Layouts run on both the server (during SSR)
|
|
6
|
+
and the client (after hydration).
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import '../app.css'
|
|
10
|
+
|
|
11
|
+
let { children }: { children: import('svelte').Snippet } = $props()
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<svelte:head>
|
|
15
|
+
<title>belte app</title>
|
|
16
|
+
</svelte:head>
|
|
17
|
+
|
|
18
|
+
<header>
|
|
19
|
+
<nav>
|
|
20
|
+
<a href="/">Home</a>
|
|
21
|
+
<a href="/about">About</a>
|
|
22
|
+
</nav>
|
|
23
|
+
</header>
|
|
24
|
+
<main>
|
|
25
|
+
{@render children()}
|
|
26
|
+
</main>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Root page — served at GET /. Every folder under src/browser/pages/ that
|
|
3
|
+
contains a page.svelte mounts at that folder's URL.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { cache } from 'belte/browser/cache'
|
|
7
|
+
import { getHello } from '$server/rpc/getHello.ts'
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
Top-level await runs on the server during SSR. The decoded body is captured
|
|
11
|
+
into the per-request cache, serialized into the HTML, and replayed on the
|
|
12
|
+
client during hydration — no second fetch. `cache(fn)()` returns the
|
|
13
|
+
Content-Type-decoded value (JSON object, string, or Blob); reach for
|
|
14
|
+
`.raw(args)` if you need the underlying Response.
|
|
15
|
+
*/
|
|
16
|
+
const hello = await cache(getHello)()
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<h1>{hello.message}</h1>
|
|
20
|
+
<p>Edit <code>src/browser/pages/page.svelte</code> and the page hot-reloads.</p>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Run `<command> --help` for command-specific flags.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
RPC module — every file under src/server/rpc/ exposes exactly one verb-bound remote
|
|
3
|
+
function. The filename is the export name and the URL path (under `/rpc/`),
|
|
4
|
+
and the imported verb (GET / POST / PUT / PATCH / DELETE / HEAD) picks the
|
|
5
|
+
HTTP method. The bundler swaps the runtime per build target: direct call on
|
|
6
|
+
the server, fetch over the network on the client.
|
|
7
|
+
|
|
8
|
+
Args (what the caller passes in) come from the handler's parameter type —
|
|
9
|
+
either an inline annotation or an explicit `GET<{ id: string }>(...)`
|
|
10
|
+
generic. Return (what the caller receives after Content-Type-driven
|
|
11
|
+
decoding) is inferred from the handler's return type via the
|
|
12
|
+
`TypedResponse<T>` brand on `json`/`error`/`redirect`/`jsonl`/`sse`, so
|
|
13
|
+
plain `GET(() => json({...}))` already types end-to-end.
|
|
14
|
+
|
|
15
|
+
For inbound validation pass a Standard Schema-compatible schema as the
|
|
16
|
+
second argument: `GET(fn, { schema })`. Args then infers from the schema's
|
|
17
|
+
output type and the server replies with 422 on validation failure.
|
|
18
|
+
|
|
19
|
+
`json(...)` from `belte/server/json` is a thin wrapper over `Response.json`
|
|
20
|
+
that defaults `Cache-Control: no-store`, since intermediary caches shouldn't
|
|
21
|
+
memoise rpc replies (the framework's per-request cache handles in-process
|
|
22
|
+
dedupe). Other helpers are siblings, one per file: `belte/server/error`,
|
|
23
|
+
`belte/server/redirect`, `belte/server/sse`, `belte/server/jsonl`.
|
|
24
|
+
|
|
25
|
+
Every rpc value also exposes `.raw(args?)` (returns the underlying
|
|
26
|
+
`Response`) and `.stream(args?)` (returns a `Subscribable` view of the body)
|
|
27
|
+
for callers that need headers/status or want to iterate SSE/JSONL frames.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { GET } from 'belte/server/GET'
|
|
31
|
+
import { json } from 'belte/server/json'
|
|
32
|
+
|
|
33
|
+
export const getHello = GET(() => json({ message: 'Hello from belte' }))
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Optional Svelte compiler configuration. Same shape as upstream Svelte.
|
|
3
|
+
Delete this file to use defaults.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** @type {import('belte').SvelteConfig} */
|
|
7
|
+
export default {
|
|
8
|
+
compilerOptions: {
|
|
9
|
+
// Opt in to top-level await inside Svelte components.
|
|
10
|
+
experimental: { async: true },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "belte/tsconfig",
|
|
3
|
+
"include": ["src/**/*.ts", "src/**/*.svelte"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"paths": {
|
|
6
|
+
"$server": ["./src/server"],
|
|
7
|
+
"$server/*": ["./src/server/*"],
|
|
8
|
+
"$browser": ["./src/browser"],
|
|
9
|
+
"$browser/*": ["./src/browser/*"],
|
|
10
|
+
"$shared": ["./src/shared"],
|
|
11
|
+
"$shared/*": ["./src/shared/*"],
|
|
12
|
+
"$mcp": ["./src/mcp"],
|
|
13
|
+
"$mcp/*": ["./src/mcp/*"],
|
|
14
|
+
"$cli": ["./src/cli"],
|
|
15
|
+
"$cli/*": ["./src/cli/*"]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"types": ["bun"]
|
|
15
|
+
}
|
|
16
|
+
}
|