### Run Guestbook Example
Source: https://docs.lakebed.dev/examples/guestbook
Commands to run the checked-in example locally. Use the `lakebed auth` command to simulate different users.
```bash
npx lakebed auth as alice
npx lakebed dev examples/guestbook
```
--------------------------------
### Run Lakebed Todo Example
Source: https://docs.lakebed.dev/examples/index.md
Execute the checked-in todo example using the Lakebed development server.
```sh
npx lakebed dev examples/todo
```
--------------------------------
### Access Todo Example
Source: https://docs.lakebed.dev/raw/examples/todo/README.md
URLs to access the running Todo Example. The first URL opens the app for the current user, while the second allows comparing states for different users by appending a query parameter.
```text
http://localhost:3000
http://localhost:3000/?lakebed_guest=alice
```
--------------------------------
### Start Lakebed Hosted Environment
Source: https://docs.lakebed.dev/llms-full.txt
Repository contributors can start the private hosted workspace for local deploy testing. This command is typically used in conjunction with deploying to a local API endpoint.
```sh
pnpm --filter @lakebed/hosted start
```
--------------------------------
### Start Hosted Workspace and Deploy Locally
Source: https://docs.lakebed.dev/index.md
Repository contributors can start a local hosted workspace and then deploy to it using a local API endpoint. This is useful for testing hosted deployments in a local environment.
```sh
pnpm --filter @lakebed/hosted start
npx lakebed deploy --api http://localhost:8787
```
--------------------------------
### Run Lakebed development server
Source: https://docs.lakebed.dev/raw/docs/reference.md
Start the development server for a capsule. You can specify a custom port.
```bash
npx lakebed dev [capsule-dir] [--port 3000]
```
--------------------------------
### Client-Side Routing Example
Source: https://docs.lakebed.dev/reference/index.md
Sets up client-side routing with nested routes and navigation links. Uses useParams to access route parameters.
```tsx
function TodoPage() {
const { id } = useParams<{ id: string }>();
return Todo {id};
}
export function App() {
return (
Open todo
Home} />
} />
Not found} />
);
}
```
--------------------------------
### Run Lakebed Development Server
Source: https://docs.lakebed.dev/examples/todo
Commands to start the Lakebed development server and authenticate as a specific user ('alice').
```bash
npx lakebed auth as alice
npx lakebed dev examples/todo
```
--------------------------------
### Deploy to Local Hosted Environment
Source: https://docs.lakebed.dev/llms-full.txt
After starting the local hosted environment, use this command to deploy your application to the specified local API endpoint. Ensure the API URL matches the running hosted service.
```sh
npx lakebed deploy --api http://localhost:8787
```
--------------------------------
### File Layout Example
Source: https://docs.lakebed.dev/capsule-api
Defines the standard file layout for a Lakebed application, separating server, client, and shared code.
```text
server/index.ts
client/index.tsx
shared/
```
--------------------------------
### Create and Run a Lakebed Capsule
Source: https://docs.lakebed.dev/index.md
Use `npx lakebed new` to create a new capsule with a template, `cd` into the directory, and then `npx lakebed dev` to start the development server. New capsules are initialized with a git repository unless `--no-git` is specified or if created within an existing git repository.
```sh
npx lakebed new my-app --template todo
cd my-app
npx lakebed dev
```
--------------------------------
### Run Lakebed Development Server
Source: https://docs.lakebed.dev/raw/docs/capsule-api.md
Start the local development server for Lakebed. This command also initializes an in-memory database that resets on each restart.
```bash
npx lakebed dev
```
--------------------------------
### Inspect Guestbook State
Source: https://docs.lakebed.dev/examples/guestbook
Commands to inspect the local database and logs for the running guestbook example.
```bash
npx lakebed db dump --port 3000
npx lakebed logs --port 3000
```
--------------------------------
### Development Commands
Source: https://docs.lakebed.dev/capsule-api/index.md
Run essential development commands for the Lakebed project, including starting the development server, listing, dumping, and viewing database information.
```bash
npx lakebed dev
npx lakebed db list --port 3000
npx lakebed db dump --port 3000
npx lakebed logs --port 3000
```
--------------------------------
### Client-Side Routing with Lakebed
Source: https://docs.lakebed.dev/index.md
This example shows how to implement client-side navigation using Lakebed's routing components. It defines routes for a home page, an item page with dynamic parameters, and a catch-all not found page. Use `Link` for navigation and `useParams` to access route parameters.
```tsx
import { Link, Route, Router, Routes, useParams } from "lakebed/client";
function ItemPage() {
const { id } = useParams<{ id: string }>();
return Item {id};
}
export function App() {
return (
Open item
Home} />
} />
Not found} />
);
}
```
--------------------------------
### Client Application with Routing
Source: https://docs.lakebed.dev/capsule-api/index.md
Example of a React client application demonstrating routing using lakebed's client router. It sets up links and routes for different pages, including dynamic route parameters.
```tsx
import { Link, Route, Router, Routes, useParams } from "lakebed/client";
function TodoPage() {
const { id } = useParams<{ id: string }>();
return Todo {id};
}
export function App() {
return (
Open todo
Home} />
} />
Not found} />
);
}
```
--------------------------------
### Client Application with Authentication and Data Fetching
Source: https://docs.lakebed.dev/capsule-api/index.md
Example of a React client application using lakebed hooks for authentication, querying data, and performing mutations. It includes form submission logic and conditional rendering based on authentication status.
```tsx
import { SignInWithGoogle, signOut, useAuth, useMutation, useQuery } from "lakebed/client";
import { cleanTodoText, type Todo } from "../shared/todo";
export function App() {
const auth = useAuth();
const todos = useQuery("todos");
const addTodo = useMutation<[text: string], void>("addTodo");
const setTodoDone = useMutation<[id: string, done: boolean], void>("setTodoDone");
const authLabel = auth.displayName;
const authStatus = auth.isLoading && auth.isGuest ? "checking session" : `signed in as ${authLabel}`;
async function onSubmit(event: SubmitEvent) {
event.preventDefault();
const form = event.currentTarget as HTMLFormElement;
const data = new FormData(form);
const text = cleanTodoText(String(data.get("text") ?? ""));
if (!text) {
return;
}
await addTodo(text);
form.reset();
}
return (
);
}
```
--------------------------------
### Query: Get Todos
Source: https://docs.lakebed.dev/raw/docs/capsule-api.md
Retrieves a list of todos for the authenticated user, ordered by creation date in descending order.
```APIDOC
## GET /todos
### Description
Retrieves a list of todos associated with the current user.
### Method
GET
### Endpoint
/todos
### Parameters
#### Query Parameters
None
### Response
#### Success Response (200)
- **todos** (array) - A list of todo objects.
- **id** (string) - The unique identifier for the todo.
- **text** (string) - The content of the todo.
- **done** (boolean) - Indicates if the todo is completed.
- **ownerId** (string) - The ID of the user who owns the todo.
- **createdAt** (string) - The timestamp when the todo was created.
#### Response Example
{
"todos": [
{
"id": "todo-123",
"text": "Buy groceries",
"done": false,
"ownerId": "user-abc",
"createdAt": "2023-10-27T10:00:00Z"
}
]
}
```
--------------------------------
### Get Authentication Object on Client
Source: https://docs.lakebed.dev/capsule-api/index.md
Obtain the authentication object on the client-side using the useAuth hook.
```tsx
const auth = useAuth();
```
--------------------------------
### List Databases in Local Development
Source: https://docs.lakebed.dev/raw/docs/README.md
Command to list available databases when running `npx lakebed dev`. Specify the port if it's not the default.
```sh
npx lakebed db list --port 3000
```
--------------------------------
### Create a new Lakebed project
Source: https://docs.lakebed.dev/raw/docs/reference.md
Use `npx lakebed new` to initialize a new project, optionally specifying a template and disabling Git initialization. `npx lakebed create` is an alias for this command.
```bash
npx lakebed new [name] [--template todo] [--no-git]
npx lakebed create [name] [--template todo] [--no-git]
```
--------------------------------
### Client App with Authentication and Data Fetching
Source: https://docs.lakebed.dev/raw/docs/README.md
This snippet demonstrates a basic client application structure using Lakebed. It shows how to handle authentication states, fetch data with `useQuery`, and trigger mutations with `useMutation`. Use `auth.isLoading` to manage UI during session checks.
```tsx
import { SignInWithGoogle, signOut, useAuth, useMutation, useQuery } from "lakebed/client";
type Message = {
id: string;
body: string;
authorId: string;
createdAt: string;
updatedAt: string;
};
export function App() {
const auth = useAuth();
const messages = useQuery("messages");
const sendMessage = useMutation<[body: string], void>("sendMessage");
return (
{auth.isLoading ? (
Checking session
) : auth.isGuest ? (
) : (
)}
{JSON.stringify(messages, null, 2)}
);
}
```
--------------------------------
### Manage Lakebed databases
Source: https://docs.lakebed.dev/raw/docs/reference.md
List available databases for a deploy or dump the contents of a database. Requires specifying the deploy ID or URL and optionally a port and inspection token.
```bash
npx lakebed db list [deploy-id-or-url] [--port 3000] [--inspect-token ]
npx lakebed db dump [deploy-id-or-url] [--port 3000] [--inspect-token ]
```
--------------------------------
### Inspect Database in Local Development
Source: https://docs.lakebed.dev/index.md
Commands to inspect the database state while `npx lakebed dev` is running locally. Specify the port if it's not the default.
```sh
npx lakebed db list --port 3000
npx lakebed db dump --port 3000
```
--------------------------------
### Authenticate for Deployment
Source: https://docs.lakebed.dev/capsule-api/index.md
Before your first deploy, run this command to authenticate. This generates a lakebed.json file containing your deploy ID, which should be committed to your repository.
```sh
npx lakebed auth login
```
--------------------------------
### View Logs in Local Development
Source: https://docs.lakebed.dev/index.md
Command to view application logs while `npx lakebed dev` is running locally. Specify the port if it's not the default.
```sh
npx lakebed logs --port 3000
```
--------------------------------
### Client App with Authentication and Data Fetching
Source: https://docs.lakebed.dev/index.md
This snippet demonstrates a basic client application structure using Lakebed. It includes authentication status checks, sign-in/sign-out functionality, and fetching messages using `useQuery` and sending messages with `useMutation`. Use `auth.isLoading` to manage UI states during session verification.
```tsx
import { SignInWithGoogle, signOut, useAuth, useMutation, useQuery } from "lakebed/client";
type Message = {
id: string;
body: string;
authorId: string;
createdAt: string;
updatedAt: string;
};
export function App() {
const auth = useAuth();
const messages = useQuery("messages");
const sendMessage = useMutation<[body: string], void>("sendMessage");
return (
{auth.isLoading ? (
Checking session
) : auth.isGuest ? (
) : (
)}
{JSON.stringify(messages, null, 2)}
);
}
```
--------------------------------
### Adding Google Sign-in
Source: https://docs.lakebed.dev/capsule-api
Integrate Google sign-in by rendering the `` component or calling `signInWithGoogle()` from a custom button. Verified identity is available on `ctx.auth` after sign-in.
```javascript
signInWithGoogle()
```
--------------------------------
### Deploying with Lakebed
Source: https://docs.lakebed.dev/reference
Commands and configurations for deploying applications with Lakebed, including anonymous deploys and authentication.
```bash
npx lakebed deploy
```
```bash
npx lakebed auth login
```
```bash
npx lakebed token create --name github-actions
```
```bash
npx lakebed token create --personal --name local-automation
```
```bash
npx lakebed deploy --public-inspect
```
--------------------------------
### Simulate Guest Identities
Source: https://docs.lakebed.dev/examples/index.md
Open separate browser tabs to simulate different guest identities for testing.
```txt
http://localhost:3000/?lakebed_guest=alice
http://localhost:3000/?lakebed_guest=bob
```
--------------------------------
### Call a Server Mutation
Source: https://docs.lakebed.dev/reference/index.md
Demonstrates how to define and call a server mutation. The mutation call returns a promise that can be awaited.
```tsx
const addTodo = useMutation<[text: string], void>("addTodo");
await addTodo("Ship the app");
```
--------------------------------
### Build a Lakebed capsule
Source: https://docs.lakebed.dev/raw/docs/reference.md
Build a capsule for deployment. You can specify the target, output path, and format.
```bash
npx lakebed build [capsule-dir] --target anonymous [--out .lakebed/artifacts/app.json] [--json]
```
--------------------------------
### Access Local Development Server
Source: https://docs.lakebed.dev/examples/todo
The URL to access the running Lakebed application locally.
```bash
http://localhost:3000
```
--------------------------------
### Access Guestbook Locally
Source: https://docs.lakebed.dev/examples/guestbook
Open the guestbook in your browser at the specified address. You can simulate different users by appending the `lakebed_guest` query parameter.
```bash
http://localhost:3000
http://localhost:3000/?lakebed_guest=alice
http://localhost:3000/?lakebed_guest=bob
```
--------------------------------
### Inspect a Lakebed deploy
Source: https://docs.lakebed.dev/raw/docs/reference.md
Inspect a deployed application, optionally providing an inspection token for private deploys.
```bash
npx lakebed inspect [--api ] [--inspect-token ] [--json]
```
--------------------------------
### Add Application Subdomain
Source: https://docs.lakebed.dev/index.md
After a hosted deploy is claimed, reserve a Lakebed-owned app subdomain from the capsule directory.
```sh
npx lakebed domains add my-app.lakebed.app
```
--------------------------------
### navigate Function
Source: https://docs.lakebed.dev/raw/docs/reference.md
Programmatically navigates the client to a specified path.
```APIDOC
## navigate(path: string)
### Description
Navigates the client to the specified `path`. This function is equivalent to calling the function returned by `useNavigate()`.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```typescript
navigate('/settings');
```
### Response
This function performs client-side navigation. It does not return a value.
```
--------------------------------
### Dump Database in Local Development
Source: https://docs.lakebed.dev/raw/docs/README.md
Command to dump the contents of a database when running `npx lakebed dev`. Specify the port if it's not the default.
```sh
npx lakebed db dump --port 3000
```
--------------------------------
### Server-Only Environment Variables
Source: https://docs.lakebed.dev/index.md
Define server-only environment variables in the `.env.lakebed.server` file. These are only accessible from server handlers.
```txt
OPENAI_API_KEY=sk-...
STRIPE_WEBHOOK_SECRET=whsec_...
```
--------------------------------
### Lakebed CLI Commands
Source: https://docs.lakebed.dev/reference/index.md
A comprehensive list of available Lakebed CLI commands for managing projects, development, building, deployment, and authentication.
```sh
npx lakebed new [name] [--template todo] [--no-git]
npx lakebed create [name] [--template todo] [--no-git]
npx lakebed dev [capsule-dir] [--port 3000]
npx lakebed build [capsule-dir] --target anonymous [--out .lakebed/artifacts/app.json] [--json]
npx lakebed deploy [capsule-dir] [--api ] [--public-inspect] [--json]
npx lakebed claim [capsule-dir] [--api ] [--json]
npx lakebed auth login [--api ] [--json]
npx lakebed auth status [--api ] [--json]
npx lakebed auth logout [--api ]
npx lakebed token create --name [--personal] [--api ] [--json]
npx lakebed token list [--api ] [--json]
npx lakebed token revoke [--api ]
npx lakebed domains add [--api ] [--json]
npx lakebed inspect [--api ] [--inspect-token ] [--json]
npx lakebed run-many [capsule-dir] [--count 20] [--base-port 4000]
npx lakebed auth as
npx lakebed auth reset
npx lakebed db list [deploy-id-or-url] [--port 3000] [--inspect-token ]
npx lakebed db dump [deploy-id-or-url] [--port 3000] [--inspect-token ]
npx lakebed logs [deploy-id-or-url] [--port 3000] [--inspect-token ]
```
--------------------------------
### Implement Todo Ownership Check
Source: https://docs.lakebed.dev/examples/todo
Illustrates a secure mutation pattern by fetching a row and verifying ownership before performing an update. This prevents unauthorized modifications.
```javascript
const todo = ctx.db.todos.get(id);
if (!todo || todo.ownerId !== ctx.auth.userId) {
return;
}
ctx.db.todos.update(id, { done });
```
--------------------------------
### SignInWithGoogle Component
Source: https://docs.lakebed.dev/raw/docs/reference.md
A pre-built React component that renders a button for initiating Google sign-in.
```APIDOC
##
### Description
This component renders a user interface element, typically a button, that initiates the Google sign-in process when clicked.
### Parameters
None
### Request Example
```typescript
```
### Response
This component renders a UI element. No direct response data is returned to the calling code.
```
--------------------------------
### Lakebed Capsule Structure
Source: https://docs.lakebed.dev/raw/docs/README.md
A standard Lakebed v0 capsule includes server, client, shared directories, and environment configuration.
```txt
server/index.ts
client/index.tsx
shared/
.env.lakebed.server
```
--------------------------------
### View Lakebed deploy logs
Source: https://docs.lakebed.dev/raw/docs/reference.md
Retrieve logs for a specific deployment. You can specify the deploy ID or URL, port, and an inspection token.
```bash
npx lakebed logs [deploy-id-or-url] [--port 3000] [--inspect-token ]
```
--------------------------------
### Data Fetching Hooks
Source: https://docs.lakebed.dev/reference/index.md
Hooks for subscribing to server queries and calling server mutations. `useQuery` fetches data, and `useMutation` allows for data modification. Mutation calls return promises.
```APIDOC
## useQuery("name")
### Description
Subscribe to a server query.
### Usage
```tsx
const data = useQuery("getData");
```
```
```APIDOC
## useMutation("name")
### Description
Call a server mutation. Mutation calls return promises.
### Usage
```tsx
const addTodo = useMutation<[text: string], void>("addTodo");
await addTodo("Ship the app");
```
```
--------------------------------
### signInWithGoogle Function
Source: https://docs.lakebed.dev/raw/docs/reference.md
Initiates the Google sign-in flow from a custom UI element.
```APIDOC
## signInWithGoogle()
### Description
Programmatically starts the Google sign-in process. This is useful when you want to trigger sign-in from a custom button or action not using the `` component.
### Parameters
None
### Request Example
```typescript
async function handleLogin() {
await signInWithGoogle();
}
```
### Response
This function initiates an authentication flow. It returns a promise that resolves upon successful initiation or rejects on error.
```
--------------------------------
### View Logs for a Deployed Application
Source: https://docs.lakebed.dev/raw/docs/README.md
View application logs for a hosted or locally deployed application using its deploy ID or URL.
```sh
npx lakebed logs
```
--------------------------------
### Manage Lakebed API tokens
Source: https://docs.lakebed.dev/raw/docs/reference.md
Create, list, or revoke API tokens for authentication. Personal tokens can be created for owner-wide credentials.
```bash
npx lakebed token create --name [--personal] [--api ] [--json]
npx lakebed token list [--api ] [--json]
npx lakebed token revoke [--api ]
```
--------------------------------
### Inspect a Deployed Application
Source: https://docs.lakebed.dev/raw/docs/README.md
Inspect a hosted or locally deployed application by providing its deploy ID or URL. This allows access to app manifests, state, and logs.
```sh
npx lakebed inspect
```
--------------------------------
### List Deployed Database Tables
Source: https://docs.lakebed.dev/reference/index.md
Lists database tables for a deployed Lakebed application using its deploy ID or URL. This command is used for inspecting hosted databases.
```sh
npx lakebed db list
```
--------------------------------
### useQuery
Source: https://docs.lakebed.dev/reference
Hook to subscribe to a server query. It allows the client to efficiently fetch and stay updated with data from the server.
```APIDOC
## useQuery(name: string)
### Description
Subscribes to a server query, enabling real-time data synchronization.
### Parameters
#### Type Parameters
* **T**: The expected type of the data returned by the query.
#### Arguments
* **name** (string) - Required - The name of the server query to subscribe to.
```
--------------------------------
### Authentication Hooks and Components
Source: https://docs.lakebed.dev/reference/index.md
Utilities for managing user authentication state and initiating sign-in/sign-out flows.
```APIDOC
## useAuth()
### Description
Read the current client identity. Use `auth.isLoading` to avoid showing signed-out UI while Lakebed confirms a stored session.
### Usage
```tsx
const auth = useAuth();
if (auth.isLoading) {
return ;
}
// ... render UI based on auth.user
```
```
```APIDOC
## SignInWithGoogle
### Description
Render the built-in Google sign-in button component.
### Usage
```tsx
```
```
```APIDOC
## signInWithGoogle()
### Description
Start Google sign-in from a custom UI element.
### Usage
```tsx
async function handleLogin() {
await signInWithGoogle();
}
```
```
```APIDOC
## signOut()
### Description
Return the user to a guest authentication state.
### Usage
```tsx
await signOut();
```
```
--------------------------------
### Lakebed App File Structure
Source: https://docs.lakebed.dev/raw/examples/README.md
Standard file layout for a Lakebed application, including server, client, and shared directories.
```txt
server/index.ts
client/index.tsx
shared/
```
--------------------------------
### Inspect Deployed Application
Source: https://docs.lakebed.dev/index.md
Inspect a hosted or locally deployed application by providing its deploy ID or URL. This allows access to manifests, state, and logs.
```sh
npx lakebed inspect
npx lakebed db dump
npx lakebed logs
```
--------------------------------
### Router, Routes, Route
Source: https://docs.lakebed.dev/reference
Components for setting up client-side routing within the application.
```APIDOC
## , ,
### Description
These components manage client-side navigation and page rendering based on the URL. `` should wrap your routes, `` groups individual `` definitions, and `` maps a path to a specific element.
### Router Example
```javascript
function App() {
return (
Home} />
} />
);
}
```
```
--------------------------------
### Deploy Application with Public Inspection
Source: https://docs.lakebed.dev/index.md
Use this flag to make inspection data and logs public for demos. This is useful when showcasing applications that intentionally expose public data.
```sh
npx lakebed deploy --public-inspect
```
--------------------------------
### useNavigate
Source: https://docs.lakebed.dev/raw/docs/reference.md
Hook that provides a function to programmatically navigate to a different route.
```APIDOC
## useNavigate()
### Description
Returns a function that can be called to programmatically navigate the user to a new route within the application.
### Parameters
None
### Request Example
```typescript
const navigate = useNavigate();
navigate('/dashboard');
```
### Response
#### Success Response (200)
- **navigate** (function) - A function that accepts a path string to navigate to.
```
--------------------------------
### Deploy a Lakebed capsule
Source: https://docs.lakebed.dev/raw/docs/reference.md
Deploy a capsule to the Lakebed platform. You can specify the API endpoint and whether to allow public inspection.
```bash
npx lakebed deploy [capsule-dir] [--api ] [--public-inspect] [--json]
```
--------------------------------
### Authenticate with Lakebed
Source: https://docs.lakebed.dev/raw/docs/reference.md
Log in to your Lakebed account or check the authentication status. You can also log out.
```bash
npx lakebed auth login [--api ] [--json]
npx lakebed auth status [--api ] [--json]
npx lakebed auth logout [--api ]
```
--------------------------------
### Import Lakebed Client API
Source: https://docs.lakebed.dev/reference/index.md
Imports all necessary components and hooks from the Lakebed client library.
```tsx
import {
Link,
Route,
Router,
Routes,
SignInWithGoogle,
navigate,
signInWithGoogle,
signOut,
useAuth,
useLocation,
useMutation,
useNavigate,
useParams,
useQuery
} from "lakebed/client";
```
--------------------------------
### Dump Database for a Deployed Application
Source: https://docs.lakebed.dev/raw/docs/README.md
Dump the database contents for a hosted or locally deployed application using its deploy ID or URL.
```sh
npx lakebed db dump
```
--------------------------------
### Define Server Schema, Queries, and Mutations
Source: https://docs.lakebed.dev/capsule-api/index.md
Defines the data schema, read queries, and write mutations for a Lakebed application server. Ensures server-side validation and ownership checks for data integrity.
```typescript
import { boolean, capsule, mutation, query, string, table } from "lakebed/server";
import { cleanTodoText } from "../shared/todo";
export default capsule({
schema: {
todos: table({
text: string(),
done: boolean().default(false),
ownerId: string()
})
},
queries: {
todos: query((ctx) =>
ctx.db.todos
.where("ownerId", ctx.auth.userId)
.orderBy("createdAt", "desc")
.all()
)
},
mutations: {
addTodo: mutation((ctx, text: string) => {
const cleanText = cleanTodoText(text);
if (!cleanText) {
return;
}
ctx.db.todos.insert({
text: cleanText,
done: false,
ownerId: ctx.auth.userId
});
}),
setTodoDone: mutation((ctx, id: string, done: boolean) => {
const todo = ctx.db.todos.get(id);
if (!todo || todo.ownerId !== ctx.auth.userId) {
return;
}
ctx.db.todos.update(id, { done });
})
}
});
```