kanun 0.1.8 → 1.0.2
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/README.md +15 -0
- package/dist/index.cjs +1491 -1227
- package/dist/index.d.ts +281 -103
- package/dist/index.js +1481 -1227
- package/package.json +13 -1
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,100 @@ declare abstract class IRuleContract {
|
|
|
45
45
|
trans(path: string, params?: GenericObject): string;
|
|
46
46
|
}
|
|
47
47
|
//#endregion
|
|
48
|
+
//#region src/Rules/in.d.ts
|
|
49
|
+
declare class In extends BaseRule {
|
|
50
|
+
/**
|
|
51
|
+
* The name of the rule.
|
|
52
|
+
*/
|
|
53
|
+
rule: string;
|
|
54
|
+
/**
|
|
55
|
+
* The accepted values.
|
|
56
|
+
*/
|
|
57
|
+
values: (string | number)[];
|
|
58
|
+
/**
|
|
59
|
+
* Create a new In rule instance.
|
|
60
|
+
*/
|
|
61
|
+
constructor(values: (string | number)[]);
|
|
62
|
+
/**
|
|
63
|
+
* Convert the rule to a validation string.
|
|
64
|
+
*/
|
|
65
|
+
toString(): string;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/Rules/notIn.d.ts
|
|
69
|
+
declare class NotIn extends BaseRule {
|
|
70
|
+
/**
|
|
71
|
+
* The name of the rule.
|
|
72
|
+
*/
|
|
73
|
+
rule: string;
|
|
74
|
+
/**
|
|
75
|
+
* The accepted values.
|
|
76
|
+
*/
|
|
77
|
+
values: (string | number)[];
|
|
78
|
+
/**
|
|
79
|
+
* Create a new NotIn rule instance.
|
|
80
|
+
*/
|
|
81
|
+
constructor(values: (string | number)[]);
|
|
82
|
+
/**
|
|
83
|
+
* Convert the rule to a validation string.
|
|
84
|
+
*/
|
|
85
|
+
toString(): string;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/Rules/regex.d.ts
|
|
89
|
+
declare class Regex extends IRuleContract {
|
|
90
|
+
/**
|
|
91
|
+
* The Regular expression to validate
|
|
92
|
+
*/
|
|
93
|
+
regex: RegExp;
|
|
94
|
+
/**
|
|
95
|
+
* Flag that decides whether the value should match the regular expression or not
|
|
96
|
+
*/
|
|
97
|
+
shouldMatch: boolean;
|
|
98
|
+
constructor(regex: RegExp, shouldMatch?: boolean);
|
|
99
|
+
passes(value: any): boolean;
|
|
100
|
+
getMessage(): string;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/Rules/requiredIf.d.ts
|
|
104
|
+
declare class RequiredIf extends BaseRule {
|
|
105
|
+
/**
|
|
106
|
+
* The condition that validates the attribute
|
|
107
|
+
*/
|
|
108
|
+
condition: boolean | CallableFunction;
|
|
109
|
+
/**
|
|
110
|
+
* Create a new required validation rule based on a condition.
|
|
111
|
+
*/
|
|
112
|
+
constructor(condition: boolean | CallableFunction);
|
|
113
|
+
/**
|
|
114
|
+
* Convert the rule to a validation string.
|
|
115
|
+
*/
|
|
116
|
+
toString(): string;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/Contracts/ValidationRuleName.d.ts
|
|
120
|
+
type ValidationRuleAutocompleteKind = 'plain' | 'paramable';
|
|
121
|
+
interface ValidationRuleAutocompleteMap {}
|
|
122
|
+
/**
|
|
123
|
+
* Backward-compatible alias for older plugin augmentations.
|
|
124
|
+
*/
|
|
125
|
+
interface CustomValidationRuleNameMap {}
|
|
126
|
+
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
|
127
|
+
type PluginValidationRuleNameMap = ValidationRuleAutocompleteMap & CustomValidationRuleNameMap;
|
|
128
|
+
type CustomParamableValidationRuleName = Extract<{ [K in keyof PluginValidationRuleNameMap]: PluginValidationRuleNameMap[K] extends 'paramable' ? K : never }[keyof PluginValidationRuleNameMap], string>;
|
|
129
|
+
type CustomPlainRuleName = Extract<{ [K in keyof PluginValidationRuleNameMap]: PluginValidationRuleNameMap[K] extends 'plain' ? K : never }[keyof PluginValidationRuleNameMap], string>;
|
|
130
|
+
type ParamableValidationRuleName = 'accepted_if' | 'after' | 'after_or_equal' | 'before' | 'before_or_equal' | 'between' | 'date_equals' | 'datetime' | 'declined_if' | 'digits_between' | 'different' | 'exists' | 'ends_with' | 'gt' | 'gte' | 'in' | 'includes' | 'lt' | 'lte' | 'max' | 'min' | 'not_in' | 'not_includes' | 'required_if' | 'required_unless' | 'required_with' | 'required_with_all' | 'required_without' | 'required_without_all' | 'same' | 'size' | 'starts_with' | 'unique' | CustomParamableValidationRuleName;
|
|
131
|
+
type PlainRuleName = 'accepted' | 'alpha' | 'alpha_dash' | 'alpha_num' | 'array' | 'array_unique' | 'bail' | 'boolean' | 'confirmed' | 'date' | 'declined' | 'digits' | 'email' | 'integer' | 'json' | 'not_regex' | 'nullable' | 'numeric' | 'object' | 'present' | 'regex' | 'required' | 'sometimes' | 'string' | 'url' | 'hex' | 'uuid' | CustomPlainRuleName;
|
|
132
|
+
type ValidationRuleName = ParamableValidationRuleName | PlainRuleName;
|
|
133
|
+
type MethodRules = Regex | In | NotIn | RequiredIf;
|
|
134
|
+
type ParamableRuleString = `${ParamableValidationRuleName}:${string}`;
|
|
135
|
+
type ValidationRuleString = LiteralUnion<ValidationRuleName | ParamableRuleString>;
|
|
136
|
+
/**
|
|
137
|
+
* Single rule value (supports autocomplete + arbitrary strings + RuleContract instances)
|
|
138
|
+
*/
|
|
139
|
+
type ValidationRuleEntry = ValidationRuleString | IRuleContract | MethodRules;
|
|
140
|
+
type ValidationRuleSet = ValidationRuleEntry | readonly ValidationRuleEntry[] | LiteralUnion<`${ValidationRuleName}${string & `|${string}`}` | `${ParamableRuleString}${string & `|${string}`}`>;
|
|
141
|
+
//#endregion
|
|
48
142
|
//#region src/payloads/replaceAttributePayload.d.ts
|
|
49
143
|
declare class replaceAttributePayload {
|
|
50
144
|
/**
|
|
@@ -71,7 +165,7 @@ declare class replaceAttributePayload {
|
|
|
71
165
|
}
|
|
72
166
|
//#endregion
|
|
73
167
|
//#region src/Contracts/BaseContract.d.ts
|
|
74
|
-
type InitialRule =
|
|
168
|
+
type InitialRule = ValidationRuleEntry | ValidationCallback | BaseRule;
|
|
75
169
|
type TRule = string | IRuleContract;
|
|
76
170
|
type NestedStringMap = {
|
|
77
171
|
[key: string]: string | NestedStringMap;
|
|
@@ -279,6 +373,33 @@ declare class ErrorBag {
|
|
|
279
373
|
clone(): ErrorBag;
|
|
280
374
|
}
|
|
281
375
|
//#endregion
|
|
376
|
+
//#region src/Rules/registerRule.d.ts
|
|
377
|
+
declare function register(rule: string, validate: (value: any, parameters?: string[], attribute?: string) => boolean | Promise<boolean>, replaceMessage?: (message: string, paramters: string[], data?: object, getDisplayableAttribute?: GenericCallable) => string): boolean;
|
|
378
|
+
declare function registerImplicit(rule: string, validate: (value: any, parameters?: string[] | number[], attribute?: string) => boolean | Promise<boolean>, replaceMessage?: (message: string, paramters: string[], data?: object, getDisplayableAttribute?: GenericCallable) => string): void;
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/Plugin.d.ts
|
|
381
|
+
interface ValidationValueInspector {
|
|
382
|
+
type: string;
|
|
383
|
+
matches: (value: any) => boolean;
|
|
384
|
+
size?: (value: any) => number;
|
|
385
|
+
}
|
|
386
|
+
interface ValidatorPluginApi {
|
|
387
|
+
registerRule: typeof register;
|
|
388
|
+
registerImplicitRule: typeof registerImplicit;
|
|
389
|
+
registerValueInspector: (inspector: ValidationValueInspector) => void;
|
|
390
|
+
extendTranslations: (translations: GenericObject) => void;
|
|
391
|
+
}
|
|
392
|
+
interface ValidatorPlugin {
|
|
393
|
+
name: string;
|
|
394
|
+
install: (api: ValidatorPluginApi) => void;
|
|
395
|
+
}
|
|
396
|
+
declare function definePlugin(plugin: ValidatorPlugin): ValidatorPlugin;
|
|
397
|
+
declare function usePlugin(plugin: ValidatorPlugin): void;
|
|
398
|
+
declare function registerValueInspector(inspector: ValidationValueInspector): void;
|
|
399
|
+
declare function getValidationValueInspector(value: any): ValidationValueInspector | undefined;
|
|
400
|
+
declare function getValidationMessageType(value: any, hasNumericRule?: boolean): string;
|
|
401
|
+
declare function getValidationSize(value: any, hasNumericRule?: boolean): number;
|
|
402
|
+
//#endregion
|
|
282
403
|
//#region src/BaseValidator.d.ts
|
|
283
404
|
declare class BaseValidator<D extends GenericObject = GenericObject> {
|
|
284
405
|
/**
|
|
@@ -321,15 +442,68 @@ declare class BaseValidator<D extends GenericObject = GenericObject> {
|
|
|
321
442
|
* Object of custom attribute name;
|
|
322
443
|
*/
|
|
323
444
|
customAttributes: CustomAttributes<D>;
|
|
445
|
+
/**
|
|
446
|
+
* Arbitrary per-validator context for plugins.
|
|
447
|
+
*/
|
|
448
|
+
private context;
|
|
324
449
|
constructor(data: D, rules: InitialRules<D>, customMessages?: CustomMessages<D>, customAttributes?: CustomAttributes<D>);
|
|
450
|
+
static use(plugin: ValidatorPlugin): typeof BaseValidator;
|
|
451
|
+
static useContext(context?: GenericObject): typeof BaseValidator;
|
|
452
|
+
use(plugin: ValidatorPlugin): this;
|
|
325
453
|
setData<ND extends GenericObject>(data: ND): BaseValidator<ND>;
|
|
326
454
|
setRules(rules: InitialRules<D>): this;
|
|
327
455
|
setLang(lang: string): this;
|
|
456
|
+
/**
|
|
457
|
+
* Set the validator's context.
|
|
458
|
+
*/
|
|
459
|
+
withContext(context?: GenericObject): this;
|
|
460
|
+
/**
|
|
461
|
+
* Get the validator's context.
|
|
462
|
+
* This is useful for custom rules that need access to additional data or services.
|
|
463
|
+
*
|
|
464
|
+
* @returns The current context object
|
|
465
|
+
*/
|
|
466
|
+
getContext(): GenericObject;
|
|
467
|
+
/**
|
|
468
|
+
* Get the current language used by the validator.
|
|
469
|
+
*
|
|
470
|
+
* @returns
|
|
471
|
+
*/
|
|
328
472
|
getLang(): string;
|
|
473
|
+
/**
|
|
474
|
+
* Set custom error messages for the validator.
|
|
475
|
+
*
|
|
476
|
+
* @param customMessages
|
|
477
|
+
* @returns
|
|
478
|
+
*/
|
|
329
479
|
setCustomMessages(customMessages?: CustomMessages<D>): this;
|
|
480
|
+
/**
|
|
481
|
+
* Set custom attribute names for the validator.
|
|
482
|
+
*
|
|
483
|
+
* @param customAttributes
|
|
484
|
+
* @returns
|
|
485
|
+
*/
|
|
330
486
|
setCustomAttributes(customAttributes?: CustomAttributes<D>): this;
|
|
487
|
+
/**
|
|
488
|
+
* Set whether the validator should stop validating after the first failure.
|
|
489
|
+
*
|
|
490
|
+
* @param stopOnFirstFailure
|
|
491
|
+
* @returns
|
|
492
|
+
*/
|
|
331
493
|
stopOnFirstFailure(stopOnFirstFailure?: boolean): this;
|
|
494
|
+
/**
|
|
495
|
+
* Get the error messages related to the validation.
|
|
496
|
+
*
|
|
497
|
+
* @returns
|
|
498
|
+
*/
|
|
332
499
|
errors(): ErrorBag;
|
|
500
|
+
/**
|
|
501
|
+
* Clear the error messages for the given keys.
|
|
502
|
+
* If no keys are provided, all error messages will be cleared.
|
|
503
|
+
*
|
|
504
|
+
* @param keys The keys of the error messages to clear
|
|
505
|
+
* @returns The updated ErrorBag instance
|
|
506
|
+
*/
|
|
333
507
|
clearErrors(keys?: string[]): ErrorBag;
|
|
334
508
|
/**
|
|
335
509
|
* Create a new ErrorBag instance and set the custom errors, thus removing previous error messages
|
|
@@ -349,6 +523,9 @@ declare class BaseValidator<D extends GenericObject = GenericObject> {
|
|
|
349
523
|
validateAsync(key?: string, value?: any): Promise<boolean>;
|
|
350
524
|
/**
|
|
351
525
|
* Get the displayable name of the attribute.
|
|
526
|
+
*
|
|
527
|
+
* @param attribute
|
|
528
|
+
* @returns
|
|
352
529
|
*/
|
|
353
530
|
getDisplayableAttribute(attribute: string): string;
|
|
354
531
|
private addCustomErrors;
|
|
@@ -581,88 +758,6 @@ declare abstract class IValidationRule {
|
|
|
581
758
|
passes(value: any, attribute: string): boolean | Promise<boolean>;
|
|
582
759
|
}
|
|
583
760
|
//#endregion
|
|
584
|
-
//#region src/Rules/in.d.ts
|
|
585
|
-
declare class In extends BaseRule {
|
|
586
|
-
/**
|
|
587
|
-
* The name of the rule.
|
|
588
|
-
*/
|
|
589
|
-
rule: string;
|
|
590
|
-
/**
|
|
591
|
-
* The accepted values.
|
|
592
|
-
*/
|
|
593
|
-
values: (string | number)[];
|
|
594
|
-
/**
|
|
595
|
-
* Create a new In rule instance.
|
|
596
|
-
*/
|
|
597
|
-
constructor(values: (string | number)[]);
|
|
598
|
-
/**
|
|
599
|
-
* Convert the rule to a validation string.
|
|
600
|
-
*/
|
|
601
|
-
toString(): string;
|
|
602
|
-
}
|
|
603
|
-
//#endregion
|
|
604
|
-
//#region src/Rules/notIn.d.ts
|
|
605
|
-
declare class NotIn extends BaseRule {
|
|
606
|
-
/**
|
|
607
|
-
* The name of the rule.
|
|
608
|
-
*/
|
|
609
|
-
rule: string;
|
|
610
|
-
/**
|
|
611
|
-
* The accepted values.
|
|
612
|
-
*/
|
|
613
|
-
values: (string | number)[];
|
|
614
|
-
/**
|
|
615
|
-
* Create a new NotIn rule instance.
|
|
616
|
-
*/
|
|
617
|
-
constructor(values: (string | number)[]);
|
|
618
|
-
/**
|
|
619
|
-
* Convert the rule to a validation string.
|
|
620
|
-
*/
|
|
621
|
-
toString(): string;
|
|
622
|
-
}
|
|
623
|
-
//#endregion
|
|
624
|
-
//#region src/Rules/regex.d.ts
|
|
625
|
-
declare class Regex extends IRuleContract {
|
|
626
|
-
/**
|
|
627
|
-
* The Regular expression to validate
|
|
628
|
-
*/
|
|
629
|
-
regex: RegExp;
|
|
630
|
-
/**
|
|
631
|
-
* Flag that decides whether the value should match the regular expression or not
|
|
632
|
-
*/
|
|
633
|
-
shouldMatch: boolean;
|
|
634
|
-
constructor(regex: RegExp, shouldMatch?: boolean);
|
|
635
|
-
passes(value: any): boolean;
|
|
636
|
-
getMessage(): string;
|
|
637
|
-
}
|
|
638
|
-
//#endregion
|
|
639
|
-
//#region src/Rules/requiredIf.d.ts
|
|
640
|
-
declare class RequiredIf extends BaseRule {
|
|
641
|
-
/**
|
|
642
|
-
* The condition that validates the attribute
|
|
643
|
-
*/
|
|
644
|
-
condition: boolean | CallableFunction;
|
|
645
|
-
/**
|
|
646
|
-
* Create a new required validation rule based on a condition.
|
|
647
|
-
*/
|
|
648
|
-
constructor(condition: boolean | CallableFunction);
|
|
649
|
-
/**
|
|
650
|
-
* Convert the rule to a validation string.
|
|
651
|
-
*/
|
|
652
|
-
toString(): string;
|
|
653
|
-
}
|
|
654
|
-
//#endregion
|
|
655
|
-
//#region src/Contracts/ValidationRuleName.d.ts
|
|
656
|
-
type ParamableValidationRuleName = 'accepted_if' | 'after' | 'after_or_equal' | 'before' | 'before_or_equal' | 'between' | 'date_equals' | 'datetime' | 'declined_if' | 'digits_between' | 'different' | 'exists' | 'ends_with' | 'gt' | 'gte' | 'in' | 'includes' | 'lt' | 'lte' | 'max' | 'min' | 'not_in' | 'not_includes' | 'required_if' | 'required_unless' | 'required_with' | 'required_with_all' | 'required_without' | 'required_without_all' | 'same' | 'size' | 'starts_with' | 'unique';
|
|
657
|
-
type PlainRuleName = 'accepted' | 'alpha' | 'alpha_dash' | 'alpha_num' | 'array' | 'array_unique' | 'bail' | 'boolean' | 'confirmed' | 'date' | 'declined' | 'digits' | 'email' | 'integer' | 'json' | 'not_regex' | 'nullable' | 'numeric' | 'object' | 'present' | 'regex' | 'required' | 'sometimes' | 'string' | 'url' | 'hex' | 'uuid';
|
|
658
|
-
type ValidationRuleName = ParamableValidationRuleName | PlainRuleName;
|
|
659
|
-
type MethodRules = Regex | In | NotIn | RequiredIf;
|
|
660
|
-
/**
|
|
661
|
-
* Single rule value (supports autocomplete + arbitrary strings + RuleContract instances)
|
|
662
|
-
*/
|
|
663
|
-
type RuleName = ValidationRuleName | `${ParamableValidationRuleName}:${string}` | IRuleContract | MethodRules;
|
|
664
|
-
type ValidationRuleSet = RuleName | RuleName[] | `${ValidationRuleName}${string & `|${string}`}`;
|
|
665
|
-
//#endregion
|
|
666
761
|
//#region src/Contracts/ValidatorContracts.d.ts
|
|
667
762
|
/**
|
|
668
763
|
* Parse rule names from rule string or string[] definitions
|
|
@@ -695,6 +790,8 @@ declare class IValidator<D extends Record<string, any> = any, R extends RulesFor
|
|
|
695
790
|
*/
|
|
696
791
|
static make<D extends Record<string, any>, R extends RulesForData<D>>(data: D, rules: R, messages: Partial<Record<MessagesForRules<R>, string>>): IValidator<D, R>;
|
|
697
792
|
static useDatabase(driver: IDatabaseDriver): typeof IValidator;
|
|
793
|
+
static use(plugin: ValidatorPlugin): typeof IValidator;
|
|
794
|
+
static useContext(context: Record<string, any>): typeof IValidator;
|
|
698
795
|
/**
|
|
699
796
|
* Run the validator and store results.
|
|
700
797
|
*/
|
|
@@ -719,6 +816,9 @@ declare class IValidator<D extends Record<string, any> = any, R extends RulesFor
|
|
|
719
816
|
* Stop validation on first failure.
|
|
720
817
|
*/
|
|
721
818
|
stopOnFirstFailure(): this;
|
|
819
|
+
use(plugin: ValidatorPlugin): this;
|
|
820
|
+
withContext(context: Record<string, any>): this;
|
|
821
|
+
getContext(): Record<string, any>;
|
|
722
822
|
/**
|
|
723
823
|
* Get the data that passed validation.
|
|
724
824
|
*/
|
|
@@ -777,6 +877,29 @@ declare class IValidator<D extends Record<string, any> = any, R extends RulesFor
|
|
|
777
877
|
getDatabaseDriver(): IDatabaseDriver | undefined;
|
|
778
878
|
}
|
|
779
879
|
//#endregion
|
|
880
|
+
//#region src/Context.d.ts
|
|
881
|
+
type ValidatorContext = Record<string, any>;
|
|
882
|
+
/**
|
|
883
|
+
* Get the current validator context.
|
|
884
|
+
*
|
|
885
|
+
* @returns
|
|
886
|
+
*/
|
|
887
|
+
declare function getValidatorContext(): ValidatorContext;
|
|
888
|
+
/**
|
|
889
|
+
* Use a context for the current validator instance and all of its children.
|
|
890
|
+
*
|
|
891
|
+
* @param context
|
|
892
|
+
* @returns
|
|
893
|
+
*/
|
|
894
|
+
declare function useValidatorContext(context?: ValidatorContext): ValidatorContext;
|
|
895
|
+
/**
|
|
896
|
+
* Run a function with a given validator context.
|
|
897
|
+
*
|
|
898
|
+
* @param context The context to use during the execution of the callback
|
|
899
|
+
* @param callback The function to execute with the given context
|
|
900
|
+
*/
|
|
901
|
+
declare function runWithValidatorContext<T>(context: ValidatorContext, callback: () => T): T;
|
|
902
|
+
//#endregion
|
|
780
903
|
//#region src/Rules/password.d.ts
|
|
781
904
|
declare class Password$1 extends IRuleContract {
|
|
782
905
|
/**
|
|
@@ -865,10 +988,6 @@ declare class Password$1 extends IRuleContract {
|
|
|
865
988
|
static default(): IRuleContract | Password$1;
|
|
866
989
|
}
|
|
867
990
|
//#endregion
|
|
868
|
-
//#region src/Rules/registerRule.d.ts
|
|
869
|
-
declare function register(rule: string, validate: (value: any, parameters?: string[], attribute?: string) => boolean | Promise<boolean>, replaceMessage?: (message: string, paramters: string[], data?: object, getDisplayableAttribute?: GenericCallable) => string): boolean;
|
|
870
|
-
declare function registerImplicit(rule: string, validate: (value: any, parameters?: string[] | number[], attribute?: string) => boolean | Promise<boolean>, replaceMessage?: (message: string, paramters: string[], data?: object, getDisplayableAttribute?: GenericCallable) => string): void;
|
|
871
|
-
//#endregion
|
|
872
991
|
//#region src/rule.d.ts
|
|
873
992
|
declare function requiredIf(callback: boolean | CallableFunction): RequiredIf;
|
|
874
993
|
declare function ruleIn(values: (string | number)[]): In;
|
|
@@ -1020,12 +1139,36 @@ declare class Validator<D extends Record<string, any> = any, R extends RulesForD
|
|
|
1020
1139
|
private errorBagName;
|
|
1021
1140
|
private registeredCustomRules;
|
|
1022
1141
|
private shouldStopOnFirstFailure;
|
|
1142
|
+
private context;
|
|
1023
1143
|
constructor(data: D, rules: R, messages?: Partial<Record<MessagesForRules<R>, string>>);
|
|
1024
1144
|
/**
|
|
1025
1145
|
* Validate the data and return the instance
|
|
1026
1146
|
*/
|
|
1027
1147
|
static make<D extends Record<string, any>, R extends RulesForData<D>>(data: D, rules: R, messages?: Partial<Record<MessagesForRules<R>, string>>): Validator<D, R>;
|
|
1028
1148
|
static useDatabase(driver: IDatabaseDriver): typeof Validator;
|
|
1149
|
+
/**
|
|
1150
|
+
* Set the validator's context.
|
|
1151
|
+
*
|
|
1152
|
+
* @param context
|
|
1153
|
+
* @returns
|
|
1154
|
+
*/
|
|
1155
|
+
static useContext(context?: Record<string, any>): typeof Validator;
|
|
1156
|
+
/**
|
|
1157
|
+
* Register a plugin with the validator.
|
|
1158
|
+
* Plugins can add rules, messages, and even override existing rules and messages.
|
|
1159
|
+
*
|
|
1160
|
+
* @param plugin The plugin to register
|
|
1161
|
+
* @returns The Validator class for chaining
|
|
1162
|
+
*/
|
|
1163
|
+
static use(plugin: ValidatorPlugin): typeof Validator;
|
|
1164
|
+
/**
|
|
1165
|
+
* Register a plugin with the validator.
|
|
1166
|
+
* Plugins can add rules, messages, and even override existing rules and messages.
|
|
1167
|
+
*
|
|
1168
|
+
* @param plugin The plugin to register
|
|
1169
|
+
* @returns The Validator instance for chaining
|
|
1170
|
+
*/
|
|
1171
|
+
use(plugin: ValidatorPlugin): this;
|
|
1029
1172
|
/**
|
|
1030
1173
|
* Run the validator and store results.
|
|
1031
1174
|
*/
|
|
@@ -1050,6 +1193,21 @@ declare class Validator<D extends Record<string, any> = any, R extends RulesForD
|
|
|
1050
1193
|
* Stop validation on first failure.
|
|
1051
1194
|
*/
|
|
1052
1195
|
stopOnFirstFailure(): this;
|
|
1196
|
+
/**
|
|
1197
|
+
* Set the validator's context.
|
|
1198
|
+
* This is useful for custom rules that need access to additional data or services.
|
|
1199
|
+
*
|
|
1200
|
+
* @param context
|
|
1201
|
+
* @returns
|
|
1202
|
+
*/
|
|
1203
|
+
withContext(context?: Record<string, any>): this;
|
|
1204
|
+
/**
|
|
1205
|
+
* Get the validator's context.
|
|
1206
|
+
* This is useful for custom rules that need access to additional data or services.
|
|
1207
|
+
*
|
|
1208
|
+
* @returns The current context object
|
|
1209
|
+
*/
|
|
1210
|
+
getContext(): Record<string, any>;
|
|
1053
1211
|
/**
|
|
1054
1212
|
* Get the data that passed validation.
|
|
1055
1213
|
*/
|
|
@@ -1144,6 +1302,10 @@ declare class Lang {
|
|
|
1144
1302
|
* Store the translations passed by the user
|
|
1145
1303
|
*/
|
|
1146
1304
|
static translations: GenericObject;
|
|
1305
|
+
/**
|
|
1306
|
+
* Store translations contributed by plugins.
|
|
1307
|
+
*/
|
|
1308
|
+
static translationExtensions: GenericObject;
|
|
1147
1309
|
/**
|
|
1148
1310
|
* Stores the messages that are already loaded
|
|
1149
1311
|
*/
|
|
@@ -1169,6 +1331,10 @@ declare class Lang {
|
|
|
1169
1331
|
* @param translations
|
|
1170
1332
|
*/
|
|
1171
1333
|
static setTranslationObject(translations: GenericObject): void;
|
|
1334
|
+
/**
|
|
1335
|
+
* Merge additional translations into the global catalog.
|
|
1336
|
+
*/
|
|
1337
|
+
static extendTranslationObject(translations: GenericObject): void;
|
|
1172
1338
|
/**
|
|
1173
1339
|
* Set the default lang that should be used. And assign the default messages
|
|
1174
1340
|
*
|
|
@@ -1194,6 +1360,7 @@ declare class Lang {
|
|
|
1194
1360
|
* @returns
|
|
1195
1361
|
*/
|
|
1196
1362
|
static load(lang: string): void;
|
|
1363
|
+
private static resetLoadedMessages;
|
|
1197
1364
|
}
|
|
1198
1365
|
//#endregion
|
|
1199
1366
|
//#region src/Providers/ValidationServiceProvider.d.ts
|
|
@@ -1341,6 +1508,32 @@ declare function convertValuesToNull(values: string[]): (string | null)[];
|
|
|
1341
1508
|
* @returns
|
|
1342
1509
|
*/
|
|
1343
1510
|
declare const plural: (word: string, count: number) => string;
|
|
1511
|
+
/**
|
|
1512
|
+
* Determine if a value is an object. Arrays and null are not considered objects.
|
|
1513
|
+
*
|
|
1514
|
+
* @param value
|
|
1515
|
+
* @returns
|
|
1516
|
+
*/
|
|
1517
|
+
declare function isObject(value: unknown): value is GenericObject;
|
|
1518
|
+
/**
|
|
1519
|
+
* Deeply merge two objects.
|
|
1520
|
+
* The source object will overwrite the target object when there is a conflict.
|
|
1521
|
+
* Arrays and non-object values will be overwritten, not merged.
|
|
1522
|
+
*
|
|
1523
|
+
* @param target
|
|
1524
|
+
* @param source
|
|
1525
|
+
* @returns
|
|
1526
|
+
*/
|
|
1527
|
+
declare function mergeDeep(target: GenericObject, source: GenericObject): GenericObject;
|
|
1528
|
+
/**
|
|
1529
|
+
* Deeply find a value in an object using a dot-notated path.
|
|
1530
|
+
* Returns undefined if the path does not exist.
|
|
1531
|
+
*
|
|
1532
|
+
* @param obj
|
|
1533
|
+
* @param path
|
|
1534
|
+
* @returns
|
|
1535
|
+
*/
|
|
1536
|
+
declare function deepFindMessage(obj: GenericObject, path: string): any;
|
|
1344
1537
|
//#endregion
|
|
1345
1538
|
//#region src/utilities/object.d.ts
|
|
1346
1539
|
/**
|
|
@@ -1368,21 +1561,6 @@ declare function deepSet(target: any, path: string | string[], value: any): void
|
|
|
1368
1561
|
* @returns
|
|
1369
1562
|
*/
|
|
1370
1563
|
declare function dotify(obj: GenericObject, ignoreRulesArray?: boolean, withBaseObjectType?: boolean): GenericObject;
|
|
1371
|
-
/**
|
|
1372
|
-
* Check if the value is an object
|
|
1373
|
-
*
|
|
1374
|
-
* @param value
|
|
1375
|
-
* @returns
|
|
1376
|
-
*/
|
|
1377
|
-
declare function isObject(value: any): any;
|
|
1378
|
-
/**
|
|
1379
|
-
* Deeply merge nested objects
|
|
1380
|
-
*
|
|
1381
|
-
* @param target
|
|
1382
|
-
* @param source
|
|
1383
|
-
* @returns
|
|
1384
|
-
*/
|
|
1385
|
-
declare function mergeDeep(target: GenericObject, source: GenericObject): GenericObject;
|
|
1386
1564
|
/**
|
|
1387
1565
|
* Check if objects are deep equal
|
|
1388
1566
|
*
|
|
@@ -1442,4 +1620,4 @@ declare class ValidationException extends Error {
|
|
|
1442
1620
|
getResponse(): any;
|
|
1443
1621
|
}
|
|
1444
1622
|
//#endregion
|
|
1445
|
-
export { BaseValidationRuleClass, BaseValidator, CustomAttributes, CustomErrors, CustomMessages, CustomValidationRules, DotPaths, ErrorBag, ErrorMessage, Errors, ExtendedRules, ExtractRules, FieldMessages, GenericCallable, GenericObject, IDatabaseDriver, IMessageBag, IValidationRule, IValidator, ImplicitAttributes, ImplicitRule, InitialRule, InitialRules, Lang, MessageBag, Messages, MessagesForRules, NestedStringMap, ParamableValidationRuleName, Password, PlainRuleName, ReplaceAttributeInterface, Rules, RulesForData, TRule, ValidatedByRules, ValidationCallback, ValidationDataInterface, ValidationDatabaseExistsInput, ValidationException, ValidationMessageProvider, ValidationRule, ValidationRuleCallable, ValidationRuleName, ValidationRuleParserInterface, ValidationRuleSet, ValidationServiceProvider, Validator, addImplicitRule, buildValidationMethodName, compare, convertValuesToBoolean, convertValuesToNull, convertValuesToNumber, deepEqual, deepFind, deepSet, dotify, getFormattedAttribute, getKeyCombinations, getMessage, getNumericRules, getSize, isArrayOfRules, isImplicitRule, isInteger, isNumericRule, isObject, isRule, isSizeRule, make, mergeDeep, notRegex, plural, regex, register, registerImplicit, requiredIf, ruleIn, ruleNotIn, sameType, toDate, toSnakeCase };
|
|
1623
|
+
export { BaseValidationRuleClass, BaseValidator, CustomAttributes, CustomErrors, CustomMessages, CustomParamableValidationRuleName, CustomPlainRuleName, CustomValidationRuleNameMap, CustomValidationRules, DotPaths, ErrorBag, ErrorMessage, Errors, ExtendedRules, ExtractRules, FieldMessages, GenericCallable, GenericObject, IDatabaseDriver, IMessageBag, IValidationRule, IValidator, ImplicitAttributes, ImplicitRule, InitialRule, InitialRules, Lang, MessageBag, Messages, MessagesForRules, NestedStringMap, ParamableValidationRuleName, Password, PlainRuleName, ReplaceAttributeInterface, Rules, RulesForData, TRule, ValidatedByRules, ValidationCallback, ValidationDataInterface, ValidationDatabaseExistsInput, ValidationException, ValidationMessageProvider, ValidationRule, ValidationRuleAutocompleteKind, ValidationRuleAutocompleteMap, ValidationRuleCallable, ValidationRuleEntry, ValidationRuleName, ValidationRuleParserInterface, ValidationRuleSet, ValidationServiceProvider, ValidationValueInspector, Validator, ValidatorPlugin, ValidatorPluginApi, addImplicitRule, buildValidationMethodName, compare, convertValuesToBoolean, convertValuesToNull, convertValuesToNumber, deepEqual, deepFind, deepFindMessage, deepSet, definePlugin, dotify, getFormattedAttribute, getKeyCombinations, getMessage, getNumericRules, getSize, getValidationMessageType, getValidationSize, getValidationValueInspector, getValidatorContext, isArrayOfRules, isImplicitRule, isInteger, isNumericRule, isObject, isRule, isSizeRule, make, mergeDeep, notRegex, plural, regex, register, registerImplicit, registerValueInspector, requiredIf, ruleIn, ruleNotIn, runWithValidatorContext, sameType, toDate, toSnakeCase, usePlugin, useValidatorContext };
|