@teable/create-app 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -2
- package/bin/create-teable-app.js +103 -0
- package/dist/template/AGENTS.md +284 -0
- package/dist/template/CLAUDE.md +1 -0
- package/dist/template/components.json +27 -0
- package/dist/template/drizzle/0000_init.sql +6 -0
- package/dist/template/drizzle/meta/0000_snapshot.json +55 -0
- package/dist/template/drizzle/meta/_journal.json +13 -0
- package/dist/template/drizzle/migrations.js +10 -0
- package/dist/template/drizzle.config.ts +8 -0
- package/dist/template/gitignore +8 -0
- package/dist/template/index.html +12 -0
- package/dist/template/package.json +45 -0
- package/dist/template/src/components/ui/alert.tsx +72 -0
- package/dist/template/src/components/ui/button.tsx +52 -0
- package/dist/template/src/components/ui/input.tsx +18 -0
- package/dist/template/src/server/index.ts +28 -0
- package/dist/template/src/server/schema.ts +13 -0
- package/dist/template/src/server/tsconfig.json +10 -0
- package/dist/template/src/web/app.ts +35 -0
- package/dist/template/src/web/main.tsx +49 -0
- package/dist/template/src/web/notes.test.tsx +45 -0
- package/dist/template/src/web/notes.tsx +63 -0
- package/dist/template/src/web/styles.css +146 -0
- package/dist/template/teable.json +1 -0
- package/dist/template/test/env.d.ts +10 -0
- package/dist/template/test/notes.test.ts +29 -0
- package/dist/template/test/worker.ts +5 -0
- package/dist/template/tsconfig.base.json +19 -0
- package/dist/template/tsconfig.json +13 -0
- package/dist/template/vite.config.ts +43 -0
- package/dist/template/wrangler.test.jsonc +7 -0
- package/package.json +22 -4
- package/skill/teable-next-app/SKILL.md +88 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { cn } from "cn";
|
|
3
|
+
import type * as React from "react";
|
|
4
|
+
|
|
5
|
+
const alertVariants = cva(
|
|
6
|
+
"group/alert relative grid w-full gap-0.5 rounded-2xl border px-4 py-3 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2.5 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "bg-card text-card-foreground",
|
|
11
|
+
destructive:
|
|
12
|
+
"bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: "default",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
function Alert({
|
|
22
|
+
className,
|
|
23
|
+
variant,
|
|
24
|
+
...props
|
|
25
|
+
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
data-slot="alert"
|
|
29
|
+
role="alert"
|
|
30
|
+
className={cn(alertVariants({ variant }), className)}
|
|
31
|
+
{...props}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
data-slot="alert-title"
|
|
40
|
+
className={cn(
|
|
41
|
+
"font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",
|
|
42
|
+
className,
|
|
43
|
+
)}
|
|
44
|
+
{...props}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function AlertDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
data-slot="alert-description"
|
|
53
|
+
className={cn(
|
|
54
|
+
"text-sm text-balance text-muted-foreground md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
|
|
55
|
+
className,
|
|
56
|
+
)}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
data-slot="alert-action"
|
|
66
|
+
className={cn("absolute top-2.5 right-3", className)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { Alert, AlertAction, AlertDescription, AlertTitle };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Button as ButtonPrimitive } from "@ui-sdk/react/button";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import type * as React from "react";
|
|
5
|
+
|
|
6
|
+
const buttonVariants = cva(
|
|
7
|
+
"group/button inline-flex shrink-0 items-center justify-center rounded-2xl border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
12
|
+
outline:
|
|
13
|
+
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:bg-transparent dark:hover:bg-input/30",
|
|
14
|
+
secondary:
|
|
15
|
+
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
16
|
+
ghost:
|
|
17
|
+
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
18
|
+
destructive:
|
|
19
|
+
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
20
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
21
|
+
},
|
|
22
|
+
size: {
|
|
23
|
+
default:
|
|
24
|
+
"h-8 gap-1.5 px-3 has-data-[icon=inline-end]:pr-2.5 has-data-[icon=inline-start]:pl-2.5",
|
|
25
|
+
xs: "h-6 gap-1 px-2.5 text-xs has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3",
|
|
26
|
+
sm: "h-7 gap-1 px-3 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
27
|
+
lg: "h-9 gap-1.5 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
|
|
28
|
+
icon: "size-8",
|
|
29
|
+
"icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",
|
|
30
|
+
"icon-sm": "size-7",
|
|
31
|
+
"icon-lg": "size-9",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
variant: "default",
|
|
36
|
+
size: "default",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
function Button({
|
|
42
|
+
className,
|
|
43
|
+
variant = "default",
|
|
44
|
+
size = "default",
|
|
45
|
+
...props
|
|
46
|
+
}: React.ComponentProps<typeof ButtonPrimitive> & VariantProps<typeof buttonVariants>) {
|
|
47
|
+
return (
|
|
48
|
+
<ButtonPrimitive className={cn(buttonVariants({ variant, size, className }))} {...props} />
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { Button, buttonVariants };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Input as InputPrimitive } from "@ui-sdk/react/input";
|
|
2
|
+
import { cn } from "cn";
|
|
3
|
+
import type * as React from "react";
|
|
4
|
+
|
|
5
|
+
function Input({ className, type, ...props }: React.ComponentProps<typeof InputPrimitive>) {
|
|
6
|
+
return (
|
|
7
|
+
<InputPrimitive
|
|
8
|
+
type={type}
|
|
9
|
+
className={cn(
|
|
10
|
+
"h-8 w-full min-w-0 rounded-2xl border border-transparent bg-input/50 px-2.5 py-1 text-base transition-[color,box-shadow] duration-200 outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
11
|
+
className,
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { Input };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A blank Teable app: one table, one read, one write. Replace them with the
|
|
3
|
+
* app's own; AGENTS.md says how.
|
|
4
|
+
*/
|
|
5
|
+
import { createApp, z } from "@teable/app";
|
|
6
|
+
import { schemaOf } from "@teable/app/schema";
|
|
7
|
+
import { desc } from "drizzle-orm";
|
|
8
|
+
import migrations from "../../drizzle/migrations";
|
|
9
|
+
import * as schema from "./schema";
|
|
10
|
+
import { notes } from "./schema";
|
|
11
|
+
|
|
12
|
+
const app = createApp({ schema, migrations });
|
|
13
|
+
|
|
14
|
+
export const listNotes = app.read({
|
|
15
|
+
description: "Notes, newest first",
|
|
16
|
+
output: z.array(schemaOf(notes)),
|
|
17
|
+
handler: ({ db }) => db.select().from(notes).orderBy(desc(notes.id)).all(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const addNote = app.write({
|
|
21
|
+
description: "Add a note",
|
|
22
|
+
// That the text is not blank is the table's CHECK constraint, not this schema's.
|
|
23
|
+
input: z.object({ text: z.string() }),
|
|
24
|
+
output: schemaOf(notes),
|
|
25
|
+
handler: ({ db, input }) => db.insert(notes).values(input).returning().get(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const App = app.define({ listNotes, addNote });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { check, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
3
|
+
|
|
4
|
+
export const notes = sqliteTable(
|
|
5
|
+
"notes",
|
|
6
|
+
{
|
|
7
|
+
id: integer().primaryKey({ autoIncrement: true }),
|
|
8
|
+
text: text().notNull(),
|
|
9
|
+
createdAt: integer({ mode: "timestamp_ms" }).notNull().default(sql`(unixepoch() * 1000)`),
|
|
10
|
+
},
|
|
11
|
+
// A rule SQLite can hold lives here, not in a method: every write path gets it.
|
|
12
|
+
(t) => [check("note_text_not_blank", sql`trim(${t.text}) <> ''`)],
|
|
13
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
// The app's server code runs in workerd: Workers globals, no DOM.
|
|
3
|
+
"extends": "../../tsconfig.base.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
// drizzle-kit writes the migrations index as JavaScript.
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"types": ["@cloudflare/workers-types"]
|
|
8
|
+
},
|
|
9
|
+
"include": ["."]
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { createClient, MethodError, type RealtimeEvent } from "@teable/app/client";
|
|
3
|
+
import type * as server from "../server";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This app's methods, typed from the `App` the server code exports: the names
|
|
7
|
+
* its define() registered, without internal methods and tasks.
|
|
8
|
+
*/
|
|
9
|
+
export const client = createClient<typeof server>({
|
|
10
|
+
appId: import.meta.env.VITE_TEABLE_APP_ID,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The query cache every page shares. A failed read is asked again only when
|
|
15
|
+
* another answer may come, so a refusal (not a member, one of the app's
|
|
16
|
+
* rules) shows at once instead of after three more tries.
|
|
17
|
+
*/
|
|
18
|
+
export const queryClient = new QueryClient({
|
|
19
|
+
defaultOptions: {
|
|
20
|
+
queries: {
|
|
21
|
+
retry: (failures, error) =>
|
|
22
|
+
failures < 3 && (!(error instanceof MethodError) || error.retryable),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What pages read again when the app reports an event (`client.subscribe`):
|
|
29
|
+
* method results after any; the manifest too after a new version went live or
|
|
30
|
+
* the connection was down, since either may have changed it.
|
|
31
|
+
*/
|
|
32
|
+
export function refetchAfter(event: RealtimeEvent): void {
|
|
33
|
+
queryClient.invalidateQueries({ queryKey: client.dataKey });
|
|
34
|
+
if (event.type !== "changes") queryClient.invalidateQueries({ queryKey: client.manifestKey });
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { QueryClientProvider } from "@tanstack/react-query";
|
|
2
|
+
import {
|
|
3
|
+
createRootRoute,
|
|
4
|
+
createRoute,
|
|
5
|
+
createRouter,
|
|
6
|
+
Outlet,
|
|
7
|
+
RouterProvider,
|
|
8
|
+
} from "@tanstack/react-router";
|
|
9
|
+
import { StrictMode } from "react";
|
|
10
|
+
import { createRoot } from "react-dom/client";
|
|
11
|
+
import { client, queryClient, refetchAfter } from "./app";
|
|
12
|
+
import { NotesPage } from "./notes";
|
|
13
|
+
import "./styles.css";
|
|
14
|
+
|
|
15
|
+
const rootRoute = createRootRoute({
|
|
16
|
+
component: () => (
|
|
17
|
+
<main className="mx-auto max-w-2xl p-6">
|
|
18
|
+
<Outlet />
|
|
19
|
+
</main>
|
|
20
|
+
),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const notesRoute = createRoute({
|
|
24
|
+
getParentRoute: () => rootRoute,
|
|
25
|
+
path: "/",
|
|
26
|
+
component: NotesPage,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const router = createRouter({ routeTree: rootRoute.addChildren([notesRoute]) });
|
|
30
|
+
|
|
31
|
+
declare module "@tanstack/react-router" {
|
|
32
|
+
interface Register {
|
|
33
|
+
router: typeof router;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const root = document.getElementById("root");
|
|
38
|
+
if (root) {
|
|
39
|
+
// One subscription for every page: whatever changes the app (this page,
|
|
40
|
+
// another tab, the API, a task, a deploy), pages read again what it made stale.
|
|
41
|
+
client.subscribe(refetchAfter);
|
|
42
|
+
createRoot(root).render(
|
|
43
|
+
<StrictMode>
|
|
44
|
+
<QueryClientProvider client={queryClient}>
|
|
45
|
+
<RouterProvider router={router} />
|
|
46
|
+
</QueryClientProvider>
|
|
47
|
+
</StrictMode>,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { QueryClientProvider } from "@tanstack/react-query";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { expect, it, vi } from "vitest";
|
|
4
|
+
import type * as server from "../server";
|
|
5
|
+
import { queryClient } from "./app";
|
|
6
|
+
import { NotesPage } from "./notes";
|
|
7
|
+
|
|
8
|
+
/** The runtime the page's client talks to; the test says how it answers. */
|
|
9
|
+
const runtime = vi.hoisted(() => ({ fetch: vi.fn<typeof fetch>() }));
|
|
10
|
+
|
|
11
|
+
// The app's own query cache, with a client that reaches the stand-in runtime.
|
|
12
|
+
vi.mock(import("./app"), async (importOriginal) => {
|
|
13
|
+
const { createClient } = await import("@teable/app/client");
|
|
14
|
+
return {
|
|
15
|
+
...(await importOriginal()),
|
|
16
|
+
client: createClient<typeof server>({ appId: "test", fetch: runtime.fetch }),
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("shows the notes and adds one through addNote", async () => {
|
|
21
|
+
const notes = [{ id: 1, text: "first", createdAt: "2026-12-03T08:00:00.000Z" }];
|
|
22
|
+
runtime.fetch.mockImplementation(async (url, init) => {
|
|
23
|
+
const method = new URL(String(url)).pathname.split("/").pop();
|
|
24
|
+
if (method === "addNote") {
|
|
25
|
+
const { text } = JSON.parse(String(init?.body)) as { text: string };
|
|
26
|
+
notes.unshift({ id: notes.length + 1, text, createdAt: new Date().toISOString() });
|
|
27
|
+
return Response.json(notes[0]);
|
|
28
|
+
}
|
|
29
|
+
return Response.json(notes);
|
|
30
|
+
});
|
|
31
|
+
render(
|
|
32
|
+
<QueryClientProvider client={queryClient}>
|
|
33
|
+
<NotesPage />
|
|
34
|
+
</QueryClientProvider>,
|
|
35
|
+
);
|
|
36
|
+
expect(await screen.findByText("first")).toBeTruthy();
|
|
37
|
+
|
|
38
|
+
fireEvent.change(screen.getByLabelText("New note"), { target: { value: "second" } });
|
|
39
|
+
fireEvent.click(screen.getByRole("button", { name: "Add" }));
|
|
40
|
+
expect(await screen.findByText("second")).toBeTruthy();
|
|
41
|
+
expect(runtime.fetch).toHaveBeenCalledWith(
|
|
42
|
+
expect.stringMatching(/\/apps\/test\/methods\/addNote$/),
|
|
43
|
+
expect.objectContaining({ method: "POST", body: JSON.stringify({ text: "second" }) }),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
5
|
+
import { Input } from "@/components/ui/input";
|
|
6
|
+
import { client, queryClient } from "./app";
|
|
7
|
+
|
|
8
|
+
/** The notes, newest first, and a box to add one. */
|
|
9
|
+
export function NotesPage() {
|
|
10
|
+
const notes = useQuery({
|
|
11
|
+
queryKey: client.queryKey("listNotes"),
|
|
12
|
+
queryFn: () => client.call("listNotes"),
|
|
13
|
+
});
|
|
14
|
+
const [text, setText] = useState("");
|
|
15
|
+
const add = useMutation({
|
|
16
|
+
mutationFn: (text: string) => client.call("addNote", { text }),
|
|
17
|
+
onSuccess: () => {
|
|
18
|
+
setText("");
|
|
19
|
+
return queryClient.invalidateQueries({ queryKey: client.dataKey });
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
// A page with nothing to show says why: the app's refusal, or the network's.
|
|
23
|
+
const error = add.error ?? notes.error;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<section className="space-y-4">
|
|
27
|
+
<h1 className="font-semibold text-xl">Notes</h1>
|
|
28
|
+
<form
|
|
29
|
+
className="flex gap-2"
|
|
30
|
+
onSubmit={(event) => {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
add.mutate(text);
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
<Input
|
|
36
|
+
aria-label="New note"
|
|
37
|
+
value={text}
|
|
38
|
+
onChange={(event) => setText(event.target.value)}
|
|
39
|
+
className="flex-1"
|
|
40
|
+
/>
|
|
41
|
+
<Button type="submit" disabled={text.trim() === "" || add.isPending}>
|
|
42
|
+
Add
|
|
43
|
+
</Button>
|
|
44
|
+
</form>
|
|
45
|
+
{error && (
|
|
46
|
+
<Alert variant="destructive">
|
|
47
|
+
<AlertDescription>{error.message}</AlertDescription>
|
|
48
|
+
</Alert>
|
|
49
|
+
)}
|
|
50
|
+
{notes.data ? (
|
|
51
|
+
<ul className="divide-y divide-border rounded-md border border-border">
|
|
52
|
+
{notes.data.map((note) => (
|
|
53
|
+
<li key={note.id} className="px-3 py-2 text-sm">
|
|
54
|
+
{note.text}
|
|
55
|
+
</li>
|
|
56
|
+
))}
|
|
57
|
+
</ul>
|
|
58
|
+
) : (
|
|
59
|
+
!notes.error && <p className="text-muted-foreground text-sm">Loading…</p>
|
|
60
|
+
)}
|
|
61
|
+
</section>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* shadcn's stylesheet for style ui-sdk-rhea (components on UI SDK, the Rhea
|
|
3
|
+
* preset: base color neutral, Lucide icons, the Inter font), CSS variables,
|
|
4
|
+
* Tailwind v4 (what components.json declares), as
|
|
5
|
+
* `shadcn init --base ui-sdk --preset rhea` writes it: the ui-sdk layer,
|
|
6
|
+
* declared before everything so any class beats the few styles UI SDK adds to
|
|
7
|
+
* it at runtime (hiding closed parts); tw-animate-css (enter and exit
|
|
8
|
+
* animations); shadcn/tailwind.css (the data-open: style variants that popups
|
|
9
|
+
* use); the font; and the tokens. Registry components style themselves with
|
|
10
|
+
* these.
|
|
11
|
+
*
|
|
12
|
+
* From this comment to the end, every Teable template's stylesheet and the
|
|
13
|
+
* builder's are identical, so the builder looks like the apps it builds.
|
|
14
|
+
*/
|
|
15
|
+
@layer ui-sdk;
|
|
16
|
+
|
|
17
|
+
@import "tailwindcss";
|
|
18
|
+
@import "tw-animate-css";
|
|
19
|
+
@import "shadcn/tailwind.css";
|
|
20
|
+
@import "@fontsource-variable/inter";
|
|
21
|
+
|
|
22
|
+
@custom-variant dark (&:is(.dark *));
|
|
23
|
+
|
|
24
|
+
:root {
|
|
25
|
+
--background: oklch(1 0 0);
|
|
26
|
+
--foreground: oklch(0.145 0 0);
|
|
27
|
+
--card: oklch(1 0 0);
|
|
28
|
+
--card-foreground: oklch(0.145 0 0);
|
|
29
|
+
--popover: oklch(1 0 0);
|
|
30
|
+
--popover-foreground: oklch(0.145 0 0);
|
|
31
|
+
--primary: oklch(0.205 0 0);
|
|
32
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
33
|
+
--secondary: oklch(0.97 0 0);
|
|
34
|
+
--secondary-foreground: oklch(0.205 0 0);
|
|
35
|
+
--muted: oklch(0.97 0 0);
|
|
36
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
37
|
+
--accent: oklch(0.97 0 0);
|
|
38
|
+
--accent-foreground: oklch(0.205 0 0);
|
|
39
|
+
--destructive: oklch(0.577 0.245 27.325);
|
|
40
|
+
--border: oklch(0.922 0 0);
|
|
41
|
+
--input: oklch(0.922 0 0);
|
|
42
|
+
--ring: oklch(0.708 0 0);
|
|
43
|
+
--chart-1: oklch(0.87 0 0);
|
|
44
|
+
--chart-2: oklch(0.556 0 0);
|
|
45
|
+
--chart-3: oklch(0.439 0 0);
|
|
46
|
+
--chart-4: oklch(0.371 0 0);
|
|
47
|
+
--chart-5: oklch(0.269 0 0);
|
|
48
|
+
--radius: 0.625rem;
|
|
49
|
+
--sidebar: oklch(0.985 0 0);
|
|
50
|
+
--sidebar-foreground: oklch(0.145 0 0);
|
|
51
|
+
--sidebar-primary: oklch(0.205 0 0);
|
|
52
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
53
|
+
--sidebar-accent: oklch(0.97 0 0);
|
|
54
|
+
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
55
|
+
--sidebar-border: oklch(0.922 0 0);
|
|
56
|
+
--sidebar-ring: oklch(0.708 0 0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.dark {
|
|
60
|
+
--background: oklch(0.145 0 0);
|
|
61
|
+
--foreground: oklch(0.985 0 0);
|
|
62
|
+
--card: oklch(0.205 0 0);
|
|
63
|
+
--card-foreground: oklch(0.985 0 0);
|
|
64
|
+
--popover: oklch(0.205 0 0);
|
|
65
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
66
|
+
--primary: oklch(0.922 0 0);
|
|
67
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
68
|
+
--secondary: oklch(0.269 0 0);
|
|
69
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
70
|
+
--muted: oklch(0.269 0 0);
|
|
71
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
72
|
+
--accent: oklch(0.269 0 0);
|
|
73
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
74
|
+
--destructive: oklch(0.704 0.191 22.216);
|
|
75
|
+
--border: oklch(1 0 0 / 10%);
|
|
76
|
+
--input: oklch(1 0 0 / 15%);
|
|
77
|
+
--ring: oklch(0.556 0 0);
|
|
78
|
+
--chart-1: oklch(0.87 0 0);
|
|
79
|
+
--chart-2: oklch(0.556 0 0);
|
|
80
|
+
--chart-3: oklch(0.439 0 0);
|
|
81
|
+
--chart-4: oklch(0.371 0 0);
|
|
82
|
+
--chart-5: oklch(0.269 0 0);
|
|
83
|
+
--sidebar: oklch(0.205 0 0);
|
|
84
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
85
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
86
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
87
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
88
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
89
|
+
--sidebar-border: oklch(1 0 0 / 10%);
|
|
90
|
+
--sidebar-ring: oklch(0.556 0 0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@theme inline {
|
|
94
|
+
--color-background: var(--background);
|
|
95
|
+
--color-foreground: var(--foreground);
|
|
96
|
+
--color-card: var(--card);
|
|
97
|
+
--color-card-foreground: var(--card-foreground);
|
|
98
|
+
--color-popover: var(--popover);
|
|
99
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
100
|
+
--color-primary: var(--primary);
|
|
101
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
102
|
+
--color-secondary: var(--secondary);
|
|
103
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
104
|
+
--color-muted: var(--muted);
|
|
105
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
106
|
+
--color-accent: var(--accent);
|
|
107
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
108
|
+
--color-destructive: var(--destructive);
|
|
109
|
+
--color-border: var(--border);
|
|
110
|
+
--color-input: var(--input);
|
|
111
|
+
--color-ring: var(--ring);
|
|
112
|
+
--color-chart-1: var(--chart-1);
|
|
113
|
+
--color-chart-2: var(--chart-2);
|
|
114
|
+
--color-chart-3: var(--chart-3);
|
|
115
|
+
--color-chart-4: var(--chart-4);
|
|
116
|
+
--color-chart-5: var(--chart-5);
|
|
117
|
+
--radius-sm: calc(var(--radius) * 0.6);
|
|
118
|
+
--radius-md: calc(var(--radius) * 0.8);
|
|
119
|
+
--radius-lg: var(--radius);
|
|
120
|
+
--radius-xl: calc(var(--radius) * 1.4);
|
|
121
|
+
--radius-2xl: calc(var(--radius) * 1.8);
|
|
122
|
+
--radius-3xl: calc(var(--radius) * 2.2);
|
|
123
|
+
--radius-4xl: calc(var(--radius) * 2.6);
|
|
124
|
+
--color-sidebar: var(--sidebar);
|
|
125
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
126
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
127
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
128
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
129
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
130
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
131
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
132
|
+
--font-heading: var(--font-sans);
|
|
133
|
+
--font-sans: "Inter Variable", sans-serif;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@layer base {
|
|
137
|
+
* {
|
|
138
|
+
@apply border-border outline-ring/50;
|
|
139
|
+
}
|
|
140
|
+
body {
|
|
141
|
+
@apply bg-background text-foreground;
|
|
142
|
+
}
|
|
143
|
+
html {
|
|
144
|
+
@apply font-sans;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { env } from "cloudflare:test";
|
|
2
|
+
import { MethodError } from "@teable/app/client";
|
|
3
|
+
import { testApp } from "@teable/app/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import { addNote, listNotes } from "../src/server";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A new app on an empty database. Before its first call the SDK runs the
|
|
9
|
+
* migrations and checks that the database has what schema.ts declares.
|
|
10
|
+
*/
|
|
11
|
+
const fresh = () => testApp(env.APP.getByName(crypto.randomUUID()));
|
|
12
|
+
|
|
13
|
+
it("keeps notes, newest first", async () => {
|
|
14
|
+
const app = fresh();
|
|
15
|
+
await app.call(addNote, { text: "first" });
|
|
16
|
+
await app.call(addNote, { text: "second" });
|
|
17
|
+
expect((await app.call(listNotes)).map((note) => note.text)).toEqual(["second", "first"]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("refuses a blank note: the CHECK constraint holds that rule", async () => {
|
|
21
|
+
const app = fresh();
|
|
22
|
+
const error = await app.call(addNote, { text: " " }).catch((e: unknown) => e);
|
|
23
|
+
expect(error).toBeInstanceOf(MethodError);
|
|
24
|
+
expect((error as MethodError).error).toEqual({
|
|
25
|
+
code: "CONSTRAINT",
|
|
26
|
+
message: "CHECK constraint failed: note_text_not_blank",
|
|
27
|
+
});
|
|
28
|
+
expect(await app.call(listNotes)).toEqual([]);
|
|
29
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"lib": ["ES2024"],
|
|
5
|
+
"module": "preserve",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"noImplicitOverride": true,
|
|
11
|
+
"noFallthroughCasesInSwitch": true,
|
|
12
|
+
"verbatimModuleSyntax": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"types": []
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"lib": ["ES2024", "DOM", "DOM.Iterable"],
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"types": ["@cloudflare/workers-types", "@cloudflare/vitest-plugin/types", "vite/client"],
|
|
8
|
+
"paths": { "@/*": ["./src/*"] }
|
|
9
|
+
},
|
|
10
|
+
"include": ["src", "test", "drizzle", "drizzle.config.ts", "vite.config.ts"],
|
|
11
|
+
// Checked without the DOM by src/server/tsconfig.json.
|
|
12
|
+
"exclude": ["src/server"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { cloudflareTest } from "@cloudflare/vitest-plugin";
|
|
3
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
4
|
+
import { sqlAsText } from "@teable/app/build";
|
|
5
|
+
import { APP_COMPATIBILITY_DATE } from "@teable/app/protocol";
|
|
6
|
+
import react from "@vitejs/plugin-react";
|
|
7
|
+
import { defineConfig } from "vitest/config";
|
|
8
|
+
|
|
9
|
+
/** Which Teable app this is, as teable.json says; pages call its methods. */
|
|
10
|
+
const { appId = "" } = JSON.parse(
|
|
11
|
+
readFileSync(new URL("./teable.json", import.meta.url), "utf8"),
|
|
12
|
+
) as { appId?: string };
|
|
13
|
+
|
|
14
|
+
/** The app's pages, and its tests. */
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
plugins: [react(), tailwindcss()],
|
|
17
|
+
// `@/` is src/, as tsconfig.json's paths say.
|
|
18
|
+
resolve: { tsconfigPaths: true },
|
|
19
|
+
define: { "import.meta.env.VITE_TEABLE_APP_ID": JSON.stringify(appId) },
|
|
20
|
+
build: { outDir: "dist/pages" },
|
|
21
|
+
test: {
|
|
22
|
+
projects: [
|
|
23
|
+
{
|
|
24
|
+
// The app's methods, run in workerd against real SQLite, with none of
|
|
25
|
+
// the pages' configuration.
|
|
26
|
+
extends: false,
|
|
27
|
+
plugins: [
|
|
28
|
+
sqlAsText(),
|
|
29
|
+
cloudflareTest({
|
|
30
|
+
wrangler: { configPath: "./wrangler.test.jsonc" },
|
|
31
|
+
miniflare: { compatibilityDate: APP_COMPATIBILITY_DATE },
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
test: { name: "server", include: ["test/**/*.test.ts"] },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
// Pages, in jsdom, resolved and compiled as the pages are.
|
|
38
|
+
extends: true,
|
|
39
|
+
test: { name: "web", environment: "jsdom", include: ["src/**/*.test.{ts,tsx}"] },
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
});
|