@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,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @luq-plugin
|
|
3
|
+
* @name unionGuard
|
|
4
|
+
* @category composable-conditional
|
|
5
|
+
* @description Validates union types by applying different validation rules based on type guards
|
|
6
|
+
* @allowedTypes ["union"]
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Union type validation with type guards
|
|
10
|
+
* type StringOrNumber = string | number;
|
|
11
|
+
*
|
|
12
|
+
* const validator = Builder()
|
|
13
|
+
* .use(unionGuardPlugin)
|
|
14
|
+
* .for<{ value: StringOrNumber }>()
|
|
15
|
+
* .v("value", (b) => b.union
|
|
16
|
+
* .guard(
|
|
17
|
+
* (v): v is string => typeof v === 'string',
|
|
18
|
+
* (b) => b.string.min(3)
|
|
19
|
+
* )
|
|
20
|
+
* .guard(
|
|
21
|
+
* (v): v is number => typeof v === 'number',
|
|
22
|
+
* (b) => b.number.min(0).max(100)
|
|
23
|
+
* )
|
|
24
|
+
* )
|
|
25
|
+
* .build();
|
|
26
|
+
* ```
|
|
27
|
+
* @params
|
|
28
|
+
* - condition: TypeGuardCondition - Type guard function that returns true if value matches the type
|
|
29
|
+
* - builderFn: (context: FieldBuilderContext) => any - Builder function for the specific type
|
|
30
|
+
* @returns Composable validation function that can chain multiple guards
|
|
31
|
+
* @customError
|
|
32
|
+
* Returns false if no guard condition matches the value
|
|
33
|
+
* @since 0.1.0-alpha
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Union Guard Plugin - Composable implementation for chaining
|
|
37
|
+
* Supports: guard(cond1, builder1).guard(cond2, builder2)
|
|
38
|
+
*/
|
|
39
|
+
import type { FieldBuilderContext } from "../builder/plugins/plugin-types";
|
|
40
|
+
export interface TypeGuardCondition {
|
|
41
|
+
(value: unknown): boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface GuardBuilderFunction<TObject extends object, TPlugins> {
|
|
44
|
+
(context: FieldBuilderContext<TObject, TPlugins, any>): any;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Union Guard Composable Plugin
|
|
48
|
+
* Accumulates multiple guard calls and builds an integrated validator
|
|
49
|
+
*/
|
|
50
|
+
export declare const unionGuardPlugin: import("../builder/plugins/composable-conditional-plugin").ComposableConditionalPlugin<"unionGuard", "guard", readonly ["union"]>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized Field Accessor Utilities
|
|
3
|
+
*
|
|
4
|
+
* High-performance field access with:
|
|
5
|
+
* - Pre-split path segments cached at build time
|
|
6
|
+
* - No runtime string splitting
|
|
7
|
+
* - Direct property access for common depths
|
|
8
|
+
* - Minimal object allocations
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Get or cache path segments to avoid runtime splitting
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPathSegments(fieldPath: string): readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* Create optimized accessor function for a nested field path
|
|
16
|
+
* V8 Optimization: Generate direct property access code for common depths
|
|
17
|
+
*/
|
|
18
|
+
export declare function createAccessor(pathSegments: readonly string[]): (obj: any) => any;
|
|
19
|
+
/**
|
|
20
|
+
* Create accessor from dot-notation field path with caching
|
|
21
|
+
*/
|
|
22
|
+
export declare function createFieldAccessor(fieldPath: string): (obj: any) => any;
|
|
23
|
+
/**
|
|
24
|
+
* Batch create accessors for multiple field paths
|
|
25
|
+
* Pre-allocates array for better performance
|
|
26
|
+
*/
|
|
27
|
+
export declare function createBatchAccessors(fieldPaths: readonly string[]): Array<{
|
|
28
|
+
fieldName: string;
|
|
29
|
+
accessor: (obj: any) => any;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Create field setter with caching
|
|
33
|
+
* V8 Optimization: Direct property assignment for common depths
|
|
34
|
+
*/
|
|
35
|
+
export declare function createFieldSetter(fieldPath: string): (obj: any, value: any) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Optimized nested value accessor with array support
|
|
38
|
+
* Pre-compiles access patterns for better performance
|
|
39
|
+
*/
|
|
40
|
+
export declare function createNestedValueAccessor(fieldPath: string): (obj: Record<string, unknown>) => unknown;
|
|
41
|
+
/**
|
|
42
|
+
* Pre-warm the cache with common field paths
|
|
43
|
+
* @deprecated Caches have been removed to prevent memory leaks
|
|
44
|
+
*/
|
|
45
|
+
export declare function prewarmCache(commonPaths: string[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* Clear all caches (useful for testing)
|
|
48
|
+
* @deprecated Caches have been removed to prevent memory leaks
|
|
49
|
+
*/
|
|
50
|
+
export declare function clearAllCaches(): void;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field Accessor Utilities
|
|
3
|
+
*
|
|
4
|
+
* Optimized field value access with pre-created accessor functions.
|
|
5
|
+
* V8 Optimization: Direct property access chains for better performance.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create optimized accessor function for a nested field path
|
|
9
|
+
* V8 Optimization: Generate direct property access code for common depths
|
|
10
|
+
*
|
|
11
|
+
* @param pathSegments - Array of property keys to traverse
|
|
12
|
+
* @returns Optimized accessor function
|
|
13
|
+
*/
|
|
14
|
+
export declare function createAccessor(pathSegments: string[]): (obj: any) => any;
|
|
15
|
+
/**
|
|
16
|
+
* Create accessor from dot-notation field path
|
|
17
|
+
*
|
|
18
|
+
* @param fieldPath - Field path in dot notation (e.g., "user.profile.name")
|
|
19
|
+
* @returns Optimized accessor function
|
|
20
|
+
*/
|
|
21
|
+
export declare function createFieldAccessor(fieldPath: string): (obj: any) => any;
|
|
22
|
+
/**
|
|
23
|
+
* Get cached accessor or create new one
|
|
24
|
+
* NOTE: Cache should be managed by the caller (e.g., validator factory)
|
|
25
|
+
* to avoid global state and memory leaks
|
|
26
|
+
*
|
|
27
|
+
* @param fieldPath - Field path in dot notation
|
|
28
|
+
* @param cache - Cache map provided by the caller
|
|
29
|
+
* @returns Cached or newly created accessor function
|
|
30
|
+
*/
|
|
31
|
+
export declare function getCachedAccessor(fieldPath: string, cache: Map<string, (obj: any) => any>): (obj: any) => any;
|
|
32
|
+
/**
|
|
33
|
+
* Create accessor cache factory
|
|
34
|
+
* Returns a function that manages its own cache scope
|
|
35
|
+
*
|
|
36
|
+
* @returns Function to get cached accessors with local cache
|
|
37
|
+
*/
|
|
38
|
+
export declare function createAccessorCacheFactory(): (fieldPath: string) => (obj: any) => any;
|
|
39
|
+
/**
|
|
40
|
+
* Batch create accessors for multiple field paths
|
|
41
|
+
* Useful for plugins that need to access multiple fields
|
|
42
|
+
*
|
|
43
|
+
* @param fieldPaths - Array of field paths in dot notation
|
|
44
|
+
* @returns Array of accessor objects with fieldName and accessor function
|
|
45
|
+
*/
|
|
46
|
+
export declare function createBatchAccessors(fieldPaths: string[]): Array<{
|
|
47
|
+
fieldName: string;
|
|
48
|
+
accessor: (obj: any) => any;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Create field value getter that returns values for multiple fields
|
|
52
|
+
*
|
|
53
|
+
* @param fieldPaths - Array of field paths to access
|
|
54
|
+
* @returns Function that extracts values for all specified fields
|
|
55
|
+
*/
|
|
56
|
+
export declare function createMultiFieldGetter(fieldPaths: string[]): (obj: any) => Record<string, any>;
|
|
57
|
+
/**
|
|
58
|
+
* Optimized field existence checker
|
|
59
|
+
*
|
|
60
|
+
* @param fieldPath - Field path in dot notation
|
|
61
|
+
* @returns Function that checks if field exists (not undefined)
|
|
62
|
+
*/
|
|
63
|
+
export declare function createFieldExistenceChecker(fieldPath: string): (obj: any) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Create field setter for nested paths
|
|
66
|
+
* V8 Optimization: Direct property assignment for common depths
|
|
67
|
+
*
|
|
68
|
+
* @param fieldPath - Field path in dot notation
|
|
69
|
+
* @returns Function that sets the field value
|
|
70
|
+
*/
|
|
71
|
+
export declare function createFieldSetter(fieldPath: string): (obj: any, value: any) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Create optimized nested value accessor with array support
|
|
74
|
+
* Handles array element validation patterns and standard nested access
|
|
75
|
+
* V8 Optimization: Fast paths for common access patterns
|
|
76
|
+
*
|
|
77
|
+
* @param fieldPath - Field path in dot notation
|
|
78
|
+
* @returns Function that gets nested values with array support
|
|
79
|
+
*/
|
|
80
|
+
export declare function createNestedValueAccessor(fieldPath: string): (obj: Record<string, unknown>) => unknown;
|
|
81
|
+
/**
|
|
82
|
+
* Parse field path and detect array element notation [*]
|
|
83
|
+
*
|
|
84
|
+
* @param fieldPath - Field path that may contain [*] notation
|
|
85
|
+
* @returns Object describing the path structure
|
|
86
|
+
*/
|
|
87
|
+
export declare function parseFieldPath(fieldPath: string): {
|
|
88
|
+
hasArrayElements: boolean;
|
|
89
|
+
segments: Array<{
|
|
90
|
+
name: string;
|
|
91
|
+
isArrayElement: boolean;
|
|
92
|
+
}>;
|
|
93
|
+
baseArrayPath?: string;
|
|
94
|
+
elementPath?: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Create accessor for array element fields with [*] notation
|
|
98
|
+
* Returns array of values that should be validated individually
|
|
99
|
+
*
|
|
100
|
+
* @param fieldPath - Field path with [*] notation (e.g., "categories[*]", "categories[*].name")
|
|
101
|
+
* @returns Function that returns array element values for validation
|
|
102
|
+
*/
|
|
103
|
+
export declare function createArrayElementAccessor(fieldPath: string): (obj: any) => {
|
|
104
|
+
elements: any[];
|
|
105
|
+
basePath: string;
|
|
106
|
+
elementPath: string;
|
|
107
|
+
} | null;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ValidationOptions } from "./types";
|
|
2
|
+
declare const SUPPORTED_VERSIONS: readonly [1, 3, 4, 5, 6, 7, 8];
|
|
3
|
+
type UUIDVersion = (typeof SUPPORTED_VERSIONS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* @luq-plugin
|
|
6
|
+
* @name uuid
|
|
7
|
+
* @category standard
|
|
8
|
+
* @description Validates that a string is a valid UUID (Universally Unique Identifier)
|
|
9
|
+
* @allowedTypes ["string"]
|
|
10
|
+
* @see https://tools.ietf.org/html/rfc4122 - RFC 4122: A Universally Unique IDentifier (UUID) URN Namespace
|
|
11
|
+
* @see https://developer.mozilla.org/en-US/docs/Glossary/UUID - MDN UUID Reference
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Basic usage - validate any UUID version (RFC 4122 compliant)
|
|
15
|
+
* const validator = Builder()
|
|
16
|
+
* .use(uuidPlugin)
|
|
17
|
+
* .for<Entity>()
|
|
18
|
+
* .v("id", (b) => b.string.uuid())
|
|
19
|
+
* .v("correlationId", (b) => b.string.required().uuid())
|
|
20
|
+
* .build();
|
|
21
|
+
*
|
|
22
|
+
* // Validate specific UUID version
|
|
23
|
+
* builder.v("userId", b => b.string.uuid(4)) // UUID v4 only
|
|
24
|
+
* builder.v("namespaceId", b => b.string.uuid(5)) // UUID v5 only
|
|
25
|
+
* builder.v("timestamp", b => b.string.uuid(7)) // UUID v7 only (time-based)
|
|
26
|
+
*
|
|
27
|
+
* // ✅ VALID UUID formats (RFC 4122)
|
|
28
|
+
* // UUID v1 (MAC address + timestamp based)
|
|
29
|
+
* validator.parse({ id: "12345678-1234-1234-8123-123456789abc" });
|
|
30
|
+
* validator.parse({ id: "f47ac10b-58cc-4372-a567-0e02b2c3d479" });
|
|
31
|
+
*
|
|
32
|
+
* // UUID v3 (MD5 hash based)
|
|
33
|
+
* validator.parse({ id: "6ba7b810-9dad-11d1-80b4-00c04fd430c8" });
|
|
34
|
+
* validator.parse({ id: "12345678-1234-3234-8123-123456789abc" });
|
|
35
|
+
*
|
|
36
|
+
* // UUID v4 (random)
|
|
37
|
+
* validator.parse({ id: "550e8400-e29b-41d4-a716-446655440000" });
|
|
38
|
+
* validator.parse({ id: "f47ac10b-58cc-4372-a567-0e02b2c3d479" });
|
|
39
|
+
* validator.parse({ id: "12345678-1234-4234-9123-123456789abc" });
|
|
40
|
+
*
|
|
41
|
+
* // UUID v5 (SHA-1 hash based)
|
|
42
|
+
* validator.parse({ id: "6ba7b811-9dad-11d1-80b4-00c04fd430c8" });
|
|
43
|
+
* validator.parse({ id: "12345678-1234-5234-8123-123456789abc" });
|
|
44
|
+
*
|
|
45
|
+
* // UUID v6 (reordered timestamp)
|
|
46
|
+
* validator.parse({ id: "1EC9414C-232A-6B00-B3C8-9E6BDECED846" });
|
|
47
|
+
* validator.parse({ id: "12345678-1234-6234-9123-123456789abc" });
|
|
48
|
+
*
|
|
49
|
+
* // UUID v7 (Unix timestamp based)
|
|
50
|
+
* validator.parse({ id: "017F22E2-79B0-7CC3-98C4-DC0C0C07398F" });
|
|
51
|
+
* validator.parse({ id: "12345678-1234-7234-8123-123456789abc" });
|
|
52
|
+
*
|
|
53
|
+
* // UUID v8 (custom/application-specific)
|
|
54
|
+
* validator.parse({ id: "12345678-1234-8234-9123-123456789abc" });
|
|
55
|
+
*
|
|
56
|
+
* // Case insensitive
|
|
57
|
+
* validator.parse({ id: "F47AC10B-58CC-4372-A567-0E02B2C3D479" });
|
|
58
|
+
* validator.parse({ id: "f47ac10b-58cc-4372-a567-0e02b2c3d479" });
|
|
59
|
+
*
|
|
60
|
+
* // ❌ INVALID UUID formats
|
|
61
|
+
* validator.parse({ id: "not-a-uuid" }); // Plain text
|
|
62
|
+
* validator.parse({ id: "12345678-1234-1234-1234-123456789" }); // Too short
|
|
63
|
+
* validator.parse({ id: "12345678-1234-1234-1234-123456789abcd" }); // Too long
|
|
64
|
+
* validator.parse({ id: "12345678-1234-0234-8123-123456789abc" }); // Invalid version (0)
|
|
65
|
+
* validator.parse({ id: "12345678-1234-9234-8123-123456789abc" }); // Invalid version (9)
|
|
66
|
+
* validator.parse({ id: "12345678-1234-4234-0123-123456789abc" }); // Invalid variant (0)
|
|
67
|
+
* validator.parse({ id: "12345678-1234-4234-c123-123456789abc" }); // Invalid variant (c)
|
|
68
|
+
* validator.parse({ id: "12345678-1234-4234-g123-123456789abc" }); // Invalid hex char (g)
|
|
69
|
+
* validator.parse({ id: "12345678123412348123123456789abc" }); // Missing hyphens
|
|
70
|
+
* validator.parse({ id: "12345678-1234-4234-8123-123456789ab" }); // Missing last char
|
|
71
|
+
* validator.parse({ id: "12345678-1234-4234-8123-123456789abcX" }); // Extra char
|
|
72
|
+
* validator.parse({ id: "" }); // Empty string
|
|
73
|
+
* validator.parse({ id: "12345678-1234-4234-8123-123456789ab " }); // Trailing space
|
|
74
|
+
* validator.parse({ id: " 12345678-1234-4234-8123-123456789abc" }); // Leading space
|
|
75
|
+
* ```
|
|
76
|
+
* @params
|
|
77
|
+
* - version?: 1 | 3 | 4 | 5 | 6 | 7 | 8 - Specific UUID version to validate (optional)
|
|
78
|
+
* - options?: { messageFactory?: (context: MessageContext) => string } - Optional configuration
|
|
79
|
+
* @returns Validation function that returns true if string is a valid UUID
|
|
80
|
+
* @customError
|
|
81
|
+
* ```typescript
|
|
82
|
+
* .uuid(4, {
|
|
83
|
+
* messageFactory: ({ path, value, params }) =>
|
|
84
|
+
* `${path} must be a valid UUID v${params.version} (received: ${value})`
|
|
85
|
+
* })
|
|
86
|
+
* ```
|
|
87
|
+
* @since 0.1.0-alpha
|
|
88
|
+
*/
|
|
89
|
+
export declare const uuidPlugin: import("../..").TypedPlugin<"stringUuid", "uuid", (version?: UUIDVersion | readonly UUIDVersion[], options?: ValidationOptions) => {
|
|
90
|
+
check: (value: any) => boolean;
|
|
91
|
+
code: string;
|
|
92
|
+
getErrorMessage: (value: any, path: string) => string;
|
|
93
|
+
params: (1 | 5 | 7 | 3 | 4 | ValidationOptions<{}> | 6 | 8 | readonly (1 | 5 | 7 | 3 | 4 | 6 | 8)[])[];
|
|
94
|
+
}, readonly ["string"], "validator", "standard">;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ValidationOptions, MessageContext } from "./types";
|
|
2
|
+
export interface ValidateIfContext extends MessageContext {
|
|
3
|
+
condition?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @luq-plugin
|
|
7
|
+
* @name validateIf
|
|
8
|
+
* @category conditional
|
|
9
|
+
* @description Conditionally applies all validation rules to a field based on a dynamic condition, with support for array context validation
|
|
10
|
+
* @allowedTypes ["string", "number", "boolean", "array", "object", "date", "union"]
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Validate URL only when custom endpoint is enabled
|
|
14
|
+
* const validator = Builder()
|
|
15
|
+
* .use(validateIfPlugin)
|
|
16
|
+
* .for<ConfigData>()
|
|
17
|
+
* .v("customEndpoint", b =>
|
|
18
|
+
* b.string
|
|
19
|
+
* .validateIf(values => values.useCustomEndpoint)
|
|
20
|
+
* .url()
|
|
21
|
+
* .min(10)
|
|
22
|
+
* )
|
|
23
|
+
* .build();
|
|
24
|
+
*
|
|
25
|
+
* // Skip validation in local environment
|
|
26
|
+
* builder.v("apiKey", b =>
|
|
27
|
+
* b.string
|
|
28
|
+
* .validateIf(values => values.environment !== 'local')
|
|
29
|
+
* .required()
|
|
30
|
+
* .min(32)
|
|
31
|
+
* )
|
|
32
|
+
*
|
|
33
|
+
* // Conditional sections in forms
|
|
34
|
+
* builder.v("businessDetails.taxId", b =>
|
|
35
|
+
* b.string
|
|
36
|
+
* .validateIf(values => values.accountType === 'business')
|
|
37
|
+
* .required()
|
|
38
|
+
* .pattern(/^\d{9}$/)
|
|
39
|
+
* )
|
|
40
|
+
* ```
|
|
41
|
+
* @params
|
|
42
|
+
* - condition: (allValues: TObject, arrayContext?: ArrayContext) => boolean - Function that returns true if validation should run, with access to array context
|
|
43
|
+
* - options?: ValidationOptions - Optional configuration
|
|
44
|
+
* @returns Validation function that skips all validations when condition is false
|
|
45
|
+
* @customError
|
|
46
|
+
* ```typescript
|
|
47
|
+
* This plugin does not generate errors - it controls whether validation runs
|
|
48
|
+
* ```
|
|
49
|
+
* @since 0.1.0-alpha
|
|
50
|
+
*/
|
|
51
|
+
export declare const validateIfPlugin: import("../..").TypedPlugin<"validateIf", "validateIf", <TObject>(condition: (allValues: TObject, arrayContext?: import("./types").ArrayContext) => boolean, options?: ValidationOptions<ValidateIfContext>) => {
|
|
52
|
+
check: (value: any, allValues?: TObject, arrayContext?: import("./types").ArrayContext) => boolean;
|
|
53
|
+
code: string;
|
|
54
|
+
getErrorMessage: () => never;
|
|
55
|
+
params: (((allValues: TObject, arrayContext?: import("./types").ArrayContext) => boolean) | ValidationOptions<ValidateIfContext>)[];
|
|
56
|
+
shouldSkipAllValidation: (value: any, allValues?: TObject, arrayContext?: import("./types").ArrayContext) => boolean;
|
|
57
|
+
}, readonly ["string", "number", "boolean", "array", "object", "date", "union"], "validator", "conditional">;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Registry - Shared plugin management for reusable field rules
|
|
3
|
+
*
|
|
4
|
+
* Enables:
|
|
5
|
+
* 1. Pre-defining field validation rules with plugins
|
|
6
|
+
* 2. Individual field validation before integration
|
|
7
|
+
* 3. Shared plugin pools for team consistency
|
|
8
|
+
*/
|
|
9
|
+
import { Result } from "../../types/result";
|
|
10
|
+
import { ValidationOptions, ParseOptions } from "../../types";
|
|
11
|
+
import type { TypedPlugin, FieldBuilderContext, ChainableFieldBuilder, PluginCategory, TypeName, PluginType } from "../builder/plugins/plugin-types";
|
|
12
|
+
import { IChainableBuilder } from "../builder/core/builder";
|
|
13
|
+
import type { NestedKeyOf, TypeOfPath } from "../../types/util";
|
|
14
|
+
/**
|
|
15
|
+
* Field Rule - Individual field validation rule with plugin support
|
|
16
|
+
*/
|
|
17
|
+
export interface FieldRule<T> {
|
|
18
|
+
readonly _phantomType: T;
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
readonly description?: string;
|
|
21
|
+
readonly fieldOptions?: import("../builder/types/field-options").FieldOptions<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Validate single field value
|
|
24
|
+
*/
|
|
25
|
+
validate(value: T | unknown, options?: ValidationOptions): Result<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Parse single field value (with transformations)
|
|
28
|
+
*/
|
|
29
|
+
parse(value: T | unknown, options?: ParseOptions): Result<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the plugin registry used by this rule
|
|
32
|
+
*/
|
|
33
|
+
getPluginRegistry(): PluginRegistry<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Internal: Get validators and transforms for integration
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
_getInternalValidators?: () => {
|
|
39
|
+
validators: any[];
|
|
40
|
+
transforms: any[];
|
|
41
|
+
executionPlan: any;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Plugin Registry - Manages shared plugins for field rules with type accumulation
|
|
46
|
+
*/
|
|
47
|
+
export interface PluginRegistry<TPlugins = {}> {
|
|
48
|
+
/**
|
|
49
|
+
* Add a plugin to the registry with type accumulation
|
|
50
|
+
*/
|
|
51
|
+
use<TName extends string, TMethodName extends string, TMethod extends Function, TAllowedTypes extends readonly TypeName[] | undefined, TPluginType extends PluginType = PluginType, TCategory extends PluginCategory = PluginCategory>(plugin: TypedPlugin<TName, TMethodName, TMethod, TAllowedTypes, TPluginType, TCategory>): PluginRegistry<TPlugins & {
|
|
52
|
+
[K in TName]: TypedPlugin<TName, TMethodName, TMethod, TAllowedTypes, TPluginType, TCategory>;
|
|
53
|
+
}> & TPlugins & {
|
|
54
|
+
[K in TMethodName]: TMethod;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Create a field rule using registered plugins with practical type inference
|
|
58
|
+
*/
|
|
59
|
+
createFieldRule<T>(definition: (context: FieldBuilderContext<any, TPlugins, T>) => ChainableFieldBuilder<any, TPlugins, any, T>, options?: {
|
|
60
|
+
name?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
fieldOptions?: import("../builder/types/field-options").FieldOptions<T>;
|
|
63
|
+
} | import("../builder/types/field-options").FieldConfig<T>): FieldRule<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Create a builder instance using this registry's plugins
|
|
66
|
+
*/
|
|
67
|
+
toBuilder(): IChainableBuilder<any, TPlugins & {
|
|
68
|
+
[K in keyof TPlugins]: TPlugins[K] extends TypedPlugin<any, any, any, any, any, any> ? TPlugins[K] : never;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Get all registered plugins
|
|
72
|
+
*/
|
|
73
|
+
getPlugins(): Record<string, TypedPlugin<any, any, any, any, any, any>>;
|
|
74
|
+
/**
|
|
75
|
+
* Set the target type for type-safe field rule creation
|
|
76
|
+
*/
|
|
77
|
+
for<TObject extends object>(): TypedPluginRegistry<TObject, TPlugins>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Type-safe Plugin Registry with target type specified
|
|
81
|
+
*/
|
|
82
|
+
export interface TypedPluginRegistry<TObject extends object, TPlugins = {}> extends Omit<PluginRegistry<TPlugins>, "createFieldRule" | "for"> {
|
|
83
|
+
/**
|
|
84
|
+
* Create a field rule with type-safe field names and automatic type inference
|
|
85
|
+
*/
|
|
86
|
+
createFieldRule<TName extends NestedKeyOf<TObject> & string, TExplicitType = TypeOfPath<TObject, TName>>(definition: (context: FieldBuilderContext<TObject, TPlugins, TExplicitType>) => ChainableFieldBuilder<TObject, TPlugins, any, TExplicitType>, options: {
|
|
87
|
+
name: TName;
|
|
88
|
+
description?: string;
|
|
89
|
+
fieldOptions?: import("../builder/types/field-options").FieldOptions<TExplicitType>;
|
|
90
|
+
}): FieldRule<TExplicitType>;
|
|
91
|
+
/**
|
|
92
|
+
* Create a field rule with explicit type override
|
|
93
|
+
*/
|
|
94
|
+
createFieldRule<T>(definition: (context: FieldBuilderContext<any, TPlugins, T>) => ChainableFieldBuilder<any, TPlugins, any, T>, options: {
|
|
95
|
+
name: NestedKeyOf<TObject> & string;
|
|
96
|
+
description?: string;
|
|
97
|
+
fieldOptions?: import("../builder/types/field-options").FieldOptions<T>;
|
|
98
|
+
}): FieldRule<T>;
|
|
99
|
+
/**
|
|
100
|
+
* Change the target type
|
|
101
|
+
*/
|
|
102
|
+
for<TNewObject extends object>(): TypedPluginRegistry<TNewObject, TPlugins>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a new plugin registry with empty plugin set
|
|
106
|
+
* Generic type parameter allows TypeScript to properly track plugin accumulation
|
|
107
|
+
*/
|
|
108
|
+
export declare function createPluginRegistry<TPlugins = {}>(): PluginRegistry<TPlugins>;
|
|
109
|
+
/**
|
|
110
|
+
* Type helper to extract the field type from a FieldRule
|
|
111
|
+
*/
|
|
112
|
+
export type ExtractFieldRuleType<T> = T extends FieldRule<infer U> ? U : never;
|
|
113
|
+
/**
|
|
114
|
+
* Type helper for field rule definitions
|
|
115
|
+
*/
|
|
116
|
+
export type FieldRuleDefinition<T, TPlugins = {}> = (context: FieldBuilderContext<{}, TPlugins, T>) => ChainableFieldBuilder<{}, TPlugins, any, T>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Luq Registry - Plugin registry functionality
|
|
3
|
+
*
|
|
4
|
+
* This entry point exports the plugin registry system.
|
|
5
|
+
*/
|
|
6
|
+
export { createPluginRegistry, type PluginRegistry, type FieldRule, type ExtractFieldRuleType, type FieldRuleDefinition, type TypedPluginRegistry } from "./registry/plugin-registry";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as string from "./string";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a default value transform function
|
|
3
|
+
* @param defaultValue - The default value to use when input is null or undefined
|
|
4
|
+
* @returns A function that returns the input value or default
|
|
5
|
+
*/
|
|
6
|
+
export declare function createDefaultValue(defaultValue: string): (value: string | null | undefined) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a replace transform function
|
|
3
|
+
* @param searchValue - The string or regex pattern to search for
|
|
4
|
+
* @param replaceValue - The string to replace matches with
|
|
5
|
+
* @returns A function that performs the replacement
|
|
6
|
+
*/
|
|
7
|
+
export declare function createReplace(searchValue: string | RegExp, replaceValue: string): (value: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Replaces all occurrences of a string
|
|
10
|
+
* @param searchValue - The string to search for
|
|
11
|
+
* @param replaceValue - The string to replace matches with
|
|
12
|
+
* @returns A function that performs the replacement
|
|
13
|
+
*/
|
|
14
|
+
export declare function createReplaceAll(searchValue: string, replaceValue: string): (value: string) => string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common type guard utilities
|
|
3
|
+
* Centralizes type checking logic to reduce code duplication and bundle size
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a value is a non-null object (excluding arrays)
|
|
7
|
+
*/
|
|
8
|
+
export declare const isObject: (value: unknown) => value is object;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a value is a plain object (not Date, RegExp, etc.)
|
|
11
|
+
*/
|
|
12
|
+
export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a value is a string
|
|
15
|
+
*/
|
|
16
|
+
export declare const isString: (value: unknown) => value is string;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if a value is a number
|
|
19
|
+
*/
|
|
20
|
+
export declare const isNumber: (value: unknown) => value is number;
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a value is a boolean
|
|
23
|
+
*/
|
|
24
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a value is a function
|
|
27
|
+
*/
|
|
28
|
+
export declare const isFunction: (value: unknown) => value is Function;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a value is an array
|
|
31
|
+
*/
|
|
32
|
+
export declare const isArray: (arg: any) => arg is any[];
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a value is null or undefined
|
|
35
|
+
*/
|
|
36
|
+
export declare const isNullish: (value: unknown) => value is null | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a value is undefined
|
|
39
|
+
*/
|
|
40
|
+
export declare const isUndefined: (value: unknown) => value is undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a value is null
|
|
43
|
+
*/
|
|
44
|
+
export declare const isNull: (value: unknown) => value is null;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a value is an Error instance
|
|
47
|
+
*/
|
|
48
|
+
export declare const isError: (value: unknown) => value is Error;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if an object has a specific property
|
|
51
|
+
*/
|
|
52
|
+
export declare const hasProperty: <T extends object, K extends PropertyKey>(obj: T, key: K) => obj is T & Record<K, unknown>;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a value is a valid Date
|
|
55
|
+
*/
|
|
56
|
+
export declare const isValidDate: (value: unknown) => value is Date;
|
|
57
|
+
/**
|
|
58
|
+
* Checks if a value is a finite number
|
|
59
|
+
*/
|
|
60
|
+
export declare const isFiniteNumber: (value: unknown) => value is number;
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a value is an integer
|
|
63
|
+
*/
|
|
64
|
+
export declare const isInteger: (value: unknown) => value is number;
|
|
65
|
+
/**
|
|
66
|
+
* Type guard for checking multiple types at once
|
|
67
|
+
*/
|
|
68
|
+
export declare const isOneOfTypes: <T extends readonly unknown[]>(value: unknown, guards: Array<(value: unknown) => value is T[number]>) => value is T[number];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Luq - TypeScript validation library
|
|
3
|
+
*
|
|
4
|
+
* Single entry point for all Luq functionality.
|
|
5
|
+
* This file exports everything from the library.
|
|
6
|
+
*/
|
|
7
|
+
export { Builder } from "./core/builder/core/builder";
|
|
8
|
+
export { createPluginRegistry, type PluginRegistry, type FieldRule, type ExtractFieldRuleType, type FieldRuleDefinition } from "./core/registry/plugin-registry";
|
|
9
|
+
export { type FieldBuilder, type TransformAwareValidator, type ApplyFieldTransforms, type ExtractFieldType, type TypedPlugin, type PluginType, type PluginCategory, type TypeName, type BuilderExtensionPlugin, type BuilderExtensionMethod, } from "./core/builder/plugins/plugin-types";
|
|
10
|
+
export { ValidationResult } from "./core/builder/plugins/plugin-types";
|
|
11
|
+
export { type ValidationOptions, type MessageContext, type SEVERITY, } from "./core/plugin/types";
|
|
12
|
+
export { type PluginValidationResult as BasicValidationResult, type StandardPluginImplementation, type ConditionalPluginImplementation, type TransformPluginImplementation, type FieldReferencePluginImplementation, type ArrayElementPluginImplementation, } from "./core/builder/plugins/plugin-interfaces";
|
|
13
|
+
export { plugin, type PluginImplementation, pluginPredefinedTransform, pluginConfigurableTransform, pluginBuilderExtension, } from "./core/builder/plugins/plugin-creator";
|
|
14
|
+
export { Result } from "./types/result";
|
|
15
|
+
export { GlobalConfig, globalConfig, setGlobalConfig, getGlobalConfig, resetGlobalConfig, } from "./core/global-config";
|
|
16
|
+
export { requiredPlugin } from "./core/plugin/required";
|
|
17
|
+
export { optionalPlugin } from "./core/plugin/optional";
|
|
18
|
+
export { nullablePlugin } from "./core/plugin/nullable";
|
|
19
|
+
export { stringMinPlugin } from "./core/plugin/stringMin";
|
|
20
|
+
export { stringMaxPlugin } from "./core/plugin/stringMax";
|
|
21
|
+
export { stringEmailPlugin } from "./core/plugin/stringEmail";
|
|
22
|
+
export { stringPatternPlugin } from "./core/plugin/stringPattern";
|
|
23
|
+
export { stringUrlPlugin } from "./core/plugin/stringUrl";
|
|
24
|
+
export { stringDatePlugin } from "./core/plugin/stringDate";
|
|
25
|
+
export { stringDatetimePlugin } from "./core/plugin/stringDatetime";
|
|
26
|
+
export { stringTimePlugin } from "./core/plugin/stringTime";
|
|
27
|
+
export { stringIpv4Plugin } from "./core/plugin/stringIpv4";
|
|
28
|
+
export { stringIpv6Plugin } from "./core/plugin/stringIpv6";
|
|
29
|
+
export { stringHostnamePlugin } from "./core/plugin/stringHostname";
|
|
30
|
+
export { stringDurationPlugin } from "./core/plugin/stringDuration";
|
|
31
|
+
export { stringBase64Plugin } from "./core/plugin/stringBase64";
|
|
32
|
+
export { stringJsonPointerPlugin } from "./core/plugin/stringJsonPointer";
|
|
33
|
+
export { stringRelativeJsonPointerPlugin } from "./core/plugin/stringRelativeJsonPointer";
|
|
34
|
+
export { stringIriPlugin } from "./core/plugin/stringIri";
|
|
35
|
+
export { stringIriReferencePlugin } from "./core/plugin/stringIriReference";
|
|
36
|
+
export { stringUriTemplatePlugin } from "./core/plugin/stringUriTemplate";
|
|
37
|
+
export { stringContentEncodingPlugin } from "./core/plugin/stringContentEncoding";
|
|
38
|
+
export { stringContentMediaTypePlugin } from "./core/plugin/stringContentMediaType";
|
|
39
|
+
export { uuidPlugin } from "./core/plugin/uuid";
|
|
40
|
+
export { numberMinPlugin } from "./core/plugin/numberMin";
|
|
41
|
+
export { numberMaxPlugin } from "./core/plugin/numberMax";
|
|
42
|
+
export { numberPositivePlugin } from "./core/plugin/numberPositive";
|
|
43
|
+
export { numberNegativePlugin } from "./core/plugin/numberNegative";
|
|
44
|
+
export { numberIntegerPlugin } from "./core/plugin/numberInteger";
|
|
45
|
+
export { numberMultipleOfPlugin } from "./core/plugin/numberMultipleOf";
|
|
46
|
+
export { booleanTruthyPlugin } from "./core/plugin/booleanTruthy";
|
|
47
|
+
export { booleanFalsyPlugin } from "./core/plugin/booleanFalsy";
|
|
48
|
+
export { arrayMinLengthPlugin } from "./core/plugin/arrayMinLength";
|
|
49
|
+
export { arrayMaxLengthPlugin } from "./core/plugin/arrayMaxLength";
|
|
50
|
+
export { arrayUniquePlugin } from "./core/plugin/arrayUnique";
|
|
51
|
+
export { arrayIncludesPlugin } from "./core/plugin/arrayIncludes";
|
|
52
|
+
export { arrayContainsPlugin } from "./core/plugin/arrayContains";
|
|
53
|
+
export { objectPlugin } from "./core/plugin/object";
|
|
54
|
+
export { objectMinPropertiesPlugin } from "./core/plugin/objectMinProperties";
|
|
55
|
+
export { objectMaxPropertiesPlugin } from "./core/plugin/objectMaxProperties";
|
|
56
|
+
export { objectAdditionalPropertiesPlugin } from "./core/plugin/objectAdditionalProperties";
|
|
57
|
+
export { objectPropertyNamesPlugin } from "./core/plugin/objectPropertyNames";
|
|
58
|
+
export { objectPatternPropertiesPlugin } from "./core/plugin/objectPatternProperties";
|
|
59
|
+
export { objectDependentRequiredPlugin } from "./core/plugin/objectDependentRequired";
|
|
60
|
+
export { objectDependentSchemasPlugin } from "./core/plugin/objectDependentSchemas";
|
|
61
|
+
export { oneOfPlugin } from "./core/plugin/oneOf";
|
|
62
|
+
export { literalPlugin } from "./core/plugin/literal";
|
|
63
|
+
export { compareFieldPlugin } from "./core/plugin/compareField";
|
|
64
|
+
export { requiredIfPlugin } from "./core/plugin/requiredIf";
|
|
65
|
+
export { validateIfPlugin } from "./core/plugin/validateIf";
|
|
66
|
+
export { skipPlugin } from "./core/plugin/skip";
|
|
67
|
+
export { transformPlugin } from "./core/plugin/transform";
|
|
68
|
+
export { tupleBuilderPlugin } from "./core/plugin/tupleBuilder";
|
|
69
|
+
export { readOnlyWriteOnlyPlugin } from "./core/plugin/readOnlyWriteOnly";
|
|
70
|
+
export { customPlugin } from "./core/plugin/custom";
|
|
71
|
+
export { jsonSchemaPlugin } from "./core/plugin/jsonSchema";
|
|
72
|
+
export { jsonSchemaFullFeaturePlugin } from "./core/plugin/jsonSchemaFullFeature";
|