{"version":3,"file":"set.mjs","names":[],"sources":["../../src/schemas/set.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { BaseSchema } from \"../core/base\";\nimport type { CombinedStandardProps, Schema } from \"../core/types\";\n\nexport class SetSchema<V> extends BaseSchema<unknown, Set<V>> {\n  private readonly valueSchema: Schema<unknown, V>;\n\n  constructor(valueSchema: Schema<unknown, V>) {\n    super();\n    this.valueSchema = valueSchema;\n    this.jsonSchema = {\n      type: \"array\",\n      uniqueItems: true,\n      items: valueSchema.jsonSchema,\n    };\n  }\n\n  get [\"~standard\"](): CombinedStandardProps<unknown, Set<V>> {\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        if (!(value instanceof Set)) {\n          return { issues: [{ message: \"Expected Set\" }] };\n        }\n        const issues: StandardSchemaV1.Issue[] = [];\n        const out = new Set<V>();\n        let i = 0;\n        for (const item of value.values()) {\n          const r = this.valueSchema[\"~standard\"].validate(item) as StandardSchemaV1.Result<V>;\n          if (\"issues\" in r) {\n            if (r.issues) {\n              issues.push(\n                ...r.issues.map((iss) => ({\n                  ...iss,\n                  path: iss.path ? [i, ...iss.path] : [i],\n                })),\n              );\n            }\n          } else {\n            out.add(r.value);\n          }\n          i++;\n        }\n        if (issues.length > 0) {\n          return { issues };\n        }\n        return { value: out };\n      },\n      types: {\n        input: {} as unknown,\n        output: new Set() as Set<V>,\n      },\n    };\n  }\n}\n"],"mappings":";;AAIA,IAAa,YAAb,cAAkC,WAA4B;CAC5D;CAEA,YAAY,aAAiC;EAC3C,MAAM;EACN,KAAK,cAAc;EACnB,KAAK,aAAa;GAChB,MAAM;GACN,aAAa;GACb,OAAO,YAAY;EACrB;CACF;CAEA,KAAK,eAAuD;EAC1D,OAAO;GACL,SAAS;GACT,QAAQ;GACR,YAAY;IACV,aAAa,KAAK;IAClB,cAAc,KAAK;GACrB;GACA,WAAW,UAAmB;IAC5B,IAAI,EAAE,iBAAiB,MACrB,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS,eAAe,CAAC,EAAE;IAEjD,MAAM,SAAmC,CAAC;IAC1C,MAAM,sBAAM,IAAI,IAAO;IACvB,IAAI,IAAI;IACR,KAAK,MAAM,QAAQ,MAAM,OAAO,GAAG;KACjC,MAAM,IAAI,KAAK,YAAY,YAAY,CAAC,SAAS,IAAI;KACrD,IAAI,YAAY,GACV;UAAA,EAAE,QACJ,OAAO,KACL,GAAG,EAAE,OAAO,KAAK,SAAS;OACxB,GAAG;OACH,MAAM,IAAI,OAAO,CAAC,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,CAAC;MACxC,EAAE,CACJ;KAAA,OAGF,IAAI,IAAI,EAAE,KAAK;KAEjB;IACF;IACA,IAAI,OAAO,SAAS,GAClB,OAAO,EAAE,OAAO;IAElB,OAAO,EAAE,OAAO,IAAI;GACtB;GACA,OAAO;IACL,OAAO,CAAC;IACR,wBAAQ,IAAI,IAAI;GAClB;EACF;CACF;AACF"}