@regle/schemas 1.2.0-beta.8 → 1.2.0
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
|
|
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 p(e){let t=e,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(n=>p(n)))),r=="Map"&&(t=new Map([...e].map(n=>[p(n[0]),p(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]=p(e[n]);}return t}function m(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function E(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;C(o);for(var s;s=a.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 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 U(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 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),n,a=r.length;n=r[a-1],a--;)if(!n||typeof n!="object"&&typeof n!="function")throw new Error("expected object, got "+n);for(var o=r[0],s=r.slice(1),f=s.length,a=0;a<f;a++){var y=s[a];for(var S in y)o[S]=y[S];}return o}function v(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function n(a,o,s){let f=computed(()=>unref(o)),{syncState:y={onUpdate:false,onValidate:false},...S}=s??{},{onUpdate:L=false,onValidate:H=false}=y,z={...r,...S},W=computed(()=>!m(i.value)),i=isRef(a)?a:ref(a),_=ref(m(i.value)?{...p(i.value)}:p(i.value)),h=ref({}),w;if(!f.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function q(u){let c={};return u.issues&&u.issues.map(l=>{let P=l.path?.map(T=>typeof T=="object"?T.key:T.toString()).join(".")??"",R=l.path?.[l.path.length-1],G=(typeof R=="object"&&"value"in R?Array.isArray(R.value):false)||("type"in l?l.type==="array":false)||Array.isArray(U(i.value,P));return {path:P,message:l.message,isArray:G}}).forEach(l=>{E(c,l.path,[l.message],l.isArray);}),c}async function g(u=false){let c=f.value["~standard"].validate(i.value);return c instanceof Promise&&(c=await c),W.value?h.value=c.issues?.map(b=>b.message)??[]:h.value=q(c),c.issues||(u&&H||!u&&L)&&(F?.(),m(i.value)?i.value=N(i.value,c.value):i.value=c.value,A()),c}let F;function A(){F=watch([i,f],()=>g(),{deep:true});}return A(),g(),w=async()=>{try{return {valid:!(await g(!0)).issues?.length,data:i.value}}catch(u){return Promise.reject(u)}},{r$:useRootStorage({scopeRules:computed(()=>({})),state:i,options:z,schemaErrors:h,initialState:_,shortcuts:t,schemaMode:true,onValidate:w}).regle}}return n}var d=v();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=v(e,t),n=D();return {useRegleSchema:r,inferSchema:n}}var {useCollectScope:k,useScopedRegle:$}=createScopedUseRegle({customUseRegle:d}),j=e=>{let{customStore:t,customUseRegle:r=d,asRecord:n=false}=e??{};return createScopedUseRegle({customStore:t,customUseRegle:r,asRecord:n})};export{j as createScopedUseRegleSchema,B as defineRegleSchemaConfig,M as inferSchema,k as useCollectSchemaScope,d as useRegleSchema,$ as useScopedRegleSchema,I as withDeps};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.2.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"@regle/
|
|
8
|
-
"@regle/
|
|
7
|
+
"@regle/rules": "1.2.0",
|
|
8
|
+
"@regle/core": "1.2.0"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"valibot": "^1.0.0",
|