{"version":3,"file":"guards-ForsrxnH.mjs","names":[],"sources":["../src/plugin/guards.ts"],"sourcesContent":["// Runtime guards and helpers for plugin authoring types.\n//\n// These live outside plugin/types.ts (a pure type module) because they are\n// runtime functions. The types they operate on are imported type-only.\nimport type {\n  DependencyKind,\n  PluginGeneratedExecutor,\n  PluginGeneratedExecutorWithFile,\n} from \"./types\";\n\n/**\n * Reads a table name without assuming plugin output is a valid table object.\n * @param table - Raw table value returned by a plugin hook.\n * @returns The table name when it is a string; otherwise, undefined.\n */\nexport function getRawPluginTableName(table: unknown): string | undefined {\n  const name =\n    typeof table === \"object\" && table !== null && \"name\" in table ? table.name : undefined;\n  return typeof name === \"string\" ? name : undefined;\n}\n\n/**\n * Collects the generation-time dependency kinds a plugin requires.\n * @param plugin - The plugin object to inspect.\n * @param plugin.onTailorDBReady - Hook for TailorDB readiness.\n * @param plugin.onResolverReady - Hook for resolver readiness.\n * @param plugin.onExecutorReady - Hook for executor readiness.\n * @returns Set of dependency kinds required by the plugin.\n */\nexport function getPluginGenerationDependencies(plugin: {\n  onTailorDBReady?: unknown;\n  onResolverReady?: unknown;\n  onExecutorReady?: unknown;\n}): Set<DependencyKind> {\n  const deps = new Set<DependencyKind>();\n  if (plugin.onTailorDBReady) {\n    deps.add(\"tailordb\");\n  }\n  if (plugin.onResolverReady) {\n    deps.add(\"resolver\");\n  }\n  if (plugin.onExecutorReady) {\n    deps.add(\"executor\");\n  }\n  return deps;\n}\n\n/**\n * Checks if a plugin has any generation-time hooks.\n * @param plugin - The plugin object to inspect.\n * @param plugin.onTailorDBReady - Hook for TailorDB readiness.\n * @param plugin.onResolverReady - Hook for resolver readiness.\n * @param plugin.onExecutorReady - Hook for executor readiness.\n * @returns True if the plugin has at least one generation hook.\n */\nexport function hasGenerationHooks(plugin: {\n  onTailorDBReady?: unknown;\n  onResolverReady?: unknown;\n  onExecutorReady?: unknown;\n}): boolean {\n  return !!(plugin.onTailorDBReady || plugin.onResolverReady || plugin.onExecutorReady);\n}\n\n/**\n * Checks if a plugin executor uses file-based resolution.\n * @param executor - The plugin executor to check.\n * @returns True if the executor uses file-based resolution.\n */\nexport function isPluginExecutorWithFile(\n  executor: PluginGeneratedExecutor,\n): executor is PluginGeneratedExecutorWithFile {\n  return \"resolve\" in executor && \"context\" in executor;\n}\n\n/**\n * The shape every plugin instance has, whatever else it carries.\n */\nexport interface PluginShaped {\n  id: string;\n  description: string;\n}\n\nfunction isPluginShaped(value: unknown): value is PluginShaped {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    typeof (value as Record<string, unknown>).id === \"string\" &&\n    typeof (value as Record<string, unknown>).description === \"string\"\n  );\n}\n\n/**\n * Picks the plugin arrays (`definePlugins()` results) out of a config module's\n * exports. An array counts only when every item is plugin-shaped, so an array\n * that mixes in anything else is left alone as a whole; every loader that reads\n * plugins from a config module goes through this so they agree on which ones exist.\n * @param configModule - The imported `tailor.config.ts` module namespace\n * @returns The exported arrays whose items are all plugin-shaped, in export order\n */\nexport function pickPluginArrays(configModule: object): PluginShaped[][] {\n  const arrays: PluginShaped[][] = [];\n  for (const value of Object.values(configModule)) {\n    if (Array.isArray(value) && value.length > 0 && value.every(isPluginShaped)) {\n      arrays.push(value);\n    }\n  }\n  return arrays;\n}\n"],"mappings":"AAeA,SAAgB,sBAAsB,EAAoC,CACxE,IAAM,EACJ,OAAO,GAAU,UAAY,GAAkB,SAAU,EAAQ,EAAM,KAAO,IAAA,GAChF,OAAO,OAAO,GAAS,SAAW,EAAO,IAAA,EAC3C,CAUA,SAAgB,gCAAgC,EAIxB,CACtB,IAAM,EAAO,IAAI,IAUjB,OATI,EAAO,iBACT,EAAK,IAAI,UAAU,EAEjB,EAAO,iBACT,EAAK,IAAI,UAAU,EAEjB,EAAO,iBACT,EAAK,IAAI,UAAU,EAEd,CACT,CAUA,SAAgB,mBAAmB,EAIvB,CACV,MAAO,CAAC,EAAE,EAAO,iBAAmB,EAAO,iBAAmB,EAAO,gBACvE,CAOA,SAAgB,yBACd,EAC6C,CAC7C,MAAO,YAAa,GAAY,YAAa,CAC/C,CAUA,SAAS,eAAe,EAAuC,CAC7D,OACE,OAAO,GAAU,YACjB,GACA,OAAQ,EAAkC,IAAO,UACjD,OAAQ,EAAkC,aAAgB,QAE9D,CAUA,SAAgB,iBAAiB,EAAwC,CACvE,IAAM,EAA2B,CAAC,EAClC,IAAK,IAAM,KAAS,OAAO,OAAO,CAAY,EACxC,MAAM,QAAQ,CAAK,GAAK,EAAM,OAAS,GAAK,EAAM,MAAM,cAAc,GACxE,EAAO,KAAK,CAAK,EAGrB,OAAO,CACT"}