@regle/schemas 0.10.0 → 0.10.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.
@@ -44,6 +44,12 @@ function cloneDeep(obj) {
44
44
  }
45
45
 
46
46
  // ../shared/utils/object.utils.ts
47
+ function isObject(obj) {
48
+ if (obj && (obj instanceof Date || obj.constructor.name == "File" || obj.constructor.name == "FileList")) {
49
+ return false;
50
+ }
51
+ return typeof obj === "object" && obj !== null && !Array.isArray(obj);
52
+ }
47
53
  function setObjectError(obj, propsArg, value, isArray) {
48
54
  var props, lastProp;
49
55
  if (Array.isArray(propsArg)) {
@@ -147,8 +153,11 @@ function createUseRegleSchemaComposable(options, shortcuts) {
147
153
  ...globalOptions,
148
154
  ...options2
149
155
  };
156
+ const isSingleField = vue.computed(() => !isObject(processedState.value));
150
157
  const processedState = vue.isRef(state) ? state : vue.ref(state);
151
- const initialState = vue.ref({ ...cloneDeep(processedState.value) });
158
+ const initialState = vue.ref(
159
+ isObject(processedState.value) ? { ...cloneDeep(processedState.value) } : cloneDeep(processedState.value)
160
+ );
152
161
  const customErrors = vue.ref({});
153
162
  let onValidate = undefined;
154
163
  if (!computedSchema.value?.["~standard"]) {
@@ -178,7 +187,11 @@ function createUseRegleSchemaComposable(options, shortcuts) {
178
187
  if (result instanceof Promise) {
179
188
  result = await result;
180
189
  }
181
- customErrors.value = issuesToRegleErrors(result);
190
+ if (isSingleField.value) {
191
+ customErrors.value = result.issues?.map((issue) => issue.message) ?? [];
192
+ } else {
193
+ customErrors.value = issuesToRegleErrors(result);
194
+ }
182
195
  return result;
183
196
  }
184
197
  vue.watch([processedState, computedSchema], computeErrors, { deep: true, immediate: true });
@@ -1,6 +1,6 @@
1
- import { RegleShortcutDefinition, RegleCommonStatus, JoinDiscriminatedUnions, RegleErrorTree, RegleRuleStatus, RegleCollectionErrors, MismatchInfo, DeepReactiveState, DeepMaybeRef, RegleBehaviourOptions, LocalRegleBehaviourOptions, NoInferLegacy, PrimitiveTypes } from '@regle/core';
1
+ import { RegleShortcutDefinition, Maybe, PrimitiveTypes, RegleFieldStatus, RegleCommonStatus, JoinDiscriminatedUnions, RegleErrorTree, RegleRuleStatus, RegleCollectionErrors, DeepMaybeRef, RegleBehaviourOptions, MismatchInfo, DeepReactiveState, LocalRegleBehaviourOptions, NoInferLegacy } from '@regle/core';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import { Raw, UnwrapNestedRefs, MaybeRef } from 'vue';
3
+ import { Raw, MaybeRef, MaybeRefOrGetter, UnwrapNestedRefs } from 'vue';
4
4
 
5
5
  /**
6
6
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
@@ -183,6 +183,14 @@ interface RegleSchema<TState extends Record<string, any>, TSchema extends Record
183
183
  */
184
184
  r$: Raw<RegleSchemaStatus<TState, TSchema, TShortcuts, true>>;
185
185
  }
186
+ interface RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> {
187
+ /**
188
+ * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display informations.
189
+ *
190
+ * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
191
+ */
192
+ r$: Raw<RegleFieldStatus<TState, TSchema, TShortcuts>>;
193
+ }
186
194
  type RegleSchemaResult<TSchema extends unknown> = {
187
195
  valid: false;
188
196
  data: PartialDeep<TSchema>;
@@ -261,11 +269,20 @@ type RegleSchemaCollectionStatus<TSchema extends Record<string, any>, TState ext
261
269
  [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
262
270
  });
263
271
 
264
- type useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never> = <TState extends Record<string, any>, TSchema extends StandardSchemaV1<Record<string, any>> & TValid, TValid = StandardSchemaV1.InferInput<TSchema> extends PartialDeep<UnwrapNestedRefs<TState>, {
265
- recurseIntoArrays: true;
266
- }> ? {} : MismatchInfo<UnwrapNestedRefs<TState>, PartialDeep<StandardSchemaV1.InferInput<TSchema>, {
267
- recurseIntoArrays: true;
268
- }>>>(state: MaybeRef<TState> | DeepReactiveState<TState>, schema: MaybeRef<TSchema>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<UnwrapNestedRefs<TState>, {}, never>) => RegleSchema<UnwrapNestedRefs<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts>;
272
+ interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never> {
273
+ /**
274
+ * Primitive parameter
275
+ * */
276
+ <TState extends Maybe<PrimitiveTypes>, TRules extends StandardSchemaV1<TState>>(state: MaybeRef<TState>, rulesFactory: MaybeRefOrGetter<TRules>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>>): RegleSingleFieldSchema<TState, TRules, TShortcuts>;
277
+ /**
278
+ * Object parameter
279
+ * */
280
+ <TState extends Record<string, any>, TSchema extends StandardSchemaV1<Record<string, any>> & TValid, TValid = StandardSchemaV1.InferInput<TSchema> extends PartialDeep<UnwrapNestedRefs<TState>, {
281
+ recurseIntoArrays: true;
282
+ }> ? {} : MismatchInfo<UnwrapNestedRefs<TState>, PartialDeep<StandardSchemaV1.InferInput<TSchema>, {
283
+ recurseIntoArrays: true;
284
+ }>>>(state: MaybeRef<TState> | DeepReactiveState<TState>, schema: MaybeRef<TSchema>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<UnwrapNestedRefs<TState>, {}, never>): RegleSchema<UnwrapNestedRefs<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts>;
285
+ }
269
286
  /**
270
287
  * useRegle serves as the foundation for validation logic.
271
288
  *
@@ -340,4 +357,4 @@ declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinit
340
357
  inferSchema: inferValibotSchemaFn;
341
358
  };
342
359
 
343
- export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, defineRegleSchemaConfig, inferSchema, useRegleSchema, withDeps };
360
+ export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, type RegleSingleFieldSchema, defineRegleSchemaConfig, inferSchema, useRegleSchema, withDeps };
@@ -1,6 +1,6 @@
1
- import { RegleShortcutDefinition, RegleCommonStatus, JoinDiscriminatedUnions, RegleErrorTree, RegleRuleStatus, RegleCollectionErrors, MismatchInfo, DeepReactiveState, DeepMaybeRef, RegleBehaviourOptions, LocalRegleBehaviourOptions, NoInferLegacy, PrimitiveTypes } from '@regle/core';
1
+ import { RegleShortcutDefinition, Maybe, PrimitiveTypes, RegleFieldStatus, RegleCommonStatus, JoinDiscriminatedUnions, RegleErrorTree, RegleRuleStatus, RegleCollectionErrors, DeepMaybeRef, RegleBehaviourOptions, MismatchInfo, DeepReactiveState, LocalRegleBehaviourOptions, NoInferLegacy } from '@regle/core';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import { Raw, UnwrapNestedRefs, MaybeRef } from 'vue';
3
+ import { Raw, MaybeRef, MaybeRefOrGetter, UnwrapNestedRefs } from 'vue';
4
4
 
5
5
  /**
6
6
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
@@ -183,6 +183,14 @@ interface RegleSchema<TState extends Record<string, any>, TSchema extends Record
183
183
  */
184
184
  r$: Raw<RegleSchemaStatus<TState, TSchema, TShortcuts, true>>;
185
185
  }
186
+ interface RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> {
187
+ /**
188
+ * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display informations.
189
+ *
190
+ * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
191
+ */
192
+ r$: Raw<RegleFieldStatus<TState, TSchema, TShortcuts>>;
193
+ }
186
194
  type RegleSchemaResult<TSchema extends unknown> = {
187
195
  valid: false;
188
196
  data: PartialDeep<TSchema>;
@@ -261,11 +269,20 @@ type RegleSchemaCollectionStatus<TSchema extends Record<string, any>, TState ext
261
269
  [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
262
270
  });
263
271
 
264
- type useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never> = <TState extends Record<string, any>, TSchema extends StandardSchemaV1<Record<string, any>> & TValid, TValid = StandardSchemaV1.InferInput<TSchema> extends PartialDeep<UnwrapNestedRefs<TState>, {
265
- recurseIntoArrays: true;
266
- }> ? {} : MismatchInfo<UnwrapNestedRefs<TState>, PartialDeep<StandardSchemaV1.InferInput<TSchema>, {
267
- recurseIntoArrays: true;
268
- }>>>(state: MaybeRef<TState> | DeepReactiveState<TState>, schema: MaybeRef<TSchema>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<UnwrapNestedRefs<TState>, {}, never>) => RegleSchema<UnwrapNestedRefs<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts>;
272
+ interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never> {
273
+ /**
274
+ * Primitive parameter
275
+ * */
276
+ <TState extends Maybe<PrimitiveTypes>, TRules extends StandardSchemaV1<TState>>(state: MaybeRef<TState>, rulesFactory: MaybeRefOrGetter<TRules>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>>): RegleSingleFieldSchema<TState, TRules, TShortcuts>;
277
+ /**
278
+ * Object parameter
279
+ * */
280
+ <TState extends Record<string, any>, TSchema extends StandardSchemaV1<Record<string, any>> & TValid, TValid = StandardSchemaV1.InferInput<TSchema> extends PartialDeep<UnwrapNestedRefs<TState>, {
281
+ recurseIntoArrays: true;
282
+ }> ? {} : MismatchInfo<UnwrapNestedRefs<TState>, PartialDeep<StandardSchemaV1.InferInput<TSchema>, {
283
+ recurseIntoArrays: true;
284
+ }>>>(state: MaybeRef<TState> | DeepReactiveState<TState>, schema: MaybeRef<TSchema>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<UnwrapNestedRefs<TState>, {}, never>): RegleSchema<UnwrapNestedRefs<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts>;
285
+ }
269
286
  /**
270
287
  * useRegle serves as the foundation for validation logic.
271
288
  *
@@ -340,4 +357,4 @@ declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinit
340
357
  inferSchema: inferValibotSchemaFn;
341
358
  };
342
359
 
343
- export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, defineRegleSchemaConfig, inferSchema, useRegleSchema, withDeps };
360
+ export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, type RegleSingleFieldSchema, defineRegleSchemaConfig, inferSchema, useRegleSchema, withDeps };
@@ -1 +1 @@
1
- 'use strict';var core=require('@regle/core'),vue=require('vue');function A(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,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>l(a)))),r=="Map"&&(t=new Map([...e].map(a=>[l(a[0]),l(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,A(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=l(e[a]);}return t}function w(e,t,r,a){var n,o;if(Array.isArray(t)&&(n=t.slice(0)),typeof t=="string"&&(n=t.split(".")),typeof t=="symbol"&&(n=[t]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");if(o=n.pop(),!o)return false;x(o);for(var i;i=n.shift();)if(x(i),isNaN(parseInt(i))?(typeof e[i]>"u"&&(e[i]={}),e=e[i]):((e.$each??=[])[i]={},e=e.$each[i]),!e||typeof e!="object")return false;return a?e[o]?e[o].$self=(e[o].$self??=[]).concat(r):e[o]={...e[o],$self:r}:Array.isArray(e[o])?e[o]=e[o].concat(r):e[o]=r,true}function I(e,t,r){if(!e)return r;var a,n;if(Array.isArray(t)&&(a=t.slice(0)),typeof t=="string"&&(a=t.split(".")),typeof t=="symbol"&&(a=[t]),!Array.isArray(a))throw new Error("props arg must be an array, a string or a symbol");for(;a.length;)if(n=a.shift(),!e||!n||(e=e[n],e===undefined))return r;return e}function x(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function h(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,o,i){let O=vue.ref({}),p=vue.computed(()=>vue.unref(o)),M={...r,...i},f=vue.isRef(n)?n:vue.ref(n),E=vue.ref({...l(f.value)}),S=vue.ref({}),R;if(!p.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function F(s){let T={};return s.issues&&s.issues.map(c=>{let D=c.path?.map(y=>typeof y=="object"?y.key:y.toString()).join(".")??"",u=c.path?.[c.path.length-1],N=(typeof u=="object"&&"value"in u?Array.isArray(u.value):false)||("type"in c?c.type==="array":false)||Array.isArray(I(f.value,D));return {path:D,message:c.message,isArray:N}}).forEach(c=>{w(T,c.path,[c.message],c.isArray);}),T}async function g(){let s=p.value["~standard"].validate(f.value);return s instanceof Promise&&(s=await s),S.value=F(s),s}return vue.watch([f,p],g,{deep:true,immediate:true}),R=async()=>{try{return {valid:!(await g()).issues?.length,data:f.value}}catch(s){return Promise.reject(s)}},{r$:core.useRootStorage({scopeRules:O,state:f,options:M,schemaErrors:S,initialState:E,shortcuts:t,schemaMode:true,onValidate:R}).regle}}return a}var P=h();function v(e,t){return e}function d(){function e(t,r){return r}return e}var V=d();function b({modifiers:e,shortcuts:t}){let r=h(e,t),a=d();return {useRegleSchema:r,inferSchema:a}}exports.defineRegleSchemaConfig=b;exports.inferSchema=V;exports.useRegleSchema=P;exports.withDeps=v;
1
+ 'use strict';var core=require('@regle/core'),vue=require('vue');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 f(e){let t=e,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>f(a)))),r=="Map"&&(t=new Map([...e].map(a=>[f(a[0]),f(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,C(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=f(e[a]);}return t}function S(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e,t,r,a){var n,s;if(Array.isArray(t)&&(n=t.slice(0)),typeof t=="string"&&(n=t.split(".")),typeof t=="symbol"&&(n=[t]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");if(s=n.pop(),!s)return false;w(s);for(var o;o=n.shift();)if(w(o),isNaN(parseInt(o))?(typeof e[o]>"u"&&(e[o]={}),e=e[o]):((e.$each??=[])[o]={},e=e.$each[o]),!e||typeof e!="object")return false;return a?e[s]?e[s].$self=(e[s].$self??=[]).concat(r):e[s]={...e[s],$self:r}:Array.isArray(e[s])?e[s]=e[s].concat(r):e[s]=r,true}function I(e,t,r){if(!e)return r;var a,n;if(Array.isArray(t)&&(a=t.slice(0)),typeof t=="string"&&(a=t.split(".")),typeof t=="symbol"&&(a=[t]),!Array.isArray(a))throw new Error("props arg must be an array, a string or a symbol");for(;a.length;)if(n=a.shift(),!e||!n||(e=e[n],e===undefined))return r;return e}function w(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function R(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,s,o){let F=vue.ref({}),p=vue.computed(()=>vue.unref(s)),E={...r,...o},N=vue.computed(()=>!S(l.value)),l=vue.isRef(n)?n:vue.ref(n),A=vue.ref(S(l.value)?{...f(l.value)}:f(l.value)),y=vue.ref({}),T;if(!p.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function U(i){let m={};return i.issues&&i.issues.map(c=>{let x=c.path?.map(d=>typeof d=="object"?d.key:d.toString()).join(".")??"",h=c.path?.[c.path.length-1],B=(typeof h=="object"&&"value"in h?Array.isArray(h.value):false)||("type"in c?c.type==="array":false)||Array.isArray(I(l.value,x));return {path:x,message:c.message,isArray:B}}).forEach(c=>{v(m,c.path,[c.message],c.isArray);}),m}async function D(){let i=p.value["~standard"].validate(l.value);return i instanceof Promise&&(i=await i),N.value?y.value=i.issues?.map(m=>m.message)??[]:y.value=U(i),i}return vue.watch([l,p],D,{deep:true,immediate:true}),T=async()=>{try{return {valid:!(await D()).issues?.length,data:l.value}}catch(i){return Promise.reject(i)}},{r$:core.useRootStorage({scopeRules:F,state:l,options:E,schemaErrors:y,initialState:A,shortcuts:t,schemaMode:true,onValidate:T}).regle}}return a}var P=R();function M(e,t){return e}function g(){function e(t,r){return r}return e}var O=g();function V({modifiers:e,shortcuts:t}){let r=R(e,t),a=g();return {useRegleSchema:r,inferSchema:a}}exports.defineRegleSchemaConfig=V;exports.inferSchema=O;exports.useRegleSchema=P;exports.withDeps=M;
@@ -1 +1 @@
1
- import {useRootStorage}from'@regle/core';import {ref,computed,unref,isRef,watch}from'vue';function A(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,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>l(a)))),r=="Map"&&(t=new Map([...e].map(a=>[l(a[0]),l(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,A(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=l(e[a]);}return t}function w(e,t,r,a){var n,o;if(Array.isArray(t)&&(n=t.slice(0)),typeof t=="string"&&(n=t.split(".")),typeof t=="symbol"&&(n=[t]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");if(o=n.pop(),!o)return false;x(o);for(var i;i=n.shift();)if(x(i),isNaN(parseInt(i))?(typeof e[i]>"u"&&(e[i]={}),e=e[i]):((e.$each??=[])[i]={},e=e.$each[i]),!e||typeof e!="object")return false;return a?e[o]?e[o].$self=(e[o].$self??=[]).concat(r):e[o]={...e[o],$self:r}:Array.isArray(e[o])?e[o]=e[o].concat(r):e[o]=r,true}function I(e,t,r){if(!e)return r;var a,n;if(Array.isArray(t)&&(a=t.slice(0)),typeof t=="string"&&(a=t.split(".")),typeof t=="symbol"&&(a=[t]),!Array.isArray(a))throw new Error("props arg must be an array, a string or a symbol");for(;a.length;)if(n=a.shift(),!e||!n||(e=e[n],e===undefined))return r;return e}function x(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function h(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,o,i){let O=ref({}),p=computed(()=>unref(o)),M={...r,...i},f=isRef(n)?n:ref(n),E=ref({...l(f.value)}),S=ref({}),R;if(!p.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function F(s){let T={};return s.issues&&s.issues.map(c=>{let D=c.path?.map(y=>typeof y=="object"?y.key:y.toString()).join(".")??"",u=c.path?.[c.path.length-1],N=(typeof u=="object"&&"value"in u?Array.isArray(u.value):false)||("type"in c?c.type==="array":false)||Array.isArray(I(f.value,D));return {path:D,message:c.message,isArray:N}}).forEach(c=>{w(T,c.path,[c.message],c.isArray);}),T}async function g(){let s=p.value["~standard"].validate(f.value);return s instanceof Promise&&(s=await s),S.value=F(s),s}return watch([f,p],g,{deep:true,immediate:true}),R=async()=>{try{return {valid:!(await g()).issues?.length,data:f.value}}catch(s){return Promise.reject(s)}},{r$:useRootStorage({scopeRules:O,state:f,options:M,schemaErrors:S,initialState:E,shortcuts:t,schemaMode:true,onValidate:R}).regle}}return a}var P=h();function v(e,t){return e}function d(){function e(t,r){return r}return e}var V=d();function b({modifiers:e,shortcuts:t}){let r=h(e,t),a=d();return {useRegleSchema:r,inferSchema:a}}export{b as defineRegleSchemaConfig,V as inferSchema,P as useRegleSchema,v as withDeps};
1
+ import {useRootStorage}from'@regle/core';import {ref,computed,unref,isRef,watch}from'vue';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 f(e){let t=e,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>f(a)))),r=="Map"&&(t=new Map([...e].map(a=>[f(a[0]),f(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,C(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=f(e[a]);}return t}function S(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e,t,r,a){var n,s;if(Array.isArray(t)&&(n=t.slice(0)),typeof t=="string"&&(n=t.split(".")),typeof t=="symbol"&&(n=[t]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");if(s=n.pop(),!s)return false;w(s);for(var o;o=n.shift();)if(w(o),isNaN(parseInt(o))?(typeof e[o]>"u"&&(e[o]={}),e=e[o]):((e.$each??=[])[o]={},e=e.$each[o]),!e||typeof e!="object")return false;return a?e[s]?e[s].$self=(e[s].$self??=[]).concat(r):e[s]={...e[s],$self:r}:Array.isArray(e[s])?e[s]=e[s].concat(r):e[s]=r,true}function I(e,t,r){if(!e)return r;var a,n;if(Array.isArray(t)&&(a=t.slice(0)),typeof t=="string"&&(a=t.split(".")),typeof t=="symbol"&&(a=[t]),!Array.isArray(a))throw new Error("props arg must be an array, a string or a symbol");for(;a.length;)if(n=a.shift(),!e||!n||(e=e[n],e===undefined))return r;return e}function w(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function R(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,s,o){let F=ref({}),p=computed(()=>unref(s)),E={...r,...o},N=computed(()=>!S(l.value)),l=isRef(n)?n:ref(n),A=ref(S(l.value)?{...f(l.value)}:f(l.value)),y=ref({}),T;if(!p.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function U(i){let m={};return i.issues&&i.issues.map(c=>{let x=c.path?.map(d=>typeof d=="object"?d.key:d.toString()).join(".")??"",h=c.path?.[c.path.length-1],B=(typeof h=="object"&&"value"in h?Array.isArray(h.value):false)||("type"in c?c.type==="array":false)||Array.isArray(I(l.value,x));return {path:x,message:c.message,isArray:B}}).forEach(c=>{v(m,c.path,[c.message],c.isArray);}),m}async function D(){let i=p.value["~standard"].validate(l.value);return i instanceof Promise&&(i=await i),N.value?y.value=i.issues?.map(m=>m.message)??[]:y.value=U(i),i}return watch([l,p],D,{deep:true,immediate:true}),T=async()=>{try{return {valid:!(await D()).issues?.length,data:l.value}}catch(i){return Promise.reject(i)}},{r$:useRootStorage({scopeRules:F,state:l,options:E,schemaErrors:y,initialState:A,shortcuts:t,schemaMode:true,onValidate:T}).regle}}return a}var P=R();function M(e,t){return e}function g(){function e(t,r){return r}return e}var O=g();function V({modifiers:e,shortcuts:t}){let r=R(e,t),a=g();return {useRegleSchema:r,inferSchema:a}}export{V as defineRegleSchemaConfig,O as inferSchema,P as useRegleSchema,M as withDeps};
@@ -42,6 +42,12 @@ function cloneDeep(obj) {
42
42
  }
43
43
 
44
44
  // ../shared/utils/object.utils.ts
45
+ function isObject(obj) {
46
+ if (obj && (obj instanceof Date || obj.constructor.name == "File" || obj.constructor.name == "FileList")) {
47
+ return false;
48
+ }
49
+ return typeof obj === "object" && obj !== null && !Array.isArray(obj);
50
+ }
45
51
  function setObjectError(obj, propsArg, value, isArray) {
46
52
  var props, lastProp;
47
53
  if (Array.isArray(propsArg)) {
@@ -145,8 +151,11 @@ function createUseRegleSchemaComposable(options, shortcuts) {
145
151
  ...globalOptions,
146
152
  ...options2
147
153
  };
154
+ const isSingleField = computed(() => !isObject(processedState.value));
148
155
  const processedState = isRef(state) ? state : ref(state);
149
- const initialState = ref({ ...cloneDeep(processedState.value) });
156
+ const initialState = ref(
157
+ isObject(processedState.value) ? { ...cloneDeep(processedState.value) } : cloneDeep(processedState.value)
158
+ );
150
159
  const customErrors = ref({});
151
160
  let onValidate = undefined;
152
161
  if (!computedSchema.value?.["~standard"]) {
@@ -176,7 +185,11 @@ function createUseRegleSchemaComposable(options, shortcuts) {
176
185
  if (result instanceof Promise) {
177
186
  result = await result;
178
187
  }
179
- customErrors.value = issuesToRegleErrors(result);
188
+ if (isSingleField.value) {
189
+ customErrors.value = result.issues?.map((issue) => issue.message) ?? [];
190
+ } else {
191
+ customErrors.value = issuesToRegleErrors(result);
192
+ }
180
193
  return result;
181
194
  }
182
195
  watch([processedState, computedSchema], computeErrors, { deep: true, immediate: true });
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/core": "0.10.0",
8
- "@regle/rules": "0.10.0"
7
+ "@regle/core": "0.10.1",
8
+ "@regle/rules": "0.10.1"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0-beta.11",