@teable/create-app 1.0.4 → 1.0.5

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.
@@ -102,7 +102,8 @@ Also:
102
102
  Renaming one or changing its input breaks its callers.
103
103
  - Table names starting with `_teable_` are reserved.
104
104
  - One app is one Durable Object: up to 10 GB, one thread, 128 MB of memory.
105
- Keep each call small, and page through long lists (`limit`).
105
+ Keep each call small, and page through long lists (`cursor` and `limit`,
106
+ as in "Add a read or a write").
106
107
  - Teable has no secrets store for apps yet. Never put keys or tokens in code
107
108
  or git; ask the user.
108
109
  - Pages are for the members of the app's space unless the app says
@@ -142,6 +143,26 @@ export const markPaid = app.write({
142
143
  fail("NOT_FOUND", `No invoice ${input.id}`),
143
144
  });
144
145
 
146
+ export const listInvoices = app.read({
147
+ description: "Invoices, oldest first",
148
+ input: z.object({
149
+ cursor: z.number().int().optional(), // the nextCursor of the page before; none for the first
150
+ limit: z.number().int().min(1).max(200).default(50),
151
+ }),
152
+ output: z.object({ invoices: z.array(schemaOf(invoices)), nextCursor: z.number().nullable() }),
153
+ handler: ({ db, input }) => {
154
+ const rows = db
155
+ .select()
156
+ .from(invoices)
157
+ .where(gt(invoices.id, input.cursor ?? 0))
158
+ .orderBy(invoices.id)
159
+ .limit(input.limit)
160
+ .all();
161
+ const full = rows.length === input.limit; // a shorter page is the last
162
+ return { invoices: rows, nextCursor: full ? (rows.at(-1)?.id ?? null) : null };
163
+ },
164
+ });
165
+
145
166
  export const App = app.define({ listInvoices, markPaid });
146
167
  ```
147
168
 
@@ -152,6 +173,10 @@ export const App = app.define({ listInvoices, markPaid });
152
173
  it from the tables: `schemaOf(table)` for a row (`.pick`, `.omit`,
153
174
  `.extend`), `schemaOf(table.column)` for one value. They carry the column's
154
175
  kind, so callers tell money (and its currency) from a number.
176
+ - A read of a long list returns it a page at a time, as `listInvoices` does:
177
+ it takes an optional `cursor` (and `limit`) and returns its rows in one
178
+ array beside `nextCursor`, the next page's `cursor` (null after the last).
179
+ The builder, and pages with `useInfiniteQuery`, read on from it.
155
180
  - Return plain data: end Drizzle queries with `.all()`, `.get()` or `.run()`.
156
181
  - `fail(code, message)` refuses the call with `BAD_INPUT`, `FORBIDDEN`,
157
182
  `NOT_FOUND` or `CONFLICT`; nothing the write did is kept.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teable/create-app",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Start a Teable app: a blank app, the instructions agents read in it, and the teable-next-app Agent Skill",
5
5
  "license": "MIT",
6
6
  "repository": {