{"version":3,"file":"contract.mjs","names":["decodeContract","result","schema","value","operationContract","definition"],"sources":["../../../src/modules/contracts/contract.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- These explicit validation boundaries receive untrusted transport values before schema decoding. */\n/** Structural contracts keep the optional Effect peer out of this module. */\nexport interface StandardSchema<Input = unknown, Output = Input> {\n\treadonly '~standard': {\n\t\treadonly version: 1\n\t\treadonly vendor: string\n\t\treadonly types?: { readonly input: Input; readonly output: Output }\n\t\treadonly validate: (\n\t\t\tvalue: unknown,\n\t\t) => ValidationResult<Output> | Promise<ValidationResult<Output>>\n\t}\n}\nexport interface ValidationIssue {\n\treadonly message: string\n\treadonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[]\n}\nexport type ValidationResult<Output> =\n\t| { readonly value: Output; readonly issues?: undefined }\n\t| { readonly issues: readonly ValidationIssue[] }\nexport interface LegacyParser<Output = unknown> {\n\treadonly parse: (value: unknown) => Output\n\treadonly parseAsync?: (value: unknown) => Promise<Output>\n}\n/** Decode execution is an opaque channel here; optional adapters give it concrete semantics. */\nexport interface Decoder<Input = unknown, Output = unknown, Execution = unknown> {\n\treadonly kind: 'contract' | 'effect-contract'\n\treadonly types?: { readonly input: Input; readonly output: Output }\n\treadonly decode: (value: unknown) => Execution\n}\nexport type ContractSchema = LegacyParser | StandardSchema<unknown, unknown> | Decoder\nexport type NeutralSchema =\n\t| LegacyParser\n\t| StandardSchema<unknown, unknown>\n\t| (Decoder<unknown, unknown, ValidationResult<unknown> | Promise<ValidationResult<unknown>>> & {\n\t\t\treadonly kind: 'contract'\n\t  })\nexport type ContractInput<S> =\n\tS extends Decoder<infer Input, unknown, unknown>\n\t\t? Input\n\t\t: S extends StandardSchema<infer Input, unknown>\n\t\t\t? Input\n\t\t\t: S extends { readonly _input: infer Input }\n\t\t\t\t? Input\n\t\t\t\t: S extends LegacyParser<infer Output>\n\t\t\t\t\t? Awaited<Output>\n\t\t\t\t\t: never\nexport type ContractOutput<S> =\n\tS extends Decoder<unknown, infer Output, unknown>\n\t\t? Output\n\t\t: S extends StandardSchema<unknown, infer Output>\n\t\t\t? Output\n\t\t\t: S extends LegacyParser<infer Output>\n\t\t\t\t? Awaited<Output>\n\t\t\t\t: never\nexport type ContractExecution<S> =\n\tS extends Decoder<unknown, unknown, infer Execution> ? Execution : never\n\n/** Validation failures are values. Throws/rejections are deliberately left as defects. */\nexport async function decodeContract<S extends NeutralSchema>(\n\tschema: S,\n\tvalue: unknown,\n): Promise<ValidationResult<ContractOutput<S>>> {\n\tlet result: ValidationResult<unknown>\n\tif ('kind' in schema) result = await schema.decode(value)\n\telse if ('parse' in schema)\n\t\tresult = { value: await (schema.parseAsync ? schema.parseAsync(value) : schema.parse(value)) }\n\telse result = await schema['~standard'].validate(value)\n\t// SAFETY: each branch returns the output associated with this exact schema.\n\treturn result as ValidationResult<ContractOutput<S>>\n}\n\n/** Independent final and wire contracts never reuse the fresh-result transform. */\nexport function operationContract<\n\tconst Input extends ContractSchema,\n\tconst Result extends ContractSchema,\n\tconst Replay extends ContractSchema,\n\tconst Wire extends ContractSchema,\n\tconst Definition extends object,\n>(\n\tdefinition: Definition & {\n\t\tinput: Input\n\t\tresult: Result\n\t\treplayResult: Replay & (ContractOutput<Replay> extends ContractOutput<Result> ? unknown : never)\n\t\twire: { project: (value: ContractOutput<Result>) => ContractInput<Wire>; schema: Wire }\n\t},\n) {\n\treturn definition\n}\n"],"mappings":"AA0DA,eAAsBA,EACrB,EACA,EAC+C,CAC/C,IAAIC,EAMJ,MALA,CAGKA,EAHD,SAAUC,EAAiB,MAAMA,EAAO,OAAOC,CAAK,EAC/C,UAAWD,EACV,CAAE,MAAO,MAAOA,EAAO,WAAaA,EAAO,WAAWC,CAAK,EAAID,EAAO,MAAMC,CAAK,EAAG,EAChF,MAAMD,EAAO,YAAY,CAAC,SAASC,CAAK,EAE/CF,CACR,CAGA,SAAgBG,EAOf,EAMC,CACD,OAAOC,CACR"}