File tree 2 files changed +7
-6
lines changed
2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " prisma-enum-validator-generator" ,
3
- "version" : " 0.0.5 " ,
3
+ "version" : " 0.0.6 " ,
4
4
"description" : " This will generate utility functions to validate enums in the Prisma schema file." ,
5
5
"main" : " ./dist/index.js" ,
6
6
"bin" : " ./dist/index.js" ,
Original file line number Diff line number Diff line change @@ -27,19 +27,21 @@ function parseEnums(dataModel: string) {
27
27
return name ;
28
28
} ) ?? [ ] ;
29
29
30
- console . log ( 'All enums' , enums ) ;
31
-
32
30
const enumUsage : any = { } ;
33
31
enums . forEach ( ( e ) => ( enumUsage [ e ] = 0 ) ) ;
34
32
33
+ const ignoreTokens = [ '@@' , '//' ] ;
34
+
35
35
for ( const modelString of modelStrings ?? [ ] ) {
36
36
const fieldsString = modelString . substring ( modelString . indexOf ( '{' ) ) . replace ( '{' , '' ) . replace ( '}' , '' ) . trim ( ) ;
37
37
const fields = fieldsString
38
38
. split ( '\n' )
39
39
. map ( ( f ) => f . trim ( ) )
40
- . filter ( ( f ) => ! f . startsWith ( '@@' ) ) ;
40
+ . filter ( ( f ) => f && ! ignoreTokens . some ( ( it ) => f . startsWith ( it ) ) ) ;
41
41
for ( const field of fields ) {
42
- const fieldType = field . split ( / \s / ) [ 1 ] ?? null ;
42
+ const tokens = field . split ( / \s / ) . filter ( Boolean ) ;
43
+
44
+ const fieldType = tokens [ 1 ] ?? null ;
43
45
44
46
if ( ! fieldType ) continue ;
45
47
@@ -84,7 +86,6 @@ export default async (options: GeneratorOptions) => {
84
86
85
87
const output = options . generator . output ?. value || `./prisma/enum-validators.${ isTs ? 'ts' : 'js' } ` ;
86
88
const enums = parseEnums ( options . datamodel ) ;
87
- console . log ( 'filtered' , enums ) ;
88
89
89
90
const fileContent = generateFileContent ( enums , isTs ) ;
90
91
You can’t perform that action at this time.
0 commit comments