@regle/core 0.5.5 → 0.5.7
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/README.md +1 -1
- package/dist/regle-core.d.cts +100 -10
- package/dist/regle-core.d.ts +100 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ It's heavily inspired by Vuelidate.
|
|
|
11
11
|
|
|
12
12
|
## 📚 Documentation
|
|
13
13
|
|
|
14
|
-
[](https://
|
|
14
|
+
[](https://reglejs.dev/)
|
|
15
15
|
|
|
16
16
|
## 🎮 Play with it
|
|
17
17
|
|
package/dist/regle-core.d.cts
CHANGED
|
@@ -423,12 +423,38 @@ type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, a
|
|
|
423
423
|
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? Maybe<TState> : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any> ? Params extends never[] ? Maybe<TState> : Maybe<TState> : Maybe<TState> : Maybe<TState>;
|
|
424
424
|
|
|
425
425
|
type useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> = <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>) => Regle<Unwrap<TState>, TRules, TValidationGroups, TShortcuts>;
|
|
426
|
+
/**
|
|
427
|
+
* useRegle serves as the foundation for validation logic.
|
|
428
|
+
*
|
|
429
|
+
* It accepts the following inputs:
|
|
430
|
+
*
|
|
431
|
+
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
432
|
+
* @param rules - These should align with the structure of your state.
|
|
433
|
+
* @param modifiers - Customize computed beahviour
|
|
434
|
+
*
|
|
435
|
+
* ```ts
|
|
436
|
+
* import { useRegle } from '@regle/core';
|
|
437
|
+
import { required } from '@regle/rules';
|
|
438
|
+
|
|
439
|
+
const { r$ } = useRegle({ email: '' }, {
|
|
440
|
+
email: { required }
|
|
441
|
+
})
|
|
442
|
+
* ```
|
|
443
|
+
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
444
|
+
*/
|
|
426
445
|
declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>>;
|
|
427
446
|
|
|
428
447
|
interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
429
448
|
<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 ? {} : never>(state: MaybeRef<TState> | DeepReactiveState<TState> | undefined, rulesFactory: TRules): NoInferLegacy<TRules>;
|
|
430
449
|
<TState extends PrimitiveTypes, TRules extends RegleRuleDecl>(state: MaybeRef<TState>, rulesFactory: TRules): NoInferLegacy<TRules>;
|
|
431
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
453
|
+
* It will just return the rules without any processing.
|
|
454
|
+
*
|
|
455
|
+
* @param state - The state reference
|
|
456
|
+
* @param rules - Your rule tree
|
|
457
|
+
*/
|
|
432
458
|
declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
|
|
433
459
|
|
|
434
460
|
declare function useRootStorage({ initialState, options, scopeRules, state, customRules, shortcuts, }: {
|
|
@@ -897,7 +923,6 @@ type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, No
|
|
|
897
923
|
[K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never>;
|
|
898
924
|
} : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `[Regle error] The parent property does not match the form schema`;
|
|
899
925
|
|
|
900
|
-
type ParamDecl<T = any> = MaybeRef<Maybe<T>> | (() => Maybe<T>);
|
|
901
926
|
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
902
927
|
/**
|
|
903
928
|
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
@@ -905,10 +930,10 @@ type CreateFn<T extends any[]> = (...args: T) => any;
|
|
|
905
930
|
* [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
|
|
906
931
|
*/
|
|
907
932
|
type RegleUniversalParams<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
|
|
908
|
-
[K in keyof Args]:
|
|
933
|
+
[K in keyof Args]: MaybeRefOrGetter<Maybe<Args[K]>>;
|
|
909
934
|
}) => any : never>;
|
|
910
|
-
type UnwrapRegleUniversalParams<T extends
|
|
911
|
-
[K in keyof Args]: Args[K] extends
|
|
935
|
+
type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
|
|
936
|
+
[K in keyof Args]: Args[K] extends MaybeRefOrGetter<Maybe<infer U>> ? U : Args[K];
|
|
912
937
|
}) => any : never>;
|
|
913
938
|
|
|
914
939
|
/**
|
|
@@ -1210,6 +1235,9 @@ type $InternalRegleResult = {
|
|
|
1210
1235
|
* @public
|
|
1211
1236
|
*/
|
|
1212
1237
|
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 = {}> = RegleStatus<TState, TRules, TShortcuts> & ([TValidationGroups] extends [never] ? {} : {
|
|
1238
|
+
/**
|
|
1239
|
+
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
1240
|
+
*/
|
|
1213
1241
|
$groups: {
|
|
1214
1242
|
readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput;
|
|
1215
1243
|
};
|
|
@@ -1218,12 +1246,17 @@ type RegleRoot<TState extends Record<string, any> = Record<string, any>, TRules
|
|
|
1218
1246
|
* @public
|
|
1219
1247
|
*/
|
|
1220
1248
|
type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
|
|
1249
|
+
/** 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. */
|
|
1221
1250
|
readonly $fields: {
|
|
1222
1251
|
readonly [TKey in keyof TState]: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
1223
1252
|
} & {
|
|
1224
1253
|
readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? TKey : never]-?: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
1225
1254
|
};
|
|
1255
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1256
|
+
*
|
|
1257
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
1226
1258
|
readonly $errors: RegleErrorTree<TState>;
|
|
1259
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
1227
1260
|
readonly $silentErrors: RegleErrorTree<TState>;
|
|
1228
1261
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
1229
1262
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
@@ -1256,14 +1289,23 @@ type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleS
|
|
|
1256
1289
|
* @public
|
|
1257
1290
|
*/
|
|
1258
1291
|
type RegleFieldStatus<TState extends any = any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState>, '$value'> & {
|
|
1292
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1259
1293
|
$value: Maybe<UnwrapNestedRefs<TState>>;
|
|
1294
|
+
/** $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. */
|
|
1260
1295
|
$silentValue: Maybe<UnwrapNestedRefs<TState>>;
|
|
1296
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1297
|
+
*
|
|
1298
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
1261
1299
|
readonly $errors: string[];
|
|
1300
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1262
1301
|
readonly $silentErrors: string[];
|
|
1263
1302
|
readonly $externalErrors: string[];
|
|
1264
1303
|
readonly $tooltips: string[];
|
|
1304
|
+
/** 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). */
|
|
1265
1305
|
$extractDirtyFields: (filterNullishValues?: boolean) => Maybe<TState>;
|
|
1306
|
+
/** 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). */
|
|
1266
1307
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
1308
|
+
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
1267
1309
|
readonly $rules: {
|
|
1268
1310
|
readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : any>;
|
|
1269
1311
|
};
|
|
@@ -1292,35 +1334,58 @@ interface RegleCommonStatus<TValue = any> {
|
|
|
1292
1334
|
readonly $invalid: boolean;
|
|
1293
1335
|
readonly $dirty: boolean;
|
|
1294
1336
|
readonly $anyDirty: boolean;
|
|
1337
|
+
/** Indicates if any async rule for the field is currently running. Always false for synchronous rules. */
|
|
1295
1338
|
readonly $pending: boolean;
|
|
1339
|
+
/** Convenience flag to easily decide if a message should be displayed. Equivalent to $dirty && !$pending && $invalid. */
|
|
1296
1340
|
readonly $error: boolean;
|
|
1341
|
+
/** Indicates whether the field is ready for submission. Equivalent to !$invalid && !$pending. */
|
|
1297
1342
|
readonly $ready: boolean;
|
|
1343
|
+
/** Return the current key name of the field. */
|
|
1298
1344
|
readonly $name: string;
|
|
1345
|
+
/** Id used to track collections items */
|
|
1299
1346
|
$id?: string;
|
|
1347
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1300
1348
|
$value: UnwrapNestedRefs<TValue>;
|
|
1349
|
+
/** $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. */
|
|
1301
1350
|
$silentValue: UnwrapNestedRefs<TValue>;
|
|
1351
|
+
/** Marks the field and all nested properties as $dirty. */
|
|
1302
1352
|
$touch(runCommit?: boolean, withConditions?: boolean): void;
|
|
1353
|
+
/** Resets the $dirty state on all nested properties of a form. */
|
|
1303
1354
|
$reset(): void;
|
|
1355
|
+
/** Will reset both your validation state and your form state to their initial values. */
|
|
1304
1356
|
$resetAll: () => void;
|
|
1357
|
+
/** Clears the $externalResults state back to an empty object. */
|
|
1358
|
+
$clearExternalErrors(): void;
|
|
1359
|
+
/** @interal */
|
|
1305
1360
|
$unwatch(): void;
|
|
1361
|
+
/** @interal */
|
|
1306
1362
|
$watch(): void;
|
|
1307
|
-
$clearExternalErrors(): void;
|
|
1308
1363
|
}
|
|
1309
1364
|
/**
|
|
1310
1365
|
* @public
|
|
1311
1366
|
*/
|
|
1312
1367
|
type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata extends RegleRuleMetadataDefinition = any> = {
|
|
1368
|
+
/** The name of the rule type. */
|
|
1313
1369
|
readonly $type: string;
|
|
1370
|
+
/** Returns the computed error message or messages for the current rule. */
|
|
1314
1371
|
readonly $message: string | string[];
|
|
1315
1372
|
readonly $tooltip: string | string[];
|
|
1373
|
+
/** Indicates whether or not the rule is enabled (for rules like requiredIf) */
|
|
1316
1374
|
readonly $active: boolean;
|
|
1375
|
+
/** Indicates the state of validation for this validator. */
|
|
1317
1376
|
readonly $valid: boolean;
|
|
1377
|
+
/** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
|
|
1318
1378
|
readonly $pending: boolean;
|
|
1379
|
+
/** Returns the current path of the rule (used internally for tracking) */
|
|
1319
1380
|
readonly $path: string;
|
|
1381
|
+
/** Contains the metadata returned by the validator function. */
|
|
1320
1382
|
readonly $metadata: TMetadata;
|
|
1321
|
-
|
|
1383
|
+
/** Run the rule validator and compute its properties like $message and $active */
|
|
1322
1384
|
$validate(): Promise<boolean>;
|
|
1385
|
+
/** Reset the $valid, $metadata and $pending states */
|
|
1323
1386
|
$reset(): void;
|
|
1387
|
+
/** Returns the original rule validator function. */
|
|
1388
|
+
$validator: ((value: Maybe<TValue>, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: TValue, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
1324
1389
|
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
1325
1390
|
readonly $params?: any[];
|
|
1326
1391
|
} : {
|
|
@@ -1353,13 +1418,23 @@ interface $InternalRegleRuleStatus {
|
|
|
1353
1418
|
* @public
|
|
1354
1419
|
*/
|
|
1355
1420
|
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'> & {
|
|
1421
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1356
1422
|
$value: Maybe<TState>;
|
|
1423
|
+
/** $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. */
|
|
1357
1424
|
$silentValue: Maybe<TState>;
|
|
1425
|
+
/** 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. */
|
|
1358
1426
|
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
|
|
1427
|
+
/** 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. */
|
|
1359
1428
|
readonly $field: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
|
|
1429
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1430
|
+
*
|
|
1431
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
1360
1432
|
readonly $errors: RegleCollectionErrors<TState>;
|
|
1433
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1361
1434
|
readonly $silentErrors: RegleCollectionErrors<TState>;
|
|
1435
|
+
/** 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). */
|
|
1362
1436
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
1437
|
+
/** 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). */
|
|
1363
1438
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
1364
1439
|
} & ([TShortcuts['collections']] extends [never] ? {} : {
|
|
1365
1440
|
[K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
|
|
@@ -1382,7 +1457,6 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1382
1457
|
}
|
|
1383
1458
|
|
|
1384
1459
|
/**
|
|
1385
|
-
* @description
|
|
1386
1460
|
* Create a typed custom rule that can be used like default rules.
|
|
1387
1461
|
* It can also be declared in the global options
|
|
1388
1462
|
*
|
|
@@ -1391,6 +1465,7 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1391
1465
|
* @typeParam TValue - The input value the rule should receive
|
|
1392
1466
|
* @typeParam TParams - Tuple declaration of the rule parameters (if any)
|
|
1393
1467
|
*
|
|
1468
|
+
*
|
|
1394
1469
|
* @param definition - The rule processors object
|
|
1395
1470
|
*
|
|
1396
1471
|
* @returns A rule definition that can be callable depending on params presence
|
|
@@ -1402,7 +1477,7 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1402
1477
|
* import {isFilled} from '@regle/rules';
|
|
1403
1478
|
*
|
|
1404
1479
|
* export const isFoo = createRule({
|
|
1405
|
-
* validator(value: string) {
|
|
1480
|
+
* validator(value: Maybe<string>) {
|
|
1406
1481
|
* if (isFilled(value)) {
|
|
1407
1482
|
* return value === 'foo';
|
|
1408
1483
|
* }
|
|
@@ -1410,7 +1485,10 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1410
1485
|
* },
|
|
1411
1486
|
* message: "The value should be 'foo'"
|
|
1412
1487
|
* })
|
|
1488
|
+
*
|
|
1413
1489
|
* ```
|
|
1490
|
+
*
|
|
1491
|
+
* Docs: {@link https://reglejs.dev/core-concepts/rules/reusable-rules}
|
|
1414
1492
|
*/
|
|
1415
1493
|
declare function createRule<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(definition: RegleRuleInit<TValue, TParams, TReturn, TMetadata, TAsync>): InferRegleRule<TValue, TParams, TAsync, TMetadata>;
|
|
1416
1494
|
|
|
@@ -1418,8 +1496,20 @@ declare function createRule<TValue extends any, TParams extends any[], TReturn e
|
|
|
1418
1496
|
* Returns a clean list of parameters
|
|
1419
1497
|
* Removing Ref and executing function to return the unwraped value
|
|
1420
1498
|
*/
|
|
1421
|
-
declare function unwrapRuleParameters<TParams extends any[]>(params:
|
|
1499
|
+
declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrGetter[]): TParams;
|
|
1422
1500
|
|
|
1501
|
+
/**
|
|
1502
|
+
* Define a global regle configuration, where you can:
|
|
1503
|
+
* - Customize buil-in rules messages
|
|
1504
|
+
* - Add your custom rules
|
|
1505
|
+
* - Define global modifiers
|
|
1506
|
+
* - Define shortcuts
|
|
1507
|
+
*
|
|
1508
|
+
* It will return:
|
|
1509
|
+
*
|
|
1510
|
+
* - a `useRegle` composable that can typecheck your custom rules
|
|
1511
|
+
* - an `inferRules` helper that can typecheck your custom rules
|
|
1512
|
+
*/
|
|
1423
1513
|
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<AllRulesDeclarations> = EmptyObject>({ rules, modifiers, shortcuts, }: {
|
|
1424
1514
|
rules?: () => TCustomRules;
|
|
1425
1515
|
modifiers?: RegleBehaviourOptions;
|
|
@@ -1429,4 +1519,4 @@ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TC
|
|
|
1429
1519
|
inferRules: inferRulesFn<TCustomRules>;
|
|
1430
1520
|
};
|
|
1431
1521
|
|
|
1432
|
-
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type NoInferLegacy, type
|
|
1522
|
+
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, 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 RegleStatus, type RegleUniversalParams, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, defineRegleConfig, inferRules, unwrapRuleParameters, useRegle, useRootStorage };
|
package/dist/regle-core.d.ts
CHANGED
|
@@ -423,12 +423,38 @@ type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, a
|
|
|
423
423
|
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? Maybe<TState> : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any> ? Params extends never[] ? Maybe<TState> : Maybe<TState> : Maybe<TState> : Maybe<TState>;
|
|
424
424
|
|
|
425
425
|
type useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> = <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>) => Regle<Unwrap<TState>, TRules, TValidationGroups, TShortcuts>;
|
|
426
|
+
/**
|
|
427
|
+
* useRegle serves as the foundation for validation logic.
|
|
428
|
+
*
|
|
429
|
+
* It accepts the following inputs:
|
|
430
|
+
*
|
|
431
|
+
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
432
|
+
* @param rules - These should align with the structure of your state.
|
|
433
|
+
* @param modifiers - Customize computed beahviour
|
|
434
|
+
*
|
|
435
|
+
* ```ts
|
|
436
|
+
* import { useRegle } from '@regle/core';
|
|
437
|
+
import { required } from '@regle/rules';
|
|
438
|
+
|
|
439
|
+
const { r$ } = useRegle({ email: '' }, {
|
|
440
|
+
email: { required }
|
|
441
|
+
})
|
|
442
|
+
* ```
|
|
443
|
+
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
444
|
+
*/
|
|
426
445
|
declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>>;
|
|
427
446
|
|
|
428
447
|
interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
|
|
429
448
|
<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 ? {} : never>(state: MaybeRef<TState> | DeepReactiveState<TState> | undefined, rulesFactory: TRules): NoInferLegacy<TRules>;
|
|
430
449
|
<TState extends PrimitiveTypes, TRules extends RegleRuleDecl>(state: MaybeRef<TState>, rulesFactory: TRules): NoInferLegacy<TRules>;
|
|
431
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
453
|
+
* It will just return the rules without any processing.
|
|
454
|
+
*
|
|
455
|
+
* @param state - The state reference
|
|
456
|
+
* @param rules - Your rule tree
|
|
457
|
+
*/
|
|
432
458
|
declare const inferRules: inferRulesFn<Partial<AllRulesDeclarations>>;
|
|
433
459
|
|
|
434
460
|
declare function useRootStorage({ initialState, options, scopeRules, state, customRules, shortcuts, }: {
|
|
@@ -897,7 +923,6 @@ type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, No
|
|
|
897
923
|
[K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never>;
|
|
898
924
|
} : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `[Regle error] The parent property does not match the form schema`;
|
|
899
925
|
|
|
900
|
-
type ParamDecl<T = any> = MaybeRef<Maybe<T>> | (() => Maybe<T>);
|
|
901
926
|
type CreateFn<T extends any[]> = (...args: T) => any;
|
|
902
927
|
/**
|
|
903
928
|
* Transform normal parameters tuple declaration to a rich tuple declaration
|
|
@@ -905,10 +930,10 @@ type CreateFn<T extends any[]> = (...args: T) => any;
|
|
|
905
930
|
* [foo: string, bar?: number] => [foo: MaybeRef<string> | (() => string), bar?: MaybeRef<number | undefined> | (() => number) | undefined]
|
|
906
931
|
*/
|
|
907
932
|
type RegleUniversalParams<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
|
|
908
|
-
[K in keyof Args]:
|
|
933
|
+
[K in keyof Args]: MaybeRefOrGetter<Maybe<Args[K]>>;
|
|
909
934
|
}) => any : never>;
|
|
910
|
-
type UnwrapRegleUniversalParams<T extends
|
|
911
|
-
[K in keyof Args]: Args[K] extends
|
|
935
|
+
type UnwrapRegleUniversalParams<T extends MaybeRefOrGetter[] = [], F = CreateFn<T>> = [T] extends [[]] ? [] : Parameters<F extends (...args: infer Args) => any ? (...args: {
|
|
936
|
+
[K in keyof Args]: Args[K] extends MaybeRefOrGetter<Maybe<infer U>> ? U : Args[K];
|
|
912
937
|
}) => any : never>;
|
|
913
938
|
|
|
914
939
|
/**
|
|
@@ -1210,6 +1235,9 @@ type $InternalRegleResult = {
|
|
|
1210
1235
|
* @public
|
|
1211
1236
|
*/
|
|
1212
1237
|
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 = {}> = RegleStatus<TState, TRules, TShortcuts> & ([TValidationGroups] extends [never] ? {} : {
|
|
1238
|
+
/**
|
|
1239
|
+
* Collection of validation groups used declared with the `validationGroups` modifier
|
|
1240
|
+
*/
|
|
1213
1241
|
$groups: {
|
|
1214
1242
|
readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput;
|
|
1215
1243
|
};
|
|
@@ -1218,12 +1246,17 @@ type RegleRoot<TState extends Record<string, any> = Record<string, any>, TRules
|
|
|
1218
1246
|
* @public
|
|
1219
1247
|
*/
|
|
1220
1248
|
type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
|
|
1249
|
+
/** 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. */
|
|
1221
1250
|
readonly $fields: {
|
|
1222
1251
|
readonly [TKey in keyof TState]: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
1223
1252
|
} & {
|
|
1224
1253
|
readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? TKey : never]-?: InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts>;
|
|
1225
1254
|
};
|
|
1255
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1256
|
+
*
|
|
1257
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
1226
1258
|
readonly $errors: RegleErrorTree<TState>;
|
|
1259
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
1227
1260
|
readonly $silentErrors: RegleErrorTree<TState>;
|
|
1228
1261
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
1229
1262
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
@@ -1256,14 +1289,23 @@ type $InternalRegleStatusType = $InternalRegleCollectionStatus | $InternalRegleS
|
|
|
1256
1289
|
* @public
|
|
1257
1290
|
*/
|
|
1258
1291
|
type RegleFieldStatus<TState extends any = any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = never> = Omit<RegleCommonStatus<TState>, '$value'> & {
|
|
1292
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1259
1293
|
$value: Maybe<UnwrapNestedRefs<TState>>;
|
|
1294
|
+
/** $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. */
|
|
1260
1295
|
$silentValue: Maybe<UnwrapNestedRefs<TState>>;
|
|
1296
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1297
|
+
*
|
|
1298
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
1261
1299
|
readonly $errors: string[];
|
|
1300
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1262
1301
|
readonly $silentErrors: string[];
|
|
1263
1302
|
readonly $externalErrors: string[];
|
|
1264
1303
|
readonly $tooltips: string[];
|
|
1304
|
+
/** 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). */
|
|
1265
1305
|
$extractDirtyFields: (filterNullishValues?: boolean) => Maybe<TState>;
|
|
1306
|
+
/** 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). */
|
|
1266
1307
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
1308
|
+
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
1267
1309
|
readonly $rules: {
|
|
1268
1310
|
readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : any>;
|
|
1269
1311
|
};
|
|
@@ -1292,35 +1334,58 @@ interface RegleCommonStatus<TValue = any> {
|
|
|
1292
1334
|
readonly $invalid: boolean;
|
|
1293
1335
|
readonly $dirty: boolean;
|
|
1294
1336
|
readonly $anyDirty: boolean;
|
|
1337
|
+
/** Indicates if any async rule for the field is currently running. Always false for synchronous rules. */
|
|
1295
1338
|
readonly $pending: boolean;
|
|
1339
|
+
/** Convenience flag to easily decide if a message should be displayed. Equivalent to $dirty && !$pending && $invalid. */
|
|
1296
1340
|
readonly $error: boolean;
|
|
1341
|
+
/** Indicates whether the field is ready for submission. Equivalent to !$invalid && !$pending. */
|
|
1297
1342
|
readonly $ready: boolean;
|
|
1343
|
+
/** Return the current key name of the field. */
|
|
1298
1344
|
readonly $name: string;
|
|
1345
|
+
/** Id used to track collections items */
|
|
1299
1346
|
$id?: string;
|
|
1347
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1300
1348
|
$value: UnwrapNestedRefs<TValue>;
|
|
1349
|
+
/** $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. */
|
|
1301
1350
|
$silentValue: UnwrapNestedRefs<TValue>;
|
|
1351
|
+
/** Marks the field and all nested properties as $dirty. */
|
|
1302
1352
|
$touch(runCommit?: boolean, withConditions?: boolean): void;
|
|
1353
|
+
/** Resets the $dirty state on all nested properties of a form. */
|
|
1303
1354
|
$reset(): void;
|
|
1355
|
+
/** Will reset both your validation state and your form state to their initial values. */
|
|
1304
1356
|
$resetAll: () => void;
|
|
1357
|
+
/** Clears the $externalResults state back to an empty object. */
|
|
1358
|
+
$clearExternalErrors(): void;
|
|
1359
|
+
/** @interal */
|
|
1305
1360
|
$unwatch(): void;
|
|
1361
|
+
/** @interal */
|
|
1306
1362
|
$watch(): void;
|
|
1307
|
-
$clearExternalErrors(): void;
|
|
1308
1363
|
}
|
|
1309
1364
|
/**
|
|
1310
1365
|
* @public
|
|
1311
1366
|
*/
|
|
1312
1367
|
type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata extends RegleRuleMetadataDefinition = any> = {
|
|
1368
|
+
/** The name of the rule type. */
|
|
1313
1369
|
readonly $type: string;
|
|
1370
|
+
/** Returns the computed error message or messages for the current rule. */
|
|
1314
1371
|
readonly $message: string | string[];
|
|
1315
1372
|
readonly $tooltip: string | string[];
|
|
1373
|
+
/** Indicates whether or not the rule is enabled (for rules like requiredIf) */
|
|
1316
1374
|
readonly $active: boolean;
|
|
1375
|
+
/** Indicates the state of validation for this validator. */
|
|
1317
1376
|
readonly $valid: boolean;
|
|
1377
|
+
/** If the rule is async, indicates if it's currently pending. Always false if it's synchronous. */
|
|
1318
1378
|
readonly $pending: boolean;
|
|
1379
|
+
/** Returns the current path of the rule (used internally for tracking) */
|
|
1319
1380
|
readonly $path: string;
|
|
1381
|
+
/** Contains the metadata returned by the validator function. */
|
|
1320
1382
|
readonly $metadata: TMetadata;
|
|
1321
|
-
|
|
1383
|
+
/** Run the rule validator and compute its properties like $message and $active */
|
|
1322
1384
|
$validate(): Promise<boolean>;
|
|
1385
|
+
/** Reset the $valid, $metadata and $pending states */
|
|
1323
1386
|
$reset(): void;
|
|
1387
|
+
/** Returns the original rule validator function. */
|
|
1388
|
+
$validator: ((value: Maybe<TValue>, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>) & ((value: TValue, ...args: [TParams] extends [never[]] ? [] : [unknown[]] extends [TParams] ? any[] : TParams) => RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>);
|
|
1324
1389
|
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
1325
1390
|
readonly $params?: any[];
|
|
1326
1391
|
} : {
|
|
@@ -1353,13 +1418,23 @@ interface $InternalRegleRuleStatus {
|
|
|
1353
1418
|
* @public
|
|
1354
1419
|
*/
|
|
1355
1420
|
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'> & {
|
|
1421
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1356
1422
|
$value: Maybe<TState>;
|
|
1423
|
+
/** $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. */
|
|
1357
1424
|
$silentValue: Maybe<TState>;
|
|
1425
|
+
/** 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. */
|
|
1358
1426
|
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
|
|
1427
|
+
/** 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. */
|
|
1359
1428
|
readonly $field: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
|
|
1429
|
+
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
1430
|
+
*
|
|
1431
|
+
* Only contains errors from properties where $dirty equals true. */
|
|
1360
1432
|
readonly $errors: RegleCollectionErrors<TState>;
|
|
1433
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
1361
1434
|
readonly $silentErrors: RegleCollectionErrors<TState>;
|
|
1435
|
+
/** 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). */
|
|
1362
1436
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
1437
|
+
/** 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). */
|
|
1363
1438
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
1364
1439
|
} & ([TShortcuts['collections']] extends [never] ? {} : {
|
|
1365
1440
|
[K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
|
|
@@ -1382,7 +1457,6 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1382
1457
|
}
|
|
1383
1458
|
|
|
1384
1459
|
/**
|
|
1385
|
-
* @description
|
|
1386
1460
|
* Create a typed custom rule that can be used like default rules.
|
|
1387
1461
|
* It can also be declared in the global options
|
|
1388
1462
|
*
|
|
@@ -1391,6 +1465,7 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1391
1465
|
* @typeParam TValue - The input value the rule should receive
|
|
1392
1466
|
* @typeParam TParams - Tuple declaration of the rule parameters (if any)
|
|
1393
1467
|
*
|
|
1468
|
+
*
|
|
1394
1469
|
* @param definition - The rule processors object
|
|
1395
1470
|
*
|
|
1396
1471
|
* @returns A rule definition that can be callable depending on params presence
|
|
@@ -1402,7 +1477,7 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1402
1477
|
* import {isFilled} from '@regle/rules';
|
|
1403
1478
|
*
|
|
1404
1479
|
* export const isFoo = createRule({
|
|
1405
|
-
* validator(value: string) {
|
|
1480
|
+
* validator(value: Maybe<string>) {
|
|
1406
1481
|
* if (isFilled(value)) {
|
|
1407
1482
|
* return value === 'foo';
|
|
1408
1483
|
* }
|
|
@@ -1410,7 +1485,10 @@ interface $InternalRegleCollectionStatus extends Omit<$InternalRegleStatus, '$fi
|
|
|
1410
1485
|
* },
|
|
1411
1486
|
* message: "The value should be 'foo'"
|
|
1412
1487
|
* })
|
|
1488
|
+
*
|
|
1413
1489
|
* ```
|
|
1490
|
+
*
|
|
1491
|
+
* Docs: {@link https://reglejs.dev/core-concepts/rules/reusable-rules}
|
|
1414
1492
|
*/
|
|
1415
1493
|
declare function createRule<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(definition: RegleRuleInit<TValue, TParams, TReturn, TMetadata, TAsync>): InferRegleRule<TValue, TParams, TAsync, TMetadata>;
|
|
1416
1494
|
|
|
@@ -1418,8 +1496,20 @@ declare function createRule<TValue extends any, TParams extends any[], TReturn e
|
|
|
1418
1496
|
* Returns a clean list of parameters
|
|
1419
1497
|
* Removing Ref and executing function to return the unwraped value
|
|
1420
1498
|
*/
|
|
1421
|
-
declare function unwrapRuleParameters<TParams extends any[]>(params:
|
|
1499
|
+
declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrGetter[]): TParams;
|
|
1422
1500
|
|
|
1501
|
+
/**
|
|
1502
|
+
* Define a global regle configuration, where you can:
|
|
1503
|
+
* - Customize buil-in rules messages
|
|
1504
|
+
* - Add your custom rules
|
|
1505
|
+
* - Define global modifiers
|
|
1506
|
+
* - Define shortcuts
|
|
1507
|
+
*
|
|
1508
|
+
* It will return:
|
|
1509
|
+
*
|
|
1510
|
+
* - a `useRegle` composable that can typecheck your custom rules
|
|
1511
|
+
* - an `inferRules` helper that can typecheck your custom rules
|
|
1512
|
+
*/
|
|
1423
1513
|
declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<AllRulesDeclarations> = EmptyObject>({ rules, modifiers, shortcuts, }: {
|
|
1424
1514
|
rules?: () => TCustomRules;
|
|
1425
1515
|
modifiers?: RegleBehaviourOptions;
|
|
@@ -1429,4 +1519,4 @@ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TC
|
|
|
1429
1519
|
inferRules: inferRulesFn<TCustomRules>;
|
|
1430
1520
|
};
|
|
1431
1521
|
|
|
1432
|
-
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, type NoInferLegacy, type
|
|
1522
|
+
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type LocalRegleBehaviourOptions, type Maybe, 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 RegleStatus, type RegleUniversalParams, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, defineRegleConfig, inferRules, unwrapRuleParameters, useRegle, useRootStorage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "Typescript-first model-based form validation library for Vue 3",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"vue": "^3.3.0"
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"homepage": "https://
|
|
65
|
+
"homepage": "https://reglejs.dev/",
|
|
66
66
|
"repository": {
|
|
67
67
|
"type": "git",
|
|
68
68
|
"url": "git+https://github.com/victorgarciaesgi/regle.git"
|