make prisma its own package

This commit is contained in:
Sara Vieira committed 2022-07-21 18:03:38 +02:00
1 parent dcfe1a2417
commit e78fe35ea7
53 files changed
+145 -142

No files matched your search

@@ -9,7 +9,7 @@ import {
Text,
Flex,
} from "~/shared/design-system";
import { User } from "@prisma/client";
import { User } from "@webstudio-is/prisma-client";
import { useNavigate } from "react-router-dom";
export const DashboardHeader = ({ user }: { user: User }) => {
+1 -1
View File
@@ -3,7 +3,7 @@ import { useActionData } from "@remix-run/react";
import { Flex } from "~/shared/design-system";
import interStyles from "~/shared/font-faces/inter.css";
import dashboardStyles from "./dashboard.css";
import { User } from "@prisma/client";
import { User } from "@webstudio-is/prisma-client";
import { DashboardHeader } from "./components/header";
import { SelectProjectCard } from "./components/card";
+2 -6
View File
@@ -1,12 +1,8 @@
import { useCallback, useState } from "react";
import { DndProvider } from "react-dnd";
import { TouchBackend } from "react-dnd-touch-backend";
import {
type Project,
type Asset,
useSubscribe,
usePublish,
} from "@webstudio-is/react-sdk";
import { useSubscribe, usePublish } from "@webstudio-is/react-sdk";
import { type Project, type Asset } from "@webstudio-is/prisma-client";
import type { Config } from "~/config";
import type {
HoveredInstanceData,
@@ -2,7 +2,7 @@ import { ImageIcon } from "~/shared/icons";
import { Button, Flex, Grid, Heading } from "~/shared/design-system";
import { useRef } from "react";
import { Form, useSubmit } from "@remix-run/react";
import { type Asset } from "@webstudio-is/react-sdk";
import { type Asset } from "@webstudio-is/prisma-client";
import { Image } from "~/shared/design-system/components/image";
export const TabContent = ({ assets }: { assets: Array<Asset> }) => {
@@ -1,9 +1,6 @@
import { useState, useCallback } from "react";
import {
useSubscribe,
type Publish,
type Asset,
} from "@webstudio-is/react-sdk";
import { useSubscribe, type Publish } from "@webstudio-is/react-sdk";
import type { Asset } from "@webstudio-is/prisma-client";
import {
Box,
SidebarTabs,
@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
import { useFetcher } from "@remix-run/react";
import { useId } from "@radix-ui/react-id";
import { RocketIcon, ExternalLinkIcon } from "~/shared/icons";
import { type Project } from "@webstudio-is/react-sdk";
import { type Project } from "@webstudio-is/prisma-client";
import {
Button,
Flex,
@@ -8,7 +8,7 @@ import {
TextField,
} from "~/shared/design-system";
import { Share1Icon } from "~/shared/icons";
import { type Project } from "@webstudio-is/react-sdk";
import { type Project } from "@webstudio-is/prisma-client";
import { useIsShareDialogOpen } from "../../shared/nano-states";
type ShareButtonProps = { path: string; project: Project };
@@ -1,4 +1,5 @@
import type { Project, Publish } from "@webstudio-is/react-sdk";
import type { Publish } from "@webstudio-is/react-sdk";
import type { Project } from "@webstudio-is/prisma-client";
import { darkTheme, Flex, type CSS } from "~/shared/design-system";
import type { Config } from "~/config";
import { PreviewButton } from "./preview";
+1 -1
View File
@@ -4,7 +4,7 @@ import { insertCriticalCss } from "./critical-css";
import type { EntryContext } from "@remix-run/node";
import * as Sentry from "@sentry/remix";
import { initSentry } from "./shared/sentry";
import { prisma } from "./shared/db/prisma.server";
import { prisma } from "@webstudio-is/prisma-client";
initSentry({
integrations: [new Sentry.Integrations.Prisma({ client: prisma })],
+1 -1
View File
@@ -1,6 +1,6 @@
import { useActionData, useLoaderData } from "@remix-run/react";
import { ActionFunction, LoaderFunction } from "@remix-run/node";
import type { Project, Asset } from "@webstudio-is/react-sdk";
import type { Project, Asset } from "@webstudio-is/prisma-client";
import { Designer, links } from "~/designer";
import * as db from "~/shared/db";
import config from "~/config";
+2 -1
View File
@@ -1,7 +1,8 @@
import { type ActionFunction } from "@remix-run/node";
import * as db from "~/shared/db";
import { type SyncItem } from "immerhin";
import { type Project, type Tree } from "@webstudio-is/react-sdk";
import { type Tree } from "@webstudio-is/react-sdk";
import { type Project } from "@webstudio-is/prisma-client";
const updaters = {
root: db.tree.patchRoot,
@@ -1,5 +1,5 @@
import { type LoaderFunction, redirect } from "@remix-run/node";
import type { User } from "@webstudio-is/react-sdk";
import type { User } from "@webstudio-is/prisma-client";
import * as db from "~/shared/db";
import { ensureUserCookie } from "~/shared/session";
import config from "~/config";
+1 -1
View File
@@ -1,4 +1,4 @@
import { User } from "@prisma/client";
import { User } from "@webstudio-is/prisma-client";
import { Authenticator } from "remix-auth";
import { FormStrategy } from "remix-auth-form";
import { GitHubStrategy } from "remix-auth-github";
+1 -2
View File
@@ -1,5 +1,4 @@
import { type Project } from "@webstudio-is/react-sdk";
import { prisma } from "./prisma.server";
import { prisma, Project } from "@webstudio-is/prisma-client";
import sharp from "sharp";
export const loadByProject = async (projectId?: Project["id"]) => {
@@ -1,13 +1,12 @@
import {
initialBreakpoints,
type Project,
type Tree,
type Breakpoint,
BreakpointsSchema,
} from "@webstudio-is/react-sdk";
import ObjectId from "bson-objectid";
import { applyPatches, type Patch } from "immer";
import { prisma } from "./prisma.server";
import { prisma, Project } from "@webstudio-is/prisma-client";
export const load = async (treeId?: Tree["id"]) => {
if (typeof treeId !== "string") {
@@ -1,8 +1,12 @@
import slugify from "slugify";
import { nanoid } from "nanoid";
import type { Project as BaseProject, User } from "@webstudio-is/react-sdk";
import { z } from "zod";
import { prisma, Prisma } from "./prisma.server";
import {
User,
prisma,
Prisma,
Project as BaseProject,
} from "@webstudio-is/prisma-client";
import * as db from ".";
const TreeHistorySchema = z.array(z.string());
+1 -1
View File
@@ -4,7 +4,7 @@ import {
UserPropsSchema,
} from "@webstudio-is/react-sdk";
import { applyPatches, type Patch } from "immer";
import { prisma } from "./prisma.server";
import { prisma } from "@webstudio-is/prisma-client";
import { Project } from "./project.server";
export const loadByProject = async (
+1 -1
View File
@@ -5,7 +5,7 @@ import {
InstanceSchema,
} from "@webstudio-is/react-sdk";
import { applyPatches, type Patch } from "immer";
import { prisma } from "./prisma.server";
import { prisma } from "@webstudio-is/prisma-client";
import { createInstance } from "~/shared/tree-utils";
import { sort } from "~/shared/breakpoints";
import { Tree as DbTree } from "@prisma/client";
+1 -2
View File
@@ -1,7 +1,6 @@
import { User } from "@prisma/client";
import { GitHubProfile } from "remix-auth-github";
import { GoogleProfile } from "remix-auth-google";
import { prisma } from "./prisma.server";
import { prisma, User } from "@webstudio-is/prisma-client";
export const createDemoUser = async (userId: string) => {
await prisma.team.create({
+1 -5
View File
@@ -9,10 +9,7 @@
"typecheck": "tsc -b",
"lint": "eslint . --ext .ts,.tsx --max-warnings 0",
"test": "jest",
"setup": "cp ../../node_modules/@webstudio-is/react-sdk/prisma/schema.prisma prisma/ && yarn migrate && yarn generate",
"checks": "yarn lint && yarn typecheck && yarn prettier --check && yarn test",
"migrate": "prisma migrate dev",
"generate": "prisma generate",
"watch:sdk": "relative-deps && relative-deps watch",
"prettier": "prettier \"*.{js,md,json,ts}\" \"{docs,app}/**/*.{js,md,json,ts}\"",
"storybook:run": "start-storybook -p 6006",
@@ -20,7 +17,6 @@
},
"dependencies": {
"@lexical/react": "^0.3.5",
"@prisma/client": "^3.14.0",
"@radix-ui/colors": "^0.1.8",
"@radix-ui/react-accessible-icon": "^0.1.4",
"@radix-ui/react-accordion": "^0.1.6",
@@ -57,6 +53,7 @@
"@vercel/node": "^2.4.1",
"@webstudio-is/asset-uploader": "*",
"@webstudio-is/react-sdk": "*",
"@webstudio-is/prisma-client": "*",
"bson-objectid": "^2.0.2",
"camelcase": "^6.3.0",
"debug": "^4.3.4",
@@ -129,7 +126,6 @@
"eslint-config-custom": "*",
"jest": "^27.5.1",
"prettier": "^2.6.2",
"prisma": "^3.14.0",
"react-test-renderer": "^17.0.2",
"relative-deps": "^1.0.7",
"tsconfig": "*",
+2
View File
@@ -0,0 +1,2 @@
lib
generated
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Webstudio
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+3
View File
@@ -0,0 +1,3 @@
# Webstudio Asset Uploader
The asset uploader is the packages that handles all the logic for our assets upload
+6
View File
@@ -0,0 +1,6 @@
// eslint-disable-next-line
const base = require("jest-config/jest.config.js");
module.exports = {
...base,
};
+27
View File
@@ -0,0 +1,27 @@
{
"name": "@webstudio-is/prisma-client",
"version": "0.0.1",
"description": "Webstudio Prisma layer",
"author": "Webstudio <github@webstudio.is>",
"homepage": "https://webstudio.is",
"scripts": {
"checks": "tsc --noEmit",
"build:prisma": "prisma format && prisma generate",
"migrate": "dotenv -e ../../apps/designer/.env -- prisma migrate"
},
"devDependencies": {
"dotenv-cli": "^6.0.0",
"prisma": "^4.1.0"
},
"main": "src/index.ts",
"types": "src/index.ts",
"files": [
"README.md",
"!*.test.*"
],
"license": "MIT",
"private": false,
"dependencies": {
"@prisma/client": "^4.1.0"
}
}
@@ -1,5 +1,12 @@
import { PrismaClient, Prisma } from "@prisma/client";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
import type {
InstanceProps,
Project,
User,
Breakpoints,
Asset,
} from "@prisma/client";
declare global {
// allow global `var` declarations
@@ -15,3 +22,4 @@ export const prisma = global.prisma || new PrismaClient();
if (process.env.NODE_ENV !== "production") global.prisma = prisma;
export { Prisma, PrismaClientKnownRequestError };
export type { InstanceProps, Project, User, Breakpoints, Asset };
+12
View File
@@ -0,0 +1,12 @@
// Extends can't use node's resolution rn https://github.com/dividab/tsconfig-paths/issues/209#issuecomment-1177261091
{
"extends": "../../node_modules/tsconfig/base.json",
"include": ["./src/**/*.ts"],
"compilerOptions": {
"module": "commonjs",
"target": "ES2019",
"strict": true,
"baseUrl": ".",
"outDir": "./lib"
}
}
+2 -6
View File
@@ -8,10 +8,8 @@
"build": "yarn build:mdn-data && yarn build:args",
"build:mdn-data": "./bin/mdn-data.ts ./src/css",
"build:args": "./bin/generate-arg-types.ts './src/components/*.tsx !./src/**/*.stories.tsx'",
"build:prisma": "prisma format && prisma generate",
"typecheck": "tsc --noEmit",
"build:lib": "rm -fr lib && tsc",
"postinstall": "prisma generate",
"test": "jest",
"checks": "yarn typecheck && yarn test",
"prepublishOnly": "yarn checks && yarn build:lib",
@@ -44,6 +42,7 @@
"react-docgen-typescript": "^2.2.2",
"react-dom": "^17.0.2",
"jest-config": "*",
"@webstudio-is/prisma-client": "*",
"typescript": "^4.6.2"
},
"peerDependencies": {
@@ -54,11 +53,9 @@
"react-dom": "^17.0.2"
},
"dependencies": {
"@prisma/client": "^3.10.0",
"@stitches/core": "^1.2.7",
"immer": "^9.0.12",
"mitt": "^3.0.0",
"prisma": "^3.10.0",
"react-nano-state": "^0.4.0",
"zod": "^3.17.3"
},
@@ -66,8 +63,7 @@
"types": "src/index.ts",
"files": [
"README.md",
"!*.test.*",
"prisma/*"
"!*.test.*"
],
"license": "MIT",
"private": false
-71
View File
@@ -1,71 +0,0 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
model Team {
id String @id @default(uuid())
users User[]
}
model Asset {
id String @id @default(uuid())
project Project @relation(fields: [projectId], references: [id])
projectId String
format String?
size Int
width Decimal?
height Decimal?
name String
path String
alt String?
createdAt DateTime @default(now())
}
model User {
id String @id @default(uuid())
email String? @unique
provider String?
image String?
username String?
createdAt DateTime @default(now())
Team Team? @relation(fields: [teamId], references: [id])
teamId String?
projects Project[]
}
model Project {
id String @id @default(uuid())
title String
domain String @unique
prodTreeId String? // exists when published
devTreeId String
prodTreeIdHistory String @default("[]")
User User? @relation(fields: [userId], references: [id])
userId String?
Asset Asset[]
}
model Tree {
id String @id @default(uuid())
root String
}
model InstanceProps {
id String @id @default(uuid())
instanceId String
treeId String
props String @default("[]")
}
model Breakpoints {
treeId String @id @default(uuid())
values String @default("[]")
}
+2 -8
View File
@@ -1,10 +1,4 @@
import type {
InstanceProps as DbInstanceProps,
Project,
User,
Breakpoints,
Asset,
} from "@prisma/client";
import type { InstanceProps as DbInstanceProps } from "@webstudio-is/prisma-client";
import type { UserProp } from "../user-props";
import type { Instance } from "./instance";
@@ -17,4 +11,4 @@ export type InstanceProps = Omit<DbInstanceProps, "props"> & {
props: Array<UserProp>;
};
export type { DbInstanceProps, Project, User, Breakpoints, Asset };
export type { DbInstanceProps };
-2
View File
@@ -1,2 +0,0 @@
export { PrismaClient, Prisma } from "@prisma/client";
export { PrismaClientKnownRequestError } from "@prisma/client/runtime";
+33 -18
View File
@@ -2681,22 +2681,22 @@
schema-utils "^3.0.0"
source-map "^0.7.3"
"@prisma/client@^3.10.0", "@prisma/client@^3.14.0":
version "3.15.2"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.15.2.tgz#2181398147afc79bfe0d83c03a88dc45b49bd365"
integrity sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w==
"@prisma/client@^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-4.1.0.tgz#7c5341b2276c083821e432536ff97d8cc8f8b936"
integrity sha512-MvfPGAd42vHTiCYxwS6N+2U3F+ukoJ48D2QRnX1zSPJHBkh1CBtshl75daKzvVfgQwSouzSQeugKDej5di+E/g==
dependencies:
"@prisma/engines-version" "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
"@prisma/engines-version" "4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8"
"@prisma/engines-version@3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e":
version "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz#bf5e2373ca68ce7556b967cb4965a7095e93fe53"
integrity sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w==
"@prisma/engines-version@4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8":
version "4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8.tgz#ce00e6377126e491a8b1e0e2039c97e2924bd6d9"
integrity sha512-cRRJwpHFGFJZvtHbY3GZjMffNBEjjZk68ztn+S2hDgPCGB4H66IK26roK94GJxBodSehwRJ0wGyebC2GoIH1JQ==
"@prisma/engines@3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e":
version "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz#f691893df506b93e3cb1ccc15ec6e5ac64e8e570"
integrity sha512-NHlojO1DFTsSi3FtEleL9QWXeSF/UjhCW0fgpi7bumnNZ4wj/eQ+BJJ5n2pgoOliTOGv9nX2qXvmHap7rJMNmg==
"@prisma/engines@4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-4.1.0.tgz#da8002d4b75c92e3fd564ba5b0bd04847ffb3c4c"
integrity sha512-quqHXD3P83NBLVtRlts4SgKHmqgA8GMiyDTJ7af03Wg0gl6F5t65mBYvIuwmD+52vHm42JtIsp/fAO9YIV0JBA==
"@radix-ui/colors@^0.1.8":
version "0.1.8"
@@ -7905,11 +7905,26 @@ dot-case@^3.0.4:
no-case "^3.0.4"
tslib "^2.0.3"
dotenv-cli@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/dotenv-cli/-/dotenv-cli-6.0.0.tgz#8a30cbc59d0a8aaa166b2fee0a9a55e23a1223ab"
integrity sha512-qXlCOi3UMDhCWFKe0yq5sg3X+pJAz+RQDiFN38AMSbUrnY3uZshSfDJUAge951OS7J9gwLZGfsBlWRSOYz/TRg==
dependencies:
cross-spawn "^7.0.3"
dotenv "^16.0.0"
dotenv-expand "^8.0.1"
minimist "^1.2.5"
dotenv-expand@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==
dotenv-expand@^8.0.1:
version "8.0.3"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-8.0.3.tgz#29016757455bcc748469c83a19b36aaf2b83dd6e"
integrity sha512-SErOMvge0ZUyWd5B0NXMQlDkN+8r+HhVUsxgOO7IoPDOdDRD2JjExpN6y3KnFR66jsJMwSn1pqIivhU5rcJiNg==
dotenv@^16.0.0:
version "16.0.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d"
@@ -14031,12 +14046,12 @@ pretty-ms@7.0.1, pretty-ms@^7.0.1:
dependencies:
parse-ms "^2.1.0"
prisma@^3.10.0, prisma@^3.14.0:
version "3.15.2"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.15.2.tgz#4ebe32fb284da3ac60c49fbc16c75e56ecf32067"
integrity sha512-nMNSMZvtwrvoEQ/mui8L/aiCLZRCj5t6L3yujKpcDhIPk7garp8tL4nMx2+oYsN0FWBacevJhazfXAbV1kfBzA==
prisma@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-4.1.0.tgz#5d43597f0f2603a4a75d9586346c74110d8e221f"
integrity sha512-iwqpAT6In1uvMSwQAM3PqmaBdhh2OaQ/2t+n3RjpW4vAKP3R7E1T34FZUU4zGOWtMWm5dt0sPThQkT/h87r6gw==
dependencies:
"@prisma/engines" "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
"@prisma/engines" "4.1.0"
prismjs@^1.27.0:
version "1.28.0"