{"version":3,"file":"Record.cjs","sources":["../../src/types/Record.ts"],"sourcesContent":["import { Infer } from \"../types\";\nimport XVType from \"../XVType\";\n\nclass XVRecord<K extends XVType<any>, V extends XVType<any>> extends XVType<\n  Partial<Record<Infer<K>, Infer<V>>>\n> {\n  constructor(\n    readonly recordKey: K,\n    readonly recordValue: V,\n  ) {\n    super();\n  }\n\n  protected check(value: any): Record<Infer<K>, Infer<V>> {\n    if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n      throw new Error(`Value should be a record, received ${typeof value}`);\n    }\n\n    for (const [k, v] of Object.entries(value)) {\n      try {\n        this.recordKey.parse(k);\n        value[k] = this.recordValue.parse(v);\n      } catch (error) {\n        throw new Error(\n          `Record entry '${k}' should have key of type ${this.recordKey.constructor.name} and value of type ${this.recordValue.constructor.name}, received key: ${typeof k}, value: ${typeof v}`,\n        );\n      }\n    }\n    return value;\n  }\n}\n\nexport default XVRecord;\n"],"names":[],"mappings":";;;;AAGA,MAAM,QAAuD,SAAQ,MAEpE,CAAA;IACC,WAAA,CACW,SAAY,EACZ,WAAc,EAAA;AAEvB,QAAA,KAAK,EAAE;QAHE,IAAA,CAAA,SAAS,GAAT,SAAS;QACT,IAAA,CAAA,WAAW,GAAX,WAAW;IAGtB;AAEU,IAAA,KAAK,CAAC,KAAU,EAAA;AACxB,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACvE,MAAM,IAAI,KAAK,CAAC,CAAA,mCAAA,EAAsC,OAAO,KAAK,CAAA,CAAE,CAAC;QACvE;AAEA,QAAA,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AAC1C,YAAA,IAAI;AACF,gBAAA,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACvB,gBAAA,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YACtC;YAAE,OAAO,KAAK,EAAE;AACd,gBAAA,MAAM,IAAI,KAAK,CACb,CAAA,cAAA,EAAiB,CAAC,CAAA,0BAAA,EAA6B,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAA,mBAAA,EAAsB,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAA,gBAAA,EAAmB,OAAO,CAAC,CAAA,SAAA,EAAY,OAAO,CAAC,CAAA,CAAE,CACvL;YACH;QACF;AACA,QAAA,OAAO,KAAK;IACd;AACD;;;;"}