valleyed 4.5.9 → 4.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/api/junctions.cjs +5 -0
- package/dist/cjs/api/junctions.cjs.map +1 -1
- package/dist/cjs/api/junctions.min.cjs +1 -1
- package/dist/cjs/api/junctions.min.cjs.map +1 -1
- package/dist/esm/api/junctions.min.mjs +1 -1
- package/dist/esm/api/junctions.min.mjs.map +1 -1
- package/dist/esm/api/junctions.mjs +4 -0
- package/dist/esm/api/junctions.mjs.map +1 -1
- package/dist/types/api/externals.d.ts +1 -1
- package/dist/types/api/index.d.ts +3 -2
- package/dist/types/api/junctions.d.ts +2 -1
- package/dist/types/api/junctions.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [4.5.10](https://github.com/kevinand11/valleyed/compare/v4.5.9...v4.5.10) (2025-06-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* v lazy ([6cbf1a1](https://github.com/kevinand11/valleyed/commit/6cbf1a1834d4400d599b55043b37d9781b792b37))
|
|
11
|
+
|
|
5
12
|
### [4.5.9](https://github.com/kevinand11/valleyed/compare/v4.5.8...v4.5.9) (2025-06-27)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -21,6 +21,7 @@ __export(junctions_exports, {
|
|
|
21
21
|
and: () => and,
|
|
22
22
|
discriminate: () => discriminate,
|
|
23
23
|
fromJson: () => fromJson,
|
|
24
|
+
lazy: () => lazy,
|
|
24
25
|
merge: () => merge,
|
|
25
26
|
or: () => or
|
|
26
27
|
});
|
|
@@ -82,11 +83,15 @@ const fromJson = (pipe2) => (0, import_pipes.branch)(
|
|
|
82
83
|
schema: (s) => s
|
|
83
84
|
}
|
|
84
85
|
);
|
|
86
|
+
const lazy = (pipeFn, rootSchemaPipe) => (0, import_pipes.pipe)((input) => (0, import_pipes.assert)(pipeFn(), input), {
|
|
87
|
+
schema: () => (0, import_pipes.schema)(rootSchemaPipe ?? pipeFn())
|
|
88
|
+
});
|
|
85
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
86
90
|
0 && (module.exports = {
|
|
87
91
|
and,
|
|
88
92
|
discriminate,
|
|
89
93
|
fromJson,
|
|
94
|
+
lazy,
|
|
90
95
|
merge,
|
|
91
96
|
or
|
|
92
97
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t\tcontext: (c) => c,\n\t\t\tschema: (s) => s,\n\t\t},\n\t)\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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UAAM,eAAW,iCAAe,MAAM,cAAc,KAAK,CAAC;AAC1D,QAAI,CAAC,QAAQ,QAAQ,EAAG,OAAM,sBAAU,KAAK,KAAK,KAAK;AACvD,eAAO,qBAAO,QAAQ,QAAQ,GAAG,KAAK;AAAA,EACvC;AAAA,EACA;AAAA,IACC,QAAQ,OAAO,EAAE,OAAO,OAAO,OAAO,OAAO,EAAE,IAAI,CAAC,UAAM,qBAAO,CAAC,CAAC,EAAE;AAAA,EACtE;AACD;AAEM,MAAM,WAAW,CAAgCF,cACvD;AAAA,EACCA;AAAA,EACA,CAAC,UAAU;AACV,UAAM,eAAW,uBAASA,OAAM,KAAK;AACrC,QAAI,SAAS,MAAO,QAAO,SAAS;AACpC,QAAI,OAAO,aAAa,SAAS,SAAU,OAAM,SAAS;AAE1D,UAAM,aAAS,iCAAe,MAAM,KAAK,MAAM,KAAK,GAAG,SAAS,KAAK;AACrE,QAAI,WAAW,SAAS,MAAO,OAAM,SAAS;AAC9C,eAAO,qBAAOA,OAAM,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,IACC,SAAS,CAAC,MAAM;AAAA,IAChB,QAAQ,CAAC,MAAM;AAAA,EAChB;AACD;","names":["pipe","branch","differMerge"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t\tcontext: (c) => c,\n\t\t\tschema: (s) => s,\n\t\t},\n\t)\n\nexport const lazy = <T extends Pipe<any, any, any>>(pipeFn: () => T, rootSchemaPipe?: Pipe<any, any, any>) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>((input) => assert(pipeFn(), input), {\n\t\tschema: () => schema(rootSchemaPipe ?? pipeFn()),\n\t})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoE;AACpE,oBAAqC;AACrC,uBAA+B;AAC/B,mBAAuD;AAEhD,MAAM,KAAK,CAAkC,cACnD;AAAA,EACC,CAAC,UAAU;AACV,QAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,UAAM,SAAsB,CAAC;AAC7B,eAAW,CAAC,KAAKA,KAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,YAAM,eAAW,uBAASA,OAAM,KAAK;AACrC,UAAI,SAAS,MAAO,QAAO,SAAS;AACpC,aAAO,KAAK,sBAAU,KAAK,KAAK,SAAS,OAAO,KAAK,CAAC;AAAA,IACvD;AACA,UAAM,sBAAU,SAAS,QAAQ,KAAK;AAAA,EACvC;AAAA,EACA,EAAE,QAAQ,OAAO,EAAE,OAAO,MAAM,IAAI,CAACC,gBAAW,qBAAOA,OAAM,CAAC,EAAE,GAAG;AACpE;AAEM,MAAM,MAAM,CAAgC,cAClD;AAAA,EACC,CAAC,UAAU;AACV,eAAW,CAAC,KAAKD,KAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,YAAM,eAAW,uBAASA,OAAM,KAAK;A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,IAChB,QAAQ,CAAC,MAAM;AAAA,EAChB;AACD;AAEM,MAAM,OAAO,CAAgC,QAAiB,uBACpE,mBAAkD,CAAC,cAAU,qBAAO,OAAO,GAAG,KAAK,GAAG;AAAA,EACrF,QAAQ,UAAM,qBAAO,kBAAkB,OAAO,CAAC;AAChD,CAAC;","names":["pipe","branch","differMerge"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var o in e)T(t,o,{get:e[o],enumerable:!0})},m=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of c(e))!u.call(t,a)&&a!==o&&T(t,a,{get:()=>e[a],enumerable:!(n=P(e,a))||n.enumerable});return t};var x=t=>m(T({},"__esModule",{value:!0}),t);var C={};f(C,{and:()=>l,discriminate:()=>O,fromJson:()=>v,lazy:()=>I,merge:()=>h,or:()=>d});module.exports=x(C);var p=require('./base/index.min.cjs'),y=require('../utils/differ.min.cjs'),s=require('../utils/functions/index.min.cjs'),r=require('./base/pipes.min.cjs');const d=t=>(0,r.pipe)(e=>{if(t.length===0)return e;const o=[];for(const[n,a]of Object.entries(t)){const i=(0,r.validate)(a,e);if(i.valid)return i.value;o.push(p.PipeError.path(n,i.error,e))}throw p.PipeError.rootFrom(o,e)},{schema:()=>({oneOf:t.map(e=>(0,r.schema)(e))})}),l=t=>(0,r.pipe)(e=>{for(const[o,n]of Object.entries(t)){const a=(0,r.validate)(n,e);if(!a.valid)throw p.PipeError.path(o,a.error,e);e=a.value}return e},{schema:()=>({allOf:t.map(e=>(0,r.schema)(e))})}),h=(t,e)=>(0,r.pipe)(o=>(0,y.merge)((0,r.assert)(t,o),(0,r.assert)(e,o)),{schema:()=>({allOf:[(0,r.schema)(t),(0,r.schema)(e)]})}),O=(t,e,o="doesnt match any of the schema")=>(0,r.pipe)(n=>{const a=(0,s.wrapInTryCatch)(()=>t(n));if(!e[a])throw p.PipeError.root(o,n);return(0,r.assert)(e[a],n)},{schema:()=>({oneOf:Object.values(e).map(n=>(0,r.schema)(n))})}),v=t=>(0,r.branch)(t,e=>{const o=(0,r.validate)(t,e);if(o.valid)return o.value;if(e?.constructor?.name!=="String")throw o.error;const n=(0,s.wrapInTryCatch)(()=>JSON.parse(e),o.error);if(n===o.error)throw o.error;return(0,r.assert)(t,n)},{context:e=>e,schema:e=>e}),I=(t,e)=>(0,r.pipe)(o=>(0,r.assert)(t(),o),{schema:()=>(0,r.schema)(e??t())});0&&(module.exports={and,discriminate,fromJson,lazy,merge,or});
|
|
2
2
|
//# sourceMappingURL=junctions.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t\tcontext: (c) => c,\n\t\t\tschema: (s) => s,\n\t\t},\n\t)\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,iBAAAC,EAAA,aAAAC,EAAA,UAAAC,EAAA,OAAAC,IAAA,eAAAC,
|
|
1
|
+
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t\tcontext: (c) => c,\n\t\t\tschema: (s) => s,\n\t\t},\n\t)\n\nexport const lazy = <T extends Pipe<any, any, any>>(pipeFn: () => T, rootSchemaPipe?: Pipe<any, any, any>) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>((input) => assert(pipeFn(), input), {\n\t\tschema: () => schema(rootSchemaPipe ?? pipeFn()),\n\t})\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,iBAAAC,EAAA,aAAAC,EAAA,SAAAC,EAAA,UAAAC,EAAA,OAAAC,IAAA,eAAAC,EAAAR,GAAA,IAAAS,EAAoE,kBACpEC,EAAqC,2BACrCC,EAA+B,8BAC/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,EAAQE,CAAQ,EAAGZ,CAAK,CACvC,EACA,CACC,OAAQ,KAAO,CAAE,MAAO,OAAO,OAAOU,CAAO,EAAE,IAAKG,MAAM,UAAOA,CAAC,CAAC,CAAE,EACtE,CACD,EAEYvB,EAA2Ca,MACvD,UACCA,EACCH,GAAU,CACV,MAAMI,KAAW,YAASD,EAAMH,CAAK,EACrC,GAAII,EAAS,MAAO,OAAOA,EAAS,MACpC,GAAIJ,GAAO,aAAa,OAAS,SAAU,MAAMI,EAAS,MAE1D,MAAMU,KAAS,kBAAe,IAAM,KAAK,MAAMd,CAAK,EAAGI,EAAS,KAAK,EACrE,GAAIU,IAAWV,EAAS,MAAO,MAAMA,EAAS,MAC9C,SAAO,UAAOD,EAAMW,CAAM,CAC3B,EACA,CACC,QAAUC,GAAMA,EAChB,OAASF,GAAMA,CAChB,CACD,EAEYtB,EAAO,CAAgCyB,EAAiBC,OACpE,QAAmDjB,MAAU,UAAOgB,EAAO,EAAGhB,CAAK,EAAG,CACrF,OAAQ,OAAM,UAAOiB,GAAkBD,EAAO,CAAC,CAChD,CAAC","names":["junctions_exports","__export","and","discriminate","fromJson","lazy","merge","or","__toCommonJS","import_base","import_differ","import_functions","import_pipes","pipes","input","errors","idx","pipe","validity","branch","branch1","branch2","differMerge","discriminator","schemas","err","accessor","s","parsed","c","pipeFn","rootSchemaPipe"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{PipeError as
|
|
1
|
+
import{PipeError as T}from "./base/index.min.mjs";import{merge as c}from "../utils/differ.min.mjs";import{wrapInTryCatch as P}from "../utils/functions/index.min.mjs";import{assert as p,branch as u,pipe as i,schema as a,validate as y}from "./base/pipes.min.mjs";const I=t=>i(e=>{if(t.length===0)return e;const r=[];for(const[o,n]of Object.entries(t)){const s=y(n,e);if(s.valid)return s.value;r.push(T.path(o,s.error,e))}throw T.rootFrom(r,e)},{schema:()=>({oneOf:t.map(e=>a(e))})}),C=t=>i(e=>{for(const[r,o]of Object.entries(t)){const n=y(o,e);if(!n.valid)throw T.path(r,n.error,e);e=n.value}return e},{schema:()=>({allOf:t.map(e=>a(e))})}),w=(t,e)=>i(r=>c(p(t,r),p(e,r)),{schema:()=>({allOf:[a(t),a(e)]})}),b=(t,e,r="doesnt match any of the schema")=>i(o=>{const n=P(()=>t(o));if(!e[n])throw T.root(r,o);return p(e[n],o)},{schema:()=>({oneOf:Object.values(e).map(o=>a(o))})}),g=t=>u(t,e=>{const r=y(t,e);if(r.valid)return r.value;if(e?.constructor?.name!=="String")throw r.error;const o=P(()=>JSON.parse(e),r.error);if(o===r.error)throw r.error;return p(t,o)},{context:e=>e,schema:e=>e}),k=(t,e)=>i(r=>p(t(),r),{schema:()=>a(e??t())});export{C as and,b as discriminate,g as fromJson,k as lazy,w as merge,I as or};
|
|
2
2
|
//# sourceMappingURL=junctions.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t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AC,CAAE,EAAG,CACjE,EAEYC,EAAe,CAC3BC,EACAC,EACAC,EAAM,mCAENhB,EACEK,GAAU,CACV,MAAMY,EAAWpB,EAAe,IAAMiB,EAAcT,CAAK,CAAC,EAC1D,GAAI,CAACU,EAAQE,CAAQ,EAAG,MAAMtB,EAAU,KAAKqB,EAAKX,CAAK,EACvD,OAAOP,EAAOiB,EAAQE,CAAQ,EAAGZ,CAAK,CACvC,EACA,CACC,OAAQ,KAAO,CAAE,MAAO,OAAO,OAAOU,CAAO,EAAE,IAAKG,GAAMjB,EAAOiB,CAAC,CAAC,CAAE,EACtE,CACD,EAEYC,EAA2CnB,GACvDD,EACCC,EACCK,GAAU,CACV,MAAMG,EAAWN,EAASF,EAAMK,CAAK,EACrC,GAAIG,EAAS,MAAO,OAAOA,EAAS,MACpC,GAAIH,GAAO,aAAa,OAAS,SAAU,MAAMG,EAAS,MAE1D,MAAMY,EAASvB,EAAe,IAAM,KAAK,MAAMQ,CAAK,EAAGG,EAAS,KAAK,EACrE,GAAIY,IAAWZ,EAAS,MAAO,MAAMA,EAAS,MAC9C,OAAOV,EAAOE,EAAMoB,CAAM,CAC3B,EACA,CACC,QAAUC,GAAMA,EAChB,OAASH,GAAMA,CAChB,CACD","names":["PipeError","differMerge","wrapInTryCatch","assert","branch","pipe","schema","validate","or","pipes","input","errors","idx","validity","and","merge","branch1","branch2","discriminate","discriminator","schemas","err","accessor","s","fromJson","parsed","c"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t\tcontext: (c) => c,\n\t\t\tschema: (s) => s,\n\t\t},\n\t)\n\nexport const lazy = <T extends Pipe<any, any, any>>(pipeFn: () => T, rootSchemaPipe?: Pipe<any, any, any>) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>((input) => assert(pipeFn(), input), {\n\t\tschema: () => schema(rootSchemaPipe ?? pipeFn()),\n\t})\n"],"mappings":"AAAA,OAA4B,aAAAA,MAAwC,SACpE,OAAS,SAASC,MAAmB,kBACrC,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,UAAAC,EAAQ,UAAAC,EAAQ,QAAAC,EAAM,UAAAC,EAAQ,YAAAC,MAAgB,eAEhD,MAAMC,EAAuCC,GACnDJ,EACEK,GAAU,CACV,GAAID,EAAM,SAAW,EAAG,OAAOC,EAC/B,MAAMC,EAAsB,CAAC,EAC7B,SAAW,CAACC,EAAKP,CAAI,IAAK,OAAO,QAAQI,CAAK,EAAG,CAChD,MAAMI,EAAWN,EAASF,EAAMK,CAAK,EACrC,GAAIG,EAAS,MAAO,OAAOA,EAAS,MACpCF,EAAO,KAAKX,EAAU,KAAKY,EAAKC,EAAS,MAAOH,CAAK,CAAC,CACvD,CACA,MAAMV,EAAU,SAASW,EAAQD,CAAK,CACvC,EACA,CAAE,OAAQ,KAAO,CAAE,MAAOD,EAAM,IAAKL,GAAWE,EAAOF,CAAM,CAAC,CAAE,EAAG,CACpE,EAEYU,EAAsC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CAAM,CAC3B,EACA,CACC,QAAUC,GAAMA,EAChB,OAASH,GAAMA,CAChB,CACD,EAEYI,EAAO,CAAgCC,EAAiBC,IACpExB,EAAmDK,GAAUP,EAAOyB,EAAO,EAAGlB,CAAK,EAAG,CACrF,OAAQ,IAAMJ,EAAOuB,GAAkBD,EAAO,CAAC,CAChD,CAAC","names":["PipeError","differMerge","wrapInTryCatch","assert","branch","pipe","schema","validate","or","pipes","input","errors","idx","validity","and","merge","branch1","branch2","discriminate","discriminator","schemas","err","accessor","s","fromJson","parsed","c","lazy","pipeFn","rootSchemaPipe"]}
|
|
@@ -55,10 +55,14 @@ const fromJson = (pipe2) => branch(
|
|
|
55
55
|
schema: (s) => s
|
|
56
56
|
}
|
|
57
57
|
);
|
|
58
|
+
const lazy = (pipeFn, rootSchemaPipe) => pipe((input) => assert(pipeFn(), input), {
|
|
59
|
+
schema: () => schema(rootSchemaPipe ?? pipeFn())
|
|
60
|
+
});
|
|
58
61
|
export {
|
|
59
62
|
and,
|
|
60
63
|
discriminate,
|
|
61
64
|
fromJson,
|
|
65
|
+
lazy,
|
|
62
66
|
merge,
|
|
63
67
|
or
|
|
64
68
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t\tcontext: (c) => c,\n\t\t\tschema: (s) => s,\n\t\t},\n\t)\n"],"mappings":"AAAA,SAA4B,iBAAwC;AACpE,SAAS,SAAS,mBAAmB;AACrC,SAAS,sBAAsB;AAC/B,SAAS,QAAQ,QAAQ,MAAM,QAAQ,gBAAgB;AAEhD,MAAM,KAAK,CAAkC,UACnD;AAAA,EACC,CAAC,UAAU;AACV,QAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,UAAM,SAAsB,CAAC;AAC7B,eAAW,CAAC,KAAKA,KAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,YAAM,WAAW,SAASA,OAAM,KAAK;AACrC,UAAI,SAAS,MAAO,QAAO,SAAS;AACpC,aAAO,KAAK,UAAU,KAAK,KAAK,SAAS,OAAO,KAAK,CAAC;AAAA,IACvD;AACA,UAAM,UAAU,SAAS,QAAQ,KAAK;AAAA,EACvC;AAAA,EACA,EAAE,QAAQ,OAAO,EAAE,OAAO,MAAM,IAAI,CAACC,YAAW,OAAOA,OAAM,CAAC,EAAE,GAAG;AACpE;AAEM,MAAM,MAAM,CAAgC,UAClD;AAAA,EACC,CAAC,UAAU;AACV,eAAW,CAAC,KAAKD,KAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,YAAM,WAAW,SAASA,OAAM,KAAK;AACrC,UAAI,CAAC,SAAS,MAAO,OAAM,UAAU,KAAK,KAAK,SAAS,OAAO,KAAK;AACpE,cAAQ,SAAS;AAAA,IAClB;AACA,WAAO;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,OAAO,EAAE,OAAO,MAAM,IAAI,CAACC,YAAW,OAAOA,OAAM,CAAC,EAAE,GAAG;AACpE;AAEM,MAAM,QAAQ,CAAiE,SAAa,YAClG;AAAA,EACC,CAAC,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO,SAAS,KAAK,CAAC;AAAA,EACrE,EAAE,QAAQ,OAAO,EAAE,OAAO,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,CAAC,EAAE,GAAG;AACjE;AAEM,MAAM,eAAe,CAC3B,eACA,SACA,MAAM,qCAEN;AAAA,EACC,CAAC,UAAU;AACV,UAAM,WAAW,eAAe,MAAM,cAAc,KAAK,CAAC;AAC1D,QAAI,CAAC,QAAQ,QAAQ,EAAG,OAAM,UAAU,KAAK,KAAK,KAAK;AACvD,WAAO,OAAO,QAAQ,QAAQ,GAAG,KAAK;AAAA,EACvC;AAAA,EACA;AAAA,IACC,QAAQ,OAAO,EAAE,OAAO,OAAO,OAAO,OAAO,EAAE,IAAI,CAAC,MAAM,OAAO,CAAC,CAAC,EAAE;AAAA,EACtE;AACD;AAEM,MAAM,WAAW,CAAgCD,UACvD;AAAA,EACCA;AAAA,EACA,CAAC,UAAU;AACV,UAAM,WAAW,SAASA,OAAM,KAAK;AACrC,QAAI,SAAS,MAAO,QAAO,SAAS;AACpC,QAAI,OAAO,aAAa,SAAS,SAAU,OAAM,SAAS;AAE1D,UAAM,SAAS,eAAe,MAAM,KAAK,MAAM,KAAK,GAAG,SAAS,KAAK;AACrE,QAAI,WAAW,SAAS,MAAO,OAAM,SAAS;AAC9C,WAAO,OAAOA,OAAM,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,IACC,SAAS,CAAC,MAAM;AAAA,IAChB,QAAQ,CAAC,MAAM;AAAA,EAChB;AACD;","names":["pipe","branch"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/junctions.ts"],"sourcesContent":["import { Pipe, PipeContext, PipeError, PipeInput, PipeOutput } from './base'\nimport { merge as differMerge } from '../utils/differ'\nimport { wrapInTryCatch } from '../utils/functions'\nimport { assert, branch, pipe, schema, validate } from './base/pipes'\n\nexport const or = <T extends Pipe<any, any, any>[]>(pipes: T) =>\n\tpipe<PipeInput<T[number]>, PipeOutput<T[number]>, PipeContext<T[number]>>(\n\t\t(input) => {\n\t\t\tif (pipes.length === 0) return input as any\n\t\t\tconst errors: PipeError[] = []\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (validity.valid) return validity.value\n\t\t\t\terrors.push(PipeError.path(idx, validity.error, input))\n\t\t\t}\n\t\t\tthrow PipeError.rootFrom(errors, input)\n\t\t},\n\t\t{ schema: () => ({ oneOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const and = <T extends Pipe<any, any, any>>(pipes: T[]) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\t(input) => {\n\t\t\tfor (const [idx, pipe] of Object.entries(pipes)) {\n\t\t\t\tconst validity = validate(pipe, input)\n\t\t\t\tif (!validity.valid) throw PipeError.path(idx, validity.error, input)\n\t\t\t\tinput = validity.value as any\n\t\t\t}\n\t\t\treturn input as any\n\t\t},\n\t\t{ schema: () => ({ allOf: pipes.map((branch) => schema(branch)) }) },\n\t)\n\nexport const merge = <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) =>\n\tpipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>(\n\t\t(input) => differMerge(assert(branch1, input), assert(branch2, input)),\n\t\t{ schema: () => ({ allOf: [schema(branch1), schema(branch2)] }) },\n\t)\n\nexport const discriminate = <T extends Record<PropertyKey, Pipe<any, any, any>>>(\n\tdiscriminator: (val: PipeInput<T[keyof T]>) => PropertyKey,\n\tschemas: T,\n\terr = 'doesnt match any of the schema',\n) =>\n\tpipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>(\n\t\t(input) => {\n\t\t\tconst accessor = wrapInTryCatch(() => discriminator(input))!\n\t\t\tif (!schemas[accessor]) throw PipeError.root(err, input)\n\t\t\treturn assert(schemas[accessor], input)\n\t\t},\n\t\t{\n\t\t\tschema: () => ({ oneOf: Object.values(schemas).map((s) => schema(s)) }),\n\t\t},\n\t)\n\nexport const fromJson = <T extends Pipe<any, any, any>>(pipe: T) =>\n\tbranch<T, PipeInput<T>, PipeOutput<T>, PipeContext<T>>(\n\t\tpipe,\n\t\t(input) => {\n\t\t\tconst validity = validate(pipe, input)\n\t\t\tif (validity.valid) return validity.value\n\t\t\tif (input?.constructor?.name !== 'String') throw validity.error\n\n\t\t\tconst parsed = wrapInTryCatch(() => JSON.parse(input), validity.error)\n\t\t\tif (parsed === validity.error) throw validity.error\n\t\t\treturn assert(pipe, parsed)\n\t\t},\n\t\t{\n\t\t\tcontext: (c) => c,\n\t\t\tschema: (s) => s,\n\t\t},\n\t)\n\nexport const lazy = <T extends Pipe<any, any, any>>(pipeFn: () => T, rootSchemaPipe?: Pipe<any, any, any>) =>\n\tpipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>((input) => assert(pipeFn(), input), {\n\t\tschema: () => schema(rootSchemaPipe ?? pipeFn()),\n\t})\n"],"mappings":"AAAA,SAA4B,iBAAwC;AACpE,SAAS,SAAS,mBAAmB;AACrC,SAAS,sBAAsB;AAC/B,SAAS,QAAQ,QAAQ,MAAM,QAAQ,gBAAgB;AAEhD,MAAM,KAAK,CAAkC,UACnD;AAAA,EACC,CAAC,UAAU;AACV,QAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,UAAM,SAAsB,CAAC;AAC7B,eAAW,CAAC,KAAKA,KAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,YAAM,WAAW,SAASA,OAAM,KAAK;AACrC,UAAI,SAAS,MAAO,QAAO,SAAS;AACpC,aAAO,KAAK,UAAU,KAAK,KAAK,SAAS,OAAO,KAAK,CAAC;AAAA,IACvD;AACA,UAAM,UAAU,SAAS,QAAQ,KAAK;AAAA,EACvC;AAAA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a,SAAS,SAAU,OAAM,SAAS;AAE1D,UAAM,SAAS,eAAe,MAAM,KAAK,MAAM,KAAK,GAAG,SAAS,KAAK;AACrE,QAAI,WAAW,SAAS,MAAO,OAAM,SAAS;AAC9C,WAAO,OAAOA,OAAM,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,IACC,SAAS,CAAC,MAAM;AAAA,IAChB,QAAQ,CAAC,MAAM;AAAA,EAChB;AACD;AAEM,MAAM,OAAO,CAAgC,QAAiB,mBACpE,KAAkD,CAAC,UAAU,OAAO,OAAO,GAAG,KAAK,GAAG;AAAA,EACrF,QAAQ,MAAM,OAAO,kBAAkB,OAAO,CAAC;AAChD,CAAC;","names":["pipe","branch"]}
|
|
@@ -3,7 +3,7 @@ export { array, asSet, tuple } from './arrays.js';
|
|
|
3
3
|
export { coerceBoolean, coerceNumber, coerceString, coerceTime } from './coerce.js';
|
|
4
4
|
export { custom, eq, has, in, is, max, min, ne, nin } from './core.js';
|
|
5
5
|
export { File, audio, file, fileType, image, video } from './files.js';
|
|
6
|
-
export { and, discriminate, fromJson, merge, or } from './junctions.js';
|
|
6
|
+
export { and, discriminate, fromJson, lazy, merge, or } from './junctions.js';
|
|
7
7
|
export { asRounded, gt, gte, int, lt, lte } from './numbers.js';
|
|
8
8
|
export { catch, conditional, defaults, nullable, nullish, optional } from './optionals.js';
|
|
9
9
|
export { any, boolean, instanceOf, null, number, string, undefined } from './types.js';
|
|
@@ -3,7 +3,7 @@ import { array, asSet, tuple } from './arrays.js';
|
|
|
3
3
|
import { coerceBoolean, coerceNumber, coerceString, coerceTime } from './coerce.js';
|
|
4
4
|
import { custom, eq, has, in as inArray, is, max, min, ne, nin } from './core.js';
|
|
5
5
|
import { File, audio, file, fileType, image, video } from './files.js';
|
|
6
|
-
import { and, discriminate, fromJson, merge, or } from './junctions.js';
|
|
6
|
+
import { and, discriminate, fromJson, lazy, merge, or } from './junctions.js';
|
|
7
7
|
import { asRounded, gt, gte, int, lt, lte } from './numbers.js';
|
|
8
8
|
import { catch as onCatch, conditional, defaults, nullable, nullish, optional } from './optionals.js';
|
|
9
9
|
import { any as isAny, boolean as isBoolean, instanceOf as isInstanceOf, null as isNull, number as isNumber, string as isString, undefined as isUndefined } from './types.js';
|
|
@@ -55,6 +55,7 @@ declare const externals_has: typeof has;
|
|
|
55
55
|
declare const externals_image: typeof image;
|
|
56
56
|
declare const externals_int: typeof int;
|
|
57
57
|
declare const externals_is: typeof is;
|
|
58
|
+
declare const externals_lazy: typeof lazy;
|
|
58
59
|
declare const externals_lt: typeof lt;
|
|
59
60
|
declare const externals_lte: typeof lte;
|
|
60
61
|
declare const externals_max: typeof max;
|
|
@@ -81,7 +82,7 @@ declare const externals_video: typeof video;
|
|
|
81
82
|
declare const externals_walk: typeof walk;
|
|
82
83
|
declare const externals_withStrippedHtml: typeof withStrippedHtml;
|
|
83
84
|
declare namespace externals {
|
|
84
|
-
export { externals_File as File, externals_Timeable as Timeable, externals_after as after, externals_and as and, isAny as any, externals_array as array, externals_asCapitalized as asCapitalized, externals_asISOString as asISOString, externals_asLowercased as asLowercased, externals_asMap as asMap, externals_asRounded as asRounded, externals_asSet as asSet, externals_asSliced as asSliced, externals_asStamp as asStamp, externals_asStrippedHtml as asStrippedHtml, externals_asTrimmed as asTrimmed, externals_asUppercased as asUppercased, externals_assert as assert, externals_audio as audio, externals_before as before, isBoolean as boolean, externals_branch as branch, onCatch as catch, externals_coerceBoolean as coerceBoolean, externals_coerceNumber as coerceNumber, externals_coerceString as coerceString, externals_coerceTime as coerceTime, externals_conditional as conditional, externals_context as context, externals_custom as custom, externals_defaults as defaults, externals_discriminate as discriminate, externals_email as email, externals_eq as eq, externals_file as file, externals_fileType as fileType, externals_fromJson as fromJson, externals_gt as gt, externals_gte as gte, externals_has as has, externals_image as image, inArray as in, isInstanceOf as instanceOf, externals_int as int, externals_is as is, externals_lt as lt, externals_lte as lte, externals_max as max, externals_merge as merge, externals_meta as meta, externals_min as min, externals_ne as ne, externals_nin as nin, isNull as null, externals_nullable as nullable, externals_nullish as nullish, isNumber as number, externals_object as object, externals_objectOmit as objectOmit, externals_objectPick as objectPick, externals_optional as optional, externals_or as or, externals_pipe as pipe, externals_record as record, externals_schema as schema, isString as string, externals_time as time, externals_tuple as tuple, isUndefined as undefined, externals_url as url, externals_validate as validate, externals_video as video, externals_walk as walk, externals_withStrippedHtml as withStrippedHtml };
|
|
85
|
+
export { externals_File as File, externals_Timeable as Timeable, externals_after as after, externals_and as and, isAny as any, externals_array as array, externals_asCapitalized as asCapitalized, externals_asISOString as asISOString, externals_asLowercased as asLowercased, externals_asMap as asMap, externals_asRounded as asRounded, externals_asSet as asSet, externals_asSliced as asSliced, externals_asStamp as asStamp, externals_asStrippedHtml as asStrippedHtml, externals_asTrimmed as asTrimmed, externals_asUppercased as asUppercased, externals_assert as assert, externals_audio as audio, externals_before as before, isBoolean as boolean, externals_branch as branch, onCatch as catch, externals_coerceBoolean as coerceBoolean, externals_coerceNumber as coerceNumber, externals_coerceString as coerceString, externals_coerceTime as coerceTime, externals_conditional as conditional, externals_context as context, externals_custom as custom, externals_defaults as defaults, externals_discriminate as discriminate, externals_email as email, externals_eq as eq, externals_file as file, externals_fileType as fileType, externals_fromJson as fromJson, externals_gt as gt, externals_gte as gte, externals_has as has, externals_image as image, inArray as in, isInstanceOf as instanceOf, externals_int as int, externals_is as is, externals_lazy as lazy, externals_lt as lt, externals_lte as lte, externals_max as max, externals_merge as merge, externals_meta as meta, externals_min as min, externals_ne as ne, externals_nin as nin, isNull as null, externals_nullable as nullable, externals_nullish as nullish, isNumber as number, externals_object as object, externals_objectOmit as objectOmit, externals_objectPick as objectPick, externals_optional as optional, externals_or as or, externals_pipe as pipe, externals_record as record, externals_schema as schema, isString as string, externals_time as time, externals_tuple as tuple, isUndefined as undefined, externals_url as url, externals_validate as validate, externals_video as video, externals_walk as walk, externals_withStrippedHtml as withStrippedHtml };
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
export { externals as v };
|
|
@@ -8,5 +8,6 @@ declare const and: <T extends Pipe<any, any, any>>(pipes: T[]) => Pipe<PipeInput
|
|
|
8
8
|
declare const merge: <T1 extends Pipe<any, any, any>, T2 extends Pipe<any, any, any>>(branch1: T1, branch2: T2) => Pipe<PipeInput<T1> & PipeInput<T2>, PipeOutput<T1> & PipeOutput<T2>, PipeContext<T1> & PipeContext<T2>>;
|
|
9
9
|
declare const discriminate: <T extends Record<PropertyKey, Pipe<any, any, any>>>(discriminator: (val: PipeInput<T[keyof T]>) => PropertyKey, schemas: T, err?: string) => Pipe<PipeInput<T[keyof T]>, PipeOutput<T[keyof T]>, PipeContext<T[keyof T]>>;
|
|
10
10
|
declare const fromJson: <T extends Pipe<any, any, any>>(pipe: T) => Pipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>;
|
|
11
|
+
declare const lazy: <T extends Pipe<any, any, any>>(pipeFn: () => T, rootSchemaPipe?: Pipe<any, any, any>) => Pipe<PipeInput<T>, PipeOutput<T>, PipeContext<T>>;
|
|
11
12
|
|
|
12
|
-
export { and, discriminate, fromJson, merge, or };
|
|
13
|
+
export { and, discriminate, fromJson, lazy, merge, or };
|
|
@@ -55,10 +55,14 @@ const fromJson = (pipe2) => branch(
|
|
|
55
55
|
schema: (s) => s
|
|
56
56
|
}
|
|
57
57
|
);
|
|
58
|
+
const lazy = (pipeFn, rootSchemaPipe) => pipe((input) => assert(pipeFn(), input), {
|
|
59
|
+
schema: () => schema(rootSchemaPipe ?? pipeFn())
|
|
60
|
+
});
|
|
58
61
|
export {
|
|
59
62
|
and,
|
|
60
63
|
discriminate,
|
|
61
64
|
fromJson,
|
|
65
|
+
lazy,
|
|
62
66
|
merge,
|
|
63
67
|
or
|
|
64
68
|
};
|
package/package.json
CHANGED