@rsc-kit/core 0.7.0 → 0.7.2
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 +4 -4
- package/dist/action.d.ts +0 -1
- package/dist/action.js.map +1 -1
- package/dist/build-rsc-vite.d.ts +0 -1
- package/dist/build-rsc-vite.js.map +1 -1
- package/dist/cache.d.ts +0 -1
- package/dist/cache.js.map +1 -1
- package/dist/devServer.d.ts +0 -1
- package/dist/devServer.js.map +1 -1
- package/dist/devUrls.d.ts +0 -1
- package/dist/devUrls.js.map +1 -1
- package/dist/embed.d.ts +0 -1
- package/dist/embed.js.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js.map +1 -1
- package/dist/export.d.ts +0 -1
- package/dist/export.js.map +1 -1
- package/dist/files.d.ts +0 -1
- package/dist/files.js.map +1 -1
- package/dist/headers.d.ts +0 -1
- package/dist/headers.js.map +1 -1
- package/dist/host.d.ts +0 -1
- package/dist/host.js.map +1 -1
- package/dist/hostCalls.d.ts +0 -1
- package/dist/hostCalls.js.map +1 -1
- package/dist/js/ActivityRouter.d.ts +0 -1
- package/dist/js/ActivityRouter.js.map +1 -1
- package/dist/js/DocumentTitle.d.ts +0 -1
- package/dist/js/DocumentTitle.js.map +1 -1
- package/dist/js/Form.d.ts +0 -1
- package/dist/js/Form.js.map +1 -1
- package/dist/js/Link.d.ts +0 -1
- package/dist/js/Link.js.map +1 -1
- package/dist/js/PathnameProvider.d.ts +0 -1
- package/dist/js/PathnameProvider.js.map +1 -1
- package/dist/js/RedirectBoundary.d.ts +0 -1
- package/dist/js/RedirectBoundary.js.map +1 -1
- package/dist/js/SegmentBoundary.d.ts +0 -1
- package/dist/js/SegmentBoundary.js.map +1 -1
- package/dist/js/SlotBoundary.d.ts +0 -1
- package/dist/js/SlotBoundary.js.map +1 -1
- package/dist/js/createViteRscApp.d.ts +0 -1
- package/dist/js/createViteRscApp.js.map +1 -1
- package/dist/js/errors.d.ts +0 -1
- package/dist/js/errors.js.map +1 -1
- package/dist/js/navigate.d.ts +0 -1
- package/dist/js/navigate.js.map +1 -1
- package/dist/js/onlineStore.d.ts +0 -1
- package/dist/js/onlineStore.js.map +1 -1
- package/dist/js/pagePayload.d.ts +0 -1
- package/dist/js/pagePayload.js.map +1 -1
- package/dist/js/router.d.ts +0 -1
- package/dist/js/router.js.map +1 -1
- package/dist/js/section.d.ts +0 -1
- package/dist/js/section.js.map +1 -1
- package/dist/js/segmentStore.d.ts +0 -1
- package/dist/js/segmentStore.js.map +1 -1
- package/dist/js/slotStore.d.ts +0 -1
- package/dist/js/slotStore.js.map +1 -1
- package/dist/js/standardSchema.d.ts +0 -1
- package/dist/js/standardSchema.js.map +1 -1
- package/dist/js/useForm.d.ts +0 -1
- package/dist/js/useForm.js.map +1 -1
- package/dist/js/useLinkStatus.d.ts +0 -1
- package/dist/js/useLinkStatus.js.map +1 -1
- package/dist/js/useOnline.d.ts +0 -1
- package/dist/js/useOnline.js.map +1 -1
- package/dist/js/usePathname.d.ts +0 -1
- package/dist/js/usePathname.js.map +1 -1
- package/dist/js/useSearchParams.d.ts +0 -1
- package/dist/js/useSearchParams.js.map +1 -1
- package/dist/manifest.d.ts +0 -1
- package/dist/manifest.js.map +1 -1
- package/dist/nondeterminism.d.ts +0 -1
- package/dist/nondeterminism.js.map +1 -1
- package/dist/prerender.d.ts +0 -1
- package/dist/prerender.js.map +1 -1
- package/dist/redirect.d.ts +0 -1
- package/dist/redirect.js.map +1 -1
- package/dist/redirectDigest.d.ts +0 -1
- package/dist/redirectDigest.js.map +1 -1
- package/dist/request.d.ts +0 -1
- package/dist/request.js.map +1 -1
- package/dist/revalidate.d.ts +0 -1
- package/dist/revalidate.js.map +1 -1
- package/dist/routes.d.ts +0 -1
- package/dist/routes.js.map +1 -1
- package/dist/routing.d.ts +0 -1
- package/dist/routing.js.map +1 -1
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.js.map +1 -1
- package/dist/safeUrl.d.ts +0 -1
- package/dist/safeUrl.js.map +1 -1
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +73 -9
- package/dist/vite.js.map +1 -1
- package/package.json +1 -5
- package/dist/action.d.ts.map +0 -1
- package/dist/build-rsc-vite.d.ts.map +0 -1
- package/dist/cache.d.ts.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -84
- package/dist/cli.js.map +0 -1
- package/dist/devServer.d.ts.map +0 -1
- package/dist/devUrls.d.ts.map +0 -1
- package/dist/embed.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/export.d.ts.map +0 -1
- package/dist/files.d.ts.map +0 -1
- package/dist/headers.d.ts.map +0 -1
- package/dist/host.d.ts.map +0 -1
- package/dist/hostCalls.d.ts.map +0 -1
- package/dist/js/ActivityRouter.d.ts.map +0 -1
- package/dist/js/DocumentTitle.d.ts.map +0 -1
- package/dist/js/Form.d.ts.map +0 -1
- package/dist/js/Link.d.ts.map +0 -1
- package/dist/js/PathnameProvider.d.ts.map +0 -1
- package/dist/js/RedirectBoundary.d.ts.map +0 -1
- package/dist/js/SegmentBoundary.d.ts.map +0 -1
- package/dist/js/SlotBoundary.d.ts.map +0 -1
- package/dist/js/createViteRscApp.d.ts.map +0 -1
- package/dist/js/errors.d.ts.map +0 -1
- package/dist/js/navigate.d.ts.map +0 -1
- package/dist/js/onlineStore.d.ts.map +0 -1
- package/dist/js/pagePayload.d.ts.map +0 -1
- package/dist/js/router.d.ts.map +0 -1
- package/dist/js/section.d.ts.map +0 -1
- package/dist/js/segmentStore.d.ts.map +0 -1
- package/dist/js/slotStore.d.ts.map +0 -1
- package/dist/js/standardSchema.d.ts.map +0 -1
- package/dist/js/useForm.d.ts.map +0 -1
- package/dist/js/useLinkStatus.d.ts.map +0 -1
- package/dist/js/useOnline.d.ts.map +0 -1
- package/dist/js/usePathname.d.ts.map +0 -1
- package/dist/js/useSearchParams.d.ts.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/nondeterminism.d.ts.map +0 -1
- package/dist/prerender.d.ts.map +0 -1
- package/dist/redirect.d.ts.map +0 -1
- package/dist/redirectDigest.d.ts.map +0 -1
- package/dist/request.d.ts.map +0 -1
- package/dist/revalidate.d.ts.map +0 -1
- package/dist/routes.d.ts.map +0 -1
- package/dist/routing.d.ts.map +0 -1
- package/dist/runtime.d.ts.map +0 -1
- package/dist/safeUrl.d.ts.map +0 -1
- package/dist/vite.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
The engine: a Vite plugin that discovers the route tree, and a host adapter that serves it.
|
|
4
4
|
|
|
5
|
-
This is the library. Most people want [`rsc-kit`](https://www.npmjs.com/package/rsc-kit) (the command line) or `bun create rsc-kit` (a new app).
|
|
5
|
+
This is the library. Most people want [`rsc-kit`](https://www.npmjs.com/package/rsc-kit) (the command line) or `bun create rsc-kit@latest` (a new app).
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
bun create rsc-kit my-app
|
|
8
|
+
bun create rsc-kit@latest my-app
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Why not just use Next?
|
|
@@ -80,14 +80,14 @@ something.
|
|
|
80
80
|
## Getting started
|
|
81
81
|
|
|
82
82
|
```sh
|
|
83
|
-
bun create rsc-kit my-app
|
|
83
|
+
bun create rsc-kit@latest my-app # a new app
|
|
84
84
|
cd my-app && bun run dev
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Adding it to a project you already have:
|
|
88
88
|
|
|
89
89
|
```sh
|
|
90
|
-
bunx create-rsc-kit --init
|
|
90
|
+
bunx create-rsc-kit@latest --init
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
Docs: https://rsc-kit.dev
|
package/dist/action.d.ts
CHANGED
package/dist/action.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.ts"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AAuB,CAAC,KAAK,CAAC,EAAE,CAAC;4BACnC,OAAO,EAAE,gBAAgB,EAAE,KAAK,CAAC,MAAM,EAAE,CAAA;wBAC3C,CAAC;wBAED,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;oBACvC,CAAC;gBACH,CAAC,CAAA;YACH,CAAC;SACF,CAAA;IACH,CAAC;IAED,OAAO,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AACxB,CAAC","sourcesContent":["// Server actions with a schema, middleware, and types that follow from both.\n//\n// export const action = createActionClient({ onError: report })\n//\n// export const createPost = action\n// .use(async ({ next }) => next({ ctx: { user: await currentUser() } }))\n// .input(z.object({ title: z.string().min(3) }))\n// .handler(async ({ input, ctx }) => savePost(ctx.user.id, input.title))\n//\n// `input` is typed from the schema and `ctx` from every middleware that ran, so\n// the handler is checked against both without either being written down twice.\n//\n// The built action RETURNS its failures rather than throwing them, and that is\n// not a style choice. React serialises a rejected server action opaquely —\n// production strips the message and leaves a digest — so a thrown validation\n// error reaches the browser as \"an error occurred\" and the fields it named are\n// gone. A returned object crosses the boundary intact.\n//\n// Distinct from `middleware.ts` in a route directory, which decides whether a\n// page may render. This wraps one action. They are different questions: an\n// action is reachable without any page, which is why it defends itself.\n\nimport { validateWith, type StandardSchemaV1 } from './js/standardSchema.js'\n\n/** What an action answers with. Exactly one of the three is set. */\nexport interface ActionResult<Data> {\n /** What the handler returned. */\n data?: Data\n /** Field name to messages, in the shape a form already renders. */\n validationErrors?: Record<string, string[]>\n /** Something else went wrong, reduced to a message the browser may see. */\n serverError?: string\n}\n\n/**\n * A middleware that neither continued nor refused.\n *\n * Never reported through `onError`: that reduces an error to a message for the\n * browser, and this one is for whoever wrote the middleware. A check that\n * forgot to call `next()` would otherwise look exactly like a check that\n * passed.\n */\nexport class ActionMisuse extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'ActionMisuse'\n }\n}\n\n/** Refuse from inside a handler, naming the fields. */\n/**\n * Marks a refusal so it survives a bundle seam.\n *\n * A property rather than `instanceof`, for the reason this project keeps\n * running into: an app's actions are bundled separately from the engine, so\n * each gets its own copy of this module and its own copy of the class.\n * `instanceof` compares identity across that seam and is simply false — and\n * the refusal is then reported as a server error, so the form shows \"Something\n * went wrong\" instead of naming the fields. Everything works; nothing logs.\n *\n * Symbol.for, so the two copies agree on the key as well as the value.\n */\nconst VALIDATION_MARK = Symbol.for('@rsc-kit/core.action-validation')\n\nexport class ActionValidationError extends Error {\n public readonly errors: Record<string, string[]>\n\n constructor(errors: Record<string, string[]>) {\n super('Validation failed')\n this.name = 'ActionValidationError'\n this.errors = errors\n ;(this as unknown as Record<symbol, boolean>)[VALIDATION_MARK] = true\n }\n}\n\n/** Whether this is a refusal, whichever copy of the class built it. */\nexport function isActionValidationError(error: unknown): error is ActionValidationError {\n return (\n typeof error === 'object' &&\n error !== null &&\n (error as Record<symbol, unknown>)[VALIDATION_MARK] === true\n )\n}\n\n/**\n * Fail with field errors the form can show.\n *\n * For what a schema cannot know — a name already taken, a balance too low.\n * Throws, so the handler stops where it is; the action turns it into a\n * returned result on the way out.\n */\nexport function fieldErrors(errors: Record<string, string[] | string>): never {\n const normalised: Record<string, string[]> = {}\n\n for (const [field, message] of Object.entries(errors)) {\n normalised[field] = Array.isArray(message) ? message : [message]\n }\n\n throw new ActionValidationError(normalised)\n}\n\n/**\n * What `next()` hands back, carrying what the step added.\n *\n * The context a middleware contributes cannot be inferred from the arguments\n * it passes to `next` — TypeScript infers from a function's return, not from a\n * call inside it. So `next` returns this, the middleware returns it, and the\n * addition is read off the middleware's own return type.\n */\nexport interface MiddlewareResult<Extra> {\n readonly ctx: Extra\n readonly value: unknown\n}\n\n/**\n * A step that runs before the handler.\n *\n * It calls `next` to continue, optionally adding to the context, and what it\n * adds shows up in the handler's types. Returning without calling `next` — or\n * throwing — stops the action, which is how a check refuses.\n */\nexport type ActionMiddleware<Ctx, Extra extends Record<string, unknown>> = (args: {\n ctx: Ctx\n next: <E extends Record<string, unknown> = Record<string, never>>(\n opts?: { ctx?: E },\n ) => Promise<MiddlewareResult<E>>\n}) => Promise<MiddlewareResult<Extra>>\n\ntype Output<S> = S extends StandardSchemaV1<unknown, infer O> ? O : never\n\nexport interface ActionBuilder<Ctx extends Record<string, unknown>, Input> {\n /** Add a step, and whatever context it contributes. */\n use<Extra extends Record<string, unknown> = Record<string, never>>(\n middleware: (args: {\n ctx: Ctx\n next: <E extends Record<string, unknown> = Record<string, never>>(\n opts?: { ctx?: E },\n ) => Promise<MiddlewareResult<E>>\n }) => Promise<MiddlewareResult<Extra>>,\n ): ActionBuilder<Ctx & Extra, Input>\n /** Parse and check what the caller sent. The handler's `input` follows. */\n input<S extends StandardSchemaV1>(schema: S): ActionBuilder<Ctx, Output<S>>\n /** The body. */\n handler<Data>(\n fn: (args: { input: Input; ctx: Ctx }) => Promise<Data> | Data,\n ): (input?: unknown) => Promise<ActionResult<Data>>\n}\n\nexport interface ActionClientOptions {\n /**\n * What the browser is told when something unexpected throws.\n *\n * Everything reaching here is a bug or an outage, and its message may say\n * more than a stranger should see — a query, a path, a host. Returning a\n * fixed string is the safe default; return the message only for errors you\n * raised deliberately.\n */\n onError?: (error: unknown) => string\n}\n\nconst GENERIC = 'Something went wrong.'\n\n/** FormData in, a plain object out — what a schema expects to be handed. */\nfunction fromFormData(body: FormData): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n\n for (const key of new Set(body.keys())) {\n const values = body.getAll(key)\n\n // One value stays a value. Several stay several — a multi-select that\n // collapsed to its last entry would be a silent data loss.\n out[key] = values.length > 1 ? values : values[0]\n }\n\n return out\n}\n\nexport function createActionClient(\n options: ActionClientOptions = {},\n): ActionBuilder<Record<never, never>, undefined> {\n const report = options.onError ?? (() => GENERIC)\n\n function build<Ctx extends Record<string, unknown>, Input>(\n middlewares: ActionMiddleware<never, never>[],\n schema: StandardSchemaV1 | null,\n ): ActionBuilder<Ctx, Input> {\n return {\n use(middleware) {\n return build([...middlewares, middleware as never], schema) as never\n },\n input(next) {\n return build(middlewares, next) as never\n },\n handler(fn) {\n return async (raw?: unknown) => {\n try {\n const value = raw instanceof FormData ? fromFormData(raw) : raw\n\n if (schema) {\n const invalid = await validateWith(schema, value)\n\n if (invalid) return { validationErrors: invalid }\n }\n\n const parsed = schema\n ? ((await schema['~standard'].validate(value)).value as Input)\n : (value as Input)\n\n // Composed inside-out so the first `use` is the outermost — it\n // sees the others run, which is what makes timing and cleanup\n // possible rather than only checks.\n let ctx = {} as Ctx\n let index = 0\n\n const run = async (): Promise<unknown> => {\n const middleware = middlewares[index++]\n\n if (!middleware) return await fn({ input: parsed, ctx })\n\n let continued = false\n\n const result = await (middleware as unknown as ActionMiddleware<Ctx, Record<string, unknown>>)({\n ctx,\n next: (async (opts?: { ctx?: Record<string, unknown> }) => {\n continued = true\n ctx = { ...ctx, ...(opts?.ctx ?? {}) } as Ctx\n\n return { ctx, value: await run() }\n }) as never,\n })\n\n // Silence is not refusal. A middleware that neither called\n // next() nor threw has done nothing, and guessing which it meant\n // turns a forgotten `return` into a check that quietly passes.\n if (!continued) {\n throw new ActionMisuse(\n 'A middleware returned without calling next(). Call it to continue, or throw to refuse.',\n )\n }\n\n return (result as { value?: unknown })?.value\n }\n\n return { data: (await run()) as Awaited<ReturnType<typeof fn>> }\n } catch (error) {\n // Past onError deliberately — see ActionMisuse.\n if (error instanceof ActionMisuse) throw error\n\n if (isActionValidationError(error)) {\n return { validationErrors: error.errors }\n }\n\n return { serverError: report(error) }\n }\n }\n },\n }\n }\n\n return build([], null)\n}\n"]}
|
package/dist/build-rsc-vite.d.ts
CHANGED
|
@@ -36,4 +36,3 @@ export declare function isInstalled(root: string, name: string): boolean;
|
|
|
36
36
|
export declare function missingPeers(root: string): string[];
|
|
37
37
|
/** Shown when a project has no Vite config at all. */
|
|
38
38
|
export declare function missingConfigMessage(root: string): string;
|
|
39
|
-
//# sourceMappingURL=build-rsc-vite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|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AAA;IAEpF,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE;QACpC,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE;YACH,GAAG,OAAO,CAAC,GAAG;YACd,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY;YAC5C,wEAAwE;YACxE,wEAAwE;YACxE,eAAe,EAAE,UAAU,EAAE;SAC9B;QACD,KAAK,EAAE,SAAS;KACjB,CAAC,CAAA;IAEF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,GAAG,CAAC,mBAAmB,CAAC,CAAA;QACxB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAA;IAChC,CAAC;IAED,GAAG,CAAC,oBAAoB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;AACjD,CAAC;AAED,qEAAqE;AACrE,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC/F,IAAI,EAAE,CAAA;AACR,CAAC","sourcesContent":["// CLI behind `php artisan rsc:build`.\n//\n// The build itself lives in the Vite plugin (resources/vite.ts). This only\n// decides which config Vite runs: the app's own vite.rsc.config if it has one,\n// otherwise a minimal generated config that just uses the plugin. Either way\n// Vite runs that config directly — nothing is merged on top of it.\n\nimport { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\nimport { isBun } from './runtime.js'\n\nconst projectRoot = resolve(process.env.RSC_PROJECT_ROOT || process.cwd())\n// Mirrors the plugin's default so the completion message names the\n// directory the build actually wrote to.\nconst outDir = resolve(process.env.RSC_OUT_DIR || join(projectRoot, '.rsc'))\n\nfunction log(...args: unknown[]): void {\n console.error('[rsc-kit]', ...args)\n}\n\n/**\n * Config names, most specific first.\n *\n * A project's Vite config belongs at its root, so the ordinary case is the\n * root vite.config.* with rscKit() in its plugins. The vite.rsc.config.*\n * names exist for apps whose root config already drives a separate asset\n * pipeline — a Laravel app running laravel-vite-plugin, say, whose input,\n * outDir and manifest settings would otherwise apply to the RSC build too.\n */\nexport const USER_CONFIG_NAMES = [\n 'vite.rsc.config.ts',\n 'vite.rsc.config.mts',\n 'vite.rsc.config.js',\n 'vite.rsc.config.mjs',\n 'vite.config.ts',\n 'vite.config.mts',\n 'vite.config.js',\n 'vite.config.mjs',\n] as const\n\n/**\n * Find the Vite config for the RSC build.\n *\n * Nothing is generated: the build runs the project's own config, so what it\n * does is visible in the repo and anything the app wants in it — Tailwind, the\n * React Compiler, extra aliases — is declared there like any Vite project.\n */\nexport function findUserViteConfig(root: string): string | null {\n const explicit = process.env.RSC_VITE_CONFIG\n\n if (explicit) {\n const path = resolve(explicit)\n\n return existsSync(path) ? path : null\n }\n\n for (const name of USER_CONFIG_NAMES) {\n const path = join(root, name)\n if (existsSync(path)) return path\n }\n\n return null\n}\n\n/**\n * Packages the generated entries import directly, which the project must have.\n *\n * Without this the build fails deep inside the bundler — a missing\n * @vitejs/plugin-rsc surfaces as `Rolldown failed to resolve import\n * \"@vitejs/plugin-rsc/rsc\"` from a generated file the user never wrote.\n */\nexport const REQUIRED_PEERS = ['@vitejs/plugin-rsc', 'vite', 'react', 'react-dom'] as const\n\n/**\n * Whether a package is installed in the project's node_modules, or a parent's.\n *\n * A plain directory walk rather than require.resolve: Bun resolves packages\n * from its global cache when a project has no node_modules at all, so the\n * resolver reports success for something the build will not find.\n */\nexport function isInstalled(root: string, name: string): boolean {\n let dir = resolve(root)\n\n while (true) {\n if (existsSync(join(dir, 'node_modules', name, 'package.json'))) return true\n\n const parent = dirname(dir)\n if (parent === dir) return false\n dir = parent\n }\n}\n\n/** Required packages the project does not have, in declaration order. */\nexport function missingPeers(root: string): string[] {\n return REQUIRED_PEERS.filter((name) => !isInstalled(root, name))\n}\n\n/** Shown when a project has no Vite config at all. */\nexport function missingConfigMessage(root: string): string {\n return [\n `No Vite config found in ${root}.`,\n '',\n 'Create vite.config.ts:',\n '',\n \" import { rscKit } from '@rsc-kit/core/vite'\",\n \" import { defineConfig } from 'vite'\",\n '',\n ' export default defineConfig({ plugins: [rscKit()] })',\n '',\n 'If your root config already drives another asset pipeline (laravel-vite-plugin),',\n 'put the RSC build in vite.rsc.config.ts instead so the two do not share settings.',\n ].join('\\n')\n}\n\n/** This file's directory — import.meta.dir is Bun-only. */\nfunction packageDir(): string {\n return resolve(new URL('.', import.meta.url).pathname)\n}\n\nfunction main(): void {\n const missing = missingPeers(projectRoot)\n\n if (missing.length > 0) {\n log(`Missing required package(s): ${missing.join(', ')}`)\n log(`Install them in ${projectRoot}:`)\n log('')\n log(` npm install ${missing.join(' ')}`)\n log('')\n log('rscKit() composes @vitejs/plugin-rsc itself — it only has to be installed,')\n log('not added to your Vite config.')\n process.exit(1)\n }\n\n const configPath = findUserViteConfig(projectRoot)\n\n if (!configPath) {\n log(missingConfigMessage(projectRoot))\n process.exit(1)\n }\n\n log(`Using Vite config: ${configPath}`)\n\n const watch = process.env.RSC_WATCH === '1'\n\n // A host driving the build from outside prerenders on its own terms, and has\n // to: its pages call back into it, and that callback does not exist inside a\n // `vite build`. Prerendering here would render every such page into an error\n // and fail a build that is perfectly fine. `RSC_PRERENDER=1` opts back in for\n // a host whose pages need nothing from it.\n process.env.RSC_PRERENDER ??= '0'\n\n // A development build keeps React's development bundle, so a failure reads\n // as \"Maximum update depth exceeded\" rather than \"Minified React error #185\"\n // and a link to look it up. Implied by watching, and available on its own for\n // reproducing something a production build only reports by number.\n const dev = watch || process.env.RSC_DEV === '1'\n\n const viteArgs = ['build', '--config', configPath]\n if (watch) viteArgs.push('--watch')\n // Vite's build command is production mode unless told otherwise, whatever\n // NODE_ENV says — without this the dev build still resolves React's\n // production entry.\n if (dev) viteArgs.push('--mode', 'development')\n\n // Under Bun, `bun x --bun vite` keeps Vite itself on the Bun runtime. Under\n // Node there is no such wrapper, so invoke the locally installed binary.\n const [command, args] = isBun\n ? [process.execPath, ['x', '--bun', 'vite', ...viteArgs]]\n : [join(projectRoot, 'node_modules/.bin/vite'), viteArgs]\n\n log(`Running vite build${watch ? ' --watch' : ''}${dev ? ' (development)' : ''}...`)\n\n const proc = spawnSync(command, args, {\n cwd: projectRoot,\n env: {\n ...process.env,\n NODE_ENV: dev ? 'development' : 'production',\n // Vite stages the config through node_modules/.vite-temp, so the plugin\n // cannot locate this package from its own import.meta. Pass it through.\n RSC_PACKAGE_DIR: packageDir(),\n },\n stdio: 'inherit',\n })\n\n if (proc.status !== 0) {\n log('vite build failed')\n process.exit(proc.status ?? 1)\n }\n\n log(`Build complete → ${join(outDir, 'dist')}`)\n}\n\n// Run only when invoked directly, not when imported for its helpers.\nif (process.argv[1] && resolve(process.argv[1]) === resolve(new URL(import.meta.url).pathname)) {\n main()\n}\n"]}
|
package/dist/cache.d.ts
CHANGED
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,6EAA6E;AAC7E,EAAE;AACF,gFAAgF;AAChF,4EAA4E;AAC5E,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,8EAA8E;AAC9E,cAAc;AACd,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,0DAA0D;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAoB9C,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;AAErD,MAAM,OAAO,GAAG,UAA8C,CAAA;AAE9D,IAAI,KAAK,GAAyB,I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AAC,CAAA;AACH,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,SAAS;IACvB,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,SAAS,CAAA;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,GAAqB;IACtD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,KAAK,KAAK,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACzC,OAAO,CAAC,KAAK,CAAC,KAAK,QAA4B,CAAA;QACjD,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,CAAA;IACb,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,EAAG,CAAC,QAAQ,EAAE,CAAA;IAEpC,IAAI,QAAQ;QAAE,OAAO,MAAM,GAAG,EAAE,CAAA;IAEhC,OAAO,MAAM,KAAK,EAAG,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,GAAG,CAAC,CAAA;AAC3C,CAAC","sourcesContent":["// Asking the same question twice in one request.\n//\n// import { cache } from '@rsc-kit/core/cache'\n//\n// export const currentUser = cache(async () => db.user(await sessionId()))\n//\n// A guard checks who you are; the layout wants their name; the page wants their\n// permissions. Three calls, one request, one answer — without threading the\n// result through props that only exist to carry it.\n//\n// This is the same shape as React's cache(), and deliberately not React's: the\n// engine's own boundaries are not React's. A guard runs before any component\n// does, which is exactly where the duplication starts, and React has no scope\n// open there.\n//\n// Scoped to the request, so two in flight cannot see each other's answers. The\n// scope is opened by whoever owns the request — the host, the worker, or the\n// prerenderer — and everything below it shares one store.\n\nimport { resolveScope } from './revalidate.js'\n\n/** One request's memo table. */\ntype Store = Map<unknown, ArgNode>\n\n/**\n * Arguments keyed the way React keys them: a tree, one level per argument.\n *\n * Primitives compare by value and objects by identity, which falls out of\n * using a Map for the first and a WeakMap for the second. Serialising the\n * arguments instead would make `f({ a: 1 })` and `f({ a: 1 })` the same call —\n * which they are not, if the object is mutable.\n */\ninterface ArgNode {\n /** The answer for the argument list that ends here. */\n result?: { value: unknown }\n byValue?: Map<unknown, ArgNode>\n byIdentity?: WeakMap<object, ArgNode>\n}\n\nconst SCOPE = Symbol.for('@rsc-kit/core.cache-scope')\n\nconst globals = globalThis as Record<symbol | string, unknown>\n\nlet ready: Promise<void> | null = null\n\ninterface Scope {\n getStore(): Store | undefined\n run<T>(store: Store, fn: () => T): T\n}\n\nfunction scope(): Scope | null {\n return (globals[SCOPE] as Scope | undefined) ?? null\n}\n\nfunction isObject(value: unknown): value is object {\n return (typeof value === 'object' && value !== null) || typeof value === 'function'\n}\n\n/** Walk to the node for this argument list, creating it as we go. */\nfunction nodeFor(root: ArgNode, args: unknown[]): ArgNode {\n let node = root\n\n for (const arg of args) {\n if (isObject(arg)) {\n node.byIdentity ??= new WeakMap()\n\n let next = node.byIdentity.get(arg)\n\n if (!next) {\n next = {}\n node.byIdentity.set(arg, next)\n }\n\n node = next\n } else {\n node.byValue ??= new Map()\n\n let next = node.byValue.get(arg)\n\n if (!next) {\n next = {}\n node.byValue.set(arg, next)\n }\n\n node = next\n }\n }\n\n return node\n}\n\n/**\n * Memoise a function for the length of one request.\n *\n * The *promise* is cached, not the value, so callers that arrive while the\n * first is still in flight wait on it rather than starting a second. A\n * rejection is cached too: within one request the answer to a question does\n * not change because you asked again.\n *\n * Outside a request this calls straight through. Nothing is stored, nothing\n * leaks between requests, and shared code does not have to know which side of\n * the boundary it is on — the same reason revalidate() is a no-op outside an\n * action.\n */\nexport function cache<A extends unknown[], R>(fn: (...args: A) => R): (...args: A) => R {\n return (...args: A): R => {\n const store = scope()?.getStore()\n\n if (!store) return fn(...args)\n\n let root = store.get(fn)\n\n if (!root) {\n root = {}\n store.set(fn, root)\n }\n\n const node = nodeFor(root, args)\n\n if (node.result) return node.result.value as R\n\n const value = fn(...args)\n\n node.result = { value }\n\n return value\n }\n}\n\n/** Whether anything is listening, for code that wants to know. */\nexport function isCaching(): boolean {\n return scope()?.getStore() !== undefined\n}\n\n/**\n * Run one request with a memo table of its own.\n *\n * Opened by whoever owns the request. Nesting is harmless and does not create a\n * second table — an inner call reuses the one already open, so a host that\n * wraps and an engine that also wraps do not end up with two.\n */\nexport async function withCache<T>(run: () => Promise<T>): Promise<T> {\n if (!globals[SCOPE]) {\n ready ??= resolveScope().then((resolved) => {\n globals[SCOPE] ??= resolved as unknown as Scope\n })\n\n await ready\n }\n\n const existing = scope()!.getStore()\n\n if (existing) return await run()\n\n return await scope()!.run(new Map(), run)\n}\n"]}
|
package/dist/devServer.d.ts
CHANGED
|
@@ -15,4 +15,3 @@ export interface DevServer {
|
|
|
15
15
|
export declare function startDevServer(options: DevServerOptions): Promise<DevServer>;
|
|
16
16
|
/** Entry the dev server imports, matching where the plugin generates it. */
|
|
17
17
|
export declare function devEntryPath(outDir: string): string;
|
|
18
|
-
//# sourceMappingURL=devServer.d.ts.map
|
package/dist/devServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devServer.js","sourceRoot":"","sources":["../src/devServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;;GASG;AACH,KAAK,UAAU,0BAA0B;IACvC,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;IAE3C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;QACpD,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;QAC3C,OAAO,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAA0B,CAAA;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;QACzE,OAAO,CAAC,MAA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AK,EAAE,CAAA;QACpB,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAA;IACrF,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,EAAE,CAAC;QACxC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QACpB,MAAM,IAAI,KAAK,CACb,oDAAoD;YAClD,wEAAwE;YACxE,4DAA4D,CAC/D,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAA4B,CAAA;IAEnF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAA;AACjD,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,CAAA;AAC9C,CAAC","sourcesContent":["/**\n * Vite dev server mode for the RSC worker.\n *\n * In a build the worker imports a bundled entry. Here it imports the entry\n * through Vite's runnable `rsc` environment instead, so a source edit is\n * picked up without a rebuild. The module shape is identical either way —\n * installHostFn / handleRsc* / handleAction / resolveMetadata — so nothing\n * downstream of the load knows which mode it is in.\n *\n * The host keeps serving the page; the dev server only answers module\n * requests, which is the arrangement a Laravel developer already has with\n * Vite. See devUrls.ts for how the browser is pointed at it.\n */\nimport { createRequire } from 'node:module'\nimport { join } from 'node:path'\n\n/**\n * Vite resolved the way @vitejs/plugin-rsc resolves it.\n *\n * `isRunnableDevEnvironment` is an instanceof check, and plugin-rsc calls it\n * against its own copy. Two copies of Vite — this package's and the app's, the\n * ordinary case when the package is vendored rather than installed from npm —\n * make a perfectly runnable environment report false, and the error names the\n * environment rather than the duplication. A build never reaches that code\n * path, so the mismatch is invisible until dev mode.\n */\nasync function resolveViteAsPluginRscDoes(): Promise<typeof import('vite')> {\n const here = createRequire(import.meta.url)\n\n try {\n const pluginRsc = here.resolve('@vitejs/plugin-rsc')\n const fromPlugin = createRequire(pluginRsc)\n return (await import(fromPlugin.resolve('vite'))) as typeof import('vite')\n } catch {\n // Single copy, or a layout where plugin-rsc is not resolvable from here.\n return (await import('vite')) as typeof import('vite')\n }\n}\n\nexport interface DevServerOptions {\n /** Project root — where the app's vite config lives. */\n projectRoot: string\n /** Config file to run. The build resolves this the same way. */\n configFile: string\n /** Generated rsc entry to import through the runnable environment. */\n entry: string\n /** Port to listen on. */\n port: number\n}\n\nexport interface DevServer {\n handler: Record<string, unknown>\n close: () => Promise<void>\n}\n\nexport async function startDevServer(options: DevServerOptions): Promise<DevServer> {\n const vite = await resolveViteAsPluginRscDoes()\n\n const server = await vite.createServer({\n root: options.projectRoot,\n configFile: options.configFile,\n server: {\n port: options.port,\n strictPort: true,\n // The host serves the page from its own origin, so every module request\n // is cross-origin. Dev only.\n cors: true,\n },\n })\n\n await server.listen()\n\n const env = server.environments.rsc\n\n if (!env) {\n await server.close()\n throw new Error(\"[rsc-kit] no 'rsc' environment — is rscKit() in the vite config?\")\n }\n\n if (!vite.isRunnableDevEnvironment(env)) {\n await server.close()\n throw new Error(\n \"[rsc-kit] the 'rsc' environment is not runnable.\\n\" +\n 'This usually means two copies of Vite are installed and the plugin is ' +\n 'checking against a different one than created this server.',\n )\n }\n\n const handler = (await env.runner.import(options.entry)) as Record<string, unknown>\n\n return { handler, close: () => server.close() }\n}\n\n/** Entry the dev server imports, matching where the plugin generates it. */\nexport function devEntryPath(outDir: string): string {\n return join(outDir, '.gen', 'entry.rsc.tsx')\n}\n"]}
|
package/dist/devUrls.d.ts
CHANGED
|
@@ -8,4 +8,3 @@ export declare function rewriteViteDevUrls(html: string, origin: string): string
|
|
|
8
8
|
* globals, and a foreign TransformStream is rejected by a native stream.
|
|
9
9
|
*/
|
|
10
10
|
export declare function rewriteViteDevUrlStream(stream: ReadableStream, origin: string): ReadableStream;
|
|
11
|
-
//# sourceMappingUR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;gBACR,CAAC;gBAED,MAAM,IAAI,GAAG,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;gBAC5D,kEAAkE;gBAClE,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAA;gBAC7C,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBAExB,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;oBACb,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;oBACnF,OAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,CAAC,MAAM;YACX,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC9B,CAAC;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["/**\n * Dev-only rewriting of Vite's internal URLs onto the dev server's origin.\n *\n * In dev, @vitejs/plugin-rsc emits its bootstrap and CSS links root-relative —\n * `/@id/...`, `/@fs/...`. It builds them as `config.base + url`, and Vite\n * collapses an absolute `base` to `/` during dev, so neither `base` nor\n * `server.origin` (the mechanism laravel-vite-plugin relies on) can move them.\n *\n * The host serves the page, so root-relative sends the browser to PHP for\n * modules only Vite can answer. Rewriting them here keeps the app on its\n * normal development URL while assets come from the dev server, which is the\n * arrangement Laravel developers already expect from Vite.\n *\n * Only these four prefixes are rewritten. A blanket `/@` rule would also catch\n * ordinary page text, and this runs over rendered HTML.\n */\nconst VITE_PREFIXES = ['/@id/', '/@fs/', '/@vite/', '/@react-refresh']\n\n/** Longest tail that could hide a split prefix across a chunk boundary. */\nconst CARRY = Math.max(...VITE_PREFIXES.map((p) => p.length)) + 1\n\nexport function rewriteViteDevUrls(html: string, origin: string): string {\n let out = html\n for (const prefix of VITE_PREFIXES) {\n // Anchored on the opening quote so only URL positions match, never text\n // that happens to contain the same characters.\n out = out.split('\"' + prefix).join('\"' + origin + prefix)\n out = out.split(\"'\" + prefix).join(\"'\" + origin + prefix)\n }\n return out\n}\n\n/**\n * The same rewrite over a stream. A URL can straddle a chunk boundary, so the\n * last few bytes are held back rather than emitted, and flushed at the end.\n *\n * Built from a reader rather than `pipeThrough(new TransformStream(...))`: the\n * test suites share a process with happy-dom, which replaces the stream\n * globals, and a foreign TransformStream is rejected by a native stream.\n */\nexport function rewriteViteDevUrlStream(stream: ReadableStream, origin: string): ReadableStream {\n const decoder = new TextDecoder()\n const encoder = new TextEncoder()\n const reader = stream.getReader()\n let carry = ''\n\n return new ReadableStream({\n async pull(controller) {\n while (true) {\n const { done, value } = await reader.read()\n\n if (done) {\n if (carry) controller.enqueue(encoder.encode(rewriteViteDevUrls(carry, origin)))\n controller.close()\n return\n }\n\n const text = carry + decoder.decode(value, { stream: true })\n // Hold back a possible partial prefix; emit everything before it.\n const keep = Math.max(0, text.length - CARRY)\n carry = text.slice(keep)\n\n if (keep > 0) {\n controller.enqueue(encoder.encode(rewriteViteDevUrls(text.slice(0, keep), origin)))\n return\n }\n }\n },\n cancel(reason) {\n return reader.cancel(reason)\n },\n })\n}\n"]}
|
package/dist/embed.d.ts
CHANGED
package/dist/embed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,gFAAgF;AAChF,oEAAoE;AACpE,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,iBAAiB;AACjB,EAAE;AACF,2DAA2D;AAC3D,kDAAkD;AAClD,EAAE;AACF,4EAA4E;AAC5E,0EAA0E;AAC1E,oDAAoD;AAEpD,OAAO,EAAE,UAA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AAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG;;;;EAIf,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;;;EAGlB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;;;;EAIvB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCvB,CAAA;IAEC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC7D,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAA;IAE3C,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,MAAM,EAAE,CAAA;AACrE,CAAC","sourcesContent":["// Putting the build output inside the binary.\n//\n// `bun build --compile` bundles the JavaScript it can see and nothing else, so\n// a compiled server renders pages and then 404s every stylesheet and every\n// client chunk — the page arrives, unstyled, and never hydrates. Nothing warns:\n// the server starts, the routes answer, and only the browser knows.\n//\n// Bun embeds a file when something imports it with `{ type: 'file' }`, so this\n// writes a module that imports each one and hands back the readers the host\n// already takes:\n//\n// bun run embed # after vite build && prerender\n// bun build --compile server.ts --outfile app\n//\n// The generated module is the only thing that has to exist at compile time.\n// After that the binary carries the assets, the prerendered pages and the\n// engine, and runs anywhere with nothing beside it.\n\nimport { existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from 'node:fs'\nimport { dirname, join, relative, resolve } from 'node:path'\n\nexport interface EmbedOptions {\n /** The browser build — what `assetsDir` pointed at. */\n assets?: string\n /** What the prerenderer wrote. */\n prerendered?: string\n /** Where to write the generated module. */\n out: string\n /** The url prefix assets are served under. */\n prefix?: string\n}\n\n/** Every file under a directory, as paths relative to it. */\nfunction walk(dir: string, base = dir): string[] {\n if (!existsSync(dir)) return []\n\n const found: string[] = []\n\n for (const entry of readdirSync(dir)) {\n const abs = join(dir, entry)\n\n if (statSync(abs).isDirectory()) {\n found.push(...walk(abs, base))\n } else {\n found.push(relative(base, abs).replace(/\\\\/g, '/'))\n }\n }\n\n return found\n}\n\n/**\n * Write the module that embeds the build.\n *\n * Returns what it found, so a build script can say so rather than producing a\n * binary that is quietly missing half of itself.\n */\nexport function writeEmbedModule(options: EmbedOptions): { assets: number; prerendered: number } {\n const prefix = options.prefix ?? '/assets/'\n const assetsDir = options.assets ? resolve(options.assets) : null\n const prerenderedDir = options.prerendered ? resolve(options.prerendered) : null\n\n const assetFiles = assetsDir ? walk(assetsDir) : []\n const pageFiles = prerenderedDir ? walk(prerenderedDir) : []\n\n const imports: string[] = []\n const assetEntries: string[] = []\n const pageEntries: string[] = []\n\n const outDir = dirname(resolve(options.out))\n // Relative to the generated module. An absolute path is only true on the\n // machine that wrote it, and a build that moves — a container, CI — would\n // compile a binary whose every asset points at somewhere that does not exist.\n const from = (abs: string) => {\n const rel = relative(outDir, abs).replace(/\\\\/g, '/')\n\n return rel.startsWith('.') ? rel : './' + rel\n }\n\n // Sorted, so the same input produces the same module and the same binary.\n assetFiles.sort().forEach((name, i) => {\n imports.push(`import a${i} from ${JSON.stringify(from(join(assetsDir!, name)))} with { type: 'file' }`)\n assetEntries.push(` ${JSON.stringify(prefix + name)}: a${i},`)\n })\n\n pageFiles.sort().forEach((name, i) => {\n imports.push(`import p${i} from ${JSON.stringify(from(join(prerenderedDir!, name)))} with { type: 'file' }`)\n pageEntries.push(` ${JSON.stringify(name)}: p${i},`)\n })\n\n const source = `// GENERATED — do not edit. Written by writeEmbedModule().\n//\n// Each import is what makes the file part of the binary. A path read at\n// runtime would not be: bun build --compile follows imports, not strings.\n${imports.join('\\n')}\n\nexport const assetPaths: Record<string, string> = {\n${assetEntries.join('\\n')}\n}\n\nexport const pagePaths: Record<string, string> = {\n${pageEntries.join('\\n')}\n}\n\nexport const TYPES: Record<string, string> = {\n js: 'text/javascript; charset=utf-8',\n css: 'text/css; charset=utf-8',\n map: 'application/json; charset=utf-8',\n svg: 'image/svg+xml',\n woff2: 'font/woff2',\n}\n\n/** The \\`assets\\` reader, served from inside the binary. */\nexport async function assets(pathname: string): Promise<Response | null> {\n const path = assetPaths[pathname]\n\n if (!path) return null\n\n // .stream() rather than the file itself: a Response implementation that does\n // not know what a BunFile is turns the body into the string \"[object Blob]\",\n // which serves a stylesheet that parses as nothing and reports 200.\n return new Response(Bun.file(path).stream(), {\n headers: {\n 'Content-Type': TYPES[pathname.split('.').pop() ?? ''] ?? 'application/octet-stream',\n // Content-hashed by the build, so this is safe.\n 'Cache-Control': 'public, max-age=31536000, immutable',\n },\n })\n}\n\n/** The \\`prerendered\\` reader, served from inside the binary. */\nexport async function prerendered(name: string): Promise<string | null> {\n const path = pagePaths[name]\n\n return path ? await Bun.file(path).text() : null\n}\n`\n\n mkdirSync(dirname(resolve(options.out)), { recursive: true })\n writeFileSync(resolve(options.out), source)\n\n return { assets: assetFiles.length, prerendered: pageFiles.length }\n}\n"]}
|
package/dist/errors.d.ts
CHANGED
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9B,MAAM,CAA2B;IAEjD,YAAY,OAAe,EAAE,MAAgC;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAO,GAAW,kBAAkB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CA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CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF","sourcesContent":["/**\n * The worker's own error types.\n *\n * A separate set from `src/js/errors.ts` on purpose: these are thrown inside\n * the worker and turned into HTTP statuses, so they never reach the browser as\n * objects — the client reconstructs its own from the response. The public\n * `@rsc-kit/core/errors` specifier is the client's module, because that is\n * the one an `instanceof` in a component has to match.\n */\nexport class ServerValidationError extends Error {\n public readonly errors: Record<string, string[]>;\n\n constructor(message: string, errors: Record<string, string[]>) {\n super(message);\n this.name = \"ServerValidationError\";\n this.errors = errors;\n }\n}\n\nexport class ServerAuthenticationError extends Error {\n constructor(message: string = \"Unauthenticated.\") {\n super(message);\n this.name = \"ServerAuthenticationError\";\n }\n}\n\nexport class ServerAuthorizationError extends Error {\n constructor(message: string = \"This action is unauthorized.\") {\n super(message);\n this.name = \"ServerAuthorizationError\";\n }\n}\n\nexport class ServerRedirectError extends Error {\n public readonly location: string;\n\n constructor(location: string) {\n super(`Redirect to ${location}`);\n this.name = \"ServerRedirectError\";\n this.location = location;\n }\n}\n"]}
|
package/dist/export.d.ts
CHANGED
package/dist/export.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,wBAAwB;AACxB,EAAE;AACF,wEAAwE;AACxE,4EAA4E;AAC5E,+BAA+B;AAC/B,EAAE;AACF,gCAAgC;AAChC,kBAAkB;AAClB,oCAAoC;AACpC,uBAAuB;AACvB,iDAAiD;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAmCxC,MAAM,OAAO,aAAc,SAAQ,KAAK;IACV,OAAO;IAAnC,YAA4B,OAA0B;QACpD,KAAK,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AkB,OAAO,KAAK,OAAO,sBAAsB,CAC9D,CAAA;YAED,KAAK,EAAE,CAAA;YACP,SAAQ;QACV,CAAC;QAED,MAAM,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,GAAG,GAAG,YAAY,CAAC,CAAA;QAC7C,MAAM,IAAI,CAAC,GAAG,GAAG,SAAS,EAAE,GAAG,GAAG,GAAG,WAAW,EAAE,CAAC,CAAA;QAEnD,oEAAoE;QACpE,qEAAqE;QACrE,uEAAuE;QACvE,yEAAyE;QACzE,uBAAuB;QACvB,KAAK,IAAI,KAAK,GAAG,CAAC,GAAI,KAAK,EAAE,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,GAAG,OAAO,KAAK,SAAS,CAAC,CAAA;YAEvD,IAAI,OAAO,KAAK,IAAI;gBAAE,MAAK;YAE3B,MAAM,KAAK,CAAC,GAAG,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,KAAK,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QACxF,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;IAED,MAAM,MAAM,EAAE,EAAE,CAAA;IAEhB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AAC3B,CAAC","sourcesContent":["// Writing the whole site out as files, for a host that only serves files.\n//\n// Everything a server was doing has to have happened already, which makes the\n// refusals the important part. A site exported with a route missing, or with a\n// shell nothing will ever fill, does not fail at build time and does not fail\n// on load — it serves a page that sits there, or a 404 for a url that worked\n// yesterday. So anything that is not fully static stops the export and says\n// which routes and why.\n//\n// Layout is a directory per route with an index inside it, so urls stay\n// extensionless, and the Flight payload sits beside it under a filename the\n// client was built to ask for.\n//\n// out/index.html /\n// out/index.rsc\n// out/docs/index.html /docs\n// out/docs/index.rsc\n// out/assets/… the browser bundle\n\nimport { pathKey } from './prerender.js'\nimport type { PrerenderResult } from './prerender.js'\nimport type { RouteManifest } from './manifest.js'\n\nexport interface ExportOptions {\n /** What prerender() decided, so this can refuse what it cannot serve. */\n results: PrerenderResult[]\n /** Reads what prerender() wrote. `prerenderedFrom` in `@rsc-kit/core/files`. */\n read: (name: string) => Promise<string | null> | string | null\n /**\n * Writes the site, keyed by its url path — `docs/index.html`, not an\n * absolute one. `writeTo` in `@rsc-kit/core/files` puts those under a\n * directory; a deploy that uploads straight to a bucket writes keys.\n */\n write: (path: string, contents: string) => Promise<void> | void\n /** The route table, for what the build decided about payload urls. */\n manifest: RouteManifest\n /**\n * Brings the browser bundle along, if this export has to carry it.\n *\n * A callback rather than a directory pair: copying a tree of built files is\n * a filesystem operation by nature, and a deploy that uploads them has its\n * own tooling for it. `copyAssets` in `@rsc-kit/core/files` does the local one.\n */\n assets?: () => Promise<void> | void\n /**\n * Export anyway, leaving out whatever is not static.\n *\n * The result is a site with holes in it, which is sometimes what you want\n * while moving an app towards being exportable. It is never the default,\n * because the holes are 404s at urls that worked before.\n */\n force?: boolean\n}\n\nexport class NotExportable extends Error {\n constructor(public readonly refused: PrerenderResult[]) {\n super(\n 'This site cannot be exported as it is. A static host runs nothing, so these routes have ' +\n 'no way to finish rendering:\\n\\n' +\n refused.map((r) => ` ${r.url} — ${r.reason ?? describe(r.type)}`).join('\\n') +\n '\\n\\nMake them static, or pass force to export the rest and leave these out.',\n )\n this.name = 'NotExportable'\n }\n}\n\nfunction describe(type: PrerenderResult['type']): string {\n if (type === 'shell') {\n // Worth spelling out: a shell looks like a working page in the build\n // output, and on a static host it is a page that loads and stays empty.\n return 'only a shell was stored, and nothing on a static host will fill it'\n }\n\n return 'failed to render'\n}\n\nexport async function exportSite(options: ExportOptions): Promise<{ pages: number; refused: PrerenderResult[] }> {\n const { results, read, write, manifest, assets, force = false } = options\n\n // A guarded route is frozen on purpose — the content is the same for\n // everyone allowed to see it — but the guard runs when the page is served,\n // and a static host serves without running anything. Exporting one publishes\n // the page to whoever asks, which is the opposite of what the guard said.\n const guarded = new Set(\n (manifest.routes as { component: string; middleware?: string[] }[])\n .filter((route) => route.middleware?.length)\n .map((route) => route.component),\n )\n\n const refused = results\n .filter((r) => r.type !== 'frozen' || guarded.has(r.component))\n .map((r) =>\n r.type === 'frozen' && guarded.has(r.component)\n ? { ...r, reason: 'guarded, and a static host has nothing to run the guard' }\n : r,\n )\n\n if (refused.length > 0 && !force) throw new NotExportable(refused)\n\n // The client has to ask for payloads by url, because a static host cannot\n // read the header that would otherwise select one. That is decided by the\n // build, so a site exported from a server build ships a client asking the\n // wrong way — every navigation silently falls back to a full page load.\n const payloadName = manifest.build?.payloadName\n\n if (!payloadName) {\n throw new Error(\n 'This build was made for a server, so its client asks for payloads with a header rather ' +\n \"than by url. Build with output: 'export' before exporting.\",\n )\n }\n\n const copy = async (name: string, into: string) => {\n const contents = await read(name)\n\n // Missing where the results said it would be: the prerender output and the\n // results it returned disagree, which is not something to paper over with\n // a half-written site.\n if (contents === null) {\n throw new Error(`Nothing to export at ${name}. Prerender and export must read the same output.`)\n }\n\n await write(into, contents)\n }\n\n let pages = 0\n\n for (const result of results) {\n if (result.type !== 'frozen') continue\n\n const key = pathKey(result.url)\n // The root is the out dir itself; everything else is a directory with an\n // index, so /docs stays /docs rather than becoming /docs.html.\n const dir = key === 'index' ? '' : `${key}/`\n\n // A route that only redirects is frozen as its answer rather than as a\n // page, so there is no .html to copy — and reaching for one threw, which\n // is why exporting an app with a redirect in it failed outright.\n //\n // A meta refresh because it is the one redirect every static host performs\n // without being configured; `_redirects` and its equivalents are per-host\n // files this has no business writing. The canonical link is what keeps a\n // crawler pointed at the destination rather than at this page.\n const redirect = await read(`${key}.redirect.json`)\n\n if (redirect !== null) {\n const { location } = JSON.parse(redirect) as { status: number; location: string }\n const escaped = location.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<')\n\n await write(\n `${dir}index.html`,\n `<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\">` +\n `<meta http-equiv=\"refresh\" content=\"0; url=${escaped}\">` +\n `<link rel=\"canonical\" href=\"${escaped}\">` +\n `<title>Redirecting</title></head>` +\n `<body><a href=\"${escaped}\">${escaped}</a></body></html>\\n`,\n )\n\n pages++\n continue\n }\n\n await copy(`${key}.html`, `${dir}index.html`)\n await copy(`${key}.flight`, `${dir}${payloadName}`)\n\n // One file per depth a client might already hold, addressed by name\n // because a file server cannot vary on a header. Without these every\n // navigation is a whole document, which replaces the root and unmounts\n // the pages retained behind it — so going back does not restore the form\n // you were filling in.\n for (let depth = 1; ; depth++) {\n const variant = await read(`${key}.seg${depth}.flight`)\n\n if (variant === null) break\n\n await write(`${dir}${payloadName.replace(/^index\\./, `index.seg${depth}.`)}`, variant)\n }\n\n pages++\n }\n\n await assets?.()\n\n return { pages, refused }\n}\n\n\n"]}
|
package/dist/files.d.ts
CHANGED
|
@@ -43,4 +43,3 @@ export declare function writeTo(dir: string): ((name: string, contents: string)
|
|
|
43
43
|
* has its own way to do that, and passes its own callback instead.
|
|
44
44
|
*/
|
|
45
45
|
export declare function copyAssets(from: string, to: string, url?: string): () => Promise<void>;
|
|
46
|
-
//# sourceMappingURL=files.d.ts.map
|
package/dist/files.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,4CAA4C;AAE5C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC;;;;;;;;;;;;;OAaG;IACH,IAAI,OAAO,GAAgC,IAAI,CAAA;IAE/C,MAAM,OAAO,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["// Reading built output off a disk.\n//\n// Kept apart from the host on purpose: it is the only part of serving an RSC\n// app that assumes a filesystem, and plenty of places to run one do not have\n// one. Nothing in `@rsc-kit/core/host` imports this module, so a bundle for a\n// host without a filesystem carries no reference to `node:fs` at all.\n//\n// Assets are not here any more — Nitro publishes and serves those. What is\n// left is the prerendered output: written by the build, read by the server it\n// generates, and copied by a static export.\n\nimport { cp, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\n/**\n * Read what the prerenderer wrote, from a directory.\n *\n * Missing is an answer, not an error: a partial prerender is a valid state,\n * and anything not found here is rendered on demand instead.\n */\nexport function prerenderedFrom(dir: string) {\n /**\n * What is on disk, listed once.\n *\n * A miss used to be a thrown ENOENT, and misses are the common case: the\n * host asks for `{url}.html`, then `{url}.ppr.html`, then the route's\n * pattern — so every request to a page served by a pattern shell threw and\n * caught two exceptions before finding anything. Measured at 3,000 req/s\n * against 28,000 for the same page read from memory.\n *\n * Only existence is cached, never contents: a file that is there is still\n * read on every request, so a redeploy that rewrites one is picked up. What\n * a running server will not notice is a page appearing that was not there at\n * boot — which is a build artefact, and the build has finished.\n */\n let present: Promise<Set<string>> | null = null\n\n const listing = async (): Promise<Set<string>> => {\n present ??= readdir(dir, { recursive: true })\n .then((names) => new Set(names.map((n) => String(n).replace(/\\\\/g, '/'))))\n // An absent directory is an empty one: a partial prerender is a valid\n // state, and everything falls through to being rendered.\n .catch(() => new Set<string>())\n\n return await present\n }\n\n return async (name: string): Promise<string | null> => {\n if (name.includes('..')) return null\n\n if (!(await listing()).has(name)) return null\n\n try {\n return await readFile(join(dir, name), 'utf-8')\n } catch {\n return null\n }\n }\n}\n\n/**\n * The same reader, for a directory whose absolute path is not known until the\n * server runs.\n *\n * Nitro bundles the generated entry to a different depth depending on the\n * preset — `.output/server/index.mjs` for one, `.output/server/_ssr/rsc.mjs`\n * for another — so neither a fixed relative path nor a path baked in at build\n * time survives: the first is wrong for half the presets, and the second stops\n * being true the moment `.output/` is copied to the machine that serves it.\n *\n * So the caller passes its own `import.meta.url` and the directory is found by\n * walking up from it. A few levels, bounded, and resolved once.\n *\n * prerendered: prerenderedBeside(import.meta.url, 'rsc-static')\n *\n * Not finding it is a valid state and not an error: nothing was frozen, or\n * this host has no filesystem to have frozen it on. Every page renders live,\n * which is what happens today everywhere.\n */\nexport function prerenderedBeside(moduleUrl: string, dirName: string, levels = 4) {\n let reader: Promise<(name: string) => Promise<string | null>> | null = null\n\n const resolveDir = async (): Promise<(name: string) => Promise<string | null>> => {\n const { fileURLToPath } = await import('node:url')\n\n let dir: string\n try {\n dir = dirname(fileURLToPath(moduleUrl))\n } catch {\n return async () => null\n }\n\n for (let i = 0; i <= levels; i++) {\n const candidate = join(dir, ...Array(i).fill('..'), dirName)\n\n try {\n await readdir(candidate)\n\n return prerenderedFrom(candidate)\n } catch {\n // Not at this level. Keep walking.\n }\n }\n\n return async () => null\n }\n\n return async (name: string): Promise<string | null> => {\n reader ??= resolveDir()\n\n return await (await reader)(name)\n }\n}\n\nfunction contentTypeOf(pathname: string): string {\n if (pathname.endsWith('.js')) return 'text/javascript; charset=utf-8'\n if (pathname.endsWith('.css')) return 'text/css; charset=utf-8'\n if (pathname.endsWith('.map')) return 'application/json; charset=utf-8'\n if (pathname.endsWith('.svg')) return 'image/svg+xml'\n if (pathname.endsWith('.woff2')) return 'font/woff2'\n\n return 'application/octet-stream'\n}\n\n/**\n * Write build output into a directory.\n *\n * The sink `prerender` and `exportSite` take. Names are relative and may\n * contain directories — `docs/index.html` — so each one's parent is created\n * as it goes.\n */\nexport function writeTo(dir: string): ((name: string, contents: string) => Promise<void>) & { dir: string } {\n const write = async (name: string, contents: string): Promise<void> => {\n const path = join(dir, name)\n\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, contents)\n }\n\n // Where it wrote, for a caller that has to read it back. The embeddable\n // module has to list these files, and being told the directory a second time\n // is a second place for it to be wrong.\n return Object.assign(write, { dir })\n}\n\n/**\n * Copy the built browser bundle into an exported site.\n *\n * Separate from the export itself because copying a tree of files is a\n * filesystem operation by nature — a deploy that uploads them to a bucket\n * has its own way to do that, and passes its own callback instead.\n */\nexport function copyAssets(from: string, to: string, url = '/assets/') {\n return async (): Promise<void> => {\n const at = url.replace(/^\\/+|\\/+$/g, '')\n\n if (at === '') return\n\n const target = join(to, at)\n\n await mkdir(dirname(target), { recursive: true })\n await cp(from, target, { recursive: true })\n }\n}\n"]}
|
package/dist/headers.d.ts
CHANGED
package/dist/headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../src/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,0EAA0E;AAC1E,sEAAsE;AACtE,wEAAwE;AACxE,2EAA2E;AAC3E,gCAAgC;AAChC,EAAE;AACF,gFAAgF;AAEhF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB;;;OAGG;IACH,GAAG,EAAE,OAAO;IAEZ,iFAAiF;IACjF,QAAQ,EAAE,gBAAgB;IAE1B,kEAAkE;IAClE,YAAY,EAAE,qBAAqB;IAEnC,wCAAwC;IACxC,OAAO,EAAE,eAAe;IAExB,gFAAgF;IAChF,OAAO,EAAE,eAAe;IAExB,uDAAuD;IACvD,SAAS,EAAE,iBAAiB;IAE5B,gDAAgD;IAChD,OAAO,EAAE,eAAe;IAExB,uEAAuE;IACvE,UAAU,EAAE,kBAAkB;IAE9B,0CAA0C;IAC1C,MAAM,EAAE,cAAc;IAEtB;;;;;;;OAOG;IACH,QAAQ,EAAE,gBAAgB;IAE1B;;;;;;OAMG;IACH,WAAW,EAAE,oBAAoB;IAEjC;;;;;OAKG;IACH,UAAU,EAAE,cAAc;IAC1B,mEAAmE;IACnE,YAAY,EAAE,iBAAiB;IAC/B,uDAAuD;IACvD,aAAa,EAAE,kBAAkB;CACzB,CAAA;AAEV,sBAAsB;AACtB,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAA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,kBAAkB;CACzB,CAAA;AAEV,sBAAsB;AACtB,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAA;AAE5D,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,0BAA0B,CAAA;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,CAAC,GAAG;IACV,MAAM,CAAC,QAAQ;IACf,MAAM,CAAC,UAAU;IACjB,MAAM,CAAC,SAAS;IAChB,MAAM,CAAC,OAAO;CACf,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAEZ;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAA;AAE7C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,oCAAoC,CAAA","sourcesContent":["// The wire protocol, as names rather than string literals.\n//\n// A host writing these out by hand is how they drift. Two of them are not\n// negotiable at all — the client sends them or asks for them at fixed\n// addresses, and a host that spells one differently fails silently: the\n// request falls through, the decoder never runs, and a button does nothing\n// with no error on either side.\n//\n// PROTOCOL.md describes what each one means. This is the same list, importable.\n\nexport const HEADER = {\n /**\n * Present on a request for a Flight payload rather than the document. One\n * url serves both, which is why every answer must Vary on it.\n */\n rsc: 'X-RSC',\n\n /** The layout chain the client has mounted, outermost first, comma-separated. */\n segments: 'X-RSC-Segments',\n\n /** The boundary the answer replaces. 0 means a whole document. */\n segmentDepth: 'X-RSC-Segment-Depth',\n\n /** The chain to send back next time. */\n layouts: 'X-RSC-Layouts',\n\n /** Identifies the build, so a client can notice it is talking to an old one. */\n version: 'X-RSC-Version',\n\n /** The slot an intercepted navigation is targeting. */\n intercept: 'X-RSC-Intercept',\n\n /** Where the navigation or action came from. */\n referer: 'X-RSC-Referer',\n\n /** One named region of the current page to render and return alone. */\n revalidate: 'X-RSC-Revalidate',\n\n /** The server reference being invoked. */\n action: 'X-RSC-Action',\n\n /**\n * Go here instead.\n *\n * Used for a redirect the client has to perform itself: a failed action, and\n * a navigation whose render redirected. Never a 3xx for those — `fetch`\n * follows one transparently, so the client would get the destination's HTML\n * where it expected a Flight payload and decode it as one.\n */\n redirect: 'X-RSC-Redirect',\n\n /**\n * The body's real type.\n *\n * The body itself goes out as application/octet-stream so a host that parses\n * multipart cannot consume it before the action does — reading Content-Type\n * instead leaves an upload undecodable.\n */\n contentType: 'X-RSC-Content-Type',\n\n /**\n * Where the browser posts server actions.\n *\n * Not a convention this can choose: the client runtime posts here\n * unconditionally.\n */\n actionPath: '/_rsc/action',\n /** Build-time shell for a PPR route, for an edge cache to hold. */\n pprShellPath: '/_rsc/ppr-shell',\n /** Finish a shell an edge cache is already serving. */\n pprResumePath: '/_rsc/ppr-resume',\n} as const\n\n/** Flight payload. */\nexport const FLIGHT_TYPE = 'text/x-component; charset=utf-8'\n\n/** A rendered document. */\nexport const HTML_TYPE = 'text/html; charset=utf-8'\n\n/**\n * Every request header that changes what a response body contains.\n *\n * One url answers with a whole document, a partial payload, a named region or\n * an interceptor depending on these — so a cache keyed on the url alone, or on\n * `X-RSC` alone, will hand one client another's answer. They are materially\n * different bodies, not variations in presentation.\n */\nexport const VARY_ON_RSC = [\n HEADER.rsc,\n HEADER.segments,\n HEADER.revalidate,\n HEADER.intercept,\n HEADER.referer,\n].join(', ')\n\n/**\n * What a response says about being stored, when it must not be.\n *\n * `Vary` alone is not enough on the platform this targets. Cloudflare ignores\n * `Vary` for everything except `Accept-Encoding`, and this package ships a\n * Workers story as a headline feature — so one url answering with a document,\n * a Flight payload, a segment and an interceptor, keyed only on the url, hands\n * one visitor another's body. Anything narrowed by a request header, and\n * anything behind a guard, says outright that it is not to be stored.\n */\nexport const PER_CLIENT = 'private, no-store'\n\n/**\n * And what a frozen, unguarded page says.\n *\n * Explicit rather than absent: with no directive at all, whether an\n * intermediary stores it comes down to that intermediary's heuristics, which\n * is not a decision this package should be leaving to chance in either\n * direction.\n */\nexport const REVALIDATE = 'public, max-age=0, must-revalidate'\n"]}
|
package/dist/host.d.ts
CHANGED
|
@@ -128,4 +128,3 @@ export interface RscHostOptions {
|
|
|
128
128
|
*/
|
|
129
129
|
export declare function actionOriginAllowed(request: Request, url: URL): boolean;
|
|
130
130
|
export declare function createRscHandler(options: RscHostOptions): (request: Request) => Promise<Response | null>;
|
|
131
|
-
//# sourceMappingURL=host.d.ts.map
|