diff --git a/app/__test__/app/App.spec.ts b/app/__test__/app/App.spec.ts index 03641b3..c5e9794 100644 --- a/app/__test__/app/App.spec.ts +++ b/app/__test__/app/App.spec.ts @@ -48,7 +48,7 @@ describe("App", () => { const todos = await app.getApi().data.readMany("todos"); expect(todos.length).toBe(2); - expect(todos[0].title).toBe("ctx"); - expect(todos[1].title).toBe("api"); + expect(todos[0]?.title).toBe("ctx"); + expect(todos[1]?.title).toBe("api"); }); }); diff --git a/app/build.ts b/app/build.ts index 1e48a79..6ad0dc2 100644 --- a/app/build.ts +++ b/app/build.ts @@ -71,16 +71,19 @@ async function buildApi() { }); } +async function rewriteClient(path: string) { + const bundle = await Bun.file(path).text(); + await Bun.write(path, '"use client";\n' + bundle.replaceAll("ui/client", "bknd/client")); +} + /** * Building UI for direct imports */ async function buildUi() { - await tsup.build({ + const base = { minify, sourcemap, watch, - entry: ["src/ui/index.ts", "src/ui/client/index.ts", "src/ui/main.css", "src/ui/styles.css"], - outDir: "dist/ui", external: [ "bun:test", "react", @@ -104,7 +107,24 @@ async function buildUi() { esbuildOptions: (options) => { options.logLevel = "silent"; }, + } satisfies tsup.Options; + + await tsup.build({ + ...base, + entry: ["src/ui/index.ts", "src/ui/main.css", "src/ui/styles.css"], + outDir: "dist/ui", onSuccess: async () => { + await rewriteClient("./dist/ui/index.js"); + delayTypes(); + }, + }); + + await tsup.build({ + ...base, + entry: ["src/ui/client/index.ts"], + outDir: "dist/ui/client", + onSuccess: async () => { + await rewriteClient("./dist/ui/client/index.js"); delayTypes(); }, }); @@ -146,11 +166,7 @@ async function buildUiElements() { }; }, onSuccess: async () => { - // manually replace ui/client with bknd/client - const path = "./dist/ui/elements/index.js"; - const bundle = await Bun.file(path).text(); - await Bun.write(path, bundle.replaceAll("ui/client", "bknd/client")); - + await rewriteClient("./dist/ui/elements/index.js"); delayTypes(); }, }); diff --git a/app/package.json b/app/package.json index fdb2cbe..0d71394 100644 --- a/app/package.json +++ b/app/package.json @@ -3,7 +3,7 @@ "type": "module", "sideEffects": false, "bin": "./dist/cli/index.js", - "version": "0.9.0-rc.1", + "version": "0.9.0-rc.1-7", "description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, Remix, Astro, Cloudflare, Bun, Node, AWS Lambda & more.", "homepage": "https://bknd.io", "repository": { diff --git a/app/src/App.ts b/app/src/App.ts index bbeb77b..e484685 100644 --- a/app/src/App.ts +++ b/app/src/App.ts @@ -1,4 +1,3 @@ -import { Api, type ApiOptions } from "Api"; import type { CreateUserPayload } from "auth/AppAuth"; import { $console } from "core"; import { Event } from "core/events"; @@ -188,12 +187,10 @@ export class App { return this.module.auth.createUser(p); } - async getApi(options?: LocalApiOptions) { + getApi(options?: LocalApiOptions) { const fetcher = this.server.request as typeof fetch; if (options && options instanceof Request) { - const api = new Api({ request: options, headers: options.headers, fetcher }); - await api.verifyAuth(); - return api; + return new Api({ request: options, headers: options.headers, fetcher }); } return new Api({ host: "http://localhost", ...(options ?? {}), fetcher }); diff --git a/app/src/ui/Admin.tsx b/app/src/ui/Admin.tsx index 5ece794..a0aceab 100644 --- a/app/src/ui/Admin.tsx +++ b/app/src/ui/Admin.tsx @@ -54,9 +54,9 @@ function AdminInternal() { ); } -const Skeleton = ({ theme }: { theme?: string }) => { - const actualTheme = - (theme ?? document.querySelector("html")?.classList.contains("light")) ? "light" : "dark"; +const Skeleton = ({ theme }: { theme?: any }) => { + const t = useTheme(); + const actualTheme = theme ?? t.theme; return (
diff --git a/app/src/ui/client/use-theme.ts b/app/src/ui/client/use-theme.ts index 935c1c1..b490a4a 100644 --- a/app/src/ui/client/use-theme.ts +++ b/app/src/ui/client/use-theme.ts @@ -2,7 +2,7 @@ import type { AppTheme } from "modules/server/AppServer"; import { useBkndWindowContext } from "ui/client/ClientProvider"; import { useBknd } from "ui/client/bknd"; -export function useTheme(fallback: AppTheme = "system"): { theme: AppTheme } { +export function useTheme(fallback: AppTheme = "system") { const b = useBknd(); const winCtx = useBkndWindowContext(); @@ -14,13 +14,16 @@ export function useTheme(fallback: AppTheme = "system"): { theme: AppTheme } { const override = b?.adminOverride?.color_scheme; const config = b?.config.server.admin.color_scheme; const win = winCtx.color_scheme; - const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches; + const prefersDark = + typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches; const theme = override ?? config ?? win ?? fallback; - if (theme === "system") { - return { theme: prefersDark ? "dark" : "light" }; - } - - return { theme }; + return { + theme: (theme === "system" ? (prefersDark ? "dark" : "light") : theme) as AppTheme, + prefersDark, + override, + config, + win, + }; } diff --git a/app/src/ui/hooks/use-event.ts b/app/src/ui/hooks/use-event.ts index 9f317c0..26c39e3 100644 --- a/app/src/ui/hooks/use-event.ts +++ b/app/src/ui/hooks/use-event.ts @@ -4,15 +4,15 @@ // there is no lifecycle or Hook in React that we can use to switch // .current at the right timing." // So we will have to make do with this "close enough" approach for now. -import { useInsertionEffect, useRef } from "react"; +import { useEffect, useRef } from "react"; export const useEvent = (fn: Fn | ((...args: any[]) => any) | undefined): Fn => { const ref = useRef([fn, (...args) => ref[0](...args)]).current; // Per Dan Abramov: useInsertionEffect executes marginally closer to the // correct timing for ref synchronization than useLayoutEffect on React 18. // See: https://github.com/facebook/react/pull/25881#issuecomment-1356244360 - useInsertionEffect(() => { + useEffect(() => { ref[0] = fn; - }); + }, []); return ref[1]; }; diff --git a/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx b/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx index 4d5f11b..a9a90e0 100644 --- a/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx +++ b/app/src/ui/modules/data/components/schema/create-modal/step.entity.fields.tsx @@ -45,7 +45,6 @@ export function StepEntityFields() { const values = watch(); const updateListener = useEvent((data: TAppDataEntityFields) => { - console.log("updateListener", data); setValue("fields", data as any); }); diff --git a/app/src/ui/routes/data/data.$entity.index.tsx b/app/src/ui/routes/data/data.$entity.index.tsx index 06e28e2..b754459 100644 --- a/app/src/ui/routes/data/data.$entity.index.tsx +++ b/app/src/ui/routes/data/data.$entity.index.tsx @@ -2,7 +2,7 @@ import { Type } from "core/utils"; import { type Entity, querySchema } from "data"; import { Fragment } from "react"; import { TbDots } from "react-icons/tb"; -import { useApi, useApiQuery } from "ui/client"; +import { useApiQuery } from "ui/client"; import { useBknd } from "ui/client/bknd"; import { useBkndData } from "ui/client/schema/data/use-bknd-data"; import { Button } from "ui/components/buttons/Button"; @@ -83,7 +83,7 @@ export function DataEntityList({ params }) { search.set("perPage", perPage); } - const isUpdating = $q.isLoading && $q.isValidating; + const isUpdating = $q.isLoading || $q.isValidating; return ( diff --git a/app/src/ui/routes/data/forms/entity.fields.form.tsx b/app/src/ui/routes/data/forms/entity.fields.form.tsx index 3826cb1..b85c787 100644 --- a/app/src/ui/routes/data/forms/entity.fields.form.tsx +++ b/app/src/ui/routes/data/forms/entity.fields.form.tsx @@ -108,9 +108,7 @@ export const EntityFieldsForm = forwardRef { if (props?.onChange) { - console.log("----set"); watch((data: any) => { - console.log("---calling"); props?.onChange?.(toCleanValues(data)); }); } diff --git a/examples/nextjs/.gitignore b/examples/nextjs/.gitignore index e410319..5ef6a52 100644 --- a/examples/nextjs/.gitignore +++ b/examples/nextjs/.gitignore @@ -28,8 +28,9 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +.pnpm-debug.log* -# env files (can opt-in for commiting if needed) +# env files (can opt-in for committing if needed) .env* # vercel @@ -38,4 +39,3 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts -!test.db diff --git a/examples/nextjs/README.md b/examples/nextjs/README.md index 6ee2049..e215bc4 100644 --- a/examples/nextjs/README.md +++ b/examples/nextjs/README.md @@ -1,38 +1,36 @@ -# bknd starter: Next.js -A minimal Next.js project with bknd integration. +This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). -## Project Structure +## Getting Started -Inside of your Next.js project, you'll see the following folders and files: +First, run the development server: -```text -/ -├── public/ -├── src/ -│ └── pages/ -│ └── admin/ -│ │ └── [[...admin]].tsx -│ └── api/ -│ │ └── [...route].ts -│ ├── _app.tsx -│ ├── _document.tsx -│ └── index.tsx -└── package.json +```bash +npm run dev +# or +yarn dev +# or +pnpm dev +# or +bun dev ``` -To update `bknd` config, check `src/pages/api/[...route].ts` and `src/pages/admin/[[...admin]].tsx`. +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. -## Commands +You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. -All commands are run from the root of the project, from a terminal: +This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. -| Command | Action | -|:--------------------------|:-------------------------------------------------| -| `npm install` | Installs dependencies | -| `npm run dev` | Starts local dev server at `localhost:3000` | -| `npm run build` | Build your production site | -| `npm run db` | Starts a local LibSQL database | +## Learn More -## Want to learn more? +To learn more about Next.js, take a look at the following resources: -Feel free to check [our documentation](https://docs.bknd.io/integration/nextjs) or jump into our [Discord server](https://discord.gg/952SFk8Tb8). +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. +- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. + +You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! + +## Deploy on Vercel + +The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. + +Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. diff --git a/examples/nextjs/next.config.ts b/examples/nextjs/next.config.ts index d281f49..e9ffa30 100644 --- a/examples/nextjs/next.config.ts +++ b/examples/nextjs/next.config.ts @@ -1,18 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ - reactStrictMode: true - - /*transpilePackages: [ - "@rjsf/core", - "@libsql/isomorphic-fetch", - "@libsql/isomorphic-ws", - "@libsql/kysely-libsql" - ], - experimental: { - esmExternals: "loose" - }*/ + /* config options here */ }; export default nextConfig; diff --git a/examples/nextjs/package.json b/examples/nextjs/package.json index 0a273a5..80059f9 100644 --- a/examples/nextjs/package.json +++ b/examples/nextjs/package.json @@ -3,24 +3,24 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "npm run db & next dev", - "db": "turso dev --db-file test.db", + "dev": "next dev", + "dev:turbo": "next dev --turbopack", "build": "next build", - "start": "npm run db & next start", + "start": "next start", "lint": "next lint" }, "dependencies": { "bknd": "file:../../app", - "next": "15.0.2", "react": "file:../../node_modules/react", - "react-dom": "file:../../node_modules/react-dom" + "react-dom": "file:../../node_modules/react-dom", + "next": "15.2.0" }, "devDependencies": { "typescript": "^5", "@types/node": "^20", - "@types/react": "^18", - "@types/react-dom": "^18", - "postcss": "^8", - "tailwindcss": "^3.4.1" + "@types/react": "^19", + "@types/react-dom": "^19", + "@tailwindcss/postcss": "^4", + "tailwindcss": "^4" } } diff --git a/examples/nextjs/postcss.config.mjs b/examples/nextjs/postcss.config.mjs index 1a69fd2..e046298 100644 --- a/examples/nextjs/postcss.config.mjs +++ b/examples/nextjs/postcss.config.mjs @@ -1,8 +1,6 @@ -/** @type {import('postcss-load-config').Config} */ const config = { - plugins: { - tailwindcss: {}, - }, + plugins: { + "@tailwindcss/postcss": {}, + }, }; - export default config; diff --git a/examples/nextjs/public/bknd.svg b/examples/nextjs/public/bknd.svg new file mode 100644 index 0000000..182ef92 --- /dev/null +++ b/examples/nextjs/public/bknd.svg @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/examples/nextjs/src/app/admin/[[...admin]]/page.tsx b/examples/nextjs/src/app/admin/[[...admin]]/page.tsx new file mode 100644 index 0000000..cd36b9e --- /dev/null +++ b/examples/nextjs/src/app/admin/[[...admin]]/page.tsx @@ -0,0 +1,18 @@ +import { Admin } from "bknd/ui"; +import "bknd/dist/styles.css"; +import { getApi } from "@/bknd"; + +export default async function AdminPage() { + const api = await getApi({ verify: true }); + + return ( + + ); +} diff --git a/examples/nextjs/src/app/api/[[...bknd]]/route.ts b/examples/nextjs/src/app/api/[[...bknd]]/route.ts new file mode 100644 index 0000000..6aadeae --- /dev/null +++ b/examples/nextjs/src/app/api/[[...bknd]]/route.ts @@ -0,0 +1,12 @@ +import { getApp } from "@/bknd"; + +const handler = async (request: Request) => { + const app = await getApp(); + return app.fetch(request); +}; + +export const GET = handler; +export const POST = handler; +export const PUT = handler; +export const PATCH = handler; +export const DELETE = handler; diff --git a/examples/nextjs/public/favicon.ico b/examples/nextjs/src/app/favicon.ico similarity index 100% rename from examples/nextjs/public/favicon.ico rename to examples/nextjs/src/app/favicon.ico diff --git a/examples/nextjs/src/app/globals.css b/examples/nextjs/src/app/globals.css new file mode 100644 index 0000000..bafe49a --- /dev/null +++ b/examples/nextjs/src/app/globals.css @@ -0,0 +1,25 @@ +@import "tailwindcss"; + +:root { + --background: #ffffff; + --foreground: #171717; +} + +@media (prefers-color-scheme: dark) { + :root { + --background: #0a0a0a; + --foreground: #ededed; + } +} + +@theme { + --font-sans: var(--font-geist-sans); + --font-mono: var(--font-geist-mono); + --color-background: var(--background); + --color-foreground: var(--foreground); +} + +body { + @apply bg-background text-foreground; + font-family: Arial, Helvetica, sans-serif; +} diff --git a/examples/nextjs/src/app/layout.tsx b/examples/nextjs/src/app/layout.tsx new file mode 100644 index 0000000..d6d0089 --- /dev/null +++ b/examples/nextjs/src/app/layout.tsx @@ -0,0 +1,32 @@ +import type { Metadata } from "next"; +import { Geist, Geist_Mono } from "next/font/google"; +import "./globals.css"; + +const geistSans = Geist({ + variable: "--font-geist-sans", + subsets: ["latin"], +}); + +const geistMono = Geist_Mono({ + variable: "--font-geist-mono", + subsets: ["latin"], +}); + +export const metadata: Metadata = { + title: "Create Next & bknd App", + description: "Presented by create next app & bknd", +}; + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( + + + {children} + + + ); +} diff --git a/examples/nextjs/src/app/page.tsx b/examples/nextjs/src/app/page.tsx new file mode 100644 index 0000000..c6685d2 --- /dev/null +++ b/examples/nextjs/src/app/page.tsx @@ -0,0 +1,97 @@ +import Image from "next/image"; +import { getApi } from "@/bknd"; + +export default async function Home() { + const api = await getApi(); + + return ( +
+
+
+ Next.js logo +
&
+ bknd logo +
+
    +
  1. + Get started by editing{" "} + + src/app/page.tsx + + . +
  2. +
  3. Save and see your changes instantly.
  4. +
+ + + +
+               {JSON.stringify(await api.data.readMany("posts"), null, 2)}
+            
+
+ +
+ ); +} diff --git a/examples/nextjs/src/app/ssr/page.tsx b/examples/nextjs/src/app/ssr/page.tsx new file mode 100644 index 0000000..204ac31 --- /dev/null +++ b/examples/nextjs/src/app/ssr/page.tsx @@ -0,0 +1,14 @@ +import { getApi } from "@/bknd"; + +export default async function SSRPage() { + const api = await getApi({ verify: true }); + const { data } = await api.data.readMany("posts"); + + return ( +
+

Server-Side Rendered Page

+
{JSON.stringify(data, null, 2)}
+
{JSON.stringify(api.getUser(), null, 2)}
+
+ ); +} diff --git a/examples/nextjs/src/bknd.ts b/examples/nextjs/src/bknd.ts index 7807e2f..65f00a7 100644 --- a/examples/nextjs/src/bknd.ts +++ b/examples/nextjs/src/bknd.ts @@ -1,68 +1,27 @@ -import { App, type LocalApiOptions } from "bknd"; import { type NextjsBkndConfig, getApp as getBkndApp } from "bknd/adapter/nextjs"; -import { boolean, em, entity, text } from "bknd/data"; -import { secureRandomString } from "bknd/utils"; +import { registerLocalMediaAdapter } from "bknd/adapter/node"; +import { headers } from "next/headers"; -// the em() function makes it easy to create an initial schema -const schema = em({ - todos: entity("todos", { - title: text(), - done: boolean() - }) -}); - -// register your schema to get automatic type completion -type Database = (typeof schema)["DB"]; -declare module "bknd/core" { - interface DB extends Database {} -} +registerLocalMediaAdapter(); export const config = { - // we can use any libsql config, and if omitted, uses in-memory connection: { - url: "http://localhost:8080" + // make sure to use a remote URL for production! + url: "file:data.db", }, - // an initial config is only applied if the database is empty - initialConfig: { - data: schema.toJSON(), - // we're enabling auth ... - auth: { - enabled: true, - jwt: { - secret: secureRandomString(64) - } - } - }, - options: { - // the seed option is only executed if the database was empty - seed: async (ctx) => { - await ctx.em.mutator("todos").insertMany([ - { title: "Learn bknd", done: true }, - { title: "Build something cool", done: false } - ]); - } - }, - // here we can hook into the app lifecycle events ... - beforeBuild: async (app) => { - app.emgr.onEvent( - App.Events.AppFirstBoot, - async () => { - // ... to create an initial user - await app.module.auth.createUser({ - email: "ds@bknd.io", - password: "12345678" - }); - }, - "sync" - ); - } } as const satisfies NextjsBkndConfig; export async function getApp() { return await getBkndApp(config); } -export async function getApi(options?: LocalApiOptions) { +export async function getApi(opts?: { verify?: boolean }) { const app = await getApp(); - return await app.getApi(options); + if (opts?.verify) { + const api = app.getApi({ headers: await headers() }); + await api.verifyAuth(); + return api; + } + + return app.getApi(); } diff --git a/examples/nextjs/src/pages/_app.tsx b/examples/nextjs/src/pages/_app.tsx deleted file mode 100644 index dc6113b..0000000 --- a/examples/nextjs/src/pages/_app.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import "@/styles/globals.css"; -import type { AppProps } from "next/app"; - -export default function App({ Component, pageProps }: AppProps) { - return ; -} diff --git a/examples/nextjs/src/pages/_document.tsx b/examples/nextjs/src/pages/_document.tsx deleted file mode 100644 index 628a733..0000000 --- a/examples/nextjs/src/pages/_document.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Html, Head, Main, NextScript } from "next/document"; - -export default function Document() { - return ( - - - -
- - - - ); -} diff --git a/examples/nextjs/src/pages/admin/[[...admin]].tsx b/examples/nextjs/src/pages/admin/[[...admin]].tsx deleted file mode 100644 index fa05915..0000000 --- a/examples/nextjs/src/pages/admin/[[...admin]].tsx +++ /dev/null @@ -1,27 +0,0 @@ -import type { InferGetServerSidePropsType as InferProps } from "next"; -import dynamic from "next/dynamic"; - -import { withApi } from "bknd/adapter/nextjs"; -import "bknd/dist/styles.css"; - -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({ user }: InferProps) { - if (typeof document === "undefined") return null; - return ( - - ); -} diff --git a/examples/nextjs/src/pages/api/[...route].ts b/examples/nextjs/src/pages/api/[...route].ts deleted file mode 100644 index ca039ed..0000000 --- a/examples/nextjs/src/pages/api/[...route].ts +++ /dev/null @@ -1,18 +0,0 @@ -import { config as bkndConfig } from "@/bknd"; -import { serve } from "bknd/adapter/nextjs"; - -export const config = { - runtime: "edge", - // add a matcher for bknd dist to allow dynamic otherwise build may fail. - // inside this repo it's '../../app/dist/index.js', outside probably inside node_modules - // see https://github.com/vercel/next.js/issues/51401 - // and https://github.com/vercel/next.js/pull/69402 - unstable_allowDynamic: ["**/*.js"] -}; - -export default serve({ - cleanRequest: { - searchParams: ["route"] - }, - ...bkndConfig -}); diff --git a/examples/nextjs/src/pages/api/hello.ts b/examples/nextjs/src/pages/api/hello.ts deleted file mode 100644 index ea77e8f..0000000 --- a/examples/nextjs/src/pages/api/hello.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import type { NextApiRequest, NextApiResponse } from "next"; - -type Data = { - name: string; -}; - -export default function handler( - req: NextApiRequest, - res: NextApiResponse, -) { - res.status(200).json({ name: "John Doe" }); -} diff --git a/examples/nextjs/src/pages/fonts/GeistMonoVF.woff b/examples/nextjs/src/pages/fonts/GeistMonoVF.woff deleted file mode 100644 index f2ae185..0000000 Binary files a/examples/nextjs/src/pages/fonts/GeistMonoVF.woff and /dev/null differ diff --git a/examples/nextjs/src/pages/fonts/GeistVF.woff b/examples/nextjs/src/pages/fonts/GeistVF.woff deleted file mode 100644 index 1b62daa..0000000 Binary files a/examples/nextjs/src/pages/fonts/GeistVF.woff and /dev/null differ diff --git a/examples/nextjs/src/pages/index.tsx b/examples/nextjs/src/pages/index.tsx deleted file mode 100644 index d437e05..0000000 --- a/examples/nextjs/src/pages/index.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { getApi } from "@/bknd"; -import type { InferGetServerSidePropsType } from "next"; - -export const getServerSideProps = async () => { - const api = await getApi(); - const { data = [] } = await api.data.readMany("todos"); - const user = api.getUser(); - - return { props: { data, user } }; -}; - -export default function Home({ - data, - user -}: InferGetServerSidePropsType) { - return ( -
-

Data

-
{JSON.stringify(data, null, 2)}
- -

User

-
{JSON.stringify(user, null, 2)}
-
- ); -} diff --git a/examples/nextjs/src/styles/globals.css b/examples/nextjs/src/styles/globals.css deleted file mode 100644 index 6b717ad..0000000 --- a/examples/nextjs/src/styles/globals.css +++ /dev/null @@ -1,21 +0,0 @@ -@tailwind base; -@tailwind components; -@tailwind utilities; - -:root { - --background: #ffffff; - --foreground: #171717; -} - -@media (prefers-color-scheme: dark) { - :root { - --background: #0a0a0a; - --foreground: #ededed; - } -} - -body { - color: var(--foreground); - background: var(--background); - font-family: Arial, Helvetica, sans-serif; -} diff --git a/examples/nextjs/tailwind.config.ts b/examples/nextjs/tailwind.config.ts index 021c393..321ea51 100644 --- a/examples/nextjs/tailwind.config.ts +++ b/examples/nextjs/tailwind.config.ts @@ -1,19 +1,18 @@ import type { Config } from "tailwindcss"; -const config: Config = { - content: [ - "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", - "./src/components/**/*.{js,ts,jsx,tsx,mdx}", - "./src/app/**/*.{js,ts,jsx,tsx,mdx}", - ], - theme: { - extend: { - colors: { - background: "var(--background)", - foreground: "var(--foreground)", +export default { + content: [ + "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", + "./src/components/**/*.{js,ts,jsx,tsx,mdx}", + "./src/app/**/*.{js,ts,jsx,tsx,mdx}", + ], + theme: { + extend: { + colors: { + background: "var(--background)", + foreground: "var(--foreground)", + }, }, - }, - }, - plugins: [], -}; -export default config; + }, + plugins: [], +} satisfies Config; diff --git a/examples/nextjs/test.db b/examples/nextjs/test.db deleted file mode 100644 index de29870..0000000 Binary files a/examples/nextjs/test.db and /dev/null differ diff --git a/examples/nextjs/tsconfig.json b/examples/nextjs/tsconfig.json index 572b7ad..c133409 100644 --- a/examples/nextjs/tsconfig.json +++ b/examples/nextjs/tsconfig.json @@ -13,10 +13,15 @@ "isolatedModules": true, "jsx": "preserve", "incremental": true, + "plugins": [ + { + "name": "next" + } + ], "paths": { "@/*": ["./src/*"] } }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"] }