Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Move build db utils to project-build package (#1050)
Bogdan Chadkinf6150c98da78
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsxindex 9a09cdbeb0..bf361c74dc 100644--- a/apps/builder/app/builder/builder.tsx+++ b/apps/builder/app/builder/builder.tsx@@ -1,9 +1,9 @@import { useCallback, useEffect, useMemo } from "react";import { type Publish, usePublish, useSubscribe } from "~/shared/pubsub";-import { utils as projectUtils, type Project } from "@webstudio-is/project";+import { type Pages, findPageByIdOrPath } from "@webstudio-is/project-build";+import type { Project } from "@webstudio-is/project";import { theme, Box, type CSS, Flex, Grid } from "@webstudio-is/design-system";import type { AuthPermit } from "@webstudio-is/trpc-interface";-import type { Pages } from "@webstudio-is/project-build";import { registerContainers, useBuilderStore } from "~/shared/sync";import { useSyncServer } from "./shared/sync/sync-server";// eslint-disable-next-line import/no-internal-modules@@ -39,6 +39,7 @@ import { useCopyPasteInstance } from "~/shared/copy-paste";import { AssetsProvider } from "./shared/assets";registerContainers();+export const links = () => {return [{ rel: "stylesheet", href: interFont },@@ -291,7 +292,7 @@ export const Builder = ({);const page = useMemo(() => {- const page = projectUtils.pages.findByIdOrPath(pages, pageId);+ const page = findPageByIdOrPath(pages, pageId);if (page === undefined) {throw new Error(`Page with id ${pageId} not found`);}diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx b/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsxindex 7252378db4..340e2f4fda 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx@@ -4,7 +4,11 @@ import { useDebouncedCallback } from "use-debounce";import { useUnmount } from "react-use";import slugify from "slugify";import { useFetcher } from "@remix-run/react";-import type { Page, Pages } from "@webstudio-is/project-build";+import {+ type Page,+ type Pages,+ findPageByIdOrPath,+} from "@webstudio-is/project-build";import {theme,Button,@@ -18,7 +22,6 @@ import {Tooltip,} from "@webstudio-is/design-system";import { ChevronDoubleLeftIcon, TrashIcon } from "@webstudio-is/icons";-import { utils as projectUtils } from "@webstudio-is/project";import { usePages } from "~/builder/shared/nano-states";import { useOnFetchEnd, usePersistentFetcher } from "~/shared/fetcher";import {@@ -171,15 +174,13 @@ const nameToPath = (pages: Pages | undefined, name: string) => {return path;}- if (projectUtils.pages.findByIdOrPath(pages, path) === undefined) {+ if (findPageByIdOrPath(pages, path) === undefined) {return path;}let suffix = 1;- while (- projectUtils.pages.findByIdOrPath(pages, `${path}${suffix}`) !== undefined- ) {+ while (findPageByIdOrPath(pages, `${path}${suffix}`) !== undefined) {suffix++;}@@ -342,7 +343,7 @@ export const PageSettings = ({const fetcher = useFetcher<EditPageData>();const [pages] = usePages();- const page = pages && projectUtils.pages.findByIdOrPath(pages, pageId);+ const page = pages && findPageByIdOrPath(pages, pageId);const isHomePage = page?.id === pages?.homePage.id;diff --git a/apps/builder/app/routes/builder/$projectId.tsx b/apps/builder/app/routes/builder/$projectId.tsxindex d53afd8ee5..3ed4b025db 100644--- a/apps/builder/app/routes/builder/$projectId.tsx+++ b/apps/builder/app/routes/builder/$projectId.tsx@@ -1,13 +1,14 @@import { useLoaderData } from "@remix-run/react";+import type { ShouldRevalidateFunction } from "@remix-run/react";import type { ErrorBoundaryComponent, LoaderArgs } from "@remix-run/node";-import { type BuilderProps, Builder, links } from "~/builder";+import { loadBuildByProjectId } from "@webstudio-is/project-build/server";import { db } from "@webstudio-is/project/server";+import { authorizeProject } from "@webstudio-is/trpc-interface/server";+import { createContext, createAuthReadToken } from "~/shared/context.server";import { ErrorMessage } from "~/shared/error";import { sentryException } from "~/shared/sentry";import { getBuildOrigin } from "~/shared/router-utils";-import { createContext, createAuthReadToken } from "~/shared/context.server";-import type { ShouldRevalidateFunction } from "@remix-run/react";-import { authorizeProject } from "@webstudio-is/trpc-interface/server";+import { type BuilderProps, Builder, links } from "~/builder";export { links };@@ -41,7 +42,7 @@ export const loader = async ({throw new Error(`Project "${params.projectId}" not found`);}- const devBuild = await db.build.loadByProjectId(project.id, "dev");+ const devBuild = await loadBuildByProjectId(project.id, "dev");const pages = devBuild.pages;const page =diff --git a/apps/builder/app/routes/rest/pages.$projectId.ts b/apps/builder/app/routes/rest/pages.$projectId.tsindex e97301a8f6..ca9fe25fe6 100644--- a/apps/builder/app/routes/rest/pages.$projectId.ts+++ b/apps/builder/app/routes/rest/pages.$projectId.ts@@ -1,9 +1,17 @@-import type { LoaderArgs, ActionArgs } from "@remix-run/node";-import { db } from "@webstudio-is/project/server";-import { type Pages, pathValidators } from "@webstudio-is/project-build";-import { utils } from "@webstudio-is/project";import { zfd } from "zod-form-data";import { z } from "zod";+import type { LoaderArgs, ActionArgs } from "@remix-run/node";+import {+ type Pages,+ pathValidators,+ findPageByIdOrPath,+} from "@webstudio-is/project-build";+import {+ addPage,+ deletePage,+ editPage,+ loadBuildByProjectId,+} from "@webstudio-is/project-build/server";import { sentryException } from "~/shared/sentry";import type {CreatePageData,@@ -49,20 +57,20 @@ const handlePut = async (meta: description !== undefined ? { description } : undefined,};- const devBuild = await db.build.loadByProjectId(projectId, "dev");+ const devBuild = await loadBuildByProjectId(projectId, "dev");- const existingPage = utils.pages.findByIdOrPath(devBuild.pages, data.path);+ const existingPage = findPageByIdOrPath(devBuild.pages, data.path);if (existingPage !== undefined) {return makeFieldError("path", `Already used for "${existingPage.name}"`);}- const updatedBuild = await db.build.addPage({+ const updatedBuild = await addPage({projectId,buildId: devBuild.id,data,});- const newPage = utils.pages.findByIdOrPath(updatedBuild.pages, data.path);+ const newPage = findPageByIdOrPath(updatedBuild.pages, data.path);if (newPage === undefined) {throw new Error("New page not found");@@ -93,16 +101,16 @@ const handlePost = async (meta: description !== undefined ? { description } : undefined,};- const devBuild = await db.build.loadByProjectId(projectId, "dev");+ const devBuild = await loadBuildByProjectId(projectId, "dev");if (data.path !== undefined) {- const existingPage = utils.pages.findByIdOrPath(devBuild.pages, data.path);+ const existingPage = findPageByIdOrPath(devBuild.pages, data.path);if (existingPage !== undefined && existingPage.id !== id) {return makeFieldError("path", `Already used for "${existingPage.name}"`);}}- await db.build.editPage({+ await editPage({projectId,buildId: devBuild.id,pageId: id,@@ -124,13 +132,13 @@ const handleDelete = async (}const { id } = result.data;- const devBuild = await db.build.loadByProjectId(projectId, "dev");+ const devBuild = await loadBuildByProjectId(projectId, "dev");if (devBuild.pages.homePage.id === id) {return makeFieldError("id", `Can't delete the home page`);}- await db.build.deletePage({+ await deletePage({projectId,buildId: devBuild.id,pageId: id,@@ -182,7 +190,7 @@ export const loader = async ({throw new Error(`Project ID required`);}- const prodBuild = await db.build.loadByProjectId(params.projectId, "prod");+ const prodBuild = await loadBuildByProjectId(params.projectId, "prod");if (prodBuild === undefined) {throw new Error(diff --git a/apps/builder/app/routes/rest/patch.ts b/apps/builder/app/routes/rest/patch.tsindex 48ab504d74..7ab543b232 100644--- a/apps/builder/app/routes/rest/patch.ts+++ b/apps/builder/app/routes/rest/patch.ts@@ -1,9 +1,15 @@import type { ActionArgs } from "@remix-run/node";import type { SyncItem } from "immerhin";import type { Build, Tree } from "@webstudio-is/project-build";-import * as buildDb from "@webstudio-is/project-build/server";+import {+ patchBreakpoints,+ patchProps,+ patchStyles,+ patchStyleSources,+ patchStyleSourceSelections,+ patchTree,+} from "@webstudio-is/project-build/server";import type { Project } from "@webstudio-is/project";-import { db as projectDb } from "@webstudio-is/project/server";import { createContext } from "~/shared/context.server";type PatchData = {@@ -36,29 +42,21 @@ export const action = async ({ request }: ActionArgs) => {const { namespace, patches } = change;if (namespace === "root") {- await buildDb.patchTree({ treeId, projectId }, patches, context);+ await patchTree({ treeId, projectId }, patches, context);} else if (namespace === "styleSourceSelections") {- await buildDb.patchStyleSourceSelections(+ await patchStyleSourceSelections({ treeId, projectId },patches,context);} else if (namespace === "styleSources") {- await projectDb.styleSources.patch(- { buildId, projectId },- patches,- context- );+ await patchStyleSources({ buildId, projectId }, patches, context);} else if (namespace === "styles") {- await projectDb.styles.patch({ buildId, projectId }, patches, context);+ await patchStyles({ buildId, projectId }, patches, context);} else if (namespace === "props") {- await buildDb.patchProps({ treeId, projectId }, patches, context);+ await patchProps({ treeId, projectId }, patches, context);} else if (namespace === "breakpoints") {- await projectDb.breakpoints.patch(- { buildId, projectId },- patches,- context- );+ await patchBreakpoints({ buildId, projectId }, patches, context);} else {return { errors: `Unknown namespace "${namespace}"` };}diff --git a/apps/builder/app/shared/db/canvas.server.ts b/apps/builder/app/shared/db/canvas.server.tsindex 8bbfb810e4..ad48e853bd 100644--- a/apps/builder/app/shared/db/canvas.server.ts+++ b/apps/builder/app/shared/db/canvas.server.ts@@ -1,9 +1,12 @@import type { CanvasData, Project } from "@webstudio-is/project";-import * as buildDb from "@webstudio-is/project-build/server";-import { utils } from "@webstudio-is/project";+import {+ loadBuildByProjectId,+ loadTreeById,+} from "@webstudio-is/project-build/server";import { db as projectDb } from "@webstudio-is/project/server";import { loadByProject } from "@webstudio-is/asset-uploader/server";import type { AppContext } from "@webstudio-is/trpc-interface/server";+import { findPageByIdOrPath } from "@webstudio-is/project-build";export const loadProductionCanvasData = async (props: {@@ -13,10 +16,7 @@ export const loadProductionCanvasData = async (): Promise<CanvasData[]> => {const pagesCanvasData: CanvasData[] = [];- const prodBuild = await projectDb.build.loadByProjectId(- props.projectId,- "prod"- );+ const prodBuild = await loadBuildByProjectId(props.projectId, "prod");if (prodBuild === undefined) {throw new Error(`Project ${props.projectId} not found or not published yet. Please contact us to get help.`@@ -66,21 +66,21 @@ export const loadCanvasData = async (): Promise<CanvasData> => {const build =props.env === "dev"- ? await projectDb.build.loadByProjectId(props.project.id, "dev")- : await projectDb.build.loadByProjectId(props.project.id, "prod");+ ? await loadBuildByProjectId(props.project.id, "dev")+ : await loadBuildByProjectId(props.project.id, "prod");if (build === undefined) {throw new Error("The project is not published");}- const page = utils.pages.findByIdOrPath(build.pages, props.pageIdOrPath);+ const page = findPageByIdOrPath(build.pages, props.pageIdOrPath);if (page === undefined) {throw new Error(`Page ${props.pageIdOrPath} not found`);}const [tree, assets] = await Promise.all([- buildDb.loadTreeById(+ loadTreeById({projectId: props.project.id,treeId: page.treeId,diff --git a/apps/builder/app/shared/db/misc.server.ts b/apps/builder/app/shared/db/misc.server.tsindex 414ca55c5a..9d4e6a6d17 100644--- a/apps/builder/app/shared/db/misc.server.ts+++ b/apps/builder/app/shared/db/misc.server.ts@@ -1,6 +1,10 @@import { db } from "@webstudio-is/project/server";import { prisma } from "@webstudio-is/prisma-client";import type { AppContext } from "@webstudio-is/trpc-interface/server";+import {+ createBuild,+ loadBuildByProjectId,+} from "@webstudio-is/project-build/server";/*** Conceptually publishing is cloning all data that affects user site@@ -28,10 +32,10 @@ export const publish = async (throw new Error(`Project "${projectId}" not found`);}- const devBuild = await db.build.loadByProjectId(projectId, "dev");+ const devBuild = await loadBuildByProjectId(projectId, "dev");await prisma.$transaction(async (client) => {- await db.build.create(+ await createBuild({ projectId: project.id, env: "prod", sourceBuild: devBuild },context,clientdiff --git a/packages/project-build/jest.config.js b/packages/project-build/jest.config.jsnew file mode 100644index 0000000000..e7fc137533--- /dev/null+++ b/packages/project-build/jest.config.js@@ -0,0 +1 @@+export { default } from "@webstudio-is/jest-config";diff --git a/packages/project-build/package.json b/packages/project-build/package.jsonindex 828d0115f3..099018b1cb 100644--- a/packages/project-build/package.json+++ b/packages/project-build/package.json@@ -16,13 +16,15 @@"types": "src/index.ts","files": ["lib/*",- "src/*"+ "src/*",+ "!*.test.*"],"sideEffects": false,"scripts": {"typecheck": "tsc --noEmit",+ "test": "NODE_OPTIONS=--experimental-vm-modules jest","lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",- "checks": "pnpm typecheck && pnpm lint",+ "checks": "pnpm typecheck && pnpm lint && pnpm test","dev": "build-package --watch","build": "build-package"},@@ -33,11 +35,16 @@"@webstudio-is/trpc-interface": "workspace:^","immer": "^9.0.12","nanoid": "^3.2.0",+ "uuid": "^9.0.0","zod": "^3.19.1"},"devDependencies": {+ "@jest/globals": "^29.3.1",+ "@types/uuid": "^8.3.4",+ "@webstudio-is/jest-config": "workspace:^","@webstudio-is/scripts": "workspace:^","@webstudio-is/tsconfig": "workspace:^",+ "jest": "^29.3.1","typescript": "4.9.5"}}diff --git a/packages/project/src/db/breakpoints.ts b/packages/project-build/src/db/breakpoints.tssimilarity index 87%rename from packages/project/src/db/breakpoints.tsrename to packages/project-build/src/db/breakpoints.tsindex e3c519f71e..537d6dca9a 100644--- a/packages/project/src/db/breakpoints.ts+++ b/packages/project-build/src/db/breakpoints.ts@@ -1,13 +1,13 @@import { nanoid } from "nanoid";import { applyPatches, type Patch } from "immer";-import { initialBreakpoints } from "@webstudio-is/react-sdk";import { type Project, prisma } from "@webstudio-is/prisma-client";+import type { Build } from "../types";import {- type Build,- Breakpoint,+ type Breakpoint,Breakpoints,BreakpointsList,-} from "@webstudio-is/project-build";+ initialBreakpoints,+} from "../schema/breakpoints";import {authorizeProject,type AppContext,@@ -25,7 +25,10 @@ export const serializeBreakpoints = (breakpointssMap: Breakpoints) => {return JSON.stringify(breakpointssList);};-export const createValues = (): [Breakpoint["id"], Breakpoint][] => {+export const createInitialBreakpoints = (): [+ Breakpoint["id"],+ Breakpoint+][] => {return initialBreakpoints.map((breakpoint) => {const id = nanoid();return [@@ -38,7 +41,7 @@ export const createValues = (): [Breakpoint["id"], Breakpoint][] => {});};-export const patch = async (+export const patchBreakpoints = async ({ buildId, projectId }: { buildId: Build["id"]; projectId: Project["id"] },patches: Array<Patch>,context: AppContextdiff --git a/packages/project/src/db/build.ts b/packages/project-build/src/db/build.tssimilarity index 87%rename from packages/project/src/db/build.tsrename to packages/project-build/src/db/build.tsindex bb2de7a165..b620768088 100644--- a/packages/project/src/db/build.ts+++ b/packages/project-build/src/db/build.ts@@ -6,13 +6,22 @@ import {Project,} from "@webstudio-is/prisma-client";import type { AppContext } from "@webstudio-is/trpc-interface";-import { type Build, type Page, Pages } from "@webstudio-is/project-build";-import * as buildDb from "@webstudio-is/project-build/server";-import * as db from ".";-import * as pagesUtils from "../shared/pages";-import { parseBreakpoints, serializeBreakpoints } from "./breakpoints";+import { findPageByIdOrPath } from "../shared/pages-utils";+import type { Build } from "../types";+import { type Page, Pages } from "../schema/pages";+import {+ createInitialBreakpoints,+ parseBreakpoints,+ serializeBreakpoints,+} from "./breakpoints";import { parseStyles, serializeStyles } from "./styles";import { parseStyleSources, serializeStyleSources } from "./style-sources";+import {+ cloneTree,+ createNewTreeData,+ createTree,+ deleteTreeById,+} from "./tree";const parseBuild = async (build: DbBuild): Promise<Build> => {const pages = Pages.parse(JSON.parse(build.pages));@@ -29,7 +38,7 @@ const parseBuild = async (build: DbBuild): Promise<Build> => {};};-export const loadById = async ({+export const loadBuildById = async ({projectId,buildId,}: {@@ -49,16 +58,16 @@ export const loadById = async ({return parseBuild(build);};-export async function loadByProjectId(+export async function loadBuildByProjectId(projectId: Build["projectId"],env: "dev"): Promise<Build>;-export async function loadByProjectId(+export async function loadBuildByProjectId(projectId: Build["projectId"],env: "prod"): Promise<Build | undefined>;// eslint-disable-next-line func-style-export async function loadByProjectId(+export async function loadBuildByProjectId(projectId: Build["projectId"],env: "prod" | "dev"): Promise<Build | undefined> {@@ -89,7 +98,7 @@ const updatePages = async ({ projectId, buildId }: { projectId: Project["id"]; buildId: Build["id"] },updater: (currentPages: Pages) => Promise<Pages>) => {- const build = await loadById({ projectId, buildId });+ const build = await loadBuildById({ projectId, buildId });const updatedPages = Pages.parse(await updater(build.pages));const updatedBuild = await prisma.build.update({where: {@@ -113,9 +122,7 @@ export const addPage = async ({Partial<Omit<Page, "id" | "treeId" | "name" | "path">>;}) => {return updatePages({ projectId, buildId }, async (currentPages) => {- const tree = await buildDb.createTree(- buildDb.createNewTreeData({ projectId, buildId })- );+ const tree = await createTree(createNewTreeData({ projectId, buildId }));return {homePage: currentPages.homePage,@@ -146,7 +153,7 @@ export const editPage = async ({data: Partial<Omit<Page, "id" | "treeId">>;}) => {return updatePages({ projectId, buildId }, async (currentPages) => {- const currentPage = pagesUtils.findByIdOrPath(currentPages, pageId);+ const currentPage = findPageByIdOrPath(currentPages, pageId);if (currentPage === undefined) {throw new Error(`Page with id "${pageId}" not found`);}@@ -186,12 +193,12 @@ export const deletePage = async ({throw new Error("Cannot delete home page");}- const page = pagesUtils.findByIdOrPath(currentPages, pageId);+ const page = findPageByIdOrPath(currentPages, pageId);if (page === undefined) {throw new Error(`Page with id "${pageId}" not found`);}- await buildDb.deleteTreeById({ projectId, treeId: page.treeId });+ await deleteTreeById({ projectId, treeId: page.treeId });return {homePage: currentPages.homePage,@@ -205,8 +212,8 @@ const createPages = async (_context: AppContext,client: Prisma.TransactionClient = prisma) => {- const tree = await buildDb.createTree(- buildDb.createNewTreeData({ projectId, buildId }),+ const tree = await createTree(+ createNewTreeData({ projectId, buildId }),client);return Pages.parse({@@ -228,7 +235,7 @@ const clonePage = async (context: AppContext,client: Prisma.TransactionClient = prisma) => {- const tree = await buildDb.cloneTree(+ const tree = await cloneTree({ projectId: from.projectId, treeId: from.page.treeId },to,context,@@ -266,7 +273,7 @@ const clonePages = async (* 2. when we clone a project* We create "prod" build when we publish a dev build.*/-export async function create(+export async function createBuild(props: {projectId: Build["projectId"];env: "prod";@@ -275,7 +282,7 @@ export async function create(context: AppContext,client: Prisma.TransactionClient): Promise<void>;-export async function create(+export async function createBuild(props: {projectId: Build["projectId"];env: "dev";@@ -285,7 +292,7 @@ export async function create(client: Prisma.TransactionClient): Promise<void>;// eslint-disable-next-line func-style-export async function create(+export async function createBuild(props: {projectId: Build["projectId"];env: "dev" | "prod";@@ -320,7 +327,7 @@ export async function create(projectId: props.projectId,pages: JSON.stringify([]),breakpoints: serializeBreakpoints(- new Map(props.sourceBuild?.breakpoints ?? db.breakpoints.createValues())+ new Map(props.sourceBuild?.breakpoints ?? createInitialBreakpoints())),styles: serializeStyles(new Map(props.sourceBuild?.styles)),styleSources: serializeStyleSources(diff --git a/packages/project/src/db/style-sources.ts b/packages/project-build/src/db/style-sources.tssimilarity index 90%rename from packages/project/src/db/style-sources.tsrename to packages/project-build/src/db/style-sources.tsindex 8ba23288da..f19394d011 100644--- a/packages/project/src/db/style-sources.ts+++ b/packages/project-build/src/db/style-sources.ts@@ -4,11 +4,8 @@ import {authorizeProject,type AppContext,} from "@webstudio-is/trpc-interface/server";-import {- type Build,- StyleSourcesList,- StyleSources,-} from "@webstudio-is/project-build";+import type { Build } from "../types";+import { StyleSourcesList, StyleSources } from "../schema/style-sources";export const parseStyleSources = (styleSourceString: string): StyleSources => {const styleSourcesList = StyleSourcesList.parse(@@ -24,7 +21,7 @@ export const serializeStyleSources = (styleSourcesMap: StyleSources) => {return JSON.stringify(styleSourcesList);};-export const patch = async (+export const patchStyleSources = async ({ buildId, projectId }: { buildId: Build["id"]; projectId: Project["id"] },patches: Array<Patch>,context: AppContextdiff --git a/packages/project/src/db/styles.ts b/packages/project-build/src/db/styles.tssimilarity index 97%rename from packages/project/src/db/styles.tsrename to packages/project-build/src/db/styles.tsindex a4feae7bf7..6cbd8fb0a2 100644--- a/packages/project/src/db/styles.ts+++ b/packages/project-build/src/db/styles.ts@@ -4,17 +4,17 @@ import { type Project, prisma } from "@webstudio-is/prisma-client";import type { Asset } from "@webstudio-is/asset-uploader";import { formatAsset } from "@webstudio-is/asset-uploader/server";import {- type Build,+ authorizeProject,+ type AppContext,+} from "@webstudio-is/trpc-interface/server";+import type { Build } from "../types";+import {type StoredStyleDecl,type StyleDecl,getStyleDeclKey,StoredStyles,Styles,-} from "@webstudio-is/project-build";-import {- authorizeProject,- type AppContext,-} from "@webstudio-is/trpc-interface/server";+} from "../schema/styles";const parseValue = (styleValue: StoredStyleDecl["value"],@@ -119,7 +119,7 @@ export const serializeStyles = (styles: Styles) => {return JSON.stringify(storedStyles);};-export const patch = async (+export const patchStyles = async ({ buildId, projectId }: { buildId: Build["id"]; projectId: Project["id"] },patches: Array<Patch>,context: AppContextdiff --git a/packages/project-build/src/index.server.ts b/packages/project-build/src/index.server.tsindex c88a4ab250..dfb19b9db6 100644--- a/packages/project-build/src/index.server.ts+++ b/packages/project-build/src/index.server.ts@@ -1,3 +1,7 @@+export * from "./db/build";+export * from "./db/breakpoints";+export * from "./db/styles";+export * from "./db/style-sources";export * from "./db/tree";export * from "./db/props";export * from "./db/style-source-selections";diff --git a/packages/project-build/src/index.ts b/packages/project-build/src/index.tsindex b6cc723335..7d4cd7fe3e 100644--- a/packages/project-build/src/index.ts+++ b/packages/project-build/src/index.ts@@ -6,3 +6,4 @@ export * from "./schema/style-sources";export * from "./schema/style-source-selections";export * from "./schema/breakpoints";export * from "./types";+export * from "./shared/pages-utils";diff --git a/packages/project-build/src/schema/breakpoints.ts b/packages/project-build/src/schema/breakpoints.tsindex 28d4673d8e..6f2a553c2d 100644--- a/packages/project-build/src/schema/breakpoints.ts+++ b/packages/project-build/src/schema/breakpoints.ts@@ -17,3 +17,12 @@ export type BreakpointsList = z.infer<typeof BreakpointsList>;export const Breakpoints = z.map(BreakpointId, Breakpoint);export type Breakpoints = z.infer<typeof Breakpoints>;++type BaseBreakpoint = Pick<Breakpoint, "label" | "minWidth">;++export const initialBreakpoints: BaseBreakpoint[] = [+ { label: "Mobile", minWidth: 0 },+ { label: "Tablet", minWidth: 768 },+ { label: "Laptop", minWidth: 1024 },+ { label: "Desktop", minWidth: 1280 },+];diff --git a/packages/project/src/shared/pages/find-by-id-or-path.test.ts b/packages/project-build/src/shared/pages-utils.test.tssimilarity index 72%rename from packages/project/src/shared/pages/find-by-id-or-path.test.tsrename to packages/project-build/src/shared/pages-utils.test.tsindex 37dd0a60e8..3ad01ee540 100644--- a/packages/project/src/shared/pages/find-by-id-or-path.test.ts+++ b/packages/project-build/src/shared/pages-utils.test.ts@@ -1,5 +1,5 @@import { describe, test, expect } from "@jest/globals";-import { findByIdOrPath } from "./find-by-id-or-path";+import { findPageByIdOrPath } from "./pages-utils";const pages = {homePage: {@@ -24,23 +24,23 @@ const pages = {describe("Find by id or path", () => {test("home page by id", () => {- const page = findByIdOrPath(pages, "home");+ const page = findPageByIdOrPath(pages, "home");expect(page).toEqual(pages.homePage);});test("home page by path /", () => {- const page = findByIdOrPath(pages, "/");+ const page = findPageByIdOrPath(pages, "/");expect(page).toEqual(pages.homePage);});test("home page by empty path", () => {- const page = findByIdOrPath(pages, "");+ const page = findPageByIdOrPath(pages, "");expect(page).toEqual(pages.homePage);});test("find page by id", () => {- const page = findByIdOrPath(pages, "page1");+ const page = findPageByIdOrPath(pages, "page1");expect(page).toEqual(pages.pages[0]);});test("find page by path", () => {- const page = findByIdOrPath(pages, "/page1");+ const page = findPageByIdOrPath(pages, "/page1");expect(page).toEqual(pages.pages[0]);});});diff --git a/packages/project/src/shared/pages/find-by-id-or-path.ts b/packages/project-build/src/shared/pages-utils.tssimilarity index 73%rename from packages/project/src/shared/pages/find-by-id-or-path.tsrename to packages/project-build/src/shared/pages-utils.tsindex 1fd934e113..ebbcd4ac5c 100644--- a/packages/project/src/shared/pages/find-by-id-or-path.ts+++ b/packages/project-build/src/shared/pages-utils.ts@@ -1,6 +1,6 @@-import type { Pages, Page } from "@webstudio-is/project-build";+import type { Pages, Page } from "../schema/pages";-export const findByIdOrPath = (+export const findPageByIdOrPath = (pages: Pages,idOrPath: string): Page | undefined => {diff --git a/packages/project/src/db/index.ts b/packages/project/src/db/index.tsindex 9c0b38c5be..fd0f04972d 100644--- a/packages/project/src/db/index.ts+++ b/packages/project/src/db/index.ts@@ -1,6 +1,2 @@import * as project from "./project";-import * as styles from "./styles";-import * as styleSources from "./style-sources";-import * as breakpoints from "./breakpoints";-import * as build from "./build";-export { project, breakpoints, styles, styleSources, build };+export { project };diff --git a/packages/project/src/db/project.ts b/packages/project/src/db/project.tsindex b8fa7d3bc3..fd09ee8aa0 100644--- a/packages/project/src/db/project.ts+++ b/packages/project/src/db/project.ts@@ -1,13 +1,16 @@import slugify from "slugify";import { customAlphabet } from "nanoid";+import { v4 as uuid } from "uuid";import { prisma, Prisma } from "@webstudio-is/prisma-client";import { cloneAssets } from "@webstudio-is/asset-uploader/server";-import * as db from "./index";import {authorizeProject,type AppContext,} from "@webstudio-is/trpc-interface/server";-import { v4 as uuid } from "uuid";+import {+ createBuild,+ loadBuildByProjectId,+} from "@webstudio-is/project-build/server";import { Project, Title } from "../shared/schema";const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz");@@ -105,7 +108,7 @@ export const create = async (},});- await db.build.create(+ await createBuild({ projectId: project.id, env: "dev", sourceBuild: undefined },context,client@@ -185,8 +188,8 @@ const clone = async (const build =env === "dev"- ? await db.build.loadByProjectId(project.id, "dev")- : await db.build.loadByProjectId(project.id, "prod");+ ? await loadBuildByProjectId(project.id, "dev")+ : await loadBuildByProjectId(project.id, "prod");const newProjectId = uuid();await authorizeProject.registerProjectOwner(@@ -204,7 +207,7 @@ const clone = async (},});- await db.build.create(+ await createBuild({ projectId: newProjectId, env: "dev", sourceBuild: build },context,clientdiff --git a/packages/project/src/index.ts b/packages/project/src/index.tsindex bb45c86fb1..916e7c5f50 100644--- a/packages/project/src/index.ts+++ b/packages/project/src/index.ts@@ -1,11 +1,9 @@import * as breakpointsUtils from "./shared/breakpoints";import * as treeUtils from "./shared/tree-utils";-import * as pagesUtils from "./shared/pages";export const utils = {breakpoints: breakpointsUtils,tree: treeUtils,- pages: pagesUtils,} as const;export * from "./shared/styles";diff --git a/packages/project/src/shared/breakpoints/sort.test.ts b/packages/project/src/shared/breakpoints/sort.test.tsindex f00930c17a..94eaaded16 100644--- a/packages/project/src/shared/breakpoints/sort.test.ts+++ b/packages/project/src/shared/breakpoints/sort.test.ts@@ -1,6 +1,8 @@import { describe, test, expect } from "@jest/globals";-import type { Breakpoints } from "@webstudio-is/project-build";-import { initialBreakpoints } from "@webstudio-is/react-sdk";+import {+ type Breakpoints,+ initialBreakpoints,+} from "@webstudio-is/project-build";import { nanoid } from "nanoid";import { sort } from "./sort";diff --git a/packages/project/src/shared/pages/index.ts b/packages/project/src/shared/pages/index.tsdeleted file mode 100644index f554ddda7a..0000000000--- a/packages/project/src/shared/pages/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from "./find-by-id-or-path";diff --git a/packages/react-sdk/src/css/breakpoints.ts b/packages/react-sdk/src/css/breakpoints.tsdeleted file mode 100644index cffb50b595..0000000000--- a/packages/react-sdk/src/css/breakpoints.ts+++ /dev/null@@ -1,10 +0,0 @@-import type { Breakpoint } from "@webstudio-is/project-build";--export type BaseBreakpoint = Pick<Breakpoint, "label" | "minWidth">;--export const initialBreakpoints: Array<BaseBreakpoint> = [- { label: "Mobile", minWidth: 0 },- { label: "Tablet", minWidth: 768 },- { label: "Laptop", minWidth: 1024 },- { label: "Desktop", minWidth: 1280 },-];diff --git a/packages/react-sdk/src/css/index.ts b/packages/react-sdk/src/css/index.tsindex 3802fb8bcb..8c0502a3e1 100644--- a/packages/react-sdk/src/css/index.ts+++ b/packages/react-sdk/src/css/index.ts@@ -1,3 +1,2 @@export * from "./get-browser-style";export * from "./categories";-export * from "./breakpoints";diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0f96924be1..3bac490858 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -825,15 +825,20 @@ importers:packages/project-build:specifiers:+ '@jest/globals': ^29.3.1+ '@types/uuid': ^8.3.4'@webstudio-is/asset-uploader': workspace:^'@webstudio-is/css-data': workspace:^+ '@webstudio-is/jest-config': workspace:^'@webstudio-is/prisma-client': workspace:^'@webstudio-is/scripts': workspace:^'@webstudio-is/trpc-interface': workspace:^'@webstudio-is/tsconfig': workspace:^immer: ^9.0.12+ jest: ^29.3.1nanoid: ^3.2.0typescript: 4.9.5+ uuid: ^9.0.0zod: ^3.19.1dependencies:'@webstudio-is/asset-uploader': link:../asset-uploader@@ -842,10 +847,15 @@ importers:'@webstudio-is/trpc-interface': link:../trpc-interfaceimmer: 9.0.15nanoid: 3.3.4+ uuid: 9.0.0zod: 3.19.1devDependencies:+ '@jest/globals': 29.3.1+ '@types/uuid': 8.3.4+ '@webstudio-is/jest-config': link:../jest-config'@webstudio-is/scripts': link:../scripts'@webstudio-is/tsconfig': link:../tsconfig+ jest: 29.3.1typescript: 4.9.5packages/react-sdk:@@ -4768,7 +4778,6 @@ packages:engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}dependencies:jest-get-type: 29.4.2- dev: true/@jest/expect/29.3.1:resolution: {integrity: sha512-QivM7GlSHSsIAWzgfyP8dgeExPRZ9BIe2LsdPyEhCGkZkoyA+kGsoIzbKAfZCvvRzfZioKwPtCZIt5SaoxYCvg==}@@ -14225,7 +14234,6 @@ packages:jest-matcher-utils: 29.4.2jest-message-util: 29.4.2jest-util: 29.4.2- dev: true/express/4.18.1:resolution: {integrity: sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==}@@ -16633,7 +16641,7 @@ packages:'@types/prettier': 2.7.1babel-preset-current-node-syntax: 1.0.1_@[email protected]chalk: 4.1.2- expect: 29.3.1+ expect: 29.4.2graceful-fs: 4.2.10jest-diff: 29.3.1jest-get-type: 29.2.0@@ -16642,7 +16650,7 @@ packages:jest-message-util: 29.3.1jest-util: 29.3.1natural-compare: 1.4.0- pretty-format: 29.3.1+ pretty-format: 29.4.2semver: 7.3.8transitivePeerDependencies:- supports-color