@warlock.js/seal 4.0.158 → 4.0.162
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/esm/config.d.ts +48 -0
- package/esm/config.d.ts.map +1 -0
- package/esm/config.js +42 -0
- package/esm/config.js.map +1 -0
- package/esm/factory/index.d.ts +3 -0
- package/esm/factory/index.d.ts.map +1 -0
- package/esm/factory/validate.d.ts +8 -0
- package/esm/factory/validate.d.ts.map +1 -0
- package/esm/factory/validate.js +23 -0
- package/esm/factory/validate.js.map +1 -0
- package/esm/factory/validators.d.ts +56 -0
- package/esm/factory/validators.d.ts.map +1 -0
- package/esm/factory/validators.js +45 -0
- package/esm/factory/validators.js.map +1 -0
- package/esm/helpers/date-helpers.d.ts +16 -0
- package/esm/helpers/date-helpers.d.ts.map +1 -0
- package/esm/helpers/date-helpers.js +20 -0
- package/esm/helpers/date-helpers.js.map +1 -0
- package/esm/helpers/file.utils.d.ts +8 -0
- package/esm/helpers/file.utils.d.ts.map +1 -0
- package/esm/helpers/file.utils.js +29 -0
- package/esm/helpers/file.utils.js.map +1 -0
- package/esm/helpers/get-field-value.d.ts +37 -0
- package/esm/helpers/get-field-value.d.ts.map +1 -0
- package/esm/helpers/get-field-value.js +40 -0
- package/esm/helpers/get-field-value.js.map +1 -0
- package/esm/helpers/index.d.ts +6 -0
- package/esm/helpers/index.d.ts.map +1 -0
- package/esm/helpers/is-empty-value.d.ts +2 -0
- package/esm/helpers/is-empty-value.d.ts.map +1 -0
- package/esm/helpers/is-empty-value.js +3 -0
- package/esm/helpers/is-empty-value.js.map +1 -0
- package/esm/helpers/path-helpers.d.ts +5 -0
- package/esm/helpers/path-helpers.d.ts.map +1 -0
- package/esm/helpers/path-helpers.js +8 -0
- package/esm/helpers/path-helpers.js.map +1 -0
- package/esm/helpers/validation-helpers.d.ts +26 -0
- package/esm/helpers/validation-helpers.d.ts.map +1 -0
- package/esm/helpers/validation-helpers.js +74 -0
- package/esm/helpers/validation-helpers.js.map +1 -0
- package/package.json +1 -1
package/esm/config.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seal Configuration
|
|
3
|
+
*
|
|
4
|
+
* Global configuration for the Seal validation library
|
|
5
|
+
*/
|
|
6
|
+
import type { AttributeTranslation, RuleTranslation } from "./types";
|
|
7
|
+
export type TranslateRuleCallback = (ruleTranslation: RuleTranslation) => string;
|
|
8
|
+
export type TranslateAttributeCallback = (attributeTranslation: AttributeTranslation) => string;
|
|
9
|
+
export type SealConfig = {
|
|
10
|
+
/**
|
|
11
|
+
* Translation function for error messages
|
|
12
|
+
* Default: returns the key with attributes replaced
|
|
13
|
+
*/
|
|
14
|
+
translateRule?: TranslateRuleCallback;
|
|
15
|
+
/**
|
|
16
|
+
* Translation function for attribute messages
|
|
17
|
+
*/
|
|
18
|
+
translateAttribute?: TranslateAttributeCallback;
|
|
19
|
+
/**
|
|
20
|
+
* Default to first error only in validation
|
|
21
|
+
* Default: true
|
|
22
|
+
*/
|
|
23
|
+
firstErrorOnly?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Configure Seal globally
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { configureSeal } from "@warlock.js/seal";
|
|
31
|
+
* import { trans } from "@mongez/localization";
|
|
32
|
+
*
|
|
33
|
+
* configureSeal({
|
|
34
|
+
* translateRule: (ruleTranslation) => trans(`validation.${ruleTranslation.rule.name}`, ruleTranslation.attributes),
|
|
35
|
+
* translateAttribute: (attributeTranslation) => trans(`validation.attributes.${attributeTranslation.rule.name}.${attributeTranslation.attribute}`, attributeTranslation.context.allValues),
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function configureSeal(options: Partial<SealConfig>): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get current Seal configuration
|
|
42
|
+
*/
|
|
43
|
+
export declare function getSealConfig(): SealConfig;
|
|
44
|
+
/**
|
|
45
|
+
* Reset configuration to defaults
|
|
46
|
+
*/
|
|
47
|
+
export declare function resetSealConfig(): void;
|
|
48
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAErE,MAAM,MAAM,qBAAqB,GAAG,CAClC,eAAe,EAAE,eAAe,KAC7B,MAAM,CAAC;AAEZ,MAAM,MAAM,0BAA0B,GAAG,CACvC,oBAAoB,EAAE,oBAAoB,KACvC,MAAM,CAAC;AAEZ,MAAM,MAAM,UAAU,GAAG;IACvB;;;OAGG;IACH,aAAa,CAAC,EAAE,qBAAqB,CAAC;IACtC;;OAEG;IACH,kBAAkB,CAAC,EAAE,0BAA0B,CAAC;IAEhD;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AASF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAEhE;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAKtC"}
|
package/esm/config.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seal Configuration
|
|
3
|
+
*
|
|
4
|
+
* Global configuration for the Seal validation library
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Global Seal configuration
|
|
8
|
+
*/
|
|
9
|
+
const config = {
|
|
10
|
+
firstErrorOnly: true,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Configure Seal globally
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { configureSeal } from "@warlock.js/seal";
|
|
18
|
+
* import { trans } from "@mongez/localization";
|
|
19
|
+
*
|
|
20
|
+
* configureSeal({
|
|
21
|
+
* translateRule: (ruleTranslation) => trans(`validation.${ruleTranslation.rule.name}`, ruleTranslation.attributes),
|
|
22
|
+
* translateAttribute: (attributeTranslation) => trans(`validation.attributes.${attributeTranslation.rule.name}.${attributeTranslation.attribute}`, attributeTranslation.context.allValues),
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function configureSeal(options) {
|
|
27
|
+
Object.assign(config, options);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get current Seal configuration
|
|
31
|
+
*/
|
|
32
|
+
function getSealConfig() {
|
|
33
|
+
return config;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reset configuration to defaults
|
|
37
|
+
*/
|
|
38
|
+
function resetSealConfig() {
|
|
39
|
+
delete config.translateRule;
|
|
40
|
+
delete config.translateAttribute;
|
|
41
|
+
config.firstErrorOnly = true;
|
|
42
|
+
}export{configureSeal,getSealConfig,resetSealConfig};//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../src/config.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;AAIG;AA8BH;;AAEG;AACH,MAAM,MAAM,GAAe;AACzB,IAAA,cAAc,EAAE,IAAI;CACrB,CAAC;AAEF;;;;;;;;;;;;;AAaG;AACG,SAAU,aAAa,CAAC,OAA4B,EAAA;AACxD,IAAA,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;AAEG;SACa,aAAa,GAAA;AAC3B,IAAA,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;AAEG;SACa,eAAe,GAAA;IAC7B,OAAO,MAAM,CAAC,aAAa,CAAC;IAC5B,OAAO,MAAM,CAAC,kBAAkB,CAAC;AAEjC,IAAA,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;AAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationResult } from "../types";
|
|
2
|
+
import type { BaseValidator } from "../validators";
|
|
3
|
+
import { type ValidateOptions } from "./validators";
|
|
4
|
+
/**
|
|
5
|
+
* Validate data against a schema
|
|
6
|
+
*/
|
|
7
|
+
export declare const validate: <T extends BaseValidator<unknown, unknown>>(schema: T, data: any, { context: extendedContext, ...configurations }?: ValidateOptions) => Promise<ValidationResult>;
|
|
8
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/factory/validate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,QAAQ,+DAEb,GAAG,oDACwC,eAAe,KAC/D,QAAQ,gBAAgB,CAmB1B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {getSealConfig}from'../config.js';/**
|
|
2
|
+
* Validate data against a schema
|
|
3
|
+
*/
|
|
4
|
+
const validate = async (schema, data, // Temporarily use any - will fix type inference
|
|
5
|
+
{ context: extendedContext, ...configurations } = getSealConfig() || {}) => {
|
|
6
|
+
const context = {
|
|
7
|
+
allValues: data,
|
|
8
|
+
parent: null,
|
|
9
|
+
value: data,
|
|
10
|
+
key: "",
|
|
11
|
+
path: "",
|
|
12
|
+
context: extendedContext,
|
|
13
|
+
rootContext: extendedContext,
|
|
14
|
+
translateRule(ruleTranslation) {
|
|
15
|
+
return configurations.translateRule?.(ruleTranslation) ?? "";
|
|
16
|
+
},
|
|
17
|
+
translateAttribute(attributeTranslation) {
|
|
18
|
+
return configurations.translateAttribute?.(attributeTranslation) ?? "";
|
|
19
|
+
},
|
|
20
|
+
configurations,
|
|
21
|
+
};
|
|
22
|
+
return await schema.validate(data, context);
|
|
23
|
+
};export{validate};//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sources":["../../src/factory/validate.ts"],"sourcesContent":[null],"names":[],"mappings":"yCAKA;;AAEG;AACU,MAAA,QAAQ,GAAG,OACtB,MAAS,EACT,IAAS;AACT,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,cAAc,EAAsB,GAAA,aAAa,EAAE,IAAI,EAAE,KAC3D;AAC7B,IAAA,MAAM,OAAO,GAAkB;AAC7B,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,GAAG,EAAE,EAAE;AACP,QAAA,IAAI,EAAE,EAAE;AACR,QAAA,OAAO,EAAE,eAAe;AACxB,QAAA,WAAW,EAAE,eAAe;AAC5B,QAAA,aAAa,CAAC,eAAe,EAAA;YAC3B,OAAO,cAAc,CAAC,aAAa,GAAG,eAAe,CAAC,IAAI,EAAE,CAAC;SAC9D;AACD,QAAA,kBAAkB,CAAC,oBAAoB,EAAA;YACrC,OAAO,cAAc,CAAC,kBAAkB,GAAG,oBAAoB,CAAC,IAAI,EAAE,CAAC;SACxE;QACD,cAAc;KACf,CAAC;IAEF,OAAO,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC9C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SealConfig } from "../config";
|
|
2
|
+
import type { Schema, SchemaContext, ValidationResult } from "../types";
|
|
3
|
+
import { AnyValidator } from "../validators/any-validator";
|
|
4
|
+
import { ArrayValidator } from "../validators/array-validator";
|
|
5
|
+
import type { BaseValidator } from "../validators/base-validator";
|
|
6
|
+
import { BooleanValidator } from "../validators/boolean-validator";
|
|
7
|
+
import { ComputedValidator } from "../validators/computed-validator";
|
|
8
|
+
import { DateValidator } from "../validators/date-validator";
|
|
9
|
+
import { FloatValidator } from "../validators/float-validator";
|
|
10
|
+
import { IntValidator } from "../validators/int-validator";
|
|
11
|
+
import { ManagedValidator } from "../validators/managed-validator";
|
|
12
|
+
import { NumberValidator } from "../validators/number-validator";
|
|
13
|
+
import { NumericValidator } from "../validators/numeric-validator";
|
|
14
|
+
import { ObjectValidator } from "../validators/object-validator";
|
|
15
|
+
import { RecordValidator } from "../validators/record-validator";
|
|
16
|
+
import { ScalarValidator } from "../validators/scalar-validator";
|
|
17
|
+
import { StringValidator } from "../validators/string-validator";
|
|
18
|
+
import { TupleValidator } from "../validators/tuple-validator";
|
|
19
|
+
import { UnionValidator } from "../validators/union-validator";
|
|
20
|
+
/**
|
|
21
|
+
* Seal factory object - creates instances of validators
|
|
22
|
+
*
|
|
23
|
+
* Use 'v' to create validation schemas (seals) for your data
|
|
24
|
+
*/
|
|
25
|
+
export declare const v: ValidatorV;
|
|
26
|
+
export type ValidateOptions = {
|
|
27
|
+
context?: Record<string, any>;
|
|
28
|
+
} & SealConfig;
|
|
29
|
+
export interface ValidatorV {
|
|
30
|
+
object: <T extends Schema>(schema: T, errorMessage?: string) => ObjectValidator<T>;
|
|
31
|
+
any: () => AnyValidator;
|
|
32
|
+
array: <T extends BaseValidator>(validator: T, errorMessage?: string) => ArrayValidator & {
|
|
33
|
+
validator: T;
|
|
34
|
+
};
|
|
35
|
+
record: <T extends BaseValidator>(validator?: T, errorMessage?: string) => RecordValidator & {
|
|
36
|
+
valueValidator: T;
|
|
37
|
+
};
|
|
38
|
+
tuple: <T extends BaseValidator[]>(validators: T, errorMessage?: string) => TupleValidator & {
|
|
39
|
+
validators: T;
|
|
40
|
+
};
|
|
41
|
+
date: (errorMessage?: string) => DateValidator;
|
|
42
|
+
string: (errorMessage?: string) => StringValidator;
|
|
43
|
+
email: (errorMessage?: string) => StringValidator;
|
|
44
|
+
enum: (values: any, errorMessage?: string) => ScalarValidator;
|
|
45
|
+
number: (errorMessage?: string) => NumberValidator;
|
|
46
|
+
numeric: (errorMessage?: string) => NumericValidator;
|
|
47
|
+
int: (errorMessage?: string) => IntValidator;
|
|
48
|
+
float: (errorMessage?: string) => FloatValidator;
|
|
49
|
+
boolean: (errorMessage?: string) => BooleanValidator;
|
|
50
|
+
scalar: (errorMessage?: string) => ScalarValidator;
|
|
51
|
+
union: (validators: BaseValidator[], errorMessage?: string) => UnionValidator;
|
|
52
|
+
computed: <TResult = any>(callback: (data: any, context: SchemaContext) => TResult | Promise<TResult>, resultValidator?: BaseValidator) => ComputedValidator<TResult>;
|
|
53
|
+
managed: <TResult = any>(callback?: (context: SchemaContext) => TResult | Promise<TResult>, resultValidator?: BaseValidator) => ManagedValidator<TResult>;
|
|
54
|
+
validate: <T extends BaseValidator>(schema: T, data: any, options?: ValidateOptions) => Promise<ValidationResult>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/factory/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAA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AAO,CAAC,EAC3E,eAAe,CAAC,EAAE,aAAa,KAC5B,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,OAAO,GAAG,GAAG,EACrB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EACjE,eAAe,CAAC,EAAE,aAAa,KAC5B,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,SAAS,aAAa,EAChC,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE,eAAe,KACtB,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAChC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {AnyValidator}from'../validators/any-validator.js';import {ArrayValidator}from'../validators/array-validator.js';import {BooleanValidator}from'../validators/boolean-validator.js';import {ComputedValidator}from'../validators/computed-validator.js';import {DateValidator}from'../validators/date-validator.js';import {FloatValidator}from'../validators/float-validator.js';import {IntValidator}from'../validators/int-validator.js';import {ManagedValidator}from'../validators/managed-validator.js';import {NumberValidator}from'../validators/number-validator.js';import {NumericValidator}from'../validators/numeric-validator.js';import {ObjectValidator}from'../validators/object-validator.js';import {RecordValidator}from'../validators/record-validator.js';import {ScalarValidator}from'../validators/scalar-validator.js';import {StringValidator}from'../validators/string-validator.js';import {TupleValidator}from'../validators/tuple-validator.js';import {UnionValidator}from'../validators/union-validator.js';import {validate}from'./validate.js';/**
|
|
2
|
+
* Seal factory object - creates instances of validators
|
|
3
|
+
*
|
|
4
|
+
* Use 'v' to create validation schemas (seals) for your data
|
|
5
|
+
*/
|
|
6
|
+
const v = {
|
|
7
|
+
/** Create an object validator */
|
|
8
|
+
object: (schema, errorMessage) => new ObjectValidator(schema, errorMessage),
|
|
9
|
+
/** Create an any validator */
|
|
10
|
+
any: () => new AnyValidator(),
|
|
11
|
+
/** Create an array validator */
|
|
12
|
+
array: (validator, errorMessage) => new ArrayValidator(validator, errorMessage),
|
|
13
|
+
/** Create a record validator - object with dynamic keys and consistent value types */
|
|
14
|
+
record: (validator, errorMessage) => new RecordValidator(validator || v.any(), errorMessage),
|
|
15
|
+
/** Create a tuple validator - fixed-length array with position-specific types */
|
|
16
|
+
tuple: (validators, errorMessage) => new TupleValidator(validators, errorMessage),
|
|
17
|
+
/** Create a date validator */
|
|
18
|
+
date: (errorMessage) => new DateValidator(errorMessage),
|
|
19
|
+
/** Create a string validator */
|
|
20
|
+
string: (errorMessage) => new StringValidator(errorMessage),
|
|
21
|
+
/** Create an email validator */
|
|
22
|
+
email: (emailErrorMessage, errorMessage) => new StringValidator(errorMessage).email(emailErrorMessage),
|
|
23
|
+
/** Create an enum validator */
|
|
24
|
+
enum: (values, errorMessage) => new ScalarValidator().enum(values, errorMessage),
|
|
25
|
+
/** Create a number validator */
|
|
26
|
+
number: (errorMessage) => new NumberValidator(errorMessage),
|
|
27
|
+
/** Create a numeric validator */
|
|
28
|
+
numeric: (errorMessage) => new NumericValidator(errorMessage),
|
|
29
|
+
/** Create an integer validator */
|
|
30
|
+
int: (errorMessage) => new IntValidator(errorMessage),
|
|
31
|
+
/** Create a float validator */
|
|
32
|
+
float: (errorMessage) => new FloatValidator(errorMessage),
|
|
33
|
+
/** Create a boolean validator */
|
|
34
|
+
boolean: (errorMessage) => new BooleanValidator(errorMessage),
|
|
35
|
+
/** Create a scalar validator */
|
|
36
|
+
scalar: (errorMessage) => new ScalarValidator(errorMessage),
|
|
37
|
+
/** Create a union validator - validates against multiple types */
|
|
38
|
+
union: (validators, errorMessage) => new UnionValidator().union(validators, errorMessage),
|
|
39
|
+
/** Create a computed field validator - derives value from other validated fields */
|
|
40
|
+
computed: (callback, resultValidator) => new ComputedValidator(callback, resultValidator),
|
|
41
|
+
/** Create a managed field validator - framework-injected value */
|
|
42
|
+
managed: (callback, resultValidator) => new ManagedValidator(callback, resultValidator),
|
|
43
|
+
/** Validate data against a schema */
|
|
44
|
+
validate: validate,
|
|
45
|
+
};export{v};//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sources":["../../src/factory/validators.ts"],"sourcesContent":[null],"names":["validateFunction"],"mappings":"uhCAqBA;;;;AAIG;AACU,MAAA,CAAC,GAAe;;AAE3B,IAAA,MAAM,EAAE,CAAmB,MAAS,EAAE,YAAqB,KACzD,IAAI,eAAe,CAAI,MAAM,EAAE,YAAY,CAAC;;AAG9C,IAAA,GAAG,EAAE,MAAM,IAAI,YAAY,EAAE;;AAG7B,IAAA,KAAK,EAAE,CAA0B,SAAY,EAAE,YAAqB,KAClE,IAAI,cAAc,CAAC,SAAS,EAAE,YAAY,CAEzC;;AAGH,IAAA,MAAM,EAAE,CAA0B,SAAa,EAAE,YAAqB,KACpE,IAAI,eAAe,CAAC,SAAS,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,YAAY,CAErD;;AAGH,IAAA,KAAK,EAAE,CAA4B,UAAa,EAAE,YAAqB,KACrE,IAAI,cAAc,CAAC,UAAU,EAAE,YAAY,CAE1C;;IAGH,IAAI,EAAE,CAAC,YAAqB,KAAK,IAAI,aAAa,CAAC,YAAY,CAAC;;IAGhE,MAAM,EAAE,CAAC,YAAqB,KAAK,IAAI,eAAe,CAAC,YAAY,CAAC;;AAGpE,IAAA,KAAK,EAAE,CAAC,iBAA0B,EAAE,YAAqB,KACvD,IAAI,eAAe,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;;AAG5D,IAAA,IAAI,EAAE,CAAC,MAAW,EAAE,YAAqB,KAAK,IAAI,eAAe,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC;;IAG9F,MAAM,EAAE,CAAC,YAAqB,KAAK,IAAI,eAAe,CAAC,YAAY,CAAC;;IAGpE,OAAO,EAAE,CAAC,YAAqB,KAAK,IAAI,gBAAgB,CAAC,YAAY,CAAC;;IAGtE,GAAG,EAAE,CAAC,YAAqB,KAAK,IAAI,YAAY,CAAC,YAAY,CAAC;;IAG9D,KAAK,EAAE,CAAC,YAAqB,KAAK,IAAI,cAAc,CAAC,YAAY,CAAC;;IAGlE,OAAO,EAAE,CAAC,YAAqB,KAAK,IAAI,gBAAgB,CAAC,YAAY,CAAC;;IAGtE,MAAM,EAAE,CAAC,YAAqB,KAAK,IAAI,eAAe,CAAC,YAAY,CAAC;;AAGpE,IAAA,KAAK,EAAE,CAAC,UAA2B,EAAE,YAAqB,KACxD,IAAI,cAAc,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC;;AAGtD,IAAA,QAAQ,EAAE,CACR,QAA2E,EAC3E,eAA+B,KAC5B,IAAI,iBAAiB,CAAU,QAAQ,EAAE,eAAe,CAAC;;AAG9D,IAAA,OAAO,EAAE,CACP,QAAgE,EAChE,eAA+B,KAC5B,IAAI,gBAAgB,CAAU,QAAQ,EAAE,eAAe,CAAC;;AAG7D,IAAA,QAAQ,EAAEA,QAAgB;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect if value is a date value or field name
|
|
3
|
+
*
|
|
4
|
+
* Date values:
|
|
5
|
+
* - Date instance
|
|
6
|
+
* - Number (timestamp)
|
|
7
|
+
* - String with date separators (- or /)
|
|
8
|
+
*
|
|
9
|
+
* Field names:
|
|
10
|
+
* - Strings without - or /
|
|
11
|
+
*
|
|
12
|
+
* @param value - Value to check
|
|
13
|
+
* @returns true if it's a date value, false if it's a field name
|
|
14
|
+
*/
|
|
15
|
+
export declare function isDateValue(value: any): boolean;
|
|
16
|
+
//# sourceMappingURL=date-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/date-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAM/C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect if value is a date value or field name
|
|
3
|
+
*
|
|
4
|
+
* Date values:
|
|
5
|
+
* - Date instance
|
|
6
|
+
* - Number (timestamp)
|
|
7
|
+
* - String with date separators (- or /)
|
|
8
|
+
*
|
|
9
|
+
* Field names:
|
|
10
|
+
* - Strings without - or /
|
|
11
|
+
*
|
|
12
|
+
* @param value - Value to check
|
|
13
|
+
* @returns true if it's a date value, false if it's a field name
|
|
14
|
+
*/
|
|
15
|
+
function isDateValue(value) {
|
|
16
|
+
if (value instanceof Date)
|
|
17
|
+
return true;
|
|
18
|
+
const date = new Date(value);
|
|
19
|
+
return !isNaN(date.getTime());
|
|
20
|
+
}export{isDateValue};//# sourceMappingURL=date-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-helpers.js","sources":["../../src/helpers/date-helpers.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;AAaG;AACG,SAAU,WAAW,CAAC,KAAU,EAAA;IACpC,IAAI,KAAK,YAAY,IAAI;AAAE,QAAA,OAAO,IAAI,CAAC;AAEvC,IAAA,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AAChC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FileSizeOption } from "../types/file.types";
|
|
2
|
+
export declare function resolveFileSize(size: number | FileSizeOption): number;
|
|
3
|
+
/**
|
|
4
|
+
* Convert the given size to a human size
|
|
5
|
+
* i.e 2MB, 0.5MB, 120KB, 1.5GB..etc
|
|
6
|
+
*/
|
|
7
|
+
export declare function humanizeSize(sizeInBits: number): string;
|
|
8
|
+
//# sourceMappingURL=file.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.utils.d.ts","sourceRoot":"","sources":["../../src/helpers/file.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,MAAM,CAerE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAWvD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function resolveFileSize(size) {
|
|
2
|
+
if (typeof size === "number") {
|
|
3
|
+
return size;
|
|
4
|
+
}
|
|
5
|
+
switch (size.unit) {
|
|
6
|
+
case "B":
|
|
7
|
+
return size.size;
|
|
8
|
+
case "KB":
|
|
9
|
+
return size.size * 1024;
|
|
10
|
+
case "MB":
|
|
11
|
+
return size.size * 1024 * 1024;
|
|
12
|
+
case "GB":
|
|
13
|
+
return size.size * 1024 * 1024 * 1024;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert the given size to a human size
|
|
18
|
+
* i.e 2MB, 0.5MB, 120KB, 1.5GB..etc
|
|
19
|
+
*/
|
|
20
|
+
function humanizeSize(sizeInBits) {
|
|
21
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
22
|
+
let size = sizeInBits;
|
|
23
|
+
let unitIndex = 0;
|
|
24
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
25
|
+
size /= 1024;
|
|
26
|
+
unitIndex++;
|
|
27
|
+
}
|
|
28
|
+
return `${Number.isInteger(size) ? size : size.toFixed(2)}${units[unitIndex]}`;
|
|
29
|
+
}export{humanizeSize,resolveFileSize};//# sourceMappingURL=file.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.utils.js","sources":["../../src/helpers/file.utils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEM,SAAU,eAAe,CAAC,IAA6B,EAAA;AAC3D,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AAC5B,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;IAED,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,GAAG;YACN,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,QAAA,KAAK,IAAI;AACP,YAAA,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AAC1B,QAAA,KAAK,IAAI;AACP,YAAA,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACjC,QAAA,KAAK,IAAI;YACP,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,KAAA;AACH,CAAC;AAED;;;AAGG;AACG,SAAU,YAAY,CAAC,UAAkB,EAAA;IAC7C,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtC,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,OAAO,IAAI,IAAI,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACnD,IAAI,IAAI,IAAI,CAAC;AACb,QAAA,SAAS,EAAE,CAAC;AACb,KAAA;IAED,OAAO,CAAA,EAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAG,EAAA,KAAK,CAAC,SAAS,CAAC,CAAA,CAAE,CAAC;AACjF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ContextualSchemaRule, SchemaContext } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Get field value based on scope from rule options
|
|
4
|
+
*
|
|
5
|
+
* This utility extracts a field value from either the global context or sibling context
|
|
6
|
+
* based on the `scope` option in the rule's context.
|
|
7
|
+
*
|
|
8
|
+
* @param rule - The contextual schema rule containing options with:
|
|
9
|
+
* - `field` (or custom fieldKey): The field name to extract
|
|
10
|
+
* - `scope` (optional): Either "global" (default) or "sibling"
|
|
11
|
+
* @param context - The schema validation context containing allValues and parent
|
|
12
|
+
* @param fieldKey - The key in rule.context.options that contains the field name (defaults to "field")
|
|
13
|
+
*
|
|
14
|
+
* @returns The value of the specified field from the appropriate source
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // In a validation rule with scope support:
|
|
18
|
+
* async validate(value: any, context) {
|
|
19
|
+
* const otherFieldValue = getFieldValue(this, context);
|
|
20
|
+
* // Extracts from context.allValues if scope is "global"
|
|
21
|
+
* // Extracts from context.parent if scope is "sibling"
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Using a custom field key:
|
|
26
|
+
* async validate(value: any, context) {
|
|
27
|
+
* const compareValue = getFieldValue(this, context, "compareField");
|
|
28
|
+
* // Looks for rule.context.options.compareField instead of .field
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* - **Global scope** (`scope: "global"`): Searches the entire input data (context.allValues)
|
|
33
|
+
* - **Sibling scope** (`scope: "sibling"`): Searches only within the parent object (context.parent)
|
|
34
|
+
* - Uses `@mongez/reinforcements.get()` to support nested paths (e.g., "user.email")
|
|
35
|
+
*/
|
|
36
|
+
export declare function getFieldValue(rule: ContextualSchemaRule, context: SchemaContext, fieldKey?: string): any;
|
|
37
|
+
//# sourceMappingURL=get-field-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-field-value.d.ts","sourceRoot":"","sources":["../../src/helpers/get-field-value.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,aAAa,EACtB,QAAQ,SAAU,OAMnB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {get}from'@mongez/reinforcements';/**
|
|
2
|
+
* Get field value based on scope from rule options
|
|
3
|
+
*
|
|
4
|
+
* This utility extracts a field value from either the global context or sibling context
|
|
5
|
+
* based on the `scope` option in the rule's context.
|
|
6
|
+
*
|
|
7
|
+
* @param rule - The contextual schema rule containing options with:
|
|
8
|
+
* - `field` (or custom fieldKey): The field name to extract
|
|
9
|
+
* - `scope` (optional): Either "global" (default) or "sibling"
|
|
10
|
+
* @param context - The schema validation context containing allValues and parent
|
|
11
|
+
* @param fieldKey - The key in rule.context.options that contains the field name (defaults to "field")
|
|
12
|
+
*
|
|
13
|
+
* @returns The value of the specified field from the appropriate source
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // In a validation rule with scope support:
|
|
17
|
+
* async validate(value: any, context) {
|
|
18
|
+
* const otherFieldValue = getFieldValue(this, context);
|
|
19
|
+
* // Extracts from context.allValues if scope is "global"
|
|
20
|
+
* // Extracts from context.parent if scope is "sibling"
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Using a custom field key:
|
|
25
|
+
* async validate(value: any, context) {
|
|
26
|
+
* const compareValue = getFieldValue(this, context, "compareField");
|
|
27
|
+
* // Looks for rule.context.options.compareField instead of .field
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* - **Global scope** (`scope: "global"`): Searches the entire input data (context.allValues)
|
|
32
|
+
* - **Sibling scope** (`scope: "sibling"`): Searches only within the parent object (context.parent)
|
|
33
|
+
* - Uses `@mongez/reinforcements.get()` to support nested paths (e.g., "user.email")
|
|
34
|
+
*/
|
|
35
|
+
function getFieldValue(rule, context, fieldKey = "field") {
|
|
36
|
+
const field = rule.context.options[fieldKey];
|
|
37
|
+
const scope = rule.context.options.scope || "global";
|
|
38
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
39
|
+
return get(source, field);
|
|
40
|
+
}export{getFieldValue};//# sourceMappingURL=get-field-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-field-value.js","sources":["../../src/helpers/get-field-value.ts"],"sourcesContent":[null],"names":[],"mappings":"yCAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCG;AACG,SAAU,aAAa,CAC3B,IAA0B,EAC1B,OAAsB,EACtB,QAAQ,GAAG,OAAO,EAAA;IAElB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,QAAQ,CAAC;AACrD,IAAA,MAAM,MAAM,GAAG,KAAK,KAAK,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;AACxE,IAAA,OAAO,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-empty-value.d.ts","sourceRoot":"","sources":["../../src/helpers/is-empty-value.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,WAEtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-empty-value.js","sources":["../../src/helpers/is-empty-value.ts"],"sourcesContent":[null],"names":[],"mappings":"qDAEM,SAAU,YAAY,CAAC,KAAU,EAAA;IACrC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/path-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,OAAO,MAAM,KAAG,MAGtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-helpers.js","sources":["../../src/helpers/path-helpers.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;AAEG;MACU,UAAU,GAAG,CAAC,IAAY,EAAE,GAAW,KAAY;AAC9D,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,OAAO,GAAG,CAAC;AACtB,IAAA,OAAO,CAAG,EAAA,IAAI,CAAI,CAAA,EAAA,GAAG,EAAE,CAAC;AAC1B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ContextualSchemaRule, RuleResult, SchemaContext } from "../types";
|
|
2
|
+
export declare const VALID_RULE: RuleResult;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a single attribute value through the full translation priority chain:
|
|
5
|
+
* 1. attributesList[key] — developer direct text override (highest priority)
|
|
6
|
+
* 2. translatedAttributes[key] — developer explicit translation key
|
|
7
|
+
* 3. translator(rawValue) — auto-translate the raw value (fallback)
|
|
8
|
+
*
|
|
9
|
+
* Use this in rule bodies when you need per-item translation
|
|
10
|
+
* (e.g. translating each enum value before joining them).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Translate each enum value individually then join
|
|
14
|
+
* const enumList = enumValues
|
|
15
|
+
* .map(v => resolveTranslation(String(v), String(v), this, context))
|
|
16
|
+
* .join(", ");
|
|
17
|
+
* this.context.translationParams.enumList = enumList;
|
|
18
|
+
*/
|
|
19
|
+
export declare const resolveTranslation: ({ key, rawValue, rule, context, }: {
|
|
20
|
+
key: string;
|
|
21
|
+
rawValue: any;
|
|
22
|
+
rule: ContextualSchemaRule;
|
|
23
|
+
context: SchemaContext;
|
|
24
|
+
}) => string;
|
|
25
|
+
export declare const invalidRule: (rule: ContextualSchemaRule, context: SchemaContext) => RuleResult;
|
|
26
|
+
//# sourceMappingURL=validation-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/validation-helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAmB,aAAa,EAAE,MAAM,UAAU,CAAC;AAEjG,eAAO,MAAM,UAAU,EAAE,UAExB,CAAC;AACF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB;SAMxB,MAAM;cACD,GAAG;UACP,oBAAoB;aACjB,aAAa;MACpB,MAeH,CAAC;AAKF,eAAO,MAAM,WAAW,SAAU,oBAAoB,WAAW,aAAa,KAAG,UA+ChF,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {getSealConfig}from'../config.js';const VALID_RULE = {
|
|
2
|
+
isValid: true,
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a single attribute value through the full translation priority chain:
|
|
6
|
+
* 1. attributesList[key] — developer direct text override (highest priority)
|
|
7
|
+
* 2. translatedAttributes[key] — developer explicit translation key
|
|
8
|
+
* 3. translator(rawValue) — auto-translate the raw value (fallback)
|
|
9
|
+
*
|
|
10
|
+
* Use this in rule bodies when you need per-item translation
|
|
11
|
+
* (e.g. translating each enum value before joining them).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Translate each enum value individually then join
|
|
15
|
+
* const enumList = enumValues
|
|
16
|
+
* .map(v => resolveTranslation(String(v), String(v), this, context))
|
|
17
|
+
* .join(", ");
|
|
18
|
+
* this.context.translationParams.enumList = enumList;
|
|
19
|
+
*/
|
|
20
|
+
const resolveTranslation = ({ key, rawValue, rule, context, }) => {
|
|
21
|
+
const translator = getSealConfig().translateAttribute;
|
|
22
|
+
// 1. Direct text override wins
|
|
23
|
+
const direct = rule.context.attributesList?.[key];
|
|
24
|
+
if (direct && typeof direct === "string")
|
|
25
|
+
return direct;
|
|
26
|
+
if (!translator)
|
|
27
|
+
return String(rawValue ?? key);
|
|
28
|
+
// 2. Explicit translation key
|
|
29
|
+
const transKey = rule.context.translatedAttributes?.[key];
|
|
30
|
+
if (transKey)
|
|
31
|
+
return translator({ attribute: transKey, context, rule });
|
|
32
|
+
// 3. Auto-translate the raw value (fallback)
|
|
33
|
+
return translator({ attribute: String(rawValue ?? key), context, rule });
|
|
34
|
+
};
|
|
35
|
+
// Internal alias — invalidRule uses the same function without re-importing config
|
|
36
|
+
const resolveAttribute = resolveTranslation;
|
|
37
|
+
const invalidRule = (rule, context) => {
|
|
38
|
+
// `input` is always translatable — rules may add more (e.g., field references in sameAs)
|
|
39
|
+
// Rule-defined translatableParams override the default input if the key matches
|
|
40
|
+
const translatableWithInput = {
|
|
41
|
+
// Fall back to "schema" when validating at the root level (no key)
|
|
42
|
+
input: context.key || "schema",
|
|
43
|
+
...rule.context.translatableParams,
|
|
44
|
+
};
|
|
45
|
+
// Resolve all translatable params through the full priority chain
|
|
46
|
+
const resolvedParams = Object.fromEntries(Object.entries(translatableWithInput).map(([key, rawValue]) => [
|
|
47
|
+
key,
|
|
48
|
+
resolveAttribute({ key, rawValue, rule, context }),
|
|
49
|
+
]));
|
|
50
|
+
const attributes = {
|
|
51
|
+
path: context.path,
|
|
52
|
+
key: context.key,
|
|
53
|
+
value: context.value,
|
|
54
|
+
// Raw placeholders (:enumList, :min, :max, etc.) — no translation
|
|
55
|
+
...rule.context.translationParams,
|
|
56
|
+
// Translated placeholders (:input, :field, etc.) — override raws if key collides
|
|
57
|
+
...resolvedParams,
|
|
58
|
+
// Satisfy TypeScript's required field (always present via resolvedParams)
|
|
59
|
+
input: resolvedParams.input,
|
|
60
|
+
};
|
|
61
|
+
const rawError = rule.context.errorMessage ||
|
|
62
|
+
rule.errorMessage ||
|
|
63
|
+
context.translateRule?.({ rule, context, attributes }) ||
|
|
64
|
+
rule.defaultErrorMessage;
|
|
65
|
+
// Fallback interpolation: replace :placeholder patterns from attributes
|
|
66
|
+
// This kicks in when translateRule is absent or returns "" (not configured)
|
|
67
|
+
const error = rawError.replace(/:([a-zA-Z_]+)/g, (match, key) => key in attributes ? String(attributes[key]) : match);
|
|
68
|
+
return {
|
|
69
|
+
isValid: false,
|
|
70
|
+
error,
|
|
71
|
+
input: attributes.input,
|
|
72
|
+
path: context.path,
|
|
73
|
+
};
|
|
74
|
+
};export{VALID_RULE,invalidRule,resolveTranslation};//# sourceMappingURL=validation-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-helpers.js","sources":["../../src/helpers/validation-helpers.ts"],"sourcesContent":[null],"names":[],"mappings":"yCAGa,MAAA,UAAU,GAAe;AACpC,IAAA,OAAO,EAAE,IAAI;EACb;AACF;;;;;;;;;;;;;;;AAeG;AACI,MAAM,kBAAkB,GAAG,CAAC,EACjC,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,OAAO,GAMR,KAAY;AACX,IAAA,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC,kBAAkB,CAAC;;IAGtD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,GAAG,GAAG,CAAC,CAAC;AAClD,IAAA,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;AAAE,QAAA,OAAO,MAAM,CAAC;AAExD,IAAA,IAAI,CAAC,UAAU;AAAE,QAAA,OAAO,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC,CAAC;;IAGhD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,GAAG,GAAG,CAAC,CAAC;AAC1D,IAAA,IAAI,QAAQ;AAAE,QAAA,OAAO,UAAU,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE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