@regle/schemas 1.8.5 → 1.9.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.
@@ -115,7 +115,7 @@ function getDotPath(obj, propsArg, defaultValue) {
115
115
  function prototypeCheck(prop) {
116
116
  if (prop == "__proto__" || prop == "constructor" || prop == "prototype") throw new Error("setting of prototype values not supported");
117
117
  }
118
- function merge(obj1, ...objs) {
118
+ function merge(_obj1, ..._objs) {
119
119
  var args = [].slice.call(arguments);
120
120
  var arg;
121
121
  var i = args.length;
@@ -159,27 +159,23 @@ function createUseRegleSchemaComposable(options, shortcuts) {
159
159
  if (!computedSchema.value?.["~standard"]) throw new Error(`Only "standard-schema" compatible libraries are supported`);
160
160
  function issuesToRegleErrors(result) {
161
161
  const output = {};
162
- if (result.issues) {
163
- const issues = result.issues.map((issue) => {
164
- let $path = issue.path?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
165
- const lastItem = issue.path?.[issue.path.length - 1];
166
- const lastItemKey = typeof lastItem === "object" ? lastItem.key : lastItem;
167
- const isArray = (typeof lastItem === "object" && "value" in lastItem ? Array.isArray(lastItem.value) : false) || ("type" in issue ? issue.type === "array" : false) || Array.isArray(getDotPath(processedState.value, $path));
168
- const isPrimitivesArray = !isArray && typeof lastItemKey === "number";
169
- if (isPrimitivesArray) $path = issue.path?.slice(0, issue.path.length - 1)?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
170
- return {
171
- ...issue,
172
- $path,
173
- isArray,
174
- $property: lastItemKey,
175
- $rule: "schema",
176
- $message: issue.message
177
- };
178
- });
179
- issues.forEach(({ isArray, $path,...issue }) => {
180
- setObjectError(output, $path, [issue], isArray);
181
- });
182
- }
162
+ if (result.issues) result.issues.map((issue) => {
163
+ let $path = issue.path?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
164
+ const lastItem = issue.path?.[issue.path.length - 1];
165
+ const lastItemKey = typeof lastItem === "object" ? lastItem.key : lastItem;
166
+ const isArray = (typeof lastItem === "object" && "value" in lastItem ? Array.isArray(lastItem.value) : false) || ("type" in issue ? issue.type === "array" : false) || Array.isArray(getDotPath(processedState.value, $path));
167
+ if (!isArray && typeof lastItemKey === "number") $path = issue.path?.slice(0, issue.path.length - 1)?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
168
+ return {
169
+ ...issue,
170
+ $path,
171
+ isArray,
172
+ $property: lastItemKey,
173
+ $rule: "schema",
174
+ $message: issue.message
175
+ };
176
+ }).forEach(({ isArray, $path,...issue }) => {
177
+ setObjectError(output, $path, [issue], isArray);
178
+ });
183
179
  return output;
184
180
  }
185
181
  async function computeErrors(isValidate = false) {
@@ -210,16 +206,17 @@ function createUseRegleSchemaComposable(options, shortcuts) {
210
206
  computeErrors();
211
207
  onValidate = async () => {
212
208
  try {
213
- const result = await computeErrors(true);
214
209
  return {
215
- valid: !result.issues?.length,
216
- data: processedState.value
210
+ valid: !(await computeErrors(true)).issues?.length,
211
+ data: processedState.value,
212
+ errors: {},
213
+ issues: {}
217
214
  };
218
215
  } catch (e) {
219
216
  return Promise.reject(e);
220
217
  }
221
218
  };
222
- const regle = useRootStorage({
219
+ return { r$: useRootStorage({
223
220
  scopeRules: computed(() => ({})),
224
221
  state: processedState,
225
222
  options: resolvedOptions,
@@ -229,8 +226,7 @@ function createUseRegleSchemaComposable(options, shortcuts) {
229
226
  shortcuts,
230
227
  schemaMode: true,
231
228
  onValidate
232
- });
233
- return { r$: regle.regle };
229
+ }).regle };
234
230
  }
235
231
  return useRegleSchema$1;
236
232
  }
@@ -273,7 +269,7 @@ const useRegleSchema = createUseRegleSchemaComposable();
273
269
  * useRegleSchema({name: ''}, schema)
274
270
  * ```
275
271
  */
276
- function withDeps(schema, depsArray) {
272
+ function withDeps(schema, _depsArray) {
277
273
  return schema;
278
274
  }
279
275
 
@@ -1 +1 @@
1
- import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(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 l(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 u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(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;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],c(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}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(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 m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(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 g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=d(C.value)?{...u(C.value)}:u(C.value),E=i({}),D;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function O(e){let t={};if(e.issues){let n=e.issues.map(e=>{let t=e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``,n=e.path?.[e.path.length-1],r=typeof n==`object`?n.key:n,i=(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(p(C.value,t)),a=!i&&typeof r==`number`;return a&&(t=e.path?.slice(0,e.path.length-1)?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``),{...e,$path:t,isArray:i,$property:r,$rule:`schema`,$message:e.message}});n.forEach(({isArray:e,$path:n,...r})=>{f(t,n,[r],e)})}return t}async function k(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?E.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:E.value=O(t),t.issues||(e&&b||!e&&y)&&(A?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,j()),t}let A;function j(){A=o([C,g],()=>k(),{deep:!0})}j(),k(),D=async()=>{try{let e=await k(!0);return{valid:!e.issues?.length,data:C.value}}catch(e){return Promise.reject(e)}};let M=t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:E,initialState:w,originalState:T,shortcuts:s,schemaMode:!0,onValidate:D});return{r$:M.regle}}return l}const _=g();function v(e,t){return e}function y(){function e(e,t){return t}return e}const b=y();function x({modifiers:e,shortcuts:t}){let n=g(e,t),r=y();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:S,useScopedRegle:C}=e({customUseRegle:_}),w=t=>{let{customStore:n,customUseRegle:r=_,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{w as createScopedUseRegleSchema,x as defineRegleSchemaConfig,b as inferSchema,S as useCollectSchemaScope,_ as useRegleSchema,C as useScopedRegleSchema,v as withDeps};
1
+ import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(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 l(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 u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(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;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],c(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}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(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 m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(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 g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=d(C.value)?{...u(C.value)}:u(C.value),E=i({}),D;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function O(e){let t={};return e.issues&&e.issues.map(e=>{let t=e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``,n=e.path?.[e.path.length-1],r=typeof n==`object`?n.key:n,i=(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(p(C.value,t));return!i&&typeof r==`number`&&(t=e.path?.slice(0,e.path.length-1)?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``),{...e,$path:t,isArray:i,$property:r,$rule:`schema`,$message:e.message}}).forEach(({isArray:e,$path:n,...r})=>{f(t,n,[r],e)}),t}async function k(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?E.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:E.value=O(t),t.issues||(e&&b||!e&&y)&&(A?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,j()),t}let A;function j(){A=o([C,g],()=>k(),{deep:!0})}return j(),k(),D=async()=>{try{return{valid:!(await k(!0)).issues?.length,data:C.value,errors:{},issues:{}}}catch(e){return Promise.reject(e)}},{r$:t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:E,initialState:w,originalState:T,shortcuts:s,schemaMode:!0,onValidate:D}).regle}}return l}const _=g();function v(e,t){return e}function y(){function e(e,t){return t}return e}const b=y();function x({modifiers:e,shortcuts:t}){let n=g(e,t),r=y();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:S,useScopedRegle:C}=e({customUseRegle:_}),w=t=>{let{customStore:n,customUseRegle:r=_,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{w as createScopedUseRegleSchema,x as defineRegleSchemaConfig,b as inferSchema,S as useCollectSchemaScope,_ as useRegleSchema,C as useScopedRegleSchema,v as withDeps};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.8.5",
3
+ "version": "1.9.0-beta.1",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/core": "1.8.5",
8
- "@regle/rules": "1.8.5"
7
+ "@regle/core": "1.9.0-beta.1",
8
+ "@regle/rules": "1.9.0-beta.1"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",
@@ -25,23 +25,17 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@total-typescript/ts-reset": "0.6.1",
28
- "@types/node": "22.18.0",
29
- "@typescript-eslint/eslint-plugin": "8.42.0",
30
- "@typescript-eslint/parser": "8.42.0",
28
+ "@types/node": "22.13.14",
31
29
  "@vue/test-utils": "2.4.6",
32
- "eslint": "9.34.0",
33
- "eslint-config-prettier": "10.1.8",
34
- "eslint-plugin-vue": "10.4.0",
35
30
  "prettier": "3.6.2",
36
- "tsdown": "0.14.2",
37
- "type-fest": "4.41.0",
31
+ "tsdown": "0.15.2",
32
+ "type-fest": "5.0.0",
38
33
  "typescript": "5.9.2",
39
34
  "valibot": "1.1.0",
40
35
  "vitest": "3.2.4",
41
36
  "vue": "3.5.21",
42
- "vue-eslint-parser": "10.2.0",
43
- "vue-tsc": "3.0.6",
44
- "zod": "4.1.5"
37
+ "vue-tsc": "3.0.7",
38
+ "zod": "4.1.9"
45
39
  },
46
40
  "type": "module",
47
41
  "exports": {
@@ -85,8 +79,6 @@
85
79
  "build": "tsdown",
86
80
  "build:sourcemaps": "tsdown --config=tsdown.sourcemap.ts",
87
81
  "dev": "tsdown --config=tsdown.dev.ts --watch",
88
- "test": "echo 'no tests'",
89
- "lint": "eslint src/**/*.ts",
90
- "lint:fix": "eslint src/**/*.ts --fix"
82
+ "test": "echo 'no tests'"
91
83
  }
92
84
  }