@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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -2
  3. package/bin/create-teable-app.js +103 -0
  4. package/dist/template/AGENTS.md +284 -0
  5. package/dist/template/CLAUDE.md +1 -0
  6. package/dist/template/components.json +27 -0
  7. package/dist/template/drizzle/0000_init.sql +6 -0
  8. package/dist/template/drizzle/meta/0000_snapshot.json +55 -0
  9. package/dist/template/drizzle/meta/_journal.json +13 -0
  10. package/dist/template/drizzle/migrations.js +10 -0
  11. package/dist/template/drizzle.config.ts +8 -0
  12. package/dist/template/gitignore +8 -0
  13. package/dist/template/index.html +12 -0
  14. package/dist/template/package.json +45 -0
  15. package/dist/template/src/components/ui/alert.tsx +72 -0
  16. package/dist/template/src/components/ui/button.tsx +52 -0
  17. package/dist/template/src/components/ui/input.tsx +18 -0
  18. package/dist/template/src/server/index.ts +28 -0
  19. package/dist/template/src/server/schema.ts +13 -0
  20. package/dist/template/src/server/tsconfig.json +10 -0
  21. package/dist/template/src/web/app.ts +35 -0
  22. package/dist/template/src/web/main.tsx +49 -0
  23. package/dist/template/src/web/notes.test.tsx +45 -0
  24. package/dist/template/src/web/notes.tsx +63 -0
  25. package/dist/template/src/web/styles.css +146 -0
  26. package/dist/template/teable.json +1 -0
  27. package/dist/template/test/env.d.ts +10 -0
  28. package/dist/template/test/notes.test.ts +29 -0
  29. package/dist/template/test/worker.ts +5 -0
  30. package/dist/template/tsconfig.base.json +19 -0
  31. package/dist/template/tsconfig.json +13 -0
  32. package/dist/template/vite.config.ts +43 -0
  33. package/dist/template/wrangler.test.jsonc +7 -0
  34. package/package.json +22 -4
  35. package/skill/teable-next-app/SKILL.md +88 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Teable, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @teable/create-app
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Start a Teable app: a Drizzle schema plus read, write and task methods that
4
+ Teable runs with its own SQLite database, with an HTTP API, MCP tools and
5
+ React pages.
6
+
7
+ ```sh
8
+ npx @teable/create-app my-app --app-id <appId> # or: bunx @teable/create-app, npm init @teable/app
9
+ cd my-app && bun install && bun run check
10
+ ```
11
+
12
+ `create-teable-app <dir> [--app-id <id>]` writes a blank app into `<dir>`,
13
+ which must be absent or empty (a lone `.git` is fine), and `teable.json`
14
+ naming the app on Teable; without `--app-id` it names none. The app's
15
+ `AGENTS.md` (read by Claude Code through `CLAUDE.md`, and by other agents)
16
+ holds its rules, commands and how to publish it with `teable app publish`.
17
+ It needs [Bun](https://bun.sh).
18
+
19
+ ## The Agent Skill
20
+
21
+ `skill/teable-next-app/SKILL.md` tells an agent when to build a Teable app,
22
+ how to start one or pick one up, and the loop from edit to publish. Copy the
23
+ directory where your agent reads skills, for Claude Code
24
+ `~/.claude/skills/teable-next-app/`.
25
+
26
+ ## Where it comes from
27
+
28
+ The scaffold is `templates/blank` of the teable-next repository, copied when
29
+ this package is packed, with the versions of `@teable/app` and the other
30
+ packages it was released with. The repository typechecks, tests and builds
31
+ that template like any app, and this package's tests install, check and build
32
+ a scaffolded app outside the repository.
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+ /**
4
+ * create-teable-app <dir> [--app-id <id>]
5
+ *
6
+ * Writes a blank Teable app into <dir>: the scaffold this package carries
7
+ * (templates/blank of the teable-next repository, with the versions it was
8
+ * released with) and teable.json, which names the app on Teable. <dir> must
9
+ * be absent or empty; a lone .git is fine, so a fresh repository can take it.
10
+ *
11
+ * npx runs this with Node from node_modules, where Node runs no TypeScript,
12
+ * so it is JavaScript, and it imports only Node's own modules: nothing to
13
+ * install, and Bun runs it too.
14
+ */
15
+ import {
16
+ cpSync,
17
+ existsSync,
18
+ readdirSync,
19
+ readFileSync,
20
+ renameSync,
21
+ statSync,
22
+ writeFileSync,
23
+ } from "node:fs";
24
+ import { basename, join, relative, resolve } from "node:path";
25
+ import { fileURLToPath } from "node:url";
26
+ import { parseArgs } from "node:util";
27
+
28
+ const USAGE = "usage: create-teable-app <dir> [--app-id <id>]";
29
+ const TEMPLATE = fileURLToPath(new URL("../dist/template", import.meta.url));
30
+
31
+ /**
32
+ * @param {string} message
33
+ * @returns {never}
34
+ */
35
+ function fail(message) {
36
+ console.error(`${message}\n${USAGE}`);
37
+ process.exit(1);
38
+ }
39
+
40
+ /** @param {string[]} argv */
41
+ function parse(argv) {
42
+ try {
43
+ return parseArgs({
44
+ args: argv,
45
+ options: { "app-id": { type: "string" }, help: { type: "boolean", short: "h" } },
46
+ allowPositionals: true,
47
+ });
48
+ } catch (error) {
49
+ return fail(error instanceof Error ? error.message : String(error));
50
+ }
51
+ }
52
+
53
+ /** Absent, or a directory holding nothing but perhaps .git. @param {string} dir */
54
+ function isEmpty(dir) {
55
+ if (!existsSync(dir)) return true;
56
+ return statSync(dir).isDirectory() && readdirSync(dir).every((entry) => entry === ".git");
57
+ }
58
+
59
+ /** An npm package name from the directory's name. @param {string} dir */
60
+ function packageName(dir) {
61
+ const name = basename(dir)
62
+ .toLowerCase()
63
+ .replace(/[^a-z0-9._~-]+/g, "-")
64
+ .replace(/^[._-]+|-+$/g, "");
65
+ return name || "teable-app";
66
+ }
67
+
68
+ const { values, positionals } = parse(process.argv.slice(2));
69
+ if (values.help) {
70
+ console.log(USAGE);
71
+ process.exit(0);
72
+ }
73
+ const [target, ...extra] = positionals;
74
+ if (target === undefined) fail("Name the directory to create the app in.");
75
+ if (extra.length > 0) fail(`One directory only; also got: ${extra.join(" ")}`);
76
+ const appId = values["app-id"];
77
+ if (appId !== undefined && appId.trim() === "") fail("--app-id needs the app's id.");
78
+ if (!existsSync(TEMPLATE)) fail(`No scaffold at ${TEMPLATE}: this package was packed without it.`);
79
+
80
+ const dir = resolve(target);
81
+ if (!isEmpty(dir)) fail(`${dir} exists and is not an empty directory.`);
82
+
83
+ cpSync(TEMPLATE, dir, { recursive: true });
84
+ renameSync(join(dir, "gitignore"), join(dir, ".gitignore"));
85
+ const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
86
+ writeFileSync(
87
+ join(dir, "package.json"),
88
+ `${JSON.stringify({ ...pkg, name: packageName(dir) }, null, 2)}\n`,
89
+ );
90
+ writeFileSync(join(dir, "teable.json"), `${JSON.stringify(appId ? { appId } : {}, null, 2)}\n`);
91
+
92
+ const where = relative(process.cwd(), dir) || ".";
93
+ /** The path as a shell takes it. */
94
+ const shell = /^[\w@%+=:,./-]+$/.test(where) ? where : `'${where.replaceAll("'", "'\\''")}'`;
95
+ console.log(`Created a Teable app in ${where}.
96
+
97
+ cd ${shell}
98
+ bun install
99
+ bun run check
100
+
101
+ AGENTS.md has the rules, the commands and how to publish.`);
102
+ if (appId === undefined)
103
+ console.log("teable.json names no app yet: add its appId before publishing.");
@@ -0,0 +1,284 @@
1
+ # Teable app
2
+
3
+ This repository is one Teable app: a Drizzle schema plus read, write and task
4
+ methods, written with `@teable/app`. Teable runs it on Cloudflare in a Durable
5
+ Object with its own SQLite database, and makes an HTTP API and MCP tools from
6
+ its methods. Change it here, run the checks, and publish it with
7
+ `teable app publish`.
8
+
9
+ It starts as an example (a `notes` table, `listNotes`, `addNote`, a page, a
10
+ test at each level) that shows the whole shape. Replace it with the app the
11
+ user needs.
12
+
13
+ ## Layout
14
+
15
+ | Path | What it is |
16
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------------------- |
17
+ | `src/server/schema.ts` | Tables, with their rules (Drizzle). drizzle-kit loads it in Node: it imports only `drizzle-orm` and `@teable/app/schema`. |
18
+ | `src/server/index.ts` | Methods. `export const App = app.define({ ... })` names them; Teable runs this module. |
19
+ | `drizzle/` | Migrations written by `bun run db:generate`, and `migrations.js`, which lists them. |
20
+ | `src/web/` | Pages: React, TanStack Router and Query, shadcn's components. `app.ts` holds the client and the query cache. |
21
+ | `src/components/ui/` | shadcn's components on UI SDK, as `bunx shadcn add <name>` writes them (`components.json`); the app's own. |
22
+ | `test/` | Method tests. They run in workerd, against a real SQLite database. |
23
+ | `src/**/*.test.tsx` | Page tests, in jsdom, against a stubbed client. |
24
+ | `teable.json` | `appId`: which app on Teable this is. The `teable` CLI and the pages read it; leave it as it is. |
25
+ | `dist/` | What `bun run build` writes: `server.js`, which publishing uploads, and `pages/`. Not committed. |
26
+
27
+ ## Commands
28
+
29
+ ```sh
30
+ bun install
31
+ bun run check # typecheck, tests, migration checks; before every push
32
+ bun run build # dist/server.js (what publish uploads) and dist/pages/
33
+ bun run db:generate --name <change> # after changing schema.ts: the next migration
34
+ bun run test [file] [-t <name>] # tests only, or some of them
35
+ teable app push -m "<what changed>" # commit, and save the source to Teable
36
+ teable app publish # deploy dist/server.js, with its commit, as the next version
37
+ teable app versions # published versions, newest first: when, by whom, which commit
38
+ teable app rollback --version <n> # deploy version n's code again, as the next version
39
+ ```
40
+
41
+ `teable app <command> --help` lists every option. There is no local server
42
+ (`dev`): the runtime that hosts apps is not published. Tests are the loop:
43
+ methods against a real database, pages against a stubbed client. Publish to
44
+ see the app running.
45
+
46
+ ## The rules, and why
47
+
48
+ 1. **Data is touched only through the app's methods.** Pages, the API, MCP
49
+ tools, tasks and other apps all call methods; there is no other way into
50
+ the database. Why: the database exists only inside the app's Durable
51
+ Object, and every change is recorded with the call that made it (realtime
52
+ updates, history). SQLite triggers refuse a row change made outside a
53
+ write method.
54
+ 2. **Read and write handlers are synchronous; anything that waits is a
55
+ task.** No `async`, `await` or `fetch` in a read or a write. Why: a write
56
+ runs in one SQLite transaction, so its rows and the tasks it enqueues
57
+ commit or roll back together, and a read runs in one that fails if
58
+ anything was written. A transaction cannot wait on the network without
59
+ stopping the whole app. Returning a Promise is a type error and fails at
60
+ runtime.
61
+ 3. **Rules SQLite can enforce live in SQLite:** `.notNull()`, `check()`,
62
+ `.unique()`, `.references()`, generated columns, triggers. Methods hold
63
+ the rest. Why: a constraint holds for every write, including methods
64
+ written later, table edits and tasks; a check in one method holds only
65
+ there. A method may check first to give a readable message
66
+ (`fail("CONFLICT", "...")`); the constraint stays as the guarantee.
67
+ 4. **Migrations are append-only.** Never edit, delete, rename or reorder a
68
+ migration that a published version contained; change the schema with a
69
+ new one. Why: the live database has run them, and the SDK refuses to start
70
+ code whose migrations were edited, removed, or dated before ones already
71
+ applied, so publishing fails. Before the first publish nothing has run
72
+ anywhere: replace the example and generate `drizzle/` again (delete it,
73
+ then `bun run db:generate --name init`). In a cloned app, treat every
74
+ migration as published.
75
+ 5. **Capabilities are declared.** The app has no network and no platform
76
+ services except those it lists in `createApp`, as
77
+ `capabilities: ["files", "http"]`. Why: Teable wires in only what is
78
+ declared and shows the list to the people who run the app. Using one that
79
+ is not declared fails with a message that says how to declare it.
80
+
81
+ Also:
82
+
83
+ - Pages import server code with `import type` only, so no server code
84
+ (Drizzle, zod, `cloudflare:` modules) reaches the browser.
85
+ - Server code runs in workerd: Web APIs, no `node:` modules, no DOM.
86
+ `src/server/tsconfig.json` checks it without the DOM.
87
+ - Method results are JSON: Dates arrive as ISO strings; bigint and binary
88
+ columns are refused.
89
+ - Method names and inputs are the app's public API (HTTP, MCP, pages).
90
+ Renaming one or changing its input breaks its callers.
91
+ - Table names starting with `_teable_` are reserved.
92
+ - One app is one Durable Object: up to 10 GB, one thread, 128 MB of memory.
93
+ Keep each call small, and page through long lists (`limit`).
94
+ - Teable has no secrets store for apps yet. Never put keys or tokens in code
95
+ or git; ask the user.
96
+
97
+ ## How to
98
+
99
+ ### Add a table
100
+
101
+ 1. Declare it in `src/server/schema.ts` and export it, with its rules on it.
102
+ `col` from `@teable/app/schema` adds kinds SQLite cannot express:
103
+ `col.money({ currency })` (an integer in minor units), `col.user()`,
104
+ `col.attachments()`.
105
+ 2. `bun run db:generate --name <change>` writes `drizzle/NNNN_<change>.sql`
106
+ and its snapshot, and adds it to `drizzle/migrations.js`. Read the SQL;
107
+ commit all of it.
108
+ 3. A new NOT NULL column on a table that has rows needs `.default(...)`, or
109
+ the migration fails on live data.
110
+ 4. For SQL drizzle-kit does not write (triggers, backfills),
111
+ `bun run db:generate --custom --name <change>` makes an empty migration.
112
+ drizzle-kit changes most columns by rebuilding the table, which drops the
113
+ table's triggers: create them again in that same migration. The SDK
114
+ refuses a migration that loses one.
115
+
116
+ ### Add a read or a write
117
+
118
+ ```ts
119
+ export const markPaid = app.write({
120
+ description: "Mark an invoice paid", // shown in the API and to MCP clients
121
+ input: z.object({ id: z.number().int() }), // z from @teable/app
122
+ output: schemaOf(invoices), // what callers get; schemaOf from @teable/app/schema
123
+ access: "editor", // reads default to viewer, writes to editor
124
+ handler: ({ db, input }) =>
125
+ db.update(invoices).set({ paid: true }).where(eq(invoices.id, input.id)).returning().get() ??
126
+ fail("NOT_FOUND", `No invoice ${input.id}`),
127
+ });
128
+
129
+ export const App = app.define({ listInvoices, markPaid });
130
+ ```
131
+
132
+ - Its key in `define()` is its name in the API, MCP and pages.
133
+ - `output` says what it returns. Callers get what it outputs (keys it does
134
+ not declare are dropped); the API's response body, the MCP tool's output
135
+ schema and the builder's view come from it, and pages are typed by it. Build
136
+ it from the tables: `schemaOf(table)` for a row (`.pick`, `.omit`,
137
+ `.extend`), `schemaOf(table.column)` for one value. They carry the column's
138
+ kind, so callers tell money (and its currency) from a number.
139
+ - Return plain data: end Drizzle queries with `.all()`, `.get()` or `.run()`.
140
+ - `fail(code, message)` refuses the call with `BAD_INPUT`, `FORBIDDEN`,
141
+ `NOT_FOUND` or `CONFLICT`; nothing the write did is kept.
142
+ - `access`: the least space role that may call it (`viewer`, `commenter`,
143
+ `editor`, `creator`, `owner`), `public` (anyone, signed in or not) or
144
+ `internal` (only the app's own tasks). Finer rules check `caller` in the
145
+ handler.
146
+ - Inputs arrive as JSON. Take a date as `z.iso.datetime()` or
147
+ `z.coerce.date()`, never `z.date()`.
148
+ - Add a test in `test/`.
149
+
150
+ ### Add a page
151
+
152
+ 1. Write it in `src/web/<page>.tsx`. Read with
153
+ `useQuery({ queryKey: client.queryKey("listInvoices", input), queryFn: () => client.call("listInvoices", input) })`;
154
+ write with `useMutation`, then
155
+ `queryClient.invalidateQueries({ queryKey: client.dataKey })`. Names,
156
+ inputs and results are typed from `App`; tasks and internal methods are
157
+ not callable.
158
+ 2. Add its route in `src/web/main.tsx` (`createRoute`, then
159
+ `rootRoute.addChildren`).
160
+ 3. Build it from shadcn's components on UI SDK (style `ui-sdk-rhea`), as the
161
+ notes page does with `Button`, `Input` and `Alert`:
162
+ `bunx shadcn add <name>` writes one to `src/components/ui/`. Before using
163
+ one, read `node_modules/@ui-sdk/react/docs/llms.txt` and the component's
164
+ page next to it (`docs/components/<name>.md`), which match the installed
165
+ version; UI SDK's guide for agents is
166
+ `node_modules/@ui-sdk/core/skills/ui-sdk/SKILL.md`. Never hand-roll what
167
+ it ships: a `role="listbox"`, `"menu"` or `"dialog"` is a component to
168
+ add. UI SDK needs no providers, takes `render={<Button />}` where Radix
169
+ took `asChild`, and renders popups in place, in the top layer (no portals,
170
+ no `z-50`).
171
+ 4. Lay it out with Tailwind classes on shadcn's tokens (`bg-primary`,
172
+ `text-muted-foreground`, `border-border`, `text-destructive`); they are in
173
+ `styles.css`, whose first rule stays `@layer ui-sdk;`. Write the text in
174
+ the user's language.
175
+ 5. Test it next to it (`<page>.test.tsx`), with a client whose `fetch` the
176
+ test answers, as `notes.test.tsx` does.
177
+
178
+ ### Add a task or a schedule
179
+
180
+ ```ts
181
+ export const sendReminder = app.task({
182
+ input: z.object({ id: z.number().int() }),
183
+ handler: async ({ input, call, http }) => {
184
+ const invoice = await call(getInvoice, input); // data only through methods
185
+ await http.fetch("https://...", { method: "POST", body: JSON.stringify(invoice) });
186
+ await call(markReminded, input); // a write; access "internal" keeps it to tasks
187
+ },
188
+ });
189
+
190
+ // In a write: runs after the write commits, and not at all if it fails.
191
+ enqueue(sendReminder, { id }, { delayMs: 60 * 60_000 });
192
+
193
+ // On a schedule; its input must accept {}.
194
+ export const dailyDigest = app.task({
195
+ schedule: { cron: "0 9 * * *", timezone: "Asia/Shanghai" },
196
+ handler: async ({ call }) => {
197
+ await call(recordDigest, {});
198
+ },
199
+ });
200
+ ```
201
+
202
+ - Register tasks in `define()` too. They run outside transactions and are
203
+ never exposed.
204
+ - A failed run is retried after 1 s, 2 s, 4 s and so on, up to an hour
205
+ apart, until `maxAttempts` (8 by default): make tasks idempotent.
206
+ - A schedule missed while the app slept runs once, not once per missed time.
207
+ - Test with `await app.runTasks()`; `app.runTasks(until)` moves the clock.
208
+
209
+ ### Use a capability
210
+
211
+ Declare it in `createApp`, then use it in tasks, from their context:
212
+
213
+ - `files`: `files.put({ name, type, data })` stores a file and returns an
214
+ `Attachment` to keep in a `col.attachments()` column through a write;
215
+ `files.get(key)`; `files.share(key, { expiresInSeconds })` makes a link
216
+ anyone can open. Pages upload with `client.upload(file)` (editors, up to
217
+ 100 MB) and read with `client.fileUrl(attachment)`. Inputs that take files
218
+ validate them with `z.array(attachment)` from `@teable/app/schema`.
219
+ - `http`: the app's own `fetch()` reaches other services, so npm SDKs work
220
+ as they are; `http.fetch` is the same. Only tasks can wait for an answer.
221
+ Teable meters every request and refuses its own hosts.
222
+
223
+ These two are all there is; an app cannot add another.
224
+
225
+ ### Test
226
+
227
+ ```ts
228
+ const app = testApp(env.APP.getByName(crypto.randomUUID())); // new app, empty database
229
+ await app.call(addNote, { text: "hi" }); // as an owner, through JSON, as callers get it
230
+ await app.as({ kind: "user", userId: "u2", role: "viewer", via: "web" }).call(listNotes);
231
+ await app.runTasks(); // run due tasks, and the tasks they enqueue
232
+ await app.changes(); // the changefeed: every row change, with its call
233
+ ```
234
+
235
+ A refused call throws `MethodError` (`error.code`, `error.message`,
236
+ `status`). Before its first call, a new app runs the migrations and checks
237
+ that the database has what `schema.ts` declares, so every test also checks
238
+ the migrations.
239
+
240
+ ## When something fails
241
+
242
+ | You see | Do |
243
+ | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
244
+ | `read and write handlers must be synchronous` (type error), or `returned a Promise` | Take `async`/`await` out of the handler; move the waiting into a task the write enqueues. |
245
+ | `returned what its output schema refuses, at <path>` | The handler returned what `output` does not accept (a missing key, a null, another type): fix one or the other. |
246
+ | `returned a ... at result ... Did you forget .get() or .all()?` | End the query with `.all()`, `.get()` or `.run()`. |
247
+ | `Read method "..." wrote data` | Make it a write. |
248
+ | `The database does not match schema.ts` | `schema.ts` changed without a migration: `bun run db:generate`. |
249
+ | `Migration ... removed trigger ...` | Create the trigger again in that migration, after the rebuild. |
250
+ | `Migration ... drops table ..., and dropping a table deletes its rows first` | Do what the message says: change the reference to `NO ACTION` or `RESTRICT` in a migration of its own first. |
251
+ | `Migration ... changed after it was applied`, or `was applied but is missing` | A published migration was edited or deleted. Restore it from git, and make the change in a new migration. |
252
+ | `Migration ... is older than the latest applied migration` | It was generated before one that is already live: delete it (its `.sql`, snapshot and entries) and generate it again. |
253
+ | `CONSTRAINT`: `CHECK constraint failed: <name>`, `UNIQUE ...`, `NOT NULL ...`, `FOREIGN KEY ...` | A rule in SQLite refused the input; the rule works. For a readable message, check first in the method and `fail(...)`. Never drop a constraint to make a call pass. |
254
+ | `BAD_INPUT`: `Input does not match the method's schema` | `issues` names the fields that failed the input's zod schema. |
255
+ | `Declare capabilities: [...] in createApp`, or `not permitted to access the internet` | Declare the capability; use it in a task. |
256
+ | `must export the class from define() as "App"` (build) | `export const App = app.define({ ... })` in `src/server/index.ts`. |
257
+ | `Stripping types is currently unsupported for files under node_modules` | Vite or Vitest ran on Node; run them through `bun run test` and `bun run build`. |
258
+ | `FORBIDDEN` from `teable app publish` or `rollback` | Publishing takes the `creator` or `owner` role in the app's space; ask the user. |
259
+ | `CONFLICT` from `teable app rollback` | That version lacks a migration the live database has run: roll forward with a new version instead. |
260
+ | `RATE_LIMITED` (HTTP 429) | Wait as long as `Retry-After` says, then try again. |
261
+ | `Deploy rejected: built for app protocol N; this runtime speaks M` (publish) | `bun add @teable/app@latest`, then check, build and publish again. |
262
+ | `Deploy rejected` with `Migration ... failed: ...` (publish) | The migration does not fit the live rows (a NOT NULL column without a default, a CHECK some rows break): make it handle them (a default, an `UPDATE` first). A rejected migration never ran: edit it. |
263
+
264
+ ## Publishing
265
+
266
+ Once `bun run check` and `bun run build` pass, push and publish:
267
+ `teable app push -m "<what changed>"`, then `teable app publish`. Do not wait
268
+ to be asked: publishing is how the user gets the change, and a publish that
269
+ fails changes nothing. It takes the `creator` or `owner` role in the app's
270
+ space. Teable starts the new version on a copy of the live data first,
271
+ running its migrations, then on the live data, and makes it live only if both
272
+ work; open pages read everything again. Every version records when it was
273
+ published, by whom, and from which commit. Then tell the user what changed.
274
+ The methods are live at once through the API
275
+ (`/api/v4/apps/<appId>/methods/<name>`, described at `.../openapi.json`), MCP
276
+ (`/api/v4/apps/<appId>/mcp`) and the app on Teable; Teable does not serve
277
+ `dist/pages` yet.
278
+
279
+ `teable app rollback` deploys an earlier version's code again, as the next
280
+ version. It cannot go back past a migration: the live database has run it,
281
+ and code without it does not start, so the rollback is refused (`CONFLICT`);
282
+ undo a schema change with a new migration. A rollback changes only what
283
+ runs, not this repository: fix or revert the code here before publishing
284
+ again, or the next publish brings it back.
@@ -0,0 +1 @@
1
+ @AGENTS.md
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "ui-sdk-rhea",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "",
8
+ "css": "src/web/styles.css",
9
+ "baseColor": "neutral",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "iconLibrary": "lucide",
14
+ "rtl": false,
15
+ "aliases": {
16
+ "components": "@/components",
17
+ "utils": "@/lib/utils",
18
+ "ui": "@/components/ui",
19
+ "lib": "@/lib",
20
+ "hooks": "@/hooks"
21
+ },
22
+ "menuColor": "default",
23
+ "menuAccent": "subtle",
24
+ "registries": {
25
+ "@teable": "https://teable.ai/r/{name}.json"
26
+ }
27
+ }
@@ -0,0 +1,6 @@
1
+ CREATE TABLE `notes` (
2
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
3
+ `text` text NOT NULL,
4
+ `createdAt` integer DEFAULT (unixepoch() * 1000) NOT NULL,
5
+ CONSTRAINT "note_text_not_blank" CHECK(trim("notes"."text") <> '')
6
+ );
@@ -0,0 +1,55 @@
1
+ {
2
+ "version": "6",
3
+ "dialect": "sqlite",
4
+ "id": "38b2accd-10fa-4dee-b111-417bcba3e7ed",
5
+ "prevId": "00000000-0000-0000-0000-000000000000",
6
+ "tables": {
7
+ "notes": {
8
+ "name": "notes",
9
+ "columns": {
10
+ "id": {
11
+ "name": "id",
12
+ "type": "integer",
13
+ "primaryKey": true,
14
+ "notNull": true,
15
+ "autoincrement": true
16
+ },
17
+ "text": {
18
+ "name": "text",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true,
22
+ "autoincrement": false
23
+ },
24
+ "createdAt": {
25
+ "name": "createdAt",
26
+ "type": "integer",
27
+ "primaryKey": false,
28
+ "notNull": true,
29
+ "autoincrement": false,
30
+ "default": "(unixepoch() * 1000)"
31
+ }
32
+ },
33
+ "indexes": {},
34
+ "foreignKeys": {},
35
+ "compositePrimaryKeys": {},
36
+ "uniqueConstraints": {},
37
+ "checkConstraints": {
38
+ "note_text_not_blank": {
39
+ "name": "note_text_not_blank",
40
+ "value": "trim(\"notes\".\"text\") <> ''"
41
+ }
42
+ }
43
+ }
44
+ },
45
+ "views": {},
46
+ "enums": {},
47
+ "_meta": {
48
+ "schemas": {},
49
+ "tables": {},
50
+ "columns": {}
51
+ },
52
+ "internal": {
53
+ "indexes": {}
54
+ }
55
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "sqlite",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "6",
8
+ "when": 1796289550119,
9
+ "tag": "0000_init",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,10 @@
1
+ import journal from './meta/_journal.json';
2
+ import m0000 from './0000_init.sql';
3
+
4
+ export default {
5
+ journal,
6
+ migrations: {
7
+ m0000
8
+ }
9
+ }
10
+
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "drizzle-kit";
2
+
3
+ export default defineConfig({
4
+ dialect: "sqlite",
5
+ driver: "durable-sqlite",
6
+ schema: "./src/server/schema.ts",
7
+ out: "./drizzle",
8
+ });
@@ -0,0 +1,8 @@
1
+ node_modules/
2
+ dist/
3
+ .wrangler/
4
+ .dev.vars
5
+ .env
6
+ .env.*
7
+ *.log
8
+ .DS_Store
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Notes</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/src/web/main.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@teable/template-blank",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "check": "bun run typecheck && bun run test && drizzle-kit check",
8
+ "build": "teable-app build && vite build",
9
+ "db:generate": "drizzle-kit generate",
10
+ "typecheck": "tsc -p . && tsc -p src/server",
11
+ "test": "vitest run"
12
+ },
13
+ "dependencies": {
14
+ "@fontsource-variable/inter": "5.3.0",
15
+ "@tanstack/react-query": "5.108.4",
16
+ "@tanstack/react-router": "1.170.46",
17
+ "@teable/app": "^5.0.1",
18
+ "@ui-sdk/core": "0.1.0-beta.24",
19
+ "@ui-sdk/react": "0.1.0-beta.24",
20
+ "class-variance-authority": "0.7.1",
21
+ "cn": "0.5.2",
22
+ "drizzle-orm": "0.45.4",
23
+ "lucide-react": "1.87.0",
24
+ "react": "19.3.1",
25
+ "react-dom": "19.3.1"
26
+ },
27
+ "devDependencies": {
28
+ "@cloudflare/vitest-plugin": "1.10.2",
29
+ "@cloudflare/workers-types": "5.20261201.1",
30
+ "@tailwindcss/vite": "4.3.5",
31
+ "@testing-library/react": "16.3.3",
32
+ "@types/node": "26.6.11",
33
+ "@types/react": "19.3.3",
34
+ "@types/react-dom": "19.3.0",
35
+ "@vitejs/plugin-react": "6.3.1",
36
+ "drizzle-kit": "0.31.11",
37
+ "jsdom": "31.0.1",
38
+ "shadcn": "4.24.0",
39
+ "tailwindcss": "4.3.5",
40
+ "tw-animate-css": "1.4.0",
41
+ "typescript": "7.0.2",
42
+ "vite": "8.4.1",
43
+ "vitest": "5.1.2"
44
+ }
45
+ }