valleyed 4.5.14 → 4.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/api/arrays.cjs +2 -2
- package/dist/cjs/api/arrays.cjs.map +1 -1
- package/dist/cjs/api/arrays.min.cjs +1 -1
- package/dist/cjs/api/arrays.min.cjs.map +1 -1
- package/dist/cjs/api/base/errors.cjs +15 -4
- package/dist/cjs/api/base/errors.cjs.map +1 -1
- package/dist/cjs/api/base/errors.min.cjs +2 -2
- package/dist/cjs/api/base/errors.min.cjs.map +1 -1
- package/dist/cjs/api/base/pipes.cjs +4 -6
- package/dist/cjs/api/base/pipes.cjs.map +1 -1
- package/dist/cjs/api/base/pipes.min.cjs +2 -2
- package/dist/cjs/api/base/pipes.min.cjs.map +1 -1
- package/dist/cjs/api/junctions.cjs +3 -2
- package/dist/cjs/api/junctions.cjs.map +1 -1
- package/dist/cjs/api/junctions.min.cjs +1 -1
- package/dist/cjs/api/junctions.min.cjs.map +1 -1
- package/dist/cjs/api/optionals.cjs +2 -2
- package/dist/cjs/api/optionals.cjs.map +1 -1
- package/dist/cjs/api/optionals.min.cjs +1 -1
- package/dist/cjs/api/optionals.min.cjs.map +1 -1
- package/dist/cjs/api/records.cjs +10 -4
- package/dist/cjs/api/records.cjs.map +1 -1
- package/dist/cjs/api/records.min.cjs +1 -1
- package/dist/cjs/api/records.min.cjs.map +1 -1
- package/dist/esm/api/arrays.min.mjs +1 -1
- package/dist/esm/api/arrays.min.mjs.map +1 -1
- package/dist/esm/api/arrays.mjs +2 -2
- package/dist/esm/api/arrays.mjs.map +1 -1
- package/dist/esm/api/base/errors.min.mjs +2 -2
- package/dist/esm/api/base/errors.min.mjs.map +1 -1
- package/dist/esm/api/base/errors.mjs +15 -4
- package/dist/esm/api/base/errors.mjs.map +1 -1
- package/dist/esm/api/base/pipes.min.mjs +2 -2
- package/dist/esm/api/base/pipes.min.mjs.map +1 -1
- package/dist/esm/api/base/pipes.mjs +4 -6
- package/dist/esm/api/base/pipes.mjs.map +1 -1
- package/dist/esm/api/junctions.min.mjs +1 -1
- package/dist/esm/api/junctions.min.mjs.map +1 -1
- package/dist/esm/api/junctions.mjs +3 -2
- package/dist/esm/api/junctions.mjs.map +1 -1
- package/dist/esm/api/optionals.min.mjs +1 -1
- package/dist/esm/api/optionals.min.mjs.map +1 -1
- package/dist/esm/api/optionals.mjs +3 -3
- package/dist/esm/api/optionals.mjs.map +1 -1
- package/dist/esm/api/records.min.mjs +1 -1
- package/dist/esm/api/records.min.mjs.map +1 -1
- package/dist/esm/api/records.mjs +10 -4
- package/dist/esm/api/records.mjs.map +1 -1
- package/dist/types/api/arrays.d.ts +1 -1
- package/dist/types/api/arrays.js +2 -2
- package/dist/types/api/base/errors.d.ts +1 -1
- package/dist/types/api/base/errors.js +15 -4
- package/dist/types/api/base/index.d.ts +1 -1
- package/dist/types/api/base/pipes.d.ts +3 -3
- package/dist/types/api/base/pipes.js +4 -6
- package/dist/types/api/base/types.d.ts +1 -1
- package/dist/types/api/coerce.d.ts +1 -1
- package/dist/types/api/core.d.ts +1 -1
- package/dist/types/api/externals.d.ts +1 -1
- package/dist/types/api/files.d.ts +1 -1
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/junctions.d.ts +1 -1
- package/dist/types/api/junctions.js +3 -2
- package/dist/types/api/numbers.d.ts +1 -1
- package/dist/types/api/optionals.d.ts +1 -1
- package/dist/types/api/optionals.js +3 -3
- package/dist/types/api/records.d.ts +1 -1
- package/dist/types/api/records.js +10 -4
- package/dist/types/api/strings.d.ts +1 -1
- package/dist/types/api/times.d.ts +1 -1
- package/dist/types/api/types.d.ts +1 -1
- package/dist/types/{errors-C1ef9q7I.d.ts → errors-B_b7Rsqj.d.ts} +2 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [4.5.15](https://github.com/kevinand11/valleyed/compare/v4.5.14...v4.5.15) (2025-07-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* path for PipeError ([9c1a49d](https://github.com/kevinand11/valleyed/commit/9c1a49d12d64f39bf1df49fe34683be1469e31e3))
|
|
11
|
+
|
|
5
12
|
### [4.5.14](https://github.com/kevinand11/valleyed/compare/v4.5.13...v4.5.14) (2025-07-06)
|
|
6
13
|
|
|
7
14
|
|
package/dist/cjs/api/arrays.cjs
CHANGED
|
@@ -37,8 +37,8 @@ const array = (branch, err = "is not an array") => {
|
|
|
37
37
|
`let ${validatedVarname}`,
|
|
38
38
|
`for (let idx = 0; idx < ${input}.length; idx++) {`,
|
|
39
39
|
` ${validatedVarname} = ${input}[idx]`,
|
|
40
|
-
...(0, import_pipes.compileNested)({ opts, pipe: branch, input: validatedVarname, errorType: "assign" }),
|
|
41
|
-
opts.failEarly ? `if (${validatedVarname} instanceof PipeError) ${opts.wrapError.format(`PipeError.path(idx, ${validatedVarname})`)}` : ` if (${validatedVarname} instanceof PipeError) ${errorsVarname}.push(PipeError.path(idx, ${validatedVarname}))`,
|
|
40
|
+
...(0, import_pipes.compileNested)({ opts, pipe: branch, input: validatedVarname, errorType: "assign", key: validatedVarname }),
|
|
41
|
+
opts.failEarly ? `if (${validatedVarname} instanceof PipeError) ${opts.wrapError.format(`PipeError.path(idx, '${validatedVarname}', ${validatedVarname})`)}` : ` if (${validatedVarname} instanceof PipeError) ${errorsVarname}.push(PipeError.path(idx, '${validatedVarname}', ${validatedVarname}))`,
|
|
42
42
|
` else ${resVarname}[idx] = ${validatedVarname}`,
|
|
43
43
|
`}`,
|
|
44
44
|
opts.failEarly ? "" : opts.wrapError(`${errorsVarname}.length`, `PipeError.rootFrom(${errorsVarname})`),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/arrays.ts"],"sourcesContent":["import { PipeInput, type Pipe, type 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' }),\n\t\t\topts.failEarly\n\t\t\t\t? `if (${validatedVarname} instanceof PipeError) ${opts.wrapError.format(`PipeError.path(idx, ${validatedVarname})`)}`\n\t\t\t\t: `\tif (${validatedVarname} instanceof PipeError) ${errorsVarname}.push(PipeError.path(idx, ${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,
|
|
1
|
+
{"version":3,"sources":["../../../src/api/arrays.ts"],"sourcesContent":["import { PipeInput, type Pipe, type 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`\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AAa,WAAW,sBAAsB,aAAa,GAAG;AAAA,QACtG,GAAG,KAAK,MAAM,UAAU;AAAA,MACzB;AAAA,IACH;AAAA,IACA;AAAA,MACC,QAAQ,OAAO;AAAA,QACd,MAAM;AAAA,QACN,OAAO,SAAS,IAAI,CAAC,aAAS,qBAAO,IAAI,CAAC;AAAA,QAC1C,UAAU,SAAS;AAAA,QACnB,UAAU,SAAS;AAAA,MACpB;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,QAAQ,CAAI,QAA+B,CAAC,MAAM,MAAgB;AAC9E,QAAM,UAAU,WAAO,iCAAe,CAAC;AACvC,aAAO;AAAA,IACN,CAAC,EAAE,OAAO,QAAQ,MAAM;AAAA,MACvB,SAAS,OAAO;AAAA,MAChB,GAAG,KAAK,MAAM,KAAK;AAAA,MACnB,gBAAgB,OAAO;AAAA,MACvB,SAAS,OAAO;AAAA,MAChB,KAAK,OAAO;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,MACC,SAAS,EAAE,MAAM;AAAA,IAClB;AAAA,EACD;AACD;","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var P=(a,e)=>{for(var $ in e)c(a,$,{get:e[$],enumerable:!0})},T=(a,e,$,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of f(e))!E.call(a,r)&&r!==$&&c(a,r,{get:()=>e[r],enumerable:!(n=m(e,r))||n.enumerable});return a};var u=a=>T(c({},"__esModule",{value:!0}),a);var k={};P(k,{array:()=>d,asSet:()=>h,tuple:()=>g});module.exports=u(k);var p=require('./base/pipes.min.cjs'),s=require('../utils/functions/index.min.cjs');const d=(a,e="is not an array")=>{const $=`errors_${(0,s.getRandomValue)()}`,n=`res_${(0,s.getRandomValue)()}`,r=`validated_${(0,s.getRandomValue)()}`;return(0,p.standard)(({input:t,path:y},o)=>[o.wrapError(`!Array.isArray(${t})`,`PipeError.root('${e}', ${t}, ${y})`),o.failEarly?"":`const ${$} = []`,`const ${n} = []`,`let ${r}`,`for (let idx = 0; idx < ${t}.length; idx++) {`,` ${r} = ${t}[idx]`,...(0,p.compileNested)({opts:o,pipe:a,input:r,errorType:"assign"}),o.failEarly?`if (${r} instanceof PipeError) ${o.wrapError.format(`PipeError.path(idx, ${r})`)}`:` if (${r} instanceof PipeError) ${$}.push(PipeError.path(idx, ${r}))`,` else ${n}[idx] = ${r}`,"}",o.failEarly?"":o.wrapError(`${$}.length`,`PipeError.rootFrom(${$})`),o.wrapError(`${t} instanceof PipeError`,`${t}`),`${t} = ${n}`],{schema:()=>({type:"array",items:(0,p.schema)(a)})})},g=(a,e="is not an array")=>{const $=`errors_${(0,s.getRandomValue)()}`,n=`res_${(0,s.getRandomValue)()}`,r=`validated_${(0,s.getRandomValue)()}`;return(0,p.standard)(({input:t,path:y},o)=>[o.wrapError(`!Array.isArray(${t})`,`PipeError.root('${e}', ${t}, ${y})`),...a.length===0?[]:[`const ${n} = []`,o.failEarly?"":`const ${$} = []`,...a.flatMap((l,i)=>[`let ${r}${i} = ${t}[${i}]`,...(0,p.compileNested)({opts:o,pipe:l,input:`${r}${i}`,key:`${i}`,errorType:"assign"}),o.failEarly?o.wrapError(`${r}${i} instanceof PipeError`,`${r}${i}`):` if (${r}${i} instanceof PipeError) ${$}.push(${r}${i})`,`if (!(${r}${i} instanceof PipeError)) ${n}[${i}] = ${r}${i}`]),o.failEarly?"":o.wrapError(`${$}.length`,`PipeError.rootFrom(${$})`),`${t} = ${n}`]],{schema:()=>({type:"array",items:a.map(t=>(0,p.schema)(t)),minItems:a.length,maxItems:a.length})})},h=(a=e=>e)=>{const e=`obj_${(0,s.getRandomValue)()}`;return(0,p.standard)(({input:$,context:n})=>[`const ${e} = {}`,`${$} = ${$}.reduce((acc, cur) => {`,` const key = ${n}.keyFn(cur)`,` if (!${e}[key]) {`,` ${e}[key] = true`," acc.push(cur)"," }"," return acc","}, [])"],{context:{keyFn:a}})};0&&(module.exports={array,asSet,tuple});
|
|
1
|
+
"use strict";var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var P=(a,e)=>{for(var $ in e)c(a,$,{get:e[$],enumerable:!0})},T=(a,e,$,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of f(e))!E.call(a,r)&&r!==$&&c(a,r,{get:()=>e[r],enumerable:!(n=m(e,r))||n.enumerable});return a};var u=a=>T(c({},"__esModule",{value:!0}),a);var k={};P(k,{array:()=>d,asSet:()=>h,tuple:()=>g});module.exports=u(k);var p=require('./base/pipes.min.cjs'),s=require('../utils/functions/index.min.cjs');const d=(a,e="is not an array")=>{const $=`errors_${(0,s.getRandomValue)()}`,n=`res_${(0,s.getRandomValue)()}`,r=`validated_${(0,s.getRandomValue)()}`;return(0,p.standard)(({input:t,path:y},o)=>[o.wrapError(`!Array.isArray(${t})`,`PipeError.root('${e}', ${t}, ${y})`),o.failEarly?"":`const ${$} = []`,`const ${n} = []`,`let ${r}`,`for (let idx = 0; idx < ${t}.length; idx++) {`,` ${r} = ${t}[idx]`,...(0,p.compileNested)({opts:o,pipe:a,input:r,errorType:"assign",key:r}),o.failEarly?`if (${r} instanceof PipeError) ${o.wrapError.format(`PipeError.path(idx, '${r}', ${r})`)}`:` if (${r} instanceof PipeError) ${$}.push(PipeError.path(idx, '${r}', ${r}))`,` else ${n}[idx] = ${r}`,"}",o.failEarly?"":o.wrapError(`${$}.length`,`PipeError.rootFrom(${$})`),o.wrapError(`${t} instanceof PipeError`,`${t}`),`${t} = ${n}`],{schema:()=>({type:"array",items:(0,p.schema)(a)})})},g=(a,e="is not an array")=>{const $=`errors_${(0,s.getRandomValue)()}`,n=`res_${(0,s.getRandomValue)()}`,r=`validated_${(0,s.getRandomValue)()}`;return(0,p.standard)(({input:t,path:y},o)=>[o.wrapError(`!Array.isArray(${t})`,`PipeError.root('${e}', ${t}, ${y})`),...a.length===0?[]:[`const ${n} = []`,o.failEarly?"":`const ${$} = []`,...a.flatMap((l,i)=>[`let ${r}${i} = ${t}[${i}]`,...(0,p.compileNested)({opts:o,pipe:l,input:`${r}${i}`,key:`${i}`,errorType:"assign"}),o.failEarly?o.wrapError(`${r}${i} instanceof PipeError`,`${r}${i}`):` if (${r}${i} instanceof PipeError) ${$}.push(${r}${i})`,`if (!(${r}${i} instanceof PipeError)) ${n}[${i}] = ${r}${i}`]),o.failEarly?"":o.wrapError(`${$}.length`,`PipeError.rootFrom(${$})`),`${t} = ${n}`]],{schema:()=>({type:"array",items:a.map(t=>(0,p.schema)(t)),minItems:a.length,maxItems:a.length})})},h=(a=e=>e)=>{const e=`obj_${(0,s.getRandomValue)()}`;return(0,p.standard)(({input:$,context:n})=>[`const ${e} = {}`,`${$} = ${$}.reduce((acc, cur) => {`,` const key = ${n}.keyFn(cur)`,` if (!${e}[key]) {`,` ${e}[key] = true`," acc.push(cur)"," }"," return acc","}, [])"],{context:{keyFn:a}})};0&&(module.exports={array,asSet,tuple});
|
|
2
2
|
//# sourceMappingURL=arrays.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/arrays.ts"],"sourcesContent":["import { PipeInput, type Pipe, type 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' }),\n\t\t\topts.failEarly\n\t\t\t\t? `if (${validatedVarname} instanceof PipeError) ${opts.wrapError.format(`PipeError.path(idx, ${validatedVarname})`)}`\n\t\t\t\t: `\tif (${validatedVarname} instanceof PipeError) ${errorsVarname}.push(PipeError.path(idx, ${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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,UAAAC,EAAA,UAAAC,IAAA,eAAAC,EAAAL,GACA,IAAAM,EAAgD,wBAChDC,EAA+B,8BAExB,MAAML,EAAQ,CAA2BM,EAAWC,EAAM,oBAAsB,CACtF,MAAMC,EAAgB,aAAU,kBAAe,CAAC,GAC1CC,EAAa,UAAO,kBAAe,CAAC,GACpCC,EAAmB,gBAAa,kBAAe,CAAC,GACtD,SAAO,YACN,CAAC,CAAE,MAAAC,EAAO,KAAAC,CAAK,EAAGC,IAAS,CAC1BA,EAAK,UAAU,kBAAkBF,CAAK,IAAK,mBAAmBJ,CAAG,MAAMI,CAAK,KAAKC,CAAI,GAAG,EACxFC,EAAK,UAAY,GAAK,SAASL,CAAa,QAC5C,SAASC,CAAU,QACnB,OAAOC,CAAgB,GACvB,2BAA2BC,CAAK,oBAChC,IAAID,CAAgB,MAAMC,CAAK,QAC/B,MAAG,iBAAc,CAAE,KAAAE,EAAM,KAAMP,EAAQ,MAAOI,EAAkB,UAAW,
|
|
1
|
+
{"version":3,"sources":["../../../src/api/arrays.ts"],"sourcesContent":["import { PipeInput, type Pipe, type 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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,UAAAC,EAAA,UAAAC,IAAA,eAAAC,EAAAL,GACA,IAAAM,EAAgD,wBAChDC,EAA+B,8BAExB,MAAML,EAAQ,CAA2BM,EAAWC,EAAM,oBAAsB,CACtF,MAAMC,EAAgB,aAAU,kBAAe,CAAC,GAC1CC,EA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","__export","array","asSet","tuple","__toCommonJS","import_pipes","import_functions","branch","err","errorsVarname","resVarname","validatedVarname","input","path","opts","branches","idx","pipe","keyFn","v","varname","context"]}
|
|
@@ -38,11 +38,22 @@ class PipeError {
|
|
|
38
38
|
static rootFrom(errors) {
|
|
39
39
|
return new PipeError(errors.flatMap((error) => error.messages));
|
|
40
40
|
}
|
|
41
|
-
static path(path, error) {
|
|
42
|
-
if (path === 0
|
|
43
|
-
if (!path) return error;
|
|
41
|
+
static path(path, key, error) {
|
|
42
|
+
if (path === void 0 || path === null) return error;
|
|
44
43
|
return new PipeError(
|
|
45
|
-
error.messages.map((message) => ({
|
|
44
|
+
error.messages.map((message) => ({
|
|
45
|
+
...message,
|
|
46
|
+
path: message.path?.split(".").map((p) => p == key ? path.toString() : p).join(".")
|
|
47
|
+
}))
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
static wrap(path, error) {
|
|
51
|
+
if (path === void 0 || path === null) return error;
|
|
52
|
+
return new PipeError(
|
|
53
|
+
error.messages.map((message) => ({
|
|
54
|
+
...message,
|
|
55
|
+
path: [path.toString(), message.path].filter(Boolean).join(".")
|
|
56
|
+
}))
|
|
46
57
|
);
|
|
47
58
|
}
|
|
48
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/api/base/errors.ts"],"sourcesContent":["import { PipeErrorHandler } from './types'\n\ntype PipeErrorMessage = { message: string; path?: string; value: unknown }\n\nfunction formatError(message: PipeErrorMessage) {\n\treturn `${message.path ? `${message.path}: ` : ''}${message.message}`\n}\n\nexport class PipeError {\n\tconstructor(public messages: PipeErrorMessage[]) {}\n\n\ttoString() {\n\t\treturn this.messages.map(formatError).join('\\n')\n\t}\n\n\tstatic root(message: string, value: unknown, path?: string) {\n\t\treturn new PipeError([{ message, path, value }])\n\t}\n\n\tstatic rootFrom(errors: PipeError[]) {\n\t\treturn new PipeError(errors.flatMap((error) => error.messages))\n\t}\n\n\tstatic path(path: PropertyKey, error: PipeError) {\n\t\tif (path ===
|
|
1
|
+
{"version":3,"sources":["../../../../src/api/base/errors.ts"],"sourcesContent":["import { PipeErrorHandler } from './types'\n\ntype PipeErrorMessage = { message: string; path?: string; value: unknown }\n\nfunction formatError(message: PipeErrorMessage) {\n\treturn `${message.path ? `${message.path}: ` : ''}${message.message}`\n}\n\nexport class PipeError {\n\tconstructor(public messages: PipeErrorMessage[]) {}\n\n\ttoString() {\n\t\treturn this.messages.map(formatError).join('\\n')\n\t}\n\n\tstatic root(message: string, value: unknown, path?: string) {\n\t\treturn new PipeError([{ message, path, value }])\n\t}\n\n\tstatic rootFrom(errors: PipeError[]) {\n\t\treturn new PipeError(errors.flatMap((error) => error.messages))\n\t}\n\n\tstatic path(path: PropertyKey, key: string, error: PipeError) {\n\t\tif (path === undefined || path === null) return error\n\t\treturn new PipeError(\n\t\t\terror.messages.map((message) => ({\n\t\t\t\t...message,\n\t\t\t\tpath: message.path\n\t\t\t\t\t?.split('.')\n\t\t\t\t\t.map((p) => (p == key ? path.toString() : p))\n\t\t\t\t\t.join('.'),\n\t\t\t})),\n\t\t)\n\t}\n\n\tstatic wrap(path: PropertyKey, error: PipeError) {\n\t\tif (path === undefined || path === null) return error\n\t\treturn new PipeError(\n\t\t\terror.messages.map((message) => ({\n\t\t\t\t...message,\n\t\t\t\tpath: [path.toString(), message.path].filter(Boolean).join('.'),\n\t\t\t})),\n\t\t)\n\t}\n}\n\nexport function createErrorHandler(input: string, type: 'return' | 'throw' | 'assign'): PipeErrorHandler {\n\tconst handler: PipeErrorHandler = Object.assign(\n\t\t(...args: Parameters<PipeErrorHandler>) =>\n\t\t\t(lines: string[]) => {\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'return':\n\t\t\t\t\tcase 'throw':\n\t\t\t\t\t\treturn [`if (${args[0]}) ${handler.format(args[1])}`, ...lines]\n\t\t\t\t\tcase 'assign':\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t`if (${args[0]}) ${handler.format(args[1])}`,\n\t\t\t\t\t\t\t...(lines.length ? [`else {`, ...lines.map((l) => `\t${l}`), `}`] : []),\n\t\t\t\t\t\t]\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(`Unknown error handling type: ${type satisfies never}`)\n\t\t\t\t}\n\t\t\t},\n\t\t{\n\t\t\ttype,\n\t\t\tformat: (error: string) => {\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'return':\n\t\t\t\t\t\treturn `return ${error}`\n\t\t\t\t\tcase 'throw':\n\t\t\t\t\t\treturn `throw ${error}`\n\t\t\t\t\tcase 'assign':\n\t\t\t\t\t\treturn `${input} = ${error}`\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(`Unknown error handling type: ${type satisfies never}`)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\n\treturn handler\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,SAAS,YAAY,SAA2B;AAC/C,SAAO,GAAG,QAAQ,OAAO,GAAG,QAAQ,IAAI,OAAO,EAAE,GAAG,QAAQ,OAAO;AACpE;AAEO,MAAM,UAAU;AAAA,EACtB,YAAmB,UAA8B;AAA9B;AAAA,EAA+B;AAAA,EAElD,WAAW;AACV,WAAO,KAAK,SAAS,IAAI,WAAW,EAAE,KAAK,IAAI;AAAA,EAChD;AAAA,EAEA,OAAO,KAAK,SAAiB,OAAgB,MAAe;AAC3D,WAAO,IAAI,UAAU,CAAC,EAAE,SAAS,MAAM,MAAM,CAAC,CAAC;AAAA,EAChD;AAAA,EAEA,OAAO,SAAS,QAAqB;AACpC,WAAO,IAAI,UAAU,OAAO,QAAQ,CAAC,UAAU,MAAM,QAAQ,CAAC;AAAA,EAC/D;AAAA,EAEA,OAAO,KAAK,MAAmB,KAAa,OAAkB;AAC7D,QAAI,SAAS,UAAa,SAAS,KAAM,QAAO;AAChD,WAAO,IAAI;AAAA,MACV,MAAM,SAAS,IAAI,CA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,mBAAO,GAAG,KAAK,MAAM,KAAK;AAAA,UAC3B;AACC,kBAAM,IAAI,MAAM,gCAAgC,IAAoB,EAAE;AAAA,QACxE;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;","names":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var
|
|
2
|
-
`)}static root(r,e
|
|
1
|
+
"use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var g=(t,r)=>{for(var n in r)o(t,n,{get:r[n],enumerable:!0})},l=(t,r,n,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of p(r))!c.call(t,s)&&s!==n&&o(t,s,{get:()=>r[s],enumerable:!(e=u(r,s))||e.enumerable});return t};var f=t=>l(o({},"__esModule",{value:!0}),t);var m={};g(m,{PipeError:()=>a,createErrorHandler:()=>h});module.exports=f(m);function w(t){return`${t.path?`${t.path}: `:""}${t.message}`}class a{constructor(r){this.messages=r}toString(){return this.messages.map(w).join(`
|
|
2
|
+
`)}static root(r,n,e){return new a([{message:r,path:e,value:n}])}static rootFrom(r){return new a(r.flatMap(n=>n.messages))}static path(r,n,e){return r==null?e:new a(e.messages.map(s=>({...s,path:s.path?.split(".").map(i=>i==n?r.toString():i).join(".")})))}static wrap(r,n){return r==null?n:new a(n.messages.map(e=>({...e,path:[r.toString(),e.path].filter(Boolean).join(".")})))}}function h(t,r){const n=Object.assign((...e)=>s=>{switch(r){case"return":case"throw":return[`if (${e[0]}) ${n.format(e[1])}`,...s];case"assign":return[`if (${e[0]}) ${n.format(e[1])}`,...s.length?["else {",...s.map(i=>` ${i}`),"}"]:[]];default:throw new Error(`Unknown error handling type: ${r}`)}},{type:r,format:e=>{switch(r){case"return":return`return ${e}`;case"throw":return`throw ${e}`;case"assign":return`${t} = ${e}`;default:throw new Error(`Unknown error handling type: ${r}`)}}});return n}0&&(module.exports={PipeError,createErrorHandler});
|
|
3
3
|
//# sourceMappingURL=errors.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/api/base/errors.ts"],"sourcesContent":["import { PipeErrorHandler } from './types'\n\ntype PipeErrorMessage = { message: string; path?: string; value: unknown }\n\nfunction formatError(message: PipeErrorMessage) {\n\treturn `${message.path ? `${message.path}: ` : ''}${message.message}`\n}\n\nexport class PipeError {\n\tconstructor(public messages: PipeErrorMessage[]) {}\n\n\ttoString() {\n\t\treturn this.messages.map(formatError).join('\\n')\n\t}\n\n\tstatic root(message: string, value: unknown, path?: string) {\n\t\treturn new PipeError([{ message, path, value }])\n\t}\n\n\tstatic rootFrom(errors: PipeError[]) {\n\t\treturn new PipeError(errors.flatMap((error) => error.messages))\n\t}\n\n\tstatic path(path: PropertyKey, error: PipeError) {\n\t\tif (path ===
|
|
1
|
+
{"version":3,"sources":["../../../../src/api/base/errors.ts"],"sourcesContent":["import { PipeErrorHandler } from './types'\n\ntype PipeErrorMessage = { message: string; path?: string; value: unknown }\n\nfunction formatError(message: PipeErrorMessage) {\n\treturn `${message.path ? `${message.path}: ` : ''}${message.message}`\n}\n\nexport class PipeError {\n\tconstructor(public messages: PipeErrorMessage[]) {}\n\n\ttoString() {\n\t\treturn this.messages.map(formatError).join('\\n')\n\t}\n\n\tstatic root(message: string, value: unknown, path?: string) {\n\t\treturn new PipeError([{ message, path, value }])\n\t}\n\n\tstatic rootFrom(errors: PipeError[]) {\n\t\treturn new PipeError(errors.flatMap((error) => error.messages))\n\t}\n\n\tstatic path(path: PropertyKey, key: string, error: PipeError) {\n\t\tif (path === undefined || path === null) return error\n\t\treturn new PipeError(\n\t\t\terror.messages.map((message) => ({\n\t\t\t\t...message,\n\t\t\t\tpath: message.path\n\t\t\t\t\t?.split('.')\n\t\t\t\t\t.map((p) => (p == key ? path.toString() : p))\n\t\t\t\t\t.join('.'),\n\t\t\t})),\n\t\t)\n\t}\n\n\tstatic wrap(path: PropertyKey, error: PipeError) {\n\t\tif (path === undefined || path === null) return error\n\t\treturn new PipeError(\n\t\t\terror.messages.map((message) => ({\n\t\t\t\t...message,\n\t\t\t\tpath: [path.toString(), message.path].filter(Boolean).join('.'),\n\t\t\t})),\n\t\t)\n\t}\n}\n\nexport function createErrorHandler(input: string, type: 'return' | 'throw' | 'assign'): PipeErrorHandler {\n\tconst handler: PipeErrorHandler = Object.assign(\n\t\t(...args: Parameters<PipeErrorHandler>) =>\n\t\t\t(lines: string[]) => {\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'return':\n\t\t\t\t\tcase 'throw':\n\t\t\t\t\t\treturn [`if (${args[0]}) ${handler.format(args[1])}`, ...lines]\n\t\t\t\t\tcase 'assign':\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t`if (${args[0]}) ${handler.format(args[1])}`,\n\t\t\t\t\t\t\t...(lines.length ? [`else {`, ...lines.map((l) => `\t${l}`), `}`] : []),\n\t\t\t\t\t\t]\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(`Unknown error handling type: ${type satisfies never}`)\n\t\t\t\t}\n\t\t\t},\n\t\t{\n\t\t\ttype,\n\t\t\tformat: (error: string) => {\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'return':\n\t\t\t\t\t\treturn `return ${error}`\n\t\t\t\t\tcase 'throw':\n\t\t\t\t\t\treturn `throw ${error}`\n\t\t\t\t\tcase 'assign':\n\t\t\t\t\t\treturn `${input} = ${error}`\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(`Unknown error handling type: ${type satisfies never}`)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\n\treturn handler\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,uBAAAC,IAAA,eAAAC,EAAAJ,GAIA,SAASK,EAAYC,EAA2B,CAC/C,MAAO,GAAGA,EAAQ,KAAO,GAAGA,EAA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AAOC,EAAK,CAAC,CAAC,CAAC,GAC1C,GAAIC,EAAM,OAAS,CAAC,SAAU,GAAGA,EAAM,IAAKC,GAAM,IAAIA,CAAC,EAAE,EAAG,GAAG,EAAI,CAAC,CACrE,EACD,QACC,MAAM,IAAI,MAAM,gCAAgCJ,CAAoB,EAAE,CACxE,CACD,EACD,CACC,KAAAA,EACA,OAASJ,GAAkB,CAC1B,OAAQI,EAAM,CACb,IAAK,SACJ,MAAO,UAAUJ,CAAK,GACvB,IAAK,QACJ,MAAO,SAASA,CAAK,GACtB,IAAK,SACJ,MAAO,GAAGG,CAAK,MAAMH,CAAK,GAC3B,QACC,MAAM,IAAI,MAAM,gCAAgCI,CAAoB,EAAE,CACxE,CACD,CACD,CACD,EAEA,OAAOC,CACR","names":["errors_exports","__export","PipeError","createErrorHandler","__toCommonJS","formatError","message","messages","value","path","errors","error","key","p","input","type","handler","args","lines","l"]}
|
|
@@ -65,16 +65,14 @@ function schema(pipe, schema2 = {}) {
|
|
|
65
65
|
function meta(p, meta2) {
|
|
66
66
|
return p.pipe(standard(() => [], { schema: () => meta2 }));
|
|
67
67
|
}
|
|
68
|
-
function compile(pipe, {
|
|
69
|
-
failEarly = true
|
|
70
|
-
} = {}) {
|
|
68
|
+
function compile(pipe, opts = {}) {
|
|
71
69
|
const inputStr = "input";
|
|
72
70
|
const contextStr = "context";
|
|
73
71
|
const { lines, context: context2 } = compilePipeToString({
|
|
74
72
|
pipe,
|
|
75
73
|
input: inputStr,
|
|
76
74
|
context: contextStr,
|
|
77
|
-
failEarly,
|
|
75
|
+
failEarly: !opts.allErrors,
|
|
78
76
|
base: [`return ${inputStr}`]
|
|
79
77
|
});
|
|
80
78
|
const allLines = [
|
|
@@ -121,9 +119,9 @@ function standard(compile2, config = {}) {
|
|
|
121
119
|
function define(fn, config = {}) {
|
|
122
120
|
const key = `define_${(0, import_functions.getRandomValue)()}`;
|
|
123
121
|
return standard(
|
|
124
|
-
({ input, context: context2, path }) => [
|
|
122
|
+
({ input, context: context2, path }, opts) => [
|
|
125
123
|
`${input} = ${context2}['${key}'](${input})`,
|
|
126
|
-
|
|
124
|
+
opts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`)
|
|
127
125
|
],
|
|
128
126
|
{
|
|
129
127
|
context: { ...config?.context, [key]: fn },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(\n\tpipe: T,\n\t{\n\t\tfailEarly = true,\n\t}: {\n\t\tfailEarly?: boolean\n\t} = {},\n): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\t`if (${input} instanceof PipeError) return PipeError.path(${path}, ${input})`,\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8C;AAE9C,uBAA+B;AAGxB,SAAS,KAAQ,MAAsB,MAAS,QAA4C;AAClG,MAAI,MAAS;AACb,SAAO,MAAM;AACZ,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,KAAK;AAAA,EACb;AACA,SAAO;AACR;AAEO,SAAS,QAAkC,MAAkB;AACnE,SAAO,KAAK,MAAM,CAAC,GAAc,CAAC,GAAG,SAAS,EAAE,GAAG,KAAK,GAAG,EAAE,QAAQ,EAAE,EAAE;AAC1E;AAEO,SAAS,OAAiC,MAAS,OAA+B;AACxF,QAAM,SAAS,SAAS,MAAM,KAAK;AACnC,MAAI,CAAC,OAAO,MAAO,OAAM,OAAO;AAChC,SAAO,OAAO;AACf;AAEO,SAAS,SACf,MACA,OAC6E;AAC7E,MAAI;AACH,UAAM,KAAK,KAAK,cAAc,QAAQ,IAAI;AAC1C,UAAM,MAAM,GAAG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,OAAO,QAAQ,WAAY,OAAM,IAAI,GAAG;AACjD,WAAO;AAAA,EACR,GAAG,IAAI;AACR;","names":["schema","meta","context","compile"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8C;AAE9C,uBAA+B;AAGxB,SAAS,KAAQ,MAAsB,MAAS,QAA4C;AAClG,MAAI,MAAS;AACb,SAAO,MAAM;AACZ,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,KAAK;AAAA,EACb;AACA,SAAO;AACR;AAEO,SAAS,QAAkC,MAAkB;AACnE,SAAO,KAAK,MAAM,CAAC,GAAc,CAAC,GAAG,SAAS,EAAE,GAAG,KAAK,GAAG,EAAE,QAAQ,EAAE,EAAE;AAC1E;AAEO,SAAS,OAAiC,MAAS,OAA+B;AACxF,QAAM,SAAS,SAAS,MAAM,KAAK;AACnC,MAAI,CAAC,OAAO,MAAO,OAAM,OAAO;AAChC,SAAO,OAAO;AACf;AAEO,SAAS,SACf,MACA,OAC6E;AAC7E,MAAI;AACH,UAAM,KAAK,KAAK,cAAc,QAAQ,IAAI;AAC1C,UAAM,MAAM,GAAG,KAAK;AACpB,WAAO,eAAe,0BAAY,EAAE,OAAO,KAAK,OAAO,MAAM,IAAI,EAAE,OAAO,KAAK,OAAO,KAAK;AAAA,EAC5F,SAAS,OAAO;AACf,QAAI,iBAAiB,w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1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var
|
|
2
|
-
`))(i,
|
|
1
|
+
"use strict";var l=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},O=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!w.call(e,o)&&o!==n&&l(e,o,{get:()=>t[o],enumerable:!(r=$(t,o))||r.enumerable});return e};var S=e=>O(l({},"__esModule",{value:!0}),e);var R={};g(R,{assert:()=>_,compile:()=>T,compileNested:()=>F,context:()=>y,define:()=>h,meta:()=>I,schema:()=>k,standard:()=>f,validate:()=>x,walk:()=>c});module.exports=S(R);var s=require('./errors.min.cjs'),u=require('../../utils/functions/index.min.cjs');function c(e,t,n){let r=t;for(;e;)r=n(e,r),e=e.next;return r}function y(e){return c(e,{},(t,n)=>({...n,...t.context()}))}function _(e,t){const n=x(e,t);if(!n.valid)throw n.error;return n.value}function x(e,t){try{const r=(e.__compiled??T(e))(t);return r instanceof s.PipeError?{error:r,valid:!1}:{value:r,valid:!0}}catch(n){return n instanceof s.PipeError?{error:n,valid:!1}:{error:s.PipeError.root(n instanceof Error?n.message:`${n}`,t,void 0),valid:!1}}}function k(e,t={}){const n=y(e);return c(e,t,(r,o)=>({...o,...r.schema(n)}))}function I(e,t){return e.pipe(f(()=>[],{schema:()=>t}))}function T(e,t={}){const n="input",r="context",{lines:o,context:i}=P({pipe:e,input:n,context:r,failEarly:!t.allErrors,base:[`return ${n}`]}),a=[`return (${n}) => {`,...o.filter(p=>p.trim()!=="").map(p=>` ${p}`),` throw PipeError.root('unhandled root validation', ${n})`,"}"];return e.__compiled=new Function(r,"PipeError",a.join(`
|
|
2
|
+
`))(i,s.PipeError),e.__compiled}function f(e,t={}){const n={context:()=>t.context??{},schema:r=>t.schema?.(r)??{},pipe:(...r)=>{delete n.__compiled;for(const o of r){const i=typeof o=="function"?h(o,t):o;n.next||(n.next=i),n.last&&(n.last.next=i),n.last=i.last??i}return n},compile:e,"~standard":{version:1,vendor:"valleyed",validate(r){const o=x(n,r);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:a})=>({message:i,path:a?a.split("."):void 0}))}}}};return n}function h(e,t={}){const n=`define_${(0,u.getRandomValue)()}`;return f(({input:r,context:o,path:i},a)=>[`${r} = ${o}['${n}'](${r})`,a.wrapError(`${r} instanceof PipeError`,`PipeError.wrap(${i}, ${r})`)],{context:{...t?.context,[n]:e},schema:t?.schema})}function F(e){const t=(0,u.getRandomValue)(),{lines:n,context:r}=P({...e.opts,wrapError:(0,s.createErrorHandler)(e.input,e.errorType??e.opts.wrapError.type),pipe:e.pipe,input:e.input,context:`context[\`${t}\`]`,path:[e.opts.path,"key"in e?e.key:""].filter(Boolean).join(".")||void 0});return e.opts.rootContext[t]=r,n}function P({pipe:e,input:t,context:n,failEarly:r=!1,path:o="",rootContext:i,wrapError:a=(0,s.createErrorHandler)(t,"return"),base:p=[]}){const m=y(e);i??=m;const E=c(e,[],(v,d)=>(d.push(v.compile({input:t,context:n,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:r,path:o,wrapError:a})),d));return{lines:J(p,E.flat()),context:m}}function J(e,t){return(Array.isArray(t)?t:[t]).reduceRight((n,r)=>(typeof r=="string"?n.unshift(r):typeof r=="function"&&(n=r(n)),n),e)}0&&(module.exports={assert,compile,compileNested,context,define,meta,schema,standard,validate,walk});
|
|
3
3
|
//# sourceMappingURL=pipes.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(\n\tpipe: T,\n\t{\n\t\tfailEarly = true,\n\t}: {\n\t\tfailEarly?: boolean\n\t} = {},\n): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\t`if (${input} instanceof PipeError) return PipeError.path(${path}, ${input})`,\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,EAAA,YAAAC,EAAA,kBAAAC,EAAA,YAAAC,EAAA,WAAAC,EAAA,SAAAC,EAAA,WAAAC,EAAA,aAAAC,EAAA,aAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAZ,GAAA,IAAAa,EAA8C,oBAE9CC,EAA+B,iCAGxB,SAASH,EAAQI,EAAsBC,EAASC,EAA4C,CAClG,IAAIC,EAASF,EACb,KAAOD,GACNG,EAAMD,EAAOF,EAAMG,CAAG,EACtBH,EAAOA,EAAK,KAEb,OAAOG,CACR,CAEO,SAASb,EAAkCU,EAAkB,CACnE,OAAOJ,EAAKI,EAAM,CAAC,EAAc,CAACI,EAAGD,KAAS,CAAE,GAAGA,EAAK,GAAGC,EAAE,QAAQ,CAAE,EAAE,CAC1E,CAEO,SAASjB,EAAiCa,EAASK,EAA+B,CACxF,MAAMC,EAASX,EAASK,EAAMK,CAAK,EACnC,GAAI,CAACC,EAAO,MAAO,MAAMA,EAAO,MAChC,OAAOA,EAAO,KACf,CAEO,SAASX,EACfK,EACAK,EAC6E,CAC7E,GAAI,CAEH,MAAME,GADKP,EAAK,YAAcZ,EAAQY,CAAI,GAC3BK,CAAK,EACpB,OAAOE,aAAe,YAAY,CAAE,MAAOA,EAAK,MAAO,EAAM,EAAI,CAAE,MAAOA,EAAK,MAAO,EAAK,CAC5F,OAASC,EAAO,CACf,OAAIA,aAAiB,YAAkB,CAAE,MAAAA,EAAO,MAAO,EAAM,EACtD,CAAE,MAAO,YAAU,KAAKA,aAAiB,MAAQA,EAAM,QAAU,GAAGA,CAAK,GAAIH,EAAO,MAAS,EAAG,MAAO,EAAM,CACrH,CACD,CAEO,SAASZ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zBuB,CACR,CAEA,SAASC,EAAoB,CAC5B,KAAAd,EACA,MAAAK,EACA,QAASO,EACT,UAAAF,EAAY,GACZ,KAAAc,EAAO,GACP,YAAAK,EACA,UAAAC,KAAY,sBAAmBzB,EAAO,QAAQ,EAC9C,KAAA0B,EAAO,CAAC,CACT,EASG,CACF,MAAMC,EAAM1C,EAAQU,CAAI,EACxB6B,IAAgBG,EAChB,MAAMC,EAAWrC,EAAKI,EAA+C,CAAC,EAAG,CAACI,EAAGD,KAC5EA,EAAI,KACHC,EAAE,QACD,CAAE,MAAAC,EAAO,QAASO,EAAY,KAAM,GAAGY,EAAO,IAAIA,CAAI,IAAM,MAAS,EAAG,EACxE,CAAE,YAAAK,EAAa,UAAAnB,EAAW,KAAAc,EAAM,UAAAM,CAAU,CAC3C,CACD,EACO3B,EACP,EAED,MAAO,CAAE,MADK+B,EAAeH,EAAME,EAAS,KAAK,CAAC,EAClC,QAASD,CAAI,CAC9B,CAEA,SAASE,EAAeH,EAAgBlB,EAA8C,CACrF,OAAQ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,YAAsB,CAACV,EAAKiB,KACvE,OAAOA,GAAQ,SAAUjB,EAAI,QAAQiB,CAAG,EACnC,OAAOA,GAAQ,aAAYjB,EAAMiB,EAAIjB,CAAG,GAC1CA,GACL4B,CAAI,CACR","names":["pipes_exports","__export","assert","compile","compileNested","context","define","meta","schema","standard","validate","walk","__toCommonJS","import_errors","import_functions","pipe","init","nodeFn","acc","p","input","result","res","error","cont","failEarly","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","value","validity","message","path","fn","key","data","random","rootContext","wrapError","base","ctx","compiled","mergePipeLines"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,EAAA,YAAAC,EAAA,kBAAAC,EAAA,YAAAC,EAAA,WAAAC,EAAA,SAAAC,EAAA,WAAAC,EAAA,aAAAC,EAAA,aAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAZ,GAAA,IAAAa,EAA8C,oBAE9CC,EAA+B,iCAGxB,SAASH,EAAQI,EAAsBC,EAASC,EAA4C,CAClG,IAAIC,EAASF,EACb,KAAOD,GACNG,EAAMD,EAAOF,EAAMG,CAAG,EACtBH,EAAOA,EAAK,KAEb,OAAOG,CACR,CAEO,SAASb,EAAkCU,EAAkB,CACnE,OAAOJ,EAAKI,EAAM,CAAC,EAAc,CAACI,EAAGD,KAAS,CAAE,GAAGA,EAAK,GAAGC,EAAE,QAAQ,CAAE,EAAE,CAC1E,CAEO,SAASjB,EAAiCa,EAASK,EAA+B,CACxF,MAAMC,EAASX,EAASK,EAAMK,CAAK,EACnC,GAAI,CAACC,EAAO,MAAO,MAAMA,EAAO,MAChC,OAAOA,EAAO,KACf,CAEO,SAASX,EACfK,EACAK,EAC6E,CAC7E,GAAI,CAEH,MAAME,GADKP,EAAK,YAAcZ,EAAQY,CAAI,GAC3BK,CAAK,EACpB,OAAOE,aAAe,YAAY,CAAE,MAAOA,EAAK,MAAO,EAAM,EAAI,CAAE,MAAOA,EAAK,MAAO,EAAK,CAC5F,OAASC,EAAO,CACf,OAAIA,aAAiB,YAAkB,CAAE,MAAAA,EAAO,MAAO,EAAM,EACtD,CAAE,MAAO,YAAU,KAAKA,aAAiB,MAAQA,EAAM,QAAU,GAAGA,CAAK,GAAIH,EAAO,MAAS,EAAG,MAAO,EAAM,CACrH,CACD,CAEO,SAASZ,EAAiCO,EAAS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AM,EAAItC,EACzBuB,CACR,CAEA,SAASC,EAAoB,CAC5B,KAAAd,EACA,MAAAK,EACA,QAASO,EACT,UAAAiB,EAAY,GACZ,KAAAL,EAAO,GACP,YAAAM,EACA,UAAAC,KAAY,sBAAmB1B,EAAO,QAAQ,EAC9C,KAAA2B,EAAO,CAAC,CACT,EASG,CACF,MAAMC,EAAM3C,EAAQU,CAAI,EACxB8B,IAAgBG,EAChB,MAAMC,EAAWtC,EAAKI,EAA+C,CAAC,EAAG,CAACI,EAAGD,KAC5EA,EAAI,KACHC,EAAE,QACD,CAAE,MAAAC,EAAO,QAASO,EAAY,KAAM,GAAGY,EAAO,IAAIA,CAAI,IAAM,MAAS,EAAG,EACxE,CAAE,YAAAM,EAAa,UAAAD,EAAW,KAAAL,EAAM,UAAAO,CAAU,CAC3C,CACD,EACO5B,EACP,EAED,MAAO,CAAE,MADKgC,EAAeH,EAAME,EAAS,KAAK,CAAC,EAClC,QAASD,CAAI,CAC9B,CAEA,SAASE,EAAeH,EAAgBnB,EAA8C,CACrF,OAAQ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,YAAsB,CAACV,EAAKiB,KACvE,OAAOA,GAAQ,SAAUjB,EAAI,QAAQiB,CAAG,EACnC,OAAOA,GAAQ,aAAYjB,EAAMiB,EAAIjB,CAAG,GAC1CA,GACL6B,CAAI,CACR","names":["pipes_exports","__export","assert","compile","compileNested","context","define","meta","schema","standard","validate","walk","__toCommonJS","import_errors","import_functions","pipe","init","nodeFn","acc","p","input","result","res","error","cont","opts","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","value","validity","message","path","fn","key","data","random","failEarly","rootContext","wrapError","base","ctx","compiled","mergePipeLines"]}
|
|
@@ -42,10 +42,11 @@ const or = (branches) => {
|
|
|
42
42
|
opts: { ...opts, failEarly: true },
|
|
43
43
|
pipe: branch,
|
|
44
44
|
input: validatedVarname,
|
|
45
|
-
errorType: "assign"
|
|
45
|
+
errorType: "assign",
|
|
46
|
+
key: validatedVarname
|
|
46
47
|
}),
|
|
47
48
|
`if (${validatedVarname} instanceof PipeError) {`,
|
|
48
|
-
` ${errorsVarname}.push(PipeError.path(${idx}, ${validatedVarname}))`,
|
|
49
|
+
` ${errorsVarname}.push(PipeError.path(${idx}, '${validatedVarname}', ${validatedVarname}))`,
|
|
49
50
|
...lines.map((l) => ` ${l}`),
|
|
50
51
|
idx === branches.length - 1 ? ` ${opts.wrapError.format(`PipeError.rootFrom(${errorsVarname})`)}` : "",
|
|
51
52
|
`}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { getRandomValue, wrapInTryCatch } from '../utils/functions'\nimport { compileNested, context, standard, schema, define, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any>[]>(branches: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\tconst errorsVarname = `errors_${getRandomValue()}`\n\treturn standard<PipeInput<T[number]>, PipeOutput<T[number]>>(\n\t\t({ input }, opts) =>\n\t\t\tbranches.length === 0\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t`const ${errorsVarname} = []`,\n\t\t\t\t\t\t`let ${validatedVarname}`,\n\t\t\t\t\t\t...branches\n\t\t\t\t\t\t\t.map((branch, idx) => (lines: string[]) => [\n\t\t\t\t\t\t\t\t`${validatedVarname} = ${input}`,\n\t\t\t\t\t\t\t\t...compileNested({\n\t\t\t\t\t\t\t\t\topts: { ...opts, failEarly: true },\n\t\t\t\t\t\t\t\t\tpipe: branch,\n\t\t\t\t\t\t\t\t\tinput: validatedVarname,\n\t\t\t\t\t\t\t\t\terrorType: 'assign',\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\t\t\t\t\t\t`\t${errorsVarname}.push(PipeError.path(${idx}, ${validatedVarname}))`,\n\t\t\t\t\t\t\t\t...lines.map((l) => `\t${l}`),\n\t\t\t\t\t\t\t\tidx === branches.length - 1 ? `\t${opts.wrapError.format(`PipeError.rootFrom(${errorsVarname})`)}` : '',\n\t\t\t\t\t\t\t\t`}`,\n\t\t\t\t\t\t\t\t`else ${input} = ${validatedVarname}`,\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t.reduceRight<string[]>((acc, cur) => cur(acc), []),\n\t\t\t\t\t\topts.wrapError(`${input} instanceof PipeError`, input),\n\t\t\t\t\t],\n\t\t{\n\t\t\tschema: () => ({ oneOf: branches.map((branch) => schema(branch)) }),\n\t\t},\n\t)\n}\n\nexport const merge = <T1 extends Pipe<any, any>, T2 extends Pipe<any, any>>(branch1: T1, branch2: T2) => {\n\tconst inputVarname = `input_${getRandomValue()}`\n\treturn standard<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${inputVarname}A = ${input}`,\n\t\t\t`let ${inputVarname}B = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch1, input: `${inputVarname}A` }),\n\t\t\topts.wrapError(`${inputVarname}A instanceof PipeError`, `${inputVarname}A`),\n\t\t\t...compileNested({ opts, pipe: branch2, input: `${inputVarname}B` }),\n\t\t\topts.wrapError(`${inputVarname}B instanceof PipeError`, `${inputVarname}B`),\n\t\t\t`${input} = ${context}.differMerge(${inputVarname}A, ${inputVarname}B)`,\n\t\t],\n\t\t{\n\t\t\tcontext: { differMerge },\n\t\t\tschema: () => ({ allOf: [schema(branch1), schema(branch2)] }),\n\t\t},\n\t)\n}\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tbranches: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tstandard<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`switch (${context}.wrapInTryCatch(() => ${context}.discriminator(${input}))) {`,\n\t\t\t...Object.entries(branches).flatMap(([key, branch]) => [\n\t\t\t\t`\tcase ('${key}'): {`,\n\t\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => `\t\t${l}`),\n\t\t\t\t`\t\tbreak`,\n\t\t\t\t`\t}`,\n\t\t\t]),\n\t\t\t`\tdefault: ${opts.wrapError.format(`PipeError.root(\"${err}\", ${input}, ${path})`)}`,\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { wrapInTryCatch, discriminator },\n\t\t\tschema: () => ({ oneOf: Object.values(branches).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any>>(branch: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${validatedVarname} = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }),\n\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\topts.wrapError(`${input}?.constructor?.name !== 'String'`, validatedVarname),\n\t\t\t`\t${validatedVarname} = ${context}.wrapInTryCatch(() => JSON.parse(${input}), ${validatedVarname})`,\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }).map((l) => `\t${l}`),\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t`}`,\n\t\t\t`${input} = ${validatedVarname}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { ...context(branch), wrapInTryCatch },\n\t\t\tschema: branch.schema,\n\t\t},\n\t)\n}\n\nexport const lazy = <T extends Pipe<any, any>>(pipeFn: () => T) =>\n\tdefine<PipeInput<T>, PipeOutput<T>>(\n\t\t(input) => {\n\t\t\tconst result = validate(pipeFn(), input)\n\t\t\treturn result.valid ? result.value : result.error\n\t\t},\n\t\t{\n\t\t\tschema: () => schema(pipeFn()),\n\t\t},\n\t)\n\nexport const recursive = <T extends Pipe<any, any>>(pipeFn: () => T, $refId: string) => {\n\tconst fnVarname = `fn_${getRandomValue()}`\n\tlet compiledBefore = false\n\tlet schemedBefore = false\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input }, opts) => {\n\t\t\tconst common = [`${input} = ${fnVarname}(${input})`, opts.wrapError(`${input} instanceof PipeError`, input)]\n\t\t\tif (compiledBefore) return common\n\t\t\tcompiledBefore = true\n\t\t\treturn [\n\t\t\t\t`function ${fnVarname}(node) {`,\n\t\t\t\t...compileNested({ opts: { ...opts, failEarly: true }, pipe: pipeFn(), input: 'node', errorType: 'return' }).map(\n\t\t\t\t\t(l) => `\t${l}`,\n\t\t\t\t),\n\t\t\t\t'}',\n\t\t\t\t...common,\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\tschema: () => {\n\t\t\t\tif (schemedBefore) return { $refId }\n\t\t\t\tschemedBefore = true\n\t\t\t\treturn schema(pipeFn(), { $refId })\n\t\t\t},\n\t\t},\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAqC;AACrC,uBAA+C;AAC/C,mBAA2E;AAEpE,MAAM,KAAK,CAA6B,aAAgB;AAC9D,QAAM,mBAAmB,iBAAa,iCAAe,CAAC;AACtD,QAAM,gBAAgB,cAAU,iCAAe,CAAC;AAChD,aAAO;AAAA,IACN,CAAC,EAAE,MAAM,GAAG,SACX,SAAS,WAAW,IACjB,CAAC,IACD;AAAA,MACA,SAAS,aAAa;AAAA,MACtB,OAAO,gBAAgB;AAAA,MACvB,GAAG,SACD,IAAI,CAAC,QAAQ,QAAQ,CAAC,UAAoB;AAAA,QAC1C,GAAG,gBAAgB,MAAM,KAAK;AAAA,QAC9B,OAAG,4BAAc;AAAA,UAChB,MAAM,EAAE,GAAG,MAAM,WAAW,KAAK;AAAA,UACjC,MAAM;AAAA,UACN,OAAO;AAAA,UACP,WAAW;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { getRandomValue, wrapInTryCatch } from '../utils/functions'\nimport { compileNested, context, standard, schema, define, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any>[]>(branches: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\tconst errorsVarname = `errors_${getRandomValue()}`\n\treturn standard<PipeInput<T[number]>, PipeOutput<T[number]>>(\n\t\t({ input }, opts) =>\n\t\t\tbranches.length === 0\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t`const ${errorsVarname} = []`,\n\t\t\t\t\t\t`let ${validatedVarname}`,\n\t\t\t\t\t\t...branches\n\t\t\t\t\t\t\t.map((branch, idx) => (lines: string[]) => [\n\t\t\t\t\t\t\t\t`${validatedVarname} = ${input}`,\n\t\t\t\t\t\t\t\t...compileNested({\n\t\t\t\t\t\t\t\t\topts: { ...opts, failEarly: true },\n\t\t\t\t\t\t\t\t\tpipe: branch,\n\t\t\t\t\t\t\t\t\tinput: validatedVarname,\n\t\t\t\t\t\t\t\t\terrorType: 'assign',\n\t\t\t\t\t\t\t\t\tkey: validatedVarname,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\t\t\t\t\t\t`\t${errorsVarname}.push(PipeError.path(${idx}, '${validatedVarname}', ${validatedVarname}))`,\n\t\t\t\t\t\t\t\t...lines.map((l) => `\t${l}`),\n\t\t\t\t\t\t\t\tidx === branches.length - 1 ? `\t${opts.wrapError.format(`PipeError.rootFrom(${errorsVarname})`)}` : '',\n\t\t\t\t\t\t\t\t`}`,\n\t\t\t\t\t\t\t\t`else ${input} = ${validatedVarname}`,\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t.reduceRight<string[]>((acc, cur) => cur(acc), []),\n\t\t\t\t\t\topts.wrapError(`${input} instanceof PipeError`, input),\n\t\t\t\t\t],\n\t\t{\n\t\t\tschema: () => ({ oneOf: branches.map((branch) => schema(branch)) }),\n\t\t},\n\t)\n}\n\nexport const merge = <T1 extends Pipe<any, any>, T2 extends Pipe<any, any>>(branch1: T1, branch2: T2) => {\n\tconst inputVarname = `input_${getRandomValue()}`\n\treturn standard<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${inputVarname}A = ${input}`,\n\t\t\t`let ${inputVarname}B = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch1, input: `${inputVarname}A` }),\n\t\t\topts.wrapError(`${inputVarname}A instanceof PipeError`, `${inputVarname}A`),\n\t\t\t...compileNested({ opts, pipe: branch2, input: `${inputVarname}B` }),\n\t\t\topts.wrapError(`${inputVarname}B instanceof PipeError`, `${inputVarname}B`),\n\t\t\t`${input} = ${context}.differMerge(${inputVarname}A, ${inputVarname}B)`,\n\t\t],\n\t\t{\n\t\t\tcontext: { differMerge },\n\t\t\tschema: () => ({ allOf: [schema(branch1), schema(branch2)] }),\n\t\t},\n\t)\n}\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tbranches: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tstandard<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`switch (${context}.wrapInTryCatch(() => ${context}.discriminator(${input}))) {`,\n\t\t\t...Object.entries(branches).flatMap(([key, branch]) => [\n\t\t\t\t`\tcase ('${key}'): {`,\n\t\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => `\t\t${l}`),\n\t\t\t\t`\t\tbreak`,\n\t\t\t\t`\t}`,\n\t\t\t]),\n\t\t\t`\tdefault: ${opts.wrapError.format(`PipeError.root(\"${err}\", ${input}, ${path})`)}`,\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { wrapInTryCatch, discriminator },\n\t\t\tschema: () => ({ oneOf: Object.values(branches).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any>>(branch: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${validatedVarname} = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }),\n\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\topts.wrapError(`${input}?.constructor?.name !== 'String'`, validatedVarname),\n\t\t\t`\t${validatedVarname} = ${context}.wrapInTryCatch(() => JSON.parse(${input}), ${validatedVarname})`,\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }).map((l) => `\t${l}`),\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t`}`,\n\t\t\t`${input} = ${validatedVarname}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { ...context(branch), wrapInTryCatch },\n\t\t\tschema: branch.schema,\n\t\t},\n\t)\n}\n\nexport const lazy = <T extends Pipe<any, any>>(pipeFn: () => T) =>\n\tdefine<PipeInput<T>, PipeOutput<T>>(\n\t\t(input) => {\n\t\t\tconst result = validate(pipeFn(), input)\n\t\t\treturn result.valid ? result.value : result.error\n\t\t},\n\t\t{\n\t\t\tschema: () => schema(pipeFn()),\n\t\t},\n\t)\n\nexport const recursive = <T extends Pipe<any, any>>(pipeFn: () => T, $refId: string) => {\n\tconst fnVarname = `fn_${getRandomValue()}`\n\tlet compiledBefore = false\n\tlet schemedBefore = false\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input }, opts) => {\n\t\t\tconst common = [`${input} = ${fnVarname}(${input})`, opts.wrapError(`${input} instanceof PipeError`, input)]\n\t\t\tif (compiledBefore) return common\n\t\t\tcompiledBefore = true\n\t\t\treturn [\n\t\t\t\t`function ${fnVarname}(node) {`,\n\t\t\t\t...compileNested({ opts: { ...opts, failEarly: true }, pipe: pipeFn(), input: 'node', errorType: 'return' }).map(\n\t\t\t\t\t(l) => `\t${l}`,\n\t\t\t\t),\n\t\t\t\t'}',\n\t\t\t\t...common,\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\tschema: () => {\n\t\t\t\tif (schemedBefore) return { $refId }\n\t\t\t\tschemedBefore = true\n\t\t\t\treturn schema(pipeFn(), { $refId })\n\t\t\t},\n\t\t},\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAqC;AACrC,uBAA+C;AAC/C,mBAA2E;AAEpE,MAAM,KAAK,CAA6B,aAAgB;AAC9D,QAAM,mBAAmB,iBAAa,iCAAe,CAAC;AACtD,QAAM,gBAAgB,cAAU,iCAAe,CAAC;AAChD,aAAO;AAAA,IACN,CAAC,EAAE,MAAM,GAAG,SACX,SAAS,WAAW,IACjB,CAAC,IACD;AAAA,MACA,SAAS,aAAa;AAAA,MACtB,OAAO,gBAAgB;AAAA,MACvB,GAAG,SACD,IAAI,CAAC,QAAQ,QAAQ,CAAC,UAAoB;AAAA,QAC1C,GAAG,gBAAgB,MAAM,KAAK;AAAA,QAC9B,OAAG,4BAAc;AAAA,UAChB,MAAM,EAAE,GAAG,MAAM,WAAW,KAAK;AAAA,UACjC,MAAM;AAAA,UACN,OAAO;AAAA,UACP,WAAW;AAAA,UACX,KAAK;AAAA,QACN,CAAC;AAAA,QACD,OAAO,gBAAgB;AAAA,QACvB,IAAI,aAAa,wBAAwB,GAAG,MAAM,gBAAgB,M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AAO,CAAC;AAAA,MACnC;AAAA,IACD;AAAA,EACD;AACD;","names":["context","differMerge"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var r in e)u(t,r,{get:e[r],enumerable:!0})},d=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of P(e))!l.call(t,o)&&o!==r&&u(t,o,{get:()=>e[o],enumerable:!(n=T(e,o))||n.enumerable});return t};var E=t=>d(u({},"__esModule",{value:!0}),t);var v={};y(v,{discriminate:()=>O,fromJson:()=>w,lazy:()=>h,merge:()=>x,or:()=>g,recursive:()=>I});module.exports=E(v);var c=require('../utils/differ.min.cjs'),$=require('../utils/functions/index.min.cjs'),a=require('./base/pipes.min.cjs');const g=t=>{const e=`validated_${(0,$.getRandomValue)()}`,r=`errors_${(0,$.getRandomValue)()}`;return(0,a.standard)(({input:n},o)=>t.length===0?[]:[`const ${r} = []`,`let ${e}`,...t.map((p,i)=>s=>[`${e} = ${n}`,...(0,a.compileNested)({opts:{...o,failEarly:!0},pipe:p,input:e,errorType:"assign",key:e}),`if (${e} instanceof PipeError) {`,` ${r}.push(PipeError.path(${i}, '${e}', ${e}))`,...s.map(m=>` ${m}`),i===t.length-1?` ${o.wrapError.format(`PipeError.rootFrom(${r})`)}`:"","}",`else ${n} = ${e}`]).reduceRight((p,i)=>i(p),[]),o.wrapError(`${n} instanceof PipeError`,n)],{schema:()=>({oneOf:t.map(n=>(0,a.schema)(n))})})},x=(t,e)=>{const r=`input_${(0,$.getRandomValue)()}`;return(0,a.standard)(({input:n,context:o},p)=>[`let ${r}A = ${n}`,`let ${r}B = ${n}`,...(0,a.compileNested)({opts:p,pipe:t,input:`${r}A`}),p.wrapError(`${r}A instanceof PipeError`,`${r}A`),...(0,a.compileNested)({opts:p,pipe:e,input:`${r}B`}),p.wrapError(`${r}B instanceof PipeError`,`${r}B`),`${n} = ${o}.differMerge(${r}A, ${r}B)`],{context:{differMerge:c.merge},schema:()=>({allOf:[(0,a.schema)(t),(0,a.schema)(e)]})})},O=(t,e,r="doesnt match any of the schema")=>(0,a.standard)(({input:n,context:o,path:p},i)=>[`switch (${o}.wrapInTryCatch(() => ${o}.discriminator(${n}))) {`,...Object.entries(e).flatMap(([s,m])=>[` case ('${s}'): {`,...(0,a.compileNested)({opts:i,pipe:m,input:n}).map(f=>` ${f}`)," break"," }"]),` default: ${i.wrapError.format(`PipeError.root("${r}", ${n}, ${p})`)}`,"}"],{context:{wrapInTryCatch:$.wrapInTryCatch,discriminator:t},schema:()=>({oneOf:Object.values(e).map(n=>(0,a.schema)(n))})}),w=t=>{const e=`validated_${(0,$.getRandomValue)()}`;return(0,a.standard)(({input:r,context:n},o)=>[`let ${e} = ${r}`,...(0,a.compileNested)({opts:o,pipe:t,input:e,errorType:"assign"}),`if (${e} instanceof PipeError) {`,o.wrapError(`${r}?.constructor?.name !== 'String'`,e),` ${e} = ${n}.wrapInTryCatch(() => JSON.parse(${r}), ${e})`,o.wrapError(`${e} instanceof PipeError`,e),...(0,a.compileNested)({opts:o,pipe:t,input:e,errorType:"assign"}).map(p=>` ${p}`),o.wrapError(`${e} instanceof PipeError`,e),"}",`${r} = ${e}`],{context:{...(0,a.context)(t),wrapInTryCatch:$.wrapInTryCatch},schema:t.schema})},h=t=>(0,a.define)(e=>{const r=(0,a.validate)(t(),e);return r.valid?r.value:r.error},{schema:()=>(0,a.schema)(t())}),I=(t,e)=>{const r=`fn_${(0,$.getRandomValue)()}`;let n=!1,o=!1;return(0,a.standard)(({input:p},i)=>{const s=[`${p} = ${r}(${p})`,i.wrapError(`${p} instanceof PipeError`,p)];return n?s:(n=!0,[`function ${r}(node) {`,...(0,a.compileNested)({opts:{...i,failEarly:!0},pipe:t(),input:"node",errorType:"return"}).map(m=>` ${m}`),"}",...s])},{schema:()=>o?{$refId:e}:(o=!0,(0,a.schema)(t(),{$refId:e}))})};0&&(module.exports={discriminate,fromJson,lazy,merge,or,recursive});
|
|
2
2
|
//# sourceMappingURL=junctions.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { getRandomValue, wrapInTryCatch } from '../utils/functions'\nimport { compileNested, context, standard, schema, define, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any>[]>(branches: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\tconst errorsVarname = `errors_${getRandomValue()}`\n\treturn standard<PipeInput<T[number]>, PipeOutput<T[number]>>(\n\t\t({ input }, opts) =>\n\t\t\tbranches.length === 0\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t`const ${errorsVarname} = []`,\n\t\t\t\t\t\t`let ${validatedVarname}`,\n\t\t\t\t\t\t...branches\n\t\t\t\t\t\t\t.map((branch, idx) => (lines: string[]) => [\n\t\t\t\t\t\t\t\t`${validatedVarname} = ${input}`,\n\t\t\t\t\t\t\t\t...compileNested({\n\t\t\t\t\t\t\t\t\topts: { ...opts, failEarly: true },\n\t\t\t\t\t\t\t\t\tpipe: branch,\n\t\t\t\t\t\t\t\t\tinput: validatedVarname,\n\t\t\t\t\t\t\t\t\terrorType: 'assign',\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\t\t\t\t\t\t`\t${errorsVarname}.push(PipeError.path(${idx}, ${validatedVarname}))`,\n\t\t\t\t\t\t\t\t...lines.map((l) => `\t${l}`),\n\t\t\t\t\t\t\t\tidx === branches.length - 1 ? `\t${opts.wrapError.format(`PipeError.rootFrom(${errorsVarname})`)}` : '',\n\t\t\t\t\t\t\t\t`}`,\n\t\t\t\t\t\t\t\t`else ${input} = ${validatedVarname}`,\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t.reduceRight<string[]>((acc, cur) => cur(acc), []),\n\t\t\t\t\t\topts.wrapError(`${input} instanceof PipeError`, input),\n\t\t\t\t\t],\n\t\t{\n\t\t\tschema: () => ({ oneOf: branches.map((branch) => schema(branch)) }),\n\t\t},\n\t)\n}\n\nexport const merge = <T1 extends Pipe<any, any>, T2 extends Pipe<any, any>>(branch1: T1, branch2: T2) => {\n\tconst inputVarname = `input_${getRandomValue()}`\n\treturn standard<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${inputVarname}A = ${input}`,\n\t\t\t`let ${inputVarname}B = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch1, input: `${inputVarname}A` }),\n\t\t\topts.wrapError(`${inputVarname}A instanceof PipeError`, `${inputVarname}A`),\n\t\t\t...compileNested({ opts, pipe: branch2, input: `${inputVarname}B` }),\n\t\t\topts.wrapError(`${inputVarname}B instanceof PipeError`, `${inputVarname}B`),\n\t\t\t`${input} = ${context}.differMerge(${inputVarname}A, ${inputVarname}B)`,\n\t\t],\n\t\t{\n\t\t\tcontext: { differMerge },\n\t\t\tschema: () => ({ allOf: [schema(branch1), schema(branch2)] }),\n\t\t},\n\t)\n}\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tbranches: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tstandard<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`switch (${context}.wrapInTryCatch(() => ${context}.discriminator(${input}))) {`,\n\t\t\t...Object.entries(branches).flatMap(([key, branch]) => [\n\t\t\t\t`\tcase ('${key}'): {`,\n\t\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => `\t\t${l}`),\n\t\t\t\t`\t\tbreak`,\n\t\t\t\t`\t}`,\n\t\t\t]),\n\t\t\t`\tdefault: ${opts.wrapError.format(`PipeError.root(\"${err}\", ${input}, ${path})`)}`,\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { wrapInTryCatch, discriminator },\n\t\t\tschema: () => ({ oneOf: Object.values(branches).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any>>(branch: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${validatedVarname} = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }),\n\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\topts.wrapError(`${input}?.constructor?.name !== 'String'`, validatedVarname),\n\t\t\t`\t${validatedVarname} = ${context}.wrapInTryCatch(() => JSON.parse(${input}), ${validatedVarname})`,\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }).map((l) => `\t${l}`),\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t`}`,\n\t\t\t`${input} = ${validatedVarname}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { ...context(branch), wrapInTryCatch },\n\t\t\tschema: branch.schema,\n\t\t},\n\t)\n}\n\nexport const lazy = <T extends Pipe<any, any>>(pipeFn: () => T) =>\n\tdefine<PipeInput<T>, PipeOutput<T>>(\n\t\t(input) => {\n\t\t\tconst result = validate(pipeFn(), input)\n\t\t\treturn result.valid ? result.value : result.error\n\t\t},\n\t\t{\n\t\t\tschema: () => schema(pipeFn()),\n\t\t},\n\t)\n\nexport const recursive = <T extends Pipe<any, any>>(pipeFn: () => T, $refId: string) => {\n\tconst fnVarname = `fn_${getRandomValue()}`\n\tlet compiledBefore = false\n\tlet schemedBefore = false\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input }, opts) => {\n\t\t\tconst common = [`${input} = ${fnVarname}(${input})`, opts.wrapError(`${input} instanceof PipeError`, input)]\n\t\t\tif (compiledBefore) return common\n\t\t\tcompiledBefore = true\n\t\t\treturn [\n\t\t\t\t`function ${fnVarname}(node) {`,\n\t\t\t\t...compileNested({ opts: { ...opts, failEarly: true }, pipe: pipeFn(), input: 'node', errorType: 'return' }).map(\n\t\t\t\t\t(l) => `\t${l}`,\n\t\t\t\t),\n\t\t\t\t'}',\n\t\t\t\t...common,\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\tschema: () => {\n\t\t\t\tif (schemedBefore) return { $refId }\n\t\t\t\tschemedBefore = true\n\t\t\t\treturn schema(pipeFn(), { $refId })\n\t\t\t},\n\t\t},\n\t)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,aAAAC,EAAA,SAAAC,EAAA,UAAAC,EAAA,OAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAR,GACA,IAAAS,EAAqC,2BACrCC,EAA+C,8BAC/CC,EAA2E,wBAEpE,MAAML,EAAkCM,GAAgB,CAC9D,MAAMC,EAAmB,gBAAa,kBAAe,CAAC,GAChDC,EAAgB,aAAU,kBAAe,CAAC,GAChD,SAAO,YACN,CAAC,CAAE,MAAAC,CAAM,EAAGC,IACXJ,EAAS,SAAW,EACjB,CAAC,EACD,CACA,SAASE,CAAa,QACtB,OAAOD,CAAgB,GACvB,GAAGD,EACD,IAAI,CAACK,EAAQC,IAASC,GAAoB,CAC1C,GAAGN,CAAgB,MAAME,CAAK,GAC9B,MAAG,iBAAc,CAChB,KAAM,CAAE,GAAGC,EAAM,UAAW,EAAK,EACjC,KAAMC,EACN,MAAOJ,EACP,UAAW,
|
|
1
|
+
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { getRandomValue, wrapInTryCatch } from '../utils/functions'\nimport { compileNested, context, standard, schema, define, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any>[]>(branches: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\tconst errorsVarname = `errors_${getRandomValue()}`\n\treturn standard<PipeInput<T[number]>, PipeOutput<T[number]>>(\n\t\t({ input }, opts) =>\n\t\t\tbranches.length === 0\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t`const ${errorsVarname} = []`,\n\t\t\t\t\t\t`let ${validatedVarname}`,\n\t\t\t\t\t\t...branches\n\t\t\t\t\t\t\t.map((branch, idx) => (lines: string[]) => [\n\t\t\t\t\t\t\t\t`${validatedVarname} = ${input}`,\n\t\t\t\t\t\t\t\t...compileNested({\n\t\t\t\t\t\t\t\t\topts: { ...opts, failEarly: true },\n\t\t\t\t\t\t\t\t\tpipe: branch,\n\t\t\t\t\t\t\t\t\tinput: validatedVarname,\n\t\t\t\t\t\t\t\t\terrorType: 'assign',\n\t\t\t\t\t\t\t\t\tkey: validatedVarname,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\t\t\t\t\t\t`\t${errorsVarname}.push(PipeError.path(${idx}, '${validatedVarname}', ${validatedVarname}))`,\n\t\t\t\t\t\t\t\t...lines.map((l) => `\t${l}`),\n\t\t\t\t\t\t\t\tidx === branches.length - 1 ? `\t${opts.wrapError.format(`PipeError.rootFrom(${errorsVarname})`)}` : '',\n\t\t\t\t\t\t\t\t`}`,\n\t\t\t\t\t\t\t\t`else ${input} = ${validatedVarname}`,\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t.reduceRight<string[]>((acc, cur) => cur(acc), []),\n\t\t\t\t\t\topts.wrapError(`${input} instanceof PipeError`, input),\n\t\t\t\t\t],\n\t\t{\n\t\t\tschema: () => ({ oneOf: branches.map((branch) => schema(branch)) }),\n\t\t},\n\t)\n}\n\nexport const merge = <T1 extends Pipe<any, any>, T2 extends Pipe<any, any>>(branch1: T1, branch2: T2) => {\n\tconst inputVarname = `input_${getRandomValue()}`\n\treturn standard<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${inputVarname}A = ${input}`,\n\t\t\t`let ${inputVarname}B = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch1, input: `${inputVarname}A` }),\n\t\t\topts.wrapError(`${inputVarname}A instanceof PipeError`, `${inputVarname}A`),\n\t\t\t...compileNested({ opts, pipe: branch2, input: `${inputVarname}B` }),\n\t\t\topts.wrapError(`${inputVarname}B instanceof PipeError`, `${inputVarname}B`),\n\t\t\t`${input} = ${context}.differMerge(${inputVarname}A, ${inputVarname}B)`,\n\t\t],\n\t\t{\n\t\t\tcontext: { differMerge },\n\t\t\tschema: () => ({ allOf: [schema(branch1), schema(branch2)] }),\n\t\t},\n\t)\n}\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tbranches: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tstandard<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`switch (${context}.wrapInTryCatch(() => ${context}.discriminator(${input}))) {`,\n\t\t\t...Object.entries(branches).flatMap(([key, branch]) => [\n\t\t\t\t`\tcase ('${key}'): {`,\n\t\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => `\t\t${l}`),\n\t\t\t\t`\t\tbreak`,\n\t\t\t\t`\t}`,\n\t\t\t]),\n\t\t\t`\tdefault: ${opts.wrapError.format(`PipeError.root(\"${err}\", ${input}, ${path})`)}`,\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { wrapInTryCatch, discriminator },\n\t\t\tschema: () => ({ oneOf: Object.values(branches).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any>>(branch: T) => {\n\tconst validatedVarname = `validated_${getRandomValue()}`\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`let ${validatedVarname} = ${input}`,\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }),\n\t\t\t`if (${validatedVarname} instanceof PipeError) {`,\n\t\t\topts.wrapError(`${input}?.constructor?.name !== 'String'`, validatedVarname),\n\t\t\t`\t${validatedVarname} = ${context}.wrapInTryCatch(() => JSON.parse(${input}), ${validatedVarname})`,\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t...compileNested({ opts, pipe: branch, input: validatedVarname, errorType: 'assign' }).map((l) => `\t${l}`),\n\t\t\topts.wrapError(`${validatedVarname} instanceof PipeError`, validatedVarname),\n\t\t\t`}`,\n\t\t\t`${input} = ${validatedVarname}`,\n\t\t],\n\t\t{\n\t\t\tcontext: { ...context(branch), wrapInTryCatch },\n\t\t\tschema: branch.schema,\n\t\t},\n\t)\n}\n\nexport const lazy = <T extends Pipe<any, any>>(pipeFn: () => T) =>\n\tdefine<PipeInput<T>, PipeOutput<T>>(\n\t\t(input) => {\n\t\t\tconst result = validate(pipeFn(), input)\n\t\t\treturn result.valid ? result.value : result.error\n\t\t},\n\t\t{\n\t\t\tschema: () => schema(pipeFn()),\n\t\t},\n\t)\n\nexport const recursive = <T extends Pipe<any, any>>(pipeFn: () => T, $refId: string) => {\n\tconst fnVarname = `fn_${getRandomValue()}`\n\tlet compiledBefore = false\n\tlet schemedBefore = false\n\treturn standard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input }, opts) => {\n\t\t\tconst common = [`${input} = ${fnVarname}(${input})`, opts.wrapError(`${input} instanceof PipeError`, input)]\n\t\t\tif (compiledBefore) return common\n\t\t\tcompiledBefore = true\n\t\t\treturn [\n\t\t\t\t`function ${fnVarname}(node) {`,\n\t\t\t\t...compileNested({ opts: { ...opts, failEarly: true }, pipe: pipeFn(), input: 'node', errorType: 'return' }).map(\n\t\t\t\t\t(l) => `\t${l}`,\n\t\t\t\t),\n\t\t\t\t'}',\n\t\t\t\t...common,\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\tschema: () => {\n\t\t\t\tif (schemedBefore) return { $refId }\n\t\t\t\tschemedBefore = true\n\t\t\t\treturn schema(pipeFn(), { $refId })\n\t\t\t},\n\t\t},\n\t)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,aAAAC,EAAA,SAAAC,EAAA,UAAAC,EAAA,OAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAR,GACA,IAAAS,EAAqC,2BACrCC,EAA+C,8BAC/CC,EAA2E,wBAEpE,MAAML,EAAkCM,GAAgB,CAC9D,MAAMC,EAAmB,gBAAa,kBAAe,CAAC,GAChDC,EAAgB,aAAU,kBAAe,CAAC,GAChD,SAAO,YACN,CAAC,CAAE,MAAAC,CAAM,EAAGC,IACXJ,EAAS,SAAW,EACjB,CAAC,EACD,CACA,SAASE,CAAa,QACtB,OAAOD,CAAgB,GACvB,GAAGD,EACD,IAAI,CAACK,EAAQC,IAASC,GAAoB,CAC1C,GAAGN,CAAgB,MAAME,CAAK,GAC9B,MAAG,iBAAc,CAChB,KAAM,CAAE,GAAGC,EAAM,UAAW,EAAK,EACjC,KAAMC,EACN,MAAOJ,EACP,UAAW,SACX,IAAKA,CACN,CAAC,EACD,OAAOA,CAAgB,2BACvB,IAAIC,CAAa,wBAAwBI,CAAG,MAAML,CAAgB,MAAMA,CAAgB,KACxF,GAAGM,EAAM,IAAKC,GAAM,IAAIA,CAAC,EAAE,EAC3BF,IAAQN,EAAS,OAAS,EAAI,IAAII,EAAK,UAAU,OAAO,sBAAsBF,CAAa,GAAG,CAAC,GAAK,GACpG,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B,EAAO,MAAQA,EAAO,MAAQA,EAAO,KAC7C,EACA,CACC,OAAQ,OAAM,UAAOD,EAAO,CAAC,CAC9B,CACD,EAEY1B,EAAY,CAA2B0B,EAAiBE,IAAmB,CACvF,MAAMC,EAAY,SAAM,kBAAe,CAAC,GACxC,IAAIC,EAAiB,GACjBC,EAAgB,GACpB,SAAO,YACN,CAAC,CAAE,MAAAvB,CAAM,EAAGC,IAAS,CACpB,MAAMuB,EAAS,CAAC,GAAGxB,CAAK,MAAMqB,CAAS,IAAIrB,CAAK,IAAKC,EAAK,UAAU,GAAGD,CAAK,wBAAyBA,CAAK,CAAC,EAC3G,OAAIsB,EAAuBE,GAC3BF,EAAiB,GACV,CACN,YAAYD,CAAS,WACrB,MAAG,iBAAc,CAAE,KAAM,CAAE,GAAGpB,EAAM,UAAW,EAAK,EAAG,KAAMiB,EAAO,EAAG,MAAO,OAAQ,UAAW,QAAS,CAAC,EAAE,IAC3Gb,GAAM,IAAIA,CAAC,EACb,EACA,IACA,GAAGmB,CACJ,EACD,EACA,CACC,OAAQ,IACHD,EAAsB,CAAE,OAAAH,CAAO,GACnCG,EAAgB,MACT,UAAOL,EAAO,EAAG,CAAE,OAAAE,CAAO,CAAC,EAEpC,CACD,CACD","names":["junctions_exports","__export","discriminate","fromJson","lazy","merge","or","recursive","__toCommonJS","import_differ","import_functions","import_pipes","branches","validatedVarname","errorsVarname","input","opts","branch","idx","lines","l","acc","cur","branch1","branch2","inputVarname","context","differMerge","discriminator","err","path","key","s","pipeFn","result","$refId","fnVarname","compiledBefore","schemedBefore","common"]}
|
|
@@ -59,7 +59,7 @@ const defaults = (branch, def) => (0, import_pipes.standard)(
|
|
|
59
59
|
],
|
|
60
60
|
{
|
|
61
61
|
schema: (c) => ({ ...(0, import_pipes.schema)(branch), default: c.defaults ?? def }),
|
|
62
|
-
context: { ...(0, import_pipes.context)(branch), defaults: def, optional: true
|
|
62
|
+
context: { ...(0, import_pipes.context)(branch), defaults: def, optional: true }
|
|
63
63
|
}
|
|
64
64
|
);
|
|
65
65
|
const onCatch = (branch, def) => (0, import_pipes.standard)(
|
|
@@ -69,7 +69,7 @@ const onCatch = (branch, def) => (0, import_pipes.standard)(
|
|
|
69
69
|
],
|
|
70
70
|
{
|
|
71
71
|
schema: (c) => ({ ...(0, import_pipes.schema)(branch), default: c.catch ?? def }),
|
|
72
|
-
context: { ...(0, import_pipes.context)(branch), catch: def
|
|
72
|
+
context: { ...(0, import_pipes.context)(branch), catch: def }
|
|
73
73
|
}
|
|
74
74
|
);
|
|
75
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import { Pipe, PipeInput, PipeOutput } from './base'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import { Pipe, PipeInput, PipeOutput } from './base'\nimport { standard, compileNested, context, schema } from './base/pipes'\nimport { DeepPartial } from '../utils/types'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyD;AAGzD,MAAM,UAAU,CACf,QACA,kBACA,eAEA;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,QAAQA,QAAO,qBAAqB,KAAK;AAAA,IACzC,OAAG,4BAAc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AG,SAAS,EAAE,YAAY,IAAI;AAAA,IAChE,SAAS,EAAE,OAAG,sBAAQ,MAAM,GAAG,UAAU,KAAK,UAAU,KAAK;AAAA,EAC9D;AACD;AAED,MAAM,UAAU,CAA2B,QAAW,YACrD;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,OAAG,4BAAc,EAAE,MAAM,MAAM,QAAQ,OAAO,WAAW,SAAS,CAAC;AAAA,IACnE,OAAO,KAAK,0BAA0B,KAAK,MAAMA,QAAO;AAAA,EACzD;AAAA,EACA;AAAA,IACC,QAAQ,CAAC,OAAO,EAAE,OAAG,qBAAO,MAAM,GAAG,SAAS,EAAE,SAAS,IAAI;AAAA,IAC7D,SAAS,EAAE,OAAG,sBAAQ,MAAM,GAAG,OAAO,IAAI;AAAA,EAC3C;AACD;","names":["context"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var n in t)u(e,n,{get:t[n],enumerable:!0})},x=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of P(t))!c.call(e,a)&&a!==n&&u(e,a,{get:()=>t[a],enumerable:!(o=T(t,a))||o.enumerable});return e};var r=e=>x(u({},"__esModule",{value:!0}),e);var D={};f(D,{catch:()=>l,conditional:()=>I,defaults:()=>O,nullable:()=>y,nullish:()=>$,optional:()=>m});module.exports=r(D);var p=require('./base/pipes.min.cjs');const i=(e,t,n)=>(0,p.standard)(({input:o,context:a},d)=>[`if (!${a}.partialCondition(${o})) {`,...(0,p.compileNested)({opts:d,pipe:e,input:o}).map(s=>` ${s}`),"}"],{...n,context:{...n?.context,partialCondition:t}}),y=e=>i(e,t=>t===null,{schema:()=>({oneOf:[(0,p.schema)(e),{type:"null"}]})}),m=e=>i(e,t=>t===void 0,{context:{optional:!0}}),$=e=>i(e,t=>t==null,{schema:()=>({oneOf:[(0,p.schema)(e),{type:"null"}]}),context:{...(0,p.context)(e),optional:!0}}),I=(e,t)=>i(e,()=>!t(),{schema:()=>(0,p.schema)(e),context:{...(0,p.context)(e),optional:!0}}),O=(e,t)=>(0,p.standard)(({input:n,context:o},a)=>[`if (${n} === undefined) ${n} = ${o}.defaults`,...(0,p.compileNested)({opts:a,pipe:e,input:n})],{schema:n=>({...(0,p.schema)(e),default:n.defaults??t}),context:{...(0,p.context)(e),defaults:t,optional:!0}}),l=(e,t)=>(0,p.standard)(({input:n,context:o},a)=>[...(0,p.compileNested)({opts:a,pipe:e,input:n,errorType:"assign"}),`if (${n} instanceof PipeError) ${n} = ${o}.catch`],{schema:n=>({...(0,p.schema)(e),default:n.catch??t}),context:{...(0,p.context)(e),catch:t}});0&&(module.exports={catch:null,conditional,defaults,nullable,nullish,optional});
|
|
2
2
|
//# sourceMappingURL=optionals.min.cjs.map
|