equipped 5.0.15 → 5.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/validations/valleyed.cjs +6 -4
- package/dist/cjs/validations/valleyed.cjs.map +1 -1
- package/dist/cjs/validations/valleyed.min.cjs +1 -1
- package/dist/cjs/validations/valleyed.min.cjs.map +1 -1
- package/dist/esm/validations/valleyed.min.mjs +1 -1
- package/dist/esm/validations/valleyed.min.mjs.map +1 -1
- package/dist/esm/validations/valleyed.mjs +6 -4
- package/dist/esm/validations/valleyed.mjs.map +1 -1
- package/dist/types/validations/index.d.ts +3 -4
- package/dist/types/validations/valleyed.js +6 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [5.0.16](https://github.com/kevinand11/equipped/compare/v5.0.15...v5.0.16) (2025-07-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* withRequest and withResponse ([80c5a7f](https://github.com/kevinand11/equipped/commit/80c5a7fda7c4e4f221ef8ad427a55b12bfd6087d))
|
|
11
|
+
|
|
5
12
|
### [5.0.15](https://github.com/kevinand11/equipped/compare/v5.0.14...v5.0.15) (2025-07-06)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -20,15 +20,17 @@ const incomingFiles = (err) => _valleyed.v.define(_valleyed.v.compile(filePipe(e
|
|
|
20
20
|
});
|
|
21
21
|
const requestLocalStorage = new (0, _nodeasync_hooks.AsyncLocalStorage)();
|
|
22
22
|
const responseLocalStorage = new (0, _nodeasync_hooks.AsyncLocalStorage)();
|
|
23
|
-
const withRequest = (fn) => _valleyed.v.
|
|
23
|
+
const withRequest = (fn) => _valleyed.v.define((input) => {
|
|
24
24
|
const req = requestLocalStorage.getStore();
|
|
25
25
|
if (!req) throw new Error("Request not found in context");
|
|
26
|
-
|
|
26
|
+
const validated = _valleyed.v.validate(fn(req), input);
|
|
27
|
+
return validated.valid ? validated.value : validated.error;
|
|
27
28
|
});
|
|
28
|
-
const withResponse = (fn) => _valleyed.v.
|
|
29
|
+
const withResponse = (fn) => _valleyed.v.define((input) => {
|
|
29
30
|
const res = responseLocalStorage.getStore();
|
|
30
31
|
if (!res) throw new Error("Response not found in context");
|
|
31
|
-
|
|
32
|
+
const validated = _valleyed.v.validate(fn(res), input);
|
|
33
|
+
return validated.valid ? validated.value : validated.error;
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/validations/valleyed.ts","/home/runner/work/equipped/equipped/dist/cjs/validations/valleyed.cjs"],"names":["err"],"mappings":"AAAA,goBAAkC;AAElC,
|
|
1
|
+
{"version":3,"sources":["../../../src/validations/valleyed.ts","/home/runner/work/equipped/equipped/dist/cjs/validations/valleyed.cjs"],"names":["err"],"mappings":"AAAA,goBAAkC;AAElC,oCAA0D;AAE1D,iDAAyB;AAGzB,MAAM,SAAA,EAAW,CAAC,GAAA,EAAA,GACjB,WAAA,CAAE,KAAA;AAAA,EACD,WAAA,CAAE,IAAA,CAAmB,GAAG,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,EAAA,GAAU;AACzC,IAAA,MAAMA,KAAAA,EAAM,CAAA,gCAAA,kBAAmC,kBAAA,mBAAS,GAAA,mBAAI,CAAA,qBAAE,QAAA,qBAAS,MAAA,6BAAQ,QAAA,qBAAS,uBAAqB,CAAA,EAAA,CAAA;AAC7G,IAAA,MAAM,MAAA,EAAQ,MAAA,EAAQ,CAAC,KAAA,CAAM,YAAA,EAAc,IAAA;AAC3C,IAAA,GAAA,CAAI,KAAA,EAAO,OAAO,KAAA;AAClB,IAAA,MAAM,mBAAA,CAAU,IAAA,CAAKA,IAAAA,EAAK,KAAK,CAAA;AAAA,EAChC,CAAC;AACF,CAAA;AAEM,MAAM,aAAA,EAAe,CAAC,GAAA,EAAA,GAC5B,WAAA,CAAE,MAAA;AAAA,EACD,WAAA,CAAE,OAAA;AAAA,IACD,QAAA,CAAS,GAAG,CAAA,CACV,IAAA,CAAK,WAAA,CAAE,GAAA,CAAI,CAAA,EAAG,kBAAkB,CAAC,CAAA,CACjC,IAAA,CAAK,CAAC,KAAA,EAAA,GAAU,KAAA,CAAM,CAAC,CAAC;AAAA,EAC3B,CAAA;AAAA,EACA,EAAE,MAAA,EAAQ,CAAA,EAAA,GAAA,CAAO,EAAE,IAAA,EAAM,QAAA,EAAU,MAAA,EAAQ,SAAS,CAAA,EAAG;AACxD,CAAA;AAEM,MAAM,cAAA,EAAgB,CAAC,GAAA,EAAA,GAC7B,WAAA,CAAE,MAAA,CAAgC,WAAA,CAAE,OAAA,CAAQ,QAAA,CAAS,GAAG,CAAC,CAAA,EAAG;AAAA,EAC3D,MAAA,EAAQ,CAAA,EAAA,GAAA,CAAO,EAAE,IAAA,EAAM,QAAA,EAAU,MAAA,EAAQ,SAAS,CAAA;AACnD,CAAC,CAAA;AAEK,MAAM,oBAAA,EAAsB,IAAI,uCAAA,CAAuD,CAAA;AACvF,MAAM,qBAAA,EAAuB,IAAI,uCAAA,CAAwD,CAAA;AAEzF,MAAM,YAAA,EAAc,CAA2B,EAAA,EAAA,GACrD,WAAA,CAAE,MAAA,CAAoC,CAAC,KAAA,EAAA,GAAU;AAChD,EAAA,MAAM,IAAA,EAAM,mBAAA,CAAoB,QAAA,CAAS,CAAA;AACzC,EAAA,GAAA,CAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,8BAA8B,CAAA;AACxD,EAAA,MAAM,UAAA,EAAY,WAAA,CAAE,QAAA,CAAS,EAAA,CAAG,GAAG,CAAA,EAAG,KAAK,CAAA;AAC3C,EAAA,OAAO,SAAA,CAAU,MAAA,EAAQ,SAAA,CAAU,MAAA,EAAQ,SAAA,CAAU,KAAA;AACtD,CAAC,CAAA;AAEK,MAAM,aAAA,EAAe,CAA2B,EAAA,EAAA,GACtD,WAAA,CAAE,MAAA,CAAoC,CAAC,KAAA,EAAA,GAAU;AAChD,EAAA,MAAM,IAAA,EAAM,oBAAA,CAAqB,QAAA,CAAS,CAAA;AAC1C,EAAA,GAAA,CAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,+BAA+B,CAAA;AACzD,EAAA,MAAM,UAAA,EAAY,WAAA,CAAE,QAAA,CAAS,EAAA,CAAG,GAAG,CAAA,EAAG,KAAK,CAAA;AAC3C,EAAA,OAAO,SAAA,CAAU,MAAA,EAAQ,SAAA,CAAU,MAAA,EAAQ,SAAA,CAAU,KAAA;AACtD,CAAC,CAAA;ACfF;AACE;AACA;AACA;AACA;AACA;AACA;AACF,2PAAC","file":"/home/runner/work/equipped/equipped/dist/cjs/validations/valleyed.cjs","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { Pipe, PipeError, PipeInput, PipeOutput, v } from 'valleyed'\n\nimport { Instance } from '../instance'\nimport type { IncomingFile, Response, Request, RouteDef, RouteDefToReqRes } from '../server'\n\nconst filePipe = (err?: string) =>\n\tv.array(\n\t\tv.file<IncomingFile>(err).pipe((input) => {\n\t\t\tconst err = `is larger than allowed limit of ${Instance.get().settings.server?.requests.maxFileUploadSizeInMb}mb`\n\t\t\tconst valid = input ? !input.isTruncated : true\n\t\t\tif (valid) return input\n\t\t\tthrow PipeError.root(err, input)\n\t\t}),\n\t)\n\nexport const incomingFile = (err?: string) =>\n\tv.define<unknown, IncomingFile>(\n\t\tv.compile(\n\t\t\tfilePipe(err)\n\t\t\t\t.pipe(v.min(1, 'no file provided'))\n\t\t\t\t.pipe((files) => files[0]),\n\t\t),\n\t\t{ schema: () => ({ type: 'string', format: 'binary' }) },\n\t)\n\nexport const incomingFiles = (err?: string) =>\n\tv.define<unknown, IncomingFile[]>(v.compile(filePipe(err)), {\n\t\tschema: () => ({ type: 'string', format: 'binary' }),\n\t})\n\nexport const requestLocalStorage = new AsyncLocalStorage<Request<RouteDefToReqRes<RouteDef>>>()\nexport const responseLocalStorage = new AsyncLocalStorage<Response<RouteDefToReqRes<RouteDef>>>()\n\nexport const withRequest = <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst req = requestLocalStorage.getStore()\n\t\tif (!req) throw new Error('Request not found in context')\n\t\tconst validated = v.validate(fn(req), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n\nexport const withResponse = <T extends Pipe<any, any>>(fn: (req: Response<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst res = responseLocalStorage.getStore()\n\t\tif (!res) throw new Error('Response not found in context')\n\t\tconst validated = v.validate(fn(res), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n",null]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _nodeasync_hooks = require('node:async_hooks');var _valleyed = require('valleyed');var _indexmincjs = require('../instance/index.min.cjs');const
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _nodeasync_hooks = require('node:async_hooks');var _valleyed = require('valleyed');var _indexmincjs = require('../instance/index.min.cjs');const s=o=>_valleyed.v.array(_valleyed.v.file(o).pipe(t=>{const r=`is larger than allowed limit of ${_optionalChain([_indexmincjs.Instance, 'access', _ => _.get, 'call', _2 => _2(), 'access', _3 => _3.settings, 'access', _4 => _4.server, 'optionalAccess', _5 => _5.requests, 'access', _6 => _6.maxFileUploadSizeInMb])}mb`;if(t?!t.isTruncated:!0)return t;throw _valleyed.PipeError.root(r,t)})),q= exports.incomingFile =o=>_valleyed.v.define(_valleyed.v.compile(s(o).pipe(_valleyed.v.min(1,"no file provided")).pipe(t=>t[0])),{schema:()=>({type:"string",format:"binary"})}),v= exports.incomingFiles =o=>_valleyed.v.define(_valleyed.v.compile(s(o)),{schema:()=>({type:"string",format:"binary"})}),u= exports.requestLocalStorage =new _nodeasync_hooks.AsyncLocalStorage,c= exports.responseLocalStorage =new _nodeasync_hooks.AsyncLocalStorage,T= exports.withRequest =o=>_valleyed.v.define(t=>{const r=u.getStore();if(!r)throw new Error("Request not found in context");const n=_valleyed.v.validate(o(r),t);return n.valid?n.value:n.error}),w= exports.withResponse =o=>_valleyed.v.define(t=>{const r=c.getStore();if(!r)throw new Error("Response not found in context");const n=_valleyed.v.validate(o(r),t);return n.valid?n.value:n.error});exports.incomingFile = q; exports.incomingFiles = v; exports.requestLocalStorage = u; exports.responseLocalStorage = c; exports.withRequest = T; exports.withResponse = w;
|
|
2
2
|
//# sourceMappingURL=valleyed.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/validations/valleyed.ts"],"names":["err","input","PipeError","incomingFile","v","incomingFiles","requestLocalStorage","AsyncLocalStorage","withRequest","req","
|
|
1
|
+
{"version":3,"sources":["../../../src/validations/valleyed.ts"],"names":["err","input","PipeError","incomingFile","v","incomingFiles","requestLocalStorage","AsyncLocalStorage","withRequest","req","validated","fn","res"],"mappings":"AAAA,goBAAkC,oCAEwB,wDAMvD,MACC,CAAA,CAAA,CAAA,EAAmBA,WAAG,CAAA,KAAE,CAAMC,WAAAA,CAAAA,IAC/B,CAAA,CAAA,CAAA,CAAMD,IAAM,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,CAAA,gCAAkD,kBAAA,qBAAA,mBAAS,GAAA,mBAAA,CAAA,qBAAA,QAAQ,qBAAA,MAAS,6BAAA,QAAA,qBAAA,uBAC3D,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAc,CAAA,CAAA,CAChC,WACX,CAAA,CAAA,CAAA,CAAME,OAAeF,CAAAA,CAAKC,MAIhBE,mBAAAA,CAAgBH,IAC5BI,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACDA,CAAAA,CAAE,wBAAA,CAAA,EAAA,WAAA,CAAA,MACW,CACV,WAAA,CAAA,OAAO,CAAA,CAAI,CAAA,CAAG,CAAA,CAAA,IAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,CAAA,kBACU,CAC3B,CAAA,CACA,IAAE,CAAA,CAAA,EAAQ,CAAA,CAAA,CAAA,CAAA,CAAO,CAAE,CAAA,CAAA,MAAM,CAAA,CAAA,CAAA,EAAA,CAAU,CAAA,IAAA,CAAA,QAAQ,CAAS,MAGzCC,CAAiBL,QAC3B,CAAA,CAAA,CAAA,CAAgCI,CAAAA,CAAE,yBAAA,CAAA,EAAA,WAAA,CAAA,MAAqB,CAAA,WAAG,CAC3D,OAAQ,CAAA,CAAA,CAAA,CAAA,CAAO,CAAE,CAAA,CAAA,MAAM,CAAA,CAAA,CAAA,EAAA,CAAU,CAAA,IAAA,CAAA,QAAQ,CAAS,MAGvCE,CAAsB,QACC,CAAA,CAAA,CAAA,CAAIC,CAAAA,CAE3BC,+BAAAA,IACZJ,kCAAAA,CAAE,CAAA,gCAAA,IAAA,kCAAqCH,CAAAA,CAAAA,uBAAU,CAChD,EAAA,WAAA,CAAA,MAAgC,CAAA,CAAA,EAAA,CAAA,MAChC,CAAA,CAAA,CAAI,CAACQ,QAAW,CAAA,CAAA,CAAA,EAAI,CAAA,CAAA,CAAA,CAAA,MAAM,IAAA,KAAA,CAAA,8BACN,CAAA,CAAA,MAAYA,CAAG,CAAA,WAAGR,CAAK,QAC3C,CAAOS,CAAAA,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQA,OAAU,CAAQA,CAAAA,KAAU,CACtD,CAAC,CAAA,KAEqDC,CACtDP,CAAAA,CAAE,KAAA,CAAA,CAAqCH,CAAAA,CAAAA,wBAAU,CAChD,EAAA,WAAA,CAAA,MAAiC,CAAA,CAAA,EAAA,CAAA,MACjC,CAAA,CAAA,CAAI,CAACW,QAAW,CAAA,CAAA,CAAA,EAAI,CAAA,CAAA,CAAA,CAAA,MAAM,IAAA,KAAA,CAAA,+BACN,CAAA,CAAA,MAAYA,CAAG,CAAA,WAAGX,CAAK,QAC3C,CAAOS,CAAAA,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQA,OAAU,CAAQA,CAAAA,KAAU,CACtD,CAAC,CAAA,KAAA,CAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,0KAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/validations/valleyed.min.cjs","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { Pipe, PipeError, PipeInput, PipeOutput, v } from 'valleyed'\n\nimport { Instance } from '../instance'\nimport type { IncomingFile, Response, Request, RouteDef, RouteDefToReqRes } from '../server'\n\nconst filePipe = (err?: string) =>\n\tv.array(\n\t\tv.file<IncomingFile>(err).pipe((input) => {\n\t\t\tconst err = `is larger than allowed limit of ${Instance.get().settings.server?.requests.maxFileUploadSizeInMb}mb`\n\t\t\tconst valid = input ? !input.isTruncated : true\n\t\t\tif (valid) return input\n\t\t\tthrow PipeError.root(err, input)\n\t\t}),\n\t)\n\nexport const incomingFile = (err?: string) =>\n\tv.define<unknown, IncomingFile>(\n\t\tv.compile(\n\t\t\tfilePipe(err)\n\t\t\t\t.pipe(v.min(1, 'no file provided'))\n\t\t\t\t.pipe((files) => files[0]),\n\t\t),\n\t\t{ schema: () => ({ type: 'string', format: 'binary' }) },\n\t)\n\nexport const incomingFiles = (err?: string) =>\n\tv.define<unknown, IncomingFile[]>(v.compile(filePipe(err)), {\n\t\tschema: () => ({ type: 'string', format: 'binary' }),\n\t})\n\nexport const requestLocalStorage = new AsyncLocalStorage<Request<RouteDefToReqRes<RouteDef>>>()\nexport const responseLocalStorage = new AsyncLocalStorage<Response<RouteDefToReqRes<RouteDef>>>()\n\nexport const withRequest = <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst req = requestLocalStorage.getStore()\n\t\tif (!req) throw new Error('Request not found in context')\n\t\tconst validated = v.validate(fn(req), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n\nexport const withResponse = <T extends Pipe<any, any>>(fn: (req: Response<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst res = responseLocalStorage.getStore()\n\t\tif (!res) throw new Error('Response not found in context')\n\t\tconst validated = v.validate(fn(res), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{AsyncLocalStorage as
|
|
1
|
+
import{AsyncLocalStorage as i}from"node:async_hooks";import{PipeError as p,v as e}from"valleyed";import{Instance as a}from "../instance/index.min.mjs";const s=o=>e.array(e.file(o).pipe(t=>{const r=`is larger than allowed limit of ${a.get().settings.server?.requests.maxFileUploadSizeInMb}mb`;if(t?!t.isTruncated:!0)return t;throw p.root(r,t)})),q=o=>e.define(e.compile(s(o).pipe(e.min(1,"no file provided")).pipe(t=>t[0])),{schema:()=>({type:"string",format:"binary"})}),v=o=>e.define(e.compile(s(o)),{schema:()=>({type:"string",format:"binary"})}),u=new i,c=new i,T=o=>e.define(t=>{const r=u.getStore();if(!r)throw new Error("Request not found in context");const n=e.validate(o(r),t);return n.valid?n.value:n.error}),w=o=>e.define(t=>{const r=c.getStore();if(!r)throw new Error("Response not found in context");const n=e.validate(o(r),t);return n.valid?n.value:n.error});export{q as incomingFile,v as incomingFiles,u as requestLocalStorage,c as responseLocalStorage,T as withRequest,w as withResponse};
|
|
2
2
|
//# sourceMappingURL=valleyed.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/validations/valleyed.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { Pipe, PipeError, v } from 'valleyed'\n\nimport { Instance } from '../instance'\nimport type { IncomingFile, Response, Request, RouteDef, RouteDefToReqRes } from '../server'\n\nconst filePipe = (err?: string) =>\n\tv.array(\n\t\tv.file<IncomingFile>(err).pipe((input) => {\n\t\t\tconst err = `is larger than allowed limit of ${Instance.get().settings.server?.requests.maxFileUploadSizeInMb}mb`\n\t\t\tconst valid = input ? !input.isTruncated : true\n\t\t\tif (valid) return input\n\t\t\tthrow PipeError.root(err, input)\n\t\t}),\n\t)\n\nexport const incomingFile = (err?: string) =>\n\tv.define<unknown, IncomingFile>(\n\t\tv.compile(\n\t\t\tfilePipe(err)\n\t\t\t\t.pipe(v.min(1, 'no file provided'))\n\t\t\t\t.pipe((files) => files[0]),\n\t\t),\n\t\t{ schema: () => ({ type: 'string', format: 'binary' }) },\n\t)\n\nexport const incomingFiles = (err?: string) =>\n\tv.define<unknown, IncomingFile[]>(v.compile(filePipe(err)), {\n\t\tschema: () => ({ type: 'string', format: 'binary' }),\n\t})\n\nexport const requestLocalStorage = new AsyncLocalStorage<Request<RouteDefToReqRes<RouteDef>>>()\nexport const responseLocalStorage = new AsyncLocalStorage<Response<RouteDefToReqRes<RouteDef>>>()\n\nexport const withRequest = <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.
|
|
1
|
+
{"version":3,"sources":["../../../src/validations/valleyed.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { Pipe, PipeError, PipeInput, PipeOutput, v } from 'valleyed'\n\nimport { Instance } from '../instance'\nimport type { IncomingFile, Response, Request, RouteDef, RouteDefToReqRes } from '../server'\n\nconst filePipe = (err?: string) =>\n\tv.array(\n\t\tv.file<IncomingFile>(err).pipe((input) => {\n\t\t\tconst err = `is larger than allowed limit of ${Instance.get().settings.server?.requests.maxFileUploadSizeInMb}mb`\n\t\t\tconst valid = input ? !input.isTruncated : true\n\t\t\tif (valid) return input\n\t\t\tthrow PipeError.root(err, input)\n\t\t}),\n\t)\n\nexport const incomingFile = (err?: string) =>\n\tv.define<unknown, IncomingFile>(\n\t\tv.compile(\n\t\t\tfilePipe(err)\n\t\t\t\t.pipe(v.min(1, 'no file provided'))\n\t\t\t\t.pipe((files) => files[0]),\n\t\t),\n\t\t{ schema: () => ({ type: 'string', format: 'binary' }) },\n\t)\n\nexport const incomingFiles = (err?: string) =>\n\tv.define<unknown, IncomingFile[]>(v.compile(filePipe(err)), {\n\t\tschema: () => ({ type: 'string', format: 'binary' }),\n\t})\n\nexport const requestLocalStorage = new AsyncLocalStorage<Request<RouteDefToReqRes<RouteDef>>>()\nexport const responseLocalStorage = new AsyncLocalStorage<Response<RouteDefToReqRes<RouteDef>>>()\n\nexport const withRequest = <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst req = requestLocalStorage.getStore()\n\t\tif (!req) throw new Error('Request not found in context')\n\t\tconst validated = v.validate(fn(req), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n\nexport const withResponse = <T extends Pipe<any, any>>(fn: (req: Response<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst res = responseLocalStorage.getStore()\n\t\tif (!res) throw new Error('Response not found in context')\n\t\tconst validated = v.validate(fn(res), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n"],"mappings":"AAAA,OAAS,qBAAAA,MAAyB,mBAElC,OAAe,aAAAC,EAAkC,KAAAC,MAAS,WAE1D,OAAS,YAAAC,MAAgB,cAGzB,MAAMC,EAAYC,GACjBH,EAAE,MACDA,EAAE,KAAmBG,CAAG,EAAE,KAAMC,GAAU,CACzC,MAAMD,EAAM,mCAAmCF,EAAS,IAAI,EAAE,SAAS,QAAQ,SAAS,qBAAqB,KAE7G,GADcG,EAAQ,CAACA,EAAM,YAAc,GAChC,OAAOA,EAClB,MAAML,EAAU,KAAKI,EAAKC,CAAK,CAChC,CAAC,CACF,EAEYC,EAAgBF,GAC5BH,EAAE,OACDA,EAAE,QACDE,EAASC,CAAG,EACV,KAAKH,EAAE,IAAI,EAAG,kBAAkB,CAAC,EACjC,KAAMM,GAAUA,EAAM,CAAC,CAAC,CAC3B,EACA,CAAE,OAAQ,KAAO,CAAE,KAAM,SAAU,OAAQ,QAAS,EAAG,CACxD,EAEYC,EAAiBJ,GAC7BH,EAAE,OAAgCA,EAAE,QAAQE,EAASC,CAAG,CAAC,EAAG,CAC3D,OAAQ,KAAO,CAAE,KAAM,SAAU,OAAQ,QAAS,EACnD,CAAC,EAEWK,EAAsB,IAAIV,EAC1BW,EAAuB,IAAIX,EAE3BY,EAAyCC,GACrDX,EAAE,OAAqCI,GAAU,CAChD,MAAMQ,EAAMJ,EAAoB,SAAS,EACzC,GAAI,CAACI,EAAK,MAAM,IAAI,MAAM,8BAA8B,EACxD,MAAMC,EAAYb,EAAE,SAASW,EAAGC,CAAG,EAAGR,CAAK,EAC3C,OAAOS,EAAU,MAAQA,EAAU,MAAQA,EAAU,KACtD,CAAC,EAEWC,EAA0CH,GACtDX,EAAE,OAAqCI,GAAU,CAChD,MAAMW,EAAMN,EAAqB,SAAS,EAC1C,GAAI,CAACM,EAAK,MAAM,IAAI,MAAM,+BAA+B,EACzD,MAAMF,EAAYb,EAAE,SAASW,EAAGI,CAAG,EAAGX,CAAK,EAC3C,OAAOS,EAAU,MAAQA,EAAU,MAAQA,EAAU,KACtD,CAAC","names":["AsyncLocalStorage","PipeError","v","Instance","filePipe","err","input","incomingFile","files","incomingFiles","requestLocalStorage","responseLocalStorage","withRequest","fn","req","validated","withResponse","res"]}
|
|
@@ -20,15 +20,17 @@ const incomingFiles = (err) => v.define(v.compile(filePipe(err)), {
|
|
|
20
20
|
});
|
|
21
21
|
const requestLocalStorage = new AsyncLocalStorage();
|
|
22
22
|
const responseLocalStorage = new AsyncLocalStorage();
|
|
23
|
-
const withRequest = (fn) => v.
|
|
23
|
+
const withRequest = (fn) => v.define((input) => {
|
|
24
24
|
const req = requestLocalStorage.getStore();
|
|
25
25
|
if (!req) throw new Error("Request not found in context");
|
|
26
|
-
|
|
26
|
+
const validated = v.validate(fn(req), input);
|
|
27
|
+
return validated.valid ? validated.value : validated.error;
|
|
27
28
|
});
|
|
28
|
-
const withResponse = (fn) => v.
|
|
29
|
+
const withResponse = (fn) => v.define((input) => {
|
|
29
30
|
const res = responseLocalStorage.getStore();
|
|
30
31
|
if (!res) throw new Error("Response not found in context");
|
|
31
|
-
|
|
32
|
+
const validated = v.validate(fn(res), input);
|
|
33
|
+
return validated.valid ? validated.value : validated.error;
|
|
32
34
|
});
|
|
33
35
|
export {
|
|
34
36
|
incomingFile,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/validations/valleyed.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { Pipe, PipeError, v } from 'valleyed'\n\nimport { Instance } from '../instance'\nimport type { IncomingFile, Response, Request, RouteDef, RouteDefToReqRes } from '../server'\n\nconst filePipe = (err?: string) =>\n\tv.array(\n\t\tv.file<IncomingFile>(err).pipe((input) => {\n\t\t\tconst err = `is larger than allowed limit of ${Instance.get().settings.server?.requests.maxFileUploadSizeInMb}mb`\n\t\t\tconst valid = input ? !input.isTruncated : true\n\t\t\tif (valid) return input\n\t\t\tthrow PipeError.root(err, input)\n\t\t}),\n\t)\n\nexport const incomingFile = (err?: string) =>\n\tv.define<unknown, IncomingFile>(\n\t\tv.compile(\n\t\t\tfilePipe(err)\n\t\t\t\t.pipe(v.min(1, 'no file provided'))\n\t\t\t\t.pipe((files) => files[0]),\n\t\t),\n\t\t{ schema: () => ({ type: 'string', format: 'binary' }) },\n\t)\n\nexport const incomingFiles = (err?: string) =>\n\tv.define<unknown, IncomingFile[]>(v.compile(filePipe(err)), {\n\t\tschema: () => ({ type: 'string', format: 'binary' }),\n\t})\n\nexport const requestLocalStorage = new AsyncLocalStorage<Request<RouteDefToReqRes<RouteDef>>>()\nexport const responseLocalStorage = new AsyncLocalStorage<Response<RouteDefToReqRes<RouteDef>>>()\n\nexport const withRequest = <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.
|
|
1
|
+
{"version":3,"sources":["../../../src/validations/valleyed.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { Pipe, PipeError, PipeInput, PipeOutput, v } from 'valleyed'\n\nimport { Instance } from '../instance'\nimport type { IncomingFile, Response, Request, RouteDef, RouteDefToReqRes } from '../server'\n\nconst filePipe = (err?: string) =>\n\tv.array(\n\t\tv.file<IncomingFile>(err).pipe((input) => {\n\t\t\tconst err = `is larger than allowed limit of ${Instance.get().settings.server?.requests.maxFileUploadSizeInMb}mb`\n\t\t\tconst valid = input ? !input.isTruncated : true\n\t\t\tif (valid) return input\n\t\t\tthrow PipeError.root(err, input)\n\t\t}),\n\t)\n\nexport const incomingFile = (err?: string) =>\n\tv.define<unknown, IncomingFile>(\n\t\tv.compile(\n\t\t\tfilePipe(err)\n\t\t\t\t.pipe(v.min(1, 'no file provided'))\n\t\t\t\t.pipe((files) => files[0]),\n\t\t),\n\t\t{ schema: () => ({ type: 'string', format: 'binary' }) },\n\t)\n\nexport const incomingFiles = (err?: string) =>\n\tv.define<unknown, IncomingFile[]>(v.compile(filePipe(err)), {\n\t\tschema: () => ({ type: 'string', format: 'binary' }),\n\t})\n\nexport const requestLocalStorage = new AsyncLocalStorage<Request<RouteDefToReqRes<RouteDef>>>()\nexport const responseLocalStorage = new AsyncLocalStorage<Response<RouteDefToReqRes<RouteDef>>>()\n\nexport const withRequest = <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst req = requestLocalStorage.getStore()\n\t\tif (!req) throw new Error('Request not found in context')\n\t\tconst validated = v.validate(fn(req), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n\nexport const withResponse = <T extends Pipe<any, any>>(fn: (req: Response<RouteDefToReqRes<RouteDef>>) => T) =>\n\tv.define<PipeInput<T>, PipeOutput<T>>((input) => {\n\t\tconst res = responseLocalStorage.getStore()\n\t\tif (!res) throw new Error('Response not found in context')\n\t\tconst validated = v.validate(fn(res), input)\n\t\treturn validated.valid ? validated.value : validated.error\n\t})\n"],"mappings":"AAAA,SAAS,yBAAyB;AAElC,SAAe,WAAkC,SAAS;AAE1D,SAAS,gBAAgB;AAGzB,MAAM,WAAW,CAAC,QACjB,EAAE;AAAA,EACD,EAAE,KAAmB,GAAG,EAAE,KAAK,CAAC,UAAU;AACzC,UAAMA,OAAM,mCAAmC,SAAS,IAAI,EAAE,SAAS,QAAQ,SAAS,qBAAqB;AAC7G,UAAM,QAAQ,QAAQ,CAAC,MAAM,cAAc;AAC3C,QAAI,MAAO,QAAO;AAClB,UAAM,UAAU,KAAKA,MAAK,KAAK;AAAA,EAChC,CAAC;AACF;AAEM,MAAM,eAAe,CAAC,QAC5B,EAAE;AAAA,EACD,EAAE;AAAA,IACD,SAAS,GAAG,EACV,KAAK,EAAE,IAAI,GAAG,kBAAkB,CAAC,EACjC,KAAK,CAAC,UAAU,MAAM,CAAC,CAAC;AAAA,EAC3B;AAAA,EACA,EAAE,QAAQ,OAAO,EAAE,MAAM,UAAU,QAAQ,SAAS,GAAG;AACxD;AAEM,MAAM,gBAAgB,CAAC,QAC7B,EAAE,OAAgC,EAAE,QAAQ,SAAS,GAAG,CAAC,GAAG;AAAA,EAC3D,QAAQ,OAAO,EAAE,MAAM,UAAU,QAAQ,SAAS;AACnD,CAAC;AAEK,MAAM,sBAAsB,IAAI,kBAAuD;AACvF,MAAM,uBAAuB,IAAI,kBAAwD;AAEzF,MAAM,cAAc,CAA2B,OACrD,EAAE,OAAoC,CAAC,UAAU;AAChD,QAAM,MAAM,oBAAoB,SAAS;AACzC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,8BAA8B;AACxD,QAAM,YAAY,EAAE,SAAS,GAAG,GAAG,GAAG,KAAK;AAC3C,SAAO,UAAU,QAAQ,UAAU,QAAQ,UAAU;AACtD,CAAC;AAEK,MAAM,eAAe,CAA2B,OACtD,EAAE,OAAoC,CAAC,UAAU;AAChD,QAAM,MAAM,qBAAqB,SAAS;AAC1C,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,+BAA+B;AACzD,QAAM,YAAY,EAAE,SAAS,GAAG,GAAG,GAAG,KAAK;AAC3C,SAAO,UAAU,QAAQ,UAAU,QAAQ,UAAU;AACtD,CAAC;","names":["err"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Pipe, PipeError, PipeOutput } from 'valleyed';
|
|
1
|
+
import { Pipe, PipeInput, PipeOutput, PipeError } from 'valleyed';
|
|
3
2
|
export * from 'valleyed';
|
|
4
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
4
|
import { I as IncomingFile, a as Request, b as Response, c as RouteDefToReqRes, d as RouteDef } from '../requests-DBqR41Uw.js';
|
|
@@ -56,8 +55,8 @@ declare const responseLocalStorage: AsyncLocalStorage<Response<{
|
|
|
56
55
|
[x: string]: unknown;
|
|
57
56
|
};
|
|
58
57
|
}>>;
|
|
59
|
-
declare const withRequest: <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) => Pipe<
|
|
60
|
-
declare const withResponse: <T extends Pipe<any, any>>(fn: (req: Response<RouteDefToReqRes<RouteDef>>) => T) => Pipe<
|
|
58
|
+
declare const withRequest: <T extends Pipe<any, any>>(fn: (req: Request<RouteDefToReqRes<RouteDef>>) => T) => Pipe<PipeInput<T>, PipeOutput<T>>;
|
|
59
|
+
declare const withResponse: <T extends Pipe<any, any>>(fn: (req: Response<RouteDefToReqRes<RouteDef>>) => T) => Pipe<PipeInput<T>, PipeOutput<T>>;
|
|
61
60
|
|
|
62
61
|
declare const valleyed_incomingFile: typeof incomingFile;
|
|
63
62
|
declare const valleyed_incomingFiles: typeof incomingFiles;
|
|
@@ -20,15 +20,17 @@ const incomingFiles = (err) => v.define(v.compile(filePipe(err)), {
|
|
|
20
20
|
});
|
|
21
21
|
const requestLocalStorage = new AsyncLocalStorage();
|
|
22
22
|
const responseLocalStorage = new AsyncLocalStorage();
|
|
23
|
-
const withRequest = (fn) => v.
|
|
23
|
+
const withRequest = (fn) => v.define((input) => {
|
|
24
24
|
const req = requestLocalStorage.getStore();
|
|
25
25
|
if (!req) throw new Error("Request not found in context");
|
|
26
|
-
|
|
26
|
+
const validated = v.validate(fn(req), input);
|
|
27
|
+
return validated.valid ? validated.value : validated.error;
|
|
27
28
|
});
|
|
28
|
-
const withResponse = (fn) => v.
|
|
29
|
+
const withResponse = (fn) => v.define((input) => {
|
|
29
30
|
const res = responseLocalStorage.getStore();
|
|
30
31
|
if (!res) throw new Error("Response not found in context");
|
|
31
|
-
|
|
32
|
+
const validated = v.validate(fn(res), input);
|
|
33
|
+
return validated.valid ? validated.value : validated.error;
|
|
32
34
|
});
|
|
33
35
|
export {
|
|
34
36
|
incomingFile,
|