File tree Expand file tree Collapse file tree 14 files changed +350
-5
lines changed Expand file tree Collapse file tree 14 files changed +350
-5
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " @vue-hooks-form/class-validator" ,
3+ "version" : " 0.0.0" ,
4+ "type" : " module" ,
5+ "description" : " class-validator resolver for vue-hooks-form" ,
6+ "keywords" : [
7+ " class-validator" ,
8+ " vue-hooks-form" ,
9+ " vue-hooks-form-resolver" ],
10+ "license" : " MIT" ,
11+ "author" : " Elone Hoo <hi@gmail.com>" ,
12+ "main" : " ./dist/index.js" ,
13+ "module" : " ./dist/index.cjs" ,
14+ "types" : " ./dist/index.d.ts" ,
15+ "exports" : {
16+ "." : {
17+ "require" : " ./dist/index.js" ,
18+ "import" : " ./dist/index.cjs"
19+ }
20+ },
21+ "files" : [
22+ " dist"
23+ ],
24+ "scripts" : {
25+ "build" : " tsup" ,
26+ "dev" : " tsup --watch src" ,
27+ "build:fix" : " esno scripts/postbuild.ts"
28+ },
29+ "peerDependencies" : {
30+ "class-transformer" : " ^0.4.0" ,
31+ "class-validator" : " ^0.12.0" ,
32+ "@vue-hooks-form/core" : " workspace:*"
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ import { basename , dirname , resolve } from 'path'
2+ import { promises as fs } from 'fs'
3+ import { fileURLToPath } from 'url'
4+ import fg from 'fast-glob'
5+ import chalk from 'chalk'
6+
7+ async function run ( ) {
8+ // fix cjs exports
9+ const files = await fg ( '*.cjs' , {
10+ ignore : [ 'chunk-*' ] ,
11+ absolute : true ,
12+ cwd : resolve ( dirname ( fileURLToPath ( import . meta. url ) ) , '../dist' ) ,
13+ } )
14+ for ( const file of files ) {
15+ console . log ( chalk . cyan . inverse ( ' POST ' ) , `Fix ${ basename ( file ) } ` )
16+ let code = await fs . readFile ( file , 'utf8' )
17+ code = code . replace ( 'exports.default =' , 'module.exports =' )
18+ code += 'exports.default = module.exports;'
19+ await fs . writeFile ( file , code )
20+ }
21+ }
22+
23+ run ( )
Original file line number Diff line number Diff line change 1+ import type { ValidationError , ValidatorOptions } from 'class-validator'
2+ import { validate } from 'class-validator'
3+ import { plainToClass } from 'class-transformer'
4+ import type { FieldError } from '@vue-hooks-form/core/src/types/errors'
5+
6+ async function getErrors (
7+ instance : object ,
8+ options : ValidatorOptions ,
9+ ) {
10+ const errors = await validate ( instance , options ) as ValidationError [ ]
11+
12+ const res = { } as any
13+
14+ errors . forEach ( ( error ) => {
15+ const validateErrors = error . constraints || { }
16+ const errName = Object . keys ( validateErrors as any ) [ 0 ]
17+ const errMessage = validateErrors [ errName ]
18+ res [ error . property ] = { type : errName , message : errMessage }
19+ } )
20+
21+ return res
22+ }
23+
24+ export function useClassValidator (
25+ ClassResolver : new ( ...args : any [ ] ) => any ,
26+ resolverOptions : ValidatorOptions = { } ,
27+ ) {
28+ return async (
29+ values : Record < string , any > ,
30+ ) : Promise < FieldError > => {
31+ const schema = plainToClass ( ClassResolver , values )
32+
33+ const errors = await getErrors ( schema , resolverOptions )
34+
35+ return errors || { }
36+ }
37+ }
38+
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "target" : " ESNext" ,
4+ "useDefineForClassFields" : true ,
5+ "module" : " ESNext" ,
6+ "lib" : [" ESNext" , " DOM" ],
7+ "moduleResolution" : " Node" ,
8+ "strict" : true ,
9+ "sourceMap" : true ,
10+ "resolveJsonModule" : true ,
11+ "isolatedModules" : true ,
12+ "esModuleInterop" : true ,
13+ "noEmit" : true ,
14+ "noUnusedLocals" : true ,
15+ "noUnusedParameters" : true ,
16+ "noImplicitReturns" : true ,
17+ "skipLibCheck" : true
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ import type { Options } from 'tsup'
2+
3+ export default < Options > {
4+ entryPoints : [
5+ 'src/*.ts' ,
6+ ] ,
7+ clean : true ,
8+ format : [ 'cjs' , 'esm' ] ,
9+ dts : true ,
10+ onSuccess : 'npm run build:fix' ,
11+ }
Original file line number Diff line number Diff line change 11{
2- "name" : " vue-hooks-form" ,
2+ "name" : " @ vue-hooks-form/core " ,
33 "type" : " module" ,
44 "version" : " 0.0.0" ,
55 "description" : " Vue Composition API for validating form." ,
Original file line number Diff line number Diff line change @@ -31,10 +31,14 @@ export type UseFieldArrayRemove = (id: number | number[]) => void
3131export type UseFieldArraySwap = ( from : number , to : number ) => void
3232
3333export interface UseFieldArrayReturn < FieldValues > {
34+ //@ts -ignore
3435 insert : UseFieldArrayInsert < FieldValues [ ] >
3536 remove : UseFieldArrayRemove
37+ //@ts -ignore
3638 prepend : UseFieldArrayPrepend < FieldValues [ ] >
39+ //@ts -ignore
3740 append : UseFieldArrayAppend < FieldValues [ ] >
3841 swap : UseFieldArraySwap
42+ //@ts -ignore
3943 fields : UseFieldArrayField < FieldValues > [ ]
4044}
Original file line number Diff line number Diff line change @@ -123,9 +123,13 @@ export interface UseFormHandlers<
123123 clearErrors : UseFormClearErrors < FieldName >
124124 setValue : UseFormSetValue < TFieldValues , keyof TFieldValues >
125125 triggerValidate : UseFormTriggerValidate < FieldName >
126+ //@ts -ignore
126127 reset : UseFormReset < TFieldValues >
128+ //@ts -ignore
127129 handleSubmit : UseFormHandleSubmit < TFieldValues >
130+ //@ts -ignore
128131 unregister : UseFormUnregister < TFieldValues >
132+ //@ts -ignore
129133 register : UseFormRegister < TFieldValues >
130134 setFocus : UseFormSetFocus < TFieldValues >
131135 isExistInErrors : UseFormIsExistInErrors < TFieldValues >
@@ -146,6 +150,7 @@ export type UseFormReturn<TFieldValues extends FieldValues> = {
146150
147151export interface FormState < TFieldValues > {
148152 isDirty : boolean
153+ //@ts -ignore
149154 dirtyFields : FieldNamesMarkedBoolean < TFieldValues >
150155 isSubmitted : boolean
151156 isSubmitSuccessful : boolean
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " @vue-hooks-form/yup" ,
3+ "version" : " 0.0.0" ,
4+ "type" : " module" ,
5+ "description" : " yup resolver for vue-hooks-form" ,
6+ "keywords" : [
7+ " yup" ,
8+ " vue-hooks-form" ,
9+ " vue-hooks-form-resolver"
10+ ],
11+ "license" : " MIT" ,
12+ "author" : " Elone Hoo <hi@elonehoo.me>" ,
13+ "main" : " ./dist/index.js" ,
14+ "module" : " ./dist/index.cjs" ,
15+ "types" : " ./dist/index.d.ts" ,
16+ "exports" : {
17+ "." : {
18+ "require" : " ./dist/index.js" ,
19+ "import" : " ./dist/index.cjs"
20+ }
21+ },
22+ "files" : [
23+ " dist"
24+ ],
25+ "scripts" : {
26+ "build" : " tsup" ,
27+ "dev" : " tsup --watch src" ,
28+ "build:fix" : " esno scripts/postbuild.ts"
29+ },
30+ "peerDependencies" : {
31+ "@vue-hooks-form/core" : " workspace:*" ,
32+ "yup" : " >=0.32.11"
33+ },
34+ "dependencies" : {
35+ "@vue-hooks-form/core" : " workspace:*" ,
36+ "yup" : " ^0.32.11"
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ import { basename , dirname , resolve } from 'path'
2+ import { promises as fs } from 'fs'
3+ import { fileURLToPath } from 'url'
4+ import fg from 'fast-glob'
5+ import chalk from 'chalk'
6+
7+ async function run ( ) {
8+ // fix cjs exports
9+ const files = await fg ( '*.cjs' , {
10+ ignore : [ 'chunk-*' ] ,
11+ absolute : true ,
12+ cwd : resolve ( dirname ( fileURLToPath ( import . meta. url ) ) , '../dist' ) ,
13+ } )
14+ for ( const file of files ) {
15+ console . log ( chalk . cyan . inverse ( ' POST ' ) , `Fix ${ basename ( file ) } ` )
16+ let code = await fs . readFile ( file , 'utf8' )
17+ code = code . replace ( 'exports.default =' , 'module.exports =' )
18+ code += 'exports.default = module.exports;'
19+ await fs . writeFile ( file , code )
20+ }
21+ }
22+
23+ run ( )
You can’t perform that action at this time.
0 commit comments