Merge remote-tracking branch 'origin/refactor/ext-deps' into release/0.2.3

This commit is contained in:
dswbx
2024-12-07 09:30:06 +01:00
7 changed files with 56 additions and 56 deletions

View File

@@ -88,7 +88,7 @@ await tsup.build({
watch, watch,
entry: ["src/index.ts", "src/data/index.ts", "src/core/index.ts", "src/core/utils/index.ts"], entry: ["src/index.ts", "src/data/index.ts", "src/core/index.ts", "src/core/utils/index.ts"],
outDir: "dist", outDir: "dist",
external: ["bun:test"], external: ["bun:test", "@libsql/client"],
metafile: true, metafile: true,
platform: "browser", platform: "browser",
format: ["esm", "cjs"], format: ["esm", "cjs"],
@@ -107,7 +107,7 @@ await tsup.build({
watch, watch,
entry: ["src/ui/index.ts", "src/ui/client/index.ts", "src/ui/main.css"], entry: ["src/ui/index.ts", "src/ui/client/index.ts", "src/ui/main.css"],
outDir: "dist/ui", outDir: "dist/ui",
external: ["bun:test"], external: ["bun:test", "react", "react-dom", "use-sync-external-store"],
metafile: true, metafile: true,
platform: "browser", platform: "browser",
format: ["esm", "cjs"], format: ["esm", "cjs"],

View File

@@ -8,7 +8,7 @@
"build:all": "bun run build && bun run build:cli", "build:all": "bun run build && bun run build:cli",
"dev": "vite", "dev": "vite",
"test": "ALL_TESTS=1 bun test --bail", "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", "watch": "bun run build.ts --types --watch",
"types": "bun tsc --noEmit", "types": "bun tsc --noEmit",
"clean:types": "find ./dist -name '*.d.ts' -delete && rm -f ./dist/tsconfig.tsbuildinfo", "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", "watch:css": "bun tailwindcss --watch -i src/ui/main.css -o ./dist/styles.css",
"updater": "bun x npm-check-updates -ui", "updater": "bun x npm-check-updates -ui",
"build:cli": "bun build src/cli/index.ts --target node --outdir dist/cli --minify", "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", "license": "FSL-1.1-MIT",
"dependencies": { "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", "@libsql/client": "^0.14.0",
"@tanstack/react-form": "0.19.2"
},
"devDependencies": {
"@libsql/kysely-libsql": "^0.4.1", "@libsql/kysely-libsql": "^0.4.1",
"@mantine/core": "^7.13.4", "@mantine/core": "^7.13.4",
"@mantine/hooks": "^7.13.4", "@mantine/hooks": "^7.13.4",
@@ -40,7 +35,6 @@
"@rjsf/core": "^5.22.2", "@rjsf/core": "^5.22.2",
"@sinclair/typebox": "^0.32.34", "@sinclair/typebox": "^0.32.34",
"@tabler/icons-react": "3.18.0", "@tabler/icons-react": "3.18.0",
"@tanstack/react-form": "0.19.2",
"@tanstack/react-query": "^5.59.16", "@tanstack/react-query": "^5.59.16",
"@uiw/react-codemirror": "^4.23.6", "@uiw/react-codemirror": "^4.23.6",
"@xyflow/react": "^12.3.2", "@xyflow/react": "^12.3.2",
@@ -59,11 +53,17 @@
"tailwind-merge": "^2.5.4", "tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"wouter": "^3.3.5", "wouter": "^3.3.5",
"zod": "^3.23.8" "zod": "^3.23.8",
}, "@cfworker/json-schema": "^2.0.1",
"devDependencies": { "@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", "@aws-sdk/client-s3": "^3.613.0",
"@hono/node-server": "^1.13.7",
"@hono/vite-dev-server": "^0.17.0", "@hono/vite-dev-server": "^0.17.0",
"@tanstack/react-query-devtools": "^5.59.16", "@tanstack/react-query-devtools": "^5.59.16",
"@types/diff": "^5.2.3", "@types/diff": "^5.2.3",
@@ -84,9 +84,12 @@
"vite-plugin-static-copy": "^2.0.0", "vite-plugin-static-copy": "^2.0.0",
"vite-tsconfig-paths": "^5.0.1" "vite-tsconfig-paths": "^5.0.1"
}, },
"optionalDependencies": {
"@hono/node-server": "^1.13.7"
},
"peerDependencies": { "peerDependencies": {
"react": ">=18", "react": ">=18 <20",
"react-dom": ">=18" "react-dom": ">=18 <20"
}, },
"main": "./dist/index.js", "main": "./dist/index.js",
"module": "./dist/index.js", "module": "./dist/index.js",
@@ -165,6 +168,9 @@
"./dist/styles.css": "./dist/ui/main.css", "./dist/styles.css": "./dist/ui/main.css",
"./dist/manifest.json": "./dist/static/manifest.json" "./dist/manifest.json": "./dist/static/manifest.json"
}, },
"publishConfig": {
"access": "public"
},
"files": [ "files": [
"dist", "dist",
"README.md", "README.md",

View File

@@ -21,7 +21,7 @@ export class AppBuiltEvent extends Event<{ app: App }> {
export const AppEvents = { AppConfigUpdatedEvent, AppBuiltEvent } as const; export const AppEvents = { AppConfigUpdatedEvent, AppBuiltEvent } as const;
export type CreateAppConfig = { export type CreateAppConfig = {
connection: connection?:
| Connection | Connection
| { | {
type: "libsql"; type: "libsql";
@@ -59,17 +59,19 @@ export class App<DB = any> {
static create(config: CreateAppConfig) { static create(config: CreateAppConfig) {
let connection: Connection | undefined = undefined; let connection: Connection | undefined = undefined;
try {
if (Connection.isConnection(config.connection)) { if (Connection.isConnection(config.connection)) {
connection = config.connection; connection = config.connection;
} else if (typeof config.connection === "object") { } else if (typeof config.connection === "object") {
switch (config.connection.type) {
case "libsql":
connection = new LibsqlConnection(config.connection.config); connection = new LibsqlConnection(config.connection.config);
break;
}
} else { } else {
throw new Error(`Unknown connection of type ${typeof config.connection} given.`); connection = new LibsqlConnection({ url: ":memory:" });
console.warn("[!] No connection provided, using in-memory database");
} }
} catch (e) {
console.error("Could not create connection", e);
}
if (!connection) { if (!connection) {
throw new Error("Invalid connection"); throw new Error("Invalid connection");
} }

View File

@@ -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<typeof getServerSideProps>) => {
if (typeof document === "undefined") return null;
return <Admin withProvider={{ user: props.user }} {...adminProps} />;
};
}

View File

@@ -1,2 +1 @@
export * from "./nextjs.adapter"; export * from "./nextjs.adapter";
export * from "./AdminPage";

View File

@@ -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 { LibsqlDialect } from "@libsql/kysely-libsql";
import { type DatabaseIntrospector, Kysely, ParseJSONResultsPlugin, sql } from "kysely"; import { type DatabaseIntrospector, Kysely, ParseJSONResultsPlugin, sql } from "kysely";
import { FilterNumericKeysPlugin } from "../plugins/FilterNumericKeysPlugin"; import { FilterNumericKeysPlugin } from "../plugins/FilterNumericKeysPlugin";

View File

@@ -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: Create a file `[[...admin]].tsx` inside the `pages/admin` folder:
```tsx ```tsx
// pages/admin/[[...admin]].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"; import "bknd/dist/styles.css";
export { getServerSideProps }; const Admin = dynamic(() => import("bknd/ui").then((mod) => mod.Admin), {
export default adminPage({ ssr: false,
config: { basepath: "/admin" }
}); });
export const getServerSideProps = withApi(async (context) => {
return {
props: {
user: context.api.getUser(),
},
};
});
export default function AdminPage() {
if (typeof document === "undefined") return null;
return <Admin withProvider config={{ basepath: "/admin" }} />;
}
``` ```
## Example usage of the API in pages dir ## Example usage of the API in pages dir