diff --git a/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap b/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap index 33f0e170..719881c2 100644 --- a/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap +++ b/packages/generator/tests/admin/__snapshots__/generateAdminSettings.test.ts.snap @@ -21,6 +21,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` "fields": [ { "create": false, + "defaultValue": "@default(autoincrement())", "editor": false, "filter": true, "id": "User.id", @@ -42,6 +43,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": false, + "defaultValue": "@default(now())", "editor": false, "filter": true, "id": "User.createdAt", @@ -63,6 +65,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": undefined, "editor": false, "filter": true, "id": "User.email", @@ -84,6 +87,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": undefined, "editor": false, "filter": true, "id": "User.name", @@ -105,6 +109,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": undefined, "editor": false, "filter": true, "id": "User.password", @@ -126,6 +131,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": "@default(\"{}\")", "editor": false, "filter": true, "id": "User.permissions", @@ -147,6 +153,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": undefined, "editor": false, "filter": true, "id": "User.posts", @@ -180,6 +187,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` "fields": [ { "create": false, + "defaultValue": "@default(autoincrement())", "editor": false, "filter": true, "id": "Post.id", @@ -201,6 +209,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": "@default(false)", "editor": false, "filter": true, "id": "Post.published", @@ -222,6 +231,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": undefined, "editor": false, "filter": true, "id": "Post.title", @@ -243,6 +253,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": true, + "defaultValue": undefined, "editor": false, "filter": true, "id": "Post.author", @@ -263,6 +274,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": false, + "defaultValue": undefined, "editor": false, "filter": true, "id": "Post.authorId", @@ -284,6 +296,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": false, + "defaultValue": "@default(now())", "editor": false, "filter": true, "id": "Post.createdAt", @@ -305,6 +318,7 @@ exports[`Generate Json Object For Admin Tables Should back with Json Settings 1` }, { "create": false, + "defaultValue": undefined, "editor": false, "filter": true, "id": "Post.updatedAt", diff --git a/packages/schema/src/json.ts b/packages/schema/src/json.ts index 575a0f9c..fdc77c46 100644 --- a/packages/schema/src/json.ts +++ b/packages/schema/src/json.ts @@ -39,6 +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')), 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 d6a2ecc5..fc00e8c2 100644 --- a/packages/schema/tests/json.test.ts +++ b/packages/schema/tests/json.test.ts @@ -3,6 +3,7 @@ import { join } from 'path'; test('generate Json object from prisma schema', () => { const generate = new ConvertSchemaToObject(join(__dirname, './schemas/schema.prisma')).run(); + expect(generate).toMatchInlineSnapshot(` { "enums": [ @@ -19,6 +20,7 @@ test('generate Json object from prisma schema', () => { "documentation": "// User modal documentation", "fields": [ { + "defaultValue": "@default(autoincrement())", "documentation": "", "isId": true, "kind": "scalar", @@ -31,6 +33,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": "@default(now())", "documentation": "", "isId": false, "kind": "scalar", @@ -43,6 +46,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": undefined, "documentation": "", "isId": false, "kind": "scalar", @@ -55,6 +59,7 @@ test('generate Json object from prisma schema', () => { "unique": true, }, { + "defaultValue": undefined, "documentation": "", "isId": false, "kind": "scalar", @@ -67,6 +72,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": undefined, "documentation": "// password documentation // password second line documentation", "isId": false, @@ -80,6 +86,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": "@default(\"{}\")", "documentation": "", "isId": false, "kind": "scalar", @@ -92,6 +99,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": undefined, "documentation": "", "isId": false, "kind": "object", @@ -110,6 +118,7 @@ test('generate Json object from prisma schema', () => { "documentation": "", "fields": [ { + "defaultValue": "@default(autoincrement())", "documentation": "", "isId": true, "kind": "scalar", @@ -122,6 +131,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": "@default(false)", "documentation": "", "isId": false, "kind": "scalar", @@ -134,6 +144,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": undefined, "documentation": "", "isId": false, "kind": "scalar", @@ -146,6 +157,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": undefined, "documentation": "", "isId": false, "kind": "object", @@ -165,6 +177,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": undefined, "documentation": "", "isId": false, "kind": "scalar", @@ -177,6 +190,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": "@default(now())", "documentation": "", "isId": false, "kind": "scalar", @@ -189,6 +203,7 @@ test('generate Json object from prisma schema', () => { "unique": false, }, { + "defaultValue": undefined, "documentation": "", "isId": false, "kind": "scalar", diff --git a/packages/types/src/generatedSchema.ts b/packages/types/src/generatedSchema.ts index 117c7b4b..ccb0fd50 100644 --- a/packages/types/src/generatedSchema.ts +++ b/packages/types/src/generatedSchema.ts @@ -10,6 +10,7 @@ export interface Field { isId: boolean; unique: boolean; kind: 'object' | 'enum' | 'scalar'; + defaultValue?: string; map?: string; relationField?: boolean; documentation?: string;