@regle/schemas 1.8.0-beta.1 → 1.8.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 +22 -5
- package/dist/regle-schemas.js +2 -0
- package/dist/regle-schemas.min.js +1 -1
- package/package.json +11 -11
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1185,11 +1185,21 @@ type InferDeepReactiveState<TState> = NonNullable<TState> extends Array<infer U
|
|
|
1185
1185
|
//#region src/types/core/reset.types.d.ts
|
|
1186
1186
|
type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
1187
1187
|
/**
|
|
1188
|
-
* Reset validation status and reset form state to its initial state
|
|
1188
|
+
* Reset validation status and reset form state to its initial state.
|
|
1189
|
+
*
|
|
1190
|
+
* Initial state is different than the original state as the initial state can be mutated when using `$reset`.
|
|
1191
|
+
*
|
|
1192
|
+
* This serve as the base comparison state for `$edited` property.
|
|
1189
1193
|
*
|
|
1190
1194
|
* ⚠️ This doesn't work if the state is a `reactive` object.
|
|
1191
1195
|
*/
|
|
1192
1196
|
toInitialState?: boolean;
|
|
1197
|
+
/**
|
|
1198
|
+
* Reset validation status and reset form state to its original state.
|
|
1199
|
+
*
|
|
1200
|
+
* Original state is the unmutated state that was passed to the form when it was initialized.
|
|
1201
|
+
*/
|
|
1202
|
+
toOriginalState?: boolean;
|
|
1193
1203
|
/**
|
|
1194
1204
|
* Reset validation status and reset form state to the given state
|
|
1195
1205
|
* Also set the new state as the initial state.
|
|
@@ -1346,8 +1356,8 @@ interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortc
|
|
|
1346
1356
|
*
|
|
1347
1357
|
* Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
|
|
1348
1358
|
*/
|
|
1349
|
-
type DeepExact<
|
|
1350
|
-
type ExactObject<
|
|
1359
|
+
type DeepExact<TInfer, TTree> = NonNullable<TTree> extends MaybeRef<RegleRuleDecl> ? TTree : NonNullable<TTree> extends MaybeRef<RegleCollectionRuleDecl> ? TTree : [keyof TInfer] extends [keyof ExtractFromGetter<TTree>] ? ExactObject<TInfer, TTree> : { [K in keyof TInfer as K extends keyof TTree ? never : K]: TypeError<`Unknown property: <${Coerce<K>}>`> };
|
|
1360
|
+
type ExactObject<TInfer, TTree> = { [K in keyof TTree]: NonNullable<TTree[K]> extends Record<string, any> ? ExtendOnlyRealRecord<TTree[K]> extends true ? NonNullable<TTree[K]> extends MaybeRef<RegleRuleDecl> ? TTree[K] : K extends keyof TInfer ? DeepExact<TInfer[K], NonNullable<TTree[K]>> : TTree[K] : TTree[K] : TTree[K] };
|
|
1351
1361
|
type TypeError<Msg> = {
|
|
1352
1362
|
[' TypeError']: Msg;
|
|
1353
1363
|
};
|
|
@@ -1818,10 +1828,17 @@ interface RegleCommonStatus<TValue = any> {
|
|
|
1818
1828
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
1819
1829
|
$value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1820
1830
|
/**
|
|
1821
|
-
*
|
|
1831
|
+
* This value reflect the current initial value of the field.
|
|
1832
|
+
* The initial value is different than the original value as the initial value can be mutated when using `$reset`.
|
|
1822
1833
|
*/
|
|
1823
1834
|
readonly $initialValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1824
|
-
/**
|
|
1835
|
+
/**
|
|
1836
|
+
* This value reflect the original value of the field at original call. This can't be mutated
|
|
1837
|
+
*/
|
|
1838
|
+
readonly $originalValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1839
|
+
/**
|
|
1840
|
+
* `$value` variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction.
|
|
1841
|
+
* */
|
|
1825
1842
|
$silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
|
|
1826
1843
|
/** Marks the field and all nested properties as $dirty. */
|
|
1827
1844
|
$touch(): void;
|
package/dist/regle-schemas.js
CHANGED
|
@@ -156,6 +156,7 @@ function createUseRegleSchemaComposable(options, shortcuts) {
|
|
|
156
156
|
const isSingleField = computed(() => !isObject(processedState.value));
|
|
157
157
|
const processedState = isRef(state) ? state : ref(state);
|
|
158
158
|
const initialState = ref(isObject(processedState.value) ? { ...cloneDeep(processedState.value) } : cloneDeep(processedState.value));
|
|
159
|
+
const originalState = isObject(processedState.value) ? { ...cloneDeep(processedState.value) } : cloneDeep(processedState.value);
|
|
159
160
|
const customErrors = ref({});
|
|
160
161
|
let onValidate = void 0;
|
|
161
162
|
if (!computedSchema.value?.["~standard"]) throw new Error(`Only "standard-schema" compatible libraries are supported`);
|
|
@@ -227,6 +228,7 @@ function createUseRegleSchemaComposable(options, shortcuts) {
|
|
|
227
228
|
options: resolvedOptions,
|
|
228
229
|
schemaErrors: customErrors,
|
|
229
230
|
initialState,
|
|
231
|
+
originalState,
|
|
230
232
|
shortcuts,
|
|
231
233
|
schemaMode: true,
|
|
232
234
|
onValidate
|
|
@@ -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}
|
|
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]={...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};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.8.0
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"@regle/
|
|
8
|
-
"@regle/
|
|
7
|
+
"@regle/rules": "1.8.0",
|
|
8
|
+
"@regle/core": "1.8.0"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"valibot": "^1.0.0",
|
|
@@ -25,23 +25,23 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@total-typescript/ts-reset": "0.6.1",
|
|
28
|
-
"@types/node": "22.
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
30
|
-
"@typescript-eslint/parser": "8.
|
|
28
|
+
"@types/node": "22.18.0",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "8.42.0",
|
|
30
|
+
"@typescript-eslint/parser": "8.42.0",
|
|
31
31
|
"@vue/test-utils": "2.4.6",
|
|
32
|
-
"eslint": "9.
|
|
32
|
+
"eslint": "9.34.0",
|
|
33
33
|
"eslint-config-prettier": "10.1.8",
|
|
34
34
|
"eslint-plugin-vue": "10.4.0",
|
|
35
35
|
"prettier": "3.6.2",
|
|
36
|
-
"tsdown": "0.14.
|
|
36
|
+
"tsdown": "0.14.2",
|
|
37
37
|
"type-fest": "4.41.0",
|
|
38
38
|
"typescript": "5.9.2",
|
|
39
39
|
"valibot": "1.1.0",
|
|
40
40
|
"vitest": "3.2.4",
|
|
41
|
-
"vue": "3.5.
|
|
41
|
+
"vue": "3.5.21",
|
|
42
42
|
"vue-eslint-parser": "10.2.0",
|
|
43
|
-
"vue-tsc": "3.0.
|
|
44
|
-
"zod": "4.
|
|
43
|
+
"vue-tsc": "3.0.6",
|
|
44
|
+
"zod": "4.1.5"
|
|
45
45
|
},
|
|
46
46
|
"type": "module",
|
|
47
47
|
"exports": {
|