{"version":3,"sources":["../../../src/api/arrays.ts"],"sourcesContent":["import type { PipeInput, Pipe, PipeOutput } from './base'\nimport { standard, schema, compileNested } from './base/pipes'\nimport { getRandomValue } from '../utils/functions'\n\nexport const array = <T extends Pipe<any, any>>(branch: T, err = 'is not an array') => {\n\tconst errorsVarname = `errors_${getRandomValue()}`\n\tconst resVarname = `res_${getRandomValue()}`\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\treturn standard<PipeInput<T>[], PipeOutput<T>[]>(\n\t\t({ input, path }, opts) => [\n\t\t\topts.wrapError(`!Array.isArray(${input})`, `PipeError.root('${err}', ${input}, ${path})`),\n\t\t\topts.failEarly ? '' : `const ${errorsVarname} = []`,\n\t\t\t`const ${resVarname} = []`,\n\t\t\t`let ${validatedVarname}`,\n\t\t\t`for (let idx = 0; idx < ${input}.length; idx++) {`,\n\t\t\t`\t${validatedVarname} = ${input}[idx]`,\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign', key: validatedVarname }),\n\t\t\topts.failEarly\n\t\t\t\t? `if (${validatedVarname} instanceof PipeError) ${opts.wrapError.format(`PipeError.path(idx, '${validatedVarname}', ${validatedVarname})`)}`\n\t\t\t\t: `\tif (${validatedVarname} instanceof PipeError) ${errorsVarname}.push(PipeError.path(idx, '${validatedVarname}', ${validatedVarname}))`,\n\t\t\t`\telse ${resVarname}[idx] = ${validatedVarname}`,\n\t\t\t`}`,\n\t\t\topts.failEarly ? '' : opts.wrapError(`${errorsVarname}.length`, `PipeError.rootFrom(${errorsVarname})`),\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `${input}`),\n\t\t\t`${input} = ${resVarname}`,\n\t\t],\n\t\t{\n\t\t\tschema: () => ({ type: 'array', items: schema(branch) }),\n\t\t},\n\t)\n}\n\nexport const tuple = <T extends ReadonlyArray<Pipe<any, any>>>(branches: readonly [...T], err = 'is not an array') => {\n\tconst errorsVarname = `errors_${getRandomValue()}`\n\tconst resVarname = `res_${getRandomValue()}`\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\treturn standard<{ [K in keyof T]: PipeInput<T[K]> }, { [K in keyof T]: PipeOutput<T[K]> }>(\n\t\t({ input, path }, opts) => [\n\t\t\topts.wrapError(`!Array.isArray(${input})`, `PipeError.root('${err}', ${input}, ${path})`),\n\t\t\t...(branches.length === 0\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t`const ${resVarname} = []`,\n\t\t\t\t\t\topts.failEarly ? '' : `const ${errorsVarname} = []`,\n\t\t\t\t\t\t...branches.flatMap((branch, idx) => [\n\t\t\t\t\t\t\t`let ${validatedVarname}${idx} = ${input}[${idx}]`,\n\t\t\t\t\t\t\t...compileNested({\n\t\t\t\t\t\t\t\topts,\n\t\t\t\t\t\t\t\tpipe: branch,\n\t\t\t\t\t\t\t\tinput: `${validatedVarname}${idx}`,\n\t\t\t\t\t\t\t\tkey: `${idx}`,\n\t\t\t\t\t\t\t\terrorType: 'assign',\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\topts.failEarly\n\t\t\t\t\t\t\t\t? opts.wrapError(`${validatedVarname}${idx} instanceof PipeError`, `${validatedVarname}${idx}`)\n\t\t\t\t\t\t\t\t: `\tif (${validatedVarname}${idx} instanceof PipeError) ${errorsVarname}.push(${validatedVarname}${idx})`,\n\t\t\t\t\t\t\t`if (!(${validatedVarname}${idx} instanceof PipeError)) ${resVarname}[${idx}] = ${validatedVarname}${idx}`,\n\t\t\t\t\t\t]),\n\t\t\t\t\t\topts.failEarly ? '' : opts.wrapError(`${errorsVarname}.length`, `PipeError.rootFrom(${errorsVarname})`),\n\t\t\t\t\t\t`${input} = ${resVarname}`,\n\t\t\t\t\t]),\n\t\t],\n\t\t{\n\t\t\tschema: () => ({\n\t\t\t\ttype: 'array',\n\t\t\t\titems: branches.map((pipe) => schema(pipe)),\n\t\t\t\tminItems: branches.length,\n\t\t\t\tmaxItems: branches.length,\n\t\t\t}),\n\t\t},\n\t)\n}\n\nexport const asSet = <T>(keyFn: (i: T) => PropertyKey = (v) => v as string) => {\n\tconst varname = `obj_${getRandomValue()}`\n\treturn standard<T[], T[]>(\n\t\t({ input, context }) => [\n\t\t\t`const ${varname} = {}`,\n\t\t\t`${input} = ${input}.reduce((acc, cur) => {`,\n\t\t\t`\tconst key = ${context}.keyFn(cur)`,\n\t\t\t`\tif (!${varname}[key]) {`,\n\t\t\t`\t\t${varname}[key] = true`,\n\t\t\t`\t\tacc.push(cur)`,\n\t\t\t`\t}`,\n\t\t\t`\treturn acc`,\n\t\t\t`}, [])`,\n\t\t],\n\t\t{\n\t\t\tcontext: { keyFn },\n\t\t},\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAgD;AAChD,uBAA+B;AAExB,MAAM,QAAQ,CAA2B,QAAW,MAAM,sBAAsB;AACtF,QAAM,gBAAgB,cAAU,iCAAe,CAAC;AAChD,QAAM,aAAa,WAAO,iCAAe,CAAC;AAC1C,QAAM,mBAAmB,iBAAa,iCAAe,CAAC;AACtD,aAAO;AAAA,IACN,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS;AAAA,MAC1B,KAAK,UAAU,kBAAkB,KAAK,KAAK,mBAAmB,GAAG,MAAM,KAAK,KAAK,IAAI,GAAG;AAAA,MACxF,KAAK,YAAY,KAAK,SAAS,aAAa;AAAA,MAC5C,SAAS,UAAU;AAAA,MACnB,OAAO,gBAAgB;AAAA,MACvB,2BAA2B,KAAK;AAAA,MAChC,IAAI,gBAAgB,MAAM,KAAK;AAAA,MAC/B,OAAG,4BAAc,EAAE,MAAM,MAAM,QAAQ,OAAO,kBAAkB,WAAW,UAAU,KAAK,iBAAiB,CAAC;AAAA,MAC5G,KAAK,YACF,OAAO,gBAAgB,0BAA0B,KAAK,UAAU,OAAO,wBAAwB,gBAAgB,MAAM,gBAAgB,GAAG,CAAC,KACzI,QAAQ,gBAAgB,0BAA0B,aAAa,8BAA8B,gBAAgB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