@regle/core 1.2.0-beta.2 → 1.2.0-beta.3
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/dist/regle-core.d.ts +78 -69
- package/package.json +8 -8
package/dist/regle-core.d.ts
CHANGED
|
@@ -157,6 +157,46 @@ type Fail = IsEmptyObject<null>; //=> false
|
|
|
157
157
|
*/
|
|
158
158
|
type IsEmptyObject<T> = T extends EmptyObject ? true : false;
|
|
159
159
|
|
|
160
|
+
/**
|
|
161
|
+
Extract all optional keys from the given type.
|
|
162
|
+
|
|
163
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
164
|
+
|
|
165
|
+
@example
|
|
166
|
+
```
|
|
167
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
168
|
+
|
|
169
|
+
interface User {
|
|
170
|
+
name: string;
|
|
171
|
+
surname: string;
|
|
172
|
+
|
|
173
|
+
luckyNumber?: number;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
177
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
178
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const update1: UpdateOperation<User> = {
|
|
182
|
+
name: 'Alice'
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const update2: UpdateOperation<User> = {
|
|
186
|
+
name: 'Bob',
|
|
187
|
+
luckyNumber: REMOVE_FIELD
|
|
188
|
+
};
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
@category Utilities
|
|
192
|
+
*/
|
|
193
|
+
type OptionalKeysOf<BaseType extends object> =
|
|
194
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
195
|
+
? (keyof {
|
|
196
|
+
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
197
|
+
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
198
|
+
: never; // Should never happen
|
|
199
|
+
|
|
160
200
|
/**
|
|
161
201
|
Extract all required keys from the given type.
|
|
162
202
|
|
|
@@ -181,11 +221,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
|
|
|
181
221
|
|
|
182
222
|
@category Utilities
|
|
183
223
|
*/
|
|
184
|
-
type RequiredKeysOf<BaseType extends object> =
|
|
185
|
-
|
|
186
|
-
?
|
|
187
|
-
: never
|
|
188
|
-
}[keyof BaseType], undefined>;
|
|
224
|
+
type RequiredKeysOf<BaseType extends object> =
|
|
225
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
226
|
+
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
|
|
227
|
+
: never; // Should never happen
|
|
189
228
|
|
|
190
229
|
/**
|
|
191
230
|
Returns a boolean for whether the given type is `never`.
|
|
@@ -566,45 +605,6 @@ type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
|
566
605
|
IsAny$1<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
567
606
|
);
|
|
568
607
|
|
|
569
|
-
/**
|
|
570
|
-
Extract all optional keys from the given type.
|
|
571
|
-
|
|
572
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
573
|
-
|
|
574
|
-
@example
|
|
575
|
-
```
|
|
576
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
577
|
-
|
|
578
|
-
interface User {
|
|
579
|
-
name: string;
|
|
580
|
-
surname: string;
|
|
581
|
-
|
|
582
|
-
luckyNumber?: number;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
586
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
587
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
const update1: UpdateOperation<User> = {
|
|
591
|
-
name: 'Alice'
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
const update2: UpdateOperation<User> = {
|
|
595
|
-
name: 'Bob',
|
|
596
|
-
luckyNumber: REMOVE_FIELD
|
|
597
|
-
};
|
|
598
|
-
```
|
|
599
|
-
|
|
600
|
-
@category Utilities
|
|
601
|
-
*/
|
|
602
|
-
type OptionalKeysOf<BaseType extends object> = Exclude<{
|
|
603
|
-
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
|
|
604
|
-
? never
|
|
605
|
-
: Key
|
|
606
|
-
}[keyof BaseType], undefined>;
|
|
607
|
-
|
|
608
608
|
/**
|
|
609
609
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
610
610
|
*/
|
|
@@ -723,7 +723,11 @@ type ApplyDefaultOptions<
|
|
|
723
723
|
IfNever<SpecifiedOptions, Defaults,
|
|
724
724
|
Simplify<Merge<Defaults, {
|
|
725
725
|
[Key in keyof SpecifiedOptions
|
|
726
|
-
as Key extends OptionalKeysOf<Options>
|
|
726
|
+
as Key extends OptionalKeysOf<Options>
|
|
727
|
+
? Extract<SpecifiedOptions[Key], undefined> extends never
|
|
728
|
+
? Key
|
|
729
|
+
: never
|
|
730
|
+
: Key
|
|
727
731
|
]: SpecifiedOptions[Key]
|
|
728
732
|
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
729
733
|
>>;
|
|
@@ -893,27 +897,29 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
|
893
897
|
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
894
898
|
_PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
895
899
|
|
|
896
|
-
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((
|
|
900
|
+
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown))
|
|
897
901
|
? T
|
|
898
|
-
: T extends
|
|
899
|
-
?
|
|
900
|
-
: T extends
|
|
901
|
-
?
|
|
902
|
-
: T extends
|
|
903
|
-
?
|
|
904
|
-
: T extends
|
|
905
|
-
?
|
|
906
|
-
: T extends
|
|
907
|
-
?
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
902
|
+
: IsNever$1<keyof T> extends true // For functions with no properties
|
|
903
|
+
? T
|
|
904
|
+
: T extends Map<infer KeyType, infer ValueType>
|
|
905
|
+
? PartialMapDeep<KeyType, ValueType, Options>
|
|
906
|
+
: T extends Set<infer ItemType>
|
|
907
|
+
? PartialSetDeep<ItemType, Options>
|
|
908
|
+
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
909
|
+
? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
|
910
|
+
: T extends ReadonlySet<infer ItemType>
|
|
911
|
+
? PartialReadonlySetDeep<ItemType, Options>
|
|
912
|
+
: T extends object
|
|
913
|
+
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
914
|
+
? Options['recurseIntoArrays'] extends true
|
|
915
|
+
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
916
|
+
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
917
|
+
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
918
|
+
: Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
919
|
+
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
920
|
+
: T // If they don't opt into array testing, just use the original type
|
|
921
|
+
: PartialObjectDeep<T, Options>
|
|
922
|
+
: unknown;
|
|
917
923
|
|
|
918
924
|
/**
|
|
919
925
|
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
@@ -938,9 +944,12 @@ type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {
|
|
|
938
944
|
/**
|
|
939
945
|
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
940
946
|
*/
|
|
941
|
-
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
|
|
942
|
-
|
|
943
|
-
|
|
947
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
|
|
948
|
+
(ObjectType extends (...arguments_: any) => unknown
|
|
949
|
+
? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
|
|
950
|
+
: {}) & ({
|
|
951
|
+
[KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
|
|
952
|
+
});
|
|
944
953
|
|
|
945
954
|
type ExcludeUndefined<T> = Exclude<T, undefined>;
|
|
946
955
|
|
|
@@ -2751,4 +2760,4 @@ declare function defineRules<TRules extends RegleUnknownRulesTree>(rules: TRules
|
|
|
2751
2760
|
*/
|
|
2752
2761
|
declare function refineRules<TRules extends RegleUnknownRulesTree, TRefinement extends ReglePartialRuleTree<InferInput<TRules>> & RegleUnknownRulesTree>(rules: TRules, refinement: (state: Ref<InferInput<TRules>>) => TRefinement): (state: Ref<InferInput<TRules>>) => Merge<TRules, TRefinement>;
|
|
2753
2762
|
|
|
2754
|
-
export { type $InternalRegleStatus, type AllRulesDeclarations, type CommonAlphaOptions, type CommonComparisonOptions, type DeepMaybeRef, type DeepReactiveState, type DefaultValidatorsTree, type FormRuleDeclaration, type InferInput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InferSafeOutput, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeVariantStatus, type MergedRegles, type NarrowVariant, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleShortcutDefinition, type RegleSingleField, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, useRegle, useRootStorage, useScopedRegle, variantToRef };
|
|
2763
|
+
export { type $InternalRegleStatus, type AllRulesDeclarations, type CommonAlphaOptions, type CommonComparisonOptions, type DeepMaybeRef, type DeepReactiveState, type DefaultValidatorsTree, type FormRuleDeclaration, type InferInput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InferSafeOutput, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeVariantStatus, type MergedRegles, type NarrowVariant, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleShortcutDefinition, type RegleSingleField, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, type inferRulesFn, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, useRegle, type useRegleFn, useRootStorage, useScopedRegle, variantToRef };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/core",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.3",
|
|
4
4
|
"description": "Headless form validation library for Vue 3",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"pinia": ">=2.2.5",
|
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@total-typescript/ts-reset": "0.6.1",
|
|
16
|
-
"@types/node": "22.
|
|
16
|
+
"@types/node": "22.15.3",
|
|
17
17
|
"@typescript-eslint/eslint-plugin": "8.28.0",
|
|
18
18
|
"@typescript-eslint/parser": "8.28.0",
|
|
19
19
|
"@vue/test-utils": "2.4.6",
|
|
20
|
-
"eslint": "9.
|
|
20
|
+
"eslint": "9.25.1",
|
|
21
21
|
"eslint-config-prettier": "9.1.0",
|
|
22
|
-
"eslint-plugin-vue": "9.
|
|
22
|
+
"eslint-plugin-vue": "9.33.0",
|
|
23
23
|
"expect-type": "1.2.1",
|
|
24
24
|
"prettier": "3.5.3",
|
|
25
25
|
"tsup": "8.4.0",
|
|
26
|
-
"type-fest": "4.
|
|
27
|
-
"typescript": "5.8.
|
|
28
|
-
"vitest": "3.1.
|
|
26
|
+
"type-fest": "4.40.1",
|
|
27
|
+
"typescript": "5.8.3",
|
|
28
|
+
"vitest": "3.1.2",
|
|
29
29
|
"vue": "3.5.13",
|
|
30
30
|
"vue-eslint-parser": "10.1.3",
|
|
31
|
-
"vue-tsc": "2.2.
|
|
31
|
+
"vue-tsc": "2.2.10"
|
|
32
32
|
},
|
|
33
33
|
"type": "module",
|
|
34
34
|
"exports": {
|