{"version":3,"file":"transform.cjs","names":["BaseSchema"],"sources":["../../src/schemas/transform.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { BaseSchema } from \"../core/base\";\nimport type { CombinedStandardProps, Schema } from \"../core/types\";\n\nexport class TransformSchema<I, In, Out> extends BaseSchema<I, Out> {\n  private readonly innerSchema: Schema<I, In>;\n  private readonly fn: (value: In) => Out;\n\n  constructor(innerSchema: Schema<I, In>, fn: (value: In) => Out) {\n    super();\n    this.innerSchema = innerSchema;\n    this.fn = fn;\n    this.jsonSchema = { ...innerSchema.jsonSchema };\n  }\n\n  get [\"~standard\"](): CombinedStandardProps<I, Out> {\n    return {\n      version: 1,\n      vendor: \"h-schema\",\n      jsonSchema: {\n        input: () => this.jsonSchema,\n        output: () => this.jsonSchema,\n      },\n      validate: (value: unknown) => {\n        const r = this.innerSchema[\"~standard\"].validate(value) as StandardSchemaV1.Result<In>;\n        if (\"issues\" in r) {\n          return r as StandardSchemaV1.Result<Out>;\n        }\n        try {\n          return { value: this.fn(r.value) };\n        } catch (e) {\n          return {\n            issues: [{ message: e instanceof Error ? e.message : \"Transform failed\" }],\n          };\n        }\n      },\n      types: {\n        input: {} as I,\n        output: {} as Out,\n      },\n    };\n  }\n}\n\nexport class PipeSchema<I, A, B> extends BaseSchema<I, B> {\n  private readonly first: Schema<I, A>;\n  private readonly second: Schema<A, B>;\n\n  constructor(first: Schema<I, A>, second: Schema<A, B>) {\n    super();\n    this.first = first;\n    this.second = second;\n    this.jsonSchema = { ...first.jsonSchema };\n  }\n\n  get [\"~standard\"](): CombinedStandardProps<I, B> {\n    return {\n      version: 1,\n      vendor: \"h-schema\",\n      jsonSchema: {\n        input: () => this.first.jsonSchema,\n        output: () => this.second.jsonSchema ?? this.first.jsonSchema,\n      },\n      validate: (value: unknown) => {\n        const r1 = this.first[\"~standard\"].validate(value) as StandardSchemaV1.Result<A>;\n        if (\"issues\" in r1) {\n          return r1 as StandardSchemaV1.Result<B>;\n        }\n        return this.second[\"~standard\"].validate(r1.value) as StandardSchemaV1.Result<B>;\n      },\n      types: {\n        input: {} as I,\n        output: {} as B,\n      },\n    };\n  }\n}\n"],"mappings":";;AAIA,IAAa,kBAAb,cAAiDA,aAAAA,WAAmB;CAClE;CACA;CAEA,YAAY,aAA4B,IAAwB;EAC9D,MAAM;EACN,KAAK,cAAc;EACnB,KAAK,KAAK;EACV,KAAK,aAAa,EAAE,GAAG,YAAY,WAAW;CAChD;CAEA,KAAK,eAA8C;EACjD,OAAO;GACL,SAAS;GACT,QAAQ;GACR,YAAY;IACV,aAAa,KAAK;IAClB,cAAc,KAAK;GACrB;GACA,WAAW,UAAmB;IAC5B,MAAM,IAAI,KAAK,YAAY,YAAY,CAAC,SAAS,KAAK;IACtD,IAAI,YAAY,GACd,OAAO;IAET,IAAI;KACF,OAAO,EAAE,OAAO,KAAK,GAAG,EAAE,KAAK,EAAE;IACnC,SAAS,GAAG;KACV,OAAO,EACL,QAAQ,CAAC,EAAE,SAAS,aAAa,QAAQ,EAAE,UAAU,mBAAmB,CAAC,EAC3E;IACF;GACF;GACA,OAAO;IACL,OAAO,CAAC;IACR,QAAQ,CAAC;GACX;EACF;CACF;AACF;AAEA,IAAa,aAAb,cAAyCA,aAAAA,WAAiB;CACxD;CACA;CAEA,YAAY,OAAqB,QAAsB;EACrD,MAAM;EACN,KAAK,QAAQ;EACb,KAAK,SAAS;EACd,KAAK,aAAa,EAAE,GAAG,MAAM,WAAW;CAC1C;CAEA,KAAK,eAA4C;EAC/C,OAAO;GACL,SAAS;GACT,QAAQ;GACR,YAAY;IACV,aAAa,KAAK,MAAM;IACxB,cAAc,KAAK,OAAO,cAAc,KAAK,MAAM;GACrD;GACA,WAAW,UAAmB;IAC5B,MAAM,KAAK,KAAK,MAAM,YAAY,CAAC,SAAS,KAAK;IACjD,IAAI,YAAY,IACd,OAAO;IAET,OAAO,KAAK,OAAO,YAAY,CAAC,SAAS,GAAG,KAAK;GACnD;GACA,OAAO;IACL,OAAO,CAAC;IACR,QAAQ,CAAC;GACX;EACF;CACF;AACF"}