File tree Expand file tree Collapse file tree 2 files changed +65
-1
lines changed Expand file tree Collapse file tree 2 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -360,4 +360,66 @@ model User extends Base {
360
360
expect ( schema . enums ) . toMatchObject ( { Role : expect . any ( Object ) } ) ;
361
361
expect ( schema . models ) . toMatchObject ( { User : expect . any ( Object ) } ) ;
362
362
} ) ;
363
+
364
+ it ( 'generates correct default literal function arguments' , async ( ) => {
365
+ const { schema } = await generateTsSchema ( `
366
+ model User {
367
+ id String @id @default(uuid(7))
368
+ }
369
+ ` ) ;
370
+
371
+ expect ( schema . models ) . toMatchObject ( {
372
+ User : {
373
+ name : "User" ,
374
+ fields : {
375
+ id : {
376
+ name : "id" ,
377
+ type : "String" ,
378
+ id : true ,
379
+ attributes : [
380
+ {
381
+ name : "@id"
382
+ } ,
383
+ {
384
+ name : "@default" ,
385
+ args : [
386
+ {
387
+ name : "value" ,
388
+ value : {
389
+ kind : "call" ,
390
+ function : "uuid" ,
391
+ args : [
392
+ {
393
+ kind : "literal" ,
394
+ value : 7
395
+ }
396
+ ]
397
+ }
398
+ }
399
+ ]
400
+ }
401
+ ] ,
402
+ default : {
403
+ kind : "call" ,
404
+ function : "uuid" ,
405
+ args : [
406
+ {
407
+ kind : "literal" ,
408
+ value : 7
409
+ }
410
+ ]
411
+ }
412
+ }
413
+ } ,
414
+ idFields : [
415
+ "id"
416
+ ] ,
417
+ uniqueFields : {
418
+ id : {
419
+ type : "String"
420
+ }
421
+ }
422
+ }
423
+ } ) ;
424
+ } ) ;
363
425
} ) ;
Original file line number Diff line number Diff line change @@ -507,7 +507,9 @@ export class TsSchemaGenerator {
507
507
...( defaultValue . args . length > 0
508
508
? [
509
509
ts . factory . createArrayLiteralExpression (
510
- defaultValue . args . map ( ( arg ) => this . createLiteralNode ( arg ) ) ,
510
+ defaultValue . args . map ( ( arg ) => this . createExpressionUtilsCall ( 'literal' , [
511
+ this . createLiteralNode ( arg )
512
+ ] ) ) ,
511
513
) ,
512
514
]
513
515
: [ ] ) ,
You can’t perform that action at this time.
0 commit comments