@regle/core 1.0.7 → 1.1.0-beta.1
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.cjs +55 -12
- package/dist/regle-core.d.cts +211 -113
- package/dist/regle-core.d.ts +211 -113
- package/dist/regle-core.min.cjs +2 -2
- package/dist/regle-core.min.mjs +2 -2
- package/dist/regle-core.mjs +53 -13
- package/package.json +2 -2
package/dist/regle-core.d.ts
CHANGED
|
@@ -139,6 +139,23 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
|
|
|
139
139
|
*/
|
|
140
140
|
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
141
141
|
|
|
142
|
+
/**
|
|
143
|
+
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
144
|
+
|
|
145
|
+
@example
|
|
146
|
+
```
|
|
147
|
+
import type {IsEmptyObject} from 'type-fest';
|
|
148
|
+
|
|
149
|
+
type Pass = IsEmptyObject<{}>; //=> true
|
|
150
|
+
type Fail = IsEmptyObject<[]>; //=> false
|
|
151
|
+
type Fail = IsEmptyObject<null>; //=> false
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
@see EmptyObject
|
|
155
|
+
@category Object
|
|
156
|
+
*/
|
|
157
|
+
type IsEmptyObject<T> = T extends EmptyObject ? true : false;
|
|
158
|
+
|
|
142
159
|
/**
|
|
143
160
|
Extract all required keys from the given type.
|
|
144
161
|
|
|
@@ -1104,13 +1121,9 @@ type RegleSingleField<TState extends Maybe<PrimitiveTypes> = any, TRules extends
|
|
|
1104
1121
|
*/
|
|
1105
1122
|
r$: Raw<RegleFieldStatus<TState, TRules, TShortcuts>>;
|
|
1106
1123
|
} & TAdditionalReturnProperties;
|
|
1107
|
-
type
|
|
1108
|
-
[K in keyof T]-?: CheckDeepExact<NonNullable<T[K]>, K extends keyof U ? NonNullable<U[K]> : never>;
|
|
1109
|
-
}[keyof T] extends true ? true : false;
|
|
1110
|
-
type CheckDeepExact<T, U> = [U] extends [never] ? false : T extends RegleCollectionRuleDecl ? U extends RegleCollectionRuleDecl ? isDeepExact<NonNullable<T['$each']>, UnionToIntersection$1<NonNullable<U['$each']>>> : T extends RegleRuleDecl ? true : T extends ReglePartialRuleTree<any> ? isDeepExact<T, U> : false : T extends RegleRuleDecl ? true : T extends ReglePartialRuleTree<any> ? isDeepExact<T, U> : false;
|
|
1111
|
-
type DeepReactiveState<T extends Record<string, any> | undefined> = {
|
|
1124
|
+
type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? {
|
|
1112
1125
|
[K in keyof T]: InferDeepReactiveState<T[K]>;
|
|
1113
|
-
};
|
|
1126
|
+
} : never;
|
|
1114
1127
|
type InferDeepReactiveState<TState> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? DeepReactiveState<U[]> : NonNullable<TState> extends Date | File ? MaybeRef<TState> : TState extends Record<string, any> | undefined ? DeepReactiveState<TState> : MaybeRef<TState>;
|
|
1115
1128
|
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{
|
|
1116
1129
|
[K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]>;
|
|
@@ -1137,6 +1150,7 @@ type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
|
1137
1150
|
toInitialState?: boolean;
|
|
1138
1151
|
/**
|
|
1139
1152
|
* Reset validation status and reset form state to the given state
|
|
1153
|
+
* Also set the new state as new initial state.
|
|
1140
1154
|
*/
|
|
1141
1155
|
toState?: TState | (() => TState);
|
|
1142
1156
|
/**
|
|
@@ -1145,89 +1159,6 @@ type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
|
1145
1159
|
clearExternalErrors?: boolean;
|
|
1146
1160
|
}, 'toInitialState' | 'toState'>;
|
|
1147
1161
|
|
|
1148
|
-
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
1149
|
-
/**
|
|
1150
|
-
* Primitive parameter
|
|
1151
|
-
* */
|
|
1152
|
-
<TState extends Maybe<PrimitiveTypes>, TRules extends RegleRuleDecl<NonNullable<TState>, TCustomRules>>(state: MaybeRef<TState>, rulesFactory: MaybeRefOrGetter<TRules>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions): RegleSingleField<TState, TRules, TShortcuts, TAdditionalReturnProperties>;
|
|
1153
|
-
/**
|
|
1154
|
-
* Object parameter
|
|
1155
|
-
* */
|
|
1156
|
-
<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = isDeepExact<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules>> extends true ? {} : MismatchInfo<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules>>>(state: MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: MaybeRefOrGetter<TRules>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Unwrap<TState>, TRules, TValidationGroups> & TAdditionalOptions): Regle<Unwrap<TState>, TRules, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* useRegle serves as the foundation for validation logic.
|
|
1160
|
-
*
|
|
1161
|
-
* It accepts the following inputs:
|
|
1162
|
-
*
|
|
1163
|
-
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
1164
|
-
* @param rules - These should align with the structure of your state.
|
|
1165
|
-
* @param modifiers - Customize regle behaviour
|
|
1166
|
-
*
|
|
1167
|
-
* ```ts
|
|
1168
|
-
* import { useRegle } from '@regle/core';
|
|
1169
|
-
import { required } from '@regle/rules';
|
|
1170
|
-
|
|
1171
|
-
const { r$ } = useRegle({ email: '' }, {
|
|
1172
|
-
email: { required }
|
|
1173
|
-
})
|
|
1174
|
-
* ```
|
|
1175
|
-
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
1176
|
-
*/
|
|
1177
|
-
declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
|
|
1178
|
-
|
|
1179
|
-
interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
1180
|
-
<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TValid = isDeepExact<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules>> extends true ? {} : MismatchInfo<NoInferLegacy<TRules>, ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules>>>(state: MaybeRef<TState> | DeepReactiveState<TState> | undefined, rulesFactory: TRules): NoInferLegacy<TRules>;
|
|
1181
|
-
<TState extends PrimitiveTypes, TRules extends RegleRuleDecl>(state: MaybeRef<TState>, rulesFactory: TRules): NoInferLegacy<TRules>;
|
|
1182
|
-
}
|
|
1183
|
-
/**
|
|
1184
|
-
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
1185
|
-
* It will just return the rules without any processing.
|
|
1186
|
-
*
|
|
1187
|
-
* @param state - The state reference
|
|
1188
|
-
* @param rules - Your rule tree
|
|
1189
|
-
*/
|
|
1190
|
-
declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
|
|
1191
|
-
|
|
1192
|
-
declare function useRootStorage({ initialState, options, scopeRules, state, customRules, shortcuts, schemaErrors, schemaMode, onValidate, }: {
|
|
1193
|
-
scopeRules: Ref<$InternalReglePartialRuleTree>;
|
|
1194
|
-
state: Ref<Record<string, any> | PrimitiveTypes>;
|
|
1195
|
-
options: ResolvedRegleBehaviourOptions;
|
|
1196
|
-
initialState: Ref<Record<string, any> | PrimitiveTypes>;
|
|
1197
|
-
customRules?: () => CustomRulesDeclarationTree;
|
|
1198
|
-
shortcuts: RegleShortcutDefinition | undefined;
|
|
1199
|
-
schemaErrors?: Ref<any | undefined>;
|
|
1200
|
-
schemaMode?: boolean;
|
|
1201
|
-
onValidate?: () => Promise<$InternalRegleResult>;
|
|
1202
|
-
}): {
|
|
1203
|
-
regle: $InternalRegleStatusType | undefined;
|
|
1204
|
-
};
|
|
1205
|
-
|
|
1206
|
-
/**
|
|
1207
|
-
* Converts an nested $errors object to a flat array of string errors
|
|
1208
|
-
*
|
|
1209
|
-
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
1210
|
-
*/
|
|
1211
|
-
declare function flatErrors(errors: $InternalRegleErrors, options: {
|
|
1212
|
-
includePath: true;
|
|
1213
|
-
}): {
|
|
1214
|
-
error: string;
|
|
1215
|
-
path: string;
|
|
1216
|
-
}[];
|
|
1217
|
-
declare function flatErrors(errors: $InternalRegleErrors, options?: {
|
|
1218
|
-
includePath?: false;
|
|
1219
|
-
}): string[];
|
|
1220
|
-
|
|
1221
|
-
type InferRegleRoot<T extends (...args: any[]) => Regle<any, any, any, any>> = T extends (...args: any[]) => infer U ? U extends Regle<any, any, any, any> ? Prettify<U['r$']> : never : never;
|
|
1222
|
-
type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<U> & Partial<DefaultValidators>> : {};
|
|
1223
|
-
type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
|
|
1224
|
-
type RegleEnforceRequiredRules<TRules extends keyof DefaultValidators> = Omit<DefaultValidators, TRules> & {
|
|
1225
|
-
[K in TRules as keyof TRules]-?: NonNullable<DefaultValidators[K]>;
|
|
1226
|
-
};
|
|
1227
|
-
type RegleEnforceCustomRequiredRules<T extends Partial<AllRulesDeclarations> | useRegleFn<any>, TRules extends T extends useRegleFn<any> ? keyof InferRegleRules<T> : keyof T> = Omit<T extends useRegleFn<any> ? InferRegleRules<T> : T extends Partial<AllRulesDeclarations> ? UnwrapRuleTree<T> : {}, TRules> & {
|
|
1228
|
-
[K in TRules]-?: T extends useRegleFn<any> ? K extends keyof InferRegleRules<T> ? NonNullable<InferRegleRules<T>[K]> : never : K extends keyof T ? NonNullable<T[K]> : never;
|
|
1229
|
-
};
|
|
1230
|
-
|
|
1231
1162
|
/**
|
|
1232
1163
|
* Negates a boolean type.
|
|
1233
1164
|
*/
|
|
@@ -1339,6 +1270,7 @@ type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends t
|
|
|
1339
1270
|
* Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
|
|
1340
1271
|
*/
|
|
1341
1272
|
type UnionToTuple<Union> = TuplifyUnion<Union>;
|
|
1273
|
+
type IsUnion<T> = Not<Extends<UnionToTuple<T>['length'], 1>>;
|
|
1342
1274
|
|
|
1343
1275
|
/**
|
|
1344
1276
|
* The simple(ish) way to get overload info from a function
|
|
@@ -1662,6 +1594,91 @@ type DeepBrand<T> = IsNever<T> extends true ? {
|
|
|
1662
1594
|
*/
|
|
1663
1595
|
type StrictEqualUsingBranding<Left, Right> = MutuallyExtends<DeepBrand<Left>, DeepBrand<Right>>;
|
|
1664
1596
|
|
|
1597
|
+
type MaybeVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState>> extends true ? Omit<RegleStatus<TState, TRules, TShortcuts>, '$fields'> & {
|
|
1598
|
+
$fields: {
|
|
1599
|
+
[TIndex in keyof TupleToPlainObj<UnionToTuple$1<TState>>]: TIndex extends `${infer TIndexInt extends number}` ? {
|
|
1600
|
+
[TKey in keyof UnionToTuple$1<TState>[TIndexInt] as TKey extends keyof JoinDiscriminatedUnions<TRules> ? TKey : never]-?: InferRegleStatusType<NonNullable<TKey extends keyof JoinDiscriminatedUnions<TRules> ? JoinDiscriminatedUnions<TRules>[TKey] : {}>, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts>;
|
|
1601
|
+
} & {
|
|
1602
|
+
[TKey in keyof UnionToTuple$1<TState>[TIndexInt] as TKey extends keyof JoinDiscriminatedUnions<TRules> ? never : TKey]: InferRegleStatusType<{}, NonNullable<UnionToTuple$1<TState>[TIndexInt]>, TKey, TShortcuts>;
|
|
1603
|
+
} : {};
|
|
1604
|
+
}[keyof TupleToPlainObj<UnionToTuple$1<TState>>];
|
|
1605
|
+
} : RegleStatus<TState, TRules, TShortcuts>;
|
|
1606
|
+
|
|
1607
|
+
interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
1608
|
+
<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules>, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(state: Maybe<MaybeRef<TState> | DeepReactiveState<TState>>, rulesFactory: TState extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState extends Record<string, any> ? MaybeRefOrGetter<TRules> : {}, options?: TState extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState extends Record<string, any> ? Unwrap<TState> : {}>, TState extends Record<string, any> ? TRules : {}, TValidationGroups> & TAdditionalOptions): TState extends MaybeInput<PrimitiveTypes> ? RegleSingleField<TState, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState extends Record<string, any> ? Unwrap<TState> : {}, TRules, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* useRegle serves as the foundation for validation logic.
|
|
1612
|
+
*
|
|
1613
|
+
* It accepts the following inputs:
|
|
1614
|
+
*
|
|
1615
|
+
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
1616
|
+
* @param rules - These should align with the structure of your state.
|
|
1617
|
+
* @param modifiers - Customize regle behaviour
|
|
1618
|
+
*
|
|
1619
|
+
* ```ts
|
|
1620
|
+
* import { useRegle } from '@regle/core';
|
|
1621
|
+
import { required } from '@regle/rules';
|
|
1622
|
+
|
|
1623
|
+
const { r$ } = useRegle({ email: '' }, {
|
|
1624
|
+
email: { required }
|
|
1625
|
+
})
|
|
1626
|
+
* ```
|
|
1627
|
+
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
1628
|
+
*/
|
|
1629
|
+
declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
|
|
1630
|
+
|
|
1631
|
+
interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
1632
|
+
<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends TState extends MaybeInput<PrimitiveTypes> ? RegleRuleDecl<NonNullable<TState>, TCustomRules> : TState extends Record<string, any> ? ReglePartialRuleTree<Unwrap<TState>, Partial<AllRulesDeclarations> & TCustomRules> : {}>(state: MaybeRef<TState> | DeepReactiveState<TState>, rulesFactory: TRules): NoInferLegacy<TRules>;
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
1636
|
+
* It will just return the rules without any processing.
|
|
1637
|
+
*
|
|
1638
|
+
* @param state - The state reference
|
|
1639
|
+
* @param rules - Your rule tree
|
|
1640
|
+
*/
|
|
1641
|
+
declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
|
|
1642
|
+
|
|
1643
|
+
declare function useRootStorage({ initialState, options, scopeRules, state, customRules, shortcuts, schemaErrors, schemaMode, onValidate, }: {
|
|
1644
|
+
scopeRules: Ref<$InternalReglePartialRuleTree>;
|
|
1645
|
+
state: Ref<Record<string, any> | PrimitiveTypes>;
|
|
1646
|
+
options: ResolvedRegleBehaviourOptions;
|
|
1647
|
+
initialState: Ref<Record<string, any> | PrimitiveTypes>;
|
|
1648
|
+
customRules?: () => CustomRulesDeclarationTree;
|
|
1649
|
+
shortcuts: RegleShortcutDefinition | undefined;
|
|
1650
|
+
schemaErrors?: Ref<any | undefined>;
|
|
1651
|
+
schemaMode?: boolean;
|
|
1652
|
+
onValidate?: () => Promise<$InternalRegleResult>;
|
|
1653
|
+
}): {
|
|
1654
|
+
regle: $InternalRegleStatusType | undefined;
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
/**
|
|
1658
|
+
* Converts an nested $errors object to a flat array of string errors
|
|
1659
|
+
*
|
|
1660
|
+
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
1661
|
+
*/
|
|
1662
|
+
declare function flatErrors(errors: $InternalRegleErrors, options: {
|
|
1663
|
+
includePath: true;
|
|
1664
|
+
}): {
|
|
1665
|
+
error: string;
|
|
1666
|
+
path: string;
|
|
1667
|
+
}[];
|
|
1668
|
+
declare function flatErrors(errors: $InternalRegleErrors, options?: {
|
|
1669
|
+
includePath?: false;
|
|
1670
|
+
}): string[];
|
|
1671
|
+
|
|
1672
|
+
type InferRegleRoot<T extends (...args: any[]) => Regle<any, any, any, any>> = T extends (...args: any[]) => infer U ? U extends Regle<any, any, any, any> ? Prettify<U['r$']> : never : never;
|
|
1673
|
+
type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<U> & Partial<DefaultValidators>> : {};
|
|
1674
|
+
type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
|
|
1675
|
+
type RegleEnforceRequiredRules<TRules extends keyof DefaultValidators> = {
|
|
1676
|
+
[K in TRules]-?: UnwrapRuleWithParams<DefaultValidators[K]>;
|
|
1677
|
+
};
|
|
1678
|
+
type RegleEnforceCustomRequiredRules<T extends Partial<AllRulesDeclarations> | useRegleFn<any>, TRules extends T extends useRegleFn<any> ? keyof InferRegleRules<T> : keyof T> = {
|
|
1679
|
+
[K in TRules]-?: T extends useRegleFn<any> ? K extends keyof InferRegleRules<T> ? UnwrapRuleWithParams<InferRegleRules<T>[K]> : never : K extends keyof T ? NonNullable<T[K]> : never;
|
|
1680
|
+
};
|
|
1681
|
+
|
|
1665
1682
|
/**
|
|
1666
1683
|
* Borrowed from vitest
|
|
1667
1684
|
*/
|
|
@@ -1674,12 +1691,46 @@ type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, No
|
|
|
1674
1691
|
} : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `[Regle error] The parent property does not match the form schema`;
|
|
1675
1692
|
|
|
1676
1693
|
type RemoveCommonKey<T extends readonly any[], K extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K>>, ...RemoveCommonKey<R, K>] : [];
|
|
1677
|
-
|
|
1694
|
+
/**
|
|
1695
|
+
* Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
|
|
1696
|
+
*/
|
|
1697
|
+
type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K extends keyof O ? O[K] : undefined;
|
|
1698
|
+
/**
|
|
1699
|
+
* Combine all unions values to be able to get even the normally "never" values, act as an intersection type
|
|
1700
|
+
*/
|
|
1701
|
+
type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [
|
|
1702
|
+
infer F extends Record<string, any>,
|
|
1703
|
+
...infer R
|
|
1704
|
+
] ? [
|
|
1705
|
+
{
|
|
1706
|
+
[K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K>;
|
|
1707
|
+
} & {
|
|
1708
|
+
[K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K>;
|
|
1709
|
+
},
|
|
1710
|
+
...RetrieveUnionUnknownValues<R, TKeys>
|
|
1711
|
+
] : [];
|
|
1712
|
+
/**
|
|
1713
|
+
* Get all possible keys from an union, even the ones present only on one union
|
|
1714
|
+
*/
|
|
1715
|
+
type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
|
|
1716
|
+
/**
|
|
1717
|
+
* Transforms an union and apply undefined values to non-present keys to support intersection
|
|
1718
|
+
*/
|
|
1719
|
+
type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple$1<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple$1<TUnion>>>[number]>[number];
|
|
1720
|
+
/**
|
|
1721
|
+
* Combine all members of an union type, merging types for each keys, and keeping loose types
|
|
1722
|
+
*/
|
|
1723
|
+
type JoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection$1<RemoveCommonKey<UnionToTuple$1<TUnion>, keyof NormalizeUnion<TUnion>>[number]>> & Pick<NormalizeUnion<TUnion>, keyof NormalizeUnion<TUnion>>> : TUnion;
|
|
1724
|
+
type LazyJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection$1<RemoveCommonKey<UnionToTuple$1<TUnion>, keyof NonNullable<TUnion>>[number]>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
|
|
1678
1725
|
type EnumLike = {
|
|
1679
1726
|
[k: string]: string | number;
|
|
1680
1727
|
[nu: number]: string;
|
|
1681
1728
|
};
|
|
1729
|
+
type enumType<T extends Record<string, unknown>> = T[keyof T];
|
|
1682
1730
|
type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
1731
|
+
type TupleToPlainObj<T> = {
|
|
1732
|
+
[I in keyof T & `${number}`]: T[I];
|
|
1733
|
+
};
|
|
1683
1734
|
|
|
1684
1735
|
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
1685
1736
|
/**
|
|
@@ -1709,10 +1760,11 @@ interface RegleInternalRuleDefs<TValue extends any = any, TParams extends any[]
|
|
|
1709
1760
|
_async: TAsync;
|
|
1710
1761
|
readonly _brand: symbol;
|
|
1711
1762
|
}
|
|
1712
|
-
declare
|
|
1713
|
-
Inline
|
|
1714
|
-
Async
|
|
1715
|
-
}
|
|
1763
|
+
declare const InternalRuleType: {
|
|
1764
|
+
readonly Inline: "__inline";
|
|
1765
|
+
readonly Async: "__async";
|
|
1766
|
+
};
|
|
1767
|
+
type InternalRuleType = enumType<typeof InternalRuleType>;
|
|
1716
1768
|
|
|
1717
1769
|
/**
|
|
1718
1770
|
* Returned typed of rules created with `createRule`
|
|
@@ -1740,7 +1792,7 @@ type UnwrapRuleTree<T extends {
|
|
|
1740
1792
|
}> = {
|
|
1741
1793
|
[K in keyof T]: UnwrapRuleWithParams<T[K]>;
|
|
1742
1794
|
};
|
|
1743
|
-
type UnwrapRuleWithParams<T extends RegleRuleRaw<any> | undefined> = T extends RegleRuleWithParamsDefinition<infer TValue, infer TParams, infer TAsync, infer TMetadata> ? RegleRuleDefinition<TValue, TParams, TAsync, TMetadata> : T;
|
|
1795
|
+
type UnwrapRuleWithParams<T extends RegleRuleRaw<any, any, any, any> | undefined> = T extends RegleRuleWithParamsDefinition<infer TValue, infer TParams, infer TAsync, infer TMetadata> ? RegleRuleDefinition<TValue, TParams, TAsync, TMetadata> : T;
|
|
1744
1796
|
/**
|
|
1745
1797
|
* Define a rule Metadata definition
|
|
1746
1798
|
*/
|
|
@@ -1812,6 +1864,13 @@ type RegleRuleTypeReturn<TValue, TParams extends [...any[]]> = {
|
|
|
1812
1864
|
params: [...TParams];
|
|
1813
1865
|
};
|
|
1814
1866
|
|
|
1867
|
+
interface CommonComparationOptions {
|
|
1868
|
+
/**
|
|
1869
|
+
* Change the behaviour of the rule to check only if the value is equal in addition to be strictly superior or inferior
|
|
1870
|
+
* @default true
|
|
1871
|
+
*/
|
|
1872
|
+
allowEqual?: boolean;
|
|
1873
|
+
}
|
|
1815
1874
|
type DefaultValidators = {
|
|
1816
1875
|
alpha: RegleRuleDefinition<string>;
|
|
1817
1876
|
alphaNum: RegleRuleDefinition<string | number>;
|
|
@@ -1846,13 +1905,21 @@ type DefaultValidators = {
|
|
|
1846
1905
|
exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
|
|
1847
1906
|
count: number
|
|
1848
1907
|
], false, boolean>;
|
|
1908
|
+
exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
|
|
1849
1909
|
integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1850
1910
|
ipAddress: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1911
|
+
literal: RegleRuleDefinition<string | number, [literal: string | number], false, boolean, string | number>;
|
|
1851
1912
|
macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
|
|
1852
|
-
maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1913
|
+
maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
|
|
1914
|
+
count: number,
|
|
1915
|
+
options?: CommonComparationOptions
|
|
1916
|
+
], false, boolean>;
|
|
1917
|
+
maxValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparationOptions], false, boolean>;
|
|
1918
|
+
minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
|
|
1919
|
+
count: number,
|
|
1920
|
+
options?: CommonComparationOptions
|
|
1921
|
+
], false, boolean>;
|
|
1922
|
+
minValue: RegleRuleWithParamsDefinition<number, [count: number, options?: CommonComparationOptions], false, boolean>;
|
|
1856
1923
|
nativeEnum: RegleRuleDefinition<string | number, [enumLike: EnumLike], false, boolean, string | number>;
|
|
1857
1924
|
numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
|
|
1858
1925
|
oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
|
|
@@ -1860,7 +1927,6 @@ type DefaultValidators = {
|
|
|
1860
1927
|
required: RegleRuleDefinition<unknown, []>;
|
|
1861
1928
|
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
|
|
1862
1929
|
startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
|
|
1863
|
-
exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
|
|
1864
1930
|
url: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
1865
1931
|
};
|
|
1866
1932
|
|
|
@@ -1887,7 +1953,7 @@ type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Parti
|
|
|
1887
1953
|
* @public
|
|
1888
1954
|
*/
|
|
1889
1955
|
type RegleComputedRules<TForm extends MaybeRef<Record<string, any>> | DeepReactiveState<Record<string, any>>, TCustomRules extends Partial<AllRulesDeclarations> | Regle<any, any> = Partial<AllRulesDeclarations>, TState = Unwrap<TForm>, TCustom = TCustomRules extends Regle<any, infer R> ? R extends ReglePartialRuleTree<any, infer C> ? C : Partial<AllRulesDeclarations> : TCustomRules> = {
|
|
1890
|
-
[TKey in keyof TState]?: RegleFormPropertyType<TState[TKey], TCustom extends Partial<AllRulesDeclarations> ? TCustom : {}>;
|
|
1956
|
+
[TKey in keyof JoinDiscriminatedUnions<TState>]?: RegleFormPropertyType<JoinDiscriminatedUnions<TState>[TKey], TCustom extends Partial<AllRulesDeclarations> ? TCustom : {}>;
|
|
1891
1957
|
};
|
|
1892
1958
|
/**
|
|
1893
1959
|
* @internal
|
|
@@ -1910,7 +1976,7 @@ type $InternalFormPropertyTypes = $InternalRegleRuleDecl | $InternalRegleCollect
|
|
|
1910
1976
|
* Rule tree for a form property
|
|
1911
1977
|
*/
|
|
1912
1978
|
type RegleRuleDecl<TValue extends any = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = FieldRegleBehaviourOptions & {
|
|
1913
|
-
[TKey in keyof TCustomRules]?: NonNullable<TCustomRules[TKey]> extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, [...TParams, ...args: [...any[]]], boolean> : NonNullable<TCustomRules[TKey]> extends RegleRuleDefinition<any, any, any, any> ? FormRuleDeclaration<TValue, any> : FormRuleDeclaration<TValue, any> | FieldRegleBehaviourOptions[keyof FieldRegleBehaviourOptions];
|
|
1979
|
+
[TKey in keyof TCustomRules]?: NonNullable<TCustomRules[TKey]> extends RegleRuleWithParamsDefinition<any, infer TParams> ? RegleRuleDefinition<TValue, [...TParams, ...args: [...any[]]], boolean> : NonNullable<TCustomRules[TKey]> extends RegleRuleDefinition<any, any[], any, any> ? FormRuleDeclaration<TValue, any[]> : FormRuleDeclaration<TValue, any[]> | FieldRegleBehaviourOptions[keyof FieldRegleBehaviourOptions];
|
|
1914
1980
|
};
|
|
1915
1981
|
/**
|
|
1916
1982
|
* @internal
|
|
@@ -1995,7 +2061,7 @@ type $InternalRegleResult = {
|
|
|
1995
2061
|
/**
|
|
1996
2062
|
* @public
|
|
1997
2063
|
*/
|
|
1998
|
-
type RegleRoot<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialRuleTree<TState> = Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never, TShortcuts extends RegleShortcutDefinition = {}> =
|
|
2064
|
+
type RegleRoot<TState extends Record<string, any> = Record<string, any>, TRules extends ReglePartialRuleTree<TState> = Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = never, TShortcuts extends RegleShortcutDefinition = {}> = MaybeVariantStatus<TState, TRules, TShortcuts> & ([TValidationGroups] extends [never] ? {} : {
|
|
1999
2065
|
/**
|
|
2000
2066
|
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
2001
2067
|
*/
|
|
@@ -2055,9 +2121,9 @@ type SuperCompatibleRegleCollectionErrors = $InternalRegleCollectionErrors;
|
|
|
2055
2121
|
type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
|
|
2056
2122
|
/** Represents all the children of your object. You can access any nested child at any depth to get the relevant data you need for your form. */
|
|
2057
2123
|
readonly $fields: {
|
|
2058
|
-
readonly [TKey in keyof TState]: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
2124
|
+
readonly [TKey in keyof TState as IsEmptyObject<TRules[TKey]> extends true ? never : TKey]: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
2059
2125
|
} & {
|
|
2060
|
-
readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? TKey : never : never]-?: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
2126
|
+
readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject<TRules[TKey]> extends true ? TKey : never : never : never]-?: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
2061
2127
|
};
|
|
2062
2128
|
/**
|
|
2063
2129
|
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
@@ -2089,7 +2155,7 @@ interface $InternalRegleStatus extends $InternalRegleCommonStatus {
|
|
|
2089
2155
|
/**
|
|
2090
2156
|
* @public
|
|
2091
2157
|
*/
|
|
2092
|
-
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TState[TKey]> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState[TKey], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : RegleCollectionStatus<TState[TKey], {}, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState[TKey]> extends Array<any> ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ?
|
|
2158
|
+
type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl | ReglePartialRuleTree<any>, TState extends Record<PropertyKey, any> = any, TKey extends PropertyKey = string, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TState[TKey]> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TRule extends RegleCollectionRuleDefinition<any, any> ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any> ? RegleCollectionStatus<TState[TKey], ExtractFromGetter<TRule['$each']>, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : RegleCollectionStatus<TState[TKey], {}, TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : TRule extends ReglePartialRuleTree<any> ? NonNullable<TState[TKey]> extends Array<any> ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? MaybeVariantStatus<TState[TKey], TRule, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Date | File ? RegleFieldStatus<TState[TKey], TRule, TShortcuts> : NonNullable<TState[TKey]> extends Record<PropertyKey, any> ? MaybeVariantStatus<TState[TKey], ReglePartialRuleTree<TState[TKey]>, TShortcuts> : RegleFieldStatus<TState[TKey], TRule, TShortcuts>;
|
|
2093
2159
|
/**
|
|
2094
2160
|
* @internal
|
|
2095
2161
|
* @reference {@link InferRegleStatusType}
|
|
@@ -2100,9 +2166,9 @@ type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleS
|
|
|
2100
2166
|
*/
|
|
2101
2167
|
type RegleFieldStatus<TState extends any = any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState>, '$value'> & {
|
|
2102
2168
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2103
|
-
$value:
|
|
2169
|
+
$value: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
2104
2170
|
/** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
|
|
2105
|
-
$silentValue:
|
|
2171
|
+
$silentValue: MaybeOutput<UnwrapNestedRefs<TState>>;
|
|
2106
2172
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2107
2173
|
*
|
|
2108
2174
|
* Only contains errors from properties where $dirty equals true. */
|
|
@@ -2116,7 +2182,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
|
|
|
2116
2182
|
/** Represents the inactive status. Is true when this state have empty rules */
|
|
2117
2183
|
readonly $inactive: boolean;
|
|
2118
2184
|
/** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
|
|
2119
|
-
$extractDirtyFields: (filterNullishValues?: boolean) =>
|
|
2185
|
+
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>;
|
|
2120
2186
|
/** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */
|
|
2121
2187
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
2122
2188
|
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
@@ -2217,7 +2283,7 @@ type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata exte
|
|
|
2217
2283
|
/** Reset the $valid, $metadata and $pending states */
|
|
2218
2284
|
$reset(): void;
|
|
2219
2285
|
/** Returns the original rule validator function. */
|
|
2220
|
-
$validator: ((value:
|
|
2286
|
+
$validator: ((value: MaybeInput<TValue>, ...args: any[]) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: TValue, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
2221
2287
|
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
2222
2288
|
readonly $params?: any[];
|
|
2223
2289
|
} : {
|
|
@@ -2256,9 +2322,9 @@ interface $InternalRegleRuleStatus {
|
|
|
2256
2322
|
*/
|
|
2257
2323
|
type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePartialRuleTree<ArrayElement<TState>> = Record<string, any>, TFieldRule extends RegleCollectionRuleDecl<any, any> = never, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$value'> & {
|
|
2258
2324
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
2259
|
-
$value:
|
|
2325
|
+
$value: MaybeOutput<TState>;
|
|
2260
2326
|
/** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
|
|
2261
|
-
$silentValue:
|
|
2327
|
+
$silentValue: MaybeOutput<TState>;
|
|
2262
2328
|
/** Collection of status of every item in your collection. Each item will be a field you can access, or map on it to display your elements. */
|
|
2263
2329
|
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
|
|
2264
2330
|
/** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
|
|
@@ -2435,4 +2501,36 @@ declare const useScopedRegle: useRegleFn<Partial<AllRulesDeclarations>, never, {
|
|
|
2435
2501
|
namespace?: MaybeRefOrGetter<string>;
|
|
2436
2502
|
}>;
|
|
2437
2503
|
|
|
2438
|
-
|
|
2504
|
+
type PossibleLiteralTypes<T extends Record<string, any>, TKey extends keyof T> = {
|
|
2505
|
+
[TVal in NonNullable<T[TKey]>]: {
|
|
2506
|
+
[K in TKey]-?: Omit<RegleRuleDecl<TVal, Partial<AllRulesDeclarations>>, 'literal'> & {
|
|
2507
|
+
literal?: RegleRuleDefinition<TVal, [literal: TVal], false, boolean, string | number>;
|
|
2508
|
+
};
|
|
2509
|
+
};
|
|
2510
|
+
};
|
|
2511
|
+
type RequiredForm<T extends Record<string, any>, TKey extends keyof T> = Omit<ReglePartialRuleTree<T>, TKey> & PossibleLiteralTypes<T, TKey>[keyof PossibleLiteralTypes<T, TKey>];
|
|
2512
|
+
type Variant1<T extends Record<string, any>, TKey extends keyof T> = [
|
|
2513
|
+
RequiredForm<T, TKey>,
|
|
2514
|
+
...RequiredForm<T, TKey>[]
|
|
2515
|
+
];
|
|
2516
|
+
/**
|
|
2517
|
+
*
|
|
2518
|
+
* Autocomplete may not work here because of https://github.com/microsoft/TypeScript/issues/49547
|
|
2519
|
+
*/
|
|
2520
|
+
declare function createVariant<const TForm extends Record<string, any>, const TDiscriminant extends keyof JoinDiscriminatedUnions<TForm>, const TVariants extends Variant1<JoinDiscriminatedUnions<TForm>, TDiscriminant>>(root: MaybeRefOrGetter<TForm> | DeepReactiveState<TForm>, disciminantKey: TDiscriminant, variants: [...TVariants]): Ref<TVariants[number]>;
|
|
2521
|
+
declare function discriminateVariant<TRoot extends {
|
|
2522
|
+
[x: string]: unknown;
|
|
2523
|
+
}, TKey extends keyof TRoot, const TValue extends LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
2524
|
+
$value: infer V;
|
|
2525
|
+
} ? V : unknown>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): root is Extract<TRoot, {
|
|
2526
|
+
[K in TKey]: RegleFieldStatus<TValue, any, any>;
|
|
2527
|
+
}>;
|
|
2528
|
+
declare function inferVariantRef<TRoot extends {
|
|
2529
|
+
[x: string]: unknown;
|
|
2530
|
+
}, TKey extends keyof TRoot, const TValue extends LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
|
|
2531
|
+
$value: infer V;
|
|
2532
|
+
} ? V : unknown>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): Ref<Extract<TRoot, {
|
|
2533
|
+
[K in TKey]: RegleFieldStatus<TValue, any, any>;
|
|
2534
|
+
}>> | undefined;
|
|
2535
|
+
|
|
2536
|
+
export { type $InternalRegleStatus, type AllRulesDeclarations, type CommonComparationOptions, type DeepMaybeRef, type DeepReactiveState, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeVariantStatus, type MergedRegles, type MismatchInfo, 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 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, discriminateVariant, flatErrors, inferRules, inferVariantRef, mergeRegles, unwrapRuleParameters, useCollectScope, useRegle, useRootStorage, useScopedRegle };
|