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
remove Shema suffix
Roman Pominov6d9c66e0a0d8
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx b/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsxindex 72ce1c953d..f23c633d44 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx@@ -3,7 +3,7 @@ import { type Publish } from "~/shared/pubsub";import { PageIcon } from "@webstudio-is/icons";import type { TabName } from "../../types";import { Header } from "../../lib/header";-import { type Page, type Pages } from "@webstudio-is/project";+import { type Page, type Pages as PagesType } from "@webstudio-is/project";import { useMemo } from "react";import { useNavigate } from "react-router-dom";import { type Config } from "~/config";@@ -32,7 +32,7 @@ type PagesTreeNode =data: Page;};-const toTreeData = (pages: Pages): PagesTreeNode => {+const toTreeData = (pages: PagesType): PagesTreeNode => {return {type: "folder",id: "root",diff --git a/apps/designer/app/routes/designer/_assets.tsx b/apps/designer/app/routes/designer/_assets.tsxindex 8087155cb4..014a84e5d7 100644--- a/apps/designer/app/routes/designer/_assets.tsx+++ b/apps/designer/app/routes/designer/_assets.tsx@@ -13,7 +13,7 @@ import { useEffect } from "react";import { zfd } from "zod-form-data";import type { ActionData } from "~/designer/shared/assets";-const deleteAssetSchema = zfd.formData({+const DeleteAssetInput = zfd.formData({assetId: zfd.text(),assetName: zfd.text(),});@@ -25,7 +25,7 @@ export const action: ActionFunction = async ({if (params.id === undefined) throw new Error("Project id undefined");try {if (request.method === "DELETE") {- const { assetId, assetName } = deleteAssetSchema.parse(+ const { assetId, assetName } = DeleteAssetInput.parse(await request.formData());const deletedAsset = await deleteAsset({diff --git a/packages/project/src/db/breakpoints.ts b/packages/project/src/db/breakpoints.tsindex 85ecf05d1b..e095f2a19f 100644--- a/packages/project/src/db/breakpoints.ts+++ b/packages/project/src/db/breakpoints.ts@@ -1,13 +1,16 @@import {initialBreakpoints,- type Breakpoint,- BreakpointsSchema,+ Breakpoint,+ Breakpoints,} from "@webstudio-is/react-sdk";import ObjectId from "bson-objectid";import { applyPatches, type Patch } from "immer";-import { type Breakpoints, prisma } from "@webstudio-is/prisma-client";+import {+ type Breakpoints as DbBreakpoints,+ prisma,+} from "@webstudio-is/prisma-client";-export const load = async (buildId: Breakpoints["buildId"]) => {+export const load = async (buildId: DbBreakpoints["buildId"]) => {const breakpoints = await prisma.breakpoints.findUnique({where: { buildId },});@@ -16,7 +19,7 @@ export const load = async (buildId: Breakpoints["buildId"]) => {throw new Error("Breakpoints not found");}const values: Array<Breakpoint> = JSON.parse(breakpoints.values);- BreakpointsSchema.parse(values);+ Breakpoints.parse(values);return {...breakpoints,values,@@ -24,7 +27,7 @@ export const load = async (buildId: Breakpoints["buildId"]) => {};export const createValues = () =>- BreakpointsSchema.parse(+ Breakpoints.parse(initialBreakpoints.map((breakpoint) => ({...breakpoint,id: ObjectId().toString(),@@ -32,7 +35,7 @@ export const createValues = () =>);export const create = async (- buildId: Breakpoints["buildId"],+ buildId: DbBreakpoints["buildId"],values: Array<Breakpoint>) => {const breakpoints = await prisma.breakpoints.create({@@ -49,13 +52,13 @@ export const create = async (};export const patch = async (- buildId: Breakpoints["buildId"],+ buildId: DbBreakpoints["buildId"],patches: Array<Patch>) => {const breakpoints = await load(buildId);const nextValues = applyPatches(breakpoints.values, patches);- BreakpointsSchema.parse(nextValues);+ Breakpoints.parse(nextValues);await prisma.breakpoints.update({where: { buildId: breakpoints.buildId },diff --git a/packages/project/src/db/build.ts b/packages/project/src/db/build.tsindex 523b3a9359..19877cc298 100644--- a/packages/project/src/db/build.ts+++ b/packages/project/src/db/build.ts@@ -2,10 +2,10 @@ import { prisma, Build as DbBuild } from "@webstudio-is/prisma-client";import { type Breakpoint } from "@webstudio-is/react-sdk";import { v4 as uuid } from "uuid";import * as db from ".";-import { Build, Page, Pages, PagesSchema } from "./types";+import { Build, Page, Pages } from "./types";export const parseBuild = (build: DbBuild): Build => {- const pages = PagesSchema.parse(JSON.parse(build.pages));+ const pages = Pages.parse(JSON.parse(build.pages));return { ...build, pages };};@@ -65,7 +65,7 @@ const createPages = async (breakpoints: Array<Breakpoint>) => {// const breakpoints = db.breakpoints.getBreakpointsWithId();const tree = await db.tree.create(db.tree.createRootInstance(breakpoints));// await db.breakpoints.create(tree.id, breakpoints);- return PagesSchema.parse({+ return Pages.parse({homePage: {id: uuid(),name: "Home",@@ -92,7 +92,7 @@ const clonePages = async (source: Pages) => {for (const page of source.pages) {clones.push(await clonePage(page));}- return PagesSchema.parse({+ return Pages.parse({homePage: await clonePage(source.homePage),pages: clones,});diff --git a/packages/project/src/db/props.ts b/packages/project/src/db/props.tsindex 8122e8d263..d276b30511 100644--- a/packages/project/src/db/props.ts+++ b/packages/project/src/db/props.ts@@ -1,7 +1,7 @@import {type Tree,type AllUserProps,- UserPropsSchema,+ UserProps,} from "@webstudio-is/react-sdk";import { applyPatches, type Patch } from "immer";import { prisma } from "@webstudio-is/prisma-client";@@ -13,7 +13,7 @@ export const loadByTreeId = async (treeId: Tree["id"]) => {return instancePropsEntries.map((instanceProps) => {const props = JSON.parse(instanceProps.props);- UserPropsSchema.parse(props);+ UserProps.parse(props);return {...instanceProps,props,@@ -66,7 +66,7 @@ export const patch = async (await Promise.all(Object.values(nextProps).map(({ id, instanceId, treeId, props }) => {- UserPropsSchema.parse(props);+ UserProps.parse(props);const propsString = JSON.stringify(props);return prisma.instanceProps.upsert({where: { id: id },diff --git a/packages/project/src/db/tree.ts b/packages/project/src/db/tree.tsindex 859cc8b025..8e4c1f5545 100644--- a/packages/project/src/db/tree.ts+++ b/packages/project/src/db/tree.ts@@ -1,9 +1,4 @@-import {- type Instance,- type Breakpoint,- type Tree,- InstanceSchema,-} from "@webstudio-is/react-sdk";+import { type Breakpoint, type Tree, Instance } from "@webstudio-is/react-sdk";import { applyPatches, type Patch } from "immer";import { prisma } from "@webstudio-is/prisma-client";import { Tree as DbTree } from "@prisma/client";@@ -20,7 +15,7 @@ export const createRootInstance = (breakpoints: Array<Breakpoint>) => {};export const create = async (root: Instance): Promise<DbTree> => {- InstanceSchema.parse(root);+ Instance.parse(root);const rootString = JSON.stringify(root);return await prisma.tree.create({data: { root: rootString },@@ -35,7 +30,7 @@ export const loadById = async (treeId: string): Promise<Tree | null> => {if (tree === null) return null;const root = JSON.parse(tree.root);- InstanceSchema.parse(root);+ Instance.parse(root);return {...tree,root,@@ -59,7 +54,7 @@ export const patchRoot = async (throw new Error(`Tree ${treeId} not found`);}const root = applyPatches(tree.root, patches);- InstanceSchema.parse(root);+ Instance.parse(root);await prisma.tree.update({data: { root: JSON.stringify(root) },where: { id: treeId },diff --git a/packages/project/src/db/types.ts b/packages/project/src/db/types.tsindex 5183eead93..e7f1f543c5 100644--- a/packages/project/src/db/types.ts+++ b/packages/project/src/db/types.ts@@ -9,7 +9,7 @@ export type Project = Omit<BaseProject, "assets"> & {assets?: Array<Asset>;};-const PageSchema = z.object({+const Page = z.object({id: z.string(),name: z.string(),path: z.string(),@@ -18,13 +18,13 @@ const PageSchema = z.object({treeId: z.string(),});-export type Page = z.infer<typeof PageSchema>;+export type Page = z.infer<typeof Page>;-export const PagesSchema: z.ZodType<{ homePage: Page; pages: Array<Page> }> =+export const Pages: z.ZodType<{ homePage: Page; pages: Array<Page> }> =z.object({- homePage: PageSchema,- pages: z.array(PageSchema),+ homePage: Page,+ pages: z.array(Page),});-export type Pages = z.infer<typeof PagesSchema>;+export type Pages = z.infer<typeof Pages>;export type Build = Omit<DbBuild, "pages"> & { pages: Pages };diff --git a/packages/react-sdk/src/components/component-type.ts b/packages/react-sdk/src/components/component-type.tsindex a913cca8aa..631763be77 100644--- a/packages/react-sdk/src/components/component-type.ts+++ b/packages/react-sdk/src/components/component-type.ts@@ -19,7 +19,7 @@ export type WsComponentMeta<ComponentType> = {children?: Array<string>;};-export const WsComponentMetaSchema = z.lazy(() =>+export const WsComponentMeta = z.lazy(() =>z.object({Component: z.any(),diff --git a/packages/react-sdk/src/components/index.test.ts b/packages/react-sdk/src/components/index.test.tsindex a3b863d31f..0265c11cfc 100644--- a/packages/react-sdk/src/components/index.test.ts+++ b/packages/react-sdk/src/components/index.test.ts@@ -1,5 +1,5 @@import * as components from "./index";-import { WsComponentMetaSchema } from "./component-type";+import { WsComponentMeta } from "./component-type";test.each(Object.entries(components))("validating meta definition of %s",@@ -7,6 +7,6 @@ test.each(Object.entries(components))(if (name === "default") {return;}- WsComponentMetaSchema.parse(component);+ WsComponentMeta.parse(component);});diff --git a/packages/react-sdk/src/css/index.ts b/packages/react-sdk/src/css/index.tsindex f104fa6d43..73da609888 100644--- a/packages/react-sdk/src/css/index.ts+++ b/packages/react-sdk/src/css/index.ts@@ -5,4 +5,3 @@ export * from "./get-browser-style";export * from "./categories";export * from "./keyword-values";export * from "./breakpoints";-export * from "./schema";diff --git a/packages/react-sdk/src/css/schema.ts b/packages/react-sdk/src/css/schema.tsdeleted file mode 100644index 4cd2443d10..0000000000--- a/packages/react-sdk/src/css/schema.ts+++ /dev/null@@ -1,44 +0,0 @@-import { z } from "zod";-import { units } from "./units";--export const UnitSchema = z.union([z.enum(units), z.literal("number")]);--const UnitValueSchema = z.object({- type: z.literal("unit"),- unit: UnitSchema,- value: z.number(),-});--const KeywordValueSchema = z.object({- type: z.literal("keyword"),- // @todo use exact type- value: z.string(),-});--// We want to be able to render the invalid value-// and show it is invalid visually, without saving it to the db-const InvalidValueSchema = z.object({- type: z.literal("invalid"),- value: z.string(),-});--export const StyleValueSchema = z.union([- UnitValueSchema,- KeywordValueSchema,- InvalidValueSchema,-]);--export const StyleSchema = z.record(z.string(), StyleValueSchema);--export const CssRuleSchema = z.object({- style: StyleSchema,- breakpoint: z.string(),-});--export const BreakpointSchema = z.object({- id: z.string(),- label: z.string(),- minWidth: z.number(),-});--export const BreakpointsSchema = z.array(BreakpointSchema);diff --git a/packages/react-sdk/src/css/types.ts b/packages/react-sdk/src/css/types.tsindex b777676c49..8079125f9f 100644--- a/packages/react-sdk/src/css/types.ts+++ b/packages/react-sdk/src/css/types.ts@@ -1,11 +1,44 @@import { z } from "zod";import { properties } from "./properties";-import {- BreakpointSchema,- CssRuleSchema,- StyleValueSchema,- UnitSchema,-} from "./schema";+import { units } from "./units";++export const Unit = z.union([z.enum(units), z.literal("number")]);++const UnitValue = z.object({+ type: z.literal("unit"),+ unit: Unit,+ value: z.number(),+});++const KeywordValue = z.object({+ type: z.literal("keyword"),+ // @todo use exact type+ value: z.string(),+});++// We want to be able to render the invalid value+// and show it is invalid visually, without saving it to the db+const InvalidValue = z.object({+ type: z.literal("invalid"),+ value: z.string(),+});++export const StyleValue = z.union([UnitValue, KeywordValue, InvalidValue]);++export const Style = z.record(z.string(), StyleValue);++export const CssRule = z.object({+ style: Style,+ breakpoint: z.string(),+});++export const Breakpoint = z.object({+ id: z.string(),+ label: z.string(),+ minWidth: z.number(),+});++export const Breakpoints = z.array(Breakpoint);type Properties = typeof properties;@@ -17,10 +50,10 @@ export type Style = {[property in StyleProperty]?: StyleValue;};-export type CssRule = z.infer<typeof CssRuleSchema>;+export type CssRule = z.infer<typeof CssRule>;-export type Unit = z.infer<typeof UnitSchema>;+export type Unit = z.infer<typeof Unit>;-export type StyleValue = z.infer<typeof StyleValueSchema>;+export type StyleValue = z.infer<typeof StyleValue>;-export type Breakpoint = z.infer<typeof BreakpointSchema>;+export type Breakpoint = z.infer<typeof Breakpoint>;diff --git a/packages/react-sdk/src/db/instance.ts b/packages/react-sdk/src/db/instance.tsindex e5c8b71b2e..3dfdda7122 100644--- a/packages/react-sdk/src/db/instance.ts+++ b/packages/react-sdk/src/db/instance.ts@@ -1,6 +1,6 @@import { z } from "zod";import * as components from "../components";-import { type CssRule, CssRuleSchema } from "../css";+import { CssRule } from "../css";// This should be used when passing a lot of data is potentially costly.// For example, when passing data from an iframe.@@ -22,13 +22,13 @@ export const toBaseInstance = (instance: Instance): BaseInstance => {};};-export const InstanceSchema = z.lazy(+export const Instance = z.lazy(() =>z.object({id: z.string(),component: z.string(),- children: z.array(z.union([InstanceSchema, z.string()])),- cssRules: z.array(CssRuleSchema),+ children: z.array(z.union([Instance, z.string()])),+ cssRules: z.array(CssRule),})// @todo can't figure out how to make component to be z.enum(Object.keys(components))) as z.ZodType<Instance>;diff --git a/packages/react-sdk/src/user-props/index.ts b/packages/react-sdk/src/user-props/index.tsindex d8a42eebec..c40d18919e 100644--- a/packages/react-sdk/src/user-props/index.ts+++ b/packages/react-sdk/src/user-props/index.ts@@ -1,4 +1,3 @@export * from "./all-user-props";export * from "./use-user-props";export * from "./types";-export * from "./schema";diff --git a/packages/react-sdk/src/user-props/schema.ts b/packages/react-sdk/src/user-props/schema.tsdeleted file mode 100644index 9f3345e3ba..0000000000--- a/packages/react-sdk/src/user-props/schema.ts+++ /dev/null@@ -1,10 +0,0 @@-import { z } from "zod";--export const UserPropSchema = z.object({- id: z.string(),- prop: z.string(),- value: z.union([z.string(), z.boolean()]),- required: z.optional(z.boolean()),-});--export const UserPropsSchema = z.array(UserPropSchema);diff --git a/packages/react-sdk/src/user-props/types.ts b/packages/react-sdk/src/user-props/types.tsindex 4f3d1a3b70..e371a6bffe 100644--- a/packages/react-sdk/src/user-props/types.ts+++ b/packages/react-sdk/src/user-props/types.ts@@ -1,8 +1,16 @@import { z } from "zod";import type { InstanceProps, Instance } from "../db";-import { UserPropSchema } from "./schema";-export type UserProp = z.infer<typeof UserPropSchema>;+export const UserProp = z.object({+ id: z.string(),+ prop: z.string(),+ value: z.union([z.string(), z.boolean()]),+ required: z.optional(z.boolean()),+});++export const UserProps = z.array(UserProp);++export type UserProp = z.infer<typeof UserProp>;export type UserPropsUpdates = {treeId: InstanceProps["treeId"];