diff --git a/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap b/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap index 719881c2..d86ac6c7 100644 --- a/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap +++ b/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap @@ -21,7 +21,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` "fields": [ { "create": false, - "defaultValue": "@default(autoincrement())", + "defaultValue": "autoincrement()", "editor": false, "filter": true, "id": "User.id", @@ -43,7 +43,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": false, - "defaultValue": "@default(now())", + "defaultValue": "now()", "editor": false, "filter": true, "id": "User.createdAt", @@ -131,7 +131,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, - "defaultValue": "@default(\"{}\")", + "defaultValue": "\"{}\"", "editor": false, "filter": true, "id": "User.permissions", @@ -187,7 +187,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` "fields": [ { "create": false, - "defaultValue": "@default(autoincrement())", + "defaultValue": "autoincrement()", "editor": false, "filter": true, "id": "Post.id", @@ -209,7 +209,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, - "defaultValue": "@default(false)", + "defaultValue": "false", "editor": false, "filter": true, "id": "Post.published", @@ -296,7 +296,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": false, - "defaultValue": "@default(now())", + "defaultValue": "now()", "editor": false, "filter": true, "id": "Post.createdAt", diff --git a/packages/schema/src/PrismaReader.ts b/packages/schema/src/PrismaReader.ts index 7a11ab54..7d0db35f 100644 --- a/packages/schema/src/PrismaReader.ts +++ b/packages/schema/src/PrismaReader.ts @@ -66,6 +66,10 @@ export class PrismaReader { return undefined; } + getDefaultValue(line: string) { + return line.match(/@default\((.*)\)/)?.[1]; + } + getRelation(line: string) { const relationString = line.match(/@relation\((.*?)\)/); if (relationString) { diff --git a/packages/schema/src/json.ts b/packages/schema/src/json.ts index fdc77c46..b0eb0790 100644 --- a/packages/schema/src/json.ts +++ b/packages/schema/src/json.ts @@ -39,7 +39,7 @@ export class ConvertSchemaToObject extends PrismaReader { type, isId: !!line.find((part) => part.startsWith('@id')), unique: !!line.find((part) => part.startsWith('@unique')), - defaultValue: line.find((part) => part.startsWith('@default')), + defaultValue: this.getDefaultValue(lines[i]), list: line[1].includes('[]'), required: !line[1].includes('[]') && !line[1].includes('?'), kind: this.getKind(type), diff --git a/packages/schema/tests/json.test.ts b/packages/schema/tests/json.test.ts index e74fb4ec..17f5e2c5 100644 --- a/packages/schema/tests/json.test.ts +++ b/packages/schema/tests/json.test.ts @@ -20,7 +20,7 @@ test('generate Json object from prisma schema', () => { "documentation": "// User modal documentation", "fields": [ { - "defaultValue": "@default(autoincrement())", + "defaultValue": "autoincrement()", "documentation": "", "isId": true, "kind": "scalar", @@ -33,7 +33,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { - "defaultValue": "@default(now())", + "defaultValue": "now()", "documentation": "", "isId": false, "kind": "scalar", @@ -86,7 +86,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { - "defaultValue": "@default("{}")", + "defaultValue": ""{}"", "documentation": "", "isId": false, "kind": "scalar", @@ -118,7 +118,7 @@ test('generate Json object from prisma schema', () => { "documentation": "", "fields": [ { - "defaultValue": "@default(autoincrement())", + "defaultValue": "autoincrement()", "documentation": "", "isId": true, "kind": "scalar", @@ -131,7 +131,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { - "defaultValue": "@default(false)", + "defaultValue": "false", "documentation": "", "isId": false, "kind": "scalar", @@ -190,7 +190,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { - "defaultValue": "@default(now())", + "defaultValue": "now()", "documentation": "", "isId": false, "kind": "scalar",