From aabf248efba161f80f7ad39e2050f9059a57aeb8 Mon Sep 17 00:00:00 2001 From: MH4GF Date: Thu, 26 Dec 2024 14:58:02 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8:=20Add=20setPrismWasmUrl=20functi?= =?UTF-8?q?on=20to=20manage=20WASM=20URL=20for=20Prism?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/packages/db-structure/src/parser.ts | 1 + frontend/packages/db-structure/src/parser/index.ts | 2 ++ .../packages/db-structure/src/parser/schemarb/index.ts | 1 + .../db-structure/src/parser/schemarb/loadPrism.ts | 9 ++++++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/packages/db-structure/src/parser.ts b/frontend/packages/db-structure/src/parser.ts index 5f4f6fdec..69de0a96b 100644 --- a/frontend/packages/db-structure/src/parser.ts +++ b/frontend/packages/db-structure/src/parser.ts @@ -2,4 +2,5 @@ export { parse, type SupportedFormat, supportedFormatSchema, + setPrismWasmUrl, } from './parser/index.js' diff --git a/frontend/packages/db-structure/src/parser/index.ts b/frontend/packages/db-structure/src/parser/index.ts index cd1b1acc0..019ed2e07 100644 --- a/frontend/packages/db-structure/src/parser/index.ts +++ b/frontend/packages/db-structure/src/parser/index.ts @@ -3,6 +3,8 @@ import { processor as schemarbProcessor } from './schemarb/index.js' import { processor as postgresqlProcessor } from './sql/index.js' import type { ProcessResult } from './types.js' +export { setPrismWasmUrl } from './schemarb/index.js' + export const supportedFormatSchema = v.union([ v.literal('schemarb'), v.literal('postgres'), diff --git a/frontend/packages/db-structure/src/parser/schemarb/index.ts b/frontend/packages/db-structure/src/parser/schemarb/index.ts index df41b5fb4..b04b75d83 100644 --- a/frontend/packages/db-structure/src/parser/schemarb/index.ts +++ b/frontend/packages/db-structure/src/parser/schemarb/index.ts @@ -2,3 +2,4 @@ export { processor, UnsupportedTokenError, } from './parser.js' +export { setPrismWasmUrl } from './loadPrism.js' diff --git a/frontend/packages/db-structure/src/parser/schemarb/loadPrism.ts b/frontend/packages/db-structure/src/parser/schemarb/loadPrism.ts index ce25a2d9f..3add9a85e 100644 --- a/frontend/packages/db-structure/src/parser/schemarb/loadPrism.ts +++ b/frontend/packages/db-structure/src/parser/schemarb/loadPrism.ts @@ -21,8 +21,15 @@ import { WASI } from 'node:wasi' import type { ParseResult } from '@ruby/prism/src/deserialize.js' import { parsePrism } from '@ruby/prism/src/parsePrism.js' +let overrideWasmUrl: string | undefined = undefined + +export const setPrismWasmUrl = (url: string): void => { + overrideWasmUrl = url +} + export async function loadPrism(): Promise<(source: string) => ParseResult> { - const path = fileURLToPath(new URL('prism.wasm', import.meta.url)) + const path = + overrideWasmUrl ?? fileURLToPath(new URL('prism.wasm', import.meta.url)) const wasm = await WebAssembly.compile(await readFile(path)) const wasi = new WASI({ version: 'preview1' }) From c917e4286bace80c44525449633b1350301645d5 Mon Sep 17 00:00:00 2001 From: MH4GF Date: Thu, 26 Dec 2024 15:13:31 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8:=20include=20prism.wasm=20and=20s?= =?UTF-8?q?et=20its=20URL=20for=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/apps/erd-web/.gitignore | 2 ++ frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx | 6 +++++- frontend/apps/erd-web/next.config.ts | 4 +++- frontend/apps/erd-web/package.json | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/apps/erd-web/.gitignore b/frontend/apps/erd-web/.gitignore index 5ef6a5207..1ca7541a0 100644 --- a/frontend/apps/erd-web/.gitignore +++ b/frontend/apps/erd-web/.gitignore @@ -39,3 +39,5 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +prism.wasm diff --git a/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx b/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx index 46ff21b93..2c4640168 100644 --- a/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx +++ b/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx @@ -1,4 +1,6 @@ -import { parse } from '@liam-hq/db-structure/parser' +// biome-ignore lint/correctness/noNodejsModules: Required for the server component to read the wasm file +import path from 'node:path' +import { parse, setPrismWasmUrl } from '@liam-hq/db-structure/parser' import { cookies } from 'next/headers' import { notFound } from 'next/navigation' import ERDViewer from './erdViewer' @@ -23,6 +25,8 @@ export default async function Page({ const input = await res.text() + setPrismWasmUrl(path.resolve(process.cwd(), 'prism.wasm')) + // Currently supports Postgres only const { value: dbStructure, errors } = await parse(input, 'postgres') if (errors.length > 0) { diff --git a/frontend/apps/erd-web/next.config.ts b/frontend/apps/erd-web/next.config.ts index 73290639b..6cfe1c31e 100644 --- a/frontend/apps/erd-web/next.config.ts +++ b/frontend/apps/erd-web/next.config.ts @@ -1,7 +1,9 @@ import type { NextConfig } from 'next' const nextConfig: NextConfig = { - /* config options here */ + outputFileTracingIncludes: { + '/erd/p/\\[\\.\\.\\.slug\\]': ['./prism.wasm'], + }, } export default nextConfig diff --git a/frontend/apps/erd-web/package.json b/frontend/apps/erd-web/package.json index d0d3bea16..3da440599 100644 --- a/frontend/apps/erd-web/package.json +++ b/frontend/apps/erd-web/package.json @@ -24,6 +24,7 @@ "fmt:biome": "biome check --write --unsafe .", "lint": "pnpm run '/^lint:.*/'", "lint:biome": "biome check .", + "postinstall": "cp ../../packages/db-structure/src/parser/schemarb/prism.wasm prism.wasm", "start": "next start" } } From 63f86fc72d69815d0bf69cf040ca98e63942609a Mon Sep 17 00:00:00 2001 From: MH4GF Date: Thu, 26 Dec 2024 15:17:32 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=94=A7=20Add=20dependency=20configura?= =?UTF-8?q?tion=20for=20@liam-hq/erd-web=20in=20turbo.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- turbo.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/turbo.json b/turbo.json index d1d190991..5ff4cb26f 100644 --- a/turbo.json +++ b/turbo.json @@ -14,6 +14,11 @@ "cache": false, "persistent": true }, + "@liam-hq/erd-web#dev": { + "dependsOn": ["^build"], + "cache": false, + "persistent": true + }, "gen": { "dependsOn": ["^gen"] }, From bb7f169144aa8abd566447aa388d115df9815516 Mon Sep 17 00:00:00 2001 From: MH4GF Date: Thu, 26 Dec 2024 15:13:41 +0900 Subject: [PATCH 4/5] fix: Temporarily support only schema.rb --- frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx b/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx index 2c4640168..4e5389a3b 100644 --- a/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx +++ b/frontend/apps/erd-web/app/erd/p/[...slug]/page.tsx @@ -27,8 +27,8 @@ export default async function Page({ setPrismWasmUrl(path.resolve(process.cwd(), 'prism.wasm')) - // Currently supports Postgres only - const { value: dbStructure, errors } = await parse(input, 'postgres') + // Currently supports schema.rb only + const { value: dbStructure, errors } = await parse(input, 'schemarb') if (errors.length > 0) { for (const error of errors) { console.error(error) From 8515134b42359dd6fc3e03b5c269146619d9579e Mon Sep 17 00:00:00 2001 From: MH4GF Date: Thu, 26 Dec 2024 15:36:28 +0900 Subject: [PATCH 5/5] maintenance: add changeset --- .changeset/nervous-eyes-check.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nervous-eyes-check.md diff --git a/.changeset/nervous-eyes-check.md b/.changeset/nervous-eyes-check.md new file mode 100644 index 000000000..b2116aa25 --- /dev/null +++ b/.changeset/nervous-eyes-check.md @@ -0,0 +1,5 @@ +--- +"@liam-hq/db-structure": patch +--- + +:sparkles: prism's wasm URL can now be overridden