diff --git a/bun.lockb b/bun.lockb index 0d9a834..50b05d6 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/examples/astro/.gitignore b/examples/astro/.gitignore new file mode 100644 index 0000000..a0cee65 --- /dev/null +++ b/examples/astro/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ \ No newline at end of file diff --git a/examples/astro/README.md b/examples/astro/README.md new file mode 100644 index 0000000..e34a99b --- /dev/null +++ b/examples/astro/README.md @@ -0,0 +1,47 @@ +# Astro Starter Kit: Minimal + +```sh +npm create astro@latest -- --template minimal +``` + +[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal) +[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/minimal) +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/minimal/devcontainer.json) + +> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! + +## 🚀 Project Structure + +Inside of your Astro project, you'll see the following folders and files: + +```text +/ +├── public/ +├── src/ +│ └── pages/ +│ └── index.astro +└── package.json +``` + +Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. + +There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components. + +Any static assets, like images, can be placed in the `public/` directory. + +## 🧞 Commands + +All commands are run from the root of the project, from a terminal: + +| Command | Action | +| :------------------------ | :----------------------------------------------- | +| `npm install` | Installs dependencies | +| `npm run dev` | Starts local dev server at `localhost:4321` | +| `npm run build` | Build your production site to `./dist/` | +| `npm run preview` | Preview your build locally, before deploying | +| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | +| `npm run astro -- --help` | Get help using the Astro CLI | + +## 👀 Want to learn more? + +Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat). diff --git a/examples/astro/astro.config.mjs b/examples/astro/astro.config.mjs new file mode 100644 index 0000000..ba9a322 --- /dev/null +++ b/examples/astro/astro.config.mjs @@ -0,0 +1,10 @@ +// @ts-check +import { defineConfig } from "astro/config"; + +import react from "@astrojs/react"; + +// https://astro.build/config +export default defineConfig({ + output: "hybrid", + integrations: [react()] +}); diff --git a/examples/astro/package.json b/examples/astro/package.json new file mode 100644 index 0000000..a4f03f5 --- /dev/null +++ b/examples/astro/package.json @@ -0,0 +1,23 @@ +{ + "name": "astro", + "type": "module", + "version": "0.0.1", + "scripts": { + "dev": "astro dev", + "start": "astro dev", + "build": "astro check && astro build", + "preview": "astro preview", + "astro": "astro" + }, + "dependencies": { + "@astrojs/check": "^0.9.4", + "@astrojs/react": "^3.6.3", + "@types/react": "^18.3.12", + "@types/react-dom": "^18.3.1", + "astro": "^4.16.16", + "bknd": "workspace:*", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "typescript": "^5.7.2" + } +} diff --git a/examples/astro/public/favicon.svg b/examples/astro/public/favicon.svg new file mode 100644 index 0000000..f157bd1 --- /dev/null +++ b/examples/astro/public/favicon.svg @@ -0,0 +1,9 @@ + + + + diff --git a/examples/astro/src/env.d.ts b/examples/astro/src/env.d.ts new file mode 100644 index 0000000..e16c13c --- /dev/null +++ b/examples/astro/src/env.d.ts @@ -0,0 +1 @@ +/// diff --git a/examples/astro/src/pages/admin/[...admin].astro b/examples/astro/src/pages/admin/[...admin].astro new file mode 100644 index 0000000..dccde9d --- /dev/null +++ b/examples/astro/src/pages/admin/[...admin].astro @@ -0,0 +1,18 @@ +--- +import { Api } from "bknd"; +import { Admin } from "bknd/ui"; +import "bknd/dist/styles.css"; + +export const prerender = false; +const api = new Api({ + host: new URL(Astro.request.url).origin, + headers: Astro.request.headers +}); +const user = api.getUser(); +--- + + + + + + \ No newline at end of file diff --git a/examples/astro/src/pages/api/[...api].ts b/examples/astro/src/pages/api/[...api].ts new file mode 100644 index 0000000..401d118 --- /dev/null +++ b/examples/astro/src/pages/api/[...api].ts @@ -0,0 +1,18 @@ +import type { APIRoute } from "astro"; +import { App } from "bknd"; + +export const prerender = false; + +export const ALL: APIRoute = async ({ request }) => { + const app = App.create({ + connection: { + type: "libsql", + config: { + url: "http://127.0.0.1:8080" + } + } + }); + + await app.build(); + return app.fetch(request); +}; diff --git a/examples/astro/src/pages/index.astro b/examples/astro/src/pages/index.astro new file mode 100644 index 0000000..2693802 --- /dev/null +++ b/examples/astro/src/pages/index.astro @@ -0,0 +1,16 @@ +--- +import { Api } from "bknd"; +const api = new Api({ + host: new URL(Astro.request.url).origin +}); +const { data } = await api.data.readMany("todos"); +--- + + +

Home (static)

+

Data

+
{JSON.stringify(data, null, 2)}
+ +Admin - +SSR (with auth) - +Home (static) \ No newline at end of file diff --git a/examples/astro/src/pages/ssr.astro b/examples/astro/src/pages/ssr.astro new file mode 100644 index 0000000..a45dafe --- /dev/null +++ b/examples/astro/src/pages/ssr.astro @@ -0,0 +1,23 @@ +--- +import { Api } from "bknd"; +const api = new Api({ + host: new URL(Astro.request.url).origin, + headers: Astro.request.headers +}); +const { data } = await api.data.readMany("todos"); +const user = api.getUser(); +console.log("user", user); + +export const prerender = false; +--- + +

SSR

+

Data

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

User

+
{JSON.stringify(user, null, 2)}
+ +Admin - +SSR (with auth) - +Home (static) \ No newline at end of file diff --git a/examples/astro/tsconfig.json b/examples/astro/tsconfig.json new file mode 100644 index 0000000..bcbf8b5 --- /dev/null +++ b/examples/astro/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "astro/tsconfigs/strict" +}