@regle/core 0.7.4-beta.2 β†’ 0.7.4

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 CHANGED
@@ -22,9 +22,7 @@ It's heavily inspired by Vuelidate.
22
22
  ## 🧰 Features
23
23
  - βœ… 100% type inference
24
24
  - πŸ“– Model based validation
25
- - πŸ’€ Headless
26
25
  - πŸͺ— Extensible
27
26
  - πŸ›’ Collection validation
28
27
  - πŸ¦Έβ€β™‚οΈ [Zod](https://zod.dev/) support
29
28
  - πŸ€– [Valibot](https://valibot.dev/) support
30
- - πŸͺΆ Light(~7kb gzip) and 0 dependencies
@@ -65,7 +65,7 @@ function cloneDeep(obj) {
65
65
 
66
66
  // ../shared/utils/object.utils.ts
67
67
  function isObject(obj) {
68
- if (obj instanceof Date || obj instanceof File) {
68
+ if (obj && (obj instanceof Date || obj.constructor.name == "File" || obj.constructor.name == "FileList")) {
69
69
  return false;
70
70
  }
71
71
  return typeof obj === "object" && obj !== null && !Array.isArray(obj);
@@ -386,9 +386,6 @@ function useStorage() {
386
386
  };
387
387
  }
388
388
  function isRefObject(obj) {
389
- if (obj.value instanceof Date || obj.value instanceof File) {
390
- return false;
391
- }
392
389
  return isObject(obj.value);
393
390
  }
394
391
  function unwrapGetter(getter, value, index) {
@@ -447,6 +444,25 @@ function randomId() {
447
444
  return uint32.toString(10);
448
445
  }
449
446
  }
447
+ function tryOnScopeDispose(fn) {
448
+ if (vue.getCurrentScope()) {
449
+ vue.onScopeDispose(fn);
450
+ return true;
451
+ }
452
+ return false;
453
+ }
454
+ function createGlobalState(stateFactory) {
455
+ let initialized = false;
456
+ let state;
457
+ const scope = vue.effectScope(true);
458
+ return (...args) => {
459
+ if (!initialized) {
460
+ state = scope.run(() => stateFactory(...args));
461
+ initialized = true;
462
+ }
463
+ return state;
464
+ };
465
+ }
450
466
 
451
467
  // src/core/useRegle/guards/ruleDef.guards.ts
452
468
  function isNestedRulesDef(state, rules) {
@@ -479,7 +495,7 @@ function extractRulesErrors({
479
495
  silent = false
480
496
  }) {
481
497
  return Object.entries(field.$rules ?? {}).map(([_, rule]) => {
482
- if (silent) {
498
+ if (silent && !rule.$valid) {
483
499
  return rule.$message;
484
500
  } else if (!rule.$valid && field.$error && !rule.$validating) {
485
501
  return rule.$message;
@@ -879,20 +895,20 @@ function createReactiveFieldStatus({
879
895
  const $errors = vue.computed(() => {
880
896
  return extractRulesErrors({
881
897
  field: {
898
+ $rules: $rules.value,
882
899
  $error: $error.value,
883
900
  $externalErrors: externalErrors?.value,
884
- $schemaErrors: schemaErrors?.value,
885
- $rules: $rules.value
901
+ $schemaErrors: schemaErrors?.value
886
902
  }
887
903
  });
888
904
  });
889
905
  const $silentErrors = vue.computed(() => {
890
906
  return extractRulesErrors({
891
907
  field: {
892
- $error: true,
908
+ $rules: $rules.value,
909
+ $error: $error.value,
893
910
  $externalErrors: externalErrors?.value,
894
- $schemaErrors: schemaErrors?.value,
895
- $rules: $rules.value
911
+ $schemaErrors: schemaErrors?.value
896
912
  },
897
913
  silent: true
898
914
  });
@@ -2261,10 +2277,18 @@ function defineRegleConfig({
2261
2277
  function mergeRegles(regles, _scoped) {
2262
2278
  const scoped = _scoped == null ? false : _scoped;
2263
2279
  const $value = vue.computed({
2264
- get: () => Object.fromEntries(Object.entries(regles).map(([key, r]) => [key, r.$value])),
2280
+ get: () => {
2281
+ if (scoped) {
2282
+ return Object.values(regles).map((r) => r.$value);
2283
+ } else {
2284
+ return Object.fromEntries(Object.entries(regles).map(([key, r]) => [key, r.$value]));
2285
+ }
2286
+ },
2265
2287
  set: (value) => {
2266
- if (typeof value === "object") {
2267
- Object.entries(value).forEach(([key, newValue]) => regles[key].$value = newValue);
2288
+ if (!scoped) {
2289
+ if (typeof value === "object") {
2290
+ Object.entries(value).forEach(([key, newValue]) => regles[key].$value = newValue);
2291
+ }
2268
2292
  }
2269
2293
  }
2270
2294
  });
@@ -2277,7 +2301,8 @@ function mergeRegles(regles, _scoped) {
2277
2301
  }
2278
2302
  });
2279
2303
  const $dirty = vue.computed(() => {
2280
- return Object.entries(regles).every(([_, regle]) => {
2304
+ const entries = Object.entries(regles);
2305
+ return !!entries.length && entries.every(([_, regle]) => {
2281
2306
  return regle?.$dirty;
2282
2307
  });
2283
2308
  });
@@ -2292,8 +2317,9 @@ function mergeRegles(regles, _scoped) {
2292
2317
  });
2293
2318
  });
2294
2319
  const $valid = vue.computed(() => {
2295
- return Object.entries(regles).every(([_, regle]) => {
2296
- return regle?.$invalid;
2320
+ const entries = Object.entries(regles);
2321
+ return !!entries.length && entries.every(([_, regle]) => {
2322
+ return regle?.$valid;
2297
2323
  });
2298
2324
  });
2299
2325
  const $error = vue.computed(() => {
@@ -2302,7 +2328,8 @@ function mergeRegles(regles, _scoped) {
2302
2328
  });
2303
2329
  });
2304
2330
  const $ready = vue.computed(() => {
2305
- return Object.entries(regles).every(([_, regle]) => {
2331
+ const entries = Object.entries(regles);
2332
+ return !!entries.length && entries.every(([_, regle]) => {
2306
2333
  return regle?.$ready;
2307
2334
  });
2308
2335
  });
@@ -2312,21 +2339,34 @@ function mergeRegles(regles, _scoped) {
2312
2339
  });
2313
2340
  });
2314
2341
  const $errors = vue.computed(() => {
2315
- return Object.fromEntries(
2316
- Object.entries(regles).map(([key, regle]) => {
2317
- return [key, regle.$errors];
2318
- })
2319
- );
2342
+ if (scoped) {
2343
+ return Object.entries(regles).map(([_, regle]) => {
2344
+ return regle.$errors;
2345
+ });
2346
+ } else {
2347
+ return Object.fromEntries(
2348
+ Object.entries(regles).map(([key, regle]) => {
2349
+ return [key, regle.$errors];
2350
+ })
2351
+ );
2352
+ }
2320
2353
  });
2321
2354
  const $silentErrors = vue.computed(() => {
2322
- return Object.fromEntries(
2323
- Object.entries(regles).map(([key, regle]) => {
2324
- return [key, regle.$silentErrors];
2325
- })
2326
- );
2355
+ if (scoped) {
2356
+ return Object.entries(regles).map(([_, regle]) => {
2357
+ return regle.$silentErrors;
2358
+ });
2359
+ } else {
2360
+ return Object.fromEntries(
2361
+ Object.entries(regles).map(([key, regle]) => {
2362
+ return [key, regle.$silentErrors];
2363
+ })
2364
+ );
2365
+ }
2327
2366
  });
2328
2367
  const $edited = vue.computed(() => {
2329
- return Object.entries(regles).every(([_, regle]) => {
2368
+ const entries = Object.entries(regles);
2369
+ return !!entries.length && entries.every(([_, regle]) => {
2330
2370
  return regle?.$edited;
2331
2371
  });
2332
2372
  });
@@ -2336,7 +2376,11 @@ function mergeRegles(regles, _scoped) {
2336
2376
  });
2337
2377
  });
2338
2378
  const $instances = vue.computed(() => {
2339
- return regles;
2379
+ if (scoped) {
2380
+ return Object.values(regles);
2381
+ } else {
2382
+ return regles;
2383
+ }
2340
2384
  });
2341
2385
  function $reset() {
2342
2386
  Object.values(regles).forEach((regle) => {
@@ -2383,12 +2427,12 @@ function mergeRegles(regles, _scoped) {
2383
2427
  }
2384
2428
  return vue.reactive({
2385
2429
  ...!scoped && {
2386
- $instances,
2387
- $value,
2388
- $silentValue,
2389
- $errors,
2390
- $silentErrors
2430
+ $silentValue
2391
2431
  },
2432
+ $errors,
2433
+ $silentErrors,
2434
+ $instances,
2435
+ $value,
2392
2436
  $dirty,
2393
2437
  $anyDirty,
2394
2438
  $invalid,
@@ -2406,42 +2450,112 @@ function mergeRegles(regles, _scoped) {
2406
2450
  $clearExternalErrors
2407
2451
  });
2408
2452
  }
2409
- function createUseCollectScopedValidations(instances) {
2410
- function useCollectScopedValidations() {
2411
- const r$ = vue.ref(mergeRegles(instances.value, true));
2453
+ function createUseCollectScope(instances) {
2454
+ function useCollectScope(namespace) {
2455
+ const computedNamespace = vue.computed(() => vue.toValue(namespace));
2456
+ setEmptyNamespace();
2457
+ const r$ = vue.ref(collectRegles(instances.value));
2412
2458
  const regle = vue.reactive({ r$ });
2413
- vue.watch(instances, (newInstances) => {
2414
- r$.value = mergeRegles(newInstances, true);
2415
- });
2459
+ function setEmptyNamespace() {
2460
+ if (computedNamespace.value && !instances.value[computedNamespace.value]) {
2461
+ instances.value[computedNamespace.value] = {};
2462
+ }
2463
+ }
2464
+ vue.watch(computedNamespace, setEmptyNamespace);
2465
+ vue.watch(
2466
+ instances,
2467
+ (newInstances) => {
2468
+ r$.value = collectRegles(newInstances);
2469
+ },
2470
+ { deep: true }
2471
+ );
2472
+ function collectRegles(r$Instances) {
2473
+ if (computedNamespace.value) {
2474
+ const namespaceInstances = r$Instances[computedNamespace.value] ?? {};
2475
+ return mergeRegles(namespaceInstances, true);
2476
+ } else {
2477
+ return mergeRegles(r$Instances["~~global"] ?? {}, true);
2478
+ }
2479
+ }
2416
2480
  return { r$: regle.r$ };
2417
2481
  }
2418
- return { useCollectScopedValidations };
2482
+ return { useCollectScope };
2419
2483
  }
2420
- function createUseScopedRegleComposable(customUseRegle) {
2484
+ function createUseScopedRegleComposable(instances, customUseRegle) {
2421
2485
  const scopedUseRegle = customUseRegle ?? useRegle;
2422
- const instances = vue.ref({});
2423
2486
  const useScopedRegle = (state, rulesFactory, options) => {
2424
- const $id = randomId();
2425
- const { r$ } = scopedUseRegle(state, rulesFactory, options);
2426
- instances.value[$id] = r$;
2427
- vue.onScopeDispose(() => {
2428
- delete instances.value[$id];
2487
+ const { namespace, ...restOptions } = options ?? {};
2488
+ const computedNamespace = vue.computed(() => vue.toValue(namespace));
2489
+ const $id = vue.ref(`${Object.keys(instances.value).length + 1}-${randomId()}`);
2490
+ const instanceName = vue.computed(() => {
2491
+ return `instance-${$id.value}`;
2492
+ });
2493
+ const { r$ } = scopedUseRegle(state, rulesFactory, restOptions);
2494
+ register();
2495
+ tryOnScopeDispose(dispose);
2496
+ vue.watch(computedNamespace, (newName, oldName) => {
2497
+ dispose(oldName);
2498
+ register();
2429
2499
  });
2430
- function $dispose() {
2431
- delete instances.value[$id];
2500
+ if (vue.getCurrentInstance()) {
2501
+ vue.onMounted(() => {
2502
+ const currentInstance = vue.getCurrentInstance();
2503
+ if (typeof window !== "undefined" && currentInstance?.proxy?.$el?.parentElement) {
2504
+ if (document.documentElement && !document.documentElement.contains(currentInstance?.proxy?.$el?.parentElement)) {
2505
+ dispose();
2506
+ }
2507
+ }
2508
+ });
2509
+ }
2510
+ function dispose(oldName) {
2511
+ const nameToClean = oldName ?? computedNamespace.value;
2512
+ if (nameToClean) {
2513
+ if (instances.value[nameToClean]) {
2514
+ delete instances.value[nameToClean][instanceName.value];
2515
+ }
2516
+ } else if (instances.value["~~global"][instanceName.value]) {
2517
+ delete instances.value["~~global"][instanceName.value];
2518
+ }
2519
+ }
2520
+ function register() {
2521
+ if (computedNamespace.value) {
2522
+ if (!instances.value[computedNamespace.value]) {
2523
+ instances.value[computedNamespace.value] = {};
2524
+ }
2525
+ instances.value[computedNamespace.value][instanceName.value] = r$;
2526
+ } else {
2527
+ if (!instances.value["~~global"]) {
2528
+ instances.value["~~global"] = {};
2529
+ }
2530
+ instances.value["~~global"][instanceName.value] = r$;
2531
+ }
2432
2532
  }
2433
- return { r$, $dispose };
2533
+ return { r$, dispose, register };
2434
2534
  };
2435
- return { useScopedRegle, instances };
2535
+ return { useScopedRegle };
2436
2536
  }
2437
2537
 
2438
2538
  // src/core/createScopedUseRegle/createScopedUseRegle.ts
2439
- function createScopedUseRegle(customUseRegle) {
2440
- const { instances, useScopedRegle } = createUseScopedRegleComposable(customUseRegle);
2441
- const { useCollectScopedValidations } = createUseCollectScopedValidations(instances);
2539
+ function createScopedUseRegle(options) {
2540
+ const useInstances = options?.customStore ? () => {
2541
+ if (options.customStore) {
2542
+ if (!options.customStore?.value["~~global"]) {
2543
+ options.customStore.value["~~global"] = {};
2544
+ } else if (options.customStore?.value) {
2545
+ options.customStore.value = { "~~global": {} };
2546
+ }
2547
+ }
2548
+ return options.customStore;
2549
+ } : createGlobalState(() => {
2550
+ const $inst = vue.ref({ "~~global": {} });
2551
+ return $inst;
2552
+ });
2553
+ const instances = useInstances();
2554
+ const { useScopedRegle } = createUseScopedRegleComposable(instances, options?.customUseRegle);
2555
+ const { useCollectScope } = createUseCollectScope(instances);
2442
2556
  return {
2443
2557
  useScopedRegle,
2444
- useCollectScopedValidations
2558
+ useCollectScope
2445
2559
  };
2446
2560
  }
2447
2561
 
@@ -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 };