@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,60 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name custom
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Allows custom validation logic
|
|
7
|
+
* @allowedTypes ["string", "number", "boolean", "date", "array", "object", "tuple", "union"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic custom validation
|
|
11
|
+
* builder.v("username", b => b.string
|
|
12
|
+
* .custom((value) => {
|
|
13
|
+
* return !reservedUsernames.includes(value);
|
|
14
|
+
* }, {
|
|
15
|
+
* code: 'RESERVED_USERNAME',
|
|
16
|
+
* messageFactory: ({ path }) => `${path} username is reserved`
|
|
17
|
+
* })
|
|
18
|
+
* )
|
|
19
|
+
*
|
|
20
|
+
* // With access to all values
|
|
21
|
+
* builder.v("confirmPassword", b => b.string
|
|
22
|
+
* .custom((value, rootData) => {
|
|
23
|
+
* return value === rootData.password;
|
|
24
|
+
* }, {
|
|
25
|
+
* code: 'PASSWORD_MISMATCH',
|
|
26
|
+
* messageFactory: ({ path }) => `${path} passwords do not match`
|
|
27
|
+
* })
|
|
28
|
+
* )
|
|
29
|
+
* ```
|
|
30
|
+
* @params
|
|
31
|
+
* - validator: (value: any, rootData?: any) => boolean - Custom validation function
|
|
32
|
+
* - options?: { code?: string; messageFactory?: (context: MessageContext) => string } - Error customization
|
|
33
|
+
* @returns Validation function with custom logic
|
|
34
|
+
* @customError
|
|
35
|
+
* ```typescript
|
|
36
|
+
* .custom(
|
|
37
|
+
* (value) => value.length > 5,
|
|
38
|
+
* {
|
|
39
|
+
* messageFactory: ({ path, value }) =>
|
|
40
|
+
* `${path} custom validation failed (received: ${value})`
|
|
41
|
+
* }
|
|
42
|
+
* )
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const customPlugin: import("../..").TypedPlugin<"custom", "custom", (validator: (value: any, rootData?: any) => boolean | {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
message?: string;
|
|
48
|
+
}, options?: ValidationOptions & {
|
|
49
|
+
messageFactory?: (context: MessageContext) => string;
|
|
50
|
+
}) => {
|
|
51
|
+
check: (value: any, rootData?: any) => boolean;
|
|
52
|
+
code: string;
|
|
53
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
54
|
+
params: (((value: any, rootData?: any) => boolean | {
|
|
55
|
+
valid: boolean;
|
|
56
|
+
message?: string;
|
|
57
|
+
}) | (ValidationOptions<{}> & {
|
|
58
|
+
messageFactory?: (context: MessageContext) => string;
|
|
59
|
+
}))[];
|
|
60
|
+
}, readonly ["string", "number", "boolean", "date", "array", "object", "tuple", "union"], "validator", "standard">;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fromContext Plugin - Context-based validation
|
|
3
|
+
*
|
|
4
|
+
* Generic plugin that can uniformly handle async context,
|
|
5
|
+
* allValues, and other context data
|
|
6
|
+
*/
|
|
7
|
+
import type { ContextValidationOptions } from "../builder/plugins/plugin-interfaces";
|
|
8
|
+
/**
|
|
9
|
+
* @luq-plugin
|
|
10
|
+
* @name fromContext
|
|
11
|
+
* @category context
|
|
12
|
+
* @description Validation using context data (async context, allValues, etc.)
|
|
13
|
+
* @allowedTypes ["string", "number", "boolean", "object", "array", "date", "union", "tuple"]
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Basic usage
|
|
17
|
+
* const validator = Builder()
|
|
18
|
+
* .use(fromContextPlugin)
|
|
19
|
+
* .for<{ email: string }>()
|
|
20
|
+
* .v("email", (b) => b.string.required().fromContext({
|
|
21
|
+
* validate: (email, context) => ({
|
|
22
|
+
* valid: !context.hasEmail,
|
|
23
|
+
* message: "Email already exists"
|
|
24
|
+
* }),
|
|
25
|
+
* required: true
|
|
26
|
+
* }))
|
|
27
|
+
* .build();
|
|
28
|
+
*
|
|
29
|
+
* // Combination with async context
|
|
30
|
+
* const asyncContext = createAsyncContext<{ hasEmail: boolean }>()
|
|
31
|
+
* .set("hasEmail", checkEmailExists(email))
|
|
32
|
+
* .build();
|
|
33
|
+
*
|
|
34
|
+
* const result = await validator
|
|
35
|
+
* .withAsyncContext<{ hasEmail: boolean }>(asyncContext)
|
|
36
|
+
* .validate({ email: "test@example.com" });
|
|
37
|
+
*
|
|
38
|
+
* // Cross-field validation (using allValues)
|
|
39
|
+
* builder.v("confirmPassword", b => b.string.fromContext({
|
|
40
|
+
* validate: (confirmPassword, context, allValues) => ({
|
|
41
|
+
* valid: allValues.password === confirmPassword,
|
|
42
|
+
* message: "Password confirmation does not match"
|
|
43
|
+
* }),
|
|
44
|
+
* required: false // Async context not needed when using allValues
|
|
45
|
+
* }))
|
|
46
|
+
* ```
|
|
47
|
+
* @params
|
|
48
|
+
* - validate: (value, context, allValues) => { valid: boolean; message?: string } - Validation function
|
|
49
|
+
* - errorMessage?: string - Custom error message
|
|
50
|
+
* - required?: boolean - Whether context data is required (default: false)
|
|
51
|
+
* - fallbackToValid?: boolean - Whether to consider valid when no context (default: true)
|
|
52
|
+
* @returns Validation result using context data
|
|
53
|
+
* @since 0.1.0-alpha
|
|
54
|
+
*/
|
|
55
|
+
export declare const fromContextPlugin: import("../..").TypedPlugin<"fromContext", "fromContext", <TContext = Record<string, any>>(options: ContextValidationOptions<TContext>) => {
|
|
56
|
+
check: (value: any, allValues?: any) => boolean;
|
|
57
|
+
code: string;
|
|
58
|
+
getErrorMessage: (value: any, path: string, allValues?: any) => string;
|
|
59
|
+
params: ContextValidationOptions<TContext>[];
|
|
60
|
+
__isFromContext: boolean;
|
|
61
|
+
__contextOptions: ContextValidationOptions<TContext>;
|
|
62
|
+
fromContext: {
|
|
63
|
+
options: ContextValidationOptions<TContext>;
|
|
64
|
+
required: boolean;
|
|
65
|
+
fallbackToValid: boolean;
|
|
66
|
+
errorMessage: string;
|
|
67
|
+
performContextValidation: (value: any, ctx: any) => {
|
|
68
|
+
valid: boolean;
|
|
69
|
+
message: string;
|
|
70
|
+
} | {
|
|
71
|
+
valid: boolean;
|
|
72
|
+
message?: undefined;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}, readonly ["string", "number", "boolean", "object", "array", "date", "union", "tuple"], "validator", "context">;
|
|
76
|
+
/**
|
|
77
|
+
* Convenient helper functions
|
|
78
|
+
*/
|
|
79
|
+
/**
|
|
80
|
+
* fromContext options for email duplication check
|
|
81
|
+
*/
|
|
82
|
+
export declare function emailDuplicationCheck(): ContextValidationOptions<{
|
|
83
|
+
hasEmail: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* fromContext options for password confirmation check
|
|
87
|
+
*/
|
|
88
|
+
export declare function passwordConfirmation(): ContextValidationOptions<any>;
|
|
89
|
+
/**
|
|
90
|
+
* fromContext options for inventory check
|
|
91
|
+
*/
|
|
92
|
+
export declare function inventoryCheck(): ContextValidationOptions<{
|
|
93
|
+
inventory: Array<{
|
|
94
|
+
productId: string;
|
|
95
|
+
available: number;
|
|
96
|
+
}>;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* fromContext options for conditional validation
|
|
100
|
+
*/
|
|
101
|
+
export declare function conditionalRequired<T>(condition: (context: T, allValues: any) => boolean, message?: string): ContextValidationOptions<T>;
|
|
102
|
+
/**
|
|
103
|
+
* Type-safe fromContext helper
|
|
104
|
+
*/
|
|
105
|
+
export declare function createTypedContextValidator<TValue, TContext>(options: ContextValidationOptions<TContext>): ContextValidationOptions<TContext>;
|
|
106
|
+
/**
|
|
107
|
+
* Usage example templates
|
|
108
|
+
*/
|
|
109
|
+
export declare const ContextValidationTemplates: {
|
|
110
|
+
/**
|
|
111
|
+
* Email duplication check
|
|
112
|
+
*/
|
|
113
|
+
emailDuplication: () => ContextValidationOptions<{
|
|
114
|
+
hasEmail: boolean;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* Password confirmation
|
|
118
|
+
*/
|
|
119
|
+
passwordConfirmation: () => ContextValidationOptions<any>;
|
|
120
|
+
/**
|
|
121
|
+
* Inventory check
|
|
122
|
+
*/
|
|
123
|
+
inventoryCheck: () => ContextValidationOptions<{
|
|
124
|
+
inventory: Array<{
|
|
125
|
+
productId: string;
|
|
126
|
+
available: number;
|
|
127
|
+
}>;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* User permission check
|
|
131
|
+
*/
|
|
132
|
+
userPermission: <T extends {
|
|
133
|
+
userRole: string;
|
|
134
|
+
requiredRole: string;
|
|
135
|
+
}>() => ContextValidationOptions<T>;
|
|
136
|
+
/**
|
|
137
|
+
* Account limits check
|
|
138
|
+
*/
|
|
139
|
+
accountLimits: <T extends {
|
|
140
|
+
currentCount: number;
|
|
141
|
+
maxCount: number;
|
|
142
|
+
}>() => ContextValidationOptions<T>;
|
|
143
|
+
/**
|
|
144
|
+
* Geo restriction check
|
|
145
|
+
*/
|
|
146
|
+
geoRestriction: <T extends {
|
|
147
|
+
country: string;
|
|
148
|
+
allowedCountries: string[];
|
|
149
|
+
}>() => ContextValidationOptions<T>;
|
|
150
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export { requiredPlugin } from "./required";
|
|
2
|
+
export { optionalPlugin } from "./optional";
|
|
3
|
+
export { nullablePlugin } from "./nullable";
|
|
4
|
+
export { requiredIfPlugin } from "./requiredIf";
|
|
5
|
+
export { optionalIfPlugin } from "./optionalIf";
|
|
6
|
+
export { skipPlugin } from "./skip";
|
|
7
|
+
export { validateIfPlugin } from "./validateIf";
|
|
8
|
+
export { orFailPlugin } from "./orFail";
|
|
9
|
+
export { oneOfPlugin } from "./oneOf";
|
|
10
|
+
export { literalPlugin } from "./literal";
|
|
11
|
+
export { compareFieldPlugin } from "./compareField";
|
|
12
|
+
export { customPlugin } from "./custom";
|
|
13
|
+
export { stitchPlugin } from "./stitch";
|
|
14
|
+
export { stringMinPlugin } from "./stringMin";
|
|
15
|
+
export { stringMaxPlugin } from "./stringMax";
|
|
16
|
+
export { stringExactLengthPlugin } from "./stringExactLength";
|
|
17
|
+
export { stringPatternPlugin } from "./stringPattern";
|
|
18
|
+
export { stringEmailPlugin } from "./stringEmail";
|
|
19
|
+
export { stringUrlPlugin } from "./stringUrl";
|
|
20
|
+
export { stringAlphanumericPlugin } from "./stringAlphanumeric";
|
|
21
|
+
export { stringStartsWithPlugin } from "./stringStartsWith";
|
|
22
|
+
export { stringEndsWithPlugin } from "./stringEndsWith";
|
|
23
|
+
export { stringDatetimePlugin } from "./stringDatetime";
|
|
24
|
+
export { stringDatePlugin } from "./stringDate";
|
|
25
|
+
export { uuidPlugin } from "./uuid";
|
|
26
|
+
export { stringIpv4Plugin } from "./stringIpv4";
|
|
27
|
+
export { stringIpv6Plugin } from "./stringIpv6";
|
|
28
|
+
export { stringHostnamePlugin } from "./stringHostname";
|
|
29
|
+
export { stringTimePlugin } from "./stringTime";
|
|
30
|
+
export { stringDurationPlugin } from "./stringDuration";
|
|
31
|
+
export { stringJsonPointerPlugin } from "./stringJsonPointer";
|
|
32
|
+
export { stringBase64Plugin } from "./stringBase64";
|
|
33
|
+
export { stringIriPlugin } from "./stringIri";
|
|
34
|
+
export { stringIriReferencePlugin } from "./stringIriReference";
|
|
35
|
+
export { stringUriTemplatePlugin } from "./stringUriTemplate";
|
|
36
|
+
export { stringRelativeJsonPointerPlugin } from "./stringRelativeJsonPointer";
|
|
37
|
+
export { stringContentEncodingPlugin } from "./stringContentEncoding";
|
|
38
|
+
export { stringContentMediaTypePlugin } from "./stringContentMediaType";
|
|
39
|
+
export { numberMinPlugin } from "./numberMin";
|
|
40
|
+
export { numberMaxPlugin } from "./numberMax";
|
|
41
|
+
export { numberPositivePlugin } from "./numberPositive";
|
|
42
|
+
export { numberNegativePlugin } from "./numberNegative";
|
|
43
|
+
export { numberIntegerPlugin } from "./numberInteger";
|
|
44
|
+
export { numberFinitePlugin } from "./numberFinite";
|
|
45
|
+
export { numberMultipleOfPlugin } from "./numberMultipleOf";
|
|
46
|
+
export { numberRangePlugin } from "./numberRange";
|
|
47
|
+
export { booleanTruthyPlugin } from "./booleanTruthy";
|
|
48
|
+
export { booleanFalsyPlugin } from "./booleanFalsy";
|
|
49
|
+
export { arrayIncludesPlugin } from "./arrayIncludes";
|
|
50
|
+
export { arrayUniquePlugin } from "./arrayUnique";
|
|
51
|
+
export { arrayMinLengthPlugin } from "./arrayMinLength";
|
|
52
|
+
export { arrayMaxLengthPlugin } from "./arrayMaxLength";
|
|
53
|
+
export { objectPlugin } from "./object";
|
|
54
|
+
export { objectRecursivelyPlugin as recursivelyPlugin } from "./objectRecursively";
|
|
55
|
+
export { objectRecursivelyPlugin } from "./objectRecursively";
|
|
56
|
+
export { objectMinPropertiesPlugin } from "./objectMinProperties";
|
|
57
|
+
export { objectMaxPropertiesPlugin } from "./objectMaxProperties";
|
|
58
|
+
export { objectAdditionalPropertiesPlugin } from "./objectAdditionalProperties";
|
|
59
|
+
export { transformPlugin } from "./transform";
|
|
60
|
+
export { unionGuardPlugin } from "./unionGuard";
|
|
61
|
+
export { tupleBuilderPlugin } from "./tupleBuilder";
|
|
62
|
+
export { fromContextPlugin } from "./fromContext";
|
|
63
|
+
export { jsonSchemaPlugin } from "./jsonSchema/index";
|
|
64
|
+
export { jsonSchemaFullFeaturePlugin } from "./jsonSchemaFullFeature";
|
|
65
|
+
export { arrayContainsPlugin } from "./arrayContains";
|
|
66
|
+
export { objectPropertyNamesPlugin } from "./objectPropertyNames";
|
|
67
|
+
export { objectPatternPropertiesPlugin } from "./objectPatternProperties";
|
|
68
|
+
export { objectDependentRequiredPlugin } from "./objectDependentRequired";
|
|
69
|
+
export { objectDependentSchemasPlugin } from "./objectDependentSchemas";
|
|
70
|
+
export { readOnlyWriteOnlyPlugin } from "./readOnlyWriteOnly";
|
|
71
|
+
export type { ValidationFunction, TransformFunction } from "./types";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
import { LuqFieldDSL, LuqConstraints } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* DSL conversion utilities
|
|
5
|
+
* Convert JSON Schema to Luq DSL and back
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Convert JSON Schema to Luq DSL field definitions
|
|
9
|
+
*/
|
|
10
|
+
export declare const convertJsonSchemaToLuqDSL: (schema: JSONSchema7, parentPath?: string, rootSchema?: JSONSchema7) => LuqFieldDSL[];
|
|
11
|
+
/**
|
|
12
|
+
* Convert DSL field definition to builder function
|
|
13
|
+
*/
|
|
14
|
+
export declare const convertDSLToFieldDefinition: (dsl: LuqFieldDSL, customFormats?: Record<string, (value: any) => boolean>) => (builder: any) => any;
|
|
15
|
+
/**
|
|
16
|
+
* Apply base type to builder chain
|
|
17
|
+
*/
|
|
18
|
+
export declare const applyBaseType: (chain: any, type: LuqFieldDSL["type"]) => any;
|
|
19
|
+
/**
|
|
20
|
+
* Apply constraints to builder chain
|
|
21
|
+
*/
|
|
22
|
+
export declare const applyConstraints: (chain: any, constraints: LuqConstraints, customFormats?: Record<string, (value: any) => boolean>) => any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
import { ValidationError } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* JSON Schema validation error generation
|
|
5
|
+
* Functions for generating detailed validation error messages
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generate detailed validation errors for a value against a schema
|
|
9
|
+
*/
|
|
10
|
+
export declare const getDetailedValidationErrors: (value: any, schema: JSONSchema7 | boolean, customFormats?: Record<string, (value: string) => boolean>, rootSchema?: JSONSchema7, path?: string) => ValidationError[];
|
|
11
|
+
/**
|
|
12
|
+
* Get validation errors for specific path only
|
|
13
|
+
*/
|
|
14
|
+
export declare const getSpecificValidationErrors: (value: any, schema: JSONSchema7 | boolean, targetPath: string, customFormats?: Record<string, (value: string) => boolean>, rootSchema?: JSONSchema7) => ValidationError[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema format validation utilities
|
|
3
|
+
* Pure functions for various string format validations
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Format validation functions
|
|
7
|
+
*/
|
|
8
|
+
export declare const formatValidators: Record<string, (value: string) => boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Validate a string value against a format
|
|
11
|
+
*/
|
|
12
|
+
export declare const validateFormat: (value: string, format: string, customFormats?: Record<string, (value: string) => boolean>) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Get all supported format names
|
|
15
|
+
*/
|
|
16
|
+
export declare const getSupportedFormats: () => string[];
|
|
17
|
+
/**
|
|
18
|
+
* Check if a format is supported
|
|
19
|
+
*/
|
|
20
|
+
export declare const isFormatSupported: (format: string) => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JsonSchema Plugin - Main Entry Point
|
|
3
|
+
* Modular JSON Schema to Luq validator conversion
|
|
4
|
+
*/
|
|
5
|
+
export { LuqFieldDSL, LuqConstraints, JsonSchemaOptions, ValidationError } from "./types";
|
|
6
|
+
export { resolveRef, resolveSchemaRef, resolveAllRefs } from "./ref-resolver";
|
|
7
|
+
export { formatValidators, validateFormat, getSupportedFormats, isFormatSupported } from "./format-validators";
|
|
8
|
+
export { validateValueAgainstSchema, validateType, validateMultipleTypes, validateStringConstraints, validateNumberConstraints, validateArrayConstraints, validateObjectConstraints } from "./validation-core";
|
|
9
|
+
export { getDetailedValidationErrors, getSpecificValidationErrors } from "./error-generation";
|
|
10
|
+
export { convertJsonSchemaToLuqDSL, convertDSLToFieldDefinition, applyConstraints, applyBaseType, applyBaseType as getBaseChain } from "./dsl-converter";
|
|
11
|
+
export { jsonSchemaPlugin } from "./plugin";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
import type { BuilderExtensionPlugin, FieldBuilder } from "../../builder/plugins/plugin-types";
|
|
3
|
+
import { JsonSchemaOptions } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* @luq-plugin
|
|
6
|
+
* @name jsonSchema
|
|
7
|
+
* @category builder-extension
|
|
8
|
+
* @description Enables JSON Schema to Luq validator conversion
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(jsonSchemaPlugin)
|
|
13
|
+
* .use(requiredPlugin)
|
|
14
|
+
* .use(stringMinPlugin)
|
|
15
|
+
* .use(stringEmailPlugin)
|
|
16
|
+
* .for<UserData>()
|
|
17
|
+
* .fromJsonSchema({
|
|
18
|
+
* type: 'object',
|
|
19
|
+
* properties: {
|
|
20
|
+
* email: { type: 'string', format: 'email' },
|
|
21
|
+
* age: { type: 'number', minimum: 18 }
|
|
22
|
+
* },
|
|
23
|
+
* required: ['email']
|
|
24
|
+
* })
|
|
25
|
+
* .build();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* JSON Schema integration plugin for Luq
|
|
30
|
+
*/
|
|
31
|
+
export declare const jsonSchemaPlugin: BuilderExtensionPlugin<"jsonSchema", "fromJsonSchema", <TBuilder extends FieldBuilder<any, any, any, any>>(schema: JSONSchema7 | unknown, options?: JsonSchemaOptions) => TBuilder>;
|
|
32
|
+
export { validateValueAgainstSchema } from "./validation-core";
|
|
33
|
+
export { getDetailedValidationErrors, getSpecificValidationErrors, } from "./error-generation";
|
|
34
|
+
export { convertJsonSchemaToLuqDSL, convertDSLToFieldDefinition, } from "./dsl-converter";
|
|
35
|
+
export { resolveRef } from "./ref-resolver";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
/**
|
|
3
|
+
* Schema reference resolution utilities
|
|
4
|
+
* Pure functions for resolving JSON Schema $ref
|
|
5
|
+
*/
|
|
6
|
+
export declare const resolveRef: (ref: string, rootSchema: JSONSchema7, definitions?: Record<string, JSONSchema7>) => JSONSchema7;
|
|
7
|
+
/**
|
|
8
|
+
* Check if schema has $ref and resolve it
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolveSchemaRef: (schema: JSONSchema7, rootSchema?: JSONSchema7, definitions?: Record<string, JSONSchema7>) => JSONSchema7;
|
|
11
|
+
/**
|
|
12
|
+
* Recursively resolve all $refs in a schema
|
|
13
|
+
*/
|
|
14
|
+
export declare const resolveAllRefs: (schema: JSONSchema7, rootSchema: JSONSchema7, visited?: Set<string>) => JSONSchema7;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
/**
|
|
3
|
+
* DSL representation for field definitions
|
|
4
|
+
* Extracted from main jsonSchema.ts for better testability
|
|
5
|
+
*/
|
|
6
|
+
export interface LuqFieldDSL {
|
|
7
|
+
path: string;
|
|
8
|
+
type: "string" | "number" | "boolean" | "date" | "array" | "object" | "null" | "tuple";
|
|
9
|
+
nullable?: boolean;
|
|
10
|
+
multipleTypes?: string[];
|
|
11
|
+
allowedProperties?: string[];
|
|
12
|
+
constraints: LuqConstraints;
|
|
13
|
+
}
|
|
14
|
+
export interface LuqConstraints {
|
|
15
|
+
required?: boolean;
|
|
16
|
+
min?: number;
|
|
17
|
+
max?: number;
|
|
18
|
+
exclusiveMin?: number | boolean;
|
|
19
|
+
exclusiveMax?: number | boolean;
|
|
20
|
+
multipleOf?: number;
|
|
21
|
+
minLength?: number;
|
|
22
|
+
maxLength?: number;
|
|
23
|
+
pattern?: string;
|
|
24
|
+
format?: string;
|
|
25
|
+
contentEncoding?: string;
|
|
26
|
+
contentMediaType?: string;
|
|
27
|
+
enum?: any[];
|
|
28
|
+
const?: any;
|
|
29
|
+
integer?: boolean;
|
|
30
|
+
items?: JSONSchema7 | JSONSchema7[];
|
|
31
|
+
contains?: JSONSchema7;
|
|
32
|
+
minItems?: number;
|
|
33
|
+
maxItems?: number;
|
|
34
|
+
uniqueItems?: boolean;
|
|
35
|
+
additionalProperties?: boolean | JSONSchema7;
|
|
36
|
+
propertyNames?: JSONSchema7;
|
|
37
|
+
patternProperties?: Record<string, any>;
|
|
38
|
+
dependentRequired?: Record<string, string[]>;
|
|
39
|
+
minProperties?: number;
|
|
40
|
+
maxProperties?: number;
|
|
41
|
+
allOf?: JSONSchema7[];
|
|
42
|
+
anyOf?: JSONSchema7[];
|
|
43
|
+
oneOf?: JSONSchema7[];
|
|
44
|
+
not?: JSONSchema7;
|
|
45
|
+
if?: JSONSchema7;
|
|
46
|
+
then?: JSONSchema7;
|
|
47
|
+
else?: JSONSchema7;
|
|
48
|
+
conditionalValidation?: {
|
|
49
|
+
if: JSONSchema7;
|
|
50
|
+
then?: JSONSchema7;
|
|
51
|
+
else?: JSONSchema7;
|
|
52
|
+
};
|
|
53
|
+
requiredIf?: {
|
|
54
|
+
condition: JSONSchema7;
|
|
55
|
+
parentPath: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface JsonSchemaOptions {
|
|
59
|
+
strictRequired?: boolean;
|
|
60
|
+
allowAdditionalProperties?: boolean;
|
|
61
|
+
customFormats?: Record<string, (value: any) => boolean>;
|
|
62
|
+
}
|
|
63
|
+
export interface ValidationError {
|
|
64
|
+
path: string;
|
|
65
|
+
message: string;
|
|
66
|
+
code: string;
|
|
67
|
+
value?: any;
|
|
68
|
+
constraint?: any;
|
|
69
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
/**
|
|
3
|
+
* Type validation functions
|
|
4
|
+
*/
|
|
5
|
+
export declare const validateType: (value: any, type: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Validate value against multiple types (JSON Schema type array)
|
|
8
|
+
*/
|
|
9
|
+
export declare const validateMultipleTypes: (value: any, types: string[]) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validate string constraints
|
|
12
|
+
*/
|
|
13
|
+
export declare const validateStringConstraints: (value: string, schema: JSONSchema7, customFormats?: Record<string, (value: string) => boolean>) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Validate number constraints (including integer)
|
|
16
|
+
*/
|
|
17
|
+
export declare const validateNumberConstraints: (value: number, schema: JSONSchema7) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Validate array constraints
|
|
20
|
+
*/
|
|
21
|
+
export declare const validateArrayConstraints: (value: any[], schema: JSONSchema7, customFormats?: Record<string, (value: string) => boolean>, rootSchema?: JSONSchema7) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Validate object constraints
|
|
24
|
+
*/
|
|
25
|
+
export declare const validateObjectConstraints: (value: Record<string, any>, schema: JSONSchema7, customFormats?: Record<string, (value: string) => boolean>, rootSchema?: JSONSchema7) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Main validation function
|
|
28
|
+
*/
|
|
29
|
+
export declare const validateValueAgainstSchema: (value: any, schema: JSONSchema7, customFormats?: Record<string, (value: string) => boolean>, rootSchema?: JSONSchema7) => boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BuilderExtensionPlugin, FieldBuilder } from "../builder/plugins/plugin-types";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
import type { JsonSchemaOptions } from "./jsonSchema/types";
|
|
4
|
+
/**
|
|
5
|
+
* @luq-plugin
|
|
6
|
+
* @name jsonSchemaFullFeature
|
|
7
|
+
* @category builder-extension
|
|
8
|
+
* @description Complete JSON Schema support with all necessary plugins pre-loaded
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Single plugin import for full JSON Schema support
|
|
12
|
+
* const validator = Builder()
|
|
13
|
+
* .use(jsonSchemaFullFeaturePlugin)
|
|
14
|
+
* .fromJsonSchema({
|
|
15
|
+
* type: 'object',
|
|
16
|
+
* properties: {
|
|
17
|
+
* email: { type: 'string', format: 'email' },
|
|
18
|
+
* age: { type: 'number', minimum: 18 },
|
|
19
|
+
* roles: {
|
|
20
|
+
* type: 'array',
|
|
21
|
+
* items: { type: 'string' },
|
|
22
|
+
* uniqueItems: true
|
|
23
|
+
* }
|
|
24
|
+
* },
|
|
25
|
+
* required: ['email'],
|
|
26
|
+
* additionalProperties: false
|
|
27
|
+
* })
|
|
28
|
+
* .build();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const jsonSchemaFullFeaturePlugin: BuilderExtensionPlugin<"jsonSchemaFullFeature", "fromJsonSchema", <TBuilder extends FieldBuilder<any, any, any, any>>(schema: JSONSchema7 | unknown, options?: JsonSchemaOptions) => TBuilder>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name literal
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a value exactly matches a specific literal value
|
|
7
|
+
* @allowedTypes ["string", "number", "boolean", "null"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // String literal - exact value match
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(literalPlugin)
|
|
13
|
+
* .for<Config>()
|
|
14
|
+
* .v("type", (b) => b.string.literal("user"))
|
|
15
|
+
* .v("version", (b) => b.string.literal("v1"))
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // Number and boolean literals
|
|
19
|
+
* builder.v("maxRetries", b => b.number.literal(3))
|
|
20
|
+
* builder.v("enabled", b => b.boolean.literal(true))
|
|
21
|
+
* ```
|
|
22
|
+
* @params
|
|
23
|
+
* - expected: string | number | boolean | null - The exact value to match
|
|
24
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
25
|
+
* @returns Validation function that returns true only if value exactly matches expected
|
|
26
|
+
* @customError
|
|
27
|
+
* ```typescript
|
|
28
|
+
* .literal("active", {
|
|
29
|
+
* messageFactory: ({ path, value, params }) =>
|
|
30
|
+
* `${path} must be exactly "${params.expected}" (received: "${value}")`
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
* @since 0.1.0-alpha
|
|
34
|
+
*/
|
|
35
|
+
export declare const literalPlugin: import("../..").TypedPlugin<"literal", "literal", <TValue extends string | number | boolean | null>(expectedValue: TValue, options?: ValidationOptions) => {
|
|
36
|
+
check: (value: any) => boolean;
|
|
37
|
+
code: string;
|
|
38
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
39
|
+
params: (ValidationOptions<{}> | TValue)[];
|
|
40
|
+
}, readonly ["string", "number", "boolean", "null"], "validator", "standard">;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal message factory implementation
|
|
3
|
+
* Provides basic resolveMessage function for reporter.ts
|
|
4
|
+
*/
|
|
5
|
+
import { MessageFactory, MessageContext } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Helper to resolve error message from message factory
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveMessage<TContext extends Record<string, any>>(messageFactory: MessageFactory<TContext>, context: MessageContext & TContext): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name nullable
|
|
4
|
+
* @category standard
|
|
5
|
+
* @description Allows a field to accept null as a valid value
|
|
6
|
+
* @allowedTypes ["string", "number", "boolean", "array", "object", "date", "union"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Basic usage - field can be null or valid string
|
|
10
|
+
* const validator = Builder()
|
|
11
|
+
* .use(nullablePlugin)
|
|
12
|
+
* .for<UserProfile>()
|
|
13
|
+
* .v("middleName", (b) => b.string.nullable().min(3))
|
|
14
|
+
* .v("avatar", (b) => b.string.nullable().url())
|
|
15
|
+
* .build();
|
|
16
|
+
*
|
|
17
|
+
* // With other validations - null bypasses all validators
|
|
18
|
+
* builder.v("score", b => b.number.nullable().min(0).max(100))
|
|
19
|
+
* ```
|
|
20
|
+
* @params
|
|
21
|
+
* No parameters - this is a modifier plugin
|
|
22
|
+
* @returns Validation function that returns true for null values and continues validation for non-null values
|
|
23
|
+
* @customError
|
|
24
|
+
* This plugin does not generate errors - it allows null values
|
|
25
|
+
* @since 0.1.0-alpha
|
|
26
|
+
*/
|
|
27
|
+
export declare const nullablePlugin: import("../..").TypedPlugin<"nullable", "nullable", () => {
|
|
28
|
+
check: (value: any) => boolean;
|
|
29
|
+
code: string;
|
|
30
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
31
|
+
params: any[];
|
|
32
|
+
isNullable: boolean;
|
|
33
|
+
skipForNull: boolean;
|
|
34
|
+
}, readonly ["string", "number", "boolean", "array", "object", "date", "union"], "validator", "standard">;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name numberFinite
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a number is finite (not Infinity, -Infinity, or NaN)
|
|
7
|
+
* @allowedTypes ["number"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - ensures number is finite
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(numberFinitePlugin)
|
|
13
|
+
* .for<CalculationResult>()
|
|
14
|
+
* .v("score", (b) => b.number.finite())
|
|
15
|
+
* .v("ratio", (b) => b.number.required().finite())
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // For division results that might be infinite
|
|
19
|
+
* builder.v("average", b => b.number.finite().min(0))
|
|
20
|
+
*
|
|
21
|
+
* // For mathematical calculations
|
|
22
|
+
* builder.v("result", b => b.number.required().finite().range(-1000, 1000))
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
26
|
+
* @returns Validation function that returns true if number is finite
|
|
27
|
+
* @customError
|
|
28
|
+
* ```typescript
|
|
29
|
+
* .finite({
|
|
30
|
+
* messageFactory: ({ path, value }) =>
|
|
31
|
+
* `${path} must be a finite number (received: ${value})`
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
* @since 0.1.0-alpha
|
|
35
|
+
*/
|
|
36
|
+
export declare const numberFinitePlugin: import("../..").TypedPlugin<"numberFinite", "finite", (options?: ValidationOptions) => {
|
|
37
|
+
check: (value: any) => boolean;
|
|
38
|
+
code: string;
|
|
39
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
40
|
+
params: ValidationOptions<{}>[];
|
|
41
|
+
}, readonly ["number"], "validator", "standard">;
|