From 110c7681b791be07d086e69187026bac1a88b447 Mon Sep 17 00:00:00 2001 From: dswbx Date: Sat, 7 Dec 2024 06:29:29 +0100 Subject: [PATCH 1/3] externalize libsql dependency to let installing env install the correct dep Signed-off-by: dswbx --- app/build.ts | 2 +- app/src/App.ts | 22 +++++++++++---------- app/src/data/connection/LibsqlConnection.ts | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/build.ts b/app/build.ts index faa81d0..2889011 100644 --- a/app/build.ts +++ b/app/build.ts @@ -88,7 +88,7 @@ await tsup.build({ watch, entry: ["src/index.ts", "src/data/index.ts", "src/core/index.ts", "src/core/utils/index.ts"], outDir: "dist", - external: ["bun:test"], + external: ["bun:test", "@libsql/client"], metafile: true, platform: "browser", format: ["esm", "cjs"], diff --git a/app/src/App.ts b/app/src/App.ts index a617a0a..289ab47 100644 --- a/app/src/App.ts +++ b/app/src/App.ts @@ -21,7 +21,7 @@ export class AppBuiltEvent extends Event<{ app: App }> { export const AppEvents = { AppConfigUpdatedEvent, AppBuiltEvent } as const; export type CreateAppConfig = { - connection: + connection?: | Connection | { type: "libsql"; @@ -59,17 +59,19 @@ export class App { static create(config: CreateAppConfig) { let connection: Connection | undefined = undefined; - if (Connection.isConnection(config.connection)) { - connection = config.connection; - } else if (typeof config.connection === "object") { - switch (config.connection.type) { - case "libsql": - connection = new LibsqlConnection(config.connection.config); - break; + try { + if (Connection.isConnection(config.connection)) { + connection = config.connection; + } else if (typeof config.connection === "object") { + connection = new LibsqlConnection(config.connection.config); + } else { + connection = new LibsqlConnection({ url: ":memory:" }); + console.warn("[!] No connection provided, using in-memory database"); } - } else { - throw new Error(`Unknown connection of type ${typeof config.connection} given.`); + } catch (e) { + console.error("Could not create connection", e); } + if (!connection) { throw new Error("Invalid connection"); } diff --git a/app/src/data/connection/LibsqlConnection.ts b/app/src/data/connection/LibsqlConnection.ts index 9f6ebcb..e60fa32 100644 --- a/app/src/data/connection/LibsqlConnection.ts +++ b/app/src/data/connection/LibsqlConnection.ts @@ -1,4 +1,4 @@ -import { type Client, type Config, type InStatement, createClient } from "@libsql/client/web"; +import { type Client, type Config, type InStatement, createClient } from "@libsql/client"; import { LibsqlDialect } from "@libsql/kysely-libsql"; import { type DatabaseIntrospector, Kysely, ParseJSONResultsPlugin, sql } from "kysely"; import { FilterNumericKeysPlugin } from "../plugins/FilterNumericKeysPlugin"; From 44a427de671770e8f745ba8c0885a6a7dfbc33a7 Mon Sep 17 00:00:00 2001 From: dswbx Date: Sat, 7 Dec 2024 08:48:48 +0100 Subject: [PATCH 2/3] moved almost all deps to dev to speed up installs, updated nextjs docs --- app/build.ts | 2 +- app/package.json | 42 ++++++++++++++++------------ app/src/adapter/nextjs/AdminPage.tsx | 20 ------------- app/src/adapter/nextjs/index.ts | 1 - docs/integration/nextjs.mdx | 21 +++++++++++--- 5 files changed, 42 insertions(+), 44 deletions(-) delete mode 100644 app/src/adapter/nextjs/AdminPage.tsx diff --git a/app/build.ts b/app/build.ts index 2889011..9c3955d 100644 --- a/app/build.ts +++ b/app/build.ts @@ -107,7 +107,7 @@ await tsup.build({ watch, entry: ["src/ui/index.ts", "src/ui/client/index.ts", "src/ui/main.css"], outDir: "dist/ui", - external: ["bun:test"], + external: ["bun:test", "react", "react-dom", "use-sync-external-store"], metafile: true, platform: "browser", format: ["esm", "cjs"], diff --git a/app/package.json b/app/package.json index e19a4e5..bdde64e 100644 --- a/app/package.json +++ b/app/package.json @@ -8,7 +8,7 @@ "build:all": "bun run build && bun run build:cli", "dev": "vite", "test": "ALL_TESTS=1 bun test --bail", - "build": "bun run build.ts --minify --types", + "build": "NODE_ENV=production bun run build.ts --minify --types", "watch": "bun run build.ts --types --watch", "types": "bun tsc --noEmit", "clean:types": "find ./dist -name '*.d.ts' -delete && rm -f ./dist/tsconfig.tsbuildinfo", @@ -17,20 +17,15 @@ "watch:css": "bun tailwindcss --watch -i src/ui/main.css -o ./dist/styles.css", "updater": "bun x npm-check-updates -ui", "build:cli": "bun build src/cli/index.ts --target node --outdir dist/cli --minify", - "cli": "LOCAL=1 bun src/cli/index.ts" + "cli": "LOCAL=1 bun src/cli/index.ts", + "prepublishOnly": "bun run build:all" }, "license": "FSL-1.1-MIT", "dependencies": { - "@cfworker/json-schema": "^2.0.1", - "@codemirror/lang-html": "^6.4.9", - "@codemirror/lang-json": "^6.0.1", - "@codemirror/lang-liquid": "^6.2.1", - "@dagrejs/dagre": "^1.1.4", - "@hello-pangea/dnd": "^17.0.0", - "@hono/typebox-validator": "^0.2.6", - "@hono/zod-validator": "^0.4.1", - "@hookform/resolvers": "^3.9.1", "@libsql/client": "^0.14.0", + "@tanstack/react-form": "0.19.2" + }, + "devDependencies": { "@libsql/kysely-libsql": "^0.4.1", "@mantine/core": "^7.13.4", "@mantine/hooks": "^7.13.4", @@ -40,7 +35,6 @@ "@rjsf/core": "^5.22.2", "@sinclair/typebox": "^0.32.34", "@tabler/icons-react": "3.18.0", - "@tanstack/react-form": "0.19.2", "@tanstack/react-query": "^5.59.16", "@uiw/react-codemirror": "^4.23.6", "@xyflow/react": "^12.3.2", @@ -59,11 +53,17 @@ "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7", "wouter": "^3.3.5", - "zod": "^3.23.8" - }, - "devDependencies": { + "zod": "^3.23.8", + "@cfworker/json-schema": "^2.0.1", + "@codemirror/lang-html": "^6.4.9", + "@codemirror/lang-json": "^6.0.1", + "@codemirror/lang-liquid": "^6.2.1", + "@dagrejs/dagre": "^1.1.4", + "@hello-pangea/dnd": "^17.0.0", + "@hono/typebox-validator": "^0.2.6", + "@hono/zod-validator": "^0.4.1", + "@hookform/resolvers": "^3.9.1", "@aws-sdk/client-s3": "^3.613.0", - "@hono/node-server": "^1.13.7", "@hono/vite-dev-server": "^0.17.0", "@tanstack/react-query-devtools": "^5.59.16", "@types/diff": "^5.2.3", @@ -84,9 +84,12 @@ "vite-plugin-static-copy": "^2.0.0", "vite-tsconfig-paths": "^5.0.1" }, + "optionalDependencies": { + "@hono/node-server": "^1.13.7" + }, "peerDependencies": { - "react": ">=18", - "react-dom": ">=18" + "react": ">=18 || >=19", + "react-dom": ">=18 || >=19" }, "main": "./dist/index.js", "module": "./dist/index.js", @@ -165,6 +168,9 @@ "./dist/styles.css": "./dist/ui/main.css", "./dist/manifest.json": "./dist/static/manifest.json" }, + "publishConfig": { + "access": "public" + }, "files": [ "dist", "README.md", diff --git a/app/src/adapter/nextjs/AdminPage.tsx b/app/src/adapter/nextjs/AdminPage.tsx deleted file mode 100644 index bd0a81e..0000000 --- a/app/src/adapter/nextjs/AdminPage.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { withApi } from "bknd/adapter/nextjs"; -import type { BkndAdminProps } from "bknd/ui"; -import type { InferGetServerSidePropsType } from "next"; -import dynamic from "next/dynamic"; - -export const getServerSideProps = withApi(async (context) => { - return { - props: { - user: context.api.getUser() - } - }; -}); - -export function adminPage(adminProps?: BkndAdminProps) { - const Admin = dynamic(() => import("bknd/ui").then((mod) => mod.Admin), { ssr: false }); - return (props: InferGetServerSidePropsType) => { - if (typeof document === "undefined") return null; - return ; - }; -} diff --git a/app/src/adapter/nextjs/index.ts b/app/src/adapter/nextjs/index.ts index ef03af0..957fa9e 100644 --- a/app/src/adapter/nextjs/index.ts +++ b/app/src/adapter/nextjs/index.ts @@ -1,2 +1 @@ export * from "./nextjs.adapter"; -export * from "./AdminPage"; diff --git a/docs/integration/nextjs.mdx b/docs/integration/nextjs.mdx index 99b5735..094a566 100644 --- a/docs/integration/nextjs.mdx +++ b/docs/integration/nextjs.mdx @@ -34,13 +34,26 @@ For more information about the connection object, refer to the [Setup](/setup) g Create a file `[[...admin]].tsx` inside the `pages/admin` folder: ```tsx // pages/admin/[[...admin]].tsx -import { adminPage, getServerSideProps } from "bknd/adapter/nextjs"; +import { withApi } from "bknd/adapter/nextjs"; +import dynamic from "next/dynamic"; import "bknd/dist/styles.css"; -export { getServerSideProps }; -export default adminPage({ - config: { basepath: "/admin" } +const Admin = dynamic(() => import("bknd/ui").then((mod) => mod.Admin), { + ssr: false, }); + +export const getServerSideProps = withApi(async (context) => { + return { + props: { + user: context.api.getUser(), + }, + }; +}); + +export default function AdminPage() { + if (typeof document === "undefined") return null; + return ; +} ``` ## Example usage of the API in pages dir From 060af0a1e3b6c2b4099f9fc5e38bfd5aac8eb12f Mon Sep 17 00:00:00 2001 From: dswbx Date: Sat, 7 Dec 2024 09:03:31 +0100 Subject: [PATCH 3/3] fix react peer dependency version constraint (to prevent ERESOLVE warns) --- app/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/package.json b/app/package.json index bdde64e..b7148de 100644 --- a/app/package.json +++ b/app/package.json @@ -88,8 +88,8 @@ "@hono/node-server": "^1.13.7" }, "peerDependencies": { - "react": ">=18 || >=19", - "react-dom": ">=18 || >=19" + "react": ">=18 <20", + "react-dom": ">=18 <20" }, "main": "./dist/index.js", "module": "./dist/index.js",