@regle/schemas 1.15.2 → 1.16.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,7 +1,11 @@
1
- import * as _regle_core0 from "@regle/core";
2
- import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepPartial, DeepReactiveState, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeOutput, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, RegleStaticImpl, TupleToPlainObj, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
3
- import * as vue0 from "vue";
4
- import { MaybeRef, Raw, UnwrapNestedRefs } from "vue";
1
+ /**
2
+ * @regle/schemas v1.16.0
3
+ * (c) 2025 Victor Garcia
4
+ * @license MIT
5
+ */
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";
8
+ import { MaybeRef, MaybeRefOrGetter, Raw, UnwrapNestedRefs } from "vue";
5
9
  import { StandardSchemaV1 } from "@standard-schema/spec";
6
10
  import { EmptyObject, IsUnion, UnionToTuple } from "type-fest";
7
11
  type MaybeSchemaVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, TRoot extends boolean = false> = IsUnion<NonNullable<TState>> extends true ? Omit<RegleSchemaStatus<TState, TSchema, TShortcuts, TRoot>, '$fields'> & {
@@ -295,9 +299,6 @@ type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any
295
299
  */
296
300
  customUseRegle?: TCustomRegle;
297
301
  };
298
- declare const useCollectSchemaScope: <TValue$1 extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: vue0.MaybeRefOrGetter<string | string[]>) => {
299
- r$: _regle_core0.MergedScopedRegles<TValue$1>;
300
- }, useScopedRegleSchema: useRegleSchemaFn<_regle_core0.RegleShortcutDefinition<any>, {}, {}>;
301
302
  /**
302
303
  * Create a scoped validation system for schema-based validation.
303
304
  * Similar to `createScopedUseRegle` but for use with Standard Schema libraries.
@@ -331,6 +332,10 @@ declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn
331
332
  useScopedRegle: TReturnedRegle;
332
333
  useCollectScope: useCollectScopeFn<TAsRecord>;
333
334
  };
335
+ declare const useCollectSchemaScope: <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string | string[]>) => {
336
+ r$: MergedScopedRegles<TValue>;
337
+ };
338
+ declare const useScopedRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>, {}, {}>;
334
339
  declare module '@regle/core' {
335
340
  interface NarrowVariantExtracts {
336
341
  'regle-schemas-status': RegleSchemaStatus<any, any>;
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @regle/schemas v1.16.0
3
+ * (c) 2025 Victor Garcia
4
+ * @license MIT
5
+ */
6
+
1
7
  import { createScopedUseRegle, useRootStorage } from "@regle/core";
2
8
  import { computed, getCurrentScope, isRef, onScopeDispose, ref, unref, watch } from "vue";
3
9
 
@@ -50,16 +56,13 @@ function isEmpty(value, considerEmptyArrayInvalid = true) {
50
56
  }
51
57
 
52
58
  function getRegExpFlags(regExp) {
53
- if (typeof regExp.source.flags == "string") return regExp.source.flags;
54
- else {
55
- let flags = [];
56
- regExp.global && flags.push("g");
57
- regExp.ignoreCase && flags.push("i");
58
- regExp.multiline && flags.push("m");
59
- regExp.sticky && flags.push("y");
60
- regExp.unicode && flags.push("u");
61
- return flags.join("");
62
- }
59
+ let flags = [];
60
+ regExp.global && flags.push("g");
61
+ regExp.ignoreCase && flags.push("i");
62
+ regExp.multiline && flags.push("m");
63
+ regExp.sticky && flags.push("y");
64
+ regExp.unicode && flags.push("u");
65
+ return flags.join("");
63
66
  }
64
67
  function cloneDeep(obj, dep = 0) {
65
68
  if (dep > 20) return obj;
@@ -461,7 +464,6 @@ function defineRegleSchemaConfig({ modifiers, shortcuts }) {
461
464
  };
462
465
  }
463
466
 
464
- const { useCollectScope: useCollectSchemaScope, useScopedRegle: useScopedRegleSchema } = createScopedUseRegle({ customUseRegle: useRegleSchema });
465
467
  /**
466
468
  * Create a scoped validation system for schema-based validation.
467
469
  * Similar to `createScopedUseRegle` but for use with Standard Schema libraries.
@@ -493,5 +495,8 @@ const createScopedUseRegleSchema = (options) => {
493
495
  asRecord
494
496
  });
495
497
  };
498
+ const { useCollectScope: _useCollectSchemaScope, useScopedRegle: _useScopedRegleSchema } = createScopedUseRegle({ customUseRegle: useRegleSchema });
499
+ const useCollectSchemaScope = _useCollectSchemaScope;
500
+ const useScopedRegleSchema = _useScopedRegleSchema;
496
501
 
497
502
  export { createScopedUseRegleSchema, defineRegleSchemaConfig, inferSchema, useCollectSchemaScope, useRegleSchema, useScopedRegleSchema, withDeps };
@@ -1 +1,7 @@
1
- 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){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 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,l){let u={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function d(e,d,g){let v=n(()=>s(d)),{syncState:y={onUpdate:!1,onValidate:!1},...b}=g??{},{onUpdate:x=!1,onValidate:S=!1}=y,C={...u,...b},w=n(()=>!p(T.value)),T=i(e)?e:o(e),E=o(p(T.value)?{...f(T.value)}:f(T.value)),D=p(T.value)?{...f(T.value)}:f(T.value),O=o({}),k=o([]),A;function j(e){let t=M(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(T.value,t)),$path:t,lastItemKey:r,lastItem:n}}function M(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function N(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function P(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(!v.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function F(e,t=!1){return!t&&C.rewardEarly?k.value.length?k.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&p(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=N(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&N(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>M(e)===M(n))&&t.push(n);return t},[]):[]:e}function I(e,t=!1){let n={},r=e.issues?.map(e=>{let t=P(e);if(t){let n=h(T.value,M(t));Object.defineProperty(e,`$currentArrayValue`,{value:n,enumerable:!0,configurable:!0,writable:!0})}return e}),i=F(r??[],t);if(r?.length){let e=i.map(e=>{let{isArray:t,$path:n,lastItemKey:r}=j(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)}),k.value=e}else k.value=[];return n}async function L(e=!1){let t=v.value[`~standard`].validate(T.value);return t instanceof Promise&&(t=await t),w.value?O.value=F(t.issues??[],e)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:O.value=I(t,e),t.issues||(e&&S||!e&&x)&&(R?.(),p(T.value)?T.value=_(T.value,t.value):T.value=t.value,z()),t}let R;function z(){R=c([T,v],()=>{C.silent||L()},{deep:!0})}z(),L(),A=async()=>{try{let e=await L(!0);return B?.regle?.$touch(),{valid:!e.issues?.length,data:T.value,errors:B?.regle?.$errors,issues:O.value}}catch(e){return Promise.reject(e)}},r()&&a(()=>{R()});let B=t({scopeRules:n(()=>({})),state:T,options:C,schemaErrors:O,initialState:E,originalState:D,shortcuts:l,schemaMode:!0,onValidate:A});return{r$:B.regle}}return d}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}){return{useRegleSchema:v(e,t),inferSchema:x()}}const{useCollectScope:w,useScopedRegle:T}=e({customUseRegle:y}),E=t=>{let{customStore:n,customUseRegle:r=y,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{E as createScopedUseRegleSchema,C as defineRegleSchemaConfig,S as inferSchema,w as useCollectSchemaScope,y as useRegleSchema,T as useScopedRegleSchema,b as withDeps};
1
+ /**
2
+ * @regle/schemas v1.16.0
3
+ * (c) 2025 Victor Garcia
4
+ * @license MIT
5
+ */
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,l){let u={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function d(e,d,g){let v=n(()=>s(d)),{syncState:y={onUpdate:!1,onValidate:!1},...b}=g??{},{onUpdate:x=!1,onValidate:S=!1}=y,C={...u,...b},w=n(()=>!p(T.value)),T=i(e)?e:o(e),E=o(p(T.value)?{...f(T.value)}:f(T.value)),D=p(T.value)?{...f(T.value)}:f(T.value),O=o({}),k=o([]),A;function j(e){let t=M(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(T.value,t)),$path:t,lastItemKey:r,lastItem:n}}function M(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function N(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function P(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(!v.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function F(e,t=!1){return!t&&C.rewardEarly?k.value.length?k.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&p(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=N(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&N(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>M(e)===M(n))&&t.push(n);return t},[]):[]:e}function I(e,t=!1){let n={},r=e.issues?.map(e=>{let t=P(e);if(t){let n=h(T.value,M(t));Object.defineProperty(e,`$currentArrayValue`,{value:n,enumerable:!0,configurable:!0,writable:!0})}return e}),i=F(r??[],t);if(r?.length){let e=i.map(e=>{let{isArray:t,$path:n,lastItemKey:r}=j(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)}),k.value=e}else k.value=[];return n}async function L(e=!1){let t=v.value[`~standard`].validate(T.value);return t instanceof Promise&&(t=await t),w.value?O.value=F(t.issues??[],e)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:O.value=I(t,e),t.issues||(e&&S||!e&&x)&&(R?.(),p(T.value)?T.value=_(T.value,t.value):T.value=t.value,z()),t}let R;function z(){R=c([T,v],()=>{C.silent||L()},{deep:!0})}z(),L(),A=async()=>{try{let e=await L(!0);return B?.regle?.$touch(),{valid:!e.issues?.length,data:T.value,errors:B?.regle?.$errors,issues:O.value}}catch(e){return Promise.reject(e)}},r()&&a(()=>{R()});let B=t({scopeRules:n(()=>({})),state:T,options:C,schemaErrors:O,initialState:E,originalState:D,shortcuts:l,schemaMode:!0,onValidate:A});return{r$:B.regle}}return d}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}){return{useRegleSchema:v(e,t),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.15.2",
3
+ "version": "1.16.0",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
- "@standard-schema/spec": "1.0.0",
7
- "type-fest": "5.2.0",
8
- "@regle/core": "1.15.2",
9
- "@regle/rules": "1.15.2"
6
+ "@standard-schema/spec": "1.1.0",
7
+ "type-fest": "5.3.1",
8
+ "@regle/core": "1.16.0",
9
+ "@regle/rules": "1.16.0"
10
10
  },
11
11
  "peerDependencies": {
12
12
  "valibot": "^1.0.0",
@@ -26,17 +26,17 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@total-typescript/ts-reset": "0.6.1",
29
- "@types/node": "22.19.1",
29
+ "@types/node": "22.19.3",
30
30
  "@vue/test-utils": "2.4.6",
31
- "prettier": "3.7.3",
32
- "tsdown": "0.16.8",
33
- "type-fest": "5.2.0",
31
+ "prettier": "3.7.4",
32
+ "tsdown": "0.18.3",
33
+ "type-fest": "5.3.1",
34
34
  "typescript": "5.9.3",
35
35
  "valibot": "1.2.0",
36
- "vitest": "4.0.13",
37
- "vue": "3.5.25",
38
- "vue-tsc": "3.1.5",
39
- "zod": "4.1.13"
36
+ "vitest": "4.0.16",
37
+ "vue": "3.5.26",
38
+ "vue-tsc": "3.2.1",
39
+ "zod": "4.2.1"
40
40
  },
41
41
  "type": "module",
42
42
  "exports": {