{"version":3,"file":"application-BYlhYQyh.mjs","names":["sanitizePluginId","toCamelCase","toKebabCase","importExpr","callExpr","callExpr","callExpr","exportDecl","NAME_PATTERN","KEY_GRAMMAR","KEY_REGEX"],"sources":["../src/parser/app-config/log-level.ts","../src/cli/shared/parse-positive-int.ts","../src/cli/shared/apply-concurrency.ts","../src/cli/shared/error-diagnostics.ts","../src/cli/shared/client.ts","../src/cli/shared/plugin-import.ts","../src/cli/commands/generate/plugin-executor-generator.ts","../src/cli/commands/generate/plugin-table-generator.ts","../src/cli/cache/dep-collector-plugin.ts","../src/cli/cache/hasher.ts","../src/cli/cache/bundle-cache.ts","../src/cli/services/workflow/ast-utils.ts","../src/cli/services/workflow/sdk-binding-collector.ts","../src/cli/services/workflow/job-detector.ts","../src/cli/services/workflow/workflow-detector.ts","../src/cli/shared/start-context.ts","../src/cli/services/workflow/start-transformer.ts","../src/utils/node-builtins.ts","../src/cli/shared/bundle-log.ts","../src/cli/shared/bundle-log-level.ts","../src/cli/shared/function-treeshake.ts","../src/cli/shared/platform-bundle-plugin.ts","../src/cli/shared/resolve-tsconfig.ts","../src/cli/shared/tsconfig-paths-plugin.ts","../src/cli/shared/virtual-entry.ts","../src/cli/services/auth/bundler.ts","../src/utils/script-expr.ts","../src/parser/service/tailordb/hook-args-object.ts","../src/parser/service/tailordb/hooks-validate-precompiled-expr.ts","../src/parser/service/tailordb/field.ts","../src/parser/service/permission.ts","../src/parser/service/tailordb/permission.ts","../src/parser/service/tailordb/type-parser.ts","../src/cli/shared/free-variables.ts","../src/cli/services/tailordb/hooks-validate-bundler.ts","../src/cli/services/tailordb/type-name-validation.ts","../src/cli/services/tailordb/service.ts","../src/cli/services/auth/service.ts","../src/cli/shared/bundle-concurrency.ts","../src/cli/shared/forbidden-runtime-globals.ts","../src/cli/shared/runtime-exprs.ts","../src/cli/services/executor/bundler.ts","../src/parser/service/http-adapter/methods.ts","../src/parser/service/http-adapter/schema.ts","../src/cli/services/http-adapter/bundler.ts","../src/cli/services/http-adapter/service.ts","../src/parser/service/resolver/schema.ts","../src/cli/services/resolver/loader.ts","../src/cli/services/resolver/bundler.ts","../src/cli/services/resolver/default-permission.ts","../src/cli/services/resolver/service.ts","../src/cli/services/workflow/source-transformer.ts","../src/cli/services/workflow/bundler.ts","../../shared/src/workflow-policy.ts","../src/parser/service/workflow/schema.ts","../src/cli/services/workflow/service.ts","../src/cli/shared/auth-namespace.ts","../src/cli/shared/dist-dir.ts","../src/cli/shared/inline-sourcemap.ts","../src/cli/shared/resolver-bundle-key.ts","../src/parser/service/aigateway/schema.ts","../src/parser/service/idp/email-domains.ts","../src/parser/service/idp/schema.ts","../src/parser/service/secrets/schema.ts","../src/parser/service/staticwebsite/schema.ts","../src/parser/service/workflow/wait-point-key.ts","../src/cli/services/application.ts"],"sourcesContent":["export const LOG_LEVELS = [\"DEBUG\", \"INFO\", \"WARN\", \"ERROR\", \"SILENT\"] as const;\n\nexport function isLogLevel(value: string): value is (typeof LOG_LEVELS)[number] {\n  return (LOG_LEVELS as readonly string[]).includes(value);\n}\n","const POSITIVE_INT_PATTERN = /^\\d*[1-9]\\d*$/;\n\n/**\n * Parse a string value as a positive integer.\n *\n * Only decimal digits are accepted (leading zeros allowed), so `0`, negative\n * numbers, decimals, exponent notation, and signed values are all rejected.\n * Values above `Number.MAX_SAFE_INTEGER` are rejected too: past that point the\n * parsed number no longer represents the digits it came from, so it cannot\n * describe a meaningful limit.\n *\n * Undefined, empty strings, and unrecognized values return `undefined` so\n * that callers can fall back to their own defaults.\n * @param value - The input string (e.g. an environment variable or CLI flag value)\n * @returns The parsed integer, or `undefined` when the value is unset or unrecognized\n */\nexport function parsePositiveInt(value: string | undefined): number | undefined {\n  if (value === undefined) return undefined;\n  const normalized = value.trim();\n  if (!POSITIVE_INT_PATTERN.test(normalized)) return undefined;\n  const parsed = Number.parseInt(normalized, 10);\n  return Number.isSafeInteger(parsed) ? parsed : undefined;\n}\n","import pLimit from \"p-limit\";\nimport { parsePositiveInt } from \"./parse-positive-int\";\n\n/**\n * Default cap on concurrent operator RPCs when `TAILOR_APPLY_CONCURRENCY` is\n * unset. Chosen to tame the create burst (a fresh workspace fires one\n * `create*` per resource at once) that triggers the platform-side\n * `already_exists` race on compound creates, while still deploying quickly.\n */\nconst DEFAULT_APPLY_CONCURRENCY = 16;\n\n/**\n * Resolve the maximum number of operator RPCs to run in parallel.\n *\n * Resolution order:\n * 1. `TAILOR_APPLY_CONCURRENCY` env var (positive integer)\n * 2. `DEFAULT_APPLY_CONCURRENCY`\n *\n * A fresh-workspace apply creates every resource at once; firing all of them\n * concurrently overloads the platform, whose responses then come back as\n * `Unavailable`/`ResourceExhausted` and drive retries into the non-idempotent\n * compound-create `already_exists` race. Capping bounds the worst case.\n *\n * This is unrelated to the streaming-upload connection pool (see\n * `createPooledStreamTransport` in `client.ts`), which uses its own smaller,\n * internal connection cap: upload concurrency varies independently by call\n * site (e.g. static website deploys upload with their own fixed concurrency),\n * so this budget can't be assumed to bound how many uploads run at once.\n * @returns Concurrency cap (always >= 1)\n */\nexport function resolveApplyConcurrency(): number {\n  return parsePositiveInt(process.env.TAILOR_APPLY_CONCURRENCY) ?? DEFAULT_APPLY_CONCURRENCY;\n}\n\n/**\n * Create a limiter capped at the resolved apply concurrency. The returned\n * function defers a task until a slot is free, then resolves with its result.\n *\n * Share a single instance across all RPCs that should contend for the same\n * budget (e.g. one per operator client) so the cap bounds total in-flight\n * calls, not per-call-site bursts.\n * @returns A limiter that defers tasks beyond the concurrency cap\n */\nexport function createApplyLimiter(): <R>(task: () => Promise<R>) => Promise<R> {\n  return pLimit(resolveApplyConcurrency());\n}\n\n/**\n * Comparator that orders `name`-bearing items by `name`, for a stable,\n * reproducible apply order within the concurrency cap.\n *\n * Uses a code-point comparison rather than `localeCompare` so the order does\n * not depend on the runtime's default locale/collation.\n * @param a - Left item\n * @param b - Right item\n * @returns Negative, zero, or positive per code-point ordering of the names\n */\nexport function byName(a: { name: string }, b: { name: string }): number {\n  if (a.name < b.name) return -1;\n  if (a.name > b.name) return 1;\n  return 0;\n}\n","import { Code, ConnectError } from \"@connectrpc/connect\";\nimport type { Jsonifiable } from \"type-fest\";\n\n/** Where a failure originated, for tooling that links to source. */\nexport interface ErrorSourceLocation {\n  /** Absolute path to the file the failure points at. */\n  file: string;\n  /** 1-based line within `file`. */\n  line?: number;\n}\n\ninterface ErrorDiagnostics {\n  code?: string;\n  suggestion?: string;\n  context?: Readonly<Record<string, Jsonifiable | undefined>>;\n  causes?: Readonly<Record<string, unknown>>;\n  location?: ErrorSourceLocation;\n}\n\nconst diagnostics = new WeakMap<Error, ErrorDiagnostics>();\n\n/**\n * Attach output diagnostics without changing the error type used by callers.\n * @param error - Original error\n * @param details - Safe diagnostic fields supplied by the producer\n * @returns Original error\n */\nexport function withErrorDiagnostics<T extends Error>(error: T, details: ErrorDiagnostics): T {\n  diagnostics.set(error, { ...diagnostics.get(error), ...details });\n  return error;\n}\n\n/**\n * Read producer diagnostics and recovery guidance for a failure.\n * @param error - Failure being rendered\n * @returns Diagnostic fields\n */\nexport function getErrorDiagnostics(error: Error): ErrorDiagnostics {\n  return {\n    ...(error instanceof ConnectError ? { suggestion: rpcSuggestion(error.code) } : {}),\n    ...diagnostics.get(error),\n  };\n}\n\nfunction rpcSuggestion(code: Code): string | undefined {\n  switch (code) {\n    case Code.Unauthenticated:\n      return \"Check the active token and profile with `tailor auth status` (include the same --profile option). For an environment token, replace TAILOR_PLATFORM_TOKEN; otherwise use the original browser or --machine-user login method with the same profile. See `tailor login --help`.\";\n    case Code.PermissionDenied:\n      return \"Check the active identity and profile with `tailor auth status` (include the same --profile option), then verify its workspace role and token permissions.\";\n    case Code.Unavailable:\n    case Code.DeadlineExceeded:\n      return \"Check network connectivity and platform availability. A write may already have completed; inspect the current resource state before retrying.\";\n    default:\n      return undefined;\n  }\n}\n","import { OAuth2Client } from \"@badgateway/oauth2-client\";\nimport { create } from \"@bufbuild/protobuf\";\nimport { MethodOptions_IdempotencyLevel } from \"@bufbuild/protobuf/wkt\";\nimport {\n  type Client,\n  Code,\n  ConnectError,\n  createClient,\n  type Interceptor,\n  type StreamResponse,\n  type Transport,\n  type UnaryResponse,\n} from \"@connectrpc/connect\";\nimport { z } from \"zod\";\nimport { createApplyLimiter } from \"./apply-concurrency\";\nimport { withErrorDiagnostics } from \"./error-diagnostics\";\nimport { logger } from \"./logger\";\nimport { parseBoolean } from \"./parse-boolean\";\nimport { userAgent } from \"./user-agent\";\nimport type { OperatorService } from \"@tailor-platform/tailor-proto/service_pb\";\n\nexport const defaultPlatformBaseUrl = \"https://api.tailor.tech\";\nexport const defaultConsoleBaseUrl = \"https://console.tailor.tech\";\n\nconst defaultOAuth2ClientId = \"cpoc_0Iudir72fqSpqC6GQ58ri1cLAqcq5vJl\";\nconst oauth2DiscoveryEndpoint = \"/.well-known/oauth-authorization-server/oauth2/platform\";\n\nexport type PlatformClientConfig = {\n  platformUrl?: string;\n  oauth2ClientId?: string;\n  consoleUrl?: string;\n};\n\nconst tokenPlatformConfigs = new Map<string, PlatformClientConfig>();\n\nfunction getEnvPlatformUrl(): string | undefined {\n  return process.env.TAILOR_PLATFORM_URL ?? process.env.PLATFORM_URL;\n}\n\nfunction getEnvOAuth2ClientId(): string | undefined {\n  return process.env.TAILOR_PLATFORM_OAUTH2_CLIENT_ID ?? process.env.PLATFORM_OAUTH2_CLIENT_ID;\n}\n\nexport function normalizeBaseUrl(value: string): string {\n  const url = new URL(value);\n  url.hash = \"\";\n  url.search = \"\";\n  return url.toString().replace(/\\/$/, \"\");\n}\n\nexport function getEffectivePlatformConfig(config: PlatformClientConfig = {}) {\n  const platformUrl = config.platformUrl ?? getEnvPlatformUrl();\n  const oauth2ClientId = config.oauth2ClientId ?? getEnvOAuth2ClientId();\n  const consoleUrl = config.consoleUrl ?? process.env.TAILOR_PLATFORM_CONSOLE_URL;\n  const effective = {\n    ...(platformUrl ? { platformUrl } : {}),\n    ...(oauth2ClientId ? { oauth2ClientId } : {}),\n    ...(consoleUrl ? { consoleUrl } : {}),\n  };\n  return Object.keys(effective).length > 0 ? effective : undefined;\n}\n\nexport function rememberPlatformConfigForToken(accessToken: string, config?: PlatformClientConfig) {\n  const effectiveConfig = getEffectivePlatformConfig(config);\n  if (effectiveConfig) {\n    tokenPlatformConfigs.set(accessToken, effectiveConfig);\n  } else {\n    tokenPlatformConfigs.delete(accessToken);\n  }\n}\n\nfunction getPlatformConfigForToken(accessToken: string): PlatformClientConfig | undefined {\n  return tokenPlatformConfigs.get(accessToken);\n}\n\nexport function getPlatformBaseUrl(config: PlatformClientConfig = {}) {\n  return normalizeBaseUrl(config.platformUrl ?? getEnvPlatformUrl() ?? defaultPlatformBaseUrl);\n}\n\nexport function isDefaultPlatform(config?: PlatformClientConfig): boolean {\n  return getPlatformBaseUrl(config) === normalizeBaseUrl(defaultPlatformBaseUrl);\n}\n\nexport function getOAuth2ClientId(config: PlatformClientConfig = {}) {\n  return config.oauth2ClientId ?? getEnvOAuth2ClientId() ?? defaultOAuth2ClientId;\n}\n\nfunction inferConsoleBaseUrl(platformBaseUrl: string) {\n  const platformUrl = new URL(platformBaseUrl);\n  if (platformUrl.hostname.startsWith(\"api.\")) {\n    platformUrl.hostname = platformUrl.hostname.replace(/^api\\./, \"console.\");\n    return normalizeBaseUrl(platformUrl.toString());\n  }\n  return defaultConsoleBaseUrl;\n}\n\n/**\n * Redirect an inferred console URL to the console-next host when\n * `TAILOR_CONSOLE_NEXT` is enabled. An explicitly configured console URL\n * (`consoleUrl` / `TAILOR_PLATFORM_CONSOLE_URL`) is never rewritten.\n * @param consoleBaseUrl - Inferred console base URL\n * @returns The console-next base URL, or the input unchanged\n */\nfunction applyConsoleNext(consoleBaseUrl: string): string {\n  if (parseBoolean(process.env.TAILOR_CONSOLE_NEXT) !== true) return consoleBaseUrl;\n  const url = new URL(consoleBaseUrl);\n  url.hostname = url.hostname.replace(/^console\\./, \"console-next.\");\n  return normalizeBaseUrl(url.toString());\n}\n\nexport function getConsoleBaseUrl(config: PlatformClientConfig = {}) {\n  if (config.consoleUrl) return normalizeBaseUrl(config.consoleUrl);\n  if (config.platformUrl) {\n    const inferredUrl = inferConsoleBaseUrl(config.platformUrl);\n    if (inferredUrl !== defaultConsoleBaseUrl) return applyConsoleNext(inferredUrl);\n  }\n  if (process.env.TAILOR_PLATFORM_CONSOLE_URL)\n    return normalizeBaseUrl(process.env.TAILOR_PLATFORM_CONSOLE_URL);\n  return applyConsoleNext(inferConsoleBaseUrl(getPlatformBaseUrl(config)));\n}\n\n/**\n * Initialize an OAuth2 client for Tailor Platform.\n * @param config - Optional platform connection settings\n * @returns Configured OAuth2 client\n */\nexport function initOAuth2Client(config?: PlatformClientConfig) {\n  return new OAuth2Client({\n    clientId: getOAuth2ClientId(config),\n    server: getPlatformBaseUrl(config),\n    discoveryEndpoint: oauth2DiscoveryEndpoint,\n  });\n}\n\nexport type OperatorClient = Client<typeof OperatorService>;\n\n/**\n * Initialize an Operator client with the given access token.\n * @param accessToken - Access token for authentication\n * @param config - Optional platform connection settings\n * @returns Configured Operator client\n */\nexport async function initOperatorClient(accessToken: string, config?: PlatformClientConfig) {\n  const platformConfig = config ?? getPlatformConfigForToken(accessToken);\n  const [{ createTracingInterceptor }, { OperatorService }] = await Promise.all([\n    import(\"#/cli/telemetry/interceptor\"),\n    import(\"@tailor-platform/tailor-proto/service_pb\"),\n  ]);\n\n  const interceptors: Interceptor[] = [\n    await userAgentInterceptor(),\n    await bearerTokenInterceptor(accessToken),\n    retryInterceptor(),\n    errorHandlingInterceptor(),\n    createTracingInterceptor(),\n    // Innermost: gates the actual network attempt so each retry re-acquires a\n    // slot and backoff waits happen outside the cap.\n    concurrencyLimitInterceptor(),\n  ];\n\n  const baseUrl = getPlatformBaseUrl(platformConfig);\n  const primary = await createTransport(baseUrl, interceptors);\n  const transport = createPooledStreamTransport(\n    primary,\n    () => createTransport(baseUrl, interceptors),\n    UPLOAD_POOL_MAX_CONNECTIONS,\n  );\n  return createClient(OperatorService, transport);\n}\n\n/**\n * Create a Connect transport using connect-node (HTTP/2).\n *\n * connect-node works on both Node.js and Bun. connect-web is not used because\n * it does not support client_streaming, which is required for function uploads.\n * @param baseUrl - Base URL for the transport\n * @param interceptors - Request interceptors\n * @returns Configured transport\n */\nexport async function createTransport(\n  baseUrl: string,\n  interceptors: Interceptor[],\n): Promise<Transport> {\n  const { createConnectTransport } = await import(\"@connectrpc/connect-node\");\n  return createConnectTransport({ httpVersion: \"2\", baseUrl, interceptors });\n}\n\n/**\n * RPCs that upload a request body via client streaming and are affected by\n * the connection-pooling workaround below. Deliberately an allowlist rather\n * than `method.methodKind === \"client_streaming\"`: the workaround targets\n * outbound-DATA scheduling for uploads specifically, so a future streaming\n * RPC (client- or server-streaming) is routed to `primary` — unaffected and\n * unpooled — until someone consciously adds it here.\n *\n * A drift guard (see client.test.ts) fails CI if any `client_streaming`\n * OperatorService method is neither listed here nor explicitly exempt, so a\n * newly added client-streaming RPC can't silently bypass the pool by omission.\n * @internal\n */\nexport const POOLED_UPLOAD_METHODS: ReadonlySet<string> = new Set([\n  \"CreateFunctionRegistry\",\n  \"UpdateFunctionRegistry\",\n  \"UploadFile\",\n]);\n\n/**\n * Hard cap on the number of HTTP/2 connections `createPooledStreamTransport`\n * opens. Deliberately small and internal (not derived from\n * `TAILOR_APPLY_CONCURRENCY`, which bounds unrelated RPC concurrency and can\n * be set arbitrarily large by a user) rather than a public env var: the pool\n * now queues callers past this limit instead of relying on the caller never\n * exceeding it, so correctness does not depend on this exact number. Not\n * validated against production connection limits — kept conservative until\n * real-platform data says otherwise.\n * @internal\n */\nexport const UPLOAD_POOL_MAX_CONNECTIONS = 4;\n\n/**\n * Wrap a transport so upload RPCs (see `POOLED_UPLOAD_METHODS`) are spread\n * across a bounded pool of connections instead of sharing one. Unary calls,\n * and any streaming call not in `POOLED_UPLOAD_METHODS`, always use\n * `primary`, unaffected.\n *\n * Since Node 22.23.0/24.2.0, nghttp2 dropped its legacy priority-tree\n * scheduler. In our measurements this changed how Node's http2 client\n * schedules concurrent outbound DATA streams: uploads sharing one connection\n * can finish 12x+ apart in wall-clock time even though aggregate throughput\n * is unchanged, and there is no request header or API that opts a stream\n * into different client-side scheduling. Spreading uploads across\n * independent connections sidesteps that rather than fixing it; see this\n * change's changeset entry for the measurement.\n *\n * Acquiring a connection: reuse an idle one if any exists; otherwise open a\n * new one if the pool is below `maxConnections`; otherwise wait for a\n * connection to become idle. A connection is never reused for a second\n * concurrent upload while the pool still has room to grow or a caller is\n * waiting — at most one upload is ever in flight per connection, regardless\n * of how many uploads are requested concurrently or how they're divided\n * across call sites (independent limiters at different call sites no longer\n * need to agree on a shared concurrency cap for this invariant to hold).\n *\n * The caller's `signal` and `timeoutMs` are honored while an upload is\n * queued, not just once it's dispatched: an abort or an elapsed deadline\n * rejects the queued call immediately and frees its place in line without\n * consuming a pool slot, and time already spent queued is deducted from the\n * deadline passed to the underlying transport once a connection is acquired.\n * @internal\n * @param primary - Transport used for unary calls, non-upload streams, and as the first pool slot\n * @param createAdditional - Creates one more transport for the pool\n * @param maxConnections - Maximum number of connections in the pool (>= 1)\n * @returns A transport presenting the same interface, backed by the pool\n */\nexport function createPooledStreamTransport(\n  primary: Transport,\n  createAdditional: () => Promise<Transport>,\n  maxConnections: number,\n): Transport {\n  if (!Number.isInteger(maxConnections) || maxConnections < 1) {\n    throw new Error(\n      `createPooledStreamTransport: maxConnections must be a positive integer, got ${maxConnections}`,\n    );\n  }\n  const transports: Transport[] = [primary];\n  const idle: number[] = [0];\n  const waiters: Array<() => void> = [];\n  let pendingCreates = 0;\n\n  // Finds (or creates) a connection and marks it busy in the same\n  // synchronous step (no `await` in between) so that two `stream()` calls\n  // issued back to back (e.g. via `Promise.all(uploads.map(...))`, which\n  // starts each task synchronously) can't both claim the same idle\n  // transport before either marks it busy. Growth and waiting are the only\n  // async steps; every other transition (finding an idle slot, deciding to\n  // grow, waking a waiter) happens synchronously within one of these steps.\n  function acquireTransportIndex(\n    signal: AbortSignal | undefined,\n    deadline: number | undefined,\n  ): Promise<number> {\n    return new Promise<number>((resolve, reject) => {\n      let settled = false;\n      let timer: ReturnType<typeof setTimeout> | undefined;\n\n      function cleanup(): void {\n        settled = true;\n        clearTimeout(timer);\n        signal?.removeEventListener(\"abort\", onAbort);\n        const waiterIndex = waiters.indexOf(attempt);\n        if (waiterIndex !== -1) waiters.splice(waiterIndex, 1);\n      }\n\n      function onAbort(): void {\n        cleanup();\n        reject(ConnectError.from(signal?.reason, Code.Canceled));\n      }\n\n      function onTimeout(): void {\n        cleanup();\n        reject(new ConnectError(\"the operation timed out\", Code.DeadlineExceeded));\n      }\n\n      function claim(index: number): void {\n        if (settled) {\n          release(index);\n          return;\n        }\n        cleanup();\n        resolve(index);\n      }\n\n      function attempt(): void {\n        const idleIndex = idle.pop();\n        if (idleIndex !== undefined) {\n          claim(idleIndex);\n          return;\n        }\n        if (transports.length + pendingCreates < maxConnections) {\n          pendingCreates++;\n          createAdditional().then(\n            (transport) => {\n              pendingCreates--;\n              const index = transports.length;\n              transports.push(transport);\n              claim(index);\n            },\n            (error: unknown) => {\n              pendingCreates--;\n              cleanup();\n              reject(error instanceof Error ? error : new Error(String(error)));\n              // The failed connection never joins the pool, so a waiter\n              // stuck behind \"pool full\" would wait forever unless woken to\n              // retry (it may now see room to grow, or another release).\n              wakeOneWaiter();\n            },\n          );\n          return;\n        }\n        waiters.push(attempt);\n      }\n      if (signal?.aborted) {\n        onAbort();\n        return;\n      }\n      signal?.addEventListener(\"abort\", onAbort, { once: true });\n      if (deadline !== undefined) {\n        const remainingMs = deadline - performance.now();\n        if (remainingMs <= 0) {\n          onTimeout();\n          return;\n        }\n        timer = setTimeout(onTimeout, remainingMs);\n      }\n      attempt();\n    });\n  }\n\n  function wakeOneWaiter(): void {\n    waiters.shift()?.();\n  }\n\n  function release(index: number): void {\n    idle.push(index);\n    wakeOneWaiter();\n  }\n\n  return {\n    unary(method, signal, timeoutMs, header, input, contextValues) {\n      return primary.unary(method, signal, timeoutMs, header, input, contextValues);\n    },\n    async stream(method, signal, timeoutMs, header, input, contextValues) {\n      if (!POOLED_UPLOAD_METHODS.has(method.name)) {\n        return primary.stream(method, signal, timeoutMs, header, input, contextValues);\n      }\n      const deadline =\n        timeoutMs !== undefined && timeoutMs > 0 ? performance.now() + timeoutMs : undefined;\n      const index = await acquireTransportIndex(signal, deadline);\n      const transport = transports[index] as Transport;\n      let response: StreamResponse<typeof method.input, typeof method.output>;\n      try {\n        if (signal?.aborted) throw ConnectError.from(signal.reason, Code.Canceled);\n        const remainingMs =\n          deadline === undefined ? timeoutMs : Math.ceil(deadline - performance.now());\n        if (deadline !== undefined && remainingMs !== undefined && remainingMs <= 0) {\n          throw new ConnectError(\"the operation timed out\", Code.DeadlineExceeded);\n        }\n        response = await transport.stream(\n          method,\n          signal,\n          remainingMs,\n          header,\n          input,\n          contextValues,\n        );\n      } catch (error) {\n        release(index);\n        throw error;\n      }\n      // `stream()` resolves once response headers arrive, not once the\n      // response is fully read (or the request body fully sent) — connect's\n      // node http2 client starts writing the request body without waiting\n      // for it, and only awaits headers here. Keep the connection marked\n      // busy until the caller finishes reading `message`, so a connection\n      // isn't reused while this upload is still in flight.\n      return { ...response, message: releaseAfter(response.message, () => release(index)) };\n    },\n  };\n}\n\nasync function* releaseAfter<T>(iterable: AsyncIterable<T>, release: () => void): AsyncIterable<T> {\n  try {\n    yield* iterable;\n  } finally {\n    release();\n  }\n}\n\n/**\n * Create an interceptor that sets a User-Agent header.\n * @returns User-Agent interceptor\n */\nasync function userAgentInterceptor(): Promise<Interceptor> {\n  const ua = await userAgent();\n  return (next) => async (req) => {\n    req.header.set(\"User-Agent\", ua);\n    return await next(req);\n  };\n}\n\nexport { userAgent };\n\n/**\n * Create an interceptor that sets the Authorization bearer token.\n * @param accessToken - Access token to use\n * @returns Bearer token interceptor\n */\nasync function bearerTokenInterceptor(accessToken: string): Promise<Interceptor> {\n  return (next) => async (req) => {\n    req.header.set(\"Authorization\", `Bearer ${accessToken}`);\n    return await next(req);\n  };\n}\n\n/**\n * Create an interceptor that retries failed unary requests with backoff.\n *\n * Retries unary methods on `Unavailable`/`ResourceExhausted`, and\n * `Aborted`/`Internal` only for methods declared side-effect-free or idempotent,\n * up to 3 attempts. Workspace creation is excluded because it has no idempotency\n * key and a lost response is ambiguous.\n * As a targeted exception for the deploy/apply flow, a post-retry `AlreadyExists`\n * from an allowlisted Create (see `RETRY_SAFE_CREATE_METHODS`) is treated as\n * success, since it means a prior attempt already committed the resource\n * server-side. A first-attempt `AlreadyExists` from such a Create still\n * surfaces, but is routed to crash/error reporting first (the top-level handler\n * skips `ConnectError`), so the otherwise-silent compound-create race is\n * trackable.\n * @internal\n * @returns Retry interceptor\n */\nexport function retryInterceptor(): Interceptor {\n  return (next) => async (req) => {\n    if (req.stream) {\n      return await next(req);\n    }\n\n    let lastError: unknown;\n    for (let i = 0; i < MAX_RETRY_ATTEMPTS; i++) {\n      if (i > 0) {\n        await waitRetryBackoff(i);\n      }\n\n      try {\n        return await next(req);\n      } catch (error) {\n        // A retry that comes back AlreadyExists is treated as success: a prior\n        // attempt (the one whose retriable error sent us here) already created\n        // the resource server-side, but its response was lost as\n        // Unavailable/ResourceExhausted under load. The identical retry then\n        // races against that committed write and fails with `already_exists`.\n        // Restricted to RETRY_SAFE_CREATE_METHODS (deploy creates whose response\n        // body is unused) and to actual retries (i > 0).\n        if (isRetrySafeCreateAlreadyExists(error, req.method.name)) {\n          if (i > 0) {\n            logger.debug(\n              `retry: ${req.method.name} returned AlreadyExists on attempt ${i + 1}; ` +\n                `treating as success (prior attempt likely committed)`,\n            );\n            return synthesizeEmptyUnaryResponse(req);\n          }\n          // First-attempt AlreadyExists on a retry-safe create: no retry of ours\n          // preceded it, so the resource was committed out-of-band (a concurrent\n          // or non-idempotent compound create under load — #1350). The top-level\n          // handler skips ConnectError, so route it to error tracking here before\n          // letting it surface as the deploy error.\n          const { reportCrash } = await import(\"#/cli/crashreport/index\");\n          await reportCrash(error, \"handledError\");\n        }\n        if (req.method.name !== \"CreateWorkspace\" && isRetirable(error, req.method.idempotency)) {\n          lastError = error;\n          logger.debug(\n            `retry: ${req.method.name} attempt ${i + 1} failed with ` +\n              `${retryErrorCodeName(error)}; retrying`,\n          );\n          continue;\n        }\n        throw error;\n      }\n    }\n    throw lastError;\n  };\n}\n\n/**\n * Create an interceptor that caps the number of concurrent unary RPCs.\n *\n * A fresh-workspace apply fires one `create*` per resource at once; left\n * unbounded, the platform sheds load as `Unavailable`/`ResourceExhausted`,\n * which drives retries into the non-idempotent compound-create `already_exists`\n * race (#1350). One shared limiter per client bounds total in-flight calls\n * across every deploy resource, not just a single call site. Streaming RPCs\n * (e.g. function uploads) are not gated.\n * @internal\n * @returns Concurrency-limiting interceptor\n */\nexport function concurrencyLimitInterceptor(): Interceptor {\n  const limit = createApplyLimiter();\n  return (next) => async (req) => {\n    if (req.stream) {\n      return await next(req);\n    }\n    return await limit(() => next(req));\n  };\n}\n\n/**\n * Human-readable name for a retried error, for diagnostics.\n * @param error - Error thrown by a request (a ConnectError or a transport disconnect)\n * @returns The Connect Code name (e.g., \"Unavailable\"), the raw transport error code\n * (e.g., \"ECONNRESET\"), or \"unknown\" if neither applies\n */\nfunction retryErrorCodeName(error: unknown): string {\n  if (error instanceof ConnectError) return Code[error.code];\n  if (isTransportDisconnectError(error)) return error.code;\n  return \"unknown\";\n}\n\n/**\n * Create RPCs for which a post-retry `AlreadyExists` may be treated as success.\n *\n * Membership is deliberately an allowlist, not `startsWith(\"Create\")`: swallowing\n * synthesizes an empty response (see `synthesizeEmptyUnaryResponse`), which is only\n * safe when every caller tolerates an empty response body. These are the deploy/apply\n * resource creations that fire under heavy parallelism and discard their response —\n * except `CreateSecretManagerSecret`, whose caller reads `secret.updateTime` but\n * degrades safely when it is absent (the next deploy re-updates the secret).\n *\n * Intentionally excluded because their callers read the response body — swallowing\n * would hand back an empty message and corrupt downstream state:\n * - `CreateIdPClient` (uses `resp.client.clientSecret` to seed the secret vault)\n * - `CreateWorkflowJobFunction` (uses `response.jobFunction.version`)\n * - `CreateWorkspace` / `CreatePersonalAccessToken` / `CreateDeployment` /\n *   `CreateOrganizationFolder` (interactive commands that return created data)\n *\n * `CreateFunctionRegistry` is client-streaming and never reaches this path\n * (streaming requests bypass the retry loop entirely).\n *\n * An allowlist miss is safe: the resource simply loses race protection and an\n * `already_exists` surfaces loudly, as before — never a silent empty response.\n *\n * A drift guard (see client.test.ts) fails CI if any `client.create*` used in the\n * deploy flow is neither listed here nor explicitly classified as response-consuming,\n * so a newly added apply create cannot silently miss this list.\n * @internal\n */\nexport const RETRY_SAFE_CREATE_METHODS: ReadonlySet<string> = new Set([\n  \"CreateAIGateway\",\n  \"CreateApplication\",\n  \"CreateAuthConnection\",\n  \"CreateAuthHook\",\n  \"CreateAuthIDPConfig\",\n  \"CreateAuthMachineUser\",\n  \"CreateAuthOAuth2Client\",\n  \"CreateAuthSCIMConfig\",\n  \"CreateAuthSCIMResource\",\n  \"CreateAuthService\",\n  \"CreateExecutorExecutor\",\n  \"CreateIdPService\",\n  \"CreatePipelineResolver\",\n  \"CreatePipelineService\",\n  \"CreateSecretManagerSecret\",\n  \"CreateSecretManagerVault\",\n  \"CreateStaticWebsite\",\n  \"CreateTailorDBGQLPermission\",\n  \"CreateTailorDBService\",\n  \"CreateTailorDBType\",\n  \"CreateTenantConfig\",\n  \"CreateUserProfileConfig\",\n  \"CreateWorkflow\",\n  \"CreateWorkflowJobFunctionExecutionPolicy\",\n]);\n\n/**\n * Whether an error is an `AlreadyExists` from a retry-safe Create RPC.\n *\n * Only `AlreadyExists` stands in for \"my prior write already landed\"; for other\n * verbs/codes it would be a real conflict that must surface.\n * @param error - Error thrown by the request\n * @param methodName - RPC method name (e.g., \"CreateTailorDBType\")\n * @returns True if the error is an `AlreadyExists` from a retry-safe Create method\n */\nfunction isRetrySafeCreateAlreadyExists(error: unknown, methodName: string): boolean {\n  return (\n    error instanceof ConnectError &&\n    error.code === Code.AlreadyExists &&\n    RETRY_SAFE_CREATE_METHODS.has(methodName)\n  );\n}\n\n/**\n * Build a default (empty) unary response for the request's output message.\n *\n * Used when a retried Create is determined to have already succeeded on a prior\n * attempt: callers in the deploy pipeline ignore Create response bodies, so an\n * empty message faithfully represents the already-applied state.\n * @param req - Unary request whose output schema is used\n * @returns A synthesized unary response with an empty output message\n */\nfunction synthesizeEmptyUnaryResponse(req: {\n  service: UnaryResponse[\"service\"];\n  method: UnaryResponse[\"method\"];\n}): UnaryResponse {\n  return {\n    stream: false,\n    service: req.service,\n    method: req.method,\n    header: new Headers(),\n    message: create(req.method.output),\n    trailer: new Headers(),\n  };\n}\n\n/**\n * Base delay (ms) for the first retry. Subsequent attempts double it.\n *\n * Kept relatively large so a retry does not immediately race an original request\n * that is still settling server-side under load (e.g. a compound create whose\n * response was lost), which is what triggers the `already_exists` race.\n */\nconst RETRY_BASE_DELAY_MS = 500;\n\n/** Maximum number of attempts, including the initial one, for a retried request. */\nconst MAX_RETRY_ATTEMPTS = 3;\n\n/**\n * Wait for an exponential backoff delay with jitter.\n * @param attempt - Current retry attempt number (1-based)\n * @returns Promise that resolves after the delay\n */\nfunction waitRetryBackoff(attempt: number) {\n  const base = RETRY_BASE_DELAY_MS * 2 ** (attempt - 1);\n  const jitter = 0.1 * (Math.random() * 2 - 1);\n  const backoff = base * (1 + jitter);\n  return new Promise((resolve) => setTimeout(resolve, backoff));\n}\n\n// Node/undici error codes for a connection torn down mid-request. Whether the\n// request reached the server is unknown, same ambiguity as Code.Aborted/Internal,\n// so retry is scoped the same way (idempotent/no-side-effect methods only).\nconst TRANSPORT_DISCONNECT_ERROR_CODES: ReadonlySet<string> = new Set([\n  \"ERR_STREAM_PREMATURE_CLOSE\",\n  \"ECONNRESET\",\n  \"ETIMEDOUT\",\n  \"EPIPE\",\n]);\n\n/**\n * Whether an error is a raw Node/undici transport disconnect (not a `ConnectError`).\n * @param error - Error thrown by the request\n * @returns True if `error.code` is a known transport disconnect code\n */\nfunction isTransportDisconnectError(error: unknown): error is Error & { code: string } {\n  return (\n    error instanceof Error &&\n    \"code\" in error &&\n    typeof error.code === \"string\" &&\n    TRANSPORT_DISCONNECT_ERROR_CODES.has(error.code)\n  );\n}\n\n/**\n * Determine whether the given error is retriable for the method idempotency.\n * @param error - Error thrown by the request\n * @param idempotency - Method idempotency level\n * @returns True if the error should be retried\n */\nfunction isRetirable(error: unknown, idempotency: MethodOptions_IdempotencyLevel) {\n  const isIdempotentOrSideEffectFree =\n    idempotency === MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS ||\n    idempotency === MethodOptions_IdempotencyLevel.IDEMPOTENT;\n\n  if (!(error instanceof ConnectError)) {\n    return isTransportDisconnectError(error) && isIdempotentOrSideEffectFree;\n  }\n\n  switch (error.code) {\n    case Code.ResourceExhausted:\n    case Code.Unavailable:\n      return true;\n    case Code.Aborted:\n    case Code.Internal:\n      return isIdempotentOrSideEffectFree;\n    default:\n      return false;\n  }\n}\n\n/**\n * Create an interceptor that enhances error messages from the Operator API.\n * @internal\n * @returns Error handling interceptor\n */\nexport function errorHandlingInterceptor(): Interceptor {\n  return (next) => async (req) => {\n    try {\n      return await next(req);\n    } catch (error) {\n      if (error instanceof ConnectError) {\n        const { operation, resourceType } = parseMethodName(req.method.name);\n        const identifiers = requestIdentifiers(req.message, req.method.name);\n        const parts = Object.entries(identifiers).map(([key, value]) => `${key}: ${value}`);\n        const identity = parts.length === 0 ? \"\" : ` (${parts.join(\", \")})`;\n\n        // Re-throw as ConnectError with enhanced message to avoid re-wrapping\n        // Use rawMessage to avoid duplicating the error code prefix\n        throw withErrorDiagnostics(\n          new ConnectError(\n            `Failed to ${operation} ${resourceType}${identity}: ${error.rawMessage}`,\n            error.code,\n            error.metadata,\n          ),\n          { context: { method: req.method.name, identifiers } },\n        );\n      }\n      if (isTransportDisconnectError(error)) {\n        throw withErrorDiagnostics(error, {\n          code: \"TRANSPORT_DISCONNECTED\",\n          suggestion:\n            \"Check network connectivity and platform availability. A write may already have completed; inspect the current resource state before retrying.\",\n          context: {\n            method: req.method.name,\n            transportCode: error.code,\n            identifiers: requestIdentifiers(req.message, req.method.name),\n          },\n        });\n      }\n      throw error;\n    }\n  };\n}\n\n/**\n * @internal\n * @param methodName - RPC method name (e.g., \"CreateWorkspace\")\n * @returns Parsed operation and resource type\n */\nexport function parseMethodName(methodName: string): {\n  operation: string;\n  resourceType: string;\n} {\n  const match = methodName.match(/^(Create|Update|Delete|Set|List|Get)(.+)$/);\n  if (!match) {\n    return { operation: \"perform\", resourceType: \"resource\" };\n  }\n\n  const [, action, resource] = match as [string, string, string];\n  return { operation: action.toLowerCase(), resourceType: resource };\n}\n\n// Identifier fields surfaced in enhanced error messages. Never add fields\n// that can carry secrets or PII (tokens, scripts, query args, secret values,\n// emails), and never add a suffix that could match them (e.g. \"Key\" would\n// match future key material).\n//\n// Platform-wide naming conventions: on every API, a top-level string field\n// with one of these names or suffixes is a resource identifier.\nconst IDENTITY_KEYS = new Set([\"name\", \"id\"]);\nconst IDENTITY_KEY_SUFFIXES = [\"Name\", \"Id\", \"Namespace\"];\n// Key read from nested resource messages (e.g. the type in a create request).\n// Only materialized protobuf messages (marked by $typeName) qualify: map and\n// Struct fields materialize without one, and their entries can carry values\n// the SDK does not control (e.g. metadata labels merged from the remote).\nconst NESTED_IDENTITY_KEY = \"name\";\n// API-specific identifier fields, scoped to the RPC methods that define them\n// so a same-named field on an unrelated API is never surfaced by accident.\nconst METHOD_IDENTITY_KEYS: Readonly<Record<string, readonly string[]>> = {\n  GetMetadata: [\"trn\"],\n  SetMetadata: [\"trn\"],\n  AddCustomDomain: [\"domain\"],\n  GetCustomDomain: [\"domain\"],\n  RemoveCustomDomain: [\"domain\"],\n  CreateWorkflowJobFunctionExecutionPolicy: [\"executionPolicyKey\"],\n  UpdateWorkflowJobFunctionExecutionPolicy: [\"executionPolicyKey\"],\n  GetWorkflowJobFunctionExecutionPolicyByKey: [\"executionPolicyKey\"],\n};\n\nfunction isIdentityKey(key: string, methodName: string): boolean {\n  if (key.startsWith(\"$\")) {\n    return false;\n  }\n  return (\n    IDENTITY_KEYS.has(key) ||\n    IDENTITY_KEY_SUFFIXES.some((suffix) => key.endsWith(suffix)) ||\n    (METHOD_IDENTITY_KEYS[methodName]?.includes(key) ?? false)\n  );\n}\n\n/**\n * Extract allowlisted resource identifiers for error diagnostics.\n *\n * Only resource identifiers are included — the rest of the request payload\n * can carry credentials and must never reach terminal or CI logs.\n * @param message - Request message to extract identifiers from\n * @param methodName - RPC method name used to resolve method-scoped identifiers\n * @returns Resource identifiers keyed by request field\n */\nfunction requestIdentifiers(message: unknown, methodName: string): Record<string, string> {\n  if (typeof message !== \"object\" || message === null) {\n    return {};\n  }\n  const identifiers: Record<string, string> = {};\n  for (const [key, value] of Object.entries(message)) {\n    if (typeof value === \"string\" && value !== \"\" && isIdentityKey(key, methodName)) {\n      identifiers[key] = value;\n    } else if (\n      !key.startsWith(\"$\") &&\n      value !== null &&\n      typeof value === \"object\" &&\n      !Array.isArray(value) &&\n      typeof (value as Record<string, unknown>).$typeName === \"string\"\n    ) {\n      const nestedName = (value as Record<string, unknown>)[NESTED_IDENTITY_KEY];\n      if (typeof nestedName === \"string\" && nestedName !== \"\") {\n        identifiers[`${key}.${NESTED_IDENTITY_KEY}`] = nestedName;\n      }\n    }\n  }\n  return identifiers;\n}\n\nexport const MAX_PAGE_SIZE = 1000;\n\n/**\n * Fetch all paginated resources by repeatedly calling the given function.\n * @template T\n * @param fn - Page fetcher returning items and next page token\n * @returns All fetched items\n */\nexport async function fetchAll<T>(\n  fn: (pageToken: string, maxPageSize: number) => Promise<[T[], string]>,\n) {\n  const items: T[] = [];\n  let pageToken = \"\";\n\n  // loop exits when the platform stops returning a page token\n  // oxlint-disable-next-line typescript/no-unnecessary-condition\n  while (true) {\n    const [batch, nextPageToken] = await fn(pageToken, MAX_PAGE_SIZE);\n    items.push(...batch);\n    // loop exits when the platform stops returning a page token\n    // oxlint-disable-next-line typescript/no-unnecessary-condition\n    if (!nextPageToken) break;\n    pageToken = nextPageToken;\n  }\n  return items;\n}\n\n/**\n * @internal\n * @param error - Error value to inspect\n * @returns Whether the error is a Connect NotFound error\n */\nexport function isNotFoundError(error: unknown): boolean {\n  return error instanceof ConnectError && error.code === Code.NotFound;\n}\n\n/**\n * Fetch all paginated resources, treating an absent resource group as empty.\n * @template T\n * @param fn - Page fetcher returning items and next page token\n * @returns Items fetched before pagination completes or the fetcher raises NotFound\n */\nexport async function fetchAllTolerant<T>(\n  fn: (pageToken: string, maxPageSize: number) => Promise<[T[], string]>,\n): Promise<T[]> {\n  return await fetchAll(async (pageToken, maxPageSize) => {\n    try {\n      return await fn(pageToken, maxPageSize);\n    } catch (error) {\n      if (isNotFoundError(error)) {\n        return [[], \"\"];\n      }\n      throw error;\n    }\n  });\n}\n\n/**\n * Fetch a single resource, treating NotFound as an absent value.\n * @template T\n * @param fn - Resource getter\n * @returns Fetched resource, or undefined when the getter raises NotFound\n */\nexport async function getOrNull<T>(fn: () => Promise<T>): Promise<T | undefined> {\n  try {\n    return await fn();\n  } catch (error) {\n    if (isNotFoundError(error)) {\n      return undefined;\n    }\n    throw error;\n  }\n}\n\ninterface FetchPagedOptions {\n  /** Maximum number of items to return. 0 or undefined means unlimited. */\n  limit?: number;\n}\n\n/**\n * Fetch paginated resources with an optional upper bound on the number of\n * items returned. When `limit` is 0 or undefined the function behaves\n * like `fetchAll` and returns every page. When `limit` is positive the\n * function stops once enough items are collected, requesting smaller\n * pages as it approaches the boundary.\n * @template T\n * @param fn - Page fetcher returning items and next page token\n * @param options - Pagination options\n * @returns Fetched items (length <= limit when limit > 0)\n */\nexport async function fetchPaged<T>(\n  fn: (pageToken: string, pageSize: number) => Promise<[T[], string]>,\n  options?: FetchPagedOptions,\n): Promise<T[]> {\n  const limit = options?.limit;\n  const unbounded = limit === undefined || limit === 0;\n  const items: T[] = [];\n  let pageToken = \"\";\n\n  // loop exits when the platform stops returning a page token\n  // oxlint-disable-next-line typescript/no-unnecessary-condition\n  while (true) {\n    const pageSize = unbounded ? MAX_PAGE_SIZE : Math.min(limit - items.length, MAX_PAGE_SIZE);\n    if (!unbounded && pageSize <= 0) break;\n\n    const [batch, nextPageToken] = await fn(pageToken, pageSize);\n    items.push(...batch);\n    if (!unbounded && items.length >= limit) break;\n    // loop exits when the platform stops returning a page token\n    // oxlint-disable-next-line typescript/no-unnecessary-condition\n    if (!nextPageToken) break;\n    pageToken = nextPageToken;\n  }\n\n  if (!unbounded && items.length > limit) {\n    return items.slice(0, limit);\n  }\n  return items;\n}\n\n/**\n * Fetch user info from the Tailor Platform userinfo endpoint.\n * @param accessToken - Access token for the current user\n * @param config - Optional platform connection settings\n * @returns Parsed user info\n */\nexport async function fetchUserInfo(accessToken: string, config?: PlatformClientConfig) {\n  const userInfoUrl = new URL(\"/auth/platform/userinfo\", getPlatformBaseUrl(config)).href;\n  const resp = await fetch(userInfoUrl, {\n    headers: {\n      Authorization: `Bearer ${accessToken}`,\n      \"User-Agent\": await userAgent(),\n    },\n  });\n  if (!resp.ok) {\n    throw new Error(`Failed to fetch user info: ${resp.statusText}`);\n  }\n\n  const rawJson: unknown = await resp.json();\n  // strip unknown keys\n  const schema = z.object({\n    sub: z.string(),\n    email: z.string(),\n  });\n  return schema.parse(rawJson);\n}\n\n// Converting \"name:url\" patterns to actual Static Website URLs\n/**\n * Options for `resolveStaticWebsiteUrls`.\n */\nexport type ResolveStaticWebsiteUrlsOptions = {\n  /**\n   * Names of static websites that are defined locally in the current\n   * configuration. When the platform-side lookup for a name in this set\n   * fails specifically with a `NotFound` error, the warning is suppressed\n   * and the original `name:url[/path]` pattern is returned unresolved\n   * instead of being dropped.\n   *\n   * Use this from plan-phase callers to avoid noisy warnings on the first\n   * deployment, where the static website will be created later in the same\n   * apply run. Other failure modes (\"URL not yet assigned\", transient RPC\n   * errors, permission errors) are intentionally not suppressed so that\n   * real platform problems still surface during planning.\n   */\n  expectedLocalNames?: ReadonlySet<string>;\n};\n\n/**\n * Resolve \"name:url\" patterns to actual Static Website URLs.\n * @param client - Operator client instance\n * @param workspaceId - Workspace ID\n * @param urls - URLs or name:url patterns\n * @param context - Logging context (e.g., \"CORS\", \"OAuth2 redirect URIs\")\n * @param options - Optional behavior overrides\n * @returns Resolved URLs (or the original pattern for entries marked as\n *   expected-but-not-yet-deployed via `options.expectedLocalNames`)\n */\nexport async function resolveStaticWebsiteUrls(\n  client: OperatorClient,\n  workspaceId: string,\n  urls: string[] | undefined,\n  context: string, // for logging context (e.g., \"CORS\", \"OAuth2 redirect URIs\")\n  options: ResolveStaticWebsiteUrlsOptions = {},\n): Promise<string[]> {\n  if (!urls) {\n    return [];\n  }\n\n  const { expectedLocalNames } = options;\n\n  const results = await Promise.all(\n    urls.map(async (url) => {\n      const urlPattern = /:url(\\/.*)?$/;\n      const match = url.match(urlPattern);\n\n      if (match && match.index !== undefined) {\n        const siteName = url.substring(0, match.index);\n        const pathSuffix = match[1] || \"\";\n\n        try {\n          const response = await client.getStaticWebsite({\n            workspaceId,\n            name: siteName,\n          });\n\n          if (response.staticwebsite?.url) {\n            return [response.staticwebsite.url + pathSuffix];\n          }\n          logger.warn(\n            `Static website \"${siteName}\" has no URL assigned yet. Excluding from ${context}.`,\n          );\n          return [];\n        } catch (error) {\n          if (isNotFoundError(error) && expectedLocalNames?.has(siteName)) {\n            return [url];\n          }\n          logger.warn(\n            `Static website \"${siteName}\" not found for ${context} configuration. Excluding from ${context}.`,\n          );\n          return [];\n        }\n      }\n      return [url];\n    }),\n  );\n\n  return results.flat();\n}\n\n/**\n * Fetch an OAuth2 access token for a machine user.\n * @param url - OAuth2 server base URL\n * @param clientId - Client ID for the machine user\n * @param clientSecret - Client secret for the machine user\n * @returns Access token\n */\nexport async function fetchMachineUserToken(url: string, clientId: string, clientSecret: string) {\n  logger.registerSecret(clientSecret);\n  const tokenEndpoint = new URL(\"/oauth2/token\", url).href;\n  const formData = new URLSearchParams();\n  formData.append(\"grant_type\", \"client_credentials\");\n  formData.append(\"client_id\", clientId);\n  formData.append(\"client_secret\", clientSecret);\n\n  const request = {\n    method: \"POST\",\n    headers: {\n      \"User-Agent\": await userAgent(),\n      \"Content-Type\": \"application/x-www-form-urlencoded\",\n    },\n    body: formData,\n  };\n  const resp = await withConnectTimeoutRetry(\"machine user token request\", () =>\n    fetch(tokenEndpoint, request),\n  );\n  if (!resp.ok) {\n    const body = await resp.text().catch(() => \"\");\n    throw new Error(\n      `Failed to fetch machine user token: ${resp.status} ${resp.statusText} ${body.slice(0, 500)}`,\n    );\n  }\n  const rawJson: unknown = await resp.json();\n\n  // strip unknown keys\n  const schema = z.object({\n    token_type: z.string(),\n    access_token: z.string(),\n    expires_in: z.number(),\n  });\n  const token = schema.parse(rawJson);\n  logger.registerSecret(token.access_token);\n  return token;\n}\n\nfunction isUndiciConnectTimeout(error: unknown): boolean {\n  if (!(error instanceof TypeError)) {\n    return false;\n  }\n  const cause = error.cause;\n  return cause instanceof Error && \"code\" in cause && cause.code === \"UND_ERR_CONNECT_TIMEOUT\";\n}\n\n/**\n * Retry a request that failed before the connection was established.\n *\n * Only `UND_ERR_CONNECT_TIMEOUT` is retried: the request provably never reached\n * the server, so replaying it cannot duplicate a server-side effect.\n * @param label - Request description for the retry debug log\n * @param send - Sends the request; called once per attempt\n * @returns The first successful result\n */\nasync function withConnectTimeoutRetry<T>(label: string, send: () => Promise<T>): Promise<T> {\n  for (let attempt = 1; ; attempt++) {\n    try {\n      return await send();\n    } catch (error) {\n      if (!isUndiciConnectTimeout(error) || attempt >= MAX_RETRY_ATTEMPTS) {\n        throw error;\n      }\n      logger.debug(\n        `retry: ${label} attempt ${attempt} failed with UND_ERR_CONNECT_TIMEOUT; retrying`,\n      );\n      await waitRetryBackoff(attempt);\n    }\n  }\n}\n\n/**\n * Fetch an OAuth2 token for a platform machine user via client_credentials grant.\n * @param clientId - Client ID for the platform machine user\n * @param clientSecret - Client secret for the platform machine user\n * @param config - Optional platform connection settings\n * @returns OAuth2 token\n */\nexport async function fetchPlatformMachineUserToken(\n  clientId: string,\n  clientSecret: string,\n  config?: PlatformClientConfig,\n) {\n  logger.registerSecret(clientSecret);\n  const server = getPlatformBaseUrl(config);\n  // A new client per attempt: OAuth2Client caches its discovery promise even when\n  // it rejects, so a reused client would replay the failure without re-requesting.\n  const token = await withConnectTimeoutRetry(\"platform machine user token request\", () =>\n    new OAuth2Client({\n      clientId,\n      clientSecret,\n      server,\n      discoveryEndpoint: oauth2DiscoveryEndpoint,\n    }).clientCredentials(),\n  );\n  logger.registerSecret(token.accessToken);\n  if (token.refreshToken) logger.registerSecret(token.refreshToken);\n  return token;\n}\n\n/**\n * Close the global HTTP connection pool to prevent libuv UV_HANDLE_CLOSING\n * assertion failure on Windows at process exit (Node.js 23.x+).\n * See: https://github.com/nodejs/node/issues/56645\n *\n * The pool is reached through the global dispatcher symbol rather than the `undici`\n * package: importing that package installs its own Agent over these same globals,\n * replacing the HTTP stack Node's `fetch` already uses. The symbol is versioned per\n * Dispatcher API generation, and the newest one wins because older symbols hold a\n * wrapper around that same pool — closing both would destroy it twice.\n */\nexport async function closeConnectionPool() {\n  const globals = globalThis as Record<symbol, { close?: () => Promise<void> } | undefined>;\n  const dispatcher =\n    globals[Symbol.for(\"undici.globalDispatcher.2\")] ??\n    globals[Symbol.for(\"undici.globalDispatcher.1\")];\n  if (typeof dispatcher?.close === \"function\") {\n    await dispatcher.close();\n  }\n}\n","import * as fs from \"node:fs\";\nimport * as path from \"pathe\";\n\n/**\n * Collect base directories for resolving plugin import paths.\n * @param configPath - Path to tailor.config.ts\n * @returns Ordered list of base directories\n */\nexport function getPluginImportBaseDirs(configPath?: string): string[] {\n  if (configPath) {\n    return [path.dirname(configPath)];\n  }\n\n  return [process.cwd()];\n}\n\n/**\n * Resolve a relative plugin import path against candidate base directories.\n * @param pluginImportPath - Relative plugin import path\n * @param baseDirs - Candidate base directories\n * @returns Absolute path if found, otherwise null\n */\nexport function resolveRelativePluginImportPath(\n  pluginImportPath: string,\n  baseDirs: string[],\n): string | null {\n  if (!pluginImportPath.startsWith(\".\")) {\n    return null;\n  }\n\n  for (const baseDir of baseDirs) {\n    const absolutePath = path.resolve(baseDir, pluginImportPath);\n    if (fs.existsSync(absolutePath)) {\n      return absolutePath;\n    }\n  }\n\n  return null;\n}\n","/**\n * Plugin Executor Generator\n *\n * Generates TypeScript files for plugin-generated executors.\n * Supports both legacy format (inline trigger/operation) and new format (executorFile/context).\n */\n\nimport * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"pathe\";\nimport { CLIError, internalError } from \"#/cli/shared/errors\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport {\n  getPluginImportBaseDirs,\n  resolveRelativePluginImportPath,\n} from \"#/cli/shared/plugin-import\";\nimport { isPluginExecutorWithFile } from \"#/plugin/guards\";\nimport {\n  type PluginGeneratedExecutorLegacy,\n  type PluginGeneratedExecutorWithFile,\n  type PluginTriggerConfig,\n  type PluginOperationConfig,\n  type PluginInjectMap,\n  type PluginExecutorContext,\n} from \"#/plugin/types\";\nimport { assertDefined } from \"#/utils/assert\";\nimport ml from \"#/utils/multiline\";\nimport type {\n  PluginExecutorInfoExtended,\n  PluginTableGenerationResult,\n  SourceTableInfo,\n} from \"#/plugin/manager\";\n\n/**\n * Information needed for table import resolution.\n */\ninterface TableImportInfo {\n  /** Variable name to use in generated code */\n  variableName: string;\n  /** Import path for the table */\n  importPath: string;\n}\n\n/**\n * Generate TypeScript files for plugin-generated executors.\n * These files will be processed by the standard executor bundler.\n * @param executors - Array of plugin executor information\n * @param outputDir - Base output directory (e.g., .tailor)\n * @param tableGenerationResult - Result from plugin table generation (for import resolution)\n * @param sourceTableInfoMap - Map of source table names to their source info\n * @param configPath - Path to tailor.config.ts (used for resolving plugin import paths)\n * @returns Array of generated file paths\n */\nexport function generatePluginExecutorFiles(\n  executors: ReadonlyArray<PluginExecutorInfoExtended>,\n  outputDir: string,\n  tableGenerationResult?: PluginTableGenerationResult,\n  sourceTableInfoMap?: Map<string, SourceTableInfo>,\n  configPath?: string,\n): string[] {\n  if (executors.length === 0) {\n    return [];\n  }\n\n  const generatedFiles: string[] = [];\n  const baseDirs = getPluginImportBaseDirs(configPath);\n\n  for (const info of executors) {\n    const filePath = generateSingleExecutorFile(\n      info,\n      outputDir,\n      tableGenerationResult,\n      sourceTableInfoMap,\n      baseDirs,\n    );\n    generatedFiles.push(filePath);\n\n    const relativePath = path.relative(process.cwd(), filePath);\n    logger.log(\n      `  Plugin Executor File: ${styles.success(relativePath)} from plugin ${styles.info(info.pluginId)}`,\n    );\n  }\n\n  return generatedFiles;\n}\n\n/**\n * Generate a single executor file.\n * @param info - Plugin executor metadata and definition\n * @param outputDir - Base output directory (e.g., .tailor)\n * @param tableGenerationResult - Result from plugin table generation\n * @param sourceTableInfoMap - Map of source table names to their source info\n * @param baseDirs - Base directories for resolving plugin import paths\n * @returns Absolute path to the generated file\n */\nfunction generateSingleExecutorFile(\n  info: PluginExecutorInfoExtended,\n  outputDir: string,\n  tableGenerationResult?: PluginTableGenerationResult,\n  sourceTableInfoMap?: Map<string, SourceTableInfo>,\n  baseDirs: string[] = [],\n): string {\n  const pluginDir = sanitizePluginId(info.pluginId);\n  const executorOutputDir = path.join(outputDir, pluginDir, \"executors\");\n  fs.mkdirSync(executorOutputDir, { recursive: true });\n\n  const fileName = sanitizeExecutorFileName(info.executor.name);\n  const filePath = path.join(executorOutputDir, `${fileName}.ts`);\n\n  let content: string;\n  if (isPluginExecutorWithFile(info.executor)) {\n    content = generateExecutorFileContentNew(\n      info,\n      info.executor,\n      outputDir,\n      tableGenerationResult,\n      sourceTableInfoMap,\n      baseDirs,\n    );\n  } else {\n    content = generateExecutorFileContentLegacy(info.executor);\n  }\n\n  fs.writeFileSync(filePath, content);\n  return filePath;\n}\n\n/**\n * Generate TypeScript file content for new format executor (dynamic import).\n * Uses the executor's resolve function to dynamically import the module.\n * @param info - Plugin executor information\n * @param executor - Executor definition with resolve\n * @param outputDir - Base output directory\n * @param tableGenerationResult - Result from plugin table generation\n * @param sourceTableInfoMap - Map of source table names to their source info\n * @param baseDirs - Base directories for resolving plugin import paths\n * @returns TypeScript source code for executor file\n */\nfunction generateExecutorFileContentNew(\n  info: PluginExecutorInfoExtended,\n  executor: PluginGeneratedExecutorWithFile,\n  outputDir: string,\n  tableGenerationResult?: PluginTableGenerationResult,\n  sourceTableInfoMap?: Map<string, SourceTableInfo>,\n  baseDirs: string[] = [],\n): string {\n  const { resolve, context } = executor;\n  const pluginDir = sanitizePluginId(info.pluginId);\n  const executorOutputDir = path.join(outputDir, pluginDir, \"executors\");\n\n  const executorImportPath = resolveExecutorImportPath(\n    resolve,\n    info.pluginImportPath,\n    executorOutputDir,\n    baseDirs,\n  );\n\n  // Collect table imports from context\n  const tableImports = collectTableImports(\n    context,\n    outputDir,\n    info.pluginId,\n    tableGenerationResult,\n    sourceTableInfoMap,\n  );\n\n  // Generate import statements\n  const imports: string[] = [];\n\n  for (const [, importInfo] of tableImports) {\n    imports.push(`import { ${importInfo.variableName} } from \"${importInfo.importPath}\";`);\n  }\n\n  // Generate context object code\n  const contextCode = generateContextCode(context, tableImports);\n\n  return ml /* ts */ `\n    /**\n     * Auto-generated executor by plugin: ${info.pluginId}\n     * DO NOT EDIT - This file is generated by @tailor-platform/sdk\n     */\n    ${imports.join(\"\\n\")}\n\n    const { default: executorFactory } = await import(${JSON.stringify(executorImportPath)});\n    if (typeof executorFactory !== \"function\") {\n      throw new Error(\n        \"Plugin executor module must export a default function created by withPluginContext().\",\n      );\n    }\n    export default executorFactory(${contextCode});\n  `;\n}\n\n/**\n * Collect table imports needed for context.\n * @param context - Executor context values from plugin\n * @param outputDir - Base output directory for generated files\n * @param pluginId - Plugin identifier used for output paths\n * @param tableGenerationResult - Result from plugin table generation\n * @param sourceTableInfoMap - Map of source table names to their source info\n * @returns Map of context keys to their import information\n */\nfunction collectTableImports(\n  context: PluginExecutorContext,\n  outputDir: string,\n  pluginId: string,\n  tableGenerationResult?: PluginTableGenerationResult,\n  sourceTableInfoMap?: Map<string, SourceTableInfo>,\n): Map<string, TableImportInfo> {\n  const tableImports = new Map<string, TableImportInfo>();\n  const pluginDir = sanitizePluginId(pluginId);\n  const executorDir = path.join(outputDir, pluginDir, \"executors\");\n\n  for (const [key, value] of Object.entries(context)) {\n    if (isTableObject(value)) {\n      const tableName = value.name;\n      const sourceInfo = sourceTableInfoMap?.get(tableName);\n      const variableName = sourceInfo?.exportName ?? toCamelCase(tableName);\n\n      // Check if it's a generated table\n      let importPath: string;\n\n      if (tableGenerationResult?.tableFilePaths.has(tableName)) {\n        // It's a generated table - import from plugin types directory\n        const tableFilePath = assertDefined(\n          tableGenerationResult.tableFilePaths.get(tableName),\n          \"table file path missing\",\n        );\n        const absoluteTablePath = path.join(outputDir, tableFilePath);\n        importPath = path.relative(executorDir, absoluteTablePath).replace(/\\.ts$/, \"\");\n        if (!importPath.startsWith(\".\")) {\n          importPath = `./${importPath}`;\n        }\n      } else if (sourceInfo) {\n        // It's a user-defined table\n        const sourceFilePath = sourceInfo.filePath;\n        importPath = path.relative(executorDir, sourceFilePath).replace(/\\.ts$/, \"\");\n        if (!importPath.startsWith(\".\")) {\n          importPath = `./${importPath}`;\n        }\n      } else {\n        // Fallback: generate relative path assumption\n        // This might need adjustment based on actual project structure\n        importPath = `../../../../tailordb/${toKebabCase(tableName)}`;\n      }\n\n      tableImports.set(key, {\n        variableName,\n        importPath,\n      });\n    }\n  }\n\n  return tableImports;\n}\n\n/**\n * Generate TypeScript code for context object.\n * @param context - Executor context values from plugin\n * @param tableImports - Resolved table import information for context keys\n * @returns TypeScript object literal code\n */\nfunction generateContextCode(\n  context: PluginExecutorContext,\n  tableImports: Map<string, TableImportInfo>,\n): string {\n  const entries: string[] = [];\n\n  for (const [key, value] of Object.entries(context)) {\n    if (isTableObject(value)) {\n      const importInfo = tableImports.get(key);\n      if (importInfo) {\n        entries.push(`  ${key}: ${importInfo.variableName}`);\n      }\n    } else if (value !== undefined) {\n      entries.push(`  ${key}: ${JSON.stringify(value)}`);\n    }\n  }\n\n  return `{\\n${entries.join(\",\\n\")},\\n}`;\n}\n\n/**\n * Check if a value is a TailorDB table object.\n * @param value - Value to inspect\n * @returns True if value is a table object with name and fields\n */\nfunction isTableObject(value: unknown): value is { name: string; fields: Record<string, unknown> } {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    \"name\" in value &&\n    \"fields\" in value &&\n    typeof (value as { name: unknown }).name === \"string\"\n  );\n}\n\n// ============================================================================\n// Legacy format support\n// ============================================================================\n\n/**\n * Generate TypeScript file content for legacy format executor (trigger/operation).\n * @param executor - Legacy executor definition\n * @returns TypeScript source code for executor file\n */\nfunction generateExecutorFileContentLegacy(executor: PluginGeneratedExecutorLegacy): string {\n  const triggerCode = generateTriggerCode(executor.trigger);\n  const operationCode = generateOperationCode(executor.operation);\n\n  // Extract inject from function operation\n  const inject = executor.operation.kind === \"function\" ? executor.operation.inject : undefined;\n  const injectDeclarations = generateInjectDeclarations(inject);\n\n  const descriptionLine = executor.description\n    ? `\\n  description: ${JSON.stringify(executor.description)},`\n    : \"\";\n\n  return ml /* ts */ `\n    /**\n     * Auto-generated executor by plugin\n     * DO NOT EDIT - This file is generated by @tailor-platform/sdk\n     */\n    import { createExecutor } from \"@tailor-platform/sdk\";\n    ${injectDeclarations}\n    export default createExecutor({\n      name: ${JSON.stringify(executor.name)},${descriptionLine}\n      trigger: ${triggerCode},\n      operation: ${operationCode},\n    });\n  `;\n}\n\n/**\n * Generate const declarations for injected variables.\n * @param inject - Map of injected values keyed by variable name\n * @returns TypeScript const declarations or empty string\n */\nfunction generateInjectDeclarations(inject: PluginInjectMap | undefined): string {\n  if (!inject || Object.keys(inject).length === 0) {\n    return \"\";\n  }\n\n  const declarations = Object.entries(inject)\n    .map(([name, value]) => `const ${name} = ${JSON.stringify(value)};`)\n    .join(\"\\n\");\n\n  return `\\n// Injected variables from plugin\\n${declarations}\\n`;\n}\n\n/**\n * Generate TypeScript code for trigger configuration.\n * @param trigger - Trigger configuration for executor\n * @returns TypeScript code for trigger object\n */\nfunction generateTriggerCode(trigger: PluginTriggerConfig): string {\n  switch (trigger.kind) {\n    case \"tailordb\":\n      return `{\n    kind: ${JSON.stringify(trigger.kind)},\n    events: ${JSON.stringify(trigger.events)},\n    tableName: ${JSON.stringify(trigger.tableName)},\n  }`;\n\n    case \"schedule\":\n      return `{\n    kind: \"schedule\",\n    cron: ${JSON.stringify(trigger.cron)},\n    timezone: ${JSON.stringify(trigger.timezone ?? \"UTC\")},\n  }`;\n\n    case \"incomingWebhook\":\n      return `{\n    kind: \"incomingWebhook\",\n  }`;\n\n    default:\n      throw internalError(`Unknown trigger kind: ${(trigger as PluginTriggerConfig).kind}`);\n  }\n}\n\n/**\n * Generate TypeScript code for operation configuration.\n * @param operation - Operation configuration for executor\n * @returns TypeScript code for operation object\n */\nfunction generateOperationCode(operation: PluginOperationConfig): string {\n  switch (operation.kind) {\n    case \"graphql\": {\n      const appNameLine = operation.appName\n        ? `\\n    appName: ${JSON.stringify(operation.appName)},`\n        : \"\";\n      const variablesLine = operation.variables ? `\\n    variables: ${operation.variables},` : \"\";\n\n      return `{\n    kind: \"graphql\",\n    query: \\`${escapeTemplateLiteral(operation.query)}\\`,${appNameLine}${variablesLine}\n  }`;\n    }\n\n    case \"function\":\n      return `{\n    kind: \"function\",\n    body: ${operation.body},\n  }`;\n\n    case \"webhook\":\n      return `{\n    kind: \"webhook\",\n    url: () => ${JSON.stringify(operation.url)},\n  }`;\n\n    case \"workflow\":\n      return `{\n    kind: \"workflow\",\n    workflowName: ${JSON.stringify(operation.workflowName)},\n  }`;\n\n    default:\n      throw internalError(`Unknown operation kind: ${(operation as PluginOperationConfig).kind}`);\n  }\n}\n\n/**\n * Escape special characters in template literal content.\n * @param str - Raw template literal content\n * @returns Escaped string safe for template literals\n */\nfunction escapeTemplateLiteral(str: string): string {\n  return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/`/g, \"\\\\`\").replace(/\\$\\{/g, \"\\\\${\");\n}\n\n// ============================================================================\n// Utility functions\n// ============================================================================\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Resolve the import path for a plugin executor module.\n * @param resolve - Executor resolve function\n * @param pluginImportPath - Plugin's import path\n * @param executorOutputDir - Directory where the generated executor will be written\n * @param baseDirs - Base directories for resolving plugin import paths\n * @returns Import path string for the executor module\n */\nfunction resolveExecutorImportPath(\n  resolve: () => Promise<{ default: unknown }>,\n  pluginImportPath: string,\n  executorOutputDir: string,\n  baseDirs: string[],\n): string {\n  const specifier = extractDynamicImportSpecifier(resolve);\n  if (!specifier.startsWith(\".\")) {\n    return specifier;\n  }\n\n  const pluginBaseDir = resolvePluginBaseDir(pluginImportPath, baseDirs);\n  if (!pluginBaseDir) {\n    throw CLIError({\n      code: \"PLUGIN_IMPORT_UNRESOLVED\",\n      message: `Unable to resolve plugin import base for \"${pluginImportPath}\".`,\n      details: `Tried base dirs: ${baseDirs.join(\", \") || \"(none)\"}.`,\n      suggestion:\n        \"Use an absolute import specifier in resolve(), or ensure the plugin path is resolvable.\",\n    });\n  }\n\n  const absolutePath = path.resolve(pluginBaseDir, specifier);\n  let relativePath = path.relative(executorOutputDir, absolutePath).replace(/\\\\/g, \"/\");\n  relativePath = stripSourceExtension(relativePath);\n  if (!relativePath.startsWith(\".\")) {\n    relativePath = `./${relativePath}`;\n  }\n  return relativePath;\n}\n\n/**\n * Extract the dynamic import specifier from a resolve function.\n * @param resolve - Executor resolve function\n * @returns The module specifier string\n */\nfunction extractDynamicImportSpecifier(resolve: () => Promise<{ default: unknown }>): string {\n  const source = resolve.toString();\n  const match = source.match(/import\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)/);\n  if (!match) {\n    throw CLIError({\n      code: \"PLUGIN_RESOLVE_INVALID\",\n      message: `resolve() must return a dynamic import, e.g. \\`async () => await import(\"./executors/on-create\")\\`.`,\n    });\n  }\n  return assertDefined(match[1], \"dynamic import specifier capture group missing\");\n}\n\n/**\n * Resolve plugin base directory for relative imports.\n * @param pluginImportPath - Plugin import path\n * @param baseDirs - Base directories for resolving plugin import paths\n * @returns Directory path or null if not resolvable\n */\nfunction resolvePluginBaseDir(pluginImportPath: string, baseDirs: string[]): string | null {\n  if (pluginImportPath.startsWith(\".\")) {\n    const resolvedPath =\n      resolveRelativePluginImportPath(pluginImportPath, baseDirs) ??\n      path.resolve(baseDirs[0] ?? process.cwd(), pluginImportPath);\n    if (fs.existsSync(resolvedPath)) {\n      const stats = fs.statSync(resolvedPath);\n      return stats.isDirectory() ? resolvedPath : path.dirname(resolvedPath);\n    }\n    return path.extname(resolvedPath) ? path.dirname(resolvedPath) : resolvedPath;\n  }\n\n  for (const baseDir of baseDirs) {\n    try {\n      const resolved = require.resolve(pluginImportPath, { paths: [baseDir] });\n      return path.dirname(resolved);\n    } catch {\n      continue;\n    }\n  }\n  return null;\n}\n\n/**\n * Strip TypeScript source extensions from import paths.\n * @param importPath - Path to normalize\n * @returns Path without .ts/.tsx extension\n */\nfunction stripSourceExtension(importPath: string): string {\n  return importPath.replace(/\\.(ts|tsx)$/, \"\");\n}\n\n/**\n * Convert plugin ID to safe directory name.\n * @param pluginId - Plugin identifier (e.g., \"@scope/name\")\n * @returns Safe directory name\n */\nfunction sanitizePluginId(pluginId: string): string {\n  return pluginId.replace(/^@/, \"\").replace(/\\//g, \"-\");\n}\n\n/**\n * Convert executor name to safe filename.\n * @param executorName - Executor name\n * @returns Safe filename without extension\n */\nfunction sanitizeExecutorFileName(executorName: string): string {\n  const baseName = path.basename(executorName);\n  const withoutExtension = baseName.replace(/\\.[^/.]+$/, \"\");\n  const sanitized = withoutExtension.replace(/[^a-zA-Z0-9_-]/g, \"-\");\n  if (!sanitized) {\n    throw CLIError({\n      code: \"PLUGIN_EXECUTOR_NAME_INVALID\",\n      message: `Invalid executor name: \"${executorName}\"`,\n    });\n  }\n  return sanitized;\n}\n\n/**\n * Convert string to camelCase.\n * @param str - Input string to convert\n * @returns camelCase string\n */\nfunction toCamelCase(str: string): string {\n  const result = str.replace(/[-_\\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : \"\"));\n  return result.charAt(0).toLowerCase() + result.slice(1);\n}\n\n/**\n * Convert string to kebab-case.\n * @param str - Input string to convert\n * @returns kebab-case string\n */\nfunction toKebabCase(str: string): string {\n  return str\n    .replace(/([a-z])([A-Z])/g, \"$1-$2\")\n    .replace(/[\\s_]+/g, \"-\")\n    .toLowerCase();\n}\n","/**\n * Plugin Table Generator\n *\n * Generates TypeScript files for plugin-generated TailorDB tables.\n * These files can be imported by plugin executors to reference generated tables.\n */\n\nimport * as fs from \"node:fs\";\nimport * as path from \"pathe\";\nimport { CLIError } from \"#/cli/shared/errors\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport ml from \"#/utils/multiline\";\nimport type { PluginGeneratedTableInfo, PluginTableGenerationResult } from \"#/plugin/manager\";\nimport type { PluginGeneratedTable } from \"#/plugin/types\";\n\ntype FieldMetadata = {\n  required?: boolean;\n  index?: boolean;\n  unique?: boolean;\n  description?: string;\n  allowedValues?: ReadonlyArray<{ value: string }>;\n};\n\ntype FieldDefinition = {\n  type?: string;\n  _metadata?: FieldMetadata;\n  metadata?: FieldMetadata;\n};\n\nfunction isFieldDefinition(value: unknown): value is FieldDefinition {\n  return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Generate TypeScript files for plugin-generated tables.\n * These files export the table definition and can be imported by executor files.\n * @param tables - Array of plugin table information\n * @param outputDir - Base output directory (e.g., .tailor)\n * @returns Generation result with file paths\n */\nexport function generatePluginTableFiles(\n  tables: ReadonlyArray<PluginGeneratedTableInfo>,\n  outputDir: string,\n): PluginTableGenerationResult {\n  const tableFilePaths = new Map<string, string>();\n  const generatedFiles: string[] = [];\n\n  if (tables.length === 0) {\n    return { tableFilePaths, generatedFiles };\n  }\n\n  const seenTableNames = new Map<string, PluginGeneratedTableInfo>();\n\n  for (const info of tables) {\n    const existing = seenTableNames.get(info.table.name);\n    if (existing) {\n      throw CLIError({\n        code: \"PLUGIN_TABLE_NAME_DUPLICATE\",\n        message:\n          `Duplicate plugin-generated table name \"${info.table.name}\" detected. ` +\n          `First: plugin \"${existing.pluginId}\" (kind: \"${existing.kind}\", source: \"${existing.sourceTableName}\"), ` +\n          `Second: plugin \"${info.pluginId}\" (kind: \"${info.kind}\", source: \"${info.sourceTableName}\"). ` +\n          `Plugin-generated table names must be unique.`,\n      });\n    }\n    seenTableNames.set(info.table.name, info);\n\n    const pluginDir = sanitizePluginId(info.pluginId);\n    const tableOutputDir = path.join(outputDir, pluginDir, \"types\");\n    fs.mkdirSync(tableOutputDir, { recursive: true });\n\n    const fileName = `${toKebabCase(info.table.name)}.ts`;\n    const filePath = path.join(tableOutputDir, fileName);\n    const content = generateTableFileContent(info);\n\n    fs.writeFileSync(filePath, content);\n    generatedFiles.push(filePath);\n\n    // Store relative path from outputDir for import resolution\n    const relativePath = path.relative(outputDir, filePath);\n    tableFilePaths.set(info.table.name, relativePath);\n\n    const displayPath = path.relative(process.cwd(), filePath);\n    logger.log(\n      `  Plugin Table File: ${styles.success(displayPath)} (${styles.dim(info.kind)}) from plugin ${styles.info(info.pluginId)}`,\n    );\n  }\n\n  return { tableFilePaths, generatedFiles };\n}\n\n/**\n * Generate TypeScript file content for a single table.\n * @param info - Plugin table information\n * @returns TypeScript source code\n */\nfunction generateTableFileContent(info: PluginGeneratedTableInfo): string {\n  const { table, pluginId, sourceTableName, kind } = info;\n  const variableName = toCamelCase(table.name);\n  const fieldsCode = generateFieldsCode(table);\n\n  return ml /* ts */ `\n    /**\n     * Auto-generated table by plugin: ${pluginId}\n     * Source: ${sourceTableName}\n     * Kind: ${kind}\n     *\n     * DO NOT EDIT - This file is generated by @tailor-platform/sdk\n     */\n    import { db } from \"@tailor-platform/sdk\";\n\n    export const ${variableName} = db.table(${JSON.stringify(table.name)}, ${fieldsCode});\n\n    export type ${table.name} = typeof ${variableName};\n  `;\n}\n\n/**\n * Generate TypeScript code for field definitions.\n * This creates a simplified version of the table's fields.\n * @param table - TailorDB table\n * @returns TypeScript code for fields object\n */\nfunction generateFieldsCode(table: PluginGeneratedTable): string {\n  const fieldEntries: string[] = [];\n\n  for (const [fieldName, field] of Object.entries(table.fields)) {\n    if (!isFieldDefinition(field)) continue;\n    const fieldCode = generateSingleFieldCode(field);\n    if (fieldCode) {\n      fieldEntries.push(`  ${fieldName}: ${fieldCode}`);\n    }\n  }\n\n  return `{\\n${fieldEntries.join(\",\\n\")},\\n}`;\n}\n\n/**\n * Map from TailorDB table to SDK method name.\n */\nconst typeToMethodMap: Record<string, string> = {\n  string: \"string\",\n  integer: \"int\",\n  float: \"float\",\n  boolean: \"bool\",\n  uuid: \"uuid\",\n  datetime: \"datetime\",\n  date: \"date\",\n  time: \"time\",\n  enum: \"enum\",\n  nested: \"nested\",\n};\n\n/**\n * Generate TypeScript code for a single field definition.\n * @param field - Field definition object\n * @returns TypeScript code for the field\n */\nfunction generateSingleFieldCode(field: FieldDefinition): string | null {\n  const fieldType = field.type;\n  if (!fieldType) {\n    return null;\n  }\n\n  const method = typeToMethodMap[fieldType] ?? fieldType;\n  const metadata: FieldMetadata = field._metadata ?? field.metadata ?? {};\n\n  // Build options object\n  const optionParts: string[] = [];\n  if (metadata.required === false) {\n    optionParts.push(\"optional: true\");\n  }\n\n  const optionsArg = optionParts.length > 0 ? `{ ${optionParts.join(\", \")} }` : \"\";\n\n  // Handle enum type with values\n  if (fieldType === \"enum\") {\n    // Extract enum values from allowedValues array\n    const allowedValues = metadata.allowedValues;\n    let enumValues: string[] = [];\n    if (Array.isArray(allowedValues)) {\n      enumValues = allowedValues.map((v: { value: string }) => v.value);\n    }\n\n    let code = `db.enum(${JSON.stringify(enumValues)}${optionsArg ? `, ${optionsArg}` : \"\"})`;\n    if (metadata.index) {\n      code += \".index()\";\n    }\n    if (metadata.unique) {\n      code += \".unique()\";\n    }\n    if (metadata.description) {\n      code += `.description(${JSON.stringify(metadata.description)})`;\n    }\n    return code;\n  }\n\n  // Build method chain for other types\n  let code = `db.${method}(${optionsArg})`;\n\n  // Add index if present\n  if (metadata.index) {\n    code += \".index()\";\n  }\n\n  // Add unique if present\n  if (metadata.unique) {\n    code += \".unique()\";\n  }\n\n  // Add description if present\n  if (metadata.description) {\n    code += `.description(${JSON.stringify(metadata.description)})`;\n  }\n\n  return code;\n}\n\n/**\n * Convert plugin ID to safe directory name.\n * @param pluginId - Plugin identifier (e.g., \"@tailor-platform/change-history\")\n * @returns Safe directory name (e.g., \"tailor-platform-change-history\")\n */\nfunction sanitizePluginId(pluginId: string): string {\n  return pluginId.replace(/^@/, \"\").replace(/\\//g, \"-\");\n}\n\n/**\n * Convert string to kebab-case.\n * @param str - Input string\n * @returns kebab-case string\n */\nfunction toKebabCase(str: string): string {\n  return str\n    .replace(/([a-z])([A-Z])/g, \"$1-$2\")\n    .replace(/[\\s_]+/g, \"-\")\n    .toLowerCase();\n}\n\n/**\n * Convert string to camelCase.\n * @param str - Input string\n * @returns camelCase string\n */\nfunction toCamelCase(str: string): string {\n  const result = str.replace(/[-_\\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : \"\"));\n  return result.charAt(0).toLowerCase() + result.slice(1);\n}\n","import type { Plugin } from \"rolldown\";\n\ntype DepCollectorResult = {\n  plugin: Plugin;\n  getResult: () => string[];\n};\n\n/**\n * Create a rolldown plugin that collects all resolved module paths during a build.\n * The plugin is purely observational and does not modify any code or behavior.\n * Collected paths exclude node_modules and generated entry files.\n * node_modules changes (package upgrades) are not tracked per-bundle;\n * lockfile hash and SDK version changes invalidate the entire cache.\n * @returns An object containing the plugin and a getResult function that returns sorted, deduplicated paths\n */\nexport function createDepCollectorPlugin(): DepCollectorResult {\n  const collectedPaths = new Set<string>();\n\n  const plugin: Plugin = {\n    name: \"cache-dep-collector\",\n    load: {\n      filter: {\n        id: {\n          // Match all file types (not just JS/TS) so that JSON, CJS,\n          // and other imported files are tracked for cache invalidation.\n          include: [/\\.[^/]+$/],\n        },\n      },\n      handler(id) {\n        if (!id.includes(\"node_modules\") && !id.endsWith(\".entry.js\")) {\n          collectedPaths.add(id);\n        }\n        return null;\n      },\n    },\n  };\n\n  function getResult(): string[] {\n    return Array.from(collectedPaths).toSorted();\n  }\n\n  return { plugin, getResult };\n}\n","import * as crypto from \"node:crypto\";\nimport * as fs from \"node:fs\";\n\n/**\n * Compute the SHA-256 hex digest of an arbitrary string.\n * @param content - The string content to hash\n * @returns Hex-encoded SHA-256 hash\n */\nfunction hashContent(content: string): string {\n  return crypto.createHash(\"sha256\").update(content, \"utf-8\").digest(\"hex\");\n}\n\n/**\n * Read a file and return its SHA-256 hex digest.\n * @param filePath - Absolute path to the file\n * @returns Hex-encoded SHA-256 hash of the file content\n */\nfunction hashFile(filePath: string): string {\n  const content = fs.readFileSync(filePath);\n  return crypto.createHash(\"sha256\").update(content).digest(\"hex\");\n}\n\n// A path that does not exist hashes to a fixed marker rather than throwing, so\n// a dependency set may include files a build only probed for. Creating such a\n// file later changes the marker to a content hash, which invalidates the entry.\nconst MISSING_FILE_MARKER = \"<missing>\";\n\n/**\n * Compute a deterministic SHA-256 hash for multiple files.\n *\n * Paths are sorted alphabetically before hashing so that the result\n * is independent of the order the paths are supplied (e.g. glob ordering).\n * Each file's individual hash is concatenated and then hashed again. A path\n * that does not exist contributes a fixed marker instead of a content hash.\n * @param filePaths - Array of absolute file paths\n * @returns Hex-encoded SHA-256 hash representing all files\n */\nfunction hashFiles(filePaths: string[]): string {\n  const sorted = filePaths.toSorted();\n  const combined = sorted.map((fp) => hashFileOrMissing(fp)).join(\"\");\n  return hashContent(combined);\n}\n\nfunction hashFileOrMissing(filePath: string): string {\n  try {\n    return hashFile(filePath);\n  } catch (error) {\n    if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n      return MISSING_FILE_MARKER;\n    }\n    throw error;\n  }\n}\n\nexport { hashContent, hashFile, hashFiles };\n","import * as path from \"pathe\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { createDepCollectorPlugin } from \"./dep-collector-plugin\";\nimport { hashContent, hashFile, hashFiles } from \"./hasher\";\nimport type { CacheStore } from \"./store\";\nimport type { Plugin } from \"rolldown\";\n\ntype BundleKind =\n  | \"resolver\"\n  | \"executor\"\n  | \"workflow-job\"\n  | \"auth-hook\"\n  | \"http-adapter-input\"\n  | \"http-adapter-output\";\n\ntype BundleCacheRestoreParams = {\n  kind: BundleKind;\n  namespace?: string;\n  name: string;\n  /** Optional hash of non-file context (e.g., env variables) to include in cache validation. */\n  contextHash?: string;\n};\n\ntype BundleCacheSaveParams = {\n  kind: BundleKind;\n  namespace?: string;\n  name: string;\n  sourceFile: string;\n  content: string;\n  dependencyPaths: string[];\n  /** Optional hash of non-file context (e.g., env variables) to include in cache key computation. */\n  contextHash?: string;\n};\n\n/**\n * Cache strategy that determines whether a bundled output can be\n * restored from cache or needs rebuilding.\n */\ntype BundleCache = {\n  /** Attempt to restore cached bundle content. Returns the code string if cache is valid, undefined otherwise. */\n  tryRestore(params: BundleCacheRestoreParams): string | undefined;\n  /** Save bundle content and its metadata to the cache. */\n  save(params: BundleCacheSaveParams): void;\n};\n\nfunction buildCacheKey(kind: string, name: string, namespace?: string): string {\n  return namespace ? `${kind}:${namespace}:${name}` : `${kind}:${name}`;\n}\n\nfunction combineHash(fileHash: string, contextHash?: string): string {\n  if (!contextHash) return fileHash;\n  return hashContent(fileHash + contextHash);\n}\n\ntype ComputeBundlerContextHashParams = {\n  sourceFile: string;\n  extraContext: string;\n  tsconfig?: string;\n  inlineSourcemap?: boolean;\n  bundleLogLevel?: string;\n  prefix?: string;\n};\n\n/**\n * Compute a context hash for cache invalidation across bundlers.\n *\n * Combines the source file path, a caller-supplied extra context string\n * (e.g. serialized workflow start-call bindings, or an HTTP adapter's method\n * list), tsconfig hash, sourcemap mode, bundle log level, and an optional\n * prefix (e.g., serialized env variables) into a single SHA-256 hash.\n * @param params - Context hash computation parameters\n * @returns SHA-256 hex digest of the combined context\n */\nfunction computeBundlerContextHash(params: ComputeBundlerContextHashParams): string {\n  const { sourceFile, extraContext, tsconfig, inlineSourcemap, bundleLogLevel, prefix } = params;\n  return hashContent(\n    (prefix ?? \"\") +\n      path.resolve(sourceFile) +\n      extraContext +\n      (tsconfig ? hashFile(tsconfig) : \"\") +\n      String(inlineSourcemap ?? false) +\n      (bundleLogLevel ?? \"\"),\n  );\n}\n\ntype WithCacheParams = {\n  cache: BundleCache | undefined;\n  kind: BundleKind;\n  namespace?: string;\n  name: string;\n  sourceFile: string;\n  contextHash: string | undefined;\n  build: (plugins: Plugin[], trackDependency: (filePath: string) => void) => Promise<string>;\n};\n\n/**\n * Run a build with optional cache restore/save around it.\n * When caching is active, attempts to restore from cache first,\n * and saves the build result (with collected dependencies) on a cache miss.\n * @param params - Cache and build parameters\n * @returns The bundled code string\n */\nasync function withCache(params: WithCacheParams): Promise<string> {\n  const { cache, kind, namespace, name, sourceFile, contextHash, build } = params;\n\n  if (!cache) {\n    return await build([], () => {});\n  }\n\n  const content = cache.tryRestore({ kind, namespace, name, contextHash });\n  if (content !== undefined) {\n    logger.debug(`  ${styles.dim(\"cached\")}: ${name}`);\n    return content;\n  }\n\n  // Files a build reads without rolldown loading them as modules — tsconfigs\n  // consulted for path aliases — still have to invalidate the entry.\n  const extraDependencies = new Set<string>();\n  const { plugin, getResult } = createDepCollectorPlugin();\n  const code = await build([plugin], (filePath) => extraDependencies.add(filePath));\n\n  cache.save({\n    kind,\n    namespace,\n    name,\n    sourceFile,\n    content: code,\n    dependencyPaths: [...getResult(), ...extraDependencies],\n    contextHash,\n  });\n\n  return code;\n}\n\n/**\n * Create a bundle cache backed by the given store.\n * @param store - The cache store for persistence\n * @returns A BundleCache instance\n */\nfunction createBundleCache(store: CacheStore): BundleCache {\n  function tryRestore(params: BundleCacheRestoreParams): string | undefined {\n    const cacheKey = buildCacheKey(params.kind, params.name, params.namespace);\n    const entry = store.getEntry(cacheKey);\n\n    if (!entry) {\n      return undefined;\n    }\n\n    // Recompute hash of all stored dependency paths. A path that has appeared or\n    // disappeared since the entry was saved changes the hash, so it lands on the\n    // mismatch below rather than needing its own branch.\n    let currentHash: string;\n    try {\n      currentHash = combineHash(hashFiles(entry.dependencyPaths), params.contextHash);\n    } catch {\n      return undefined;\n    }\n\n    if (currentHash !== entry.inputHash) {\n      return undefined;\n    }\n\n    const content = store.restoreBundleContent(cacheKey);\n    const output = entry.outputFiles.find((file) => file.outputPath === cacheKey);\n    if (content === undefined || !output || hashContent(content) !== output.contentHash) {\n      return undefined;\n    }\n    return content;\n  }\n\n  function save(params: BundleCacheSaveParams): void {\n    const { kind, namespace, name, sourceFile, content, dependencyPaths, contextHash } = params;\n    const cacheKey = buildCacheKey(kind, name, namespace);\n    // Always include sourceFile in dependency paths so that changes to the\n    // source file itself are detected even when dep-collector only finds\n    // node_modules imports (which are filtered out).\n    const allDeps = dependencyPaths.includes(sourceFile)\n      ? dependencyPaths\n      : [sourceFile, ...dependencyPaths];\n\n    // Mirror tryRestore()'s tolerance: a non-ENOENT read error (e.g. EISDIR)\n    // should give up on caching this entry rather than fail the build.\n    let inputHash: string;\n    try {\n      inputHash = combineHash(hashFiles(allDeps), contextHash);\n    } catch {\n      return;\n    }\n\n    const contentHash = hashContent(content);\n\n    store.storeBundleContent(cacheKey, content);\n\n    store.setEntry(cacheKey, {\n      kind: \"bundle\",\n      inputHash,\n      dependencyPaths: allDeps,\n      outputFiles: [{ outputPath: cacheKey, contentHash }],\n      createdAt: new Date().toISOString(),\n    });\n  }\n\n  return { tryRestore, save };\n}\n\nexport { computeBundlerContextHash, createBundleCache, withCache };\nexport type { BundleCache };\n","import { assertDefined } from \"#/utils/assert\";\nimport type {\n  Expression,\n  CallExpression,\n  StaticMemberExpression,\n  ObjectPropertyKind,\n  ObjectProperty,\n  ArrowFunctionExpression,\n  Function as FunctionExpression,\n} from \"@oxc-project/types\";\n\n/** A generic AST node for walking purposes */\nexport type ASTNode = Record<string, unknown>;\n\nexport interface Replacement {\n  start: number;\n  end: number;\n  text: string;\n}\n\nexport interface StartCallInfo {\n  identifierName: string;\n  callRange: { start: number; end: number };\n  argsText: string;\n  optionsText?: string;\n}\n\nexport interface FoundProperty {\n  key: ObjectProperty[\"key\"];\n  value: Expression;\n  start: number;\n  end: number;\n}\n\n/**\n * Read an import or export name from an OXC identifier or string-literal node.\n * @param node - Import/export name node\n * @returns Module binding name, or undefined for an unsupported node\n */\nexport function getModuleExportName(node: unknown): string | undefined {\n  if (!node || typeof node !== \"object\") return undefined;\n  const exportName = node as { name?: string; value?: unknown };\n  if (exportName.name) return exportName.name;\n  return typeof exportName.value === \"string\" ? exportName.value : undefined;\n}\n\n/**\n * Check if a module source is from the Tailor SDK package (including subpaths)\n * @param source - Module source string\n * @returns True if the source is from the Tailor SDK package\n */\nexport function isTailorSdkSource(source: string): boolean {\n  return /^@tailor-platform\\/sdk(\\/|$)/.test(source);\n}\n\n/**\n * Get the source string from a dynamic import or require call\n * @param node - AST node to inspect\n * @returns Resolved import/require source string or null\n */\nexport function getImportSource(node: Expression | null | undefined): string | null {\n  if (!node) return null;\n  // await import(\"@tailor-platform/sdk\")\n  if (node.type === \"ImportExpression\") {\n    const importExpr = node;\n    const source = importExpr.source;\n    if (source.type === \"Literal\" && typeof source.value === \"string\") {\n      return source.value;\n    }\n  }\n  // require(\"@tailor-platform/sdk\")\n  if (node.type === \"CallExpression\") {\n    const callExpr = node;\n    if (callExpr.callee.type === \"Identifier\" && callExpr.callee.name === \"require\") {\n      const arg = callExpr.arguments[0];\n      if (\n        // callee may be a ComputedMemberExpression at runtime\n        // oxlint-disable-next-line typescript/no-unnecessary-condition\n        arg &&\n        \"type\" in arg &&\n        arg.type === \"Literal\" &&\n        \"value\" in arg &&\n        typeof arg.value === \"string\"\n      ) {\n        return arg.value;\n      }\n    }\n  }\n  return null;\n}\n\nfunction argumentSourceText(arg: unknown, sourceText: string): string | undefined {\n  if (arg && typeof arg === \"object\" && \"start\" in arg && \"end\" in arg) {\n    return sourceText.slice(arg.start as number, arg.end as number);\n  }\n  return undefined;\n}\n\n/**\n * Get metadata for a static `identifier.start(...)` call.\n * @param node - AST node to inspect\n * @param sourceText - Source code text\n * @returns Start call metadata, or null when the node is not a start call\n */\nexport function getStartCallInfo(\n  node: ASTNode | null | undefined,\n  sourceText: string,\n): StartCallInfo | null {\n  if (!node || typeof node !== \"object\" || node.type !== \"CallExpression\") {\n    return null;\n  }\n\n  const callExpr = node as unknown as CallExpression;\n  const callee = callExpr.callee;\n  if (callee.type !== \"MemberExpression\") {\n    return null;\n  }\n\n  const memberExpr = callee as unknown as StaticMemberExpression;\n  if (\n    // callee may be a ComputedMemberExpression at runtime\n    // oxlint-disable-next-line typescript/no-unnecessary-condition\n    memberExpr.computed ||\n    memberExpr.property.name !== \"start\" ||\n    memberExpr.object.type !== \"Identifier\"\n  ) {\n    return null;\n  }\n\n  return {\n    identifierName: memberExpr.object.name,\n    callRange: { start: callExpr.start, end: callExpr.end },\n    argsText: argumentSourceText(callExpr.arguments[0], sourceText) ?? \"\",\n    optionsText: argumentSourceText(callExpr.arguments[1], sourceText),\n  };\n}\n\n/**\n * Unwrap AwaitExpression to get the inner expression\n * @param node - AST expression node\n * @returns Inner expression if node is an AwaitExpression\n */\nexport function unwrapAwait(node: Expression | null | undefined): Expression | null | undefined {\n  if (node?.type === \"AwaitExpression\") {\n    return node.argument;\n  }\n  return node;\n}\n\n/**\n * Check if a node is a string literal\n * @param node - AST expression node\n * @returns True if node is a string literal\n */\nexport function isStringLiteral(\n  node: Expression | null | undefined,\n): node is Expression & { type: \"Literal\"; value: string } {\n  // Note: oxc uses \"Literal\" for all literals, distinguishing by value type\n  return node?.type === \"Literal\" && typeof (node as { value?: unknown }).value === \"string\";\n}\n\n/**\n * Check if a node is a function expression (arrow or regular)\n * @param node - AST expression node\n * @returns True if node is a function expression\n */\nexport function isFunctionExpression(\n  node: Expression | null | undefined,\n): node is ArrowFunctionExpression | FunctionExpression {\n  return node?.type === \"ArrowFunctionExpression\" || node?.type === \"FunctionExpression\";\n}\n\n/**\n * Find a property in an object expression\n * @param properties - Object properties to search\n * @param name - Property name to find\n * @returns Found property info or null\n */\nexport function findProperty(properties: ObjectPropertyKind[], name: string): FoundProperty | null {\n  for (const prop of properties) {\n    // Note: oxc uses \"Property\" for object properties\n    if (prop.type === \"Property\") {\n      const objProp = prop;\n      const keyName =\n        objProp.key.type === \"Identifier\"\n          ? objProp.key.name\n          : objProp.key.type === \"Literal\"\n            ? (objProp.key as { value?: string }).value\n            : null;\n      if (keyName === name) {\n        return {\n          key: objProp.key,\n          value: objProp.value,\n          start: objProp.start,\n          end: objProp.end,\n        };\n      }\n    }\n  }\n  return null;\n}\n\n/**\n * Apply string replacements to source code\n * Replacements are applied from end to start to maintain positions\n * Ranges must not overlap; applying an overlapping range on top of an\n * already-shifted string would splice at stale offsets and corrupt the output,\n * so overlap is rejected up front\n * @param source - Original source code\n * @param replacements - Replacements to apply\n * @returns Transformed source code\n */\nexport function applyReplacements(source: string, replacements: Replacement[]): string {\n  const sorted = replacements.toSorted((a, b) => b.start - a.start);\n  for (let i = 0; i + 1 < sorted.length; i++) {\n    const current = assertDefined(sorted[i], `replacement missing at index ${i}`);\n    const previous = assertDefined(sorted[i + 1], `replacement missing at index ${i + 1}`);\n    if (previous.end > current.start) {\n      throw new Error(\n        `applyReplacements: overlapping replacement ranges ` +\n          `[${previous.start}, ${previous.end}) and [${current.start}, ${current.end})`,\n      );\n    }\n  }\n  let result = source;\n  for (const r of sorted) {\n    result = result.slice(0, r.start) + r.text + result.slice(r.end);\n  }\n  return result;\n}\n\n/**\n * Find the end of a statement including any trailing newline\n * @param source - Source code\n * @param position - Start position of the statement\n * @returns Index of the end of the statement including trailing newline\n */\nexport function findStatementEnd(source: string, position: number): number {\n  let i = position;\n  // Skip any trailing semicolons and whitespace on the same line\n  while (i < source.length && (source[i] === \";\" || source[i] === \" \" || source[i] === \"\\t\")) {\n    i++;\n  }\n  // Include the newline if present\n  if (i < source.length && source[i] === \"\\n\") {\n    i++;\n  }\n  return i;\n}\n","import { type ASTNode, isTailorSdkSource, getImportSource, unwrapAwait } from \"./ast-utils\";\nimport type {\n  Program,\n  ImportDeclaration,\n  VariableDeclaration,\n  CallExpression,\n  StaticMemberExpression,\n} from \"@oxc-project/types\";\n\n/**\n * Collect all import bindings for a specific function from the Tailor SDK package\n * Returns a Set of local names that refer to the function\n * @param program - Parsed TypeScript program\n * @param functionName - Function name to collect bindings for\n * @returns Set of local names bound to the SDK function\n */\nexport function collectSdkBindings(program: Program, functionName: string): Set<string> {\n  const bindings = new Set<string>();\n\n  function walk(node: ASTNode | null | undefined): void {\n    if (!node || typeof node !== \"object\") return;\n\n    const nodeType = node.type as string | undefined;\n\n    // Static imports: import { createWorkflowJob } from \"@tailor-platform/sdk\"\n    if (nodeType === \"ImportDeclaration\") {\n      const importDecl = node as unknown as ImportDeclaration;\n      const source = importDecl.source.value;\n      if (typeof source === \"string\" && isTailorSdkSource(source)) {\n        for (const specifier of importDecl.specifiers) {\n          // import { createWorkflowJob } from \"@tailor-platform/sdk\"\n          // import { createWorkflowJob as create } from \"@tailor-platform/sdk\"\n          if (specifier.type === \"ImportSpecifier\") {\n            const importSpec = specifier;\n            const imported =\n              importSpec.imported.type === \"Identifier\"\n                ? importSpec.imported.name\n                : (importSpec.imported as { value?: string }).value;\n            if (imported === functionName) {\n              bindings.add(importSpec.local.name);\n            }\n          }\n          // import sdk from \"@tailor-platform/sdk\" → sdk.createWorkflowJob\n          // import * as sdk from \"@tailor-platform/sdk\" → sdk.createWorkflowJob\n          // callee may be a ComputedMemberExpression at runtime\n          // oxlint-disable typescript/no-unnecessary-condition\n          else if (\n            specifier.type === \"ImportDefaultSpecifier\" ||\n            specifier.type === \"ImportNamespaceSpecifier\"\n            // oxlint-enable typescript/no-unnecessary-condition\n          ) {\n            const spec = specifier;\n            // Store namespace/default with special prefix to track member access\n            bindings.add(`__namespace__:${spec.local.name}`);\n          }\n        }\n      }\n    }\n\n    // Dynamic imports and require:\n    // const sdk = await import(\"@tailor-platform/sdk\")\n    // const sdk = require(\"@tailor-platform/sdk\")\n    // const { createWorkflowJob } = await import(\"@tailor-platform/sdk\")\n    // const { createWorkflowJob } = require(\"@tailor-platform/sdk\")\n    if (nodeType === \"VariableDeclaration\") {\n      const varDecl = node as unknown as VariableDeclaration;\n      for (const decl of varDecl.declarations) {\n        const init = unwrapAwait(decl.init);\n        const source = getImportSource(init);\n\n        if (source && isTailorSdkSource(source)) {\n          const id = decl.id;\n\n          // const sdk = await import(...) / const sdk = require(...)\n          if (id.type === \"Identifier\") {\n            bindings.add(`__namespace__:${id.name}`);\n          }\n          // const { createWorkflowJob } = await import(...) / require(...)\n          // const { createWorkflowJob: create } = await import(...) / require(...)\n          else if (id.type === \"ObjectPattern\") {\n            const objPattern = id;\n            for (const prop of objPattern.properties) {\n              if (prop.type === \"Property\") {\n                const bindingProp = prop;\n                const keyName =\n                  bindingProp.key.type === \"Identifier\"\n                    ? bindingProp.key.name\n                    : (bindingProp.key as { value?: string }).value;\n                if (keyName === functionName) {\n                  const localName =\n                    bindingProp.value.type === \"Identifier\" ? bindingProp.value.name : keyName;\n                  bindings.add(localName);\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n\n    for (const key of Object.keys(node)) {\n      const child = node[key];\n      if (Array.isArray(child)) {\n        child.forEach((c: unknown) => walk(c as ASTNode | null));\n      } else if (child && typeof child === \"object\") {\n        walk(child as ASTNode);\n      }\n    }\n  }\n\n  walk(program as unknown as ASTNode);\n  return bindings;\n}\n\n/**\n * Check if a CallExpression is a call to a specific SDK function\n * @param node - AST node to inspect\n * @param bindings - Collected SDK bindings\n * @param functionName - SDK function name\n * @returns True if node is a call to the SDK function\n */\nexport function isSdkFunctionCall(\n  node: ASTNode,\n  bindings: Set<string>,\n  functionName: string,\n): node is ASTNode & { type: \"CallExpression\" } {\n  if (node.type !== \"CallExpression\") return false;\n\n  const callExpr = node as unknown as CallExpression;\n  const callee = callExpr.callee;\n\n  // Direct call: createWorkflowJob(...) or create(...)\n  if (callee.type === \"Identifier\") {\n    const identifier = callee;\n    return bindings.has(identifier.name);\n  }\n\n  // Member access: sdk.createWorkflowJob(...)\n  // Note: oxc uses MemberExpression with computed: false for static member access\n  if (callee.type === \"MemberExpression\") {\n    const memberExpr = callee as unknown as StaticMemberExpression;\n    // callee may be a ComputedMemberExpression at runtime\n    // oxlint-disable-next-line typescript/no-unnecessary-condition\n    if (!memberExpr.computed) {\n      const object = memberExpr.object;\n      const property = memberExpr.property;\n      if (\n        object.type === \"Identifier\" &&\n        bindings.has(`__namespace__:${object.name}`) &&\n        property.name === functionName\n      ) {\n        return true;\n      }\n    }\n  }\n\n  return false;\n}\n","import { assertDefined } from \"#/utils/assert\";\nimport { type ASTNode, isStringLiteral, isFunctionExpression, findProperty } from \"./ast-utils\";\nimport { collectSdkBindings, isSdkFunctionCall } from \"./sdk-binding-collector\";\nimport type { Program, CallExpression } from \"@oxc-project/types\";\n\nexport interface JobLocation {\n  name: string;\n  exportName?: string;\n  nameRange: { start: number; end: number };\n  bodyValueRange: { start: number; end: number };\n  // Range of the entire variable declaration statement (for removal)\n  statementRange?: { start: number; end: number };\n}\n\n/**\n * Find all workflow jobs by detecting createWorkflowJob calls from `@tailor-platform/sdk`\n * @param program - Parsed TypeScript program\n * @param _sourceText - Source code text (currently unused)\n * @returns Detected job locations\n */\nexport function findAllJobs(program: Program, _sourceText: string): JobLocation[] {\n  const jobs: JobLocation[] = [];\n  const bindings = collectSdkBindings(program, \"createWorkflowJob\");\n\n  function walk(node: ASTNode | null | undefined, parents: ASTNode[] = []): void {\n    if (!node || typeof node !== \"object\") return;\n\n    // Detect createWorkflowJob(...) calls\n    if (isSdkFunctionCall(node, bindings, \"createWorkflowJob\")) {\n      const callExpr = node as unknown as CallExpression;\n      const args = callExpr.arguments;\n      const firstArg = args[0];\n      if (args.length >= 1 && firstArg?.type === \"ObjectExpression\") {\n        const configObj = assertDefined(firstArg, \"createWorkflowJob first argument missing\");\n        const nameProp = findProperty(configObj.properties, \"name\");\n        const bodyProp = findProperty(configObj.properties, \"body\");\n\n        if (\n          nameProp &&\n          isStringLiteral(nameProp.value) &&\n          bodyProp &&\n          isFunctionExpression(bodyProp.value)\n        ) {\n          // Find the outermost enclosing statement and export name\n          // Iterate from closest parent (end of array) to farthest (start of array)\n          let statementRange: { start: number; end: number } | undefined;\n          let exportName: string | undefined;\n          for (let i = parents.length - 1; i >= 0; i--) {\n            const parent = assertDefined(parents[i], `parent at index ${i} missing`);\n            if (parent.type === \"VariableDeclarator\") {\n              const declarator = parent as unknown as {\n                id?: { type?: string; name?: string };\n              };\n              if (declarator.id?.type === \"Identifier\") {\n                exportName = declarator.id.name;\n              }\n            }\n            // Keep track of the outermost statement (ExportNamedDeclaration > VariableDeclaration)\n            if (parent.type === \"ExportNamedDeclaration\" || parent.type === \"VariableDeclaration\") {\n              statementRange = {\n                start: parent.start as number,\n                end: parent.end as number,\n              };\n              // Don't break - continue to find ExportNamedDeclaration if it exists\n            }\n          }\n\n          jobs.push({\n            name: nameProp.value.value,\n            exportName,\n            nameRange: { start: nameProp.start, end: nameProp.end },\n            bodyValueRange: {\n              start: bodyProp.value.start,\n              end: bodyProp.value.end,\n            },\n            statementRange,\n          });\n        }\n      }\n    }\n\n    const newParents = [...parents, node];\n    for (const key of Object.keys(node)) {\n      const child = node[key];\n      if (Array.isArray(child)) {\n        child.forEach((c: unknown) => walk(c as ASTNode | null, newParents));\n      } else if (child && typeof child === \"object\") {\n        walk(child as ASTNode, newParents);\n      }\n    }\n  }\n\n  walk(program as unknown as ASTNode);\n  return jobs;\n}\n","import { assertDefined } from \"#/utils/assert\";\nimport { type ASTNode, isStringLiteral, findProperty } from \"./ast-utils\";\nimport { collectSdkBindings, isSdkFunctionCall } from \"./sdk-binding-collector\";\nimport type { Program, CallExpression } from \"@oxc-project/types\";\n\nexport interface WorkflowLocation {\n  name: string;\n  exportName?: string;\n  isDefaultExport?: boolean;\n}\n\n/**\n * Find all workflows by detecting createWorkflow calls from `@tailor-platform/sdk`\n * @param program - Parsed TypeScript program\n * @param _sourceText - Source code text (currently unused)\n * @returns Detected workflows\n */\nexport function findAllWorkflows(program: Program, _sourceText: string): WorkflowLocation[] {\n  const workflows: WorkflowLocation[] = [];\n  const bindings = collectSdkBindings(program, \"createWorkflow\");\n\n  function walk(node: ASTNode | null | undefined, parents: ASTNode[] = []): void {\n    if (!node || typeof node !== \"object\") return;\n\n    // Detect createWorkflow(...) calls\n    if (isSdkFunctionCall(node, bindings, \"createWorkflow\")) {\n      const callExpr = node as unknown as CallExpression;\n      const args = callExpr.arguments;\n      const firstArg = args[0];\n      if (args.length >= 1 && firstArg?.type === \"ObjectExpression\") {\n        const configObj = assertDefined(firstArg, \"createWorkflow first argument missing\");\n        const nameProp = findProperty(configObj.properties, \"name\");\n\n        if (nameProp && isStringLiteral(nameProp.value)) {\n          // Find export name from parent declarations\n          let exportName: string | undefined;\n          let isDefaultExport = false;\n          for (let i = parents.length - 1; i >= 0; i--) {\n            const parent = assertDefined(parents[i], `parent at index ${i} missing`);\n            if (parent.type === \"VariableDeclarator\") {\n              const declarator = parent as unknown as {\n                id?: { type?: string; name?: string };\n              };\n              if (declarator.id?.type === \"Identifier\") {\n                exportName = declarator.id.name;\n                break;\n              }\n            }\n            // Check for export default createWorkflow(...)\n            if (parent.type === \"ExportDefaultDeclaration\") {\n              isDefaultExport = true;\n            }\n          }\n\n          workflows.push({\n            name: nameProp.value.value,\n            exportName,\n            isDefaultExport,\n          });\n        }\n      }\n    }\n\n    const newParents = [...parents, node];\n    for (const key of Object.keys(node)) {\n      const child = node[key];\n      if (Array.isArray(child)) {\n        child.forEach((c: unknown) => walk(c as ASTNode | null, newParents));\n      } else if (child && typeof child === \"object\") {\n        walk(child as ASTNode, newParents);\n      }\n    }\n  }\n\n  walk(program as unknown as ASTNode);\n  return workflows;\n}\n","import * as fs from \"node:fs\";\nimport { parseSync } from \"oxc-parser\";\nimport * as path from \"pathe\";\nimport { loadFilesWithIgnores, type FileLoadConfig } from \"#/cli/services/file-loader\";\nimport { getModuleExportName, type ASTNode } from \"#/cli/services/workflow/ast-utils\";\nimport { findAllJobs } from \"#/cli/services/workflow/job-detector\";\nimport { findAllWorkflows } from \"#/cli/services/workflow/workflow-detector\";\nimport { logger } from \"#/cli/shared/logger\";\n\nexport interface StartTarget {\n  kind: \"job\" | \"workflow\";\n  name: string;\n}\n\nexport interface StartModuleBindings {\n  sourceFile: string;\n  localBindings: Map<string, StartTarget>;\n  exports: Map<string, StartTarget>;\n}\n\nexport interface StartContext {\n  modules: Map<string, StartModuleBindings>;\n  authNamespace?: string;\n}\n\n/**\n * Normalize a source module path for start-call binding lookup.\n * @param filePath - Source file path or extensionless relative import path\n * @returns Absolute path without a JavaScript or TypeScript extension\n */\nexport function normalizeFilePath(filePath: string): string {\n  return path.resolve(filePath.replace(/[?#].*$/, \"\")).replace(/\\.(ts|mts|cts|js|mjs|cjs)$/, \"\");\n}\n\nfunction createModuleBindings(\n  sourceFile: string,\n  program: ReturnType<typeof parseSync>[\"program\"],\n  source: string,\n) {\n  const localBindings = new Map<string, StartTarget>();\n  const exports = new Map<string, StartTarget>();\n\n  for (const workflow of findAllWorkflows(program, source)) {\n    const target = { kind: \"workflow\", name: workflow.name } as const;\n    if (workflow.exportName) localBindings.set(workflow.exportName, target);\n    if (workflow.isDefaultExport) exports.set(\"default\", target);\n  }\n\n  for (const job of findAllJobs(program, source)) {\n    if (job.exportName) {\n      localBindings.set(job.exportName, { kind: \"job\", name: job.name });\n    }\n  }\n\n  for (const statement of program.body as unknown as ASTNode[]) {\n    if (statement.type === \"ExportDefaultDeclaration\") {\n      const declaration = statement.declaration as ASTNode | undefined;\n      if (declaration?.type === \"Identifier\") {\n        const target = localBindings.get(declaration.name as string);\n        if (target) exports.set(\"default\", target);\n      }\n      continue;\n    }\n\n    if (statement.type !== \"ExportNamedDeclaration\") continue;\n    const declaration = statement.declaration as ASTNode | undefined;\n    if (declaration?.type === \"VariableDeclaration\") {\n      for (const declarator of declaration.declarations as ASTNode[]) {\n        const id = declarator.id as ASTNode | undefined;\n        if (id?.type !== \"Identifier\") continue;\n        const localName = id.name as string;\n        const target = localBindings.get(localName);\n        if (target) exports.set(localName, target);\n      }\n    }\n\n    if (statement.source) continue;\n    for (const specifier of (statement.specifiers as ASTNode[] | undefined) ?? []) {\n      const localName = getModuleExportName(specifier.local);\n      const exportedName = getModuleExportName(specifier.exported);\n      if (!localName || !exportedName) continue;\n      const target = localBindings.get(localName);\n      if (target) exports.set(exportedName, target);\n    }\n  }\n\n  return { sourceFile, localBindings, exports } satisfies StartModuleBindings;\n}\n\n/**\n * Build start-call context from configured workflow source files.\n * @param workflowConfig - Workflow file loading configuration\n * @param authNamespace - Auth service namespace (optional, used for string-literal invoker expansion)\n * @param baseDir - Directory the workflow config's file patterns are resolved against (defaults to process.cwd())\n * @returns Module-local workflow and job binding metadata\n */\nexport async function buildStartContext(\n  workflowConfig: FileLoadConfig | undefined,\n  authNamespace?: string,\n  baseDir = process.cwd(),\n): Promise<StartContext> {\n  const modules = new Map<string, StartModuleBindings>();\n  if (!workflowConfig) return { modules, authNamespace };\n\n  for (const file of loadFilesWithIgnores(workflowConfig, baseDir)) {\n    try {\n      const source = await fs.promises.readFile(file, \"utf-8\");\n      const { program, errors } = parseSync(file, source);\n      if (errors.length > 0) {\n        logger.warn(\n          `Failed to parse workflow file ${file}: ${errors.map((e) => e.message).join(\"; \")}`,\n          { mode: \"stream\" },\n        );\n        continue;\n      }\n      modules.set(normalizeFilePath(file), createModuleBindings(file, program, source));\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      logger.warn(`Failed to process workflow file ${file}: ${errorMessage}`, {\n        mode: \"stream\",\n      });\n    }\n  }\n\n  return { modules, authNamespace };\n}\n\nfunction sortedTargets(bindings: Map<string, StartTarget>) {\n  return [...bindings]\n    .toSorted(([a], [b]) => a.localeCompare(b))\n    .map(([binding, target]) => [binding, target.kind, target.name]);\n}\n\n/**\n * Serialize start-call context to a deterministic cache input.\n * @param context - Start-call context to serialize\n * @returns Deterministic string, or an empty string when context is absent\n */\nexport function serializeStartContext(context: StartContext | undefined): string {\n  if (!context) return \"\";\n  const modules = [...context.modules]\n    .toSorted(([a], [b]) => a.localeCompare(b))\n    .map(([file, bindings]) => [\n      file,\n      sortedTargets(bindings.localBindings),\n      sortedTargets(bindings.exports),\n    ]);\n  return JSON.stringify(modules) + (context.authNamespace ?? \"\");\n}\n","import { parseSync } from \"oxc-parser\";\nimport * as path from \"pathe\";\nimport { logger } from \"#/cli/shared/logger\";\nimport {\n  normalizeFilePath,\n  type StartContext,\n  type StartModuleBindings,\n  type StartTarget,\n} from \"#/cli/shared/start-context\";\nimport {\n  type ASTNode,\n  type Replacement,\n  type StartCallInfo,\n  applyReplacements,\n  getModuleExportName,\n  getStartCallInfo,\n} from \"./ast-utils\";\nimport type { Program } from \"@oxc-project/types\";\nimport type { Plugin } from \"rolldown\";\n\nexport interface ResolvedStartCall extends StartCallInfo {\n  kind: \"job\" | \"workflow\";\n  targetName: string;\n}\n\nconst START_CALL_RE = /\\.start(?:\\s|\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\n]*\\n)*\\(/;\n\n/**\n * Fast pre-check for whether `code` contains a `.start(` call, tolerating\n * whitespace, newlines, and comments between `.start` and `(` that a plain\n * substring check would miss.\n * @param code - Source text to scan\n * @returns Whether `code` contains a `.start(` call\n */\nexport function hasStartCall(code: string): boolean {\n  return START_CALL_RE.test(code);\n}\n\nconst NORMALIZER_IDENTIFIER = \"__tailor_normalizeStartOptions\";\n\n/**\n * Build the source text of the injected normalizer helper.\n *\n * Renames an `invoker` in the start options to the `authInvoker` form the\n * platform RPC expects: a plain string (machine user name) becomes\n * `{ namespace, machineUserName }`, while an object form passes through\n * as-is. Any other options value is unchanged. The auth namespace is baked\n * in at bundle time.\n * @param authNamespace - Auth service namespace to embed\n * @returns Source line defining the helper\n */\nfunction buildNormalizerHelperSource(authNamespace: string): string {\n  return `const ${NORMALIZER_IDENTIFIER} = (o) => { if (!o) return o; const { invoker, ...rest } = o; return typeof invoker === \"string\" ? { ...rest, authInvoker: { namespace: ${JSON.stringify(authNamespace)}, machineUserName: invoker } } : typeof invoker === \"object\" ? { ...rest, authInvoker: invoker } : o; };\\n`;\n}\n\nfunction collectBindingNames(node: ASTNode | null | undefined, names: Set<string>): void {\n  if (!node || typeof node !== \"object\") return;\n\n  switch (node.type) {\n    case \"Identifier\":\n      names.add(node.name as string);\n      return;\n    case \"ObjectPattern\":\n      for (const property of node.properties as ASTNode[]) {\n        collectBindingNames(\n          property.type === \"RestElement\"\n            ? (property.argument as ASTNode)\n            : (property.value as ASTNode),\n          names,\n        );\n      }\n      return;\n    case \"ArrayPattern\":\n      for (const element of node.elements as Array<ASTNode | null>) {\n        collectBindingNames(element, names);\n      }\n      return;\n    case \"AssignmentPattern\":\n      collectBindingNames(node.left as ASTNode, names);\n      return;\n    case \"RestElement\":\n      collectBindingNames(node.argument as ASTNode, names);\n      return;\n    case \"TSParameterProperty\":\n      collectBindingNames(node.parameter as ASTNode, names);\n  }\n}\n\nfunction declarationNode(statement: ASTNode): ASTNode | undefined {\n  return statement.type === \"ExportNamedDeclaration\" ||\n    statement.type === \"ExportDefaultDeclaration\"\n    ? (statement.declaration as ASTNode | undefined)\n    : statement;\n}\n\nfunction collectBlockBindings(statements: ASTNode[], names: Set<string>): void {\n  for (const statement of statements) {\n    const declaration = declarationNode(statement);\n    if (!declaration) continue;\n\n    if (declaration.type === \"VariableDeclaration\") {\n      if (declaration.kind === \"var\") continue;\n      for (const declarator of declaration.declarations as ASTNode[]) {\n        collectBindingNames(declarator.id as ASTNode, names);\n      }\n    } else if (\n      declaration.type === \"FunctionDeclaration\" ||\n      declaration.type === \"ClassDeclaration\"\n    ) {\n      collectBindingNames(declaration.id as ASTNode | undefined, names);\n    }\n  }\n}\n\nfunction collectFunctionVarBindings(root: ASTNode, names: Set<string>): void {\n  function walk(node: ASTNode | null | undefined): void {\n    if (!node || typeof node !== \"object\") return;\n    if (\n      node !== root &&\n      (node.type === \"FunctionDeclaration\" ||\n        node.type === \"FunctionExpression\" ||\n        node.type === \"ArrowFunctionExpression\" ||\n        node.type === \"StaticBlock\")\n    ) {\n      return;\n    }\n    if (node.type === \"VariableDeclaration\" && node.kind === \"var\") {\n      for (const declarator of node.declarations as ASTNode[]) {\n        collectBindingNames(declarator.id as ASTNode, names);\n      }\n    }\n    for (const key of Object.keys(node)) {\n      if (key === \"parent\") continue;\n      const child = node[key];\n      if (Array.isArray(child)) {\n        for (const item of child) walk(item as ASTNode | null);\n      } else if (child && typeof child === \"object\") {\n        walk(child as ASTNode);\n      }\n    }\n  }\n\n  walk(root);\n}\n\nfunction collectScopeBindings(node: ASTNode): Set<string> | undefined {\n  const names = new Set<string>();\n\n  if (\n    node.type === \"FunctionDeclaration\" ||\n    node.type === \"FunctionExpression\" ||\n    node.type === \"ArrowFunctionExpression\"\n  ) {\n    collectBindingNames(node.id as ASTNode | undefined, names);\n    for (const parameter of node.params as ASTNode[]) {\n      collectBindingNames(parameter, names);\n    }\n    collectFunctionVarBindings(node, names);\n    return names;\n  }\n\n  if (node.type === \"BlockStatement\") {\n    collectBlockBindings(node.body as ASTNode[], names);\n    return names;\n  }\n\n  if (node.type === \"CatchClause\") {\n    collectBindingNames(node.param as ASTNode | undefined, names);\n    return names;\n  }\n\n  if (\n    node.type === \"ForStatement\" ||\n    node.type === \"ForInStatement\" ||\n    node.type === \"ForOfStatement\"\n  ) {\n    const declaration = (node.init ?? node.left) as ASTNode | undefined;\n    if (declaration?.type === \"VariableDeclaration\" && declaration.kind !== \"var\") {\n      for (const declarator of declaration.declarations as ASTNode[]) {\n        collectBindingNames(declarator.id as ASTNode, names);\n      }\n    }\n    return names;\n  }\n\n  return undefined;\n}\n\nfunction addShadowedBindings(\n  shadowedNames: ReadonlySet<string>,\n  bindings: Set<string> | undefined,\n  targetNames: ReadonlySet<string>,\n): ReadonlySet<string> {\n  if (!bindings) return shadowedNames;\n  const relevantBindings = [...bindings].filter((name) => targetNames.has(name));\n  return relevantBindings.length === 0\n    ? shadowedNames\n    : new Set([...shadowedNames, ...relevantBindings]);\n}\n\nfunction walkBindingAware(\n  program: Program,\n  targetNames: ReadonlySet<string>,\n  visitor: (\n    node: ASTNode,\n    shadowedNames: ReadonlySet<string>,\n    parentNode?: ASTNode,\n    parentKey?: string,\n  ) => void,\n): void {\n  function walk(\n    node: ASTNode | null | undefined,\n    shadowedNames: ReadonlySet<string>,\n    parentNode?: ASTNode,\n    parentKey?: string,\n  ): void {\n    if (!node || typeof node !== \"object\" || node.type === \"ImportDeclaration\") return;\n\n    const nestedShadowedNames =\n      node.type === \"Program\"\n        ? shadowedNames\n        : addShadowedBindings(shadowedNames, collectScopeBindings(node), targetNames);\n    visitor(node, nestedShadowedNames, parentNode, parentKey);\n\n    for (const key of Object.keys(node)) {\n      if (key === \"parent\") continue;\n      const child = node[key];\n      if (Array.isArray(child)) {\n        for (const item of child) {\n          walk(item as ASTNode | null, nestedShadowedNames, node, key);\n        }\n      } else if (child && typeof child === \"object\") {\n        walk(child as ASTNode, nestedShadowedNames, node, key);\n      }\n    }\n  }\n\n  walk(program as unknown as ASTNode, new Set());\n}\n\nfunction resolveRelativeImport(\n  context: StartContext,\n  currentFilePath: string,\n  importSource: string,\n): StartModuleBindings | undefined {\n  if (!importSource.startsWith(\".\")) return undefined;\n  const currentDirectory = path.dirname(currentFilePath.replace(/[?#].*$/, \"\"));\n  const modulePath = normalizeFilePath(path.resolve(currentDirectory, importSource));\n  return context.modules.get(modulePath) ?? context.modules.get(path.join(modulePath, \"index\"));\n}\n\nfunction collectLocalTargets(\n  program: Program,\n  context: StartContext,\n  currentFilePath: string,\n): Map<string, StartTarget> {\n  const targets = new Map<string, StartTarget>();\n  const currentModule = context.modules.get(normalizeFilePath(currentFilePath));\n  if (currentModule) {\n    for (const [localName, target] of currentModule.localBindings) {\n      targets.set(localName, target);\n    }\n  }\n\n  for (const statement of program.body) {\n    if (statement.type !== \"ImportDeclaration\" || statement.importKind === \"type\") continue;\n    const importSource = statement.source.value;\n    if (typeof importSource !== \"string\") continue;\n    const importedModule = resolveRelativeImport(context, currentFilePath, importSource);\n    if (!importedModule) continue;\n\n    for (const specifier of statement.specifiers) {\n      if (specifier.type === \"ImportNamespaceSpecifier\") continue;\n      if (specifier.type === \"ImportSpecifier\" && specifier.importKind === \"type\") continue;\n\n      const importedName =\n        specifier.type === \"ImportDefaultSpecifier\"\n          ? \"default\"\n          : getModuleExportName(specifier.imported);\n      if (!importedName) continue;\n      const target = importedModule.exports.get(importedName);\n      if (!target) continue;\n      targets.set(specifier.local.name, target);\n    }\n  }\n\n  return targets;\n}\n\nfunction detectStartCallsWithTargets(\n  program: Program,\n  sourceText: string,\n  targets: Map<string, StartTarget>,\n): ResolvedStartCall[] {\n  const calls: ResolvedStartCall[] = [];\n  const targetNames = new Set(targets.keys());\n\n  walkBindingAware(program, targetNames, (node, shadowedNames) => {\n    const startCall = getStartCallInfo(node, sourceText);\n    if (!startCall || shadowedNames.has(startCall.identifierName)) return;\n    const target = targets.get(startCall.identifierName);\n    if (target) {\n      calls.push({ ...startCall, kind: target.kind, targetName: target.name });\n    }\n  });\n\n  return calls;\n}\n\nexport function detectResolvedStartCalls(\n  program: Program,\n  sourceText: string,\n  context: StartContext,\n  currentFilePath: string,\n): ResolvedStartCall[] {\n  return detectStartCallsWithTargets(\n    program,\n    sourceText,\n    collectLocalTargets(program, context, currentFilePath),\n  );\n}\n\nexport function transformStartCalls(\n  source: string,\n  startContext: StartContext,\n  currentFilePath: string,\n): string {\n  const { program } = parseSync(\"input.ts\", source);\n  const localTargets = collectLocalTargets(program, startContext, currentFilePath);\n  const { authNamespace } = startContext;\n  const allStartCalls = detectStartCallsWithTargets(program, source, localTargets);\n  const nestedStartCalls: Array<{ call: ResolvedStartCall; parent: ResolvedStartCall }> = [];\n  const startCalls = allStartCalls.filter((call) => {\n    const parent = allStartCalls.find(\n      (other) =>\n        other !== call &&\n        other.callRange.start <= call.callRange.start &&\n        call.callRange.end <= other.callRange.end,\n    );\n    if (!parent) return true;\n    nestedStartCalls.push({ call, parent });\n    return false;\n  });\n\n  for (const { call, parent } of nestedStartCalls) {\n    logger.warn(\n      `Nested start call \"${call.identifierName}.start(...)\" inside \"${parent.identifierName}.start(...)\" cannot be converted. Move it to a separate statement and pass the result instead.`,\n    );\n  }\n\n  const replacements: Replacement[] = [];\n  // Whether any workflow start invoker was wrapped with the runtime\n  // normalizer. Used to decide whether to inject the helper at the top.\n  let needsNormalizerHelper = false;\n\n  for (const call of startCalls) {\n    let transformedCall: string;\n    if (call.kind === \"workflow\") {\n      let optionsPart = \"\";\n      if (call.optionsText !== undefined) {\n        if (authNamespace) {\n          optionsPart = `, ${NORMALIZER_IDENTIFIER}(${call.optionsText})`;\n          needsNormalizerHelper = true;\n        } else {\n          optionsPart = `, ${call.optionsText}`;\n        }\n      }\n      transformedCall = `tailor.workflow.startWorkflow(${JSON.stringify(call.targetName)}, ${call.argsText || \"undefined\"}${optionsPart})`;\n    } else {\n      const optionsPart = call.optionsText !== undefined ? `, ${call.optionsText}` : \"\";\n      transformedCall = `tailor.workflow.execJobFunction(${JSON.stringify(call.targetName)}, ${call.argsText || \"undefined\"}${optionsPart})`;\n    }\n    replacements.push({\n      start: call.callRange.start,\n      end: call.callRange.end,\n      text: transformedCall,\n    });\n  }\n\n  const transformed = applyReplacements(source, replacements);\n  return needsNormalizerHelper && authNamespace\n    ? buildNormalizerHelperSource(authNamespace) + transformed\n    : transformed;\n}\n\nexport function createStartTransformPlugin(\n  startContext: StartContext | undefined,\n): Plugin | undefined {\n  if (!startContext || startContext.modules.size === 0) return undefined;\n\n  return {\n    name: \"start-transform\",\n    transform: {\n      filter: { id: { include: [/\\.(ts|mts|cts|js|mjs|cjs)$/] } },\n      handler(code, id) {\n        if (!hasStartCall(code)) return null;\n        return { code: transformStartCalls(code, startContext, id) };\n      },\n    },\n  };\n}\n","import { NODE_ONLY_GLOBALS } from \"#/utils/es-builtins\";\n\nexport {\n  getForbiddenGlobalMessage,\n  getNodeBuiltinMessage,\n  isNodeBuiltinImport,\n} from \"@tailor-platform/shared/node-builtins\";\n\nexport function isForbiddenGlobal(name: string): boolean {\n  return NODE_ONLY_GLOBALS.has(name);\n}\n","import { CLIError } from \"#/cli/shared/errors\";\nimport { getNodeBuiltinMessage, isNodeBuiltinImport } from \"#/utils/node-builtins\";\nimport type * as rolldown from \"rolldown\";\n\n// rolldown externalizes an import it cannot resolve and reports it as a\n// warning, so a bundle that still contains the bare specifier would otherwise\n// deploy as a success and only fail once the platform runs it. `logLevel`\n// cannot stay `\"silent\"` here: rolldown's level gate drops warnings before\n// `onLog` is ever consulted, so the escalation only sees the log at `\"warn\"`.\n// Every other log stays suppressed by never delegating to `defaultHandler`.\nconst ESCALATED_LOG_CODE = \"UNRESOLVED_IMPORT\";\n\nexport interface BundleLogOptions {\n  /** Absolute path of the tsconfig handed to rolldown, when one was resolved. */\n  tsconfig?: string;\n}\n\ninterface BundleLogRolldownOptions {\n  logLevel: \"warn\";\n  onLog: NonNullable<rolldown.InputOptions[\"onLog\"]>;\n}\n\nexport interface BundleLog {\n  options: BundleLogRolldownOptions;\n  assertAllResolved(): void;\n}\n\n/**\n * Collect unresolved imports while keeping every other rolldown log suppressed.\n * @param options - Context used to explain which tsconfig was in effect\n * @returns Rolldown options and a post-build assertion\n */\nexport function createBundleLog(options: BundleLogOptions = {}): BundleLog {\n  const unresolvedImports = new Map<string, rolldown.RollupLog>();\n  return {\n    options: {\n      logLevel: \"warn\",\n      onLog: (_level, log) => {\n        if (log.code !== ESCALATED_LOG_CODE) return;\n        unresolvedImports.set(JSON.stringify([log.exporter, log.id]), log);\n      },\n    },\n    assertAllResolved() {\n      if (unresolvedImports.size > 0) {\n        throw unresolvedImportError([...unresolvedImports.values()], options.tsconfig);\n      }\n    },\n  };\n}\n\nfunction unresolvedImportError(logs: rolldown.RollupLog[], tsconfig: string | undefined): Error {\n  const imports = logs.map(formatUnresolvedImport);\n  const message =\n    imports.length === 1\n      ? `Could not resolve ${imports[0]}.`\n      : `Could not resolve ${imports.length} imports.`;\n  const details = imports.length === 1 ? undefined : imports.map((item) => `- ${item}`).join(\"\\n\");\n  const suggestion = unresolvedImportSuggestion(logs, tsconfig);\n  return CLIError({\n    code: \"UNRESOLVED_IMPORT\",\n    message,\n    details,\n    suggestion,\n  });\n}\n\nfunction unresolvedImportSuggestion(\n  logs: rolldown.RollupLog[],\n  tsconfig: string | undefined,\n): string {\n  const nodeSuggestions = logs\n    .map((log) => log.exporter)\n    .filter((specifier): specifier is string => specifier !== undefined)\n    .filter(isNodeBuiltinImport)\n    .map(getNodeBuiltinMessage);\n  const hasOtherImports = logs.some(\n    (log) => log.exporter === undefined || !isNodeBuiltinImport(log.exporter),\n  );\n  const pathSuggestion = tsconfig\n    ? `Check that each import path is correct, and that a \\`compilerOptions.paths\\` entry covering it is declared in the importing file's own tsconfig.json or an ancestor. The build used \"${tsconfig}\".`\n    : \"No tsconfig.json was found, so `compilerOptions.paths` aliases were not applied. Add a tsconfig.json declaring the aliases these files import.\";\n  return [...new Set([...nodeSuggestions, ...(hasOtherImports ? [pathSuggestion] : [])])].join(\n    \"\\n\",\n  );\n}\n\nfunction formatUnresolvedImport(log: rolldown.RollupLog): string {\n  const specifier = log.exporter ?? \"an imported module\";\n  // A virtual entry's id carries a leading `\\0`, which renders as a stray\n  // control character; name the bundler's generated entry instead.\n  const importerId = log.id?.startsWith(\"\\0\")\n    ? `a generated entry (${log.id.slice(1)})`\n    : log.id && `\"${log.id}\"`;\n  const importer = importerId ? ` imported from ${importerId}` : \"\";\n  return `\"${specifier}\"${importer}`;\n}\n","import { isLogLevel, LOG_LEVELS } from \"#/parser/app-config/log-level\";\nimport type { LogLevel, LogLevelInput } from \"#/configure/config/types\";\nimport type { TreeshakingOptions } from \"rolldown\";\n\nconst INFO_LEVEL_CONSOLE_METHODS = [\n  \"console.info\",\n  \"console.table\",\n  \"console.dir\",\n  \"console.dirxml\",\n  \"console.count\",\n  \"console.countReset\",\n  \"console.time\",\n  \"console.timeLog\",\n  \"console.timeEnd\",\n  \"console.group\",\n  \"console.groupCollapsed\",\n  \"console.groupEnd\",\n  \"console.clear\",\n] as const;\n\n// `console.log` is treated as a DEBUG-level method to stay consistent with the\n// platform's OpenTelemetry severity mapping, where the deployment runtime emits\n// `console.log` at DEBUG severity rather than INFO.\nconst DEBUG_LEVEL_CONSOLE_METHODS = [\"console.debug\", \"console.log\", \"console.trace\"] as const;\n\nconst WARN_LEVEL_CONSOLE_METHODS = [\"console.warn\"] as const;\n\n// `console.assert` is intentionally excluded: on the deployment runtime\n// (deno_core/V8) only log/debug/info/warn/error are wrapped with a log\n// severity, so `console.assert` sits outside the platform's severity system\n// and is never dropped by the log-level treeshaking.\nconst ERROR_LEVEL_CONSOLE_METHODS = [\"console.error\"] as const;\n\n// `@tailor-platform/sdk/runtime`'s `logger` wrapper calls\n// `(globalThis as {...}).tailor.logger.*` (see runtime/logger.ts); the `as`\n// cast is erased by the time treeshaking runs, so the callee this matches\n// against is the `globalThis.tailor.logger.*` member chain, not `tailor.logger.*`.\nconst DEBUG_LEVEL_LOGGER_METHODS = [\"globalThis.tailor.logger.debug\"] as const;\n\nconst INFO_LEVEL_LOGGER_METHODS = [\"globalThis.tailor.logger.info\"] as const;\n\nconst WARN_LEVEL_LOGGER_METHODS = [\"globalThis.tailor.logger.warn\"] as const;\n\nconst ERROR_LEVEL_LOGGER_METHODS = [\"globalThis.tailor.logger.error\"] as const;\n\nconst MANUAL_PURE_FUNCTIONS_BY_LOG_LEVEL: Record<LogLevel, readonly string[]> = {\n  DEBUG: [],\n  INFO: [...DEBUG_LEVEL_CONSOLE_METHODS, ...DEBUG_LEVEL_LOGGER_METHODS],\n  WARN: [\n    ...DEBUG_LEVEL_CONSOLE_METHODS,\n    ...INFO_LEVEL_CONSOLE_METHODS,\n    ...DEBUG_LEVEL_LOGGER_METHODS,\n    ...INFO_LEVEL_LOGGER_METHODS,\n  ],\n  ERROR: [\n    ...DEBUG_LEVEL_CONSOLE_METHODS,\n    ...INFO_LEVEL_CONSOLE_METHODS,\n    ...WARN_LEVEL_CONSOLE_METHODS,\n    ...DEBUG_LEVEL_LOGGER_METHODS,\n    ...INFO_LEVEL_LOGGER_METHODS,\n    ...WARN_LEVEL_LOGGER_METHODS,\n  ],\n  SILENT: [\n    ...DEBUG_LEVEL_CONSOLE_METHODS,\n    ...INFO_LEVEL_CONSOLE_METHODS,\n    ...WARN_LEVEL_CONSOLE_METHODS,\n    ...ERROR_LEVEL_CONSOLE_METHODS,\n    ...DEBUG_LEVEL_LOGGER_METHODS,\n    ...INFO_LEVEL_LOGGER_METHODS,\n    ...WARN_LEVEL_LOGGER_METHODS,\n    ...ERROR_LEVEL_LOGGER_METHODS,\n  ],\n};\n\nexport function normalizeBundleLogLevel(value: string): LogLevel | undefined {\n  const normalized = value.trim().toUpperCase();\n  return isLogLevel(normalized) ? normalized : undefined;\n}\n\nexport function resolveBundleLogLevel(configValue?: LogLevelInput): LogLevel {\n  if (configValue === undefined) return \"DEBUG\";\n  const resolved = normalizeBundleLogLevel(configValue);\n  if (resolved) return resolved;\n\n  throw new Error(`Invalid logLevel \"${configValue}\". Expected one of: ${LOG_LEVELS.join(\", \")}`);\n}\n\nexport function manualPureFunctionsForLogLevel(logLevel: LogLevel): readonly string[] {\n  return MANUAL_PURE_FUNCTIONS_BY_LOG_LEVEL[logLevel];\n}\n\nexport function createLogLevelTreeshakeOptions(logLevel: LogLevel): TreeshakingOptions {\n  const manualPureFunctions = manualPureFunctionsForLogLevel(logLevel);\n  return manualPureFunctions.length > 0 ? { manualPureFunctions } : {};\n}\n","import type { TreeshakingOptions } from \"rolldown\";\n\nconst BASE_FUNCTION_TREESHAKE_OPTIONS = {\n  moduleSideEffects: false,\n  annotations: true,\n  unknownGlobalSideEffects: false,\n} as const satisfies TreeshakingOptions;\n\nexport function mergeFunctionTreeshakeOptions(\n  fragments: readonly TreeshakingOptions[],\n): TreeshakingOptions {\n  const merged: TreeshakingOptions = {};\n  const manualPureFunctions = new Set<string>();\n\n  for (const fragment of fragments) {\n    Object.assign(merged, fragment);\n    for (const name of fragment.manualPureFunctions ?? []) {\n      manualPureFunctions.add(name);\n    }\n  }\n\n  if (manualPureFunctions.size > 0) {\n    merged.manualPureFunctions = [...manualPureFunctions];\n  } else {\n    delete merged.manualPureFunctions;\n  }\n\n  return merged;\n}\n\nexport function composeFunctionTreeshakeOptions(\n  fragments: readonly TreeshakingOptions[] = [],\n): TreeshakingOptions {\n  return mergeFunctionTreeshakeOptions([BASE_FUNCTION_TREESHAKE_OPTIONS, ...fragments]);\n}\n","import type * as rolldown from \"rolldown\";\n\n// Match the exact `process.env.__TAILOR_PLATFORM_BUNDLE` member-expression: the\n// leading lookbehind rejects a longer owner (`foo.process.env…`) or identifier,\n// the trailing `\\b` rejects a longer key (`…_BUNDLE_MODE`).\nconst GATE = /(?<![\\w$.])process\\.env\\.__TAILOR_PLATFORM_BUNDLE\\b/g;\n\n// Fold the gate to `true` so the minifier DCEs the test-only workflow\n// registry/serialize runner. Apply in every bundler that builds runnable\n// functions; a missed path leaves the env read in place and fails loudly on the\n// Platform's Web runtime (no `process`), which an e2e catches. rolldown exposes\n// no `define`, so this is a transform-level replace rather than a define.\n//\n// The fold above only proves the branch dead after transform+parse; rolldown\n// still resolves every top-level import a module contains before it can shake\n// the dead branch out of the output. `createWorkflowJob`'s test-only invoker\n// wrapper (test-env-key.ts, reachable from every bundler through the public\n// `createWorkflowJob` export) needs `node:async_hooks` for correct scoping\n// across concurrent local job invocations, but that specifier is never\n// available on the Platform runtime and is unreachable there once the gate\n// folds — so resolve it as external rather than failing the build over an\n// import that never survives to the bundled output.\nexport const platformBundleDefinePlugin: rolldown.Plugin = {\n  name: \"tailor-platform-bundle-define\",\n  transform(code) {\n    if (!code.includes(\"process.env.__TAILOR_PLATFORM_BUNDLE\")) return null;\n    return { code: code.replace(GATE, \"true\") };\n  },\n  resolveId(source) {\n    if (source === \"node:async_hooks\") return { id: source, external: true };\n    return null;\n  },\n};\n","import { resolveTSConfig } from \"pkg-types\";\nimport { logger } from \"#/cli/shared/logger\";\n\n// resolveTSConfigWithFallback is called once per bundler/service, so a\n// single generate/apply run can call it multiple times for the same baseDir\n// (once per resolver/executor/tailordb/etc. config sharing that directory).\n// Track which baseDirs have already warned so each one only warns once per run.\nconst warnedBaseDirs = new Set<string>();\n\n/**\n * Resolve the nearest tsconfig.json for baseDir, falling back to the tsconfig\n * resolved from the invocation cwd when baseDir's own ancestry has none.\n * @param baseDir - Directory to resolve the tsconfig against\n * @returns Absolute path to the resolved tsconfig.json, or undefined if none was found\n */\nexport async function resolveTSConfigWithFallback(baseDir: string): Promise<string | undefined> {\n  const tsconfig = await tryResolve(baseDir);\n  if (tsconfig || baseDir === process.cwd()) {\n    return tsconfig;\n  }\n\n  // v1 compatibility fallback: pre-existing configs may rely on a tsconfig\n  // discoverable from the invocation cwd rather than baseDir. Remove this\n  // fallback in v2, once such configs are expected to have migrated.\n  const fallback = await tryResolve(process.cwd());\n  if (fallback && !warnedBaseDirs.has(baseDir)) {\n    warnedBaseDirs.add(baseDir);\n    logger.warn(\n      `No tsconfig found from \"${baseDir}\"; falling back to the tsconfig resolved from ` +\n        `process.cwd(). Move (or extend) a tsconfig into this directory before ` +\n        `v2, when this fallback will be removed.`,\n    );\n  }\n  return fallback;\n}\n\nasync function tryResolve(dir: string): Promise<string | undefined> {\n  try {\n    return await resolveTSConfig(dir);\n  } catch {\n    return undefined;\n  }\n}\n","import { type Cache, createPathsMatcher, getTsconfig } from \"get-tsconfig\";\nimport * as path from \"pathe\";\nimport type * as rolldown from \"rolldown\";\n\n// A bundler hands rolldown a single tsconfig, so its normal resolution applies\n// one `paths` table to every module in the graph. When that resolution misses an\n// import from another TypeScript project, this plugin retries it against the\n// importing file's nearest tsconfig, matching the runtime hook's lookup.\n//\n// Strictly a last resort. rolldown's `order: \"post\"` only orders this hook\n// against other plugins — it still runs ahead of the builtin resolver, and a\n// non-null return wins outright. So the handler asks rolldown to resolve the\n// specifier first and bails out when that succeeds, which keeps a real\n// node_modules package ahead of a `\"*\"` catch-all alias.\n\ntype ResolutionContext = {\n  matcher: (specifier: string) => string[];\n};\n\n/**\n * The lookup cache {@link createTsconfigPathsPlugin} maintains internally by\n * default. Share one instance across every bundle in a CLI run (via the\n * `cache` option) so bundling many items — hundreds of resolvers, say — reads\n * and parses each ancestor tsconfig once instead of once per item.\n *\n * `get-tsconfig`'s `Cache` is a plain `Map`; concurrent bundles racing to\n * populate the same key recompute the same deterministic value and simply\n * overwrite each other, so sharing it across `withBundleConcurrency` workers\n * is safe.\n */\nexport interface TsconfigLookupCache {\n  tsconfigCache: Cache;\n  contextCache: Map<string, ResolutionContext | null>;\n}\n\n/**\n * Create a {@link TsconfigLookupCache} to share across every bundle in a CLI run.\n * @returns A fresh, empty lookup cache\n */\nexport function createTsconfigLookupCache(): TsconfigLookupCache {\n  return { tsconfigCache: new Map(), contextCache: new Map() };\n}\n\nexport interface TsconfigPathsPluginOptions {\n  /**\n   * Source file a bundler's virtual entry was built from. A virtual entry has no\n   * directory of its own to resolve against, so an entry that inlines the user's\n   * own import statements must name the file they came from.\n   */\n  virtualEntrySourceFile?: string;\n  /**\n   * Called with each file path the tsconfig lookup depends on, including config\n   * candidates that do not exist yet and package metadata used to resolve an\n   * `extends` target. A cached bundler must treat these as inputs: tsconfigs are\n   * never loaded as modules, so nothing else notices when an ancestor's `paths`\n   * table changes or a nearer tsconfig.json appears.\n   */\n  onTsconfigRead?: (tsconfigPath: string) => void;\n  /**\n   * Lookup cache to share across multiple bundles in one CLI run. Defaults to\n   * a fresh cache scoped to this plugin instance when omitted.\n   */\n  cache?: TsconfigLookupCache;\n}\n\n/**\n * Create the rolldown plugin that falls back to tsconfig `paths` aliases from\n * the importing file's own nearest tsconfig.\n * @param options - Resolution context for bundlers whose entry inlines user code\n * @returns Rolldown plugin to add to a bundler's plugin list\n */\nexport function createTsconfigPathsPlugin(\n  options: TsconfigPathsPluginOptions = {},\n): rolldown.Plugin {\n  const { tsconfigCache, contextCache } = options.cache ?? createTsconfigLookupCache();\n\n  return {\n    name: \"tailor-tsconfig-paths\",\n    resolveId: {\n      order: \"post\",\n      async handler(source, importer) {\n        if (!importer) return null;\n        if (source.startsWith(\".\") || source.startsWith(\"/\") || source.startsWith(\"\\0\")) {\n          return null;\n        }\n\n        const resolutionBasis = importer.startsWith(\"\\0\")\n          ? options.virtualEntrySourceFile\n          : importer;\n        if (!resolutionBasis) return null;\n\n        // Deliberately ahead of the resolvability check below: the lookup reports\n        // the tsconfigs this import depends on, and a caching bundler needs them\n        // even when the import resolves without any alias today. Editing those\n        // tsconfigs later can change the outcome.\n        const resolution = getResolutionContext(\n          path.dirname(resolutionBasis),\n          tsconfigCache,\n          contextCache,\n          options.onTsconfigRead,\n        );\n        if (!resolution) return null;\n\n        const candidates = resolution.matcher(source);\n        if (candidates.length === 0) return null;\n\n        const alreadyResolvable = await this.resolve(source, importer, { skipSelf: true });\n        if (alreadyResolvable) return null;\n\n        // Each mapped candidate goes back through rolldown as an absolute\n        // specifier, so extension substitution, directory index files and\n        // `package.json` `main`/`exports` all behave exactly as they do for a\n        // relative import. Probing the filesystem here instead would have to\n        // restate those rules and would drift from them.\n        for (const candidate of candidates) {\n          const resolved = await this.resolve(candidate, importer, { skipSelf: true });\n          if (resolved) return resolved;\n        }\n        return null;\n      },\n    },\n  };\n}\n\nfunction getResolutionContext(\n  startDir: string,\n  tsconfigCache: Cache,\n  contextCache: Map<string, ResolutionContext | null>,\n  onTsconfigRead?: (tsconfigPath: string) => void,\n): ResolutionContext | null {\n  const cached = contextCache.get(startDir);\n  if (cached !== undefined) {\n    // A shared cache (see TsconfigLookupCache) may have resolved this exact\n    // startDir already for a different bundle; that bundle's own dependency\n    // list must not become this caller's, so still report every tsconfig\n    // reachable from tsconfigCache — a superset is safe (extra invalidation\n    // at worst), missing one is not (a stale bundle never rebuilds).\n    reportTsconfigDependencies(tsconfigCache, onTsconfigRead);\n    return cached;\n  }\n\n  const tsconfig = getTsconfig(startDir, \"tsconfig.json\", tsconfigCache);\n  reportTsconfigDependencies(tsconfigCache, onTsconfigRead);\n  const paths = tsconfig?.config.compilerOptions?.paths;\n  const matcher = paths && Object.keys(paths).length > 0 ? createPathsMatcher(tsconfig) : null;\n  const resolution = matcher ? { matcher } : null;\n\n  contextCache.set(startDir, resolution);\n  return resolution;\n}\n\nfunction reportTsconfigDependencies(\n  cache: Cache,\n  onTsconfigRead?: (tsconfigPath: string) => void,\n): void {\n  if (!onTsconfigRead) return;\n\n  const directories = new Set<string>();\n  const dependencies = new Set<string>();\n  for (const [key, value] of cache) {\n    const dependencyPath = dependencyPathFromCacheKey(key);\n    if (!dependencyPath) continue;\n    if (key.startsWith(\"statSync:\") && isDirectoryStat(value)) {\n      directories.add(dependencyPath);\n    } else {\n      dependencies.add(dependencyPath);\n    }\n  }\n  for (const dependencyPath of dependencies) {\n    if (!directories.has(dependencyPath)) onTsconfigRead(dependencyPath);\n  }\n}\n\nfunction dependencyPathFromCacheKey(key: string): string | undefined {\n  const readFilePrefix = \"readFileSync:\";\n  const readFileSuffix = \":utf8\";\n  if (key.startsWith(readFilePrefix) && key.endsWith(readFileSuffix)) {\n    return key.slice(readFilePrefix.length, -readFileSuffix.length);\n  }\n  for (const prefix of [\"existsSync:\", \"statSync:\"]) {\n    if (key.startsWith(prefix)) return key.slice(prefix.length);\n  }\n  return undefined;\n}\n\nfunction isDirectoryStat(value: unknown): boolean {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    \"isDirectory\" in value &&\n    typeof value.isDirectory === \"function\" &&\n    value.isDirectory()\n  );\n}\n","import * as path from \"pathe\";\nimport type { Plugin } from \"rolldown\";\n\ntype VirtualEntry = {\n  input: string;\n  plugin: Plugin;\n};\n\n/**\n * Create an in-memory rolldown entry module with a deterministic ID.\n * @param name - Logical entry name\n * @param code - Entry module source\n * @param sourceType - Parser type for the generated module\n * @param resolutionBasis - Source file whose directory resolves generated imports\n * @returns Rolldown input and plugin for loading the entry\n */\nexport function createVirtualEntry(\n  name: string,\n  code: string,\n  sourceType: \"js\" | \"ts\" = \"js\",\n  resolutionBasis?: string,\n): VirtualEntry {\n  const input = `tailor-entry:${name}.${sourceType}`;\n  const resolvedId = `\\0${input}`;\n\n  return {\n    input,\n    plugin: {\n      name: \"tailor-virtual-entry\",\n      async resolveId(source, importer) {\n        if (source === input && importer === undefined) return resolvedId;\n        if (\n          importer !== resolvedId ||\n          !resolutionBasis ||\n          source.startsWith(\".\") ||\n          path.isAbsolute(source) ||\n          source.startsWith(\"\\0\")\n        ) {\n          return null;\n        }\n        return this.resolve(source, resolutionBasis, { skipSelf: true });\n      },\n      load(id) {\n        return id === resolvedId ? code : null;\n      },\n    },\n  };\n}\n\n/**\n * Resolve bare imports in a generated on-disk entry from its owning project.\n *\n * Generated entries live under the CLI output directory, which may be outside\n * the project selected by a config path. Resolving their injected dependencies\n * from that output directory would ignore the selected project's installation.\n * @param entryPath - Absolute path of the generated entry\n * @param projectDir - Directory whose dependencies the generated entry uses\n * @returns Rolldown plugin that rebases generated bare imports\n */\nexport function createGeneratedEntryResolverPlugin(entryPath: string, projectDir: string): Plugin {\n  const normalizedEntryPath = path.resolve(entryPath);\n  const resolutionBasis = path.join(path.resolve(projectDir), \"__tailor_sdk_generated_entry__.js\");\n\n  return {\n    name: \"tailor-generated-entry-resolver\",\n    async resolveId(source, importer) {\n      if (\n        importer === undefined ||\n        path.resolve(importer) !== normalizedEntryPath ||\n        source.startsWith(\".\") ||\n        path.isAbsolute(source) ||\n        source.startsWith(\"\\0\")\n      ) {\n        return null;\n      }\n      return this.resolve(source, resolutionBasis, { skipSelf: true });\n    },\n  };\n}\n","import * as path from \"pathe\";\nimport * as rolldown from \"rolldown\";\nimport { computeBundlerContextHash, withCache, type BundleCache } from \"#/cli/cache/bundle-cache\";\nimport { createStartTransformPlugin } from \"#/cli/services/workflow/start-transformer\";\nimport { createBundleLog } from \"#/cli/shared/bundle-log\";\nimport { createLogLevelTreeshakeOptions } from \"#/cli/shared/bundle-log-level\";\nimport { composeFunctionTreeshakeOptions } from \"#/cli/shared/function-treeshake\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { platformBundleDefinePlugin } from \"#/cli/shared/platform-bundle-plugin\";\nimport { resolveTSConfigWithFallback } from \"#/cli/shared/resolve-tsconfig\";\nimport { serializeStartContext, type StartContext } from \"#/cli/shared/start-context\";\nimport {\n  createTsconfigPathsPlugin,\n  type TsconfigLookupCache,\n} from \"#/cli/shared/tsconfig-paths-plugin\";\nimport { createVirtualEntry } from \"#/cli/shared/virtual-entry\";\nimport ml from \"#/utils/multiline\";\nimport type { LogLevel } from \"#/configure/config/types\";\n\n/**\n * Options for bundling auth hooks\n */\nexport interface BundleAuthHooksOptions {\n  /** Absolute path to the config file that exports the auth definition */\n  configPath: string;\n  /** Auth namespace name */\n  authName: string;\n  /** Dot-path expression to reach the handler from the config's default export */\n  handlerAccessPath: string;\n  /** Environment variables to inject into the hook args */\n  env?: Record<string, string | number | boolean>;\n  /** Start context for workflow/job transformations */\n  startContext?: StartContext;\n  /** Optional bundle cache for skipping unchanged builds */\n  cache?: BundleCache;\n  /** Whether to enable inline sourcemaps */\n  inlineSourcemap?: boolean;\n  /** Controls which console calls are kept in bundled code */\n  bundleLogLevel?: LogLevel;\n  /** Directory the tsconfig is resolved against */\n  baseDir: string;\n  /** Optional tsconfig lookup cache shared across bundles in this CLI run */\n  tsconfigCache?: TsconfigLookupCache;\n}\n\n/**\n * Bundle a single auth hook handler.\n *\n * Follows the same pattern as the executor bundler:\n * 1. Generate an in-memory entry module that re-exports the handler as `main`\n * 2. Bundle with rolldown + tree-shaking\n * @param options - Bundle options\n * @returns Map of function name to bundled code\n */\nexport async function bundleAuthHooks(\n  options: BundleAuthHooksOptions,\n): Promise<Map<string, string>> {\n  const {\n    configPath,\n    authName,\n    handlerAccessPath,\n    env = {},\n    startContext,\n    cache,\n    inlineSourcemap,\n    bundleLogLevel = \"DEBUG\",\n    baseDir,\n    tsconfigCache,\n  } = options;\n\n  logger.newline();\n  logger.log(`Bundling auth hook for ${styles.info(`\"${authName}\"`)}`);\n\n  const absoluteConfigPath = path.resolve(configPath);\n\n  const tsconfig = await resolveTSConfigWithFallback(baseDir);\n\n  const functionName = `auth-hook--${authName}--before-login`;\n\n  const serializedStartContext = serializeStartContext(startContext);\n\n  // Include sorted env variables as a prefix so that env changes invalidate the cache\n  const sortedEnvPrefix = JSON.stringify(\n    Object.fromEntries(Object.entries(env).toSorted(([a], [b]) => a.localeCompare(b))),\n  );\n  const contextHash = computeBundlerContextHash({\n    sourceFile: absoluteConfigPath,\n    extraContext: serializedStartContext,\n    tsconfig,\n    inlineSourcemap,\n    bundleLogLevel,\n    prefix: sortedEnvPrefix,\n  });\n\n  const code = await withCache({\n    cache,\n    kind: \"auth-hook\",\n    name: functionName,\n    sourceFile: absoluteConfigPath,\n    contextHash,\n    async build(cachePlugins, trackDependency) {\n      const entryContent = ml /* js */ `\n        import _config from \"${absoluteConfigPath}\";\n        const __auth_hook_function = _config.${handlerAccessPath};\n        export async function main(args) {\n          const env = ${JSON.stringify(env)};\n          return await __auth_hook_function({ ...args, env });\n        }\n      `;\n      const entry = createVirtualEntry(\n        `auth-hook:${functionName}`,\n        entryContent,\n        \"js\",\n        absoluteConfigPath,\n      );\n\n      const startPlugin = createStartTransformPlugin(startContext);\n      const plugins: rolldown.Plugin[] = [entry.plugin];\n      if (startPlugin) {\n        plugins.push(startPlugin);\n      }\n      plugins.push(\n        createTsconfigPathsPlugin({ onTsconfigRead: trackDependency, cache: tsconfigCache }),\n        platformBundleDefinePlugin,\n        ...cachePlugins,\n      );\n\n      const bundleLog = createBundleLog({ tsconfig });\n      const result = await rolldown.build({\n        input: entry.input,\n        write: false,\n        output: {\n          format: \"esm\",\n          sourcemap: inlineSourcemap ? \"inline\" : true,\n          minify: inlineSourcemap\n            ? {\n                mangle: {\n                  keepNames: true,\n                },\n              }\n            : true,\n          codeSplitting: false,\n        },\n        tsconfig,\n        plugins,\n        transform: {\n          define: {\n            \"process.env.TAILOR_APP_LOG_LEVEL\": JSON.stringify(bundleLogLevel),\n          },\n        },\n        treeshake: composeFunctionTreeshakeOptions([\n          createLogLevelTreeshakeOptions(bundleLogLevel),\n        ]),\n        ...bundleLog.options,\n      } as rolldown.BuildOptions);\n      bundleLog.assertAllResolved();\n\n      return result.output[0].code;\n    },\n  });\n\n  logger.log(`${styles.success(\"Bundled\")} auth hook for ${styles.info(`\"${authName}\"`)}`);\n\n  const bundledCode = new Map<string, string>();\n  bundledCode.set(functionName, code);\n  return bundledCode;\n}\n","import { parseSync } from \"oxc-parser\";\n\nconst MAX_GENERATED_CODE_LENGTH = 2_000;\n\nfunction formatGeneratedCode(expr: string): string {\n  if (expr.length <= MAX_GENERATED_CODE_LENGTH) {\n    return `Generated code:\\n${expr}`;\n  }\n  return (\n    `Generated code (truncated to ${MAX_GENERATED_CODE_LENGTH} of ${expr.length} characters):\\n` +\n    `${expr.slice(0, MAX_GENERATED_CODE_LENGTH)}\\n...`\n  );\n}\n\n/**\n * Assert that a generated script expression is syntactically valid JavaScript.\n * Invalid generated code would otherwise surface much later as a confusing\n * bundler or platform-side syntax error, far from the definition that caused it.\n * @param expr - Generated JavaScript expression\n * @param context - What generated the expression, used to label the error\n * @returns The expression unchanged when it parses successfully\n */\nexport function assertParsableExpression(expr: string, context: string): string {\n  const { errors } = parseSync(\"generated-expr.js\", `(${expr}\\n);`);\n  if (errors.length === 0) {\n    return expr;\n  }\n  const details = errors.map((error) => `  - ${error.message}`).join(\"\\n\");\n  throw new Error(\n    `Generated ${context} script is not valid JavaScript.\\n` +\n      `Parse errors:\\n${details}\\n` +\n      formatGeneratedCode(expr),\n  );\n}\n","import type { ScriptExprKind } from \"./types\";\n\n// Identifier the table-level wrapper (buildTypeScripts in type-script.ts) binds\n// tailorPrincipalMap's result to, at most once per table, so per-hook exprs\n// below can reference it instead of re-embedding the full mapping on every hook.\nexport const PRINCIPAL_VAR = \"_principal\";\n\n/**\n * Build the call-argument list a script expression is invoked with, keyed by the\n * kind of hook/validator it wraps. Shared by every caller that assembles a\n * `(${normalized})(${callArgs})` script expression - both `field.ts` and the CLI's\n * hook-precompilation bundler - so the two never drift apart.\n * @param kind - Kind of hook/validator the expression is for\n * @returns The literal source of the arguments (an object literal for every kind\n *   except `typeValidate`, which also appends a trailing `__issues` argument)\n */\nexport function buildHookCallArgs(kind: ScriptExprKind): string {\n  switch (kind) {\n    case \"validate\":\n      return `{ value: _value }`;\n    case \"hooks.create\":\n      return `{ input: _value, invoker: ${PRINCIPAL_VAR}, now: _now }`;\n    case \"hooks.update\":\n      return `{ input: _value, oldValue: _oldValue, invoker: ${PRINCIPAL_VAR}, now: _now }`;\n    case \"typeHook.create\":\n    case \"typeHook.update\":\n      return `{ input: _input, oldRecord: _oldRecord, invoker: ${PRINCIPAL_VAR}, now: _now }`;\n    case \"typeValidate\":\n      return `{ newRecord: _newRecord, oldRecord: _oldRecord, invoker: ${PRINCIPAL_VAR} }, __issues`;\n    default:\n      throw new Error(`Unknown script expr kind: ${kind satisfies never}`);\n  }\n}\n","import type { PrecompiledScriptExprKey, PrecompiledScriptExprMap, ScriptExprKind } from \"./types\";\n\nconst PRECOMPILED_EXPR_KEY: PrecompiledScriptExprKey =\n  \"tailor-platform/sdk:precompiled-script-expr\";\nconst PRECOMPILED_EXPR_SYMBOL = Symbol.for(PRECOMPILED_EXPR_KEY);\n\ntype AnyFunction = (...args: never[]) => unknown;\n\nconst precompiledExprs = new WeakMap<AnyFunction, PrecompiledScriptExprMap>();\n\n/**\n * Store a precompiled script expression for a function.\n * Keyed by role so one function reused across roles keeps a distinct expression per role.\n * @param fn - Hook or validator function the expression was compiled from.\n * @param kind - Role the expression was compiled for.\n * @param expr - Precompiled script expression.\n */\nexport function setPrecompiledScriptExpr(fn: AnyFunction, kind: ScriptExprKind, expr: string) {\n  const entry = precompiledExprs.get(fn) ?? {};\n  entry[kind] = expr;\n  precompiledExprs.set(fn, entry);\n}\n\n/**\n * Read a precompiled script expression for a function.\n * @param fn - Hook or validator function the expression was compiled from.\n * @param kind - Role the expression was compiled for.\n * @returns Precompiled script expression if attached for that role.\n */\nexport function getPrecompiledScriptExpr(\n  fn: AnyFunction,\n  kind: ScriptExprKind,\n): string | undefined {\n  const pinnedExprs = Object.hasOwn(fn, PRECOMPILED_EXPR_SYMBOL)\n    ? (fn as unknown as Record<symbol, unknown>)[PRECOMPILED_EXPR_SYMBOL]\n    : undefined;\n  if (typeof pinnedExprs === \"object\" && pinnedExprs !== null && Object.hasOwn(pinnedExprs, kind)) {\n    const pinnedExpr = (pinnedExprs as Partial<Record<ScriptExprKind, unknown>>)[kind];\n    if (typeof pinnedExpr === \"string\") {\n      return pinnedExpr;\n    }\n  }\n  return precompiledExprs.get(fn)?.[kind];\n}\n","import { parseSync } from \"oxc-parser\";\nimport { assertParsableExpression } from \"#/utils/script-expr\";\nimport { buildHookCallArgs } from \"./hook-args-object\";\nimport { getPrecompiledScriptExpr } from \"./hooks-validate-precompiled-expr\";\nimport type {\n  TailorAnyDBField,\n  DBFieldMetadata,\n  RawRelationConfig,\n} from \"#/configure/services/tailordb/types\";\nimport type { OperatorFieldConfig, ScriptExprKind } from \"#/parser/service/tailordb/types\";\nimport type { TailorDBTypeRaw as TailorDBTypeSchemaOutput } from \"#/types/tailordb.generated\";\n\ntype FieldScriptContext = {\n  tableName: string;\n  fieldPath: readonly string[];\n};\n\ntype ScriptFunction = (...args: never[]) => unknown;\n\ntype ScriptContextKind = Extract<ScriptExprKind, \"hooks.create\" | \"hooks.update\" | \"validate\">;\n\nconst NIL_UUID = \"00000000-0000-0000-0000-000000000000\";\n\n/**\n * Per-source field expressions for {@link makePrincipalExpr}. Each value is a JS\n * snippet evaluated against the raw server payload bound to `$raw`.\n */\ninterface PrincipalFieldExprs {\n  /**\n   * Raw type accessor. `raw` is matched against `USER_TYPE_*` when normalizing;\n   * `fallback` (defaulting to `raw`) supplies the type for non-matching values,\n   * which lets sources whose primary field is empty fall back to a secondary.\n   */\n  type: { raw: string; fallback?: string };\n  /** Raw id accessor. */\n  id: string;\n  workspaceId: string;\n  attributes: string;\n  attributeList: string;\n}\n\ninterface MakePrincipalExprOptions {\n  source: string;\n  fields: PrincipalFieldExprs;\n  normalize: boolean;\n  requireId?: boolean;\n}\n\n/**\n * Build the server→SDK principal mapping expression shared across services.\n *\n * All principal-bearing call sites (`caller`, `actor`, `invoker`) must agree on\n * the `TailorPrincipal | null` shape, so they are generated here rather than\n * hand-written per service.\n * @param options - Mapping source and field expressions\n * @param options.source - Expression yielding the raw server payload (e.g. `user`)\n * @param options.fields - Per-source accessors for each principal field\n * @param options.normalize - When true, map `USER_TYPE_*` to SDK type literals and\n *   return `null` for unspecified types or the nil-UUID id; when false, the\n *   payload is already in SDK shape and only `null` pass-through is applied\n * @param options.requireId - When true, missing ids are also mapped to `null`\n * @returns A JS expression string evaluating to `TailorPrincipal | null`\n */\nexport function makePrincipalExpr(options: MakePrincipalExprOptions): string {\n  const { source, fields, normalize, requireId = false } = options;\n  const body = /* js */ `{\n    id,\n    type,\n    workspaceId: ${fields.workspaceId},\n    attributes: ${fields.attributes},\n    attributeList: ${fields.attributeList},\n  }`;\n  if (!normalize) {\n    return /* js */ `(($raw) => {\n  if (!$raw) {\n    return null;\n  }\n  const id = ${fields.id};\n  const type = ${fields.type.raw};\n  return ${body};\n})(${source})`;\n  }\n  const missingIdGuard = requireId ? \" || !id\" : \"\";\n  return /* js */ `(($raw) => {\n  if (!$raw) {\n    return null;\n  }\n  const type = ${fields.type.raw} === \"USER_TYPE_USER\"\n    ? \"user\"\n    : ${fields.type.raw} === \"USER_TYPE_MACHINE_USER\"\n      ? \"machine_user\"\n      : ${fields.type.fallback ?? fields.type.raw};\n  const id = ${fields.id};\n  if (!type || type === \"USER_TYPE_UNSPECIFIED\" || id === \"${NIL_UUID}\"${missingIdGuard}) {\n    return null;\n  }\n  return ${body};\n})(${source})`;\n}\n\n// Since there's naming difference between platform and SDK, use this mapping in\n// all scripts to provide variables that match `TailorPrincipal | null`.\nexport const tailorPrincipalMap = makePrincipalExpr({\n  source: \"user\",\n  normalize: true,\n  fields: {\n    type: { raw: \"$raw?.type\" },\n    id: \"$raw.id\",\n    workspaceId: \"$raw.workspace_id ?? $raw.workspaceId\",\n    attributes: \"$raw.attribute_map ?? $raw.attributeMap ?? {}\",\n    attributeList: \"$raw.attributes ?? []\",\n  },\n});\n\n/**\n * Parse `wrapped` and return the first property of the top-level parenthesized\n * object expression, or `undefined` if it does not parse as one.\n * @param wrapped - Source wrapped as `({ ... })`\n * @returns The first object property, or `undefined`\n */\nconst firstObjectProperty = (wrapped: string) => {\n  const parseResult = parseSync(\"stringify-function.ts\", wrapped, { sourceType: \"module\" });\n  if (parseResult.errors.length > 0) {\n    return undefined;\n  }\n  const expressionStatement = parseResult.program.body[0];\n  const objectExpression =\n    expressionStatement?.type === \"ExpressionStatement\" &&\n    expressionStatement.expression.type === \"ParenthesizedExpression\"\n      ? expressionStatement.expression.expression\n      : undefined;\n  return objectExpression?.type === \"ObjectExpression\" ? objectExpression.properties[0] : undefined;\n};\n\n/**\n * Convert a function to a string representation.\n * Handles method shorthand syntax (e.g., `create() { ... }`) by converting it to\n * an anonymous function expression (e.g., `function () { ... }`), including\n * `async` and generator variants and shorthand bodies that themselves contain\n * arrow functions. The result is anonymous (rather than reusing the method\n * name) so a body that references an outer variable of the same name is not\n * shadowed by the generated function's own binding.\n * @param fn - Function to stringify\n * @returns Stringified function source\n */\n// oxlint-disable-next-line typescript/no-unsafe-function-type\nexport const stringifyFunction = (fn: Function): string => {\n  const src = fn.toString().trim();\n  // `src` is already a valid function/arrow expression (e.g. `function () {}`,\n  // `() => {}`) if it parses as an object property value as-is; leave it untouched.\n  if (firstObjectProperty(`({m: ${src}})`)) {\n    return src;\n  }\n  // Otherwise, method shorthand (e.g. `create() {}`, `async create() {}`) is\n  // only valid inside an object literal, so parse it as an object property to\n  // detect and convert it via the AST rather than guessing from source text.\n  const wrapped = `({${src}})`;\n  const property = firstObjectProperty(wrapped);\n\n  if (property?.type === \"Property\" && property.method && property.computed) {\n    throw new Error(\n      \"Computed-key method shorthand cannot be converted to a TailorDB script expression. \" +\n        \"Use an arrow function or function expression instead.\",\n    );\n  }\n  if (\n    property?.type === \"Property\" &&\n    property.method &&\n    property.value.type === \"FunctionExpression\"\n  ) {\n    const { async, generator } = property.value;\n    const body = wrapped.slice(property.value.start, property.value.end);\n    return `${async ? \"async \" : \"\"}function${generator ? \"*\" : \"\"} ${body}`;\n  }\n  return src;\n};\n\nfunction formatScriptContext(kind: ScriptContextKind, context: FieldScriptContext | undefined) {\n  if (!context) {\n    return kind === \"validate\" ? kind : \"hooks\";\n  }\n  return `${kind} for ${context.tableName}.${context.fieldPath.join(\".\")}`;\n}\n\n/**\n * Convert a hook or validator function to a script expression.\n * @param fn - Hook or validator function\n * @param kind - Label naming the source of the expression in conversion errors\n * @param context - Optional field context for conversion errors\n * @returns JavaScript expression calling the function\n */\nconst convertToScriptExpr = (\n  fn: ScriptFunction,\n  kind: ScriptContextKind,\n  context: FieldScriptContext | undefined,\n): string => {\n  const precompiledExpr = getPrecompiledScriptExpr(fn, kind);\n  if (precompiledExpr) {\n    return precompiledExpr;\n  }\n  const normalized = stringifyFunction(fn);\n  return assertParsableExpression(\n    `(${normalized})(${buildHookCallArgs(kind)})`,\n    formatScriptContext(kind, context),\n  );\n};\n\n// oxlint-disable-next-line typescript/no-unsafe-function-type\nexport const convertTypeHookToExpr = (fn: Function, op: \"create\" | \"update\"): string => {\n  const kind = `typeHook.${op}` as const;\n  const precompiledExpr = getPrecompiledScriptExpr(fn as (...args: never[]) => unknown, kind);\n  if (precompiledExpr) {\n    return precompiledExpr;\n  }\n  const normalized = stringifyFunction(fn);\n  return assertParsableExpression(`(${normalized})(${buildHookCallArgs(kind)})`, \"type-hook\");\n};\n\n// oxlint-disable-next-line typescript/no-unsafe-function-type\nexport const convertTypeValidateToExpr = (fn: Function): string => {\n  const precompiledExpr = getPrecompiledScriptExpr(\n    fn as (...args: never[]) => unknown,\n    \"typeValidate\",\n  );\n  if (precompiledExpr) {\n    return precompiledExpr;\n  }\n  const normalized = stringifyFunction(fn);\n  return assertParsableExpression(\n    `(${normalized})(${buildHookCallArgs(\"typeValidate\")})`,\n    \"type-validate\",\n  );\n};\n\nfunction formatFieldLocation(context: FieldScriptContext | undefined): string {\n  return context ? `Field \"${context.fieldPath.join(\".\")}\" on table \"${context.tableName}\": ` : \"\";\n}\n\n/**\n * Parse TailorDBField into OperatorFieldConfig.\n * This transforms user-defined functions into script expressions.\n * @param field - TailorDB field definition\n * @param context - Optional field context for conversion errors\n * @returns Parsed operator field configuration\n */\nexport function parseFieldConfig(\n  field: TailorDBTypeSchemaOutput[\"fields\"][string],\n  context?: FieldScriptContext,\n): OperatorFieldConfig {\n  const metadata = field.metadata as DBFieldMetadata;\n  const fieldType = field.type;\n  // Access rawRelation via getter (if available)\n  const rawRelation = (field as unknown as { rawRelation?: RawRelationConfig }).rawRelation;\n\n  if (context && context.fieldPath.length > 1 && metadata.default !== undefined) {\n    throw new Error(\n      `${formatFieldLocation(context)}.default() cannot be used on nested inner fields`,\n    );\n  }\n\n  if (context && context.fieldPath.length > 1 && metadata.hooks) {\n    throw new Error(\n      `${formatFieldLocation(context)}.hooks() cannot be used on nested inner fields`,\n    );\n  }\n\n  if (fieldType === \"enum\" && (metadata.allowedValues ?? []).length === 0) {\n    throw new Error(\n      `${formatFieldLocation(context)}enum fields must define at least one allowed value`,\n    );\n  }\n\n  const nestedFields = field.fields as Record<string, TailorAnyDBField> | undefined;\n  return {\n    type: fieldType,\n    ...metadata,\n    rawRelation,\n    ...(fieldType === \"nested\" && nestedFields && Object.keys(nestedFields).length > 0\n      ? {\n          fields: Object.entries(nestedFields).reduce(\n            (acc, [key, nestedField]) => {\n              acc[key] = parseFieldConfig(\n                nestedField,\n                context && {\n                  ...context,\n                  fieldPath: [...context.fieldPath, key],\n                },\n              );\n              return acc;\n            },\n            {} as Record<string, OperatorFieldConfig>,\n          ),\n        }\n      : {}),\n    validate: metadata.validate?.map((fn) => ({\n      script: {\n        expr: convertToScriptExpr(fn, \"validate\", context),\n      },\n      errorMessage: \"\",\n    })),\n    hooks: metadata.hooks\n      ? {\n          create: metadata.hooks.create\n            ? {\n                expr: convertToScriptExpr(\n                  metadata.hooks.create as ScriptFunction,\n                  \"hooks.create\",\n                  context,\n                ),\n              }\n            : undefined,\n          update: metadata.hooks.update\n            ? {\n                expr: convertToScriptExpr(\n                  metadata.hooks.update as ScriptFunction,\n                  \"hooks.update\",\n                  context,\n                ),\n              }\n            : undefined,\n        }\n      : undefined,\n    serial: metadata.serial\n      ? {\n          start: metadata.serial.start,\n          maxValue: metadata.serial.maxValue,\n          format: \"format\" in metadata.serial ? metadata.serial.format : undefined,\n        }\n      : undefined,\n  };\n}\n","type NormalizedPermit = \"allow\" | \"deny\";\n\nexport interface NormalizedActionPermission<Condition> {\n  conditions: Condition[];\n  permit: NormalizedPermit;\n  description?: string;\n}\n\n/**\n * Check whether a permission rule uses the object format (`{ conditions, permit?, description? }`).\n * @param p - A raw permission rule\n * @returns Whether the rule is in object format\n */\nfunction isObjectPermissionFormat(\n  p: unknown,\n): p is { conditions: unknown; permit?: boolean; description?: string } {\n  return typeof p === \"object\" && p !== null && \"conditions\" in p;\n}\n\nfunction isSingleConditionFormat(cond: readonly unknown[]): boolean {\n  return cond.length >= 2 && typeof cond[1] === \"string\"; // Check if middle element is an operator\n}\n\nfunction normalizeOperand(operand: unknown): unknown {\n  if (operand === null) {\n    throw new Error(\"Invalid permission operand: null\");\n  }\n  if (typeof operand === \"object\" && !Array.isArray(operand)) {\n    if (\"user\" in operand) {\n      const user = operand.user;\n      return { user: user === \"id\" ? \"_id\" : user };\n    }\n  }\n  return operand;\n}\n\n/**\n * Build the permission normalizer shared by the services that accept the\n * condition-triple permission formats (object form, single-condition\n * shorthand, and condition-array shorthand).\n *\n * The services differ only in their operator vocabulary and in the type they\n * give the normalized conditions, so both are parameters.\n * @param operatorMap - Service-specific map from source operators to normalized names\n * @returns `normalizeConditions` and `normalizeActionPermission` for the service\n */\nexport function createPermissionNormalizer<Operator extends string, Condition>(\n  operatorMap: Record<Operator, string>,\n) {\n  type RawCondition = readonly [unknown, Operator, unknown];\n\n  function normalizeConditions(conditions: readonly RawCondition[]): Condition[] {\n    return conditions.map((cond) => {\n      const [left, operator, right] = cond;\n      return [normalizeOperand(left), operatorMap[operator], normalizeOperand(right)];\n    }) as Condition[];\n  }\n\n  function normalizeActionPermission(permission: unknown): NormalizedActionPermission<Condition> {\n    // object format\n    if (isObjectPermissionFormat(permission)) {\n      const conditions = permission.conditions as RawCondition | readonly RawCondition[];\n      return {\n        conditions: normalizeConditions(\n          isSingleConditionFormat(conditions)\n            ? [conditions as RawCondition]\n            : (conditions as readonly RawCondition[]),\n        ),\n        permit: permission.permit ? \"allow\" : \"deny\",\n        description: permission.description,\n      };\n    }\n\n    if (!Array.isArray(permission)) {\n      throw new Error(\"Invalid permission format\");\n    }\n\n    // Single condition shorthand, with an optional trailing permit boolean\n    if (isSingleConditionFormat(permission)) {\n      const [op1, operator, op2, permit] = [...permission, true] as [\n        unknown,\n        Operator,\n        unknown,\n        boolean,\n      ];\n      return {\n        conditions: normalizeConditions([[op1, operator, op2]]),\n        permit: permit ? \"allow\" : \"deny\",\n      };\n    }\n\n    // Array of conditions format, with an optional permit boolean among the items\n    const conditions: RawCondition[] = [];\n    let permit = true;\n    for (const item of permission as readonly unknown[]) {\n      if (typeof item === \"boolean\") {\n        permit = item;\n        continue;\n      }\n      conditions.push(item as RawCondition);\n    }\n\n    return {\n      conditions: normalizeConditions(conditions),\n      permit: permit ? \"allow\" : \"deny\",\n    };\n  }\n\n  return { normalizeConditions, normalizeActionPermission };\n}\n\n/**\n * Whether an object-format rule omits `permit`.\n *\n * Object-format rules default to `deny` when `permit` is omitted, whereas the\n * array shorthand defaults to `allow`. Omitting `permit` on an object rule is\n * therefore an easy way to accidentally deny access you meant to grant, so the\n * CLI warns about such rules to nudge authors toward setting `permit`\n * explicitly.\n * @param rule - A raw permission rule\n * @returns Whether the rule is object-format with `permit` omitted\n */\nexport function hasOmittedPermit(rule: unknown): boolean {\n  return isObjectPermissionFormat(rule) && rule.permit === undefined;\n}\n","import { createPermissionNormalizer, hasOmittedPermit } from \"#/parser/service/permission\";\nimport type {\n  StandardTailorTypePermission,\n  StandardTailorTypeGqlPermission,\n  StandardActionPermission,\n  StandardPermissionCondition,\n  StandardGqlPermissionPolicy,\n  Permissions,\n} from \"#/parser/service/tailordb/types\";\nimport type { GqlOperations, RawPermissions } from \"#/types/tailordb.generated\";\n\n// Raw permission types for normalize function parameters\ntype PermissionOperator = \"=\" | \"!=\" | \"in\" | \"not in\" | \"hasAny\" | \"not hasAny\";\n\ntype PermissionCondition = readonly [unknown, PermissionOperator, unknown];\n\nconst { normalizeConditions, normalizeActionPermission: normalizeRawActionPermission } =\n  createPermissionNormalizer<PermissionOperator, StandardPermissionCondition>({\n    \"=\": \"eq\",\n    \"!=\": \"ne\",\n    in: \"in\",\n    \"not in\": \"nin\",\n    hasAny: \"hasAny\",\n    \"not hasAny\": \"nhasAny\",\n  });\n\ntype GqlPermissionPolicy = {\n  conditions: readonly PermissionCondition[];\n  actions: \"all\" | readonly GqlPermissionAction[];\n  permit?: boolean;\n  description?: string;\n};\n\ntype GqlPermissionAction = \"read\" | \"create\" | \"update\" | \"delete\" | \"aggregate\" | \"bulkUpsert\";\n\n/**\n * Normalize record-level permissions into a standard structure.\n * @param permission - Tailor table permission\n * @returns Normalized record permissions\n */\nfunction normalizePermission(\n  permission: NonNullable<RawPermissions[\"record\"]>,\n): StandardTailorTypePermission {\n  const keys = Object.keys(permission) as Array<keyof typeof permission>;\n  return keys.reduce((acc, action) => {\n    acc[action] = permission[action].map((p) => normalizeActionPermission(p));\n    return acc;\n    // oxlint-disable-next-line no-explicit-any\n  }, {} as any);\n}\n\n/**\n * Normalize GraphQL permissions into a standard structure.\n * @param permission - Tailor GQL permission\n * @returns Normalized GQL permissions\n */\nexport function normalizeGqlPermission(\n  permission: NonNullable<RawPermissions[\"gql\"]>,\n): StandardTailorTypeGqlPermission {\n  return (permission as readonly GqlPermissionPolicy[]).map((policy) => normalizeGqlPolicy(policy));\n}\n\nfunction normalizeGqlPolicy(policy: GqlPermissionPolicy): StandardGqlPermissionPolicy {\n  return {\n    conditions: normalizeConditions(policy.conditions),\n    actions: policy.actions === \"all\" ? [\"all\"] : policy.actions,\n    permit: policy.permit ? \"allow\" : \"deny\",\n    description: policy.description,\n  } as StandardGqlPermissionPolicy;\n}\n\n/**\n * Parse raw permissions into normalized permissions.\n * This is the main entry point for permission parsing in the parser layer.\n * @param rawPermissions - Raw permissions definition\n * @returns Normalized permissions\n */\nexport function parsePermissions(rawPermissions: RawPermissions): Permissions {\n  return {\n    ...(rawPermissions.record && {\n      record: normalizePermission(rawPermissions.record),\n    }),\n    ...(rawPermissions.gql && {\n      gql: normalizeGqlPermission(rawPermissions.gql),\n    }),\n  };\n}\n\n/**\n * Normalize a single action permission into the standard format.\n * @param permission - Raw permission definition\n * @returns Normalized action permission\n */\nexport function normalizeActionPermission(permission: unknown): StandardActionPermission {\n  return normalizeRawActionPermission(permission);\n}\n\n/**\n * Find object-format permission rules that omit `permit` (which defaults to\n * `deny` there, unlike the array shorthand), so the CLI can warn about them.\n * @param rawPermissions - Raw permissions definition\n * @returns Dotted locations of offending rules, e.g. `record.read[0]`, `gql[1]`\n */\nexport function findOmittedPermitRules(rawPermissions: RawPermissions): string[] {\n  const locations: string[] = [];\n\n  const record = rawPermissions.record;\n  if (record) {\n    for (const action of Object.keys(record) as Array<keyof typeof record>) {\n      record[action].forEach((rule: unknown, index: number) => {\n        if (hasOmittedPermit(rule)) {\n          locations.push(`record.${String(action)}[${index}]`);\n        }\n      });\n    }\n  }\n\n  // GQL policies are always object form, so no isObjectFormat guard is needed.\n  const gql = rawPermissions.gql;\n  if (gql) {\n    (gql as readonly GqlPermissionPolicy[]).forEach((policy, index) => {\n      if (policy.permit === undefined) {\n        locations.push(`gql[${index}]`);\n      }\n    });\n  }\n\n  return locations;\n}\n\n/**\n * Check whether GraphQL exposure is fully disabled for a table, given its\n * effective gqlOperations (the table's own setting, falling back to the\n * TailorDB namespace default). `undefined` means the default of all\n * operations enabled, so it is never considered fully disabled.\n * @param gqlOperations - Effective, normalized gqlOperations configuration\n * @returns Whether create, update, delete, and read are all explicitly disabled\n */\nexport function isGqlOperationsFullyDisabled(gqlOperations: GqlOperations | undefined): boolean {\n  if (!gqlOperations) {\n    return false;\n  }\n  return (\n    gqlOperations.create === false &&\n    gqlOperations.update === false &&\n    gqlOperations.delete === false &&\n    gqlOperations.read === false\n  );\n}\n\n/**\n * Missing permission configuration detected for a TailorDB table.\n */\nexport interface MissingTypePermissionConfig {\n  /** Whether record-level permission (`.permission()`) is missing */\n  missingPermission: boolean;\n  /** Whether GraphQL permission (`.gqlPermission()`) is missing while GraphQL exposure is enabled */\n  missingGqlPermission: boolean;\n}\n\n/**\n * Find missing permission configuration for a TailorDB table.\n *\n * Record-level permission is always required: TailorDB denies all record\n * operations for a table without it, regardless of whether the table is\n * exposed via GraphQL. GraphQL permission is required whenever GraphQL\n * exposure is enabled for the table (the default, unless every operation is\n * explicitly disabled via `gqlOperations`).\n * @param rawPermissions - Raw permissions definition for the table\n * @param effectiveGqlOperations - The table's own gqlOperations, falling back to the namespace default\n * @returns Which permission configuration, if any, is missing\n */\nexport function findMissingPermissionConfig(\n  rawPermissions: RawPermissions,\n  effectiveGqlOperations: GqlOperations | undefined,\n): MissingTypePermissionConfig {\n  return {\n    missingPermission: !rawPermissions.record,\n    missingGqlPermission:\n      !rawPermissions.gql && !isGqlOperationsFullyDisabled(effectiveGqlOperations),\n  };\n}\n","import * as inflection from \"inflection\";\nimport { isPluginGeneratedTable } from \"#/parser/service/tailordb/type-source\";\nimport { convertTypeHookToExpr, convertTypeValidateToExpr, parseFieldConfig } from \"./field\";\nimport { parsePermissions } from \"./permission\";\nimport {\n  validateRelationConfig,\n  processRelationMetadata,\n  buildRelationInfo,\n  applyRelationMetadataToFieldConfig,\n} from \"./relation\";\nimport type { TailorDBField } from \"#/configure/services/tailordb/types\";\nimport type {\n  TypeSourceInfo,\n  ParsedField,\n  ParsedRelationship,\n  TailorDBType,\n} from \"#/parser/service/tailordb/types\";\nimport type { TailorDBTypeRaw as TailorDBTypeSchemaOutput } from \"#/types/tailordb.generated\";\n\n/**\n * Parse multiple TailorDB tables, build relationships, and validate uniqueness.\n * This is the main entry point for parsing TailorDB tables.\n * @param rawTypes - Raw TailorDB tables keyed by name\n * @param namespace - TailorDB namespace name\n * @param typeSourceInfo - Optional table source information\n * @returns Parsed tables\n */\nexport function parseTypes(\n  rawTypes: Record<string, TailorDBTypeSchemaOutput>,\n  namespace: string,\n  typeSourceInfo?: TypeSourceInfo,\n): Record<string, TailorDBType> {\n  const types = createRecord<TailorDBType>();\n  const allTableNames = new Set(Object.keys(rawTypes));\n\n  for (const [tableName, type] of Object.entries(rawTypes)) {\n    types[tableName] = parseTailorDBType(type, allTableNames, rawTypes, typeSourceInfo);\n  }\n\n  buildBackwardRelationships(types, namespace, typeSourceInfo);\n  validatePluralFormUniqueness(types, namespace, typeSourceInfo);\n\n  return types;\n}\n\n/**\n * Parse a TailorDBTypeSchemaOutput into a TailorDBType.\n * @param type - TailorDB table to parse\n * @param allTableNames - Set of all TailorDB table names\n * @param rawTypes - All raw TailorDB tables keyed by name\n * @param typeSourceInfo - Optional table source information\n * @returns Parsed TailorDB table\n */\nfunction parseTailorDBType(\n  type: TailorDBTypeSchemaOutput,\n  allTableNames: Set<string>,\n  rawTypes: Record<string, TailorDBTypeSchemaOutput>,\n  typeSourceInfo?: TypeSourceInfo,\n): TailorDBType {\n  const metadata = type.metadata;\n  const pluralForm = metadata.settings?.pluralForm || inflection.pluralize(type.name);\n  const typeLocation = formatTypeSourceLocation(getTypeSourceInfo(typeSourceInfo, type.name));\n\n  const fields = createRecord<ParsedField>();\n  const forwardRelationships = createRecord<ParsedRelationship>();\n\n  for (const [fieldName, fieldDef] of Object.entries(type.fields) as [\n    string,\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TailorDBField requires generic type parameters\n    TailorDBField<any, any>,\n  ][]) {\n    const context = { tableName: type.name, fieldName, allTableNames };\n    let fieldConfig = parseFieldConfig(fieldDef, {\n      tableName: type.name,\n      fieldPath: [fieldName],\n    });\n    const rawRelation = fieldConfig.rawRelation;\n\n    // Process relation if rawRelation is present\n    if (rawRelation) {\n      validateRelationConfig(rawRelation, context);\n\n      // Validate that n-1/manyToOne relations cannot have explicit unique\n      const isNToOne = [\"n-1\", \"manyToOne\", \"N-1\"].includes(rawRelation.type);\n      if (isNToOne && fieldConfig.unique) {\n        throw new Error(\n          `Field \"${fieldName}\" on table \"${type.name}\": cannot set unique on n-1 (manyToOne) relation. ` +\n            `Use 1-1 (oneToOne) relation instead, or remove the unique constraint.`,\n        );\n      }\n\n      const relationMetadata = processRelationMetadata(rawRelation, context, fieldConfig.array);\n      fieldConfig = applyRelationMetadataToFieldConfig(fieldConfig, relationMetadata);\n    }\n\n    // Validate that index/unique are not set on array fields\n    if (fieldConfig.array && fieldConfig.index) {\n      throw new Error(\n        `Field \"${fieldName}\" on table \"${type.name}\": index cannot be set on array fields`,\n      );\n    }\n    if (fieldConfig.array && fieldConfig.unique) {\n      throw new Error(\n        `Field \"${fieldName}\" on table \"${type.name}\": unique cannot be set on array fields`,\n      );\n    }\n\n    const parsedField: ParsedField = { name: fieldName, config: fieldConfig };\n\n    // Build relation info for forward/backward relationships\n    const relationInfo = rawRelation ? buildRelationInfo(rawRelation, context) : undefined;\n    if (relationInfo) {\n      parsedField.relation = { ...relationInfo };\n      const forwardName = relationInfo.forwardName;\n\n      if (forwardName.length === 0) {\n        throw new Error(\n          `Forward relation name for field \"${fieldName}\" on table \"${type.name}\"${typeLocation} cannot be empty. ` +\n            `Use the \"as\" option in .relation({ toward: { as: ... } }) to specify a non-empty name.`,\n        );\n      }\n\n      const existingForward = forwardRelationships[forwardName];\n      if (existingForward) {\n        throw new Error(\n          `Forward relation name \"${forwardName}\" on table \"${type.name}\"${typeLocation} is duplicated ` +\n            `between fields \"${existingForward.targetField}\" and \"${fieldName}\". ` +\n            `Use the \"as\" option in .relation({ toward: { as: ... } }) to specify a unique name.`,\n        );\n      }\n      if (Object.hasOwn(type.fields, forwardName)) {\n        const message =\n          forwardName === fieldName\n            ? `Forward relation name \"${forwardName}\" on table \"${type.name}\"${typeLocation} is the same as its own relation field \"${fieldName}\". ` +\n              `Use the \"as\" option in .relation({ toward: { as: ... } }) to specify a different name.`\n            : `Forward relation name \"${forwardName}\" from field \"${fieldName}\" on table \"${type.name}\"${typeLocation} ` +\n              `conflicts with existing field \"${forwardName}\". ` +\n              `Use the \"as\" option in .relation({ toward: { as: ... } }) to specify a different name.`;\n        throw new Error(message);\n      }\n      if (Object.hasOwn(metadata.files, forwardName)) {\n        throw new Error(\n          `Forward relation name \"${forwardName}\" from field \"${fieldName}\" on table \"${type.name}\"${typeLocation} ` +\n            `conflicts with files field \"${forwardName}\". ` +\n            `Use the \"as\" option in .relation({ toward: { as: ... } }) to specify a different name.`,\n        );\n      }\n\n      const targetType = rawTypes[relationInfo.targetType];\n      forwardRelationships[forwardName] = {\n        name: forwardName,\n        targetType: relationInfo.targetType,\n        targetField: fieldName,\n        sourceField: relationInfo.key,\n        isArray: false,\n        description: targetType?.metadata.description || \"\",\n      };\n    }\n\n    fields[fieldName] = parsedField;\n  }\n\n  return {\n    name: type.name,\n    pluralForm,\n    description: metadata.description,\n    fields,\n    forwardRelationships,\n    backwardRelationships: createRecord<ParsedRelationship>(),\n    settings: metadata.settings ?? {},\n    permissions: parsePermissions(metadata.permissions),\n    indexes: metadata.indexes,\n    files: metadata.files,\n    ...(metadata.typeHook && {\n      typeHookExpr: {\n        ...(typeof metadata.typeHook.create === \"function\" && {\n          create: convertTypeHookToExpr(metadata.typeHook.create, \"create\"),\n        }),\n        ...(typeof metadata.typeHook.update === \"function\" && {\n          update: convertTypeHookToExpr(metadata.typeHook.update, \"update\"),\n        }),\n      },\n    }),\n    ...(typeof metadata.typeValidate === \"function\" && {\n      typeValidateExpr: convertTypeValidateToExpr(metadata.typeValidate),\n    }),\n  };\n}\n\n/**\n * Build backward relationships between parsed tables.\n * Also validates that backward relation names are unique within each table.\n * @param types - Parsed tables\n * @param namespace - TailorDB namespace name\n * @param typeSourceInfo - Optional table source information\n */\nfunction buildBackwardRelationships(\n  types: Record<string, TailorDBType>,\n  namespace: string,\n  typeSourceInfo?: TypeSourceInfo,\n): void {\n  // Track backward name sources for duplicate detection\n  // Map: targetTypeName -> backwardName -> array of source info\n  const backwardNameSources: Record<\n    string,\n    Record<string, { sourceType: string; fieldName: string }[]>\n  > = Object.create(null);\n\n  // Initialize tracking for all tables\n  for (const tableName of Object.keys(types)) {\n    backwardNameSources[tableName] = Object.create(null) as Record<\n      string,\n      { sourceType: string; fieldName: string }[]\n    >;\n  }\n\n  // Build backward relationships and track sources\n  for (const [tableName, type] of Object.entries(types)) {\n    for (const [otherTypeName, otherType] of Object.entries(types)) {\n      for (const [fieldName, field] of Object.entries(otherType.fields)) {\n        if (field.relation && field.relation.targetType === tableName) {\n          let backwardName = field.relation.backwardName;\n\n          if (!backwardName) {\n            const lowerName = inflection.camelize(otherTypeName, true);\n            backwardName = field.relation.unique\n              ? inflection.singularize(lowerName)\n              : inflection.pluralize(lowerName);\n          }\n\n          // Track the source of this backward name\n          const tableBackwardNames = backwardNameSources[tableName];\n          if (tableBackwardNames === undefined) {\n            throw new Error(`backward name sources not initialized for table: ${tableName}`);\n          }\n          if (!tableBackwardNames[backwardName]) {\n            tableBackwardNames[backwardName] = [];\n          }\n          const sources = tableBackwardNames[backwardName];\n          if (sources === undefined) {\n            throw new Error(`backward name sources entry not initialized for: ${backwardName}`);\n          }\n          sources.push({\n            sourceType: otherTypeName,\n            fieldName,\n          });\n\n          type.backwardRelationships[backwardName] = {\n            name: backwardName,\n            targetType: otherTypeName,\n            targetField: fieldName,\n            sourceField: field.relation.key,\n            isArray: !field.relation.unique,\n            description: otherType.description || \"\",\n          };\n        }\n      }\n    }\n  }\n\n  // Check for duplicates and collect errors\n  const errors: string[] = [];\n\n  for (const [targetTypeName, backwardNames] of Object.entries(backwardNameSources)) {\n    const targetType = types[targetTypeName];\n    if (targetType === undefined) {\n      throw new Error(`type not found: ${targetTypeName}`);\n    }\n    const targetTypeSourceInfo = getTypeSourceInfo(typeSourceInfo, targetTypeName);\n    const targetLocation = formatTypeSourceLocation(targetTypeSourceInfo);\n\n    for (const [backwardName, sources] of Object.entries(backwardNames)) {\n      // Check for duplicate backward relation names\n      if (sources.length > 1) {\n        const sourceList = sources\n          .map((s) => {\n            const sourceInfo = getTypeSourceInfo(typeSourceInfo, s.sourceType);\n            const location = formatTypeSourceLocation(sourceInfo);\n            return `${s.sourceType}.${s.fieldName}${location}`;\n          })\n          .join(\", \");\n        errors.push(\n          `Backward relation name \"${backwardName}\" on table \"${targetTypeName}\" is duplicated from: ${sourceList}. ` +\n            `Use the \"backward\" option in .relation() to specify unique names.`,\n        );\n      }\n\n      // Check for conflict with existing fields\n      if (Object.hasOwn(targetType.fields, backwardName)) {\n        const source = sources[0];\n        if (source === undefined) {\n          throw new Error(`no source found for backward name: ${backwardName}`);\n        }\n        const sourceInfo = getTypeSourceInfo(typeSourceInfo, source.sourceType);\n        const sourceLocation = formatTypeSourceLocation(sourceInfo);\n        errors.push(\n          `Backward relation name \"${backwardName}\" from ${source.sourceType}.${source.fieldName}${sourceLocation} ` +\n            `conflicts with existing field \"${backwardName}\" on table \"${targetTypeName}\"${targetLocation}. ` +\n            `Use the \"backward\" option in .relation() to specify a different name.`,\n        );\n      }\n\n      // Check for conflict with files fields\n      if (targetType.files && Object.hasOwn(targetType.files, backwardName)) {\n        const source = sources[0];\n        if (source === undefined) {\n          throw new Error(`no source found for backward name: ${backwardName}`);\n        }\n        const sourceInfo = getTypeSourceInfo(typeSourceInfo, source.sourceType);\n        const sourceLocation = formatTypeSourceLocation(sourceInfo);\n        errors.push(\n          `Backward relation name \"${backwardName}\" from ${source.sourceType}.${source.fieldName}${sourceLocation} ` +\n            `conflicts with files field \"${backwardName}\" on table \"${targetTypeName}\"${targetLocation}. ` +\n            `Use the \"backward\" option in .relation() to specify a different name.`,\n        );\n      }\n\n      if (Object.hasOwn(targetType.forwardRelationships, backwardName)) {\n        const source = sources[0];\n        if (source === undefined) {\n          throw new Error(`no source found for backward name: ${backwardName}`);\n        }\n        const sourceInfo = getTypeSourceInfo(typeSourceInfo, source.sourceType);\n        const sourceLocation = formatTypeSourceLocation(sourceInfo);\n        errors.push(\n          `Relation name \"${backwardName}\" on table \"${targetTypeName}\"${targetLocation} is used by both ` +\n            `a forward relationship and a backward relationship from ${source.sourceType}.${source.fieldName}${sourceLocation}. ` +\n            `Use the \"as\" option in .relation({ toward: { as: ... } }) or the \"backward\" option in .relation() to specify unique names.`,\n        );\n      }\n    }\n  }\n\n  if (errors.length > 0) {\n    throw new Error(\n      `Backward relation name conflicts detected in TailorDB service \"${namespace}\".\\n` +\n        `${errors.map((e) => `  - ${e}`).join(\"\\n\")}`,\n    );\n  }\n}\n\n/**\n * Validate GraphQL query field name uniqueness.\n * Checks for:\n * 1. Each table's singular query name != plural query name\n * 2. No duplicate query names across all tables\n * @param types - Parsed tables\n * @param namespace - TailorDB namespace name\n * @param typeSourceInfo - Optional table source information\n */\nfunction validatePluralFormUniqueness(\n  types: Record<string, TailorDBType>,\n  namespace: string,\n  typeSourceInfo?: TypeSourceInfo,\n): void {\n  const errors: string[] = [];\n\n  // Check 1: Each table's singular and plural query names must be different\n  for (const [, parsedType] of Object.entries(types)) {\n    const singularQuery = inflection.camelize(parsedType.name, true);\n    const pluralQuery = inflection.camelize(parsedType.pluralForm, true);\n\n    if (singularQuery === pluralQuery) {\n      const sourceInfo = getTypeSourceInfo(typeSourceInfo, parsedType.name);\n      const location = formatTypeSourceLocation(sourceInfo);\n      errors.push(\n        `Table \"${parsedType.name}\"${location} has identical singular and plural query names \"${singularQuery}\". ` +\n          `Use db.table([\"${parsedType.name}\", \"UniquePluralForm\"], {...}) to set a unique pluralForm.`,\n      );\n    }\n  }\n\n  // Check 2: All query names must be unique across tables\n  const queryNameToSource = new Map<string, { tableName: string; kind: string }[]>();\n\n  for (const parsedType of Object.values(types)) {\n    const singularQuery = inflection.camelize(parsedType.name, true);\n    const pluralQuery = inflection.camelize(parsedType.pluralForm, true);\n\n    const singularSources = queryNameToSource.get(singularQuery) ?? [];\n    singularSources.push({\n      tableName: parsedType.name,\n      kind: \"singular\",\n    });\n    queryNameToSource.set(singularQuery, singularSources);\n\n    if (singularQuery !== pluralQuery) {\n      const pluralSources = queryNameToSource.get(pluralQuery) ?? [];\n      pluralSources.push({\n        tableName: parsedType.name,\n        kind: \"plural\",\n      });\n      queryNameToSource.set(pluralQuery, pluralSources);\n    }\n  }\n\n  const duplicates = [...queryNameToSource].filter(([, sources]) => sources.length > 1);\n\n  for (const [queryName, sources] of duplicates) {\n    const sourceList = sources\n      .map((s) => {\n        const sourceInfo = getTypeSourceInfo(typeSourceInfo, s.tableName);\n        const location = formatTypeSourceLocation(sourceInfo);\n        return `\"${s.tableName}\"${location} (${s.kind})`;\n      })\n      .join(\", \");\n    errors.push(`GraphQL query field \"${queryName}\" conflicts between: ${sourceList}`);\n  }\n\n  if (errors.length > 0) {\n    throw new Error(\n      `GraphQL field name conflicts detected in TailorDB service \"${namespace}\".\\n` +\n        `${errors.map((e) => `  - ${e}`).join(\"\\n\")}`,\n    );\n  }\n}\n\nfunction getTypeSourceInfo(\n  typeSourceInfo: TypeSourceInfo | undefined,\n  tableName: string,\n): TypeSourceInfo[string] | undefined {\n  return typeSourceInfo && Object.hasOwn(typeSourceInfo, tableName)\n    ? typeSourceInfo[tableName]\n    : undefined;\n}\n\nfunction formatTypeSourceLocation(sourceInfo: TypeSourceInfo[string] | undefined): string {\n  if (!sourceInfo) {\n    return \"\";\n  }\n  return isPluginGeneratedTable(sourceInfo)\n    ? ` (plugin: ${sourceInfo.pluginId})`\n    : ` (${sourceInfo.filePath})`;\n}\n\nfunction createRecord<T>(): Record<string, T> {\n  return Object.create(null) as Record<string, T>;\n}\n","import { parseSync } from \"oxc-parser\";\nimport { ES_BUILTINS } from \"#/utils/es-builtins\";\nimport type { BindingPattern, Node, ParamPattern } from \"@oxc-project/types\";\n\n/** Fields that contain TypeScript type annotations (not runtime references). */\nexport const TS_TYPE_FIELDS = new Set([\n  \"typeAnnotation\",\n  \"typeParameters\",\n  \"returnType\",\n  \"superTypeArguments\",\n  \"typeArguments\",\n]);\n\n/**\n * Recursively extract binding names from a destructuring pattern node.\n * @param pattern - The binding pattern AST node.\n * @param bindings - Set to collect binding names into.\n */\nfunction collectBindingsFromPattern(pattern: BindingPattern, bindings: Set<string>): void {\n  switch (pattern.type) {\n    case \"Identifier\":\n      bindings.add(pattern.name);\n      break;\n    case \"ObjectPattern\":\n      for (const prop of pattern.properties) {\n        if (prop.type === \"RestElement\") {\n          collectBindingsFromPattern(prop.argument, bindings);\n        } else {\n          collectBindingsFromPattern(prop.value, bindings);\n        }\n      }\n      break;\n    case \"ArrayPattern\":\n      for (const elem of pattern.elements) {\n        if (elem) {\n          if (elem.type === \"RestElement\") {\n            collectBindingsFromPattern(elem.argument, bindings);\n          } else {\n            collectBindingsFromPattern(elem, bindings);\n          }\n        }\n      }\n      break;\n    case \"AssignmentPattern\":\n      collectBindingsFromPattern(pattern.left, bindings);\n      break;\n  }\n}\n\nfunction isBindingPattern(param: ParamPattern): param is BindingPattern {\n  return param.type !== \"TSParameterProperty\";\n}\n\n/**\n * A function-scope boundary (function declaration/expression, arrow\n * function, or the module root). Declarations resolve within the scope they\n * are collected into; references are checked against this chain at the end,\n * once every scope's bindings have been fully collected. Block-level\n * scoping (`let`/`const`/`catch` shadowing within an `if`/`for`/`{}`) is not\n * modeled — such bindings are attached to their nearest enclosing function\n * scope, which is safe for detecting a forbidden global reachable from\n * outside the block but does not detect one shadowed only within it.\n */\ninterface Scope {\n  bindings: Set<string>;\n  parent: Scope | null;\n}\n\nfunction isBoundInScope(scope: Scope, name: string): boolean {\n  for (let s: Scope | null = scope; s; s = s.parent) {\n    if (s.bindings.has(name)) return true;\n  }\n  return false;\n}\n\nconst NEGATIVE_EQUALITY_OPERATORS = new Set([\"!==\", \"!=\"]);\nconst POSITIVE_EQUALITY_OPERATORS = new Set([\"===\", \"==\"]);\n\n/**\n * Read the static string value of a string literal or a template literal with\n * no interpolated expressions (e.g. `` `object` ``, which minifiers use in\n * place of `\"object\"` — both are the same string at runtime).\n * @param node - Candidate literal AST node.\n * @returns The literal's string value, or undefined if `node` isn't one.\n */\nfunction staticStringValue(node: Node): string | undefined {\n  if (node.type === \"Literal\" && typeof node.value === \"string\") return node.value;\n  if (\n    node.type === \"TemplateLiteral\" &&\n    node.expressions.length === 0 &&\n    node.quasis.length === 1\n  ) {\n    return node.quasis[0]?.value.cooked ?? undefined;\n  }\n  return undefined;\n}\n\n/**\n * If `expr` is a `typeof x === \"...\"` / `typeof x !== \"...\"` comparison that\n * is only true while `x` is declared, return `x`'s name. `typeof` never\n * throws on an undeclared identifier, so `typeof x !== \"undefined\" && x` (and\n * `typeof x === \"<anything but undefined>\" && x`) cannot actually reference\n * `x` when it is undeclared — this is the cross-environment global-detection\n * idiom used by es-toolkit, lodash, core-js, etc. The opposite direction —\n * `typeof x === \"undefined\" && x` or `typeof x !== \"<anything but\n * undefined>\" && x` — is true precisely when `x` is NOT safely usable (or\n * says nothing about it), so it must not be treated as a guard. Loose\n * equality (`==`/`!=`) is included because minifiers rewrite `===`/`!==`\n * against a `typeof` result to the loose form (the result is always a\n * string, so the two are equivalent there).\n * @param expr - Candidate comparison AST node.\n * @returns The guarded identifier's name, or undefined if `expr` doesn't guard one.\n */\nfunction typeofGuardTarget(expr: Node): string | undefined {\n  if (expr.type !== \"BinaryExpression\") return undefined;\n  const { left, right, operator } = expr;\n  const [typeofSide, literalSide] =\n    left.type === \"UnaryExpression\" &&\n    left.operator === \"typeof\" &&\n    left.argument.type === \"Identifier\"\n      ? [left, right]\n      : right.type === \"UnaryExpression\" &&\n          right.operator === \"typeof\" &&\n          right.argument.type === \"Identifier\"\n        ? [right, left]\n        : [undefined, undefined];\n  if (!typeofSide) return undefined;\n  const literalValue = staticStringValue(literalSide);\n  if (literalValue === undefined) return undefined;\n  const comparesToUndefined = literalValue === \"undefined\";\n  const isSafe =\n    (NEGATIVE_EQUALITY_OPERATORS.has(operator) && comparesToUndefined) ||\n    (POSITIVE_EQUALITY_OPERATORS.has(operator) && !comparesToUndefined);\n  if (!isSafe) return undefined;\n  return (typeofSide.argument as { name: string }).name;\n}\n\n/**\n * Check whether `node` is `guardedName` itself, or a member-expression chain\n * rooted at it (`x.y`, `x.y[z]`), as in `typeof x !== \"undefined\" && x.y`.\n * Computed property expressions along the chain are still walked for their\n * own free variables (e.g. the `z` in `x.y[z]`) — only the guarded root\n * identifier is treated as safe.\n * @param node - Candidate right-hand side of a `typeof`-guarded `&&`.\n * @param guardedName - The identifier name the `typeof` check guards.\n * @param walk - The AST walker, used to visit computed property expressions.\n * @returns Whether `node` is entirely covered by the guard.\n */\nfunction walkGuardedChain(\n  node: Node,\n  guardedName: string,\n  walk: (n: Node | null | undefined) => void,\n): boolean {\n  if (node.type === \"Identifier\") {\n    return node.name === guardedName;\n  }\n  if (node.type === \"MemberExpression\") {\n    if (!walkGuardedChain(node.object, guardedName, walk)) return false;\n    if (node.computed) walk(node.property);\n    return true;\n  }\n  return false;\n}\n\ninterface FindUndefinedReferencesOptions {\n  /** Include references protected by typeof checks, even though they cannot throw. */\n  includeGuardedReferences?: boolean;\n}\n\n/**\n * Parse a code string with oxc-parser and return identifiers that are referenced\n * but never bound anywhere in the snippet (free variables), excluding ES builtins.\n * @param code - Valid JavaScript code to analyze.\n * @param options - Whether guarded references should also be returned.\n * @returns Set of undefined variable names.\n */\nexport function findUndefinedReferences(\n  code: string,\n  options?: FindUndefinedReferencesOptions,\n): Set<string> {\n  const { program, errors } = parseSync(\"_.js\", code);\n  if (errors.length > 0) {\n    const details = errors.map((error) => `  - ${error.message}`).join(\"\\n\");\n    throw new Error(`Failed to parse code for free-variable analysis.\\nParse errors:\\n${details}`);\n  }\n  const references: { name: string; scope: Scope }[] = [];\n  const rootScope: Scope = { bindings: new Set(), parent: null };\n  let currentScope: Scope = rootScope;\n\n  const walk = (node: Node | null | undefined): void => {\n    if (!node) return;\n\n    switch (node.type) {\n      case \"VariableDeclarator\":\n        collectBindingsFromPattern(node.id, currentScope.bindings);\n        walk(node.init);\n        return;\n\n      case \"ImportDeclaration\":\n        for (const specifier of node.specifiers) {\n          currentScope.bindings.add(specifier.local.name);\n        }\n        return;\n\n      case \"FunctionDeclaration\":\n      case \"FunctionExpression\": {\n        if (node.type === \"FunctionDeclaration\" && node.id) {\n          currentScope.bindings.add(node.id.name);\n        }\n        const functionScope: Scope = { bindings: new Set(), parent: currentScope };\n        if (node.type === \"FunctionExpression\" && node.id) {\n          functionScope.bindings.add(node.id.name);\n        }\n        for (const param of node.params) {\n          if (isBindingPattern(param)) {\n            collectBindingsFromPattern(param, functionScope.bindings);\n          }\n        }\n        const outerScope = currentScope;\n        currentScope = functionScope;\n        for (const param of node.params) {\n          if (isBindingPattern(param)) walk(param);\n        }\n        walk(node.body);\n        currentScope = outerScope;\n        return;\n      }\n\n      case \"ArrowFunctionExpression\": {\n        const functionScope: Scope = { bindings: new Set(), parent: currentScope };\n        for (const param of node.params) {\n          if (isBindingPattern(param)) {\n            collectBindingsFromPattern(param, functionScope.bindings);\n          }\n        }\n        const outerScope = currentScope;\n        currentScope = functionScope;\n        for (const param of node.params) {\n          if (isBindingPattern(param)) walk(param);\n        }\n        walk(node.body);\n        currentScope = outerScope;\n        return;\n      }\n\n      case \"ClassDeclaration\":\n      case \"ClassExpression\":\n        if (node.id) currentScope.bindings.add(node.id.name);\n        walk(node.superClass);\n        walk(node.body);\n        return;\n\n      case \"CatchClause\":\n        if (node.param) collectBindingsFromPattern(node.param, currentScope.bindings);\n        walk(node.body);\n        return;\n\n      case \"MemberExpression\":\n        walk(node.object);\n        if (node.computed) walk(node.property);\n        return;\n\n      case \"UnaryExpression\":\n        if (\n          !options?.includeGuardedReferences &&\n          node.operator === \"typeof\" &&\n          node.argument.type === \"Identifier\"\n        ) {\n          return;\n        }\n        walk(node.argument);\n        return;\n\n      case \"LogicalExpression\": {\n        const guardedName = node.operator === \"&&\" ? typeofGuardTarget(node.left) : undefined;\n        walk(node.left);\n        if (\n          !options?.includeGuardedReferences &&\n          guardedName &&\n          walkGuardedChain(node.right, guardedName, walk)\n        ) {\n          return;\n        }\n        walk(node.right);\n        return;\n      }\n\n      case \"Property\":\n        if (node.computed) walk(node.key);\n        walk(node.value);\n        return;\n\n      case \"MethodDefinition\":\n      case \"TSAbstractMethodDefinition\":\n      case \"PropertyDefinition\":\n      case \"TSAbstractPropertyDefinition\":\n      case \"AccessorProperty\":\n      case \"TSAbstractAccessorProperty\":\n        for (const decorator of node.decorators) walk(decorator.expression);\n        if (node.computed) walk(node.key);\n        walk(node.value);\n        return;\n\n      case \"LabeledStatement\":\n        walk(node.body);\n        return;\n\n      case \"Identifier\":\n        references.push({ name: node.name, scope: currentScope });\n        return;\n\n      default:\n        break;\n    }\n\n    // Generic child walk for all other node types, skipping TS type-annotation fields\n    const rec = node as unknown as Record<string, unknown>;\n    for (const [key, value] of Object.entries(rec)) {\n      if (key === \"type\" || TS_TYPE_FIELDS.has(key)) continue;\n      if (Array.isArray(value)) {\n        for (const item of value) walk(item as Node);\n      } else if (value && typeof value === \"object\" && \"type\" in value) {\n        walk(value as Node);\n      }\n    }\n  };\n\n  walk(program);\n\n  // Free variables = references not bound in their own or any enclosing scope, minus builtins\n  const freeVars = new Set<string>();\n  for (const { name, scope } of references) {\n    if (!isBoundInScope(scope, name) && !ES_BUILTINS.has(name)) {\n      freeVars.add(name);\n    }\n  }\n  return freeVars;\n}\n","import { readFileSync } from \"node:fs\";\nimport { parseSync } from \"oxc-parser\";\nimport { resolve } from \"pathe\";\nimport * as rolldown from \"rolldown\";\nimport { createBundleLog } from \"#/cli/shared/bundle-log\";\nimport { findUndefinedReferences, TS_TYPE_FIELDS } from \"#/cli/shared/free-variables\";\nimport { platformBundleDefinePlugin } from \"#/cli/shared/platform-bundle-plugin\";\nimport { createTsconfigPathsPlugin } from \"#/cli/shared/tsconfig-paths-plugin\";\nimport { createVirtualEntry } from \"#/cli/shared/virtual-entry\";\nimport { stringifyFunction } from \"#/parser/service/tailordb/field\";\nimport { buildHookCallArgs } from \"#/parser/service/tailordb/hook-args-object\";\nimport {\n  getPrecompiledScriptExpr,\n  setPrecompiledScriptExpr,\n} from \"#/parser/service/tailordb/hooks-validate-precompiled-expr\";\nimport { assertDefined } from \"#/utils/assert\";\nimport { assertParsableExpression } from \"#/utils/script-expr\";\nimport type { ScriptExprKind } from \"#/parser/service/tailordb/types\";\nimport type { TailorDBTypeRaw as TailorDBTypeSchemaOutput } from \"#/types/tailordb.generated\";\n\ntype ScriptFunction = (...args: unknown[]) => unknown;\n\ntype ScriptTarget = {\n  fn: ScriptFunction;\n  kind: ScriptExprKind;\n};\n\n/** Binding found in the source file: either an import or a top-level declaration */\nexport type SourceBinding = {\n  name: string;\n  /** The original source text of the import/declaration statement */\n  sourceText: string;\n  kind: \"import\" | \"declaration\";\n};\n\nfunction toScriptFunction(value: unknown, kind: ScriptExprKind): ScriptFunction | undefined {\n  if (typeof value !== \"function\") return undefined;\n  // Already pinned (e.g. a built-in SDK hook, see `db.fields.timestamps()`) - bundling\n  // it again would derive a new expr from this build's `Function.prototype.toString()`\n  // output and overwrite the pin.\n  if (getPrecompiledScriptExpr(value as ScriptFunction, kind)) return undefined;\n  return value as unknown as ScriptFunction;\n}\n\nfunction collectScriptTargets(type: TailorDBTypeSchemaOutput): ScriptTarget[] {\n  const targets: ScriptTarget[] = [];\n\n  const collectFieldTargets = (field: TailorDBTypeSchemaOutput[\"fields\"][string]) => {\n    const metadata = field.metadata;\n\n    const createHook = toScriptFunction(metadata.hooks?.create, \"hooks.create\");\n    if (createHook) {\n      targets.push({ fn: createHook, kind: \"hooks.create\" });\n    }\n    const updateHook = toScriptFunction(metadata.hooks?.update, \"hooks.update\");\n    if (updateHook) {\n      targets.push({ fn: updateHook, kind: \"hooks.update\" });\n    }\n\n    for (const validateInput of metadata.validate ?? []) {\n      const validateFn = toScriptFunction(validateInput, \"validate\");\n      if (validateFn) targets.push({ fn: validateFn, kind: \"validate\" });\n    }\n\n    if (field.type === \"nested\" && field.fields) {\n      for (const nestedField of Object.values(field.fields as TailorDBTypeSchemaOutput[\"fields\"])) {\n        collectFieldTargets(nestedField);\n      }\n    }\n  };\n\n  for (const field of Object.values(type.fields)) {\n    collectFieldTargets(field);\n  }\n\n  if (type.metadata.typeHook) {\n    for (const op of [\"create\", \"update\"] as const) {\n      const kind = `typeHook.${op}` as const;\n      const fn = toScriptFunction(type.metadata.typeHook[op], kind);\n      if (fn) {\n        targets.push({ fn, kind });\n      }\n    }\n  }\n\n  const typeValidateFn = toScriptFunction(type.metadata.typeValidate, \"typeValidate\");\n  if (typeValidateFn) {\n    targets.push({ fn: typeValidateFn, kind: \"typeValidate\" });\n  }\n\n  return targets;\n}\n\n/**\n * Collect all Identifier names from a TypeScript/JavaScript code string using oxc-parser.\n * @param code - Code string to analyze.\n * @returns Set of identifier names found in the code.\n */\nfunction collectIdentifierNames(code: string): Set<string> {\n  const { program } = parseSync(\"_.ts\", code);\n  const names = new Set<string>();\n  const walk = (node: unknown): void => {\n    if (!node || typeof node !== \"object\") return;\n    const record = node as Record<string, unknown>;\n    if (record.type === \"Identifier\" && typeof record.name === \"string\") {\n      names.add(record.name);\n    }\n    for (const [key, value] of Object.entries(record)) {\n      // Skip non-computed MemberExpression property (e.g. `length` in `value.length`)\n      // but keep computed properties (e.g. `foo` in `obj[foo]`) as they are real references\n      if (key === \"property\" && record.type === \"MemberExpression\" && !record.computed) continue;\n      // Skip non-computed Property keys (e.g. `format` in `{ format: \"x\" }` is not a reference)\n      if (key === \"key\" && record.type === \"Property\" && !record.computed) continue;\n      // Skip TypeScript type annotation fields (not runtime references)\n      if (TS_TYPE_FIELDS.has(key)) continue;\n      if (Array.isArray(value)) {\n        for (const item of value) walk(item);\n      } else if (value && typeof value === \"object\" && \"type\" in value) {\n        walk(value);\n      }\n    }\n  };\n  walk(program);\n  return names;\n}\n\n/**\n * Collect top-level bindings (imports and declarations) from a TypeScript source file.\n * @param sourceFilePath - Absolute path to the source file.\n * @returns Map of binding name to SourceBinding.\n */\nexport function collectSourceBindings(sourceFilePath: string): Map<string, SourceBinding> {\n  const source = readFileSync(sourceFilePath, \"utf-8\");\n  const { program } = parseSync(sourceFilePath, source);\n  const bindings = new Map<string, SourceBinding>();\n\n  for (const stmt of program.body) {\n    if (stmt.type === \"ImportDeclaration\") {\n      const importDecl = stmt;\n      const text = source.slice(importDecl.start, importDecl.end);\n      for (const spec of importDecl.specifiers) {\n        bindings.set(spec.local.name, {\n          name: spec.local.name,\n          sourceText: text,\n          kind: \"import\",\n        });\n      }\n    } else if (stmt.type === \"VariableDeclaration\") {\n      const varDecl = stmt;\n      const text = source.slice(varDecl.start, varDecl.end);\n      for (const decl of varDecl.declarations) {\n        if (decl.id.type === \"Identifier\") {\n          bindings.set(decl.id.name, { name: decl.id.name, sourceText: text, kind: \"declaration\" });\n        }\n      }\n    } else if (stmt.type === \"FunctionDeclaration\") {\n      const funcDecl = stmt;\n      if (funcDecl.id) {\n        const text = source.slice(funcDecl.start, funcDecl.end);\n        bindings.set(funcDecl.id.name, {\n          name: funcDecl.id.name,\n          sourceText: text,\n          kind: \"declaration\",\n        });\n      }\n    } else if (stmt.type === \"ExportNamedDeclaration\") {\n      const exportDecl = stmt;\n      const innerDecl = exportDecl.declaration;\n      if (!innerDecl) continue;\n\n      if (innerDecl.type === \"VariableDeclaration\") {\n        const varDecl = innerDecl;\n        // Slice only the inner declaration (without export keyword) so it is valid standalone\n        const text = source.slice(varDecl.start, varDecl.end);\n        for (const decl of varDecl.declarations) {\n          if (decl.id.type === \"Identifier\") {\n            bindings.set(decl.id.name, {\n              name: decl.id.name,\n              sourceText: text,\n              kind: \"declaration\",\n            });\n          }\n        }\n      } else if (innerDecl.type === \"FunctionDeclaration\") {\n        const funcDecl = innerDecl;\n        if (funcDecl.id) {\n          const text = source.slice(funcDecl.start, funcDecl.end);\n          bindings.set(funcDecl.id.name, {\n            name: funcDecl.id.name,\n            sourceText: text,\n            kind: \"declaration\",\n          });\n        }\n      }\n    }\n  }\n\n  return bindings;\n}\n\n/**\n * Resolve all bindings needed by a function, recursively including\n * dependencies of top-level declarations.\n * @param freeVars - Set of free variable names extracted from the function.\n * @param sourceBindings - Available bindings from the source file.\n * @returns Object with needed import statements and declaration texts.\n */\nexport function resolveNeededBindings(\n  freeVars: Set<string>,\n  sourceBindings: Map<string, SourceBinding>,\n): { imports: string[]; declarations: string[]; unresolved: string[] } {\n  const neededImports = new Set<string>();\n  const neededDeclarations = new Set<string>();\n  const unresolved: string[] = [];\n  const resolved = new Set<string>();\n\n  const resolveVars = (vars: Set<string>): void => {\n    for (const varName of vars) {\n      if (resolved.has(varName)) continue;\n      resolved.add(varName);\n\n      const binding = sourceBindings.get(varName);\n      if (!binding) {\n        unresolved.push(varName);\n        continue;\n      }\n\n      if (binding.kind === \"import\") {\n        neededImports.add(binding.sourceText);\n      } else {\n        // Parse the declaration with oxc-parser (handles TypeScript) and collect\n        // all Identifier names, then resolve those that match other source bindings.\n        const identifiers = collectIdentifierNames(binding.sourceText);\n        const referencedVars = new Set<string>();\n        for (const id of identifiers) {\n          if (id !== varName && sourceBindings.has(id)) {\n            referencedVars.add(id);\n          }\n        }\n        resolveVars(referencedVars);\n        neededDeclarations.add(binding.sourceText);\n      }\n    }\n  };\n\n  resolveVars(freeVars);\n\n  return {\n    imports: [...neededImports],\n    declarations: [...neededDeclarations],\n    unresolved,\n  };\n}\n\nfunction buildPrecompiledExpr(bundleCode: string, argsObject: string): string {\n  return (\n    \"(() => {\\n\" +\n    \"  const module = { exports: {} };\\n\" +\n    \"  const exports = module.exports;\\n\" +\n    `${bundleCode}\\n` +\n    `  return module.exports.main(${argsObject});\\n` +\n    \"})()\"\n  );\n}\n\n/**\n * Build entry file content from already-resolved imports and declarations.\n * @param imports - Import statement texts.\n * @param declarations - Declaration statement texts.\n * @param fnSource - The function source code.\n * @param sourceFilePath - Path to the source file for resolving relative imports.\n * @param multiArg - Whether the function accepts multiple arguments (spread via `...args`).\n * @returns Entry file content string.\n */\nexport function buildMinimalEntryFromResolved(\n  imports: string[],\n  declarations: string[],\n  fnSource: string,\n  sourceFilePath: string,\n  multiArg = false,\n): string {\n  const sourceDir = resolve(sourceFilePath, \"..\").replace(/\\\\/g, \"/\");\n\n  // Rewrite relative import paths to absolute paths so rolldown can resolve them\n  const resolvedImports = imports.map((imp) =>\n    imp.replace(\n      /from\\s+[\"'](\\.[^\"']+)[\"']/g,\n      (_match, relPath: string) => `from \"${resolve(sourceDir, relPath).replace(/\\\\/g, \"/\")}\"`,\n    ),\n  );\n\n  const lines = [\n    ...resolvedImports,\n    ...declarations,\n    multiArg\n      ? `export function main(...args) { return (${fnSource})(...args); }`\n      : `export function main(input) { return (${fnSource})(input); }`,\n  ];\n  return lines.join(\"\\n\");\n}\n\nasync function bundleScriptTarget(args: {\n  fn: ScriptFunction;\n  kind: ScriptExprKind;\n  sourceFilePath: string;\n  sourceBindings: Map<string, SourceBinding>;\n  tableName: string;\n  targetIndex: number;\n  tsconfig: string | undefined;\n}): Promise<string> {\n  const { fn, kind, sourceFilePath, sourceBindings, tableName, targetIndex, tsconfig } = args;\n  const context = `${kind} in ${sourceFilePath}`;\n  const fnSource = stringifyFunction(fn);\n  if ((kind === \"typeValidate\" || kind === \"validate\") && fn.constructor.name === \"AsyncFunction\") {\n    throw new Error(\n      `${context} must be synchronous — the generated validator runs synchronously, ` +\n        \"so issues reported after an await are silently lost. Remove the async keyword.\",\n    );\n  }\n  const inlineExpr = assertParsableExpression(`(${fnSource})(${buildHookCallArgs(kind)})`, context);\n\n  // Check if the function has free variables that need bundling\n  const freeVars = findUndefinedReferences(`const __fn = ${fnSource};`);\n  if (freeVars.size === 0) {\n    // No external dependencies - use inline expression without bundling\n    return inlineExpr;\n  }\n\n  const { imports, declarations, unresolved } = resolveNeededBindings(freeVars, sourceBindings);\n  if (unresolved.length > 0) {\n    throw new Error(\n      `${context} captures unresolvable variables (${unresolved.join(\", \")}). ` +\n        \"Hooks and validators must not reference variables that cannot be resolved from the source file.\\n\" +\n        `  ${kind}: ${fnSource}`,\n    );\n  }\n\n  const entryContent = buildMinimalEntryFromResolved(\n    imports,\n    declarations,\n    fnSource,\n    sourceFilePath,\n    kind === \"typeValidate\",\n  );\n  const entry = createVirtualEntry(\n    `tailordb-script:${tableName}:${targetIndex}`,\n    entryContent,\n    \"ts\",\n    sourceFilePath,\n  );\n\n  const bundleLog = createBundleLog({ tsconfig });\n  const buildResult = await rolldown.build({\n    plugins: [\n      entry.plugin,\n      createTsconfigPathsPlugin({ virtualEntrySourceFile: sourceFilePath }),\n      platformBundleDefinePlugin,\n    ],\n    input: entry.input,\n    write: false,\n    output: {\n      format: \"cjs\",\n      sourcemap: false,\n      minify: true,\n      codeSplitting: false,\n    },\n    tsconfig,\n    treeshake: {\n      moduleSideEffects: false,\n      annotations: true,\n      unknownGlobalSideEffects: false,\n    },\n    ...bundleLog.options,\n  } as rolldown.BuildOptions);\n  bundleLog.assertAllResolved();\n\n  const bundledCode = buildResult.output[0].code;\n  return assertParsableExpression(\n    buildPrecompiledExpr(bundledCode, buildHookCallArgs(kind)),\n    context,\n  );\n}\n\n/**\n * Precompile TailorDB hooks/validators into self-contained script expressions using rolldown.\n * Uses oxc-parser AST walking to extract free variables from functions, then builds\n * minimal entry points containing only the needed imports and declarations.\n * @param type - TailorDB table schema output.\n * @param sourceFilePath - Source file where the table is defined.\n * @param tsconfig - Resolved tsconfig path, or undefined if not found.\n */\nexport async function precompileTailorDBTypeScripts(\n  type: TailorDBTypeSchemaOutput,\n  sourceFilePath: string,\n  tsconfig: string | undefined,\n): Promise<void> {\n  const targets = collectScriptTargets(type);\n  if (targets.length === 0) return;\n\n  // Collect source bindings once for all targets in this file\n  const sourceBindings = collectSourceBindings(sourceFilePath);\n\n  const results = await Promise.allSettled(\n    targets.map((target, index) =>\n      bundleScriptTarget({\n        fn: target.fn,\n        kind: target.kind,\n        sourceFilePath,\n        sourceBindings,\n        tableName: type.name,\n        targetIndex: index,\n        tsconfig,\n      }),\n    ),\n  );\n  const firstError = results.find((r): r is PromiseRejectedResult => r.status === \"rejected\");\n  if (firstError) {\n    throw firstError.reason;\n  }\n  for (const [index, result] of results.entries()) {\n    if (result.status === \"fulfilled\") {\n      const target = assertDefined(targets[index], `bundle target at index ${index} missing`);\n      setPrecompiledScriptExpr(target.fn, target.kind, result.value);\n    }\n  }\n}\n","import { fetchAll, isNotFoundError } from \"#/cli/shared/client\";\nimport { isPluginGeneratedTable } from \"#/parser/service/tailordb/type-source\";\nimport type { TypeSourceInfo, TypeSourceInfoEntry } from \"#/parser/service/tailordb/types\";\n\ntype LocalTailorDBService = {\n  readonly namespace: string;\n  readonly types: Readonly<Record<string, unknown>>;\n  readonly typeSourceInfo: Readonly<TypeSourceInfo>;\n};\n\ntype TailorDBTypeNameSourceKind = \"local\" | \"external\";\n\nexport type TailorDBTypeNameSource = {\n  readonly namespace: string;\n  readonly tableName: string;\n  readonly kind: TailorDBTypeNameSourceKind;\n  readonly detail?: string;\n};\n\ntype ListTailorDBTypesArgs = {\n  workspaceId: string;\n  namespaceName: string;\n  pageToken?: string;\n  pageSize?: number;\n};\n\ntype ListTailorDBTypesResult = {\n  tailordbTypes: Array<{ name: string }>;\n  nextPageToken?: string;\n};\n\ntype ListTailorDBTypesClient = {\n  listTailorDBTypes(args: ListTailorDBTypesArgs): Promise<ListTailorDBTypesResult>;\n};\n\nexport interface CollectLocalTailorDBTypeNameSourcesArgs {\n  /** Loaded local TailorDB services. */\n  tailorDBServices: ReadonlyArray<LocalTailorDBService>;\n}\n\nexport interface FetchExternalTailorDBTypeNameSourcesArgs {\n  /** Client used to read TailorDB metadata. */\n  client: ListTailorDBTypesClient;\n  /** Workspace that owns the configured namespaces. */\n  workspaceId: string;\n  /** External TailorDB namespaces declared in the application config. */\n  externalTailorDBNamespaces: ReadonlyArray<string>;\n}\n\ninterface AssertUniqueTailorDBTypeNamesArgs {\n  /** Table-name sources to validate. */\n  sources: ReadonlyArray<TailorDBTypeNameSource>;\n}\n\nexport interface AssertUniqueTailorDBTypeNamesWithExternalArgs\n  extends CollectLocalTailorDBTypeNameSourcesArgs, FetchExternalTailorDBTypeNameSourcesArgs {\n  /** External TailorDB services planned in the same deploy run. */\n  plannedExternalTailorDBServices?: ReadonlyArray<LocalTailorDBService>;\n}\n\n/**\n * Format a TailorDB table source for validation errors.\n * @param sourceInfo - Source information captured when loading the table\n * @returns Human-readable source detail\n */\nexport function formatTailorDBTypeSourceInfo(\n  sourceInfo: TypeSourceInfoEntry | undefined,\n): string | undefined {\n  if (!sourceInfo) {\n    return undefined;\n  }\n\n  if (isPluginGeneratedTable(sourceInfo)) {\n    const parts = [`plugin ${sourceInfo.pluginId}`];\n    if (sourceInfo.generatedTableKind) {\n      parts.push(`kind ${sourceInfo.generatedTableKind}`);\n    }\n    if (sourceInfo.originalFilePath) {\n      parts.push(`source ${sourceInfo.originalFilePath}`);\n    }\n    if (sourceInfo.originalExportName) {\n      parts.push(`export ${sourceInfo.originalExportName}`);\n    }\n    return parts.join(\", \");\n  }\n\n  return `${sourceInfo.filePath} export ${sourceInfo.exportName}`;\n}\n\n/**\n * Collect TailorDB table-name sources from loaded local services.\n * @param args - Collection inputs\n * @returns Table-name sources for local services\n */\nfunction collectLocalTailorDBTypeNameSources(\n  args: CollectLocalTailorDBTypeNameSourcesArgs,\n): TailorDBTypeNameSource[] {\n  const sources: TailorDBTypeNameSource[] = [];\n\n  for (const service of args.tailorDBServices) {\n    for (const tableName of Object.keys(service.types)) {\n      sources.push({\n        namespace: service.namespace,\n        tableName,\n        kind: \"local\",\n        detail: formatTailorDBTypeSourceInfo(service.typeSourceInfo[tableName]),\n      });\n    }\n  }\n\n  return sources;\n}\n\n/**\n * Fetch TailorDB table-name sources for external namespaces.\n * @param args - Fetch inputs\n * @returns Table-name sources for external services\n */\nexport async function fetchExternalTailorDBTypeNameSources(\n  args: FetchExternalTailorDBTypeNameSourcesArgs,\n): Promise<TailorDBTypeNameSource[]> {\n  const sourcesByNamespace = await Promise.all(\n    args.externalTailorDBNamespaces.map(async (namespace) => {\n      const sources: TailorDBTypeNameSource[] = [];\n      const tailordbTypes = await fetchAll(async (pageToken, maxPageSize) => {\n        try {\n          const { tailordbTypes, nextPageToken } = await args.client.listTailorDBTypes({\n            workspaceId: args.workspaceId,\n            namespaceName: namespace,\n            pageToken,\n            pageSize: maxPageSize,\n          });\n          return [tailordbTypes, nextPageToken ?? \"\"];\n        } catch (error) {\n          if (isNotFoundError(error)) {\n            return [[], \"\"];\n          }\n          throw error;\n        }\n      });\n\n      for (const type of tailordbTypes) {\n        sources.push({\n          namespace,\n          tableName: type.name,\n          kind: \"external\",\n        });\n      }\n\n      return sources;\n    }),\n  );\n\n  return sourcesByNamespace.flat();\n}\n\n/**\n * Assert that TailorDB table names are unique across all supplied sources.\n * @param args - Validation inputs\n */\nfunction assertUniqueTailorDBTypeNames(args: AssertUniqueTailorDBTypeNamesArgs): void {\n  const sourcesByTableName = new Map<string, TailorDBTypeNameSource[]>();\n\n  for (const source of args.sources) {\n    const existing = sourcesByTableName.get(source.tableName);\n    if (existing) {\n      existing.push(source);\n    } else {\n      sourcesByTableName.set(source.tableName, [source]);\n    }\n  }\n\n  const errors: string[] = [];\n  for (const [tableName, sources] of sourcesByTableName) {\n    if (sources.length <= 1) {\n      continue;\n    }\n\n    const sourceList = sources.map(formatTailorDBTypeNameSource).join(\", \");\n    errors.push(`Table \"${tableName}\" is defined more than once: ${sourceList}`);\n  }\n\n  if (errors.length > 0) {\n    throw new Error(\n      \"Duplicate TailorDB table names detected.\\n\" +\n        `${errors.map((error) => `  - ${error}`).join(\"\\n\")}\\n` +\n        \"TailorDB table names must be unique across all TailorDB namespaces in an application.\",\n    );\n  }\n}\n\n/**\n * Assert local TailorDB table names are unique.\n * @param args - Validation inputs\n */\nexport function assertUniqueLocalTailorDBTypeNames(\n  args: CollectLocalTailorDBTypeNameSourcesArgs,\n): void {\n  assertUniqueTailorDBTypeNames({\n    sources: collectLocalTailorDBTypeNameSources(args),\n  });\n}\n\n/**\n * Assert TailorDB table names are unique across local and external namespaces.\n * @param args - Validation inputs\n */\nexport async function assertUniqueTailorDBTypeNamesWithExternal(\n  args: AssertUniqueTailorDBTypeNamesWithExternalArgs,\n): Promise<void> {\n  const localSources = collectLocalTailorDBTypeNameSources(args);\n  const plannedExternalServices = args.plannedExternalTailorDBServices ?? [];\n  const plannedExternalNamespaces = new Set(\n    plannedExternalServices.map((service) => service.namespace),\n  );\n  const plannedExternalSources = collectLocalTailorDBTypeNameSources({\n    tailorDBServices: plannedExternalServices,\n  }).map((source) => ({\n    ...source,\n    kind: \"external\" as const,\n  }));\n  const remoteExternalNamespaces = args.externalTailorDBNamespaces.filter(\n    (namespace) => !plannedExternalNamespaces.has(namespace),\n  );\n  const externalSources =\n    remoteExternalNamespaces.length > 0\n      ? await fetchExternalTailorDBTypeNameSources({\n          client: args.client,\n          workspaceId: args.workspaceId,\n          externalTailorDBNamespaces: remoteExternalNamespaces,\n        })\n      : [];\n\n  assertUniqueTailorDBTypeNames({\n    sources: [...localSources, ...plannedExternalSources, ...externalSources],\n  });\n}\n\nfunction formatTailorDBTypeNameSource(source: TailorDBTypeNameSource): string {\n  const namespaceLabel =\n    source.kind === \"external\"\n      ? `external namespace \"${source.namespace}\"`\n      : `namespace \"${source.namespace}\"`;\n\n  return source.detail ? `${namespaceLabel} (${source.detail})` : namespaceLabel;\n}\n","import * as path from \"pathe\";\nimport { loadFilesWithIgnores } from \"#/cli/services/file-loader\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { resolveTSConfigWithFallback } from \"#/cli/shared/resolve-tsconfig\";\nimport { importUserModule } from \"#/cli/shared/user-modules\";\nimport {\n  pickTailorDBTypeSchemaKeys,\n  stripTailorDBTypeBuilderHelpers,\n} from \"#/parser/service/tailordb/builder-helpers\";\nimport { parseTypes, TailorDBTypeSchema } from \"#/parser/service/tailordb/index\";\nimport {\n  findMissingPermissionConfig,\n  findOmittedPermitRules,\n} from \"#/parser/service/tailordb/permission\";\nimport { getRawPluginTableName } from \"#/plugin/guards\";\nimport { assertDefined } from \"#/utils/assert\";\nimport { isSdkBranded } from \"#/utils/brand\";\nimport { precompileTailorDBTypeScripts } from \"./hooks-validate-bundler\";\nimport { formatTailorDBTypeSourceInfo } from \"./type-name-validation\";\nimport type {\n  TypeSourceInfo,\n  TypeSourceInfoEntry,\n  TailorDBType,\n} from \"#/parser/service/tailordb/types\";\nimport type { PluginManager } from \"#/plugin/manager\";\nimport type { PluginAttachment } from \"#/plugin/types\";\nimport type {\n  TailorDBServiceConfig,\n  TailorDBTypeRaw as TailorDBTypeSchemaOutput,\n} from \"#/types/tailordb.generated\";\n\nexport type TailorDBService = {\n  readonly namespace: string;\n  readonly config: TailorDBServiceConfig;\n  readonly types: Readonly<Record<string, TailorDBType>>;\n  readonly typeSourceInfo: Readonly<TypeSourceInfo>;\n  readonly pluginAttachments: ReadonlyMap<string, readonly PluginAttachment[]>;\n  loadTypes: () => Promise<Record<string, TailorDBType> | undefined>;\n  processNamespacePlugins: () => Promise<void>;\n};\n\n/**\n * Parameters for creating a TailorDBService\n */\nexport interface CreateTailorDBServiceParams {\n  /** The namespace for this TailorDB service */\n  namespace: string;\n  /** The TailorDB service configuration */\n  config: TailorDBServiceConfig;\n  /** Plugin manager for processing plugins */\n  pluginManager?: PluginManager;\n  /** Directory the config's file patterns are resolved against */\n  baseDir: string;\n}\n\n/**\n * Creates a new TailorDBService instance.\n * @param params - Parameters for creating the service\n * @returns A new TailorDBService instance\n */\nexport function createTailorDBService(params: CreateTailorDBServiceParams): TailorDBService {\n  const { namespace, config, pluginManager, baseDir } = params;\n  type TailorDBTypesByName = Record<string, TailorDBTypeSchemaOutput>;\n  const createRawTypesByName = (): TailorDBTypesByName =>\n    Object.create(null) as TailorDBTypesByName;\n  const rawTypes = Object.create(null) as Record<string, TailorDBTypesByName>;\n  let types: Record<string, TailorDBType> = {};\n  const typeSourceInfo = Object.create(null) as TypeSourceInfo;\n  const pluginAttachments: Map<string, PluginAttachment[]> = new Map();\n  let loadPromise: Promise<Record<string, TailorDBType> | undefined> | undefined;\n\n  const registerRawType = (\n    rawTypesKey: string,\n    tableName: string,\n    type: TailorDBTypeSchemaOutput,\n    sourceInfo: TypeSourceInfoEntry,\n  ): void => {\n    const existingSourceInfo = Object.hasOwn(typeSourceInfo, tableName)\n      ? typeSourceInfo[tableName]\n      : undefined;\n    if (existingSourceInfo) {\n      const firstSource = formatTailorDBTypeSourceInfo(existingSourceInfo) ?? \"unknown source\";\n      const secondSource = formatTailorDBTypeSourceInfo(sourceInfo) ?? \"unknown source\";\n      throw new Error(\n        `Duplicate TailorDB table name \"${tableName}\" detected in TailorDB service \"${namespace}\". ` +\n          `First: ${firstSource}. Second: ${secondSource}. ` +\n          \"TailorDB table names must be unique across all TailorDB files in a service.\",\n      );\n    }\n\n    assertDefined(rawTypes[rawTypesKey], `raw table entry missing for key: ${rawTypesKey}`)[\n      tableName\n    ] = type;\n    typeSourceInfo[tableName] = sourceInfo;\n  };\n\n  // Plugin-emitted tables are runtime values the schema has never seen, unlike\n  // user tables which are parsed in loadTypeFile; validate them here so a\n  // malformed table fails with the offending plugin named instead of crashing\n  // (or silently passing) during permission normalization.\n  const parsePluginTable = (table: unknown, origin: string): TailorDBTypeSchemaOutput => {\n    const result = TailorDBTypeSchema.safeParse(pickTailorDBTypeSchemaKeys(table));\n    if (!result.success) {\n      const issues = result.error.issues\n        .map((issue) => `  - ${issue.path.map(String).join(\".\") || \"(root)\"}: ${issue.message}`)\n        .join(\"\\n\");\n      throw new Error(\n        `TailorDB table ${origin} in TailorDB service \"${namespace}\" failed schema validation:\\n${issues}`,\n        { cause: result.error },\n      );\n    }\n    return result.data;\n  };\n\n  const describeGeneratedTable = (name: unknown, kind: string, pluginId: string): string => {\n    const namePart = typeof name === \"string\" && name.length > 0 ? `\"${name}\" ` : \"\";\n    return `${namePart}generated as \"${kind}\" by plugin \"${pluginId}\"`;\n  };\n\n  const doParseTypes = (): void => {\n    const allTypes = createRawTypesByName();\n    for (const fileTypes of Object.values(rawTypes)) {\n      for (const [tableName, type] of Object.entries(fileTypes)) {\n        allTypes[tableName] = type;\n      }\n    }\n\n    types = parseTypes(allTypes, namespace, typeSourceInfo);\n  };\n\n  // Warn about object-format permission rules that omit `permit`. Those default\n  // to \"deny\" (unlike the array shorthand, which defaults to \"allow\"), an easy\n  // way to accidentally lock out access the rule was meant to grant.\n  const warnOmittedPermit = (): void => {\n    for (const fileTypes of Object.values(rawTypes)) {\n      for (const [tableName, type] of Object.entries(fileTypes)) {\n        const locations = findOmittedPermitRules(type.metadata.permissions);\n        if (locations.length > 0) {\n          logger.warn(\n            `TailorDB table \"${tableName}\" has permission rule(s) ${locations.join(\", \")} in object form without an explicit \"permit\"; they default to \"deny\". Set permit: true (allow) or permit: false (deny) to silence this warning.`,\n          );\n        }\n      }\n    }\n  };\n\n  // Require .permission()/.gqlPermission() to be set explicitly. TailorDB\n  // fails closed for record operations without a .permission(), producing an\n  // opaque \"internal error\" instead of a clear denial when only\n  // .gqlPermission() is set. Catching the omission here, rather than at\n  // deploy/insert time, surfaces it while the table is still local.\n  const validateRequiredPermissions = (): void => {\n    const errors: string[] = [];\n    for (const fileTypes of Object.values(rawTypes)) {\n      for (const [tableName, type] of Object.entries(fileTypes)) {\n        const effectiveGqlOperations =\n          type.metadata.settings?.gqlOperations ?? config.gqlOperations;\n        const { missingPermission, missingGqlPermission } = findMissingPermissionConfig(\n          type.metadata.permissions,\n          effectiveGqlOperations,\n        );\n        if (!missingPermission && !missingGqlPermission) {\n          continue;\n        }\n        const source = formatTailorDBTypeSourceInfo(typeSourceInfo[tableName]);\n        const location = source ? ` (${source})` : \"\";\n        if (missingPermission) {\n          errors.push(\n            `TailorDB table \"${tableName}\"${location} has no .permission() configured. TailorDB denies all record operations for tables without permission; call .permission(...) to grant access explicitly.`,\n          );\n        }\n        if (missingGqlPermission) {\n          errors.push(\n            `TailorDB table \"${tableName}\"${location} has no .gqlPermission() configured, but GraphQL operations are enabled for it. Call .gqlPermission(...) to grant GraphQL access explicitly, or disable GraphQL exposure with .features({ gqlOperations: { create: false, update: false, delete: false, read: false } }).`,\n          );\n        }\n      }\n    }\n    if (errors.length > 0) {\n      throw new Error(\n        `TailorDB permission configuration errors in service \"${namespace}\":\\n${errors.map((e) => `  - ${e}`).join(\"\\n\")}`,\n      );\n    }\n  };\n\n  /**\n   * Process plugins for a table and add generated tables to rawTypes\n   * @param rawTable - The raw TailorDB table being processed\n   * @param attachments - Plugin attachments for this table\n   * @param sourceFilePath - The file path where the table was loaded from\n   */\n  const processPluginsForTable = async (\n    rawTable: TailorDBTypeSchemaOutput,\n    attachments: PluginAttachment[],\n    sourceFilePath: string,\n  ): Promise<void> => {\n    if (!pluginManager) return;\n\n    const { extendedTable, generatedTables, events } =\n      await pluginManager.processAttachmentsForTable({\n        rawTable,\n        attachments,\n        namespace,\n      });\n\n    // Validate every plugin output before registering any of it, so a failure\n    // does not leave partially registered state behind.\n    const extendingPluginIds = [\n      ...new Set(events.filter((ev) => ev.kind === \"extended\").map((ev) => ev.pluginId)),\n    ];\n    const parsedExtendedTable =\n      extendedTable === undefined\n        ? undefined\n        : parsePluginTable(\n            extendedTable,\n            `\"${rawTable.name}\" extended by ${extendingPluginIds.length === 1 ? \"plugin\" : \"plugins\"} ${extendingPluginIds.map((id) => `\"${id}\"`).join(\", \")}`,\n          );\n    const parsedGeneratedTables = generatedTables.map((generatedTable) => ({\n      ...generatedTable,\n      table: parsePluginTable(\n        generatedTable.table,\n        describeGeneratedTable(\n          generatedTable.tableName,\n          generatedTable.kind,\n          generatedTable.pluginId,\n        ),\n      ),\n    }));\n\n    if (parsedExtendedTable) {\n      assertDefined(\n        rawTypes[sourceFilePath],\n        `raw table entry missing for file: ${sourceFilePath}`,\n      )[rawTable.name] = parsedExtendedTable;\n    }\n    for (const generatedTable of parsedGeneratedTables) {\n      // Plugin-generated tables don't have a source file.\n      // Generators that need to import these tables should generate their own type files.\n      const sourceInfo: TypeSourceInfoEntry = {\n        exportName: generatedTable.tableName,\n        pluginId: generatedTable.pluginId,\n        pluginImportPath: generatedTable.pluginImportPath,\n        originalFilePath: sourceFilePath,\n        originalExportName: typeSourceInfo[rawTable.name]?.exportName || rawTable.name,\n        generatedTableKind: generatedTable.kind,\n        pluginConfig: generatedTable.pluginConfig,\n        namespace,\n      };\n      registerRawType(sourceFilePath, generatedTable.tableName, generatedTable.table, sourceInfo);\n    }\n    for (const ev of events) {\n      if (ev.kind === \"extended\") {\n        logger.debug(\n          `  Extended: ${styles.success(ev.tableName)} with ${styles.highlight(ev.fieldCount.toString())} fields by plugin ${styles.info(ev.pluginId)}`,\n        );\n      } else {\n        logger.debug(\n          `  Generated: ${styles.success(ev.tableName)} by plugin ${styles.info(ev.pluginId)}`,\n        );\n      }\n    }\n  };\n\n  const loadTypeFile = async (\n    typeFile: string,\n    tsconfig: string | undefined,\n  ): Promise<TailorDBTypesByName> => {\n    rawTypes[typeFile] = createRawTypesByName();\n    const loadedTypes = createRawTypesByName();\n    try {\n      const module = await importUserModule(typeFile);\n\n      for (const exportName of Object.keys(module)) {\n        const exportedValue = module[exportName];\n\n        const result = TailorDBTypeSchema.safeParse(stripTailorDBTypeBuilderHelpers(exportedValue));\n        if (!result.success) {\n          if (isSdkBranded(exportedValue, \"tailordb-type\")) {\n            throw result.error;\n          }\n          continue;\n        }\n\n        const relativePath = path.relative(process.cwd(), typeFile);\n        logger.debug(\n          `Type: ${styles.successBright(`\"${result.data.name}\"`)} loaded from ${styles.path(relativePath)}`,\n        );\n        await precompileTailorDBTypeScripts(result.data, typeFile, tsconfig);\n        loadedTypes[result.data.name] = result.data;\n        registerRawType(typeFile, result.data.name, result.data, {\n          filePath: typeFile,\n          exportName,\n        });\n\n        // Process plugins if any\n        const rawType = exportedValue as TailorDBTypeSchemaOutput & {\n          plugins?: PluginAttachment[];\n        };\n        if (rawType.plugins && Array.isArray(rawType.plugins) && rawType.plugins.length > 0) {\n          pluginAttachments.set(rawType.name, [...rawType.plugins]);\n          logger.debug(\n            `  Plugin attachments: ${styles.info(rawType.plugins.map((p) => p.pluginId).join(\", \"))}`,\n          );\n\n          await processPluginsForTable(rawType, rawType.plugins, typeFile);\n        }\n      }\n    } catch (error) {\n      const relativePath = path.relative(process.cwd(), typeFile);\n      logger.error(`Failed to load table from ${styles.bold(relativePath)}`);\n      logger.error(String(error));\n      throw error;\n    }\n    return loadedTypes;\n  };\n\n  return {\n    namespace,\n    config,\n    get types() {\n      return types;\n    },\n    get typeSourceInfo() {\n      return typeSourceInfo;\n    },\n    get pluginAttachments() {\n      return pluginAttachments as ReadonlyMap<string, readonly PluginAttachment[]>;\n    },\n    loadTypes: async () => {\n      if (!loadPromise) {\n        loadPromise = (async () => {\n          if (config.files.length === 0) {\n            return undefined;\n          }\n\n          const typeFiles = [...new Set(loadFilesWithIgnores(config, baseDir))];\n\n          const tsconfig = await resolveTSConfigWithFallback(baseDir);\n\n          logger.newline();\n          logger.log(\n            `Found ${styles.highlight(typeFiles.length.toString())} table files for TailorDB service ${styles.highlight(`\"${namespace}\"`)}`,\n          );\n\n          if (pluginManager) {\n            for (const typeFile of typeFiles) {\n              await loadTypeFile(typeFile, tsconfig);\n            }\n          } else {\n            await Promise.all(typeFiles.map((typeFile) => loadTypeFile(typeFile, tsconfig)));\n          }\n          doParseTypes();\n          warnOmittedPermit();\n          validateRequiredPermissions();\n          return types;\n        })();\n      }\n      return loadPromise;\n    },\n    processNamespacePlugins: async () => {\n      if (!pluginManager) return;\n\n      const results = await pluginManager.processNamespacePlugins(namespace);\n      const pluginGeneratedKey = \"__plugin_generated__\";\n\n      const successfulResults = results.map(({ pluginId, config, result }) => {\n        if (!result.success) {\n          logger.error(result.error);\n          throw new Error(result.error);\n        }\n        return { pluginId, config, output: result.output };\n      });\n\n      // Validate every generated table before mutating rawTypes/typeSourceInfo,\n      // so a failure does not leave partially registered state behind.\n      const parsedGeneratedTables = successfulResults.flatMap(({ pluginId, config, output }) =>\n        Object.entries(output.tables ?? {}).map(([kind, generatedTable]) => ({\n          pluginId,\n          config,\n          kind,\n          table: parsePluginTable(\n            generatedTable,\n            describeGeneratedTable(getRawPluginTableName(generatedTable), kind, pluginId),\n          ),\n        })),\n      );\n\n      const hasPreviousGeneratedTables = Object.hasOwn(rawTypes, pluginGeneratedKey);\n      const previousGeneratedTables = rawTypes[pluginGeneratedKey];\n      const previousGeneratedTableKeys = previousGeneratedTables\n        ? Object.keys(previousGeneratedTables)\n        : [];\n      const hadPreviousGeneratedTables = previousGeneratedTableKeys.length > 0;\n      if (hasPreviousGeneratedTables) {\n        for (const tableName of previousGeneratedTableKeys) {\n          delete typeSourceInfo[tableName];\n        }\n      }\n      rawTypes[pluginGeneratedKey] = createRawTypesByName();\n\n      for (const { pluginId, config, kind, table } of parsedGeneratedTables) {\n        const sourceInfo: TypeSourceInfoEntry = {\n          exportName: table.name,\n          pluginId,\n          pluginImportPath: pluginManager.getPluginImportPath(pluginId) ?? \"\",\n          originalFilePath: \"\",\n          originalExportName: \"\",\n          generatedTableKind: kind,\n          pluginConfig: config,\n          namespace,\n        };\n        registerRawType(pluginGeneratedKey, table.name, table, sourceInfo);\n\n        logger.debug(\n          `  Generated: ${styles.success(table.name)} by namespace plugin ${styles.info(pluginId)}`,\n        );\n      }\n\n      // Re-parse tables to include namespace plugin tables\n      if (parsedGeneratedTables.length > 0 || hadPreviousGeneratedTables) {\n        doParseTypes();\n        validateRequiredPermissions();\n      }\n    },\n  };\n}\n","import { type TailorDBService } from \"#/cli/services/tailordb/service\";\nimport { type AuthConfigSchema } from \"#/parser/service/auth/index\";\nimport { assertDefined } from \"#/utils/assert\";\nimport type { AuthConnectionConfig } from \"#/types/auth-connection.generated\";\nimport type { z } from \"zod\";\n\n/**\n * Auth config after `AuthConfigSchema.parse` (e.g. token lifetimes as Duration).\n */\ntype ParsedAuthConfig = z.output<typeof AuthConfigSchema>;\n\ntype UserProfile = NonNullable<ParsedAuthConfig[\"userProfile\"]> & {\n  namespace: string;\n};\n\nexport type AuthService = {\n  readonly config: ParsedAuthConfig;\n  readonly tailorDBServices: ReadonlyArray<TailorDBService>;\n  readonly externalTailorDBNamespaces: ReadonlyArray<string>;\n  readonly connections: Readonly<Record<string, AuthConnectionConfig>>;\n  readonly userProfile: UserProfile | undefined;\n  resolveNamespaces: () => Promise<void>;\n};\n\n/**\n * Creates a new AuthService instance.\n * @param config - The auth configuration\n * @param tailorDBServices - The TailorDB services\n * @param externalTailorDBNamespaces - External TailorDB namespaces\n * @returns A new AuthService instance\n */\nexport function createAuthService(\n  config: ParsedAuthConfig,\n  tailorDBServices: ReadonlyArray<TailorDBService>,\n  externalTailorDBNamespaces: ReadonlyArray<string>,\n): AuthService {\n  const connections: Record<string, AuthConnectionConfig> = config.connections\n    ? { ...config.connections }\n    : {};\n\n  let userProfile: UserProfile | undefined;\n\n  return {\n    config,\n    tailorDBServices,\n    externalTailorDBNamespaces,\n    connections,\n    get userProfile() {\n      return userProfile;\n    },\n    resolveNamespaces: async () => {\n      // No userProfile defined\n      if (!config.userProfile) {\n        return;\n      }\n\n      // 1. Explicit namespace\n      if (config.userProfile.namespace) {\n        userProfile = {\n          ...config.userProfile,\n          namespace: config.userProfile.namespace,\n        };\n        return;\n      }\n\n      const totalNamespaceCount = tailorDBServices.length + externalTailorDBNamespaces.length;\n      let userProfileNamespace: string | undefined;\n\n      // 2. Single TailorDB\n      if (totalNamespaceCount === 1) {\n        userProfileNamespace =\n          tailorDBServices[0]?.namespace ??\n          assertDefined(externalTailorDBNamespaces[0], \"external TailorDB namespace missing\");\n      } else {\n        // 3. Multiple TailorDBs\n        await Promise.all(tailorDBServices.map((tailordb) => tailordb.loadTypes()));\n\n        const userProfileTypeName =\n          typeof config.userProfile.type === \"object\" && \"name\" in config.userProfile.type\n            ? config.userProfile.type.name\n            : undefined;\n\n        if (userProfileTypeName) {\n          for (const service of tailorDBServices) {\n            const types = service.types;\n            if (Object.prototype.hasOwnProperty.call(types, userProfileTypeName)) {\n              userProfileNamespace = service.namespace;\n              break;\n            }\n          }\n        }\n\n        if (!userProfileNamespace) {\n          throw new Error(\n            `userProfile type \"${config.userProfile.type.name}\" not found in any TailorDB namespace`,\n          );\n        }\n      }\n\n      userProfile = {\n        ...config.userProfile,\n        namespace: userProfileNamespace,\n      };\n    },\n  };\n}\n","import * as os from \"node:os\";\nimport pLimit from \"p-limit\";\nimport { parsePositiveInt } from \"./parse-positive-int\";\n\n/**\n * Resolve the maximum number of bundle operations to run in parallel.\n *\n * Resolution order:\n * 1. `TAILOR_BUNDLE_CONCURRENCY` env var (positive integer)\n * 2. `os.cpus().length`, clamped to at least 1\n *\n * Each `rolldown.build` invocation drives its own module graph and Rust thread\n * pool, so unbounded parallelism can exhaust native memory on constrained\n * runners (e.g. ubuntu-latest GitHub Actions runners with hundreds of\n * resolvers). Capping at CPU count keeps the worst case predictable.\n * @returns Concurrency cap (always >= 1)\n */\nexport function resolveBundleConcurrency(): number {\n  return parsePositiveInt(process.env.TAILOR_BUNDLE_CONCURRENCY) ?? Math.max(1, os.cpus().length);\n}\n\n/**\n * Run an async worker over each item with the bundle-concurrency cap applied.\n * Results are returned in the same order as the input items.\n *\n * On the first rejection no further queued work starts, but already-running\n * workers are awaited before that first rejection is rethrown, so a failing\n * bundle cannot leave sibling builds writing output after the caller\n * has moved on.\n * @param items - Items to process\n * @param worker - Async worker function\n * @returns Worker results in input order\n */\nexport async function withBundleConcurrency<T, R>(\n  items: T[],\n  worker: (item: T) => Promise<R>,\n): Promise<R[]> {\n  const results: R[] = [];\n  results.length = items.length;\n  const limit = pLimit(resolveBundleConcurrency());\n  let rejection: { reason: unknown } | undefined;\n\n  await Promise.all(\n    // flatMap skips sparse slots and, unlike map, emits no slot for them either.\n    items.flatMap((item, index) => [\n      limit(async () => {\n        if (rejection) return;\n        try {\n          results[index] = await worker(item);\n        } catch (reason) {\n          rejection ??= { reason };\n        }\n      }),\n    ]),\n  );\n\n  if (rejection) {\n    throw rejection.reason;\n  }\n  return results;\n}\n","import { findUndefinedReferences } from \"#/cli/shared/free-variables\";\nimport { getForbiddenGlobalMessage, isForbiddenGlobal } from \"#/utils/node-builtins\";\nimport { CLIError } from \"./errors\";\n\n/**\n * Throw a CLIError when bundled code still references a Node-only global\n * (`process`, `Buffer`, etc.) that the Tailor Platform runtime never defines.\n * Run this against already-bundled output, not source text — bundling\n * resolves every reachable import first, so any free variable left over is\n * either a genuine runtime global or unreachable dead code the bundler failed\n * to resolve (which `bundleLog.assertAllResolved()` already catches).\n * @param code - Bundled JavaScript to scan.\n * @param context - Human-readable description of what produced `code`, used in the error message.\n */\nexport function assertNoForbiddenRuntimeGlobals(code: string, context: string): void {\n  const freeVars = findUndefinedReferences(code);\n  const forbidden = [...freeVars].filter(isForbiddenGlobal).toSorted();\n  if (forbidden.length === 0) return;\n\n  const noun = forbidden.length === 1 ? \"a global\" : \"globals\";\n  throw CLIError({\n    code: \"FORBIDDEN_RUNTIME_GLOBAL\",\n    message: `${context} references ${noun} unavailable in the Tailor Platform runtime: ${forbidden.join(\", \")}.`,\n    details: forbidden.map(getForbiddenGlobalMessage).join(\"\\n\"),\n  });\n}\n","/**\n * JS expressions that shape the inputs passed to user-authored code.\n *\n * Two delivery paths:\n * - Apply config: shipped with apply and evaluated by the platform before\n *   invoking user code.\n * - Bundle inline: interpolated into the generated entry module and\n *   evaluated inside the bundled script at function entry.\n *\n * The principal field mapping (server → SDK) shared across services is built by\n * `makePrincipalExpr` from `@/parser/service/tailordb`; `tailorPrincipalMap`\n * (the `caller` mapping) is one of its outputs. `INVOKER_EXPR` and\n * `ACTOR_TRANSFORM_EXPR` below come from the same factory so the three stay in\n * sync.\n */\nimport { makePrincipalExpr, tailorPrincipalMap } from \"#/parser/service/tailordb/index\";\nimport type { Trigger } from \"#/types/executor.generated\";\nimport type { Resolver } from \"#/types/resolver.generated\";\n\n// ---------------------------------------------------------------------------\n// Bundle inline\n// ---------------------------------------------------------------------------\n\n/**\n * `invoker` value expression, inlined into bundler entry wrappers.\n *\n * Calls `tailor.context.getInvoker()` at function entry and maps the server\n * shape to `TailorPrincipal | null`. The payload is already in SDK type shape,\n * so no `USER_TYPE_*` normalization is needed; anonymous callers (`null`) pass\n * through as `null`.\n */\nexport const INVOKER_EXPR = makePrincipalExpr({\n  source: \"tailor.context.getInvoker()\",\n  normalize: false,\n  fields: {\n    type: { raw: \"$raw.type\" },\n    id: \"$raw.id\",\n    workspaceId: \"$raw.workspaceId\",\n    attributes: \"$raw.attributeMap\",\n    attributeList: \"$raw.attributes\",\n  },\n});\n\n// ---------------------------------------------------------------------------\n// Executor\n// ---------------------------------------------------------------------------\n\n/**\n * Actor field transformation expression.\n *\n * Transforms the server's actor object to match `TailorPrincipal | null`.\n */\nconst ACTOR_TRANSFORM_EXPR = `actor: ${makePrincipalExpr({\n  source: \"args.actor\",\n  normalize: true,\n  requireId: true,\n  fields: {\n    type: { raw: \"$raw?.userType\", fallback: \"$raw?.type\" },\n    id: \"$raw?.userId ?? $raw?.id\",\n    workspaceId: \"$raw.workspaceId\",\n    attributes: \"$raw.attributeMap ?? {}\",\n    attributeList: \"$raw.attributes ?? []\",\n  },\n})}`;\n\n/**\n * Build the JavaScript expression that transforms server-format executor event\n * args into SDK-format args at runtime.\n *\n * The Tailor Platform server delivers event args with server-side field names.\n * The SDK exposes different field names to user code. This function produces a\n * JavaScript expression string that performs the mapping when evaluated\n * server-side.\n * @param triggerKind - The trigger kind discriminant from the parsed executor\n * @param env - Application env record to embed in the expression\n * @returns A JavaScript expression string, e.g. `({ ...args, ... })`\n */\nexport function buildExecutorArgsExpr(\n  triggerKind: Trigger[\"kind\"],\n  env: Record<string, string | number | boolean>,\n): string {\n  const envExpr = `env: ${JSON.stringify(env)}`;\n\n  switch (triggerKind) {\n    case \"schedule\":\n      return `({ ...args, appNamespace: args.namespaceName, ${ACTOR_TRANSFORM_EXPR}, ${envExpr} })`;\n\n    case \"resolverExecuted\":\n      return `({ ...args, appNamespace: args.namespaceName, ${ACTOR_TRANSFORM_EXPR}, success: !!args.succeeded, result: args.succeeded?.result.resolver, error: args.failed?.error, ${envExpr} })`;\n\n    case \"incomingWebhook\":\n      return `({ ...args, appNamespace: args.namespaceName, rawBody: args.raw_body, ${envExpr} })`;\n\n    // Workflow events carry no namespace, and a single trigger can mix events\n    // that report an outcome with events that do not, so `success` is derived\n    // only when the delivered event actually has a result.\n    case \"workflowExecution\":\n    case \"workflowJobExecution\":\n      return `({ ...args, event: args.eventType?.split(\".\").pop(), rawEvent: args.eventType, ${ACTOR_TRANSFORM_EXPR}, ...(args.succeeded ? { success: true } : args.failed ? { success: false, error: args.failed.error ?? \"\" } : {}), ${envExpr} })`;\n\n    default:\n      // All event triggers: inject event (short name) and rawEvent (full event type) from server-side eventType\n      return `({ ...args, event: args.eventType?.split(\".\").pop(), rawEvent: args.eventType, appNamespace: args.namespaceName, ${ACTOR_TRANSFORM_EXPR}, ${envExpr} })`;\n  }\n}\n\n// ---------------------------------------------------------------------------\n// Resolver\n// ---------------------------------------------------------------------------\n\n/**\n * Build the operationHook expression for resolver pipelines.\n *\n * Transforms server context to SDK resolver context:\n *   context.args        → input\n *   context.pipeline     → spread into result\n *   user (global var)    → caller (`TailorPrincipal | null`)\n *   env                 → injected as JSON\n * @param env - Application env record to embed in the expression\n * @returns A JavaScript expression string for the operationHook\n */\nexport function buildResolverOperationHookExpr(\n  env: Record<string, string | number | boolean>,\n): string {\n  return `({ ...context.pipeline, input: context.args, caller: ${tailorPrincipalMap}, env: ${JSON.stringify(env)} });`;\n}\n\ntype ResolverPermissionPolicies = Extract<NonNullable<Resolver[\"permission\"]>, readonly unknown[]>;\ntype ResolverPermissionPolicy = ResolverPermissionPolicies[number];\ntype ResolverPermissionOperand = string | boolean | { user: string };\ntype ResolverPermissionCondition = readonly [\n  ResolverPermissionOperand,\n  \"=\" | \"!=\",\n  ResolverPermissionOperand,\n];\n\nfunction isSingleResolverCondition(\n  conditions: ResolverPermissionPolicy[\"conditions\"],\n): conditions is ResolverPermissionCondition {\n  return conditions.length === 3 && typeof conditions[1] === \"string\";\n}\n\nfunction resolverPermissionOperandExpr(operand: ResolverPermissionOperand): string {\n  if (typeof operand === \"object\") {\n    if (operand.user === \"_loggedIn\") {\n      return `(context.caller !== null)`;\n    }\n    if (operand.user === \"id\") {\n      return `context.caller?.id`;\n    }\n    return `context.caller?.attributes?.[${JSON.stringify(operand.user)}]`;\n  }\n  return JSON.stringify(operand);\n}\n\n// `_loggedIn` always evaluates to a defined boolean, but `id` and arbitrary\n// attribute lookups go through `context.caller?.` and can be `undefined` --\n// the caller is `null` for anonymous requests, and an attribute key may not\n// be set.\nfunction isArbitraryAttributeOperand(operand: ResolverPermissionOperand): boolean {\n  return typeof operand === \"object\" && operand.user !== \"_loggedIn\";\n}\n\nfunction resolverPermissionConditionExpr(condition: ResolverPermissionCondition): string {\n  const [left, operator, right] = condition;\n  const leftExpr = resolverPermissionOperandExpr(left);\n  const rightExpr = resolverPermissionOperandExpr(right);\n\n  if (operator === \"!=\") {\n    // A missing attribute must not satisfy `!=` -- otherwise an\n    // attribute-less caller would unintentionally match a policy meant to\n    // exclude only a specific value (`{ user: \"role\" } != \"BANNED\"` should\n    // not let a caller with no `role` attribute at all through).\n    const userOperandExpr = isArbitraryAttributeOperand(left)\n      ? leftExpr\n      : isArbitraryAttributeOperand(right)\n        ? rightExpr\n        : undefined;\n    if (userOperandExpr) {\n      return `(${userOperandExpr} !== undefined && ${leftExpr} !== ${rightExpr})`;\n    }\n  }\n\n  const jsOperator = operator === \"=\" ? \"===\" : \"!==\";\n  return `(${leftExpr} ${jsOperator} ${rightExpr})`;\n}\n\nfunction resolverPermissionPolicyExpr(policy: ResolverPermissionPolicy): string {\n  const conditions = isSingleResolverCondition(policy.conditions)\n    ? [policy.conditions]\n    : policy.conditions;\n  if (conditions.length === 0) {\n    throw new Error(\n      \"Resolver permission policy must have at least one condition, got an empty array.\",\n    );\n  }\n  return conditions.map(resolverPermissionConditionExpr).join(\" && \");\n}\n\n/**\n * Build a JS object literal capturing whether `policy` matched and its\n * (possibly empty) description, for runtime denial-reason attribution.\n * @param policy - The policy to compile\n * @returns A JS object literal expression: `{ matched, description }`\n */\nfunction policyEntryExpr(policy: ResolverPermissionPolicy): string {\n  return `{ matched: ${resolverPermissionPolicyExpr(policy)}, description: ${JSON.stringify(policy.description ?? \"\")} }`;\n}\n\n/**\n * Build the permission guard statement injected at resolver entry.\n *\n * Rejects the call with `TailorErrors` — the only error class the platform\n * turns back into a message the caller can read — when the caller doesn't match\n * `permission`, evaluated against `context.caller` — the original caller,\n * unaffected by `authInvoker`. `permission` is deny-by-default: a caller is\n * granted only by a matching `permit: true` policy, and a matching\n * `permit: false` policy always overrides that grant. The thrown message only\n * includes the description(s) of the policy/policies that actually caused the\n * denial.\n *\n * The schema requires at least one `permit: true` policy (an array of only\n * `permit: false` policies is rejected at build time), so `allowPolicies` is\n * never empty here for schema-valid input; this function still handles that\n * case defensively since it also runs against test-authored raw shapes.\n * @param permission - The resolver's `permission` config\n * @returns A JS statement, or `undefined` when `permission` is omitted or `\"allowAnonymous\"`\n */\nexport function buildResolverPermissionGuardExpr(\n  permission: Resolver[\"permission\"],\n): string | undefined {\n  if (!permission || permission === \"allowAnonymous\") {\n    return undefined;\n  }\n  if (permission.length === 0) {\n    throw new Error(\"Resolver permission must have at least one policy, got an empty array.\");\n  }\n  const denyPolicies = permission.filter((policy) => policy.permit === false);\n  const allowPolicies = permission.filter((policy) => policy.permit !== false);\n\n  const denyEntriesExpr = `[${denyPolicies.map(policyEntryExpr).join(\", \")}]`;\n  const allowEntriesExpr = `[${allowPolicies.map(policyEntryExpr).join(\", \")}]`;\n\n  return `{\n    const $denyPolicies = ${denyEntriesExpr};\n    const $allowPolicies = ${allowEntriesExpr};\n    const $matchedDeny = $denyPolicies.filter((p) => p.matched);\n    const $anyAllowMatched = $allowPolicies.some((p) => p.matched);\n    if ($matchedDeny.length > 0 || ($allowPolicies.length > 0 && !$anyAllowMatched)) {\n      const $reasons = ($matchedDeny.length > 0 ? $matchedDeny : $allowPolicies)\n        .map((p) => p.description)\n        .filter(Boolean);\n      const $message = $reasons.length > 0 ? \"access denied: \" + $reasons.join(\"; \") : \"access denied\";\n      throw new TailorErrors([{ message: $message, path: [] }]);\n    }\n  }`;\n}\n\n/**\n * A resolver's permission config together with the default declared by its\n * namespace. The resolver's own `permission` replaces the namespace default\n * instead of merging with it, so a resolver opts out of a namespace-wide\n * requirement with `permission: \"allowAnonymous\"`.\n */\nexport type ResolverPermissionResolution = {\n  permission: Resolver[\"permission\"];\n  defaultPermission?: Resolver[\"permission\"];\n};\n\n/**\n * Build an expression that checks resolver permissions and returns parsed input.\n * Requires `context`, `invoker`, `_internalResolver`, `t`, and `TailorErrors`\n * in the enclosing scope.\n * @param params - The resolver's and its namespace's permission config\n * @returns A JS expression that returns validated input without modifying context\n */\nexport function buildResolverValidatedInputExpr(params: ResolverPermissionResolution): string {\n  const { permission, defaultPermission } = params;\n  const permissionGuardExpr = buildResolverPermissionGuardExpr(permission ?? defaultPermission);\n  return `\n    (() => {\n      ${permissionGuardExpr ?? \"\"}\n      if (!_internalResolver.input) return context.input;\n      const result = t.object(_internalResolver.input).parse({\n        value: context.input,\n        data: context.input,\n        invoker,\n      });\n\n      if (result.issues) {\n        throw new TailorErrors(result.issues.map(issue => ({\n          message: issue.message,\n          path: issue.path ?? [],\n        })));\n      }\n      return result.value;\n    })()\n  `;\n}\n","import * as path from \"pathe\";\nimport * as rolldown from \"rolldown\";\nimport { computeBundlerContextHash, withCache, type BundleCache } from \"#/cli/cache/bundle-cache\";\nimport { loadFilesWithIgnores, type FileLoadConfig } from \"#/cli/services/file-loader\";\nimport { createStartTransformPlugin } from \"#/cli/services/workflow/start-transformer\";\nimport { withBundleConcurrency } from \"#/cli/shared/bundle-concurrency\";\nimport { createBundleLog } from \"#/cli/shared/bundle-log\";\nimport { createLogLevelTreeshakeOptions } from \"#/cli/shared/bundle-log-level\";\nimport { assertNoForbiddenRuntimeGlobals } from \"#/cli/shared/forbidden-runtime-globals\";\nimport { composeFunctionTreeshakeOptions } from \"#/cli/shared/function-treeshake\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { platformBundleDefinePlugin } from \"#/cli/shared/platform-bundle-plugin\";\nimport { resolveTSConfigWithFallback } from \"#/cli/shared/resolve-tsconfig\";\nimport { INVOKER_EXPR } from \"#/cli/shared/runtime-exprs\";\nimport { serializeStartContext, type StartContext } from \"#/cli/shared/start-context\";\nimport {\n  createTsconfigPathsPlugin,\n  type TsconfigLookupCache,\n} from \"#/cli/shared/tsconfig-paths-plugin\";\nimport { createVirtualEntry } from \"#/cli/shared/virtual-entry\";\nimport ml from \"#/utils/multiline\";\nimport { loadExecutor } from \"./loader\";\nimport type { LogLevel } from \"#/configure/config/types\";\n\ninterface ExecutorInfo {\n  name: string;\n  sourceFile: string;\n}\n\n/**\n * Options for bundling executors\n */\nexport interface BundleExecutorsOptions {\n  /** Executor file loading configuration */\n  config: FileLoadConfig;\n  /** Start context for workflow/job transformations */\n  startContext?: StartContext;\n  /** Additional files to bundle (e.g., plugin-generated executors) */\n  additionalFiles?: string[];\n  /** Optional bundle cache for skipping unchanged builds */\n  cache?: BundleCache;\n  /** Whether to enable inline sourcemaps */\n  inlineSourcemap?: boolean;\n  /** Controls which console calls are kept in bundled code */\n  bundleLogLevel?: LogLevel;\n  /** Directory the config's file patterns are resolved against */\n  baseDir: string;\n  /** Optional tsconfig lookup cache shared across bundles in this CLI run */\n  tsconfigCache?: TsconfigLookupCache;\n}\n\n/**\n * Bundle executors from the specified configuration\n *\n * This function:\n * 1. Creates an in-memory entry module that extracts operation.body\n * 2. Bundles in a single step with tree-shaking\n * @param options - Bundle executor options\n * @returns Map of executor name to bundled code\n */\nexport async function bundleExecutors(\n  options: BundleExecutorsOptions,\n): Promise<Map<string, string>> {\n  const bundledCode = new Map<string, string>();\n  const {\n    config,\n    startContext,\n    additionalFiles = [],\n    cache,\n    inlineSourcemap,\n    bundleLogLevel = \"DEBUG\",\n    baseDir,\n    tsconfigCache,\n  } = options;\n  const configFiles = loadFilesWithIgnores(config, baseDir);\n  const files = [...configFiles, ...additionalFiles];\n  if (files.length === 0) {\n    logger.warn(`No executor files found for patterns: ${config.files.join(\", \")}`);\n    return bundledCode;\n  }\n\n  logger.newline();\n  logger.log(\n    `Bundling ${styles.highlight(files.length.toString())} files for ${styles.info('\"executor\"')}`,\n  );\n\n  // Load all executors and filter to function/jobFunction only\n  const executors: ExecutorInfo[] = [];\n  for (const file of files) {\n    const executor = await loadExecutor(file);\n    if (!executor) {\n      logger.debug(`  Skipping: ${file} (could not be loaded)`);\n      continue;\n    }\n\n    // Only bundle function and jobFunction executors\n    if (![\"function\", \"jobFunction\"].includes(executor.operation.kind)) {\n      logger.debug(`  Skipping: ${executor.name} (not a function executor)`);\n      continue;\n    }\n\n    executors.push({\n      name: executor.name,\n      sourceFile: file,\n    });\n  }\n\n  if (executors.length === 0) {\n    logger.debug(\"  No function executors to bundle\");\n    return bundledCode;\n  }\n\n  const tsconfig = await resolveTSConfigWithFallback(baseDir);\n\n  // Process each executor, capped by TAILOR_BUNDLE_CONCURRENCY to bound native\n  // memory use (each rolldown.build allocates its own module graph).\n  const results = await withBundleConcurrency(executors, (executor) =>\n    bundleSingleExecutor(\n      executor,\n      tsconfig,\n      startContext,\n      cache,\n      inlineSourcemap,\n      bundleLogLevel,\n      tsconfigCache,\n    ),\n  );\n\n  for (const [name, code] of results) {\n    bundledCode.set(name, code);\n  }\n\n  logger.log(`${styles.success(\"Bundled\")} ${styles.info('\"executor\"')}`);\n\n  return bundledCode;\n}\n\nasync function bundleSingleExecutor(\n  executor: ExecutorInfo,\n  tsconfig: string | undefined,\n  startContext?: StartContext,\n  cache?: BundleCache,\n  inlineSourcemap?: boolean,\n  bundleLogLevel: LogLevel = \"DEBUG\",\n  tsconfigCache?: TsconfigLookupCache,\n): Promise<[string, string]> {\n  const serializedStartContext = serializeStartContext(startContext);\n\n  const contextHash = computeBundlerContextHash({\n    sourceFile: executor.sourceFile,\n    extraContext: serializedStartContext,\n    tsconfig,\n    inlineSourcemap,\n    bundleLogLevel,\n  });\n\n  const code = await withCache({\n    cache,\n    kind: \"executor\",\n    name: executor.name,\n    sourceFile: executor.sourceFile,\n    contextHash,\n    async build(cachePlugins, trackDependency) {\n      const absoluteSourcePath = path.resolve(executor.sourceFile);\n\n      const entryContent = ml /* js */ `\n        import _internalExecutor from \"${absoluteSourcePath}\";\n\n        const __executor_function = async (args) => {\n          const invoker = ${INVOKER_EXPR};\n          return _internalExecutor.operation.body({ ...args, invoker });\n        };\n\n        export { __executor_function as main };\n      `;\n      const entry = createVirtualEntry(\n        `executor:${executor.name}`,\n        entryContent,\n        \"js\",\n        absoluteSourcePath,\n      );\n\n      const startPlugin = createStartTransformPlugin(startContext);\n      const plugins: rolldown.Plugin[] = [entry.plugin];\n      if (startPlugin) {\n        plugins.push(startPlugin);\n      }\n      plugins.push(\n        createTsconfigPathsPlugin({ onTsconfigRead: trackDependency, cache: tsconfigCache }),\n        platformBundleDefinePlugin,\n        ...cachePlugins,\n      );\n\n      const bundleLog = createBundleLog({ tsconfig });\n      const result = await rolldown.build({\n        input: entry.input,\n        write: false,\n        output: {\n          format: \"esm\",\n          sourcemap: inlineSourcemap ? \"inline\" : true,\n          minify: inlineSourcemap\n            ? {\n                mangle: {\n                  keepNames: true,\n                },\n              }\n            : true,\n          codeSplitting: false,\n        },\n        tsconfig,\n        plugins,\n        treeshake: composeFunctionTreeshakeOptions([\n          createLogLevelTreeshakeOptions(bundleLogLevel),\n        ]),\n        ...bundleLog.options,\n      } as rolldown.BuildOptions);\n      bundleLog.assertAllResolved();\n\n      const bundledCode = result.output[0].code;\n      assertNoForbiddenRuntimeGlobals(bundledCode, `Executor \"${executor.name}\"`);\n      return bundledCode;\n    },\n  });\n\n  return [executor.name, code];\n}\n","import type { HttpAdapterConfigInput } from \"#/types/http-adapter.generated\";\n\n/**\n * Maps the lowercase `input` handler keys to the HTTP methods they serve.\n * The key set is tied to `inputHandlersSchema` in `./schema` via the\n * zinfer-generated config type, so the two cannot drift apart.\n */\nexport const HTTP_METHODS = {\n  get: \"GET\",\n  post: \"POST\",\n  put: \"PUT\",\n  patch: \"PATCH\",\n  delete: \"DELETE\",\n} as const satisfies Record<keyof Required<HttpAdapterConfigInput[\"input\"]>, string>;\n\nexport type HttpMethodKey = keyof typeof HTTP_METHODS;\n\nexport const HTTP_METHOD_KEYS = Object.keys(HTTP_METHODS) as readonly HttpMethodKey[];\n","import { z } from \"zod\";\nimport { functionSchema } from \"../common\";\n\nconst NAME_PATTERN = /^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/;\n\nconst inputHandlersSchema = z\n  .strictObject({\n    get: functionSchema.optional().describe(\"Handler for GET requests\"),\n    post: functionSchema.optional().describe(\"Handler for POST requests\"),\n    put: functionSchema.optional().describe(\"Handler for PUT requests\"),\n    patch: functionSchema.optional().describe(\"Handler for PATCH requests\"),\n    delete: functionSchema.optional().describe(\"Handler for DELETE requests\"),\n  })\n\n  .refine(\n    // optional fields become undefined after zod parses them\n    // oxlint-disable-next-line typescript/no-unnecessary-condition\n    (val) => Object.values(val).some((v) => v !== undefined),\n    \"input must declare at least one HTTP method handler\",\n  )\n  .describe(\"Per-method functions that transform HTTP requests to GraphQL requests\");\n\nexport const HttpAdapterConfigSchema = z.strictObject({\n  name: z\n    .string()\n    .regex(\n      NAME_PATTERN,\n      \"name must be 3-63 chars, lowercase alphanumeric with hyphens, not starting or ending with a hyphen\",\n    )\n    .describe(\"Unique adapter name within the domain\"),\n  pathPattern: z\n    .string()\n    .min(1)\n    .describe(\"Path pattern with segment wildcards (trailing or single-segment)\"),\n  enabled: z.boolean().default(true).describe(\"Whether the adapter is active\"),\n  priority: z\n    .number()\n    .int()\n    .min(0)\n    .default(0)\n    .describe(\"Matching priority; the lowest value wins when multiple adapters match\"),\n  input: inputHandlersSchema,\n  output: functionSchema\n    .optional()\n    .describe(\"Function that transforms GraphQL response to HTTP response\"),\n});\n","import { createRequire } from \"node:module\";\nimport { parseSync } from \"oxc-parser\";\nimport * as path from \"pathe\";\nimport * as rolldown from \"rolldown\";\nimport { computeBundlerContextHash, withCache, type BundleCache } from \"#/cli/cache/bundle-cache\";\nimport { withBundleConcurrency } from \"#/cli/shared/bundle-concurrency\";\nimport { createBundleLog } from \"#/cli/shared/bundle-log\";\nimport { createLogLevelTreeshakeOptions } from \"#/cli/shared/bundle-log-level\";\nimport { composeFunctionTreeshakeOptions } from \"#/cli/shared/function-treeshake\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { resolveTSConfigWithFallback } from \"#/cli/shared/resolve-tsconfig\";\nimport {\n  createTsconfigPathsPlugin,\n  type TsconfigLookupCache,\n} from \"#/cli/shared/tsconfig-paths-plugin\";\nimport { createVirtualEntry } from \"#/cli/shared/virtual-entry\";\nimport { HTTP_METHODS, type HttpMethodKey } from \"#/parser/service/http-adapter/index\";\nimport { getNodeBuiltinMessage, isNodeBuiltinImport } from \"#/utils/node-builtins\";\nimport type { LogLevel } from \"#/configure/config/types\";\n\nconst ADAPTER_BUNDLE_WARN_BYTES = 64 * 1024;\nconst ADAPTER_BUNDLE_ERROR_BYTES = 256 * 1024;\nconst nodeRequire = createRequire(import.meta.url);\nconst GRAPHQL_WEB_MODULE = nodeRequire.resolve(\"@0no-co/graphql.web\");\n\nexport interface HttpAdapterBundleInput {\n  name: string;\n  sourceFile: string;\n  methods: HttpMethodKey[];\n  hasOutput: boolean;\n}\n\nexport interface HttpAdapterBundleResult {\n  /** Adapter name → bundled input JS string. */\n  bundledInputs: Map<string, string>;\n  /** Adapter name → bundled output JS string. Only populated when the adapter has an output. */\n  bundledOutputs: Map<string, string>;\n}\n\n/**\n * Bundle each adapter's `input` (and `output`, if present) into a standalone\n * IIFE defining a global `transform(input)` entry point. `input` gets a\n * generated dispatcher that routes by `req.method`; `output` is used as is.\n * @param adapters - Detected adapters to bundle\n * @param baseDir - Directory the owning config's tsconfig is resolved against\n * @param cache - Optional bundle cache for skipping unchanged builds\n * @param bundleLogLevel - Controls which console calls are kept in bundled code\n * @param tsconfigCache - Optional tsconfig lookup cache shared across bundles in this CLI run\n * @returns Bundled scripts keyed by adapter name\n */\nexport async function bundleHttpAdapters(\n  adapters: HttpAdapterBundleInput[],\n  baseDir: string,\n  cache?: BundleCache,\n  bundleLogLevel: LogLevel = \"DEBUG\",\n  tsconfigCache?: TsconfigLookupCache,\n): Promise<HttpAdapterBundleResult> {\n  if (adapters.length === 0) {\n    return { bundledInputs: new Map(), bundledOutputs: new Map() };\n  }\n\n  logger.newline();\n  logger.log(\n    `Bundling ${styles.highlight(adapters.length.toString())} files for ${styles.info('\"http-adapter\"')}`,\n  );\n\n  const tsconfig = await resolveTSConfigWithFallback(baseDir);\n\n  // rolldown.build() is memory-intensive; cap parallelism like the other SDK bundlers.\n  const tasks = adapters.flatMap((adapter) => {\n    const kinds: Array<\"input\" | \"output\"> = adapter.hasOutput ? [\"input\", \"output\"] : [\"input\"];\n    return kinds.map((kind) => ({ adapter, kind }));\n  });\n  const results = await withBundleConcurrency(tasks, ({ adapter, kind }) =>\n    bundleAdapterScript(adapter, kind, tsconfig, cache, bundleLogLevel, tsconfigCache),\n  );\n\n  const bundledInputs = new Map<string, string>();\n  const bundledOutputs = new Map<string, string>();\n  for (const [name, kind, code] of results) {\n    if (kind === \"input\") {\n      bundledInputs.set(name, code);\n    } else {\n      bundledOutputs.set(name, code);\n    }\n  }\n\n  logger.log(`${styles.success(\"Bundled\")} ${styles.info('\"http-adapter\"')}`);\n\n  return { bundledInputs, bundledOutputs };\n}\n\nasync function bundleAdapterScript(\n  adapter: HttpAdapterBundleInput,\n  kind: \"input\" | \"output\",\n  tsconfig: string | undefined,\n  cache: BundleCache | undefined,\n  bundleLogLevel: LogLevel = \"DEBUG\",\n  tsconfigCache?: TsconfigLookupCache,\n): Promise<[string, \"input\" | \"output\", string]> {\n  const contextHash = computeBundlerContextHash({\n    sourceFile: adapter.sourceFile,\n    extraContext: kind === \"input\" ? adapter.methods.join(\",\") : \"\",\n    tsconfig,\n    inlineSourcemap: false,\n    bundleLogLevel,\n    prefix: `${kind}:document-query-normalize-v1`,\n  });\n\n  const code = await withCache({\n    cache,\n    kind: kind === \"input\" ? \"http-adapter-input\" : \"http-adapter-output\",\n    name: adapter.name,\n    sourceFile: adapter.sourceFile,\n    contextHash,\n    async build(cachePlugins, trackDependency) {\n      const absoluteSourcePath = path.resolve(adapter.sourceFile);\n      const entryContent =\n        kind === \"input\"\n          ? buildInputEntry(absoluteSourcePath, adapter.methods, GRAPHQL_WEB_MODULE)\n          : buildOutputEntry(absoluteSourcePath);\n      const entry = createVirtualEntry(\n        `http-adapter:${adapter.name}:${kind}`,\n        entryContent,\n        \"js\",\n        absoluteSourcePath,\n      );\n\n      const rejectNodeImports: rolldown.Plugin = {\n        name: \"http-adapter-reject-node-imports\",\n        resolveId(source) {\n          if (isNodeBuiltinImport(source)) {\n            throw new Error(`HTTP adapter \"${adapter.name}\": ${getNodeBuiltinMessage(source)}`);\n          }\n          return null;\n        },\n      };\n\n      // Stub out `@tailor-platform/sdk` imports: only the brand matters at\n      // build time, and the IIFE must not depend on external globals.\n      const stubSdkImports: rolldown.Plugin = {\n        name: \"http-adapter-stub-sdk\",\n        resolveId(source) {\n          if (source === \"@tailor-platform/sdk\" || source.startsWith(\"@tailor-platform/sdk/\")) {\n            return { id: \"\\0http-adapter-sdk-stub\", moduleSideEffects: false };\n          }\n          return null;\n        },\n        load(id) {\n          if (id === \"\\0http-adapter-sdk-stub\") {\n            return \"export const createHttpAdapter = (cfg) => cfg;\\nexport default { createHttpAdapter };\\n\";\n          }\n          return null;\n        },\n      };\n\n      const plugins: rolldown.Plugin[] = [\n        entry.plugin,\n        rejectNodeImports,\n        stubSdkImports,\n        createTsconfigPathsPlugin({ onTsconfigRead: trackDependency, cache: tsconfigCache }),\n        ...cachePlugins,\n      ];\n\n      const bundleLog = createBundleLog({ tsconfig });\n      const result = await rolldown.build({\n        input: entry.input,\n        write: false,\n        output: {\n          format: \"iife\",\n          sourcemap: false,\n          minify: true,\n          codeSplitting: false,\n        },\n        tsconfig,\n        plugins,\n        // es2017 on purpose: async/await must survive downleveling so\n        // rejectAsyncInBundle can reject it (lower targets rewrite it into\n        // generator+Promise code that evades the check and breaks on Sobek).\n        transform: { target: \"es2017\" },\n        treeshake: composeFunctionTreeshakeOptions([\n          createLogLevelTreeshakeOptions(bundleLogLevel),\n        ]),\n        ...bundleLog.options,\n      } as rolldown.BuildOptions);\n      bundleLog.assertAllResolved();\n      const bundled = result.output[0].code;\n\n      const byteLength = Buffer.byteLength(bundled, \"utf8\");\n      if (byteLength > ADAPTER_BUNDLE_ERROR_BYTES) {\n        throw new Error(\n          `HTTP adapter \"${adapter.name}\" ${kind} script is ${byteLength} bytes, exceeding the ${ADAPTER_BUNDLE_ERROR_BYTES} byte limit`,\n        );\n      }\n      if (byteLength > ADAPTER_BUNDLE_WARN_BYTES) {\n        logger.warn(\n          `HTTP adapter \"${adapter.name}\" ${kind} script is ${byteLength} bytes, larger than the recommended ${ADAPTER_BUNDLE_WARN_BYTES} byte limit`,\n        );\n      }\n\n      // Load-time checks only see the handler functions; imported helpers can\n      // still introduce async/await, so verify the whole bundle is synchronous.\n      rejectAsyncInBundle(bundled, adapter.name, kind);\n\n      return bundled;\n    },\n  });\n\n  return [adapter.name, kind, code];\n}\n\nfunction buildInputEntry(\n  absoluteSourcePath: string,\n  methods: HttpMethodKey[],\n  graphqlPrinterModule: string,\n): string {\n  const cases = methods\n    .map((method) => {\n      const result = `__adapter.input.${method}(req)`;\n      const expression = `__normalizeHttpAdapterGraphQLRequest(${result})`;\n      return `    case \"${HTTP_METHODS[method]}\": return ${expression};`;\n    })\n    .join(\"\\n\");\n  const supported = methods.map((m) => HTTP_METHODS[m]).join(\", \");\n  const documentNormalizer = `import { print as __printHttpAdapterDocument } from ${JSON.stringify(graphqlPrinterModule)};\nfunction __normalizeHttpAdapterGraphQLRequest(result) {\n  if (!result || typeof result.query === \"string\") {\n    return result;\n  }\n  return { ...result, query: __printHttpAdapterDocument(result.query) };\n}\n`;\n  return `${documentNormalizer}import __adapter from ${JSON.stringify(absoluteSourcePath)};\nglobalThis.transform = function(req) {\n  switch (req.method) {\n${cases}\n    default: throw new Error(\"HTTP adapter received unsupported method: \" + req.method + \" (supported: ${supported})\");\n  }\n};\n`;\n}\n\nfunction buildOutputEntry(absoluteSourcePath: string): string {\n  return `import __adapter from ${JSON.stringify(absoluteSourcePath)};\nglobalThis.transform = __adapter.output;\n`;\n}\n\nfunction rejectAsyncInBundle(code: string, adapterName: string, kind: \"input\" | \"output\"): void {\n  // Use a fake filename so oxc treats this as a module. The bundle is already\n  // minified IIFE; oxc parses it without complaint.\n  const { program } = parseSync(`${adapterName}.${kind}.bundle.js`, code);\n\n  let asyncFound = false;\n  const stack: unknown[] = [program];\n  while (stack.length > 0) {\n    const node = stack.pop();\n    if (!node || typeof node !== \"object\") continue;\n    const n = node as Record<string, unknown>;\n    const type = typeof n.type === \"string\" ? n.type : \"\";\n    if (type === \"AwaitExpression\") {\n      asyncFound = true;\n      break;\n    }\n    if (\n      (type === \"FunctionDeclaration\" ||\n        type === \"FunctionExpression\" ||\n        type === \"ArrowFunctionExpression\") &&\n      n.async === true\n    ) {\n      asyncFound = true;\n      break;\n    }\n    if ((type === \"ForOfStatement\" || type === \"ForStatement\") && n.await === true) {\n      asyncFound = true;\n      break;\n    }\n    for (const key of Object.keys(n)) {\n      const child = n[key];\n      if (Array.isArray(child)) {\n        for (const c of child) stack.push(c);\n      } else if (child && typeof child === \"object\") {\n        stack.push(child);\n      }\n    }\n  }\n\n  if (asyncFound) {\n    throw new Error(\n      `HTTP adapter \"${adapterName}\" ${kind} bundle contains async/await, which is unavailable in the gateway runtime. ` +\n        `Check imported helper modules — even if your handler is synchronous, an async helper will fail at runtime.`,\n    );\n  }\n}\n","import * as path from \"pathe\";\nimport { loadFilesWithIgnores } from \"#/cli/services/file-loader\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { importUserModule } from \"#/cli/shared/user-modules\";\nimport { type HttpAdapterServiceInput } from \"#/configure/config/types\";\nimport {\n  HTTP_METHOD_KEYS,\n  HttpAdapterConfigSchema,\n  type HttpMethodKey,\n} from \"#/parser/service/http-adapter/index\";\nimport { type HttpAdapterConfig } from \"#/types/http-adapter.generated\";\nimport { isSdkBranded } from \"#/utils/brand\";\n\ntype HttpAdapterServiceConfig = HttpAdapterServiceInput;\n\ntype LoadedHttpAdapter = {\n  adapter: HttpAdapterConfig;\n  sourceFile: string;\n  methods: HttpMethodKey[];\n  hasOutput: boolean;\n};\n\nexport type HttpAdapterService = {\n  readonly config: HttpAdapterServiceConfig;\n  readonly adapters: ReadonlyArray<LoadedHttpAdapter>;\n  readonly fileCount: number;\n  loadAdapters: () => Promise<void>;\n  printLoadedAdapters: () => void;\n};\n\nexport interface CreateHttpAdapterServiceParams {\n  config: HttpAdapterServiceConfig;\n  /** Directory the config's file patterns are resolved against */\n  baseDir: string;\n}\n\nexport function createHttpAdapterService(\n  params: CreateHttpAdapterServiceParams,\n): HttpAdapterService {\n  const { config, baseDir } = params;\n  let adapters: LoadedHttpAdapter[] = [];\n  let fileCount = 0;\n  let loaded = false;\n\n  return {\n    config,\n    get adapters() {\n      return adapters;\n    },\n    get fileCount() {\n      return fileCount;\n    },\n    loadAdapters: async () => {\n      if (loaded) return;\n      const result = await loadAdapterFiles(config, baseDir);\n      adapters = result.adapters;\n      fileCount = result.fileCount;\n      loaded = true;\n    },\n    printLoadedAdapters: () => {\n      if (adapters.length === 0) return;\n      logger.newline();\n      logger.log(`Found ${styles.highlight(adapters.length.toString())} HTTP adapters`);\n      for (const { adapter, sourceFile } of adapters) {\n        const relativePath = path.relative(process.cwd(), sourceFile);\n        logger.debug(\n          `HTTP adapter: ${styles.successBright(\n            `\"${adapter.name}\"`,\n          )} loaded from ${styles.path(relativePath)}`,\n        );\n      }\n    },\n  };\n}\n\nasync function loadAdapterFiles(\n  config: HttpAdapterServiceConfig,\n  baseDir: string,\n): Promise<{ adapters: LoadedHttpAdapter[]; fileCount: number }> {\n  if (config.files.length === 0) {\n    return { adapters: [], fileCount: 0 };\n  }\n\n  const files = loadFilesWithIgnores(config, baseDir);\n\n  // Import every matched file and keep the ones whose default export is a\n  // createHttpAdapter() result, mirroring the resolver/executor loaders.\n  // Matched files without one (e.g. shared helpers) are skipped.\n  const loadResults = await Promise.all(files.map(loadAdapterFromFile));\n\n  const adapters: LoadedHttpAdapter[] = [];\n  const seenNames = new Map<string, string>();\n  for (const result of loadResults) {\n    if (!result) continue;\n    const existing = seenNames.get(result.adapter.name);\n    if (existing) {\n      throw new Error(\n        `Duplicate HTTP adapter name \"${result.adapter.name}\" found:\\n` +\n          `  - ${existing}\\n` +\n          `  - ${result.sourceFile}\\n` +\n          `Each HTTP adapter must have a unique name.`,\n      );\n    }\n    seenNames.set(result.adapter.name, result.sourceFile);\n    adapters.push(result);\n  }\n\n  return { adapters, fileCount: files.length };\n}\n\nasync function loadAdapterFromFile(filePath: string): Promise<LoadedHttpAdapter | null> {\n  try {\n    const module = await importUserModule(filePath);\n    // Only a createHttpAdapter() result is a valid default export; a plain\n    // object that happens to match the schema is rejected by the brand check.\n    if (!isSdkBranded(module.default, \"http-adapter\")) {\n      // Not an adapter file (e.g. a shared helper matched by the glob). Guard\n      // against an adapter that is only exported under a named export, which\n      // would otherwise silently disappear from the deployment.\n      const named = Object.entries(module).find(\n        ([exportName, value]) => exportName !== \"default\" && isSdkBranded(value, \"http-adapter\"),\n      );\n      if (named) {\n        throw new Error(\n          `HTTP adapter must be the default export, but it is exported as \\`${named[0]}\\`. ` +\n            \"Re-export it: `export default createHttpAdapter({...})`.\",\n        );\n      }\n      return null;\n    }\n\n    const parsed = HttpAdapterConfigSchema.safeParse(module.default);\n    if (!parsed.success) {\n      throw parsed.error;\n    }\n\n    const adapter = parsed.data;\n    const methods = collectMethodKeys(adapter);\n    rejectAsyncHandlers(adapter, methods, filePath);\n\n    return {\n      adapter,\n      sourceFile: filePath,\n      methods,\n      hasOutput: adapter.output !== undefined,\n    };\n  } catch (error) {\n    const relativePath = path.relative(process.cwd(), filePath);\n    logger.error(\n      `${styles.error(\"Failed to load HTTP adapter from\")} ${styles.errorBright(relativePath)}`,\n    );\n    logger.error(String(error));\n    throw error;\n  }\n}\n\nfunction collectMethodKeys(adapter: HttpAdapterConfig): HttpMethodKey[] {\n  const input = adapter.input as Partial<Record<HttpMethodKey, unknown>>;\n  return HTTP_METHOD_KEYS.filter((key) => typeof input[key] === \"function\");\n}\n\nfunction rejectAsyncHandlers(\n  adapter: HttpAdapterConfig,\n  methods: HttpMethodKey[],\n  sourceFile: string,\n): void {\n  const input = adapter.input as Partial<Record<HttpMethodKey, unknown>>;\n  for (const method of methods) {\n    if (isAsyncFunction(input[method])) {\n      throw new Error(\n        `HTTP adapter \"${adapter.name}\" in ${sourceFile} has an async \\`input.${method}\\` function. ` +\n          `Handlers must be synchronous; async/await is not supported.`,\n      );\n    }\n  }\n  if (adapter.output !== undefined && isAsyncFunction(adapter.output)) {\n    throw new Error(\n      `HTTP adapter \"${adapter.name}\" in ${sourceFile} has an async \\`output\\` function. ` +\n        `Handlers must be synchronous; async/await is not supported.`,\n    );\n  }\n}\n\nfunction isAsyncFunction(fn: unknown): boolean {\n  return typeof fn === \"function\" && fn.constructor.name === \"AsyncFunction\";\n}\n","import { z } from \"zod\";\nimport { AuthInvokerSchema } from \"#/parser/service/auth/schema\";\nimport { TailorFieldSchema } from \"#/parser/service/field/schema\";\nimport { functionSchema } from \"../common\";\n\nexport const QueryTypeSchema = z\n  .union([z.literal(\"query\"), z.literal(\"mutation\")])\n  .describe(\"GraphQL operation type\");\n\nconst ResolverPermissionOperandSchema = z.union([\n  z.strictObject({ user: z.string() }),\n  z.string(),\n  z.boolean(),\n]);\n\nconst ResolverPermissionOperatorSchema = z.union([z.literal(\"=\"), z.literal(\"!=\")]);\n\nconst isUserOperand = (operand: z.infer<typeof ResolverPermissionOperandSchema>) =>\n  typeof operand === \"object\";\n\n// Fixed `user` keys have a known value type; arbitrary user attributes don't\n// (their declared type lives in the configure-layer generic, not here), so\n// only these two are checked against the operand they're compared to.\nconst KNOWN_USER_OPERAND_TYPES: Record<string, \"string\" | \"boolean\"> = {\n  _loggedIn: \"boolean\",\n  id: \"string\",\n};\n\nconst operandTypeMismatch = (\n  userOperand: z.infer<typeof ResolverPermissionOperandSchema>,\n  otherOperand: z.infer<typeof ResolverPermissionOperandSchema>,\n) => {\n  if (typeof userOperand !== \"object\") {\n    return undefined;\n  }\n  const expected = KNOWN_USER_OPERAND_TYPES[userOperand.user];\n  if (\n    expected === undefined ||\n    typeof otherOperand === \"object\" ||\n    typeof otherOperand === expected\n  ) {\n    return undefined;\n  }\n  return { key: userOperand.user, expected };\n};\n\nconst ResolverPermissionConditionSchema = z\n  .tuple([\n    ResolverPermissionOperandSchema,\n    ResolverPermissionOperatorSchema,\n    ResolverPermissionOperandSchema,\n  ])\n  .refine(\n    ([left, , right]) => isUserOperand(left) !== isUserOperand(right),\n    \"Resolver permission condition must reference a `user` operand on exactly one side \" +\n      \"(comparing two `user` operands to each other can match on `undefined === undefined`)\",\n  )\n  .superRefine(([left, , right], ctx) => {\n    for (const mismatch of [operandTypeMismatch(left, right), operandTypeMismatch(right, left)]) {\n      if (mismatch) {\n        ctx.addIssue({\n          code: \"custom\",\n          message: `\\`${mismatch.key}\\` must compare to a ${mismatch.expected}`,\n        });\n      }\n    }\n  })\n  .readonly();\n\nconst ResolverPermissionPolicySchema = z.strictObject({\n  conditions: z.union([\n    ResolverPermissionConditionSchema,\n    z\n      .array(ResolverPermissionConditionSchema)\n      .min(1, \"Resolver permission policy must have at least one condition\")\n      .readonly(),\n  ]),\n  permit: z.boolean(),\n  description: z\n    .string()\n    .optional()\n    .describe(\"Reason recorded for this policy, used in the access-denied error message\"),\n});\n\nexport const ResolverPermissionSchema = z\n  .union([\n    z\n      .array(ResolverPermissionPolicySchema)\n      .min(1, \"Resolver permission must have at least one policy\")\n      .refine(\n        (policies) => policies.some((policy) => policy.permit === true),\n        \"Resolver permission must include at least one `permit: true` policy — a policy array \" +\n          \"with only `permit: false` policies still lets any caller through by simply not \" +\n          \"authenticating, since none of the deny conditions apply to a caller with no user \" +\n          \"attributes at all\",\n      )\n      .readonly(),\n    z.literal(\"allowAnonymous\"),\n  ])\n  .describe(\n    \"Access requirement for this resolver, evaluated against the original caller \" +\n      '(unaffected by `invoker`) before `body` runs. \"allowAnonymous\" documents that ' +\n      \"anonymous callers are allowed. Omitted (default): unchanged, anonymous callers can \" +\n      \"reach the resolver\",\n  );\n\nexport const ResolverSchema = z.strictObject({\n  operation: QueryTypeSchema.describe(\"GraphQL operation type (query or mutation)\"),\n  name: z.string().describe(\"Resolver name\"),\n  description: z.string().optional().describe(\"Resolver description\"),\n  input: z.record(z.string(), TailorFieldSchema).optional().describe(\"Input field definitions\"),\n  body: functionSchema.describe(\"Resolver implementation function\"),\n  output: TailorFieldSchema.describe(\"Output field definition\"),\n  publishEvents: z.boolean().optional().describe(\"Enable publishing events from this resolver\"),\n  invoker: AuthInvokerSchema.optional().describe(\"Machine user to execute this resolver as\"),\n  permission: ResolverPermissionSchema.optional(),\n});\n","import { importUserModule } from \"#/cli/shared/user-modules\";\nimport { ResolverSchema } from \"#/parser/service/resolver/index\";\nimport type { Resolver } from \"#/types/resolver.generated\";\n\n/**\n * Load and validate a resolver definition from a file.\n * @param resolverFilePath - Path to the resolver file\n * @returns Parsed resolver or null if invalid\n */\nexport async function loadResolver(resolverFilePath: string): Promise<Resolver | null> {\n  const resolverModule = await importUserModule(resolverFilePath);\n  const resolver = resolverModule.default;\n\n  const parseResult = ResolverSchema.safeParse(resolver);\n  if (!parseResult.success) {\n    return null;\n  }\n\n  return parseResult.data;\n}\n","import * as path from \"pathe\";\nimport * as rolldown from \"rolldown\";\nimport { type BundleCache, computeBundlerContextHash, withCache } from \"#/cli/cache/bundle-cache\";\nimport { type FileLoadConfig, loadFilesWithIgnores } from \"#/cli/services/file-loader\";\nimport { createStartTransformPlugin } from \"#/cli/services/workflow/start-transformer\";\nimport { withBundleConcurrency } from \"#/cli/shared/bundle-concurrency\";\nimport { createBundleLog } from \"#/cli/shared/bundle-log\";\nimport { createLogLevelTreeshakeOptions } from \"#/cli/shared/bundle-log-level\";\nimport { assertNoForbiddenRuntimeGlobals } from \"#/cli/shared/forbidden-runtime-globals\";\nimport { composeFunctionTreeshakeOptions } from \"#/cli/shared/function-treeshake\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { platformBundleDefinePlugin } from \"#/cli/shared/platform-bundle-plugin\";\nimport { resolveTSConfigWithFallback } from \"#/cli/shared/resolve-tsconfig\";\nimport { buildResolverValidatedInputExpr, INVOKER_EXPR } from \"#/cli/shared/runtime-exprs\";\nimport { serializeStartContext, type StartContext } from \"#/cli/shared/start-context\";\nimport {\n  createTsconfigPathsPlugin,\n  type TsconfigLookupCache,\n} from \"#/cli/shared/tsconfig-paths-plugin\";\nimport { createVirtualEntry } from \"#/cli/shared/virtual-entry\";\nimport ml from \"#/utils/multiline\";\nimport { loadResolver } from \"./loader\";\nimport type { LogLevel } from \"#/configure/config/types\";\nimport type { Resolver } from \"#/types/resolver.generated\";\n\ninterface ResolverInfo {\n  name: string;\n  sourceFile: string;\n  permission: Resolver[\"permission\"];\n}\n\nexport interface BundleResolversOptions {\n  /** Resolver namespace name */\n  namespace: string;\n  /** Resolver file loading configuration */\n  config: FileLoadConfig;\n  /** Directory the config's file patterns are resolved against */\n  baseDir: string;\n  /** The namespace's `defaultPermission`, applied to resolvers declaring none */\n  defaultPermission?: Resolver[\"permission\"];\n  /** Start context for workflow/job transformations */\n  startContext?: StartContext;\n  /** Optional bundle cache for skipping unchanged builds */\n  cache?: BundleCache;\n  /** Whether to enable inline sourcemaps */\n  inlineSourcemap?: boolean;\n  /** Controls which console calls are kept in bundled code */\n  bundleLogLevel?: LogLevel;\n  /** Optional tsconfig lookup cache shared across bundles in this CLI run */\n  tsconfigCache?: TsconfigLookupCache;\n}\n\n/**\n * Bundle resolvers for the specified namespace\n *\n * This function:\n * 1. Uses a transform plugin to add validation wrapper during bundling\n * 2. Creates an in-memory entry module\n * 3. Bundles in a single step with tree-shaking\n * @param options - Bundle options\n * @returns Map of resolver name to bundled code\n */\nexport async function bundleResolvers(\n  options: BundleResolversOptions,\n): Promise<Map<string, string>> {\n  const {\n    namespace,\n    config,\n    baseDir,\n    defaultPermission,\n    startContext,\n    cache,\n    inlineSourcemap,\n    bundleLogLevel = \"DEBUG\",\n    tsconfigCache,\n  } = options;\n  const bundledCode = new Map<string, string>();\n  const files = loadFilesWithIgnores(config, baseDir);\n  if (files.length === 0) {\n    logger.warn(`No resolver files found for patterns: ${config.files.join(\", \")}`);\n    return bundledCode;\n  }\n\n  logger.newline();\n  logger.log(\n    `Bundling ${styles.highlight(files.length.toString())} files for ${styles.info(\n      `\"${namespace}\"`,\n    )}`,\n  );\n\n  // Load all resolvers to get their names\n  const resolvers: ResolverInfo[] = [];\n  for (const file of files) {\n    const resolver = await loadResolver(file);\n    if (!resolver) {\n      logger.debug(`  Skipping: ${file} (could not be loaded)`);\n      continue;\n    }\n    resolvers.push({\n      name: resolver.name,\n      sourceFile: file,\n      permission: resolver.permission,\n    });\n  }\n\n  const tsconfig = await resolveTSConfigWithFallback(baseDir);\n\n  // Process each resolver, capped by TAILOR_BUNDLE_CONCURRENCY to bound native\n  // memory use (each rolldown.build allocates its own module graph).\n  const results = await withBundleConcurrency(resolvers, (resolver) =>\n    bundleSingleResolver({\n      namespace,\n      resolver,\n      tsconfig,\n      defaultPermission,\n      startContext,\n      cache,\n      inlineSourcemap,\n      bundleLogLevel,\n      tsconfigCache,\n    }),\n  );\n\n  for (const [name, code] of results) {\n    bundledCode.set(name, code);\n  }\n\n  logger.log(`${styles.success(\"Bundled\")} ${styles.info(`\"${namespace}\"`)}`);\n\n  return bundledCode;\n}\n\ntype BundleSingleResolverOptions = Omit<BundleResolversOptions, \"config\" | \"baseDir\"> & {\n  resolver: ResolverInfo;\n  tsconfig: string | undefined;\n};\n\nasync function bundleSingleResolver(\n  options: BundleSingleResolverOptions,\n): Promise<[string, string]> {\n  const {\n    namespace,\n    resolver,\n    tsconfig,\n    defaultPermission,\n    startContext,\n    cache,\n    inlineSourcemap,\n    bundleLogLevel = \"DEBUG\",\n    tsconfigCache,\n  } = options;\n  const serializedStartContext = serializeStartContext(startContext);\n\n  const contextHash = computeBundlerContextHash({\n    sourceFile: resolver.sourceFile,\n    // The namespace default is part of the generated guard but lives in the\n    // config file, not in any resolver source, so a cached bundle would\n    // otherwise survive a change to it. Encoded as a pair rather than joined,\n    // so no separator has to be a character neither value can contain.\n    extraContext: JSON.stringify([serializedStartContext, defaultPermission ?? null]),\n    tsconfig,\n    inlineSourcemap,\n    bundleLogLevel,\n  });\n\n  const code = await withCache({\n    cache,\n    kind: \"resolver\",\n    namespace,\n    name: resolver.name,\n    sourceFile: resolver.sourceFile,\n    contextHash,\n    async build(cachePlugins, trackDependency) {\n      const absoluteSourcePath = path.resolve(resolver.sourceFile);\n      const validatedInputExpr = buildResolverValidatedInputExpr({\n        permission: resolver.permission,\n        defaultPermission,\n      });\n\n      const entryContent = ml /* js */ `\n        import _internalResolver from \"${absoluteSourcePath}\";\n        import { t } from \"@tailor-platform/sdk\";\n        import { serializeDateFields } from \"@tailor-platform/sdk/runtime\";\n\n        const $tailor_resolver_body = async (context) => {\n          const invoker = ${INVOKER_EXPR};\n          const input = ${validatedInputExpr};\n          const result = await _internalResolver.body({ ...context, input, invoker });\n          return serializeDateFields(_internalResolver.output, result);\n        };\n\n        export { $tailor_resolver_body as main };\n      `;\n      const entry = createVirtualEntry(\n        `resolver:${resolver.name}`,\n        entryContent,\n        \"js\",\n        absoluteSourcePath,\n      );\n\n      const startPlugin = createStartTransformPlugin(startContext);\n      const plugins: rolldown.Plugin[] = [entry.plugin];\n      if (startPlugin) {\n        plugins.push(startPlugin);\n      }\n      plugins.push(\n        createTsconfigPathsPlugin({ onTsconfigRead: trackDependency, cache: tsconfigCache }),\n        platformBundleDefinePlugin,\n        ...cachePlugins,\n      );\n\n      const bundleLog = createBundleLog({ tsconfig });\n      const result = await rolldown.build({\n        input: entry.input,\n        write: false,\n        output: {\n          format: \"esm\",\n          sourcemap: inlineSourcemap ? \"inline\" : true,\n          minify: inlineSourcemap\n            ? {\n                mangle: {\n                  keepNames: true,\n                },\n              }\n            : true,\n          codeSplitting: false,\n        },\n        tsconfig,\n        plugins,\n        treeshake: composeFunctionTreeshakeOptions([\n          createLogLevelTreeshakeOptions(bundleLogLevel),\n        ]),\n        ...bundleLog.options,\n      } as rolldown.BuildOptions);\n      bundleLog.assertAllResolved();\n\n      const bundledCode = result.output[0].code;\n      assertNoForbiddenRuntimeGlobals(bundledCode, `Resolver \"${resolver.name}\"`);\n      return bundledCode;\n    },\n  });\n\n  return [resolver.name, code];\n}\n","import * as path from \"pathe\";\nimport { loadFilesWithIgnores } from \"#/cli/services/file-loader\";\nimport { ResolverPermissionSchema } from \"#/parser/service/resolver/index\";\nimport type { ResolverServiceConfig, ResolverServiceInput } from \"#/configure/config/types\";\nimport type { Resolver } from \"#/types/resolver.generated\";\n\ntype ParseParams = {\n  namespace: string;\n  config: ResolverServiceConfig;\n};\n\n/**\n * Validate a resolver namespace's `defaultPermission` with the same schema as\n * a resolver's own `permission`, so an invalid policy fails the build instead\n * of compiling into a guard that lets everyone through.\n * @param params - The namespace name and its resolver service config\n * @returns The validated default, or `undefined` when the namespace declares none\n */\nexport function parseResolverDefaultPermission(\n  params: ParseParams,\n): Resolver[\"permission\"] | undefined {\n  const { namespace, config } = params;\n  if (config.defaultPermission === undefined) {\n    return undefined;\n  }\n  const result = ResolverPermissionSchema.safeParse(config.defaultPermission);\n  if (!result.success) {\n    throw new Error(\n      `Invalid \\`defaultPermission\\` for resolver namespace \"${namespace}\": ` +\n        result.error.issues.map((issue) => issue.message).join(\"; \"),\n    );\n  }\n  return result.data;\n}\n\ntype ResolveForFileParams = {\n  config: ResolverServiceInput | undefined;\n  filePath: string;\n  baseDir: string;\n};\n\n/**\n * Find the `defaultPermission` of the resolver namespace a file belongs to.\n *\n * `function run` receives a single file rather than a namespace, so the\n * namespace is recovered by matching the file against each namespace's own\n * patterns — otherwise a test run would skip a guard the deployed resolver has.\n *\n * Nothing stops two namespaces' patterns from claiming the same file, and\n * `deploy` then bundles that resolver once per namespace, each with its own\n * default. Picking one here would make the test run agree with only one of\n * the deployed copies, so an ambiguous file is rejected instead.\n * @param params - The config's resolver section, the resolver file, and the config's own directory\n * @returns The owning namespace's validated default, or `undefined` when no namespace claims the file\n */\nexport function resolveResolverDefaultPermissionForFile(\n  params: ResolveForFileParams,\n): Resolver[\"permission\"] | undefined {\n  const { config, filePath, baseDir } = params;\n  if (!config) {\n    return undefined;\n  }\n\n  // Globbed paths keep the platform's own separators; `path.resolve` here is\n  // pathe's, which normalizes both sides to the same form before comparing.\n  const targetFile = path.resolve(filePath);\n  const owners: Array<{ namespace: string; config: ResolverServiceConfig }> = [];\n  for (const [namespace, serviceConfig] of Object.entries(config)) {\n    if (\"external\" in serviceConfig) {\n      continue;\n    }\n    const files = loadFilesWithIgnores(serviceConfig, baseDir);\n    if (files.some((file) => path.resolve(file) === targetFile)) {\n      owners.push({ namespace, config: serviceConfig });\n    }\n  }\n\n  if (owners.length > 1) {\n    throw new Error(\n      `Resolver ${path.relative(process.cwd(), targetFile)} matches more than one resolver ` +\n        `namespace: ${owners.map((owner) => `\"${owner.namespace}\"`).join(\", \")}. ` +\n        `Each namespace applies its own \\`defaultPermission\\`, so narrow the \\`files\\`/` +\n        `\\`ignores\\` patterns until exactly one namespace claims this file.`,\n    );\n  }\n\n  const [owner] = owners;\n  return owner ? parseResolverDefaultPermission(owner) : undefined;\n}\n","import * as path from \"pathe\";\nimport { loadFilesWithIgnores } from \"#/cli/services/file-loader\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { importUserModule } from \"#/cli/shared/user-modules\";\nimport { ResolverSchema } from \"#/parser/service/resolver/index\";\nimport { isSdkBranded } from \"#/utils/brand\";\nimport { parseResolverDefaultPermission } from \"./default-permission\";\nimport type { ResolverServiceConfig } from \"#/configure/config/types\";\nimport type { Resolver } from \"#/types/resolver.generated\";\n\nexport type ResolverService = {\n  readonly namespace: string;\n  readonly config: ResolverServiceConfig;\n  /** The namespace's validated `defaultPermission`, applied to resolvers declaring none. */\n  readonly defaultPermission: Resolver[\"permission\"] | undefined;\n  readonly resolvers: Record<string, Resolver>;\n  loadResolvers: () => Promise<void>;\n};\n\n/**\n * Creates a new ResolverService instance.\n * @param namespace - The namespace for this resolver service\n * @param config - The resolver service configuration\n * @param baseDir - Directory the config's file patterns are resolved against\n * @returns A new ResolverService instance\n */\nexport function createResolverService(\n  namespace: string,\n  config: ResolverServiceConfig,\n  baseDir: string,\n): ResolverService {\n  const resolvers: Record<string, Resolver> = {};\n  const defaultPermission = parseResolverDefaultPermission({ namespace, config });\n  let loaded = false;\n\n  const loadResolverForFile = async (resolverFile: string): Promise<Resolver | undefined> => {\n    try {\n      const resolverModule = await importUserModule(resolverFile);\n      const result = ResolverSchema.safeParse(resolverModule.default);\n      if (result.success) {\n        const relativePath = path.relative(process.cwd(), resolverFile);\n        logger.debug(\n          `Resolver: ${styles.successBright(`\"${result.data.name}\"`)} loaded from ${styles.path(relativePath)}`,\n        );\n        resolvers[resolverFile] = result.data;\n        return result.data;\n      }\n      if (isSdkBranded(resolverModule.default, \"resolver\")) {\n        throw result.error;\n      }\n    } catch (error) {\n      const relativePath = path.relative(process.cwd(), resolverFile);\n      logger.error(`Failed to load resolver from ${styles.bold(relativePath)}`);\n      logger.error(String(error));\n      throw error;\n    }\n    return undefined;\n  };\n\n  return {\n    namespace,\n    config,\n    defaultPermission,\n    get resolvers() {\n      return resolvers;\n    },\n    loadResolvers: async () => {\n      if (loaded) {\n        return;\n      }\n      if (config.files.length === 0) {\n        return;\n      }\n\n      const resolverFiles = loadFilesWithIgnores(config, baseDir);\n\n      logger.log(\n        `Found ${styles.highlight(resolverFiles.length.toString())} resolver files for service ${styles.highlight(`\"${namespace}\"`)}`,\n      );\n\n      await Promise.all(resolverFiles.map((resolverFile) => loadResolverForFile(resolverFile)));\n      assertUniqueResolverNames(resolvers, namespace);\n      warnUndeclaredPermissions({ namespace, defaultPermission, resolvers });\n      loaded = true;\n    },\n  };\n}\n\ntype WarnUndeclaredPermissionsParams = {\n  namespace: string;\n  defaultPermission: Resolver[\"permission\"] | undefined;\n  resolvers: Record<string, Resolver>;\n};\n\n/**\n * Warn about resolvers that declare no access requirement at all.\n *\n * A namespace-level `defaultPermission` covers every resolver in the\n * namespace, so the warning only fires when the namespace declares none and\n * at least one of its resolvers declares none either — those resolvers are\n * reachable by anonymous callers.\n * @param params - The namespace, its default permission, and its loaded resolvers\n */\nfunction warnUndeclaredPermissions(params: WarnUndeclaredPermissionsParams): void {\n  const { namespace, defaultPermission, resolvers } = params;\n  if (defaultPermission !== undefined) {\n    return;\n  }\n\n  const loaded = Object.values(resolvers);\n  const undeclared = loaded.filter((resolver) => resolver.permission === undefined);\n  if (undeclared.length === 0) {\n    return;\n  }\n\n  logger.warn(\n    `Resolver namespace ${styles.highlight(`\"${namespace}\"`)}: ${undeclared.length} of ` +\n      `${loaded.length} resolvers declare no \\`permission\\`, so anonymous callers can reach ` +\n      `them. Set \\`defaultPermission\\` on the namespace, or declare \\`permission\\` on each ` +\n      `resolver (\"allowAnonymous\" if public access is intended).`,\n  );\n  // Sorted because resolvers load concurrently, so their record order varies per run.\n  const names = undeclared.map((resolver) => resolver.name).toSorted();\n  logger.debug(`  Resolvers without \\`permission\\`: ${names.join(\", \")}`);\n}\n\n/**\n * Assert that every loaded resolver in a namespace has a unique name.\n * Resolvers are stored by source file, so two files declaring the same\n * `name` would otherwise silently share a single bundle cache entry.\n * @param resolvers - Loaded resolvers keyed by source file\n * @param namespace - The namespace the resolvers belong to\n */\nfunction assertUniqueResolverNames(resolvers: Record<string, Resolver>, namespace: string): void {\n  const seenNames = new Map<string, string>();\n  for (const [file, resolver] of Object.entries(resolvers)) {\n    const relativePath = path.relative(process.cwd(), file);\n    const existing = seenNames.get(resolver.name);\n    if (existing) {\n      throw new Error(\n        `Duplicate resolver name \"${resolver.name}\" found in namespace \"${namespace}\":\\n` +\n          `  - ${existing}\\n` +\n          `  - ${relativePath}\\n` +\n          `Each resolver must have a unique name within a namespace.`,\n      );\n    }\n    seenNames.set(resolver.name, relativePath);\n  }\n}\n","import { parseSync } from \"oxc-parser\";\nimport { type ASTNode, type Replacement, applyReplacements, findStatementEnd } from \"./ast-utils\";\nimport { findAllJobs } from \"./job-detector\";\nimport { collectSdkBindings, isSdkFunctionCall } from \"./sdk-binding-collector\";\nimport type { Program } from \"@oxc-project/types\";\n\n/**\n * Find variable declarations by export names\n * Returns a map of export name to statement range\n * @param program - Parsed TypeScript program\n * @returns Map of export name to statement range\n */\nfunction findVariableDeclarationsByName(\n  program: Program,\n): Map<string, { start: number; end: number }> {\n  const declarations = new Map<string, { start: number; end: number }>();\n\n  for (const statement of program.body) {\n    const declaration =\n      statement.type === \"ExportNamedDeclaration\" ? statement.declaration : statement;\n    if (declaration?.type !== \"VariableDeclaration\") continue;\n\n    const variableDeclaration = declaration;\n    for (const declarator of variableDeclaration.declarations) {\n      if (declarator.id.type === \"Identifier\") {\n        declarations.set(declarator.id.name, {\n          start: statement.start,\n          end: statement.end,\n        });\n      }\n    }\n  }\n\n  return declarations;\n}\n\n/**\n * Find createWorkflow default export declarations\n * Returns the range of the export statement to remove\n * @param program - Parsed TypeScript program\n * @returns Range of the default export statement or null\n */\nfunction findWorkflowDefaultExport(program: Program): { start: number; end: number } | null {\n  const bindings = collectSdkBindings(program, \"createWorkflow\");\n\n  for (const statement of program.body) {\n    if (statement.type === \"ExportDefaultDeclaration\") {\n      const exportDecl = statement;\n      const declaration = exportDecl.declaration;\n\n      // Check for direct createWorkflow call: export default createWorkflow({...})\n      if (isSdkFunctionCall(declaration as unknown as ASTNode, bindings, \"createWorkflow\")) {\n        return { start: exportDecl.start, end: exportDecl.end };\n      }\n\n      // Check for variable reference that was assigned from createWorkflow\n      // This handles: const wf = createWorkflow({...}); export default wf;\n      if (declaration.type === \"Identifier\") {\n        return { start: exportDecl.start, end: exportDecl.end };\n      }\n    }\n  }\n\n  return null;\n}\n\n/**\n * Transform workflow source code\n * - Other jobs: remove entire variable declaration\n * @param source - The source code to transform\n * @param targetJobName - The name of the target job (from job config)\n * @param targetJobExportName - The export name of the target job (optional, for enhanced detection)\n * @param otherJobExportNames - Export names of other jobs to remove (optional, for enhanced detection)\n * @returns Transformed workflow source code\n */\nexport function transformWorkflowSource(\n  source: string,\n  targetJobName: string,\n  targetJobExportName?: string,\n  otherJobExportNames?: string[],\n): string {\n  // Use .ts extension to properly parse TypeScript code\n  const { program } = parseSync(\"input.ts\", source);\n\n  // Find all jobs using AST detection\n  const detectedJobs = findAllJobs(program, source);\n\n  // Defense-in-depth: the bundler already gates this function behind an\n  // isJobSourceFile check, so dependency files should not reach here.\n  // Guard anyway so that external callers don't accidentally strip exports\n  // from files that don't contain the target job.\n  const targetJobExistsInFile = detectedJobs.some((j) => j.name === targetJobName);\n  if (!targetJobExistsInFile) {\n    return source;\n  }\n\n  // Find all variable declarations for export name-based removal\n  const allDeclarations = findVariableDeclarationsByName(program);\n\n  const replacements: Replacement[] = [];\n  const removedStarts = new Set<number>();\n\n  // Step 1: First, collect all ranges that will be removed (other job declarations)\n  // This runs before the trigger pass so calls inside sibling jobs are removed first.\n  for (const job of detectedJobs) {\n    if (job.name === targetJobName) {\n      continue;\n    }\n\n    if (job.statementRange && !removedStarts.has(job.statementRange.start)) {\n      const endPos = findStatementEnd(source, job.statementRange.end);\n      removedStarts.add(job.statementRange.start);\n      replacements.push({\n        start: job.statementRange.start,\n        end: endPos,\n        text: \"\",\n      });\n    } else if (!job.statementRange) {\n      // Fallback: replace body with empty function if we can't find the statement\n      removedStarts.add(job.bodyValueRange.start);\n      replacements.push({\n        start: job.bodyValueRange.start,\n        end: job.bodyValueRange.end,\n        text: \"() => {}\",\n      });\n    }\n  }\n\n  // Step 2: Remove other jobs by export name (catches jobs missed by AST detection)\n  if (otherJobExportNames) {\n    for (const exportName of otherJobExportNames) {\n      if (exportName === targetJobExportName) continue;\n\n      const declRange = allDeclarations.get(exportName);\n      if (declRange && !removedStarts.has(declRange.start)) {\n        const endPos = findStatementEnd(source, declRange.end);\n        removedStarts.add(declRange.start);\n        replacements.push({\n          start: declRange.start,\n          end: endPos,\n          text: \"\",\n        });\n      }\n    }\n  }\n\n  // Step 3: Remove createWorkflow default export (not needed in job bundles)\n  const workflowExport = findWorkflowDefaultExport(program);\n  if (workflowExport && !removedStarts.has(workflowExport.start)) {\n    const endPos = findStatementEnd(source, workflowExport.end);\n    removedStarts.add(workflowExport.start);\n    replacements.push({\n      start: workflowExport.start,\n      end: endPos,\n      text: \"\",\n    });\n  }\n\n  return applyReplacements(source, replacements);\n}\n","import * as fs from \"node:fs\";\nimport { parseSync } from \"oxc-parser\";\nimport * as path from \"pathe\";\nimport * as rolldown from \"rolldown\";\nimport { computeBundlerContextHash, withCache, type BundleCache } from \"#/cli/cache/bundle-cache\";\nimport { withBundleConcurrency } from \"#/cli/shared/bundle-concurrency\";\nimport { createBundleLog } from \"#/cli/shared/bundle-log\";\nimport { createLogLevelTreeshakeOptions } from \"#/cli/shared/bundle-log-level\";\nimport { assertNoForbiddenRuntimeGlobals } from \"#/cli/shared/forbidden-runtime-globals\";\nimport { composeFunctionTreeshakeOptions } from \"#/cli/shared/function-treeshake\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { platformBundleDefinePlugin } from \"#/cli/shared/platform-bundle-plugin\";\nimport { resolveTSConfigWithFallback } from \"#/cli/shared/resolve-tsconfig\";\nimport { INVOKER_EXPR } from \"#/cli/shared/runtime-exprs\";\nimport { serializeStartContext, type StartContext } from \"#/cli/shared/start-context\";\nimport {\n  createTsconfigPathsPlugin,\n  type TsconfigLookupCache,\n} from \"#/cli/shared/tsconfig-paths-plugin\";\nimport { createVirtualEntry } from \"#/cli/shared/virtual-entry\";\nimport ml from \"#/utils/multiline\";\nimport { getModuleExportName, type ASTNode } from \"./ast-utils\";\nimport { findAllJobs } from \"./job-detector\";\nimport { transformWorkflowSource } from \"./source-transformer\";\nimport { detectResolvedStartCalls, hasStartCall, transformStartCalls } from \"./start-transformer\";\nimport type { LogLevel } from \"#/configure/config/types\";\n\nfunction safeRealpath(p: string): string {\n  const resolved = path.resolve(p);\n  try {\n    return fs.realpathSync(resolved);\n  } catch (e) {\n    logger.debug(`realpathSync failed for ${resolved}: ${e instanceof Error ? e.message : e}`);\n    return resolved;\n  }\n}\n\ninterface JobInfo {\n  name: string;\n  exportName: string;\n  sourceFile: string;\n}\n\n/**\n * Thrown when a job's dependency graph cannot be statically determined, so the\n * job or a call to it would otherwise be silently dropped from the bundle.\n */\nclass WorkflowJobDetectionError extends Error {}\n\nfunction isExecJobFunctionCallee(node: unknown): boolean {\n  if (!node || typeof node !== \"object\") return false;\n  const callee = node as ASTNode;\n  if (callee.type !== \"MemberExpression\") return false;\n  const property = callee.property as ASTNode | undefined;\n  if (property?.type !== \"Identifier\" || property.name !== \"execJobFunction\") return false;\n  const object = callee.object as ASTNode | undefined;\n  if (object?.type !== \"MemberExpression\") return false;\n  const workflowProperty = object.property as ASTNode | undefined;\n  if (workflowProperty?.type !== \"Identifier\" || workflowProperty.name !== \"workflow\") {\n    return false;\n  }\n  const root = object.object as ASTNode | undefined;\n  return root?.type === \"Identifier\" && root.name === \"tailor\";\n}\n\nfunction extractStaticStringValue(node: unknown): string | undefined {\n  if (!node || typeof node !== \"object\") return undefined;\n  const value = node as ASTNode;\n  if (value.type === \"Literal\" && typeof value.value === \"string\") {\n    return value.value;\n  }\n  if (value.type === \"TemplateLiteral\") {\n    const quasis = value.quasis as Array<{ value?: { cooked?: string } }> | undefined;\n    const expressions = value.expressions as unknown[] | undefined;\n    if (quasis?.length === 1 && (expressions?.length ?? 0) === 0) {\n      return quasis[0]?.value?.cooked;\n    }\n  }\n  return undefined;\n}\n\nconst RUNTIME_WORKFLOW_MODULE_SPECIFIERS = new Set([\n  \"@tailor-platform/sdk/runtime\",\n  \"@tailor-platform/sdk/runtime/workflow\",\n]);\n\nfunction collectRuntimeWorkflowImportBindings(program: ASTNode): Set<string> {\n  const bindings = new Set<string>();\n  for (const statement of (program.body as ASTNode[] | undefined) ?? []) {\n    if (statement.type !== \"ImportDeclaration\" || statement.importKind === \"type\") continue;\n    const source = statement.source as ASTNode | undefined;\n    if (\n      typeof source?.value !== \"string\" ||\n      !RUNTIME_WORKFLOW_MODULE_SPECIFIERS.has(source.value)\n    ) {\n      continue;\n    }\n    for (const specifier of (statement.specifiers as ASTNode[] | undefined) ?? []) {\n      if (specifier.type !== \"ImportSpecifier\" || specifier.importKind === \"type\") continue;\n      const imported = getModuleExportName(specifier.imported);\n      const local = getModuleExportName(specifier.local);\n      if (imported === \"workflow\" && local) bindings.add(local);\n    }\n  }\n  return bindings;\n}\n\nfunction isDirectExecJobFunctionCallee(\n  node: unknown,\n  runtimeWorkflowBindings: ReadonlySet<string>,\n): boolean {\n  if (isExecJobFunctionCallee(node)) return true;\n  if (!node || typeof node !== \"object\") return false;\n  const callee = node as ASTNode;\n  if (callee.type !== \"MemberExpression\") return false;\n  const property = callee.property as ASTNode | undefined;\n  if (property?.type !== \"Identifier\" || property.name !== \"execJobFunction\") return false;\n  const object = callee.object as ASTNode | undefined;\n  return object?.type === \"Identifier\" && runtimeWorkflowBindings.has(object.name as string);\n}\n\ninterface DirectExecJobFunctionCall {\n  targetName: string | undefined;\n}\n\n/**\n * Find calls to `execJobFunction` written directly in workflow source, on\n * either the ambient `tailor.workflow` global or a `workflow` value imported\n * from `@tailor-platform/sdk/runtime`(`/workflow`) (aliases included). Such a\n * call is never recognized as a dependency, so its target would silently be\n * dropped from the bundle unless something else happens to reference it.\n * @param program - Parsed workflow file AST\n * @returns Every direct execJobFunction call found, with its static target\n * name when the first argument is a string literal\n */\nfunction findDirectExecJobFunctionCalls(program: ASTNode): DirectExecJobFunctionCall[] {\n  const runtimeWorkflowBindings = collectRuntimeWorkflowImportBindings(program);\n  const calls: DirectExecJobFunctionCall[] = [];\n\n  function walk(node: ASTNode | null | undefined): void {\n    if (!node || typeof node !== \"object\") return;\n    if (\n      node.type === \"CallExpression\" &&\n      isDirectExecJobFunctionCallee(node.callee, runtimeWorkflowBindings)\n    ) {\n      const args = node.arguments as unknown[] | undefined;\n      calls.push({ targetName: extractStaticStringValue(args?.[0]) });\n    }\n    for (const key of Object.keys(node)) {\n      const child = node[key];\n      if (Array.isArray(child)) {\n        child.forEach((c: unknown) => walk(c as ASTNode | null));\n      } else if (child && typeof child === \"object\") {\n        walk(child as ASTNode);\n      }\n    }\n  }\n\n  walk(program);\n  return calls;\n}\n\nfunction buildDirectExecJobFunctionErrorMessage(\n  sourceFile: string,\n  call: DirectExecJobFunctionCall,\n): string {\n  if (call.targetName !== undefined) {\n    return (\n      `Workflow file ${sourceFile} calls execJobFunction(\"${call.targetName}\", ...) directly. A ` +\n      `direct call is never recognized as a dependency, so \"${call.targetName}\" would silently be ` +\n      `dropped from the bundle unless something else happens to reference it. Call the ` +\n      `\"${call.targetName}\" job's .start(...) method from inside a job body instead.`\n    );\n  }\n  return (\n    `Workflow file ${sourceFile} calls execJobFunction(...) directly with a job name that isn't a ` +\n    `string literal, so the target can't be resolved at build time. Call the target job's own ` +\n    `.start(...) method from inside a job body instead of calling execJobFunction directly.`\n  );\n}\n\n/**\n * Find the job names a bundled job's code calls `execJobFunction` on, by\n * looking for `tailor.workflow.execJobFunction(<name>, ...)` calls with a\n * static string name.\n * @param code - Bundled job code\n * @returns Target job names referenced with a statically known name\n */\nexport function collectExecJobFunctionTargets(code: string): string[] {\n  const { program, errors } = parseSync(\"input.js\", code);\n  if (errors.length > 0) {\n    throw new WorkflowJobDetectionError(\n      `Failed to parse bundled job code while checking for missed dependencies: ` +\n        `${errors.map((e) => e.message).join(\"; \")}`,\n    );\n  }\n  const targets: string[] = [];\n\n  function walk(node: ASTNode | null | undefined): void {\n    if (!node || typeof node !== \"object\") return;\n    if (node.type === \"CallExpression\" && isExecJobFunctionCallee(node.callee)) {\n      const args = node.arguments as unknown[] | undefined;\n      const target = extractStaticStringValue(args?.[0]);\n      if (target !== undefined) targets.push(target);\n    }\n    for (const key of Object.keys(node)) {\n      const child = node[key];\n      if (Array.isArray(child)) {\n        child.forEach((c: unknown) => walk(c as ASTNode | null));\n      } else if (child && typeof child === \"object\") {\n        walk(child as ASTNode);\n      }\n    }\n  }\n\n  walk(program as unknown as ASTNode);\n  return targets;\n}\n\n/**\n * Check every bundled job's code for execJobFunction targets that were not\n * bundled, throwing a WorkflowJobDetectionError naming the caller job when\n * one is found (or when the caller's own bundled code fails to parse).\n * @param bundledCode - Bundled job code by job name\n * @param usedJobNames - Job names that were actually bundled\n */\nexport function validateBundledDependencies(\n  bundledCode: Map<string, string>,\n  usedJobNames: readonly string[],\n): void {\n  const usedJobNameSet = new Set(usedJobNames);\n  for (const [callerJobName, code] of bundledCode) {\n    let targets: string[];\n    try {\n      targets = collectExecJobFunctionTargets(code);\n    } catch (error) {\n      const message = error instanceof Error ? error.message : String(error);\n      throw new WorkflowJobDetectionError(\n        `Failed to check the bundled output of workflow job \"${callerJobName}\" for missed ` +\n          `dependencies: ${message}`,\n      );\n    }\n\n    for (const targetJobName of targets) {\n      if (!usedJobNameSet.has(targetJobName)) {\n        throw new WorkflowJobDetectionError(\n          `Workflow job \"${callerJobName}\" calls execJobFunction(\"${targetJobName}\", ...) — usually the ` +\n            `result of a rewritten \"${targetJobName}\" job .start() call — but \"${targetJobName}\" was not ` +\n            `detected as a dependency and is not included in the bundle. Call the \"${targetJobName}\" job's ` +\n            `.start() method from inside the body of workflow job \"${callerJobName}\" (a nested function ` +\n            `inside body works too), or make sure the file containing the call is covered by the workflow ` +\n            `service's \"files\" pattern.`,\n        );\n      }\n    }\n  }\n}\n\nexport interface BundleWorkflowJobsResult {\n  /** Maps mainJobName -> list of all job names it depends on (including itself) */\n  mainJobDeps: Record<string, string[]>;\n  /** Job names that were actually bundled */\n  usedJobNames: string[];\n  /** Maps job name to bundled code string */\n  bundledCode: Map<string, string>;\n}\n\n/**\n * Bundle workflow jobs\n *\n * This function:\n * 1. Detects which jobs are actually used (mainJobs + their dependencies)\n * 2. Uses a transform plugin to transform start calls during bundling\n * 3. Creates an in-memory entry module and bundles with tree-shaking\n *\n * Returns metadata about which jobs each workflow uses.\n * @param allJobs - All available job infos\n * @param mainJobNames - Names of main jobs\n * @param env - Environment variables to inject\n * @param startContext - Start context for transformations\n * @param baseDir - Directory the owning config's tsconfig is resolved against\n * @param cache - Optional bundle cache for skipping unchanged builds\n * @param inlineSourcemap - Whether to enable inline sourcemaps\n * @param bundleLogLevel - Controls which console calls are kept in bundled code\n * @param tsconfigCache - Optional tsconfig lookup cache shared across bundles in this CLI run\n * @returns Workflow job bundling result\n */\nexport async function bundleWorkflowJobs(\n  allJobs: JobInfo[],\n  mainJobNames: string[],\n  env: Record<string, string | number | boolean> = {},\n  startContext: StartContext,\n  baseDir: string,\n  cache?: BundleCache,\n  inlineSourcemap?: boolean,\n  bundleLogLevel: LogLevel = \"DEBUG\",\n  tsconfigCache?: TsconfigLookupCache,\n): Promise<BundleWorkflowJobsResult> {\n  if (allJobs.length === 0) {\n    logger.warn(\"No workflow jobs to bundle\");\n    return { mainJobDeps: {}, usedJobNames: [], bundledCode: new Map() };\n  }\n\n  // Filter to only used jobs and get per-mainJob dependencies\n  const { usedJobs, mainJobDeps } = await filterUsedJobs(allJobs, mainJobNames, startContext);\n\n  logger.newline();\n  logger.log(\n    `Bundling ${styles.highlight(usedJobs.length.toString())} files for ${styles.info('\"workflow-job\"')}`,\n  );\n\n  const tsconfig = await resolveTSConfigWithFallback(baseDir);\n\n  // Process each job, capped by TAILOR_BUNDLE_CONCURRENCY to bound native\n  // memory use (each rolldown.build allocates its own module graph).\n  const results = await withBundleConcurrency(usedJobs, (job) =>\n    bundleSingleJob(\n      job,\n      usedJobs,\n      tsconfig,\n      env,\n      startContext,\n      cache,\n      inlineSourcemap,\n      bundleLogLevel,\n      tsconfigCache,\n    ),\n  );\n\n  const bundledCode = new Map<string, string>();\n  for (const [name, code] of results) {\n    bundledCode.set(name, code);\n  }\n\n  // Backstop for dependency-graph gaps the source-level checks in\n  // filterUsedJobs cannot see (e.g. a factored-out .start() call inside a\n  // helper file outside `workflow.files`): the rewrite still resolves and\n  // produces a valid execJobFunction call, but the target was never bundled.\n  // Runs before the success log below so a failure here doesn't print a\n  // misleading \"Bundled\" message right before throwing.\n  validateBundledDependencies(\n    bundledCode,\n    usedJobs.map((job) => job.name),\n  );\n\n  logger.log(`${styles.success(\"Bundled\")} ${styles.info('\"workflow-job\"')}`);\n\n  return {\n    mainJobDeps,\n    usedJobNames: usedJobs.map((job) => job.name),\n    bundledCode,\n  };\n}\n\ninterface FilterUsedJobsResult {\n  usedJobs: JobInfo[];\n  mainJobDeps: Record<string, string[]>;\n}\n\n/**\n * Filter jobs to only include those that are actually used.\n * A job is \"used\" if:\n * - It's a mainJob of a workflow\n * - It's called via .start() from another used job (transitively)\n *\n * Also returns a map of mainJob -> all jobs it depends on (for metadata).\n * @param allJobs - All available job infos\n * @param mainJobNames - Names of main jobs\n * @param startContext - Module binding metadata for resolving start targets\n * @returns Used jobs and main job dependency map\n */\nasync function filterUsedJobs(\n  allJobs: JobInfo[],\n  mainJobNames: string[],\n  startContext: StartContext,\n): Promise<FilterUsedJobsResult> {\n  if (allJobs.length === 0 || mainJobNames.length === 0) {\n    return { usedJobs: [], mainJobDeps: {} };\n  }\n\n  // Build maps for lookups\n  const jobsBySourceFile = new Map<string, JobInfo[]>();\n  for (const job of allJobs) {\n    const existing = jobsBySourceFile.get(job.sourceFile) || [];\n    existing.push(job);\n    jobsBySourceFile.set(job.sourceFile, existing);\n  }\n\n  // Files with no job of their own (e.g. a shared helper module factoring out\n  // .start() calls) still need scanning for stray start calls below; otherwise\n  // a call factored into such a file is never checked at all.\n  const filesToScan = new Map(jobsBySourceFile);\n  const knownRealpaths = new Set([...jobsBySourceFile.keys()].map(safeRealpath));\n  for (const binding of startContext.modules.values()) {\n    if (!knownRealpaths.has(safeRealpath(binding.sourceFile))) {\n      filesToScan.set(binding.sourceFile, []);\n    }\n  }\n\n  // Detect start calls and build dependency graph\n  // Maps job name -> set of job names it starts\n  const dependencies = new Map<string, Set<string>>();\n\n  // Process all source files in parallel\n  const fileResults = await Promise.all(\n    Array.from(filesToScan.entries()).map(async ([sourceFile, jobs]) => {\n      try {\n        const source = await fs.promises.readFile(sourceFile, \"utf-8\");\n        const { program, errors } = parseSync(sourceFile, source);\n        if (errors.length > 0) {\n          throw new WorkflowJobDetectionError(\n            `Failed to parse ${sourceFile}: ${errors.map((e) => e.message).join(\"; \")}`,\n          );\n        }\n\n        const [firstDirectExecCall] = findDirectExecJobFunctionCalls(program as unknown as ASTNode);\n        if (firstDirectExecCall) {\n          throw new WorkflowJobDetectionError(\n            buildDirectExecJobFunctionErrorMessage(sourceFile, firstDirectExecCall),\n          );\n        }\n\n        // Find all jobs in this file to get body ranges\n        const detectedJobs = findAllJobs(program, source);\n        const startCalls = detectResolvedStartCalls(program, source, startContext, sourceFile);\n\n        // For each job in this file, find which start calls are inside its body\n        const jobDependencies: Array<{ jobName: string; deps: Set<string> }> = [];\n\n        for (const job of jobs) {\n          const detectedJob = detectedJobs.find((d) => d.name === job.name);\n          if (!detectedJob) {\n            throw new WorkflowJobDetectionError(\n              `Workflow job \"${job.name}\" (export \"${job.exportName}\" in ${sourceFile}) could not be ` +\n                `statically detected: createWorkflowJob's \"name\" must be a string literal and \"body\" ` +\n                `must be a function expression. Dynamic or computed values (e.g. body: someWrapper(fn)) ` +\n                `cannot be bundled and would be silently dropped.`,\n            );\n          }\n\n          const jobDeps = new Set<string>();\n\n          for (const call of startCalls) {\n            // Check if this start call is inside the job's body\n            if (\n              call.kind === \"job\" &&\n              call.callRange.start >= detectedJob.bodyValueRange.start &&\n              call.callRange.end <= detectedJob.bodyValueRange.end\n            ) {\n              jobDeps.add(call.targetName);\n            }\n          }\n\n          if (jobDeps.size > 0) {\n            jobDependencies.push({ jobName: job.name, deps: jobDeps });\n          }\n        }\n\n        for (const call of startCalls) {\n          if (call.kind !== \"job\") continue;\n          const isInsideAJobBody = detectedJobs.some(\n            (detectedJob) =>\n              call.callRange.start >= detectedJob.bodyValueRange.start &&\n              call.callRange.end <= detectedJob.bodyValueRange.end,\n          );\n          if (!isInsideAJobBody) {\n            throw new WorkflowJobDetectionError(\n              `Call to job \"${call.targetName}\".start() in ${sourceFile} is not inside any workflow ` +\n                `job's body: it was factored into a function defined outside the calling job's body. ` +\n                `Dependency detection only sees .start() calls lexically inside a job body, so this call ` +\n                `would silently drop \"${call.targetName}\" from the bundle. Move the call to a function ` +\n                `defined inside the calling job's body.`,\n            );\n          }\n        }\n\n        return jobDependencies;\n      } catch (error) {\n        if (error instanceof WorkflowJobDetectionError) throw error;\n        // Some other unexpected error (e.g. a file read failure): treat the\n        // file as having no dependencies rather than failing the whole build.\n        return [];\n      }\n    }),\n  );\n\n  // Merge results into dependencies map\n  for (const jobDependencies of fileResults) {\n    for (const { jobName, deps } of jobDependencies) {\n      dependencies.set(jobName, deps);\n    }\n  }\n\n  // Collect all used jobs and per-mainJob dependencies\n  const usedJobNames = new Set<string>();\n  const mainJobDeps: Record<string, string[]> = {};\n\n  function collectDeps(jobName: string, collected: Set<string>) {\n    if (collected.has(jobName)) return;\n    collected.add(jobName);\n\n    // Recursively collect dependencies\n    const deps = dependencies.get(jobName);\n    if (deps) {\n      for (const dep of deps) {\n        collectDeps(dep, collected);\n      }\n    }\n  }\n\n  // For each mainJob, collect all its dependencies\n  for (const mainJobName of mainJobNames) {\n    const depsForMainJob = new Set<string>();\n    collectDeps(mainJobName, depsForMainJob);\n    mainJobDeps[mainJobName] = Array.from(depsForMainJob);\n\n    // Add to global used jobs\n    for (const dep of depsForMainJob) {\n      usedJobNames.add(dep);\n    }\n  }\n\n  // Filter to only used jobs\n  const usedJobs = allJobs.filter((job) => usedJobNames.has(job.name));\n  return { usedJobs, mainJobDeps };\n}\n\nasync function bundleSingleJob(\n  job: JobInfo,\n  allJobs: JobInfo[],\n  tsconfig: string | undefined,\n  env: Record<string, string | number | boolean>,\n  startContext: StartContext,\n  cache?: BundleCache,\n  inlineSourcemap?: boolean,\n  bundleLogLevel: LogLevel = \"DEBUG\",\n  tsconfigCache?: TsconfigLookupCache,\n): Promise<[string, string]> {\n  const serializedStartContext = serializeStartContext(startContext);\n\n  // Include sorted env variables as a prefix so that env changes invalidate the cache\n  const sortedEnvPrefix = JSON.stringify(\n    Object.fromEntries(Object.entries(env).toSorted(([a], [b]) => a.localeCompare(b))),\n  );\n  const contextHash = computeBundlerContextHash({\n    sourceFile: job.sourceFile,\n    extraContext: serializedStartContext,\n    tsconfig,\n    inlineSourcemap,\n    bundleLogLevel,\n    prefix: sortedEnvPrefix,\n  });\n\n  const code = await withCache({\n    cache,\n    kind: \"workflow-job\",\n    name: job.name,\n    sourceFile: job.sourceFile,\n    contextHash,\n    async build(cachePlugins, trackDependency) {\n      const absoluteSourcePath = path.resolve(job.sourceFile);\n\n      const entryContent = ml /* js */ `\n        import { ${job.exportName} } from \"${absoluteSourcePath}\";\n\n        export async function main(input) {\n          const env = ${JSON.stringify(env)};\n          const invoker = ${INVOKER_EXPR};\n          return await ${job.exportName}.body(input, { env, invoker });\n        }\n      `;\n      const entry = createVirtualEntry(\n        `workflow-job:${job.name}`,\n        entryContent,\n        \"js\",\n        absoluteSourcePath,\n      );\n\n      // Pre-compute once to avoid redundant realpathSync calls per module\n      const resolvedSourceFile = safeRealpath(job.sourceFile);\n\n      // Step 2: Bundle with a transform plugin that transforms start calls\n      // Collect export names for enhanced AST removal (catches jobs missed by AST detection)\n      const otherJobExportNames = allJobs\n        .filter(\n          (candidate) =>\n            candidate.name !== job.name &&\n            safeRealpath(candidate.sourceFile) === resolvedSourceFile,\n        )\n        .map((j) => j.exportName);\n\n      // Create transform plugin to transform start calls and remove other job declarations\n      const transformPlugin: rolldown.Plugin = {\n        name: \"workflow-transform\",\n        transform: {\n          filter: {\n            id: {\n              include: [/\\.(ts|mts|cts|js|mjs|cjs)$/],\n            },\n          },\n          handler(code, id) {\n            // Only transform source files that contain workflow jobs or start calls\n            if (\n              !code.includes(\"createWorkflowJob\") &&\n              !code.includes(\"createWorkflow\") &&\n              !hasStartCall(code)\n            ) {\n              return null;\n            }\n\n            // Only remove other jobs and the default workflow export from the job's\n            // own source file. Dependency files imported by the source file must keep\n            // their exports intact for rolldown to resolve cross-file\n            // imports (e.g. `import workflow from \"./other-workflow\"`).\n            let transformed = code;\n            const isJobSourceFile = safeRealpath(id) === resolvedSourceFile;\n            if (isJobSourceFile) {\n              transformed = transformWorkflowSource(\n                code,\n                job.name,\n                job.exportName,\n                otherJobExportNames,\n              );\n            }\n\n            // Apply workflow.start / job.start transformation.\n            if (hasStartCall(transformed)) {\n              transformed = transformStartCalls(transformed, startContext, id);\n            }\n\n            if (transformed === code) return null;\n            return { code: transformed };\n          },\n        },\n      };\n\n      const plugins: rolldown.Plugin[] = [\n        entry.plugin,\n        transformPlugin,\n        createTsconfigPathsPlugin({ onTsconfigRead: trackDependency, cache: tsconfigCache }),\n        platformBundleDefinePlugin,\n        ...cachePlugins,\n      ];\n\n      const bundleLog = createBundleLog({ tsconfig });\n      const result = await rolldown.build({\n        input: entry.input,\n        write: false,\n        output: {\n          format: \"esm\",\n          sourcemap: inlineSourcemap ? \"inline\" : true,\n          minify: inlineSourcemap\n            ? {\n                mangle: {\n                  keepNames: true,\n                },\n              }\n            : true,\n          codeSplitting: false,\n        },\n        tsconfig,\n        plugins,\n        treeshake: composeFunctionTreeshakeOptions([\n          createLogLevelTreeshakeOptions(bundleLogLevel),\n        ]),\n        ...bundleLog.options,\n      } as rolldown.BuildOptions);\n      bundleLog.assertAllResolved();\n\n      const bundledCode = result.output[0].code;\n      assertNoForbiddenRuntimeGlobals(bundledCode, `Workflow job \"${job.name}\"`);\n      return bundledCode;\n    },\n  });\n\n  return [job.name, code];\n}\n","export const EXECUTION_POLICY_NAME_PATTERN = /^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/;\nexport const EXECUTION_POLICY_NAME_MESSAGE =\n  \"Invalid execution policy name: must match [a-z0-9-] (3-63 chars; must start and end with [a-z0-9])\";\n\nexport const EXECUTION_POLICY_KEY_PATTERN = /^[a-z0-9][a-z0-9_:.-]{0,62}[a-z0-9*]$/;\nexport const EXECUTION_POLICY_KEY_MESSAGE =\n  \"Invalid execution policy key: must match [a-z0-9_:.-] (2-64 chars; must start with [a-z0-9] and end with [a-z0-9] or a trailing '*')\";\nexport const EXECUTION_POLICY_KEY_WILDCARD_MESSAGE =\n  \"key must not end with '*'; omit the '*' and set matchType: \\\"prefix\\\" for wildcard policies (the SDK appends '*' automatically).\";\n\n/** Platform-facing execution policy key: the declared key plus `*` for prefix policies. */\nexport function toPlatformExecutionPolicyKey(key: string, matchType: \"exact\" | \"prefix\"): string {\n  return matchType === \"prefix\" ? `${key}*` : key;\n}\n\nexport const DURATION_UNITS = [\"ms\", \"s\", \"m\"] as const;\n\nconst UNIT_TO_SECONDS: Record<(typeof DURATION_UNITS)[number], number> = {\n  ms: 1 / 1000,\n  s: 1,\n  m: 60,\n};\n\n/**\n * Convert a workflow duration string (`500ms`, `1s`, `1m`) to seconds.\n * @returns The duration in seconds, or null when the string is not a duration.\n */\nexport function durationToSeconds(duration: string): number | null {\n  const match = /^(\\d+)(ms|s|m)$/.exec(duration);\n  if (match?.[1] === undefined || match[2] === undefined) return null;\n  return parseInt(match[1], 10) * UNIT_TO_SECONDS[match[2] as (typeof DURATION_UNITS)[number]];\n}\n\nexport const RETRY_POLICY_LIMITS = {\n  maxRetries: { min: 1, max: 10 },\n  initialBackoffMaxSeconds: 3600,\n  maxBackoffMaxSeconds: 86400,\n  backoffMultiplierMin: 1,\n} as const;\n","import {\n  DURATION_UNITS,\n  durationToSeconds,\n  EXECUTION_POLICY_KEY_MESSAGE,\n  EXECUTION_POLICY_KEY_PATTERN,\n  EXECUTION_POLICY_NAME_MESSAGE,\n  EXECUTION_POLICY_NAME_PATTERN,\n  RETRY_POLICY_LIMITS,\n} from \"@tailor-platform/shared/workflow-policy\";\nimport { z } from \"zod\";\nimport { functionSchema } from \"../common\";\n\nexport const WorkflowJobSchema = z.strictObject({\n  name: z.string().describe(\"Job name (must be unique across the project)\"),\n  start: functionSchema.describe(\"Start function that initiates the job\"),\n  body: functionSchema.describe(\"Job implementation function\"),\n  publishEvents: z\n    .boolean()\n    .optional()\n    .describe(\"Enable publishing job execution events for this job\"),\n});\n\nconst seconds = (duration: string): number => durationToSeconds(duration) ?? 0;\n\nconst baseDurationSchema = z.templateLiteral([z.number().int().positive(), z.enum(DURATION_UNITS)]);\n\nconst durationSchema = (maxSeconds: number) =>\n  baseDurationSchema.refine((val) => seconds(val) <= maxSeconds, {\n    message: `Duration must be at most ${maxSeconds} seconds`,\n  });\n\nexport const RetryPolicySchema = z\n  .strictObject({\n    maxRetries: z\n      .number()\n      .int()\n      .min(RETRY_POLICY_LIMITS.maxRetries.min)\n      .max(RETRY_POLICY_LIMITS.maxRetries.max)\n      .describe(\"Maximum number of retries (1-10)\"),\n    initialBackoff: durationSchema(RETRY_POLICY_LIMITS.initialBackoffMaxSeconds).describe(\n      \"Initial backoff duration (e.g., '1s', '500ms', '1m', max 1h)\",\n    ),\n    maxBackoff: durationSchema(RETRY_POLICY_LIMITS.maxBackoffMaxSeconds).describe(\n      \"Maximum backoff duration (e.g., '30s', '5m', max 24h)\",\n    ),\n    backoffMultiplier: z\n      .number()\n      .min(RETRY_POLICY_LIMITS.backoffMultiplierMin)\n      .describe(\"Backoff multiplier (>= 1)\"),\n  })\n\n  .refine((data) => seconds(data.initialBackoff) <= seconds(data.maxBackoff), {\n    message: \"initialBackoff must be less than or equal to maxBackoff\",\n    path: [\"initialBackoff\"],\n  })\n  .refine((data) => seconds(data.initialBackoff) > 0, {\n    message: \"initialBackoff must be greater than 0\",\n    path: [\"initialBackoff\"],\n  });\n\nexport const ConcurrencyPolicySchema = z.strictObject({\n  maxConcurrentExecutions: z\n    .number()\n    .int()\n    .min(1)\n    .max(1000)\n    .describe(\"Maximum number of concurrent executions (1-1000)\"),\n});\n\nexport const ExecutionPolicyNameSchema = z\n  .string()\n  .regex(EXECUTION_POLICY_NAME_PATTERN, EXECUTION_POLICY_NAME_MESSAGE)\n  .describe(\"Workspace-unique execution policy name embedded in the resource TRN\");\n\nexport const ExecutionPolicyKeySchema = z\n  .string()\n  .regex(EXECUTION_POLICY_KEY_PATTERN, EXECUTION_POLICY_KEY_MESSAGE)\n  .describe(\"Execution policy key passed to execJobFunction's executionPolicyKey option\");\n\nexport const WorkflowJobFunctionExecutionPolicySchema = z.strictObject({\n  name: ExecutionPolicyNameSchema,\n  key: ExecutionPolicyKeySchema,\n  concurrencyPolicy: ConcurrencyPolicySchema.optional().describe(\n    \"Optional per-key concurrency cap for job function dispatches matching this policy\",\n  ),\n});\n\nexport const WorkflowSchema = z.strictObject({\n  name: z.string().describe(\"Workflow name\"),\n  mainJob: WorkflowJobSchema.describe(\"Main job that starts the workflow\"),\n  retryPolicy: RetryPolicySchema.optional().describe(\"Retry policy for the workflow\"),\n  concurrencyPolicy: ConcurrencyPolicySchema.optional().describe(\n    \"Concurrency policy for the workflow\",\n  ),\n  publishEvents: z\n    .boolean()\n    .optional()\n    .describe(\"Enable publishing workflow execution events for this workflow\"),\n});\n","import * as path from \"pathe\";\nimport { loadFilesWithIgnores } from \"#/cli/services/file-loader\";\nimport { logger, styles } from \"#/cli/shared/logger\";\nimport { importUserModule } from \"#/cli/shared/user-modules\";\nimport { WorkflowJobSchema, WorkflowSchema } from \"#/parser/service/workflow/index\";\nimport { isSdkBranded } from \"#/utils/brand\";\nimport type { WorkflowServiceConfig } from \"#/configure/config/types\";\nimport type { Workflow } from \"#/types/workflow.generated\";\n\nexport interface CollectedJob {\n  name: string;\n  exportName: string;\n  sourceFile: string;\n  /** Explicit `publishEvents` from `createWorkflowJob`, when the job set one. */\n  publishEvents?: boolean;\n}\n\nfunction stripRuntimeStart(workflow: unknown): unknown {\n  if (\n    !isSdkBranded(workflow, \"workflow\") ||\n    workflow === null ||\n    typeof workflow !== \"object\" ||\n    !(\"start\" in workflow)\n  ) {\n    return workflow;\n  }\n  const { start: _start, ...rest } = workflow as Record<string, unknown>;\n  return rest;\n}\n\ninterface WorkflowLoadResult {\n  workflows: Record<string, Workflow>;\n  workflowSources: Array<{ workflow: Workflow; sourceFile: string }>;\n  jobs: CollectedJob[];\n  fileCount: number;\n}\n\nexport type WorkflowService = {\n  readonly config: WorkflowServiceConfig;\n  readonly workflows: Record<string, Workflow>;\n  readonly workflowSources: ReadonlyArray<{ workflow: Workflow; sourceFile: string }>;\n  readonly jobs: CollectedJob[];\n  readonly fileCount: number;\n  loadWorkflows: () => Promise<void>;\n  printLoadedWorkflows: () => void;\n};\n\n/**\n * Parameters for creating a WorkflowService\n */\nexport interface CreateWorkflowServiceParams {\n  /** The workflow service configuration */\n  config: WorkflowServiceConfig;\n  /** Directory the config's file patterns are resolved against */\n  baseDir: string;\n}\n\n/**\n * Creates a new WorkflowService instance.\n * @param params - Parameters for creating the service\n * @returns A new WorkflowService instance\n */\nexport function createWorkflowService(params: CreateWorkflowServiceParams): WorkflowService {\n  const { config, baseDir } = params;\n  let workflows: Record<string, Workflow> = {};\n  let workflowSources: Array<{ workflow: Workflow; sourceFile: string }> = [];\n  let jobs: CollectedJob[] = [];\n  let fileCount = 0;\n  let loaded = false;\n\n  return {\n    config,\n    get workflows() {\n      return workflows;\n    },\n    get workflowSources() {\n      return workflowSources;\n    },\n    get jobs() {\n      return jobs;\n    },\n    get fileCount() {\n      return fileCount;\n    },\n    loadWorkflows: async () => {\n      if (loaded) {\n        return;\n      }\n      const result = await loadAndCollectJobs(config, baseDir);\n      workflows = result.workflows;\n      workflowSources = result.workflowSources;\n      jobs = result.jobs;\n      fileCount = result.fileCount;\n      loaded = true;\n    },\n    printLoadedWorkflows: () => {\n      if (fileCount === 0) {\n        return;\n      }\n      logger.newline();\n      logger.log(`Found ${styles.highlight(fileCount.toString())} workflow files`);\n      for (const { workflow, sourceFile } of workflowSources) {\n        const relativePath = path.relative(process.cwd(), sourceFile);\n        logger.debug(\n          `Workflow: ${styles.successBright(`\"${workflow.name}\"`)} loaded from ${styles.path(relativePath)}`,\n        );\n      }\n    },\n  };\n}\n\n/**\n * Load workflow files and collect all jobs in a single pass.\n * Dependencies are detected at bundle time via AST analysis.\n * @param config - Workflow service configuration\n * @param baseDir - Directory the config's file patterns are resolved against\n * @returns Loaded workflows and collected jobs\n */\nasync function loadAndCollectJobs(\n  config: WorkflowServiceConfig,\n  baseDir: string,\n): Promise<WorkflowLoadResult> {\n  const workflows: Record<string, Workflow> = {};\n  const workflowSources: Array<{ workflow: Workflow; sourceFile: string }> = [];\n  const collectedJobs: CollectedJob[] = [];\n\n  if (config.files.length === 0) {\n    return {\n      workflows,\n      workflowSources,\n      jobs: collectedJobs,\n      fileCount: 0,\n    };\n  }\n\n  const workflowFiles = loadFilesWithIgnores(config, baseDir);\n  const fileCount = workflowFiles.length;\n\n  // Maps for collecting data\n  const allJobsMap = new Map<string, CollectedJob>();\n\n  // Load all files in parallel and collect jobs and workflows\n  const loadResults = await Promise.all(\n    workflowFiles.map(async (workflowFile) => {\n      const { jobs, workflow } = await loadFileContent(workflowFile);\n      return { workflowFile, jobs, workflow };\n    }),\n  );\n\n  for (const { workflowFile, jobs, workflow } of loadResults) {\n    if (workflow) {\n      workflowSources.push({ workflow, sourceFile: workflowFile });\n      workflows[workflowFile] = workflow;\n    }\n\n    for (const job of jobs) {\n      const existing = allJobsMap.get(job.name);\n      if (existing) {\n        throw new Error(\n          `Duplicate job name \"${job.name}\" found:\\n` +\n            `  - ${existing.sourceFile} (export: ${existing.exportName})\\n` +\n            `  - ${job.sourceFile} (export: ${job.exportName})\\n` +\n            `Each job must have a unique name.`,\n        );\n      }\n      allJobsMap.set(job.name, job);\n      collectedJobs.push(job);\n    }\n  }\n\n  return {\n    workflows,\n    workflowSources,\n    jobs: collectedJobs,\n    fileCount,\n  };\n}\n\n/**\n * Load a single file and extract jobs and workflow\n * @param filePath - Path to the workflow file\n * @returns Extracted jobs and workflow\n */\nasync function loadFileContent(filePath: string): Promise<{\n  jobs: CollectedJob[];\n  workflow: Workflow | null;\n}> {\n  const jobs: CollectedJob[] = [];\n  let workflow: Workflow | null = null;\n\n  try {\n    const module = await importUserModule(filePath);\n\n    for (const [exportName, exportValue] of Object.entries(module)) {\n      // Check if it's a workflow (default export)\n      if (exportName === \"default\") {\n        const workflowResult = WorkflowSchema.safeParse(stripRuntimeStart(exportValue));\n        if (workflowResult.success) {\n          workflow = workflowResult.data;\n        } else if (isSdkBranded(exportValue, [\"workflow\", \"workflow-job\"])) {\n          throw workflowResult.error;\n        }\n        continue;\n      }\n\n      const jobResult = WorkflowJobSchema.safeParse(exportValue);\n      if (jobResult.success) {\n        jobs.push({\n          name: jobResult.data.name,\n          exportName,\n          sourceFile: filePath,\n          ...(jobResult.data.publishEvents !== undefined\n            ? { publishEvents: jobResult.data.publishEvents }\n            : {}),\n        });\n      } else if (isSdkBranded(exportValue, [\"workflow\", \"workflow-job\"])) {\n        throw jobResult.error;\n      }\n    }\n  } catch (error) {\n    const relativePath = path.relative(process.cwd(), filePath);\n    logger.error(\n      `${styles.error(\"Failed to load workflow from\")} ${styles.errorBright(relativePath)}`,\n    );\n    logger.error(String(error));\n    throw error;\n  }\n\n  return { jobs, workflow };\n}\n","import type { AppConfig } from \"#/configure/config/types\";\n\ntype AuthNamespaceApplication = {\n  authService?: { config: { name: string } };\n  config?: Pick<AppConfig, \"auth\">;\n};\n\n/**\n * Resolve the auth namespace configured for an application.\n * @param application - Loaded application with local or external Auth config\n * @returns Auth namespace, or undefined when no Auth config is present\n */\nexport function getApplicationAuthNamespace(\n  application: AuthNamespaceApplication,\n): string | undefined {\n  return application.authService?.config.name ?? application.config?.auth?.name;\n}\n\n/**\n * Resolve the auth namespace configured for an application, throwing when none is configured.\n * @param application - Loaded application with local or external Auth config\n * @returns Auth namespace\n */\nexport function requireApplicationAuthNamespace(application: AuthNamespaceApplication): string {\n  const authNamespace = getApplicationAuthNamespace(application);\n  if (!authNamespace) {\n    throw new Error(\"No Auth service configured\");\n  }\n  return authNamespace;\n}\n","let distPath: string | null = null;\n\nexport const getDistDir = (): string => {\n  const configured = process.env.TAILOR_BUILD_OUTPUT_DIR;\n  if (configured && configured !== distPath) {\n    distPath = configured;\n  } else if (distPath === null) {\n    distPath = configured || \".tailor\";\n  }\n  return distPath;\n};\n","import { parseBoolean } from \"./parse-boolean\";\n\n/**\n * Resolve whether inline sourcemaps should be enabled.\n *\n * Resolution order:\n * 1. Config value (`inlineSourcemap` in defineConfig) — if explicitly set\n * 2. Environment variable `TAILOR_INLINE_SOURCEMAP` — if explicitly set\n * 3. Default: `true`\n * @param configValue - The `inlineSourcemap` value from AppConfig\n * @returns Whether inline sourcemaps should be enabled\n */\nexport function resolveInlineSourcemap(configValue?: boolean): boolean {\n  if (configValue !== undefined) return configValue;\n  const envValue = parseBoolean(process.env.TAILOR_INLINE_SOURCEMAP);\n  if (envValue !== undefined) return envValue;\n  return true;\n}\n","export function resolverBundleKey(namespace: string, resolverName: string): string {\n  return `${namespace}:${resolverName}`;\n}\n","import { z } from \"zod\";\n\nconst NAME_PATTERN = /^[a-z0-9][a-z0-9-]{1,28}[a-z0-9]$/;\nconst AUTH_NAMESPACE_PATTERN = /^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/;\n\n// strip unknown keys\nexport const AIGatewaySchema = z.strictObject({\n  name: z\n    .string()\n    .regex(NAME_PATTERN, \"Must be 3-30 lowercase alphanumeric characters or hyphens\")\n    .describe(\"AI Gateway name\"),\n  authNamespace: z\n    .string()\n    .regex(AUTH_NAMESPACE_PATTERN, \"Must be 3-63 lowercase alphanumeric characters or hyphens\")\n    .optional()\n    .describe(\n      \"Auth namespace used to resolve request tokens against the workspace's auth. Defaults to the application's own auth service when omitted; omitting it without an Auth service configured is rejected.\",\n    ),\n  cors: z\n    .array(z.string())\n    .optional()\n    .describe(\n      \"Allowed CORS origins for browser-based clients. Each entry is `*`, `http(s)://*`, `http(s)://*.example.com`, or `http(s)://app.example.com`, optionally with `:port`. Empty list disables cross-origin access.\",\n    ),\n});\n","/**\n * The `allowedEmailDomains` entry that permits every email domain. It has to be\n * the only entry in the list.\n */\nexport const ALL_EMAIL_DOMAINS = \"*\";\n\n/**\n * A single `allowedEmailDomains` entry: a hostname, or {@link ALL_EMAIL_DOMAINS}.\n *\n * Two forms the platform accepts are rejected here, because each stores an entry\n * that can never match: surrounding whitespace, which the platform trims and then\n * echoes back normalized as a permanent diff in every later plan, and a trailing\n * dot, which a domain taken from an email address never carries. Elsewhere this\n * is looser than the platform's own check, so nothing else it accepts is rejected\n * here.\n */\nexport const allowedEmailDomainPattern =\n  /^(\\*|[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/;\n\n/**\n * Whether the list carries the all-domains entry.\n *\n * Trimming mirrors the platform, which trims before comparing, so a padded\n * entry cannot slip past the exclusivity check here either.\n * @param domains - Raw `allowedEmailDomains` entries\n * @returns Whether any entry is the all-domains entry\n */\nexport function containsAllEmailDomains(domains: readonly string[]): boolean {\n  return domains.some((domain) => domain.trim() === ALL_EMAIL_DOMAINS);\n}\n\ntype EmailDomainPolicy = {\n  useNonEmailIdentifier?: boolean | undefined;\n  allowedEmailDomains?: readonly string[] | undefined;\n};\n\n/**\n * Whether a policy leaves the accepted email domains implicit.\n *\n * An empty or omitted `allowedEmailDomains` currently means \"every domain\", but\n * the platform is moving that meaning behind an explicit `[\"*\"]`, so the CLI\n * warns about such policies to nudge authors into declaring their intent while\n * both forms still work. Namespaces with `useNonEmailIdentifier` never reach\n * domain validation and cannot set the field at all, so they are not affected.\n * @param policy - The IdP user auth policy from user config\n * @returns Whether the CLI should warn about an implicit all-domains state\n */\nexport function hasImplicitAllEmailDomains(policy: EmailDomainPolicy | undefined): boolean {\n  if (policy?.useNonEmailIdentifier === true) {\n    return false;\n  }\n  return !policy?.allowedEmailDomains || policy.allowedEmailDomains.length === 0;\n}\n","import { z } from \"zod\";\nimport {\n  ALL_EMAIL_DOMAINS,\n  allowedEmailDomainPattern,\n  containsAllEmailDomains,\n} from \"#/parser/service/idp/email-domains\";\n\n/**\n * Normalize IdPGqlOperationsConfig (alias or object) to IdPGqlOperations object.\n * \"query\" alias expands to read-only mode: every mutation is disabled while\n * queries (`read`, `requestMfaSettingsUrl`) stay enabled.\n * @param config - The config to normalize\n * @returns The normalized IdPGqlOperations object\n */\nfunction normalizeIdPGqlOperations(\n  config:\n    | \"query\"\n    | {\n        create?: boolean;\n        update?: boolean;\n        delete?: boolean;\n        read?: boolean;\n        sendPasswordResetEmail?: boolean;\n        requestMfaSettingsUrl?: boolean;\n        unenrollMfa?: boolean;\n      },\n) {\n  if (config === \"query\") {\n    return {\n      create: false,\n      update: false,\n      delete: false,\n      read: true,\n      sendPasswordResetEmail: false,\n      requestMfaSettingsUrl: true,\n      unenrollMfa: false,\n    };\n  }\n  return config;\n}\n\n/**\n * Zod schema for IdPGqlOperations configuration with normalization transform.\n * Accepts \"query\" alias or detailed object, normalizes to IdPGqlOperations object.\n */\nexport const IdPGqlOperationsSchema = z\n  .union([\n    z.literal(\"query\"),\n    z.strictObject({\n      create: z.boolean().optional().describe(\"Enable _createUser mutation (default: true)\"),\n      update: z.boolean().optional().describe(\"Enable _updateUser mutation (default: true)\"),\n      delete: z.boolean().optional().describe(\"Enable _deleteUser mutation (default: true)\"),\n      read: z.boolean().optional().describe(\"Enable _users and _user queries (default: true)\"),\n      sendPasswordResetEmail: z\n        .boolean()\n        .optional()\n        .describe(\"Enable _sendPasswordResetEmail mutation (default: true)\"),\n      requestMfaSettingsUrl: z\n        .boolean()\n        .optional()\n        .describe(\"Enable _requestMfaSettingsUrl query (default: true)\"),\n      unenrollMfa: z.boolean().optional().describe(\"Enable _unenrollMfa mutation (default: true)\"),\n    }),\n  ])\n  .describe(\n    \"Configuration for GraphQL operations on IdP users.\\nAll operations are enabled by default (undefined or true = enabled, false = disabled).\",\n  )\n  .transform((val) => normalizeIdPGqlOperations(val));\n\nexport const IdPLangSchema = z.enum([\"en\", \"ja\"]).describe(\"IdP UI language\");\n\n// Origins are either a literal http(s) origin (scheme + host + optional port,\n// no path/query/fragment) or a static-website `<name>:url` placeholder that\n// the CLI resolves to a real origin at apply time. The placeholder branch\n// uses the same slug rule as the platform's static-website name validator so\n// typos like `https://app.example.com:url` are rejected instead of being\n// silently interpreted as a website name at apply time.\nconst allowedReturnOriginPattern =\n  /^(https?:\\/\\/[a-zA-Z0-9.-]+(:[0-9]+)?|[a-z0-9][a-z0-9-]{1,61}[a-z0-9]:url)$/;\n\nexport const IdPUserAuthPolicySchema = z\n  .strictObject({\n    useNonEmailIdentifier: z\n      .boolean()\n      .optional()\n      .describe(\"Use non-email identifier for usernames\"),\n    allowSelfPasswordReset: z\n      .boolean()\n      .optional()\n      .describe(\"Allow users to reset their own passwords\"),\n    passwordRequireUppercase: z\n      .boolean()\n      .optional()\n      .describe(\"Require uppercase letters in passwords\"),\n    passwordRequireLowercase: z\n      .boolean()\n      .optional()\n      .describe(\"Require lowercase letters in passwords\"),\n    passwordRequireNonAlphanumeric: z\n      .boolean()\n      .optional()\n      .describe(\"Require non-alphanumeric characters in passwords\"),\n    passwordRequireNumeric: z\n      .boolean()\n      .optional()\n      .describe(\"Require numeric characters in passwords\"),\n    passwordMinLength: z\n      .number()\n      .int()\n      .refine((val) => val >= 6 && val <= 30, {\n        message: \"passwordMinLength must be between 6 and 30\",\n      })\n      .optional()\n      .describe(\"Minimum password length (6-30)\"),\n    passwordMaxLength: z\n      .number()\n      .int()\n      .refine((val) => val >= 6 && val <= 4096, {\n        message: \"passwordMaxLength must be between 6 and 4096\",\n      })\n      .optional()\n      .describe(\"Maximum password length (6-4096)\"),\n    allowedEmailDomains: z\n      .array(\n        z\n          .string()\n          .regex(\n            allowedEmailDomainPattern,\n            `must be a hostname, or ${ALL_EMAIL_DOMAINS} to allow all email domains`,\n          ),\n      )\n      .max(100, \"allowedEmailDomains accepts at most 100 entries\")\n      .refine((domains) => new Set(domains.map((d) => d.toLowerCase())).size === domains.length, {\n        message: \"allowedEmailDomains entries must be unique, compared case-insensitively\",\n      })\n      .refine((domains) => domains.length <= 1 || !containsAllEmailDomains(domains), {\n        message: `allowedEmailDomains cannot contain other entries when ${ALL_EMAIL_DOMAINS} is set`,\n      })\n      .optional()\n      .describe(\n        `Restrict registration to these email domains. A lone ${ALL_EMAIL_DOMAINS} entry allows every domain`,\n      ),\n    allowGoogleOauth: z.boolean().optional().describe(\"Enable Google OAuth login\"),\n    allowMicrosoftOauth: z.boolean().optional().describe(\"Enable Microsoft OAuth login\"),\n    disablePasswordAuth: z.boolean().optional().describe(\"Disable password-based authentication\"),\n    enableMfa: z\n      .boolean()\n      .optional()\n      .describe(\"Make TOTP MFA available for users in this namespace\"),\n    requireMfa: z\n      .boolean()\n      .optional()\n      .describe(\n        \"Require TOTP MFA enrollment and challenge for password-authenticated users (requires enableMfa)\",\n      ),\n    allowedReturnOrigins: z\n      .array(\n        z\n          .string()\n          .regex(\n            allowedReturnOriginPattern,\n            'must be an http(s) origin like \"https://app.example.com\" (scheme + host + optional port, no path/query/fragment) or a static-website placeholder like \"<name>:url\"',\n          ),\n      )\n      .optional()\n      .describe(\n        \"Application origins (scheme + host + optional port) allowed as MFA self-service return targets\",\n      ),\n    mfaIssuer: z\n      .string()\n      .max(64, \"mfaIssuer must be 64 characters or less\")\n      .optional()\n      .describe(\"Label shown next to the user account in authenticator apps\"),\n  })\n\n  .refine(\n    (data) =>\n      data.passwordMinLength === undefined ||\n      data.passwordMaxLength === undefined ||\n      data.passwordMinLength <= data.passwordMaxLength,\n    {\n      message: \"passwordMinLength must be less than or equal to passwordMaxLength\",\n      path: [\"passwordMinLength\"],\n    },\n  )\n  .refine(\n    (data) =>\n      !data.allowedEmailDomains ||\n      data.allowedEmailDomains.length === 0 ||\n      !data.useNonEmailIdentifier,\n    {\n      message: \"allowedEmailDomains cannot be set when useNonEmailIdentifier is true\",\n      path: [\"allowedEmailDomains\"],\n    },\n  )\n  .refine(\n    (data) =>\n      data.allowGoogleOauth === undefined ||\n      data.allowGoogleOauth === false ||\n      !data.useNonEmailIdentifier,\n    {\n      message: \"allowGoogleOauth cannot be set when useNonEmailIdentifier is true\",\n      path: [\"allowGoogleOauth\"],\n    },\n  )\n  .refine(\n    (data) =>\n      !data.allowGoogleOauth || (data.allowedEmailDomains && data.allowedEmailDomains.length > 0),\n    {\n      message: `allowGoogleOauth requires a non-empty allowedEmailDomains ([\"${ALL_EMAIL_DOMAINS}\"] to allow every domain)`,\n      path: [\"allowGoogleOauth\"],\n    },\n  )\n  .refine((data) => !data.allowMicrosoftOauth || !data.useNonEmailIdentifier, {\n    message: \"allowMicrosoftOauth cannot be set when useNonEmailIdentifier is true\",\n    path: [\"allowMicrosoftOauth\"],\n  })\n  .refine(\n    (data) =>\n      !data.allowMicrosoftOauth ||\n      (data.allowedEmailDomains && data.allowedEmailDomains.length > 0),\n    {\n      message: `allowMicrosoftOauth requires a non-empty allowedEmailDomains ([\"${ALL_EMAIL_DOMAINS}\"] to allow every domain)`,\n      path: [\"allowMicrosoftOauth\"],\n    },\n  )\n  .refine((data) => !data.allowMicrosoftOauth || data.disablePasswordAuth === true, {\n    message: \"allowMicrosoftOauth requires disablePasswordAuth to be enabled\",\n    path: [\"allowMicrosoftOauth\"],\n  })\n  .refine(\n    (data) =>\n      !data.disablePasswordAuth ||\n      data.allowGoogleOauth === true ||\n      data.allowMicrosoftOauth === true,\n    {\n      message: \"disablePasswordAuth requires allowGoogleOauth or allowMicrosoftOauth to be enabled\",\n      path: [\"disablePasswordAuth\"],\n    },\n  )\n  .refine((data) => !data.disablePasswordAuth || !data.allowSelfPasswordReset, {\n    message: \"disablePasswordAuth cannot be used with allowSelfPasswordReset\",\n    path: [\"disablePasswordAuth\"],\n  })\n  .refine((data) => !data.requireMfa || data.enableMfa === true, {\n    message: \"requireMfa requires enableMfa to be enabled\",\n    path: [\"requireMfa\"],\n  })\n  .refine(\n    (data) =>\n      !data.enableMfa || (data.allowedReturnOrigins && data.allowedReturnOrigins.length > 0),\n    {\n      message:\n        \"enableMfa requires allowedReturnOrigins to list at least one origin so MFA self-service has a valid return target\",\n      path: [\"enableMfa\"],\n    },\n  );\n\nconst emailFieldSchema = z\n  .string()\n  .max(200, \"must be 200 characters or less\")\n  .regex(/^[^\\r\\n]*$/, \"must not contain newline characters\");\n\nexport const IdPEmailConfigSchema = z\n  .strictObject({\n    fromName: emailFieldSchema.optional().describe(\"Default sender display name for emails\"),\n    passwordResetSubject: emailFieldSchema\n      .optional()\n      .describe(\"Default subject for password reset emails\"),\n  })\n\n  .describe(\"Namespace-level email configuration defaults\");\n\nconst IdPPermissionOperandSchema = z.union([\n  z.string(),\n  z.boolean(),\n  z.array(z.string()).readonly(),\n  z.array(z.boolean()).readonly(),\n  z.strictObject({ user: z.string() }),\n  z.strictObject({ idpUser: z.enum([\"id\", \"name\", \"disabled\"]) }),\n  z.strictObject({ oldIdpUser: z.enum([\"id\", \"name\", \"disabled\"]) }),\n  z.strictObject({ newIdpUser: z.enum([\"id\", \"name\", \"disabled\"]) }),\n]);\n\nconst IdPPermissionOperatorSchema = z.enum([\"=\", \"!=\", \"in\", \"not in\"]);\n\nconst IdPPermissionConditionSchema = z\n  .tuple([IdPPermissionOperandSchema, IdPPermissionOperatorSchema, IdPPermissionOperandSchema])\n  .readonly();\n\nconst IdPActionPermissionSchema = z.union([\n  // Object format: { conditions, description?, permit? }\n  z.strictObject({\n    conditions: z.union([\n      IdPPermissionConditionSchema,\n      z.array(IdPPermissionConditionSchema).readonly(),\n    ]),\n    description: z.string().optional(),\n    permit: z.boolean().optional(),\n  }),\n  // Single condition tuple: [operand, operator, operand]\n  z\n    .tuple([IdPPermissionOperandSchema, IdPPermissionOperatorSchema, IdPPermissionOperandSchema])\n    .readonly(),\n  // Single condition tuple with permit: [operand, operator, operand, permit]\n  z\n    .tuple([\n      IdPPermissionOperandSchema,\n      IdPPermissionOperatorSchema,\n      IdPPermissionOperandSchema,\n      z.boolean(),\n    ])\n    .readonly(),\n  // Multiple conditions with optional trailing permit\n  z\n    .array(z.union([IdPPermissionConditionSchema, z.boolean()]))\n    .refine(\n      (arr) => {\n        const boolIndex = arr.findIndex((item) => typeof item === \"boolean\");\n        return boolIndex === -1 || boolIndex === arr.length - 1;\n      },\n      { message: \"Boolean permit flag must only appear at the end\" },\n    )\n    .readonly(),\n]);\n\nexport const IdPPermissionSchema = z\n  .strictObject({\n    create: z.array(IdPActionPermissionSchema).readonly(),\n    read: z.array(IdPActionPermissionSchema).readonly(),\n    update: z.array(IdPActionPermissionSchema).readonly(),\n    delete: z.array(IdPActionPermissionSchema).readonly(),\n    sendPasswordResetEmail: z.array(IdPActionPermissionSchema).readonly().optional(),\n    unenrollMfa: z.array(IdPActionPermissionSchema).readonly().optional(),\n  })\n\n  .describe(\"Per-operation permission policies for IdP users\");\n\nexport const IdPSchema = z\n  .strictObject({\n    name: z.string().describe(\"IdP service name\"),\n    authorization: z\n      .union([z.literal(\"insecure\"), z.literal(\"loggedIn\"), z.strictObject({ cel: z.string() })])\n      .optional()\n      .describe(\"Authorization mode for IdP API access\"),\n    clients: z.array(z.string()).describe(\"OAuth2 client names that can use this IdP\"),\n    lang: IdPLangSchema.optional().describe(\"UI language for IdP pages\"),\n    userAuthPolicy: IdPUserAuthPolicySchema.transform((input) =>\n      // transform input may be undefined before schema parse\n      // oxlint-disable-next-line typescript/no-unnecessary-condition\n      IdPUserAuthPolicySchema.parse(input ?? {}),\n    )\n      .optional()\n      .describe(\"User authentication policy configuration\"),\n    publishEvents: z.boolean().optional().describe(\"Enable publishing user lifecycle events\"),\n    gqlOperations: IdPGqlOperationsSchema.optional().describe(\n      \"Configure which GraphQL operations are enabled\",\n    ),\n    emailConfig: IdPEmailConfigSchema.optional().describe(\n      \"Namespace-level email configuration defaults\",\n    ),\n    permission: IdPPermissionSchema.optional().describe(\n      \"Per-operation permission policies for IdP users\",\n    ),\n  })\n\n  .refine(\n    (data) =>\n      !data.userAuthPolicy?.enableMfa ||\n      data.gqlOperations?.unenrollMfa === false ||\n      (data.permission !== undefined && data.permission.unenrollMfa !== undefined),\n    {\n      message:\n        \"permission.unenrollMfa must be set explicitly when userAuthPolicy.enableMfa is true (set [{ conditions: [...], permit: true }] to allow, or [] to deny all). permission itself must also be defined. The requirement is only relaxed when gqlOperations.unenrollMfa is false.\",\n      path: [\"permission\", \"unenrollMfa\"],\n    },\n  )\n  .refine(\n    (data) =>\n      !data.permission ||\n      data.userAuthPolicy?.disablePasswordAuth === true ||\n      data.gqlOperations?.sendPasswordResetEmail === false ||\n      data.permission.sendPasswordResetEmail !== undefined,\n    {\n      message:\n        \"permission.sendPasswordResetEmail must be set explicitly when password authentication is enabled (set [{ conditions: [...], permit: true }] to allow, or [] to deny; only optional when userAuthPolicy.disablePasswordAuth is true or gqlOperations.sendPasswordResetEmail is false)\",\n      path: [\"permission\", \"sendPasswordResetEmail\"],\n    },\n  );\n","import { z } from \"zod\";\n\nconst namePattern = /^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/;\nconst nameSchema = z.string().regex(namePattern);\n\nconst secretsVaultSchema = z.record(nameSchema, z.string().nullish());\nexport const SecretsSchema = z.strictObject({\n  vaults: z.record(nameSchema, secretsVaultSchema),\n  options: z.strictObject({\n    ignoreNullishValues: z.boolean(),\n  }),\n});\n","import { z } from \"zod\";\n\n// strip unknown keys\nexport const StaticWebsiteSchema = z.strictObject({\n  name: z.string().describe(\"Static website name\"),\n  description: z.string().optional().describe(\"Static website description\"),\n  allowedIpAddresses: z\n    .array(z.string())\n    .optional()\n    .describe(\"IP addresses allowed to access the website\"),\n  customDomains: z.array(z.string()).optional().describe(\"Custom domains for the static website\"),\n});\n","import {\n  WAIT_POINT_KEY_GRAMMAR as KEY_GRAMMAR,\n  WAIT_POINT_KEY_MAX_LENGTH as MAX_KEY_LENGTH,\n  WAIT_POINT_KEY_REGEX as KEY_REGEX,\n  isWaitPointParamSegment,\n} from \"#/utils/wait-point-key-grammar\";\nimport type { RegisteredWaitPoint } from \"#/utils/wait-point-registry\";\n\nconst LITERAL_SEGMENT_REGEX = /^[a-z0-9]+$/;\nconst PARAM_NAME_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * Check one declared wait point key against the key rules.\n *\n * The declaration matters: only `createWaitPoints`' `define` receives the key\n * before the type arguments, so only there can TypeScript read the `$params`\n * off the key literal.\n * @param waitPoint - A key as declared, with the declaration it came from\n * @returns The rule the key breaks, or undefined when the key is usable\n */\nexport function checkWaitPointKey(waitPoint: RegisteredWaitPoint): string | undefined {\n  const { key, declaredBy } = waitPoint;\n  const segments = key.split(\"-\");\n  // Excluding bare \"$\" matters here: otherwise a key carrying one would be\n  // answered with advice about typing its $params.\n  const paramSegments = segments.filter(isWaitPointParamSegment);\n\n  if (paramSegments.length > 0 && declaredBy !== \"define\") {\n    return declaredBy === \"property\"\n      ? `Invalid wait point key \"${key}\": $params cannot come from a property name. Pass the key to define instead, e.g. define.for(\"${key}\")<Payload, Result>().`\n      : `Invalid wait point key \"${key}\": createWaitPoint takes its type arguments first, which stops TypeScript inferring the key as a literal, so it cannot type the $params. Declare it through createWaitPoints instead: createWaitPoints((define) => ({ myWaitPoint: define.for(\"${key}\")<Payload, Result>() })).`;\n  }\n\n  const seen = new Set<string>();\n  let literals = 0;\n\n  for (const segment of segments) {\n    if (segment.startsWith(\"$\")) {\n      const name = segment.slice(1);\n      if (!PARAM_NAME_REGEX.test(name)) {\n        return `Invalid wait point key \"${key}\": \"${segment}\" is not a usable parameter name. Use letters, digits and underscores, starting with a letter or underscore.`;\n      }\n      if (seen.has(name)) {\n        return `Invalid wait point key \"${key}\": parameter \"$${name}\" appears more than once.`;\n      }\n      seen.add(name);\n      continue;\n    }\n    // An empty segment comes from a run of hyphens, which the key grammar allows\n    // inside a key. Leave the placement rules to the whole-key checks below.\n    if (segment === \"\") continue;\n    if (!LITERAL_SEGMENT_REGEX.test(segment)) {\n      return `Invalid wait point key \"${key}\": segment \"${segment}\" may only contain [a-z0-9]. Wait point keys accept ${KEY_GRAMMAR}, with $params standing in for runtime values.`;\n    }\n    literals += 1;\n  }\n\n  // Only a key that actually carries $params can be identity-less in this\n  // sense; without them, an empty run of segments is a plain grammar failure.\n  if (literals === 0 && paramSegments.length > 0) {\n    // A key that also sits outside the grammar needs to hear that first:\n    // adding the literal this message asks for would leave \"-$id\" broken.\n    return key.startsWith(\"-\") || key.endsWith(\"-\")\n      ? `Invalid wait point key \"${key}\": must match ${KEY_GRAMMAR}.`\n      : `Invalid wait point key \"${key}\": it needs at least one literal segment alongside its $params, otherwise the key carries no identity of its own and can collide with an unrelated wait point.`;\n  }\n\n  if (paramSegments.length === 0) {\n    return KEY_REGEX.test(key)\n      ? undefined\n      : `Invalid wait point key \"${key}\": must match ${KEY_GRAMMAR}.`;\n  }\n\n  // Every param value is itself `[a-z0-9]`-bounded, so the shortest instance of\n  // the pattern is valid exactly when every instance is.\n  const shortest = segments.map((segment) => (segment.startsWith(\"$\") ? \"0\" : segment)).join(\"-\");\n  if (shortest.length > MAX_KEY_LENGTH) {\n    return `Wait point key \"${key}\" cannot fit in ${MAX_KEY_LENGTH} characters: even single-character parameter values produce ${shortest.length}.`;\n  }\n  return KEY_REGEX.test(shortest)\n    ? undefined\n    : `Invalid wait point key \"${key}\": must match ${KEY_GRAMMAR}.`;\n}\n\n/**\n * Check every declared wait point key, reporting each broken rule once.\n * @param waitPoints - The keys declared across the project, as registered\n * @returns One message per distinct declaration that breaks a rule\n */\nexport function collectWaitPointKeyFailures(waitPoints: readonly RegisteredWaitPoint[]): string[] {\n  const failures: string[] = [];\n  // The declaration is half of what makes a key valid, so the same key\n  // declared two ways is two things to check, not one.\n  const seen = new Set<string>();\n  for (const waitPoint of waitPoints) {\n    const identity = `${waitPoint.declaredBy} ${waitPoint.key}`;\n    if (seen.has(identity)) continue;\n    seen.add(identity);\n    const failure = checkWaitPointKey(waitPoint);\n    if (failure) failures.push(failure);\n  }\n  return failures;\n}\n","import * as path from \"pathe\";\nimport { generatePluginExecutorFiles } from \"#/cli/commands/generate/plugin-executor-generator\";\nimport { generatePluginTableFiles } from \"#/cli/commands/generate/plugin-table-generator\";\nimport { bundleAuthHooks } from \"#/cli/services/auth/bundler\";\nimport { createAuthService, type AuthService } from \"#/cli/services/auth/service\";\nimport { bundleExecutors } from \"#/cli/services/executor/bundler\";\nimport { createExecutorService, type ExecutorService } from \"#/cli/services/executor/service\";\nimport {\n  bundleHttpAdapters,\n  type HttpAdapterBundleResult,\n} from \"#/cli/services/http-adapter/bundler\";\nimport {\n  createHttpAdapterService,\n  type HttpAdapterService,\n} from \"#/cli/services/http-adapter/service\";\nimport { bundleResolvers } from \"#/cli/services/resolver/bundler\";\nimport { createResolverService, type ResolverService } from \"#/cli/services/resolver/service\";\nimport { createTailorDBService, type TailorDBService } from \"#/cli/services/tailordb/service\";\nimport { assertUniqueLocalTailorDBTypeNames } from \"#/cli/services/tailordb/type-name-validation\";\nimport { bundleWorkflowJobs, type BundleWorkflowJobsResult } from \"#/cli/services/workflow/bundler\";\nimport { createWorkflowService, type WorkflowService } from \"#/cli/services/workflow/service\";\nimport { getApplicationAuthNamespace } from \"#/cli/shared/auth-namespace\";\nimport { resolveBundleLogLevel } from \"#/cli/shared/bundle-log-level\";\nimport { type LoadedConfig } from \"#/cli/shared/config-loader\";\nimport { getDistDir } from \"#/cli/shared/dist-dir\";\nimport { resolveInlineSourcemap } from \"#/cli/shared/inline-sourcemap\";\nimport { logger } from \"#/cli/shared/logger\";\nimport { resolverBundleKey } from \"#/cli/shared/resolver-bundle-key\";\nimport { buildStartContext } from \"#/cli/shared/start-context\";\nimport { createTsconfigLookupCache } from \"#/cli/shared/tsconfig-paths-plugin\";\nimport {\n  type AppConfig,\n  type ExecutorServiceInput,\n  type HttpAdapterServiceInput,\n  type ResolverServiceInput,\n  type WorkflowServiceConfig,\n} from \"#/configure/config/types\";\nimport { type AuthConfig } from \"#/configure/services/auth/types\";\nimport { type IdPConfig, type IdPOwnConfig } from \"#/configure/services/idp/types\";\nimport { AIGatewaySchema } from \"#/parser/service/aigateway/index\";\nimport { AuthConfigSchema } from \"#/parser/service/auth/index\";\nimport { IdPSchema } from \"#/parser/service/idp/index\";\nimport { SecretsSchema } from \"#/parser/service/secrets/index\";\nimport { StaticWebsiteSchema } from \"#/parser/service/staticwebsite/index\";\nimport { TailorDBServiceConfigSchema } from \"#/parser/service/tailordb/index\";\nimport { collectWaitPointKeyFailures } from \"#/parser/service/workflow/wait-point-key\";\nimport { getScopedWaitPoints } from \"#/utils/wait-point-registry\";\nimport type { BundleCache } from \"#/cli/cache/bundle-cache\";\nimport type { BundledScripts } from \"#/cli/commands/deploy/function-registry-types\";\nimport type { TailorDBServiceInput } from \"#/configure/services/tailordb/types\";\nimport type { PluginManager } from \"#/plugin/manager\";\nimport type { AIGateway, AIGatewayInput } from \"#/types/aigateway.generated\";\nimport type { IdP } from \"#/types/idp.generated\";\nimport type { StaticWebsite, StaticWebsiteInput } from \"#/types/staticwebsite.generated\";\n\ntype SecretVault = {\n  readonly vaultName: string;\n  readonly secrets: ReadonlyArray<{ name: string; value: string | null | undefined }>;\n};\n\nexport type Application = {\n  readonly name: string;\n  readonly id: string | undefined;\n  readonly config: AppConfig;\n  readonly subgraphs: ReadonlyArray<{ Type: string; Name: string }>;\n  readonly tailorDBServices: ReadonlyArray<TailorDBService>;\n  readonly externalTailorDBNamespaces: ReadonlyArray<string>;\n  readonly resolverServices: ReadonlyArray<ResolverService>;\n  readonly idpServices: ReadonlyArray<IdP>;\n  readonly authService: Readonly<AuthService> | undefined;\n  readonly executorService: Readonly<ExecutorService> | undefined;\n  readonly workflowService: Readonly<WorkflowService> | undefined;\n  readonly httpAdapterService: Readonly<HttpAdapterService> | undefined;\n  readonly staticWebsiteServices: ReadonlyArray<StaticWebsite>;\n  readonly aiGatewayServices: ReadonlyArray<AIGateway>;\n  readonly secrets: ReadonlyArray<SecretVault>;\n  readonly ignoreNullishValues: boolean;\n  readonly env: Readonly<Record<string, string | number | boolean>>;\n  readonly applications: ReadonlyArray<Application>;\n};\n\n/**\n * Result of loading the application\n */\nexport interface LoadApplicationResult {\n  /** Fully initialized application */\n  application: Application;\n  /** Workflow bundling result (if workflows were bundled) */\n  workflowBuildResult?: BundleWorkflowJobsResult;\n  /** HTTP adapter bundling result (if adapters were bundled) */\n  httpAdapterBuildResult?: HttpAdapterBundleResult;\n  /** In-memory bundled scripts organized by kind */\n  bundledScripts: BundledScripts;\n}\n\ntype DefineTailorDBResult = {\n  tailorDBServices: TailorDBService[];\n  externalTailorDBNamespaces: string[];\n  subgraphs: Array<{ Type: string; Name: string }>;\n};\n\nfunction defineTailorDB(\n  config: TailorDBServiceInput | undefined,\n  baseDir: string,\n  pluginManager?: PluginManager,\n): DefineTailorDBResult {\n  const tailorDBServices: TailorDBService[] = [];\n  const externalTailorDBNamespaces: string[] = [];\n  const subgraphs: Array<{ Type: string; Name: string }> = [];\n\n  if (!config) {\n    return { tailorDBServices, externalTailorDBNamespaces, subgraphs };\n  }\n\n  for (const [namespace, serviceConfig] of Object.entries(config)) {\n    if (\"external\" in serviceConfig) {\n      externalTailorDBNamespaces.push(namespace);\n    } else {\n      // Parse config through schema to normalize gqlOperations\n      const parsedConfig = TailorDBServiceConfigSchema.parse(serviceConfig);\n      const tailorDB = createTailorDBService({\n        namespace,\n        config: parsedConfig,\n        pluginManager,\n        baseDir,\n      });\n      tailorDBServices.push(tailorDB);\n    }\n    subgraphs.push({ Type: \"tailordb\", Name: namespace });\n  }\n\n  return { tailorDBServices, externalTailorDBNamespaces, subgraphs };\n}\n\ntype DefineResolverResult = {\n  resolverServices: ResolverService[];\n  subgraphs: Array<{ Type: string; Name: string }>;\n};\n\nfunction defineResolver(\n  config: ResolverServiceInput | undefined,\n  baseDir: string,\n): DefineResolverResult {\n  const resolverServices: ResolverService[] = [];\n  const subgraphs: Array<{ Type: string; Name: string }> = [];\n\n  if (!config) {\n    return { resolverServices, subgraphs };\n  }\n\n  for (const [namespace, serviceConfig] of Object.entries(config)) {\n    if (!(\"external\" in serviceConfig)) {\n      const resolverService = createResolverService(namespace, serviceConfig, baseDir);\n      resolverServices.push(resolverService);\n    }\n    subgraphs.push({ Type: \"pipeline\", Name: namespace });\n  }\n\n  return { resolverServices, subgraphs };\n}\n\ntype DefineIdpResult = {\n  idpServices: IdP[];\n  subgraphs: Array<{ Type: string; Name: string }>;\n};\n\nfunction stripIdpProviderHelper(idpConfig: IdPOwnConfig): IdPOwnConfig {\n  const configWithProvider = idpConfig as IdPOwnConfig & { provider?: unknown };\n  if (typeof configWithProvider.provider !== \"function\") return idpConfig;\n  const { provider: _provider, ...config } = configWithProvider;\n  return config;\n}\n\nfunction defineIdp(config: readonly IdPConfig[] | undefined): DefineIdpResult {\n  const idpServices: IdP[] = [];\n  const subgraphs: Array<{ Type: string; Name: string }> = [];\n\n  if (!config) {\n    return { idpServices, subgraphs };\n  }\n\n  const idpNames = new Set<string>();\n  config.forEach((idpConfig) => {\n    const name = idpConfig.name;\n    if (idpNames.has(name)) {\n      throw new Error(`IdP with name \"${name}\" already defined.`);\n    }\n    idpNames.add(name);\n    if (!(\"external\" in idpConfig)) {\n      const idp = IdPSchema.parse(stripIdpProviderHelper(idpConfig));\n      idpServices.push(idp);\n    }\n    subgraphs.push({ Type: \"idp\", Name: name });\n  });\n\n  return { idpServices, subgraphs };\n}\n\ntype DefineAuthResult = {\n  authService: AuthService | undefined;\n  subgraphs: Array<{ Type: string; Name: string }>;\n};\n\nfunction defineAuth(\n  config: AuthConfig | undefined,\n  tailorDBServices: ReadonlyArray<TailorDBService>,\n  externalTailorDBNamespaces: ReadonlyArray<string>,\n): DefineAuthResult {\n  const subgraphs: Array<{ Type: string; Name: string }> = [];\n\n  if (!config) {\n    return { authService: undefined, subgraphs };\n  }\n\n  let authService: AuthService | undefined;\n  if (!(\"external\" in config)) {\n    authService = createAuthService(\n      AuthConfigSchema.parse(config),\n      tailorDBServices,\n      externalTailorDBNamespaces,\n    );\n  }\n  subgraphs.push({ Type: \"auth\", Name: config.name });\n\n  return { authService, subgraphs };\n}\n\nfunction defineExecutor(\n  config: ExecutorServiceInput | undefined,\n  baseDir: string,\n  hasPluginExecutors: boolean,\n): ExecutorService | undefined {\n  if (!config && !hasPluginExecutors) {\n    return undefined;\n  }\n  return createExecutorService({ config: config ?? { files: [] }, baseDir });\n}\n\nfunction defineWorkflow(\n  config: WorkflowServiceConfig | undefined,\n  baseDir: string,\n): WorkflowService | undefined {\n  if (!config) {\n    return undefined;\n  }\n  return createWorkflowService({ config, baseDir });\n}\n\nfunction defineHttpAdapterService(\n  config: HttpAdapterServiceInput | undefined,\n  baseDir: string,\n): HttpAdapterService | undefined {\n  if (!config) {\n    return undefined;\n  }\n  return createHttpAdapterService({ config, baseDir });\n}\n\nfunction stripStaticWebsiteUrlHelper(config: StaticWebsiteInput): StaticWebsiteInput {\n  const configWithUrl = config as StaticWebsiteInput & { url?: unknown };\n  if (configWithUrl.url !== `${config.name}:url`) return config;\n  const { url: _url, ...websiteConfig } = configWithUrl;\n  return websiteConfig;\n}\n\nfunction defineStaticWebsites(\n  websites: readonly StaticWebsiteInput[] | undefined,\n): StaticWebsite[] {\n  const staticWebsiteServices: StaticWebsite[] = [];\n  const websiteNames = new Set<string>();\n\n  (websites ?? []).forEach((config) => {\n    const website = StaticWebsiteSchema.parse(stripStaticWebsiteUrlHelper(config));\n    if (websiteNames.has(website.name)) {\n      throw new Error(`Static website with name \"${website.name}\" already defined.`);\n    }\n    websiteNames.add(website.name);\n    staticWebsiteServices.push(website);\n  });\n\n  return staticWebsiteServices;\n}\n\nfunction defineAIGateways(\n  gateways: readonly AIGatewayInput[] | undefined,\n  applicationAuthNamespace: string | undefined,\n): AIGateway[] {\n  const aiGatewayServices: AIGateway[] = [];\n  const gatewayNames = new Set<string>();\n\n  (gateways ?? []).forEach((config) => {\n    const gateway = AIGatewaySchema.parse(config);\n    if (gatewayNames.has(gateway.name)) {\n      throw new Error(`AI Gateway with name \"${gateway.name}\" already defined.`);\n    }\n    gatewayNames.add(gateway.name);\n    if (gateway.authNamespace === undefined) {\n      if (!applicationAuthNamespace) {\n        throw new Error(\n          `AI Gateway \"${gateway.name}\" has no \"authNamespace\" and no Auth service is configured ` +\n            `to default to. Define an Auth service, or set \"authNamespace\" explicitly.`,\n        );\n      }\n      gateway.authNamespace = applicationAuthNamespace;\n    }\n    aiGatewayServices.push(gateway);\n  });\n\n  return aiGatewayServices;\n}\n\nfunction parseSecretManager(config: AppConfig[\"secrets\"]): {\n  secrets: SecretVault[];\n  ignoreNullishValues: boolean;\n} {\n  if (!config) {\n    return { secrets: [], ignoreNullishValues: false };\n  }\n\n  const parsed = SecretsSchema.parse(config);\n  const { ignoreNullishValues } = parsed.options;\n\n  const secrets = Object.entries(parsed.vaults).map(([vaultName, vaultSecrets]) => ({\n    vaultName,\n    secrets: Object.entries(vaultSecrets).map(([name, value]) => ({ name, value })),\n  }));\n\n  // Defensive check: error if nullish values exist without ignoreNullishValues\n  if (!ignoreNullishValues) {\n    for (const vault of secrets) {\n      for (const secret of vault.secrets) {\n        if (secret.value == null) {\n          throw new Error(\n            `Secret \"${vault.vaultName}/${secret.name}\" has no value. ` +\n              `Use { ignoreNullishValues: true } option in defineSecretManager() to skip secrets without values.`,\n          );\n        }\n      }\n    }\n  }\n\n  return { secrets, ignoreNullishValues };\n}\n\ntype DefineServicesResult = {\n  tailordbResult: DefineTailorDBResult;\n  resolverResult: DefineResolverResult;\n  idpResult: DefineIdpResult;\n  authResult: DefineAuthResult;\n  staticWebsiteServices: StaticWebsite[];\n  aiGatewayServices: AIGateway[];\n  secrets: SecretVault[];\n  ignoreNullishValues: boolean;\n};\n\nfunction defineServices(\n  config: AppConfig,\n  baseDir: string,\n  pluginManager?: PluginManager,\n): DefineServicesResult {\n  const tailordbResult = defineTailorDB(config.db, baseDir, pluginManager);\n  const resolverResult = defineResolver(config.resolver, baseDir);\n  const idpResult = defineIdp(config.idp);\n  const authResult = defineAuth(\n    config.auth,\n    tailordbResult.tailorDBServices,\n    tailordbResult.externalTailorDBNamespaces,\n  );\n  const staticWebsiteServices = defineStaticWebsites(config.staticWebsites);\n  const aiGatewayServices = defineAIGateways(\n    config.aiGateways,\n    getApplicationAuthNamespace({ authService: authResult.authService, config }),\n  );\n  const { secrets, ignoreNullishValues } = parseSecretManager(config.secrets);\n  return {\n    tailordbResult,\n    resolverResult,\n    idpResult,\n    authResult,\n    staticWebsiteServices,\n    aiGatewayServices,\n    secrets,\n    ignoreNullishValues: ignoreNullishValues,\n  };\n}\n\nfunction buildApplication(params: {\n  config: AppConfig;\n  tailordbResult: DefineTailorDBResult;\n  resolverResult: DefineResolverResult;\n  idpResult: DefineIdpResult;\n  authResult: DefineAuthResult;\n  executorService: ExecutorService | undefined;\n  workflowService: WorkflowService | undefined;\n  httpAdapterService: HttpAdapterService | undefined;\n  staticWebsiteServices: StaticWebsite[];\n  aiGatewayServices: AIGateway[];\n  secrets: SecretVault[];\n  ignoreNullishValues: boolean;\n  env: Record<string, string | number | boolean>;\n}): Application {\n  const application: Application = {\n    name: params.config.name,\n    id: params.config.id,\n    config: params.config,\n    subgraphs: [\n      ...params.tailordbResult.subgraphs,\n      ...params.resolverResult.subgraphs,\n      ...params.idpResult.subgraphs,\n      ...params.authResult.subgraphs,\n    ],\n    tailorDBServices: params.tailordbResult.tailorDBServices,\n    externalTailorDBNamespaces: params.tailordbResult.externalTailorDBNamespaces,\n    resolverServices: params.resolverResult.resolverServices,\n    idpServices: params.idpResult.idpServices,\n    authService: params.authResult.authService,\n    executorService: params.executorService,\n    workflowService: params.workflowService,\n    httpAdapterService: params.httpAdapterService,\n    staticWebsiteServices: params.staticWebsiteServices,\n    aiGatewayServices: params.aiGatewayServices,\n    secrets: params.secrets,\n    ignoreNullishValues: params.ignoreNullishValues,\n    env: params.env,\n    get applications() {\n      return [application];\n    },\n  };\n  return application;\n}\n\n/**\n * Parameters for defining an application\n */\nexport interface DefineApplicationParams {\n  /** Application configuration object (must be loaded via loadConfig) */\n  config: LoadedConfig;\n  /** Plugin manager for processing plugins */\n  pluginManager?: PluginManager;\n  /** Optional bundle cache for skipping unchanged builds */\n  bundleCache?: BundleCache;\n}\n\n/**\n * Define a Tailor application from the given configuration.\n * This is a lightweight, synchronous function that creates the application\n * structure without loading tables or bundling files.\n * @param params - Parameters for defining the application\n * @returns Configured application instance\n */\nexport function defineApplication(params: DefineApplicationParams): Application {\n  const { config, pluginManager } = params;\n  const baseDir = path.dirname(config.path);\n  const services = defineServices(config, baseDir, pluginManager);\n  // Plugin executors are not known at define-time; generate/apply flows handle them after table loading.\n  const executorService = defineExecutor(config.executor, baseDir, false);\n  const workflowService = defineWorkflow(config.workflow, baseDir);\n  const httpAdapterService = defineHttpAdapterService(config.httpAdapter, baseDir);\n\n  return buildApplication({\n    config,\n    ...services,\n    executorService,\n    workflowService,\n    httpAdapterService,\n    env: config.env ?? {},\n  });\n}\n\n/**\n * Generate plugin table and executor files if a plugin manager is provided.\n * Collects source table info from TailorDB services and delegates to PluginManager.\n * @param pluginManager - Plugin manager instance (skips if undefined)\n * @param tailorDBServices - TailorDB services to collect table source info from\n * @param configPath - Path to tailor.config.ts for resolving plugin imports\n * @returns Generated executor file paths\n */\nexport function generatePluginFilesIfNeeded(\n  pluginManager: PluginManager | undefined,\n  tailorDBServices: ReadonlyArray<TailorDBService>,\n  configPath: string,\n): string[] {\n  if (!pluginManager) return [];\n\n  const sourceTableInfoMap = new Map<string, { filePath: string; exportName: string }>();\n  for (const db of tailorDBServices) {\n    const tableSourceInfo = db.typeSourceInfo;\n    for (const [tableName, sourceInfo] of Object.entries(tableSourceInfo)) {\n      if (sourceInfo.filePath) {\n        sourceTableInfoMap.set(tableName, {\n          filePath: sourceInfo.filePath,\n          exportName: sourceInfo.exportName,\n        });\n      }\n    }\n  }\n\n  return pluginManager.generatePluginFiles({\n    outputDir: path.join(getDistDir(), \"plugin\"),\n    sourceTableInfoMap,\n    configPath,\n    tableGenerator: generatePluginTableFiles,\n    executorGenerator: generatePluginExecutorFiles,\n  });\n}\n\nfunction assertWaitPointKeys(): void {\n  const failures = collectWaitPointKeyFailures(getScopedWaitPoints());\n  if (failures.length === 0) return;\n  throw new Error(failures.join(\"\\n\"));\n}\n\n/**\n * Load and fully initialize a Tailor application.\n * This performs all I/O-heavy operations: loading tables, processing plugins,\n * generating plugin files, bundling, and loading definitions for validation.\n * @param params - Parameters for defining and loading the application\n * @returns Fully initialized application with workflow results\n */\nexport async function loadApplication(\n  params: DefineApplicationParams,\n): Promise<LoadApplicationResult> {\n  const { config, pluginManager, bundleCache } = params;\n  const baseDir = path.dirname(config.path);\n\n  // 1. Define services (synchronous)\n  const {\n    tailordbResult,\n    resolverResult,\n    idpResult,\n    authResult,\n    staticWebsiteServices,\n    aiGatewayServices,\n    secrets,\n    ignoreNullishValues,\n  } = defineServices(config, baseDir, pluginManager);\n\n  // 2. Load TailorDB tables and process namespace plugins\n  for (const tailordb of tailordbResult.tailorDBServices) {\n    await tailordb.loadTypes();\n    await tailordb.processNamespacePlugins();\n  }\n  assertUniqueLocalTailorDBTypeNames({\n    tailorDBServices: tailordbResult.tailorDBServices,\n  });\n\n  // 3. Generate plugin files and determine executor file paths\n  const pluginExecutorFiles = generatePluginFilesIfNeeded(\n    pluginManager,\n    tailordbResult.tailorDBServices,\n    config.path,\n  );\n\n  // 4. Determine final executorService (const, no reassignment)\n  const executorService = defineExecutor(config.executor, baseDir, pluginExecutorFiles.length > 0);\n\n  // 5. Load and collect workflows\n  const workflowService = defineWorkflow(config.workflow, baseDir);\n  if (workflowService) {\n    await workflowService.loadWorkflows();\n  }\n\n  // 6. Load and collect HTTP adapters\n  const httpAdapterService = defineHttpAdapterService(config.httpAdapter, baseDir);\n  if (httpAdapterService) {\n    await httpAdapterService.loadAdapters();\n  }\n\n  // 7. Build start context for workflow/job start transformation\n  const startContext = await buildStartContext(\n    config.workflow,\n    getApplicationAuthNamespace({ authService: authResult.authService, config }),\n    baseDir,\n  );\n\n  // 8. Resolve bundle settings\n  const inlineSourcemap = resolveInlineSourcemap(config.inlineSourcemap);\n  const bundleLogLevel = resolveBundleLogLevel(config.logLevel);\n  // Shared across every bundle below so a project with many resolvers/executors/etc.\n  // reads and parses each ancestor tsconfig once instead of once per item.\n  const tsconfigCache = createTsconfigLookupCache();\n\n  // Collect in-memory bundled scripts\n  const bundledScripts: BundledScripts = {\n    resolvers: new Map(),\n    executors: new Map(),\n    workflowJobs: new Map(),\n    authHooks: new Map(),\n  };\n\n  // 9. Bundle resolvers\n  for (const pipeline of resolverResult.resolverServices) {\n    const resolverBundles = await bundleResolvers({\n      namespace: pipeline.namespace,\n      config: pipeline.config,\n      baseDir,\n      defaultPermission: pipeline.defaultPermission,\n      startContext,\n      cache: bundleCache,\n      inlineSourcemap,\n      bundleLogLevel,\n      tsconfigCache,\n    });\n    for (const [name, code] of resolverBundles) {\n      bundledScripts.resolvers.set(resolverBundleKey(pipeline.namespace, name), code);\n    }\n  }\n\n  // 10. Bundle executors\n  if (executorService) {\n    bundledScripts.executors = await bundleExecutors({\n      config: executorService.config,\n      startContext,\n      additionalFiles: [...pluginExecutorFiles],\n      cache: bundleCache,\n      inlineSourcemap,\n      bundleLogLevel,\n      baseDir,\n      tsconfigCache,\n    });\n  }\n\n  // 11. Bundle workflows\n  let workflowBuildResult: BundleWorkflowJobsResult | undefined;\n  if (workflowService && workflowService.jobs.length > 0) {\n    const mainJobNames = workflowService.workflowSources.map((ws) => ws.workflow.mainJob.name);\n    workflowBuildResult = await bundleWorkflowJobs(\n      workflowService.jobs,\n      mainJobNames,\n      config.env ?? {},\n      startContext,\n      baseDir,\n      bundleCache,\n      inlineSourcemap,\n      bundleLogLevel,\n      tsconfigCache,\n    );\n    bundledScripts.workflowJobs = workflowBuildResult.bundledCode;\n  }\n\n  // 12. Bundle HTTP adapters\n  let httpAdapterBuildResult: HttpAdapterBundleResult | undefined;\n  if (httpAdapterService && httpAdapterService.adapters.length > 0) {\n    httpAdapterBuildResult = await bundleHttpAdapters(\n      httpAdapterService.adapters.map((a) => ({\n        name: a.adapter.name,\n        sourceFile: a.sourceFile,\n        methods: a.methods,\n        hasOutput: a.hasOutput,\n      })),\n      baseDir,\n      bundleCache,\n      bundleLogLevel,\n      tsconfigCache,\n    );\n  }\n\n  // 13. Bundle auth hooks\n  if (authResult.authService?.config.hooks?.beforeLogin) {\n    const authName = authResult.authService.config.name;\n    bundledScripts.authHooks = await bundleAuthHooks({\n      configPath: config.path,\n      authName,\n      handlerAccessPath: `auth.hooks.beforeLogin.handler`,\n      env: config.env ?? {},\n      startContext,\n      cache: bundleCache,\n      inlineSourcemap,\n      bundleLogLevel,\n      baseDir,\n      tsconfigCache,\n    });\n  }\n\n  // 14. Load resolver and executor definitions (for validation/logging)\n  for (const pipeline of resolverResult.resolverServices) {\n    await pipeline.loadResolvers();\n  }\n  if (executorService) {\n    await executorService.loadExecutors();\n    if (pluginExecutorFiles.length > 0) {\n      await executorService.loadPluginExecutorFiles([...pluginExecutorFiles]);\n    }\n  }\n  // 15. Check the wait point keys every loaded module declared\n  assertWaitPointKeys();\n\n  if (workflowService) {\n    workflowService.printLoadedWorkflows();\n  }\n  if (httpAdapterService) {\n    httpAdapterService.printLoadedAdapters();\n  }\n  logger.newline();\n\n  // 16. Build immutable Application\n  const application = buildApplication({\n    config,\n    tailordbResult,\n    resolverResult,\n    idpResult,\n    authResult,\n    executorService,\n    workflowService,\n    httpAdapterService,\n    staticWebsiteServices,\n    aiGatewayServices,\n    secrets,\n    ignoreNullishValues,\n    env: config.env ?? {},\n  });\n\n  return { application, workflowBuildResult, httpAdapterBuildRes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