@bepalo/spine 2.7.19 → 2.8.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/middlewares.d.ts +30 -24
- package/dist/cjs/middlewares.d.ts.map +1 -1
- package/dist/cjs/middlewares.js +126 -76
- package/dist/cjs/middlewares.js.map +1 -1
- package/dist/middlewares.d.ts +30 -24
- package/dist/middlewares.d.ts.map +1 -1
- package/dist/middlewares.js +126 -76
- package/dist/middlewares.js.map +1 -1
- package/package.json +5 -2
|
@@ -202,17 +202,17 @@ export type ValidatorFn<Target, ExtendContext extends Record<string, unknown> =
|
|
|
202
202
|
};
|
|
203
203
|
export type ValidatorFnIt<Target, ExtendContext extends Record<string, unknown> = {}> = Type<any, any> & {
|
|
204
204
|
(target: Target): ValidatorReturn<Target>;
|
|
205
|
+
(target: Target, index: number): ValidatorReturn<Target>;
|
|
205
206
|
(this: Context<ExtendContext>, target: Target): ValidatorReturn<Target>;
|
|
206
|
-
(
|
|
207
|
+
(this: Context<ExtendContext>, target: Target, index: number): ValidatorReturn<Target>;
|
|
207
208
|
};
|
|
208
209
|
export type PropValidator<Target, ExtendContext extends Record<string, unknown> = {}> = {
|
|
209
210
|
(target: Target): ValidatorReturn<Target>;
|
|
210
211
|
(this: Context<ExtendContext>, target: Target): ValidatorReturn<Target>;
|
|
211
212
|
};
|
|
212
213
|
export type PropValidatorIt<Target, ExtendContext extends Record<string, unknown> = {}> = {
|
|
213
|
-
(target: Target): ValidatorReturn<Target>;
|
|
214
|
-
(this: Context<ExtendContext>, target: Target): ValidatorReturn<Target>;
|
|
215
|
-
(target: Target, ctx: Context<ExtendContext>, index: number): ValidatorReturn<Target>;
|
|
214
|
+
(target: Target, index: number): ValidatorReturn<Target>;
|
|
215
|
+
(this: Context<ExtendContext>, target: Target, index: number): ValidatorReturn<Target>;
|
|
216
216
|
};
|
|
217
217
|
export type Validator<Target, ExtendContext extends Record<string, unknown> = {}> = ValidatorFn<Target, ExtendContext> | (Target extends Record<string, unknown> ? {
|
|
218
218
|
[K in keyof Target]: PropValidator<Target[K], ExtendContext>;
|
|
@@ -229,6 +229,7 @@ export type ValidateCookieParser<ExtendContext extends Record<string, unknown> =
|
|
|
229
229
|
export type ValidateBodyParser<ExtendContext extends Record<string, unknown> = {}> = {
|
|
230
230
|
(ctx: Context<CTBody & ExtendContext>): Promise<void> | void;
|
|
231
231
|
};
|
|
232
|
+
export type ValidatorStrangeReturnType = Error | HttpError | unknown;
|
|
232
233
|
/**
|
|
233
234
|
* Options type for validator middleware function.
|
|
234
235
|
*/
|
|
@@ -256,36 +257,36 @@ export interface ValidateOptions<ExtendContext extends ({
|
|
|
256
257
|
})) | Record<string, unknown> = {}> {
|
|
257
258
|
responseType?: "text" | "status" | "json";
|
|
258
259
|
errors?: Array<CustomErrorType>;
|
|
259
|
-
|
|
260
|
+
paramsMutation?: boolean;
|
|
260
261
|
params?: Validator<Record<string, string>, ExtendContext>;
|
|
261
262
|
paramsErrors?: Array<CustomErrorType>;
|
|
262
263
|
strangeParams?: boolean | {
|
|
263
|
-
<Target extends Record<string, unknown
|
|
264
|
+
<Target extends Record<string, unknown> = {}>(key: string, target: Target): ValidatorStrangeReturnType;
|
|
264
265
|
};
|
|
265
266
|
queryParse?: boolean | ValidateQueryParser<ExtendContext>;
|
|
266
|
-
|
|
267
|
+
queryMutation?: boolean;
|
|
267
268
|
query?: Validator<Record<string, string>, ExtendContext>;
|
|
268
269
|
queryErrors?: Array<CustomErrorType>;
|
|
269
270
|
strangeQuery?: boolean | {
|
|
270
|
-
<Target extends Record<string, unknown
|
|
271
|
+
<Target extends Record<string, unknown> = {}>(key: string, target: Target): ValidatorStrangeReturnType;
|
|
271
272
|
};
|
|
272
273
|
cookieParse?: boolean | ValidateCookieParser<ExtendContext>;
|
|
273
|
-
|
|
274
|
+
cookieMutation?: boolean;
|
|
274
275
|
cookie?: Validator<Record<string, string>, ExtendContext>;
|
|
275
276
|
cookieErrors?: Array<CustomErrorType>;
|
|
276
277
|
strangeCookie?: boolean | {
|
|
277
|
-
<Target extends Record<string, unknown
|
|
278
|
+
<Target extends Record<string, unknown> = {}>(key: string, target: Target): ValidatorStrangeReturnType;
|
|
278
279
|
};
|
|
279
280
|
bodyParseOptions?: ParseBodyOptions;
|
|
280
281
|
bodyParse?: boolean | ValidateBodyParser<ExtendContext>;
|
|
281
|
-
|
|
282
|
-
body?:
|
|
282
|
+
bodyMutation?: boolean;
|
|
283
|
+
body?: Validator<ParsedBody, ExtendContext> | Array<ValidatorIt<ParsedBody, ExtendContext>>;
|
|
283
284
|
bodyErrors?: Array<CustomErrorType>;
|
|
284
285
|
strangeBody?: boolean | {
|
|
285
|
-
<Target extends Record<string, unknown
|
|
286
|
+
<Target extends Record<string, unknown> = {}>(key: string, target: Target, index?: number): ValidatorStrangeReturnType;
|
|
286
287
|
};
|
|
287
288
|
strange?: boolean | {
|
|
288
|
-
<Target extends Record<string, unknown
|
|
289
|
+
<Target extends Record<string, unknown> = {}>(key: string, target: Target): ValidatorStrangeReturnType;
|
|
289
290
|
};
|
|
290
291
|
breakPipeline?: boolean;
|
|
291
292
|
}
|
|
@@ -305,20 +306,25 @@ export interface ValidateOptions<ExtendContext extends ({
|
|
|
305
306
|
* @param {ValidatorFnIt<ParsedBody,ExtendContext>|Array<ValidatorIt<ParsedBody,ExtendContext>>} [config.body] Body validator
|
|
306
307
|
* @param {CustomErrorType} [config.bodyErrors] Body validator's expected error instance types other than Error derivatives
|
|
307
308
|
* @param {Array<CustomErrorType>} [config.errors] All validator's expected error instance types other than Error derivatives. Can be overridden.
|
|
308
|
-
* @param {boolean} [config.
|
|
309
|
-
* @param {boolean} [config.
|
|
310
|
-
* @param {boolean} [config.
|
|
311
|
-
* @param {boolean} [config.
|
|
312
|
-
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeParams] Handle strange or unexpected properties
|
|
313
|
-
*
|
|
314
|
-
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.
|
|
315
|
-
*
|
|
316
|
-
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.
|
|
309
|
+
* @param {boolean} [config.paramsMutation] Modify object with validated return value of the params validator function
|
|
310
|
+
* @param {boolean} [config.queryMutation] Modify object with validated return value of the query validator function
|
|
311
|
+
* @param {boolean} [config.cookieMutation] Modify object with validated return value of the cookie validator function
|
|
312
|
+
* @param {boolean} [config.bodyMutation] Modify object with validated return value of the body validator function
|
|
313
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeParams] Handle strange or unexpected properties.
|
|
314
|
+
* - If false excludes strange properties from the mutated object.
|
|
315
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeQuery] Handle strange or unexpected properties.
|
|
316
|
+
* - If false excludes strange properties from the mutated object.
|
|
317
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeCookie] Handle strange or unexpected properties.
|
|
318
|
+
* - If false excludes strange properties from the mutated object.
|
|
319
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeBody] Handle strange or unexpected properties.
|
|
320
|
+
* - If false excludes strange properties from the mutated object.
|
|
321
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strange] A default common option to handle strange or unexpected properties.
|
|
322
|
+
* - If false excludes strange properties from the mutated object.
|
|
317
323
|
* @param {"status"|"text"|"json"} [config.responseType="text"] Response type.
|
|
318
324
|
* - Note: 'status' type will omit content
|
|
319
325
|
* @param {boolean} [config.breakPipeline=false] If true, returns Break_Pipeline
|
|
320
326
|
* @returns {HandlerReturn}
|
|
321
327
|
*/
|
|
322
|
-
export declare const validate: <ExtendContext extends Record<string, unknown> = {}, Options extends ValidateOptions<ExtendContext> = ValidateOptions<ExtendContext>>({ responseType, errors,
|
|
328
|
+
export declare const validate: <ExtendContext extends Record<string, unknown> = {}, Options extends ValidateOptions<ExtendContext> = ValidateOptions<ExtendContext>>({ responseType, errors, paramsMutation, params: paramsValidator, paramsErrors, strangeParams, queryParse, queryMutation, query: queryValidator, queryErrors, strangeQuery, cookieParse, cookieMutation, cookie: cookieValidator, cookieErrors, strangeCookie, bodyParse, bodyParseOptions, bodyMutation, body: bodyValidator, bodyErrors, strangeBody, strange, breakPipeline, }: Options) => Handler<ExtendContext & CTFrom<ExtendContext, Options>>;
|
|
323
329
|
export {};
|
|
324
330
|
//# sourceMappingURL=middlewares.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewares.d.ts","sourceRoot":"","sources":["../../src/middlewares.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,MAAM,EACN,QAAQ,EAER,OAAO,EACP,gBAAgB,EAEhB,UAAU,EAEX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAA8B,SAAS,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,OAAO,EACP,OAAO,EACP,UAAU,EACV,aAAa,EACb,cAAc,EACd,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,gCAAgC,EAChC,uBAAuB,EACvB,2BAA2B,EAC3B,uCAAuC,EACvC,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GACrB,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,EAClD,SAAS;IACT,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,aAAa,CAUxB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAC1B,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,EAClD,SAAS;IACT,cAAc,CAAC,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QACE,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,EAC1C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GACb,0BAA0B,CAAC;KAC/B,CAAC;IAEN,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,QAAQ,GACnB,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,EAClD,OAAO,SAAS,eAAe,CAAC,aAAa,CAAC,GAC5C,eAAe,CAAC,aAAa,CAAC,EAChC,kXA8BC,OAAO,KAAG,OAAO,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CA2uBlE,CAAC"}
|
package/dist/cjs/middlewares.js
CHANGED
|
@@ -386,21 +386,26 @@ exports.cors = cors;
|
|
|
386
386
|
* @param {ValidatorFnIt<ParsedBody,ExtendContext>|Array<ValidatorIt<ParsedBody,ExtendContext>>} [config.body] Body validator
|
|
387
387
|
* @param {CustomErrorType} [config.bodyErrors] Body validator's expected error instance types other than Error derivatives
|
|
388
388
|
* @param {Array<CustomErrorType>} [config.errors] All validator's expected error instance types other than Error derivatives. Can be overridden.
|
|
389
|
-
* @param {boolean} [config.
|
|
390
|
-
* @param {boolean} [config.
|
|
391
|
-
* @param {boolean} [config.
|
|
392
|
-
* @param {boolean} [config.
|
|
393
|
-
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeParams] Handle strange or unexpected properties
|
|
394
|
-
*
|
|
395
|
-
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.
|
|
396
|
-
*
|
|
397
|
-
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.
|
|
389
|
+
* @param {boolean} [config.paramsMutation] Modify object with validated return value of the params validator function
|
|
390
|
+
* @param {boolean} [config.queryMutation] Modify object with validated return value of the query validator function
|
|
391
|
+
* @param {boolean} [config.cookieMutation] Modify object with validated return value of the cookie validator function
|
|
392
|
+
* @param {boolean} [config.bodyMutation] Modify object with validated return value of the body validator function
|
|
393
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeParams] Handle strange or unexpected properties.
|
|
394
|
+
* - If false excludes strange properties from the mutated object.
|
|
395
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeQuery] Handle strange or unexpected properties.
|
|
396
|
+
* - If false excludes strange properties from the mutated object.
|
|
397
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeCookie] Handle strange or unexpected properties.
|
|
398
|
+
* - If false excludes strange properties from the mutated object.
|
|
399
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strangeBody] Handle strange or unexpected properties.
|
|
400
|
+
* - If false excludes strange properties from the mutated object.
|
|
401
|
+
* @param {boolean|{<Target extends Record<string, unknown>>(target: Target,key: string,):void|any;}} [config.strange] A default common option to handle strange or unexpected properties.
|
|
402
|
+
* - If false excludes strange properties from the mutated object.
|
|
398
403
|
* @param {"status"|"text"|"json"} [config.responseType="text"] Response type.
|
|
399
404
|
* - Note: 'status' type will omit content
|
|
400
405
|
* @param {boolean} [config.breakPipeline=false] If true, returns Break_Pipeline
|
|
401
406
|
* @returns {HandlerReturn}
|
|
402
407
|
*/
|
|
403
|
-
const validate = ({ responseType = "text", errors,
|
|
408
|
+
const validate = ({ responseType = "text", errors, paramsMutation = false, params: paramsValidator, paramsErrors, strangeParams, queryParse, queryMutation = false, query: queryValidator, queryErrors, strangeQuery, cookieParse, cookieMutation = false, cookie: cookieValidator, cookieErrors, strangeCookie, bodyParse, bodyParseOptions, bodyMutation = false, body: bodyValidator, bodyErrors, strangeBody, strange, breakPipeline = false, }) => {
|
|
404
409
|
paramsErrors = paramsErrors !== null && paramsErrors !== void 0 ? paramsErrors : errors;
|
|
405
410
|
queryErrors = queryErrors !== null && queryErrors !== void 0 ? queryErrors : errors;
|
|
406
411
|
cookieErrors = cookieErrors !== null && cookieErrors !== void 0 ? cookieErrors : errors;
|
|
@@ -496,10 +501,10 @@ const validate = ({ responseType = "text", errors, paramsReassign = false, param
|
|
|
496
501
|
throw new TypeError("Validator cookieParse type must be either boolean, undefined or a function");
|
|
497
502
|
}
|
|
498
503
|
// Validate body parser
|
|
499
|
-
if (
|
|
500
|
-
typeof
|
|
501
|
-
typeof
|
|
502
|
-
throw new TypeError("Validator
|
|
504
|
+
if (bodyParse != undefined &&
|
|
505
|
+
typeof bodyParse !== "boolean" &&
|
|
506
|
+
typeof bodyParse !== "function") {
|
|
507
|
+
throw new TypeError("Validator bodyParse type must be either boolean, undefined or a function");
|
|
503
508
|
}
|
|
504
509
|
const respond = responseType === "json"
|
|
505
510
|
? (code, content, key, tag, init) => (0, helpers_ts_1.json)({ [key]: `${tag}: ${content}`, tag }, Object.assign(Object.assign({}, init), { status: code }))
|
|
@@ -622,49 +627,55 @@ const validate = ({ responseType = "text", errors, paramsReassign = false, param
|
|
|
622
627
|
const params = ctx.params;
|
|
623
628
|
// Validate Params
|
|
624
629
|
if (paramsValidatorIsFunction) {
|
|
625
|
-
const result = paramsValidator.
|
|
626
|
-
? paramsValidator.
|
|
630
|
+
const result = paramsValidator.bind
|
|
631
|
+
? paramsValidator.bind(ctx)(params)
|
|
627
632
|
: paramsValidator(params);
|
|
628
633
|
if (result instanceof Error) {
|
|
629
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "
|
|
634
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "params-validator");
|
|
630
635
|
}
|
|
631
636
|
else if (paramsErrors && errorMatches(result, paramsErrors)) {
|
|
632
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "params");
|
|
637
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "params-validator");
|
|
633
638
|
}
|
|
634
639
|
else if (result instanceof Response ||
|
|
635
640
|
result === types_ts_1.Break_Pipe ||
|
|
636
641
|
result === types_ts_1.Break_Pipeline) {
|
|
637
642
|
return result;
|
|
638
643
|
}
|
|
639
|
-
else if (
|
|
644
|
+
else if (paramsMutation) {
|
|
640
645
|
ctx.params = result;
|
|
641
646
|
}
|
|
642
647
|
}
|
|
643
|
-
else if (
|
|
648
|
+
else if (paramsValidator) {
|
|
649
|
+
const keys = Object.keys(paramsValidator);
|
|
644
650
|
for (const key of Object.keys(params)) {
|
|
651
|
+
if (!(key in paramsValidator)) {
|
|
652
|
+
keys.push(key);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
for (const key of keys) {
|
|
645
656
|
const validator = paramsValidator[key];
|
|
646
657
|
if (validator == null && !strangeParams) {
|
|
647
658
|
continue;
|
|
648
659
|
}
|
|
649
660
|
const result = validator == null
|
|
650
661
|
? typeof strangeParams === "function"
|
|
651
|
-
? strangeParams(
|
|
662
|
+
? strangeParams(key, params)
|
|
652
663
|
: params[key]
|
|
653
|
-
: validator.
|
|
654
|
-
? validator.
|
|
664
|
+
: validator.bind
|
|
665
|
+
? validator.bind(ctx)(params[key])
|
|
655
666
|
: validator(params[key]);
|
|
656
667
|
if (result instanceof Error) {
|
|
657
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "params");
|
|
668
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "params-validator");
|
|
658
669
|
}
|
|
659
670
|
else if (paramsErrors && errorMatches(result, paramsErrors)) {
|
|
660
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "params");
|
|
671
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "params-validator");
|
|
661
672
|
}
|
|
662
673
|
else if (result instanceof Response ||
|
|
663
674
|
result === types_ts_1.Break_Pipe ||
|
|
664
675
|
result === types_ts_1.Break_Pipeline) {
|
|
665
676
|
return result;
|
|
666
677
|
}
|
|
667
|
-
else if (
|
|
678
|
+
else if (paramsMutation) {
|
|
668
679
|
params[key] = result;
|
|
669
680
|
}
|
|
670
681
|
}
|
|
@@ -676,49 +687,55 @@ const validate = ({ responseType = "text", errors, paramsReassign = false, param
|
|
|
676
687
|
const query = ctx.query;
|
|
677
688
|
// Validate Query
|
|
678
689
|
if (queryValidatorIsFunction) {
|
|
679
|
-
const result = queryValidator.
|
|
680
|
-
? queryValidator.
|
|
690
|
+
const result = queryValidator.bind
|
|
691
|
+
? queryValidator.bind(ctx)(query)
|
|
681
692
|
: queryValidator(query);
|
|
682
693
|
if (result instanceof Error) {
|
|
683
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "query");
|
|
694
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "query-validator");
|
|
684
695
|
}
|
|
685
696
|
else if (queryErrors && errorMatches(result, queryErrors)) {
|
|
686
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "query");
|
|
697
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "query-validator");
|
|
687
698
|
}
|
|
688
699
|
else if (result instanceof Response ||
|
|
689
700
|
result === types_ts_1.Break_Pipe ||
|
|
690
701
|
result === types_ts_1.Break_Pipeline) {
|
|
691
702
|
return result;
|
|
692
703
|
}
|
|
693
|
-
else if (
|
|
704
|
+
else if (queryMutation) {
|
|
694
705
|
ctx.query = result;
|
|
695
706
|
}
|
|
696
707
|
}
|
|
697
|
-
else if (
|
|
708
|
+
else if (queryValidator) {
|
|
709
|
+
const keys = Object.keys(queryValidator);
|
|
698
710
|
for (const key of Object.keys(query)) {
|
|
711
|
+
if (!(key in queryValidator)) {
|
|
712
|
+
keys.push(key);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
for (const key of keys) {
|
|
699
716
|
const validator = queryValidator[key];
|
|
700
717
|
if (validator == null && !strangeQuery) {
|
|
701
718
|
continue;
|
|
702
719
|
}
|
|
703
720
|
const result = validator == null
|
|
704
721
|
? typeof strangeQuery === "function"
|
|
705
|
-
? strangeQuery(
|
|
722
|
+
? strangeQuery(key, query)
|
|
706
723
|
: query[key]
|
|
707
|
-
: validator.
|
|
708
|
-
? validator.
|
|
724
|
+
: validator.bind
|
|
725
|
+
? validator.bind(ctx)(query[key])
|
|
709
726
|
: validator(query[key]);
|
|
710
727
|
if (result instanceof Error) {
|
|
711
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "query");
|
|
728
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "query-validator");
|
|
712
729
|
}
|
|
713
730
|
else if (queryErrors && errorMatches(result, queryErrors)) {
|
|
714
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "query");
|
|
731
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "query-validator");
|
|
715
732
|
}
|
|
716
733
|
else if (result instanceof Response ||
|
|
717
734
|
result === types_ts_1.Break_Pipe ||
|
|
718
735
|
result === types_ts_1.Break_Pipeline) {
|
|
719
736
|
return result;
|
|
720
737
|
}
|
|
721
|
-
else if (
|
|
738
|
+
else if (queryMutation) {
|
|
722
739
|
query[key] = result;
|
|
723
740
|
}
|
|
724
741
|
}
|
|
@@ -730,49 +747,55 @@ const validate = ({ responseType = "text", errors, paramsReassign = false, param
|
|
|
730
747
|
const cookie = ctx.cookie;
|
|
731
748
|
// Validate Cookie
|
|
732
749
|
if (cookieValidatorIsFunction) {
|
|
733
|
-
const result = cookieValidator.
|
|
734
|
-
? cookieValidator.
|
|
750
|
+
const result = cookieValidator.bind
|
|
751
|
+
? cookieValidator.bind(ctx)(cookie)
|
|
735
752
|
: cookieValidator(cookie);
|
|
736
753
|
if (result instanceof Error) {
|
|
737
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "cookie");
|
|
754
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "cookie-validator");
|
|
738
755
|
}
|
|
739
756
|
else if (cookieErrors && errorMatches(result, cookieErrors)) {
|
|
740
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "cookie");
|
|
757
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "cookie-validator");
|
|
741
758
|
}
|
|
742
759
|
else if (result instanceof Response ||
|
|
743
760
|
result === types_ts_1.Break_Pipe ||
|
|
744
761
|
result === types_ts_1.Break_Pipeline) {
|
|
745
762
|
return result;
|
|
746
763
|
}
|
|
747
|
-
else if (
|
|
764
|
+
else if (cookieMutation) {
|
|
748
765
|
ctx.cookie = result;
|
|
749
766
|
}
|
|
750
767
|
}
|
|
751
|
-
else if (
|
|
768
|
+
else if (cookieValidator) {
|
|
769
|
+
const keys = Object.keys(cookieValidator);
|
|
752
770
|
for (const key of Object.keys(cookie)) {
|
|
771
|
+
if (!(key in cookieValidator)) {
|
|
772
|
+
keys.push(key);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
for (const key of keys) {
|
|
753
776
|
const validator = cookieValidator[key];
|
|
754
777
|
if (validator == null && !strangeCookie) {
|
|
755
778
|
continue;
|
|
756
779
|
}
|
|
757
780
|
const result = validator == null
|
|
758
781
|
? typeof strangeCookie === "function"
|
|
759
|
-
? strangeCookie(
|
|
782
|
+
? strangeCookie(key, cookie)
|
|
760
783
|
: cookie[key]
|
|
761
|
-
: validator.
|
|
762
|
-
? validator.
|
|
784
|
+
: validator.bind
|
|
785
|
+
? validator.bind(ctx)(cookie[key])
|
|
763
786
|
: validator(cookie[key]);
|
|
764
787
|
if (result instanceof Error) {
|
|
765
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "cookie");
|
|
788
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "cookie-validator");
|
|
766
789
|
}
|
|
767
790
|
else if (cookieErrors && errorMatches(result, cookieErrors)) {
|
|
768
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "cookie");
|
|
791
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "cookie-validator");
|
|
769
792
|
}
|
|
770
793
|
else if (result instanceof Response ||
|
|
771
794
|
result === types_ts_1.Break_Pipe ||
|
|
772
795
|
result === types_ts_1.Break_Pipeline) {
|
|
773
796
|
return result;
|
|
774
797
|
}
|
|
775
|
-
else if (
|
|
798
|
+
else if (cookieMutation) {
|
|
776
799
|
cookie[key] = result;
|
|
777
800
|
}
|
|
778
801
|
}
|
|
@@ -784,24 +807,33 @@ const validate = ({ responseType = "text", errors, paramsReassign = false, param
|
|
|
784
807
|
const body = ctx.body;
|
|
785
808
|
// Validate Body
|
|
786
809
|
if (bodyValidators) {
|
|
787
|
-
|
|
810
|
+
const bodyIsArray = Array.isArray(body);
|
|
811
|
+
if (bodyValidatorIsArray && !bodyIsArray) {
|
|
812
|
+
return respond(status_ts_1.Status._400_BadRequest, "array body type expected", "error", "body-validator");
|
|
813
|
+
}
|
|
814
|
+
else if (!bodyValidatorIsArray && bodyIsArray) {
|
|
815
|
+
return respond(status_ts_1.Status._400_BadRequest, "object body type expected", "error", "body-validator");
|
|
816
|
+
}
|
|
817
|
+
if (bodyIsArray) {
|
|
788
818
|
for (let i = 0; i < body.length; i++) {
|
|
789
819
|
const validator = bodyValidators[i % bodyValidators.length];
|
|
790
820
|
const activeBody = body[i];
|
|
791
821
|
if (typeof validator === "function") {
|
|
792
|
-
const result = validator.
|
|
822
|
+
const result = validator.bind
|
|
823
|
+
? validator.bind(ctx)(activeBody, i)
|
|
824
|
+
: validator(activeBody, i);
|
|
793
825
|
if (result instanceof Error) {
|
|
794
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body");
|
|
826
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body-validator");
|
|
795
827
|
}
|
|
796
828
|
else if (bodyErrors && errorMatches(result, bodyErrors)) {
|
|
797
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body");
|
|
829
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body-validator");
|
|
798
830
|
}
|
|
799
831
|
else if (result instanceof Response ||
|
|
800
832
|
result === types_ts_1.Break_Pipe ||
|
|
801
833
|
result === types_ts_1.Break_Pipeline) {
|
|
802
834
|
return result;
|
|
803
835
|
}
|
|
804
|
-
else if (
|
|
836
|
+
else if (bodyMutation) {
|
|
805
837
|
body[i] = result;
|
|
806
838
|
}
|
|
807
839
|
}
|
|
@@ -809,36 +841,45 @@ const validate = ({ responseType = "text", errors, paramsReassign = false, param
|
|
|
809
841
|
if (activeBody &&
|
|
810
842
|
typeof activeBody === "object" &&
|
|
811
843
|
!Array.isArray(activeBody)) {
|
|
844
|
+
const keys = Object.keys(validator);
|
|
812
845
|
for (const key of Object.keys(activeBody)) {
|
|
846
|
+
if (!(key in validator)) {
|
|
847
|
+
keys.push(key);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
for (const key of keys) {
|
|
813
851
|
const propValidator = validator[key];
|
|
814
852
|
if (propValidator == null && !strangeBody) {
|
|
853
|
+
if (bodyMutation) {
|
|
854
|
+
delete activeBody[key];
|
|
855
|
+
}
|
|
815
856
|
continue;
|
|
816
857
|
}
|
|
817
858
|
const result = propValidator == null
|
|
818
859
|
? typeof strangeBody === "function"
|
|
819
|
-
? strangeBody(activeBody,
|
|
860
|
+
? strangeBody(key, activeBody, i)
|
|
820
861
|
: activeBody[key]
|
|
821
|
-
: propValidator.
|
|
822
|
-
? propValidator.
|
|
823
|
-
: propValidator(activeBody[key]);
|
|
862
|
+
: propValidator.bind
|
|
863
|
+
? propValidator.bind(ctx)(activeBody[key], i)
|
|
864
|
+
: propValidator(activeBody[key], i);
|
|
824
865
|
if (result instanceof Error) {
|
|
825
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body");
|
|
866
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body-validator");
|
|
826
867
|
}
|
|
827
868
|
else if (bodyErrors && errorMatches(result, bodyErrors)) {
|
|
828
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body");
|
|
869
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body-validator");
|
|
829
870
|
}
|
|
830
871
|
else if (result instanceof Response ||
|
|
831
872
|
result === types_ts_1.Break_Pipe ||
|
|
832
873
|
result === types_ts_1.Break_Pipeline) {
|
|
833
874
|
return result;
|
|
834
875
|
}
|
|
835
|
-
else if (
|
|
876
|
+
else if (bodyMutation) {
|
|
836
877
|
activeBody[key] = result;
|
|
837
878
|
}
|
|
838
879
|
}
|
|
839
880
|
}
|
|
840
881
|
else {
|
|
841
|
-
return respond(status_ts_1.Status._400_BadRequest, `Invalid body type at index ${i}`, "error", "body");
|
|
882
|
+
return respond(status_ts_1.Status._400_BadRequest, `Invalid body type at index ${i}`, "error", "body-validator");
|
|
842
883
|
}
|
|
843
884
|
}
|
|
844
885
|
}
|
|
@@ -846,56 +887,65 @@ const validate = ({ responseType = "text", errors, paramsReassign = false, param
|
|
|
846
887
|
else {
|
|
847
888
|
const validator = bodyValidators[0];
|
|
848
889
|
if (typeof validator === "function") {
|
|
849
|
-
const result = validator.
|
|
850
|
-
? validator.
|
|
890
|
+
const result = validator.bind
|
|
891
|
+
? validator.bind(ctx)(body)
|
|
851
892
|
: validator(body);
|
|
852
893
|
if (result instanceof Error) {
|
|
853
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body");
|
|
894
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body-validator");
|
|
854
895
|
}
|
|
855
896
|
else if (bodyErrors && errorMatches(result, bodyErrors)) {
|
|
856
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body");
|
|
897
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body-validator");
|
|
857
898
|
}
|
|
858
899
|
else if (result instanceof Response ||
|
|
859
900
|
result === types_ts_1.Break_Pipe ||
|
|
860
901
|
result === types_ts_1.Break_Pipeline) {
|
|
861
902
|
return result;
|
|
862
903
|
}
|
|
863
|
-
else if (
|
|
904
|
+
else if (bodyMutation) {
|
|
864
905
|
ctx.body = result;
|
|
865
906
|
}
|
|
866
907
|
}
|
|
867
908
|
else if (validator) {
|
|
868
909
|
if (body && typeof body === "object" && !Array.isArray(body)) {
|
|
910
|
+
const keys = Object.keys(validator);
|
|
869
911
|
for (const key of Object.keys(body)) {
|
|
912
|
+
if (!(key in validator)) {
|
|
913
|
+
keys.push(key);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
for (const key of keys) {
|
|
870
917
|
const propValidator = validator[key];
|
|
871
918
|
if (propValidator == null && !strangeBody) {
|
|
919
|
+
if (bodyMutation) {
|
|
920
|
+
delete body[key];
|
|
921
|
+
}
|
|
872
922
|
continue;
|
|
873
923
|
}
|
|
874
924
|
const result = propValidator == null
|
|
875
925
|
? typeof strangeBody === "function"
|
|
876
|
-
? strangeBody(
|
|
877
|
-
: body
|
|
878
|
-
: propValidator.
|
|
879
|
-
? propValidator.
|
|
926
|
+
? strangeBody(key, body)
|
|
927
|
+
: body[key]
|
|
928
|
+
: propValidator.bind
|
|
929
|
+
? propValidator.bind(ctx)(body[key])
|
|
880
930
|
: propValidator(body[key]);
|
|
881
931
|
if (result instanceof Error) {
|
|
882
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body");
|
|
932
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, result.message, "error", "body-validator");
|
|
883
933
|
}
|
|
884
934
|
else if (bodyErrors && errorMatches(result, bodyErrors)) {
|
|
885
|
-
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body");
|
|
935
|
+
return respond(result.status || status_ts_1.Status._400_BadRequest, String(result), "error", "body-validator");
|
|
886
936
|
}
|
|
887
937
|
else if (result instanceof Response ||
|
|
888
938
|
result === types_ts_1.Break_Pipe ||
|
|
889
939
|
result === types_ts_1.Break_Pipeline) {
|
|
890
940
|
return result;
|
|
891
941
|
}
|
|
892
|
-
else if (
|
|
942
|
+
else if (bodyMutation) {
|
|
893
943
|
body[key] = result;
|
|
894
944
|
}
|
|
895
945
|
}
|
|
896
946
|
}
|
|
897
947
|
else {
|
|
898
|
-
return respond(status_ts_1.Status._400_BadRequest, "Invalid body type", "error", "body");
|
|
948
|
+
return respond(status_ts_1.Status._400_BadRequest, "Invalid body type", "error", "body-validator");
|
|
899
949
|
}
|
|
900
950
|
}
|
|
901
951
|
}
|