♻️ (results) Introduce tRPC and use it for the results
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
{
|
||||
"name": "configs",
|
||||
"version": "1.0.0",
|
||||
"main": "./index.ts",
|
||||
"types": "./index.ts",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"devDependencies": {
|
||||
"prisma": "4.6.1",
|
||||
"typescript": "4.8.4",
|
||||
"dotenv-cli": "6.0.0"
|
||||
"dotenv-cli": "6.0.0",
|
||||
"tsconfig": "workspace:*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"composite": true,
|
||||
"outDir": "build",
|
||||
"isolatedModules": false
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules", "build"]
|
||||
"extends": "tsconfig/base.json",
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"devDependencies": {
|
||||
"typescript": "4.8.4",
|
||||
"next": "13.0.3",
|
||||
"db": "workspace:*"
|
||||
"db": "workspace:*",
|
||||
"tsconfig": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "12.0.0",
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import { Answer as AnswerFromPrisma } from 'db'
|
||||
import { z } from 'zod'
|
||||
|
||||
export type Answer = Omit<
|
||||
AnswerFromPrisma,
|
||||
'resultId' | 'createdAt' | 'storageUsed'
|
||||
> & { storageUsed?: number }
|
||||
export const answerSchema = z.object({
|
||||
createdAt: z.date(),
|
||||
resultId: z.string(),
|
||||
blockId: z.string(),
|
||||
groupId: z.string(),
|
||||
variableId: z.string().nullable(),
|
||||
content: z.string(),
|
||||
storageUsed: z.number().nullable(),
|
||||
})
|
||||
|
||||
export type Stats = {
|
||||
totalViews: number
|
||||
totalStarts: number
|
||||
totalCompleted: number
|
||||
}
|
||||
|
||||
export type Answer = z.infer<typeof answerSchema>
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
import { Result as ResultFromPrisma } from 'db'
|
||||
import { Answer } from './answer'
|
||||
import { z } from 'zod'
|
||||
import { answerSchema } from './answer'
|
||||
import { InputBlockType } from './blocks'
|
||||
import { VariableWithValue } from './typebot/variable'
|
||||
import { variableWithValueSchema } from './typebot/variable'
|
||||
|
||||
export type Result = Omit<ResultFromPrisma, 'createdAt' | 'variables'> & {
|
||||
createdAt: string
|
||||
variables: VariableWithValue[]
|
||||
}
|
||||
export const resultSchema = z.object({
|
||||
id: z.string(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
typebotId: z.string(),
|
||||
variables: z.array(variableWithValueSchema),
|
||||
isCompleted: z.boolean(),
|
||||
hasStarted: z.boolean().nullable(),
|
||||
isArchived: z.boolean().nullable(),
|
||||
})
|
||||
|
||||
export type ResultWithAnswers = Result & { answers: Answer[] }
|
||||
export const resultWithAnswersSchema = resultSchema.and(
|
||||
z.object({
|
||||
answers: z.array(answerSchema),
|
||||
})
|
||||
)
|
||||
|
||||
export const logSchema = z.object({
|
||||
id: z.string(),
|
||||
createdAt: z.date(),
|
||||
resultId: z.string(),
|
||||
status: z.string(),
|
||||
description: z.string(),
|
||||
details: z.string().nullable(),
|
||||
})
|
||||
|
||||
export type Result = z.infer<typeof resultSchema>
|
||||
|
||||
export type ResultWithAnswers = z.infer<typeof resultWithAnswersSchema>
|
||||
|
||||
export type Log = z.infer<typeof logSchema>
|
||||
|
||||
export type ResultValues = Pick<
|
||||
ResultWithAnswers,
|
||||
|
||||
@@ -3,21 +3,29 @@ import { z } from 'zod'
|
||||
export const variableSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
value: z.string().optional().nullable(),
|
||||
value: z.string().nullish(),
|
||||
})
|
||||
|
||||
/**
|
||||
* Variable when retrieved from the database
|
||||
*/
|
||||
export type VariableWithValue = Omit<Variable, 'value'> & {
|
||||
value: string
|
||||
}
|
||||
export const variableWithValueSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
value: z.string(),
|
||||
})
|
||||
|
||||
/**
|
||||
* Variable when computed or retrieved from a block
|
||||
*/
|
||||
export type VariableWithUnknowValue = Omit<VariableWithValue, 'value'> & {
|
||||
value: unknown
|
||||
}
|
||||
const VariableWithUnknowValueSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
value: z.unknown(),
|
||||
})
|
||||
|
||||
export type Variable = z.infer<typeof variableSchema>
|
||||
export type VariableWithValue = z.infer<typeof variableWithValueSchema>
|
||||
export type VariableWithUnknowValue = z.infer<
|
||||
typeof VariableWithUnknowValueSchema
|
||||
>
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"declaration": true,
|
||||
"declarationDir": "types",
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"emitDeclarationOnly": true
|
||||
}
|
||||
"extends": "tsconfig/base.json",
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
21
packages/tsconfig/base.json
Normal file
21
packages/tsconfig/base.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"display": "Default",
|
||||
"compilerOptions": {
|
||||
"composite": false,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"inlineSources": false,
|
||||
"isolatedModules": true,
|
||||
"moduleResolution": "node",
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"preserveWatchOutput": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"downlevelIteration": true
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
19
packages/tsconfig/nextjs.json
Normal file
19
packages/tsconfig/nextjs.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"display": "Next.js",
|
||||
"extends": "./base.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"incremental": true,
|
||||
"jsx": "preserve",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"module": "esnext",
|
||||
"noEmit": true,
|
||||
"resolveJsonModule": true,
|
||||
"target": "es5"
|
||||
},
|
||||
"include": ["src", "next-env.d.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
3
packages/tsconfig/package.json
Normal file
3
packages/tsconfig/package.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "tsconfig"
|
||||
}
|
||||
@@ -14,7 +14,8 @@
|
||||
"models": "workspace:*",
|
||||
"next": "13.0.3",
|
||||
"nodemailer": "6.8.0",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "4.8.4",
|
||||
"tsconfig": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"aws-sdk": "2.1152.0",
|
||||
|
||||
@@ -177,7 +177,9 @@ export const parseAnswers =
|
||||
createdAt,
|
||||
answers,
|
||||
variables: resultVariables,
|
||||
}: Pick<ResultWithAnswers, 'createdAt' | 'answers' | 'variables'>): {
|
||||
}: Pick<ResultWithAnswers, 'answers' | 'variables'> & {
|
||||
createdAt: string
|
||||
}): {
|
||||
[key: string]: string
|
||||
} => {
|
||||
const header = parseResultHeader(typebot, linkedTypebots)
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"declaration": true,
|
||||
"declarationDir": "types",
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"emitDeclarationOnly": true
|
||||
}
|
||||
"extends": "tsconfig/base.json",
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user