@maroonedog/luq 0.1.0-alpha
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/LICENSE +9 -0
- package/README.md +879 -0
- package/dist/constants.d.ts +27 -0
- package/dist/core/async.experimental/async-context.d.ts +60 -0
- package/dist/core/builder/array-batch-optimizer.d.ts +66 -0
- package/dist/core/builder/context/field-context.d.ts +31 -0
- package/dist/core/builder/context/field-type-detector.d.ts +19 -0
- package/dist/core/builder/core/builder.d.ts +10 -0
- package/dist/core/builder/core/field-builder.d.ts +13 -0
- package/dist/core/builder/core/index.d.ts +17 -0
- package/dist/core/builder/index.d.ts +24 -0
- package/dist/core/builder/nested-array-processor.d.ts +52 -0
- package/dist/core/builder/plugins/composable-conditional-plugin.d.ts +32 -0
- package/dist/core/builder/plugins/composable-directly-plugin.d.ts +32 -0
- package/dist/core/builder/plugins/composable-plugin.d.ts +242 -0
- package/dist/core/builder/plugins/plugin-creator.d.ts +38 -0
- package/dist/core/builder/plugins/plugin-interfaces.d.ts +343 -0
- package/dist/core/builder/plugins/plugin-types.d.ts +441 -0
- package/dist/core/builder/raw-validator.d.ts +22 -0
- package/dist/core/builder/types/field-options.d.ts +46 -0
- package/dist/core/builder/types/types.d.ts +318 -0
- package/dist/core/builder/ultra-fast-validator.d.ts +30 -0
- package/dist/core/builder/validator-factory.d.ts +29 -0
- package/dist/core/global-config.d.ts +27 -0
- package/dist/core/index.d.ts +36 -0
- package/dist/core/optimization/array-batch-validator.d.ts +68 -0
- package/dist/core/optimization/core/field-utils.d.ts +103 -0
- package/dist/core/optimization/core/strategy-factory.d.ts +84 -0
- package/dist/core/optimization/core/validation-engine.d.ts +107 -0
- package/dist/core/optimization/execution-strategy-selector.d.ts +23 -0
- package/dist/core/optimization/unified-validator.d.ts +45 -0
- package/dist/core/plugin/__tests__/test-utils.d.ts +1 -0
- package/dist/core/plugin/arrayContains.d.ts +37 -0
- package/dist/core/plugin/arrayIncludes.d.ts +42 -0
- package/dist/core/plugin/arrayMaxLength.d.ts +43 -0
- package/dist/core/plugin/arrayMinLength.d.ts +43 -0
- package/dist/core/plugin/arrayUnique.d.ts +41 -0
- package/dist/core/plugin/booleanFalsy.d.ts +41 -0
- package/dist/core/plugin/booleanTruthy.d.ts +38 -0
- package/dist/core/plugin/compareField.d.ts +58 -0
- package/dist/core/plugin/conditionalSchema.d.ts +24 -0
- package/dist/core/plugin/custom.d.ts +60 -0
- package/dist/core/plugin/fromContext.d.ts +150 -0
- package/dist/core/plugin/index.d.ts +71 -0
- package/dist/core/plugin/jsonSchema/dsl-converter.d.ts +22 -0
- package/dist/core/plugin/jsonSchema/error-generation.d.ts +14 -0
- package/dist/core/plugin/jsonSchema/format-validators.d.ts +20 -0
- package/dist/core/plugin/jsonSchema/index.d.ts +11 -0
- package/dist/core/plugin/jsonSchema/plugin.d.ts +35 -0
- package/dist/core/plugin/jsonSchema/ref-resolver.d.ts +14 -0
- package/dist/core/plugin/jsonSchema/types.d.ts +69 -0
- package/dist/core/plugin/jsonSchema/validation-core.d.ts +29 -0
- package/dist/core/plugin/jsonSchemaFullFeature.d.ts +31 -0
- package/dist/core/plugin/literal.d.ts +40 -0
- package/dist/core/plugin/message-factories.d.ts +9 -0
- package/dist/core/plugin/nullable.d.ts +34 -0
- package/dist/core/plugin/numberFinite.d.ts +41 -0
- package/dist/core/plugin/numberInteger.d.ts +41 -0
- package/dist/core/plugin/numberMax.d.ts +49 -0
- package/dist/core/plugin/numberMin.d.ts +49 -0
- package/dist/core/plugin/numberMultipleOf.d.ts +42 -0
- package/dist/core/plugin/numberNegative.d.ts +41 -0
- package/dist/core/plugin/numberPositive.d.ts +41 -0
- package/dist/core/plugin/numberRange.d.ts +48 -0
- package/dist/core/plugin/object.d.ts +43 -0
- package/dist/core/plugin/objectAdditionalProperties.d.ts +51 -0
- package/dist/core/plugin/objectDependentRequired.d.ts +42 -0
- package/dist/core/plugin/objectDependentSchemas.d.ts +40 -0
- package/dist/core/plugin/objectMaxProperties.d.ts +42 -0
- package/dist/core/plugin/objectMinProperties.d.ts +42 -0
- package/dist/core/plugin/objectPatternProperties.d.ts +46 -0
- package/dist/core/plugin/objectPropertyNames.d.ts +36 -0
- package/dist/core/plugin/objectRecursively.d.ts +81 -0
- package/dist/core/plugin/oneOf.d.ts +44 -0
- package/dist/core/plugin/optional.d.ts +35 -0
- package/dist/core/plugin/optionalIf.d.ts +42 -0
- package/dist/core/plugin/orFail.d.ts +132 -0
- package/dist/core/plugin/readOnlyWriteOnly.d.ts +48 -0
- package/dist/core/plugin/required.d.ts +45 -0
- package/dist/core/plugin/requiredIf.d.ts +66 -0
- package/dist/core/plugin/shared-constants.d.ts +45 -0
- package/dist/core/plugin/shared.d.ts +3 -0
- package/dist/core/plugin/skip.d.ts +57 -0
- package/dist/core/plugin/stitch-typed.d.ts +15 -0
- package/dist/core/plugin/stitch.d.ts +1 -0
- package/dist/core/plugin/stitchSimple.d.ts +4 -0
- package/dist/core/plugin/stringAlphanumeric.d.ts +42 -0
- package/dist/core/plugin/stringBase64.d.ts +119 -0
- package/dist/core/plugin/stringContentEncoding.d.ts +43 -0
- package/dist/core/plugin/stringContentMediaType.d.ts +47 -0
- package/dist/core/plugin/stringDate.d.ts +48 -0
- package/dist/core/plugin/stringDatetime.d.ts +108 -0
- package/dist/core/plugin/stringDuration.d.ts +41 -0
- package/dist/core/plugin/stringEmail.d.ts +81 -0
- package/dist/core/plugin/stringEndsWith.d.ts +42 -0
- package/dist/core/plugin/stringExactLength.d.ts +46 -0
- package/dist/core/plugin/stringHostname.d.ts +104 -0
- package/dist/core/plugin/stringIpv4.d.ts +85 -0
- package/dist/core/plugin/stringIpv6.d.ts +104 -0
- package/dist/core/plugin/stringIri.d.ts +117 -0
- package/dist/core/plugin/stringIriReference.d.ts +43 -0
- package/dist/core/plugin/stringJsonPointer.d.ts +107 -0
- package/dist/core/plugin/stringMax.d.ts +43 -0
- package/dist/core/plugin/stringMin.d.ts +43 -0
- package/dist/core/plugin/stringPattern.d.ts +40 -0
- package/dist/core/plugin/stringRelativeJsonPointer.d.ts +42 -0
- package/dist/core/plugin/stringStartsWith.d.ts +42 -0
- package/dist/core/plugin/stringTime.d.ts +39 -0
- package/dist/core/plugin/stringUriTemplate.d.ts +43 -0
- package/dist/core/plugin/stringUrl.d.ts +97 -0
- package/dist/core/plugin/testUtils.d.ts +15 -0
- package/dist/core/plugin/transform-type-restrictions.d.ts +61 -0
- package/dist/core/plugin/transform.d.ts +35 -0
- package/dist/core/plugin/tupleBuilder.d.ts +66 -0
- package/dist/core/plugin/types.d.ts +143 -0
- package/dist/core/plugin/unionGuard.d.ts +50 -0
- package/dist/core/plugin/utils/field-accessor-optimized.d.ts +50 -0
- package/dist/core/plugin/utils/field-accessor.d.ts +107 -0
- package/dist/core/plugin/uuid.d.ts +95 -0
- package/dist/core/plugin/validateIf.d.ts +57 -0
- package/dist/core/registry/plugin-registry.d.ts +116 -0
- package/dist/core/registry.d.ts +6 -0
- package/dist/core/transform/index.d.ts +1 -0
- package/dist/core/transform/string/defaultValue.d.ts +6 -0
- package/dist/core/transform/string/index.d.ts +3 -0
- package/dist/core/transform/string/replace.d.ts +14 -0
- package/dist/core/transform/string/sanitize.d.ts +6 -0
- package/dist/core/utils/type-guards.d.ts +68 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +7 -0
- package/dist/plugins/arrayContains.d.ts +37 -0
- package/dist/plugins/arrayContains.js +1 -0
- package/dist/plugins/arrayContains.mjs +1 -0
- package/dist/plugins/arrayIncludes.d.ts +42 -0
- package/dist/plugins/arrayIncludes.js +1 -0
- package/dist/plugins/arrayIncludes.mjs +1 -0
- package/dist/plugins/arrayMaxLength.d.ts +43 -0
- package/dist/plugins/arrayMaxLength.js +1 -0
- package/dist/plugins/arrayMaxLength.mjs +1 -0
- package/dist/plugins/arrayMinLength.d.ts +43 -0
- package/dist/plugins/arrayMinLength.js +1 -0
- package/dist/plugins/arrayMinLength.mjs +1 -0
- package/dist/plugins/arrayUnique.d.ts +41 -0
- package/dist/plugins/arrayUnique.js +1 -0
- package/dist/plugins/arrayUnique.mjs +1 -0
- package/dist/plugins/booleanFalsy.d.ts +41 -0
- package/dist/plugins/booleanFalsy.js +1 -0
- package/dist/plugins/booleanFalsy.mjs +1 -0
- package/dist/plugins/booleanTruthy.d.ts +38 -0
- package/dist/plugins/booleanTruthy.js +1 -0
- package/dist/plugins/booleanTruthy.mjs +1 -0
- package/dist/plugins/compareField.d.ts +58 -0
- package/dist/plugins/compareField.js +1 -0
- package/dist/plugins/compareField.mjs +1 -0
- package/dist/plugins/custom.d.ts +60 -0
- package/dist/plugins/custom.js +1 -0
- package/dist/plugins/custom.mjs +1 -0
- package/dist/plugins/jsonSchema.d.ts +11 -0
- package/dist/plugins/jsonSchema.js +1 -0
- package/dist/plugins/jsonSchema.mjs +1 -0
- package/dist/plugins/jsonSchemaFullFeature.d.ts +31 -0
- package/dist/plugins/jsonSchemaFullFeature.js +1 -0
- package/dist/plugins/jsonSchemaFullFeature.mjs +1 -0
- package/dist/plugins/literal.d.ts +40 -0
- package/dist/plugins/literal.js +1 -0
- package/dist/plugins/literal.mjs +1 -0
- package/dist/plugins/nullable.d.ts +34 -0
- package/dist/plugins/nullable.js +1 -0
- package/dist/plugins/nullable.mjs +1 -0
- package/dist/plugins/numberInteger.d.ts +41 -0
- package/dist/plugins/numberInteger.js +1 -0
- package/dist/plugins/numberInteger.mjs +1 -0
- package/dist/plugins/numberMax.d.ts +49 -0
- package/dist/plugins/numberMax.js +1 -0
- package/dist/plugins/numberMax.mjs +1 -0
- package/dist/plugins/numberMin.d.ts +49 -0
- package/dist/plugins/numberMin.js +1 -0
- package/dist/plugins/numberMin.mjs +1 -0
- package/dist/plugins/numberMultipleOf.d.ts +42 -0
- package/dist/plugins/numberMultipleOf.js +1 -0
- package/dist/plugins/numberMultipleOf.mjs +1 -0
- package/dist/plugins/numberNegative.d.ts +41 -0
- package/dist/plugins/numberNegative.js +1 -0
- package/dist/plugins/numberNegative.mjs +1 -0
- package/dist/plugins/numberPositive.d.ts +41 -0
- package/dist/plugins/numberPositive.js +1 -0
- package/dist/plugins/numberPositive.mjs +1 -0
- package/dist/plugins/object.d.ts +43 -0
- package/dist/plugins/object.js +1 -0
- package/dist/plugins/object.mjs +1 -0
- package/dist/plugins/objectAdditionalProperties.d.ts +51 -0
- package/dist/plugins/objectAdditionalProperties.js +1 -0
- package/dist/plugins/objectAdditionalProperties.mjs +1 -0
- package/dist/plugins/objectDependentRequired.d.ts +42 -0
- package/dist/plugins/objectDependentRequired.js +1 -0
- package/dist/plugins/objectDependentRequired.mjs +1 -0
- package/dist/plugins/objectDependentSchemas.d.ts +40 -0
- package/dist/plugins/objectDependentSchemas.js +1 -0
- package/dist/plugins/objectDependentSchemas.mjs +1 -0
- package/dist/plugins/objectMaxProperties.d.ts +42 -0
- package/dist/plugins/objectMaxProperties.js +1 -0
- package/dist/plugins/objectMaxProperties.mjs +1 -0
- package/dist/plugins/objectMinProperties.d.ts +42 -0
- package/dist/plugins/objectMinProperties.js +1 -0
- package/dist/plugins/objectMinProperties.mjs +1 -0
- package/dist/plugins/objectPatternProperties.d.ts +46 -0
- package/dist/plugins/objectPatternProperties.js +1 -0
- package/dist/plugins/objectPatternProperties.mjs +1 -0
- package/dist/plugins/objectPropertyNames.d.ts +36 -0
- package/dist/plugins/objectPropertyNames.js +1 -0
- package/dist/plugins/objectPropertyNames.mjs +1 -0
- package/dist/plugins/oneOf.d.ts +44 -0
- package/dist/plugins/oneOf.js +1 -0
- package/dist/plugins/oneOf.mjs +1 -0
- package/dist/plugins/optional.d.ts +35 -0
- package/dist/plugins/optional.js +1 -0
- package/dist/plugins/optional.mjs +1 -0
- package/dist/plugins/readOnlyWriteOnly.d.ts +48 -0
- package/dist/plugins/readOnlyWriteOnly.js +1 -0
- package/dist/plugins/readOnlyWriteOnly.mjs +1 -0
- package/dist/plugins/required.d.ts +45 -0
- package/dist/plugins/required.js +1 -0
- package/dist/plugins/required.mjs +1 -0
- package/dist/plugins/requiredIf.d.ts +66 -0
- package/dist/plugins/requiredIf.js +1 -0
- package/dist/plugins/requiredIf.mjs +1 -0
- package/dist/plugins/skip.d.ts +57 -0
- package/dist/plugins/skip.js +1 -0
- package/dist/plugins/skip.mjs +1 -0
- package/dist/plugins/stringBase64.d.ts +119 -0
- package/dist/plugins/stringBase64.js +1 -0
- package/dist/plugins/stringBase64.mjs +1 -0
- package/dist/plugins/stringContentEncoding.d.ts +43 -0
- package/dist/plugins/stringContentEncoding.js +1 -0
- package/dist/plugins/stringContentEncoding.mjs +1 -0
- package/dist/plugins/stringContentMediaType.d.ts +47 -0
- package/dist/plugins/stringContentMediaType.js +1 -0
- package/dist/plugins/stringContentMediaType.mjs +1 -0
- package/dist/plugins/stringDate.d.ts +48 -0
- package/dist/plugins/stringDate.js +1 -0
- package/dist/plugins/stringDate.mjs +1 -0
- package/dist/plugins/stringDatetime.d.ts +108 -0
- package/dist/plugins/stringDatetime.js +1 -0
- package/dist/plugins/stringDatetime.mjs +1 -0
- package/dist/plugins/stringDuration.d.ts +41 -0
- package/dist/plugins/stringDuration.js +1 -0
- package/dist/plugins/stringDuration.mjs +1 -0
- package/dist/plugins/stringEmail.d.ts +81 -0
- package/dist/plugins/stringEmail.js +1 -0
- package/dist/plugins/stringEmail.mjs +1 -0
- package/dist/plugins/stringHostname.d.ts +104 -0
- package/dist/plugins/stringHostname.js +1 -0
- package/dist/plugins/stringHostname.mjs +1 -0
- package/dist/plugins/stringIpv4.d.ts +85 -0
- package/dist/plugins/stringIpv4.js +1 -0
- package/dist/plugins/stringIpv4.mjs +1 -0
- package/dist/plugins/stringIpv6.d.ts +104 -0
- package/dist/plugins/stringIpv6.js +1 -0
- package/dist/plugins/stringIpv6.mjs +1 -0
- package/dist/plugins/stringIri.d.ts +117 -0
- package/dist/plugins/stringIri.js +1 -0
- package/dist/plugins/stringIri.mjs +1 -0
- package/dist/plugins/stringIriReference.d.ts +43 -0
- package/dist/plugins/stringIriReference.js +1 -0
- package/dist/plugins/stringIriReference.mjs +1 -0
- package/dist/plugins/stringJsonPointer.d.ts +107 -0
- package/dist/plugins/stringJsonPointer.js +1 -0
- package/dist/plugins/stringJsonPointer.mjs +1 -0
- package/dist/plugins/stringMax.d.ts +43 -0
- package/dist/plugins/stringMax.js +1 -0
- package/dist/plugins/stringMax.mjs +1 -0
- package/dist/plugins/stringMin.d.ts +43 -0
- package/dist/plugins/stringMin.js +1 -0
- package/dist/plugins/stringMin.mjs +1 -0
- package/dist/plugins/stringPattern.d.ts +40 -0
- package/dist/plugins/stringPattern.js +1 -0
- package/dist/plugins/stringPattern.mjs +1 -0
- package/dist/plugins/stringRelativeJsonPointer.d.ts +42 -0
- package/dist/plugins/stringRelativeJsonPointer.js +1 -0
- package/dist/plugins/stringRelativeJsonPointer.mjs +1 -0
- package/dist/plugins/stringTime.d.ts +39 -0
- package/dist/plugins/stringTime.js +1 -0
- package/dist/plugins/stringTime.mjs +1 -0
- package/dist/plugins/stringUriTemplate.d.ts +43 -0
- package/dist/plugins/stringUriTemplate.js +1 -0
- package/dist/plugins/stringUriTemplate.mjs +1 -0
- package/dist/plugins/stringUrl.d.ts +97 -0
- package/dist/plugins/stringUrl.js +1 -0
- package/dist/plugins/stringUrl.mjs +1 -0
- package/dist/plugins/transform.d.ts +35 -0
- package/dist/plugins/transform.js +1 -0
- package/dist/plugins/transform.mjs +1 -0
- package/dist/plugins/tupleBuilder.d.ts +66 -0
- package/dist/plugins/tupleBuilder.js +1 -0
- package/dist/plugins/tupleBuilder.mjs +1 -0
- package/dist/plugins/uuid.d.ts +95 -0
- package/dist/plugins/uuid.js +1 -0
- package/dist/plugins/uuid.mjs +1 -0
- package/dist/plugins/validateIf.d.ts +57 -0
- package/dist/plugins/validateIf.js +1 -0
- package/dist/plugins/validateIf.mjs +1 -0
- package/dist/types/array-type-analysis.d.ts +115 -0
- package/dist/types/index.d.ts +74 -0
- package/dist/types/indexed-result.d.ts +44 -0
- package/dist/types/result.d.ts +159 -0
- package/dist/types/stitch-types.d.ts +118 -0
- package/dist/types/util.d.ts +19 -0
- package/dist/types/valitator.d.ts +10 -0
- package/package.json +353 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
export declare const RECURSIVE_SELF: "__Self";
|
|
3
|
+
export declare const RECURSIVE_ELEMENT: "__Element";
|
|
4
|
+
type RecursiveKeyword = typeof RECURSIVE_SELF | typeof RECURSIVE_ELEMENT;
|
|
5
|
+
interface RecursiveOptions<TFieldPath extends RecursiveKeyword> extends ValidationOptions<{
|
|
6
|
+
targetPath: RecursiveKeyword;
|
|
7
|
+
}> {
|
|
8
|
+
targetFieldPath: TFieldPath;
|
|
9
|
+
maxDepth?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @luq-plugin
|
|
13
|
+
* @name objectRecursively
|
|
14
|
+
* @category standard
|
|
15
|
+
* @description Applies validation rules recursively to nested fields or array elements
|
|
16
|
+
* @allowedTypes ["object"]
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Self-referential structure using __Self
|
|
20
|
+
* type TreeNode = {
|
|
21
|
+
* id: string;
|
|
22
|
+
* name: string;
|
|
23
|
+
* value: number;
|
|
24
|
+
* parent?: TreeNode;
|
|
25
|
+
* left?: TreeNode;
|
|
26
|
+
* right?: TreeNode;
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* const validator = Builder()
|
|
30
|
+
* .use(objectRecursivelyPlugin)
|
|
31
|
+
* .for<TreeNode>()
|
|
32
|
+
* .v("id", b => b.string.required())
|
|
33
|
+
* .v("name", b => b.string.required().min(3))
|
|
34
|
+
* .v("value", b => b.number.required().min(0))
|
|
35
|
+
* .v("parent", b => b.object.optional().recursively("__Self"))
|
|
36
|
+
* .v("left", b => b.object.optional().recursively("__Self"))
|
|
37
|
+
* .v("right", b => b.object.optional().recursively("__Self"))
|
|
38
|
+
* .build();
|
|
39
|
+
*
|
|
40
|
+
* // Array elements using __Element
|
|
41
|
+
* type Category = {
|
|
42
|
+
* id: number;
|
|
43
|
+
* name: string;
|
|
44
|
+
* description?: string;
|
|
45
|
+
* parentCategory?: Category;
|
|
46
|
+
* subcategories: Category[];
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* const categoryValidator = Builder()
|
|
50
|
+
* .use(objectRecursivelyPlugin)
|
|
51
|
+
* .for<Category>()
|
|
52
|
+
* .v("id", b => b.number.required().min(1))
|
|
53
|
+
* .v("name", b => b.string.required())
|
|
54
|
+
* .v("description", b => b.string.optional())
|
|
55
|
+
* .v("parentCategory", b => b.object.optional().recursively("__Self"))
|
|
56
|
+
* .v("subcategories", b => b.array.required())
|
|
57
|
+
* .v("subcategories[*]", b => b.object.recursively("__Element"))
|
|
58
|
+
* .build();
|
|
59
|
+
* ```
|
|
60
|
+
* @params
|
|
61
|
+
* - targetFieldPath: string | "__Self" | "__Element" - Special keywords or field path
|
|
62
|
+
* - options?: { maxDepth?: number } - Optional configuration for recursion depth
|
|
63
|
+
* @returns Validation function that marks object for recursive validation
|
|
64
|
+
* @customError
|
|
65
|
+
* ```typescript
|
|
66
|
+
* This plugin does not generate errors - it enables recursive validation
|
|
67
|
+
* ```
|
|
68
|
+
* @since 0.1.0-alpha
|
|
69
|
+
*/
|
|
70
|
+
export declare const objectRecursivelyPlugin: import("../..").TypedPlugin<"recursively", "recursively", (targetFieldPath: RecursiveKeyword, options?: Omit<RecursiveOptions<RecursiveKeyword>, "targetFieldPath">) => {
|
|
71
|
+
check: (value: any) => boolean;
|
|
72
|
+
code: string;
|
|
73
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
74
|
+
params: (RecursiveKeyword | Omit<RecursiveOptions<RecursiveKeyword>, "targetFieldPath">)[];
|
|
75
|
+
__isRecursive: boolean;
|
|
76
|
+
recursive: {
|
|
77
|
+
targetFieldPath: RecursiveKeyword;
|
|
78
|
+
maxDepth: number;
|
|
79
|
+
};
|
|
80
|
+
}, readonly ["object"], "validator", "standard">;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name oneOf
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a value is one of the specified allowed values (enum-like validation)
|
|
7
|
+
* @allowedTypes ["string", "number", "boolean"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // String enum validation
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(oneOfPlugin)
|
|
13
|
+
* .for<FormData>()
|
|
14
|
+
* .v("status", (b) => b.string.oneOf(["active", "inactive", "pending"]))
|
|
15
|
+
* .v("role", (b) => b.string.oneOf(["admin", "user", "guest"]))
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // Number enum validation
|
|
19
|
+
* builder.v("priority", b => b.number.oneOf([0, 1, 2, 3]))
|
|
20
|
+
*
|
|
21
|
+
* // With TypeScript const for type safety
|
|
22
|
+
* const ROLES = ["admin", "user", "guest"] as const;
|
|
23
|
+
* builder.v("userRole", b => b.string.oneOf(ROLES))
|
|
24
|
+
* ```
|
|
25
|
+
* @params
|
|
26
|
+
* - allowed: Array<string | number | boolean> - Array of allowed values
|
|
27
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
28
|
+
* @returns Validation function that returns true if value is in the allowed list
|
|
29
|
+
* @customError
|
|
30
|
+
* ```typescript
|
|
31
|
+
* .oneOf(["A", "B", "C"], {
|
|
32
|
+
* messageFactory: ({ path, value, params }) =>
|
|
33
|
+
* `${path} must be one of: ${params.allowed.join(", ")} (received: ${value})`
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
* @since 0.1.0-alpha
|
|
37
|
+
*/
|
|
38
|
+
export declare const oneOfPlugin: import("../..").TypedPlugin<"oneOf", "oneOf", (allowedValues: readonly any[], options?: ValidationOptions) => {
|
|
39
|
+
check: (value: any) => boolean;
|
|
40
|
+
code: string;
|
|
41
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
42
|
+
params: (any[] | ValidationOptions<{}>)[];
|
|
43
|
+
allowedValues: readonly any[];
|
|
44
|
+
}, readonly ["string", "number", "boolean"], "validator", "standard">;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name optional
|
|
4
|
+
* @category standard
|
|
5
|
+
* @description Allows a field to be undefined (but not null or empty string)
|
|
6
|
+
* @allowedTypes ["string", "number", "boolean", "array", "object", "date", "union"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Basic usage - field can be undefined
|
|
10
|
+
* const validator = Builder()
|
|
11
|
+
* .use(optionalPlugin)
|
|
12
|
+
* .for<UserProfile>()
|
|
13
|
+
* .v("nickname", (b) => b.string.optional().min(3))
|
|
14
|
+
* .v("age", (b) => b.number.optional().min(0))
|
|
15
|
+
* .build();
|
|
16
|
+
*
|
|
17
|
+
* // Arrays and objects can be optional
|
|
18
|
+
* builder.v("hobbies", b => b.array.optional().minLength(1))
|
|
19
|
+
* builder.v("settings", b => b.object.optional())
|
|
20
|
+
* ```
|
|
21
|
+
* @params
|
|
22
|
+
* No parameters - this is a modifier plugin
|
|
23
|
+
* @returns Validation function that returns true and skips further validation if value is undefined
|
|
24
|
+
* @customError
|
|
25
|
+
* This plugin does not generate errors - it allows undefined values
|
|
26
|
+
* @since 0.1.0-alpha
|
|
27
|
+
*/
|
|
28
|
+
export declare const optionalPlugin: import("../..").TypedPlugin<"optional", "optional", () => {
|
|
29
|
+
check: (value: any) => boolean;
|
|
30
|
+
code: string;
|
|
31
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
32
|
+
params: any[];
|
|
33
|
+
isOptional: boolean;
|
|
34
|
+
skipForUndefined: boolean;
|
|
35
|
+
}, readonly ["string", "number", "boolean", "array", "object", "date", "union"], "validator", "standard">;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
export interface OptionalIfContext extends MessageContext {
|
|
3
|
+
condition?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @luq-plugin
|
|
7
|
+
* @name optionalIf
|
|
8
|
+
* @category conditional
|
|
9
|
+
* @description Makes a field optional based on a dynamic condition evaluated at validation time, with support for array context validation
|
|
10
|
+
* @allowedTypes ["string", "number", "boolean", "array", "object", "date", "union"]
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Basic conditional optional
|
|
14
|
+
* const validator = Builder()
|
|
15
|
+
* .use(optionalIfPlugin)
|
|
16
|
+
* .for<UserForm>()
|
|
17
|
+
* .v("middleName", (b) =>
|
|
18
|
+
* b.string.optionalIf(values => !values.includeMiddleName).min(2)
|
|
19
|
+
* )
|
|
20
|
+
* .build();
|
|
21
|
+
*
|
|
22
|
+
* // Phone optional if email provided
|
|
23
|
+
* builder.v("phone", b =>
|
|
24
|
+
* b.string.optionalIf(values => !!values.email).pattern(/^\d{10}$/)
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
* @params
|
|
28
|
+
* - condition: (allValues: TObject, arrayContext?: ArrayContext) => boolean - Condition function that determines if field is optional, with access to array context
|
|
29
|
+
* @returns Validation function that skips validation when condition is true and value is empty
|
|
30
|
+
* @customError
|
|
31
|
+
* This plugin does not generate errors - it conditionally allows empty values
|
|
32
|
+
* @since 0.1.0-alpha
|
|
33
|
+
*/
|
|
34
|
+
export declare const optionalIfPlugin: import("../..").TypedPlugin<"optionalIf", "optionalIf", <TObject>(condition: (allValues: TObject, arrayContext?: import("./types").ArrayContext) => boolean, options?: ValidationOptions<OptionalIfContext>) => {
|
|
35
|
+
check: (value: any, allValues?: TObject, arrayContext?: import("./types").ArrayContext) => boolean;
|
|
36
|
+
code: string;
|
|
37
|
+
getErrorMessage: (value: any, path: string, allValues?: TObject, arrayContext?: import("./types").ArrayContext) => string;
|
|
38
|
+
params: (((allValues: TObject, arrayContext?: import("./types").ArrayContext) => boolean) | ValidationOptions<OptionalIfContext>)[];
|
|
39
|
+
isOptional: boolean;
|
|
40
|
+
skipForUndefined: boolean;
|
|
41
|
+
shouldSkipValidation: (value: any, allValues?: TObject, arrayContext?: import("./types").ArrayContext) => boolean;
|
|
42
|
+
}, readonly ["string", "number", "boolean", "array", "object", "date", "union"], "validator", "conditional">;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name orFail
|
|
5
|
+
* @category conditional
|
|
6
|
+
* @description Conditionally forces validation to fail with a custom error message
|
|
7
|
+
* @allowedTypes ["string", "number", "boolean", "array", "object", "date", "union", "tuple"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - fails when condition is true
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(orFailPlugin)
|
|
13
|
+
* .for<FormData>()
|
|
14
|
+
* .v("deprecated", (b) => b.string.orFail(
|
|
15
|
+
* values => values.useDeprecatedField === true,
|
|
16
|
+
* { messageFactory: ({ path }) => `${path} is deprecated and should not be used` }
|
|
17
|
+
* ))
|
|
18
|
+
* .build();
|
|
19
|
+
*
|
|
20
|
+
* // Environment-based validation
|
|
21
|
+
* builder.v("debugData", b =>
|
|
22
|
+
* b.object.orFail(
|
|
23
|
+
* values => values.environment === 'production',
|
|
24
|
+
* { messageFactory: ({ path }) => `${path} should not be present in production` }
|
|
25
|
+
* )
|
|
26
|
+
* )
|
|
27
|
+
*
|
|
28
|
+
* // Feature flag based
|
|
29
|
+
* builder.v("betaFeature", b =>
|
|
30
|
+
* b.string.orFail(
|
|
31
|
+
* values => !values.betaEnabled,
|
|
32
|
+
* { messageFactory: ({ path }) => `${path} requires beta features to be enabled` }
|
|
33
|
+
* )
|
|
34
|
+
* )
|
|
35
|
+
* ```
|
|
36
|
+
* @params
|
|
37
|
+
* - condition: (allValues: TObject) => boolean - Condition that determines if validation should fail
|
|
38
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration with custom message factory
|
|
39
|
+
* @returns Validation function that fails when condition is true
|
|
40
|
+
* @customError
|
|
41
|
+
* ```typescript
|
|
42
|
+
* .orFail(
|
|
43
|
+
* values => values.isRestricted,
|
|
44
|
+
* {
|
|
45
|
+
* messageFactory: ({ path, value }) => `${path} is restricted for this user (value: ${value})`
|
|
46
|
+
* }
|
|
47
|
+
* )
|
|
48
|
+
* ```
|
|
49
|
+
* @since 0.1.0-alpha
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* Conditionally forces validation to fail with a custom error message based on form state.
|
|
53
|
+
* This plugin is useful for marking fields as deprecated, temporarily disabled,
|
|
54
|
+
* or for implementing strict validation rules during development.
|
|
55
|
+
*
|
|
56
|
+
* Usage:
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Mark deprecated fields based on version
|
|
59
|
+
* builder.v("oldApiKey", b =>
|
|
60
|
+
* b.string.orFail(
|
|
61
|
+
* values => values.apiVersion >= 2,
|
|
62
|
+
* { message: "This field is deprecated. Use 'apiToken' instead" }
|
|
63
|
+
* )
|
|
64
|
+
* )
|
|
65
|
+
*
|
|
66
|
+
* // Temporarily disable fields based on feature flags
|
|
67
|
+
* builder.v("experimentalFeature", b =>
|
|
68
|
+
* b.object.orFail(
|
|
69
|
+
* values => !values.features?.experimental,
|
|
70
|
+
* { message: "This feature is temporarily disabled" }
|
|
71
|
+
* )
|
|
72
|
+
* )
|
|
73
|
+
*
|
|
74
|
+
* // Strict validation in production
|
|
75
|
+
* builder.v("debugInfo", b =>
|
|
76
|
+
* b.object.orFail(
|
|
77
|
+
* values => values.environment === 'production',
|
|
78
|
+
* { message: "Debug information should not be included in production" }
|
|
79
|
+
* )
|
|
80
|
+
* )
|
|
81
|
+
*
|
|
82
|
+
* // Role-based restrictions
|
|
83
|
+
* builder.v("adminSettings", b =>
|
|
84
|
+
* b.object.orFail(
|
|
85
|
+
* values => values.userRole !== 'admin',
|
|
86
|
+
* { message: "Admin settings can only be modified by administrators" }
|
|
87
|
+
* )
|
|
88
|
+
* )
|
|
89
|
+
*
|
|
90
|
+
* // Combine with other validations
|
|
91
|
+
* builder.v("restrictedField", b =>
|
|
92
|
+
* b.string
|
|
93
|
+
* .min(10)
|
|
94
|
+
* .pattern(/^RESTRICTED-/)
|
|
95
|
+
* .orFail(
|
|
96
|
+
* values => !values.hasPermission,
|
|
97
|
+
* { message: "This field requires special permissions" }
|
|
98
|
+
* )
|
|
99
|
+
* )
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* Note: When condition evaluates to true, the field will be invalid regardless of its value.
|
|
103
|
+
* This is useful for conditional restrictions and dynamic validation rules.
|
|
104
|
+
*/
|
|
105
|
+
export declare const orFailPlugin: import("../..").TypedPlugin<"orFail", "orFail", <TObject = any>(condition: (allValues: TObject) => boolean, options?: ValidationOptions & {
|
|
106
|
+
messageFactory?: (context: MessageContext) => string;
|
|
107
|
+
message?: string;
|
|
108
|
+
}) => {
|
|
109
|
+
check: (value: any, allValues?: TObject) => boolean;
|
|
110
|
+
code: string;
|
|
111
|
+
getErrorMessage: (value: any, path: string, allValues?: TObject) => string;
|
|
112
|
+
params: (((allValues: TObject) => boolean) | (ValidationOptions<{}> & {
|
|
113
|
+
messageFactory?: (context: MessageContext) => string;
|
|
114
|
+
message?: string;
|
|
115
|
+
}))[];
|
|
116
|
+
__isOrFail: boolean;
|
|
117
|
+
__condition: (allValues: TObject) => boolean;
|
|
118
|
+
orFail: {
|
|
119
|
+
condition: (allValues: TObject) => boolean;
|
|
120
|
+
message: string;
|
|
121
|
+
options: ValidationOptions<{}> & {
|
|
122
|
+
messageFactory?: (context: MessageContext) => string;
|
|
123
|
+
message?: string;
|
|
124
|
+
};
|
|
125
|
+
performOrFailValidation: (value: any, ctx: any) => Readonly<{
|
|
126
|
+
valid: true;
|
|
127
|
+
}> | {
|
|
128
|
+
valid: boolean;
|
|
129
|
+
message: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
}, readonly ["string", "number", "boolean", "array", "object", "date", "union", "tuple"], "validator", "conditional">;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name readOnlyWriteOnly
|
|
4
|
+
* @category context
|
|
5
|
+
* @description Validates fields based on read-only or write-only context
|
|
6
|
+
* @allowedTypes ["string", "number", "boolean", "date", "array", "object"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Read-only field (should not be modified after creation)
|
|
10
|
+
* const validator = Builder()
|
|
11
|
+
* .use(readOnlyWriteOnlyPlugin)
|
|
12
|
+
* .for<{ id: string; name: string; }>()
|
|
13
|
+
* .v("id", (b) => b.string.readOnly())
|
|
14
|
+
* .v("name", (b) => b.string.required())
|
|
15
|
+
* .build();
|
|
16
|
+
*
|
|
17
|
+
* // Write-only field (e.g., password that shouldn't be read back)
|
|
18
|
+
* builder.v("password", b => b.string.writeOnly())
|
|
19
|
+
*
|
|
20
|
+
* // With operation context
|
|
21
|
+
* const result = validator.validate(data, {
|
|
22
|
+
* context: { operation: "read" } // or "write"
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
* @params
|
|
26
|
+
* - mode?: "readOnly" | "writeOnly" - The access mode for the field
|
|
27
|
+
* - options?: { errorMessage?: string } - Optional configuration
|
|
28
|
+
* @returns Validation function that checks field access based on context
|
|
29
|
+
* @since 0.1.0-alpha
|
|
30
|
+
*/
|
|
31
|
+
export interface ReadOnlyWriteOnlyOptions {
|
|
32
|
+
/** Custom error message */
|
|
33
|
+
errorMessage?: string;
|
|
34
|
+
/** Whether to skip validation entirely for inaccessible fields */
|
|
35
|
+
skipValidation?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const readOnlyWriteOnlyPlugin: import("../..").TypedPlugin<"readOnlyWriteOnly", "readOnly", (options?: ReadOnlyWriteOnlyOptions) => {
|
|
38
|
+
check: (value: any, allValues: any, context?: any) => boolean;
|
|
39
|
+
code: string;
|
|
40
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
41
|
+
params: (string | ReadOnlyWriteOnlyOptions)[];
|
|
42
|
+
}, readonly ["string", "number", "boolean", "date", "array", "object"], "validator", "context">;
|
|
43
|
+
export declare const writeOnlyPlugin: import("../..").TypedPlugin<"writeOnly", "writeOnly", (options?: ReadOnlyWriteOnlyOptions) => {
|
|
44
|
+
check: (value: any, allValues: any, context?: any) => boolean;
|
|
45
|
+
code: string;
|
|
46
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
47
|
+
params: (string | ReadOnlyWriteOnlyOptions)[];
|
|
48
|
+
}, readonly ["string", "number", "boolean", "date", "array", "object"], "validator", "context">;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name required
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a field is required (not null, undefined, or empty string)
|
|
7
|
+
* @allowedTypes ["string", "number", "boolean", "date", "array", "object", "tuple", "union"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(requiredPlugin)
|
|
13
|
+
* .for<UserProfile>()
|
|
14
|
+
* .v("name", (b) => b.string.required())
|
|
15
|
+
* .v("age", (b) => b.number.required())
|
|
16
|
+
* .v("terms", (b) => b.boolean.required())
|
|
17
|
+
* .build();
|
|
18
|
+
*
|
|
19
|
+
* // Custom error message
|
|
20
|
+
* builder.v("email", b => b.string.required({
|
|
21
|
+
* messageFactory: ({ path }) => `${path} is required`
|
|
22
|
+
* }))
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - messageFactory?: (context: MessageContext) => string - Custom error message factory
|
|
26
|
+
* @returns Validation function that returns true if value exists (not null/undefined/empty string)
|
|
27
|
+
* @customError
|
|
28
|
+
* ```typescript
|
|
29
|
+
* .required({
|
|
30
|
+
* messageFactory: ({ path, value }) =>
|
|
31
|
+
* `${path} field is required (current value: ${value})`
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
* @since 0.1.0-alpha
|
|
35
|
+
*/
|
|
36
|
+
export declare const requiredPlugin: import("../..").TypedPlugin<"required", "required", (options?: ValidationOptions & {
|
|
37
|
+
allowNull?: boolean;
|
|
38
|
+
}) => {
|
|
39
|
+
check: (value: any) => boolean;
|
|
40
|
+
code: string;
|
|
41
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
42
|
+
params: (ValidationOptions<{}> & {
|
|
43
|
+
allowNull?: boolean;
|
|
44
|
+
})[];
|
|
45
|
+
}, readonly ["array", "boolean", "number", "object", "string", "date", "union", "tuple"], "validator", "standard">;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
export interface RequiredIfContext extends MessageContext {
|
|
3
|
+
condition?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @luq-plugin
|
|
7
|
+
* @name requiredIf
|
|
8
|
+
* @category conditional
|
|
9
|
+
* @description Makes a field required based on a dynamic condition evaluated at validation time, with support for array context validation
|
|
10
|
+
* @allowedTypes ["string", "number", "boolean", "array", "object", "date", "union"]
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Basic conditional required
|
|
14
|
+
* const validator = Builder()
|
|
15
|
+
* .use(requiredIfPlugin)
|
|
16
|
+
* .for<ContactForm>()
|
|
17
|
+
* .v("email", (b) => b.string.requiredIf(values => values.contactMethod === 'email'))
|
|
18
|
+
* .v("phone", (b) => b.string.requiredIf(values => values.contactMethod === 'phone'))
|
|
19
|
+
* .build();
|
|
20
|
+
*
|
|
21
|
+
* // Multiple conditions
|
|
22
|
+
* builder.v("ssn", b =>
|
|
23
|
+
* b.string.requiredIf(values =>
|
|
24
|
+
* values.country === 'US' && values.employmentType === 'full-time'
|
|
25
|
+
* )
|
|
26
|
+
* )
|
|
27
|
+
*
|
|
28
|
+
* // Array context validation - conditional required within array items
|
|
29
|
+
* builder.v("items[].billingAddress", b =>
|
|
30
|
+
* b.string.requiredIf((allValues, arrayContext) => {
|
|
31
|
+
* // arrayContext.index: current index in array
|
|
32
|
+
* // arrayContext.item: current object at index
|
|
33
|
+
* // arrayContext.array: full array
|
|
34
|
+
* return arrayContext?.item?.type === 'premium';
|
|
35
|
+
* })
|
|
36
|
+
* )
|
|
37
|
+
*
|
|
38
|
+
* // Mixed validation - access both form values and array context
|
|
39
|
+
* builder.v("orders[].shippingAddress", b =>
|
|
40
|
+
* b.string.requiredIf((allValues, arrayContext) => {
|
|
41
|
+
* const isInternational = allValues.country !== 'US';
|
|
42
|
+
* const requiresShipping = arrayContext?.item?.requiresShipping;
|
|
43
|
+
* return isInternational && requiresShipping;
|
|
44
|
+
* })
|
|
45
|
+
* )
|
|
46
|
+
* ```
|
|
47
|
+
* @params
|
|
48
|
+
* - condition: (allValues: TObject, arrayContext?: ArrayContext) => boolean - Condition function that receives all form values and optional array context
|
|
49
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
50
|
+
* @returns Validation function that checks if field is required based on condition
|
|
51
|
+
* @customError
|
|
52
|
+
* ```typescript
|
|
53
|
+
* .requiredIf(
|
|
54
|
+
* (values, arrayContext) => values.hasAccount && arrayContext?.item?.isActive,
|
|
55
|
+
* { messageFactory: ({ path }) => `${path} is required when account exists and item is active` }
|
|
56
|
+
* )
|
|
57
|
+
* ```
|
|
58
|
+
* @since 0.1.0-alpha
|
|
59
|
+
*/
|
|
60
|
+
export declare const requiredIfPlugin: import("../..").TypedPlugin<"requiredIf", "requiredIf", <TObject>(condition: (allValues: TObject, arrayContext?: import("./types").ArrayContext) => boolean, options?: ValidationOptions<RequiredIfContext>) => {
|
|
61
|
+
check: (value: any, allValues?: TObject, arrayContext?: import("./types").ArrayContext) => boolean;
|
|
62
|
+
code: string;
|
|
63
|
+
getErrorMessage: (value: any, path: string, allValues?: TObject, arrayContext?: import("./types").ArrayContext) => string;
|
|
64
|
+
params: (((allValues: TObject, arrayContext?: import("./types").ArrayContext) => boolean) | ValidationOptions<RequiredIfContext>)[];
|
|
65
|
+
evaluateCondition: (allValues?: TObject, arrayContext?: import("./types").ArrayContext) => boolean;
|
|
66
|
+
}, readonly ["string", "number", "boolean", "array", "object", "date", "union"], "validator", "conditional">;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared constants for all plugins
|
|
3
|
+
* V8 Optimization: Frozen objects for better performance
|
|
4
|
+
*/
|
|
5
|
+
export declare const VALID_RESULT: Readonly<{
|
|
6
|
+
valid: true;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const INVALID_RESULT: Readonly<{
|
|
9
|
+
valid: false;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const ERROR_SEVERITY: "ERROR";
|
|
12
|
+
/**
|
|
13
|
+
* Common error codes
|
|
14
|
+
*/
|
|
15
|
+
export declare const ErrorCodes: {
|
|
16
|
+
readonly MIN_VALUE: "min_value";
|
|
17
|
+
readonly MAX_VALUE: "max_value";
|
|
18
|
+
readonly MIN_LENGTH: "min_length";
|
|
19
|
+
readonly MAX_LENGTH: "max_length";
|
|
20
|
+
readonly EXACT_LENGTH: "exact_length";
|
|
21
|
+
readonly RANGE: "range";
|
|
22
|
+
readonly REQUIRED: "required";
|
|
23
|
+
readonly INVALID_TYPE: "invalid_type";
|
|
24
|
+
readonly INVALID_FORMAT: "invalid_format";
|
|
25
|
+
readonly INVALID_EMAIL: "invalid_email";
|
|
26
|
+
readonly INVALID_URL: "invalid_url";
|
|
27
|
+
readonly INVALID_UUID: "invalid_uuid";
|
|
28
|
+
readonly INVALID_DATETIME: "invalid_datetime";
|
|
29
|
+
readonly INVALID_PATTERN: "invalid_pattern";
|
|
30
|
+
readonly NOT_INTEGER: "not_integer";
|
|
31
|
+
readonly NOT_FINITE: "not_finite";
|
|
32
|
+
readonly NOT_POSITIVE: "not_positive";
|
|
33
|
+
readonly NOT_NEGATIVE: "not_negative";
|
|
34
|
+
readonly NOT_MULTIPLE: "not_multiple";
|
|
35
|
+
readonly NOT_UNIQUE: "not_unique";
|
|
36
|
+
readonly MISSING_REQUIRED: "missing_required";
|
|
37
|
+
readonly NOT_TRUTHY: "not_truthy";
|
|
38
|
+
readonly NOT_FALSY: "not_falsy";
|
|
39
|
+
readonly NOT_EQUAL: "not_equal";
|
|
40
|
+
readonly VALIDATION_ERROR: "validation_error";
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Type for error codes
|
|
44
|
+
*/
|
|
45
|
+
export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name skip
|
|
5
|
+
* @category conditional
|
|
6
|
+
* @description Completely skips validation for a field based on a dynamic condition
|
|
7
|
+
* @allowedTypes ["string", "number", "boolean", "array", "object", "date", "union"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Skip validation when not needed
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(skipPlugin)
|
|
13
|
+
* .for<FormData>()
|
|
14
|
+
* .v("advancedOptions", b =>
|
|
15
|
+
* b.object
|
|
16
|
+
* .skip(values => !values.showAdvanced)
|
|
17
|
+
* .required()
|
|
18
|
+
* )
|
|
19
|
+
* .build();
|
|
20
|
+
*
|
|
21
|
+
* // Skip debug fields in production
|
|
22
|
+
* builder.v("debugInfo", b =>
|
|
23
|
+
* b.string
|
|
24
|
+
* .skip(values => values.environment === 'production')
|
|
25
|
+
* .min(10)
|
|
26
|
+
* )
|
|
27
|
+
*
|
|
28
|
+
* // Skip entire sections conditionally
|
|
29
|
+
* builder.v("enterpriseSettings", b =>
|
|
30
|
+
* b.object
|
|
31
|
+
* .skip(values => values.plan !== 'enterprise')
|
|
32
|
+
* .recursively()
|
|
33
|
+
* )
|
|
34
|
+
* ```
|
|
35
|
+
* @params
|
|
36
|
+
* - condition: (allValues: TObject) => boolean - Function that returns true if field should be skipped
|
|
37
|
+
* - options?: ValidationOptions - Optional configuration
|
|
38
|
+
* @returns Validation function that skips field entirely when condition is true
|
|
39
|
+
* @customError
|
|
40
|
+
* ```typescript
|
|
41
|
+
* This plugin does not generate errors - it removes fields from validation
|
|
42
|
+
* ```
|
|
43
|
+
* @since 0.1.0-alpha
|
|
44
|
+
*/
|
|
45
|
+
export declare const skipPlugin: import("../..").TypedPlugin<"skip", "skip", <TObject>(condition: (allValues: TObject) => boolean, options?: ValidationOptions) => {
|
|
46
|
+
check: (value: any, allValues?: TObject) => boolean;
|
|
47
|
+
shouldSkipAllValidation: (value: any, allValues?: TObject) => boolean;
|
|
48
|
+
code: string;
|
|
49
|
+
getErrorMessage: () => string;
|
|
50
|
+
params: (ValidationOptions<{}> | ((allValues: TObject) => boolean))[];
|
|
51
|
+
metadata: {
|
|
52
|
+
type: string;
|
|
53
|
+
category: string;
|
|
54
|
+
skipCondition: (allValues: TObject) => boolean;
|
|
55
|
+
async: boolean;
|
|
56
|
+
};
|
|
57
|
+
}, readonly ["string", "number", "boolean", "array", "object", "date", "union"], "validator", "conditional">;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe Stitch Plugin with explicit type signatures
|
|
3
|
+
*/
|
|
4
|
+
import { NestedKeyOf } from "./types";
|
|
5
|
+
import { TypeSafeStitchOptions } from "../../types/stitch-types";
|
|
6
|
+
import { ValidatorFormat } from "../builder/plugins/plugin-interfaces";
|
|
7
|
+
/**
|
|
8
|
+
* Create a type-safe stitch validator
|
|
9
|
+
* This function preserves all generic type parameters
|
|
10
|
+
*/
|
|
11
|
+
export declare function createStitchValidator<TObject, TCurrentField, const TFields extends readonly (NestedKeyOf<TObject> & string)[]>(options: TypeSafeStitchOptions<TObject, TCurrentField, TFields>): ValidatorFormat;
|
|
12
|
+
/**
|
|
13
|
+
* Stitch plugin with proper type inference
|
|
14
|
+
*/
|
|
15
|
+
export declare const stitchPluginTyped: import("../..").TypedPlugin<"stitch", "stitch", any, readonly ["string", "number", "boolean", "date", "object", "array", "tuple", "union"], "validator", "multiFieldReference">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stitchPlugin: import("../..").TypedPlugin<"stitch", "stitch", any, readonly ["string", "number", "boolean", "date", "object", "array", "tuple", "union"], "validator", "multiFieldReference">;
|