valleyed 4.5.19 → 4.5.20
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/optionals.cjs +2 -1
- package/dist/cjs/api/optionals.cjs.map +1 -1
- package/dist/cjs/api/optionals.min.cjs +1 -1
- package/dist/cjs/api/optionals.min.cjs.map +1 -1
- package/dist/esm/api/optionals.min.mjs +1 -1
- package/dist/esm/api/optionals.min.mjs.map +1 -1
- package/dist/esm/api/optionals.mjs +3 -2
- package/dist/esm/api/optionals.mjs.map +1 -1
- package/dist/types/api/optionals.d.ts +1 -1
- package/dist/types/api/optionals.js +3 -2
- 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.20](https://github.com/kevinand11/valleyed/compare/v4.5.19...v4.5.20) (2026-05-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* schema for optionals ([5f64648](https://github.com/kevinand11/valleyed/commit/5f646483d82d4835e8d218eb54f2d840b1427f6a))
|
|
11
|
+
|
|
5
12
|
### [4.5.19](https://github.com/kevinand11/valleyed/compare/v4.5.18...v4.5.19) (2026-03-02)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -42,7 +42,8 @@ const nullable = (branch) => partial(branch, (i) => i === null, {
|
|
|
42
42
|
schema: () => ({ oneOf: [(0, import_pipes.schema)(branch), { type: "null" }] })
|
|
43
43
|
});
|
|
44
44
|
const optional = (branch) => partial(branch, (i) => i === void 0, {
|
|
45
|
-
context: { optional: true }
|
|
45
|
+
context: { optional: true },
|
|
46
|
+
schema: () => (0, import_pipes.schema)(branch)
|
|
46
47
|
});
|
|
47
48
|
const nullish = (branch) => partial(branch, (i) => i === null || i === void 0, {
|
|
48
49
|
schema: () => ({ oneOf: [(0, import_pipes.schema)(branch), { type: "null" }] }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { Pipe, PipeInput, PipeOutput } from './base'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { DeepPartial } from '../utils/types'\nimport type { Pipe, PipeInput, PipeOutput } from './base'\nimport { compileNested, context, schema, standard } from './base/pipes'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t\tschema: () => schema(branch),\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAyD;AAEzD,MAAM,UAAU,CACf,QACA,kBACA,eAEA;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,QAAQA,QAAO,qBAAqB,KAAK;AAAA,IACzC,OAAG,4BAAc,EAAE,MAAM,MAAM,QAAQ,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AAAA,IACnE;AAAA,EACD;AAAA,EACA;AAAA,IACC,GAAG;AAAA,IACH,SAAS,EAAE,GAAG,QAAQ,SAAS,iBAAiB;AAAA,EACjD;AACD;AAEM,MAAM,WAAW,CAA2B,WAClD,QAAiB,QAAQ,CAAC,MAAM,MAAM,MAA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AAG,4BAAc,EAAE,MAAM,MAAM,QAAQ,OAAO,WAAW,SAAS,CAAC;AAAA,IACnE,OAAO,KAAK,0BAA0B,KAAK,MAAMA,QAAO;AAAA,EACzD;AAAA,EACA;AAAA,IACC,QAAQ,CAAC,OAAO,EAAE,OAAG,qBAAO,MAAM,GAAG,SAAS,EAAE,SAAS,IAAI;AAAA,IAC7D,SAAS,EAAE,OAAG,sBAAQ,MAAM,GAAG,OAAO,IAAI;AAAA,EAC3C;AACD;","names":["context"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var p in t)u(e,p,{get:t[p],enumerable:!0})},x=(e,t,p,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of P(t))!c.call(e,a)&&a!==p&&u(e,a,{get:()=>t[a],enumerable:!(o=T(t,a))||o.enumerable});return e};var y=e=>x(u({},"__esModule",{value:!0}),e);var D={};f(D,{catch:()=>l,conditional:()=>I,defaults:()=>O,nullable:()=>r,nullish:()=>$,optional:()=>m});module.exports=y(D);var n=require('./base/pipes.min.cjs');const i=(e,t,p)=>(0,n.standard)(({input:o,context:a},s)=>[`if (!${a}.partialCondition(${o})) {`,...(0,n.compileNested)({opts:s,pipe:e,input:o}).map(d=>` ${d}`),"}"],{...p,context:{...p?.context,partialCondition:t}}),r=e=>i(e,t=>t===null,{schema:()=>({oneOf:[(0,n.schema)(e),{type:"null"}]})}),m=e=>i(e,t=>t===void 0,{context:{optional:!0},schema:()=>(0,n.schema)(e)}),$=e=>i(e,t=>t==null,{schema:()=>({oneOf:[(0,n.schema)(e),{type:"null"}]}),context:{...(0,n.context)(e),optional:!0}}),I=(e,t)=>i(e,()=>!t(),{schema:()=>(0,n.schema)(e),context:{...(0,n.context)(e),optional:!0}}),O=(e,t)=>(0,n.standard)(({input:p,context:o},a)=>[`if (${p} === undefined) ${p} = ${o}.defaults`,...(0,n.compileNested)({opts:a,pipe:e,input:p})],{schema:p=>({...(0,n.schema)(e),default:p.defaults??t}),context:{...(0,n.context)(e),defaults:t,optional:!0}}),l=(e,t)=>(0,n.standard)(({input:p,context:o},a)=>[...(0,n.compileNested)({opts:a,pipe:e,input:p,errorType:"assign"}),`if (${p} instanceof PipeError) ${p} = ${o}.catch`],{schema:p=>({...(0,n.schema)(e),default:p.catch??t}),context:{...(0,n.context)(e),catch:t}});0&&(module.exports={catch:null,conditional,defaults,nullable,nullish,optional});
|
|
2
2
|
//# sourceMappingURL=optionals.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { Pipe, PipeInput, PipeOutput } from './base'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { DeepPartial } from '../utils/types'\nimport type { Pipe, PipeInput, PipeOutput } from './base'\nimport { compileNested, context, schema, standard } from './base/pipes'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t\tschema: () => schema(branch),\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,gBAAAC,EAAA,aAAAC,EAAA,aAAAC,EAAA,YAAAC,E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,MAAG,iBAAc,CAAE,KAAAC,EAAM,KAAML,EAAQ,MAAAG,CAAM,CAAC,CAC/C,EACA,CACC,OAASO,IAAO,CAAE,MAAG,UAAOV,CAAM,EAAG,QAASU,EAAE,UAAYD,CAAI,GAChE,QAAS,CAAE,MAAG,WAAQT,CAAM,EAAG,SAAUS,EAAK,SAAU,EAAK,CAC9D,CACD,EAEKlB,EAAU,CAA2BS,EAAWS,OACrD,YACC,CAAC,CAAE,MAAAN,EAAO,QAAAC,CAAQ,EAAGC,IAAS,CAC7B,MAAG,iBAAc,CAAE,KAAAA,EAAM,KAAML,EAAQ,MAAAG,EAAO,UAAW,QAAS,CAAC,EACnE,OAAOA,CAAK,0BAA0BA,CAAK,MAAMC,CAAO,QACzD,EACA,CACC,OAASM,IAAO,CAAE,MAAG,UAAOV,CAAM,EAAG,QAASU,EAAE,OAASD,CAAI,GAC7D,QAAS,CAAE,MAAG,WAAQT,CAAM,EAAG,MAAOS,CAAI,CAC3C,CACD","names":["optionals_exports","__export","onCatch","conditional","defaults","nullable","nullish","optional","__toCommonJS","import_pipes","partial","branch","partialCondition","config","input","context","opts","l","i","condition","def","c"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{compileNested as l,context as i,schema as a,standard as s}from "./base/pipes.min.mjs";const u=(e,t,n)=>s(({input:p,context:o},d)=>[`if (!${o}.partialCondition(${p})) {`,...l({opts:d,pipe:e,input:p}).map(T=>` ${T}`),"}"],{...n,context:{...n?.context,partialCondition:t}}),f=e=>u(e,t=>t===null,{schema:()=>({oneOf:[a(e),{type:"null"}]})}),x=e=>u(e,t=>t===void 0,{context:{optional:!0},schema:()=>a(e)}),y=e=>u(e,t=>t==null,{schema:()=>({oneOf:[a(e),{type:"null"}]}),context:{...i(e),optional:!0}}),r=(e,t)=>u(e,()=>!t(),{schema:()=>a(e),context:{...i(e),optional:!0}}),m=(e,t)=>s(({input:n,context:p},o)=>[`if (${n} === undefined) ${n} = ${p}.defaults`,...l({opts:o,pipe:e,input:n})],{schema:n=>({...a(e),default:n.defaults??t}),context:{...i(e),defaults:t,optional:!0}}),P=(e,t)=>s(({input:n,context:p},o)=>[...l({opts:o,pipe:e,input:n,errorType:"assign"}),`if (${n} instanceof PipeError) ${n} = ${p}.catch`],{schema:n=>({...a(e),default:n.catch??t}),context:{...i(e),catch:t}});export{P as catch,r as conditional,m as defaults,f as nullable,y as nullish,x as optional};
|
|
2
2
|
//# sourceMappingURL=optionals.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { Pipe, PipeInput, PipeOutput } from './base'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { DeepPartial } from '../utils/types'\nimport type { Pipe, PipeInput, PipeOutput } from './base'\nimport { compileNested, context, schema, standard } from './base/pipes'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t\tschema: () => schema(branch),\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":"AAEA,OAAS,iBAAAA,EAAe,WAAAC,EAAS,UAAAC,EAAQ,YAAAC,MAAgB,eAEzD,MAAMC,EAAU,CACfC,EACAC,EACAC,IAEAJ,EACC,CAAC,CAAE,MAAAK,EAAO,QAAAP,CAAQ,EAAGQ,IAAS,CAC7B,QAAQR,CAAO,qBAAqBO,CAAK,OACzC,GAAGR,EAAc,CAAE,KAAAS,EAAM,KAAMJ,EAAQ,MAAAG,CAAM,CAAC,EAAE,I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EAAWa,IACrDf,EACC,CAAC,CAAE,MAAAK,EAAO,QAAAP,CAAQ,EAAGQ,IAAS,CAC7B,GAAGT,EAAc,CAAE,KAAAS,EAAM,KAAMJ,EAAQ,MAAAG,EAAO,UAAW,QAAS,CAAC,EACnE,OAAOA,CAAK,0BAA0BA,CAAK,MAAMP,CAAO,QACzD,EACA,CACC,OAASkB,IAAO,CAAE,GAAGjB,EAAOG,CAAM,EAAG,QAASc,EAAE,OAASD,CAAI,GAC7D,QAAS,CAAE,GAAGjB,EAAQI,CAAM,EAAG,MAAOa,CAAI,CAC3C,CACD","names":["compileNested","context","schema","standard","partial","branch","partialCondition","config","input","opts","l","nullable","i","optional","nullish","conditional","condition","defaults","def","c","onCatch"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileNested, context, schema, standard } from "./base/pipes.mjs";
|
|
2
2
|
const partial = (branch, partialCondition, config) => standard(
|
|
3
3
|
({ input, context: context2 }, opts) => [
|
|
4
4
|
`if (!${context2}.partialCondition(${input})) {`,
|
|
@@ -14,7 +14,8 @@ const nullable = (branch) => partial(branch, (i) => i === null, {
|
|
|
14
14
|
schema: () => ({ oneOf: [schema(branch), { type: "null" }] })
|
|
15
15
|
});
|
|
16
16
|
const optional = (branch) => partial(branch, (i) => i === void 0, {
|
|
17
|
-
context: { optional: true }
|
|
17
|
+
context: { optional: true },
|
|
18
|
+
schema: () => schema(branch)
|
|
18
19
|
});
|
|
19
20
|
const nullish = (branch) => partial(branch, (i) => i === null || i === void 0, {
|
|
20
21
|
schema: () => ({ oneOf: [schema(branch), { type: "null" }] }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { Pipe, PipeInput, PipeOutput } from './base'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/api/optionals.ts"],"sourcesContent":["import type { DeepPartial } from '../utils/types'\nimport type { Pipe, PipeInput, PipeOutput } from './base'\nimport { compileNested, context, schema, standard } from './base/pipes'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t\tschema: () => schema(branch),\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":"AAEA,SAAS,eAAe,SAAS,QAAQ,gBAAgB;AAEzD,MAAM,UAAU,CACf,QACA,kBACA,WAEA;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,QAAQA,QAAO,qBAAqB,KAAK;AAAA,IACzC,GAAG,cAAc,EAAE,MAAM,MAAM,QAAQ,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AAAA,IACnE;AAAA,EACD;AAAA,EACA;AAAA,IACC,GAAG;AAAA,IACH,SAAS,EAAE,GAAG,QAAQ,SAAS,iBAAiB;AAAA,EACjD;AACD;AAEM,MAAM,WAAW,CAA2B,WAClD,QAAiB,QAAQ,CAAC,MAAM,MAAM,MAAM;AAAA,EAC3C,QAAQ,OAAO,EAAE,OAAO,CAAC,OAAO,MAAM,GAAG,EAAE,MAAM,OAAO,CAAC,EAAE;AAC5D,CAAC;AAEK,MAAM,WAAW,CAA2B,WAClD,QAAsB,QAAQ,CAAC,MAAM,MAAM,QAAW;AAAA,EACrD,SAAS,EAAE,UAAU,KAAK;AAAA,EAC1B,QAAQ,MAAM,OAAO,MAAM;AAC5B,CAAC;AAEK,MAAM,UAAU,CAA2B,WACjD,QAA6B,QAAQ,CAAC,MAAM,MAAM,QAAQ,MAAM,QAAW;AAAA,EAC1E,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ipeOutput } from '../errors-B5taetnA.js';
|
|
2
1
|
import { DeepPartial } from '../utils/types.js';
|
|
2
|
+
import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B5taetnA.js';
|
|
3
3
|
import '@standard-schema/spec';
|
|
4
4
|
|
|
5
5
|
declare const nullable: <T extends Pipe<any, any>>(branch: T) => Pipe<PipeInput<T> | null, PipeOutput<T> | null>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileNested, context, schema, standard } from "./base/pipes.js";
|
|
2
2
|
const partial = (branch, partialCondition, config) => standard(
|
|
3
3
|
({ input, context: context2 }, opts) => [
|
|
4
4
|
`if (!${context2}.partialCondition(${input})) {`,
|
|
@@ -14,7 +14,8 @@ const nullable = (branch) => partial(branch, (i) => i === null, {
|
|
|
14
14
|
schema: () => ({ oneOf: [schema(branch), { type: "null" }] })
|
|
15
15
|
});
|
|
16
16
|
const optional = (branch) => partial(branch, (i) => i === void 0, {
|
|
17
|
-
context: { optional: true }
|
|
17
|
+
context: { optional: true },
|
|
18
|
+
schema: () => schema(branch)
|
|
18
19
|
});
|
|
19
20
|
const nullish = (branch) => partial(branch, (i) => i === null || i === void 0, {
|
|
20
21
|
schema: () => ({ oneOf: [schema(branch), { type: "null" }] }),
|
package/package.json
CHANGED