@regle/schemas 1.4.0-beta.2 → 1.4.1-beta.1

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.
@@ -7,6 +7,7 @@ type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
7
7
  type Maybe<T = any> = T | null | undefined;
8
8
  type MaybeInput<T = any> = T | null | undefined;
9
9
  type MaybeOutput<T = any> = T | undefined;
10
+ type NonUndefined<T> = Exclude<T, undefined>;
10
11
  type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
11
12
  type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
12
13
  type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
@@ -330,6 +331,56 @@ const anyA = get(anyObject, 'a');
330
331
  */
331
332
  type IsAny$1<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
332
333
  //#endregion
334
+ //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-equal.d.ts
335
+ /**
336
+ Returns a boolean for whether the two given types are equal.
337
+
338
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
339
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
340
+
341
+ Use-cases:
342
+ - If you want to make a conditional branch based on the result of a comparison of two types.
343
+
344
+ @example
345
+ ```
346
+ import type {IsEqual} from 'type-fest';
347
+
348
+ // This type returns a boolean for whether the given array includes the given item.
349
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
350
+ type Includes<Value extends readonly any[], Item> =
351
+ Value extends readonly [Value[0], ...infer rest]
352
+ ? IsEqual<Value[0], Item> extends true
353
+ ? true
354
+ : Includes<rest, Item>
355
+ : false;
356
+ ```
357
+
358
+ @category Type Guard
359
+ @category Utilities
360
+ */
361
+ type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
362
+ //#endregion
363
+ //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/or.d.ts
364
+ /**
365
+ Returns a boolean for whether either of two given types are true.
366
+
367
+ Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
368
+
369
+ @example
370
+ ```
371
+ import type {Or} from 'type-fest';
372
+
373
+ Or<true, false>;
374
+ //=> true
375
+
376
+ Or<false, false>;
377
+ //=> false
378
+ ```
379
+
380
+ @see {@link And}
381
+ */
382
+ type Or<A extends boolean, B extends boolean> = [A, B][number] extends false ? false : true extends [IsEqual<A, true>, IsEqual<B, true>][number] ? true : never;
383
+ //#endregion
333
384
  //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/keys.d.ts
334
385
  /**
335
386
  Disallows any of the given keys.
@@ -1646,9 +1697,9 @@ type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, No
1646
1697
  //#endregion
1647
1698
  //#region src/types/core/variants.types.d.ts
1648
1699
 
1649
- type MaybeVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState>> extends true ? Omit<RegleStatus<TState, TRules, TShortcuts>, '$fields'> & {
1700
+ type MaybeVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState>> extends true ? Omit<RegleStatus<TState, TRules, TShortcuts>, '$fields' | keyof RegleStatus<TState, TRules, TShortcuts>['$fields']> & {
1650
1701
  $fields: ProcessChildrenFields<TState, TRules, TShortcuts>[keyof ProcessChildrenFields<TState, TRules, TShortcuts>];
1651
- } : RegleStatus<TState, TRules, TShortcuts>;
1702
+ } & (HasNamedKeys<TState> extends true ? ProcessChildrenFields<TState, TRules, TShortcuts>[keyof ProcessChildrenFields<TState, TRules, TShortcuts>] : {}) : RegleStatus<TState, TRules, TShortcuts>;
1652
1703
  type ProcessChildrenFields<TState extends Record<string, any> | undefined, TRules extends ReglePartialRuleTree<NonNullable<TState>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState>[TIndexInt] as IsEmptyObject$1<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1, NonNullable<UnionToTuple<TState>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple<TState>[TIndexInt] as IsEmptyObject$1<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1> extends true ? TKey extends keyof TState ? TState[TKey] extends NonNullable<TState[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState>[TIndexInt] : never, UnionToTuple<TRules>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject$1 : EmptyObject$1, NonNullable<UnionToTuple<TState>[TIndexInt]>, TKey, TShortcuts> } : {} };
1653
1704
  type FindCorrespondingVariant<TState extends Record<string, any>, TRules extends any[]> = TRules extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState> ? [F] : FindCorrespondingVariant<TState, R> : [];
1654
1705
  //#endregion
@@ -1701,7 +1752,7 @@ type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K ex
1701
1752
  /**
1702
1753
  * Combine all union values to be able to get even the normally "never" values, act as an intersection type
1703
1754
  */
1704
- type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonNullable<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
1755
+ type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
1705
1756
  /**
1706
1757
  * Get all possible keys from a union, even the ones present only on one union
1707
1758
  */
@@ -1720,6 +1771,7 @@ type EnumLike = {
1720
1771
  };
1721
1772
  type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
1722
1773
  type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
1774
+ type HasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
1723
1775
  //#endregion
1724
1776
  //#region src/types/utils/mismatch.types.d.ts
1725
1777
  type isDeepExact<TRules, TTree> = { [K in keyof TRules]-?: CheckDeepExact<NonNullable<TRules[K]>, K extends keyof JoinDiscriminatedUnions<TTree> ? NonNullable<JoinDiscriminatedUnions<TTree>[K]> : never> }[keyof TRules] extends true ? true : false;
@@ -1855,6 +1907,7 @@ interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync e
1855
1907
  active?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
1856
1908
  tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
1857
1909
  type?: string;
1910
+ async?: boolean;
1858
1911
  }
1859
1912
  /**
1860
1913
  * @internal
@@ -2011,16 +2064,24 @@ type RegleRoot<TState extends Record<string, any> = {}, TRules extends ReglePart
2011
2064
  */
2012
2065
  $groups: { readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput };
2013
2066
  });
2067
+ type ProcessNestedFields$1<TState extends Record<string, any> | undefined, TRules extends ReglePartialRuleTree<NonNullable<TState>>, TShortcuts extends RegleShortcutDefinition = {}, TIsFields extends boolean = false> = Or<HasNamedKeys<TState>, TIsFields> extends true ? { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject$1<TRules[TKey]> extends true ? TKey : never : never : TKey]: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } & { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject$1<TRules[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } : {};
2014
2068
  /**
2015
2069
  * @public
2016
2070
  */
2017
2071
  type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
2018
2072
  /** Represents all the children of your object. You can access any nested child at any depth to get the relevant data you need for your form. */
2019
- readonly $fields: { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject$1<TRules[TKey]> extends true ? TKey : never : never : TKey]: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } & { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject$1<TRules[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> };
2073
+ readonly $fields: ProcessNestedFields$1<TState, TRules, TShortcuts, true>;
2074
+ /**
2075
+ * Collection of all the issues, collected for all children properties and nested forms.
2076
+ *
2077
+ * Only contains issues from properties where $dirty equals true.
2078
+ */
2079
+ readonly $issues: RegleIssuesTree<TState>;
2020
2080
  /**
2021
2081
  * Collection of all the error messages, collected for all children properties and nested forms.
2022
2082
  *
2023
- * Only contains errors from properties where $dirty equals true. */
2083
+ * Only contains errors from properties where $dirty equals true.
2084
+ * */
2024
2085
  readonly $errors: RegleErrorTree<TState>;
2025
2086
  /** Collection of all the error messages, collected for all children properties. */
2026
2087
  readonly $silentErrors: RegleErrorTree<TState>;
@@ -2028,7 +2089,7 @@ type RegleStatus<TState extends Record<string, any> | undefined = Record<string,
2028
2089
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
2029
2090
  /** 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). */
2030
2091
  $validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, TRules>>;
2031
- } & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
2092
+ } & ProcessNestedFields$1<TState, TRules, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
2032
2093
  /**
2033
2094
  * @internal
2034
2095
  * @reference {@link RegleStatus}
@@ -2043,13 +2104,26 @@ type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl
2043
2104
  * @reference {@link InferRegleStatusType}
2044
2105
  */
2045
2106
 
2046
- interface RegleFieldIssue {
2047
- $property: string;
2048
- $rule: string;
2049
- $type?: string;
2050
- $message: string;
2051
- [x: string]: unknown;
2052
- }
2107
+ type RegleFieldIssue<TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = EmptyObject$1> = {
2108
+ readonly $property: string;
2109
+ readonly $type?: string;
2110
+ readonly $message: string;
2111
+ } & (IsEmptyObject$1<TRules> extends true ? {
2112
+ readonly $rule: string;
2113
+ } : { [K in keyof ComputeFieldRules<any, TRules>]: ComputeFieldRules<any, TRules>[K] extends {
2114
+ $metadata: infer TMetadata;
2115
+ } ? K extends string ? {
2116
+ readonly $rule: K;
2117
+ } & (TMetadata extends boolean ? {
2118
+ readonly $rule: string;
2119
+ } : TMetadata) : {
2120
+ readonly $rule: string;
2121
+ } : {
2122
+ readonly $rule: string;
2123
+ } }[keyof ComputeFieldRules<any, TRules>]);
2124
+ type ComputeFieldRules<TState extends any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>>> = IsEmptyObject$1<TRules> extends true ? {
2125
+ readonly [x: string]: RegleRuleStatus<TState, any[], any>;
2126
+ } : { readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : boolean> };
2053
2127
  /**
2054
2128
  * @public
2055
2129
  */
@@ -2065,13 +2139,13 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
2065
2139
  /** Collection of all the error messages, collected for all children properties and nested forms. */
2066
2140
  readonly $silentErrors: string[];
2067
2141
  /**
2068
- * Collect all metadata of validators, Only contains errors from properties where $dirty equals true.
2142
+ * Collect all metadata of validators, Only contains metadata from properties where $dirty equals true.
2069
2143
  */
2070
- readonly $issues: RegleFieldIssue[];
2144
+ readonly $issues: RegleFieldIssue<TRules>[];
2071
2145
  /**
2072
2146
  * Collect all metadata of validators, including the error message.
2073
2147
  */
2074
- readonly $silentIssues: RegleFieldIssue[];
2148
+ readonly $silentIssues: RegleFieldIssue<TRules>[];
2075
2149
  /** Stores external errors of the current field */
2076
2150
  readonly $externalErrors: string[];
2077
2151
  /** Stores active tooltips messages of the current field */
@@ -2083,9 +2157,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
2083
2157
  /** 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). */
2084
2158
  $validate: () => Promise<RegleResult<TState, TRules>>;
2085
2159
  /** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
2086
- readonly $rules: IsEmptyObject$1<TRules> extends true ? {
2087
- readonly [x: string]: RegleRuleStatus<TState, any[], any>;
2088
- } : { readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : boolean> };
2160
+ readonly $rules: ComputeFieldRules<TState, TRules>;
2089
2161
  } & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
2090
2162
  /**
2091
2163
  * @internal
@@ -2126,6 +2198,8 @@ interface RegleCommonStatus<TValue = any> {
2126
2198
  readonly $ready: boolean;
2127
2199
  /** Return the current key name of the field. */
2128
2200
  readonly $name: string;
2201
+ /** Returns the current path of the rule (used internally for tracking) */
2202
+ readonly $path: string;
2129
2203
  /** Id used to track collections items */
2130
2204
  $id?: string;
2131
2205
  /** A reference to the original validated model. It can be used to bind your form with v-model.*/
@@ -2216,6 +2290,12 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
2216
2290
  readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
2217
2291
  /** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
2218
2292
  readonly $self: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
2293
+ /**
2294
+ * Collection of all the issues, collected for all children properties and nested forms.
2295
+ *
2296
+ * Only contains issues from properties where $dirty equals true.
2297
+ */
2298
+ readonly $issues: RegleCollectionErrors<TState, true>;
2219
2299
  /** Collection of all the error messages, collected for all children properties and nested forms.
2220
2300
  *
2221
2301
  * Only contains errors from properties where $dirty equals true. */
@@ -2234,15 +2314,16 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
2234
2314
 
2235
2315
  //#endregion
2236
2316
  //#region src/types/rules/rule.errors.types.d.ts
2237
- type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false> };
2317
+ type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>, TIssue extends boolean = false> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false, TIssue> };
2318
+ type RegleIssuesTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false, true> };
2238
2319
  type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true> };
2239
- type RegleValidationErrors<TState extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false, TIssue extends boolean = false> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TExternal extends false ? RegleCollectionErrors<U> : RegleExternalCollectionErrors<U> : TIssue extends true ? RegleFieldIssue[] : string[] : NonNullable<TState> extends Date | File ? TIssue extends true ? RegleFieldIssue[] : string[] : NonNullable<TState> extends Record<string, any> ? TExternal extends false ? RegleErrorTree<TState> : RegleExternalErrorTree<TState> : TIssue extends true ? RegleFieldIssue[] : string[];
2320
+ type RegleValidationErrors<TState extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false, TIssue extends boolean = false> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TExternal extends false ? RegleCollectionErrors<U, TIssue> : RegleExternalCollectionErrors<U, TIssue> : TIssue extends true ? RegleFieldIssue[] : string[] : NonNullable<TState> extends Date | File ? TIssue extends true ? RegleFieldIssue[] : string[] : NonNullable<TState> extends Record<string, any> ? TExternal extends false ? RegleErrorTree<TState, TIssue> : RegleExternalErrorTree<TState> : TIssue extends true ? RegleFieldIssue[] : string[];
2240
2321
  type RegleCollectionErrors<TState extends Record<string, any>, TIssue extends boolean = false> = {
2241
- readonly $self: string[];
2322
+ readonly $self: TIssue extends true ? RegleFieldIssue[] : string[];
2242
2323
  readonly $each: RegleValidationErrors<TState, false, TIssue>[];
2243
2324
  };
2244
2325
  type RegleExternalCollectionErrors<TState extends Record<string, any>, TIssue extends boolean = false> = {
2245
- readonly $self?: string[];
2326
+ readonly $self?: TIssue extends true ? RegleFieldIssue[] : string[];
2246
2327
  readonly $each?: RegleValidationErrors<TState, true, TIssue>[];
2247
2328
  };
2248
2329
  /** @internal */
@@ -2255,17 +2336,16 @@ type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
2255
2336
  $validate: () => Promise<SuperCompatibleRegleResult>;
2256
2337
  };
2257
2338
  type SuperCompatibleRegleResult = $InternalRegleResult;
2258
- interface SuperCompatibleRegleStatus extends SuperCompatibleRegleCommonStatus {
2259
- $fields: {
2260
- [x: string]: unknown;
2339
+ type SuperCompatibleRegleStatus = {
2340
+ readonly $fields: {
2341
+ [x: string]: any;
2261
2342
  };
2343
+ readonly $issues: Record<string, RegleValidationErrors<any, false, true>>;
2262
2344
  readonly $errors: Record<string, RegleValidationErrors<any, false>>;
2263
2345
  readonly $silentErrors: Record<string, RegleValidationErrors<any, false>>;
2264
2346
  $extractDirtyFields: (filterNullishValues?: boolean) => Record<string, any>;
2265
2347
  $validate?: () => Promise<SuperCompatibleRegleResult>;
2266
- }
2267
- type SuperCompatibleRegleCommonStatus = Omit<RegleCommonStatus, '$pending'> & {
2268
- $pending?: boolean;
2348
+ [x: string]: any;
2269
2349
  };
2270
2350
  //#endregion
2271
2351
  //#region src/core/mergeRegles.d.ts
@@ -2316,7 +2396,7 @@ type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>
2316
2396
  //#endregion
2317
2397
  //#region src/core/createScopedUseRegle/useCollectScope.d.ts
2318
2398
  type useCollectScopeFn<TNamedScoped extends boolean = false> = TNamedScoped extends true ? <const TValue extends Record<string, Record<string, any>>>(namespace?: MaybeRefOrGetter<string>) => {
2319
- r$: MergedRegles<{ [K in keyof TValue]: RegleRoot<TValue[K]> }>;
2399
+ r$: MergedRegles<{ [K in keyof TValue]: RegleRoot<TValue[K]> & SuperCompatibleRegleRoot }>;
2320
2400
  } : <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
2321
2401
  r$: MergedScopedRegles<TValue>;
2322
2402
  };
@@ -3084,12 +3164,17 @@ type RegleSchemaResult<TSchema extends unknown> = {
3084
3164
  valid: true;
3085
3165
  data: TSchema;
3086
3166
  };
3167
+ type ProcessNestedFields<TState extends Record<string, any>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition> = HasNamedKeys<TState> extends true ? { readonly [TKey in keyof JoinDiscriminatedUnions<TState>]: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never } & { readonly [TKey in keyof JoinDiscriminatedUnions<TState> as TKey extends keyof JoinDiscriminatedUnions<TSchema> ? JoinDiscriminatedUnions<TSchema>[TKey] extends NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never } : {};
3087
3168
  /**
3088
3169
  * @public
3089
3170
  */
3090
3171
  type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>, TSchema extends Record<string, any> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit<RegleCommonStatus<TState>, IsRoot extends false ? '$pending' : ''> & {
3091
3172
  /** Represents all the children of your object. You can access any nested child at any depth to get the relevant data you need for your form. */
3092
- readonly $fields: { readonly [TKey in keyof JoinDiscriminatedUnions<TState>]: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never } & { readonly [TKey in keyof JoinDiscriminatedUnions<TState> as TKey extends keyof JoinDiscriminatedUnions<TSchema> ? JoinDiscriminatedUnions<TSchema>[TKey] extends NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never };
3173
+ readonly $fields: ProcessNestedFields<TState, TSchema, TShortcuts>;
3174
+ /** Collection of all issues, collected for all children properties and nested forms.
3175
+ *
3176
+ * Only contains errors from properties where $dirty equals true. */
3177
+ readonly $issues: RegleIssuesTree<TState>;
3093
3178
  /** Collection of all the error messages, collected for all children properties and nested forms.
3094
3179
  *
3095
3180
  * Only contains errors from properties where $dirty equals true. */
@@ -3098,7 +3183,7 @@ type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>,
3098
3183
  readonly $silentErrors: RegleErrorTree<TState>;
3099
3184
  /** 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). */
3100
3185
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
3101
- } & (IsRoot extends true ? {
3186
+ } & ProcessNestedFields<TState, TSchema, TShortcuts> & (IsRoot extends true ? {
3102
3187
  /** 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). */
3103
3188
  $validate: () => Promise<RegleSchemaResult<TSchema>>;
3104
3189
  } : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
@@ -3110,6 +3195,12 @@ type InferRegleSchemaStatusType<TSchema extends unknown, TState extends unknown,
3110
3195
  * @public
3111
3196
  */
3112
3197
  type RegleSchemaFieldStatus<TSchema extends unknown, TState = any, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$pending'> & {
3198
+ /** Collection of all the error messages, collected for all children properties and nested forms.
3199
+ *
3200
+ * Only contains errors from properties where $dirty equals true. */
3201
+ readonly $errors: string[];
3202
+ /** Collection of all the error messages, collected for all children properties and nested forms. */
3203
+ readonly $silentErrors: string[];
3113
3204
  /**
3114
3205
  * Collect all metadata of validators, Only contains errors from properties where $dirty equals true.
3115
3206
  */
@@ -3118,12 +3209,6 @@ type RegleSchemaFieldStatus<TSchema extends unknown, TState = any, TShortcuts ex
3118
3209
  * Collect all metadata of validators, including the error message.
3119
3210
  */
3120
3211
  readonly $silentIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
3121
- /** Collection of all the error messages, collected for all children properties and nested forms.
3122
- *
3123
- * Only contains errors from properties where $dirty equals true. */
3124
- readonly $errors: string[];
3125
- /** Collection of all the error messages, collected for all children properties and nested forms. */
3126
- readonly $silentErrors: string[];
3127
3212
  /** 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). */
3128
3213
  readonly $externalErrors?: string[];
3129
3214
  /** Represents the inactive status. Is true when this state have empty rules */
@@ -3143,6 +3228,12 @@ type RegleSchemaCollectionStatus<TSchema extends Record<string, any>, TState ext
3143
3228
  readonly $each: Array<InferRegleSchemaStatusType<NonNullable<TSchema>, ArrayElement<TState>, TShortcuts>>;
3144
3229
  /** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
3145
3230
  readonly $self: RegleSchemaFieldStatus<TSchema, TState, TShortcuts>;
3231
+ /**
3232
+ * Collection of all the issues, collected for all children properties and nested forms.
3233
+ *
3234
+ * Only contains issues from properties where $dirty equals true.
3235
+ */
3236
+ readonly $issues: RegleCollectionErrors<TSchema, true>;
3146
3237
  /** Collection of all the error messages, collected for all children properties and nested forms.
3147
3238
  *
3148
3239
  * Only contains errors from properties where $dirty equals true. */
@@ -3173,9 +3264,9 @@ type RegleSchemaBehaviourOptions = {
3173
3264
  //#region src/core/useRegleSchema.d.ts
3174
3265
  type useRegleSchemaFnOptions<TAdditionalOptions extends Record<string, any>> = Omit<Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, {}, never>, 'validationGroups' | 'lazy' | 'rewardEarly' | 'silent'> & RegleSchemaBehaviourOptions & TAdditionalOptions;
3175
3266
  interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
3176
- <TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<TState, {
3267
+ <TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<NoInferLegacy<TState>, {
3177
3268
  recurseIntoArrays: true;
3178
- }>> | DeepReactiveState<PartialDeep<TState, {
3269
+ }>> | DeepReactiveState<PartialDeep<NoInferLegacy<TState>, {
3179
3270
  recurseIntoArrays: true;
3180
3271
  }>>, rulesFactory: MaybeRef<TSchema>, ...(HaveAnyRequiredProps<useRegleSchemaFnOptions<TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions<TAdditionalOptions>] : [options?: useRegleSchemaFnOptions<TAdditionalOptions>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleFieldSchema<NonNullable<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts, TAdditionalReturnProperties> : RegleSchema<UnwrapNestedRefs<NonNullable<TState>>, UnwrapNestedRefs<NonNullable<StandardSchemaV1.InferInput<TSchema>>>, TShortcuts, TAdditionalReturnProperties>;
3181
3272
  }
@@ -132,22 +132,23 @@ function createUseRegleSchemaComposable(options, shortcuts) {
132
132
  const output = {};
133
133
  if (result.issues) {
134
134
  const issues = result.issues.map((issue) => {
135
- let path = issue.path?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
135
+ let $path = issue.path?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
136
136
  const lastItem = issue.path?.[issue.path.length - 1];
137
- const isArray = (typeof lastItem === "object" && "value" in lastItem ? Array.isArray(lastItem.value) : false) || ("type" in issue ? issue.type === "array" : false) || Array.isArray(getDotPath(processedState.value, path));
138
- const isPrimitivesArray = !isArray && typeof (typeof lastItem === "object" ? lastItem.key : lastItem) === "number";
139
- if (isPrimitivesArray) path = issue.path?.slice(0, issue.path.length - 1)?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
137
+ const lastItemKey = typeof lastItem === "object" ? lastItem.key : lastItem;
138
+ const isArray = (typeof lastItem === "object" && "value" in lastItem ? Array.isArray(lastItem.value) : false) || ("type" in issue ? issue.type === "array" : false) || Array.isArray(getDotPath(processedState.value, $path));
139
+ const isPrimitivesArray = !isArray && typeof lastItemKey === "number";
140
+ if (isPrimitivesArray) $path = issue.path?.slice(0, issue.path.length - 1)?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
140
141
  return {
141
142
  ...issue,
142
- path,
143
+ $path,
143
144
  isArray,
144
- $property: lastItem,
145
+ $property: lastItemKey,
145
146
  $rule: "schema",
146
147
  $message: issue.message
147
148
  };
148
149
  });
149
- issues.forEach(({ isArray, path,...issue }) => {
150
- setObjectError(output, path, [issue], isArray);
150
+ issues.forEach(({ isArray, $path,...issue }) => {
151
+ setObjectError(output, $path, [issue], isArray);
151
152
  });
152
153
  }
153
154
  return output;
@@ -1 +1 @@
1
- import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";const s=Symbol(`regle-rule`);function c(e){if(typeof e.source.flags==`string`)return e.source.flags;{let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}}function l(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>l(e)))),n==`Map`&&(t=new Map([...e].map(e=>[l(e[0]),l(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,c(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=l(e[n]);return t}function u(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function d(e,t,n,r){var i,a;if(Array.isArray(t)&&(i=t.slice(0)),typeof t==`string`&&(i=t.split(`.`)),typeof t==`symbol`&&(i=[t]),!Array.isArray(i))throw Error(`props arg must be an array, a string or a symbol`);if(a=i.pop(),!a)return!1;p(a);for(var o;o=i.shift();)if(p(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):((e.$each??=[])[o]={},e=e.$each[o]),!e||typeof e!=`object`)return!1;return r?e[a]?e[a].$self=(e[a].$self??=[]).concat(n):e[a]={...e[a],$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function f(e,t,n){if(!e)return n;var r,i;if(Array.isArray(t)&&(r=t.slice(0)),typeof t==`string`&&(r=t.split(`.`)),typeof t==`symbol`&&(r=[t]),!Array.isArray(r))throw Error(`props arg must be an array, a string or a symbol`);for(;r.length;)if(i=r.shift(),!e||!i||(e=e[i],e===void 0))return n;return e}function p(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function m(e,...t){for(var n=[].slice.call(arguments),r,i=n.length;r=n[i-1],i--;)if(!r||typeof r!=`object`&&typeof r!=`function`)throw Error(`expected object, got `+r);for(var a=n[0],o=n.slice(1),s=o.length,i=0;i<s;i++){var c=o[i];for(var l in c)a[l]=c[l]}return a}function h(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function p(e,p,h){let g=n(()=>a(p)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=h??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!u(C.value)),C=r(e)?e:i(e),w=i(u(C.value)?{...l(C.value)}:l(C.value)),T=i({}),E;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function D(e){let t={};if(e.issues){let n=e.issues.map(e=>{let t=e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``,n=e.path?.[e.path.length-1],r=(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(f(C.value,t)),i=!r&&typeof(typeof n==`object`?n.key:n)==`number`;return i&&(t=e.path?.slice(0,e.path.length-1)?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``),{...e,path:t,isArray:r,$property:n,$rule:`schema`,$message:e.message}});n.forEach(({isArray:e,path:n,...r})=>{d(t,n,[r],e)})}return t}async function O(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?T.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:T.value=D(t),t.issues||(e&&b||!e&&y)&&(k?.(),u(C.value)?C.value=m(C.value,t.value):C.value=t.value,A()),t}let k;function A(){k=o([C,g],()=>O(),{deep:!0})}A(),O(),E=async()=>{try{let e=await O(!0);return{valid:!e.issues?.length,data:C.value}}catch(e){return Promise.reject(e)}};let j=t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:T,initialState:w,shortcuts:s,schemaMode:!0,onValidate:E});return{r$:j.regle}}return p}const g=h();function _(e,t){return e}function v(){function e(e,t){return t}return e}const y=v();function b({modifiers:e,shortcuts:t}){let n=h(e,t),r=v();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:x,useScopedRegle:S}=e({customUseRegle:g}),C=t=>{let{customStore:n,customUseRegle:r=g,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{C as createScopedUseRegleSchema,b as defineRegleSchemaConfig,y as inferSchema,x as useCollectSchemaScope,g as useRegleSchema,S as useScopedRegleSchema,_ as withDeps};
1
+ import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";const s=Symbol(`regle-rule`);function c(e){if(typeof e.source.flags==`string`)return e.source.flags;{let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}}function l(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>l(e)))),n==`Map`&&(t=new Map([...e].map(e=>[l(e[0]),l(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,c(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=l(e[n]);return t}function u(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function d(e,t,n,r){var i,a;if(Array.isArray(t)&&(i=t.slice(0)),typeof t==`string`&&(i=t.split(`.`)),typeof t==`symbol`&&(i=[t]),!Array.isArray(i))throw Error(`props arg must be an array, a string or a symbol`);if(a=i.pop(),!a)return!1;p(a);for(var o;o=i.shift();)if(p(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):((e.$each??=[])[o]={},e=e.$each[o]),!e||typeof e!=`object`)return!1;return r?e[a]?e[a].$self=(e[a].$self??=[]).concat(n):e[a]={...e[a],$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function f(e,t,n){if(!e)return n;var r,i;if(Array.isArray(t)&&(r=t.slice(0)),typeof t==`string`&&(r=t.split(`.`)),typeof t==`symbol`&&(r=[t]),!Array.isArray(r))throw Error(`props arg must be an array, a string or a symbol`);for(;r.length;)if(i=r.shift(),!e||!i||(e=e[i],e===void 0))return n;return e}function p(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function m(e,...t){for(var n=[].slice.call(arguments),r,i=n.length;r=n[i-1],i--;)if(!r||typeof r!=`object`&&typeof r!=`function`)throw Error(`expected object, got `+r);for(var a=n[0],o=n.slice(1),s=o.length,i=0;i<s;i++){var c=o[i];for(var l in c)a[l]=c[l]}return a}function h(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function p(e,p,h){let g=n(()=>a(p)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=h??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!u(C.value)),C=r(e)?e:i(e),w=i(u(C.value)?{...l(C.value)}:l(C.value)),T=i({}),E;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function D(e){let t={};if(e.issues){let n=e.issues.map(e=>{let t=e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``,n=e.path?.[e.path.length-1],r=typeof n==`object`?n.key:n,i=(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(f(C.value,t)),a=!i&&typeof r==`number`;return a&&(t=e.path?.slice(0,e.path.length-1)?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``),{...e,$path:t,isArray:i,$property:r,$rule:`schema`,$message:e.message}});n.forEach(({isArray:e,$path:n,...r})=>{d(t,n,[r],e)})}return t}async function O(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?T.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:T.value=D(t),t.issues||(e&&b||!e&&y)&&(k?.(),u(C.value)?C.value=m(C.value,t.value):C.value=t.value,A()),t}let k;function A(){k=o([C,g],()=>O(),{deep:!0})}A(),O(),E=async()=>{try{let e=await O(!0);return{valid:!e.issues?.length,data:C.value}}catch(e){return Promise.reject(e)}};let j=t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:T,initialState:w,shortcuts:s,schemaMode:!0,onValidate:E});return{r$:j.regle}}return p}const g=h();function _(e,t){return e}function v(){function e(e,t){return t}return e}const y=v();function b({modifiers:e,shortcuts:t}){let n=h(e,t),r=v();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:x,useScopedRegle:S}=e({customUseRegle:g}),C=t=>{let{customStore:n,customUseRegle:r=g,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{C as createScopedUseRegleSchema,b as defineRegleSchemaConfig,y as inferSchema,x as useCollectSchemaScope,g as useRegleSchema,S as useScopedRegleSchema,_ as withDeps};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.4.0-beta.2",
3
+ "version": "1.4.1-beta.1",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/core": "1.4.0-beta.2",
8
- "@regle/rules": "1.4.0-beta.2"
7
+ "@regle/core": "1.4.1-beta.1",
8
+ "@regle/rules": "1.4.1-beta.1"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",
@@ -33,7 +33,7 @@
33
33
  "eslint-config-prettier": "10.1.5",
34
34
  "eslint-plugin-vue": "10.1.0",
35
35
  "prettier": "3.5.3",
36
- "tsdown": "0.12.7",
36
+ "tsdown": "0.12.8",
37
37
  "type-fest": "4.41.0",
38
38
  "typescript": "5.8.3",
39
39
  "valibot": "1.1.0",