Skip to content

Commit 348abee

Browse files
authored
fix: literal function arguments with @default() (#288)
* fix: literal function arguments with `@default()` * Add test. --------- Co-authored-by: = <=>
1 parent 8fbe27d commit 348abee

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

packages/cli/test/ts-schema-gen.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,66 @@ model User extends Base {
360360
expect(schema.enums).toMatchObject({ Role: expect.any(Object) });
361361
expect(schema.models).toMatchObject({ User: expect.any(Object) });
362362
});
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+
});
363425
});

packages/sdk/src/ts-schema-generator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,9 @@ export class TsSchemaGenerator {
507507
...(defaultValue.args.length > 0
508508
? [
509509
ts.factory.createArrayLiteralExpression(
510-
defaultValue.args.map((arg) => this.createLiteralNode(arg)),
510+
defaultValue.args.map((arg) => this.createExpressionUtilsCall('literal', [
511+
this.createLiteralNode(arg)
512+
])),
511513
),
512514
]
513515
: []),

0 commit comments

Comments
 (0)