valleyed 4.5.18 → 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.
Files changed (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/api/base/pipes.cjs +10 -6
  3. package/dist/cjs/api/base/pipes.cjs.map +1 -1
  4. package/dist/cjs/api/base/pipes.min.cjs +2 -2
  5. package/dist/cjs/api/base/pipes.min.cjs.map +1 -1
  6. package/dist/cjs/api/base/types.cjs.map +1 -1
  7. package/dist/cjs/api/base/types.min.cjs +1 -1
  8. package/dist/cjs/api/base/types.min.cjs.map +1 -1
  9. package/dist/cjs/api/optionals.cjs +2 -1
  10. package/dist/cjs/api/optionals.cjs.map +1 -1
  11. package/dist/cjs/api/optionals.min.cjs +1 -1
  12. package/dist/cjs/api/optionals.min.cjs.map +1 -1
  13. package/dist/esm/api/base/pipes.min.mjs +2 -2
  14. package/dist/esm/api/base/pipes.min.mjs.map +1 -1
  15. package/dist/esm/api/base/pipes.mjs +10 -6
  16. package/dist/esm/api/base/pipes.mjs.map +1 -1
  17. package/dist/esm/api/base/types.min.mjs.map +1 -1
  18. package/dist/esm/api/base/types.mjs.map +1 -1
  19. package/dist/esm/api/optionals.min.mjs +1 -1
  20. package/dist/esm/api/optionals.min.mjs.map +1 -1
  21. package/dist/esm/api/optionals.mjs +3 -2
  22. package/dist/esm/api/optionals.mjs.map +1 -1
  23. package/dist/types/api/arrays.d.ts +1 -1
  24. package/dist/types/api/base/errors.d.ts +1 -1
  25. package/dist/types/api/base/index.d.ts +1 -1
  26. package/dist/types/api/base/pipes.d.ts +1 -1
  27. package/dist/types/api/base/pipes.js +10 -6
  28. package/dist/types/api/base/types.d.ts +1 -1
  29. package/dist/types/api/coerce.d.ts +1 -1
  30. package/dist/types/api/core.d.ts +1 -1
  31. package/dist/types/api/externals.d.ts +1 -1
  32. package/dist/types/api/files.d.ts +1 -1
  33. package/dist/types/api/index.d.ts +1 -1
  34. package/dist/types/api/junctions.d.ts +1 -1
  35. package/dist/types/api/numbers.d.ts +1 -1
  36. package/dist/types/api/optionals.d.ts +1 -1
  37. package/dist/types/api/optionals.js +3 -2
  38. package/dist/types/api/records.d.ts +1 -1
  39. package/dist/types/api/strings.d.ts +1 -1
  40. package/dist/types/api/times.d.ts +1 -1
  41. package/dist/types/api/types.d.ts +1 -1
  42. package/dist/types/{errors-B_b7Rsqj.d.ts → errors-B5taetnA.d.ts} +1 -2
  43. package/dist/types/index.d.ts +1 -1
  44. package/package.json +5 -5
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.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
+
12
+ ### [4.5.19](https://github.com/kevinand11/valleyed/compare/v4.5.18...v4.5.19) (2026-03-02)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * pipe.pipe returns first pipe instead of new pipe ([43ab3f9](https://github.com/kevinand11/valleyed/commit/43ab3f9f907e5e54fe4acb800d4b3394b0e8c6e4))
18
+
5
19
  ### [4.5.18](https://github.com/kevinand11/valleyed/compare/v4.5.17...v4.5.18) (2026-01-18)
6
20
 
7
21
 
@@ -34,10 +34,14 @@ var import_errors = require('./errors.cjs');
34
34
  var import_functions = require('../../utils/functions/index.cjs');
35
35
  function walk(pipe, init, nodeFn) {
36
36
  let acc = init;
37
+ const pipes = [pipe];
37
38
  while (pipe) {
38
- acc = nodeFn(pipe, acc);
39
- pipe = pipe.next;
39
+ const prev = pipe.prev;
40
+ if (!prev) break;
41
+ pipes.push(prev);
42
+ pipe = prev;
40
43
  }
44
+ for (const pipe2 of pipes.reverse()) acc = nodeFn(pipe2, acc);
41
45
  return acc;
42
46
  }
43
47
  function context(pipe) {
@@ -90,13 +94,13 @@ function standard(compile2, config = {}) {
90
94
  schema: (context2) => config.schema?.(context2) ?? {},
91
95
  pipe: (...entries) => {
92
96
  delete piper.__compiled;
97
+ let pipe = piper;
93
98
  for (const cur of entries) {
94
99
  const p = typeof cur === "function" ? define(cur, config) : cur;
95
- if (!piper.next) piper.next = p;
96
- if (piper.last) piper.last.next = p;
97
- piper.last = p.last ?? p;
100
+ p.prev = pipe;
101
+ pipe = p;
98
102
  }
99
- return piper;
103
+ return pipe;
100
104
  },
101
105
  compile: compile2,
102
106
  "~standard": {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport type { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8C;AAE9C,uBAA+B;AAGxB,SAAS,KAAQ,MAAsB,MAAS,QAA4C;AAClG,MAAI,MAAS;AACb,SAAO,MAAM;AACZ,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,KAAK;AAAA,EACb;AACA,SAAO;AACR;AAEO,SAAS,QAAkC,MAAkB;AACnE,SAAO,KAAK,MAAM,CAAC,GAAc,CAAC,GAAG,SAAS,EAAE,GAAG,KAAK,GAAG,EAAE,QAAQ,EAAE,EAAE;AAC1E;AAEO,SAAS,OAAiC,MAAS,OAA+B;AACxF,QAAM,SAAS,SAAS,MAAM,KAAK;AACnC,MAA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,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 type { Context, Entry, JsonSchemaBuilder, Pipe, PipeCompiledFn, PipeErrorHandler, PipeFn, PipeMeta, PipeOutput } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { 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\tconst pipes: Pipe<any, any>[] = [pipe]\n\twhile (pipe) {\n\t\tconst prev = pipe.prev\n\t\tif (!prev) break\n\t\tpipes.push(prev)\n\t\tpipe = prev\n\t}\n\tfor (const pipe of pipes.reverse()) acc = nodeFn(pipe, acc)\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tlet pipe = piper\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\tp.prev = pipe\n\t\t\t\tpipe = p\n\t\t\t}\n\t\t\treturn pipe\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8C;AAE9C,uBAA+B;AAGxB,SAAS,KAAQ,MAAsB,MAAS,QAA4C;AAClG,MAAI,MAAS;AACb,QAAM,QAA0B,CAAC,IAAI;AACrC,SAAO,MAAM;AACZ,UAAM,OAAO,KAAK;AAClB,QAAI,CAAC,KAAM;AACX,UAAM,KAAK,IAAI;AACf,WAAO;AAAA,EACR;AACA,aAAWA,SAAQ,MAAM,QAAQ,EAAG,OAAM,OAAOA,OAAM,GAAG;AAC1D,SAAO;AACR;AAEO,SAAS,QAAkC,MAAkB;AACnE,SAAO,KAAK,MAAM,CAAC,GAAc,CAAC,GAAG,SAAS,EAAE,GAAG,KAAK,GAAG,EAAE,QAAQ,EAAE,E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,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":["pipe","schema","meta","context","compile"]}
@@ -1,3 +1,3 @@
1
- "use strict";var l=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var g=(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))!w.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={};g(R,{assert:()=>_,compile:()=>T,compileNested:()=>F,context:()=>y,define:()=>h,meta:()=>I,schema:()=>k,standard:()=>f,validate:()=>x,walk:()=>c});module.exports=S(R);var p=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=x(e,n);if(!t.valid)throw t.error;return t.value}function x(e,n){try{const r=(e.__compiled??T(e))(n);return r instanceof p.PipeError?{error:r,valid:!1}:{value:r,valid:!0}}catch(t){return t instanceof p.PipeError?{error:t,valid:!1}:{error:p.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(f(()=>[],{schema:()=>n}))}function T(e,n={}){const t="input",r="context",{lines:o,context:i}=P({pipe:e,input:t,context:r,failEarly:!n.allErrors,base:[`return ${t}`]}),a=[`return (${t}) => {`,...o.filter(s=>s.trim()!=="").map(s=>` ${s}`),` throw PipeError.root('unhandled root validation', ${t})`,"}"];return e.__compiled=new Function(r,"PipeError",a.join(`
2
- `))(i,p.PipeError),e.__compiled}function f(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=x(t,r);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:a})=>({message:i,path:a?a.split("."):void 0}))}}}};return t}function h(e,n={}){const t=`define_${(0,u.getRandomValue)()}`;return f(({input:r,context:o,path:i},a)=>[`${r} = ${o}['${t}'](${r})`,a.wrapError(`${r} instanceof PipeError`,`PipeError.wrap(${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,p.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:a=(0,p.createErrorHandler)(n,"return"),base:s=[]}){const m=y(e);i??=m;const E=c(e,[],(v,d)=>(d.push(v.compile({input:n,context:t,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:r,path:o,wrapError:a})),d));return{lines:J(s,E.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});
1
+ "use strict";var l=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},O=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!w.call(e,o)&&o!==n&&l(e,o,{get:()=>t[o],enumerable:!(r=$(t,o))||r.enumerable});return e};var k=e=>O(l({},"__esModule",{value:!0}),e);var R={};g(R,{assert:()=>S,compile:()=>T,compileNested:()=>F,context:()=>y,define:()=>h,meta:()=>I,schema:()=>_,standard:()=>m,validate:()=>f,walk:()=>c});module.exports=k(R);var p=require('./errors.min.cjs'),u=require('../../utils/functions/index.min.cjs');function c(e,t,n){let r=t;const o=[e];for(;e;){const i=e.prev;if(!i)break;o.push(i),e=i}for(const i of o.reverse())r=n(i,r);return r}function y(e){return c(e,{},(t,n)=>({...n,...t.context()}))}function S(e,t){const n=f(e,t);if(!n.valid)throw n.error;return n.value}function f(e,t){try{const r=(e.__compiled??T(e))(t);return r instanceof p.PipeError?{error:r,valid:!1}:{value:r,valid:!0}}catch(n){return n instanceof p.PipeError?{error:n,valid:!1}:{error:p.PipeError.root(n instanceof Error?n.message:`${n}`,t,void 0),valid:!1}}}function _(e,t={}){const n=y(e);return c(e,t,(r,o)=>({...o,...r.schema(n)}))}function I(e,t){return e.pipe(m(()=>[],{schema:()=>t}))}function T(e,t={}){const n="input",r="context",{lines:o,context:i}=P({pipe:e,input:n,context:r,failEarly:!t.allErrors,base:[`return ${n}`]}),a=[`return (${n}) => {`,...o.filter(s=>s.trim()!=="").map(s=>` ${s}`),` throw PipeError.root('unhandled root validation', ${n})`,"}"];return e.__compiled=new Function(r,"PipeError",a.join(`
2
+ `))(i,p.PipeError),e.__compiled}function m(e,t={}){const n={context:()=>t.context??{},schema:r=>t.schema?.(r)??{},pipe:(...r)=>{delete n.__compiled;let o=n;for(const i of r){const a=typeof i=="function"?h(i,t):i;a.prev=o,o=a}return o},compile:e,"~standard":{version:1,vendor:"valleyed",validate(r){const o=f(n,r);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:a})=>({message:i,path:a?a.split("."):void 0}))}}}};return n}function h(e,t={}){const n=`define_${(0,u.getRandomValue)()}`;return m(({input:r,context:o,path:i},a)=>[`${r} = ${o}['${n}'](${r})`,a.wrapError(`${r} instanceof PipeError`,`PipeError.wrap(${i}, ${r})`)],{context:{...t?.context,[n]:e},schema:t?.schema})}function F(e){const t=(0,u.getRandomValue)(),{lines:n,context:r}=P({...e.opts,wrapError:(0,p.createErrorHandler)(e.input,e.errorType??e.opts.wrapError.type),pipe:e.pipe,input:e.input,context:`context[\`${t}\`]`,path:[e.opts.path,"key"in e?e.key:""].filter(Boolean).join(".")||void 0});return e.opts.rootContext[t]=r,n}function P({pipe:e,input:t,context:n,failEarly:r=!1,path:o="",rootContext:i,wrapError:a=(0,p.createErrorHandler)(t,"return"),base:s=[]}){const x=y(e);i??=x;const v=c(e,[],(E,d)=>(d.push(E.compile({input:t,context:n,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:r,path:o,wrapError:a})),d));return{lines:J(s,v.flat()),context:x}}function J(e,t){return(Array.isArray(t)?t:[t]).reduceRight((n,r)=>(typeof r=="string"?n.unshift(r):typeof r=="function"&&(n=r(n)),n),e)}0&&(module.exports={assert,compile,compileNested,context,define,meta,schema,standard,validate,walk});
3
3
  //# sourceMappingURL=pipes.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport type { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA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,EAC9C,KAAA2B,EAAO,CAAC,CACT,EASG,CACF,MAAMC,EAAM3C,EAAQU,CAAI,EACxB8B,IAAgBG,EAChB,MAAMC,EAAWtC,EAAKI,EAA+C,CAAC,EAAG,CAACI,EAAGD,KAC5EA,EAAI,KACHC,EAAE,QACD,CAAE,MAAAC,EAAO,QAASO,EAAY,KAAM,GAAGY,EAAO,IAAIA,CAAI,IAAM,MAAS,EAAG,EACxE,CAAE,YAAAM,EAAa,UAAAD,EAAW,KAAAL,EAAM,UAAAO,CAAU,CAC3C,CACD,EACO5B,EACP,EAED,MAAO,CAAE,MADKgC,EAAeH,EAAME,EAAS,KAAK,CAAC,EAClC,QAASD,CAAI,CAC9B,CAEA,SAASE,EAAeH,EAAgBnB,EAA8C,CACrF,OAAQ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,YAAsB,CAACV,EAAKiB,KACvE,OAAOA,GAAQ,SAAUjB,EAAI,QAAQiB,CAAG,EACnC,OAAOA,GAAQ,aAAYjB,EAAMiB,EAAIjB,CAAG,GAC1CA,GACL6B,CAAI,CACR","names":["pipes_exports","__export","assert","compile","compileNested","context","define","meta","schema","standard","validate","walk","__toCommonJS","import_errors","import_functions","pipe","init","nodeFn","acc","p","input","result","res","error","cont","opts","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","value","validity","message","path","fn","key","data","random","failEarly","rootContext","wrapError","base","ctx","compiled","mergePipeLines"]}
1
+ {"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport type { Context, Entry, JsonSchemaBuilder, Pipe, PipeCompiledFn, PipeErrorHandler, PipeFn, PipeMeta, PipeOutput } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { 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\tconst pipes: Pipe<any, any>[] = [pipe]\n\twhile (pipe) {\n\t\tconst prev = pipe.prev\n\t\tif (!prev) break\n\t\tpipes.push(prev)\n\t\tpipe = prev\n\t}\n\tfor (const pipe of pipes.reverse()) acc = nodeFn(pipe, acc)\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tlet pipe = piper\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\tp.prev = pipe\n\t\t\t\tpipe = p\n\t\t\t}\n\t\t\treturn pipe\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t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,YAAYC,CAAM,EAAIxC,EACzByB,CACR,CAEA,SAASC,EAAoB,CAC5B,KAAAhB,EACA,MAAAO,EACA,QAASO,EACT,UAAAiB,EAAY,GACZ,KAAAL,EAAO,GACP,YAAAM,EACA,UAAAC,KAAY,sBAAmB1B,EAAO,QAAQ,EAC9C,KAAA2B,EAAO,CAAC,CACT,EASG,CACF,MAAMC,EAAM7C,EAAQU,CAAI,EACxBgC,IAAgBG,EAChB,MAAMC,EAAWxC,EAAKI,EAA+C,CAAC,EAAG,CAACM,EAAGH,KAC5EA,EAAI,KACHG,EAAE,QACD,CAAE,MAAAC,EAAO,QAASO,EAAY,KAAM,GAAGY,EAAO,IAAIA,CAAI,IAAM,MAAS,EAAG,EACxE,CAAE,YAAAM,EAAa,UAAAD,EAAW,KAAAL,EAAM,UAAAO,CAAU,CAC3C,CACD,EACO9B,EACP,EAED,MAAO,CAAE,MADKkC,EAAeH,EAAME,EAAS,KAAK,CAAC,EAClC,QAASD,CAAI,CAC9B,CAEA,SAASE,EAAeH,EAAgBnB,EAA8C,CACrF,OAAQ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,YAAsB,CAACZ,EAAKmB,KACvE,OAAOA,GAAQ,SAAUnB,EAAI,QAAQmB,CAAG,EACnC,OAAOA,GAAQ,aAAYnB,EAAMmB,EAAInB,CAAG,GAC1CA,GACL+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","pipes","prev","p","input","result","res","error","cont","opts","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","value","validity","message","path","fn","key","data","random","failEarly","rootContext","wrapError","base","ctx","compiled","mergePipeLines"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tnext?: Pipe<any, any>\n\tlast?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;AAEA,oBAA0B;","names":[]}
1
+ {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tprev?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;AAEA,oBAA0B;","names":[]}
@@ -1,2 +1,2 @@
1
- "use strict";var e=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var f=(n,T,y,t)=>{if(T&&typeof T=="object"||typeof T=="function")for(let r of i(T))!E.call(n,r)&&r!==y&&e(n,r,{get:()=>T[r],enumerable:!(t=p(T,r))||t.enumerable});return n};var o=n=>f(e({},"__esModule",{value:!0}),n);var a={};module.exports=o(a);var s=require('./errors.min.cjs');
1
+ "use strict";var e=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var f=(r,T,y,t)=>{if(T&&typeof T=="object"||typeof T=="function")for(let n of i(T))!E.call(r,n)&&n!==y&&e(r,n,{get:()=>T[n],enumerable:!(t=p(T,n))||t.enumerable});return r};var o=r=>f(e({},"__esModule",{value:!0}),r);var a={};module.exports=o(a);var s=require('./errors.min.cjs');
2
2
  //# sourceMappingURL=types.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tnext?: Pipe<any, any>\n\tlast?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":"+WAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAEA,IAAAE,EAA0B","names":["types_exports","__toCommonJS","import_errors"]}
1
+ {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tprev?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":"+WAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAEA,IAAAE,EAA0B","names":["types_exports","__toCommonJS","import_errors"]}
@@ -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 { standard, compileNested, context, schema } from './base/pipes'\nimport type { DeepPartial } from '../utils/types'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyD;AAGzD,MAAM,UAAU,CACf,QACA,kBACA,eAEA;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,QAAQA,QAAO,qBAAqB,KAAK;AAAA,IACzC,OAAG,4BAAc,EAAE,MAAM,MAAM,QAAQ,MAAM,CAAC,EAAE,IAAI,CAAC,MA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BAAQ,MAAM,GAAG,UAAU,KAAK,UAAU,KAAK;AAAA,EAC9D;AACD;AAED,MAAM,UAAU,CAA2B,QAAW,YACrD;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,OAAG,4BAAc,EAAE,MAAM,MAAM,QAAQ,OAAO,WAAW,SAAS,CAAC;AAAA,IACnE,OAAO,KAAK,0BAA0B,KAAK,MAAMA,QAAO;AAAA,EACzD;AAAA,EACA;AAAA,IACC,QAAQ,CAAC,OAAO,EAAE,OAAG,qBAAO,MAAM,GAAG,SAAS,EAAE,SAAS,IAAI;AAAA,IAC7D,SAAS,EAAE,OAAG,sBAAQ,MAAM,GAAG,OAAO,IAAI;AAAA,EAC3C;AACD;","names":["context"]}
1
+ {"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,I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AAA,IACC,QAAQ,CAAC,OAAO,EAAE,OAAG,qBAAO,MAAM,GAAG,SAAS,EAAE,YAAY,IAAI;AAAA,IAChE,SAAS,EAAE,OAAG,sBAAQ,MAAM,GAAG,UAAU,KAAK,UAAU,KAAK;AAAA,EAC9D;AACD;AAED,MAAM,UAAU,CAA2B,QAAW,YACrD;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,OAAG,4BAAc,EAAE,MAAM,MAAM,QAAQ,OAAO,WAAW,SAAS,CAAC;AAAA,IACnE,OAAO,KAAK,0BAA0B,KAAK,MAAMA,QAAO;AAAA,EACzD;AAAA,EACA;AAAA,IACC,QAAQ,CAAC,OAAO,EAAE,OAAG,qBAAO,MAAM,GAAG,SAAS,EAAE,SAAS,IAAI;AAAA,IAC7D,SAAS,EAAE,OAAG,sBAAQ,MAAM,GAAG,OAAO,IAAI;AAAA,EAC3C;AACD;","names":["context"]}
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var n in t)u(e,n,{get:t[n],enumerable:!0})},x=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of P(t))!c.call(e,a)&&a!==n&&u(e,a,{get:()=>t[a],enumerable:!(o=T(t,a))||o.enumerable});return e};var r=e=>x(u({},"__esModule",{value:!0}),e);var D={};f(D,{catch:()=>l,conditional:()=>I,defaults:()=>O,nullable:()=>y,nullish:()=>$,optional:()=>m});module.exports=r(D);var p=require('./base/pipes.min.cjs');const i=(e,t,n)=>(0,p.standard)(({input:o,context:a},s)=>[`if (!${a}.partialCondition(${o})) {`,...(0,p.compileNested)({opts:s,pipe:e,input:o}).map(d=>` ${d}`),"}"],{...n,context:{...n?.context,partialCondition:t}}),y=e=>i(e,t=>t===null,{schema:()=>({oneOf:[(0,p.schema)(e),{type:"null"}]})}),m=e=>i(e,t=>t===void 0,{context:{optional:!0}}),$=e=>i(e,t=>t==null,{schema:()=>({oneOf:[(0,p.schema)(e),{type:"null"}]}),context:{...(0,p.context)(e),optional:!0}}),I=(e,t)=>i(e,()=>!t(),{schema:()=>(0,p.schema)(e),context:{...(0,p.context)(e),optional:!0}}),O=(e,t)=>(0,p.standard)(({input:n,context:o},a)=>[`if (${n} === undefined) ${n} = ${o}.defaults`,...(0,p.compileNested)({opts:a,pipe:e,input:n})],{schema:n=>({...(0,p.schema)(e),default:n.defaults??t}),context:{...(0,p.context)(e),defaults:t,optional:!0}}),l=(e,t)=>(0,p.standard)(({input:n,context:o},a)=>[...(0,p.compileNested)({opts:a,pipe:e,input:n,errorType:"assign"}),`if (${n} instanceof PipeError) ${n} = ${o}.catch`],{schema:n=>({...(0,p.schema)(e),default:n.catch??t}),context:{...(0,p.context)(e),catch:t}});0&&(module.exports={catch:null,conditional,defaults,nullable,nullish,optional});
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 { standard, compileNested, context, schema } from './base/pipes'\nimport type { DeepPartial } from '../utils/types'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,gBAAAC,EAAA,aAAAC,EAAA,aAAAC,EAAA,YAAAC,EAAA,aAAAC,I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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
+ {"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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7B,OAAOF,CAAK,mBAAmBA,CAAK,MAAMC,CAAO,YACjD,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,3 +1,3 @@
1
- import{createErrorHandler as y,PipeError as s}from "./errors.min.mjs";import{getRandomValue as x}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 f(t){return c(t,{},(r,e)=>({...e,...r.context()}))}function O(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??E(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 S(t,r={}){const e=f(t);return c(t,r,(n,o)=>({...o,...n.schema(e)}))}function _(t,r){return t.pipe(d(()=>[],{schema:()=>r}))}function E(t,r={}){const e="input",n="context",{lines:o,context:i}=P({pipe:t,input:e,context:n,failEarly:!r.allErrors,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"?v(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 v(t,r={}){const e=`define_${x()}`;return d(({input:n,context:o,path:i},a)=>[`${n} = ${o}['${e}'](${n})`,a.wrapError(`${n} instanceof PipeError`,`PipeError.wrap(${i}, ${n})`)],{context:{...r?.context,[e]:t},schema:r?.schema})}function k(t){const r=x(),{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=f(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{O as assert,E as compile,k as compileNested,f as context,v as define,_ as meta,S as schema,d as standard,m as validate,c as walk};
1
+ import{createErrorHandler as y,PipeError as s}from "./errors.min.mjs";import{getRandomValue as f}from "../../utils/functions/index.min.mjs";function c(e,r,n){let t=r;const o=[e];for(;e;){const i=e.prev;if(!i)break;o.push(i),e=i}for(const i of o.reverse())t=n(i,t);return t}function m(e){return c(e,{},(r,n)=>({...n,...r.context()}))}function O(e,r){const n=x(e,r);if(!n.valid)throw n.error;return n.value}function x(e,r){try{const t=(e.__compiled??v(e))(r);return t instanceof s?{error:t,valid:!1}:{value:t,valid:!0}}catch(n){return n instanceof s?{error:n,valid:!1}:{error:s.root(n instanceof Error?n.message:`${n}`,r,void 0),valid:!1}}}function k(e,r={}){const n=m(e);return c(e,r,(t,o)=>({...o,...t.schema(n)}))}function S(e,r){return e.pipe(d(()=>[],{schema:()=>r}))}function v(e,r={}){const n="input",t="context",{lines:o,context:i}=P({pipe:e,input:n,context:t,failEarly:!r.allErrors,base:[`return ${n}`]}),a=[`return (${n}) => {`,...o.filter(p=>p.trim()!=="").map(p=>` ${p}`),` throw PipeError.root('unhandled root validation', ${n})`,"}"];return e.__compiled=new Function(t,"PipeError",a.join(`
2
+ `))(i,s),e.__compiled}function d(e,r={}){const n={context:()=>r.context??{},schema:t=>r.schema?.(t)??{},pipe:(...t)=>{delete n.__compiled;let o=n;for(const i of t){const a=typeof i=="function"?E(i,r):i;a.prev=o,o=a}return o},compile:e,"~standard":{version:1,vendor:"valleyed",validate(t){const o=x(n,t);return o.valid?{value:o.value}:{issues:o.error.messages.map(({message:i,path:a})=>({message:i,path:a?a.split("."):void 0}))}}}};return n}function E(e,r={}){const n=`define_${f()}`;return d(({input:t,context:o,path:i},a)=>[`${t} = ${o}['${n}'](${t})`,a.wrapError(`${t} instanceof PipeError`,`PipeError.wrap(${i}, ${t})`)],{context:{...r?.context,[n]:e},schema:r?.schema})}function _(e){const r=f(),{lines:n,context:t}=P({...e.opts,wrapError:y(e.input,e.errorType??e.opts.wrapError.type),pipe:e.pipe,input:e.input,context:`context[\`${r}\`]`,path:[e.opts.path,"key"in e?e.key:""].filter(Boolean).join(".")||void 0});return e.opts.rootContext[r]=t,n}function P({pipe:e,input:r,context:n,failEarly:t=!1,path:o="",rootContext:i,wrapError:a=y(r,"return"),base:p=[]}){const l=m(e);i??=l;const T=c(e,[],(h,u)=>(u.push(h.compile({input:r,context:n,path:`${o?`'${o}'`:void 0}`},{rootContext:i,failEarly:t,path:o,wrapError:a})),u));return{lines:$(p,T.flat()),context:l}}function $(e,r){return(Array.isArray(r)?r:[r]).reduceRight((n,t)=>(typeof t=="string"?n.unshift(t):typeof t=="function"&&(n=t(n)),n),e)}export{O as assert,v as compile,_ as compileNested,m as context,E as define,S as meta,k as schema,d as standard,x 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 type { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":"AAAA,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,CAAC,EAAc,CAACK,EAAGF,KAAS,CAAE,GAAGA,EAAK,GAAGE,EAAE,QAAQ,CAAE,EAAE,CAC1E,CAEO,SAASC,EAAiCN,EAASO,EAA+B,CACxF,MAAMC,EAASC,EAAST,EAAMO,CAAK,EACnC,GAAI,CAACC,EAAO,MAA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QwB,CAAG,EACnC,OAAOA,GAAQ,aAAYxB,EAAMwB,EAAIxB,CAAG,GAC1CA,GACLsC,CAAI,CACR","names":["createErrorHandler","PipeError","getRandomValue","walk","pipe","init","nodeFn","acc","context","p","assert","input","result","validate","res","compile","error","schema","cont","meta","standard","opts","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","define","value","validity","message","path","fn","key","compileNested","data","random","failEarly","rootContext","wrapError","base","ctx","compiled","mergePipeLines"]}
1
+ {"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport type { Context, Entry, JsonSchemaBuilder, Pipe, PipeCompiledFn, PipeErrorHandler, PipeFn, PipeMeta, PipeOutput } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { 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\tconst pipes: Pipe<any, any>[] = [pipe]\n\twhile (pipe) {\n\t\tconst prev = pipe.prev\n\t\tif (!prev) break\n\t\tpipes.push(prev)\n\t\tpipe = prev\n\t}\n\tfor (const pipe of pipes.reverse()) acc = nodeFn(pipe, acc)\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tlet pipe = piper\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\tp.prev = pipe\n\t\t\t\tpipe = p\n\t\t\t}\n\t\t\treturn pipe\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":"AAAA,OAAS,sBAAAA,EAAoB,aAAAC,MAAiB,WAE9C,OAAS,kBAAAC,MAAsB,wBAGxB,SAASC,EAAQC,EAAsBC,EAASC,EAA4C,CAClG,IAAIC,EAASF,EACb,MAAMG,EAA0B,CAACJ,CAAI,EACrC,KAAOA,GAAM,CACZ,MAAMK,EAAOL,EAAK,KAClB,GAAI,CAACK,EAAM,MACXD,EAAM,KAAKC,CAAI,EACfL,EAAOK,CACR,CACA,UAAWL,KAAQI,EAAM,QAAQ,EAAGD,EAAMD,EAAOF,EAAMG,CAAG,EAC1D,OAAOA,CACR,CAEO,SAASG,EAAkCN,EAAkB,CACnE,OAAOD,EAAKC,EAAM,CAAC,EAAc,CAACO,EAAGJ,KAAS,CAAE,GAAGA,EAAK,GAAGI,EAAE,QAAQ,CAAE,EAAE,CAC1E,CAEO,SAASC,EAAiCR,EAASS,E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AAU1B,EAAI,QAAQ0B,CAAG,EACnC,OAAOA,GAAQ,aAAY1B,EAAM0B,EAAI1B,CAAG,GAC1CA,GACLwC,CAAI,CACR","names":["createErrorHandler","PipeError","getRandomValue","walk","pipe","init","nodeFn","acc","pipes","prev","context","p","assert","input","result","validate","res","compile","error","schema","cont","meta","standard","opts","inputStr","contextStr","lines","compilePipeToString","allLines","l","config","piper","entries","cur","define","value","validity","message","path","fn","key","compileNested","data","random","failEarly","rootContext","wrapError","base","ctx","compiled","mergePipeLines"]}
@@ -2,10 +2,14 @@ import { createErrorHandler, PipeError } from "./errors.mjs";
2
2
  import { getRandomValue } from "../../utils/functions/index.mjs";
3
3
  function walk(pipe, init, nodeFn) {
4
4
  let acc = init;
5
+ const pipes = [pipe];
5
6
  while (pipe) {
6
- acc = nodeFn(pipe, acc);
7
- pipe = pipe.next;
7
+ const prev = pipe.prev;
8
+ if (!prev) break;
9
+ pipes.push(prev);
10
+ pipe = prev;
8
11
  }
12
+ for (const pipe2 of pipes.reverse()) acc = nodeFn(pipe2, acc);
9
13
  return acc;
10
14
  }
11
15
  function context(pipe) {
@@ -58,13 +62,13 @@ function standard(compile2, config = {}) {
58
62
  schema: (context2) => config.schema?.(context2) ?? {},
59
63
  pipe: (...entries) => {
60
64
  delete piper.__compiled;
65
+ let pipe = piper;
61
66
  for (const cur of entries) {
62
67
  const p = typeof cur === "function" ? define(cur, config) : cur;
63
- if (!piper.next) piper.next = p;
64
- if (piper.last) piper.last.next = p;
65
- piper.last = p.last ?? p;
68
+ p.prev = pipe;
69
+ pipe = p;
66
70
  }
67
- return piper;
71
+ return pipe;
68
72
  },
69
73
  compile: compile2,
70
74
  "~standard": {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/api/base/pipes.ts"],"sourcesContent":["import { createErrorHandler, PipeError } from './errors'\nimport type { Context, JsonSchemaBuilder, PipeMeta, Pipe, Entry, PipeOutput, PipeFn, PipeCompiledFn, PipeErrorHandler } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { JsonSchema } from '../../utils/types'\n\nexport function walk<T>(pipe: Pipe<any, any>, init: T, nodeFn: (cur: Pipe<any, any>, acc: T) => T) {\n\tlet acc: T = init\n\twhile (pipe) {\n\t\tacc = nodeFn(pipe, acc)\n\t\tpipe = pipe.next!\n\t}\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tfor (const cur of entries) {\n\t\t\t\tconst p = typeof cur === 'function' ? define(cur, config) : cur\n\t\t\t\tif (!piper.next) piper.next = p\n\t\t\t\tif (piper.last) piper.last.next = p\n\t\t\t\tpiper.last = p.last ?? p\n\t\t\t}\n\t\t\treturn piper\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"],"mappings":"AAAA,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,KAAK;AACnC,MAAI,CAAC,OAAO,MAAO,OAAM,OAAO;AAChC,SAAO,OAAO;AACf;AAEO,SAAS,SACf,MACA,OAC6E;AAC7E,MAAI;AACH,UAAM,KAAK,KAAK,cAAc,QAAQ,IAAI;AAC1C,UAAM,MAAM,GAAG,KAAK;AACpB,WAAO,eAAe,YAAY,EAAE,OAAO,KAAK,OAAO,MAAM,IAAI,EAAE,OAAO,KAAK,OAAO,KAAK;AAAA,EAC5F,SAAS,OAAO;AACf,QAAI,iBAAiB,UAAW,QAAO,EAAE,OAAO,OAAO,MAAM;AAC7D,WAAO,EAAE,OAAO,UAAU,KAAK,iBAAiB,QAAQ,MAAM,UAAU,GAAG,KAAK,IAAI,OAAO,MAAS,GAAG,OAAO,MAAM;AAAA,EACrH;AACD;AAEO,SAAS,OAAiC,MAASA,UAAqB,CAAC,GAAe;AAC9F,QAAM,OAAO,QAAQ,IAAI;AACzB,SAAO,KAAK,MAAMA,SAAQ,CAAC,GAAG,SAAS,EAAE,GAAG,KAAK,GAAG,EAAE,OAAO,IAAI,EAAE,EAAE;AACtE;AAEO,SAAS,KA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AAAA,EAC5B;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP;AAAA,EACA,YAAY,mBAAmB,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 type { Context, Entry, JsonSchemaBuilder, Pipe, PipeCompiledFn, PipeErrorHandler, PipeFn, PipeMeta, PipeOutput } from './types'\nimport { getRandomValue } from '../../utils/functions'\nimport type { 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\tconst pipes: Pipe<any, any>[] = [pipe]\n\twhile (pipe) {\n\t\tconst prev = pipe.prev\n\t\tif (!prev) break\n\t\tpipes.push(prev)\n\t\tpipe = prev\n\t}\n\tfor (const pipe of pipes.reverse()) acc = nodeFn(pipe, acc)\n\treturn acc\n}\n\nexport function context<T extends Pipe<any, any>>(pipe: T): Context {\n\treturn walk(pipe, {} as Context, (p, acc) => ({ ...acc, ...p.context() }))\n}\n\nexport function assert<T extends Pipe<any, any>>(pipe: T, input: unknown): PipeOutput<T> {\n\tconst result = validate(pipe, input)\n\tif (!result.valid) throw result.error\n\treturn result.value\n}\n\nexport function validate<T extends Pipe<any, any>>(\n\tpipe: T,\n\tinput: unknown,\n): { value: PipeOutput<T>; valid: true } | { error: PipeError; valid: false } {\n\ttry {\n\t\tconst fn = pipe.__compiled ?? compile(pipe)\n\t\tconst res = fn(input) as ReturnType<PipeCompiledFn<T>>\n\t\treturn res instanceof PipeError ? { error: res, valid: false } : { value: res, valid: true }\n\t} catch (error) {\n\t\tif (error instanceof PipeError) return { error, valid: false }\n\t\treturn { error: PipeError.root(error instanceof Error ? error.message : `${error}`, input, undefined), valid: false }\n\t}\n}\n\nexport function schema<T extends Pipe<any, any>>(pipe: T, schema: JsonSchema = {}): JsonSchema {\n\tconst cont = context(pipe)\n\treturn walk(pipe, schema, (p, acc) => ({ ...acc, ...p.schema(cont) }))\n}\n\nexport function meta<T extends Pipe<any, any>>(p: T, meta: PipeMeta): T {\n\treturn p.pipe(standard(() => [], { schema: () => meta })) as T\n}\n\nexport function compile<T extends Pipe<any, any>>(pipe: T, opts: { allErrors?: boolean } = {}): PipeCompiledFn<T> {\n\tconst inputStr = 'input'\n\tconst contextStr = 'context'\n\tconst { lines, context } = compilePipeToString({\n\t\tpipe,\n\t\tinput: inputStr,\n\t\tcontext: contextStr,\n\t\tfailEarly: !opts.allErrors,\n\t\tbase: [`return ${inputStr}`],\n\t})\n\tconst allLines = [\n\t\t`return (${inputStr}) => {`,\n\t\t...lines.filter((l) => l.trim() !== '').map((l) => `\\t${l}`),\n\t\t`\tthrow PipeError.root('unhandled root validation', ${inputStr})`,\n\t\t`}`,\n\t]\n\tpipe.__compiled = new Function(contextStr, 'PipeError', allLines.join('\\n'))(context, PipeError)\n\treturn pipe.__compiled!\n}\n\nexport function standard<I, O>(\n\tcompile: Pipe<I, O>['compile'],\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst piper: Pipe<I, O> = {\n\t\tcontext: () => config.context ?? ({} as any),\n\t\tschema: (context: Context) => config.schema?.(context) ?? ({} as any),\n\t\tpipe: (...entries: Entry<any, any>[]) => {\n\t\t\tdelete piper.__compiled\n\t\t\tlet pipe = piper\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\tp.prev = pipe\n\t\t\t\tpipe = p\n\t\t\t}\n\t\t\treturn pipe\n\t\t},\n\t\tcompile,\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'valleyed',\n\t\t\tvalidate(value) {\n\t\t\t\tconst validity = validate(piper, value)\n\t\t\t\tif (validity.valid) return { value: validity.value }\n\t\t\t\treturn {\n\t\t\t\t\tissues: validity.error.messages.map(({ message, path }) => ({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tpath: path ? path.split('.') : undefined,\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn piper\n}\n\nexport function define<I, O>(\n\tfn: PipeFn<I, O>,\n\tconfig: {\n\t\tcontext?: Context\n\t\tschema?: (context: Context) => JsonSchemaBuilder\n\t} = {},\n): Pipe<I, O> {\n\tconst key = `define_${getRandomValue()}`\n\treturn standard<I, O>(\n\t\t({ input, context, path }, opts) => [\n\t\t\t`${input} = ${context}['${key}'](${input})`,\n\t\t\topts.wrapError(`${input} instanceof PipeError`, `PipeError.wrap(${path}, ${input})`),\n\t\t],\n\t\t{\n\t\t\tcontext: { ...config?.context, [key]: fn },\n\t\t\tschema: config?.schema,\n\t\t},\n\t)\n}\n\nexport function compileNested(\n\tdata: {\n\t\tpipe: Pipe<any, any>\n\t\terrorType?: Parameters<typeof createErrorHandler>[1]\n\t\topts: Required<Pick<Parameters<Pipe<any, any>['compile']>[1], 'rootContext' | 'failEarly' | 'path' | 'wrapError'>>\n\t} & { input: string; key?: string },\n) {\n\tconst random = getRandomValue()\n\tconst { lines, context } = compilePipeToString({\n\t\t...data.opts,\n\t\twrapError: createErrorHandler(data.input, data.errorType ?? data.opts.wrapError.type),\n\t\tpipe: data.pipe,\n\t\tinput: data.input,\n\t\tcontext: `context[\\`${random}\\`]`,\n\t\tpath: [data.opts.path, 'key' in data ? data.key : ''].filter(Boolean).join('.') || undefined,\n\t})\n\tdata.opts.rootContext[random] = context\n\treturn lines\n}\n\nfunction compilePipeToString({\n\tpipe,\n\tinput,\n\tcontext: contextStr,\n\tfailEarly = false,\n\tpath = '',\n\trootContext,\n\twrapError = createErrorHandler(input, 'return'),\n\tbase = [],\n}: {\n\tpipe: Pipe<any, any>\n\tinput: string\n\tcontext: string\n\tfailEarly?: boolean\n\tpath?: string\n\trootContext?: Context\n\twrapError?: PipeErrorHandler\n\tbase?: string[]\n}) {\n\tconst ctx = context(pipe)\n\trootContext ??= ctx\n\tconst compiled = walk(pipe, <ReturnType<Pipe<any, any>['compile']>[]>[], (p, acc) => {\n\t\tacc.push(\n\t\t\tp.compile(\n\t\t\t\t{ input, context: contextStr, path: `${path ? `'${path}'` : undefined}` },\n\t\t\t\t{ rootContext, failEarly, path, wrapError },\n\t\t\t),\n\t\t)\n\t\treturn acc\n\t})\n\tconst lines = mergePipeLines(base, compiled.flat())\n\treturn { lines, context: ctx }\n}\n\nfunction mergePipeLines(base: string[], lines: ReturnType<Pipe<any, any>['compile']>) {\n\treturn (Array.isArray(lines) ? lines : [lines]).reduceRight<string[]>((acc, cur) => {\n\t\tif (typeof cur === 'string') acc.unshift(cur)\n\t\telse if (typeof cur === 'function') acc = cur(acc)\n\t\treturn acc\n\t}, base)\n}\n"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;AAAA,EACP;AAAA,EACA,YAAY,mBAAmB,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":["pipe","schema","meta","context","compile"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tnext?: Pipe<any, any>\n\tlast?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":"AAEA,MAA0B","names":[]}
1
+ {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tprev?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":"AAEA,MAA0B","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tnext?: Pipe<any, any>\n\tlast?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":"AAEA,SAAS,iBAAiB;","names":[]}
1
+ {"version":3,"sources":["../../../../src/api/base/types.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { PipeError } from './errors'\nimport type { JsonSchema } from '../../utils/types'\n\nexport type PipeFn<I, O> = (input: I) => O | PipeError\nexport type PipeCompiledFn<T extends Pipe<any, any>> = (input: unknown) => PipeOutput<T> | PipeError\nexport type PipeErrorHandlerType = 'return' | 'throw' | 'assign'\nexport type PipeErrorHandler = ((errorCondition: string, error: string) => (lines: string[]) => string[]) & {\n\ttype: PipeErrorHandlerType\n\tformat: (error: string) => string\n}\n\nexport type PipeInput<T> = T extends Pipe<infer I, any> ? I : never\nexport type PipeOutput<T> = T extends Pipe<any, infer O> ? O : never\nexport type PipeMeta = Pick<JsonSchema, '$refId' | 'title' | 'description' | 'examples' | 'default'>\nexport type Context = Record<string, any>\nexport type JsonSchemaBuilder = JsonSchema\n\nexport type Entry<I, O> = Pipe<I, O> | PipeFn<I, O>\ntype PipeChain<I, O> = {\n\t<T1>(fn1: Entry<O, T1>): Pipe<I, T1>\n\t<T1, T2>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>): Pipe<I, T2>\n\t<T1, T2, T3>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>): Pipe<I, T3>\n\t<T1, T2, T3, T4>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>): Pipe<I, T4>\n\t<T1, T2, T3, T4, T5>(fn1: Entry<O, T1>, fn2: Entry<T1, T2>, f3: Entry<T2, T3>, f4: Entry<T3, T4>, f5: Entry<T4, T5>): Pipe<I, T5>\n\t<T1, T2, T3, T4, T5, T6>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t): Pipe<I, T6>\n\t<T1, T2, T3, T4, T5, T6, T7>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t): Pipe<I, T7>\n\t<T1, T2, T3, T4, T5, T6, T7, T8>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t): Pipe<I, T8>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t): Pipe<I, T9>\n\t<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(\n\t\tfn1: Entry<O, T1>,\n\t\tfn2: Entry<T1, T2>,\n\t\tf3: Entry<T2, T3>,\n\t\tf4: Entry<T3, T4>,\n\t\tf5: Entry<T4, T5>,\n\t\tf6: Entry<T5, T6>,\n\t\tf7: Entry<T6, T7>,\n\t\tf8: Entry<T7, T8>,\n\t\tf9: Entry<T8, T9>,\n\t\tf10: Entry<T9, T10>,\n\t): Pipe<I, T10>\n}\n\ntype Arrayable<T> = T | T[]\n\nexport interface Pipe<I, O> extends StandardSchemaV1<I, O> {\n\treadonly context: () => Context\n\treadonly schema: (context: Context) => JsonSchema\n\treadonly pipe: PipeChain<I, O>\n\treadonly compile: (\n\t\tnames: { input: string; context: string; path: string },\n\t\topts: { rootContext: Context; failEarly: boolean; path: string; wrapError: PipeErrorHandler },\n\t) => Arrayable<string | ReturnType<PipeErrorHandler>>\n\tprev?: Pipe<any, any>\n\t__compiled?: PipeCompiledFn<any>\n}\n"],"mappings":"AAEA,SAAS,iBAAiB;","names":[]}
@@ -1,2 +1,2 @@
1
- import{standard as l,compileNested as s,context as i,schema as o}from "./base/pipes.min.mjs";const u=(e,t,n)=>l(({input:p,context:a},d)=>[`if (!${a}.partialCondition(${p})) {`,...s({opts:d,pipe:e,input:p}).map(T=>` ${T}`),"}"],{...n,context:{...n?.context,partialCondition:t}}),f=e=>u(e,t=>t===null,{schema:()=>({oneOf:[o(e),{type:"null"}]})}),x=e=>u(e,t=>t===void 0,{context:{optional:!0}}),r=e=>u(e,t=>t==null,{schema:()=>({oneOf:[o(e),{type:"null"}]}),context:{...i(e),optional:!0}}),y=(e,t)=>u(e,()=>!t(),{schema:()=>o(e),context:{...i(e),optional:!0}}),m=(e,t)=>l(({input:n,context:p},a)=>[`if (${n} === undefined) ${n} = ${p}.defaults`,...s({opts:a,pipe:e,input:n})],{schema:n=>({...o(e),default:n.defaults??t}),context:{...i(e),defaults:t,optional:!0}}),P=(e,t)=>l(({input:n,context:p},a)=>[...s({opts:a,pipe:e,input:n,errorType:"assign"}),`if (${n} instanceof PipeError) ${n} = ${p}.catch`],{schema:n=>({...o(e),default:n.catch??t}),context:{...i(e),catch:t}});export{P as catch,y as conditional,m as defaults,f as nullable,r as nullish,x as optional};
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 { standard, compileNested, context, schema } from './base/pipes'\nimport type { DeepPartial } from '../utils/types'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":"AACA,OAAS,YAAAA,EAAU,iBAAAC,EAAe,WAAAC,EAAS,UAAAC,MAAc,eAGzD,MAAMC,EAAU,CACfC,EACAC,EACAC,IAEAP,EACC,CAAC,CAAE,MAAAQ,EAAO,QAAAN,CAAQ,EAAGO,IAAS,CAC7B,QAAQP,CAAO,qBAAqBM,CAAK,OACzC,GAAGP,EAAc,CAAE,K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EKE,EAAU,CAA2Bf,EAAWa,IACrDlB,EACC,CAAC,CAAE,MAAAQ,EAAO,QAAAN,CAAQ,EAAGO,IAAS,CAC7B,GAAGR,EAAc,CAAE,KAAAQ,EAAM,KAAMJ,EAAQ,MAAAG,EAAO,UAAW,QAAS,CAAC,EACnE,OAAOA,CAAK,0BAA0BA,CAAK,MAAMN,CAAO,QACzD,EACA,CACC,OAASiB,IAAO,CAAE,GAAGhB,EAAOE,CAAM,EAAG,QAASc,EAAE,OAASD,CAAI,GAC7D,QAAS,CAAE,GAAGhB,EAAQG,CAAM,EAAG,MAAOa,CAAI,CAC3C,CACD","names":["standard","compileNested","context","schema","partial","branch","partialCondition","config","input","opts","l","nullable","i","optional","nullish","conditional","condition","defaults","def","c","onCatch"]}
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,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,SAAU,EAAK,CAC9D,CACD,EAEKE,EAAU,CAA2Bf,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 { standard, compileNested, context, schema } from "./base/pipes.mjs";
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 { standard, compileNested, context, schema } from './base/pipes'\nimport type { DeepPartial } from '../utils/types'\n\nconst partial = <T extends Pipe<any, any>, P>(\n\tbranch: T,\n\tpartialCondition: (i: unknown) => boolean,\n\tconfig: Parameters<typeof standard<PipeInput<T> | P, PipeOutput<T> | P>>[1],\n) =>\n\tstandard<PipeInput<T> | P, PipeOutput<T> | P>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (!${context}.partialCondition(${input})) {`,\n\t\t\t...compileNested({ opts, pipe: branch, input }).map((l) => ` ${l}`),\n\t\t\t`}`,\n\t\t],\n\t\t{\n\t\t\t...config,\n\t\t\tcontext: { ...config?.context, partialCondition },\n\t\t},\n\t)\n\nexport const nullable = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null>(branch, (i) => i === null, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t})\n\nexport const optional = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, undefined>(branch, (i) => i === undefined, {\n\t\tcontext: { optional: true },\n\t})\n\nexport const nullish = <T extends Pipe<any, any>>(branch: T) =>\n\tpartial<T, null | undefined>(branch, (i) => i === null || i === undefined, {\n\t\tschema: () => ({ oneOf: [schema(branch), { type: 'null' }] }),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\nexport const conditional = <T extends Pipe<any, any>>(branch: T, condition: () => boolean) =>\n\tpartial<T, never>(branch, () => !condition(), {\n\t\tschema: () => schema(branch),\n\t\tcontext: { ...context(branch), optional: true },\n\t})\n\ntype DefaultValue<T> = T extends object ? DeepPartial<T> : T\n\nexport const defaults = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T> | undefined, Exclude<PipeOutput<T>, undefined>>(\n\t\t({ input, context }, opts) => [\n\t\t\t`if (${input} === undefined) ${input} = ${context}.defaults`,\n\t\t\t...compileNested({ opts, pipe: branch, input }),\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.defaults ?? def }),\n\t\t\tcontext: { ...context(branch), defaults: def, optional: true },\n\t\t},\n\t)\n\nconst onCatch = <T extends Pipe<any, any>>(branch: T, def: DefaultValue<PipeInput<T>>) =>\n\tstandard<PipeInput<T>, PipeOutput<T>>(\n\t\t({ input, context }, opts) => [\n\t\t\t...compileNested({ opts, pipe: branch, input, errorType: 'assign' }),\n\t\t\t`if (${input} instanceof PipeError) ${input} = ${context}.catch`,\n\t\t],\n\t\t{\n\t\t\tschema: (c) => ({ ...schema(branch), default: c.catch ?? def }),\n\t\t\tcontext: { ...context(branch), catch: def },\n\t\t},\n\t)\n\nexport { onCatch as catch }\n"],"mappings":"AACA,SAAS,UAAU,eAAe,SAAS,cAAc;AAGzD,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;AAC3B,CAAC;AAEK,MAAM,UAAU,CAA2B,WACjD,QAA6B,QAAQ,CAAC,MAAM,MAAM,QAAQ,MAAM,QAAW;AAAA,EAC1E,QAAQ,OAAO,EAAE,OAAO,CAAC,OAAO,MAAM,GAAG,EAAE,MAAM,OAAO,CAAC,EAAE;AAAA,EAC3D,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,UAAU,KAAK;AAC/C,CAAC;AAEK,MAAM,cAAc,CAA2B,QAAW,cAChE,QAAkB,QAAQ,MAAM,CAAC,UAAU,GAAG;AAAA,EAC7C,QAAQ,MAAM,OAAO,MAAM;AAAA,EAC3B,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,UAAU,KAAK;AAC/C,CAAC;AAIK,MAAM,WAAW,CAA2B,QAAW,QAC7D;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,OAAO,KAAK,mBAAmB,KAAK,MAAMA,QAAO;AAAA,IACjD,GAAG,cAAc,EAAE,MAAM,MAAM,QAAQ,MAAM,CAAC;AAAA,EAC/C;AAAA,EACA;AAAA,IACC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,MAAM,GAAG,SAAS,EAAE,YAAY,IAAI;AAAA,IAChE,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,UAAU,KAAK,UAAU,KAAK;AAAA,EAC9D;AACD;AAED,MAAM,UAAU,CAA2B,QAAW,QACrD;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,GAAG,cAAc,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,GAAG,OAAO,MAAM,GAAG,SAAS,EAAE,SAAS,IAAI;AAAA,IAC7D,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,OAAO,IAAI;AAAA,EAC3C;AACD;","names":["context"]}
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,QAAQ,OAAO,EAAE,OAAO,CAAC,OAAO,MAAM,GAAG,EAAE,MAAM,OAAO,CAAC,EAAE;AAAA,EAC3D,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,UAAU,KAAK;AAC/C,CAAC;AAEK,MAAM,cAAc,CAA2B,QAAW,cAChE,QAAkB,QAAQ,MAAM,CAAC,UAAU,GAAG;AAAA,EAC7C,QAAQ,MAAM,OAAO,MAAM;AAAA,EAC3B,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,UAAU,KAAK;AAC/C,CAAC;AAIK,MAAM,WAAW,CAA2B,QAAW,QAC7D;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,OAAO,KAAK,mBAAmB,KAAK,MAAMA,QAAO;AAAA,IACjD,GAAG,cAAc,EAAE,MAAM,MAAM,QAAQ,MAAM,CAAC;AAAA,EAC/C;AAAA,EACA;AAAA,IACC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,MAAM,GAAG,SAAS,EAAE,YAAY,IAAI;AAAA,IAChE,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,UAAU,KAAK,UAAU,KAAK;AAAA,EAC9D;AACD;AAED,MAAM,UAAU,CAA2B,QAAW,QACrD;AAAA,EACC,CAAC,EAAE,OAAO,SAAAA,SAAQ,GAAG,SAAS;AAAA,IAC7B,GAAG,cAAc,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,GAAG,OAAO,MAAM,GAAG,SAAS,EAAE,SAAS,IAAI;AAAA,IAC7D,SAAS,EAAE,GAAG,QAAQ,MAAM,GAAG,OAAO,IAAI;AAAA,EAC3C;AACD;","names":["context"]}
@@ -1,4 +1,4 @@
1
- import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -1,3 +1,3 @@
1
- export { P as PipeError, c as createErrorHandler } from '../../errors-B_b7Rsqj.js';
1
+ export { P as PipeError, c as createErrorHandler } from '../../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../../utils/types.js';
@@ -1,4 +1,4 @@
1
- export { C as Context, E as Entry, J as JsonSchemaBuilder, i as Pipe, b as PipeCompiledFn, P as PipeError, e as PipeErrorHandler, d as PipeErrorHandlerType, a as PipeFn, f as PipeInput, h as PipeMeta, g as PipeOutput, c as createErrorHandler } from '../../errors-B_b7Rsqj.js';
1
+ export { C as Context, E as Entry, J as JsonSchemaBuilder, i as Pipe, b as PipeCompiledFn, P as PipeError, e as PipeErrorHandler, d as PipeErrorHandlerType, a as PipeFn, f as PipeInput, h as PipeMeta, g as PipeOutput, c as createErrorHandler } from '../../errors-B5taetnA.js';
2
2
  export { compileNested } from './pipes.js';
3
3
  import '@standard-schema/spec';
4
4
  import '../../utils/types.js';
@@ -1,4 +1,4 @@
1
- import { i as Pipe, c as createErrorHandler, g as PipeOutput, C as Context, P as PipeError, b as PipeCompiledFn, a as PipeFn, J as JsonSchemaBuilder, h as PipeMeta } from '../../errors-B_b7Rsqj.js';
1
+ import { i as Pipe, c as createErrorHandler, g as PipeOutput, C as Context, P as PipeError, b as PipeCompiledFn, a as PipeFn, J as JsonSchemaBuilder, h as PipeMeta } from '../../errors-B5taetnA.js';
2
2
  import { JsonSchema } from '../../utils/types.js';
3
3
  import '@standard-schema/spec';
4
4
 
@@ -2,10 +2,14 @@ import { createErrorHandler, PipeError } from "./errors.js";
2
2
  import { getRandomValue } from "../../utils/functions/index.js";
3
3
  function walk(pipe, init, nodeFn) {
4
4
  let acc = init;
5
+ const pipes = [pipe];
5
6
  while (pipe) {
6
- acc = nodeFn(pipe, acc);
7
- pipe = pipe.next;
7
+ const prev = pipe.prev;
8
+ if (!prev) break;
9
+ pipes.push(prev);
10
+ pipe = prev;
8
11
  }
12
+ for (const pipe2 of pipes.reverse()) acc = nodeFn(pipe2, acc);
9
13
  return acc;
10
14
  }
11
15
  function context(pipe) {
@@ -58,13 +62,13 @@ function standard(compile2, config = {}) {
58
62
  schema: (context2) => config.schema?.(context2) ?? {},
59
63
  pipe: (...entries) => {
60
64
  delete piper.__compiled;
65
+ let pipe = piper;
61
66
  for (const cur of entries) {
62
67
  const p = typeof cur === "function" ? define(cur, config) : cur;
63
- if (!piper.next) piper.next = p;
64
- if (piper.last) piper.last.next = p;
65
- piper.last = p.last ?? p;
68
+ p.prev = pipe;
69
+ pipe = p;
66
70
  }
67
- return piper;
71
+ return pipe;
68
72
  },
69
73
  compile: compile2,
70
74
  "~standard": {
@@ -1,3 +1,3 @@
1
1
  import '@standard-schema/spec';
2
- export { C as Context, E as Entry, J as JsonSchemaBuilder, i as Pipe, b as PipeCompiledFn, e as PipeErrorHandler, d as PipeErrorHandlerType, a as PipeFn, f as PipeInput, h as PipeMeta, g as PipeOutput } from '../../errors-B_b7Rsqj.js';
2
+ export { C as Context, E as Entry, J as JsonSchemaBuilder, i as Pipe, b as PipeCompiledFn, e as PipeErrorHandler, d as PipeErrorHandlerType, a as PipeFn, f as PipeInput, h as PipeMeta, g as PipeOutput } from '../../errors-B5taetnA.js';
3
3
  import '../../utils/types.js';
@@ -1,4 +1,4 @@
1
- import { i as Pipe } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { i as Pipe } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -10,6 +10,6 @@ export { any, boolean, instanceOf, null, number, string, undefined } from './typ
10
10
  export { asMap, object, objectOmit, objectPick, record } from './records.js';
11
11
  export { asCapitalized, asLowercased, asSliced, asStrippedHtml, asTrimmed, asUppercased, email, url, withStrippedHtml } from './strings.js';
12
12
  export { Timeable, after, asISOString, asStamp, before, time } from './times.js';
13
- import '../errors-B_b7Rsqj.js';
13
+ import '../errors-B5taetnA.js';
14
14
  import '@standard-schema/spec';
15
15
  import '../utils/types.js';
@@ -1,4 +1,4 @@
1
- import { i as Pipe } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -10,7 +10,7 @@ import { any as isAny, boolean as isBoolean, instanceOf as isInstanceOf, null as
10
10
  import { asMap, object, objectOmit, objectPick, record } from './records.js';
11
11
  import { asCapitalized, asLowercased, asSliced, asStrippedHtml, asTrimmed, asUppercased, email, url, withStrippedHtml } from './strings.js';
12
12
  import { Timeable, after, asISOString, asStamp, before, time } from './times.js';
13
- import '../errors-B_b7Rsqj.js';
13
+ import '../errors-B5taetnA.js';
14
14
  import '@standard-schema/spec';
15
15
  import '../utils/types.js';
16
16
 
@@ -1,4 +1,4 @@
1
- import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B5taetnA.js';
2
2
  import { JSONRedacted } from '../utils/types.js';
3
3
  import '@standard-schema/spec';
4
4
 
@@ -1,4 +1,4 @@
1
- import { i as Pipe } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -1,5 +1,5 @@
1
- import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B_b7Rsqj.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 { standard, compileNested, context, schema } from "./base/pipes.js";
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" }] }),
@@ -1,4 +1,4 @@
1
- import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe, f as PipeInput, g as PipeOutput } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { i as Pipe } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { i as Pipe } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { i as Pipe } from '../errors-B_b7Rsqj.js';
1
+ import { i as Pipe } from '../errors-B5taetnA.js';
2
2
  import '@standard-schema/spec';
3
3
  import '../utils/types.js';
4
4
 
@@ -41,8 +41,7 @@ interface Pipe<I, O> extends StandardSchemaV1<I, O> {
41
41
  path: string;
42
42
  wrapError: PipeErrorHandler;
43
43
  }) => Arrayable<string | ReturnType<PipeErrorHandler>>;
44
- next?: Pipe<any, any>;
45
- last?: Pipe<any, any>;
44
+ prev?: Pipe<any, any>;
46
45
  __compiled?: PipeCompiledFn<any>;
47
46
  }
48
47
 
@@ -3,7 +3,7 @@ export { d as differ } from './differ-oxbwYLvl.js';
3
3
  export { addToArray, capitalize, chunkArray, compareTwoStrings, divideByZero, extractUrls, formatNumber, getAlphabet, getPercentage, getRandomSample, getRandomValue, groupBy, pluralize, shuffleArray, stripHTML, trimToLength, wrapInTryCatch } from './utils/functions/index.js';
4
4
  export { g as geohash } from './geohash-BCD6jCDO.js';
5
5
  export { BSONValueOf, ConditionalObjectKeys, DeepOmit, DeepPartial, DistributiveOmit, EnumToStringUnion, IsClassInstance, IsInTypeList, IsPlainObject, IsType, JSONRedacted, JSONValueOf, JsonSchema, Paths, Prettify } from './utils/types.js';
6
- export { C as Context, E as Entry, J as JsonSchemaBuilder, i as Pipe, b as PipeCompiledFn, P as PipeError, e as PipeErrorHandler, d as PipeErrorHandlerType, a as PipeFn, f as PipeInput, h as PipeMeta, g as PipeOutput, c as createErrorHandler } from './errors-B_b7Rsqj.js';
6
+ export { C as Context, E as Entry, J as JsonSchemaBuilder, i as Pipe, b as PipeCompiledFn, P as PipeError, e as PipeErrorHandler, d as PipeErrorHandlerType, a as PipeFn, f as PipeInput, h as PipeMeta, g as PipeOutput, c as createErrorHandler } from './errors-B5taetnA.js';
7
7
  export { compileNested } from './api/base/pipes.js';
8
8
  export { v } from './api/index.js';
9
9
  import '@standard-schema/spec';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valleyed",
3
- "version": "4.5.18",
3
+ "version": "4.5.20",
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,
@@ -38,17 +38,17 @@
38
38
  "author": "Kevin Izuchukwu",
39
39
  "license": "ISC",
40
40
  "devDependencies": {
41
- "@commitlint/cli": "^20.3.1",
42
- "@commitlint/config-conventional": "^20.3.1",
41
+ "@commitlint/cli": "^20.4.2",
42
+ "@commitlint/config-conventional": "^20.4.2",
43
43
  "@k11/configs": "^0.1.2",
44
- "@types/node": "^25.0.9",
44
+ "@types/node": "^25.3.3",
45
45
  "esbuild-fix-imports-plugin": "^1.0.23",
46
46
  "eslint": "^9.39.2",
47
47
  "husky": "^9.1.7",
48
48
  "standard-version": "^9.5.0",
49
49
  "tsup": "^8.5.1",
50
50
  "typescript": "^5.9.3",
51
- "vitest": "^4.0.17"
51
+ "vitest": "^4.0.18"
52
52
  },
53
53
  "files": [
54
54
  "LICENSE",