@belte/belte 0.19.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 +313 -0
- package/LICENSE +21 -0
- package/README.md +559 -0
- package/bin/belte.ts +183 -0
- package/package.json +110 -0
- package/src/App.svelte +31 -0
- package/src/appEntry.ts +151 -0
- package/src/assets/app.html +14 -0
- package/src/belteResolverPlugin.ts +858 -0
- package/src/build.ts +147 -0
- package/src/buildCli.ts +129 -0
- package/src/buildDisconnected.ts +122 -0
- package/src/bundleApp.ts +149 -0
- package/src/bundleDisconnectedEntry.ts +17 -0
- package/src/cliEntry.ts +25 -0
- package/src/clientBuildPlugins.ts +41 -0
- package/src/clientEntry.ts +7 -0
- package/src/compile.ts +64 -0
- package/src/controlServerWorker.ts +422 -0
- package/src/dedupeSveltePlugin.ts +66 -0
- package/src/devEntry.ts +169 -0
- package/src/discoveryEntry.ts +81 -0
- package/src/lib/browser/applyStreamedResolution.ts +33 -0
- package/src/lib/browser/cacheEntryFromSnapshot.ts +48 -0
- package/src/lib/browser/flushUnresolvedPlaceholders.ts +16 -0
- package/src/lib/browser/installStreamingPlaceholders.ts +32 -0
- package/src/lib/browser/openResolveStream.ts +42 -0
- package/src/lib/browser/page.svelte.ts +258 -0
- package/src/lib/browser/pageStreamController.ts +17 -0
- package/src/lib/browser/refetchPlaceholder.ts +12 -0
- package/src/lib/browser/remoteProxy.ts +37 -0
- package/src/lib/browser/socketChannel.ts +192 -0
- package/src/lib/browser/socketProxy.ts +57 -0
- package/src/lib/browser/startClient.ts +153 -0
- package/src/lib/browser/subscribe.ts +131 -0
- package/src/lib/browser/types/Errors.ts +9 -0
- package/src/lib/browser/types/Layouts.ts +7 -0
- package/src/lib/browser/types/Pages.ts +7 -0
- package/src/lib/browser/types/StreamingDeferred.ts +9 -0
- package/src/lib/bundle/BundleMenu.ts +11 -0
- package/src/lib/bundle/BundleMenuItem.ts +24 -0
- package/src/lib/bundle/BundleWindow.ts +36 -0
- package/src/lib/bundle/WEBVIEW_BUILD_REVISION.ts +9 -0
- package/src/lib/bundle/WEBVIEW_VERSION.ts +7 -0
- package/src/lib/bundle/bindConnectedFlag.ts +29 -0
- package/src/lib/bundle/bindRequestNavigate.ts +31 -0
- package/src/lib/bundle/buildWebviewLib.ts +111 -0
- package/src/lib/bundle/disconnected.css +9 -0
- package/src/lib/bundle/disconnected.svelte +386 -0
- package/src/lib/bundle/ensureWebviewLib.ts +20 -0
- package/src/lib/bundle/exitWithParent.ts +28 -0
- package/src/lib/bundle/infoPlist.ts +46 -0
- package/src/lib/bundle/installDownloads.ts +24 -0
- package/src/lib/bundle/installMacMenu.ts +39 -0
- package/src/lib/bundle/listenLocalControlServer.ts +19 -0
- package/src/lib/bundle/native/belteMenu.mm +422 -0
- package/src/lib/bundle/native/webview.h +4557 -0
- package/src/lib/bundle/onMenu.ts +41 -0
- package/src/lib/bundle/openWebview.ts +104 -0
- package/src/lib/bundle/pngToIcns.ts +47 -0
- package/src/lib/bundle/probeBelteServer.ts +34 -0
- package/src/lib/bundle/resolveServerBinary.ts +12 -0
- package/src/lib/bundle/resolveWebviewLib.ts +53 -0
- package/src/lib/bundle/serverBinaryFilename.ts +8 -0
- package/src/lib/bundle/signMacApp.ts +35 -0
- package/src/lib/bundle/spawnEmbeddedServer.ts +65 -0
- package/src/lib/bundle/stableLocalPort.ts +19 -0
- package/src/lib/bundle/waitForServer.ts +23 -0
- package/src/lib/bundle/webviewCachePath.ts +23 -0
- package/src/lib/bundle/webviewLibName.ts +11 -0
- package/src/lib/cli/connectToServer.ts +23 -0
- package/src/lib/cli/createClient.ts +170 -0
- package/src/lib/cli/dispatchCommand.ts +71 -0
- package/src/lib/cli/loadEnvFromBinaryDir.ts +16 -0
- package/src/lib/cli/parseArgvForRpc.ts +97 -0
- package/src/lib/cli/printHelp.ts +119 -0
- package/src/lib/cli/printSessionHelp.ts +27 -0
- package/src/lib/cli/printSessionStatus.ts +21 -0
- package/src/lib/cli/printTrimmed.ts +8 -0
- package/src/lib/cli/printValue.ts +10 -0
- package/src/lib/cli/resolveCliTarget.ts +48 -0
- package/src/lib/cli/runCli.ts +139 -0
- package/src/lib/cli/runSession.ts +105 -0
- package/src/lib/cli/startLocalInstance.ts +14 -0
- package/src/lib/cli/tokenizeLine.ts +51 -0
- package/src/lib/cli/types/CliManifest.ts +9 -0
- package/src/lib/cli/types/CliManifestEntry.ts +17 -0
- package/src/lib/cli/types/CliTarget.ts +13 -0
- package/src/lib/mcp/annotationsForMethod.ts +29 -0
- package/src/lib/mcp/createMcpResourceServer.ts +101 -0
- package/src/lib/mcp/createMcpServer.ts +42 -0
- package/src/lib/mcp/dispatchMcpRequest.ts +146 -0
- package/src/lib/mcp/mcpResourceServerSlot.ts +18 -0
- package/src/lib/mcp/mcpSurface.ts +265 -0
- package/src/lib/mcp/toolResultFromResponse.ts +66 -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 +33 -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/PATCH.ts +9 -0
- package/src/lib/server/POST.ts +9 -0
- package/src/lib/server/PUT.ts +9 -0
- package/src/lib/server/agent.ts +76 -0
- package/src/lib/server/appDataDir.ts +15 -0
- package/src/lib/server/cli/buildEnvContent.ts +19 -0
- package/src/lib/server/cli/createTarGz.ts +76 -0
- package/src/lib/server/cli/handleCliDownload.ts +153 -0
- package/src/lib/server/cli/handleCliInstall.ts +37 -0
- package/src/lib/server/cli/installScript.ts +29 -0
- package/src/lib/server/cli/maxSourceMtime.ts +26 -0
- package/src/lib/server/cookies.ts +29 -0
- package/src/lib/server/env.ts +50 -0
- package/src/lib/server/error.ts +70 -0
- package/src/lib/server/json.ts +28 -0
- package/src/lib/server/jsonl.ts +46 -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/renderPromptTemplate.ts +16 -0
- package/src/lib/server/prompts/types/Prompt.ts +13 -0
- package/src/lib/server/prompts/types/PromptOptions.ts +12 -0
- package/src/lib/server/prompts/types/PromptRegistryEntry.ts +13 -0
- package/src/lib/server/prompts/types/PromptRoutes.ts +10 -0
- package/src/lib/server/redirect.ts +42 -0
- package/src/lib/server/request.ts +18 -0
- package/src/lib/server/rpc/defineVerb.ts +133 -0
- package/src/lib/server/rpc/dispatchVerbInProcess.ts +46 -0
- package/src/lib/server/rpc/findVerbByCommandName.ts +18 -0
- package/src/lib/server/rpc/parseArgs.ts +95 -0
- package/src/lib/server/rpc/registerVerb.ts +6 -0
- package/src/lib/server/rpc/types/RemoteHandler.ts +27 -0
- package/src/lib/server/rpc/types/RemoteRoutes.ts +13 -0
- package/src/lib/server/rpc/types/TypedResponse.ts +18 -0
- package/src/lib/server/rpc/types/VerbHelper.ts +68 -0
- package/src/lib/server/rpc/types/VerbRegistryEntry.ts +29 -0
- package/src/lib/server/rpc/unprocessed.ts +14 -0
- package/src/lib/server/rpc/verbRegistry.ts +11 -0
- package/src/lib/server/runtime/DEFAULT_PORT.ts +6 -0
- package/src/lib/server/runtime/DEV_REBUILD_MESSAGE.ts +4 -0
- package/src/lib/server/runtime/DEV_RELOAD_CLIENT_SCRIPT.ts +29 -0
- package/src/lib/server/runtime/acceptsZstd.ts +8 -0
- package/src/lib/server/runtime/buildOpenApiSpec.ts +106 -0
- package/src/lib/server/runtime/cacheControlForAsset.ts +22 -0
- package/src/lib/server/runtime/containsTraversal.ts +37 -0
- package/src/lib/server/runtime/createAssetHeaderCache.ts +35 -0
- package/src/lib/server/runtime/createPublicAssetServer.ts +63 -0
- package/src/lib/server/runtime/createRouteDispatcher.ts +100 -0
- package/src/lib/server/runtime/createServer.ts +692 -0
- package/src/lib/server/runtime/devReloadResponse.ts +35 -0
- package/src/lib/server/runtime/disableIdleTimeoutForStream.ts +27 -0
- package/src/lib/server/runtime/envSchemaStore.ts +15 -0
- package/src/lib/server/runtime/findOpenPort.ts +35 -0
- package/src/lib/server/runtime/getActiveServer.ts +6 -0
- package/src/lib/server/runtime/globToPathSet.ts +29 -0
- package/src/lib/server/runtime/inProcessServer.ts +20 -0
- package/src/lib/server/runtime/internalErrorResponse.ts +25 -0
- package/src/lib/server/runtime/isCrossOriginUpgrade.ts +19 -0
- package/src/lib/server/runtime/listenOnOpenPort.ts +36 -0
- package/src/lib/server/runtime/logExposedSurfaces.ts +162 -0
- package/src/lib/server/runtime/mimeForExtension.ts +20 -0
- package/src/lib/server/runtime/parseIdleTimeout.ts +10 -0
- package/src/lib/server/runtime/parsePort.ts +11 -0
- package/src/lib/server/runtime/registryManifests.ts +66 -0
- package/src/lib/server/runtime/requestContext.ts +5 -0
- package/src/lib/server/runtime/resolveStreamResponse.ts +29 -0
- package/src/lib/server/runtime/runWithRequestScope.ts +57 -0
- package/src/lib/server/runtime/safeJsonForScript.ts +17 -0
- package/src/lib/server/runtime/serializeCacheSnapshot.ts +45 -0
- package/src/lib/server/runtime/serverSlot.ts +13 -0
- package/src/lib/server/runtime/setActiveServer.ts +6 -0
- package/src/lib/server/runtime/snapshotEntryFromCache.ts +81 -0
- package/src/lib/server/runtime/streamCacheResolutions.ts +37 -0
- package/src/lib/server/runtime/streamFromIterator.ts +86 -0
- package/src/lib/server/runtime/streamStash.ts +64 -0
- package/src/lib/server/runtime/types/Assets.ts +1 -0
- package/src/lib/server/runtime/types/RequestStore.ts +27 -0
- package/src/lib/server/runtime/withResponseDefaults.ts +24 -0
- package/src/lib/server/server.ts +32 -0
- package/src/lib/server/socket.ts +31 -0
- package/src/lib/server/sockets/createSocketDispatcher.ts +311 -0
- package/src/lib/server/sockets/defineSocket.ts +167 -0
- package/src/lib/server/sockets/lookupSocket.ts +6 -0
- package/src/lib/server/sockets/recentHistory.ts +11 -0
- package/src/lib/server/sockets/registerSocket.ts +6 -0
- package/src/lib/server/sockets/socketOperations.ts +35 -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/SocketOperation.ts +22 -0
- package/src/lib/server/sockets/types/SocketOptions.ts +22 -0
- package/src/lib/server/sockets/types/SocketRegistryEntry.ts +17 -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 +53 -0
- package/src/lib/shared/BELTE_PACKAGE_NAME.ts +7 -0
- package/src/lib/shared/CACHE_CONTROL_VALUES.ts +16 -0
- package/src/lib/shared/HttpError.ts +19 -0
- package/src/lib/shared/RESOLVE_STREAM_PATH.ts +7 -0
- package/src/lib/shared/STREAMING_CONTENT_TYPES.ts +11 -0
- package/src/lib/shared/activeCacheStore.ts +20 -0
- package/src/lib/shared/appDataDir.ts +34 -0
- package/src/lib/shared/belteImportName.ts +44 -0
- package/src/lib/shared/browserClientFlags.ts +10 -0
- package/src/lib/shared/buildRpcRequest.ts +70 -0
- package/src/lib/shared/bundleLayout.ts +36 -0
- package/src/lib/shared/bundled.ts +34 -0
- package/src/lib/shared/cache.ts +559 -0
- package/src/lib/shared/cacheStoreSlot.ts +16 -0
- package/src/lib/shared/canonicalJson.ts +63 -0
- package/src/lib/shared/carriesBodyArgs.ts +13 -0
- package/src/lib/shared/clearLastConnection.ts +7 -0
- package/src/lib/shared/commandNameForUrl.ts +17 -0
- package/src/lib/shared/createCacheStore.ts +75 -0
- package/src/lib/shared/createPushIterator.ts +93 -0
- package/src/lib/shared/createRemoteFunction.ts +99 -0
- package/src/lib/shared/decodeResponse.ts +47 -0
- package/src/lib/shared/detectTarget.ts +27 -0
- package/src/lib/shared/exeSuffix.ts +9 -0
- package/src/lib/shared/exitOnBuildFailure.ts +17 -0
- package/src/lib/shared/extraForwardHeaders.ts +16 -0
- package/src/lib/shared/fileStem.ts +9 -0
- package/src/lib/shared/findExportCallSite.ts +479 -0
- package/src/lib/shared/forwardHeaders.ts +41 -0
- package/src/lib/shared/getRemoteMeta.ts +5 -0
- package/src/lib/shared/globalCacheStore.ts +15 -0
- package/src/lib/shared/globalCacheStoreSlot.ts +14 -0
- package/src/lib/shared/importNamesToStrip.ts +13 -0
- package/src/lib/shared/invalidateEvent.ts +11 -0
- package/src/lib/shared/isCompileTarget.ts +15 -0
- package/src/lib/shared/isDebugEnabled.ts +23 -0
- package/src/lib/shared/isModuleNotFound.ts +16 -0
- package/src/lib/shared/isReadOnlyMethod.ts +14 -0
- package/src/lib/shared/isStreamingResponse.ts +11 -0
- package/src/lib/shared/jsonSchemaForPromptArguments.ts +29 -0
- package/src/lib/shared/jsonSchemaForSchema.ts +32 -0
- package/src/lib/shared/jsonlErrorFrame.ts +24 -0
- package/src/lib/shared/keyForRemoteCall.ts +29 -0
- package/src/lib/shared/lastConnectionPath.ts +7 -0
- package/src/lib/shared/loadEnvFile.ts +17 -0
- package/src/lib/shared/loadEnvFromDataDir.ts +15 -0
- package/src/lib/shared/loadSvelteConfig.ts +18 -0
- package/src/lib/shared/log.ts +104 -0
- package/src/lib/shared/manifestModule.ts +39 -0
- package/src/lib/shared/memoizeByKey.ts +24 -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/parseBoundedEnvInt.ts +20 -0
- package/src/lib/shared/parseEnv.ts +30 -0
- package/src/lib/shared/parsePromptMarkdown.ts +34 -0
- package/src/lib/shared/parseRouteSegments.ts +22 -0
- package/src/lib/shared/prepareRpcModule.ts +59 -0
- package/src/lib/shared/prepareSocketModule.ts +49 -0
- package/src/lib/shared/programNameForPackage.ts +14 -0
- package/src/lib/shared/promptNameForFile.ts +10 -0
- package/src/lib/shared/queryStringFromArgs.ts +27 -0
- package/src/lib/shared/readEnvFile.ts +15 -0
- package/src/lib/shared/readLastConnection.ts +18 -0
- package/src/lib/shared/readPackageJson.ts +9 -0
- package/src/lib/shared/recordRemoteMeta.ts +5 -0
- package/src/lib/shared/remoteMetaStore.ts +16 -0
- package/src/lib/shared/resolveClientFlags.ts +20 -0
- package/src/lib/shared/responseErrorText.ts +9 -0
- package/src/lib/shared/rpcUrlForFile.ts +19 -0
- package/src/lib/shared/runningAsStandaloneBinary.ts +13 -0
- package/src/lib/shared/serializeEnv.ts +18 -0
- package/src/lib/shared/setCacheStoreResolver.ts +6 -0
- package/src/lib/shared/setGlobalCacheStoreResolver.ts +6 -0
- package/src/lib/shared/socketNameForFile.ts +11 -0
- package/src/lib/shared/sseErrorFrame.ts +29 -0
- package/src/lib/shared/streamResponse.ts +169 -0
- package/src/lib/shared/stripImport.ts +27 -0
- package/src/lib/shared/subscribableFromResponse.ts +51 -0
- package/src/lib/shared/toBunRoutePattern.ts +28 -0
- package/src/lib/shared/types/CacheEntry.ts +63 -0
- package/src/lib/shared/types/CacheInvalidation.ts +9 -0
- package/src/lib/shared/types/CacheOptions.ts +33 -0
- package/src/lib/shared/types/CacheSnapshot.ts +16 -0
- package/src/lib/shared/types/CacheSnapshotEntry.ts +15 -0
- package/src/lib/shared/types/CacheStore.ts +32 -0
- package/src/lib/shared/types/ClientFlags.ts +11 -0
- package/src/lib/shared/types/CompileTarget.ts +6 -0
- package/src/lib/shared/types/HttpVerb.ts +1 -0
- package/src/lib/shared/types/LastConnection.ts +9 -0
- package/src/lib/shared/types/PromptArgument.ts +12 -0
- package/src/lib/shared/types/RawRemoteFunction.ts +13 -0
- package/src/lib/shared/types/RemoteFunction.ts +42 -0
- package/src/lib/shared/types/StandardSchemaV1.ts +57 -0
- package/src/lib/shared/types/StreamedResolution.ts +10 -0
- package/src/lib/shared/types/StreamingPlaceholder.ts +13 -0
- package/src/lib/shared/types/Subscribable.ts +15 -0
- package/src/lib/shared/types/SvelteConfig.ts +5 -0
- package/src/lib/shared/withJsonSchema.ts +20 -0
- package/src/lib/shared/writeLastConnection.ts +13 -0
- package/src/lib/shared/writeRoutesDts.ts +67 -0
- package/src/lib/test/clearVerbRegistry.ts +11 -0
- package/src/lib/test/createTestClient.ts +78 -0
- package/src/preload.ts +20 -0
- package/src/scaffold.ts +92 -0
- package/src/serverBuildPlugins.ts +25 -0
- package/src/serverEntry.ts +94 -0
- package/src/sveltePlugin.ts +58 -0
- package/src/tailwindStylePreprocessor.ts +62 -0
- package/template/bunfig.toml +4 -0
- package/template/package.json +19 -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/bundle/icon.png +0 -0
- package/template/src/cli/banner.txt +3 -0
- package/template/src/cli/footer.txt +1 -0
- package/template/src/server/config.ts +17 -0
- package/template/src/server/rpc/getHello.ts +35 -0
- package/template/svelte.config.js +12 -0
- package/template/tsconfig.json +18 -0
- package/tsconfig.app.json +16 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
2
|
+
import * as appMod from './_virtual/app.ts'
|
|
3
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
4
|
+
import { appInfo } from './_virtual/app-info.ts'
|
|
5
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
6
|
+
import { assets } from './_virtual/assets.ts'
|
|
7
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
8
|
+
import cliProgramName from './_virtual/cli-name.ts'
|
|
9
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
10
|
+
import { errors } from './_virtual/errors.ts'
|
|
11
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
12
|
+
import { layouts } from './_virtual/layouts.ts'
|
|
13
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
14
|
+
import mcp from './_virtual/mcp.ts'
|
|
15
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
16
|
+
import { mcpResources } from './_virtual/mcp-resources.ts'
|
|
17
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
18
|
+
import { pages } from './_virtual/pages.ts'
|
|
19
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
20
|
+
import { prompts } from './_virtual/prompts.ts'
|
|
21
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
22
|
+
import { publicAssets } from './_virtual/public-assets.ts'
|
|
23
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
24
|
+
import { rpc } from './_virtual/rpc.ts'
|
|
25
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
26
|
+
import { shell } from './_virtual/shell.ts'
|
|
27
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
28
|
+
import { sockets } from './_virtual/sockets.ts'
|
|
29
|
+
import { exitWithParent } from './lib/bundle/exitWithParent.ts'
|
|
30
|
+
import { loadEnvFromBinaryDir } from './lib/cli/loadEnvFromBinaryDir.ts'
|
|
31
|
+
import { createServer } from './lib/server/runtime/createServer.ts'
|
|
32
|
+
import { requestContext } from './lib/server/runtime/requestContext.ts'
|
|
33
|
+
import { createCacheStore } from './lib/shared/createCacheStore.ts'
|
|
34
|
+
import { loadEnvFromDataDir } from './lib/shared/loadEnvFromDataDir.ts'
|
|
35
|
+
import { runningAsStandaloneBinary } from './lib/shared/runningAsStandaloneBinary.ts'
|
|
36
|
+
import { setCacheStoreResolver } from './lib/shared/setCacheStoreResolver.ts'
|
|
37
|
+
import { setGlobalCacheStoreResolver } from './lib/shared/setGlobalCacheStoreResolver.ts'
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
Resolve config into process.env before anything reads it (createServer reads
|
|
41
|
+
PORT, app code reads Bun.env.*). Standalone-only: data-dir first so the user's
|
|
42
|
+
saved config wins over the binary-dir shipped default; both back-fill only what
|
|
43
|
+
the shell didn't already set. A bundle launched via `open` has cwd `/`, so the
|
|
44
|
+
data-dir `.env` is how it gets its config at all. Under `bun dev`/`bun start`
|
|
45
|
+
these bundle layers don't apply — the project's own CWD `.env` (Bun-autoloaded)
|
|
46
|
+
is the config — so loading them would let a stray data-dir `PORT` defeat dev's
|
|
47
|
+
port scan.
|
|
48
|
+
*/
|
|
49
|
+
if (runningAsStandaloneBinary()) {
|
|
50
|
+
await loadEnvFromDataDir(cliProgramName)
|
|
51
|
+
await loadEnvFromBinaryDir()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
Eager-import src/server/config.ts (via belte:config) now that every .env layer
|
|
56
|
+
is merged into process.env — its top-level `env(schema)` validates the
|
|
57
|
+
environment and fails the boot loudly here, before the server starts, rather
|
|
58
|
+
than lazily on the first handler that imports `$server/config`. A dynamic
|
|
59
|
+
import (not a static top-level one) so it runs after the merge above, not at
|
|
60
|
+
module-eval time. No-op when the file is absent.
|
|
61
|
+
*/
|
|
62
|
+
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
63
|
+
await import('./_virtual/config.ts')
|
|
64
|
+
|
|
65
|
+
// In a bundle, tie this server's life to the launcher's (no-op standalone).
|
|
66
|
+
exitWithParent()
|
|
67
|
+
|
|
68
|
+
setCacheStoreResolver(() => requestContext.getStore()?.cache)
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
Process-level store for cache(fn, { global: true }) — one per server process,
|
|
72
|
+
outlives every request so memoised external calls are shared across them.
|
|
73
|
+
*/
|
|
74
|
+
const globalCacheStore = createCacheStore()
|
|
75
|
+
setGlobalCacheStoreResolver(() => globalCacheStore)
|
|
76
|
+
|
|
77
|
+
await createServer({
|
|
78
|
+
pages,
|
|
79
|
+
rpc,
|
|
80
|
+
sockets,
|
|
81
|
+
prompts,
|
|
82
|
+
layouts,
|
|
83
|
+
errors,
|
|
84
|
+
shell,
|
|
85
|
+
app: appMod,
|
|
86
|
+
assets,
|
|
87
|
+
publicAssets,
|
|
88
|
+
mcpResources,
|
|
89
|
+
mcp,
|
|
90
|
+
cliProgramName,
|
|
91
|
+
appInfo,
|
|
92
|
+
// Set by the dev orchestrator (devEntry); mounts the live-reload channel.
|
|
93
|
+
dev: Bun.env.BELTE_DEV === '1',
|
|
94
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BunPlugin } from 'bun'
|
|
2
|
+
import { compile, compileModule, preprocess } from 'svelte/compiler'
|
|
3
|
+
import { log } from './lib/shared/log.ts'
|
|
4
|
+
import type { SvelteConfig } from './lib/shared/types/SvelteConfig.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.debug('belte: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.debug('belte: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,19 @@
|
|
|
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
|
+
"cli": "belte cli",
|
|
12
|
+
"bundle": "belte bundle",
|
|
13
|
+
"test": "bun test"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@belte/belte": "^0.2.0",
|
|
17
|
+
"svelte": "^5.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -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/belte/server/AppModule'
|
|
11
|
+
|
|
12
|
+
export const init: AppModule['init'] = () => {
|
|
13
|
+
// one-time setup; optionally return a cleanup to run on SIGINT/SIGTERM
|
|
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/belte/shared/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>
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Run `<command> --help` for command-specific flags.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Typed environment. `env(schema)` validates Bun.env against a Standard Schema at
|
|
3
|
+
boot — a missing or malformed variable fails the boot with every issue listed,
|
|
4
|
+
instead of surfacing as `undefined` inside a handler. Import `config` from
|
|
5
|
+
`$server/config` anywhere server-side; it's typed from the schema.
|
|
6
|
+
|
|
7
|
+
Belte eager-imports this file at boot (the belte:config virtual) — no import is
|
|
8
|
+
needed from your own code. The floor below re-exports Bun.env untyped; swap it
|
|
9
|
+
for a schema once you have required variables:
|
|
10
|
+
|
|
11
|
+
import { env } from '@belte/belte/server/env'
|
|
12
|
+
import { z } from 'zod'
|
|
13
|
+
export const config = env(z.object({ DATABASE_URL: z.string() }))
|
|
14
|
+
|
|
15
|
+
Optional — delete this file to read Bun.env directly instead.
|
|
16
|
+
*/
|
|
17
|
+
export const config = Bun.env
|
|
@@ -0,0 +1,35 @@
|
|
|
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 as `inputSchema` in the
|
|
16
|
+
second argument: `GET(fn, { inputSchema })`. Args then infers from the
|
|
17
|
+
schema's output type and the server replies with 422 on validation
|
|
18
|
+
failure. An optional `outputSchema` describes the success body for the
|
|
19
|
+
OpenAPI 200 response and the MCP tool output.
|
|
20
|
+
|
|
21
|
+
`json(...)` from `belte/server/json` is a thin wrapper over `Response.json`
|
|
22
|
+
that defaults `Cache-Control: no-store`, since intermediary caches shouldn't
|
|
23
|
+
memoise rpc replies (the framework's per-request cache handles in-process
|
|
24
|
+
dedupe). Other helpers are siblings, one per file: `belte/server/error`,
|
|
25
|
+
`belte/server/redirect`, `belte/server/sse`, `belte/server/jsonl`.
|
|
26
|
+
|
|
27
|
+
Every rpc value also exposes `.raw(args?)` (returns the underlying
|
|
28
|
+
`Response`) and `.stream(args?)` (returns a `Subscribable` view of the body)
|
|
29
|
+
for callers that need headers/status or want to iterate SSE/JSONL frames.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { GET } from '@belte/belte/server/GET'
|
|
33
|
+
import { json } from '@belte/belte/server/json'
|
|
34
|
+
|
|
35
|
+
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('@briancray/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/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
|
+
}
|