2
0

♻️ Normalize data

This commit is contained in:
Baptiste Arnaud
2022-01-06 09:40:56 +01:00
parent 6c1e0fd345
commit 9fa4c7dffa
114 changed files with 1545 additions and 1632 deletions

7
packages/models/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
node_modules
# Keep environment variables out of version control
.env
dist
types
yarn-error.log

View 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"
}
}

View 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
}

View File

@ -0,0 +1,5 @@
export * from './typebot'
export * from './publicTypebot'
export * from './result'
export * from './answer'
export * from './utils'

View 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
}

View File

@ -0,0 +1,3 @@
import { Result as ResultFromPrisma } from 'db'
export type Result = Omit<ResultFromPrisma, 'createdAt'> & { createdAt: string }

View File

@ -0,0 +1,4 @@
export * from './typebot'
export * from './steps'
export * from './theme'
export * from './settings'

View File

@ -0,0 +1,9 @@
export type Settings = {
typingEmulation: TypingEmulationSettings
}
export type TypingEmulationSettings = {
enabled: boolean
speed: number
maxDelay: number
}

View 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 }

View 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
}

View 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[]
}

View File

@ -0,0 +1 @@
export type Table<T> = { byId: { [key: string]: T }; allIds: string[] }

View File

@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"declaration": true,
"declarationDir": "./types",
"outDir": "./dist"
}
}