@regle/core 0.7.4-beta.3 → 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.
@@ -444,6 +444,25 @@ function randomId() {
444
444
  return uint32.toString(10);
445
445
  }
446
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
+ }
447
466
 
448
467
  // src/core/useRegle/guards/ruleDef.guards.ts
449
468
  function isNestedRulesDef(state, rules) {
@@ -476,7 +495,7 @@ function extractRulesErrors({
476
495
  silent = false
477
496
  }) {
478
497
  return Object.entries(field.$rules ?? {}).map(([_, rule]) => {
479
- if (silent) {
498
+ if (silent && !rule.$valid) {
480
499
  return rule.$message;
481
500
  } else if (!rule.$valid && field.$error && !rule.$validating) {
482
501
  return rule.$message;
@@ -876,20 +895,20 @@ function createReactiveFieldStatus({
876
895
  const $errors = vue.computed(() => {
877
896
  return extractRulesErrors({
878
897
  field: {
898
+ $rules: $rules.value,
879
899
  $error: $error.value,
880
900
  $externalErrors: externalErrors?.value,
881
- $schemaErrors: schemaErrors?.value,
882
- $rules: $rules.value
901
+ $schemaErrors: schemaErrors?.value
883
902
  }
884
903
  });
885
904
  });
886
905
  const $silentErrors = vue.computed(() => {
887
906
  return extractRulesErrors({
888
907
  field: {
889
- $error: true,
908
+ $rules: $rules.value,
909
+ $error: $error.value,
890
910
  $externalErrors: externalErrors?.value,
891
- $schemaErrors: schemaErrors?.value,
892
- $rules: $rules.value
911
+ $schemaErrors: schemaErrors?.value
893
912
  },
894
913
  silent: true
895
914
  });
@@ -2258,10 +2277,18 @@ function defineRegleConfig({
2258
2277
  function mergeRegles(regles, _scoped) {
2259
2278
  const scoped = _scoped == null ? false : _scoped;
2260
2279
  const $value = vue.computed({
2261
- 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
+ },
2262
2287
  set: (value) => {
2263
- if (typeof value === "object") {
2264
- 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
+ }
2265
2292
  }
2266
2293
  }
2267
2294
  });
@@ -2274,7 +2301,8 @@ function mergeRegles(regles, _scoped) {
2274
2301
  }
2275
2302
  });
2276
2303
  const $dirty = vue.computed(() => {
2277
- return Object.entries(regles).every(([_, regle]) => {
2304
+ const entries = Object.entries(regles);
2305
+ return !!entries.length && entries.every(([_, regle]) => {
2278
2306
  return regle?.$dirty;
2279
2307
  });
2280
2308
  });
@@ -2289,8 +2317,9 @@ function mergeRegles(regles, _scoped) {
2289
2317
  });
2290
2318
  });
2291
2319
  const $valid = vue.computed(() => {
2292
- return Object.entries(regles).every(([_, regle]) => {
2293
- return regle?.$invalid;
2320
+ const entries = Object.entries(regles);
2321
+ return !!entries.length && entries.every(([_, regle]) => {
2322
+ return regle?.$valid;
2294
2323
  });
2295
2324
  });
2296
2325
  const $error = vue.computed(() => {
@@ -2299,7 +2328,8 @@ function mergeRegles(regles, _scoped) {
2299
2328
  });
2300
2329
  });
2301
2330
  const $ready = vue.computed(() => {
2302
- return Object.entries(regles).every(([_, regle]) => {
2331
+ const entries = Object.entries(regles);
2332
+ return !!entries.length && entries.every(([_, regle]) => {
2303
2333
  return regle?.$ready;
2304
2334
  });
2305
2335
  });
@@ -2309,21 +2339,34 @@ function mergeRegles(regles, _scoped) {
2309
2339
  });
2310
2340
  });
2311
2341
  const $errors = vue.computed(() => {
2312
- return Object.fromEntries(
2313
- Object.entries(regles).map(([key, regle]) => {
2314
- return [key, regle.$errors];
2315
- })
2316
- );
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
+ }
2317
2353
  });
2318
2354
  const $silentErrors = vue.computed(() => {
2319
- return Object.fromEntries(
2320
- Object.entries(regles).map(([key, regle]) => {
2321
- return [key, regle.$silentErrors];
2322
- })
2323
- );
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
+ }
2324
2366
  });
2325
2367
  const $edited = vue.computed(() => {
2326
- return Object.entries(regles).every(([_, regle]) => {
2368
+ const entries = Object.entries(regles);
2369
+ return !!entries.length && entries.every(([_, regle]) => {
2327
2370
  return regle?.$edited;
2328
2371
  });
2329
2372
  });
@@ -2333,7 +2376,11 @@ function mergeRegles(regles, _scoped) {
2333
2376
  });
2334
2377
  });
2335
2378
  const $instances = vue.computed(() => {
2336
- return regles;
2379
+ if (scoped) {
2380
+ return Object.values(regles);
2381
+ } else {
2382
+ return regles;
2383
+ }
2337
2384
  });
2338
2385
  function $reset() {
2339
2386
  Object.values(regles).forEach((regle) => {
@@ -2380,12 +2427,12 @@ function mergeRegles(regles, _scoped) {
2380
2427
  }
2381
2428
  return vue.reactive({
2382
2429
  ...!scoped && {
2383
- $instances,
2384
- $value,
2385
- $silentValue,
2386
- $errors,
2387
- $silentErrors
2430
+ $silentValue
2388
2431
  },
2432
+ $errors,
2433
+ $silentErrors,
2434
+ $instances,
2435
+ $value,
2389
2436
  $dirty,
2390
2437
  $anyDirty,
2391
2438
  $invalid,
@@ -2403,42 +2450,112 @@ function mergeRegles(regles, _scoped) {
2403
2450
  $clearExternalErrors
2404
2451
  });
2405
2452
  }
2406
- function createUseCollectScopedValidations(instances) {
2407
- function useCollectScopedValidations() {
2408
- 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));
2409
2458
  const regle = vue.reactive({ r$ });
2410
- vue.watch(instances, (newInstances) => {
2411
- r$.value = mergeRegles(newInstances, true);
2412
- });
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
+ }
2413
2480
  return { r$: regle.r$ };
2414
2481
  }
2415
- return { useCollectScopedValidations };
2482
+ return { useCollectScope };
2416
2483
  }
2417
- function createUseScopedRegleComposable(customUseRegle) {
2484
+ function createUseScopedRegleComposable(instances, customUseRegle) {
2418
2485
  const scopedUseRegle = customUseRegle ?? useRegle;
2419
- const instances = vue.ref({});
2420
2486
  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];
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();
2426
2499
  });
2427
- function $dispose() {
2428
- 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
+ }
2429
2532
  }
2430
- return { r$, $dispose };
2533
+ return { r$, dispose, register };
2431
2534
  };
2432
- return { useScopedRegle, instances };
2535
+ return { useScopedRegle };
2433
2536
  }
2434
2537
 
2435
2538
  // src/core/createScopedUseRegle/createScopedUseRegle.ts
2436
- function createScopedUseRegle(customUseRegle) {
2437
- const { instances, useScopedRegle } = createUseScopedRegleComposable(customUseRegle);
2438
- 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);
2439
2556
  return {
2440
2557
  useScopedRegle,
2441
- useCollectScopedValidations
2558
+ useCollectScope
2442
2559
  };
2443
2560
  }
2444
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 };