@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,41 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name numberInteger
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a number is an integer (whole number without decimals)
|
|
7
|
+
* @allowedTypes ["number"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - ensures number is an integer
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(numberIntegerPlugin)
|
|
13
|
+
* .for<OrderData>()
|
|
14
|
+
* .v("quantity", (b) => b.number.integer())
|
|
15
|
+
* .v("count", (b) => b.number.required().integer())
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // Combined with range validation
|
|
19
|
+
* builder.v("score", b => b.number.integer().min(0).max(100))
|
|
20
|
+
*
|
|
21
|
+
* // For ID validation
|
|
22
|
+
* builder.v("userId", b => b.number.required().integer().positive())
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
26
|
+
* @returns Validation function that returns true if number is an integer
|
|
27
|
+
* @customError
|
|
28
|
+
* ```typescript
|
|
29
|
+
* .integer({
|
|
30
|
+
* messageFactory: ({ path, value }) =>
|
|
31
|
+
* `${path} must be a whole number (received: ${value})`
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
* @since 0.1.0-alpha
|
|
35
|
+
*/
|
|
36
|
+
export declare const numberIntegerPlugin: import("../..").TypedPlugin<"numberInteger", "integer", (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">;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
export interface NumberMaxContext extends MessageContext {
|
|
3
|
+
max: number;
|
|
4
|
+
actual: number;
|
|
5
|
+
exclusive: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @luq-plugin
|
|
9
|
+
* @name numberMax
|
|
10
|
+
* @category standard
|
|
11
|
+
* @description Validates that a number is less than or equal to the specified maximum value
|
|
12
|
+
* @allowedTypes ["number"]
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Basic usage - set maximum allowed value
|
|
16
|
+
* const validator = Builder()
|
|
17
|
+
* .use(numberMaxPlugin)
|
|
18
|
+
* .for<Settings>()
|
|
19
|
+
* .v("percentage", (b) => b.number.max(100))
|
|
20
|
+
* .v("discount", (b) => b.number.max(50))
|
|
21
|
+
* .v("temperature", (b) => b.number.max(40))
|
|
22
|
+
* .build();
|
|
23
|
+
*
|
|
24
|
+
* // For percentages with range
|
|
25
|
+
* builder.v("successRate", b => b.number.min(0).max(100))
|
|
26
|
+
* ```
|
|
27
|
+
* @params
|
|
28
|
+
* - max: number - Maximum allowed value (inclusive)
|
|
29
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
30
|
+
* @returns Validation function that returns true if number is less than or equal to maximum
|
|
31
|
+
* @customError
|
|
32
|
+
* ```typescript
|
|
33
|
+
* .max(100, {
|
|
34
|
+
* messageFactory: ({ path, value, params }) =>
|
|
35
|
+
* `${path} must not exceed ${params.max} (received: ${value})`
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
* @since 0.1.0-alpha
|
|
39
|
+
*/
|
|
40
|
+
export declare const numberMaxPlugin: import("../..").TypedPlugin<"numberMax", "max", (maxValue: number, options?: ValidationOptions<NumberMaxContext> & {
|
|
41
|
+
exclusive?: boolean;
|
|
42
|
+
}) => {
|
|
43
|
+
check: (value: any) => boolean;
|
|
44
|
+
code: string;
|
|
45
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
46
|
+
params: (number | (ValidationOptions<NumberMaxContext> & {
|
|
47
|
+
exclusive?: boolean;
|
|
48
|
+
}))[];
|
|
49
|
+
}, readonly ["number"], "validator", "standard">;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
export interface NumberMinContext extends MessageContext {
|
|
3
|
+
min: number;
|
|
4
|
+
actual: number;
|
|
5
|
+
exclusive: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @luq-plugin
|
|
9
|
+
* @name numberMin
|
|
10
|
+
* @category standard
|
|
11
|
+
* @description Validates that a number is greater than or equal to the specified minimum value
|
|
12
|
+
* @allowedTypes ["number"]
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Basic usage - set minimum allowed value
|
|
16
|
+
* const validator = Builder()
|
|
17
|
+
* .use(numberMinPlugin)
|
|
18
|
+
* .for<OrderForm>()
|
|
19
|
+
* .v("age", (b) => b.number.min(18))
|
|
20
|
+
* .v("quantity", (b) => b.number.min(1))
|
|
21
|
+
* .v("price", (b) => b.number.min(0.01))
|
|
22
|
+
* .build();
|
|
23
|
+
*
|
|
24
|
+
* // Combined with max for range validation
|
|
25
|
+
* builder.v("percentage", b => b.number.min(0).max(100))
|
|
26
|
+
* ```
|
|
27
|
+
* @params
|
|
28
|
+
* - min: number - Minimum allowed value (inclusive)
|
|
29
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
30
|
+
* @returns Validation function that returns true if number is greater than or equal to minimum
|
|
31
|
+
* @customError
|
|
32
|
+
* ```typescript
|
|
33
|
+
* .min(18, {
|
|
34
|
+
* messageFactory: ({ path, value, params }) =>
|
|
35
|
+
* `${path} must be at least ${params.min} (received: ${value})`
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
* @since 0.1.0-alpha
|
|
39
|
+
*/
|
|
40
|
+
export declare const numberMinPlugin: import("../..").TypedPlugin<"numberMin", "min", (minValue: number, options?: ValidationOptions<NumberMinContext> & {
|
|
41
|
+
exclusive?: boolean;
|
|
42
|
+
}) => {
|
|
43
|
+
check: (value: any) => boolean;
|
|
44
|
+
code: string;
|
|
45
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
46
|
+
params: (number | (ValidationOptions<NumberMinContext> & {
|
|
47
|
+
exclusive?: boolean;
|
|
48
|
+
}))[];
|
|
49
|
+
}, readonly ["number"], "validator", "standard">;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name numberMultipleOf
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a number is a multiple of a specified divisor
|
|
7
|
+
* @allowedTypes ["number"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - ensures number is a multiple of divisor
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(numberMultipleOfPlugin)
|
|
13
|
+
* .for<PricingData>()
|
|
14
|
+
* .v("quantity", (b) => b.number.multipleOf(5))
|
|
15
|
+
* .v("price", (b) => b.number.required().multipleOf(0.25))
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // For time intervals (minutes)
|
|
19
|
+
* builder.v("duration", b => b.number.multipleOf(15).min(0).max(240))
|
|
20
|
+
*
|
|
21
|
+
* // For currency with cents
|
|
22
|
+
* builder.v("amount", b => b.number.multipleOf(0.01).positive())
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - divisor: number - The number that the value must be divisible by
|
|
26
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
27
|
+
* @returns Validation function that returns true if number is a multiple of divisor
|
|
28
|
+
* @customError
|
|
29
|
+
* ```typescript
|
|
30
|
+
* .multipleOf(0.25, {
|
|
31
|
+
* messageFactory: ({ path, value, params }) =>
|
|
32
|
+
* `${path} must be in increments of ${params.divisor} (received: ${value})`
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
* @since 0.1.0-alpha
|
|
36
|
+
*/
|
|
37
|
+
export declare const numberMultipleOfPlugin: import("../..").TypedPlugin<"numberMultipleOf", "multipleOf", (divisor: number, options?: ValidationOptions) => {
|
|
38
|
+
check: (value: any) => boolean;
|
|
39
|
+
code: string;
|
|
40
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
41
|
+
params: (number | ValidationOptions<{}>)[];
|
|
42
|
+
}, readonly ["number"], "validator", "standard">;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name numberNegative
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a number is strictly negative (less than zero)
|
|
7
|
+
* @allowedTypes ["number"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - ensures number is negative (< 0)
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(numberNegativePlugin)
|
|
13
|
+
* .for<TemperatureData>()
|
|
14
|
+
* .v("temperature", (b) => b.number.negative())
|
|
15
|
+
* .v("debt", (b) => b.number.required().negative())
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // For temperature below freezing
|
|
19
|
+
* builder.v("celsius", b => b.number.negative().max(-1))
|
|
20
|
+
*
|
|
21
|
+
* // For negative offsets or adjustments
|
|
22
|
+
* builder.v("adjustment", b => b.number.negative().integer())
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
26
|
+
* @returns Validation function that returns true if number is less than zero
|
|
27
|
+
* @customError
|
|
28
|
+
* ```typescript
|
|
29
|
+
* .negative({
|
|
30
|
+
* messageFactory: ({ path, value }) =>
|
|
31
|
+
* `${path} must be negative (received: ${value})`
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
* @since 0.1.0-alpha
|
|
35
|
+
*/
|
|
36
|
+
export declare const numberNegativePlugin: import("../..").TypedPlugin<"numberNegative", "negative", (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">;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name numberPositive
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a number is strictly positive (greater than zero)
|
|
7
|
+
* @allowedTypes ["number"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - ensures number is positive (> 0)
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(numberPositivePlugin)
|
|
13
|
+
* .for<PricingData>()
|
|
14
|
+
* .v("price", (b) => b.number.positive())
|
|
15
|
+
* .v("quantity", (b) => b.number.required().positive())
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // For monetary values
|
|
19
|
+
* builder.v("payment", b => b.number.positive().multipleOf(0.01))
|
|
20
|
+
*
|
|
21
|
+
* // For counts and quantities
|
|
22
|
+
* builder.v("itemCount", b => b.number.positive().integer())
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
26
|
+
* @returns Validation function that returns true if number is greater than zero
|
|
27
|
+
* @customError
|
|
28
|
+
* ```typescript
|
|
29
|
+
* .positive({
|
|
30
|
+
* messageFactory: ({ path, value }) =>
|
|
31
|
+
* `${path} must be positive (received: ${value})`
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
* @since 0.1.0-alpha
|
|
35
|
+
*/
|
|
36
|
+
export declare const numberPositivePlugin: import("../..").TypedPlugin<"numberPositive", "positive", (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">;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
export interface NumberRangeContext extends MessageContext {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
actual: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @luq-plugin
|
|
9
|
+
* @name numberRange
|
|
10
|
+
* @category standard
|
|
11
|
+
* @description Validates that a number is within a specified range (inclusive)
|
|
12
|
+
* @allowedTypes ["number"]
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Basic usage - ensures number is within range
|
|
16
|
+
* const validator = Builder()
|
|
17
|
+
* .use(numberRangePlugin)
|
|
18
|
+
* .for<FormData>()
|
|
19
|
+
* .v("age", (b) => b.number.range(18, 65))
|
|
20
|
+
* .v("percentage", (b) => b.number.required().range(0, 100))
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* // For ratings
|
|
24
|
+
* builder.v("rating", b => b.number.range(1, 5).integer())
|
|
25
|
+
*
|
|
26
|
+
* // For temperature ranges
|
|
27
|
+
* builder.v("celsius", b => b.number.range(-273.15, 100))
|
|
28
|
+
* ```
|
|
29
|
+
* @params
|
|
30
|
+
* - min: number - Minimum value (inclusive)
|
|
31
|
+
* - max: number - Maximum value (inclusive)
|
|
32
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
33
|
+
* @returns Validation function that returns true if number is within range
|
|
34
|
+
* @customError
|
|
35
|
+
* ```typescript
|
|
36
|
+
* .range(0, 100, {
|
|
37
|
+
* messageFactory: ({ path, value, params }) =>
|
|
38
|
+
* `${path} must be between ${params.min} and ${params.max} (received: ${value})`
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
* @since 0.1.0-alpha
|
|
42
|
+
*/
|
|
43
|
+
export declare const numberRangePlugin: import("../..").TypedPlugin<"numberRange", "range", (min: number, max: number, options?: ValidationOptions<NumberRangeContext>) => {
|
|
44
|
+
check: (value: any) => boolean;
|
|
45
|
+
code: string;
|
|
46
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
47
|
+
params: (number | ValidationOptions<NumberRangeContext>)[];
|
|
48
|
+
}, readonly ["number"], "validator", "standard">;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name object
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that a value is a plain object (not null, array, or other types)
|
|
7
|
+
* @allowedTypes ["object"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - validates that value is an object
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(objectPlugin)
|
|
13
|
+
* .for<FormData>()
|
|
14
|
+
* .v("settings", (b) => b.object.object())
|
|
15
|
+
* .v("config", (b) => b.object.required().object())
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // For nested object validation
|
|
19
|
+
* builder.v("data", b => b.object.object())
|
|
20
|
+
* .v("data.name", b => b.string.required())
|
|
21
|
+
* .v("data.age", b => b.number.min(0))
|
|
22
|
+
*
|
|
23
|
+
* // Combined with required for mandatory objects
|
|
24
|
+
* builder.v("user", b => b.object.required().object())
|
|
25
|
+
* ```
|
|
26
|
+
* @params
|
|
27
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
28
|
+
* @returns Validation function that returns true if value is a plain object
|
|
29
|
+
* @customError
|
|
30
|
+
* ```typescript
|
|
31
|
+
* .object({
|
|
32
|
+
* messageFactory: ({ path, value }) =>
|
|
33
|
+
* `${path} must be an object (received: ${typeof value})`
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
* @since 0.1.0-alpha
|
|
37
|
+
*/
|
|
38
|
+
export declare const objectPlugin: import("../..").TypedPlugin<"object", "object", (options?: ValidationOptions) => {
|
|
39
|
+
check: (value: any) => boolean;
|
|
40
|
+
code: string;
|
|
41
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
42
|
+
params: ValidationOptions<{}>[];
|
|
43
|
+
}, readonly ["object"], "validator", "standard">;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
interface AdditionalPropertiesOptions extends ValidationOptions {
|
|
4
|
+
allowedProperties?: string[];
|
|
5
|
+
additionalPropertiesSchema?: JSONSchema7;
|
|
6
|
+
strict?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @luq-plugin
|
|
10
|
+
* @name objectAdditionalProperties
|
|
11
|
+
* @category standard
|
|
12
|
+
* @description Validates additional properties in objects according to JSON Schema additionalProperties rules
|
|
13
|
+
* @allowedTypes ["object"]
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Strict mode - no additional properties allowed
|
|
17
|
+
* const validator = Builder()
|
|
18
|
+
* .use(objectAdditionalPropertiesPlugin)
|
|
19
|
+
* .for<UserData>()
|
|
20
|
+
* .v("user", (b) => b.object.additionalProperties(false, {
|
|
21
|
+
* allowedProperties: ["name", "age", "email"]
|
|
22
|
+
* }))
|
|
23
|
+
* .build();
|
|
24
|
+
*
|
|
25
|
+
* // With schema validation for additional properties
|
|
26
|
+
* builder.v("config", b => b.object.additionalProperties({
|
|
27
|
+
* type: "string",
|
|
28
|
+
* minLength: 1
|
|
29
|
+
* }))
|
|
30
|
+
* ```
|
|
31
|
+
* @params
|
|
32
|
+
* - allowed: boolean | JSONSchema7 - Whether additional properties are allowed or schema for validation
|
|
33
|
+
* - options?: AdditionalPropertiesOptions - Configuration including allowed property names
|
|
34
|
+
* @returns Validation function that validates additional properties according to rules
|
|
35
|
+
* @customError
|
|
36
|
+
* ```typescript
|
|
37
|
+
* .additionalProperties(false, {
|
|
38
|
+
* allowedProperties: ["name", "age"],
|
|
39
|
+
* messageFactory: ({ path, value }) =>
|
|
40
|
+
* `${path} has unexpected properties: ${Object.keys(value).filter(k => !allowedProps.includes(k)).join(", ")}`
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
* @since 0.1.0-alpha
|
|
44
|
+
*/
|
|
45
|
+
export declare const objectAdditionalPropertiesPlugin: import("../..").TypedPlugin<"objectAdditionalProperties", "additionalProperties", (allowed: boolean | JSONSchema7, options?: AdditionalPropertiesOptions) => {
|
|
46
|
+
check: (value: any) => boolean;
|
|
47
|
+
code: string;
|
|
48
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
49
|
+
params: (boolean | JSONSchema7 | AdditionalPropertiesOptions)[];
|
|
50
|
+
}, readonly ["object"], "validator", "standard">;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name objectDependentRequired
|
|
4
|
+
* @category object
|
|
5
|
+
* @description Validates that when certain properties exist, other properties become required
|
|
6
|
+
* @allowedTypes ["object"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Dependent required fields
|
|
10
|
+
* const validator = Builder()
|
|
11
|
+
* .use(objectDependentRequiredPlugin)
|
|
12
|
+
* .for<{ name?: string; first?: string; last?: string; }>()
|
|
13
|
+
* .v("", (b) => b.object.dependentRequired({
|
|
14
|
+
* name: ["first", "last"],
|
|
15
|
+
* credit_card: ["billing_address"]
|
|
16
|
+
* }))
|
|
17
|
+
* .build();
|
|
18
|
+
*
|
|
19
|
+
* // With custom error messages
|
|
20
|
+
* builder.v("", b => b.object.dependentRequired({
|
|
21
|
+
* email: {
|
|
22
|
+
* required: ["email_verified"],
|
|
23
|
+
* message: "When email is provided, email_verified is required"
|
|
24
|
+
* }
|
|
25
|
+
* }))
|
|
26
|
+
* ```
|
|
27
|
+
* @params
|
|
28
|
+
* - dependencies: Record<string, string[] | DependentRequiredSchema> - Property dependencies mapping
|
|
29
|
+
* @returns Validation function that checks dependent required fields
|
|
30
|
+
* @since 0.1.0-alpha
|
|
31
|
+
*/
|
|
32
|
+
export interface DependentRequiredSchema {
|
|
33
|
+
required: string[];
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
export type DependentRequiredMapping = Record<string, string[] | DependentRequiredSchema>;
|
|
37
|
+
export declare const objectDependentRequiredPlugin: import("../..").TypedPlugin<"objectDependentRequired", "dependentRequired", (dependencies: DependentRequiredMapping) => {
|
|
38
|
+
check: (value: any, allValues?: any) => boolean;
|
|
39
|
+
code: string;
|
|
40
|
+
getErrorMessage: (value: any, path: string, allValues?: any) => string;
|
|
41
|
+
params: DependentRequiredMapping[];
|
|
42
|
+
}, readonly ["object"], "validator", "standard">;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name objectDependentSchemas
|
|
4
|
+
* @category object
|
|
5
|
+
* @description Validates object with dependent schemas that apply when certain properties exist
|
|
6
|
+
* @allowedTypes ["object"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Dependent schemas validation
|
|
10
|
+
* const validator = Builder()
|
|
11
|
+
* .use(objectDependentSchemasPlugin)
|
|
12
|
+
* .for<{ creditCard?: string; billingAddress?: string; zipCode?: string; }>()
|
|
13
|
+
* .v("", (b) => b.object.dependentSchemas({
|
|
14
|
+
* creditCard: {
|
|
15
|
+
* properties: {
|
|
16
|
+
* billingAddress: { type: "string", minLength: 10 },
|
|
17
|
+
* zipCode: { type: "string", pattern: "^[0-9]{5}$" }
|
|
18
|
+
* },
|
|
19
|
+
* required: ["billingAddress", "zipCode"]
|
|
20
|
+
* }
|
|
21
|
+
* }))
|
|
22
|
+
* .build();
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - schemas: Record<string, JSONSchema7 | SchemaValidator> - Property to schema mapping
|
|
26
|
+
* @returns Validation function that applies schemas when trigger properties exist
|
|
27
|
+
* @since 0.1.0-alpha
|
|
28
|
+
*/
|
|
29
|
+
import type { JSONSchema7 } from "json-schema";
|
|
30
|
+
export interface SchemaValidator {
|
|
31
|
+
validator: (value: any) => boolean;
|
|
32
|
+
message?: string;
|
|
33
|
+
}
|
|
34
|
+
export type DependentSchemasMapping = Record<string, JSONSchema7 | SchemaValidator>;
|
|
35
|
+
export declare const objectDependentSchemasPlugin: import("../..").TypedPlugin<"objectDependentSchemas", "dependentSchemas", (schemas: DependentSchemasMapping) => {
|
|
36
|
+
check: (value: any, allValues?: any) => boolean;
|
|
37
|
+
code: string;
|
|
38
|
+
getErrorMessage: (value: any, path: string, allValues?: any) => string;
|
|
39
|
+
params: DependentSchemasMapping[];
|
|
40
|
+
}, readonly ["object"], "validator", "standard">;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name objectMaxProperties
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that an object has at most the specified maximum number of properties
|
|
7
|
+
* @allowedTypes ["object"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - ensure object doesn't exceed maximum properties
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(objectMaxPropertiesPlugin)
|
|
13
|
+
* .for<ConfigObject>()
|
|
14
|
+
* .v("metadata", (b) => b.object.maxProperties(5))
|
|
15
|
+
* .v("settings", (b) => b.object.maxProperties(10))
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // With custom error message
|
|
19
|
+
* builder.v("config", b => b.object.maxProperties(3, {
|
|
20
|
+
* messageFactory: ({ path, params }) =>
|
|
21
|
+
* `${path} can have at most ${params.max} properties`
|
|
22
|
+
* }))
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - max: number - Maximum number of properties allowed
|
|
26
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
27
|
+
* @returns Validation function that returns true if object has at most maximum properties
|
|
28
|
+
* @customError
|
|
29
|
+
* ```typescript
|
|
30
|
+
* .maxProperties(3, {
|
|
31
|
+
* messageFactory: ({ path, value, params }) =>
|
|
32
|
+
* `${path} can have at most ${params.max} properties (has ${Object.keys(value).length})`
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
* @since 0.1.0-alpha
|
|
36
|
+
*/
|
|
37
|
+
export declare const objectMaxPropertiesPlugin: import("../..").TypedPlugin<"objectMaxProperties", "maxProperties", (maxValue: number, options?: ValidationOptions) => {
|
|
38
|
+
check: (value: any) => boolean;
|
|
39
|
+
code: string;
|
|
40
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
41
|
+
params: (number | ValidationOptions<{}>)[];
|
|
42
|
+
}, readonly ["object"], "validator", "standard">;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @luq-plugin
|
|
4
|
+
* @name objectMinProperties
|
|
5
|
+
* @category standard
|
|
6
|
+
* @description Validates that an object has at least the specified minimum number of properties
|
|
7
|
+
* @allowedTypes ["object"]
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage - ensure object has minimum properties
|
|
11
|
+
* const validator = Builder()
|
|
12
|
+
* .use(objectMinPropertiesPlugin)
|
|
13
|
+
* .for<ConfigObject>()
|
|
14
|
+
* .v("metadata", (b) => b.object.minProperties(2))
|
|
15
|
+
* .v("settings", (b) => b.object.minProperties(1))
|
|
16
|
+
* .build();
|
|
17
|
+
*
|
|
18
|
+
* // With custom error message
|
|
19
|
+
* builder.v("config", b => b.object.minProperties(3, {
|
|
20
|
+
* messageFactory: ({ path, params }) =>
|
|
21
|
+
* `${path} must have at least ${params.min} properties`
|
|
22
|
+
* }))
|
|
23
|
+
* ```
|
|
24
|
+
* @params
|
|
25
|
+
* - min: number - Minimum number of properties required
|
|
26
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
27
|
+
* @returns Validation function that returns true if object has at least minimum properties
|
|
28
|
+
* @customError
|
|
29
|
+
* ```typescript
|
|
30
|
+
* .minProperties(3, {
|
|
31
|
+
* messageFactory: ({ path, value, params }) =>
|
|
32
|
+
* `${path} requires at least ${params.min} properties (has ${Object.keys(value).length})`
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
* @since 0.1.0-alpha
|
|
36
|
+
*/
|
|
37
|
+
export declare const objectMinPropertiesPlugin: import("../..").TypedPlugin<"objectMinProperties", "minProperties", (minValue: number, options?: ValidationOptions) => {
|
|
38
|
+
check: (value: any) => boolean;
|
|
39
|
+
code: string;
|
|
40
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
41
|
+
params: (number | ValidationOptions<{}>)[];
|
|
42
|
+
}, readonly ["object"], "validator", "standard">;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name objectPatternProperties
|
|
4
|
+
* @category object
|
|
5
|
+
* @description Validates object properties that match specific patterns with corresponding schemas
|
|
6
|
+
* @allowedTypes ["object"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Pattern-based property validation
|
|
10
|
+
* const validator = Builder()
|
|
11
|
+
* .use(objectPatternPropertiesPlugin)
|
|
12
|
+
* .for<{ [key: string]: any }>()
|
|
13
|
+
* .v("config", (b) => b.object.patternProperties({
|
|
14
|
+
* "^str_": (value) => typeof value === "string",
|
|
15
|
+
* "^num_": (value) => typeof value === "number"
|
|
16
|
+
* }))
|
|
17
|
+
* .build();
|
|
18
|
+
*
|
|
19
|
+
* // With custom validators and messages
|
|
20
|
+
* builder.v("data", b => b.object.patternProperties({
|
|
21
|
+
* "^email_": {
|
|
22
|
+
* validator: (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value),
|
|
23
|
+
* message: "Email properties must be valid email addresses"
|
|
24
|
+
* },
|
|
25
|
+
* "^id_": {
|
|
26
|
+
* validator: (value) => typeof value === "string" && value.length > 0,
|
|
27
|
+
* message: "ID properties must be non-empty strings"
|
|
28
|
+
* }
|
|
29
|
+
* }))
|
|
30
|
+
* ```
|
|
31
|
+
* @params
|
|
32
|
+
* - patterns: Record<string, (value: any) => boolean | PatternValidator> - Pattern to validator mapping
|
|
33
|
+
* @returns Validation function that checks properties matching patterns
|
|
34
|
+
* @since 0.1.0-alpha
|
|
35
|
+
*/
|
|
36
|
+
export interface PatternValidator {
|
|
37
|
+
validator: (value: any) => boolean;
|
|
38
|
+
message?: string;
|
|
39
|
+
}
|
|
40
|
+
export type PatternPropertiesSchema = Record<string, ((value: any) => boolean) | PatternValidator>;
|
|
41
|
+
export declare const objectPatternPropertiesPlugin: import("../..").TypedPlugin<"objectPatternProperties", "patternProperties", (patterns: PatternPropertiesSchema) => {
|
|
42
|
+
check: (value: any) => boolean;
|
|
43
|
+
code: string;
|
|
44
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
45
|
+
params: PatternPropertiesSchema[];
|
|
46
|
+
}, readonly ["object"], "validator", "standard">;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name objectPropertyNames
|
|
4
|
+
* @category object
|
|
5
|
+
* @description Validates that all property names in an object match a specified pattern or schema
|
|
6
|
+
* @allowedTypes ["object"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Property names must match pattern
|
|
10
|
+
* const validator = Builder()
|
|
11
|
+
* .use(objectPropertyNamesPlugin)
|
|
12
|
+
* .for<{ [key: string]: any }>()
|
|
13
|
+
* .v("config", (b) => b.object.propertyNames(/^[a-zA-Z_][a-zA-Z0-9_]*$/))
|
|
14
|
+
* .build();
|
|
15
|
+
*
|
|
16
|
+
* // Property names with custom validator
|
|
17
|
+
* builder.v("data", b => b.object.propertyNames({
|
|
18
|
+
* validator: (name) => name.length >= 3 && !name.startsWith('_'),
|
|
19
|
+
* message: "Property names must be at least 3 characters and not start with underscore"
|
|
20
|
+
* }))
|
|
21
|
+
* ```
|
|
22
|
+
* @params
|
|
23
|
+
* - schema: RegExp | string | { validator: (name: string) => boolean, message?: string } - Pattern or validation schema for property names
|
|
24
|
+
* @returns Validation function that checks all property names
|
|
25
|
+
* @since 0.1.0-alpha
|
|
26
|
+
*/
|
|
27
|
+
export interface PropertyNamesSchema {
|
|
28
|
+
validator: (name: string) => boolean;
|
|
29
|
+
message?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const objectPropertyNamesPlugin: import("../..").TypedPlugin<"objectPropertyNames", "propertyNames", (schema: RegExp | string | PropertyNamesSchema) => {
|
|
32
|
+
check: (value: any) => boolean;
|
|
33
|
+
code: string;
|
|
34
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
35
|
+
params: (string | RegExp | PropertyNamesSchema)[];
|
|
36
|
+
}, readonly ["object"], "validator", "standard">;
|