♻️ Normalize data
This commit is contained in:
7
packages/models/.gitignore
vendored
Normal file
7
packages/models/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
.env
|
||||
|
||||
dist
|
||||
types
|
||||
yarn-error.log
|
19
packages/models/package.json
Normal file
19
packages/models/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "models",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/index.js",
|
||||
"types": "types/index.d.ts",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "^12.0.7",
|
||||
"db": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch"
|
||||
}
|
||||
}
|
9
packages/models/src/answer.ts
Normal file
9
packages/models/src/answer.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Answer as AnswerFromPrisma } from 'db'
|
||||
|
||||
export type Answer = Omit<AnswerFromPrisma, 'resultId' | 'createdAt'>
|
||||
|
||||
export type Stats = {
|
||||
totalViews: number
|
||||
totalStarts: number
|
||||
completionRate: number
|
||||
}
|
5
packages/models/src/index.ts
Normal file
5
packages/models/src/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export * from './typebot'
|
||||
export * from './publicTypebot'
|
||||
export * from './result'
|
||||
export * from './answer'
|
||||
export * from './utils'
|
13
packages/models/src/publicTypebot.ts
Normal file
13
packages/models/src/publicTypebot.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { PublicTypebot as PublicTypebotFromPrisma } from 'db'
|
||||
import { Block, Settings, Step, Theme } from './typebot'
|
||||
import { Table } from './utils'
|
||||
|
||||
export type PublicTypebot = Omit<
|
||||
PublicTypebotFromPrisma,
|
||||
'blocks' | 'startBlock' | 'theme' | 'settings' | 'steps'
|
||||
> & {
|
||||
blocks: Table<Block>
|
||||
steps: Table<Step>
|
||||
theme: Theme
|
||||
settings: Settings
|
||||
}
|
3
packages/models/src/result.ts
Normal file
3
packages/models/src/result.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { Result as ResultFromPrisma } from 'db'
|
||||
|
||||
export type Result = Omit<ResultFromPrisma, 'createdAt'> & { createdAt: string }
|
4
packages/models/src/typebot/index.ts
Normal file
4
packages/models/src/typebot/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './typebot'
|
||||
export * from './steps'
|
||||
export * from './theme'
|
||||
export * from './settings'
|
9
packages/models/src/typebot/settings.ts
Normal file
9
packages/models/src/typebot/settings.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export type Settings = {
|
||||
typingEmulation: TypingEmulationSettings
|
||||
}
|
||||
|
||||
export type TypingEmulationSettings = {
|
||||
enabled: boolean
|
||||
speed: number
|
||||
maxDelay: number
|
||||
}
|
29
packages/models/src/typebot/steps.ts
Normal file
29
packages/models/src/typebot/steps.ts
Normal file
@ -0,0 +1,29 @@
|
||||
export type Step = StartStep | BubbleStep | InputStep
|
||||
|
||||
export type BubbleStep = TextStep
|
||||
|
||||
export type InputStep = TextInputStep
|
||||
|
||||
export enum StepType {
|
||||
START = 'start',
|
||||
TEXT = 'text',
|
||||
TEXT_INPUT = 'text input',
|
||||
}
|
||||
|
||||
export type StepBase = { id: string; blockId: string; target?: Target }
|
||||
|
||||
export type StartStep = StepBase & {
|
||||
type: StepType.START
|
||||
label: string
|
||||
}
|
||||
|
||||
export type TextStep = StepBase & {
|
||||
type: StepType.TEXT
|
||||
content: { html: string; richText: unknown[]; plainText: string }
|
||||
}
|
||||
|
||||
export type TextInputStep = StepBase & {
|
||||
type: StepType.TEXT_INPUT
|
||||
}
|
||||
|
||||
export type Target = { blockId: string; stepId?: string }
|
17
packages/models/src/typebot/theme.ts
Normal file
17
packages/models/src/typebot/theme.ts
Normal file
@ -0,0 +1,17 @@
|
||||
export type Theme = {
|
||||
general: {
|
||||
font: string
|
||||
background: Background
|
||||
}
|
||||
}
|
||||
|
||||
export enum BackgroundType {
|
||||
COLOR = 'Color',
|
||||
IMAGE = 'Image',
|
||||
NONE = 'None',
|
||||
}
|
||||
|
||||
export type Background = {
|
||||
type: BackgroundType
|
||||
content: string
|
||||
}
|
25
packages/models/src/typebot/typebot.ts
Normal file
25
packages/models/src/typebot/typebot.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Typebot as TypebotFromPrisma } from 'db'
|
||||
import { Table } from '../utils'
|
||||
import { Settings } from './settings'
|
||||
import { Step } from './steps'
|
||||
import { Theme } from './theme'
|
||||
|
||||
export type Typebot = Omit<
|
||||
TypebotFromPrisma,
|
||||
'blocks' | 'theme' | 'settings' | 'steps'
|
||||
> & {
|
||||
blocks: Table<Block>
|
||||
steps: Table<Step>
|
||||
theme: Theme
|
||||
settings: Settings
|
||||
}
|
||||
|
||||
export type Block = {
|
||||
id: string
|
||||
title: string
|
||||
graphCoordinates: {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
stepIds: string[]
|
||||
}
|
1
packages/models/src/utils.ts
Normal file
1
packages/models/src/utils.ts
Normal file
@ -0,0 +1 @@
|
||||
export type Table<T> = { byId: { [key: string]: T }; allIds: string[] }
|
13
packages/models/tsconfig.json
Normal file
13
packages/models/tsconfig.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2016",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"declarationDir": "./types",
|
||||
"outDir": "./dist"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user