@rsc-kit/core 0.42.1 → 0.43.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"typegen.js","sourceRoot":"","sources":["../src/typegen.ts"],"names":[],"mappings":";AACA,gEAAgE;AAChE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,sEAAsE;AACtE,2EAA2E;AAC3E,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQzC,KAAK,UAAU,OAAO,CAAC,MAAe;IACpC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC;IAE3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEhF,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAmB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,KAAK,GAAG,KAAK;IACvD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,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AC0B,QAAQ;uDACrB,QAAQ;eAChD,QAAQ;WACZ,IAAI;uBACQ,SAAS;;;CAG/B,CAAC;IAEA,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IAE9C,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE1B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["#!/usr/bin/env node\n// rsc-kit-typegen: write the route types without starting Vite.\n//\n// The types - every url the app has, for <Link href> and redirect() - are\n// written when the dev server or a build starts, and again when a dev server\n// sees a route added. A typecheck run with neither, by an agent or in CI,\n// read the types from the last start: a route added since failed with\n// '\"/admin\"' is not assignable to type Route until something started Vite.\n//\n// The app's own vite.config is loaded, through the app's own Vite, so the\n// plugin's options - sourceDir, outDir, a host's route file - are the ones it\n// builds with. Only the plugin's config step runs, which is what writes them.\n\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { join, relative } from \"node:path\";\nimport { cwd, exit, stderr, stdout } from \"node:process\";\nimport { pathToFileURL } from \"node:url\";\n\ninterface PluginLike {\n name?: string;\n config?: (config: object, env: { command: string; mode: string }) => unknown;\n api?: { generatedFiles?: () => string[]; info?: () => Record<string, unknown>; sourceDir?: () => string };\n}\n\nasync function flatten(option: unknown): Promise<PluginLike[]> {\n const value = await option;\n\n if (Array.isArray(value)) return (await Promise.all(value.map(flatten))).flat();\n\n return value && typeof value === \"object\" ? [value as PluginLike] : [];\n}\n\n/**\n * Write the types; or, with `check`, say which committed generated files are\n * not what the backend and the route tree produce now, and change nothing.\n *\n * For CI: `rsc-kit-typegen --check` fails when rsc-host.json or the types were\n * committed and the backend has moved on since. Only files that were already\n * there are compared - one that is not committed is written fresh by every\n * build and cannot be stale - and every one is put back as it was.\n */\nexport async function typegen(root = cwd(), check = false): Promise<string[]> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n\n // As a build would: a manifest command that fails is a failure, not a\n // warning, when the question is whether what is committed is current.\n const env = check ? { command: \"build\", mode: \"production\" } : { command: \"serve\", mode: \"development\" };\n const loaded = await vite.loadConfigFromFile(env, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.config) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n if (!check) {\n await plugin.config({}, env);\n\n return [];\n }\n\n const files = plugin.api?.generatedFiles?.() ?? [];\n const before = new Map(files.filter((f) => existsSync(f)).map((f) => [f, readFileSync(f, \"utf-8\")]));\n\n try {\n await plugin.config({}, env);\n\n return [...before].filter(([f, text]) => !existsSync(f) || readFileSync(f, \"utf-8\") !== text).map(([f]) => f);\n } finally {\n for (const [f, text] of before) writeFileSync(f, text);\n }\n}\n\n// Run as a command, not when imported.\nif (import.meta.url === pathToFileURL(process.argv[1] ?? \"\").href || process.argv[1]?.endsWith(\"rsc-kit-typegen\")) {\n const check = process.argv.includes(\"--check\");\n\n typegen(cwd(), check)\n .then((stale) => {\n if (!check) {\n stdout.write(\"rsc-kit: route types written\\n\");\n\n return;\n }\n\n if (stale.length === 0) {\n stdout.write(\"rsc-kit: generated files are current\\n\");\n\n return;\n }\n\n stderr.write(\n \"rsc-kit-typegen --check: these are committed and no longer what the backend and the routes produce:\\n\" +\n stale.map((f) => \" \" + relative(cwd(), f)).join(\"\\n\") +\n \"\\nRun rsc-kit-typegen and commit the result.\\n\",\n );\n exit(1);\n })\n .catch((error: unknown) => {\n stderr.write(\"rsc-kit-typegen: \" + (error instanceof Error ? error.message : String(error)) + \"\\n\");\n exit(1);\n });\n}\n\n/**\n * What a build of the app in `root` will produce - `{ output: \"server\", ... }`\n * or `{ output: \"export\", dir }` - read before building, from the app's own\n * Vite config, evaluated the way a build evaluates it. A value computed in\n * the config, or RSC_OUTPUT in the environment, resolves exactly as the build\n * resolves it, because it is the same code deciding.\n */\nexport async function appInfo(root = cwd()): Promise<Record<string, unknown>> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n // From inside the app, as a build runs: rscKit() takes its project root\n // from the working directory when the config creates it.\n const from = cwd();\n\n process.chdir(root);\n\n try {\n const loaded = await vite.loadConfigFromFile({ command: \"build\", mode: \"production\" }, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.api?.info) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n return plugin.api.info();\n } finally {\n process.chdir(from);\n }\n}\n\n\n/** A form's name from its action's: contactSend is contact-send. */\nfunction formName(action: string): string {\n return action.replace(/\\./g, \"-\").replace(/([a-z0-9])([A-Z])/g, \"$1-$2\").toLowerCase();\n}\n\n/**\n * Write `<sourceDir>/forms/<name>.ts`: a public form drawn from a backend\n * action, the way the docs write it by hand. The backend is asked first, as a\n * dev server start asks it, so an action added a moment ago is there.\n *\n * The file is the app's to edit afterwards - a theme, labels, `done` - and is\n * never overwritten unless `force` says so.\n */\nexport async function makeForm(\n root: string,\n action: string,\n options: { name?: string; force?: boolean } = {},\n): Promise<string> {\n await typegen(root);\n\n const local = createRequire(join(root, \"package.json\"));\n const vite = (await import(pathToFileURL(local.resolve(\"vite\")).href)) as {\n loadConfigFromFile: (env: { command: string; mode: string }, file?: string, root?: string) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n const loaded = await vite.loadConfigFromFile({ command: \"serve\", mode: \"development\" }, undefined, root);\n const plugin = (await flatten(loaded?.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n const files = plugin?.api?.generatedFiles?.() ?? [];\n const manifestFile = files.find((f) => f.endsWith(\"rsc-host.json\"));\n\n if (!manifestFile || !existsSync(manifestFile)) {\n throw new Error(\"No rsc-host.json: this app has no backend that describes its actions (rscKit({ hostManifest }) or a Go registry).\");\n }\n\n const manifest = JSON.parse(readFileSync(manifestFile, \"utf-8\")) as {\n actions?: Record<string, Record<string, string>>;\n types?: Record<string, { params?: unknown[] }>;\n };\n // Named as rpc() names it - Contact.send - and found in whichever module\n // the backend put it.\n const all = Object.entries(manifest.actions ?? {}).flatMap(([module, exports]) =>\n Object.entries(exports).map(([name, target]) => ({ module, name, target })),\n );\n const found = all.find((a) => a.target === action);\n const target = found?.target;\n\n if (!found || !target) {\n const known = all.map((a) => a.target);\n\n throw new Error(\n `The backend has no action named ${action}.` +\n (known.length ? ` It has: ${known.join(\", \")}.` : \" It has none: a form posts to an action, which is a class in app/Rsc/Actions in Laravel, or reg.HandleAction in Go.\"),\n );\n }\n\n const name = options.name ?? formName(action).replace(/-(send|submit|store|create)$/, \"\");\n const from = \"../server-actions/\" + found.module;\n\n if (!/^[a-z0-9-]+$/.test(name)) throw new Error(`A form's name is lowercase letters, digits and dashes: ${name}`);\n\n const sourceDir = plugin?.api?.sourceDir?.() ?? join(root, \"src\");\n const file = join(sourceDir, \"forms\", name + \".ts\");\n\n if (existsSync(file) && !options.force) throw new Error(`${relative(root, file)} is already there. Pass --force to write over it.`);\n\n const exported = name.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase());\n // The action under its own name - send - unless that is the form's, or a\n // word JavaScript keeps (delete): then send + Action. A default is named\n // after its module.\n const own = found.name === \"default\" ? found.module.split(\"/\").pop()!.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase()) : found.name;\n const usable = (id: string) => {\n try {\n new Function(`let ${id}`);\n return id !== exported;\n } catch {\n return false;\n }\n };\n const reference = usable(own) ? own : own + \"Action\";\n const imported =\n found.name === \"default\"\n ? `import ${reference} from '${from}'`\n : `import { ${reference === found.name ? reference : `${found.name} as ${reference}`} } from '${from}'`;\n const text = `import { defineBlueprint } from '@rsc-kit/press/forms'\nimport { shadcn } from '@rsc-kit/press/shadcn'\n${imported}\n\n// The fields and every check are ${target}'s: the backend says what it takes,\n// and its refusals land under the fields. Place it in any page: <${exported}.Form />.\n// Add actions.update to edit a record with it too: <${exported}.Form id={...} values={...} />.\nexport const ${exported} = defineBlueprint({\n name: '${name}',\n actions: { create: ${reference} },\n theme: shadcn,\n})\n`;\n\n const { mkdirSync } = await import(\"node:fs\");\n\n mkdirSync(join(sourceDir, \"forms\"), { recursive: true });\n writeFileSync(file, text);\n\n return file;\n}\n"]}
1
+ {"version":3,"file":"typegen.js","sourceRoot":"","sources":["../src/typegen.ts"],"names":[],"mappings":";AACA,gEAAgE;AAChE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,sEAAsE;AACtE,2EAA2E;AAC3E,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACz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AI,GAAG,CAAC;IAC5G,MAAM,IAAI,GAAG;;EAEb,QAAQ;;oCAE0B,MAAM;oEAC0B,QAAQ;uDACrB,QAAQ;eAChD,QAAQ;WACZ,IAAI;uBACQ,SAAS;;;CAG/B,CAAC;IAEA,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IAE9C,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE1B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["#!/usr/bin/env node\n// rsc-kit-typegen: write the route types without starting Vite.\n//\n// The types - every url the app has, for <Link href> and redirect() - are\n// written when the dev server or a build starts, and again when a dev server\n// sees a route added. A typecheck run with neither, by an agent or in CI,\n// read the types from the last start: a route added since failed with\n// '\"/admin\"' is not assignable to type Route until something started Vite.\n//\n// The app's own vite.config is loaded, through the app's own Vite, so the\n// plugin's options - sourceDir, outDir, a host's route file - are the ones it\n// builds with. Only the plugin's config step runs, which is what writes them.\n\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { join, relative } from \"node:path\";\nimport { cwd, exit, stderr, stdout } from \"node:process\";\nimport { pathToFileURL } from \"node:url\";\nimport { withoutSources } from \"./hostSources.js\";\n\ninterface PluginLike {\n name?: string;\n config?: (config: object, env: { command: string; mode: string }) => unknown;\n api?: { generatedFiles?: () => string[]; info?: () => Record<string, unknown>; sourceDir?: () => string };\n}\n\nasync function flatten(option: unknown): Promise<PluginLike[]> {\n const value = await option;\n\n if (Array.isArray(value)) return (await Promise.all(value.map(flatten))).flat();\n\n return value && typeof value === \"object\" ? [value as PluginLike] : [];\n}\n\n/**\n * Write the types; or, with `check`, say which committed generated files are\n * not what the backend and the route tree produce now, and change nothing.\n *\n * For CI: `rsc-kit-typegen --check` fails when rsc-host.json or the types were\n * committed and the backend has moved on since. Only files that were already\n * there are compared - one that is not committed is written fresh by every\n * build and cannot be stale - and every one is put back as it was.\n */\nexport async function typegen(root = cwd(), check = false): Promise<string[]> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n\n // As a build would: a manifest command that fails is a failure, not a\n // warning, when the question is whether what is committed is current.\n const env = check ? { command: \"build\", mode: \"production\" } : { command: \"serve\", mode: \"development\" };\n const loaded = await vite.loadConfigFromFile(env, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.config) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n if (!check) {\n await plugin.config({}, env);\n\n return [];\n }\n\n const generated = plugin.api?.generatedFiles?.() ?? [];\n // A declaration's map is put back with it, and never compared.\n const files = generated.flatMap((f) => (f.endsWith(\".d.ts\") ? [f, f + \".map\"] : [f]));\n const before = new Map(files.filter((f) => existsSync(f)).map((f) => [f, readFileSync(f, \"utf-8\")]));\n // Where the backend's functions are is the editor's, and moves with every\n // edit above them: a manifest that differs in that alone is not stale.\n const same = (f: string, text: string) => {\n const now = readFileSync(f, \"utf-8\");\n\n return f.endsWith(\"rsc-host.json\") ? withoutSources(now) === withoutSources(text) : now === text;\n };\n\n try {\n await plugin.config({}, env);\n\n return [...before].filter(([f, text]) => !f.endsWith(\".map\") && (!existsSync(f) || !same(f, text))).map(([f]) => f);\n } finally {\n for (const [f, text] of before) writeFileSync(f, text);\n }\n}\n\n// Run as a command, not when imported.\nif (import.meta.url === pathToFileURL(process.argv[1] ?? \"\").href || process.argv[1]?.endsWith(\"rsc-kit-typegen\")) {\n const check = process.argv.includes(\"--check\");\n\n typegen(cwd(), check)\n .then((stale) => {\n if (!check) {\n stdout.write(\"rsc-kit: route types written\\n\");\n\n return;\n }\n\n if (stale.length === 0) {\n stdout.write(\"rsc-kit: generated files are current\\n\");\n\n return;\n }\n\n stderr.write(\n \"rsc-kit-typegen --check: these are committed and no longer what the backend and the routes produce:\\n\" +\n stale.map((f) => \" \" + relative(cwd(), f)).join(\"\\n\") +\n \"\\nRun rsc-kit-typegen and commit the result.\\n\",\n );\n exit(1);\n })\n .catch((error: unknown) => {\n stderr.write(\"rsc-kit-typegen: \" + (error instanceof Error ? error.message : String(error)) + \"\\n\");\n exit(1);\n });\n}\n\n/**\n * What a build of the app in `root` will produce - `{ output: \"server\", ... }`\n * or `{ output: \"export\", dir }` - read before building, from the app's own\n * Vite config, evaluated the way a build evaluates it. A value computed in\n * the config, or RSC_OUTPUT in the environment, resolves exactly as the build\n * resolves it, because it is the same code deciding.\n */\nexport async function appInfo(root = cwd()): Promise<Record<string, unknown>> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n // From inside the app, as a build runs: rscKit() takes its project root\n // from the working directory when the config creates it.\n const from = cwd();\n\n process.chdir(root);\n\n try {\n const loaded = await vite.loadConfigFromFile({ command: \"build\", mode: \"production\" }, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.api?.info) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n return plugin.api.info();\n } finally {\n process.chdir(from);\n }\n}\n\n\n/** A form's name from its action's: contactSend is contact-send. */\nfunction formName(action: string): string {\n return action.replace(/\\./g, \"-\").replace(/([a-z0-9])([A-Z])/g, \"$1-$2\").toLowerCase();\n}\n\n/**\n * Write `<sourceDir>/forms/<name>.ts`: a public form drawn from a backend\n * action, the way the docs write it by hand. The backend is asked first, as a\n * dev server start asks it, so an action added a moment ago is there.\n *\n * The file is the app's to edit afterwards - a theme, labels, `done` - and is\n * never overwritten unless `force` says so.\n */\nexport async function makeForm(\n root: string,\n action: string,\n options: { name?: string; force?: boolean } = {},\n): Promise<string> {\n await typegen(root);\n\n const local = createRequire(join(root, \"package.json\"));\n const vite = (await import(pathToFileURL(local.resolve(\"vite\")).href)) as {\n loadConfigFromFile: (env: { command: string; mode: string }, file?: string, root?: string) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n const loaded = await vite.loadConfigFromFile({ command: \"serve\", mode: \"development\" }, undefined, root);\n const plugin = (await flatten(loaded?.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n const files = plugin?.api?.generatedFiles?.() ?? [];\n const manifestFile = files.find((f) => f.endsWith(\"rsc-host.json\"));\n\n if (!manifestFile || !existsSync(manifestFile)) {\n throw new Error(\"No rsc-host.json: this app has no backend that describes its actions (rscKit({ hostManifest }) or a Go registry).\");\n }\n\n const manifest = JSON.parse(readFileSync(manifestFile, \"utf-8\")) as {\n actions?: Record<string, Record<string, string>>;\n types?: Record<string, { params?: unknown[] }>;\n };\n // Named as rpc() names it - Contact.send - and found in whichever module\n // the backend put it.\n const all = Object.entries(manifest.actions ?? {}).flatMap(([module, exports]) =>\n Object.entries(exports).map(([name, target]) => ({ module, name, target })),\n );\n const found = all.find((a) => a.target === action);\n const target = found?.target;\n\n if (!found || !target) {\n const known = all.map((a) => a.target);\n\n throw new Error(\n `The backend has no action named ${action}.` +\n (known.length ? ` It has: ${known.join(\", \")}.` : \" It has none: a form posts to an action, which is a class in app/Rsc/Actions in Laravel, or reg.HandleAction in Go.\"),\n );\n }\n\n const name = options.name ?? formName(action).replace(/-(send|submit|store|create)$/, \"\");\n const from = \"../server-actions/\" + found.module;\n\n if (!/^[a-z0-9-]+$/.test(name)) throw new Error(`A form's name is lowercase letters, digits and dashes: ${name}`);\n\n const sourceDir = plugin?.api?.sourceDir?.() ?? join(root, \"src\");\n const file = join(sourceDir, \"forms\", name + \".ts\");\n\n if (existsSync(file) && !options.force) throw new Error(`${relative(root, file)} is already there. Pass --force to write over it.`);\n\n const exported = name.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase());\n // The action under its own name - send - unless that is the form's, or a\n // word JavaScript keeps (delete): then send + Action. A default is named\n // after its module.\n const own = found.name === \"default\" ? found.module.split(\"/\").pop()!.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase()) : found.name;\n const usable = (id: string) => {\n try {\n new Function(`let ${id}`);\n return id !== exported;\n } catch {\n return false;\n }\n };\n const reference = usable(own) ? own : own + \"Action\";\n const imported =\n found.name === \"default\"\n ? `import ${reference} from '${from}'`\n : `import { ${reference === found.name ? reference : `${found.name} as ${reference}`} } from '${from}'`;\n const text = `import { defineBlueprint } from '@rsc-kit/press/forms'\nimport { shadcn } from '@rsc-kit/press/shadcn'\n${imported}\n\n// The fields and every check are ${target}'s: the backend says what it takes,\n// and its refusals land under the fields. Place it in any page: <${exported}.Form />.\n// Add actions.update to edit a record with it too: <${exported}.Form id={...} values={...} />.\nexport const ${exported} = defineBlueprint({\n name: '${name}',\n actions: { create: ${reference} },\n theme: shadcn,\n})\n`;\n\n const { mkdirSync } = await import(\"node:fs\");\n\n mkdirSync(join(sourceDir, \"forms\"), { recursive: true });\n writeFileSync(file, text);\n\n return file;\n}\n"]}
package/dist/vite.d.ts CHANGED
@@ -38,10 +38,11 @@ export interface RscKitOptions {
38
38
  * in a page whose body is whole before it is sent (a stored page, a kept
39
39
  * one, a shell), and a nonce, new per response, on one that streams.
40
40
  *
41
- * rscKit({ contentSecurityPolicy: { directives: { 'img-src': ["'self'", 'data:'] } } })
41
+ * rscKit({ contentSecurityPolicy: { extend: { 'img-src': 'data:' } } })
42
42
  *
43
43
  * `{}` is a strict default: `default-src 'self'; base-uri 'self';
44
- * object-src 'none'; style-src-attr 'unsafe-inline'`. `reportOnly` sends
44
+ * object-src 'none'; style-src-attr 'unsafe-inline'`. `extend` adds sources
45
+ * to it; `directives` is a whole policy in its place. `reportOnly` sends
45
46
  * Content-Security-Policy-Report-Only instead. A static export carries it
46
47
  * as a `<meta>`. `vite dev` sends it too, with `'unsafe-eval'` for React's
47
48
  * development build. Not together with a Content-Security-Policy in
@@ -376,8 +377,20 @@ export interface RscKitOptions {
376
377
  * and a function added to the backend is not typed until the next start.
377
378
  */
378
379
  watch?: string[];
380
+ /**
381
+ * How the build asks the backend what rpc() answers. The arguments the
382
+ * manifest names, added to `command`, unless given here: a whole command
383
+ * - `['./api', '-calls']` - or false to ask nothing, so every page that
384
+ * calls rpc() streams it.
385
+ */
386
+ calls?: string[] | false;
379
387
  };
380
388
  }
389
+ /** The command a build asks what rpc() answers; see hostManifest.calls. */
390
+ declare let hostCallsCommand: {
391
+ command: string[];
392
+ cwd: string;
393
+ } | null;
381
394
  /** The backend's actions by module - its path under server-actions/ - and then by export. */
382
395
  export type HostActions = Record<string, Record<string, string>>;
383
396
  /**
@@ -449,6 +462,8 @@ export declare function pageUnderBackendPath(routes: {
449
462
  component: string;
450
463
  segments: RouteSegment[];
451
464
  }[], paths: readonly string[]): string | null;
465
+ /** @internal What answers rpc() during a build, or null when nothing does. */
466
+ export declare function buildCallsCommand(spec: RscKitOptions["hostManifest"], declared: string[] | null): typeof hostCallsCommand;
452
467
  /**
453
468
  * The service worker, written into the client output at build time.
454
469
  *