@regle/schemas 1.9.0 → 1.9.2

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.
@@ -1238,7 +1238,7 @@ type CollectionRegleBehaviourOptions = FieldRegleBehaviourOptions & {
1238
1238
  $deepCompare?: boolean;
1239
1239
  };
1240
1240
  type ShortcutCommonFn<T extends Record<string, any>> = {
1241
- [x: string]: (element: OmitByType<T, Function>) => unknown;
1241
+ [x: string]: (element: Omit<OmitByType<T, Function>, '~standard'>) => unknown;
1242
1242
  };
1243
1243
  type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
1244
1244
  /**
@@ -1319,8 +1319,17 @@ type ResetOptions<TState extends unknown> = RequireOneOrNone<{
1319
1319
  toState?: TState | (() => TState);
1320
1320
  /**
1321
1321
  * Clears the $externalErrors state back to an empty object.
1322
+ *
1323
+ * @default false
1322
1324
  */
1323
1325
  clearExternalErrors?: boolean;
1326
+ /**
1327
+ * Keep the validation state of the form ($dirty, $invalid, $pending etc..)
1328
+ * Only useful if you only want to reset the form state.
1329
+ *
1330
+ * @default false
1331
+ */
1332
+ keepValidationState?: boolean;
1324
1333
  }, 'toInitialState' | 'toState'>;
1325
1334
  //#endregion
1326
1335
  //#region src/types/core/scopedRegle.types.d.ts
@@ -1338,6 +1347,28 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules exte
1338
1347
  valid: true;
1339
1348
  data: IsUnknown<Data> extends true ? unknown : IsAny$1<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules> : SafeFieldProperty<Data, TRules> : unknown;
1340
1349
  };
1350
+ type RegleNestedResult<Data extends Record<string, any> | unknown, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
1351
+ valid: false;
1352
+ issues: RegleIssuesTree<Data>;
1353
+ errors: RegleErrorTree<Data>;
1354
+ } | {
1355
+ valid: true;
1356
+ issues: EmptyObject$1;
1357
+ errors: EmptyObject$1;
1358
+ });
1359
+ type RegleCollectionResult<Data extends any[], TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
1360
+ valid: false;
1361
+ issues: RegleCollectionErrors<Data, true>;
1362
+ errors: RegleCollectionErrors<Data>;
1363
+ } | {
1364
+ valid: true;
1365
+ issues: EmptyObject$1;
1366
+ errors: EmptyObject$1;
1367
+ });
1368
+ type RegleFieldResult<Data extends any, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & {
1369
+ issues: RegleFieldIssue<TRules>[];
1370
+ errors: string[];
1371
+ };
1341
1372
  /**
1342
1373
  * Infer safe output from any `r$` instance
1343
1374
  *
@@ -1349,6 +1380,8 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules exte
1349
1380
  type $InternalRegleResult = {
1350
1381
  valid: boolean;
1351
1382
  data: any;
1383
+ errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
1384
+ issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
1352
1385
  };
1353
1386
  type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState[K], TRules[K]> } & { [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState[K], TRules[K]> ? unknown : NonNullable<SafeProperty<TState[K], TRules[K]>> }> : TState;
1354
1387
  type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends MaybeRef<RegleRuleDecl<any, any>> ? [unknown] extends UnwrapRef<TRule>['required'] ? NonNullable<UnwrapRef<TRule>['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<UnwrapRef<TRule>['required']> extends UnwrapRef<TRule>['required'] ? UnwrapRef<TRule>['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
@@ -1434,6 +1467,72 @@ interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortc
1434
1467
  * Docs: {@link https://reglejs.dev/core-concepts/}
1435
1468
  */
1436
1469
 
1470
+ //#endregion
1471
+ //#region ../../node_modules/.pnpm/@standard-schema+spec@1.0.0/node_modules/@standard-schema/spec/dist/index.d.ts
1472
+ /** The Standard Schema interface. */
1473
+ interface StandardSchemaV1$1<Input = unknown, Output = Input> {
1474
+ /** The Standard Schema properties. */
1475
+ readonly "~standard": StandardSchemaV1$1.Props<Input, Output>;
1476
+ }
1477
+ declare namespace StandardSchemaV1$1 {
1478
+ /** The Standard Schema properties interface. */
1479
+ export interface Props<Input = unknown, Output = Input> {
1480
+ /** The version number of the standard. */
1481
+ readonly version: 1;
1482
+ /** The vendor name of the schema library. */
1483
+ readonly vendor: string;
1484
+ /** Validates unknown input values. */
1485
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
1486
+ /** Inferred types associated with the schema. */
1487
+ readonly types?: Types<Input, Output> | undefined;
1488
+ }
1489
+ /** The result interface of the validate function. */
1490
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
1491
+ /** The result interface if validation succeeds. */
1492
+ export interface SuccessResult<Output> {
1493
+ /** The typed output value. */
1494
+ readonly value: Output;
1495
+ /** The non-existent issues. */
1496
+ readonly issues?: undefined;
1497
+ }
1498
+ /** The result interface if validation fails. */
1499
+ export interface FailureResult {
1500
+ /** The issues of failed validation. */
1501
+ readonly issues: ReadonlyArray<Issue>;
1502
+ }
1503
+ /** The issue interface of the failure output. */
1504
+ export interface Issue {
1505
+ /** The error message of the issue. */
1506
+ readonly message: string;
1507
+ /** The path of the issue, if any. */
1508
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
1509
+ }
1510
+ /** The path segment interface of the issue. */
1511
+ export interface PathSegment {
1512
+ /** The key representing a path segment. */
1513
+ readonly key: PropertyKey;
1514
+ }
1515
+ /** The Standard Schema types interface. */
1516
+ export interface Types<Input = unknown, Output = Input> {
1517
+ /** The input type of the schema. */
1518
+ readonly input: Input;
1519
+ /** The output type of the schema. */
1520
+ readonly output: Output;
1521
+ }
1522
+ /** Infers the input type of a Standard Schema. */
1523
+ export type InferInput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["input"];
1524
+ /** Infers the output type of a Standard Schema. */
1525
+ export type InferOutput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["output"];
1526
+ export {};
1527
+ }
1528
+ //#endregion
1529
+ //#region src/core/useRegle/useErrors.d.ts
1530
+ /**
1531
+ * Converts a nested $errors object to a flat array of string errors
1532
+ *
1533
+ * Can also flatten to an array containing the path of each error with the options.includePath
1534
+ */
1535
+
1437
1536
  //#endregion
1438
1537
  //#region src/types/utils/mismatch.types.d.ts
1439
1538
  /**
@@ -1781,7 +1880,7 @@ type RegleStatus<TState extends Record<string, any> | undefined = Record<string,
1781
1880
  /** 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). */
1782
1881
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
1783
1882
  /** 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). */
1784
- $validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, TRules>>;
1883
+ $validate: (forceValues?: JoinDiscriminatedUnions<TState> extends EmptyObject$1 ? any : HasNamedKeys<JoinDiscriminatedUnions<TState>> extends true ? IsUnknown<JoinDiscriminatedUnions<TState>> extends true ? any : JoinDiscriminatedUnions<TState> : any) => Promise<RegleNestedResult<JoinDiscriminatedUnions<TState>, TRules>>;
1785
1884
  } & ProcessNestedFields$1<TState, TRules, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
1786
1885
  /**
1787
1886
  * @internal
@@ -1848,7 +1947,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
1848
1947
  /** 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). */
1849
1948
  $extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>;
1850
1949
  /** 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). */
1851
- $validate: () => Promise<RegleResult<TState, TRules>>;
1950
+ $validate: (forceValues?: IsUnknown<TState> extends true ? any : TState) => Promise<RegleFieldResult<TState, TRules>>;
1852
1951
  /** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
1853
1952
  readonly $rules: ComputeFieldRules<TState, TRules>;
1854
1953
  } & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
@@ -1860,7 +1959,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
1860
1959
  /**
1861
1960
  * @public
1862
1961
  */
1863
- interface RegleCommonStatus<TValue = any> {
1962
+ interface RegleCommonStatus<TValue = any> extends StandardSchemaV1$1<TValue> {
1864
1963
  /** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
1865
1964
  readonly $invalid: boolean;
1866
1965
  /**
@@ -2009,7 +2108,7 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
2009
2108
  /** 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). */
2010
2109
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
2011
2110
  /** 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). */
2012
- $validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, JoinDiscriminatedUnions<TRules>>>;
2111
+ $validate: (value?: JoinDiscriminatedUnions<TState>) => Promise<RegleCollectionResult<TState, JoinDiscriminatedUnions<TRules>>>;
2013
2112
  } & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
2014
2113
  /**
2015
2114
  * @internal
@@ -2031,13 +2130,31 @@ type RegleExternalCollectionErrors<TState extends Record<string, any>, TIssue ex
2031
2130
  readonly $each?: RegleValidationErrors<TState, true, TIssue>[];
2032
2131
  };
2033
2132
  /** @internal */
2133
+ type $InternalRegleCollectionErrors = {
2134
+ readonly $self?: string[];
2135
+ readonly $each?: $InternalRegleErrors[];
2136
+ };
2137
+ type $InternalRegleErrorTree = {
2138
+ [x: string]: $InternalRegleErrors;
2139
+ };
2140
+ type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
2141
+ type $InternalRegleIssuesTree = {
2142
+ [x: string]: $InternalRegleIssues;
2143
+ };
2144
+ type $InternalRegleIssues = $InternalRegleCollectionIssues | RegleFieldIssue[] | $InternalRegleIssuesTree;
2145
+ type $InternalRegleCollectionIssues = {
2146
+ readonly $self?: RegleFieldIssue[];
2147
+ readonly $each?: $InternalRegleIssues[];
2148
+ };
2149
+ //#endregion
2150
+ //#region src/types/rules/compatibility.rules.d.ts
2034
2151
 
2035
2152
  /** Supports both core Regle and schemas Regle for Zod/Valibot */
2036
2153
  type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
2037
2154
  $groups?: {
2038
2155
  [x: string]: RegleValidationGroupOutput;
2039
2156
  };
2040
- $validate: () => Promise<SuperCompatibleRegleResult>;
2157
+ $validate: (...args: any[]) => Promise<SuperCompatibleRegleResult>;
2041
2158
  };
2042
2159
  type SuperCompatibleRegleResult = $InternalRegleResult;
2043
2160
  type SuperCompatibleRegleStatus = {
@@ -2066,10 +2183,12 @@ type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TVal
2066
2183
  readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
2067
2184
  /** Collection of all the error messages, collected for all children properties. */
2068
2185
  readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
2186
+ readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
2187
+ readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
2069
2188
  /** 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). */
2070
2189
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TValue>;
2071
2190
  /** 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). */
2072
- $validate: () => Promise<MergedReglesResult<TRegles>>;
2191
+ $validate: (forceValues?: TRegles['$value']) => Promise<MergedReglesResult<TRegles>>;
2073
2192
  };
2074
2193
  type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
2075
2194
  /** Array of scoped Regles instances */
@@ -2080,10 +2199,16 @@ type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string
2080
2199
  readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
2081
2200
  /** Collection of all registered Regles instances silent errors */
2082
2201
  readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
2202
+ /** Collection of all registered Regles instances issues */
2203
+ readonly $issues: RegleValidationErrors<Record<string, unknown>, false, true>[];
2204
+ /** Collection of all registered Regles instances silent issues */
2205
+ readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
2083
2206
  /** 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
- $validate: () => Promise<{
2207
+ $validate: (forceValues?: TValue) => Promise<{
2085
2208
  valid: boolean;
2086
2209
  data: TValue;
2210
+ errors: RegleValidationErrors<Record<string, unknown>>[];
2211
+ issues: RegleValidationErrors<Record<string, unknown>>[];
2087
2212
  }>;
2088
2213
  };
2089
2214
  type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
@@ -2091,11 +2216,15 @@ type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>
2091
2216
  data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
2092
2217
  valid: false;
2093
2218
  }>['data'] };
2219
+ errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
2220
+ issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
2094
2221
  } | {
2095
2222
  valid: true;
2096
2223
  data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
2097
2224
  valid: true;
2098
2225
  }>['data'] };
2226
+ errors: EmptyObject$1;
2227
+ issues: EmptyObject$1;
2099
2228
  };
2100
2229
  //#endregion
2101
2230
  //#region src/core/createScopedUseRegle/useCollectScope.d.ts
@@ -2853,15 +2982,19 @@ type RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extend
2853
2982
  */
2854
2983
  r$: Raw<RegleSchemaFieldStatus<TState, TSchema, TShortcuts> & {
2855
2984
  /** 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). */
2856
- $validate: () => Promise<RegleSchemaResult<TSchema>>;
2985
+ $validate: (forceValues?: TSchema extends EmptyObject ? any : HasNamedKeys<TSchema> extends true ? TSchema : any) => Promise<RegleSchemaResult<TSchema>>;
2857
2986
  }>;
2858
2987
  } & TAdditionalReturnProperties;
2859
2988
  type RegleSchemaResult<TSchema extends unknown> = {
2860
2989
  valid: false;
2861
2990
  data: PartialDeep<TSchema>;
2991
+ issues: RegleIssuesTree<TSchema>;
2992
+ errors: RegleErrorTree<TSchema>;
2862
2993
  } | {
2863
2994
  valid: true;
2864
2995
  data: TSchema;
2996
+ issues: EmptyObject;
2997
+ errors: EmptyObject;
2865
2998
  };
2866
2999
  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 } : {};
2867
3000
  /**
@@ -2884,7 +3017,7 @@ type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>,
2884
3017
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
2885
3018
  } & ProcessNestedFields<TState, TSchema, TShortcuts> & (IsRoot extends true ? {
2886
3019
  /** 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). */
2887
- $validate: () => Promise<RegleSchemaResult<TSchema>>;
3020
+ $validate: (forceValues?: TSchema extends EmptyObject ? (HasNamedKeys<TSchema> extends true ? TSchema : any) : TSchema) => Promise<RegleSchemaResult<TSchema>>;
2888
3021
  } : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
2889
3022
  /**
2890
3023
  * @public
@@ -208,7 +208,9 @@ function createUseRegleSchemaComposable(options, shortcuts) {
208
208
  try {
209
209
  return {
210
210
  valid: !(await computeErrors(true)).issues?.length,
211
- data: processedState.value
211
+ data: processedState.value,
212
+ errors: {},
213
+ issues: {}
212
214
  };
213
215
  } catch (e) {
214
216
  return Promise.reject(e);
@@ -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";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function l(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 u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(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;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],c(e.$each[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]={$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(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 m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(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 g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=d(C.value)?{...u(C.value)}:u(C.value),E=i({}),D;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function O(e){let t={};return e.issues&&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(p(C.value,t));return!i&&typeof r==`number`&&(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}}).forEach(({isArray:e,$path:n,...r})=>{f(t,n,[r],e)}),t}async function k(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?E.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:E.value=O(t),t.issues||(e&&b||!e&&y)&&(A?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,j()),t}let A;function j(){A=o([C,g],()=>k(),{deep:!0})}return j(),k(),D=async()=>{try{return{valid:!(await k(!0)).issues?.length,data:C.value}}catch(e){return Promise.reject(e)}},{r$:t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:E,initialState:w,originalState:T,shortcuts:s,schemaMode:!0,onValidate:D}).regle}}return l}const _=g();function v(e,t){return e}function y(){function e(e,t){return t}return e}const b=y();function x({modifiers:e,shortcuts:t}){let n=g(e,t),r=y();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:S,useScopedRegle:C}=e({customUseRegle:_}),w=t=>{let{customStore:n,customUseRegle:r=_,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{w as createScopedUseRegleSchema,x as defineRegleSchemaConfig,b as inferSchema,S as useCollectSchemaScope,_ as useRegleSchema,C as useScopedRegleSchema,v 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";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function l(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 u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(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;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],c(e.$each[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]={$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(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 m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(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 g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=d(C.value)?{...u(C.value)}:u(C.value),E=i({}),D;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function O(e){let t={};return e.issues&&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(p(C.value,t));return!i&&typeof r==`number`&&(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}}).forEach(({isArray:e,$path:n,...r})=>{f(t,n,[r],e)}),t}async function k(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?E.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:E.value=O(t),t.issues||(e&&b||!e&&y)&&(A?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,j()),t}let A;function j(){A=o([C,g],()=>k(),{deep:!0})}return j(),k(),D=async()=>{try{return{valid:!(await k(!0)).issues?.length,data:C.value,errors:{},issues:{}}}catch(e){return Promise.reject(e)}},{r$:t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:E,initialState:w,originalState:T,shortcuts:s,schemaMode:!0,onValidate:D}).regle}}return l}const _=g();function v(e,t){return e}function y(){function e(e,t){return t}return e}const b=y();function x({modifiers:e,shortcuts:t}){let n=g(e,t),r=y();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:S,useScopedRegle:C}=e({customUseRegle:_}),w=t=>{let{customStore:n,customUseRegle:r=_,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{w as createScopedUseRegleSchema,x as defineRegleSchemaConfig,b as inferSchema,S as useCollectSchemaScope,_ as useRegleSchema,C as useScopedRegleSchema,v as withDeps};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/core": "1.9.0",
8
- "@regle/rules": "1.9.0"
7
+ "@regle/core": "1.9.2",
8
+ "@regle/rules": "1.9.2"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",