valgen 5.1.0 → 5.2.0

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 CHANGED
@@ -1,3 +1,10 @@
1
+ # v5.2.0
2
+ [2024-01-04]
3
+
4
+ ### Changes
5
+
6
+ * Now validator options persist in context ([`418901f`](https://github.com/panates/valgen/commit/418901f74ee266d84e50ee82ba5a7221bd2be627))
7
+
1
8
  # v5.1.0
2
9
  [2023-12-23]
3
10
 
@@ -9,14 +9,7 @@ const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
9
9
  class Context {
10
10
  constructor(options) {
11
11
  this.errors = [];
12
- if (options?.maxErrors != null)
13
- this.maxErrors = options.maxErrors;
14
- if (typeof options?.onFail === 'function')
15
- this.onFail = options.onFail;
16
- if (options?.coerce != null)
17
- this.coerce = options?.coerce;
18
- if (options?.label != null)
19
- this.label = options?.label;
12
+ Object.assign(this, options);
20
13
  }
21
14
  fail(rule, message, value, details) {
22
15
  const issue = (0, omit_undefined_js_1.omitUndefined)({
@@ -6,14 +6,7 @@ const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
6
6
  export class Context {
7
7
  constructor(options) {
8
8
  this.errors = [];
9
- if (options?.maxErrors != null)
10
- this.maxErrors = options.maxErrors;
11
- if (typeof options?.onFail === 'function')
12
- this.onFail = options.onFail;
13
- if (options?.coerce != null)
14
- this.coerce = options?.coerce;
15
- if (options?.label != null)
16
- this.label = options?.label;
9
+ Object.assign(this, options);
17
10
  }
18
11
  fail(rule, message, value, details) {
19
12
  const issue = omitUndefined({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valgen",
3
3
  "description": "Fast runtime type validator, converter and io (encoding/decoding) library",
4
- "version": "5.1.0",
4
+ "version": "5.2.0",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -12,6 +12,7 @@ export declare class Context implements ExecutionOptions {
12
12
  property?: string;
13
13
  index?: number;
14
14
  label?: string;
15
+ [key: string]: any;
15
16
  constructor(options?: ExecutionOptions);
16
17
  fail(rule: Validator, message: string | Error, value: any, details?: Record<string, any>): void;
17
18
  extend(options?: ExecutionOptions): Context;
@@ -19,4 +19,5 @@ export interface ExecutionOptions extends ValidationOptions {
19
19
  coerce?: boolean;
20
20
  maxErrors?: number;
21
21
  label?: string;
22
+ [key: string]: any;
22
23
  }
@@ -15,4 +15,4 @@ export interface Validator<T = any, I = any, O extends ExecutionOptions = Execut
15
15
  }
16
16
  export declare function validator<T, I = T, O extends ExecutionOptions = ExecutionOptions>(fn: ValidateFunction<T, I>, validatorOptions?: ValidationOptions): Validator<T, I, O>;
17
17
  export declare function validator<T, I = T, O extends ExecutionOptions = ExecutionOptions>(id: string, fn: ValidateFunction<T, I>, validatorOptions?: ValidationOptions): Validator<T, I, O>;
18
- export declare function isValidator(x: any): x is Validator<any, any>;
18
+ export declare function isValidator(x: any): x is Validator;
@@ -23,5 +23,5 @@ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(
23
23
  Validator<T4, I4>,
24
24
  Validator<T5, I5>,
25
25
  Validator<T6, I6>,
26
- ...Validator<any, any>[]
26
+ ...Validator[]
27
27
  ], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5, T6, ...any[]], [I1, I2, I3, I4, I5, I5, ...any[]]>;
@@ -3,9 +3,9 @@ import { Validator } from '../core/index.js';
3
3
  *
4
4
  * @validator pipe
5
5
  */
6
- export declare function pipe<T>(...rules: [...Validator<any, any>[], Validator<T, any>]): Validator<T, any, import("../core/types.js").ExecutionOptions>;
6
+ export declare function pipe<T>(...rules: [...Validator[], Validator<T, any>]): Validator<T, any, import("../core/types.js").ExecutionOptions>;
7
7
  /**
8
8
  * Test given value against to all codecs and returns original input
9
9
  * @validator allOf
10
10
  */
11
- export declare function allOf(...rules: Validator<any, any>[]): Validator<any, any, import("../core/types.js").ExecutionOptions>;
11
+ export declare function allOf(...rules: Validator[]): Validator<any, any, import("../core/types.js").ExecutionOptions>;