{"version":3,"file":"schema.mjs","names":["ContractValidationError","issues","effectContract","effectSchema","Schema","schema","effectStandardSchema","decodeEffectContract","Effect","value","decodeContract","result","error"],"sources":["../../../src/modules/effect/schema.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- Explicit schema decoder boundaries validate untrusted transport input. */\nimport { Effect, Schema } from 'effect'\nimport type {\n\tContractSchema,\n\tContractOutput,\n\tDecoder,\n\tLegacyParser,\n\tNeutralSchema,\n\tValidationIssue,\n} from '../contracts/contract'\nimport { decodeContract } from '../contracts/contract'\n\nexport class ContractValidationError {\n\treadonly _tag = 'ContractValidationError'\n\tconstructor(readonly issues: readonly ValidationIssue[]) {}\n}\nexport interface EffectDecoder<Input, Output, Error = never, Requirements = never> extends Decoder<\n\tInput,\n\tOutput,\n\tEffect.Effect<Output, Error, Requirements>\n> {\n\treadonly kind: 'effect-contract'\n}\n/** Explicit custom decoders preserve their exact typed error and service channels. */\nexport function effectContract<Input, Output, Error = never, Requirements = never>(\n\tdecode: (value: unknown) => Effect.Effect<Output, Error, Requirements>,\n): EffectDecoder<Input, Output, Error, Requirements> {\n\treturn { kind: 'effect-contract', decode }\n}\n/** Encoding requirements remain independent of the decoder's requirements. */\nexport function effectSchema<const S extends Schema.Constraint>(schema: S) {\n\treturn {\n\t\t...effectContract<S['Encoded'], S['Type'], Schema.SchemaError, S['DecodingServices']>(\n\t\t\tSchema.decodeUnknownEffect(schema),\n\t\t),\n\t\tschema,\n\t\tencode: Schema.encodeEffect(schema),\n\t}\n}\n/** The service-free bridge cannot erase decoder requirements. */\nexport function effectStandardSchema<const S extends Schema.ConstraintDecoder<unknown>>(schema: S) {\n\treturn Schema.toStandardSchemaV1(schema)\n}\nexport type ContractDecoderError<S> =\n\tS extends EffectDecoder<unknown, unknown, infer Error, unknown>\n\t\t? Error\n\t\t: S extends LegacyParser\n\t\t\t? never\n\t\t\t: S extends ContractSchema\n\t\t\t\t? ContractValidationError\n\t\t\t\t: never\nexport type ContractDecoderRequirements<S> =\n\tS extends EffectDecoder<unknown, unknown, unknown, infer Requirements> ? Requirements : never\n\n/** Decode input, fresh results, and final replay values within the current Effect scope. */\nexport function decodeEffectContract<S extends ContractSchema>(\n\tschema: S,\n\tvalue: unknown,\n): Effect.Effect<ContractOutput<S>, ContractDecoderError<S>, ContractDecoderRequirements<S>> {\n\tconst decoded = Effect.suspend(() => {\n\t\tif ('kind' in schema && schema.kind === 'effect-contract') {\n\t\t\t// SAFETY: only the explicit optional adapter exposes this discriminator.\n\t\t\treturn schema.decode(value) as Effect.Effect<unknown, unknown, unknown>\n\t\t}\n\t\t// SAFETY: the Effect discriminator was excluded; ordinary adapters return validation results.\n\t\treturn Effect.promise(() => decodeContract(schema as NeutralSchema, value)).pipe(\n\t\t\tEffect.flatMap((result) => {\n\t\t\t\tif (!result.issues) return Effect.succeed(result.value)\n\t\t\t\tconst error = new ContractValidationError(result.issues)\n\t\t\t\t// Legacy parsers have always exposed validation throws as defects.\n\t\t\t\treturn 'parse' in schema ? Effect.die(error) : Effect.fail(error)\n\t\t\t}),\n\t\t)\n\t})\n\t// SAFETY: conditional channels correspond to the explicit Effect branch or neutral validation branch.\n\treturn decoded as Effect.Effect<\n\t\tContractOutput<S>,\n\t\tContractDecoderError<S>,\n\t\tContractDecoderRequirements<S>\n\t>\n}\n"],"mappings":"uGAYA,IAAaA,EAAb,KAAqC,CAEf,OADrB,KAAgB,0BAChB,YAAY,EAA6C,CAApC,KAAA,OAAAC,CAAqC,CAC3D,EASA,SAAgBC,EACf,EACoD,CACpD,MAAO,CAAE,KAAM,kBAAmB,QAAO,CAC1C,CAEA,SAAgBC,EAAgD,EAAW,CAC1E,MAAO,CACN,GAAGD,EACFE,EAAO,oBAAoBC,CAAM,CAClC,EACA,SACA,OAAQD,EAAO,aAAaC,CAAM,CACnC,CACD,CAEA,SAAgBC,EAAwE,EAAW,CAClG,OAAOF,EAAO,mBAAmBC,CAAM,CACxC,CAaA,SAAgBE,EACf,EACA,EAC4F,CAiB5F,OAhBgBC,EAAO,YAClB,SAAUH,GAAUA,EAAO,OAAS,kBAEhCA,EAAO,OAAOI,CAAK,EAGpBD,EAAO,YAAcE,EAAeL,EAAyBI,CAAK,CAAC,CAAC,CAAC,KAC3ED,EAAO,QAAS,GAAW,CAC1B,GAAI,CAACG,EAAO,OAAQ,OAAOH,EAAO,QAAQG,EAAO,KAAK,EACtD,IAAMC,EAAQ,IAAIZ,EAAwBW,EAAO,MAAM,EAEvD,MAAO,UAAWN,EAASG,EAAO,IAAII,CAAK,EAAIJ,EAAO,KAAKI,CAAK,CACjE,CAAC,CACF,CAGY,CAKd"}