@regle/schemas 1.2.0-beta.6 → 1.2.0-beta.8
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.
- package/dist/regle-schemas.min.mjs +1 -1
- package/dist/regle-schemas.mjs +25 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createScopedUseRegle,useRootStorage}from'@regle/core';import {computed,unref,ref,isRef,watch}from'vue';function
|
|
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};
|
package/dist/regle-schemas.mjs
CHANGED
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "1.2.0-beta.8",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"@regle/
|
|
8
|
-
"@regle/
|
|
7
|
+
"@regle/core": "1.2.0-beta.8",
|
|
8
|
+
"@regle/rules": "1.2.0-beta.8"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"valibot": "^1.0.0",
|