@regle/schemas 1.3.2 → 1.4.0-beta.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.
@@ -7,7 +7,6 @@ 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>;
11
10
  type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
12
11
  type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
13
12
  type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
@@ -1702,7 +1701,7 @@ type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K ex
1702
1701
  /**
1703
1702
  * Combine all union values to be able to get even the normally "never" values, act as an intersection type
1704
1703
  */
1705
- 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>] : [];
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>] : [];
1706
1705
  /**
1707
1706
  * Get all possible keys from a union, even the ones present only on one union
1708
1707
  */
@@ -1920,7 +1919,7 @@ type DefaultValidators = {
1920
1919
  numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
1921
1920
  oneOf: RegleRuleDefinition<string | number, [options: (string | number)[]], false, boolean, string | number>;
1922
1921
  regex: RegleRuleWithParamsDefinition<string, [regexp: RegExp], false, boolean>;
1923
- required: RegleRuleDefinition<unknown, []>;
1922
+ required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
1924
1923
  sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
1925
1924
  string: RegleRuleDefinition<unknown, [], false, boolean, any, unknown>;
1926
1925
  type: RegleRuleDefinition<unknown, [], false, boolean, unknown, unknown>;
@@ -2001,21 +2000,6 @@ type InlineRuleDeclaration<TValue extends any = any, TParams extends any[] = any
2001
2000
  * Regroup inline and registered rules
2002
2001
  * */
2003
2002
  type FormRuleDeclaration<TValue extends any = unknown, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn), TAsync extends boolean = boolean> = InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata> | RegleRuleWithParamsDefinitionInput<TValue, [param?: any], TAsync, TMetadata> | RegleRuleWithParamsDefinitionInput<TValue, [param?: any, ...any[]], TAsync, TMetadata>;
2004
- //#endregion
2005
- //#region src/types/rules/rule.errors.types.d.ts
2006
- type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false> };
2007
- type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true> };
2008
- type RegleValidationErrors<TState extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TExternal extends false ? RegleCollectionErrors<U> : RegleExternalCollectionErrors<U> : string[] : NonNullable<TState> extends Date | File ? string[] : NonNullable<TState> extends Record<string, any> ? TExternal extends false ? RegleErrorTree<TState> : RegleExternalErrorTree<TState> : string[];
2009
- type RegleCollectionErrors<TState extends Record<string, any>> = {
2010
- readonly $self: string[];
2011
- readonly $each: RegleValidationErrors<TState, false>[];
2012
- };
2013
- type RegleExternalCollectionErrors<TState extends Record<string, any>> = {
2014
- readonly $self?: string[];
2015
- readonly $each?: RegleValidationErrors<TState, true>[];
2016
- };
2017
- /** @internal */
2018
-
2019
2003
  //#endregion
2020
2004
  //#region src/types/rules/rule.status.types.d.ts
2021
2005
  /**
@@ -2059,6 +2043,13 @@ type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl
2059
2043
  * @reference {@link InferRegleStatusType}
2060
2044
  */
2061
2045
 
2046
+ interface RegleFieldIssue {
2047
+ $property: string;
2048
+ $rule: string;
2049
+ $type?: string;
2050
+ $message: string;
2051
+ [x: string]: unknown;
2052
+ }
2062
2053
  /**
2063
2054
  * @public
2064
2055
  */
@@ -2073,6 +2064,14 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
2073
2064
  readonly $errors: string[];
2074
2065
  /** Collection of all the error messages, collected for all children properties and nested forms. */
2075
2066
  readonly $silentErrors: string[];
2067
+ /**
2068
+ * Collect all metadata of validators, Only contains errors from properties where $dirty equals true.
2069
+ */
2070
+ readonly $issues: RegleFieldIssue[];
2071
+ /**
2072
+ * Collect all metadata of validators, including the error message.
2073
+ */
2074
+ readonly $silentIssues: RegleFieldIssue[];
2076
2075
  /** Stores external errors of the current field */
2077
2076
  readonly $externalErrors: string[];
2078
2077
  /** Stores active tooltips messages of the current field */
@@ -2086,7 +2085,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
2086
2085
  /** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
2087
2086
  readonly $rules: IsEmptyObject$1<TRules> extends true ? {
2088
2087
  readonly [x: string]: RegleRuleStatus<TState, any[], any>;
2089
- } : { 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 : 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> };
2090
2089
  } & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
2091
2090
  /**
2092
2091
  * @internal
@@ -2181,7 +2180,7 @@ type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata exte
2181
2180
  * @reference {@link RegleRuleStatus}
2182
2181
  */
2183
2182
  interface $InternalRegleRuleStatus {
2184
- $type: string;
2183
+ $type?: string;
2185
2184
  $message: string | string[];
2186
2185
  $tooltip: string | string[];
2187
2186
  $active: boolean;
@@ -2233,6 +2232,21 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
2233
2232
  * @reference {@link RegleCollectionStatus}
2234
2233
  */
2235
2234
 
2235
+ //#endregion
2236
+ //#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> };
2238
+ 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[];
2240
+ type RegleCollectionErrors<TState extends Record<string, any>, TIssue extends boolean = false> = {
2241
+ readonly $self: string[];
2242
+ readonly $each: RegleValidationErrors<TState, false, TIssue>[];
2243
+ };
2244
+ type RegleExternalCollectionErrors<TState extends Record<string, any>, TIssue extends boolean = false> = {
2245
+ readonly $self?: string[];
2246
+ readonly $each?: RegleValidationErrors<TState, true, TIssue>[];
2247
+ };
2248
+ /** @internal */
2249
+
2236
2250
  /** Supports both core Regle and schemas Regle for Zod/Valibot */
2237
2251
  type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
2238
2252
  $groups?: {
@@ -3096,6 +3110,14 @@ type InferRegleSchemaStatusType<TSchema extends unknown, TState extends unknown,
3096
3110
  * @public
3097
3111
  */
3098
3112
  type RegleSchemaFieldStatus<TSchema extends unknown, TState = any, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$pending'> & {
3113
+ /**
3114
+ * Collect all metadata of validators, Only contains errors from properties where $dirty equals true.
3115
+ */
3116
+ readonly $issues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
3117
+ /**
3118
+ * Collect all metadata of validators, including the error message.
3119
+ */
3120
+ readonly $silentIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
3099
3121
  /** Collection of all the error messages, collected for all children properties and nested forms.
3100
3122
  *
3101
3123
  * Only contains errors from properties where $dirty equals true. */
@@ -3151,9 +3173,9 @@ type RegleSchemaBehaviourOptions = {
3151
3173
  //#region src/core/useRegleSchema.d.ts
3152
3174
  type useRegleSchemaFnOptions<TAdditionalOptions extends Record<string, any>> = Omit<Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, {}, never>, 'validationGroups' | 'lazy' | 'rewardEarly' | 'silent'> & RegleSchemaBehaviourOptions & TAdditionalOptions;
3153
3175
  interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
3154
- <TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<NoInferLegacy<TState>, {
3176
+ <TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<TState, {
3155
3177
  recurseIntoArrays: true;
3156
- }>> | DeepReactiveState<PartialDeep<NoInferLegacy<TState>, {
3178
+ }>> | DeepReactiveState<PartialDeep<TState, {
3157
3179
  recurseIntoArrays: true;
3158
3180
  }>>, 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>;
3159
3181
  }
@@ -131,20 +131,23 @@ function createUseRegleSchemaComposable(options, shortcuts) {
131
131
  function issuesToRegleErrors(result) {
132
132
  const output = {};
133
133
  if (result.issues) {
134
- const errors = result.issues.map((issue) => {
134
+ const issues = result.issues.map((issue) => {
135
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
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
138
  const isPrimitivesArray = !isArray && typeof (typeof lastItem === "object" ? lastItem.key : lastItem) === "number";
139
139
  if (isPrimitivesArray) path = issue.path?.slice(0, issue.path.length - 1)?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
140
140
  return {
141
+ ...issue,
141
142
  path,
142
- message: issue.message,
143
- isArray
143
+ isArray,
144
+ $property: lastItem,
145
+ $rule: "schema",
146
+ $message: issue.message
144
147
  };
145
148
  });
146
- errors.forEach((error) => {
147
- setObjectError(output, error.path, [error.message], error.isArray);
149
+ issues.forEach(({ isArray, path,...issue }) => {
150
+ setObjectError(output, path, [issue], isArray);
148
151
  });
149
152
  }
150
153
  return output;
@@ -152,7 +155,12 @@ function createUseRegleSchemaComposable(options, shortcuts) {
152
155
  async function computeErrors(isValidate = false) {
153
156
  let result = computedSchema.value["~standard"].validate(processedState.value);
154
157
  if (result instanceof Promise) result = await result;
155
- if (isSingleField.value) customErrors.value = result.issues?.map((issue) => issue.message) ?? [];
158
+ if (isSingleField.value) customErrors.value = result.issues?.map((issue) => ({
159
+ $message: issue.message,
160
+ $property: issue.path?.[issue.path.length - 1]?.toString() ?? "-",
161
+ $rule: "schema",
162
+ ...issue
163
+ })) ?? [];
156
164
  else customErrors.value = issuesToRegleErrors(result);
157
165
  if (!result.issues) {
158
166
  if (isValidate && syncOnValidate || !isValidate && syncOnUpdate) {
@@ -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(`.`)??``),{path:t,message:e.message,isArray:r}});n.forEach(e=>{d(t,e.path,[e.message],e.isArray)})}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=>e.message)??[]: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`&&`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};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.3.2",
3
+ "version": "1.4.0-beta.2",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/core": "1.3.2",
8
- "@regle/rules": "1.3.2"
7
+ "@regle/core": "1.4.0-beta.2",
8
+ "@regle/rules": "1.4.0-beta.2"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",