enhance prisma json types (#327)

This commit is contained in:
Matti Nannt
2023-05-31 15:57:10 +02:00
committed by GitHub
parent 99bb6932c9
commit 0e94900e2c
6 changed files with 101 additions and 21 deletions

View File

@@ -60,13 +60,11 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
}
// if survey exists, return survey
return res
.status(200)
.json({
...survey,
brandColor: product?.brandColor,
formbricksSignature: product?.formbricksSignature,
});
return res.status(200).json({
...survey,
brandColor: product?.brandColor,
formbricksSignature: product?.formbricksSignature,
});
}
// Unknown HTTP Method

View File

@@ -25,7 +25,9 @@
"studio": "prisma studio"
},
"dependencies": {
"@prisma/client": "^4.14.1"
"@formbricks/types": "workspace:*",
"@prisma/client": "^4.14.1",
"prisma-json-types-generator": "^2.4.0"
},
"devDependencies": {
"@formbricks/tsconfig": "workspace:*",

View File

@@ -12,6 +12,16 @@ generator client {
//provider = "prisma-dbml-generator"
}
generator json {
provider = "prisma-json-types-generator"
// namespace = "PrismaJson"
// clientOutput = "<finds it automatically>"
// (./ -> relative to schema, or an importable path to require() it)
// useType = "MyType"
// In case you need to use a type, export it inside the namespace and we will add a index signature to it
// (e.g. export namespace PrismaJson { export type MyType = {a: 1, b: 2} }; will generate namespace.MyType["TYPE HERE"])
}
enum PipelineTriggers {
responseCreated
responseUpdated
@@ -75,17 +85,18 @@ model Person {
}
model Response {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
finished Boolean @default(false)
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
surveyId String
person Person? @relation(fields: [personId], references: [id], onDelete: Cascade)
personId String?
data Json @default("{}")
meta Json @default("{}")
userAttributes Json @default("[]")
id String @id @default(cuid())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
finished Boolean @default(false)
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
surveyId String
person Person? @relation(fields: [personId], references: [id], onDelete: Cascade)
personId String?
/// [ResponseData]
data Json @default("{}")
/// [ResponseMeta]
meta Json @default("{}")
}
enum SurveyStatus {
@@ -165,7 +176,9 @@ model Survey {
environment Environment @relation(fields: [environmentId], references: [id], onDelete: Cascade)
environmentId String
status SurveyStatus @default(draft)
/// [SurveyQuestions]
questions Json @default("[]")
/// [SurveyThankYouCard]
thankYouCard Json @default("{\"enabled\": false}")
responses Response[]
displayOption displayOptions @default(displayOnce)
@@ -173,7 +186,7 @@ model Survey {
triggers SurveyTrigger[]
attributeFilters SurveyAttributeFilter[]
displays Display[]
autoClose Int?
autoClose Int?
}
model Event {
@@ -183,6 +196,7 @@ model Event {
eventClassId String?
session Session @relation(fields: [sessionId], references: [id], onDelete: Cascade)
sessionId String
/// [EventProperties]
properties Json @default("{}")
}
@@ -200,6 +214,7 @@ model EventClass {
description String?
type EventType
events Event[]
/// [EventClassNoCodeConfig]
noCodeConfig Json?
environment Environment @relation(fields: [environmentId], references: [id], onDelete: Cascade)
environmentId String
@@ -384,5 +399,6 @@ model User {
invitesAccepted Invite[] @relation("inviteAcceptedBy")
role Role?
objective Objective?
/// [UserNotificationSettings]
notificationSettings Json @default("{}")
}

View File

@@ -1,4 +1,5 @@
import { PrismaClient } from "@prisma/client";
import "../types/jsonTypes";
declare global {
var prisma: PrismaClient | undefined;

View File

@@ -0,0 +1,16 @@
import { NoCodeConfig } from "@formbricks/types/events";
import { Question } from "@formbricks/types/questions";
import { ThankYouCard } from "@formbricks/types/surveys";
import { NotificationSettings } from "@formbricks/types/users";
declare global {
namespace PrismaJson {
export type EventProperties = { [key: string]: string };
export type EventClassNoCodeConfig = NoCodeConfig;
export type ResponseData = { [questionId: string]: string };
export type ResponseMeta = { [key: string]: string };
export type SurveyQuestions = Question[];
export type SurveyThankYouCard = ThankYouCard;
export type UserNotificationSettings = NotificationSettings;
}
}

49
pnpm-lock.yaml generated
View File

@@ -352,9 +352,15 @@ importers:
packages/database:
dependencies:
'@formbricks/types':
specifier: workspace:*
version: link:../types
'@prisma/client':
specifier: ^4.14.1
version: 4.14.1(prisma@4.14.1)
prisma-json-types-generator:
specifier: ^2.4.0
version: 2.4.0
devDependencies:
'@formbricks/tsconfig':
specifier: workspace:*
@@ -3937,6 +3943,16 @@ packages:
prisma: 4.14.1
dev: false
/@prisma/debug@4.15.0:
resolution: {integrity: sha512-dkbPz+gOVlWDBAaOEseSpAUz9NppT38UlwdryPyrwct6OClLirNC7wH+TpAQk5OZp9x59hNnfDz+T7XvL1v0/Q==}
dependencies:
'@types/debug': 4.1.8
debug: 4.3.4
strip-ansi: 6.0.1
transitivePeerDependencies:
- supports-color
dev: false
/@prisma/debug@4.6.1:
resolution: {integrity: sha512-BezDvSenTgQDQ6WA3TdTDGcrt0Oh4vmpZtmSOYm1KaSZiSVIL2xT0P9TFM3vtOa4wn7sn/003PyTSxyHS3mShg==}
dependencies:
@@ -4006,6 +4022,17 @@ packages:
- supports-color
dev: true
/@prisma/generator-helper@4.15.0:
resolution: {integrity: sha512-JVHNgXr0LrcqXqmFrs+BzxfyRL6cFD5GLTMVWfCLU7kqSJdWuZxfoZW995tg6mOXnBgPTf6Ocv3RY4RLQq8k4g==}
dependencies:
'@prisma/debug': 4.15.0
'@types/cross-spawn': 6.0.2
cross-spawn: 7.0.3
kleur: 4.1.5
transitivePeerDependencies:
- supports-color
dev: false
/@prisma/generator-helper@4.6.1:
resolution: {integrity: sha512-70XBmqDhmpe8H35ttOJOgyg1OpppO/uelILB1SIwjeSI7PHHdU2+Y/+LkpnifkCEpSZKIhxEIPbHx17m2neAsA==}
dependencies:
@@ -4919,13 +4946,18 @@ packages:
resolution: {integrity: sha512-KuwNhp3eza+Rhu8IFI5HUXRP0LIhqH5cAjubUvGXXthh4YYBuP2ntwEX+Cz8GJoZUHlKo247wPWOfA9LYEq4cw==}
dependencies:
'@types/node': 20.2.3
dev: true
/@types/debug@4.1.7:
resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==}
dependencies:
'@types/ms': 0.7.31
/@types/debug@4.1.8:
resolution: {integrity: sha512-/vPO1EPOs306Cvhwv7KfVfYvOJqA/S/AXjaHQiJboCZzcNDb+TIJFN9/2C9DZ//ijSKWioNyUxD792QmDJ+HKQ==}
dependencies:
'@types/ms': 0.7.31
dev: false
/@types/enzyme@3.10.13:
resolution: {integrity: sha512-FCtoUhmFsud0Yx9fmZk179GkdZ4U9B0GFte64/Md+W/agx0L5SxsIIbhLBOxIb9y2UfBA4WQnaG1Od/UsUQs9Q==}
dependencies:
@@ -16461,6 +16493,17 @@ packages:
- supports-color
dev: true
/prisma-json-types-generator@2.4.0:
resolution: {integrity: sha512-iOdo8sBoUz2jCi+kw5nwACbe0QHcPIIEToXyvn0cW5IJhPEhoYbY/XwMhEDIEla247YhXe1yYPiKwviFm9LNpg==}
engines: {node: '>=14.0'}
hasBin: true
dependencies:
'@prisma/generator-helper': 4.15.0
tslib: 2.5.2
transitivePeerDependencies:
- supports-color
dev: false
/prisma@4.14.1:
resolution: {integrity: sha512-z6hxzTMYqT9SIKlzD08dhzsLUpxjFKKsLpp5/kBDnSqiOjtUyyl/dC5tzxLcOa3jkEHQ8+RpB/fE3w8bgNP51g==}
engines: {node: '>=14.17'}
@@ -19219,6 +19262,10 @@ packages:
/tslib@2.4.1:
resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==}
/tslib@2.5.2:
resolution: {integrity: sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA==}
dev: false
/tsup@6.7.0(postcss@8.4.23)(typescript@5.0.4):
resolution: {integrity: sha512-L3o8hGkaHnu5TdJns+mCqFsDBo83bJ44rlK7e6VdanIvpea4ArPcU3swWGsLVbXak1PqQx/V+SSmFPujBK+zEQ==}
engines: {node: '>=14.18'}