valleyed 4.5.12 → 4.5.14

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 CHANGED
@@ -2,6 +2,20 @@
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.14](https://github.com/kevinand11/valleyed/compare/v4.5.13...v4.5.14) (2025-07-06)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * correct nested pipes path ([bed1c26](https://github.com/kevinand11/valleyed/commit/bed1c26b1e0ffa755d15f77176c14085c88f383b))
11
+
12
+ ### [4.5.13](https://github.com/kevinand11/valleyed/compare/v4.5.12...v4.5.13) (2025-07-05)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * types of v.lazy ([e3baef0](https://github.com/kevinand11/valleyed/commit/e3baef0b1902f5acc562bc055f1e1e5b6067bb01))
18
+
5
19
  ### [4.5.12](https://github.com/kevinand11/valleyed/compare/v4.5.11...v4.5.12) (2025-07-05)
6
20
 
7
21
  ### [4.5.11](https://github.com/kevinand11/valleyed/compare/v4.5.10...v4.5.11) (2025-07-05)
@@ -139,7 +139,7 @@ function compileNested(data) {
139
139
  pipe: data.pipe,
140
140
  input: data.input,
141
141
  context: `context[\`${random}\`]`,
142
- path: ["key" in data ? data.key : "", data.opts.path].filter(Boolean).join(".") || void 0
142
+ path: [data.opts.path, "key" in data ? data.key : ""].filter(Boolean).join(".") || void 0
143
143
  });
144
144
  data.opts.rootContext[random] = context2;
145
145
  return lines;
@@ -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: ['key' in data ? data.key : '', data.opts.path].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)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;AAEA,SAAS,oBAAoB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP;AAAA,EACA,gBAAY,kCAAmB,OAAO,QAAQ;AAAA,EAC9C,OAAO,CAAC;AACT,GASG;AACF,QAAM,MAAM,QAAQ,IAAI;AACxB,kBAAgB;AAChB,QAAM,WAAW,KAAK,MAA+C,CAAC,GAAG,CAAC,GAAG,QAAQ;AACpF,QAAI;AAAA,MACH,EAAE;AAAA,QACD,EAAE,OAAO,SAAS,YAAY,MAAM,GAAG,OAAO,IAAI,IAAI,MAAM,MAAS,GAAG;AAAA,QACxE,EAAE,aAAa,WAAW,MAAM,UAAU;AAAA,MAC3C;AAAA,IACD;AACA,WAAO;AAAA,EACR,CAAC;AACD,QAAM,QAAQ,eAAe,MAAM,SAAS,KAAK,CAAC;AAClD,SAAO,EAAE,OAAO,SAAS,IAAI;AAC9B;AAEA,SAAS,eAAe,MAAgB,OAA8C;AACrF,UAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG,YAAsB,CAAC,KAAK,QAAQ;AACnF,QAAI,OAAO,QAAQ,SAAU,KAAI,QAAQ,GAAG;AAAA,aACnC,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>>(\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":";;;;;;;;;;;;;;;;;;A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AAmB,OAAO,QAAQ;AAAA,EAC9C,OAAO,CAAC;AACT,GASG;AACF,QAAM,MAAM,QAAQ,IAAI;AACxB,kBAAgB;AAChB,QAAM,WAAW,KAAK,MAA+C,CAAC,GAAG,CAAC,GAAG,QAAQ;AACpF,QAAI;AAAA,MACH,EAAE;AAAA,QACD,EAAE,OAAO,SAAS,YAAY,MAAM,GAAG,OAAO,IAAI,IAAI,MAAM,MAAS,GAAG;AAAA,QACxE,EAAE,aAAa,WAAW,MAAM,UAAU;AAAA,MAC3C;AAAA,IACD;AACA,WAAO;AAAA,EACR,CAAC;AACD,QAAM,QAAQ,eAAe,MAAM,SAAS,KAAK,CAAC;AAClD,SAAO,EAAE,OAAO,SAAS,IAAI;AAC9B;AAEA,SAAS,eAAe,MAAgB,OAA8C;AACrF,UAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG,YAAsB,CAAC,KAAK,QAAQ;AACnF,QAAI,OAAO,QAAQ,SAAU,KAAI,QAAQ,GAAG;AAAA,aACnC,OAAO,QAAQ,WAAY,OAAM,IAAI,GAAG;AACjD,WAAO;AAAA,EACR,GAAG,IAAI;AACR;","names":["schema","meta","context","compile"]}
@@ -1,3 +1,3 @@
1
1
  "use strict";var l=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var w=(e,n)=>{for(var t in n)l(e,t,{get:n[t],enumerable:!0})},O=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of C(n))!g.call(e,o)&&o!==t&&l(e,o,{get:()=>n[o],enumerable:!(r=$(n,o))||r.enumerable});return e};var S=e=>O(l({},"__esModule",{value:!0}),e);var R={};w(R,{assert:()=>_,compile:()=>T,compileNested:()=>F,context:()=>y,define:()=>h,meta:()=>I,schema:()=>k,standard:()=>x,validate:()=>f,walk:()=>c});module.exports=S(R);var a=require('./errors.min.cjs'),u=require('../../utils/functions/index.min.cjs');function c(e,n,t){let r=n;for(;e;)r=t(e,r),e=e.next;return r}function y(e){return c(e,{},(n,t)=>({...t,...n.context()}))}function _(e,n){const t=f(e,n);if(!t.valid)throw t.error;return t.value}function f(e,n){try{const r=(e.__compiled??T(e))(n);return r instanceof a.PipeError?{error:r,valid:!1}:{value:r,valid:!0}}catch(t){return t instanceof a.PipeError?{error:t,valid:!1}:{error:a.PipeError.root(t instanceof Error?t.message:`${t}`,n,void 0),valid:!1}}}function k(e,n={}){const t=y(e);return c(e,n,(r,o)=>({...o,...r.schema(t)}))}function I(e,n){return e.pipe(x(()=>[],{schema:()=>n}))}function T(e,{failEarly:n=!0}={}){const t="input",r="context",{lines:o,context:i}=P({pipe:e,input:t,context:r,failEarly:n,base:[`return ${t}`]}),p=[`return (${t}) => {`,...o.filter(s=>s.trim()!=="").map(s=>` ${s}`),` throw PipeError.root('unhandled root validation', ${t})`,"}"];return e.__compiled=new Function(r,"PipeError",p.join(`
2
- `))(i,a.PipeError),e.__compiled}function x(e,n={}){const t={context:()=>n.context??{},schema:r=>n.schema?.(r)??{},pipe:(...r)=>{delete t.__compiled;for(const o of r){const i=typeof o=="function"?h(o,n):o;t.next||(t.next=i),t.last&&(t.last.next=i),t.last=i.last??i}return t},compile:e,"~standard":{version:1,vendor:"valleyed",validate(r){const o=f(t,r);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:p})=>({message:i,path:p?p.split("."):void 0}))}}}};return t}function h(e,n={}){const t=`define_${(0,u.getRandomValue)()}`;return x(({input:r,context:o,path:i})=>[`${r} = ${o}['${t}'](${r})`,`if (${r} instanceof PipeError) return PipeError.path(${i}, ${r})`],{context:{...n?.context,[t]:e},schema:n?.schema})}function F(e){const n=(0,u.getRandomValue)(),{lines:t,context:r}=P({...e.opts,wrapError:(0,a.createErrorHandler)(e.input,e.errorType??e.opts.wrapError.type),pipe:e.pipe,input:e.input,context:`context[\`${n}\`]`,path:["key"in e?e.key:"",e.opts.path].filter(Boolean).join(".")||void 0});return e.opts.rootContext[n]=r,t}function P({pipe:e,input:n,context:t,failEarly:r=!1,path:o="",rootContext:i,wrapError:p=(0,a.createErrorHandler)(n,"return"),base:s=[]}){const m=y(e);i??=m;const v=c(e,[],(E,d)=>(d.push(E.compile({input:n,context:t,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:r,path:o,wrapError:p})),d));return{lines:J(s,v.flat()),context:m}}function J(e,n){return(Array.isArray(n)?n:[n]).reduceRight((t,r)=>(typeof r=="string"?t.unshift(r):typeof r=="function"&&(t=r(t)),t),e)}0&&(module.exports={assert,compile,compileNested,context,define,meta,schema,standard,validate,walk});
2
+ `))(i,a.PipeError),e.__compiled}function x(e,n={}){const t={context:()=>n.context??{},schema:r=>n.schema?.(r)??{},pipe:(...r)=>{delete t.__compiled;for(const o of r){const i=typeof o=="function"?h(o,n):o;t.next||(t.next=i),t.last&&(t.last.next=i),t.last=i.last??i}return t},compile:e,"~standard":{version:1,vendor:"valleyed",validate(r){const o=f(t,r);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:p})=>({message:i,path:p?p.split("."):void 0}))}}}};return t}function h(e,n={}){const t=`define_${(0,u.getRandomValue)()}`;return x(({input:r,context:o,path:i})=>[`${r} = ${o}['${t}'](${r})`,`if (${r} instanceof PipeError) return PipeError.path(${i}, ${r})`],{context:{...n?.context,[t]:e},schema:n?.schema})}function F(e){const n=(0,u.getRandomValue)(),{lines:t,context:r}=P({...e.opts,wrapError:(0,a.createErrorHandler)(e.input,e.errorType??e.opts.wrapError.type),pipe:e.pipe,input:e.input,context:`context[\`${n}\`]`,path:[e.opts.path,"key"in e?e.key:""].filter(Boolean).join(".")||void 0});return e.opts.rootContext[n]=r,t}function P({pipe:e,input:n,context:t,failEarly:r=!1,path:o="",rootContext:i,wrapError:p=(0,a.createErrorHandler)(n,"return"),base:s=[]}){const m=y(e);i??=m;const v=c(e,[],(E,d)=>(d.push(E.compile({input:n,context:t,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:r,path:o,wrapError:p})),d));return{lines:J(s,v.flat()),context:m}}function J(e,n){return(Array.isArray(n)?n:[n]).reduceRight((t,r)=>(typeof r=="string"?t.unshift(r):typeof r=="function"&&(t=r(t)),t),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: ['key' in data ? data.key : '', data.opts.path].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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,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>>(\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,CA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B,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 +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(\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,QACZ,CAAC;AAAA,QACD,OAAO,gBAAgB;AAAA,QACvB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O,qBAAO,OAAO,GAAG,EAAE,OAAO,CAAC;AAAA,MACnC;AAAA,IACD;AAAA,EACD;AACD;","names":["context","differMerge"]}
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,QACZ,CAAC;AAAA,QACD,OAAO,gBAAgB;AAAA,QACvB,IAAI,aAAa,wBAAwB,GAAG,KAAK,gBAAgB;AAAA,QACjE,GAAG,MAAM,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;AAAA,QAC3B,QAAQ,SA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c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},y=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of P(e))!l.call(t,o)&&o!==r&&c(t,o,{get:()=>e[o],enumerable:!(n=T(e,o))||n.enumerable});return t};var E=t=>y(c({},"__esModule",{value:!0}),t);var I={};d(I,{discriminate:()=>w,fromJson:()=>O,lazy:()=>h,merge:()=>x,or:()=>g,recursive:()=>v});module.exports=E(I);var u=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"}),`if (${e} instanceof PipeError) {`,` ${r}.push(PipeError.path(${i}, ${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:u.merge},schema:()=>({allOf:[(0,a.schema)(t),(0,a.schema)(e)]})})},w=(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))})}),O=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())}),v=(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});
1
+ "use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var r in e)u(t,r,{get:e[r],enumerable:!0})},y=(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=>y(u({},"__esModule",{value:!0}),t);var v={};d(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"}),`if (${e} instanceof PipeError) {`,` ${r}.push(PipeError.path(${i}, ${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(\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,QACZ,CAAC,EACD,OAAOA,CAAgB,2BACvB,IAAIC,CAAa,wBAAwBI,CAAG,KAAKL,CAAgB,KACjE,GAAGM,EAAM,IAAKC,GAAM,IAAIA,CAAC,EAAE,EAC3BF,IAAQN,EAAS,OAAS,EAAI,IAAII,EAAK,UAAU,OAAO,sBAAsBF,CAAa,GAAG,CAAC,GAAK,GACpG,IACA,QAAQC,CAAK,MAAMF,CAAgB,EACpC,CAAC,EACA,YAAsB,CAACQ,EAAKC,IAAQA,EAAID,CAAG,EAAG,CAAC,CAAC,EAClDL,EAAK,UAAU,GA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AAmB,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"]}
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,GAAA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AiB,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"]}
@@ -1,3 +1,3 @@
1
1
  import{createErrorHandler as y,PipeError as s}from "./errors.min.mjs";import{getRandomValue as f}from "../../utils/functions/index.min.mjs";function c(t,r,e){let n=r;for(;t;)n=e(t,n),t=t.next;return n}function x(t){return c(t,{},(r,e)=>({...e,...r.context()}))}function A(t,r){const e=m(t,r);if(!e.valid)throw e.error;return e.value}function m(t,r){try{const n=(t.__compiled??v(t))(r);return n instanceof s?{error:n,valid:!1}:{value:n,valid:!0}}catch(e){return e instanceof s?{error:e,valid:!1}:{error:s.root(e instanceof Error?e.message:`${e}`,r,void 0),valid:!1}}}function L(t,r={}){const e=x(t);return c(t,r,(n,o)=>({...o,...n.schema(e)}))}function M(t,r){return t.pipe(d(()=>[],{schema:()=>r}))}function v(t,{failEarly:r=!0}={}){const e="input",n="context",{lines:o,context:i}=P({pipe:t,input:e,context:n,failEarly:r,base:[`return ${e}`]}),a=[`return (${e}) => {`,...o.filter(p=>p.trim()!=="").map(p=>` ${p}`),` throw PipeError.root('unhandled root validation', ${e})`,"}"];return t.__compiled=new Function(n,"PipeError",a.join(`
2
- `))(i,s),t.__compiled}function d(t,r={}){const e={context:()=>r.context??{},schema:n=>r.schema?.(n)??{},pipe:(...n)=>{delete e.__compiled;for(const o of n){const i=typeof o=="function"?E(o,r):o;e.next||(e.next=i),e.last&&(e.last.next=i),e.last=i.last??i}return e},compile:t,"~standard":{version:1,vendor:"valleyed",validate(n){const o=m(e,n);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:a})=>({message:i,path:a?a.split("."):void 0}))}}}};return e}function E(t,r={}){const e=`define_${f()}`;return d(({input:n,context:o,path:i})=>[`${n} = ${o}['${e}'](${n})`,`if (${n} instanceof PipeError) return PipeError.path(${i}, ${n})`],{context:{...r?.context,[e]:t},schema:r?.schema})}function q(t){const r=f(),{lines:e,context:n}=P({...t.opts,wrapError:y(t.input,t.errorType??t.opts.wrapError.type),pipe:t.pipe,input:t.input,context:`context[\`${r}\`]`,path:["key"in t?t.key:"",t.opts.path].filter(Boolean).join(".")||void 0});return t.opts.rootContext[r]=n,e}function P({pipe:t,input:r,context:e,failEarly:n=!1,path:o="",rootContext:i,wrapError:a=y(r,"return"),base:p=[]}){const l=x(t);i??=l;const T=c(t,[],(h,u)=>(u.push(h.compile({input:r,context:e,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:n,path:o,wrapError:a})),u));return{lines:$(p,T.flat()),context:l}}function $(t,r){return(Array.isArray(r)?r:[r]).reduceRight((e,n)=>(typeof n=="string"?e.unshift(n):typeof n=="function"&&(e=n(e)),e),t)}export{A as assert,v as compile,q as compileNested,x as context,E as define,M as meta,L as schema,d as standard,m as validate,c as walk};
2
+ `))(i,s),t.__compiled}function d(t,r={}){const e={context:()=>r.context??{},schema:n=>r.schema?.(n)??{},pipe:(...n)=>{delete e.__compiled;for(const o of n){const i=typeof o=="function"?E(o,r):o;e.next||(e.next=i),e.last&&(e.last.next=i),e.last=i.last??i}return e},compile:t,"~standard":{version:1,vendor:"valleyed",validate(n){const o=m(e,n);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:a})=>({message:i,path:a?a.split("."):void 0}))}}}};return e}function E(t,r={}){const e=`define_${f()}`;return d(({input:n,context:o,path:i})=>[`${n} = ${o}['${e}'](${n})`,`if (${n} instanceof PipeError) return PipeError.path(${i}, ${n})`],{context:{...r?.context,[e]:t},schema:r?.schema})}function q(t){const r=f(),{lines:e,context:n}=P({...t.opts,wrapError:y(t.input,t.errorType??t.opts.wrapError.type),pipe:t.pipe,input:t.input,context:`context[\`${r}\`]`,path:[t.opts.path,"key"in t?t.key:""].filter(Boolean).join(".")||void 0});return t.opts.rootContext[r]=n,e}function P({pipe:t,input:r,context:e,failEarly:n=!1,path:o="",rootContext:i,wrapError:a=y(r,"return"),base:p=[]}){const l=x(t);i??=l;const T=c(t,[],(h,u)=>(u.push(h.compile({input:r,context:e,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:n,path:o,wrapError:a})),u));return{lines:$(p,T.flat()),context:l}}function $(t,r){return(Array.isArray(r)?r:[r]).reduceRight((e,n)=>(typeof n=="string"?e.unshift(n):typeof n=="function"&&(e=n(e)),e),t)}export{A as assert,v as compile,q as compileNested,x as context,E as define,M as meta,L as schema,d as standard,m as validate,c as walk};
3
3
  //# sourceMappingURL=pipes.min.mjs.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: ['key' in data ? data.key : '', data.opts.path].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,OAAS,sBAAAA,EAAoB,aAAAC,MAAiB,WAE9C,OAAS,kBAAAC,MAAsB,wBAGxB,SAASC,EAAQC,EAAsBC,EAASC,EAA4C,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,YAAAM,EAAa,UAAArB,EAAW,KAAAe,EAAM,UAAAO,CAAU,CAC3C,CACD,EACOpC,EACP,EAED,MAAO,CAAE,MADKwC,EAAeH,EAAME,EAAS,KAAK,CAAC,EAClC,QAASD,CAAI,CAC9B,CAEA,SAASE,EAAeH,EAAgBpB,EAA8C,CACrF,OAAQ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,YAAsB,CAACjB,EAAKwB,KACvE,OAAOA,GAAQ,SAAUxB,EAAI,QAAQwB,CAAG,EACnC,OAAOA,GAAQ,aAAYxB,EAAMwB,EAAIxB,CAAG,GAC1CA,GACLqC,CAAI,CACR","names":["createErrorHandler","PipeError","getRandomValue","walk","pipe","init","nodeFn","acc","context","p","assert","input","result","validate","res","compile","error","schema","cont","meta","standard","failEarly","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","define","value","validity","message","path","fn","key","compileNested","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>>(\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,OAAS,sBAAAA,EAAoB,aAAAC,MAAiB,WAE9C,OAAS,kBAAAC,MAAsB,wBAGxB,SAASC,EAAQC,EAAsBC,EAASC,EAA4C,CAClG,IAAIC,EAASF,EACb,KAAOD,GACNG,EAAMD,EAAOF,EAAMG,CAAG,EACtBH,EAAOA,EAAK,KAEb,OAAOG,CACR,CAEO,SAASC,EAAkCJ,EAAkB,CACnE,OAAOD,EAAKC,EAAM,C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EA,SAASE,EAAeH,EAAgBpB,EAA8C,CACrF,OAAQ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,YAAsB,CAACjB,EAAKwB,KACvE,OAAOA,GAAQ,SAAUxB,EAAI,QAAQwB,CAAG,EACnC,OAAOA,GAAQ,aAAYxB,EAAMwB,EAAIxB,CAAG,GAC1CA,GACLqC,CAAI,CACR","names":["createErrorHandler","PipeError","getRandomValue","walk","pipe","init","nodeFn","acc","context","p","assert","input","result","validate","res","compile","error","schema","cont","meta","standard","failEarly","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","define","value","validity","message","path","fn","key","compileNested","data","random","rootContext","wrapError","base","ctx","compiled","mergePipeLines"]}
@@ -107,7 +107,7 @@ function compileNested(data) {
107
107
  pipe: data.pipe,
108
108
  input: data.input,
109
109
  context: `context[\`${random}\`]`,
110
- path: ["key" in data ? data.key : "", data.opts.path].filter(Boolean).join(".") || void 0
110
+ path: [data.opts.path, "key" in data ? data.key : ""].filter(Boolean).join(".") || void 0
111
111
  });
112
112
  data.opts.rootContext[random] = context2;
113
113
  return lines;
@@ -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: ['key' in data ? data.key : '', data.opts.path].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,SAAS,oBAAoB,iBAAiB;AAE9C,SAAS,sBAAsB;AAGxB,SAAS,KAAQ,MAAsB,MAAS,QAA4C;AAClG,MAAI,MAAS;AACb,SAAO,MAAM;AACZ,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,KAAK;AAAA,E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I,MAAM,MAAS,GAAG;AAAA,QACxE,EAAE,aAAa,WAAW,MAAM,UAAU;AAAA,MAC3C;AAAA,IACD;AACA,WAAO;AAAA,EACR,CAAC;AACD,QAAM,QAAQ,eAAe,MAAM,SAAS,KAAK,CAAC;AAClD,SAAO,EAAE,OAAO,SAAS,IAAI;AAC9B;AAEA,SAAS,eAAe,MAAgB,OAA8C;AACrF,UAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG,YAAsB,CAAC,KAAK,QAAQ;AACnF,QAAI,OAAO,QAAQ,SAAU,KAAI,QAAQ,GAAG;AAAA,aACnC,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>>(\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,SAAS,oBAAoB,iBAAiB;AAE9C,SAAS,sBAAsB;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,KA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e,MAAgB,OAA8C;AACrF,UAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG,YAAsB,CAAC,KAAK,QAAQ;AACnF,QAAI,OAAO,QAAQ,SAAU,KAAI,QAAQ,GAAG;AAAA,aACnC,OAAO,QAAQ,WAAY,OAAM,IAAI,GAAG;AACjD,WAAO;AAAA,EACR,GAAG,IAAI;AACR;","names":["schema","meta","context","compile"]}
@@ -1,2 +1,2 @@
1
- import{merge as P}from "../utils/differ.min.mjs";import{getRandomValue as c,wrapInTryCatch as f}from "../utils/functions/index.min.mjs";import{compileNested as i,context as l,standard as u,schema as s,define as d,validate as y}from "./base/pipes.min.mjs";const I=a=>{const e=`validated_${c()}`,r=`errors_${c()}`;return u(({input:t},n)=>a.length===0?[]:[`const ${r} = []`,`let ${e}`,...a.map((o,p)=>$=>[`${e} = ${t}`,...i({opts:{...n,failEarly:!0},pipe:o,input:e,errorType:"assign"}),`if (${e} instanceof PipeError) {`,` ${r}.push(PipeError.path(${p}, ${e}))`,...$.map(m=>` ${m}`),p===a.length-1?` ${n.wrapError.format(`PipeError.rootFrom(${r})`)}`:"","}",`else ${t} = ${e}`]).reduceRight((o,p)=>p(o),[]),n.wrapError(`${t} instanceof PipeError`,t)],{schema:()=>({oneOf:a.map(t=>s(t))})})},B=(a,e)=>{const r=`input_${c()}`;return u(({input:t,context:n},o)=>[`let ${r}A = ${t}`,`let ${r}B = ${t}`,...i({opts:o,pipe:a,input:`${r}A`}),o.wrapError(`${r}A instanceof PipeError`,`${r}A`),...i({opts:o,pipe:e,input:`${r}B`}),o.wrapError(`${r}B instanceof PipeError`,`${r}B`),`${t} = ${n}.differMerge(${r}A, ${r}B)`],{context:{differMerge:P},schema:()=>({allOf:[s(a),s(e)]})})},V=(a,e,r="doesnt match any of the schema")=>u(({input:t,context:n,path:o},p)=>[`switch (${n}.wrapInTryCatch(() => ${n}.discriminator(${t}))) {`,...Object.entries(e).flatMap(([$,m])=>[` case ('${$}'): {`,...i({opts:p,pipe:m,input:t}).map(T=>` ${T}`)," break"," }"]),` default: ${p.wrapError.format(`PipeError.root("${r}", ${t}, ${o})`)}`,"}"],{context:{wrapInTryCatch:f,discriminator:a},schema:()=>({oneOf:Object.values(e).map(t=>s(t))})}),A=a=>{const e=`validated_${c()}`;return u(({input:r,context:t},n)=>[`let ${e} = ${r}`,...i({opts:n,pipe:a,input:e,errorType:"assign"}),`if (${e} instanceof PipeError) {`,n.wrapError(`${r}?.constructor?.name !== 'String'`,e),` ${e} = ${t}.wrapInTryCatch(() => JSON.parse(${r}), ${e})`,n.wrapError(`${e} instanceof PipeError`,e),...i({opts:n,pipe:a,input:e,errorType:"assign"}).map(o=>` ${o}`),n.wrapError(`${e} instanceof PipeError`,e),"}",`${r} = ${e}`],{context:{...l(a),wrapInTryCatch:f},schema:a.schema})},_=a=>d(e=>{const r=y(a(),e);return r.valid?r.value:r.error},{schema:()=>s(a())}),k=(a,e)=>{const r=`fn_${c()}`;let t=!1,n=!1;return u(({input:o},p)=>{const $=[`${o} = ${r}(${o})`,p.wrapError(`${o} instanceof PipeError`,o)];return t?$:(t=!0,[`function ${r}(node) {`,...i({opts:{...p,failEarly:!0},pipe:a(),input:"node",errorType:"return"}).map(m=>` ${m}`),"}",...$])},{schema:()=>n?{$refId:e}:(n=!0,s(a(),{$refId:e}))})};export{V as discriminate,A as fromJson,_ as lazy,B as merge,I as or,k as recursive};
1
+ import{merge as P}from "../utils/differ.min.mjs";import{getRandomValue as u,wrapInTryCatch as f}from "../utils/functions/index.min.mjs";import{compileNested as i,context as l,standard as c,schema as s,define as d,validate as y}from "./base/pipes.min.mjs";const v=a=>{const e=`validated_${u()}`,r=`errors_${u()}`;return c(({input:t},n)=>a.length===0?[]:[`const ${r} = []`,`let ${e}`,...a.map((o,p)=>$=>[`${e} = ${t}`,...i({opts:{...n,failEarly:!0},pipe:o,input:e,errorType:"assign"}),`if (${e} instanceof PipeError) {`,` ${r}.push(PipeError.path(${p}, ${e}))`,...$.map(m=>` ${m}`),p===a.length-1?` ${n.wrapError.format(`PipeError.rootFrom(${r})`)}`:"","}",`else ${t} = ${e}`]).reduceRight((o,p)=>p(o),[]),n.wrapError(`${t} instanceof PipeError`,t)],{schema:()=>({oneOf:a.map(t=>s(t))})})},B=(a,e)=>{const r=`input_${u()}`;return c(({input:t,context:n},o)=>[`let ${r}A = ${t}`,`let ${r}B = ${t}`,...i({opts:o,pipe:a,input:`${r}A`}),o.wrapError(`${r}A instanceof PipeError`,`${r}A`),...i({opts:o,pipe:e,input:`${r}B`}),o.wrapError(`${r}B instanceof PipeError`,`${r}B`),`${t} = ${n}.differMerge(${r}A, ${r}B)`],{context:{differMerge:P},schema:()=>({allOf:[s(a),s(e)]})})},V=(a,e,r="doesnt match any of the schema")=>c(({input:t,context:n,path:o},p)=>[`switch (${n}.wrapInTryCatch(() => ${n}.discriminator(${t}))) {`,...Object.entries(e).flatMap(([$,m])=>[` case ('${$}'): {`,...i({opts:p,pipe:m,input:t}).map(T=>` ${T}`)," break"," }"]),` default: ${p.wrapError.format(`PipeError.root("${r}", ${t}, ${o})`)}`,"}"],{context:{wrapInTryCatch:f,discriminator:a},schema:()=>({oneOf:Object.values(e).map(t=>s(t))})}),A=a=>{const e=`validated_${u()}`;return c(({input:r,context:t},n)=>[`let ${e} = ${r}`,...i({opts:n,pipe:a,input:e,errorType:"assign"}),`if (${e} instanceof PipeError) {`,n.wrapError(`${r}?.constructor?.name !== 'String'`,e),` ${e} = ${t}.wrapInTryCatch(() => JSON.parse(${r}), ${e})`,n.wrapError(`${e} instanceof PipeError`,e),...i({opts:n,pipe:a,input:e,errorType:"assign"}).map(o=>` ${o}`),n.wrapError(`${e} instanceof PipeError`,e),"}",`${r} = ${e}`],{context:{...l(a),wrapInTryCatch:f},schema:a.schema})},_=a=>d(e=>{const r=y(a(),e);return r.valid?r.value:r.error},{schema:()=>s(a())}),k=(a,e)=>{const r=`fn_${u()}`;let t=!1,n=!1;return c(({input:o},p)=>{const $=[`${o} = ${r}(${o})`,p.wrapError(`${o} instanceof PipeError`,o)];return t?$:(t=!0,[`function ${r}(node) {`,...i({opts:{...p,failEarly:!0},pipe:a(),input:"node",errorType:"return"}).map(m=>` ${m}`),"}",...$])},{schema:()=>n?{$refId:e}:(n=!0,s(a(),{$refId:e}))})};export{V as discriminate,A as fromJson,_ as lazy,B as merge,v as or,k as recursive};
2
2
  //# sourceMappingURL=junctions.min.mjs.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(\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":"AACA,OAAS,SAASA,MAAmB,kBACrC,OAAS,kBAAAC,EAAgB,kBAAAC,MAAsB,qBAC/C,OAAS,iBAAAC,EAAe,WAAAC,EAAS,YAAAC,EAAU,UAAAC,EAAQ,UAAAC,EAAQ,YAAAC,MAAgB,eAEpE,MAAMC,EAAkCC,GAAgB,CAC9D,MAAMC,EAAmB,aAAaV,EAAe,CAAC,GAChDW,EAAgB,UAAUX,EAAe,CAAC,GAChD,OAAOI,EACN,CAAC,CAAE,MAAAQ,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,GAAGV,EAAc,CAChB,KAAM,CAAE,GAAGW,EAAM,UAAW,EAAK,EACjC,KAAMC,EACN,MAAOJ,EACP,UAAW,QACZ,CAAC,EACD,OAAOA,CAAgB,2B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,IACA,GAAGE,CAAK,MAAMF,CAAgB,EAC/B,EACA,CACC,QAAS,CAAE,GAAGP,EAAQW,CAAM,EAAG,eAAAb,CAAe,EAC9C,OAAQa,EAAO,MAChB,CACD,CACD,EAEaiB,EAAkCC,GAC9C1B,EACEM,GAAU,CACV,MAAMqB,EAAS1B,EAASyB,EAAO,EAAGpB,CAAK,EACvC,OAAOqB,EAAO,MAAQA,EAAO,MAAQA,EAAO,KAC7C,EACA,CACC,OAAQ,IAAM5B,EAAO2B,EAAO,CAAC,CAC9B,CACD,EAEYE,EAAY,CAA2BF,EAAiBG,IAAmB,CACvF,MAAMC,EAAY,MAAMpC,EAAe,CAAC,GACxC,IAAIqC,EAAiB,GACjBC,EAAgB,GACpB,OAAOlC,EACN,CAAC,CAAE,MAAAQ,CAAM,EAAGC,IAAS,CACpB,MAAM0B,EAAS,CAAC,GAAG3B,CAAK,MAAMwB,CAAS,IAAIxB,CAAK,IAAKC,EAAK,UAAU,GAAGD,CAAK,wBAAyBA,CAAK,CAAC,EAC3G,OAAIyB,EAAuBE,GAC3BF,EAAiB,GACV,CACN,YAAYD,CAAS,WACrB,GAAGlC,EAAc,CAAE,KAAM,CAAE,GAAGW,EAAM,UAAW,EAAK,EAAG,KAAMmB,EAAO,EAAG,MAAO,OAAQ,UAAW,QAAS,CAAC,EAAE,IAC3Gf,GAAM,IAAIA,CAAC,EACb,EACA,IACA,GAAGsB,CACJ,EACD,EACA,CACC,OAAQ,IACHD,EAAsB,CAAE,OAAAH,CAAO,GACnCG,EAAgB,GACTjC,EAAO2B,EAAO,EAAG,CAAE,OAAAG,CAAO,CAAC,EAEpC,CACD,CACD","names":["differMerge","getRandomValue","wrapInTryCatch","compileNested","context","standard","schema","define","validate","or","branches","validatedVarname","errorsVarname","input","opts","branch","idx","lines","l","acc","cur","merge","branch1","branch2","inputVarname","discriminate","discriminator","err","path","key","s","fromJson","lazy","pipeFn","result","recursive","$refId","fnVarname","compiledBefore","schemedBefore","common"]}
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":"AACA,OAAS,SAASA,MAAmB,kBACrC,OAAS,kBAAAC,EAAgB,kBAAAC,MAAsB,qBAC/C,OAAS,iBAAAC,EAAe,WAAAC,EAAS,YAAAC,EAAU,UAAAC,EAAQ,UAAAC,EAAQ,YAAAC,MAAgB,eAEpE,MAAMC,EAAkCC,GAAgB,CAC9D,MAAMC,EAAmB,aAAaV,EAAe,CAAC,GAChDW,EAAgB,UAAUX,EAAe,CAAC,GAChD,OAAOI,EACN,CAAC,CAAE,MAAAQ,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,GAAGV,EAAc,CAChB,KAAM,CAAE,GAAGW,EAAM,UAAW,EAAK,EACjC,KAAMC,EACN,MAAOJ,EACP,UAAW,QACZ,CAAC,EACD,OAAOA,CAAgB,2BACvB,IAAIC,CAAa,wBAAwBI,CAAG,KAAKL,CAAgB,KACjE,GAAGM,EAAM,IAAKC,GAAM,IAAIA,CAAC,EAAE,EAC3BF,IAAQN,EAAS,OAAS,EAAI,IAAII,EAAK,UAAU,OAAO,sBAAsBF,CAAa,GAAG,CAAC,GAAK,GACpG,IACA,QAAQC,CAAK,MAAMF,CAAgB,EACpC,CAAC,EACA,YAAsB,CAACQ,EAA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A,EAAO,KAC7C,EACA,CACC,OAAQ,IAAM5B,EAAO2B,EAAO,CAAC,CAC9B,CACD,EAEYE,EAAY,CAA2BF,EAAiBG,IAAmB,CACvF,MAAMC,EAAY,MAAMpC,EAAe,CAAC,GACxC,IAAIqC,EAAiB,GACjBC,EAAgB,GACpB,OAAOlC,EACN,CAAC,CAAE,MAAAQ,CAAM,EAAGC,IAAS,CACpB,MAAM0B,EAAS,CAAC,GAAG3B,CAAK,MAAMwB,CAAS,IAAIxB,CAAK,IAAKC,EAAK,UAAU,GAAGD,CAAK,wBAAyBA,CAAK,CAAC,EAC3G,OAAIyB,EAAuBE,GAC3BF,EAAiB,GACV,CACN,YAAYD,CAAS,WACrB,GAAGlC,EAAc,CAAE,KAAM,CAAE,GAAGW,EAAM,UAAW,EAAK,EAAG,KAAMmB,EAAO,EAAG,MAAO,OAAQ,UAAW,QAAS,CAAC,EAAE,IAC3Gf,GAAM,IAAIA,CAAC,EACb,EACA,IACA,GAAGsB,CACJ,EACD,EACA,CACC,OAAQ,IACHD,EAAsB,CAAE,OAAAH,CAAO,GACnCG,EAAgB,GACTjC,EAAO2B,EAAO,EAAG,CAAE,OAAAG,CAAO,CAAC,EAEpC,CACD,CACD","names":["differMerge","getRandomValue","wrapInTryCatch","compileNested","context","standard","schema","define","validate","or","branches","validatedVarname","errorsVarname","input","opts","branch","idx","lines","l","acc","cur","merge","branch1","branch2","inputVarname","discriminate","discriminator","err","path","key","s","fromJson","lazy","pipeFn","result","recursive","$refId","fnVarname","compiledBefore","schemedBefore","common"]}
@@ -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(\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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AEM,MAAM,YAAY,CAA2B,QAAiB,WAAmB;AACvF,QAAM,YAAY,MAAM,eAAe,CAAC;AACxC,MAAI,iBAAiB;AACrB,MAAI,gBAAgB;AACpB,SAAO;AAAA,IACN,CAAC,EAAE,MAAM,GAAG,SAAS;AACpB,YAAM,SAAS,CAAC,GAAG,KAAK,MAAM,SAAS,IAAI,KAAK,KAAK,KAAK,UAAU,GAAG,KAAK,yBAAyB,KAAK,CAAC;AAC3G,UAAI,eAAgB,QAAO;AAC3B,uBAAiB;AACjB,aAAO;AAAA,QACN,YAAY,SAAS;AAAA,QACrB,GAAG,cAAc,EAAE,MAAM,EAAE,GAAG,MAAM,WAAW,KAAK,GAAG,MAAM,OAAO,GAAG,OAAO,QAAQ,WAAW,SAAS,CAAC,EAAE;AAAA,UAC5G,CAAC,MAAM,IAAI,CAAC;AAAA,QACb;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACJ;AAAA,IACD;AAAA,IACA;AAAA,MACC,QAAQ,MAAM;AACb,YAAI,cAAe,QAAO,EAAE,OAAO;AACnC,wBAAgB;AAChB,eAAO,OAAO,OAAO,GAAG,EAAE,OAAO,CAAC;AAAA,MACnC;AAAA,IACD;AAAA,EACD;AACD;","names":["context"]}
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":"AACA,SAAS,SAAS,mBAAmB;AACrC,SAAS,gBAAgB,sBAAsB;AAC/C,SAAS,eAAe,SAAS,UAAU,QAAQ,QAAQ,gBAAgB;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S,CAAC,GAAG,KAAK,MAAM,SAAS,IAAI,KAAK,KAAK,KAAK,UAAU,GAAG,KAAK,yBAAyB,KAAK,CAAC;AAC3G,UAAI,eAAgB,QAAO;AAC3B,uBAAiB;AACjB,aAAO;AAAA,QACN,YAAY,SAAS;AAAA,QACrB,GAAG,cAAc,EAAE,MAAM,EAAE,GAAG,MAAM,WAAW,KAAK,GAAG,MAAM,OAAO,GAAG,OAAO,QAAQ,WAAW,SAAS,CAAC,EAAE;AAAA,UAC5G,CAAC,MAAM,IAAI,CAAC;AAAA,QACb;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACJ;AAAA,IACD;AAAA,IACA;AAAA,MACC,QAAQ,MAAM;AACb,YAAI,cAAe,QAAO,EAAE,OAAO;AACnC,wBAAgB;AAChB,eAAO,OAAO,OAAO,GAAG,EAAE,OAAO,CAAC;AAAA,MACnC;AAAA,IACD;AAAA,EACD;AACD;","names":["context"]}
@@ -107,7 +107,7 @@ function compileNested(data) {
107
107
  pipe: data.pipe,
108
108
  input: data.input,
109
109
  context: `context[\`${random}\`]`,
110
- path: ["key" in data ? data.key : "", data.opts.path].filter(Boolean).join(".") || void 0
110
+ path: [data.opts.path, "key" in data ? data.key : ""].filter(Boolean).join(".") || void 0
111
111
  });
112
112
  data.opts.rootContext[random] = context2;
113
113
  return lines;
@@ -6,7 +6,7 @@ declare const or: <T extends Pipe<any, any>[]>(branches: T) => Pipe<PipeInput<T[
6
6
  declare const merge: <T1 extends Pipe<any, any>, T2 extends Pipe<any, any>>(branch1: T1, branch2: T2) => Pipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>>;
7
7
  declare const discriminate: <T extends Record<PropertyKey, Pipe<any, any>>>(discriminator: (val: PipeInput<T[keyof T]>) => PropertyKey, branches: T, err?: string) => Pipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>>;
8
8
  declare const fromJson: <T extends Pipe<any, any>>(branch: T) => Pipe<PipeInput<T>, PipeOutput<T>>;
9
- declare const lazy: <T extends Pipe<any, any>>(pipeFn: () => T) => Pipe<unknown, PipeOutput<T>>;
9
+ declare const lazy: <T extends Pipe<any, any>>(pipeFn: () => T) => Pipe<PipeInput<T>, PipeOutput<T>>;
10
10
  declare const recursive: <T extends Pipe<any, any>>(pipeFn: () => T, $refId: string) => Pipe<PipeInput<T>, PipeOutput<T>>;
11
11
 
12
12
  export { discriminate, fromJson, lazy, merge, or, recursive };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valleyed",
3
- "version": "4.5.12",
3
+ "version": "4.5.14",
4
4
  "description": "A lightweight package with definitions for various validation rules, and helper services to consume said rules.",
5
5
  "type": "module",
6
6
  "sideEffects": false,