@parlor/host 0.3.0 → 0.3.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/dist/build.d.ts +5 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +14 -1
- package/dist/build.js.map +1 -1
- package/dist/entry.d.ts +10 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +25 -3
- package/dist/entry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/location-hint.d.ts +9 -0
- package/dist/location-hint.d.ts.map +1 -0
- package/dist/location-hint.js +68 -0
- package/dist/location-hint.js.map +1 -0
- package/package.json +8 -8
package/dist/build.d.ts
CHANGED
|
@@ -36,5 +36,10 @@ export interface DevWranglerConfig {
|
|
|
36
36
|
}
|
|
37
37
|
/** The bindings a cloudflare-durable build declares, as Wrangler's `getPlatformProxy()` reads them. */
|
|
38
38
|
export declare function devWranglerConfig(config: ParlorConfig, compatibilityDate?: string): DevWranglerConfig;
|
|
39
|
+
/**
|
|
40
|
+
* The CLI of the nitro this package builds with, for `nitro deploy`. Nitro ships it as a
|
|
41
|
+
* `bin`, not an export, so it is found through nitro's own manifest.
|
|
42
|
+
*/
|
|
43
|
+
export declare function nitroCli(): string;
|
|
39
44
|
export {};
|
|
40
45
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAmB/C,OAAO,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AQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,kFAAkF;IAClF,QAAQ,CAAC,WAAW,EAAE,SAAS,wBAAwB,EAAE,CAAC;CAC3D;AAED,uGAAuG;AACvG,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,iBAAiB,GAAE,MAAmC,GACrD,iBAAiB,CAwBnB;AAkCD;;;GAGG;AACH,wBAAgB,QAAQ,IAAI,MAAM,CAQjC"}
|
package/dist/build.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { pagePattern, UI_MANIFEST_FILE } from "@parlor/agent-ui";
|
|
5
6
|
import { appServerEnv, ConfigError, generatedDir, } from "@parlor/config";
|
|
@@ -202,4 +203,16 @@ async function prepareDurable({ config, rootDir }, hostRoot, serverEntry) {
|
|
|
202
203
|
},
|
|
203
204
|
};
|
|
204
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* The CLI of the nitro this package builds with, for `nitro deploy`. Nitro ships it as a
|
|
208
|
+
* `bin`, not an export, so it is found through nitro's own manifest.
|
|
209
|
+
*/
|
|
210
|
+
export function nitroCli() {
|
|
211
|
+
const manifest = createRequire(import.meta.url).resolve("nitro/package.json");
|
|
212
|
+
const { bin } = JSON.parse(readFileSync(manifest, "utf8"));
|
|
213
|
+
const entry = typeof bin === "string" ? bin : bin?.nitro;
|
|
214
|
+
if (!entry)
|
|
215
|
+
throw new Error(`${manifest} names no nitro CLI.`);
|
|
216
|
+
return join(dirname(manifest), entry);
|
|
217
|
+
}
|
|
205
218
|
//# sourceMappingURL=build.js.map
|
package/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AAG,IAAI,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;IAC7D,MAAM,SAAS,CACb,WAAW,EACX,mBAAmB,CAAC;QAClB,WAAW;QACX,gBAAgB,EAAE,SAAS,CAAC,OAAO,EAAE,cAAc,CAAC;QACpD,aAAa,EAAE,iBAAiB;KACjC,CAAC,CACH,CAAC;IACF,OAAO;QACL,UAAU,EAAE,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC;QACnE,KAAK,EAAE;YACL,OAAO,EAAE,WAAW;YACpB,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,qBAAqB,CAAC,MAAM,CAAC;SACxC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\n\nimport { pagePattern, UI_MANIFEST_FILE, type UiManifest } from \"@parlor/agent-ui\";\nimport {\n appServerEnv,\n ConfigError,\n generatedDir,\n type LoadedConfig,\n type ParlorConfig,\n} from \"@parlor/config\";\nimport { appCsp, extendCsp, serializeCsp, webOutDir } from \"@parlor/shell-web\";\nimport { readMigrationFiles } from \"drizzle-orm/migrator\";\nimport { build, copyPublicAssets, createNitro, prepare } from \"nitro/builder\";\nimport type { NitroConfig } from \"nitro/types\";\n\nimport {\n importRequiredBuiltins,\n keepJsonOutOfChunkGroups,\n labelChunkGroups,\n} from \"./bundle.js\";\nimport {\n cloudflareEntrySource,\n DURABLE_SERVER_BINDING,\n DURABLE_SERVER_CLASS,\n durableServerSource,\n hostEntrySource,\n INDEX_HTML_PLACEHOLDER,\n NONCE_PLACEHOLDER,\n PAGE_ROUTES_PLACEHOLDER,\n type RenderEntryOptions,\n UI_MANIFEST_PLACEHOLDER,\n} from \"./entry.js\";\nimport {\n type DeployPreset,\n nitroPresetFor,\n runsOnWorkerd,\n syncTransportFor,\n} from \"./presets.js\";\n\nexport const SYNC_TRANSPORT_ENV = \"PARLOR_SYNC_TRANSPORT\";\nexport const MIGRATIONS_PLACEHOLDER = \"__PARLOR_MIGRATIONS__\";\nconst TRACED_DEPENDENCIES = [\"@electric-sql/pglite\", \"pg\"] as const;\nconst DEFAULT_COMPATIBILITY_DATE =\n \"2026-10-01\" satisfies NitroConfig[\"compatibilityDate\"];\n\nexport interface ServerBuildOptions {\n readonly preset: DeployPreset;\n readonly basePath?: string | undefined;\n readonly compatibilityDate?: NitroConfig[\"compatibilityDate\"] | undefined;\n /** The server render module `buildRender` wrote, for an app with `web.ssr`. */\n readonly render?: string | undefined;\n}\n\nexport interface ServerBuildResult {\n readonly rootDir: string;\n readonly outputDir: string;\n readonly preset: DeployPreset;\n readonly syncTransport: \"sse\" | \"poll\";\n}\n\nexport function hostRootDir(projectRoot: string): string {\n return join(generatedDir(projectRoot), \"nitro\");\n}\n\nfunction pageRoutesSource(manifest: Pick<UiManifest, \"routes\"> | undefined): string {\n return `[${(manifest?.routes ?? []).map((route) => String(pagePattern(route.path))).join(\", \")}]`;\n}\n\n/**\n * The entry sets the policy on the documents it serves itself, so these cover only the static\n * files: a rule matching every path would also override the app's own responses.\n */\nasync function staticFileRules(\n webDir: string,\n headers: Record<string, string>,\n ignored: readonly string[],\n): Promise<NonNullable<NitroConfig[\"routeRules\"]>> {\n const entries = await readdir(webDir, { withFileTypes: true }).catch(() => []);\n const rules: NonNullable<NitroConfig[\"routeRules\"]> = {};\n for (const entry of entries) {\n if (ignored.includes(entry.name)) continue;\n rules[entry.isDirectory() ? `/${entry.name}/**` : `/${entry.name}`] = { headers };\n if (entry.name === \"index.html\") rules[\"/\"] = { headers };\n }\n return rules;\n}\n\nexport async function buildServer(\n { config, rootDir }: LoadedConfig,\n options: ServerBuildOptions,\n): Promise<ServerBuildResult> {\n const hostRoot = hostRootDir(rootDir);\n const basePath = options.basePath ?? \"/_parlor\";\n const syncTransport = config.server.sync?.transport ?? syncTransportFor(options.preset);\n const indexHtml = await readFile(join(webOutDir(rootDir), \"index.html\"), \"utf8\").catch(\n () => \"\",\n );\n const manifest = await readFile(\n join(generatedDir(rootDir), UI_MANIFEST_FILE),\n \"utf8\",\n ).then(\n (text) => JSON.parse(text) as UiManifest,\n () => undefined,\n );\n const policy = appCsp(config, {});\n const contentSecurityPolicy = serializeCsp(policy);\n const render: RenderEntryOptions | undefined = options.render\n ? {\n module: options.render,\n contentSecurityPolicy: serializeCsp(\n extendCsp(policy, { \"script-src\": [`'nonce-${NONCE_PLACEHOLDER}'`] }),\n ),\n }\n : undefined;\n\n // With server rendering, every document goes through the entry, `/` included.\n const ignoredAssets = render ? [\"index.html\"] : [];\n\n await mkdir(hostRoot, { recursive: true });\n const serverEntry = join(rootDir, config.server.entry);\n const entryPath = join(hostRoot, \"entry.mjs\");\n const cloudflare =\n options.preset === \"cloudflare-durable\"\n ? await prepareDurable({ config, rootDir }, hostRoot, serverEntry)\n : undefined;\n await writeFile(\n entryPath,\n cloudflare\n ? cloudflareEntrySource({\n basePath,\n contentSecurityPolicy,\n render,\n locationHint: config.deploy.cloudflare?.locationHint,\n })\n : hostEntrySource({ serverEntry, basePath, contentSecurityPolicy, render }),\n );\n await writeFile(join(hostRoot, \".gitignore\"), \"*\\n\");\n\n const nitro = await createNitro({\n rootDir: hostRoot,\n preset: nitroPresetFor(options.preset),\n serverEntry: entryPath,\n ...(cloudflare ? { cloudflare: cloudflare.nitro } : {}),\n compatibilityDate: options.compatibilityDate ?? DEFAULT_COMPATIBILITY_DATE,\n publicAssets: [\n {\n dir: webOutDir(rootDir),\n baseURL: \"/\",\n fallthrough: true,\n ...(render\n ? { ignore: ignoredAssets.map((name) => join(webOutDir(rootDir), name)) }\n : {}),\n },\n ],\n routeRules: await staticFileRules(\n webOutDir(rootDir),\n { \"content-security-policy\": contentSecurityPolicy },\n ignoredAssets,\n ),\n traceDeps: [...TRACED_DEPENDENCIES],\n hooks: {\n \"rollup:before\": (nitroBuild, bundle) => {\n keepJsonOutOfChunkGroups(bundle);\n labelChunkGroups(bundle);\n if (runsOnWorkerd(options.preset)) importRequiredBuiltins(nitroBuild, bundle);\n },\n },\n replace: {\n [INDEX_HTML_PLACEHOLDER]: JSON.stringify(indexHtml),\n [UI_MANIFEST_PLACEHOLDER]: manifest ? JSON.stringify(manifest) : \"undefined\",\n [PAGE_ROUTES_PLACEHOLDER]: pageRoutesSource(manifest),\n [`process.env.${SYNC_TRANSPORT_ENV}`]: JSON.stringify(syncTransport),\n ...(cloudflare ? { [MIGRATIONS_PLACEHOLDER]: cloudflare.migrations } : {}),\n ...Object.fromEntries(\n Object.entries(appServerEnv(config)).map(([name, value]) => [\n `process.env.${name}`,\n JSON.stringify(value),\n ]),\n ),\n },\n });\n await prepare(nitro);\n await copyPublicAssets(nitro);\n await build(nitro);\n await nitro.close();\n\n return {\n rootDir: hostRoot,\n outputDir: nitro.options.output.dir,\n preset: options.preset,\n syncTransport,\n };\n}\n\ntype CloudflareOptions = NonNullable<NitroConfig[\"cloudflare\"]>;\ntype WranglerConfig = NonNullable<CloudflareOptions[\"wrangler\"]>;\n\ninterface DurableBuild {\n readonly nitro: CloudflareOptions;\n readonly migrations: string;\n}\n\n/** `app.id` is reverse-DNS lowercase alphanumerics, so only its dots need replacing. */\nfunction workerName(appId: string): string {\n return appId.replaceAll(\".\", \"-\").slice(0, 63);\n}\n\nfunction embeddedMigrations(rootDir: string, folder: string): string {\n const absolute = join(rootDir, folder);\n if (!existsSync(join(absolute, \"meta\", \"_journal.json\"))) return \"undefined\";\n return JSON.stringify({ [folder]: readMigrationFiles({ migrationsFolder: absolute }) });\n}\n\n/** The bundler's view: a node_modules lookup from the project, never NODE_PATH. */\nfunction installed(rootDir: string, name: string): boolean {\n for (let dir = rootDir; ; dir = dirname(dir)) {\n if (existsSync(join(dir, \"node_modules\", name, \"package.json\"))) return true;\n if (dirname(dir) === dir) return false;\n }\n}\n\n/**\n * Wrangler applies Durable Object migrations as an append-only log, after the last tag a\n * deployment applied. An app with its own migrations lists ours where it first deployed.\n */\nexport function withServerMigration(\n migrations: NonNullable<WranglerConfig[\"migrations\"]>,\n): NonNullable<WranglerConfig[\"migrations\"]> {\n const declared = migrations.some((migration) =>\n [migration.new_classes, migration.new_sqlite_classes].some((classes) =>\n classes?.includes(DURABLE_SERVER_CLASS),\n ),\n );\n if (declared) return migrations;\n return [\n ...migrations,\n { tag: \"parlor-server-v1\", new_sqlite_classes: [DURABLE_SERVER_CLASS] },\n ];\n}\n\nfunction durableWranglerConfig(config: ParlorConfig): WranglerConfig {\n const own = (config.deploy.cloudflare?.wrangler ?? {}) as WranglerConfig;\n return {\n name: workerName(config.app.id),\n ...own,\n durable_objects: {\n bindings: [\n { name: DURABLE_SERVER_BINDING, class_name: DURABLE_SERVER_CLASS },\n ...(own.durable_objects?.bindings ?? []),\n ],\n },\n migrations: withServerMigration(own.migrations ?? []),\n };\n}\n\nexport interface UnavailableDurableObject {\n readonly binding: string;\n readonly className: string;\n}\n\nexport interface DevWranglerConfig {\n readonly wrangler: WranglerConfig;\n /** Classes the Worker itself would define: no Worker code runs in development. */\n readonly unavailable: readonly UnavailableDurableObject[];\n}\n\n/** The bindings a cloudflare-durable build declares, as Wrangler's `getPlatformProxy()` reads them. */\nexport function devWranglerConfig(\n config: ParlorConfig,\n compatibilityDate: string = DEFAULT_COMPATIBILITY_DATE,\n): DevWranglerConfig {\n const {\n main: _main,\n assets: _assets,\n migrations: _migrations,\n durable_objects: durableObjects,\n ...production\n } = durableWranglerConfig(config);\n const bindings = durableObjects?.bindings ?? [];\n const ownClass = (binding: (typeof bindings)[number]) =>\n !binding.script_name || binding.script_name === production.name;\n return {\n wrangler: {\n ...production,\n compatibility_date: production.compatibility_date ?? compatibilityDate,\n compatibility_flags: [\n ...new Set([...(production.compatibility_flags ?? []), \"nodejs_compat\"]),\n ],\n durable_objects: { bindings: bindings.filter((binding) => !ownClass(binding)) },\n },\n unavailable: bindings\n .filter(ownClass)\n .map((binding) => ({ binding: binding.name, className: binding.class_name })),\n };\n}\n\nasync function prepareDurable(\n { config, rootDir }: Pick<LoadedConfig, \"config\" | \"rootDir\">,\n hostRoot: string,\n serverEntry: string,\n): Promise<DurableBuild> {\n const workerExports = config.deploy.cloudflare?.exports;\n const workerExportsPath = workerExports ? join(rootDir, workerExports) : undefined;\n if (workerExportsPath && !existsSync(workerExportsPath)) {\n throw new ConfigError(\n `deploy.cloudflare.exports names ${workerExports}, which does not exist in ${rootDir}`,\n );\n }\n const exportsPath = join(hostRoot, \"exports.cloudflare.mjs\");\n await writeFile(\n exportsPath,\n durableServerSource({\n serverEntry,\n connectionScopes: installed(rootDir, \"@parlor/data\"),\n workerExports: workerExportsPath,\n }),\n );\n return {\n migrations: embeddedMigrations(rootDir, config.database.migrations),\n nitro: {\n exports: exportsPath,\n deployConfig: true,\n nodeCompat: true,\n wrangler: durableWranglerConfig(config),\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AAClF,OAAO,EACL,YAAY,EACZ,WAAW,EACX,YAAY,GAGb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eA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AC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAExD,CAAC;IACF,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC;IACzD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,sBAAsB,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, writeFile } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\n\nimport { pagePattern, UI_MANIFEST_FILE, type UiManifest } from \"@parlor/agent-ui\";\nimport {\n appServerEnv,\n ConfigError,\n generatedDir,\n type LoadedConfig,\n type ParlorConfig,\n} from \"@parlor/config\";\nimport { appCsp, extendCsp, serializeCsp, webOutDir } from \"@parlor/shell-web\";\nimport { readMigrationFiles } from \"drizzle-orm/migrator\";\nimport { build, copyPublicAssets, createNitro, prepare } from \"nitro/builder\";\nimport type { NitroConfig } from \"nitro/types\";\n\nimport {\n importRequiredBuiltins,\n keepJsonOutOfChunkGroups,\n labelChunkGroups,\n} from \"./bundle.js\";\nimport {\n cloudflareEntrySource,\n DURABLE_SERVER_BINDING,\n DURABLE_SERVER_CLASS,\n durableServerSource,\n hostEntrySource,\n INDEX_HTML_PLACEHOLDER,\n NONCE_PLACEHOLDER,\n PAGE_ROUTES_PLACEHOLDER,\n type RenderEntryOptions,\n UI_MANIFEST_PLACEHOLDER,\n} from \"./entry.js\";\nimport {\n type DeployPreset,\n nitroPresetFor,\n runsOnWorkerd,\n syncTransportFor,\n} from \"./presets.js\";\n\nexport const SYNC_TRANSPORT_ENV = \"PARLOR_SYNC_TRANSPORT\";\nexport const MIGRATIONS_PLACEHOLDER = \"__PARLOR_MIGRATIONS__\";\nconst TRACED_DEPENDENCIES = [\"@electric-sql/pglite\", \"pg\"] as const;\nconst DEFAULT_COMPATIBILITY_DATE =\n \"2026-10-01\" satisfies NitroConfig[\"compatibilityDate\"];\n\nexport interface ServerBuildOptions {\n readonly preset: DeployPreset;\n readonly basePath?: string | undefined;\n readonly compatibilityDate?: NitroConfig[\"compatibilityDate\"] | undefined;\n /** The server render module `buildRender` wrote, for an app with `web.ssr`. */\n readonly render?: string | undefined;\n}\n\nexport interface ServerBuildResult {\n readonly rootDir: string;\n readonly outputDir: string;\n readonly preset: DeployPreset;\n readonly syncTransport: \"sse\" | \"poll\";\n}\n\nexport function hostRootDir(projectRoot: string): string {\n return join(generatedDir(projectRoot), \"nitro\");\n}\n\nfunction pageRoutesSource(manifest: Pick<UiManifest, \"routes\"> | undefined): string {\n return `[${(manifest?.routes ?? []).map((route) => String(pagePattern(route.path))).join(\", \")}]`;\n}\n\n/**\n * The entry sets the policy on the documents it serves itself, so these cover only the static\n * files: a rule matching every path would also override the app's own responses.\n */\nasync function staticFileRules(\n webDir: string,\n headers: Record<string, string>,\n ignored: readonly string[],\n): Promise<NonNullable<NitroConfig[\"routeRules\"]>> {\n const entries = await readdir(webDir, { withFileTypes: true }).catch(() => []);\n const rules: NonNullable<NitroConfig[\"routeRules\"]> = {};\n for (const entry of entries) {\n if (ignored.includes(entry.name)) continue;\n rules[entry.isDirectory() ? `/${entry.name}/**` : `/${entry.name}`] = { headers };\n if (entry.name === \"index.html\") rules[\"/\"] = { headers };\n }\n return rules;\n}\n\nexport async function buildServer(\n { config, rootDir }: LoadedConfig,\n options: ServerBuildOptions,\n): Promise<ServerBuildResult> {\n const hostRoot = hostRootDir(rootDir);\n const basePath = options.basePath ?? \"/_parlor\";\n const syncTransport = config.server.sync?.transport ?? syncTransportFor(options.preset);\n const indexHtml = await readFile(join(webOutDir(rootDir), \"index.html\"), \"utf8\").catch(\n () => \"\",\n );\n const manifest = await readFile(\n join(generatedDir(rootDir), UI_MANIFEST_FILE),\n \"utf8\",\n ).then(\n (text) => JSON.parse(text) as UiManifest,\n () => undefined,\n );\n const policy = appCsp(config, {});\n const contentSecurityPolicy = serializeCsp(policy);\n const render: RenderEntryOptions | undefined = options.render\n ? {\n module: options.render,\n contentSecurityPolicy: serializeCsp(\n extendCsp(policy, { \"script-src\": [`'nonce-${NONCE_PLACEHOLDER}'`] }),\n ),\n }\n : undefined;\n\n // With server rendering, every document goes through the entry, `/` included.\n const ignoredAssets = render ? [\"index.html\"] : [];\n\n await mkdir(hostRoot, { recursive: true });\n const serverEntry = join(rootDir, config.server.entry);\n const entryPath = join(hostRoot, \"entry.mjs\");\n const cloudflare =\n options.preset === \"cloudflare-durable\"\n ? await prepareDurable({ config, rootDir }, hostRoot, serverEntry)\n : undefined;\n await writeFile(\n entryPath,\n cloudflare\n ? cloudflareEntrySource({\n basePath,\n contentSecurityPolicy,\n render,\n locationHint: config.deploy.cloudflare?.locationHint,\n })\n : hostEntrySource({ serverEntry, basePath, contentSecurityPolicy, render }),\n );\n await writeFile(join(hostRoot, \".gitignore\"), \"*\\n\");\n\n const nitro = await createNitro({\n rootDir: hostRoot,\n preset: nitroPresetFor(options.preset),\n serverEntry: entryPath,\n ...(cloudflare ? { cloudflare: cloudflare.nitro } : {}),\n compatibilityDate: options.compatibilityDate ?? DEFAULT_COMPATIBILITY_DATE,\n publicAssets: [\n {\n dir: webOutDir(rootDir),\n baseURL: \"/\",\n fallthrough: true,\n ...(render\n ? { ignore: ignoredAssets.map((name) => join(webOutDir(rootDir), name)) }\n : {}),\n },\n ],\n routeRules: await staticFileRules(\n webOutDir(rootDir),\n { \"content-security-policy\": contentSecurityPolicy },\n ignoredAssets,\n ),\n traceDeps: [...TRACED_DEPENDENCIES],\n hooks: {\n \"rollup:before\": (nitroBuild, bundle) => {\n keepJsonOutOfChunkGroups(bundle);\n labelChunkGroups(bundle);\n if (runsOnWorkerd(options.preset)) importRequiredBuiltins(nitroBuild, bundle);\n },\n },\n replace: {\n [INDEX_HTML_PLACEHOLDER]: JSON.stringify(indexHtml),\n [UI_MANIFEST_PLACEHOLDER]: manifest ? JSON.stringify(manifest) : \"undefined\",\n [PAGE_ROUTES_PLACEHOLDER]: pageRoutesSource(manifest),\n [`process.env.${SYNC_TRANSPORT_ENV}`]: JSON.stringify(syncTransport),\n ...(cloudflare ? { [MIGRATIONS_PLACEHOLDER]: cloudflare.migrations } : {}),\n ...Object.fromEntries(\n Object.entries(appServerEnv(config)).map(([name, value]) => [\n `process.env.${name}`,\n JSON.stringify(value),\n ]),\n ),\n },\n });\n await prepare(nitro);\n await copyPublicAssets(nitro);\n await build(nitro);\n await nitro.close();\n\n return {\n rootDir: hostRoot,\n outputDir: nitro.options.output.dir,\n preset: options.preset,\n syncTransport,\n };\n}\n\ntype CloudflareOptions = NonNullable<NitroConfig[\"cloudflare\"]>;\ntype WranglerConfig = NonNullable<CloudflareOptions[\"wrangler\"]>;\n\ninterface DurableBuild {\n readonly nitro: CloudflareOptions;\n readonly migrations: string;\n}\n\n/** `app.id` is reverse-DNS lowercase alphanumerics, so only its dots need replacing. */\nfunction workerName(appId: string): string {\n return appId.replaceAll(\".\", \"-\").slice(0, 63);\n}\n\nfunction embeddedMigrations(rootDir: string, folder: string): string {\n const absolute = join(rootDir, folder);\n if (!existsSync(join(absolute, \"meta\", \"_journal.json\"))) return \"undefined\";\n return JSON.stringify({ [folder]: readMigrationFiles({ migrationsFolder: absolute }) });\n}\n\n/** The bundler's view: a node_modules lookup from the project, never NODE_PATH. */\nfunction installed(rootDir: string, name: string): boolean {\n for (let dir = rootDir; ; dir = dirname(dir)) {\n if (existsSync(join(dir, \"node_modules\", name, \"package.json\"))) return true;\n if (dirname(dir) === dir) return false;\n }\n}\n\n/**\n * Wrangler applies Durable Object migrations as an append-only log, after the last tag a\n * deployment applied. An app with its own migrations lists ours where it first deployed.\n */\nexport function withServerMigration(\n migrations: NonNullable<WranglerConfig[\"migrations\"]>,\n): NonNullable<WranglerConfig[\"migrations\"]> {\n const declared = migrations.some((migration) =>\n [migration.new_classes, migration.new_sqlite_classes].some((classes) =>\n classes?.includes(DURABLE_SERVER_CLASS),\n ),\n );\n if (declared) return migrations;\n return [\n ...migrations,\n { tag: \"parlor-server-v1\", new_sqlite_classes: [DURABLE_SERVER_CLASS] },\n ];\n}\n\nfunction durableWranglerConfig(config: ParlorConfig): WranglerConfig {\n const own = (config.deploy.cloudflare?.wrangler ?? {}) as WranglerConfig;\n return {\n name: workerName(config.app.id),\n ...own,\n durable_objects: {\n bindings: [\n { name: DURABLE_SERVER_BINDING, class_name: DURABLE_SERVER_CLASS },\n ...(own.durable_objects?.bindings ?? []),\n ],\n },\n migrations: withServerMigration(own.migrations ?? []),\n };\n}\n\nexport interface UnavailableDurableObject {\n readonly binding: string;\n readonly className: string;\n}\n\nexport interface DevWranglerConfig {\n readonly wrangler: WranglerConfig;\n /** Classes the Worker itself would define: no Worker code runs in development. */\n readonly unavailable: readonly UnavailableDurableObject[];\n}\n\n/** The bindings a cloudflare-durable build declares, as Wrangler's `getPlatformProxy()` reads them. */\nexport function devWranglerConfig(\n config: ParlorConfig,\n compatibilityDate: string = DEFAULT_COMPATIBILITY_DATE,\n): DevWranglerConfig {\n const {\n main: _main,\n assets: _assets,\n migrations: _migrations,\n durable_objects: durableObjects,\n ...production\n } = durableWranglerConfig(config);\n const bindings = durableObjects?.bindings ?? [];\n const ownClass = (binding: (typeof bindings)[number]) =>\n !binding.script_name || binding.script_name === production.name;\n return {\n wrangler: {\n ...production,\n compatibility_date: production.compatibility_date ?? compatibilityDate,\n compatibility_flags: [\n ...new Set([...(production.compatibility_flags ?? []), \"nodejs_compat\"]),\n ],\n durable_objects: { bindings: bindings.filter((binding) => !ownClass(binding)) },\n },\n unavailable: bindings\n .filter(ownClass)\n .map((binding) => ({ binding: binding.name, className: binding.class_name })),\n };\n}\n\nasync function prepareDurable(\n { config, rootDir }: Pick<LoadedConfig, \"config\" | \"rootDir\">,\n hostRoot: string,\n serverEntry: string,\n): Promise<DurableBuild> {\n const workerExports = config.deploy.cloudflare?.exports;\n const workerExportsPath = workerExports ? join(rootDir, workerExports) : undefined;\n if (workerExportsPath && !existsSync(workerExportsPath)) {\n throw new ConfigError(\n `deploy.cloudflare.exports names ${workerExports}, which does not exist in ${rootDir}`,\n );\n }\n const exportsPath = join(hostRoot, \"exports.cloudflare.mjs\");\n await writeFile(\n exportsPath,\n durableServerSource({\n serverEntry,\n connectionScopes: installed(rootDir, \"@parlor/data\"),\n workerExports: workerExportsPath,\n }),\n );\n return {\n migrations: embeddedMigrations(rootDir, config.database.migrations),\n nitro: {\n exports: exportsPath,\n deployConfig: true,\n nodeCompat: true,\n wrangler: durableWranglerConfig(config),\n },\n };\n}\n\n/**\n * The CLI of the nitro this package builds with, for `nitro deploy`. Nitro ships it as a\n * `bin`, not an export, so it is found through nitro's own manifest.\n */\nexport function nitroCli(): string {\n const manifest = createRequire(import.meta.url).resolve(\"nitro/package.json\");\n const { bin } = JSON.parse(readFileSync(manifest, \"utf8\")) as {\n readonly bin?: string | Readonly<Record<string, string>>;\n };\n const entry = typeof bin === \"string\" ? bin : bin?.nitro;\n if (!entry) throw new Error(`${manifest} names no nitro CLI.`);\n return join(dirname(manifest), entry);\n}\n"]}
|
package/dist/entry.d.ts
CHANGED
|
@@ -21,7 +21,16 @@ export declare function hostEntrySource({ serverEntry, ...document }: EntryOptio
|
|
|
21
21
|
export interface CloudflareEntryOptions extends DocumentOptions {
|
|
22
22
|
readonly locationHint?: string | undefined;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The Durable Object's name. A hint only places an object when it is first created, so the
|
|
26
|
+
* name follows the hint: setting or changing it starts the server where it says. The server
|
|
27
|
+
* keeps nothing in the object's own storage, so the new one starts complete.
|
|
28
|
+
*/
|
|
29
|
+
export declare function durableServerName(locationHint: string | undefined): string;
|
|
30
|
+
/**
|
|
31
|
+
* The stateless Worker: documents here, everything else to the one Durable Object, started
|
|
32
|
+
* beside the database. The configured hint wins; without one, the region `DATABASE_URL` names.
|
|
33
|
+
*/
|
|
25
34
|
export declare function cloudflareEntrySource({ locationHint, ...document }: CloudflareEntryOptions): string;
|
|
26
35
|
export interface DurableServerOptions {
|
|
27
36
|
readonly serverEntry: string;
|
package/dist/entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAClD;AAED,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;AAC9D,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAChE,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAEhE,eAAO,MAAM,sBAAsB,kBAAkB,CAAC;AACtD,eAAO,MAAM,oBAAoB,iBAAiB,CAAC;AAEnD,KAAK,eAAe,GAAG,IAAI,CACzB,YAAY,EACZ,UAAU,GAAG,uBAAuB,GAAG,QAAQ,CAChD,CAAC;AAuEF,wBAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,GAAG,QAAQ,EAAE,EAAE,YAAY,GAAG,MAAM,CAyBlF;AAED,MAAM,WAAW,sBAAuB,SAAQ,eAAe;IAC7D,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE1E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,YAAY,EACZ,GAAG,QAAQ,EACZ,EAAE,sBAAsB,GAAG,MAAM,CAyBjC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,wEAAwE;IACxE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,WAAW,EACX,gBAAgB,EAChB,aAAa,GACd,EAAE,oBAAoB,GAAG,MAAM,CAmB/B"}
|
package/dist/entry.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UNROUTED_HEADER } from "@parlor/agent-ui";
|
|
2
|
+
import { locationHintForDatabase } from "./location-hint.js";
|
|
2
3
|
export const NONCE_PLACEHOLDER = "{nonce}";
|
|
3
4
|
export const INDEX_HTML_PLACEHOLDER = "__PARLOR_INDEX_HTML__";
|
|
4
5
|
export const UI_MANIFEST_PLACEHOLDER = "__PARLOR_UI_MANIFEST__";
|
|
@@ -93,18 +94,39 @@ export default {
|
|
|
93
94
|
};
|
|
94
95
|
`;
|
|
95
96
|
}
|
|
96
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* The Durable Object's name. A hint only places an object when it is first created, so the
|
|
99
|
+
* name follows the hint: setting or changing it starts the server where it says. The server
|
|
100
|
+
* keeps nothing in the object's own storage, so the new one starts complete.
|
|
101
|
+
*/
|
|
102
|
+
export function durableServerName(locationHint) {
|
|
103
|
+
return locationHint ? `app@${locationHint}` : "app";
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The stateless Worker: documents here, everything else to the one Durable Object, started
|
|
107
|
+
* beside the database. The configured hint wins; without one, the region `DATABASE_URL` names.
|
|
108
|
+
*/
|
|
97
109
|
export function cloudflareEntrySource({ locationHint, ...document }) {
|
|
98
110
|
return `import { env } from "cloudflare:workers";
|
|
99
111
|
|
|
100
112
|
${documentSource(document)}
|
|
101
113
|
|
|
114
|
+
${locationHintForDatabase.toString()}
|
|
115
|
+
|
|
116
|
+
${durableServerName.toString()}
|
|
117
|
+
|
|
118
|
+
const CONFIGURED_HINT = ${JSON.stringify(locationHint ?? null)};
|
|
119
|
+
let placement;
|
|
120
|
+
|
|
102
121
|
export default {
|
|
103
122
|
fetch(request) {
|
|
104
123
|
return withDocument(request, (request) => {
|
|
124
|
+
if (!placement) {
|
|
125
|
+
const hint = CONFIGURED_HINT ?? locationHintForDatabase(env.DATABASE_URL);
|
|
126
|
+
placement = { name: durableServerName(hint), options: hint ? { locationHint: hint } : {} };
|
|
127
|
+
}
|
|
105
128
|
const servers = env.${DURABLE_SERVER_BINDING};
|
|
106
|
-
|
|
107
|
-
return server.fetch(request);
|
|
129
|
+
return servers.get(servers.idFromName(placement.name), placement.options).fetch(request);
|
|
108
130
|
});
|
|
109
131
|
},
|
|
110
132
|
};
|
package/dist/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAgB7D,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAA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AC,KAAK,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,YAAY,EACZ,GAAG,QAAQ,EACY;IACvB,OAAO;;EAEP,cAAc,CAAC,QAAQ,CAAC;;EAExB,uBAAuB,CAAC,QAAQ,EAAE;;EAElC,iBAAiB,CAAC,QAAQ,EAAE;;0BAEJ,IAAI,CAAC,SAAS,CAAC,YAAY,IAAI,IAAI,CAAC;;;;;;;;;;4BAUlC,sBAAsB;;;;;CAKjD,CAAC;AACF,CAAC;AASD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,WAAW,EACX,gBAAgB,EAChB,aAAa,GACQ;IACrB,OAAO;EACP,gBAAgB,CAAC,CAAC,CAAC,yDAAyD,CAAC,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;sBACxI,uBAAuB;;;;+BAId,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;;;;;;eAM3C,oBAAoB;EACjC,gBAAgB,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,EAAE;MACnE,gBAAgB,CAAC,CAAC,CAAC,yEAAyE,CAAC,CAAC,CAAC,uDAAuD;;;CAG3J,CAAC;AACF,CAAC","sourcesContent":["import { UNROUTED_HEADER } from \"@parlor/agent-ui\";\n\nimport { locationHintForDatabase } from \"./location-hint.js\";\n\nexport interface RenderEntryOptions {\n /** The module `parlor build` built from `web.ssr`, exporting `render`. */\n readonly module: string;\n /** The page policy with `{nonce}` in `script-src`, replaced per response. */\n readonly contentSecurityPolicy: string;\n}\n\nexport interface EntryOptions {\n readonly serverEntry: string;\n readonly basePath: string;\n readonly contentSecurityPolicy: string;\n readonly render?: RenderEntryOptions | undefined;\n}\n\nexport const NONCE_PLACEHOLDER = \"{nonce}\";\n\nexport const INDEX_HTML_PLACEHOLDER = \"__PARLOR_INDEX_HTML__\";\nexport const UI_MANIFEST_PLACEHOLDER = \"__PARLOR_UI_MANIFEST__\";\nexport const PAGE_ROUTES_PLACEHOLDER = \"__PARLOR_PAGE_ROUTES__\";\n\nexport const DURABLE_SERVER_BINDING = \"PARLOR_SERVER\";\nexport const DURABLE_SERVER_CLASS = \"ParlorServer\";\n\ntype DocumentOptions = Pick<\n EntryOptions,\n \"basePath\" | \"contentSecurityPolicy\" | \"render\"\n>;\n\n/** Imported on the first page it renders, keeping the app's pages out of the server's startup. */\nconst renderSource = (render: RenderEntryOptions | undefined) =>\n render\n ? `let rendering;\nconst loadRender = () => (rendering ??= import(${JSON.stringify(render.module)}).then((module) => module.render));\nconst RENDERED_POLICY = ${JSON.stringify(render.contentSecurityPolicy)};\n\nfunction createNonce() {\n return btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(16))));\n}\n\nasync function renderPage(request, serve) {\n const nonce = createNonce();\n try {\n const page = await (await loadRender())(request, { template: INDEX_HTML, fetch: serve, nonce });\n if (!page) return undefined;\n const response = new Response(page.body, page);\n response.headers.set(\"content-security-policy\", RENDERED_POLICY.replace(${JSON.stringify(NONCE_PLACEHOLDER)}, nonce));\n if (!response.headers.has(\"cache-control\")) response.headers.set(\"cache-control\", \"private, no-cache\");\n return response;\n } catch (error) {\n console.error(\\`[parlor] Rendering \\${request.url} on the server failed, so it is served without:\\`, error);\n return undefined;\n }\n}`\n : \"const renderPage = async () => undefined;\";\n\n/**\n * A page route's document is rendered on the server when its routes opt in, and is\n * `index.html` otherwise, without asking the app. Any other request goes to the app, and a\n * browser gets the document only when no route of the app's matches either.\n */\nconst documentSource = ({\n basePath,\n contentSecurityPolicy,\n render,\n}: DocumentOptions) => `const INDEX_HTML = ${INDEX_HTML_PLACEHOLDER};\nconst PAGE_ROUTES = ${PAGE_ROUTES_PLACEHOLDER};\nconst BASE_PATH = ${JSON.stringify(basePath)};\nconst DOCUMENT_HEADERS = {\n \"content-type\": \"text/html; charset=utf-8\",\n \"cache-control\": \"no-cache\",\n \"content-security-policy\": ${JSON.stringify(contentSecurityPolicy)},\n};\n\n${renderSource(render)}\n\nfunction wantsDocument(request, path) {\n if (!INDEX_HTML || request.method !== \"GET\" || path.startsWith(BASE_PATH)) return false;\n return (request.headers.get(\"accept\") ?? \"\").includes(\"text/html\");\n}\n\nasync function withDocument(request, serve) {\n const { pathname } = new URL(request.url);\n if (INDEX_HTML && pathname === \"/index.html\") {\n return new Response(INDEX_HTML, { headers: DOCUMENT_HEADERS });\n }\n const document = wantsDocument(request, pathname);\n if (document && PAGE_ROUTES.some((page) => page.test(pathname))) {\n return (await renderPage(request, serve)) ?? new Response(INDEX_HTML, { headers: DOCUMENT_HEADERS });\n }\n const response = await serve(request);\n if (!document || response.status !== 404 || !response.headers.has(${JSON.stringify(UNROUTED_HEADER)})) {\n return response;\n }\n await response.body?.cancel();\n return new Response(INDEX_HTML, { headers: DOCUMENT_HEADERS });\n}`;\n\nexport function hostEntrySource({ serverEntry, ...document }: EntryOptions): string {\n return `import app from ${JSON.stringify(serverEntry)};\n\nconst UI_MANIFEST = ${UI_MANIFEST_PLACEHOLDER};\n${documentSource(document)}\n\napp.installUiManifest?.(() => UI_MANIFEST);\n\nfor (const signal of [\"SIGINT\", \"SIGTERM\"]) {\n globalThis.process?.once?.(signal, async () => {\n try {\n await app.close?.();\n } catch (error) {\n console.error(\"[parlor] shutdown failed:\", error);\n }\n process.kill(process.pid, signal);\n });\n}\n\nexport default {\n fetch(request) {\n return withDocument(request, (request) => app.fetch(request));\n },\n};\n`;\n}\n\nexport interface CloudflareEntryOptions extends DocumentOptions {\n readonly locationHint?: string | undefined;\n}\n\n/**\n * The Durable Object's name. A hint only places an object when it is first created, so the\n * name follows the hint: setting or changing it starts the server where it says. The server\n * keeps nothing in the object's own storage, so the new one starts complete.\n */\nexport function durableServerName(locationHint: string | undefined): string {\n return locationHint ? `app@${locationHint}` : \"app\";\n}\n\n/**\n * The stateless Worker: documents here, everything else to the one Durable Object, started\n * beside the database. The configured hint wins; without one, the region `DATABASE_URL` names.\n */\nexport function cloudflareEntrySource({\n locationHint,\n ...document\n}: CloudflareEntryOptions): string {\n return `import { env } from \"cloudflare:workers\";\n\n${documentSource(document)}\n\n${locationHintForDatabase.toString()}\n\n${durableServerName.toString()}\n\nconst CONFIGURED_HINT = ${JSON.stringify(locationHint ?? null)};\nlet placement;\n\nexport default {\n fetch(request) {\n return withDocument(request, (request) => {\n if (!placement) {\n const hint = CONFIGURED_HINT ?? locationHintForDatabase(env.DATABASE_URL);\n placement = { name: durableServerName(hint), options: hint ? { locationHint: hint } : {} };\n }\n const servers = env.${DURABLE_SERVER_BINDING};\n return servers.get(servers.idFromName(placement.name), placement.options).fetch(request);\n });\n },\n};\n`;\n}\n\nexport interface DurableServerOptions {\n readonly serverEntry: string;\n readonly connectionScopes: boolean;\n /** The app's own Worker exports, such as its Durable Object classes. */\n readonly workerExports?: string | undefined;\n}\n\n/**\n * The app's server, imported on the Durable Object's first request: workerd allows no I/O\n * or timers while a module loads, and server.ts may await its database at the top level.\n */\nexport function durableServerSource({\n serverEntry,\n connectionScopes,\n workerExports,\n}: DurableServerOptions): string {\n return `import { DurableObject } from \"cloudflare:workers\";\n${connectionScopes ? 'import { createConnectionScope } from \"@parlor/data\";\\n' : \"\"}${workerExports ? `export * from ${JSON.stringify(workerExports)};\\n` : \"\"}\nconst UI_MANIFEST = ${UI_MANIFEST_PLACEHOLDER};\n\nlet loading;\nfunction app() {\n return (loading ??= import(${JSON.stringify(serverEntry)}).then(({ default: server }) => {\n server.installUiManifest?.(() => UI_MANIFEST);\n return server;\n }));\n}\n\nexport class ${DURABLE_SERVER_CLASS} extends DurableObject {\n${connectionScopes ? \" #connections = createConnectionScope();\\n\\n\" : \"\"} fetch(request) {\n ${connectionScopes ? \"return this.#connections.run(async () => (await app()).fetch(request));\" : \"return app().then((server) => server.fetch(request));\"}\n }\n}\n`;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildServer, devWranglerConfig, type DevWranglerConfig, hostRootDir, type ServerBuildOptions, type ServerBuildResult, SYNC_TRANSPORT_ENV, type UnavailableDurableObject, } from "./build.js";
|
|
1
|
+
export { buildServer, devWranglerConfig, type DevWranglerConfig, hostRootDir, nitroCli, type ServerBuildOptions, type ServerBuildResult, SYNC_TRANSPORT_ENV, type UnavailableDurableObject, } from "./build.js";
|
|
2
2
|
export { type EntryOptions, hostEntrySource, INDEX_HTML_PLACEHOLDER, type RenderEntryOptions, UI_MANIFEST_PLACEHOLDER, } from "./entry.js";
|
|
3
3
|
export { DEPLOY_PRESETS, type DeployPreset, detectCiPreset, isDeployPreset, nitroPresetFor, PresetError, renderConditionsFor, resolvePreset, syncTransportFor, } from "./presets.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,YAAY,EACjB,eAAe,EACf,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,KAAK,YAAY,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,WAAW,EACX,QAAQ,EACR,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,YAAY,EACjB,eAAe,EACf,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,KAAK,YAAY,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildServer, devWranglerConfig, hostRootDir, SYNC_TRANSPORT_ENV, } from "./build.js";
|
|
1
|
+
export { buildServer, devWranglerConfig, hostRootDir, nitroCli, SYNC_TRANSPORT_ENV, } from "./build.js";
|
|
2
2
|
export { hostEntrySource, INDEX_HTML_PLACEHOLDER, UI_MANIFEST_PLACEHOLDER, } from "./entry.js";
|
|
3
3
|
export { DEPLOY_PRESETS, detectCiPreset, isDeployPreset, nitroPresetFor, PresetError, renderConditionsFor, resolvePreset, syncTransportFor, } from "./presets.js";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,WAAW,EACX,QAAQ,EAGR,kBAAkB,GAEnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,eAAe,EACf,sBAAsB,EAEtB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EAEd,cAAc,EACd,cAAc,EACd,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAC","sourcesContent":["export {\n buildServer,\n devWranglerConfig,\n type DevWranglerConfig,\n hostRootDir,\n nitroCli,\n type ServerBuildOptions,\n type ServerBuildResult,\n SYNC_TRANSPORT_ENV,\n type UnavailableDurableObject,\n} from \"./build.js\";\nexport {\n type EntryOptions,\n hostEntrySource,\n INDEX_HTML_PLACEHOLDER,\n type RenderEntryOptions,\n UI_MANIFEST_PLACEHOLDER,\n} from \"./entry.js\";\nexport {\n DEPLOY_PRESETS,\n type DeployPreset,\n detectCiPreset,\n isDeployPreset,\n nitroPresetFor,\n PresetError,\n renderConditionsFor,\n resolvePreset,\n syncTransportFor,\n} from \"./presets.js\";\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cloudflare location hint for a Postgres connection string, read off the cloud region
|
|
3
|
+
* its host names (Neon `ep-x.ap-southeast-1.aws.neon.tech`, Supabase, RDS, GCP, Azure), so
|
|
4
|
+
* the Durable Object starts beside the database. Undefined for a host that names no region.
|
|
5
|
+
*
|
|
6
|
+
* Self-contained: the Worker entry embeds its source.
|
|
7
|
+
*/
|
|
8
|
+
export declare function locationHintForDatabase(url: string | undefined): string | undefined;
|
|
9
|
+
//# sourceMappingURL=location-hint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location-hint.d.ts","sourceRoot":"","sources":["../src/location-hint.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CA8CnF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cloudflare location hint for a Postgres connection string, read off the cloud region
|
|
3
|
+
* its host names (Neon `ep-x.ap-southeast-1.aws.neon.tech`, Supabase, RDS, GCP, Azure), so
|
|
4
|
+
* the Durable Object starts beside the database. Undefined for a host that names no region.
|
|
5
|
+
*
|
|
6
|
+
* Self-contained: the Worker entry embeds its source.
|
|
7
|
+
*/
|
|
8
|
+
export function locationHintForDatabase(url) {
|
|
9
|
+
let host;
|
|
10
|
+
try {
|
|
11
|
+
host = new URL(url ?? "").hostname.toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const aws = /(?:^|[.-])(us|ca|sa|eu|me|af|ap)-([a-z]+)-(\d)(?:[.-]|$)/.exec(host);
|
|
17
|
+
if (aws) {
|
|
18
|
+
const [, area, direction, number] = aws;
|
|
19
|
+
if (area === "us")
|
|
20
|
+
return direction === "west" ? "wnam" : "enam";
|
|
21
|
+
if (area === "ca")
|
|
22
|
+
return "enam";
|
|
23
|
+
if (area === "sa")
|
|
24
|
+
return "sam";
|
|
25
|
+
if (area === "eu")
|
|
26
|
+
return "weur";
|
|
27
|
+
if (area === "me")
|
|
28
|
+
return "me";
|
|
29
|
+
if (area === "af")
|
|
30
|
+
return "afr";
|
|
31
|
+
return direction === "southeast" && (number === "2" || number === "4")
|
|
32
|
+
? "oc"
|
|
33
|
+
: "apac";
|
|
34
|
+
}
|
|
35
|
+
const gcp = /(?:^|[.-])(us|northamerica|southamerica|europe|asia|australia|me|africa)-([a-z]+)\d(?:[.-]|$)/.exec(host);
|
|
36
|
+
if (gcp) {
|
|
37
|
+
const [, area, direction] = gcp;
|
|
38
|
+
if (area === "us")
|
|
39
|
+
return direction === "west" ? "wnam" : "enam";
|
|
40
|
+
if (area === "northamerica")
|
|
41
|
+
return "enam";
|
|
42
|
+
if (area === "southamerica")
|
|
43
|
+
return "sam";
|
|
44
|
+
if (area === "europe")
|
|
45
|
+
return "weur";
|
|
46
|
+
if (area === "asia")
|
|
47
|
+
return "apac";
|
|
48
|
+
if (area === "australia")
|
|
49
|
+
return "oc";
|
|
50
|
+
if (area === "me")
|
|
51
|
+
return "me";
|
|
52
|
+
return "afr";
|
|
53
|
+
}
|
|
54
|
+
const azure = /(?:^|\.)(eastus2?|centralus|westus[23]?|westeurope|northeurope|germanywestcentral|uksouth|eastasia|southeastasia|japaneast|australiaeast)\./.exec(host);
|
|
55
|
+
if (!azure)
|
|
56
|
+
return undefined;
|
|
57
|
+
const region = azure[1];
|
|
58
|
+
if (region.startsWith("west") && region.includes("us"))
|
|
59
|
+
return "wnam";
|
|
60
|
+
if (region.includes("us"))
|
|
61
|
+
return "enam";
|
|
62
|
+
if (region.includes("asia") || region === "japaneast")
|
|
63
|
+
return "apac";
|
|
64
|
+
if (region === "australiaeast")
|
|
65
|
+
return "oc";
|
|
66
|
+
return "weur";
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=location-hint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location-hint.js","sourceRoot":"","sources":["../src/location-hint.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAuB;IAC7D,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,GAAG,GAAG,0DAA0D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClF,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC;QACxC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QACjE,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QACjC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,KAAK,CAA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MAAM,CAAC;IACtE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IACzC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,KAAK,WAAW;QAAE,OAAO,MAAM,CAAC;IACrE,IAAI,MAAM,KAAK,eAAe;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * The Cloudflare location hint for a Postgres connection string, read off the cloud region\n * its host names (Neon `ep-x.ap-southeast-1.aws.neon.tech`, Supabase, RDS, GCP, Azure), so\n * the Durable Object starts beside the database. Undefined for a host that names no region.\n *\n * Self-contained: the Worker entry embeds its source.\n */\nexport function locationHintForDatabase(url: string | undefined): string | undefined {\n let host: string;\n try {\n host = new URL(url ?? \"\").hostname.toLowerCase();\n } catch {\n return undefined;\n }\n const aws = /(?:^|[.-])(us|ca|sa|eu|me|af|ap)-([a-z]+)-(\\d)(?:[.-]|$)/.exec(host);\n if (aws) {\n const [, area, direction, number] = aws;\n if (area === \"us\") return direction === \"west\" ? \"wnam\" : \"enam\";\n if (area === \"ca\") return \"enam\";\n if (area === \"sa\") return \"sam\";\n if (area === \"eu\") return \"weur\";\n if (area === \"me\") return \"me\";\n if (area === \"af\") return \"afr\";\n return direction === \"southeast\" && (number === \"2\" || number === \"4\")\n ? \"oc\"\n : \"apac\";\n }\n const gcp =\n /(?:^|[.-])(us|northamerica|southamerica|europe|asia|australia|me|africa)-([a-z]+)\\d(?:[.-]|$)/.exec(\n host,\n );\n if (gcp) {\n const [, area, direction] = gcp;\n if (area === \"us\") return direction === \"west\" ? \"wnam\" : \"enam\";\n if (area === \"northamerica\") return \"enam\";\n if (area === \"southamerica\") return \"sam\";\n if (area === \"europe\") return \"weur\";\n if (area === \"asia\") return \"apac\";\n if (area === \"australia\") return \"oc\";\n if (area === \"me\") return \"me\";\n return \"afr\";\n }\n const azure =\n /(?:^|\\.)(eastus2?|centralus|westus[23]?|westeurope|northeurope|germanywestcentral|uksouth|eastasia|southeastasia|japaneast|australiaeast)\\./.exec(\n host,\n );\n if (!azure) return undefined;\n const region = azure[1]!;\n if (region.startsWith(\"west\") && region.includes(\"us\")) return \"wnam\";\n if (region.includes(\"us\")) return \"enam\";\n if (region.includes(\"asia\") || region === \"japaneast\") return \"apac\";\n if (region === \"australiaeast\") return \"oc\";\n return \"weur\";\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parlor/host",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"homepage": "https://cychien.github.io/parlor",
|
|
5
5
|
"bugs": "https://github.com/cychien/parlor/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"drizzle-orm": "^0.45.4",
|
|
24
24
|
"nitro": "3.0.260903-beta",
|
|
25
|
-
"@parlor/
|
|
26
|
-
"@parlor/shell-web": "0.3.
|
|
27
|
-
"@parlor/
|
|
25
|
+
"@parlor/agent-ui": "0.3.2",
|
|
26
|
+
"@parlor/shell-web": "0.3.2",
|
|
27
|
+
"@parlor/config": "0.3.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@tanstack/react-query": "^5.104.1",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"typescript": "^7.0.2",
|
|
36
36
|
"vitest": "^5.0.3",
|
|
37
37
|
"wrangler": "^4.152.0",
|
|
38
|
-
"@parlor/
|
|
39
|
-
"@parlor/
|
|
40
|
-
"@parlor/
|
|
41
|
-
"@parlor/
|
|
38
|
+
"@parlor/core": "0.3.2",
|
|
39
|
+
"@parlor/client": "0.3.2",
|
|
40
|
+
"@parlor/server": "0.3.2",
|
|
41
|
+
"@parlor/data": "0.3.2"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsc -p tsconfig.json",
|