{"version":3,"file":"interpret.mjs","names":[],"sources":["../src/interpret.ts"],"sourcesContent":["import type {\n  ContractSourceContext,\n  ContractSourceDiagnostic,\n  ContractSourceDiagnostics,\n  ContractSourceProvider,\n  PslContractSourceProvider,\n} from '@prisma-next/config/config-types';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { notOk, type Result } from '@prisma-next/utils/result';\nimport type { SourceFile } from './source-file';\nimport type { SymbolTable } from './symbol-table';\nimport type { DocumentAst } from './syntax/ast/declarations';\n\n/**\n * Lets editor tooling that already parses incrementally (e.g. the language\n * server) hand cached artifacts to the interpreter instead of forcing a\n * disk re-parse.\n */\nexport interface PslInterpretInput {\n  readonly document: DocumentAst;\n  readonly sourceFile: SourceFile;\n  readonly symbolTable: SymbolTable;\n  readonly sourceId: string;\n}\n\n/**\n * Declared here — the authoring layer that owns `DocumentAst` / `SourceFile` /\n * `SymbolTable` — because `@prisma-next/config` (core) cannot name authoring\n * types. `interpret` must not read disk or `context.resolvedInputs` — those\n * are load-path concerns.\n */\nexport interface PslInterpretCapable extends PslContractSourceProvider {\n  interpret(\n    input: PslInterpretInput,\n    context: ContractSourceContext,\n  ): Result<Contract, ContractSourceDiagnostics>;\n}\n\n/**\n * Merges caller-side diagnostics (e.g. parse / symbol-table findings) into an\n * interpretation result. The authored headline is deliberately uniform — it\n * reports how many errors the schema has, never which pipeline stage found\n * them.\n */\nexport function withSeedDiagnostics(\n  result: Result<Contract, ContractSourceDiagnostics>,\n  seedDiagnostics: readonly ContractSourceDiagnostic[],\n): Result<Contract, ContractSourceDiagnostics> {\n  if (seedDiagnostics.length === 0) {\n    return result;\n  }\n  const diagnostics = result.ok\n    ? seedDiagnostics\n    : [...seedDiagnostics, ...result.failure.diagnostics];\n  return notOk({\n    summary: `Schema has ${diagnostics.length} error${diagnostics.length === 1 ? '' : 's'}`,\n    diagnostics,\n    ...(result.ok || result.failure.meta === undefined ? {} : { meta: result.failure.meta }),\n  });\n}\n\n/** The single seam that narrows a contract source to the interpret capability. */\nexport function hasPslInterpreter(source: ContractSourceProvider): source is PslInterpretCapable {\n  return (\n    source.sourceFormat === 'psl' && 'interpret' in source && typeof source.interpret === 'function'\n  );\n}\n"],"mappings":";;;;;;;;AA4CA,SAAgB,oBACd,QACA,iBAC6C;CAC7C,IAAI,gBAAgB,WAAW,GAC7B,OAAO;CAET,MAAM,cAAc,OAAO,KACvB,kBACA,CAAC,GAAG,iBAAiB,GAAG,OAAO,QAAQ,WAAW;CACtD,OAAO,MAAM;EACX,SAAS,cAAc,YAAY,OAAO,QAAQ,YAAY,WAAW,IAAI,KAAK;EAClF;EACA,GAAI,OAAO,MAAM,OAAO,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,OAAO,QAAQ,KAAK;CACxF,CAAC;AACH;;AAGA,SAAgB,kBAAkB,QAA+D;CAC/F,OACE,OAAO,iBAAiB,SAAS,eAAe,UAAU,OAAO,OAAO,cAAc;AAE1F"}