@regle/schemas 1.16.2 → 1.17.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.
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.17.0
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepPartial, DeepReactiveState, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeOutput, MergedScopedRegles, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, RegleStaticImpl, TupleToPlainObj, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
|
|
7
|
+
import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepPartial, DeepReactiveState, GlobalConfigOverrides, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeOutput, MergedScopedRegles, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, RegleStaticImpl, TupleToPlainObj, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
|
|
8
8
|
import { MaybeRef, MaybeRefOrGetter, Raw, UnwrapNestedRefs } from "vue";
|
|
9
9
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
10
10
|
import { EmptyObject, IsUnion, UnionToTuple } from "type-fest";
|
|
@@ -285,10 +285,12 @@ declare const inferSchema: inferSchemaFn;
|
|
|
285
285
|
*/
|
|
286
286
|
declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinition>({
|
|
287
287
|
modifiers,
|
|
288
|
-
shortcuts
|
|
288
|
+
shortcuts,
|
|
289
|
+
overrides
|
|
289
290
|
}: {
|
|
290
291
|
modifiers?: RegleBehaviourOptions;
|
|
291
292
|
shortcuts?: TShortcuts;
|
|
293
|
+
overrides?: GlobalConfigOverrides;
|
|
292
294
|
}): {
|
|
293
295
|
useRegleSchema: useRegleSchemaFn<TShortcuts>;
|
|
294
296
|
inferSchema: inferSchemaFn;
|
package/dist/regle-schemas.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.17.0
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -148,7 +148,8 @@ function merge(_obj1, ..._objs) {
|
|
|
148
148
|
return result;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
function createUseRegleSchemaComposable(
|
|
151
|
+
function createUseRegleSchemaComposable(params) {
|
|
152
|
+
const { options, shortcuts, overrides } = params ?? {};
|
|
152
153
|
const globalOptions = {
|
|
153
154
|
autoDirty: options?.autoDirty,
|
|
154
155
|
lazy: options?.lazy,
|
|
@@ -313,7 +314,8 @@ function createUseRegleSchemaComposable(options, shortcuts) {
|
|
|
313
314
|
originalState,
|
|
314
315
|
shortcuts,
|
|
315
316
|
schemaMode: true,
|
|
316
|
-
onValidate
|
|
317
|
+
onValidate,
|
|
318
|
+
overrides
|
|
317
319
|
});
|
|
318
320
|
return { r$: regle.regle };
|
|
319
321
|
}
|
|
@@ -457,9 +459,13 @@ const inferSchema = createInferSchemaHelper();
|
|
|
457
459
|
*
|
|
458
460
|
* @see {@link https://reglejs.dev/integrations/schemas-libraries Documentation}
|
|
459
461
|
*/
|
|
460
|
-
function defineRegleSchemaConfig({ modifiers, shortcuts }) {
|
|
462
|
+
function defineRegleSchemaConfig({ modifiers, shortcuts, overrides }) {
|
|
461
463
|
return {
|
|
462
|
-
useRegleSchema: createUseRegleSchemaComposable(
|
|
464
|
+
useRegleSchema: createUseRegleSchemaComposable({
|
|
465
|
+
options: modifiers,
|
|
466
|
+
shortcuts,
|
|
467
|
+
overrides
|
|
468
|
+
}),
|
|
463
469
|
inferSchema: createInferSchemaHelper()
|
|
464
470
|
};
|
|
465
471
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.17.0
|
|
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,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function d(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 f(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=>f(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[f(e[0]),f(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,d(e))),r==`Array`||r==`Object`)for(let r in n=Array.isArray(e)?[]:{},e)n[r]=f(e[r],t++);return n}function p(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function m(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;g(a);for(var o;o=i.shift();)if(g(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],u(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 h(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 g(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function _(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 v(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,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function d(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 f(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=>f(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[f(e[0]),f(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,d(e))),r==`Array`||r==`Object`)for(let r in n=Array.isArray(e)?[]:{},e)n[r]=f(e[r],t++);return n}function p(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function m(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;g(a);for(var o;o=i.shift();)if(g(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],u(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 h(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 g(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function _(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 v(e){let{options:l,shortcuts:u,overrides:d}=e??{},g={autoDirty:l?.autoDirty,lazy:l?.lazy,rewardEarly:l?.rewardEarly,clearExternalErrorsOnChange:l?.clearExternalErrorsOnChange};function v(e,l,v){let y=n(()=>s(l)),{syncState:b={onUpdate:!1,onValidate:!1},...x}=v??{},{onUpdate:S=!1,onValidate:C=!1}=b,w={...g,...x},T=n(()=>!p(E.value)),E=i(e)?e:o(e),D=o(p(E.value)?{...f(E.value)}:f(E.value)),O=p(E.value)?{...f(E.value)}:f(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(h(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&&p(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=h(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})=>{m(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?.(),p(E.value)?E.value=_(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:u,schemaMode:!0,onValidate:j,overrides:d});return{r$:V.regle}}return v}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,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.1.0",
|
|
7
7
|
"type-fest": "5.3.1",
|
|
8
|
-
"@regle/core": "1.
|
|
9
|
-
"@regle/rules": "1.
|
|
8
|
+
"@regle/core": "1.17.0",
|
|
9
|
+
"@regle/rules": "1.17.0"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
12
|
"valibot": "^1.0.0",
|