@regle/schemas 1.2.0-beta.6 → 1.2.0-beta.7

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.
@@ -1 +1 @@
1
- import {createScopedUseRegle,useRootStorage}from'@regle/core';import {computed,unref,ref,isRef,watch}from'vue';function J(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,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(n=>u(n)))),r=="Map"&&(t=new Map([...e].map(n=>[u(n[0]),u(n[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,J(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let n in e)t[n]=u(e[n]);}return t}function g(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function P(e,t,r,n){var a,o;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");if(o=a.pop(),!o)return false;A(o);for(var i;i=a.shift();)if(A(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 n?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 C(e,t,r){if(!e)return r;var n,a;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");for(;n.length;)if(a=n.shift(),!e||!a||(e=e[a],e===void 0))return r;return e}function A(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function x(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function n(a,o,i){let m=computed(()=>unref(o)),{syncState:k={onUpdate:false,onValidate:false},...$}=i??{},{onUpdate:L=false,onValidate:H=false}=k,z={...r,...$},W=computed(()=>!g(c.value)),c=isRef(a)?a:ref(a),_=ref(g(c.value)?{...u(c.value)}:u(c.value)),d=ref({}),v;if(!m.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function q(p){let s={};return p.issues&&p.issues.map(l=>{let F=l.path?.map(h=>typeof h=="object"?h.key:h.toString()).join(".")??"",S=l.path?.[l.path.length-1],G=(typeof S=="object"&&"value"in S?Array.isArray(S.value):false)||("type"in l?l.type==="array":false)||Array.isArray(C(c.value,F));return {path:F,message:l.message,isArray:G}}).forEach(l=>{P(s,l.path,[l.message],l.isArray);}),s}async function y(p=false){let s=m.value["~standard"].validate(c.value);return s instanceof Promise&&(s=await s),W.value?d.value=s.issues?.map(b=>b.message)??[]:d.value=q(s),s.issues||(p&&H||!p&&L)&&(D?.(),c.value=s.value,w()),s}let D;function w(){D=watch([c,m],()=>y(),{deep:true});}return w(),y(),v=async()=>{try{return {valid:!(await y(!0)).issues?.length,data:c.value}}catch(p){return Promise.reject(p)}},{r$:useRootStorage({scopeRules:computed(()=>({})),state:c,options:z,schemaErrors:d,initialState:_,shortcuts:t,schemaMode:true,onValidate:v}).regle}}return n}var f=x();function U(e,t){return e}function O(){function e(t,r){return r}return e}var E=O();function N({modifiers:e,shortcuts:t}){let r=x(e,t),n=O();return {useRegleSchema:r,inferSchema:n}}var {useCollectScope:M,useScopedRegle:B}=createScopedUseRegle({customUseRegle:f}),V=e=>{let{customStore:t,customUseRegle:r=f,asRecord:n=false}=e??{};return createScopedUseRegle({customStore:t,customUseRegle:r,asRecord:n})};export{V as createScopedUseRegleSchema,N as defineRegleSchemaConfig,E as inferSchema,M as useCollectSchemaScope,f as useRegleSchema,B as useScopedRegleSchema,U as withDeps};
1
+ import {createScopedUseRegle,useRootStorage}from'@regle/core';import {computed,unref,ref,isRef,watch}from'vue';function K(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,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>u(a)))),r=="Map"&&(t=new Map([...e].map(a=>[u(a[0]),u(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,K(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=u(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 U(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;C(o);for(var s;s=n.shift();)if(C(s),isNaN(parseInt(s))?(typeof e[s]>"u"&&(e[s]={}),e=e[s]):((e.$each??=[])[s]={},e=e.$each[s]),!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 E(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===void 0))return r;return e}function C(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function N(e,...t){for(var r=[].slice.call(arguments),a,n=r.length;a=r[n-1],n--;)if(!a||typeof a!="object"&&typeof a!="function")throw new Error("expected object, got "+a);for(var o=r[0],s=r.slice(1),f=s.length,n=0;n<f;n++){var d=s[n];for(var y in d)o[y]=d[y];}return o}function O(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,o,s){let f=computed(()=>unref(o)),{syncState:d={onUpdate:false,onValidate:false},...y}=s??{},{onUpdate:H=false,onValidate:z=false}=d,W={...r,...y},_=computed(()=>!S(i.value)),i=isRef(n)?n:ref(n),q=ref(S(i.value)?{...u(i.value)}:u(i.value)),h=ref({}),w;if(!f.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function G(p){let c={};return p.issues&&p.issues.map(l=>{let P=l.path?.map(T=>typeof T=="object"?T.key:T.toString()).join(".")??"",R=l.path?.[l.path.length-1],J=(typeof R=="object"&&"value"in R?Array.isArray(R.value):false)||("type"in l?l.type==="array":false)||Array.isArray(E(i.value,P));return {path:P,message:l.message,isArray:J}}).forEach(l=>{U(c,l.path,[l.message],l.isArray);}),c}async function g(p=false){let c=f.value["~standard"].validate(i.value);return c instanceof Promise&&(c=await c),_.value?h.value=c.issues?.map(A=>A.message)??[]:h.value=G(c),c.issues||(p&&z||!p&&H)&&(b?.(),S(i.value)?i.value=N(i.value,c.value):i.value=c.value,F()),c}let b;function F(){b=watch([i,f],()=>g(),{deep:true});}return F(),g(),w=async()=>{try{return {valid:!(await g(!0)).issues?.length,data:i.value}}catch(p){return Promise.reject(p)}},{r$:useRootStorage({scopeRules:computed(()=>({})),state:i,options:W,schemaErrors:h,initialState:q,shortcuts:t,schemaMode:true,onValidate:w}).regle}}return a}var m=O();function I(e,t){return e}function D(){function e(t,r){return r}return e}var M=D();function B({modifiers:e,shortcuts:t}){let r=O(e,t),a=D();return {useRegleSchema:r,inferSchema:a}}var {useCollectScope:k,useScopedRegle:$}=createScopedUseRegle({customUseRegle:m}),L=e=>{let{customStore:t,customUseRegle:r=m,asRecord:a=false}=e??{};return createScopedUseRegle({customStore:t,customUseRegle:r,asRecord:a})};export{L as createScopedUseRegleSchema,B as defineRegleSchemaConfig,M as inferSchema,k as useCollectSchemaScope,m as useRegleSchema,$ as useScopedRegleSchema,I as withDeps};
@@ -135,6 +135,26 @@ function prototypeCheck(prop) {
135
135
  throw new Error("setting of prototype values not supported");
136
136
  }
137
137
  }
138
+ function merge(obj1, ...objs) {
139
+ var args = [].slice.call(arguments);
140
+ var arg;
141
+ var i = args.length;
142
+ while (arg = args[i - 1], i--) {
143
+ if (!arg || typeof arg != "object" && typeof arg != "function") {
144
+ throw new Error("expected object, got " + arg);
145
+ }
146
+ }
147
+ var result = args[0];
148
+ var extenders = args.slice(1);
149
+ var len = extenders.length;
150
+ for (var i = 0; i < len; i++) {
151
+ var extender = extenders[i];
152
+ for (var key in extender) {
153
+ result[key] = extender[key];
154
+ }
155
+ }
156
+ return result;
157
+ }
138
158
 
139
159
  // src/core/useRegleSchema.ts
140
160
  function createUseRegleSchemaComposable(options, shortcuts) {
@@ -194,7 +214,11 @@ function createUseRegleSchemaComposable(options, shortcuts) {
194
214
  if (!result.issues) {
195
215
  if (isValidate && syncOnValidate || !isValidate && syncOnUpdate) {
196
216
  unWatchState?.();
197
- processedState.value = result.value;
217
+ if (isObject(processedState.value)) {
218
+ processedState.value = merge(processedState.value, result.value);
219
+ } else {
220
+ processedState.value = result.value;
221
+ }
198
222
  defineWatchState();
199
223
  }
200
224
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.2.0-beta.6",
3
+ "version": "1.2.0-beta.7",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/rules": "1.2.0-beta.6",
8
- "@regle/core": "1.2.0-beta.6"
7
+ "@regle/rules": "1.2.0-beta.7",
8
+ "@regle/core": "1.2.0-beta.7"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",