@regle/schemas 1.18.3 → 1.19.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.
package/dist/regle-schemas.d.ts
CHANGED
package/dist/regle-schemas.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.19.0-beta.2
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -153,13 +153,7 @@ function cloneDeep(obj, dep = 0) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
function createUseRegleSchemaComposable(params) {
|
|
156
|
-
const { options, shortcuts, overrides } = params ?? {};
|
|
157
|
-
const globalOptions = {
|
|
158
|
-
autoDirty: options?.autoDirty,
|
|
159
|
-
lazy: options?.lazy,
|
|
160
|
-
rewardEarly: options?.rewardEarly,
|
|
161
|
-
clearExternalErrorsOnChange: options?.clearExternalErrorsOnChange
|
|
162
|
-
};
|
|
156
|
+
const { options: modifiers, shortcuts, overrides } = params ?? {};
|
|
163
157
|
function useRegleSchema(state, schema, options) {
|
|
164
158
|
const computedSchema = computed(() => unref(schema));
|
|
165
159
|
const { syncState = {
|
|
@@ -168,7 +162,7 @@ function createUseRegleSchemaComposable(params) {
|
|
|
168
162
|
}, ...defaultOptions } = options ?? {};
|
|
169
163
|
const { onUpdate: syncOnUpdate = false, onValidate: syncOnValidate = false } = syncState;
|
|
170
164
|
const resolvedOptions = {
|
|
171
|
-
...
|
|
165
|
+
...modifiers,
|
|
172
166
|
...defaultOptions
|
|
173
167
|
};
|
|
174
168
|
const isSingleField = computed(() => !isObject(processedState.value));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.19.0-beta.2
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,getCurrentScope as r,isRef as i,onScopeDispose as a,ref as o,unref as s,watch as c}from"vue";function l(e){return e?.constructor?.name==`File`}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??=[],h(e.$each[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]={$self:n}:isNaN(parseInt(a))?Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n:(e.$each??=[],e.$each[a]=(e.$each[a]??=[]).concat(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,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:u(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function g(e){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 _(e,t=0){if(t>20)return e;let n=e,r={}.toString.call(e).slice(8,-1);if(r==`Set`&&(n=new Set([...e].map(e=>_(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[_(e[0]),_(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,g(e))),r==`Array`||r==`Object`)for(let r in n=Array.isArray(e)?[]:{},e)n[r]=_(e[r],t++);return n}function v(e){let{options:l,shortcuts:p,overrides:h}=e??{}
|
|
7
|
+
import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,getCurrentScope as r,isRef as i,onScopeDispose as a,ref as o,unref as s,watch as c}from"vue";function l(e){return e?.constructor?.name==`File`}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??=[],h(e.$each[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]={$self:n}:isNaN(parseInt(a))?Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n:(e.$each??=[],e.$each[a]=(e.$each[a]??=[]).concat(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,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:u(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function g(e){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 _(e,t=0){if(t>20)return e;let n=e,r={}.toString.call(e).slice(8,-1);if(r==`Set`&&(n=new Set([...e].map(e=>_(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[_(e[0]),_(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,g(e))),r==`Array`||r==`Object`)for(let r in n=Array.isArray(e)?[]:{},e)n[r]=_(e[r],t++);return n}function v(e){let{options:l,shortcuts:p,overrides:h}=e??{};function g(e,g,v){let y=n(()=>s(g)),{syncState:b={onUpdate:!1,onValidate:!1},...x}=v??{},{onUpdate:S=!1,onValidate:C=!1}=b,w={...l,...x},T=n(()=>!u(E.value)),E=i(e)?e:o(e),D=o(u(E.value)?{..._(E.value)}:_(E.value)),O=u(E.value)?{..._(E.value)}:_(E.value),k=o({}),A=o([]),j;function M(e){let t=N(e),n=e.path?.[e.path.length-1],r=typeof n==`object`?n.key:n;return{isArray:(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(f(E.value,t)),$path:t,lastItemKey:r,lastItem:n}}function N(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function P(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function F(e){let t=e.path?.at(-1),n=typeof t==`object`?typeof t.key==`string`:typeof t==`string`,r=e.path?.findLastIndex(e=>typeof e==`object`?typeof e.key==`number`:typeof e==`number`);if(!(!n&&r===-1)&&r!=null){let t=e.path?.slice(0,r+1);return{...e,path:t}}}if(!y.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function I(e,t=!1){return!t&&w.rewardEarly?A.value.length?A.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&u(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=P(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&P(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>N(e)===N(n))&&t.push(n);return t},[]):[]:e}function L(e,t=!1){let n={},r=e.issues?.map(e=>{let t=F(e);if(t){let n=f(E.value,N(t));Object.defineProperty(e,`$currentArrayValue`,{value:n,enumerable:!0,configurable:!0,writable:!0})}return e}),i=I(r??[],t);if(r?.length){let e=i.map(e=>{let{isArray:t,$path:n,lastItemKey:r}=M(e);return{...e,$path:n,isArray:t,$property:r,$rule:`schema`,$message:e.message}});e.forEach(({isArray:e,$path:t,...r})=>{d(n,t,[r],e)}),A.value=e}else A.value=[];return n}async function R(e=!1){let t=y.value[`~standard`].validate(E.value);return t instanceof Promise&&(t=await t),T.value?k.value=I(t.issues??[],e)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:k.value=L(t,e),t.issues||(e&&C||!e&&S)&&(z?.(),u(E.value)?E.value=m(E.value,t.value):E.value=t.value,B()),t}let z;function B(){z=c([E,y],()=>{w.silent||R()},{deep:!0})}B(),R(),j=async()=>{try{let e=await R(!0);return V?.regle?.$touch(),{valid:!e.issues?.length,data:E.value,errors:V?.regle?.$errors,issues:k.value}}catch(e){return Promise.reject(e)}},r()&&a(()=>{z()});let V=t({scopeRules:n(()=>({})),state:E,options:w,schemaErrors:k,initialState:D,originalState:O,shortcuts:p,schemaMode:!0,onValidate:j,overrides:h});return{r$:V.regle}}return g}const y=v();function b(e,t){return e}function x(){function e(e,t){return t}return e}const S=x();function C({modifiers:e,shortcuts:t,overrides:n}){return{useRegleSchema:v({options:e,shortcuts:t,overrides:n}),inferSchema:x()}}const w=t=>{let{customStore:n,customUseRegle:r=y,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})},{useCollectScope:T,useScopedRegle:E}=e({customUseRegle:y}),D=T,O=E;export{w as createScopedUseRegleSchema,C as defineRegleSchemaConfig,S as inferSchema,D as useCollectSchemaScope,y as useRegleSchema,O as useScopedRegleSchema,b as withDeps};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0-beta.2",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"homepage": "https://reglejs.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@standard-schema/spec": "1.1.0",
|
|
39
39
|
"type-fest": "5.4.3",
|
|
40
|
-
"@regle/
|
|
41
|
-
"@regle/
|
|
40
|
+
"@regle/core": "1.19.0-beta.2",
|
|
41
|
+
"@regle/rules": "1.19.0-beta.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@total-typescript/ts-reset": "0.6.1",
|