@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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Essential constants - optimized for minimal bundle size
|
|
3
|
+
* Only contains constants that are actively used in the codebase
|
|
4
|
+
*/
|
|
5
|
+
export declare const DOT = ".";
|
|
6
|
+
export declare const VALIDATE_MODE: "validate";
|
|
7
|
+
export declare const PARSE_MODE: "parse";
|
|
8
|
+
export type ValidationMode = typeof VALIDATE_MODE | typeof PARSE_MODE;
|
|
9
|
+
/**
|
|
10
|
+
* Base message parameters for validation errors
|
|
11
|
+
*/
|
|
12
|
+
export interface BaseMessageParams {
|
|
13
|
+
path: string;
|
|
14
|
+
value?: any;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Extended message parameters with validation-specific properties
|
|
18
|
+
*/
|
|
19
|
+
export interface ValidationMessageParams extends BaseMessageParams {
|
|
20
|
+
expected?: any;
|
|
21
|
+
actual?: any;
|
|
22
|
+
min?: number;
|
|
23
|
+
max?: number;
|
|
24
|
+
pattern?: string;
|
|
25
|
+
code?: string;
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async Context Design - Separate async layer from validation
|
|
3
|
+
*
|
|
4
|
+
* User proposal: validator.withAsyncContext(ctx).validate()
|
|
5
|
+
* Completely decouple async layer from validation flow to maintain performance
|
|
6
|
+
*/
|
|
7
|
+
import { ValidationOptions, AsyncContextOptions, AsyncContext, AsyncAwareValidator } from "../builder/types/types";
|
|
8
|
+
import { Result } from "../../types/result";
|
|
9
|
+
/**
|
|
10
|
+
* Extended validation options for async context
|
|
11
|
+
*/
|
|
12
|
+
interface AsyncValidationOptions extends ValidationOptions {
|
|
13
|
+
asyncContext?: any;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Async context builder (simplified)
|
|
17
|
+
*/
|
|
18
|
+
export declare class AsyncContextBuilder<T = {}> {
|
|
19
|
+
private promises;
|
|
20
|
+
private options;
|
|
21
|
+
/**
|
|
22
|
+
* Add async data
|
|
23
|
+
*/
|
|
24
|
+
set<K extends string, V>(key: K, promise: Promise<V>): AsyncContextBuilder<T & {
|
|
25
|
+
[P in K]: V;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Set options
|
|
29
|
+
*/
|
|
30
|
+
withOptions(options: AsyncContextOptions): this;
|
|
31
|
+
/**
|
|
32
|
+
* Build async context (simplified)
|
|
33
|
+
*/
|
|
34
|
+
build(): Promise<AsyncContext<T>>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Helper to create async context
|
|
38
|
+
*/
|
|
39
|
+
export declare function createAsyncContext<T = {}>(): AsyncContextBuilder<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Decorator to add async functionality to existing validator (type-safe version)
|
|
42
|
+
*/
|
|
43
|
+
export declare function addAsyncSupport<TObject>(validator: {
|
|
44
|
+
validate: (value: any, options?: any) => Result<TObject>;
|
|
45
|
+
}): AsyncAwareValidator<TObject>;
|
|
46
|
+
/**
|
|
47
|
+
* Helper to access async context in plugins (type-safe version)
|
|
48
|
+
*/
|
|
49
|
+
export declare function getAsyncContext<T extends Record<string, any> = Record<string, any>>(options?: AsyncValidationOptions): T | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Type-safe async context access (with key)
|
|
52
|
+
*/
|
|
53
|
+
export declare function getAsyncContextValue<T extends Record<string, any>, K extends keyof T>(options: ValidationOptions | undefined, key: K): T[K] | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Type guard for async context
|
|
56
|
+
*/
|
|
57
|
+
export declare function hasAsyncContextKey<T extends Record<string, any>, K extends keyof T>(options: ValidationOptions | undefined, key: K): options is ValidationOptions & {
|
|
58
|
+
asyncContext: T;
|
|
59
|
+
};
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array Batch Processing Optimizer
|
|
3
|
+
*
|
|
4
|
+
* Optimizes validation by batching array element fields:
|
|
5
|
+
* Instead of accessing the same array multiple times for different element properties,
|
|
6
|
+
* we access the array once and validate all element properties in batch.
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
* - customer.addresses.type
|
|
10
|
+
* - customer.addresses.name
|
|
11
|
+
* - customer.addresses.street
|
|
12
|
+
*
|
|
13
|
+
* Instead of 3 separate array accesses, we do:
|
|
14
|
+
* 1. Get customer.addresses array once
|
|
15
|
+
* 2. For each address element, validate type, name, street together
|
|
16
|
+
*/
|
|
17
|
+
import { ValidationMode } from "../../constants";
|
|
18
|
+
import { ArrayStructureInfo } from "../../types/array-type-analysis";
|
|
19
|
+
import { NestedArrayBatchInfo } from "./nested-array-processor";
|
|
20
|
+
export interface ArrayBatchInfo {
|
|
21
|
+
arrayPath: string;
|
|
22
|
+
elementFields: string[];
|
|
23
|
+
fullFieldPaths: string[];
|
|
24
|
+
validators: Map<string, any>;
|
|
25
|
+
accessors: Map<string, (obj: any) => any>;
|
|
26
|
+
arrayStructure?: ArrayStructureInfo;
|
|
27
|
+
optimizedValidator?: (array: any, rootData: any, options: any) => ValidationResult;
|
|
28
|
+
_nestedInfo?: NestedArrayBatchInfo;
|
|
29
|
+
}
|
|
30
|
+
interface ValidationResult {
|
|
31
|
+
valid: boolean;
|
|
32
|
+
errors: Array<{
|
|
33
|
+
path: string;
|
|
34
|
+
code: string;
|
|
35
|
+
message: string;
|
|
36
|
+
paths: () => string[];
|
|
37
|
+
}>;
|
|
38
|
+
transformedData?: any;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Field definition with array information
|
|
42
|
+
*/
|
|
43
|
+
interface FieldDefinitionWithArray {
|
|
44
|
+
path: string;
|
|
45
|
+
builderFunction?: (context: any) => any;
|
|
46
|
+
inferredType?: string;
|
|
47
|
+
isArrayField?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Analyze field paths to identify array batching opportunities
|
|
51
|
+
* Now uses field definitions with array field information
|
|
52
|
+
*/
|
|
53
|
+
export declare function analyzeArrayBatching(fieldDefinitions: FieldDefinitionWithArray[]): Map<string, ArrayBatchInfo>;
|
|
54
|
+
/**
|
|
55
|
+
* Create optimized batch validator for array processing
|
|
56
|
+
*/
|
|
57
|
+
export declare function createArrayBatchValidator(batchInfo: ArrayBatchInfo, fieldValidators: Map<string, any>): (arrayData: any[], rootData: any, abortEarly: boolean, abortEarlyOnEachField: boolean, mode?: ValidationMode) => {
|
|
58
|
+
errors: Array<{
|
|
59
|
+
path: string;
|
|
60
|
+
code: string;
|
|
61
|
+
message: string;
|
|
62
|
+
paths: () => string[];
|
|
63
|
+
}>;
|
|
64
|
+
transformedData?: any[];
|
|
65
|
+
};
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized field context creation for V8 performance
|
|
3
|
+
* Removes Proxy usage and reduces object allocation
|
|
4
|
+
*/
|
|
5
|
+
import type { TypeName, ChainableFieldBuilder, FieldBuilderContext, TransformFunction } from "../plugins/plugin-types";
|
|
6
|
+
type OptimizedValidator<T = unknown> = (value: T, currentValue: T) => boolean;
|
|
7
|
+
interface ValidatorWithMeta<TValue = unknown> {
|
|
8
|
+
check: OptimizedValidator<TValue>;
|
|
9
|
+
name: string;
|
|
10
|
+
messageFactory?: (context: any) => string;
|
|
11
|
+
inputType?: TypeName;
|
|
12
|
+
outputType?: TypeName;
|
|
13
|
+
metadata?: {
|
|
14
|
+
severity?: "error" | "warning" | "info";
|
|
15
|
+
async?: boolean;
|
|
16
|
+
dependencies?: string[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create type-safe chainable field builder without Proxy
|
|
21
|
+
* All methods are directly attached to the builder object with proper typing
|
|
22
|
+
*/
|
|
23
|
+
export declare function createOptimizedTypeBuilder<TObject extends object, TPlugins, TType extends TypeName>(type: TType, fieldPath: string, plugins: TPlugins, existingState?: {
|
|
24
|
+
validators: ValidatorWithMeta<unknown>[];
|
|
25
|
+
transforms: Array<TransformFunction<unknown, unknown>>;
|
|
26
|
+
}): ChainableFieldBuilder<TObject, TPlugins, TType, any>;
|
|
27
|
+
/**
|
|
28
|
+
* Create type-safe field context without Proxy
|
|
29
|
+
*/
|
|
30
|
+
export declare function createOptimizedFieldContext<TObject extends object, TPlugins, TFieldType>(fieldPath: string, plugins: TPlugins): FieldBuilderContext<TObject, TPlugins, TFieldType>;
|
|
31
|
+
export { createOptimizedFieldContext as createFieldContext };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field Type Detector
|
|
3
|
+
* Detects the actual type of a field by tracking which type builder is used
|
|
4
|
+
*/
|
|
5
|
+
export type FieldType = "string" | "number" | "boolean" | "date" | "array" | "object" | "tuple" | "union";
|
|
6
|
+
/**
|
|
7
|
+
* Detect field type by executing the builder function and tracking which type builder is accessed
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectFieldType(fieldDef: {
|
|
10
|
+
path: string;
|
|
11
|
+
builderFunction: Function;
|
|
12
|
+
}, plugins: Record<string, any>): FieldType | null;
|
|
13
|
+
/**
|
|
14
|
+
* Batch detect field types for multiple field definitions
|
|
15
|
+
*/
|
|
16
|
+
export declare function detectFieldTypes(fieldDefinitions: Array<{
|
|
17
|
+
path: string;
|
|
18
|
+
builderFunction: Function;
|
|
19
|
+
}>, plugins: Record<string, any>): Map<string, FieldType>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced integration with better type inference
|
|
3
|
+
*/
|
|
4
|
+
import { IChainableBuilder } from "../types/types";
|
|
5
|
+
export type { ChainableBuilder, IChainableBuilder, PluginMapFromArray, BuilderExtensions, } from "../types/types";
|
|
6
|
+
/**
|
|
7
|
+
* Factory function with better type inference
|
|
8
|
+
*/
|
|
9
|
+
declare function createBuilder<TInput = any>(): IChainableBuilder<TInput, {}, {}>;
|
|
10
|
+
export declare const Builder: typeof createBuilder;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refactored Field Builder - Streamlined through separation of concerns
|
|
3
|
+
* Focused on core builder logic
|
|
4
|
+
*/
|
|
5
|
+
import type { FieldBuilder } from "../plugins/plugin-types";
|
|
6
|
+
import { FieldBuilderDefinition } from "../types/types";
|
|
7
|
+
export type { FieldBuilder } from "../plugins/plugin-types";
|
|
8
|
+
export type { FieldBuilderDefinition } from "../types/types";
|
|
9
|
+
/**
|
|
10
|
+
* Streamlined FieldBuilder implementation focused on core building logic
|
|
11
|
+
*/
|
|
12
|
+
export declare function createFieldBuilderImpl<TObject extends object, TMap = {}, TPlugins = {}, TDeclaredFields extends string = never>(plugins: TPlugins, chainableBuilder: any, fieldDefinitions?: Array<FieldBuilderDefinition>, isStrict?: boolean): FieldBuilder<TObject, TMap, TPlugins, TDeclaredFields>;
|
|
13
|
+
export declare const FieldBuilderImpl: any;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder module exports
|
|
3
|
+
*
|
|
4
|
+
* This module contains all the core functionality for creating and managing plugins
|
|
5
|
+
*/
|
|
6
|
+
export { Builder } from "./builder";
|
|
7
|
+
export { PluginValidationResult as BasicValidationResult, StandardPluginImplementation, ConditionalPluginImplementation, TransformPluginImplementation, FieldReferencePluginImplementation, ArrayElementPluginImplementation, } from "../plugins/plugin-interfaces";
|
|
8
|
+
export { plugin, PluginImplementation, pluginPredefinedTransform, pluginConfigurableTransform, } from "../plugins/plugin-creator";
|
|
9
|
+
export * from "../plugins/plugin-types";
|
|
10
|
+
export { FieldBuilder, createFieldBuilderImpl } from "./field-builder";
|
|
11
|
+
export { createFieldContext, createOptimizedFieldContext, } from "../context/field-context";
|
|
12
|
+
export { createComposablePlugin, attachComposablePlugin, createValidator, createValidatorResult, createSingleValidatorResult, createCompositionBuilder, mergeValidatorResults, VALID_RESULT, INVALID_RESULT, } from "../plugins/composable-plugin";
|
|
13
|
+
export type { ComposablePlugin, ComposableValidatorResult, ValidatorDefinition, TransformFunction, CompositionBuilder, } from "../plugins/composable-plugin";
|
|
14
|
+
export { createComposableConditionalPlugin } from "../plugins/composable-conditional-plugin";
|
|
15
|
+
export type { ComposableConditionalPlugin } from "../plugins/composable-conditional-plugin";
|
|
16
|
+
export { createComposableDirectlyPlugin } from "../plugins/composable-directly-plugin";
|
|
17
|
+
export type { ComposableDirectlyPlugin } from "../plugins/composable-directly-plugin";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder module - organized by functionality
|
|
3
|
+
*
|
|
4
|
+
* New directory structure:
|
|
5
|
+
* - core/ - Core builder functionality
|
|
6
|
+
* - plugins/ - Plugin system
|
|
7
|
+
* - context/ - Field context management
|
|
8
|
+
* - validation/ - Validation engine
|
|
9
|
+
* - types/ - Type definitions and results
|
|
10
|
+
* - analysis/ - Analysis and optimization
|
|
11
|
+
*/
|
|
12
|
+
export * from "./core/builder";
|
|
13
|
+
export * from "./core/field-builder";
|
|
14
|
+
export * from "./plugins/composable-plugin";
|
|
15
|
+
export * from "./plugins/composable-conditional-plugin";
|
|
16
|
+
export * from "./plugins/composable-directly-plugin";
|
|
17
|
+
export * from "./plugins/plugin-interfaces";
|
|
18
|
+
export * from "./plugins/plugin-types";
|
|
19
|
+
export * from "./context/field-context";
|
|
20
|
+
export { createValidatorFactory } from "./validator-factory";
|
|
21
|
+
export * from "./types/types";
|
|
22
|
+
export { Builder } from "./core/builder";
|
|
23
|
+
export type { FieldBuilder } from "./core/field-builder";
|
|
24
|
+
export { createFieldContext } from "./context/field-context";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Nested Array Processor
|
|
3
|
+
*
|
|
4
|
+
* Supports complete nested array validation with accurate error paths.
|
|
5
|
+
* This module handles arrays at any depth level with proper index tracking.
|
|
6
|
+
*/
|
|
7
|
+
import { ValidationMode } from "../../constants";
|
|
8
|
+
/**
|
|
9
|
+
* Parse array element path pattern and extract array path and element field
|
|
10
|
+
* Examples:
|
|
11
|
+
* - "items[*].name" => { arrayPath: "items", elementField: "name" }
|
|
12
|
+
* - "items.*.name" => { arrayPath: "items", elementField: "name" }
|
|
13
|
+
* - "users[*].addresses[*].street" => { arrayPath: "users", elementField: "addresses[*].street" }
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseArrayElementPath(path: string): {
|
|
16
|
+
isArrayElementPath: boolean;
|
|
17
|
+
arrayPath?: string;
|
|
18
|
+
elementField?: string;
|
|
19
|
+
};
|
|
20
|
+
export interface NestedArrayBatchInfo {
|
|
21
|
+
arrayPath: string;
|
|
22
|
+
elementFields: string[];
|
|
23
|
+
fullFieldPaths: string[];
|
|
24
|
+
validators: Map<string, any>;
|
|
25
|
+
accessors: Map<string, (obj: any) => any>;
|
|
26
|
+
childArrays: Map<string, NestedArrayBatchInfo>;
|
|
27
|
+
depth: number;
|
|
28
|
+
parentPath?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build hierarchical array structure from field definitions
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildNestedArrayHierarchy(fieldDefinitions: Array<{
|
|
34
|
+
path: string;
|
|
35
|
+
isArrayField?: boolean;
|
|
36
|
+
builderFunction?: (context: any) => any;
|
|
37
|
+
}>): Map<string, NestedArrayBatchInfo>;
|
|
38
|
+
/**
|
|
39
|
+
* Create hierarchical nested array validator
|
|
40
|
+
*/
|
|
41
|
+
export declare function createNestedArrayValidator(nestedBatchInfo: NestedArrayBatchInfo, fieldValidators: Map<string, any>): (arrayData: any[], rootData: any, abortEarly: boolean, abortEarlyOnEachField: boolean, mode: ValidationMode, parentPath?: string) => NestedValidationResult;
|
|
42
|
+
interface NestedError {
|
|
43
|
+
path: string;
|
|
44
|
+
code: string;
|
|
45
|
+
message: string;
|
|
46
|
+
paths: () => string[];
|
|
47
|
+
}
|
|
48
|
+
interface NestedValidationResult {
|
|
49
|
+
errors: NestedError[];
|
|
50
|
+
transformedData?: any[];
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable Conditional Plugin Pattern - For guard-like conditional validation
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for creating composable plugins that apply
|
|
5
|
+
* conditional validation based on type guards or conditions. This is specifically
|
|
6
|
+
* designed for union type validation where different rules apply based on the value type.
|
|
7
|
+
*/
|
|
8
|
+
import type { TypeName } from "../plugins/plugin-types";
|
|
9
|
+
import { type ComposableValidatorResult } from "../plugins/composable-plugin";
|
|
10
|
+
/**
|
|
11
|
+
* Interface for Composable Conditional Plugin
|
|
12
|
+
*/
|
|
13
|
+
export interface ComposableConditionalPlugin<TName extends string, TMethodName extends string, TAllowedTypes extends readonly TypeName[]> {
|
|
14
|
+
name: TName;
|
|
15
|
+
methodName: TMethodName;
|
|
16
|
+
allowedTypes: TAllowedTypes;
|
|
17
|
+
category: "composable-conditional";
|
|
18
|
+
/**
|
|
19
|
+
* Create a Composer that accumulates conditional validations
|
|
20
|
+
*/
|
|
21
|
+
createComposer<TPlugins>(fieldPath: string, plugins: TPlugins): any;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a composable conditional plugin for guard-based validation
|
|
25
|
+
*
|
|
26
|
+
* @param name - The unique name of the plugin
|
|
27
|
+
* @param methodName - The method name that will be added to the field builder
|
|
28
|
+
* @param allowedTypes - Array of type names this plugin can be applied to
|
|
29
|
+
* @param builderFn - Function that builds validators from accumulated conditions
|
|
30
|
+
* @returns A composable conditional plugin instance
|
|
31
|
+
*/
|
|
32
|
+
export declare function createComposableConditionalPlugin<TName extends string, TMethodName extends string, TAllowedTypes extends readonly TypeName[], TComposition = unknown[]>(name: TName, methodName: TMethodName, allowedTypes: TAllowedTypes, builderFn: <TPlugins>(compositions: TComposition[], fieldPath: string, plugins: TPlugins) => ComposableValidatorResult): ComposableConditionalPlugin<TName, TMethodName, TAllowedTypes>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable Directly Plugin Pattern - For direct builder composition
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for creating composable plugins that directly
|
|
5
|
+
* compose builders without conditional logic. This is specifically designed for
|
|
6
|
+
* tuple validation where each element has its own builder.
|
|
7
|
+
*/
|
|
8
|
+
import type { TypeName } from "../plugins/plugin-types";
|
|
9
|
+
import { type ComposableValidatorResult } from "../plugins/composable-plugin";
|
|
10
|
+
/**
|
|
11
|
+
* Interface for Composable Directly Plugin
|
|
12
|
+
*/
|
|
13
|
+
export interface ComposableDirectlyPlugin<TName extends string, TMethodName extends string, TAllowedTypes extends readonly TypeName[]> {
|
|
14
|
+
name: TName;
|
|
15
|
+
methodName: TMethodName;
|
|
16
|
+
allowedTypes: TAllowedTypes;
|
|
17
|
+
category: "composable-directly";
|
|
18
|
+
/**
|
|
19
|
+
* Create a Composer that directly builds validators
|
|
20
|
+
*/
|
|
21
|
+
createComposer<TPlugins>(fieldPath: string, plugins: TPlugins): any;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a composable directly plugin for direct builder composition
|
|
25
|
+
*
|
|
26
|
+
* @param name - The unique name of the plugin
|
|
27
|
+
* @param methodName - The method name that will be added to the field builder
|
|
28
|
+
* @param allowedTypes - Array of type names this plugin can be applied to
|
|
29
|
+
* @param builderFn - Function that builds validators from composed builders
|
|
30
|
+
* @returns A composable directly plugin instance
|
|
31
|
+
*/
|
|
32
|
+
export declare function createComposableDirectlyPlugin<TName extends string, TMethodName extends string, TAllowedTypes extends readonly TypeName[], TComposition = unknown[]>(name: TName, methodName: TMethodName, allowedTypes: TAllowedTypes, builderFn: <TPlugins>(compositions: TComposition[], fieldPath: string, plugins: TPlugins) => ComposableValidatorResult): ComposableDirectlyPlugin<TName, TMethodName, TAllowedTypes>;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable Plugin Pattern - Accumulate multiple calls and build validators
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for creating composable plugins that can accumulate
|
|
5
|
+
* multiple method calls and build a unified validator. This pattern is useful for
|
|
6
|
+
* validation rules that need to be composed from multiple conditions or checks.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Create a composable plugin
|
|
11
|
+
* const myPlugin = createComposablePlugin(
|
|
12
|
+
* "myPlugin",
|
|
13
|
+
* "check",
|
|
14
|
+
* ["string", "number"] as const,
|
|
15
|
+
* (compositions, fieldPath, plugins) => {
|
|
16
|
+
* // Build validators from compositions
|
|
17
|
+
* const validators = compositions.map(([arg1, arg2]) =>
|
|
18
|
+
* createValidator("myCheck", (value) => checkSomething(value, arg1, arg2))
|
|
19
|
+
* );
|
|
20
|
+
* return createValidatorResult(validators);
|
|
21
|
+
* }
|
|
22
|
+
* );
|
|
23
|
+
*
|
|
24
|
+
* // Use in field builder
|
|
25
|
+
* builder.field("name", b => b.string.check(arg1, arg2).check(arg3, arg4))
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import type { TypeName, TransformFunction } from "../plugins/plugin-types";
|
|
29
|
+
export type { TransformFunction };
|
|
30
|
+
/**
|
|
31
|
+
* Pre-defined validation results for common cases
|
|
32
|
+
*/
|
|
33
|
+
export declare const VALID_RESULT: Readonly<{
|
|
34
|
+
valid: true;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const INVALID_RESULT: Readonly<{
|
|
37
|
+
valid: false;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Basic interface for Composable Plugin
|
|
41
|
+
*/
|
|
42
|
+
export interface ComposablePlugin<TName extends string, TMethodName extends string, TAllowedTypes extends readonly TypeName[]> {
|
|
43
|
+
name: TName;
|
|
44
|
+
methodName: TMethodName;
|
|
45
|
+
allowedTypes: TAllowedTypes;
|
|
46
|
+
category: "composable";
|
|
47
|
+
/**
|
|
48
|
+
* Create a Composer that accumulates multiple calls
|
|
49
|
+
*/
|
|
50
|
+
createComposer<TPlugins>(fieldPath: string, plugins: TPlugins): ComposableComposerWithMethod<TMethodName>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Single validator definition
|
|
54
|
+
*/
|
|
55
|
+
export interface ValidatorDefinition {
|
|
56
|
+
check: (value: unknown, currentValue: unknown) => boolean;
|
|
57
|
+
name: string;
|
|
58
|
+
inputType?: TypeName;
|
|
59
|
+
outputType?: TypeName;
|
|
60
|
+
metadata?: {
|
|
61
|
+
severity?: "error" | "warning" | "info";
|
|
62
|
+
async?: boolean;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validator build result type
|
|
67
|
+
*/
|
|
68
|
+
export interface ComposableValidatorResult {
|
|
69
|
+
_validators: ValidatorDefinition[];
|
|
70
|
+
_transforms: TransformFunction<unknown, unknown>[];
|
|
71
|
+
validate: (value: unknown) => {
|
|
72
|
+
valid: boolean;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a validator result from an array of validators and transforms.
|
|
77
|
+
*
|
|
78
|
+
* @param validators - Array of validator definitions to include
|
|
79
|
+
* @param transforms - Optional array of transform functions to apply
|
|
80
|
+
* @param customValidate - Optional custom validation function that overrides default behavior
|
|
81
|
+
* @returns A composable validator result that can be used by the builder
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const result = createValidatorResult([
|
|
86
|
+
* createValidator("minLength", (value) => value.length >= 3),
|
|
87
|
+
* createValidator("maxLength", (value) => value.length <= 10)
|
|
88
|
+
* ]);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function createValidatorResult(validators: ValidatorDefinition[], transforms?: TransformFunction<unknown, unknown>[], customValidate?: (value: unknown) => {
|
|
92
|
+
valid: boolean;
|
|
93
|
+
}): ComposableValidatorResult;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a validator result from a single validator with optional configuration.
|
|
96
|
+
* This is a convenience function that combines createValidator and createValidatorResult.
|
|
97
|
+
*
|
|
98
|
+
* @param name - The name of the validator
|
|
99
|
+
* @param check - The validation function
|
|
100
|
+
* @param options - Optional configuration including metadata and transforms
|
|
101
|
+
* @returns A composable validator result
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const result = createSingleValidatorResult(
|
|
106
|
+
* "email",
|
|
107
|
+
* (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value),
|
|
108
|
+
* { inputType: "string", severity: "error" }
|
|
109
|
+
* );
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function createSingleValidatorResult(name: string, check: (value: unknown, currentValue: unknown) => boolean, options?: {
|
|
113
|
+
inputType?: TypeName;
|
|
114
|
+
outputType?: TypeName;
|
|
115
|
+
severity?: "error" | "warning" | "info";
|
|
116
|
+
async?: boolean;
|
|
117
|
+
transforms?: TransformFunction<unknown, unknown>[];
|
|
118
|
+
customValidate?: (value: unknown) => {
|
|
119
|
+
valid: boolean;
|
|
120
|
+
};
|
|
121
|
+
}): ComposableValidatorResult;
|
|
122
|
+
/**
|
|
123
|
+
* Creates a single validator definition with metadata.
|
|
124
|
+
*
|
|
125
|
+
* @param name - The name of the validator
|
|
126
|
+
* @param check - The validation function that returns true if valid
|
|
127
|
+
* @param options - Optional metadata for the validator
|
|
128
|
+
* @returns A validator definition
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const validator = createValidator(
|
|
133
|
+
* "range",
|
|
134
|
+
* (value) => value >= 0 && value <= 100,
|
|
135
|
+
* { inputType: "number", severity: "error" }
|
|
136
|
+
* );
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function createValidator(name: string, check: (value: unknown, currentValue: unknown) => boolean, options?: {
|
|
140
|
+
inputType?: TypeName;
|
|
141
|
+
outputType?: TypeName;
|
|
142
|
+
severity?: "error" | "warning" | "info";
|
|
143
|
+
async?: boolean;
|
|
144
|
+
}): ValidatorDefinition;
|
|
145
|
+
/**
|
|
146
|
+
* Composition builder context for accumulating validations
|
|
147
|
+
*/
|
|
148
|
+
export interface CompositionBuilder<TComposition> {
|
|
149
|
+
compositions: TComposition[];
|
|
150
|
+
add(composition: TComposition): this;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Creates a builder for accumulating compositions.
|
|
154
|
+
* This is useful for plugins that need to collect multiple method calls.
|
|
155
|
+
*
|
|
156
|
+
* @returns A composition builder instance
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const builder = createCompositionBuilder<[string, number]>();
|
|
161
|
+
* builder.add(["test", 5]).add(["example", 10]);
|
|
162
|
+
* // builder.compositions now contains all added items
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare function createCompositionBuilder<TComposition>(): CompositionBuilder<TComposition>;
|
|
166
|
+
/**
|
|
167
|
+
* Merges multiple validator results into a single result.
|
|
168
|
+
* All validators and transforms are combined, and validation stops at the first failure.
|
|
169
|
+
*
|
|
170
|
+
* @param results - Array of validator results to merge
|
|
171
|
+
* @returns A single merged validator result
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const result1 = createSingleValidatorResult("min", (v) => v >= 0);
|
|
176
|
+
* const result2 = createSingleValidatorResult("max", (v) => v <= 100);
|
|
177
|
+
* const merged = mergeValidatorResults([result1, result2]);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function mergeValidatorResults(results: ComposableValidatorResult[]): ComposableValidatorResult;
|
|
181
|
+
/**
|
|
182
|
+
* Composer that accumulates calls and builds a validator
|
|
183
|
+
*/
|
|
184
|
+
export interface ComposableComposer<TMethodName extends string> {
|
|
185
|
+
/**
|
|
186
|
+
* Add a call (chainable)
|
|
187
|
+
*/
|
|
188
|
+
add(args: unknown[]): ComposableComposer<TMethodName>;
|
|
189
|
+
/**
|
|
190
|
+
* Build validator from accumulated calls
|
|
191
|
+
*/
|
|
192
|
+
build(): ComposableValidatorResult;
|
|
193
|
+
}
|
|
194
|
+
export type ComposableComposerWithMethod<TMethodName extends string> = ComposableComposer<TMethodName> & {
|
|
195
|
+
[K in TMethodName]: (...args: unknown[]) => ComposableComposerWithMethod<TMethodName>;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Creates a composable plugin that can accumulate multiple method calls.
|
|
199
|
+
*
|
|
200
|
+
* @param name - The unique name of the plugin
|
|
201
|
+
* @param methodName - The method name that will be added to the field builder
|
|
202
|
+
* @param allowedTypes - Array of type names this plugin can be applied to
|
|
203
|
+
* @param builderFn - Function that builds validators from accumulated compositions
|
|
204
|
+
* @returns A composable plugin instance
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Example: Create a range check plugin that accumulates multiple ranges
|
|
209
|
+
* const rangePlugin = createComposablePlugin(
|
|
210
|
+
* "range",
|
|
211
|
+
* "between",
|
|
212
|
+
* ["number"] as const,
|
|
213
|
+
* (compositions: Array<[number, number]>, fieldPath, plugins) => {
|
|
214
|
+
* const validators = compositions.map(([min, max], index) =>
|
|
215
|
+
* createValidator(
|
|
216
|
+
* `range_${index}`,
|
|
217
|
+
* (value) => typeof value === 'number' && value >= min && value <= max,
|
|
218
|
+
* { inputType: "number", severity: "error" }
|
|
219
|
+
* )
|
|
220
|
+
* );
|
|
221
|
+
*
|
|
222
|
+
* // Custom validate function that checks all ranges
|
|
223
|
+
* const customValidate = (value: unknown) => {
|
|
224
|
+
* if (typeof value !== 'number') return { valid: false };
|
|
225
|
+
* return compositions.every(([min, max]) => value >= min && value <= max)
|
|
226
|
+
* ? { valid: true }
|
|
227
|
+
* : { valid: false };
|
|
228
|
+
* };
|
|
229
|
+
*
|
|
230
|
+
* return createValidatorResult(validators, [], customValidate);
|
|
231
|
+
* }
|
|
232
|
+
* );
|
|
233
|
+
*
|
|
234
|
+
* // Usage:
|
|
235
|
+
* builder.field("score", b => b.number.between(0, 100).between(10, 90))
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export declare function createComposablePlugin<TName extends string, TMethodName extends string, TAllowedTypes extends readonly TypeName[], TComposition = unknown[]>(name: TName, methodName: TMethodName, allowedTypes: TAllowedTypes, builderFn: <TPlugins>(compositions: TComposition[], fieldPath: string, plugins: TPlugins) => ComposableValidatorResult): ComposablePlugin<TName, TMethodName, TAllowedTypes>;
|
|
239
|
+
/**
|
|
240
|
+
* Integration of Composable Plugin in Field Context
|
|
241
|
+
*/
|
|
242
|
+
export declare function attachComposablePlugin<TObject extends object, TPlugins, TBuilder>(builder: TBuilder, plugin: ComposablePlugin<string, string, readonly TypeName[]>, fieldPath: string, plugins: TPlugins): void;
|