{"version":3,"file":"integrations-DDqfWjvH.cjs","names":[],"sources":["../../src/integrations/hooks.ts","../../src/integrations/index.ts"],"sourcesContent":["// --- Integration hooks for optional packages (plan §11.6) ---\n//\n// These hooks allow optional packages (nix-i18n, nix-js-auth, nix-query,\n// nix-js-testing) to integrate with the Kit runtime without being a\n// dependency. The Kit calls these hooks at well-defined points; integrations\n// register themselves via `registerIntegration()`.\n//\n// Design:\n//   - Hooks are typed interfaces, not concrete implementations.\n//   - The Kit never imports optional packages directly.\n//   - Integrations register via the public API.\n//   - Missing integrations are silently skipped (no error).\n\nimport type { NixKitIntegration } from \"./index.js\";\n\n// i18n hooks (nix-i18n)\n\nexport interface I18nIntegration {\n  /** Extracts the locale from a request (e.g. from URL, cookie, Accept-Language). */\n  getLocale(request: Request): string | Promise<string>;\n  /** Returns hreflang alternates for a given URL and locale. */\n  getAlternates(url: URL, locale: string): Array<{ hreflang: string; href: string }>;\n  /** Translates a key for a given locale. */\n  translate(key: string, locale: string, params?: Record<string, unknown>): string;\n}\n\n// Auth hooks (nix-js-auth)\n\nexport interface AuthIntegration {\n  /** Extracts the user/session from a request and populates locals. */\n  getSession(request: Request): Promise<{ user?: unknown; session?: unknown } | null>;\n  /** Seeds SSR data with auth state for client hydration. */\n  seedSSR(locals: Record<string, unknown>): Record<string, unknown>;\n}\n\n// Query hooks (nix-query)\n\nexport interface QueryIntegration {\n  /** Dehydrates query cache for SSR serialization. */\n  dehydrate(): Record<string, unknown>;\n  /** Rehydrates query cache on the client from SSR data. */\n  rehydrate(data: Record<string, unknown>): void;\n  /** Invalidates queries by tags/keys after an action. */\n  invalidate(tags: readonly string[], keys?: readonly string[]): void | Promise<void>;\n}\n\n// Testing hooks (nix-js-testing)\n\nexport interface TestingIntegration {\n  /** Creates a test request fixture. */\n  createRequest(method: string, path: string, options?: RequestInit): Request;\n  /** Creates a render fixture for a given route. */\n  createRenderFixture(routePath: string, params?: Record<string, string>): unknown;\n  /** Resets test state between tests. */\n  reset(): void;\n}\n\n// Registry\n\ninterface IntegrationRegistry {\n  i18n?: I18nIntegration;\n  auth?: AuthIntegration;\n  query?: QueryIntegration;\n  testing?: TestingIntegration;\n  custom: NixKitIntegration[];\n}\n\nconst registry: IntegrationRegistry = { custom: [] };\n\n/**\n * Registers an integration. Optional packages call this on import.\n * The Kit never imports optional packages — they register themselves.\n */\nexport function registerIntegration(\n  type: \"i18n\",\n  integration: I18nIntegration,\n): void;\nexport function registerIntegration(\n  type: \"auth\",\n  integration: AuthIntegration,\n): void;\nexport function registerIntegration(\n  type: \"query\",\n  integration: QueryIntegration,\n): void;\nexport function registerIntegration(\n  type: \"testing\",\n  integration: TestingIntegration,\n): void;\nexport function registerIntegration(\n  type: \"custom\",\n  integration: NixKitIntegration,\n): void;\nexport function registerIntegration(\n  type: keyof IntegrationRegistry,\n  integration: unknown,\n): void {\n  if (type === \"custom\") {\n    registry.custom.push(integration as NixKitIntegration);\n  } else {\n    (registry as unknown as Record<string, unknown>)[type] = integration;\n  }\n}\n\n/** Gets the registered i18n integration, if any. */\nexport function getI18nIntegration(): I18nIntegration | undefined {\n  return registry.i18n;\n}\n\n/** Gets the registered auth integration, if any. */\nexport function getAuthIntegration(): AuthIntegration | undefined {\n  return registry.auth;\n}\n\n/** Gets the registered query integration, if any. */\nexport function getQueryIntegration(): QueryIntegration | undefined {\n  return registry.query;\n}\n\n/** Gets the registered testing integration, if any. */\nexport function getTestingIntegration(): TestingIntegration | undefined {\n  return registry.testing;\n}\n\n/** Gets all registered custom integrations. */\nexport function getCustomIntegrations(): readonly NixKitIntegration[] {\n  return registry.custom;\n}\n\n/** Clears all registered integrations. Used in tests. */\nexport function clearIntegrations(): void {\n  registry.i18n = undefined;\n  registry.auth = undefined;\n  registry.query = undefined;\n  registry.testing = undefined;\n  registry.custom = [];\n}\n","export interface NixKitIntegrationContext {\n  root: string;\n  command: \"dev\" | \"build\" | \"preview\" | \"start\" | \"check\" | \"routes\" | \"doctor\";\n}\n\nexport interface NixKitIntegration {\n  name: string;\n  config?(config: Record<string, unknown>, context: NixKitIntegrationContext): void | Promise<void>;\n  routes?(manifest: unknown, context: NixKitIntegrationContext): void | Promise<void>;\n  request?(request: Request, context: NixKitIntegrationContext): void | Response | Promise<void | Response>;\n  render?(result: { html: string }, context: NixKitIntegrationContext): void | Promise<void>;\n  build?(result: unknown, context: NixKitIntegrationContext): void | Promise<void>;\n  clientEntry?(source: string, context: NixKitIntegrationContext): string | void | Promise<string | void>;\n  error?(error: unknown, context: NixKitIntegrationContext): void | Promise<void>;\n}\n\nexport async function runIntegrationHook<K extends keyof Omit<NixKitIntegration, \"name\">>(\n  integrations: readonly NixKitIntegration[],\n  hook: K,\n  args: Parameters<NonNullable<NixKitIntegration[K]>>,\n): Promise<void> {\n  for (const integration of integrations) {\n    const handler = integration[hook];\n    if (typeof handler === \"function\") await (handler as (...values: unknown[]) => unknown)(...args);\n  }\n}\n\n// Typed integration hooks for optional packages (plan §11.6).\nexport {\n  type I18nIntegration,\n  type AuthIntegration,\n  type QueryIntegration,\n  type TestingIntegration,\n  registerIntegration,\n  getI18nIntegration,\n  getAuthIntegration,\n  getQueryIntegration,\n  getTestingIntegration,\n  getCustomIntegrations,\n  clearIntegrations,\n} from \"./hooks.js\";\n"],"mappings":"AAmEA,IAAM,EAAgC,CAAE,OAAQ,CAAC,CAAE,EA0BnD,SAAgB,EACd,EACA,EACM,CACF,IAAS,SACX,EAAS,OAAO,KAAK,CAAgC,EAErD,EAAiD,GAAQ,CAE7D,CAGA,SAAgB,GAAkD,CAChE,OAAO,EAAS,IAClB,CAGA,SAAgB,GAAkD,CAChE,OAAO,EAAS,IAClB,CAGA,SAAgB,GAAoD,CAClE,OAAO,EAAS,KAClB,CAGA,SAAgB,GAAwD,CACtE,OAAO,EAAS,OAClB,CAGA,SAAgB,GAAsD,CACpE,OAAO,EAAS,MAClB,CAGA,SAAgB,GAA0B,CACxC,EAAS,KAAO,IAAA,GAChB,EAAS,KAAO,IAAA,GAChB,EAAS,MAAQ,IAAA,GACjB,EAAS,QAAU,IAAA,GACnB,EAAS,OAAS,CAAC,CACrB,CCxHA,eAAsB,EACpB,EACA,EACA,EACe,CACf,IAAK,IAAM,KAAe,EAAc,CACtC,IAAM,EAAU,EAAY,GACxB,OAAO,GAAY,YAAY,MAAO,EAA8C,GAAG,CAAI,CACjG,CACF"}