### Run It Source: https://docs.lakebed.dev/examples/todo Commands to run the checked-in example. ```bash npx lakebed auth as alice npx lakebed dev examples/todo ``` -------------------------------- ### Open Todo Example with Different Guests Source: https://docs.lakebed.dev/examples Open the todo example in separate browser tabs with different guest identities to test user-specific functionality. ```bash http://localhost:3000/?lakebed_guest=alice http://localhost:3000/?lakebed_guest=bob ``` -------------------------------- ### Run Todo Example Source: https://docs.lakebed.dev/examples Command to run the checked-in todo example locally. ```bash npx lakebed dev examples/todo ``` -------------------------------- ### Create and run a capsule Source: https://docs.lakebed.dev/ Example of creating a new capsule using the 'todo' template and then starting the development server. ```bash npx lakebed new my-app --template todo cd my-app npx lakebed dev ``` -------------------------------- ### Run Guestbook Example Source: https://docs.lakebed.dev/llms-full.txt Command to run the checked-in guestbook example. ```sh npx lakebed auth as alice npx lakebed dev examples/guestbook ``` -------------------------------- ### Todo Example Directory Structure Source: https://docs.lakebed.dev/examples The file layout for a complete Lakebed app, as demonstrated by the todo example. ```text server/index.ts client/index.tsx shared/ ``` -------------------------------- ### Inspect State Commands Source: https://docs.lakebed.dev/examples/todo Commands to inspect the state and logs of the running Todo example. ```bash npx lakebed db dump --port 3000 npx lakebed logs --port 3000 ``` -------------------------------- ### Server Pattern Source: https://docs.lakebed.dev/examples/todo This pattern shows how to handle authenticated per-user data with server-owned mutations in Lakebed. ```javascript queries: { todos: query((ctx) => ctx.db.todos .where("ownerId", ctx.auth.userId) .orderBy("createdAt", "desc") .all() ) } ``` -------------------------------- ### Server Handler Example Source: https://docs.lakebed.dev/reference Example of a server handler defining queries and mutations. ```typescript query((ctx) => ( ctx.db.todos.where("ownerId", ctx.auth.userId) .orderBy("createdAt", "desc") .all() ) }, mutations: { addTodo: mutation((ctx, text: string) => ctx.db.todos.insert({ text, done: false, ownerId: ctx.auth.userId }) ) } }); ``` -------------------------------- ### Client API Usage Example Source: https://docs.lakebed.dev/reference Example of using the useMutation hook on the client. ```typescript const addTodo = useMutation<[text: string], void>("addTodo"); await addTodo("Ship the app"); ``` -------------------------------- ### CLI: Development Server Source: https://docs.lakebed.dev/reference Command to start the local development server. ```bash npx lakebed dev [capsule-dir] [--port 3000] ``` -------------------------------- ### View Guestbook Logs Source: https://docs.lakebed.dev/examples/guestbook Command to view the logs of the guestbook application running on port 3000. ```bash npx lakebed logs --port 3000 ``` -------------------------------- ### Server Pattern - Writes Source: https://docs.lakebed.dev/examples/guestbook Inserts a new entry into the database, using server-side authentication for author details. ```javascript ctx.db.entries.insert({ body: trimmed, authorId: ctx.auth.userId, authorName: ctx.auth.displayName, authorPicture: ctx.auth.picture ?? "" }); ``` -------------------------------- ### Client API - Mutation Example Source: https://docs.lakebed.dev/llms-full.txt Example of using a mutation hook in the client to call a server mutation. ```typescript const addTodo = useMutation<[text: string], void>("addTodo"); await addTodo("Ship the app"); ``` -------------------------------- ### Mutation Ownership Check Source: https://docs.lakebed.dev/examples/todo For mutations, fetch the row and check ownership before changing it. ```javascript const todo = ctx.db.todos.get(id); if (!todo || todo.ownerId !== ctx.auth.userId) { return; } ctx.db.todos.update(id, { done }); ``` -------------------------------- ### Server Pattern - Queries Source: https://docs.lakebed.dev/examples/guestbook Defines a shared feed query for entries, ordered by creation date and limited to 50. ```javascript queries: { entries: query((ctx) => ctx.db.entries.orderBy("createdAt", "desc").limit(50).all()) } ``` -------------------------------- ### Reading Server Environment Variables Source: https://docs.lakebed.dev/ Example of reading server environment variables within a query. ```typescript queries: { settings: query((ctx) => ({ hasOpenAiKey: Boolean(ctx.env.OPENAI_API_KEY) })) } ``` -------------------------------- ### Server-Only Environment Variables Source: https://docs.lakebed.dev/ Example of server-only environment variables in .env.lakebed.server. ```dotenv OPENAI_API_KEY=sk-... STRIPE_WEBHOOK_SECRET=whsec_... ``` -------------------------------- ### Development Commands Source: https://docs.lakebed.dev/capsule-api Commands for starting the development server, listing databases, dumping database contents, and viewing logs. ```bash npx lakebed dev npx lakebed db list --port 3000 npx lakebed db dump --port 3000 npx lakebed logs --port 3000 ``` -------------------------------- ### Reading Server Environment Variables Source: https://docs.lakebed.dev/reference Example of reading server-only environment variables. ```typescript query((ctx) => Boolean(ctx.env.OPENAI_API_KEY)); ``` -------------------------------- ### Server API - Capsule Definition Source: https://docs.lakebed.dev/llms-full.txt Example of defining a capsule with schema, queries, and mutations. ```typescript import { boolean, capsule, mutation, query, string, table } from "lakebed/server"; 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) => ctx.db.todos.insert({ text, done: false, ownerId: ctx.auth.userId }) ) } }); ``` -------------------------------- ### Define The Server (Capsule API) Source: https://docs.lakebed.dev/llms-full.txt Example of defining a Lakebed capsule with schema, queries, and mutations using the server-side API. ```ts 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 }); }) } }); ``` -------------------------------- ### Server Contract Definition Source: https://docs.lakebed.dev/ Example of defining a capsule with mutations, queries, and tables using the Lakebed server library. ```typescript import { capsule, mutation, query, string, table } from "lakebed/server"; export default capsule({ ``` -------------------------------- ### Server Environment Variable Reading Source: https://docs.lakebed.dev/capsule-api Example of how to define and read server-only environment variables. ```typescript queries: { hasOpenAiKey: query((ctx) => Boolean(ctx.env.OPENAI_API_KEY)) } ``` -------------------------------- ### Server Contract Definition Source: https://docs.lakebed.dev/llms-full.txt Example of defining a capsule's server contract, including schema, queries, and mutations. ```typescript import { capsule, mutation, query, string, table } from "lakebed/server"; export default capsule({ schema: { messages: table({ body: string(), authorId: string() }) }, queries: { messages: query((ctx) => ctx.db.messages .where("authorId", ctx.auth.userId) .orderBy("createdAt", "desc") .all() ) }, mutations: { sendMessage: mutation((ctx, body: string) => ctx.db.messages.insert({ body, authorId: ctx.auth.userId }) ) } }); ``` -------------------------------- ### Client Contract: App Component Source: https://docs.lakebed.dev/ Example React component using Lakebed client hooks for authentication, queries, and mutations. ```typescript 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)}
); } ``` -------------------------------- ### CLI: Run Anonymous Server Locally Source: https://docs.lakebed.dev/reference Command to run an anonymous server locally. ```bash npx lakebed anonymous-server [--port 8787] [--public-root-url ] [--app-base-domain ] ``` -------------------------------- ### Hosted Runtime Inspection Commands Source: https://docs.lakebed.dev/reference CLI commands for inspecting a deployed Lakebed application. ```bash npx lakebed inspect npx lakebed db list npx lakebed db dump npx lakebed logs ``` -------------------------------- ### Local Deploy Runner Commands Source: https://docs.lakebed.dev/ Commands to run a local deploy runner and deploy an application. ```bash npx lakebed anonymous-server --port 8787 npx lakebed deploy --api http://localhost:8787 ``` -------------------------------- ### CLI: Build for Anonymous Server Source: https://docs.lakebed.dev/reference Command to build a capsule for an anonymous server target. ```bash npx lakebed build [capsule-dir] --target anonymous [--out .lakebed/artifacts/app.json] [--json] ``` -------------------------------- ### CLI: Inspect Deployed App Source: https://docs.lakebed.dev/reference Command to inspect a deployed Lakebed application. ```bash npx lakebed inspect [--api ] [--inspect-token ] [--json] ``` -------------------------------- ### Hosted/Deployed App Inspection Commands Source: https://docs.lakebed.dev/ Commands to inspect, dump database, or view logs for hosted or locally deployed apps. ```bash npx lakebed inspect npx lakebed db dump npx lakebed logs ``` -------------------------------- ### CLI: Run Many Capsules Locally Source: https://docs.lakebed.dev/reference Command to run multiple capsule instances locally for testing. ```bash npx lakebed run-many [capsule-dir] [--count 20] [--base-port 4000] ``` -------------------------------- ### Server Environment Variables Source: https://docs.lakebed.dev/llms-full.txt This snippet demonstrates how to define and read server-only environment variables. ```txt # .env.lakebed.server OPENAI_API_KEY=sk-... ``` -------------------------------- ### CLI: Create New Capsule Source: https://docs.lakebed.dev/reference Command to create a new Lakebed capsule. ```bash npx lakebed new [name] [--template todo] [--no-git] npx lakebed create [name] [--template todo] [--no-git] ``` -------------------------------- ### CLI: Deploy Capsule Source: https://docs.lakebed.dev/reference Command to deploy a Lakebed capsule. ```bash npx lakebed deploy [capsule-dir] [--api ] [--public-inspect] [--json] ``` -------------------------------- ### Lakebed CLI Commands Source: https://docs.lakebed.dev/llms-full.txt A list of available commands for the Lakebed CLI, including options for project creation, development, building, deployment, and database management. ```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 domains add [--api ] [--json] npx lakebed anonymous-server [--port 8787] [--public-root-url ] [--app-base-domain ] 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 ] ``` -------------------------------- ### Local Development Inspection Commands Source: https://docs.lakebed.dev/ Commands to inspect the database, dump data, and view logs during local development. ```bash npx lakebed db list --port 3000 npx lakebed db dump --port 3000 npx lakebed logs --port 3000 ``` -------------------------------- ### CLI: Add Domain Source: https://docs.lakebed.dev/reference Command to add a custom domain to a Lakebed deployment. ```bash npx lakebed domains add [--api ] [--json] ``` -------------------------------- ### Server Schema, Queries, and Mutations Source: https://docs.lakebed.dev/ Defines the schema for messages, a query to retrieve messages for the current user, and a mutation to send a new message. ```typescript schema: { messages: table({ body: string(), authorId: string() }) }, queries: { messages: query((ctx) => ctx.db.messages .where("authorId", ctx.auth.userId) .orderBy("createdAt", "desc") .all() ) }, mutations: { sendMessage: mutation((ctx, body: string) => ctx.db.messages.insert({ body, authorId: ctx.auth.userId }) ) } ``` -------------------------------- ### Lakebed CLI Commands Source: https://docs.lakebed.dev/reference Common commands for managing Lakebed deployments, authentication, and databases. ```bash 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 ] ``` -------------------------------- ### Setting Global Guest Identity Source: https://docs.lakebed.dev/ Command to set the current global guest identity for development. ```bash npx lakebed auth as alice ``` -------------------------------- ### Reserve App Subdomain Source: https://docs.lakebed.dev/ Command to reserve a Lakebed-owned app subdomain after a hosted deploy is claimed. ```bash npx lakebed domains add my-app.lakebed.app ``` -------------------------------- ### Setting Identity Per Browser Tab Source: https://docs.lakebed.dev/reference URL parameter to set identity per browser tab. ```bash http://localhost:3000/?lakebed_guest=alice ``` -------------------------------- ### CLI: Claim Capsule Source: https://docs.lakebed.dev/reference Command to claim a Lakebed capsule. ```bash npx lakebed claim [capsule-dir] [--api ] [--json] ``` -------------------------------- ### Define The Server Source: https://docs.lakebed.dev/capsule-api This code snippet demonstrates how to define the server-side capsule API, including schema, queries, and mutations. ```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; } }) } }); ``` -------------------------------- ### Public Inspection Deployment Source: https://docs.lakebed.dev/capsule-api Use this flag for demos where making hosted data and logs public is intentional. ```bash npx lakebed deploy --public-inspect ``` -------------------------------- ### Server API Imports Source: https://docs.lakebed.dev/reference Imports for defining a Lakebed server API. ```typescript import { boolean, capsule, mutation, query, string, table } from "lakebed/server"; ``` -------------------------------- ### Deployment Command Source: https://docs.lakebed.dev/capsule-api Command to deploy the application. Running it again after configuring server-side fetch or .env.lakebed.server is necessary for Lakebed to publish the source-backed server path. ```bash npx lakebed deploy ``` -------------------------------- ### Server Auth Context Source: https://docs.lakebed.dev/llms-full.txt This snippet shows how to access authenticated user information within server handlers. ```ts ctx.auth.userId; ctx.auth.displayName; ctx.auth.picture; ctx.auth.email; ``` -------------------------------- ### Client Auth Hook Source: https://docs.lakebed.dev/llms-full.txt This snippet shows how to access authenticated user information on the client using the `useAuth` hook. ```tsx const auth = useAuth(); ``` -------------------------------- ### Capsule Definition Source: https://docs.lakebed.dev/reference Exporting a default capsule call with schema and queries. ```typescript export default capsule({ schema: { todos: table({ text: string(), done: boolean().default(false), ownerId: string() }) }, queries: { todos: query((ctx) => ctx.db.todos ``` -------------------------------- ### Client-side App Component Source: https://docs.lakebed.dev/capsule-api The main application component for the client, handling authentication, queries, mutations, and form submission for todos. ```typescript 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 (
{!auth.isLoading && auth.picture ? ( ) : null}

{authStatus}

{!auth.isLoading && auth.isGuest ? ( ) : !auth.isLoading ? ( ) : null}
void onSubmit(event)}>
    {todos.map((todo) => (
  • ))}
); } ``` -------------------------------- ### Auth - Auth Type Definition Source: https://docs.lakebed.dev/llms-full.txt TypeScript type definition for the authentication object on client and server. ```typescript type Auth = { userId: string; displayName: string; provider: "guest" | "google"; isGuest: boolean; isAuthenticated: boolean; isLoading?: boolean; // client-only email?: string; emailVerified?: boolean; picture?: string; }; ``` -------------------------------- ### Capsule Directory Shape Source: https://docs.lakebed.dev/reference The expected directory structure for a Lakebed capsule in v0. ```text server/index.ts client/index.tsx shared/ .env.lakebed.server ``` -------------------------------- ### Todo Type Definition and Text Cleaning Source: https://docs.lakebed.dev/capsule-api Defines the structure of a Todo item and a utility function to clean its text content. ```typescript export type Todo = { id: string; text: string; done: boolean; ownerId: string; createdAt: string; updatedAt: string; }; export function cleanTodoText(value: string): string { return value.trim().slice(0, 160); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.