heliumts 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/bin/helium.js +4 -0
- package/dist/bin/helium.js.map +1 -1
- package/dist/client/callMethod.d.ts +13 -0
- package/dist/client/callMethod.d.ts.map +1 -0
- package/dist/client/callMethod.js +10 -0
- package/dist/client/callMethod.js.map +1 -0
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/rpcClient.d.ts +7 -3
- package/dist/client/rpcClient.d.ts.map +1 -1
- package/dist/client/rpcClient.js +10 -7
- package/dist/client/rpcClient.js.map +1 -1
- package/dist/server/devServer.d.ts.map +1 -1
- package/dist/server/devServer.js +8 -23
- package/dist/server/devServer.js.map +1 -1
- package/dist/server/httpCompression.d.ts +8 -0
- package/dist/server/httpCompression.d.ts.map +1 -0
- package/dist/server/httpCompression.js +58 -0
- package/dist/server/httpCompression.js.map +1 -0
- package/dist/server/prodServer.d.ts.map +1 -1
- package/dist/server/prodServer.js +8 -23
- package/dist/server/prodServer.js.map +1 -1
- package/dist/server/rpcRegistry.d.ts +4 -0
- package/dist/server/rpcRegistry.d.ts.map +1 -1
- package/dist/server/rpcRegistry.js +14 -9
- package/dist/server/rpcRegistry.js.map +1 -1
- package/dist/server/serializer.js +12 -6
- package/dist/server/serializer.js.map +1 -1
- package/dist/vite/heliumPlugin.d.ts.map +1 -1
- package/dist/vite/heliumPlugin.js +4 -0
- package/dist/vite/heliumPlugin.js.map +1 -1
- package/dist/vite/ssg.d.ts.map +1 -1
- package/dist/vite/ssg.js +4 -0
- package/dist/vite/ssg.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
# HeliumTS
|
|
7
7
|
|
|
8
|
-
HeliumTS is a
|
|
8
|
+
HeliumTS is a lightweight, opinionated full-stack React + Vite framework designed for simplicity and type safety. It provides typed RPC communication and file-based routing.
|
|
9
9
|
|
|
10
10
|
## Table of Contents
|
|
11
11
|
|
|
@@ -31,7 +31,7 @@ HeliumTS is a blazing fast 🚀 and opinionated full-stack React + Vite framewor
|
|
|
31
31
|
|
|
32
32
|
## 1. Getting Started
|
|
33
33
|
|
|
34
|
-
The current release is **0.9.
|
|
34
|
+
The current release is **0.9.7**. See the [changelog](./CHANGELOG.md) for fixes and upgrade notes.
|
|
35
35
|
|
|
36
36
|
### 1.1. Installation
|
|
37
37
|
|
|
@@ -430,4 +430,4 @@ See [SSR Documentation](./docs/ssr.md) for detailed information including sideca
|
|
|
430
430
|
Contributions are welcome! Please read the [contributing guide](./CONTRIBUTING.md) for details.
|
|
431
431
|
|
|
432
432
|
## 7. License
|
|
433
|
-
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
|
433
|
+
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
package/dist/bin/helium.js
CHANGED
|
@@ -222,6 +222,10 @@ export function AppRouter() {
|
|
|
222
222
|
return null;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
export async function callMethod() {
|
|
226
|
+
throw new Error('callMethod is only available in the browser. Load server data with getServerSideProps instead.');
|
|
227
|
+
}
|
|
228
|
+
|
|
225
229
|
export function useCall() {
|
|
226
230
|
return {
|
|
227
231
|
call: async () => null,
|
package/dist/bin/helium.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helium.js","sourceRoot":"","sources":["../../src/bin/helium.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAqB,KAAK,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,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AC;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE;IAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACxD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,OAAO,EAAE,mDAAmD,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,sEAAsE;IACtE,gDAAgD;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE;QACjD,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,YAAY,EAAE,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;KACtH,CAAC,CAAC;IACH,YAAY,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,KAAK,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { type ChildProcess, spawn } from \"child_process\";\nimport { build as esbuild } from \"esbuild\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { build as viteBuild } from \"vite\";\n\nimport { replaceHtmlRootContents } from \"../utils/html.js\";\nimport { log } from \"../utils/logger.js\";\nimport { scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"../vite/scanner.js\";\nimport { generateStaticPages } from \"../vite/ssg.js\";\nimport { generateClientModule, generateServerManifest, generateTypeDefinitions } from \"../vite/virtualServerModule.js\";\n\nconst cli = cac(\"helium\");\nconst root = process.cwd();\n\nfunction monitorChild(child: ChildProcess) {\n const onInterrupt = () => child.kill(\"SIGINT\");\n const onTerminate = () => child.kill(\"SIGTERM\");\n process.on(\"SIGINT\", onInterrupt);\n process.on(\"SIGTERM\", onTerminate);\n child.on(\"error\", (error) => {\n log(\"error\", \"Failed to start child process:\", error);\n process.exit(1);\n });\n child.on(\"close\", (code, signal) => {\n process.off(\"SIGINT\", onInterrupt);\n process.off(\"SIGTERM\", onTerminate);\n process.exit(code ?? (signal === \"SIGINT\" ? 130 : signal === \"SIGTERM\" ? 143 : 1));\n });\n}\n\ncli.command(\"dev\", \"Start development server\").action(async () => {\n const vitePackage = fileURLToPath(import.meta.resolve(\"vite/package.json\"));\n monitorChild(spawn(process.execPath, [path.join(path.dirname(vitePackage), \"bin\", \"vite.js\")], { stdio: \"inherit\" }));\n});\n\ncli.command(\"build\", \"Build for production\").action(async () => {\n // Generate type definitions before building so TypeScript can resolve\n // server method types even if the dev server was never started.\n const { methods } = scanServerExports(root);\n const dts = generateTypeDefinitions(methods, root);\n const typesDir = path.join(root, \"src\", \"types\");\n const dtsPath = path.join(typesDir, \"heliumts-server.d.ts\");\n\n if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n if (!fs.existsSync(dtsPath) || fs.readFileSync(dtsPath, \"utf-8\") !== dts) {\n fs.writeFileSync(dtsPath, dts);\n log(\"info\", `Generated type definitions for ${methods.length} method(s)`);\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"Building client...\");\n\n try {\n const result = await viteBuild({\n root,\n logLevel: \"silent\",\n build: {\n outDir: \"dist\",\n },\n });\n\n // Display build output\n if (result && \"output\" in result) {\n const outputs = result.output;\n const zlib = await import(\"zlib\");\n\n for (const chunk of outputs) {\n if (chunk.type === \"asset\" || chunk.type === \"chunk\") {\n const fileName = chunk.fileName;\n const content = \"code\" in chunk ? chunk.code : chunk.source;\n const size = Buffer.byteLength(content, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(content);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${fileName.padEnd(35)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n }\n }\n }\n\n log(\"info\", \"Client build complete.\");\n\n // Generate static pages for SSG\n log(\"info\", \"--------------------------------\");\n try {\n // Read the generated index.html as a template for SSG\n const distDir = path.join(root, \"dist\");\n const htmlPath = path.join(distDir, \"index.html\");\n\n if (fs.existsSync(htmlPath)) {\n let htmlTemplate = fs.readFileSync(htmlPath, \"utf-8\");\n\n // Clean up the template for SSG:\n // 1. Remove the build-time HELIUM_CONNECTION_TOKEN (SSG pages don't need it)\n htmlTemplate = htmlTemplate.replace(/<script>window\\.HELIUM_CONNECTION_TOKEN = \"build-time-placeholder\";<\\/script>/g, \"\");\n\n // 2. Clear any existing content in root div from SPA build\n htmlTemplate = replaceHtmlRootContents(htmlTemplate, \"\", { \"data-ssg-page\": null, \"data-ssg-failed\": null });\n\n await generateStaticPages(null, root, htmlTemplate, distDir);\n } else {\n log(\"warn\", \"index.html not found in dist, skipping SSG\");\n }\n } catch (e) {\n log(\"warn\", \"SSG generation failed:\", e);\n // Don't fail the build if SSG fails\n }\n log(\"info\", \"--------------------------------\");\n } catch (e) {\n log(\"error\", \"Client build failed:\", e);\n process.exit(1);\n }\n\n log(\"info\", \"Building server...\");\n // Generate server entry\n const serverExports = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const ssrPages = scanSSRPages(root);\n const appShell = scanAppShell(root);\n const manifestCode = generateServerManifest(\n serverExports.methods,\n serverExports.httpHandlers,\n serverExports.seoMetadata,\n pageRoutePatterns,\n ssrPages,\n appShell,\n serverExports.middleware,\n serverExports.workers\n );\n\n // Create the main server module that will be imported after env is loaded\n const serverModuleCode = `\nimport { startProdServer, loadConfig } from 'heliumts/server';\n${manifestCode}\n\nexport async function start() {\n const config = await loadConfig();\n\n startProdServer({\n config,\n registerHandlers: (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n ssrPages,\n appShell,\n workers\n });\n}\n`;\n\n // Create the entry loader that loads env first, then imports the server module\n const entryCode = `\n// Load environment variables FIRST, before any other imports\nimport './env-loader.js';\n// Now import and start the server (this ensures handlers load after env)\nconst { start } = await import('./server-module.js');\nawait start();\n`;\n\n const envLoaderCode = `\nimport { loadEnvFiles, injectEnvToProcess, log } from 'heliumts/server';\nimport { fileURLToPath } from 'node:url';\nprocess.env.HELIUM_CONFIG_DIR ??= fileURLToPath(new URL('.', import.meta.url));\nprocess.env.NODE_ENV ??= 'production';\nconst envRoot = process.cwd();\nlog('info', \\`Loading .env files from: \\${envRoot}\\`);\nconst envVars = loadEnvFiles({ mode: 'production' });\ninjectEnvToProcess(envVars);\nif (Object.keys(envVars).length > 0) {\n log('info', \\`Loaded \\${Object.keys(envVars).length} environment variable(s) from .env files\\`);\n} else {\n log('info', 'No .env files found (using platform environment variables if available)');\n}\n`;\n\n const heliumDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumDir)) {\n fs.mkdirSync(heliumDir, { recursive: true });\n }\n const entryPath = path.join(heliumDir, \"server-entry.ts\");\n const envLoaderPath = path.join(heliumDir, \"env-loader.ts\");\n const serverModuleSrcPath = path.join(heliumDir, \"server-module.ts\");\n const ssrClientStubPath = path.join(heliumDir, \"ssr-client-stub.ts\");\n const ssrTransitionsStubPath = path.join(heliumDir, \"ssr-transitions-stub.ts\");\n const ssrPrefetchStubPath = path.join(heliumDir, \"ssr-prefetch-stub.ts\");\n\n const ssrClientStubCode = `\nimport React from 'react';\n\nexport const RouterContext = React.createContext(null);\n\nfunction getSSRRouterSnapshot() {\n const snapshot = globalThis.__HELIUM_SSR_ROUTER__ as\n | { path?: string; params?: Record<string, string | string[]>; search?: string }\n | undefined;\n\n if (!snapshot || typeof snapshot !== 'object') {\n return {\n path: '/',\n params: {},\n search: '',\n };\n }\n\n return {\n path: typeof snapshot.path === 'string' ? snapshot.path : '/',\n params: snapshot.params && typeof snapshot.params === 'object' ? snapshot.params : {},\n search: typeof snapshot.search === 'string' ? snapshot.search : '',\n };\n}\n\nexport function useRouter() {\n const snapshot = getSSRRouterSnapshot();\n return {\n path: snapshot.path,\n params: snapshot.params,\n searchParams: new URLSearchParams(snapshot.search),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n isNavigating: false,\n isPending: false,\n };\n}\n\nexport function Link(props: { href?: string; children?: React.ReactNode } & Record<string, unknown>) {\n const { href = '#', children, prefetch: _prefetch, ...rest } = props || {};\n return React.createElement('a', { href, ...rest }, children);\n}\n\nexport function Redirect() {\n return null;\n}\n\nexport function AppRouter() {\n return null;\n}\n\nexport function useCall() {\n return {\n call: async () => null,\n isCalling: false,\n error: null,\n };\n}\n\nexport function useFetch() {\n return {\n data: null,\n isLoading: false,\n error: null,\n refetch: async () => undefined,\n };\n}\n\nexport class RpcError extends Error {}\n\nexport function getPublicEnv() {\n return Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.startsWith('HELIUM_PUBLIC_') && value !== undefined));\n}\n\nexport function getPublicEnvValue(key: string) {\n return getPublicEnv()[key];\n}\n\nexport function isDevEnvironment() {\n return false;\n}\n\nexport function getRpcTransport() {\n return 'websocket';\n}\n\nexport function isAutoHttpOnMobileEnabled() {\n return false;\n}\n\nexport function preconnect() {}\n\nexport function isSSR() {\n return true;\n}\n`;\n\n const ssrTransitionsStubCode = `\nimport React from 'react';\nimport { useRouter } from 'heliumts/client';\n\nexport function useDeferredNavigation() {\n const { path } = useRouter();\n return {\n path,\n deferredPath: path,\n isStale: false,\n isPending: false,\n isTransitioning: false,\n };\n}\n\nexport function PageTransition({ children, fallback = null }: { children?: React.ReactNode; fallback?: React.ReactNode }) {\n return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },\n React.createElement(React.Suspense, { fallback }, children));\n}\n`;\n\n const ssrPrefetchStubCode = `\nexport function prefetchRoute() {}\nexport function clearPrefetchCache() {}\n`;\n\n fs.writeFileSync(entryPath, entryCode);\n fs.writeFileSync(envLoaderPath, envLoaderCode);\n fs.writeFileSync(serverModuleSrcPath, serverModuleCode);\n // Generate a client-side stub for heliumts/server that provides method stubs\n // (e.g. { __id: 'subscribeWaitlist' }) so client components that import\n // user-defined methods from 'heliumts/server' resolve correctly during\n // the esbuild server bundle (mirroring the Vite plugin's virtual module).\n const rpcClientStubPath = path.join(heliumDir, \"rpc-client-stub.ts\");\n const rpcClientStubCode = `export * from 'heliumts/server';\\n${generateClientModule(serverExports.methods)}`;\n fs.writeFileSync(rpcClientStubPath, rpcClientStubCode);\n\n fs.writeFileSync(ssrClientStubPath, ssrClientStubCode);\n fs.writeFileSync(ssrTransitionsStubPath, ssrTransitionsStubCode);\n fs.writeFileSync(ssrPrefetchStubPath, ssrPrefetchStubCode);\n\n // Bundle with esbuild\n try {\n await esbuild({\n entryPoints: [entryPath],\n outfile: path.join(root, \"dist\", \"server.js\"),\n bundle: true,\n platform: \"node\",\n format: \"esm\",\n jsx: \"automatic\",\n jsxImportSource: \"react\",\n plugins: [\n {\n name: \"helium-ssr-client-alias\",\n setup(build) {\n build.onResolve({ filter: /^heliumts\\/client$/ }, () => ({ path: ssrClientStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/transitions$/ }, () => ({ path: ssrTransitionsStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/prefetch$/ }, () => ({ path: ssrPrefetchStubPath }));\n // Intercept heliumts/server imports from client code\n // and redirect to the RPC stub module (method stubs).\n // Server-side files and generated server-module resolve normally.\n const serverDirAbs = path.join(root, \"src\", \"server\");\n build.onResolve({ filter: /^heliumts\\/server$/ }, (args) => {\n const importer = args.importer;\n // Allow the generated server-module and env-loader to\n // import the real heliumts/server framework exports.\n if (importer.startsWith(heliumDir) || importer.startsWith(serverDirAbs)) {\n return undefined; // let esbuild resolve normally\n }\n return { path: rpcClientStubPath };\n });\n },\n },\n ],\n external: [\n // External common database and heavy dependencies\n \"mongodb\",\n \"mongoose\",\n \"pg\",\n \"mysql\",\n \"mysql2\",\n \"sqlite3\",\n \"better-sqlite3\",\n \"redis\",\n \"esbuild\",\n // Node.js built-ins are automatically external, but let's be explicit\n \"crypto\",\n \"fs\",\n \"path\",\n \"http\",\n \"https\",\n \"stream\",\n \"zlib\",\n \"util\",\n ],\n target: \"node18\",\n metafile: true,\n banner: {\n js: \"import { createRequire } from 'module'; const require = createRequire(import.meta.url);\",\n },\n });\n\n // Display server build output\n const serverOutputPath = path.relative(root, path.join(root, \"dist\", \"server.js\"));\n const serverStats = fs.statSync(path.join(root, \"dist\", \"server.js\"));\n const serverSizeKB = (serverStats.size / 1024).toFixed(2);\n log(\"info\", ` ${serverOutputPath.padEnd(35)} ${serverSizeKB.padStart(8)} kB`);\n\n log(\"info\", \"Server build complete.\");\n\n // Bundle config helpers so moving the config into dist preserves relative imports.\n const configFile = [\"helium.config.js\", \"helium.config.mjs\", \"helium.config.ts\"].map((name) => path.join(root, name)).find((candidate) => fs.existsSync(candidate));\n if (configFile) {\n await esbuild({\n entryPoints: [configFile],\n outfile: path.join(root, \"dist\", \"helium.config.js\"),\n bundle: true,\n packages: \"external\",\n platform: \"node\",\n format: \"esm\",\n target: \"node20\",\n });\n log(\"info\", \"Bundled Helium config to dist/helium.config.js\");\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"✓ Build finished successfully.\");\n log(\"info\", \"▶ Run 'helium start' to start the production server.\");\n\n // Exit cleanly after build completes\n process.exit(0);\n } catch (e) {\n log(\"error\", \"Server build failed:\", e);\n process.exit(1);\n }\n});\n\ncli.command(\"start\", \"Start production server\").action(async () => {\n const serverPath = path.join(root, \"dist\", \"server.js\");\n if (!fs.existsSync(serverPath)) {\n log(\"error\", 'Server build not found. Run \"helium build\" first.');\n process.exit(1);\n }\n\n // When running in production, look for config in dist directory first\n // This allows the transpiled config to be found\n const server = spawn(process.execPath, [serverPath], {\n stdio: \"inherit\",\n env: { ...process.env, NODE_ENV: process.env.NODE_ENV || \"production\", HELIUM_CONFIG_DIR: path.join(root, \"dist\") },\n });\n monitorChild(server);\n});\n\ncli.help();\ncli.parse();\n"]}
|
|
1
|
+
{"version":3,"file":"helium.js","sourceRoot":"","sources":["../../src/bin/helium.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAqB,KAAK,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1G,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEvH,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,MAAM,IAAI,GAAG,OAAO,C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UAAU,CAAC,EAAE;QACjD,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,YAAY,EAAE,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;KACtH,CAAC,CAAC;IACH,YAAY,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,KAAK,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { type ChildProcess, spawn } from \"child_process\";\nimport { build as esbuild } from \"esbuild\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { build as viteBuild } from \"vite\";\n\nimport { replaceHtmlRootContents } from \"../utils/html.js\";\nimport { log } from \"../utils/logger.js\";\nimport { scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"../vite/scanner.js\";\nimport { generateStaticPages } from \"../vite/ssg.js\";\nimport { generateClientModule, generateServerManifest, generateTypeDefinitions } from \"../vite/virtualServerModule.js\";\n\nconst cli = cac(\"helium\");\nconst root = process.cwd();\n\nfunction monitorChild(child: ChildProcess) {\n const onInterrupt = () => child.kill(\"SIGINT\");\n const onTerminate = () => child.kill(\"SIGTERM\");\n process.on(\"SIGINT\", onInterrupt);\n process.on(\"SIGTERM\", onTerminate);\n child.on(\"error\", (error) => {\n log(\"error\", \"Failed to start child process:\", error);\n process.exit(1);\n });\n child.on(\"close\", (code, signal) => {\n process.off(\"SIGINT\", onInterrupt);\n process.off(\"SIGTERM\", onTerminate);\n process.exit(code ?? (signal === \"SIGINT\" ? 130 : signal === \"SIGTERM\" ? 143 : 1));\n });\n}\n\ncli.command(\"dev\", \"Start development server\").action(async () => {\n const vitePackage = fileURLToPath(import.meta.resolve(\"vite/package.json\"));\n monitorChild(spawn(process.execPath, [path.join(path.dirname(vitePackage), \"bin\", \"vite.js\")], { stdio: \"inherit\" }));\n});\n\ncli.command(\"build\", \"Build for production\").action(async () => {\n // Generate type definitions before building so TypeScript can resolve\n // server method types even if the dev server was never started.\n const { methods } = scanServerExports(root);\n const dts = generateTypeDefinitions(methods, root);\n const typesDir = path.join(root, \"src\", \"types\");\n const dtsPath = path.join(typesDir, \"heliumts-server.d.ts\");\n\n if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n if (!fs.existsSync(dtsPath) || fs.readFileSync(dtsPath, \"utf-8\") !== dts) {\n fs.writeFileSync(dtsPath, dts);\n log(\"info\", `Generated type definitions for ${methods.length} method(s)`);\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"Building client...\");\n\n try {\n const result = await viteBuild({\n root,\n logLevel: \"silent\",\n build: {\n outDir: \"dist\",\n },\n });\n\n // Display build output\n if (result && \"output\" in result) {\n const outputs = result.output;\n const zlib = await import(\"zlib\");\n\n for (const chunk of outputs) {\n if (chunk.type === \"asset\" || chunk.type === \"chunk\") {\n const fileName = chunk.fileName;\n const content = \"code\" in chunk ? chunk.code : chunk.source;\n const size = Buffer.byteLength(content, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(content);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${fileName.padEnd(35)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n }\n }\n }\n\n log(\"info\", \"Client build complete.\");\n\n // Generate static pages for SSG\n log(\"info\", \"--------------------------------\");\n try {\n // Read the generated index.html as a template for SSG\n const distDir = path.join(root, \"dist\");\n const htmlPath = path.join(distDir, \"index.html\");\n\n if (fs.existsSync(htmlPath)) {\n let htmlTemplate = fs.readFileSync(htmlPath, \"utf-8\");\n\n // Clean up the template for SSG:\n // 1. Remove the build-time HELIUM_CONNECTION_TOKEN (SSG pages don't need it)\n htmlTemplate = htmlTemplate.replace(/<script>window\\.HELIUM_CONNECTION_TOKEN = \"build-time-placeholder\";<\\/script>/g, \"\");\n\n // 2. Clear any existing content in root div from SPA build\n htmlTemplate = replaceHtmlRootContents(htmlTemplate, \"\", { \"data-ssg-page\": null, \"data-ssg-failed\": null });\n\n await generateStaticPages(null, root, htmlTemplate, distDir);\n } else {\n log(\"warn\", \"index.html not found in dist, skipping SSG\");\n }\n } catch (e) {\n log(\"warn\", \"SSG generation failed:\", e);\n // Don't fail the build if SSG fails\n }\n log(\"info\", \"--------------------------------\");\n } catch (e) {\n log(\"error\", \"Client build failed:\", e);\n process.exit(1);\n }\n\n log(\"info\", \"Building server...\");\n // Generate server entry\n const serverExports = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const ssrPages = scanSSRPages(root);\n const appShell = scanAppShell(root);\n const manifestCode = generateServerManifest(\n serverExports.methods,\n serverExports.httpHandlers,\n serverExports.seoMetadata,\n pageRoutePatterns,\n ssrPages,\n appShell,\n serverExports.middleware,\n serverExports.workers\n );\n\n // Create the main server module that will be imported after env is loaded\n const serverModuleCode = `\nimport { startProdServer, loadConfig } from 'heliumts/server';\n${manifestCode}\n\nexport async function start() {\n const config = await loadConfig();\n\n startProdServer({\n config,\n registerHandlers: (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n ssrPages,\n appShell,\n workers\n });\n}\n`;\n\n // Create the entry loader that loads env first, then imports the server module\n const entryCode = `\n// Load environment variables FIRST, before any other imports\nimport './env-loader.js';\n// Now import and start the server (this ensures handlers load after env)\nconst { start } = await import('./server-module.js');\nawait start();\n`;\n\n const envLoaderCode = `\nimport { loadEnvFiles, injectEnvToProcess, log } from 'heliumts/server';\nimport { fileURLToPath } from 'node:url';\nprocess.env.HELIUM_CONFIG_DIR ??= fileURLToPath(new URL('.', import.meta.url));\nprocess.env.NODE_ENV ??= 'production';\nconst envRoot = process.cwd();\nlog('info', \\`Loading .env files from: \\${envRoot}\\`);\nconst envVars = loadEnvFiles({ mode: 'production' });\ninjectEnvToProcess(envVars);\nif (Object.keys(envVars).length > 0) {\n log('info', \\`Loaded \\${Object.keys(envVars).length} environment variable(s) from .env files\\`);\n} else {\n log('info', 'No .env files found (using platform environment variables if available)');\n}\n`;\n\n const heliumDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumDir)) {\n fs.mkdirSync(heliumDir, { recursive: true });\n }\n const entryPath = path.join(heliumDir, \"server-entry.ts\");\n const envLoaderPath = path.join(heliumDir, \"env-loader.ts\");\n const serverModuleSrcPath = path.join(heliumDir, \"server-module.ts\");\n const ssrClientStubPath = path.join(heliumDir, \"ssr-client-stub.ts\");\n const ssrTransitionsStubPath = path.join(heliumDir, \"ssr-transitions-stub.ts\");\n const ssrPrefetchStubPath = path.join(heliumDir, \"ssr-prefetch-stub.ts\");\n\n const ssrClientStubCode = `\nimport React from 'react';\n\nexport const RouterContext = React.createContext(null);\n\nfunction getSSRRouterSnapshot() {\n const snapshot = globalThis.__HELIUM_SSR_ROUTER__ as\n | { path?: string; params?: Record<string, string | string[]>; search?: string }\n | undefined;\n\n if (!snapshot || typeof snapshot !== 'object') {\n return {\n path: '/',\n params: {},\n search: '',\n };\n }\n\n return {\n path: typeof snapshot.path === 'string' ? snapshot.path : '/',\n params: snapshot.params && typeof snapshot.params === 'object' ? snapshot.params : {},\n search: typeof snapshot.search === 'string' ? snapshot.search : '',\n };\n}\n\nexport function useRouter() {\n const snapshot = getSSRRouterSnapshot();\n return {\n path: snapshot.path,\n params: snapshot.params,\n searchParams: new URLSearchParams(snapshot.search),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n isNavigating: false,\n isPending: false,\n };\n}\n\nexport function Link(props: { href?: string; children?: React.ReactNode } & Record<string, unknown>) {\n const { href = '#', children, prefetch: _prefetch, ...rest } = props || {};\n return React.createElement('a', { href, ...rest }, children);\n}\n\nexport function Redirect() {\n return null;\n}\n\nexport function AppRouter() {\n return null;\n}\n\nexport async function callMethod() {\n throw new Error('callMethod is only available in the browser. Load server data with getServerSideProps instead.');\n}\n\nexport function useCall() {\n return {\n call: async () => null,\n isCalling: false,\n error: null,\n };\n}\n\nexport function useFetch() {\n return {\n data: null,\n isLoading: false,\n error: null,\n refetch: async () => undefined,\n };\n}\n\nexport class RpcError extends Error {}\n\nexport function getPublicEnv() {\n return Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.startsWith('HELIUM_PUBLIC_') && value !== undefined));\n}\n\nexport function getPublicEnvValue(key: string) {\n return getPublicEnv()[key];\n}\n\nexport function isDevEnvironment() {\n return false;\n}\n\nexport function getRpcTransport() {\n return 'websocket';\n}\n\nexport function isAutoHttpOnMobileEnabled() {\n return false;\n}\n\nexport function preconnect() {}\n\nexport function isSSR() {\n return true;\n}\n`;\n\n const ssrTransitionsStubCode = `\nimport React from 'react';\nimport { useRouter } from 'heliumts/client';\n\nexport function useDeferredNavigation() {\n const { path } = useRouter();\n return {\n path,\n deferredPath: path,\n isStale: false,\n isPending: false,\n isTransitioning: false,\n };\n}\n\nexport function PageTransition({ children, fallback = null }: { children?: React.ReactNode; fallback?: React.ReactNode }) {\n return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },\n React.createElement(React.Suspense, { fallback }, children));\n}\n`;\n\n const ssrPrefetchStubCode = `\nexport function prefetchRoute() {}\nexport function clearPrefetchCache() {}\n`;\n\n fs.writeFileSync(entryPath, entryCode);\n fs.writeFileSync(envLoaderPath, envLoaderCode);\n fs.writeFileSync(serverModuleSrcPath, serverModuleCode);\n // Generate a client-side stub for heliumts/server that provides method stubs\n // (e.g. { __id: 'subscribeWaitlist' }) so client components that import\n // user-defined methods from 'heliumts/server' resolve correctly during\n // the esbuild server bundle (mirroring the Vite plugin's virtual module).\n const rpcClientStubPath = path.join(heliumDir, \"rpc-client-stub.ts\");\n const rpcClientStubCode = `export * from 'heliumts/server';\\n${generateClientModule(serverExports.methods)}`;\n fs.writeFileSync(rpcClientStubPath, rpcClientStubCode);\n\n fs.writeFileSync(ssrClientStubPath, ssrClientStubCode);\n fs.writeFileSync(ssrTransitionsStubPath, ssrTransitionsStubCode);\n fs.writeFileSync(ssrPrefetchStubPath, ssrPrefetchStubCode);\n\n // Bundle with esbuild\n try {\n await esbuild({\n entryPoints: [entryPath],\n outfile: path.join(root, \"dist\", \"server.js\"),\n bundle: true,\n platform: \"node\",\n format: \"esm\",\n jsx: \"automatic\",\n jsxImportSource: \"react\",\n plugins: [\n {\n name: \"helium-ssr-client-alias\",\n setup(build) {\n build.onResolve({ filter: /^heliumts\\/client$/ }, () => ({ path: ssrClientStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/transitions$/ }, () => ({ path: ssrTransitionsStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/prefetch$/ }, () => ({ path: ssrPrefetchStubPath }));\n // Intercept heliumts/server imports from client code\n // and redirect to the RPC stub module (method stubs).\n // Server-side files and generated server-module resolve normally.\n const serverDirAbs = path.join(root, \"src\", \"server\");\n build.onResolve({ filter: /^heliumts\\/server$/ }, (args) => {\n const importer = args.importer;\n // Allow the generated server-module and env-loader to\n // import the real heliumts/server framework exports.\n if (importer.startsWith(heliumDir) || importer.startsWith(serverDirAbs)) {\n return undefined; // let esbuild resolve normally\n }\n return { path: rpcClientStubPath };\n });\n },\n },\n ],\n external: [\n // External common database and heavy dependencies\n \"mongodb\",\n \"mongoose\",\n \"pg\",\n \"mysql\",\n \"mysql2\",\n \"sqlite3\",\n \"better-sqlite3\",\n \"redis\",\n \"esbuild\",\n // Node.js built-ins are automatically external, but let's be explicit\n \"crypto\",\n \"fs\",\n \"path\",\n \"http\",\n \"https\",\n \"stream\",\n \"zlib\",\n \"util\",\n ],\n target: \"node18\",\n metafile: true,\n banner: {\n js: \"import { createRequire } from 'module'; const require = createRequire(import.meta.url);\",\n },\n });\n\n // Display server build output\n const serverOutputPath = path.relative(root, path.join(root, \"dist\", \"server.js\"));\n const serverStats = fs.statSync(path.join(root, \"dist\", \"server.js\"));\n const serverSizeKB = (serverStats.size / 1024).toFixed(2);\n log(\"info\", ` ${serverOutputPath.padEnd(35)} ${serverSizeKB.padStart(8)} kB`);\n\n log(\"info\", \"Server build complete.\");\n\n // Bundle config helpers so moving the config into dist preserves relative imports.\n const configFile = [\"helium.config.js\", \"helium.config.mjs\", \"helium.config.ts\"].map((name) => path.join(root, name)).find((candidate) => fs.existsSync(candidate));\n if (configFile) {\n await esbuild({\n entryPoints: [configFile],\n outfile: path.join(root, \"dist\", \"helium.config.js\"),\n bundle: true,\n packages: \"external\",\n platform: \"node\",\n format: \"esm\",\n target: \"node20\",\n });\n log(\"info\", \"Bundled Helium config to dist/helium.config.js\");\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"✓ Build finished successfully.\");\n log(\"info\", \"▶ Run 'helium start' to start the production server.\");\n\n // Exit cleanly after build completes\n process.exit(0);\n } catch (e) {\n log(\"error\", \"Server build failed:\", e);\n process.exit(1);\n }\n});\n\ncli.command(\"start\", \"Start production server\").action(async () => {\n const serverPath = path.join(root, \"dist\", \"server.js\");\n if (!fs.existsSync(serverPath)) {\n log(\"error\", 'Server build not found. Run \"helium build\" first.');\n process.exit(1);\n }\n\n // When running in production, look for config in dist directory first\n // This allows the transpiled config to be found\n const server = spawn(process.execPath, [serverPath], {\n stdio: \"inherit\",\n env: { ...process.env, NODE_ENV: process.env.NODE_ENV || \"production\", HELIUM_CONFIG_DIR: path.join(root, \"dist\") },\n });\n monitorChild(server);\n});\n\ncli.help();\ncli.parse();\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RpcResult } from "./rpcClient.js";
|
|
2
|
+
import type { MethodStub } from "./types.js";
|
|
3
|
+
export type CallMethodOptions = {
|
|
4
|
+
/** Use a specific transport without automatic fallback to another transport. */
|
|
5
|
+
transport?: "http" | "websocket";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Call a typed server method outside React hooks. Does not update hook state or
|
|
9
|
+
* invalidate cached queries. Omit transport to use the configured selection and
|
|
10
|
+
* fallback behavior; the result reports the transport used for the response.
|
|
11
|
+
*/
|
|
12
|
+
export declare function callMethod<TArgs, TResult>(method: MethodStub<TArgs, TResult>, args: TArgs, options?: CallMethodOptions): Promise<RpcResult<TResult>>;
|
|
13
|
+
//# sourceMappingURL=callMethod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callMethod.d.ts","sourceRoot":"","sources":["../../src/client/callMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,iBAAiB,GAAG;IAC5B,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAExJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { rpcCallWithOptions } from "./rpcClient.js";
|
|
2
|
+
/**
|
|
3
|
+
* Call a typed server method outside React hooks. Does not update hook state or
|
|
4
|
+
* invalidate cached queries. Omit transport to use the configured selection and
|
|
5
|
+
* fallback behavior; the result reports the transport used for the response.
|
|
6
|
+
*/
|
|
7
|
+
export function callMethod(method, args, options = {}) {
|
|
8
|
+
return rpcCallWithOptions(method.__id, args, options);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=callMethod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callMethod.js","sourceRoot":"","sources":["../../src/client/callMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,gBAAgB,CAAC;AAQpE;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAiB,MAAkC,EAAE,IAAW,EAAE,UAA6B,EAAE;IACvH,OAAO,kBAAkB,CAAiB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import { rpcCallWithOptions, type RpcResult } from \"./rpcClient.js\";\nimport type { MethodStub } from \"./types.js\";\n\nexport type CallMethodOptions = {\n /** Use a specific transport without automatic fallback to another transport. */\n transport?: \"http\" | \"websocket\";\n};\n\n/**\n * Call a typed server method outside React hooks. Does not update hook state or\n * invalidate cached queries. Omit transport to use the configured selection and\n * fallback behavior; the result reports the transport used for the response.\n */\nexport function callMethod<TArgs, TResult>(method: MethodStub<TArgs, TResult>, args: TArgs, options: CallMethodOptions = {}): Promise<RpcResult<TResult>> {\n return rpcCallWithOptions<TResult, TArgs>(method.__id, args, options);\n}\n"]}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type { AppShellProps, LinkProps, RouterNavigationOptions } from "./Router
|
|
|
3
3
|
export { AppRouter, Link, Redirect, RouterContext, useRouter } from "./Router.js";
|
|
4
4
|
export type { LayoutProps } from "./routerManifest.js";
|
|
5
5
|
export type { PageTransitionProps } from "./transitions.js";
|
|
6
|
+
export { callMethod, type CallMethodOptions } from "./callMethod.js";
|
|
6
7
|
export * from "./useCall.js";
|
|
7
8
|
export * from "./useFetch.js";
|
|
8
9
|
export { RpcError } from "./RpcError.js";
|
|
@@ -12,7 +13,7 @@ export { RpcError } from "./RpcError.js";
|
|
|
12
13
|
* while still rendering providers and structural content for SSR.
|
|
13
14
|
*/
|
|
14
15
|
export declare function isSSR(): boolean;
|
|
15
|
-
export type { RpcTransport } from "./rpcClient.js";
|
|
16
|
+
export type { RpcResult, RpcTransport } from "./rpcClient.js";
|
|
16
17
|
export { getRpcTransport, isAutoHttpOnMobileEnabled, preconnect } from "./rpcClient.js";
|
|
17
18
|
export * from "./types.js";
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK7E,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClF,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG5D,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAG9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAGD,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK7E,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClF,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAG9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAGD,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGxF,cAAc,YAAY,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { getPublicEnv, getPublicEnvValue, isDevEnvironment } from "./env.js";
|
|
|
3
3
|
installStaleClientRecovery();
|
|
4
4
|
export { AppRouter, Link, Redirect, RouterContext, useRouter } from "./Router.js";
|
|
5
5
|
// RPC hooks for data fetching and mutations
|
|
6
|
+
export { callMethod } from "./callMethod.js";
|
|
6
7
|
export * from "./useCall.js";
|
|
7
8
|
export * from "./useFetch.js";
|
|
8
9
|
// RPC error type
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7E,0BAA0B,EAAE,CAAC;AAI7B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAOlF,4CAA4C;AAC5C,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAE9B,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,MAAM,UAAU,KAAK;IACjB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACzC,CAAC;AAID,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAExF,mBAAmB;AACnB,cAAc,YAAY,CAAC;AAE3B,yEAAyE","sourcesContent":["import { installStaleClientRecovery } from \"./staleRecovery.js\";\n\nexport { getPublicEnv, getPublicEnvValue, isDevEnvironment } from \"./env.js\";\n\ninstallStaleClientRecovery();\n\n// Router components and hooks\nexport type { AppShellProps, LinkProps, RouterNavigationOptions } from \"./Router.js\";\nexport { AppRouter, Link, Redirect, RouterContext, useRouter } from \"./Router.js\";\nexport type { LayoutProps } from \"./routerManifest.js\";\n\n// React 18+ page transitions (separate module for better tree-shaking)\n// Import from \"heliumts/client/transitions\" to ensure they're only bundled when used\nexport type { PageTransitionProps } from \"./transitions.js\";\n\n// RPC hooks for data fetching and mutations\nexport * from \"./useCall.js\";\nexport * from \"./useFetch.js\";\n\n// RPC error type\nexport { RpcError } from \"./RpcError.js\";\n\n/**\n * Returns `true` when the current code is executing during server-side rendering.\n * Use this in layouts or components to skip browser-only logic (e.g. auth guards)\n * while still rendering providers and structural content for SSR.\n */\nexport function isSSR(): boolean {\n return typeof window === \"undefined\";\n}\n\n// RPC transport info (configured via helium.config.js)\nexport type { RpcTransport } from \"./rpcClient.js\";\nexport { getRpcTransport, isAutoHttpOnMobileEnabled, preconnect } from \"./rpcClient.js\";\n\n// Type definitions\nexport * from \"./types.js\";\n\n// Internal - rpcClient and cache are used by hooks, not exposed to users\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE7E,0BAA0B,EAAE,CAAC;AAI7B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAOlF,4CAA4C;AAC5C,OAAO,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AACrE,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAE9B,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,MAAM,UAAU,KAAK;IACjB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACzC,CAAC;AAID,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAExF,mBAAmB;AACnB,cAAc,YAAY,CAAC;AAE3B,yEAAyE","sourcesContent":["import { installStaleClientRecovery } from \"./staleRecovery.js\";\n\nexport { getPublicEnv, getPublicEnvValue, isDevEnvironment } from \"./env.js\";\n\ninstallStaleClientRecovery();\n\n// Router components and hooks\nexport type { AppShellProps, LinkProps, RouterNavigationOptions } from \"./Router.js\";\nexport { AppRouter, Link, Redirect, RouterContext, useRouter } from \"./Router.js\";\nexport type { LayoutProps } from \"./routerManifest.js\";\n\n// React 18+ page transitions (separate module for better tree-shaking)\n// Import from \"heliumts/client/transitions\" to ensure they're only bundled when used\nexport type { PageTransitionProps } from \"./transitions.js\";\n\n// RPC hooks for data fetching and mutations\nexport { callMethod, type CallMethodOptions } from \"./callMethod.js\";\nexport * from \"./useCall.js\";\nexport * from \"./useFetch.js\";\n\n// RPC error type\nexport { RpcError } from \"./RpcError.js\";\n\n/**\n * Returns `true` when the current code is executing during server-side rendering.\n * Use this in layouts or components to skip browser-only logic (e.g. auth guards)\n * while still rendering providers and structural content for SSR.\n */\nexport function isSSR(): boolean {\n return typeof window === \"undefined\";\n}\n\n// RPC transport info (configured via helium.config.js)\nexport type { RpcResult, RpcTransport } from \"./rpcClient.js\";\nexport { getRpcTransport, isAutoHttpOnMobileEnabled, preconnect } from \"./rpcClient.js\";\n\n// Type definitions\nexport * from \"./types.js\";\n\n// Internal - rpcClient and cache are used by hooks, not exposed to users\n"]}
|
|
@@ -2,14 +2,18 @@ import type { RpcStats } from "../runtime/protocol.js";
|
|
|
2
2
|
export type RpcResult<T> = {
|
|
3
3
|
data: T;
|
|
4
4
|
stats: RpcStats;
|
|
5
|
+
/** The transport that actually delivered this response, including automatic fallback. */
|
|
6
|
+
transport: "http" | "websocket";
|
|
5
7
|
};
|
|
6
8
|
export type RpcCallOptions = {
|
|
7
9
|
forceHttp?: boolean;
|
|
10
|
+
/** Explicit selection disables automatic transport switching. */
|
|
11
|
+
transport?: "http" | "websocket";
|
|
8
12
|
};
|
|
9
13
|
/**
|
|
10
14
|
* Transport mode for RPC calls.
|
|
11
|
-
* - "http": Uses HTTP POST requests
|
|
12
|
-
* - "websocket": Uses persistent WebSocket connection
|
|
15
|
+
* - "http": Uses HTTP POST requests, with connection reuse provided by the browser
|
|
16
|
+
* - "websocket": Uses a persistent WebSocket connection
|
|
13
17
|
* - "auto": Automatically selects based on connection type
|
|
14
18
|
*/
|
|
15
19
|
export type RpcTransport = "http" | "websocket" | "auto";
|
|
@@ -28,7 +32,7 @@ export declare function isMobileRpcDevice(): boolean;
|
|
|
28
32
|
*
|
|
29
33
|
* Includes automatic retry logic: if a call fails due to a connection error
|
|
30
34
|
* (e.g. stale WebSocket after mobile browser was backgrounded), the client
|
|
31
|
-
* forces a fresh connection
|
|
35
|
+
* forces a fresh connection and retries with bounded exponential backoff.
|
|
32
36
|
*/
|
|
33
37
|
export declare function rpcCall<TResult = unknown, TArgs = unknown>(methodId: string, args?: TArgs): Promise<RpcResult<TResult>>;
|
|
34
38
|
export declare function rpcCallWithOptions<TResult = unknown, TArgs = unknown>(methodId: string, args: TArgs | undefined, options: RpcCallOptions): Promise<RpcResult<TResult>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpcClient.d.ts","sourceRoot":"","sources":["../../src/client/rpcClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA2B,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGhF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACvB,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"rpcClient.d.ts","sourceRoot":"","sources":["../../src/client/rpcClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA2B,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGhF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACvB,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,QAAQ,CAAC;IAChB,yFAAyF;IACzF,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CACpC,CAAC;AAWF;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAqBzD;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AA4CD,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAqtBD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAE7H;AAED,wBAAsB,kBAAkB,CAAC,OAAO,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,SAAS,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAE5K;AA0CD;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAYjC"}
|
package/dist/client/rpcClient.js
CHANGED
|
@@ -153,7 +153,7 @@ async function sendBatchHttp(batch) {
|
|
|
153
153
|
const res = responseMap.get(item.req.id);
|
|
154
154
|
if (res) {
|
|
155
155
|
if (res.ok) {
|
|
156
|
-
item.resolve({ data: res.result, stats: res.stats });
|
|
156
|
+
item.resolve({ data: res.result, stats: res.stats, transport: "http" });
|
|
157
157
|
}
|
|
158
158
|
else {
|
|
159
159
|
item.reject(new RpcError(res.error, res.stats));
|
|
@@ -547,7 +547,7 @@ async function createSocket() {
|
|
|
547
547
|
return;
|
|
548
548
|
}
|
|
549
549
|
if (res.ok) {
|
|
550
|
-
entry.resolve({ data: res.result, stats: res.stats });
|
|
550
|
+
entry.resolve({ data: res.result, stats: res.stats, transport: "websocket" });
|
|
551
551
|
}
|
|
552
552
|
else {
|
|
553
553
|
entry.reject(new RpcError(res.error, res.stats));
|
|
@@ -683,7 +683,7 @@ async function rpcCallWebSocket(methodId, args) {
|
|
|
683
683
|
*
|
|
684
684
|
* Includes automatic retry logic: if a call fails due to a connection error
|
|
685
685
|
* (e.g. stale WebSocket after mobile browser was backgrounded), the client
|
|
686
|
-
* forces a fresh connection
|
|
686
|
+
* forces a fresh connection and retries with bounded exponential backoff.
|
|
687
687
|
*/
|
|
688
688
|
export async function rpcCall(methodId, args) {
|
|
689
689
|
return rpcCallWithRetry(methodId, args, 0, {});
|
|
@@ -700,23 +700,26 @@ async function rpcCallViaHttpBatch(methodId, args) {
|
|
|
700
700
|
});
|
|
701
701
|
}
|
|
702
702
|
async function rpcCallWithRetry(methodId, args, attempt = 0, options = {}) {
|
|
703
|
+
const useHttp = options.transport === "http" || (options.transport === undefined && (options.forceHttp || shouldUseHttpTransport()));
|
|
703
704
|
try {
|
|
704
|
-
if (
|
|
705
|
+
if (useHttp) {
|
|
705
706
|
return await rpcCallViaHttpBatch(methodId, args);
|
|
706
707
|
}
|
|
707
708
|
return await rpcCallWebSocket(methodId, args);
|
|
708
709
|
}
|
|
709
710
|
catch (err) {
|
|
710
711
|
if (attempt < MAX_RETRIES && isRetriableError(err)) {
|
|
711
|
-
//
|
|
712
|
-
|
|
712
|
+
// An HTTP failure must not close unrelated in-flight WebSocket calls.
|
|
713
|
+
if (!useHttp) {
|
|
714
|
+
forceReconnect();
|
|
715
|
+
}
|
|
713
716
|
// Exponential backoff with jitter: 500ms, 1000ms, 2000ms (capped at 5s)
|
|
714
717
|
const baseDelay = Math.min(RETRY_BASE_DELAY_MS * 2 ** attempt, RETRY_MAX_DELAY_MS);
|
|
715
718
|
const jitter = Math.random() * baseDelay * 0.3;
|
|
716
719
|
await new Promise((r) => setTimeout(r, baseDelay + jitter));
|
|
717
720
|
return rpcCallWithRetry(methodId, args, attempt + 1, options);
|
|
718
721
|
}
|
|
719
|
-
if (isRetriableError(err) && configuredTransport !== "http" && !options.forceHttp) {
|
|
722
|
+
if (isRetriableError(err) && !useHttp && options.transport === undefined && configuredTransport !== "http" && !options.forceHttp) {
|
|
720
723
|
activateTemporaryHttpFallback();
|
|
721
724
|
return rpcCallViaHttpBatch(methodId, args);
|
|
722
725
|
}
|