Skip to content

Commit

Permalink
temp: merge regles
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgarciaesgi committed Jan 5, 2025
1 parent b54066a commit def789e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/core/defaultValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ export type DefaultValidators = {
required: RegleRuleDefinition<unknown, []>;
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
url: RegleRuleDefinition<string, [], false, boolean, string>;
};
3 changes: 3 additions & 0 deletions packages/core/src/core/mergeRegles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { SuperCompatibleRegleRoot } from '../types';

export function mergeRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>>(regles: TRegles) {}
22 changes: 22 additions & 0 deletions packages/core/src/types/rules/rule.status.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ export type RegleRoot<
};
});

export type SuperCompatibleRegleRoot = $InternalRegleStatus & {
$groups?: { [x: string]: RegleValidationGroupOutput };
};

export type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>> = Omit<
RegleCommonStatus,
'$name' | '$value' | '$silentValue'
> & {
/** Dictionnay of merged Regle instances and their properties */
$instances: { [K in keyof TRegles]: TRegles[K] };
/** Collection of all the error messages, collected for all children properties and nested forms.
*
* Only contains errors from properties where $dirty equals true. */
readonly $errors: RegleErrorTree<TState>;
/** Collection of all the error messages, collected for all children properties. */
readonly $silentErrors: RegleErrorTree<TState>;
/* 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). */
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
/* 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). */
$validate: () => Promise<RegleResult<TState, TRules>>;
};

/**
* @public
*/
Expand Down

0 comments on commit def789e

Please sign in to comment.