@regle/schemas 1.8.6 → 1.9.0-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.
@@ -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
  /**
@@ -1338,6 +1338,28 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules exte
1338
1338
  valid: true;
1339
1339
  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
1340
  };
1341
+ type RegleNestedResult<Data extends Record<string, any> | unknown, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
1342
+ valid: false;
1343
+ issues: RegleIssuesTree<Data>;
1344
+ errors: RegleErrorTree<Data>;
1345
+ } | {
1346
+ valid: true;
1347
+ issues: EmptyObject$1;
1348
+ errors: EmptyObject$1;
1349
+ });
1350
+ type RegleCollectionResult<Data extends any[], TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
1351
+ valid: false;
1352
+ issues: RegleCollectionErrors<Data, true>;
1353
+ errors: RegleCollectionErrors<Data>;
1354
+ } | {
1355
+ valid: true;
1356
+ issues: EmptyObject$1;
1357
+ errors: EmptyObject$1;
1358
+ });
1359
+ type RegleFieldResult<Data extends any, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & {
1360
+ issues: RegleFieldIssue<TRules>[];
1361
+ errors: string[];
1362
+ };
1341
1363
  /**
1342
1364
  * Infer safe output from any `r$` instance
1343
1365
  *
@@ -1349,6 +1371,8 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules exte
1349
1371
  type $InternalRegleResult = {
1350
1372
  valid: boolean;
1351
1373
  data: any;
1374
+ errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
1375
+ issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
1352
1376
  };
1353
1377
  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
1378
  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 +1458,72 @@ interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortc
1434
1458
  * Docs: {@link https://reglejs.dev/core-concepts/}
1435
1459
  */
1436
1460
 
1461
+ //#endregion
1462
+ //#region ../../node_modules/.pnpm/@standard-schema+spec@1.0.0/node_modules/@standard-schema/spec/dist/index.d.ts
1463
+ /** The Standard Schema interface. */
1464
+ interface StandardSchemaV1$1<Input = unknown, Output = Input> {
1465
+ /** The Standard Schema properties. */
1466
+ readonly "~standard": StandardSchemaV1$1.Props<Input, Output>;
1467
+ }
1468
+ declare namespace StandardSchemaV1$1 {
1469
+ /** The Standard Schema properties interface. */
1470
+ export interface Props<Input = unknown, Output = Input> {
1471
+ /** The version number of the standard. */
1472
+ readonly version: 1;
1473
+ /** The vendor name of the schema library. */
1474
+ readonly vendor: string;
1475
+ /** Validates unknown input values. */
1476
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
1477
+ /** Inferred types associated with the schema. */
1478
+ readonly types?: Types<Input, Output> | undefined;
1479
+ }
1480
+ /** The result interface of the validate function. */
1481
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
1482
+ /** The result interface if validation succeeds. */
1483
+ export interface SuccessResult<Output> {
1484
+ /** The typed output value. */
1485
+ readonly value: Output;
1486
+ /** The non-existent issues. */
1487
+ readonly issues?: undefined;
1488
+ }
1489
+ /** The result interface if validation fails. */
1490
+ export interface FailureResult {
1491
+ /** The issues of failed validation. */
1492
+ readonly issues: ReadonlyArray<Issue>;
1493
+ }
1494
+ /** The issue interface of the failure output. */
1495
+ export interface Issue {
1496
+ /** The error message of the issue. */
1497
+ readonly message: string;
1498
+ /** The path of the issue, if any. */
1499
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
1500
+ }
1501
+ /** The path segment interface of the issue. */
1502
+ export interface PathSegment {
1503
+ /** The key representing a path segment. */
1504
+ readonly key: PropertyKey;
1505
+ }
1506
+ /** The Standard Schema types interface. */
1507
+ export interface Types<Input = unknown, Output = Input> {
1508
+ /** The input type of the schema. */
1509
+ readonly input: Input;
1510
+ /** The output type of the schema. */
1511
+ readonly output: Output;
1512
+ }
1513
+ /** Infers the input type of a Standard Schema. */
1514
+ export type InferInput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["input"];
1515
+ /** Infers the output type of a Standard Schema. */
1516
+ export type InferOutput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["output"];
1517
+ export {};
1518
+ }
1519
+ //#endregion
1520
+ //#region src/core/useRegle/useErrors.d.ts
1521
+ /**
1522
+ * Converts a nested $errors object to a flat array of string errors
1523
+ *
1524
+ * Can also flatten to an array containing the path of each error with the options.includePath
1525
+ */
1526
+
1437
1527
  //#endregion
1438
1528
  //#region src/types/utils/mismatch.types.d.ts
1439
1529
  /**
@@ -1781,7 +1871,7 @@ type RegleStatus<TState extends Record<string, any> | undefined = Record<string,
1781
1871
  /** 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
1872
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
1783
1873
  /** 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>>;
1874
+ $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
1875
  } & ProcessNestedFields$1<TState, TRules, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
1786
1876
  /**
1787
1877
  * @internal
@@ -1848,7 +1938,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
1848
1938
  /** 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
1939
  $extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>;
1850
1940
  /** 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>>;
1941
+ $validate: (forceValues?: IsUnknown<TState> extends true ? any : TState) => Promise<RegleFieldResult<TState, TRules>>;
1852
1942
  /** 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
1943
  readonly $rules: ComputeFieldRules<TState, TRules>;
1854
1944
  } & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
@@ -1860,7 +1950,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
1860
1950
  /**
1861
1951
  * @public
1862
1952
  */
1863
- interface RegleCommonStatus<TValue = any> {
1953
+ interface RegleCommonStatus<TValue = any> extends StandardSchemaV1$1<TValue> {
1864
1954
  /** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
1865
1955
  readonly $invalid: boolean;
1866
1956
  /**
@@ -2009,7 +2099,7 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
2009
2099
  /** 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
2100
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
2011
2101
  /** 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>>>;
2102
+ $validate: (value?: JoinDiscriminatedUnions<TState>) => Promise<RegleCollectionResult<TState, JoinDiscriminatedUnions<TRules>>>;
2013
2103
  } & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
2014
2104
  /**
2015
2105
  * @internal
@@ -2031,13 +2121,31 @@ type RegleExternalCollectionErrors<TState extends Record<string, any>, TIssue ex
2031
2121
  readonly $each?: RegleValidationErrors<TState, true, TIssue>[];
2032
2122
  };
2033
2123
  /** @internal */
2124
+ type $InternalRegleCollectionErrors = {
2125
+ readonly $self?: string[];
2126
+ readonly $each?: $InternalRegleErrors[];
2127
+ };
2128
+ type $InternalRegleErrorTree = {
2129
+ [x: string]: $InternalRegleErrors;
2130
+ };
2131
+ type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
2132
+ type $InternalRegleIssuesTree = {
2133
+ [x: string]: $InternalRegleIssues;
2134
+ };
2135
+ type $InternalRegleIssues = $InternalRegleCollectionIssues | RegleFieldIssue[] | $InternalRegleIssuesTree;
2136
+ type $InternalRegleCollectionIssues = {
2137
+ readonly $self?: RegleFieldIssue[];
2138
+ readonly $each?: $InternalRegleIssues[];
2139
+ };
2140
+ //#endregion
2141
+ //#region src/types/rules/compatibility.rules.d.ts
2034
2142
 
2035
2143
  /** Supports both core Regle and schemas Regle for Zod/Valibot */
2036
2144
  type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
2037
2145
  $groups?: {
2038
2146
  [x: string]: RegleValidationGroupOutput;
2039
2147
  };
2040
- $validate: () => Promise<SuperCompatibleRegleResult>;
2148
+ $validate: (...args: any[]) => Promise<SuperCompatibleRegleResult>;
2041
2149
  };
2042
2150
  type SuperCompatibleRegleResult = $InternalRegleResult;
2043
2151
  type SuperCompatibleRegleStatus = {
@@ -2066,10 +2174,12 @@ type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TVal
2066
2174
  readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
2067
2175
  /** Collection of all the error messages, collected for all children properties. */
2068
2176
  readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
2177
+ readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
2178
+ readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
2069
2179
  /** 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
2180
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TValue>;
2071
2181
  /** 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>>;
2182
+ $validate: (forceValues?: TRegles['$value']) => Promise<MergedReglesResult<TRegles>>;
2073
2183
  };
2074
2184
  type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
2075
2185
  /** Array of scoped Regles instances */
@@ -2080,10 +2190,16 @@ type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string
2080
2190
  readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
2081
2191
  /** Collection of all registered Regles instances silent errors */
2082
2192
  readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
2193
+ /** Collection of all registered Regles instances issues */
2194
+ readonly $issues: RegleValidationErrors<Record<string, unknown>, false, true>[];
2195
+ /** Collection of all registered Regles instances silent issues */
2196
+ readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
2083
2197
  /** 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<{
2198
+ $validate: (forceValues?: TValue) => Promise<{
2085
2199
  valid: boolean;
2086
2200
  data: TValue;
2201
+ errors: RegleValidationErrors<Record<string, unknown>>[];
2202
+ issues: RegleValidationErrors<Record<string, unknown>>[];
2087
2203
  }>;
2088
2204
  };
2089
2205
  type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
@@ -2091,11 +2207,15 @@ type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>
2091
2207
  data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
2092
2208
  valid: false;
2093
2209
  }>['data'] };
2210
+ errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
2211
+ issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
2094
2212
  } | {
2095
2213
  valid: true;
2096
2214
  data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
2097
2215
  valid: true;
2098
2216
  }>['data'] };
2217
+ errors: EmptyObject$1;
2218
+ issues: EmptyObject$1;
2099
2219
  };
2100
2220
  //#endregion
2101
2221
  //#region src/core/createScopedUseRegle/useCollectScope.d.ts
@@ -2853,15 +2973,19 @@ type RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extend
2853
2973
  */
2854
2974
  r$: Raw<RegleSchemaFieldStatus<TState, TSchema, TShortcuts> & {
2855
2975
  /** 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>>;
2976
+ $validate: (forceValues?: TSchema extends EmptyObject ? any : HasNamedKeys<TSchema> extends true ? TSchema : any) => Promise<RegleSchemaResult<TSchema>>;
2857
2977
  }>;
2858
2978
  } & TAdditionalReturnProperties;
2859
2979
  type RegleSchemaResult<TSchema extends unknown> = {
2860
2980
  valid: false;
2861
2981
  data: PartialDeep<TSchema>;
2982
+ issues: RegleIssuesTree<TSchema>;
2983
+ errors: RegleErrorTree<TSchema>;
2862
2984
  } | {
2863
2985
  valid: true;
2864
2986
  data: TSchema;
2987
+ issues: EmptyObject;
2988
+ errors: EmptyObject;
2865
2989
  };
2866
2990
  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
2991
  /**
@@ -2884,7 +3008,7 @@ type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>,
2884
3008
  $extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
2885
3009
  } & ProcessNestedFields<TState, TSchema, TShortcuts> & (IsRoot extends true ? {
2886
3010
  /** 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>>;
3011
+ $validate: (forceValues?: TSchema extends EmptyObject ? (HasNamedKeys<TSchema> extends true ? TSchema : any) : TSchema) => Promise<RegleSchemaResult<TSchema>>;
2888
3012
  } : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
2889
3013
  /**
2890
3014
  * @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.8.6",
3
+ "version": "1.9.0-beta.1",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/rules": "1.8.6",
8
- "@regle/core": "1.8.6"
7
+ "@regle/core": "1.9.0-beta.1",
8
+ "@regle/rules": "1.9.0-beta.1"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",