@regle/schemas 1.26.0 → 1.27.0-beta.1

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,10 +1,10 @@
1
1
  /**
2
- * @regle/schemas v1.26.0
2
+ * @regle/schemas v1.27.0-beta.1
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
6
6
 
7
- import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepPartial, DeepReactiveState, GlobalConfigOverrides, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeOutput, MergedScopedRegles, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleExternalCollectionErrors, RegleExternalSchemaErrorTree, 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, RegleExternalCollectionErrors, RegleExternalSchemaErrorTree, RegleExternalSchemaIssueTree, 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, IsAny, IsUnion, IsUnknown, UnionToTuple } from "type-fest";
@@ -59,7 +59,8 @@ type RegleSchemaStatus<TInput extends Record<string, any> | undefined = Record<s
59
59
  readonly $errors: RegleErrorTree<TInput, false, true>;
60
60
  readonly $output: TOutput; /** Collection of all the error messages, collected for all children properties. */
61
61
  readonly $silentErrors: RegleErrorTree<TInput, false, true>; /** Sets the external errors for the field. */
62
- $setExternalErrors(errors: RegleExternalSchemaErrorTree<TInput>): void; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
62
+ $setExternalErrors(errors: RegleExternalSchemaErrorTree<TInput>): void; /** Sets the external issues for the field. */
63
+ $setExternalIssues(issues: RegleExternalSchemaIssueTree<TInput>): void; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
63
64
  $extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
64
65
  } & (HasNamedKeys<TInput> extends true ? ProcessNestedFields<JoinDiscriminatedUnions<TInput>, JoinDiscriminatedUnions<TOutput>, TShortcuts> : {}) & (IsRoot extends true ? {
65
66
  /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */$validate: (forceValues?: TInput extends EmptyObject ? (HasNamedKeys<TInput> extends true ? TInput : any) : TInput) => Promise<RegleSchemaResult<StandardSchemaV1.InferOutput<TSchema>>>;
@@ -96,13 +97,15 @@ type RegleSchemaFieldStatus<TInput = any, TOutput = TInput, TShortcuts extends R
96
97
  * Collect all metadata of validators, including the error message.
97
98
  */
98
99
  readonly $silentIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[]; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
99
- readonly $externalErrors: string[]; /** Represents the inactive status. Is true when this state have empty rules */
100
+ readonly $externalErrors: string[]; /** Stores external issues of the current field */
101
+ readonly $externalIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[]; /** Represents the inactive status. Is true when this state have empty rules */
100
102
  readonly $inactive: boolean; /** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
101
103
  readonly $rules: {
102
104
  [`~validator`]: RegleRuleStatus<IsUnion<TInput> extends true ? any : TInput, []>;
103
105
  };
104
106
  readonly $output: TOutput; /** Sets the external errors for the field. */
105
- $setExternalErrors(errors: string[]): void; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
107
+ $setExternalErrors(errors: string[]): void; /** Sets the external issues for the field. */
108
+ $setExternalIssues(issues: (RegleFieldIssue & StandardSchemaV1.Issue)[]): void; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
106
109
  $extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
107
110
  } & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
108
111
  type RegleSchemaCommonStatus<TInput extends unknown = unknown, TOutput = TInput> = Omit<RegleCommonStatus<TInput, TOutput>, '$pending'>;
@@ -126,7 +129,8 @@ type RegleSchemaCollectionStatus<TInput extends any[], TOutput = TInput, TShortc
126
129
  readonly $output: TOutput;
127
130
  /** Will return a copy of your state with only the fields that are dirty. By default, it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
128
131
  /** Sets the external errors for the field. */
129
- $setExternalErrors(errors: RegleExternalCollectionErrors<TInput>): void; /** Will return a copy of your state with only the fields that are dirty. By default, it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
132
+ $setExternalErrors(errors: RegleExternalCollectionErrors<TInput>): void; /** Sets the external issues for the field. */
133
+ $setExternalIssues(errors: RegleExternalCollectionErrors<TInput, true>): void; /** Will return a copy of your state with only the fields that are dirty. By default, it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
130
134
  $extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
131
135
  } & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
132
136
  type RegleSchemaBehaviourOptions = {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/schemas v1.26.0
2
+ * @regle/schemas v1.27.0-beta.1
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -137,13 +137,13 @@ function cloneDeep(obj, dep = 0) {
137
137
  if (dep > 20) return obj;
138
138
  let result = obj;
139
139
  let type = {}.toString.call(obj).slice(8, -1);
140
- if (type == "Set") result = new Set([...obj].map((value) => cloneDeep(value, dep++)));
141
- if (type == "Map") result = new Map([...obj].map((kv) => [cloneDeep(kv[0]), cloneDeep(kv[1])]));
140
+ if (type == "Set") result = new Set([...obj].map((value) => cloneDeep(value, dep + 1)));
141
+ if (type == "Map") result = new Map([...obj].map((kv) => [cloneDeep(kv[0], dep + 1), cloneDeep(kv[1], dep + 1)]));
142
142
  if (type == "Date") result = new Date(obj.getTime());
143
143
  if (type == "RegExp") result = RegExp(obj.source, getRegExpFlags(obj));
144
144
  if (type == "Array" || type == "Object") {
145
145
  result = Array.isArray(obj) ? [] : {};
146
- for (let key in obj) result[key] = cloneDeep(obj[key], dep++);
146
+ for (let key in obj) result[key] = cloneDeep(obj[key], dep + 1);
147
147
  }
148
148
  return result;
149
149
  }
@@ -452,8 +452,10 @@ function createUseRegleSchemaComposable(params) {
452
452
  });
453
453
  bindSchemaToCurrentScope();
454
454
  return { r$: toReactive(regle.regle, isDisabled, () => {
455
- bindSchemaToCurrentScope();
456
- regle?.bindToCurrentScope();
455
+ if (!regle.regle.value) {
456
+ bindSchemaToCurrentScope();
457
+ regle.bindToCurrentScope();
458
+ }
457
459
  }) };
458
460
  }
459
461
  return useRegleSchema;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @regle/schemas v1.26.0
2
+ * @regle/schemas v1.27.0-beta.1
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,effectScope as r,getCurrentInstance as i,getCurrentScope as a,isRef as o,nextTick as s,onMounted as c,onScopeDispose as l,reactive as u,ref as d,toValue as f,unref as p,watch as m}from"vue";function h(e){return e?.constructor?.name==`File`}function g(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function _(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;y(a);for(var o;o=i.shift();)if(y(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],x(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 v(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 y(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function b(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 x(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):h(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:g(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function S(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 C(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=>C(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[C(e[0]),C(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,S(e))),r==`Array`||r==`Object`){n=Array.isArray(e)?[]:{};for(let r in e)n[r]=C(e[r],t++)}return n}function w(e,t,n){if(!o(e))return n?.(),u(e);let r=d(!1);return i()&&c(async()=>{await s(),typeof window<`u`&&window.requestAnimationFrame(()=>{r.value=!0})}),u(new Proxy({},{get(i,a,o){if(n?.(),t.value&&a!==`$value`&&r.value)return Reflect.get(i,a,o);if(e.value!==void 0)return p(Reflect.get(e.value,a,o))},set(t,r,i){return n?.(),o(e.value[r])&&!o(i)?e.value[r].value=i:e.value[r]=i,!0},deleteProperty(t,r){return n?.(),Reflect.deleteProperty(e.value,r)},has(t,r){return n?.(),e.value===void 0?!1:Reflect.has(e.value,r)},ownKeys(){return n?.(),e.value===void 0?[]:Object.keys(e.value)},getOwnPropertyDescriptor(){return n?.(),{enumerable:!0,configurable:!0}}}))}function T(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function E(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function D(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}}}function O(e,t){let n=T(e),r=e.path?.[e.path.length-1],i=typeof r==`object`?r.key:r;return{isArray:(typeof r==`object`&&`value`in r?Array.isArray(r.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(v(t.value,n)),$path:n,lastItemKey:i,lastItem:r}}function k(e,t,n,r=!1){return!r&&n?t.value.length?t.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&g(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=E(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&E(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>T(e)===T(n))&&t.push(n);return t},[]):[]:e}function A(e,t,n,r=!1){return k(e,t,n,r)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]}function j({result:e,previousIssues:t,processedState:n,rewardEarly:r,isValidate:i=!1}){let a={},o=e.issues?.map(e=>{let t=D(e);if(t){let r=v(n.value,T(t));Object.defineProperty(e,`$currentArrayValue`,{value:r,enumerable:!0,configurable:!0,writable:!0})}return e}),s=k(o??[],t,r,i);if(o?.length){let e=s.map(e=>{let{isArray:t,$path:r,lastItemKey:i}=O(e,n);return{...e,$path:r,isArray:t,$property:i,$rule:`schema`,$message:e.message}});e.forEach(({isArray:e,$path:t,...n})=>{_(a,t,[n],e)}),t.value=e}else t.value=[];return a}function M(e){let t=o(e)?e:d(e);return{processedState:t,isSingleField:n(()=>!g(t.value)),initialState:d(g(t.value)?{...C(t.value)}:C(t.value)),originalState:g(t.value)?{...C(t.value)}:C(t.value)}}function N({processedState:e,getSchema:t,isSingleField:n,customErrors:r,previousIssues:i,resolvedOptions:a,syncOnUpdate:o,syncOnValidate:s}){let c;function l(){u(),c=m([e,t],()=>{a.silent||t()[`~standard`].vendor!==`regle`&&d()},{deep:!0})}function u(){c?.(),c=void 0}async function d(c=!1){let d=t()[`~standard`].validate(e.value);return d instanceof Promise&&(d=await d),n.value?r.value=A(d.issues??[],i,f(a.rewardEarly),c):r.value=j({result:d,previousIssues:i,processedState:e,rewardEarly:f(a.rewardEarly),isValidate:c}),d.issues||(c&&s||!c&&o)&&(u(),g(e.value)?e.value=b(e.value,d.value):e.value=d.value,l()),d}return{computeErrors:d,defineWatchState:l,stopWatching:u}}function P(e){let{options:i,shortcuts:o,overrides:c}=e??{};function u(e,u,h){if(!p(u)?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);let{syncState:g={onUpdate:!1,onValidate:!1},..._}=h??{},{onUpdate:v=!1,onValidate:y=!1}=g,b={...i,..._},{processedState:x,isSingleField:S,initialState:C,originalState:T}=M(e),E=d({}),D=d([]),O=new Set,k=!1,A,j,P;function F(){return N({processedState:x,getSchema:()=>p(u),isSingleField:S,customErrors:E,previousIssues:D,resolvedOptions:b,syncOnUpdate:v,syncOnValidate:y})}function I(){A?.stop(),A=r(),A.run(()=>{j=F(),j.defineWatchState(),j.computeErrors()})}function L(){j?.stopWatching(),j=void 0,A?.stop(),A=void 0}function R(){k||(k=!0,I(),P=m(()=>f(b.disabled),e=>{e?L():I()}),f(b.disabled)&&s().then(()=>{L()}))}function z(){k&&(k=!1,P?.(),P=void 0,L())}let B,V=async()=>{try{let e=await(j??F()).computeErrors(!0);return B?.regle.value?.$touch(),{valid:!e.issues?.length,data:e.issues?x.value:e.value,errors:B?.regle.value?.$errors,issues:E.value}}catch(e){return Promise.reject(e)}};function H(){let e=a();!e||O.has(e)||(k||R(),O.add(e),l(()=>{O.delete(e),O.size||z()}))}let U=n(()=>f(b.disabled)??!1);return R(),B=t({scopeRules:n(()=>({})),state:x,options:b,schemaErrors:E,initialState:C,originalState:T,shortcuts:o,schemaMode:!0,onValidate:V,overrides:c}),H(),{r$:w(B.regle,U,()=>{H(),B?.bindToCurrentScope()})}}return u}const F=P();function I(e,t){return e}function L(){function e(e,t){return t}return e}const R=L();function z({modifiers:e,shortcuts:t,overrides:n}){return{useRegleSchema:P({options:e,shortcuts:t,overrides:n}),inferSchema:L()}}const B=t=>{let{customStore:n,customUseRegle:r=F,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})},{useCollectScope:V,useScopedRegle:H}=e({customUseRegle:F}),U=V,W=H;export{B as createScopedUseRegleSchema,z as defineRegleSchemaConfig,R as inferSchema,U as useCollectSchemaScope,F as useRegleSchema,W as useScopedRegleSchema,I as withDeps};
7
+ import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,effectScope as r,getCurrentInstance as i,getCurrentScope as a,isRef as o,nextTick as s,onMounted as c,onScopeDispose as l,reactive as u,ref as d,toValue as f,unref as p,watch as m}from"vue";function h(e){return e?.constructor?.name==`File`}function g(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function _(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;y(a);for(var o;o=i.shift();)if(y(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],x(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 v(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 y(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function b(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 x(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):h(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:g(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function S(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 C(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=>C(e,t+1)))),r==`Map`&&(n=new Map([...e].map(e=>[C(e[0],t+1),C(e[1],t+1)]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,S(e))),r==`Array`||r==`Object`){n=Array.isArray(e)?[]:{};for(let r in e)n[r]=C(e[r],t+1)}return n}function w(e,t,n){if(!o(e))return n?.(),u(e);let r=d(!1);return i()&&c(async()=>{await s(),typeof window<`u`&&window.requestAnimationFrame(()=>{r.value=!0})}),u(new Proxy({},{get(i,a,o){if(n?.(),t.value&&a!==`$value`&&r.value)return Reflect.get(i,a,o);if(e.value!==void 0)return p(Reflect.get(e.value,a,o))},set(t,r,i){return n?.(),o(e.value[r])&&!o(i)?e.value[r].value=i:e.value[r]=i,!0},deleteProperty(t,r){return n?.(),Reflect.deleteProperty(e.value,r)},has(t,r){return n?.(),e.value===void 0?!1:Reflect.has(e.value,r)},ownKeys(){return n?.(),e.value===void 0?[]:Object.keys(e.value)},getOwnPropertyDescriptor(){return n?.(),{enumerable:!0,configurable:!0}}}))}function T(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function E(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function D(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}}}function O(e,t){let n=T(e),r=e.path?.[e.path.length-1],i=typeof r==`object`?r.key:r;return{isArray:(typeof r==`object`&&`value`in r?Array.isArray(r.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(v(t.value,n)),$path:n,lastItemKey:i,lastItem:r}}function k(e,t,n,r=!1){return!r&&n?t.value.length?t.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&g(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=E(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&E(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>T(e)===T(n))&&t.push(n);return t},[]):[]:e}function A(e,t,n,r=!1){return k(e,t,n,r)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]}function j({result:e,previousIssues:t,processedState:n,rewardEarly:r,isValidate:i=!1}){let a={},o=e.issues?.map(e=>{let t=D(e);if(t){let r=v(n.value,T(t));Object.defineProperty(e,"$currentArrayValue",{value:r,enumerable:!0,configurable:!0,writable:!0})}return e}),s=k(o??[],t,r,i);if(o?.length){let e=s.map(e=>{let{isArray:t,$path:r,lastItemKey:i}=O(e,n);return{...e,$path:r,isArray:t,$property:i,$rule:`schema`,$message:e.message}});e.forEach(({isArray:e,$path:t,...n})=>{_(a,t,[n],e)}),t.value=e}else t.value=[];return a}function M(e){let t=o(e)?e:d(e);return{processedState:t,isSingleField:n(()=>!g(t.value)),initialState:d(g(t.value)?{...C(t.value)}:C(t.value)),originalState:g(t.value)?{...C(t.value)}:C(t.value)}}function N({processedState:e,getSchema:t,isSingleField:n,customErrors:r,previousIssues:i,resolvedOptions:a,syncOnUpdate:o,syncOnValidate:s}){let c;function l(){u(),c=m([e,t],()=>{a.silent||t()[`~standard`].vendor!==`regle`&&d()},{deep:!0})}function u(){c?.(),c=void 0}async function d(c=!1){let d=t()[`~standard`].validate(e.value);return d instanceof Promise&&(d=await d),n.value?r.value=A(d.issues??[],i,f(a.rewardEarly),c):r.value=j({result:d,previousIssues:i,processedState:e,rewardEarly:f(a.rewardEarly),isValidate:c}),d.issues||(c&&s||!c&&o)&&(u(),g(e.value)?e.value=b(e.value,d.value):e.value=d.value,l()),d}return{computeErrors:d,defineWatchState:l,stopWatching:u}}function P(e){let{options:i,shortcuts:o,overrides:c}=e??{};function u(e,u,h){if(!p(u)?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);let{syncState:g={onUpdate:!1,onValidate:!1},..._}=h??{},{onUpdate:v=!1,onValidate:y=!1}=g,b={...i,..._},{processedState:x,isSingleField:S,initialState:C,originalState:T}=M(e),E=d({}),D=d([]),O=new Set,k=!1,A,j,P;function F(){return N({processedState:x,getSchema:()=>p(u),isSingleField:S,customErrors:E,previousIssues:D,resolvedOptions:b,syncOnUpdate:v,syncOnValidate:y})}function I(){A?.stop(),A=r(),A.run(()=>{j=F(),j.defineWatchState(),j.computeErrors()})}function L(){j?.stopWatching(),j=void 0,A?.stop(),A=void 0}function R(){k||(k=!0,I(),P=m(()=>f(b.disabled),e=>{e?L():I()}),f(b.disabled)&&s().then(()=>{L()}))}function z(){k&&(k=!1,P?.(),P=void 0,L())}let B,V=async()=>{try{let e=await(j??F()).computeErrors(!0);return B?.regle.value?.$touch(),{valid:!e.issues?.length,data:e.issues?x.value:e.value,errors:B?.regle.value?.$errors,issues:E.value}}catch(e){return Promise.reject(e)}};function H(){let e=a();!e||O.has(e)||(k||R(),O.add(e),l(()=>{O.delete(e),O.size||z()}))}let U=n(()=>f(b.disabled)??!1);return R(),B=t({scopeRules:n(()=>({})),state:x,options:b,schemaErrors:E,initialState:C,originalState:T,shortcuts:o,schemaMode:!0,onValidate:V,overrides:c}),H(),{r$:w(B.regle,U,()=>{B.regle.value||(H(),B.bindToCurrentScope())})}}return u}const F=P();function I(e,t){return e}function L(){function e(e,t){return t}return e}const R=L();function z({modifiers:e,shortcuts:t,overrides:n}){return{useRegleSchema:P({options:e,shortcuts:t,overrides:n}),inferSchema:L()}}const B=t=>{let{customStore:n,customUseRegle:r=F,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})},{useCollectScope:V,useScopedRegle:H}=e({customUseRegle:F}),U=V,W=H;export{B as createScopedUseRegleSchema,z as defineRegleSchemaConfig,R as inferSchema,U as useCollectSchemaScope,F as useRegleSchema,W as useScopedRegleSchema,I as withDeps};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.26.0",
3
+ "version": "1.27.0-beta.1",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "homepage": "https://reglejs.dev/",
6
6
  "license": "MIT",
@@ -36,22 +36,22 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@standard-schema/spec": "1.1.0",
39
- "type-fest": "5.6.0",
40
- "@regle/core": "1.26.0",
41
- "@regle/rules": "1.26.0"
39
+ "type-fest": "5.7.0",
40
+ "@regle/core": "1.27.0-beta.1",
41
+ "@regle/rules": "1.27.0-beta.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@total-typescript/ts-reset": "0.6.1",
45
45
  "@types/node": "24.12.4",
46
- "@typescript/native-preview": "7.0.0-dev.20260519.1",
46
+ "@typescript/native-preview": "7.0.0-dev.20260603.1",
47
47
  "@vue/test-utils": "2.4.10",
48
- "tsdown": "0.21.10",
49
- "type-fest": "5.6.0",
48
+ "tsdown": "0.22.1",
49
+ "type-fest": "5.7.0",
50
50
  "typescript": "6.0.3",
51
- "valibot": "1.4.0",
52
- "vitest": "4.1.6",
53
- "vue": "3.5.34",
54
- "vue-tsc": "3.2.7",
51
+ "valibot": "1.4.1",
52
+ "vitest": "4.1.8",
53
+ "vue": "3.5.35",
54
+ "vue-tsc": "3.3.3",
55
55
  "zod": "4.4.3"
56
56
  },
57
57
  "peerDependencies": {