@@ -18,7 +18,9 @@ import {
18
18
isArrayExpr ,
19
19
isInvocationExpr ,
20
20
isLiteralExpr ,
21
+ isNullExpr ,
21
22
isReferenceExpr ,
23
+ isStringLiteral ,
22
24
LiteralExpr ,
23
25
Model ,
24
26
NumberLiteral ,
@@ -35,6 +37,7 @@ import {
35
37
PluginOptions ,
36
38
resolved ,
37
39
resolvePath ,
40
+ ZModelCodeGenerator ,
38
41
} from '@zenstackhq/sdk' ;
39
42
import fs from 'fs' ;
40
43
import { writeFile } from 'fs/promises' ;
@@ -45,6 +48,7 @@ import { name } from '.';
45
48
import { getStringLiteral } from '../../language-server/validator/utils' ;
46
49
import telemetry from '../../telemetry' ;
47
50
import { execSync } from '../../utils/exec-utils' ;
51
+ import { getPackageJson } from '../../utils/pkg-utils' ;
48
52
import {
49
53
ModelFieldType ,
50
54
AttributeArg as PrismaAttributeArg ,
@@ -62,8 +66,6 @@ import {
62
66
PassThroughAttribute as PrismaPassThroughAttribute ,
63
67
SimpleField ,
64
68
} from './prisma-builder' ;
65
- import { ZModelCodeGenerator } from '@zenstackhq/sdk' ;
66
- import { getPackageJson } from '../../utils/pkg-utils' ;
67
69
68
70
const MODEL_PASSTHROUGH_ATTR = '@@prisma.passthrough' ;
69
71
const FIELD_PASSTHROUGH_ATTR = '@prisma.passthrough' ;
@@ -377,10 +379,15 @@ export default class PrismaSchemaGenerator {
377
379
return new PrismaFunctionCall (
378
380
resolved ( node . function ) . name ,
379
381
node . args . map ( ( arg ) => {
380
- if ( ! isLiteralExpr ( arg . value ) ) {
381
- throw new PluginError ( name , 'Function call argument must be literal' ) ;
382
- }
383
- return new PrismaFunctionCallArg ( arg . name , arg . value . value ) ;
382
+ const val = match ( arg . value )
383
+ . when ( isStringLiteral , ( v ) => `"${ v . value } "` )
384
+ . when ( isLiteralExpr , ( v ) => v . value . toString ( ) )
385
+ . when ( isNullExpr , ( ) => 'null' )
386
+ . otherwise ( ( ) => {
387
+ throw new PluginError ( name , 'Function call argument must be literal or null' ) ;
388
+ } ) ;
389
+
390
+ return new PrismaFunctionCallArg ( arg . name , val ) ;
384
391
} )
385
392
) ;
386
393
}
0 commit comments