@regle/core 0.7.4-beta.3 → 0.7.5

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.
@@ -71,28 +71,6 @@ function isObject(obj) {
71
71
  return typeof obj === "object" && obj !== null && !Array.isArray(obj);
72
72
  }
73
73
 
74
- // ../shared/utils/isDate.ts
75
- function isDate(value) {
76
- if (isEmpty(value)) {
77
- return false;
78
- }
79
- try {
80
- let possibleDate = null;
81
- if (value instanceof Date) {
82
- possibleDate = value;
83
- } else if (typeof value === "string") {
84
- const date = new Date(value);
85
- if (date.toString() === "Invalid Date") {
86
- return false;
87
- }
88
- possibleDate = date;
89
- }
90
- return !!possibleDate;
91
- } catch (e) {
92
- return false;
93
- }
94
- }
95
-
96
74
  // ../shared/utils/toDate.ts
97
75
  function toDate(argument) {
98
76
  const argStr = Object.prototype.toString.call(argument);
@@ -444,6 +422,25 @@ function randomId() {
444
422
  return uint32.toString(10);
445
423
  }
446
424
  }
425
+ function tryOnScopeDispose(fn) {
426
+ if (vue.getCurrentScope()) {
427
+ vue.onScopeDispose(fn);
428
+ return true;
429
+ }
430
+ return false;
431
+ }
432
+ function createGlobalState(stateFactory) {
433
+ let initialized = false;
434
+ let state;
435
+ const scope = vue.effectScope(true);
436
+ return (...args) => {
437
+ if (!initialized) {
438
+ state = scope.run(() => stateFactory(...args));
439
+ initialized = true;
440
+ }
441
+ return state;
442
+ };
443
+ }
447
444
 
448
445
  // src/core/useRegle/guards/ruleDef.guards.ts
449
446
  function isNestedRulesDef(state, rules) {
@@ -476,7 +473,7 @@ function extractRulesErrors({
476
473
  silent = false
477
474
  }) {
478
475
  return Object.entries(field.$rules ?? {}).map(([_, rule]) => {
479
- if (silent) {
476
+ if (silent && !rule.$valid) {
480
477
  return rule.$message;
481
478
  } else if (!rule.$valid && field.$error && !rule.$validating) {
482
479
  return rule.$message;
@@ -876,27 +873,27 @@ function createReactiveFieldStatus({
876
873
  const $errors = vue.computed(() => {
877
874
  return extractRulesErrors({
878
875
  field: {
876
+ $rules: $rules.value,
879
877
  $error: $error.value,
880
878
  $externalErrors: externalErrors?.value,
881
- $schemaErrors: schemaErrors?.value,
882
- $rules: $rules.value
879
+ $schemaErrors: schemaErrors?.value
883
880
  }
884
881
  });
885
882
  });
886
883
  const $silentErrors = vue.computed(() => {
887
884
  return extractRulesErrors({
888
885
  field: {
889
- $error: true,
886
+ $rules: $rules.value,
887
+ $error: $error.value,
890
888
  $externalErrors: externalErrors?.value,
891
- $schemaErrors: schemaErrors?.value,
892
- $rules: $rules.value
889
+ $schemaErrors: schemaErrors?.value
893
890
  },
894
891
  silent: true
895
892
  });
896
893
  });
897
894
  const $edited = vue.computed(() => {
898
895
  if ($dirty.value) {
899
- if (isDate(initialState.value) && isDate(state.value)) {
896
+ if (initialState.value instanceof Date && state.value instanceof Date) {
900
897
  return toDate(initialState.value).getDate() !== toDate(state.value).getDate();
901
898
  }
902
899
  if (initialState.value == null) {
@@ -2258,10 +2255,18 @@ function defineRegleConfig({
2258
2255
  function mergeRegles(regles, _scoped) {
2259
2256
  const scoped = _scoped == null ? false : _scoped;
2260
2257
  const $value = vue.computed({
2261
- get: () => Object.fromEntries(Object.entries(regles).map(([key, r]) => [key, r.$value])),
2258
+ get: () => {
2259
+ if (scoped) {
2260
+ return Object.values(regles).map((r) => r.$value);
2261
+ } else {
2262
+ return Object.fromEntries(Object.entries(regles).map(([key, r]) => [key, r.$value]));
2263
+ }
2264
+ },
2262
2265
  set: (value) => {
2263
- if (typeof value === "object") {
2264
- Object.entries(value).forEach(([key, newValue]) => regles[key].$value = newValue);
2266
+ if (!scoped) {
2267
+ if (typeof value === "object") {
2268
+ Object.entries(value).forEach(([key, newValue]) => regles[key].$value = newValue);
2269
+ }
2265
2270
  }
2266
2271
  }
2267
2272
  });
@@ -2274,7 +2279,8 @@ function mergeRegles(regles, _scoped) {
2274
2279
  }
2275
2280
  });
2276
2281
  const $dirty = vue.computed(() => {
2277
- return Object.entries(regles).every(([_, regle]) => {
2282
+ const entries = Object.entries(regles);
2283
+ return !!entries.length && entries.every(([_, regle]) => {
2278
2284
  return regle?.$dirty;
2279
2285
  });
2280
2286
  });
@@ -2289,8 +2295,9 @@ function mergeRegles(regles, _scoped) {
2289
2295
  });
2290
2296
  });
2291
2297
  const $valid = vue.computed(() => {
2292
- return Object.entries(regles).every(([_, regle]) => {
2293
- return regle?.$invalid;
2298
+ const entries = Object.entries(regles);
2299
+ return !!entries.length && entries.every(([_, regle]) => {
2300
+ return regle?.$valid;
2294
2301
  });
2295
2302
  });
2296
2303
  const $error = vue.computed(() => {
@@ -2299,7 +2306,8 @@ function mergeRegles(regles, _scoped) {
2299
2306
  });
2300
2307
  });
2301
2308
  const $ready = vue.computed(() => {
2302
- return Object.entries(regles).every(([_, regle]) => {
2309
+ const entries = Object.entries(regles);
2310
+ return !!entries.length && entries.every(([_, regle]) => {
2303
2311
  return regle?.$ready;
2304
2312
  });
2305
2313
  });
@@ -2309,21 +2317,34 @@ function mergeRegles(regles, _scoped) {
2309
2317
  });
2310
2318
  });
2311
2319
  const $errors = vue.computed(() => {
2312
- return Object.fromEntries(
2313
- Object.entries(regles).map(([key, regle]) => {
2314
- return [key, regle.$errors];
2315
- })
2316
- );
2320
+ if (scoped) {
2321
+ return Object.entries(regles).map(([_, regle]) => {
2322
+ return regle.$errors;
2323
+ });
2324
+ } else {
2325
+ return Object.fromEntries(
2326
+ Object.entries(regles).map(([key, regle]) => {
2327
+ return [key, regle.$errors];
2328
+ })
2329
+ );
2330
+ }
2317
2331
  });
2318
2332
  const $silentErrors = vue.computed(() => {
2319
- return Object.fromEntries(
2320
- Object.entries(regles).map(([key, regle]) => {
2321
- return [key, regle.$silentErrors];
2322
- })
2323
- );
2333
+ if (scoped) {
2334
+ return Object.entries(regles).map(([_, regle]) => {
2335
+ return regle.$silentErrors;
2336
+ });
2337
+ } else {
2338
+ return Object.fromEntries(
2339
+ Object.entries(regles).map(([key, regle]) => {
2340
+ return [key, regle.$silentErrors];
2341
+ })
2342
+ );
2343
+ }
2324
2344
  });
2325
2345
  const $edited = vue.computed(() => {
2326
- return Object.entries(regles).every(([_, regle]) => {
2346
+ const entries = Object.entries(regles);
2347
+ return !!entries.length && entries.every(([_, regle]) => {
2327
2348
  return regle?.$edited;
2328
2349
  });
2329
2350
  });
@@ -2333,7 +2354,11 @@ function mergeRegles(regles, _scoped) {
2333
2354
  });
2334
2355
  });
2335
2356
  const $instances = vue.computed(() => {
2336
- return regles;
2357
+ if (scoped) {
2358
+ return Object.values(regles);
2359
+ } else {
2360
+ return regles;
2361
+ }
2337
2362
  });
2338
2363
  function $reset() {
2339
2364
  Object.values(regles).forEach((regle) => {
@@ -2380,12 +2405,12 @@ function mergeRegles(regles, _scoped) {
2380
2405
  }
2381
2406
  return vue.reactive({
2382
2407
  ...!scoped && {
2383
- $instances,
2384
- $value,
2385
- $silentValue,
2386
- $errors,
2387
- $silentErrors
2408
+ $silentValue
2388
2409
  },
2410
+ $errors,
2411
+ $silentErrors,
2412
+ $instances,
2413
+ $value,
2389
2414
  $dirty,
2390
2415
  $anyDirty,
2391
2416
  $invalid,
@@ -2403,42 +2428,112 @@ function mergeRegles(regles, _scoped) {
2403
2428
  $clearExternalErrors
2404
2429
  });
2405
2430
  }
2406
- function createUseCollectScopedValidations(instances) {
2407
- function useCollectScopedValidations() {
2408
- const r$ = vue.ref(mergeRegles(instances.value, true));
2431
+ function createUseCollectScope(instances) {
2432
+ function useCollectScope(namespace) {
2433
+ const computedNamespace = vue.computed(() => vue.toValue(namespace));
2434
+ setEmptyNamespace();
2435
+ const r$ = vue.ref(collectRegles(instances.value));
2409
2436
  const regle = vue.reactive({ r$ });
2410
- vue.watch(instances, (newInstances) => {
2411
- r$.value = mergeRegles(newInstances, true);
2412
- });
2437
+ function setEmptyNamespace() {
2438
+ if (computedNamespace.value && !instances.value[computedNamespace.value]) {
2439
+ instances.value[computedNamespace.value] = {};
2440
+ }
2441
+ }
2442
+ vue.watch(computedNamespace, setEmptyNamespace);
2443
+ vue.watch(
2444
+ instances,
2445
+ (newInstances) => {
2446
+ r$.value = collectRegles(newInstances);
2447
+ },
2448
+ { deep: true }
2449
+ );
2450
+ function collectRegles(r$Instances) {
2451
+ if (computedNamespace.value) {
2452
+ const namespaceInstances = r$Instances[computedNamespace.value] ?? {};
2453
+ return mergeRegles(namespaceInstances, true);
2454
+ } else {
2455
+ return mergeRegles(r$Instances["~~global"] ?? {}, true);
2456
+ }
2457
+ }
2413
2458
  return { r$: regle.r$ };
2414
2459
  }
2415
- return { useCollectScopedValidations };
2460
+ return { useCollectScope };
2416
2461
  }
2417
- function createUseScopedRegleComposable(customUseRegle) {
2462
+ function createUseScopedRegleComposable(instances, customUseRegle) {
2418
2463
  const scopedUseRegle = customUseRegle ?? useRegle;
2419
- const instances = vue.ref({});
2420
2464
  const useScopedRegle = (state, rulesFactory, options) => {
2421
- const $id = randomId();
2422
- const { r$ } = scopedUseRegle(state, rulesFactory, options);
2423
- instances.value[$id] = r$;
2424
- vue.onScopeDispose(() => {
2425
- delete instances.value[$id];
2465
+ const { namespace, ...restOptions } = options ?? {};
2466
+ const computedNamespace = vue.computed(() => vue.toValue(namespace));
2467
+ const $id = vue.ref(`${Object.keys(instances.value).length + 1}-${randomId()}`);
2468
+ const instanceName = vue.computed(() => {
2469
+ return `instance-${$id.value}`;
2470
+ });
2471
+ const { r$ } = scopedUseRegle(state, rulesFactory, restOptions);
2472
+ register();
2473
+ tryOnScopeDispose(dispose);
2474
+ vue.watch(computedNamespace, (newName, oldName) => {
2475
+ dispose(oldName);
2476
+ register();
2426
2477
  });
2427
- function $dispose() {
2428
- delete instances.value[$id];
2478
+ if (vue.getCurrentInstance()) {
2479
+ vue.onMounted(() => {
2480
+ const currentInstance = vue.getCurrentInstance();
2481
+ if (typeof window !== "undefined" && currentInstance?.proxy?.$el?.parentElement) {
2482
+ if (document.documentElement && !document.documentElement.contains(currentInstance?.proxy?.$el?.parentElement)) {
2483
+ dispose();
2484
+ }
2485
+ }
2486
+ });
2487
+ }
2488
+ function dispose(oldName) {
2489
+ const nameToClean = oldName ?? computedNamespace.value;
2490
+ if (nameToClean) {
2491
+ if (instances.value[nameToClean]) {
2492
+ delete instances.value[nameToClean][instanceName.value];
2493
+ }
2494
+ } else if (instances.value["~~global"][instanceName.value]) {
2495
+ delete instances.value["~~global"][instanceName.value];
2496
+ }
2429
2497
  }
2430
- return { r$, $dispose };
2498
+ function register() {
2499
+ if (computedNamespace.value) {
2500
+ if (!instances.value[computedNamespace.value]) {
2501
+ instances.value[computedNamespace.value] = {};
2502
+ }
2503
+ instances.value[computedNamespace.value][instanceName.value] = r$;
2504
+ } else {
2505
+ if (!instances.value["~~global"]) {
2506
+ instances.value["~~global"] = {};
2507
+ }
2508
+ instances.value["~~global"][instanceName.value] = r$;
2509
+ }
2510
+ }
2511
+ return { r$, dispose, register };
2431
2512
  };
2432
- return { useScopedRegle, instances };
2513
+ return { useScopedRegle };
2433
2514
  }
2434
2515
 
2435
2516
  // src/core/createScopedUseRegle/createScopedUseRegle.ts
2436
- function createScopedUseRegle(customUseRegle) {
2437
- const { instances, useScopedRegle } = createUseScopedRegleComposable(customUseRegle);
2438
- const { useCollectScopedValidations } = createUseCollectScopedValidations(instances);
2517
+ function createScopedUseRegle(options) {
2518
+ const useInstances = options?.customStore ? () => {
2519
+ if (options.customStore) {
2520
+ if (!options.customStore?.value["~~global"]) {
2521
+ options.customStore.value["~~global"] = {};
2522
+ } else if (options.customStore?.value) {
2523
+ options.customStore.value = { "~~global": {} };
2524
+ }
2525
+ }
2526
+ return options.customStore;
2527
+ } : createGlobalState(() => {
2528
+ const $inst = vue.ref({ "~~global": {} });
2529
+ return $inst;
2530
+ });
2531
+ const instances = useInstances();
2532
+ const { useScopedRegle } = createUseScopedRegleComposable(instances, options?.customUseRegle);
2533
+ const { useCollectScope } = createUseCollectScope(instances);
2439
2534
  return {
2440
2535
  useScopedRegle,
2441
- useCollectScopedValidations
2536
+ useCollectScope
2442
2537
  };
2443
2538
  }
2444
2539
 
@@ -45,6 +45,68 @@ declare global {
45
45
  }
46
46
  }
47
47
 
48
+ /**
49
+ Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
50
+
51
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
52
+
53
+ @example
54
+ ```
55
+ import type {UnionToIntersection} from 'type-fest';
56
+
57
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
58
+
59
+ type Intersection = UnionToIntersection<Union>;
60
+ //=> {the(): void; great(arg: string): void; escape: boolean};
61
+ ```
62
+
63
+ A more applicable example which could make its way into your library code follows.
64
+
65
+ @example
66
+ ```
67
+ import type {UnionToIntersection} from 'type-fest';
68
+
69
+ class CommandOne {
70
+ commands: {
71
+ a1: () => undefined,
72
+ b1: () => undefined,
73
+ }
74
+ }
75
+
76
+ class CommandTwo {
77
+ commands: {
78
+ a2: (argA: string) => undefined,
79
+ b2: (argB: string) => undefined,
80
+ }
81
+ }
82
+
83
+ const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
84
+ type Union = typeof union;
85
+ //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
86
+
87
+ type Intersection = UnionToIntersection<Union>;
88
+ //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
89
+ ```
90
+
91
+ @category Type
92
+ */
93
+ type UnionToIntersection$1<Union> = (
94
+ // `extends unknown` is always going to be the case and is used to convert the
95
+ // `Union` into a [distributive conditional
96
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
97
+ Union extends unknown
98
+ // The union type is used as the only argument to a function since the union
99
+ // of function arguments is an intersection.
100
+ ? (distributedUnion: Union) => void
101
+ // This won't happen.
102
+ : never
103
+ // Infer the `Intersection` type since TypeScript represents the positional
104
+ // arguments of unions of functions as an intersection of the union.
105
+ ) extends ((mergedIntersection: infer Intersection) => void)
106
+ // The `& Union` is to allow indexing by the resulting type
107
+ ? Intersection & Union
108
+ : never;
109
+
48
110
  declare const emptyObjectSymbol: unique symbol;
49
111
 
50
112
  /**
@@ -353,68 +415,6 @@ type RequiredObjectDeep<ObjectType extends object> = {
353
415
  [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
354
416
  };
355
417
 
356
- /**
357
- Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
358
-
359
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
360
-
361
- @example
362
- ```
363
- import type {UnionToIntersection} from 'type-fest';
364
-
365
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
366
-
367
- type Intersection = UnionToIntersection<Union>;
368
- //=> {the(): void; great(arg: string): void; escape: boolean};
369
- ```
370
-
371
- A more applicable example which could make its way into your library code follows.
372
-
373
- @example
374
- ```
375
- import type {UnionToIntersection} from 'type-fest';
376
-
377
- class CommandOne {
378
- commands: {
379
- a1: () => undefined,
380
- b1: () => undefined,
381
- }
382
- }
383
-
384
- class CommandTwo {
385
- commands: {
386
- a2: (argA: string) => undefined,
387
- b2: (argB: string) => undefined,
388
- }
389
- }
390
-
391
- const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
392
- type Union = typeof union;
393
- //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
394
-
395
- type Intersection = UnionToIntersection<Union>;
396
- //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
397
- ```
398
-
399
- @category Type
400
- */
401
- type UnionToIntersection$1<Union> = (
402
- // `extends unknown` is always going to be the case and is used to convert the
403
- // `Union` into a [distributive conditional
404
- // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
405
- Union extends unknown
406
- // The union type is used as the only argument to a function since the union
407
- // of function arguments is an intersection.
408
- ? (distributedUnion: Union) => void
409
- // This won't happen.
410
- : never
411
- // Infer the `Intersection` type since TypeScript represents the positional
412
- // arguments of unions of functions as an intersection of the union.
413
- ) extends ((mergedIntersection: infer Intersection) => void)
414
- // The `& Union` is to allow indexing by the resulting type
415
- ? Intersection & Union
416
- : never;
417
-
418
418
  /**
419
419
  Returns the last element of a union type.
420
420
 
@@ -569,7 +569,7 @@ type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, a
569
569
  ] extends [TState] ? unknown : NonNullable<TState> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule> extends false ? false : true : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends false ? false : true : false : false;
570
570
  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>;
571
571
 
572
- type useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}> = <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, TAdditionalReturnProperties>;
572
+ type useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> = <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>;
573
573
  /**
574
574
  * useRegle serves as the foundation for validation logic.
575
575
  *
@@ -589,7 +589,7 @@ type useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts e
589
589
  * ```
590
590
  * Docs: {@link https://reglejs.dev/core-concepts/}
591
591
  */
592
- declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>, {}>;
592
+ declare const useRegle: useRegleFn<Partial<AllRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
593
593
 
594
594
  interface inferRulesFn<TCustomRules extends Partial<AllRulesDeclarations>> {
595
595
  <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>;
@@ -1408,12 +1408,16 @@ type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
1408
1408
  [x: string]: RegleValidationGroupOutput;
1409
1409
  };
1410
1410
  };
1411
+ type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
1412
+ '~~global': Record<string, SuperCompatibleRegleRoot>;
1413
+ };
1414
+ type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
1411
1415
  interface SuperCompatibleRegleStatus extends RegleCommonStatus {
1412
1416
  $fields: {
1413
1417
  [x: string]: unknown;
1414
1418
  };
1415
- readonly $errors: Record<string, $InternalRegleErrors>;
1416
- readonly $silentErrors: Record<string, $InternalRegleErrors>;
1419
+ readonly $errors: Record<string, RegleValidationErrors<any>>;
1420
+ readonly $silentErrors: Record<string, RegleValidationErrors<any>>;
1417
1421
  $extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
1418
1422
  $validate: () => Promise<$InternalRegleResult>;
1419
1423
  }
@@ -1704,7 +1708,7 @@ declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrG
1704
1708
  * - a `useRegle` composable that can typecheck your custom rules
1705
1709
  * - an `inferRules` helper that can typecheck your custom rules
1706
1710
  */
1707
- declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<AllRulesDeclarations> = EmptyObject>({ rules, modifiers, shortcuts, }: {
1711
+ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<AllRulesDeclarations>>({ rules, modifiers, shortcuts, }: {
1708
1712
  rules?: () => TCustomRules;
1709
1713
  modifiers?: RegleBehaviourOptions;
1710
1714
  shortcuts?: TShortcuts;
@@ -1739,7 +1743,16 @@ type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TVal
1739
1743
  /** 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). */
1740
1744
  $validate: () => Promise<MergedReglesResult<TRegles>>;
1741
1745
  };
1742
- type MergedScopedRegles<TValue extends Record<string, any> = Record<string, unknown>> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue'>;
1746
+ type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue'> & {
1747
+ /** Array of scoped Regles instances */
1748
+ readonly $instances: SuperCompatibleRegleRoot[];
1749
+ /** Collection of all registered Regles instances values */
1750
+ readonly $value: TValue;
1751
+ /** Collection of all registered Regles instances errors */
1752
+ readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
1753
+ /** Collection of all registered Regles instances silent errors */
1754
+ readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
1755
+ };
1743
1756
  type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
1744
1757
  result: false;
1745
1758
  data: {
@@ -1758,12 +1771,18 @@ type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>
1758
1771
  declare function mergeRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TScoped extends boolean = false>(regles: TRegles, _scoped?: TScoped): TScoped extends false ? MergedRegles<TRegles> : MergedScopedRegles;
1759
1772
 
1760
1773
  declare function createScopedUseRegle<TCustomRegle extends useRegleFn<any, any> = useRegleFn<Partial<AllRulesDeclarations>>, TReturnedRegle extends useRegleFn<any, any> = TCustomRegle extends useRegleFn<infer A, infer B> ? useRegleFn<A, B, {
1761
- $dispose: () => void;
1762
- }> : useRegleFn<Partial<AllRulesDeclarations>>>(customUseRegle?: TCustomRegle): {
1774
+ dispose: () => void;
1775
+ register: () => void;
1776
+ }, {
1777
+ namespace?: MaybeRefOrGetter<string>;
1778
+ }> : useRegleFn<Partial<AllRulesDeclarations>>>(options?: {
1779
+ customUseRegle?: TCustomRegle;
1780
+ customStore?: Ref<ScopedInstancesRecordLike>;
1781
+ }): {
1763
1782
  useScopedRegle: TReturnedRegle;
1764
- useCollectScopedValidations<TValue extends Record<string, any> = Record<string, unknown>>(): {
1783
+ useCollectScope<TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>): {
1765
1784
  r$: MergedScopedRegles<TValue>;
1766
1785
  };
1767
1786
  };
1768
1787
 
1769
- export { type $InternalRegleStatus, type AllRulesDeclarations, 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 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 RegleStatus, type RegleUniversalParams, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, defineRegleConfig, inferRules, mergeRegles, unwrapRuleParameters, useRegle, useRootStorage };
1788
+ export { type $InternalRegleStatus, type AllRulesDeclarations, 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 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 RegleStatus, type RegleUniversalParams, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleRoot, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, defineRegleConfig, inferRules, mergeRegles, unwrapRuleParameters, useRegle, useRootStorage };