{"version":3,"file":"runOpa-D511z37u.mjs","names":[],"sources":["../src/commands/policy/helpers/assertOpaInstalled.ts","../src/commands/policy/helpers/runOpa.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\n\nimport { OPA_INSTALL_HINT } from '../constants.js';\n\n/**\n * Ensures the `opa` binary is available on PATH.\n *\n * @throws Error when `opa` is not installed\n */\nexport function assertOpaInstalled(): void {\n  const result = spawnSync('opa', ['version'], { stdio: 'ignore' });\n  if (result.error || result.status !== 0) {\n    throw new Error(OPA_INSTALL_HINT);\n  }\n}\n","import { spawn } from 'node:child_process';\n\nimport { OPA_INSTALL_HINT } from '../constants.js';\n\n/** Result of an OPA CLI invocation with captured output. */\nexport interface RunOpaCaptureResult {\n  /** Child process exit code */\n  code: number;\n  /** Captured stdout */\n  stdout: string;\n  /** Captured stderr */\n  stderr: string;\n}\n\n/**\n * Runs an OPA CLI command and streams stdout/stderr to the current process.\n *\n * @param args - Arguments passed to the `opa` binary\n * @param options - Optional working directory\n * @returns The child process exit code\n */\nexport function runOpa(args: string[], options: { cwd?: string } = {}): Promise<number> {\n  return new Promise<number>((resolve, reject) => {\n    const child = spawn('opa', args, {\n      cwd: options.cwd,\n      stdio: 'inherit',\n    });\n\n    child.on('error', (err) => {\n      if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n        reject(new Error(OPA_INSTALL_HINT));\n        return;\n      }\n      reject(err);\n    });\n    child.on('close', (code) => resolve(code ?? 1));\n  });\n}\n\n/**\n * Runs an OPA CLI command and captures stdout/stderr.\n *\n * @param args - Arguments passed to the `opa` binary\n * @param options - Optional working directory\n * @returns Exit code and captured output\n */\nexport function runOPACapture(\n  args: string[],\n  options: { cwd?: string } = {},\n): Promise<RunOpaCaptureResult> {\n  return new Promise<RunOpaCaptureResult>((resolve, reject) => {\n    const child = spawn('opa', args, {\n      cwd: options.cwd,\n      stdio: ['ignore', 'pipe', 'pipe'],\n    });\n\n    let stdout = '';\n    let stderr = '';\n\n    child.stdout?.on('data', (chunk: Buffer) => {\n      stdout += chunk.toString();\n    });\n    child.stderr?.on('data', (chunk: Buffer) => {\n      stderr += chunk.toString();\n    });\n\n    child.on('error', (err) => {\n      if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n        reject(new Error(OPA_INSTALL_HINT));\n        return;\n      }\n      reject(err);\n    });\n    child.on('close', (code) => resolve({ code: code ?? 1, stdout, stderr }));\n  });\n}\n"],"mappings":"uGASA,SAAgB,GAA2B,CACzC,IAAM,EAAS,EAAU,MAAO,CAAC,UAAU,CAAE,CAAE,MAAO,SAAU,CAAC,CACjE,GAAI,EAAO,OAAS,EAAO,SAAW,EACpC,MAAU,MAAM,EAAiB,CCSrC,SAAgB,EAAO,EAAgB,EAA4B,EAAE,CAAmB,CACtF,OAAO,IAAI,SAAiB,EAAS,IAAW,CAC9C,IAAM,EAAQ,EAAM,MAAO,EAAM,CAC/B,IAAK,EAAQ,IACb,MAAO,UACR,CAAC,CAEF,EAAM,GAAG,QAAU,GAAQ,CACzB,GAAK,EAA8B,OAAS,SAAU,CACpD,EAAW,MAAM,EAAiB,CAAC,CACnC,OAEF,EAAO,EAAI,EACX,CACF,EAAM,GAAG,QAAU,GAAS,EAAQ,GAAQ,EAAE,CAAC,EAC/C,CAUJ,SAAgB,EACd,EACA,EAA4B,EAAE,CACA,CAC9B,OAAO,IAAI,SAA8B,EAAS,IAAW,CAC3D,IAAM,EAAQ,EAAM,MAAO,EAAM,CAC/B,IAAK,EAAQ,IACb,MAAO,CAAC,SAAU,OAAQ,OAAO,CAClC,CAAC,CAEE,EAAS,GACT,EAAS,GAEb,EAAM,QAAQ,GAAG,OAAS,GAAkB,CAC1C,GAAU,EAAM,UAAU,EAC1B,CACF,EAAM,QAAQ,GAAG,OAAS,GAAkB,CAC1C,GAAU,EAAM,UAAU,EAC1B,CAEF,EAAM,GAAG,QAAU,GAAQ,CACzB,GAAK,EAA8B,OAAS,SAAU,CACpD,EAAW,MAAM,EAAiB,CAAC,CACnC,OAEF,EAAO,EAAI,EACX,CACF,EAAM,GAAG,QAAU,GAAS,EAAQ,CAAE,KAAM,GAAQ,EAAG,SAAQ,SAAQ,CAAC,CAAC,EACzE"}