@regle/schemas 1.2.0-beta.1 → 1.2.0-beta.2
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/README.md +17 -11
- package/dist/regle-schemas.d.ts +4 -4
- package/dist/regle-schemas.min.mjs +1 -1
- package/dist/regle-schemas.mjs +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,24 +5,30 @@
|
|
|
5
5
|
# Regle
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
Regle \ʁɛɡl\ (French word for 'rule'
|
|
8
|
+
Regle \ʁɛɡl\ (French word for 'rule') is a Typescript-first model-based validation library for Vue 3.
|
|
9
9
|
It's heavily inspired by Vuelidate.
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
## 📚 Documentation
|
|
12
13
|
|
|
13
14
|
[](https://reglejs.dev/)
|
|
14
15
|
|
|
15
16
|
## 🎮 Play with it
|
|
16
17
|
|
|
17
|
-
| Simple demo | Advanced Demo |
|
|
18
|
-
| ------------- | ------------- |
|
|
19
|
-
| [](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/simple-example?file=examples/simple-example/src/App.vue&configPath=examples/simple-example) |
|
|
18
|
+
| Playground | Simple demo | Advanced Demo |
|
|
19
|
+
| ------------- | ------------- | ------------- |
|
|
20
|
+
| <a target='_blank' href="https://play.reglejs.dev"><img width="180" src="https://raw.githubusercontent.com/victorgarciaesgi/regle/refs/heads/main/.github/images/regle-playground-button.svg" /></a> | [](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/simple-example?file=examples/simple-example/src/App.vue&configPath=examples/simple-example) | [](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/advanced-example?file=examples/advanced-example/src/App.vue&configPath=examples/advanced-example) |
|
|
20
21
|
|
|
21
22
|
## 🧰 Features
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
23
|
+
|
|
24
|
+
- ☁️ Headless
|
|
25
|
+
- ✅ Type safety
|
|
26
|
+
- 🧮 Model based
|
|
27
|
+
- 🧰 Modular
|
|
28
|
+
- 🔄 Async validation
|
|
29
|
+
- 🌐 Plug any i18n library
|
|
30
|
+
- 📗 Vuelidate compatible API
|
|
31
|
+
- Standard Schemas spec support
|
|
32
|
+
- 🦸♂️ [Zod](https://zod.dev/)
|
|
33
|
+
- 🤖 [Valibot](https://valibot.dev/)
|
|
34
|
+
- 🚢 [ArkType](https://arktype.io) 🚧
|
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -722,7 +722,7 @@ type PartialObjectDeep<ObjectType extends object, Options extends Required<Parti
|
|
|
722
722
|
|
|
723
723
|
interface RegleSchema<TState extends Record<string, any>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> {
|
|
724
724
|
/**
|
|
725
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display
|
|
725
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
726
726
|
*
|
|
727
727
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
728
728
|
*/
|
|
@@ -730,7 +730,7 @@ interface RegleSchema<TState extends Record<string, any>, TSchema extends Record
|
|
|
730
730
|
}
|
|
731
731
|
interface RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extends unknown, TShortcuts extends RegleShortcutDefinition = {}> {
|
|
732
732
|
/**
|
|
733
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display
|
|
733
|
+
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
734
734
|
*
|
|
735
735
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
736
736
|
*/
|
|
@@ -801,7 +801,7 @@ type RegleSchemaFieldStatus<TSchema extends unknown, TState = any, TShortcuts ex
|
|
|
801
801
|
* @public
|
|
802
802
|
*/
|
|
803
803
|
type RegleSchemaCollectionStatus<TSchema extends Record<string, any>, TState extends any[], TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleSchemaFieldStatus<TSchema, TState, TShortcuts>, '$errors' | '$silentErrors' | '$validate'> & {
|
|
804
|
-
/** Collection of status
|
|
804
|
+
/** Collection of status for every item in your collection. Each item will be a field you can access or iterate to display your elements. */
|
|
805
805
|
readonly $each: Array<InferRegleSchemaStatusType<NonNullable<TSchema>, ArrayElement<TState>, TShortcuts>>;
|
|
806
806
|
/** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
|
|
807
807
|
readonly $self: RegleSchemaFieldStatus<TSchema, TState, TShortcuts>;
|
|
@@ -811,7 +811,7 @@ type RegleSchemaCollectionStatus<TSchema extends Record<string, any>, TState ext
|
|
|
811
811
|
readonly $errors: RegleCollectionErrors<TSchema>;
|
|
812
812
|
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
813
813
|
readonly $silentErrors: RegleCollectionErrors<TSchema>;
|
|
814
|
-
/** 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). */
|
|
814
|
+
/** 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). */
|
|
815
815
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
816
816
|
} & ([TShortcuts['collections']] extends [never] ? {} : {
|
|
817
817
|
[K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useRootStorage}from'@regle/core';import {ref,computed,unref,isRef,watch}from'vue';function k(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){let t=e,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>f(a)))),r=="Map"&&(t=new Map([...e].map(a=>[f(a[0]),f(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,k(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=f(e[a]);}return t}function S(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e,t,r,a){var n,o;if(Array.isArray(t)&&(n=t.slice(0)),typeof t=="string"&&(n=t.split(".")),typeof t=="symbol"&&(n=[t]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");if(o=n.pop(),!o)return false;w(o);for(var s;s=n.shift();)if(w(s),isNaN(parseInt(s))?(typeof e[s]>"u"&&(e[s]={}),e=e[s]):((e.$each??=[])[s]={},e=e.$each[s]),!e||typeof e!="object")return false;return a?e[o]?e[o].$self=(e[o].$self??=[]).concat(r):e[o]={...e[o],$self:r}:Array.isArray(e[o])?e[o]=e[o].concat(r):e[o]=r,true}function b(e,t,r){if(!e)return r;var a,n;if(Array.isArray(t)&&(a=t.slice(0)),typeof t=="string"&&(a=t.split(".")),typeof t=="symbol"&&(a=[t]),!Array.isArray(a))throw new Error("props arg must be an array, a string or a symbol");for(;a.length;)if(n=a.shift(),!e||!n||(e=e[n],e===void 0))return r;return e}function w(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function g(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,o,s){let I=ref({}),p=computed(()=>unref(o)),A={...r,...s},M=computed(()=>!S(l.value)),l=isRef(n)?n:ref(n),C=ref(S(l.value)?{...f(l.value)}:f(l.value)),y=ref({}),T;if(!p.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function V(i){let u={};return i.issues&&i.issues.map(c=>{let x=c.path?.map(d=>typeof d=="object"?d.key:d.toString()).join(".")??"",h=c.path?.[c.path.length-1],B=(typeof h=="object"&&"value"in h?Array.isArray(h.value):false)||("type"in c?c.type==="array":false)||Array.isArray(b(l.value,x));return {path:x,message:c.message,isArray:B}}).forEach(c=>{v(u,c.path,[c.message],c.isArray);}),u}async function D(){let i=p.value["~standard"].validate(l.value);return i instanceof Promise&&(i=await i),M.value?y.value=i.issues?.map(u=>u.message)??[]:y.value=V(i),i}return watch([l,p],D,{deep:true,immediate:true}),T=async()=>{try{return {valid:!(await D()).issues?.length,data:l.value}}catch(i){return Promise.reject(i)}},{r$:useRootStorage({scopeRules:I,state:l,options:A,schemaErrors:y,initialState:C,shortcuts:t,schemaMode:true,onValidate:T}).regle}}return a}var P=g();function F(e,t){return e}function R(){function e(t,r){return r}return e}var E=R();function N({modifiers:e,shortcuts:t}){let r=g(e,t),a=R();return {useRegleSchema:r,inferSchema:a}}export{N as defineRegleSchemaConfig,E as inferSchema,P as useRegleSchema,F as withDeps};
|
|
1
|
+
import {useRootStorage}from'@regle/core';import {ref,computed,unref,isRef,watch}from'vue';function k(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){let t=e,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>f(a)))),r=="Map"&&(t=new Map([...e].map(a=>[f(a[0]),f(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,k(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=f(e[a]);}return t}function S(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e,t,r,a){var n,o;if(Array.isArray(t)&&(n=t.slice(0)),typeof t=="string"&&(n=t.split(".")),typeof t=="symbol"&&(n=[t]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");if(o=n.pop(),!o)return false;w(o);for(var s;s=n.shift();)if(w(s),isNaN(parseInt(s))?(typeof e[s]>"u"&&(e[s]={}),e=e[s]):((e.$each??=[])[s]={},e=e.$each[s]),!e||typeof e!="object")return false;return a?e[o]?e[o].$self=(e[o].$self??=[]).concat(r):e[o]={...e[o],$self:r}:Array.isArray(e[o])?e[o]=e[o].concat(r):e[o]=r,true}function b(e,t,r){if(!e)return r;var a,n;if(Array.isArray(t)&&(a=t.slice(0)),typeof t=="string"&&(a=t.split(".")),typeof t=="symbol"&&(a=[t]),!Array.isArray(a))throw new Error("props arg must be an array, a string or a symbol");for(;a.length;)if(n=a.shift(),!e||!n||(e=e[n],e===void 0))return r;return e}function w(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function g(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,silent:e?.silent,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,o,s){let I=ref({}),p=computed(()=>unref(o)),A={...r,...s},M=computed(()=>!S(l.value)),l=isRef(n)?n:ref(n),C=ref(S(l.value)?{...f(l.value)}:f(l.value)),y=ref({}),T;if(!p.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function V(i){let u={};return i.issues&&i.issues.map(c=>{let x=c.path?.map(d=>typeof d=="object"?d.key:d.toString()).join(".")??"",h=c.path?.[c.path.length-1],B=(typeof h=="object"&&"value"in h?Array.isArray(h.value):false)||("type"in c?c.type==="array":false)||Array.isArray(b(l.value,x));return {path:x,message:c.message,isArray:B}}).forEach(c=>{v(u,c.path,[c.message],c.isArray);}),u}async function D(){let i=p.value["~standard"].validate(l.value);return i instanceof Promise&&(i=await i),M.value?y.value=i.issues?.map(u=>u.message)??[]:y.value=V(i),i}return watch([l,p],D,{deep:true,immediate:true}),T=async()=>{try{return {valid:!(await D()).issues?.length,data:l.value}}catch(i){return Promise.reject(i)}},{r$:useRootStorage({scopeRules:I,state:l,options:A,schemaErrors:y,initialState:C,shortcuts:t,schemaMode:true,onValidate:T}).regle}}return a}var P=g();function F(e,t){return e}function R(){function e(t,r){return r}return e}var E=R();function N({modifiers:e,shortcuts:t}){let r=g(e,t),a=R();return {useRegleSchema:r,inferSchema:a}}export{N as defineRegleSchemaConfig,E as inferSchema,P as useRegleSchema,F as withDeps};
|
package/dist/regle-schemas.mjs
CHANGED
|
@@ -142,6 +142,7 @@ function createUseRegleSchemaComposable(options, shortcuts) {
|
|
|
142
142
|
autoDirty: options?.autoDirty,
|
|
143
143
|
lazy: options?.lazy,
|
|
144
144
|
rewardEarly: options?.rewardEarly,
|
|
145
|
+
silent: options?.silent,
|
|
145
146
|
clearExternalErrorsOnChange: options?.clearExternalErrorsOnChange
|
|
146
147
|
};
|
|
147
148
|
function useRegleSchema2(state, schema, options2) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.2",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"@regle/core": "1.2.0-beta.
|
|
8
|
-
"@regle/rules": "1.2.0-beta.
|
|
7
|
+
"@regle/core": "1.2.0-beta.2",
|
|
8
|
+
"@regle/rules": "1.2.0-beta.2"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"valibot": "^1.0.0",
|