@absolutejs/absolute 0.8.11 → 0.8.12

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/dist/index.js.map CHANGED
@@ -11,7 +11,7 @@
11
11
  "import { mkdir } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport { env } from \"node:process\";\nimport { write, file } from \"bun\";\nimport { compile, preprocess } from \"svelte/compiler\";\n\nexport const compileSvelte = async (\n\tentryPoints: string[],\n\toutputDirectory: string\n) => {\n\tconst pagesDir = join(outputDirectory, \"pages\");\n\tconst clientDir = join(outputDirectory, \"client\");\n\tconst indexesDir = join(outputDirectory, \"indexes\");\n\n\tawait Promise.all([\n\t\tmkdir(clientDir, { recursive: true }),\n\t\tmkdir(indexesDir, { recursive: true })\n\t]);\n\n\tconst isDev = env.NODE_ENV === \"development\";\n\n\tconst builds = await Promise.all(\n\t\tentryPoints.map(async (entry) => {\n\t\t\tconst source = await file(entry).text();\n\t\t\tconst { code: pre } = await preprocess(source, {});\n\n\t\t\tconst name = basename(entry, \".svelte\");\n\n\t\t\tconst { js: ssrJs } = compile(pre, {\n\t\t\t\tcss: \"injected\",\n\t\t\t\tdev: isDev,\n\t\t\t\tfilename: entry,\n\t\t\t\tgenerate: \"server\"\n\t\t\t});\n\t\t\tconst ssrPath = join(pagesDir, `${name}.js`);\n\n\t\t\tconst { js: clientJs } = compile(pre, {\n\t\t\t\tcss: \"injected\",\n\t\t\t\tdev: isDev,\n\t\t\t\tfilename: entry,\n\t\t\t\tgenerate: \"client\"\n\t\t\t});\n\t\t\tconst clientComponentPath = join(clientDir, `${name}.js`);\n\n\t\t\tconst bootstrap = `import Component from \"../client/${name}.js\";\nimport { hydrate } from \"svelte\";\nhydrate(Component,{target:document.body,props:window.__INITIAL_PROPS__??{}});`;\n\t\t\tconst clientIndexPath = join(indexesDir, `${name}.js`);\n\n\t\t\tawait Promise.all([\n\t\t\t\twrite(ssrPath, ssrJs.code),\n\t\t\t\twrite(clientComponentPath, clientJs.code),\n\t\t\t\twrite(clientIndexPath, bootstrap)\n\t\t\t]);\n\n\t\t\treturn { clientIndexPath, ssrPath };\n\t\t})\n\t);\n\n\treturn {\n\t\tsvelteClientPaths: builds.map(({ clientIndexPath }) => clientIndexPath),\n\t\tsvelteServerPaths: builds.map(({ ssrPath }) => ssrPath)\n\t};\n};\n",
12
12
  "import {\n\tMILLISECONDS_IN_A_SECOND,\n\tTIME_PRECISION,\n\tMILLISECONDS_IN_A_MINUTE\n} from \"../constants\";\n\nexport const getDurationString = (duration: number) => {\n\tlet durationString;\n\n\tif (duration < MILLISECONDS_IN_A_SECOND) {\n\t\tdurationString = `${duration.toFixed(TIME_PRECISION)}ms`;\n\t} else if (duration < MILLISECONDS_IN_A_MINUTE) {\n\t\tdurationString = `${(duration / MILLISECONDS_IN_A_SECOND).toFixed(TIME_PRECISION)}s`;\n\t} else {\n\t\tdurationString = `${(duration / MILLISECONDS_IN_A_MINUTE).toFixed(TIME_PRECISION)}m`;\n\t}\n\n\treturn durationString;\n};\n",
13
13
  "import { resolve, relative, sep } from \"node:path\";\n\nexport const validateSafePath = (targetPath: string, baseDirectory: string) => {\n\tconst absoluteBase = resolve(baseDirectory);\n\tconst absoluteTarget = resolve(baseDirectory, targetPath);\n\tif (relative(absoluteBase, absoluteTarget).startsWith(`..${sep}`)) {\n\t\tthrow new Error(`Unsafe path: ${targetPath}`);\n\t}\n\n\treturn absoluteTarget;\n};\n",
14
- "import { file } from \"bun\";\nimport { ComponentType, createElement } from \"react\";\nimport { renderToReadableStream as renderReactToReadableStream } from \"react-dom/server\";\nimport { Component } from \"svelte\";\nimport { renderToReadableStream as renderSvelteToReadableStream } from \"../svelte/renderToReadableStream\";\n\nexport const handleReactPageRequest = async <\n\tProps extends Record<string, unknown>\n>(\n\tpageComponent: ComponentType<Props>,\n\tindex: string,\n\t...props: keyof Props extends never ? [] : [props: Props]\n) => {\n\tconst [maybeProps] = props;\n\tconst element =\n\t\tmaybeProps !== undefined\n\t\t\t? createElement(pageComponent, maybeProps)\n\t\t\t: createElement(pageComponent);\n\n\tconst stream = await renderReactToReadableStream(element, {\n\t\tbootstrapModules: [index],\n\t\tbootstrapScriptContent: maybeProps\n\t\t\t? `window.__INITIAL_PROPS__=${JSON.stringify(maybeProps)}`\n\t\t\t: undefined\n\t});\n\n\treturn new Response(stream, {\n\t\theaders: { \"Content-Type\": \"text/html\" }\n\t});\n};\n\n// Declare overloads matching Svelte’s own component API to preserve correct type inference\ntype HandleSveltePageRequest = {\n\t(\n\t\tPageComponent: Component<Record<string, never>>,\n\t\tmanifest: Record<string, string>\n\t): Promise<Response>;\n\t<P extends Record<string, unknown>>(\n\t\tPageComponent: Component<P>,\n\t\tmanifest: Record<string, string>,\n\t\tprops: P\n\t): Promise<Response>;\n};\n\nexport const handleSveltePageRequest: HandleSveltePageRequest = async <\n\tP extends Record<string, unknown>\n>(\n\tPageComponent: Component<P>,\n\tmanifest: Record<string, string>,\n\tprops?: P\n) => {\n\tconst componentPath = PageComponent.toString();\n\tconst pathSegments = componentPath.split(\"/\");\n\tconst lastSegment = pathSegments[pathSegments.length - 1] ?? \"\";\n\tconst componentName = lastSegment.replace(/\\.svelte$/, \"\");\n\n\tconst pagePath = manifest[componentName];\n\tconst indexPath = manifest[`${componentName}Index`];\n\n\tconst { default: ImportedPageComponent } = await import(pagePath);\n\n\tconst stream = await renderSvelteToReadableStream(\n\t\tImportedPageComponent,\n\t\tprops,\n\t\t{\n\t\t\tbootstrapModules: [indexPath],\n\t\t\tbootstrapScriptContent: `window.__INITIAL_PROPS__=${JSON.stringify(\n\t\t\t\tprops\n\t\t\t)}`\n\t\t}\n\t);\n\n\treturn new Response(stream, {\n\t\theaders: { \"Content-Type\": \"text/html\" }\n\t});\n};\n\nexport const handleHTMLPageRequest = (html: string) => file(html);\n",
14
+ "import { file } from \"bun\";\nimport { ComponentType, createElement } from \"react\";\nimport { renderToReadableStream as renderReactToReadableStream } from \"react-dom/server\";\nimport { Component } from \"svelte\";\nimport { renderToReadableStream as renderSvelteToReadableStream } from \"../svelte/renderToReadableStream\";\n\nexport const handleReactPageRequest = async <\n\tProps extends Record<string, unknown> = Record<never, never>\n>(\n\tpageComponent: ComponentType<Props>,\n\tindex: string,\n\t...props: keyof Props extends never ? [] : [props: Props]\n) => {\n\tconst [maybeProps] = props;\n\tconst element =\n\t\tmaybeProps !== undefined\n\t\t\t? createElement(pageComponent, maybeProps)\n\t\t\t: createElement(pageComponent);\n\n\tconst stream = await renderReactToReadableStream(element, {\n\t\tbootstrapModules: [index],\n\t\tbootstrapScriptContent: maybeProps\n\t\t\t? `window.__INITIAL_PROPS__=${JSON.stringify(maybeProps)}`\n\t\t\t: undefined\n\t});\n\n\treturn new Response(stream, {\n\t\theaders: { \"Content-Type\": \"text/html\" }\n\t});\n};\n\n// Declare overloads matching Svelte’s own component API to preserve correct type inference\ntype HandleSveltePageRequest = {\n\t(\n\t\tPageComponent: Component<Record<string, never>>,\n\t\tmanifest: Record<string, string>\n\t): Promise<Response>;\n\t<P extends Record<string, unknown>>(\n\t\tPageComponent: Component<P>,\n\t\tmanifest: Record<string, string>,\n\t\tprops: P\n\t): Promise<Response>;\n};\n\nexport const handleSveltePageRequest: HandleSveltePageRequest = async <\n\tP extends Record<string, unknown>\n>(\n\tPageComponent: Component<P>,\n\tmanifest: Record<string, string>,\n\tprops?: P\n) => {\n\tconst componentPath = PageComponent.toString();\n\tconst pathSegments = componentPath.split(\"/\");\n\tconst lastSegment = pathSegments[pathSegments.length - 1] ?? \"\";\n\tconst componentName = lastSegment.replace(/\\.svelte$/, \"\");\n\n\tconst pagePath = manifest[componentName];\n\tconst indexPath = manifest[`${componentName}Index`];\n\n\tconst { default: ImportedPageComponent } = await import(pagePath);\n\n\tconst stream = await renderSvelteToReadableStream(\n\t\tImportedPageComponent,\n\t\tprops,\n\t\t{\n\t\t\tbootstrapModules: [indexPath],\n\t\t\tbootstrapScriptContent: `window.__INITIAL_PROPS__=${JSON.stringify(\n\t\t\t\tprops\n\t\t\t)}`\n\t\t}\n\t);\n\n\treturn new Response(stream, {\n\t\theaders: { \"Content-Type\": \"text/html\" }\n\t});\n};\n\nexport const handleHTMLPageRequest = (html: string) => file(html);\n",
15
15
  "import type { Component } from \"svelte\";\nimport { render } from \"svelte/server\";\nimport { DEFAULT_CHUNK_SIZE } from \"../constants\";\nimport { escapeScriptContent } from \"../utils/escapeScriptContent\";\n\nexport type RenderStreamOptions = {\n\tbootstrapScriptContent?: string;\n\tbootstrapScripts?: string[];\n\tbootstrapModules?: string[];\n\tnonce?: string;\n\tonError?: (error: unknown) => void;\n\tprogressiveChunkSize?: number;\n\tsignal?: AbortSignal;\n};\n\nexport const renderToReadableStream = async <\n\tProps extends Record<string, unknown> = Record<string, never>\n>(\n\tcomponent: Component<Props>,\n\tprops?: Props,\n\t{\n\t\tbootstrapScriptContent,\n\t\tbootstrapScripts = [],\n\t\tbootstrapModules = [],\n\t\tnonce,\n\t\tonError = console.error,\n\t\tprogressiveChunkSize = DEFAULT_CHUNK_SIZE,\n\t\tsignal\n\t}: RenderStreamOptions = {}\n) => {\n\ttry {\n\t\tconst { head, body } =\n\t\t\ttypeof props === \"undefined\"\n\t\t\t\t? // @ts-expect-error Svelte's render function can't determine which overload to choose when the component is generic\n\t\t\t\t\trender(component)\n\t\t\t\t: render(component, { props });\n\t\tconst nonceAttr = nonce ? ` nonce=\"${nonce}\"` : \"\";\n\t\tconst scripts =\n\t\t\t(bootstrapScriptContent\n\t\t\t\t? `<script${nonceAttr}>${escapeScriptContent(bootstrapScriptContent)}</script>`\n\t\t\t\t: \"\") +\n\t\t\tbootstrapScripts\n\t\t\t\t.map((src) => `<script${nonceAttr} src=\"${src}\"></script>`)\n\t\t\t\t.join(\"\") +\n\t\t\tbootstrapModules\n\t\t\t\t.map(\n\t\t\t\t\t(src) =>\n\t\t\t\t\t\t`<script${nonceAttr} type=\"module\" src=\"${src}\"></script>`\n\t\t\t\t)\n\t\t\t\t.join(\"\");\n\t\tconst encoder = new TextEncoder();\n\t\t// Warning: this encodes the entire document into memory in one buffer\n\t\tconst full = encoder.encode(\n\t\t\t`<!DOCTYPE html><html lang=\"en\"><head>${head}</head><body>${body}${scripts}</body></html>`\n\t\t);\n\n\t\tlet offset = 0;\n\n\t\treturn new ReadableStream<Uint8Array>({\n\t\t\ttype: \"bytes\",\n\t\t\tcancel(reason) {\n\t\t\t\tonError?.(reason);\n\t\t\t},\n\t\t\tpull(controller) {\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tcontroller.close();\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (offset >= full.length) {\n\t\t\t\t\tcontroller.close();\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst end = Math.min(\n\t\t\t\t\toffset + progressiveChunkSize,\n\t\t\t\t\tfull.length\n\t\t\t\t);\n\t\t\t\tcontroller.enqueue(full.subarray(offset, end));\n\t\t\t\toffset = end;\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\tonError?.(error);\n\t\tthrow error;\n\t}\n};\n",
16
16
  "const ESCAPE_LOOKUP: Record<string, string> = {\n\t\"\\u2028\": \"\\\\u2028\",\n\t\"\\u2029\": \"\\\\u2029\",\n\t\"&\": \"\\\\u0026\",\n\t\"<\": \"\\\\u003C\",\n\t\">\": \"\\\\u003E\"\n};\n\nconst ESCAPE_REGEX = /[&><\\u2028\\u2029]/g;\n\nexport const escapeScriptContent = (content: string) =>\n\tcontent.replace(ESCAPE_REGEX, (char) => ESCAPE_LOOKUP[char]);\n",
17
17
  "import { argv } from \"node:process\";\nimport { env } from \"bun\";\nimport { Elysia } from \"elysia\";\nimport { DEFAULT_PORT } from \"../constants\";\nimport { getLocalIPAddress } from \"../utils/networking\";\n\nlet host = env.HOST ?? \"localhost\";\nconst port = env.PORT ?? DEFAULT_PORT;\nlet localIP: string | undefined;\n\nconst args = argv;\nconst hostFlag = args.includes(\"--host\");\n\nif (hostFlag) {\n\tlocalIP = getLocalIPAddress();\n\thost = \"0.0.0.0\";\n}\n\nexport const networkingPlugin = (app: Elysia) =>\n\tapp.listen(\n\t\t{\n\t\t\thostname: host,\n\t\t\tport: port\n\t\t},\n\t\t() => {\n\t\t\t//TODO: I dont think this works properly\n\t\t\tif (hostFlag) {\n\t\t\t\tconsole.log(`Server started on http://localhost:${port}`);\n\t\t\t\tconsole.log(\n\t\t\t\t\t`Server started on network: http://${localIP}:${port}`\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconsole.log(`Server started on http://${host}:${port}`);\n\t\t\t}\n\t\t}\n\t);\n",
@@ -1,6 +1,6 @@
1
1
  import { ComponentType } from "react";
2
2
  import { Component } from "svelte";
3
- export declare const handleReactPageRequest: <Props extends Record<string, unknown>>(pageComponent: ComponentType<Props>, index: string, ...props: keyof Props extends never ? [] : [props: Props]) => Promise<Response>;
3
+ export declare const handleReactPageRequest: <Props extends Record<string, unknown> = Record<never, never>>(pageComponent: ComponentType<Props>, index: string, ...props: keyof Props extends never ? [] : [props: Props]) => Promise<Response>;
4
4
  type HandleSveltePageRequest = {
5
5
  (PageComponent: Component<Record<string, never>>, manifest: Record<string, string>): Promise<Response>;
6
6
  <P extends Record<string, unknown>>(PageComponent: Component<P>, manifest: Record<string, string>, props: P): Promise<Response>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/absolute",
3
- "version": "0.8.11",
3
+ "version": "0.8.12",
4
4
  "description": "A fullstack meta-framework for building web applications with TypeScript",
5
5
  "repository": {
6
6
  "type": "git",