{"version":3,"file":"export-types-CVGw8Hno.mjs","names":[],"sources":["../../src/module-runner/constants.shared.ts","../../src/export-types.ts"],"sourcesContent":["export const INIT_PATH = \"/__vite_module_runner/init\";\nexport const ENVIRONMENT_NAME_HEADER = \"distilled-environment-name\";\nexport const WORKER_ENTRY_PATH_HEADER = \"distilled-worker-entry-path\";\n\n/**\n * Sent by the dev server over the module runner WebSocket to ask the Worker to\n * evaluate the entry module and classify its exports. The reply comes back as\n * {@link EXPORT_TYPES_EVENT}.\n *\n * This runs over the module runner channel rather than an HTTP endpoint so it\n * cannot be intercepted by the asset router that sits in front of the Worker.\n */\nexport const REQUEST_EXPORT_TYPES_EVENT = \"distilled-cloudflare:request-export-types\";\n\n/** Reply to {@link REQUEST_EXPORT_TYPES_EVENT}, carrying an `ExportTypes` payload. */\nexport const EXPORT_TYPES_EVENT = \"distilled-cloudflare:export-types\";\n\nexport interface EntryEnvironment {\n  environmentName: string;\n  entryId: string;\n  entryName: string;\n  /** Id of the virtual module that classifies the entry module's exports. */\n  exportTypesId: string;\n}\n","import type {\n  ExportType,\n  ExportTypes,\n} from \"@distilled.cloud/cloudflare-rolldown-plugin/export-types\";\nimport type { CloudflareVitePluginOptions } from \"./plugin.ts\";\n\nconst WRAPPER_FACTORIES = {\n  DurableObject: \"createDurableObjectWrapper\",\n  WorkerEntrypoint: \"createWorkerEntrypointWrapper\",\n  WorkflowEntrypoint: \"createWorkflowEntrypointWrapper\",\n} satisfies Record<ExportType, string>;\n\nconst IDENTIFIER_REGEX = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\n/**\n * Names the generated Worker entry already uses, and which therefore cannot be\n * taken over by a user export.\n */\nconst RESERVED_EXPORT_NAMES = new Set([\"default\", \"ModuleRunnerDO\"]);\n\n/**\n * The export types that follow from the plugin options alone.\n *\n * Durable Object and Workflow classes have to be declared up front because\n * workerd needs their namespaces at startup, so they are known before the entry\n * module has ever been evaluated. Named entrypoints have no such declaration\n * and can only be discovered by classifying the entry's exports.\n */\nexport function configuredExportTypes(options: CloudflareVitePluginOptions): ExportTypes {\n  const exportTypes: ExportTypes = {};\n  for (const namespace of options.worker?.durableObjectNamespaces ?? []) {\n    exportTypes[namespace.className] = \"DurableObject\";\n  }\n  for (const workflow of options.worker?.workflows ?? []) {\n    exportTypes[workflow.className] = \"WorkflowEntrypoint\";\n  }\n  return exportTypes;\n}\n\n/**\n * Combines detected export types with the configured ones. Configuration wins:\n * a class declared as a Durable Object namespace must be wrapped as one even if\n * it is momentarily broken and classifies as something else.\n */\nexport function mergeExportTypes(configured: ExportTypes, detected: ExportTypes): ExportTypes {\n  return { ...detected, ...configured };\n}\n\n/**\n * Renders the wrapper exports for the generated Worker entry.\n *\n * An export whose name is not a valid identifier (`export { x as \"a-b\" }`)\n * cannot be re-exported by the wrapper module, so it is skipped rather than\n * emitting a module that fails to parse.\n */\nexport function renderExportWrappers(exportTypes: ExportTypes): Array<string> {\n  return Object.entries(exportTypes)\n    .filter(([name]) => IDENTIFIER_REGEX.test(name) && !RESERVED_EXPORT_NAMES.has(name))\n    .map(([name, type]) => `export const ${name} = ${WRAPPER_FACTORIES[type]}(\"${name}\");`);\n}\n"],"mappings":";AAAA,MAAa,YAAY;AACzB,MAAa,0BAA0B;;;;;;;;;AAWvC,MAAa,6BAA6B;;AAG1C,MAAa,qBAAqB;;;ACTlC,MAAM,oBAAoB;CACxB,eAAe;CACf,kBAAkB;CAClB,oBAAoB;AACtB;AAEA,MAAM,mBAAmB;;;;;AAMzB,MAAM,wCAAwB,IAAI,IAAI,CAAC,WAAW,gBAAgB,CAAC;;;;;;;;;AAUnE,SAAgB,sBAAsB,SAAmD;CACvF,MAAM,cAA2B,CAAC;CAClC,KAAK,MAAM,aAAa,QAAQ,QAAQ,2BAA2B,CAAC,GAClE,YAAY,UAAU,aAAa;CAErC,KAAK,MAAM,YAAY,QAAQ,QAAQ,aAAa,CAAC,GACnD,YAAY,SAAS,aAAa;CAEpC,OAAO;AACT;;;;;;AAOA,SAAgB,iBAAiB,YAAyB,UAAoC;CAC5F,OAAO;EAAE,GAAG;EAAU,GAAG;CAAW;AACtC;;;;;;;;AASA,SAAgB,qBAAqB,aAAyC;CAC5E,OAAO,OAAO,QAAQ,WAAW,CAAC,CAC/B,QAAQ,CAAC,UAAU,iBAAiB,KAAK,IAAI,KAAK,CAAC,sBAAsB,IAAI,IAAI,CAAC,CAAC,CACnF,KAAK,CAAC,MAAM,UAAU,gBAAgB,KAAK,KAAK,kBAAkB,MAAM,IAAI,KAAK,IAAI;AAC1F"}