@quickback-dev/cli 0.66.21 → 0.66.22
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/dist/index.js +1 -1
- package/dist/lib/migrations/drizzle-prompts.d.ts +2 -0
- package/dist/lib/migrations/drizzle-prompts.d.ts.map +1 -1
- package/dist/lib/migrations/drizzle-prompts.js +11 -0
- package/dist/lib/migrations/drizzle-prompts.js.map +1 -1
- package/dist/lib/migrations/file-envelopes.d.ts.map +1 -1
- package/dist/lib/migrations/file-envelopes.js +21 -51
- package/dist/lib/migrations/file-envelopes.js.map +1 -1
- package/dist/lib/migrations/prompt-runner.d.ts.map +1 -1
- package/dist/lib/migrations/prompt-runner.js +6 -1
- package/dist/lib/migrations/prompt-runner.js.map +1 -1
- package/dist/skill/docs/api/actions.md +13 -6
- package/dist/skill/docs/api/batch-operations.md +6 -2
- package/dist/skill/docs/api/crud.md +72 -9
- package/dist/skill/docs/api/errors.md +78 -6
- package/dist/skill/docs/api/openapi.md +1 -1
- package/dist/skill/docs/api/query-params.md +6 -7
- package/dist/skill/docs/api/typescript.md +193 -0
- package/dist/skill/docs/configure/index.md +36 -2
- package/dist/skill/docs/configure/providers.md +32 -7
- package/dist/skill/docs/define/changesets.md +2 -0
- package/dist/skill/docs/define/guards.md +7 -2
- package/dist/skill/docs/define/masking.md +14 -0
- package/dist/skill/docs/define/read.md +3 -0
- package/dist/skill/docs/define/schema.md +13 -10
- package/dist/skill/docs/define/transitions.md +9 -4
- package/dist/skill/docs/index.md +1 -0
- package/dist/skill/docs/platform/auth/plugins/agent-auth.md +1 -1
- package/dist/skill/docs/platform/payments/index.md +1 -1
- package/dist/skill/docs/start/frontend.md +278 -0
- package/dist/skill/docs/start/index.md +1 -0
- package/dist/skill/docs/tooling/cloud-compiler/troubleshooting.md +6 -0
- package/dist/skill/docs/tooling/output.md +38 -9
- package/dist/skill/docs/tooling/troubleshooting.md +67 -0
- package/dist/skill/docs/ui/admin/actions.md +6 -2
- package/dist/skill/docs/ui/admin/index.md +1 -1
- package/dist/skill/docs/ui/admin/inline-editing.md +6 -2
- package/dist/skill/docs/ui/admin/schema-format.md +74 -36
- package/dist/skill/docs/ui/admin/schema-registry.md +22 -9
- package/dist/skill/docs/ui/admin/security.md +2 -2
- package/dist/skill/docs/ui/components/action-dialog.md +62 -0
- package/dist/skill/docs/ui/components/auth.md +90 -0
- package/dist/skill/docs/ui/components/index.md +48 -0
- package/dist/skill/docs/ui/components/install.md +118 -0
- package/dist/skill/docs/ui/components/quickback-provider.md +123 -0
- package/dist/skill/docs/ui/components/resource-form.md +80 -0
- package/dist/skill/docs/ui/components/resource-table.md +46 -0
- package/package.json +1 -1
- package/src/skill/docs/api/actions.md +13 -6
- package/src/skill/docs/api/batch-operations.md +6 -2
- package/src/skill/docs/api/crud.md +72 -9
- package/src/skill/docs/api/errors.md +78 -6
- package/src/skill/docs/api/openapi.md +1 -1
- package/src/skill/docs/api/query-params.md +6 -7
- package/src/skill/docs/api/typescript.md +193 -0
- package/src/skill/docs/configure/index.md +36 -2
- package/src/skill/docs/configure/providers.md +32 -7
- package/src/skill/docs/define/changesets.md +2 -0
- package/src/skill/docs/define/guards.md +7 -2
- package/src/skill/docs/define/masking.md +14 -0
- package/src/skill/docs/define/read.md +3 -0
- package/src/skill/docs/define/schema.md +13 -10
- package/src/skill/docs/define/transitions.md +9 -4
- package/src/skill/docs/index.md +1 -0
- package/src/skill/docs/platform/auth/plugins/agent-auth.md +1 -1
- package/src/skill/docs/platform/payments/index.md +1 -1
- package/src/skill/docs/start/frontend.md +278 -0
- package/src/skill/docs/start/index.md +1 -0
- package/src/skill/docs/tooling/cloud-compiler/troubleshooting.md +6 -0
- package/src/skill/docs/tooling/output.md +38 -9
- package/src/skill/docs/tooling/troubleshooting.md +67 -0
- package/src/skill/docs/ui/admin/actions.md +6 -2
- package/src/skill/docs/ui/admin/index.md +1 -1
- package/src/skill/docs/ui/admin/inline-editing.md +6 -2
- package/src/skill/docs/ui/admin/schema-format.md +74 -36
- package/src/skill/docs/ui/admin/schema-registry.md +22 -9
- package/src/skill/docs/ui/admin/security.md +2 -2
- package/src/skill/docs/ui/components/action-dialog.md +62 -0
- package/src/skill/docs/ui/components/auth.md +90 -0
- package/src/skill/docs/ui/components/index.md +48 -0
- package/src/skill/docs/ui/components/install.md +118 -0
- package/src/skill/docs/ui/components/quickback-provider.md +123 -0
- package/src/skill/docs/ui/components/resource-form.md +80 -0
- package/src/skill/docs/ui/components/resource-table.md +46 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# quickback-provider
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npx shadcn add @quickback/quickback-provider
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Installs `components/quickback-provider.tsx` and `@tanstack/react-query@^5`.
|
|
8
|
+
The other items import their hooks from it.
|
|
9
|
+
|
|
10
|
+
## `<QuickbackProvider>`
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { createClient } from "@/lib/quickback.client"
|
|
14
|
+
import { QuickbackProvider } from "@/components/quickback-provider"
|
|
15
|
+
|
|
16
|
+
const client = createClient({ baseUrl: "https://api.example.com" })
|
|
17
|
+
|
|
18
|
+
<QuickbackProvider client={client} roles={roles}>
|
|
19
|
+
<App />
|
|
20
|
+
</QuickbackProvider>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
| Prop | Type | Description |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `client` | `Client` | The result of `createClient()` from the emitted `@/lib/quickback.client`. Required. |
|
|
26
|
+
| `roles` | `readonly string[]` | The signed-in caller's roles, e.g. the active organization member role from Better Auth. A UI hint only. See [Roles](#roles). |
|
|
27
|
+
| `realtime` | `{ subscribe(handler) => unsubscribe }` | Source of realtime frames for `useLive`. Defaults to `client.realtime` when the emitted client has one. |
|
|
28
|
+
| `queryClient` | `QueryClient` | Share your app's TanStack Query cache. Omit it and the provider creates one that retries network errors and `5xx` twice and never retries a `4xx`. |
|
|
29
|
+
| `children` | `ReactNode` | |
|
|
30
|
+
|
|
31
|
+
## Hooks
|
|
32
|
+
|
|
33
|
+
Every hook takes a **schema-registry table name** (`"jobs"`). The name is
|
|
34
|
+
resolved through the client's `resources` table, so generic UI never
|
|
35
|
+
hard-codes a URL. An unknown name throws `Unknown Quickback resource "<name>"`.
|
|
36
|
+
Calling a verb the table has no route for throws `"<table>" has no <verb> route`.
|
|
37
|
+
|
|
38
|
+
| Hook | Returns | Notes |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `useQuickback()` | `Client` | The typed client. Use it for anything the hooks don't cover. |
|
|
41
|
+
| `useRoles()` | `readonly string[] \| undefined` | The `roles` passed to the provider. |
|
|
42
|
+
| `useSchema()` | query of `SchemaRegistry` | `GET /api/v1/schema`. Cached for the session. |
|
|
43
|
+
| `useTableMeta(table)` | `TableMeta \| undefined` | One table from the registry. `undefined` while the registry loads. |
|
|
44
|
+
| `useOps(table)` | `string[]` | The operations that have a route (`list`, `get`, `create`, …). |
|
|
45
|
+
| `useList(table, params?)` | query of `{ data, pagination }` | `params` takes [list params](/api/query-params), plus `view` to read a named view and `enabled`. Keeps the previous page while the next one loads. |
|
|
46
|
+
| `useInfiniteList(table, params?)` | infinite query | Pages with the keyset cursor (`nextCursor` → `startingAfter`). Falls back to offset when the server returns no cursor, for example when sorting on a masked column. |
|
|
47
|
+
| `useRecord(table, id)` | query of the record | Disabled while `id` is `undefined`. |
|
|
48
|
+
| `useCreate(table)` | mutation `(body) => row` | |
|
|
49
|
+
| `useUpdate(table)` | mutation `({ id, body }) => row` | |
|
|
50
|
+
| `useDelete(table)` | mutation `(id) => void` | |
|
|
51
|
+
| `useAction(table, action)` | mutation `({ id?, params?, input }) => output` | Record-bound actions need `id`. Standalone actions with path parameters need `params`. |
|
|
52
|
+
| `useLive(table, enabled = true)` | `boolean` | Refetches the table when a `postgres_changes` frame for it arrives. Returns whether a realtime source is wired up. |
|
|
53
|
+
| `useDebouncedValue(value, ms = 250)` | `T` | `value`, updated only after it stops changing for `ms`. |
|
|
54
|
+
|
|
55
|
+
Every mutation invalidates all of the table's cached queries.
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { useList, useUpdate } from "@/components/quickback-provider"
|
|
59
|
+
|
|
60
|
+
function OpenJobs() {
|
|
61
|
+
const jobs = useList("jobs", { filter: { status: "open" }, sort: "-createdAt", limit: 10 })
|
|
62
|
+
const update = useUpdate("jobs")
|
|
63
|
+
if (jobs.isPending) return <p>Loading…</p>
|
|
64
|
+
return jobs.data?.data.map((job) => (
|
|
65
|
+
<button key={String(job.id)} onClick={() => update.mutate({ id: String(job.id), body: { status: "closed" } })}>
|
|
66
|
+
Close {String(job.title)}
|
|
67
|
+
</button>
|
|
68
|
+
))
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The hooks are deliberately untyped by name (`Row = Record<string, unknown>`),
|
|
73
|
+
because they serve generic UI. For typed rows, call the client directly:
|
|
74
|
+
`useQuickback().jobs.list()` returns `Api.jobs.Row[]`.
|
|
75
|
+
|
|
76
|
+
## Roles
|
|
77
|
+
|
|
78
|
+
The emitted client has no session method, so the provider only knows the
|
|
79
|
+
caller's roles if you pass them. Read the role from your auth client:
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
const member = auth.useActiveMember() // better-auth organizationClient()
|
|
83
|
+
<QuickbackProvider client={client} roles={member.data ? [member.data.role] : undefined}>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Roles are a **UI hint**. The API stays authoritative:
|
|
87
|
+
|
|
88
|
+
- **Masking.** A [masked](/define/masking) column is read-only unless the
|
|
89
|
+
roles satisfy its `show` rule. With no `roles`, every masked column is
|
|
90
|
+
read-only. A value that arrives masked (`[REDACTED]`, `j***@…`) is always
|
|
91
|
+
read-only.
|
|
92
|
+
- **Access.** When the roles plainly fail an operation's `access.roles`,
|
|
93
|
+
the form's Delete button is hidden and the action dialog shows a role
|
|
94
|
+
message instead of its form. The client can't decide hierarchy
|
|
95
|
+
(`member+`), `record`, or FGA rules, so those controls stay available and
|
|
96
|
+
the API answers.
|
|
97
|
+
|
|
98
|
+
## Realtime
|
|
99
|
+
|
|
100
|
+
`useLive(table)` refetches the table on its change frames. `ResourceTable`
|
|
101
|
+
calls it unless `live={false}`. The frames come from `client.realtime` when
|
|
102
|
+
the emitted client has one, which it does when the project enables
|
|
103
|
+
[realtime](/api/typescript#realtime). Otherwise pass any
|
|
104
|
+
`{ subscribe(handler) => unsubscribe }` source as `realtime`. See
|
|
105
|
+
[Using Realtime](/platform/realtime/using-realtime) for the ticket and
|
|
106
|
+
WebSocket handshake.
|
|
107
|
+
|
|
108
|
+
## Helpers
|
|
109
|
+
|
|
110
|
+
The other items use these, and you can too:
|
|
111
|
+
|
|
112
|
+
| Export | Description |
|
|
113
|
+
|---|---|
|
|
114
|
+
| `describeError(error)` | `{ message, fields, status? }`. `message` is the problem's `detail`, then its `title`, then `error.message`. `fields` maps field names to messages, from [`QuickbackError.fields`](/api/typescript#fetch-client). |
|
|
115
|
+
| `isMasked(meta, column, roles, value?)` | Whether the column may reach these roles masked. |
|
|
116
|
+
| `canAccess(access, roles)` | Best-effort role check. Returns `true` for rules the client can't decide. |
|
|
117
|
+
| `canWrite(meta, op, roles)` | `canAccess` for `create` / `update` / `delete` from the registry. |
|
|
118
|
+
| `getDisplayColumn(tableMeta)` | The column that names a record: the table's `displayColumn`, else the first of `name`, `title`, `label`, … |
|
|
119
|
+
| `formatLabel(name)` / `columnLabel(name, col?)` | `salaryMin` → `Salary Min`. An FK column reads as its target: `companyId` → `Company`. |
|
|
120
|
+
| `REDACTED` | `"[REDACTED]"`, the value the API sends in place of a redacted value. |
|
|
121
|
+
|
|
122
|
+
Types: `TableMeta`, `ColumnMeta`, `ActionMeta` (all derived from the emitted
|
|
123
|
+
`SchemaRegistry`), `Row`, `Page`, `RealtimeSource`, and `RealtimeFrame`.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# resource-form
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npx shadcn add @quickback/resource-form
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { ResourceForm } from "@/components/resource-form"
|
|
9
|
+
|
|
10
|
+
// Create
|
|
11
|
+
<ResourceForm table="jobs" onSuccess={(row) => navigate(`/jobs/${row.id}`)} />
|
|
12
|
+
|
|
13
|
+
// Edit, with a confirmed Delete
|
|
14
|
+
<ResourceForm table="jobs" id={jobId} onSuccess={close} onCancel={close} onDeleted={close} />
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Props
|
|
18
|
+
|
|
19
|
+
| Prop | Type | Description |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `table` | `string` | Schema-registry table name. Required. |
|
|
22
|
+
| `id` | `string` | Record id. Set it to edit that record (the form loads it first). Leave it out to create a new one. |
|
|
23
|
+
| `onSuccess` | `(row) => void` | Called with the saved record. The API's bare record, not an envelope. |
|
|
24
|
+
| `onCancel` | `() => void` | Shows a Cancel button when set. |
|
|
25
|
+
| `onDeleted` | `(id) => void` | Edit mode. Shows a Delete button that asks for confirmation inline, then calls this. See [Delete](#delete) for when the button is hidden. |
|
|
26
|
+
|
|
27
|
+
## Which fields appear
|
|
28
|
+
|
|
29
|
+
The form shows exactly the fields the API accepts:
|
|
30
|
+
|
|
31
|
+
- **Create** shows [`guards.createable`](/define/guards). **Edit** shows
|
|
32
|
+
`guards.updatable`.
|
|
33
|
+
- These fields are read-only, with persistent helper text saying why:
|
|
34
|
+
`guards.immutable` fields on edit, `guards.protected` fields ("Updated via
|
|
35
|
+
actions only"), and masked fields the caller's [roles](/ui/components/quickback-provider#roles)
|
|
36
|
+
can't see unmasked.
|
|
37
|
+
- The form needs the table's `create` (create mode) or `update` (edit mode)
|
|
38
|
+
route. Without it, submitting fails with `"<table>" has no create route`.
|
|
39
|
+
|
|
40
|
+
## Controls
|
|
41
|
+
|
|
42
|
+
| Column | Control |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `inputHints` entry `textarea` / `richtext` | Textarea |
|
|
45
|
+
| Enum validation | Select of the allowed values |
|
|
46
|
+
| FK (`.references()`) | Searchable combobox over the target table (see below) |
|
|
47
|
+
| `bool` | Checkbox |
|
|
48
|
+
| `timestamp` / `date` | Date-time / date input |
|
|
49
|
+
| `decimal` | Text input. `q.decimal()` is an exact decimal string, and a number input would round it. |
|
|
50
|
+
| `json` or array | Textarea (JSON) |
|
|
51
|
+
| `int`, `bigint`, `smallint`, `real` | Number input, with `min` / `max` from validation |
|
|
52
|
+
| `url` | URL input |
|
|
53
|
+
| `email` validation | Email input |
|
|
54
|
+
| anything else | Text input |
|
|
55
|
+
|
|
56
|
+
Constraints show as persistent helper text under the field
|
|
57
|
+
(`Up to 200 characters · Optional`), never as placeholder text.
|
|
58
|
+
|
|
59
|
+
**FK lookups** query the target table as you type (`?search=`, debounced)
|
|
60
|
+
and load more rows by cursor on demand, so there is no first-page cap. When
|
|
61
|
+
the target declares named views, it must set `read.defaultView`. Without it
|
|
62
|
+
the field is disabled with `<Target> needs read.defaultView to be looked up`.
|
|
63
|
+
|
|
64
|
+
## Validation and errors
|
|
65
|
+
|
|
66
|
+
- **Before submit**, the form checks the registry's `validation` block:
|
|
67
|
+
required (NOT NULL without a default on create, NOT NULL on edit),
|
|
68
|
+
`minLength` / `maxLength`, `min` / `max`, whole numbers for integer
|
|
69
|
+
columns, enum membership, URL, email, and `pattern`.
|
|
70
|
+
- **On submit**, create sends every non-blank value. Edit sends only the
|
|
71
|
+
fields you changed. A field you cleared is sent as `null`, which clears
|
|
72
|
+
it. It is never sent as `""`.
|
|
73
|
+
- **Server errors** show the problem's `detail` above the form. Per-field
|
|
74
|
+
messages from `QuickbackError.fields` are shown under their fields.
|
|
75
|
+
|
|
76
|
+
## Delete
|
|
77
|
+
|
|
78
|
+
The Delete button renders only when **all** of these hold: `onDeleted` is
|
|
79
|
+
set, the table has a `delete` route, and the caller's roles don't plainly
|
|
80
|
+
fail its `access.roles`. It asks for confirmation before calling the API.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# resource-table
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npx shadcn add @quickback/resource-table
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { ResourceTable } from "@/components/resource-table"
|
|
9
|
+
|
|
10
|
+
<ResourceTable
|
|
11
|
+
table="jobs"
|
|
12
|
+
onRowClick={(row) => navigate(`/jobs/${row.id}`)}
|
|
13
|
+
rowActions={(row) => <CloseJobButton id={String(row.id)} />}
|
|
14
|
+
/>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Props
|
|
18
|
+
|
|
19
|
+
| Prop | Type | Default | Description |
|
|
20
|
+
|---|---|---|---|
|
|
21
|
+
| `table` | `string` | required | Schema-registry table name. |
|
|
22
|
+
| `view` | `string` | — | Read through a named [view](/define/views). Omit it to read the collection route, which serves `read.defaultView` when the table sets one. |
|
|
23
|
+
| `columns` | `string[]` | every non-system column | Columns visible at first. Users toggle the rest from the column menu. |
|
|
24
|
+
| `pageSize` | `number` | `25` | Sent as `limit`. The server caps it at the table's `maxPageSize`. |
|
|
25
|
+
| `onRowClick` | `(row) => void` | — | Makes rows clickable. |
|
|
26
|
+
| `rowActions` | `(row) => ReactNode` | — | Renders a trailing cell per row, e.g. edit or action buttons. |
|
|
27
|
+
| `live` | `boolean` | `true` | Refetch on realtime change frames for this table (see [Realtime](/ui/components/quickback-provider#realtime)). Has no effect without a realtime source. |
|
|
28
|
+
| `className` | `string` | — | |
|
|
29
|
+
|
|
30
|
+
## Behavior
|
|
31
|
+
|
|
32
|
+
- **Columns** come from the view's declared `fields` when it has them, else
|
|
33
|
+
from the schema. The primary key, the tenant scope, and audit bookkeeping
|
|
34
|
+
(`createdBy`, `modifiedAt`, `modifiedBy`, `deletedAt`, `deletedBy`) start
|
|
35
|
+
hidden.
|
|
36
|
+
- **Pagination** uses the keyset cursor (`startingAfter` / `endingBefore`). It
|
|
37
|
+
falls back to offset when the server returns no cursor, for example when
|
|
38
|
+
sorting on a masked column.
|
|
39
|
+
- **Search** is debounced and sent as `?search=`. The box is hidden when the
|
|
40
|
+
view's `query.searchable` is empty, since the server would answer `400`.
|
|
41
|
+
- **Sorting** is by column header, sent as `?sort=`. The first load uses the
|
|
42
|
+
table's `defaultSort`.
|
|
43
|
+
- **States.** Loading, empty (`No records yet`, or `No records match "…"`),
|
|
44
|
+
and error with a retry button. The error shows the problem's `detail`.
|
|
45
|
+
- **Masked fields** render exactly what the API returns (`[REDACTED]`,
|
|
46
|
+
`***-**-1234`). The table can't see past [masking](/define/masking).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quickback-dev/cli",
|
|
3
|
-
"version": "0.66.
|
|
3
|
+
"version": "0.66.22",
|
|
4
4
|
"description": "CLI for Quickback — define your backend in TypeScript, compile to a fully wired Cloudflare Worker (or Bun / Node) with auth, database, migrations, security, CMS, and Account UI.",
|
|
5
5
|
"author": "Kardoe Incorporated <paul@kardoe.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -471,24 +471,31 @@ await db.update(applications).set({ deletedAt: now, modifiedAt: now })
|
|
|
471
471
|
|
|
472
472
|
### Validation Error Response
|
|
473
473
|
|
|
474
|
+
Every action error is `application/problem+json` (see [Errors](/api/errors)).
|
|
475
|
+
An input that fails the action's schema:
|
|
476
|
+
|
|
474
477
|
```json
|
|
475
478
|
{
|
|
476
|
-
"
|
|
479
|
+
"type": "https://quickback.dev/problems/validation-error",
|
|
480
|
+
"title": "Validation error",
|
|
481
|
+
"status": 400,
|
|
482
|
+
"code": "VALIDATION_ERROR",
|
|
483
|
+
"detail": "Request body validation failed.",
|
|
484
|
+
"instance": "/api/v1/invoices/inv_123/refund",
|
|
477
485
|
"layer": "validation",
|
|
478
|
-
"code": "VALIDATION_FAILED",
|
|
479
486
|
"details": {
|
|
480
487
|
"fields": {
|
|
481
|
-
"amount": "
|
|
488
|
+
"amount": "Too small: expected number to be >0"
|
|
482
489
|
}
|
|
483
490
|
},
|
|
484
|
-
"
|
|
491
|
+
"pointer": "/amount"
|
|
485
492
|
}
|
|
486
493
|
```
|
|
487
494
|
|
|
488
495
|
### Error Handling
|
|
489
496
|
|
|
490
|
-
**Throw an `ActionError`.** The route handler catches it by name and returns
|
|
491
|
-
|
|
497
|
+
**Throw an `ActionError`.** The route handler catches it by name and returns a
|
|
498
|
+
problem+json body carrying your `code` and `details`, with your `statusCode`:
|
|
492
499
|
|
|
493
500
|
```typescript
|
|
494
501
|
import { ActionError } from "@quickback/compiler";
|
|
@@ -61,8 +61,12 @@ server-minted ids as usual.
|
|
|
61
61
|
"error": "Duplicate value",
|
|
62
62
|
"layer": "database",
|
|
63
63
|
"code": "DB_UNIQUE_VIOLATION",
|
|
64
|
-
"details": {
|
|
65
|
-
|
|
64
|
+
"details": {
|
|
65
|
+
"column": "jobId",
|
|
66
|
+
"columns": ["jobId", "candidateId"],
|
|
67
|
+
"fields": { "jobId": "Already taken", "candidateId": "Already taken" }
|
|
68
|
+
},
|
|
69
|
+
"hint": "A record with this \"jobId\" + \"candidateId\" already exists"
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
],
|
|
@@ -134,10 +134,61 @@ Single-record reads run a role-only access check **before** the firewall query,
|
|
|
134
134
|
|
|
135
135
|
| Status | Description |
|
|
136
136
|
|--------|-------------|
|
|
137
|
+
| `400` | `:id` isn't shaped like this table's ids (`INVALID_ID`) — see [Malformed ids](#malformed-ids-400-invalid_id) |
|
|
137
138
|
| `401` | Not authenticated |
|
|
138
139
|
| `403` | Authenticated but role doesn't satisfy `read.access` — **or** the role passes and the firewall excluded the record (`FIREWALL_NOT_FOUND`). This is the default: `firewallErrorMode` is `'reveal'`. |
|
|
139
140
|
| `404` | Same firewall miss, but on a resource that sets [`firewallErrorMode: 'hide'`](/define/firewall) to make an out-of-scope row indistinguishable from a nonexistent one. |
|
|
140
141
|
|
|
142
|
+
### Malformed ids (`400 INVALID_ID`)
|
|
143
|
+
|
|
144
|
+
Every record route — `GET`, `PATCH` (plain and [changeset](/define/changesets)),
|
|
145
|
+
`PUT`, `DELETE /:id`, and record actions at `/:id/<action>` — checks `:id`
|
|
146
|
+
against the table's id format and answers `400 INVALID_ID` before any database
|
|
147
|
+
work. A client gets "that's not an id" instead of a 403/404 that reads like a
|
|
148
|
+
missing row, and garbage never costs a round-trip.
|
|
149
|
+
|
|
150
|
+
The check runs **after** the auth gate (a `401` still wins) and **before** the
|
|
151
|
+
role-only access pre-check. That ordering adds nothing to the ID-probe channel
|
|
152
|
+
above: the verdict is a function of the URL string alone — identical whether or
|
|
153
|
+
not any row exists, in any tenant — and the id format is public (it is in every
|
|
154
|
+
id the API returns). Every well-formed id still goes through the pre-check and
|
|
155
|
+
the firewall exactly as before.
|
|
156
|
+
|
|
157
|
+
The accepted shape is everything the compiler could have minted for the table,
|
|
158
|
+
not just what it mints today:
|
|
159
|
+
|
|
160
|
+
| Id column / `generateId` | `:id` accepts |
|
|
161
|
+
|--------------------------|---------------|
|
|
162
|
+
| unset (the default) | UUID **or** anything `"prefixed"` accepts — before the default became `"uuid"`, unset projects minted prefixed ids, and those rows stay addressable. See [Upgrading](/configure/providers#id-generation-options) |
|
|
163
|
+
| `"uuid"` | UUID (any case) |
|
|
164
|
+
| `"cuid"` | cuid / cuid2 (lowercase letter + 1–31 lowercase alphanumerics) **or** UUID — schema auto-injection has backed `createId()` with `crypto.randomUUID()`, so existing rows can be UUIDs |
|
|
165
|
+
| `"nanoid"` | 21 URL-safe characters |
|
|
166
|
+
| `"short"` | 6 alphanumerics |
|
|
167
|
+
| `"prefixed"` | optional alphanumeric `<prefix>_` + 32 hex (dashes allowed) — **any** prefix, since it derives from the table name and a rename leaves old rows on the old one |
|
|
168
|
+
| `serial` / `bigserial` / `smallserial` column | positive integer (any integer under `generateId: false`) |
|
|
169
|
+
| other integer column | integer |
|
|
170
|
+
| Postgres `uuid` column | UUID, whatever the strategy |
|
|
171
|
+
|
|
172
|
+
Every id a client may supply on create (`allowClientIds`, below) passes this
|
|
173
|
+
check, so a created id is always addressable.
|
|
174
|
+
|
|
175
|
+
**Never checked** — the compiler can't know the format:
|
|
176
|
+
|
|
177
|
+
- `generateId: false` (ids are any client-supplied string — this is also the
|
|
178
|
+
only mode with `PUT /:id` upsert, so upsert ids are never rejected);
|
|
179
|
+
- an id column with an **authored** default (anything other than the
|
|
180
|
+
strategy's own `$defaultFn`), or a non-`id` primary key;
|
|
181
|
+
- other column types (`varchar`, `real`, …).
|
|
182
|
+
|
|
183
|
+
> The check trusts that every row's id has the current strategy's shape. That
|
|
184
|
+
> stops being true when `generateId` changed after rows were written, data was
|
|
185
|
+
> imported with foreign ids, or an action `db.insert`s a hand-made id. Those rows
|
|
186
|
+
> answer **400 instead of the row** — they become unreachable through `/:id`. Set
|
|
187
|
+
> [`validateIdParams: false`](/configure/providers#database-options) on the
|
|
188
|
+
> database config for such a project; routes then read `:id` as a plain string
|
|
189
|
+
> again (numeric primary keys keep their integer check).
|
|
190
|
+
|
|
191
|
+
|
|
141
192
|
### FK Label Resolution
|
|
142
193
|
|
|
143
194
|
Foreign key columns are automatically enriched with `_label` fields containing the referenced table's display value. The name is the FK column with a trailing `Id` stripped, plus `_label` — so `departmentId` gets `department_label`. Enrichment only happens when the referenced table declares a display column. See [Display Column](/define/schema#display-column) for details.
|
|
@@ -157,7 +208,10 @@ Content-Type: application/json
|
|
|
157
208
|
}
|
|
158
209
|
```
|
|
159
210
|
|
|
160
|
-
Creates a new record.
|
|
211
|
+
Creates a new record. With `guards`, only fields in `guards.createable` or
|
|
212
|
+
`guards.immutable` are accepted. Without `guards`, every column except the
|
|
213
|
+
primary key, audit columns, and firewall/scope columns is accepted. Either way,
|
|
214
|
+
a client-supplied `id` is accepted where the project takes one (see below).
|
|
161
215
|
Required columns (`.required()` with no default) must be present; nullable
|
|
162
216
|
columns may be omitted or sent as `null`. An empty string is **not** a blank —
|
|
163
217
|
`""` is validated like any other value (so it fails `q.url()`, `q.enum()`, and
|
|
@@ -197,12 +251,15 @@ client-generated and server-generated ids are indistinguishable in the table:
|
|
|
197
251
|
|
|
198
252
|
| `generateId` | Accepted shape | Client mints with |
|
|
199
253
|
|--------------|----------------|-------------------|
|
|
200
|
-
| `"uuid"` | UUID | `crypto.randomUUID()` |
|
|
254
|
+
| unset (the default) or `"uuid"` | UUID | `crypto.randomUUID()` |
|
|
201
255
|
| `"prefixed"` | `<prefix>_` + 32 hex chars (e.g. `job_550e8400…`) | `` `${prefix}_${crypto.randomUUID().replaceAll('-', '')}` `` |
|
|
202
256
|
| `"cuid"` | 24-char cuid2 | `createId()` from `@paralleldrive/cuid2` |
|
|
203
257
|
| `"nanoid"` | 21-char nanoid | `nanoid()` |
|
|
204
258
|
| `"short"` | 6 alphanumerics | matching `customAlphabet` call |
|
|
205
259
|
|
|
260
|
+
The server mints the same shape on every path: `POST /`, `POST /batch`, and
|
|
261
|
+
the schema default that an action's `db.insert()` falls back on.
|
|
262
|
+
|
|
206
263
|
What breaks, and how:
|
|
207
264
|
|
|
208
265
|
- A malformed id is a `400 VALIDATION_ERROR` at the Zod boundary.
|
|
@@ -216,8 +273,11 @@ What breaks, and how:
|
|
|
216
273
|
keys (the database owns the id).
|
|
217
274
|
|
|
218
275
|
Guards do not apply to the id: it is compiler-managed, so it does not need to
|
|
219
|
-
appear in `guards.createable`.
|
|
220
|
-
|
|
276
|
+
appear in `guards.createable`. The same rule holds under `generateId: false`,
|
|
277
|
+
where the id is **required** on `POST /`, `POST /batch` and a changeset
|
|
278
|
+
`POST` (root and owned-child inserts): guards check every other field, never
|
|
279
|
+
the id. `PUT /:id` and `PATCH` are unchanged — the id still comes from the
|
|
280
|
+
URL, never the body.
|
|
221
281
|
|
|
222
282
|
### Response
|
|
223
283
|
|
|
@@ -256,7 +316,9 @@ Content-Type: application/json
|
|
|
256
316
|
}
|
|
257
317
|
```
|
|
258
318
|
|
|
259
|
-
Updates an existing record.
|
|
319
|
+
Updates an existing record. With `guards`, only fields in `guards.updatable`
|
|
320
|
+
are accepted. Without `guards`, every column except the primary key, audit
|
|
321
|
+
columns, and firewall/scope columns is accepted.
|
|
260
322
|
Omit a key to leave that column untouched; send `null` to clear a nullable
|
|
261
323
|
column. `null` on a `.required()` column is a `400` — the DB would reject the
|
|
262
324
|
write, so the API does first.
|
|
@@ -279,7 +341,7 @@ patched ones) — there is no `data` wrapper:
|
|
|
279
341
|
|
|
280
342
|
| Status | Description |
|
|
281
343
|
|--------|-------------|
|
|
282
|
-
| `400` | Invalid field or field not updatable |
|
|
344
|
+
| `400` | Invalid field or field not updatable, or a malformed `:id` ([`INVALID_ID`](#malformed-ids-400-invalid_id)) |
|
|
283
345
|
| `403` | User lacks permission to update this record, or the firewall excluded it (default `firewallErrorMode: 'reveal'`) |
|
|
284
346
|
| `404` | Record excluded by the firewall when the resource sets `firewallErrorMode: 'hide'` |
|
|
285
347
|
| `412` | `If-Match` revision mismatch |
|
|
@@ -319,6 +381,7 @@ returned, in either mode:
|
|
|
319
381
|
|
|
320
382
|
| Status | Description |
|
|
321
383
|
|--------|-------------|
|
|
384
|
+
| `400` | Malformed `:id` ([`INVALID_ID`](#malformed-ids-400-invalid_id)) |
|
|
322
385
|
| `403` | User lacks permission to delete this record, or the firewall excluded it (default `firewallErrorMode: 'reveal'`) |
|
|
323
386
|
| `404` | Record excluded by the firewall when the resource sets `firewallErrorMode: 'hide'` |
|
|
324
387
|
| `412` | `If-Match` revision mismatch |
|
|
@@ -402,7 +465,7 @@ Creates multiple records in a single request. Each record follows the same valid
|
|
|
402
465
|
"error": "Field cannot be set during creation",
|
|
403
466
|
"layer": "guards",
|
|
404
467
|
"code": "GUARD_FIELD_NOT_CREATEABLE",
|
|
405
|
-
"details": { "fields":
|
|
468
|
+
"details": { "fields": { "status": "cannot be set on create" } }
|
|
406
469
|
}
|
|
407
470
|
}
|
|
408
471
|
],
|
|
@@ -634,7 +697,7 @@ By default, batch operations use **partial success** mode:
|
|
|
634
697
|
"error": "Human-readable message",
|
|
635
698
|
"layer": "guards",
|
|
636
699
|
"code": "GUARD_FIELD_NOT_CREATEABLE",
|
|
637
|
-
"details": { "fields":
|
|
700
|
+
"details": { "fields": { "status": "cannot be set on create" } },
|
|
638
701
|
"hint": "These fields are set automatically or must be omitted"
|
|
639
702
|
}
|
|
640
703
|
}
|
|
@@ -688,7 +751,7 @@ On the first failure under `failFast: true`:
|
|
|
688
751
|
"details": {
|
|
689
752
|
"failedAt": 2,
|
|
690
753
|
"reason": "Field cannot be set during creation",
|
|
691
|
-
"errorDetails": { "fields":
|
|
754
|
+
"errorDetails": { "fields": { "status": "cannot be set on create" } }
|
|
692
755
|
},
|
|
693
756
|
"hint": "Records before index 2 were applied and are NOT rolled back. Inspect application state before retrying — re-sending the same batch may double-apply records that already succeeded."
|
|
694
757
|
}
|
|
@@ -9,7 +9,7 @@ The generated API returns structured error responses with consistent fields acro
|
|
|
9
9
|
| `200` | OK | Successful GET, PATCH, DELETE |
|
|
10
10
|
| `201` | Created | Successful POST |
|
|
11
11
|
| `207` | Multi-Status | Batch operation with mixed results |
|
|
12
|
-
| `400` | Bad Request | Guard violation, validation error, invalid input |
|
|
12
|
+
| `400` | Bad Request | Guard violation, validation error, invalid input, malformed record id (`INVALID_ID`) |
|
|
13
13
|
| `401` | Unauthorized | Missing or expired authentication |
|
|
14
14
|
| `403` | Forbidden | Access denied (wrong role, condition failed) or firewall blocked it |
|
|
15
15
|
| `404` | Not Found | Firewall blocked the record on a resource that set `firewallErrorMode: 'hide'` (or the route doesn't exist) |
|
|
@@ -66,7 +66,7 @@ enough to triage or hand the response to an LLM agent without grepping logs:
|
|
|
66
66
|
| `layer` | string | Extension — security layer that rejected the request |
|
|
67
67
|
| `code` | string | Extension — machine-readable error code (the full enum ships in `openapi.json` as `Problem.code`) |
|
|
68
68
|
| `details` | object | Extension — layer-specific context (optional) |
|
|
69
|
-
| `pointer` | string | Extension — first
|
|
69
|
+
| `pointer` | string | Extension — first key of `details.fields` for guard and validation failures, e.g. `/stage` (optional) |
|
|
70
70
|
| `hint` | string | Extension — actionable guidance for resolution (optional) |
|
|
71
71
|
| `request` | object | Extension — method, URL, redacted body, and request ID. Auto-attached by the runtime so the error body is self-contained — bodies are capped at 4 KB and well-known sensitive keys (`password`, `token`, `secret`, `apiKey`, `otp`, `code`, `authorization`, …) plus every credential field the compiler itself introduces (`sessionToken`, `eventSessionToken`, `scopeJwt`, `scopeToken`, `wsTicket`, `inviteToken`, `jwt`, `signature`, …) are replaced with `"[REDACTED]"` |
|
|
72
72
|
|
|
@@ -197,13 +197,16 @@ Guard violations return **400 Bad Request** when the request body contains field
|
|
|
197
197
|
"layer": "guards",
|
|
198
198
|
"code": "GUARD_FIELD_NOT_CREATEABLE",
|
|
199
199
|
"details": {
|
|
200
|
-
"fields":
|
|
200
|
+
"fields": { "stage": "cannot be set on create" }
|
|
201
201
|
},
|
|
202
202
|
"pointer": "/stage",
|
|
203
203
|
"hint": "These fields are set automatically or must be omitted"
|
|
204
204
|
}
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
+
`GUARD_FIELD_PROTECTED` also carries `details.actions` — the actions that may
|
|
208
|
+
change the field.
|
|
209
|
+
|
|
207
210
|
**Error codes:**
|
|
208
211
|
|
|
209
212
|
| Code | Description |
|
|
@@ -214,6 +217,67 @@ Guard violations return **400 Bad Request** when the request body contains field
|
|
|
214
217
|
| `GUARD_FIELD_IMMUTABLE` | Field cannot be modified after creation |
|
|
215
218
|
| `GUARD_SYSTEM_MANAGED` | System field (createdAt, modifiedAt, etc.) |
|
|
216
219
|
|
|
220
|
+
### Malformed record id (400)
|
|
221
|
+
|
|
222
|
+
Record routes (`GET`/`PATCH`/`PUT`/`DELETE /:id`, the changeset `PATCH`, and
|
|
223
|
+
record actions at `/:id/<action>`) check `:id` against the table's id format
|
|
224
|
+
and answer **400** before any database work when it can't be an id — a UUID
|
|
225
|
+
route given `job_123`, a serial route given `abc`:
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"type": "https://quickback.dev/problems/invalid-id",
|
|
230
|
+
"title": "Invalid id",
|
|
231
|
+
"status": 400,
|
|
232
|
+
"detail": "Malformed \"id\" path parameter",
|
|
233
|
+
"layer": "validation",
|
|
234
|
+
"code": "INVALID_ID",
|
|
235
|
+
"details": { "param": "id", "expected": "a UUID" },
|
|
236
|
+
"hint": "\"id\" must be a UUID. No record was looked up."
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
| Code | Description |
|
|
241
|
+
|------|-------------|
|
|
242
|
+
| `INVALID_ID` | `:id` isn't shaped like the table's ids — see [Malformed ids](/api/crud#malformed-ids-400-invalid_id) for the per-strategy shapes, what is never checked, and the `validateIdParams: false` opt-out |
|
|
243
|
+
|
|
244
|
+
It is its own code, not a `VALIDATION_*` one: those describe the request
|
|
245
|
+
*body*, and carry a JSON pointer into it. A bad path segment has no pointer,
|
|
246
|
+
and "that's not an id" (400) versus "no such row" (403/404) is the
|
|
247
|
+
distinction a client wants to branch on.
|
|
248
|
+
|
|
249
|
+
### Validation (400)
|
|
250
|
+
|
|
251
|
+
A body that fails the column or action-input schema returns **400** with
|
|
252
|
+
`layer: "validation"`: `VALIDATION_ERROR` for CRUD bodies,
|
|
253
|
+
`VALIDATION_INVALID_INPUT` for action input and query parameters (which also
|
|
254
|
+
carries the raw Zod `details.issues`), `VALIDATION_FAILED` inside a changeset.
|
|
255
|
+
`details.fields` maps each offending field to its message; an unknown key is
|
|
256
|
+
reported under its own name:
|
|
257
|
+
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"detail": "Invalid input",
|
|
261
|
+
"layer": "validation",
|
|
262
|
+
"code": "VALIDATION_INVALID_INPUT",
|
|
263
|
+
"details": {
|
|
264
|
+
"issues": [ … ],
|
|
265
|
+
"fields": { "name": "Required", "status": "Unrecognized field" }
|
|
266
|
+
},
|
|
267
|
+
"pointer": "/name"
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Field errors — one shape
|
|
272
|
+
|
|
273
|
+
`details.fields` has **one** shape on every layer that names fields — guards,
|
|
274
|
+
body and action-input validation, `FK_NOT_FOUND`: an object mapping the field
|
|
275
|
+
name (a dotted path for nested input) to a human-readable message. A form can
|
|
276
|
+
render each message under its input without knowing which layer rejected the
|
|
277
|
+
request; the generated client exposes it as
|
|
278
|
+
[`QuickbackError.fields`](/api/typescript#fetch-client). `pointer` names the
|
|
279
|
+
first entry.
|
|
280
|
+
|
|
217
281
|
### Masking
|
|
218
282
|
|
|
219
283
|
Masking doesn't produce errors — it silently transforms field values in the response.
|
|
@@ -227,11 +291,19 @@ Surfaced when a SQL write fails *post-validation* — most often a `NOT NULL` or
|
|
|
227
291
|
"detail": "Duplicate value",
|
|
228
292
|
"layer": "database",
|
|
229
293
|
"code": "DB_UNIQUE_VIOLATION",
|
|
230
|
-
"details": {
|
|
231
|
-
|
|
294
|
+
"details": {
|
|
295
|
+
"column": "organizationId",
|
|
296
|
+
"columns": ["organizationId", "email"],
|
|
297
|
+
"fields": { "organizationId": "Already taken", "email": "Already taken" }
|
|
298
|
+
},
|
|
299
|
+
"hint": "A record with this \"organizationId\" + \"email\" already exists"
|
|
232
300
|
}
|
|
233
301
|
```
|
|
234
302
|
|
|
303
|
+
A unique violation names every column of the constraint (a composite unique
|
|
304
|
+
lists all of them) as API field names, and marks each in `details.fields` so a
|
|
305
|
+
form can show the conflict inline. `details.column` is the first of them.
|
|
306
|
+
|
|
235
307
|
**Error codes:**
|
|
236
308
|
|
|
237
309
|
| Code | Status | Description |
|
|
@@ -273,7 +345,7 @@ keep the internal flat shape (`error` message field, `layer`, `code`,
|
|
|
273
345
|
"error": "Field cannot be set during creation",
|
|
274
346
|
"layer": "guards",
|
|
275
347
|
"code": "GUARD_FIELD_NOT_CREATEABLE",
|
|
276
|
-
"details": { "fields":
|
|
348
|
+
"details": { "fields": { "stage": "cannot be set on create" } },
|
|
277
349
|
"hint": "These fields are set automatically or must be omitted"
|
|
278
350
|
}
|
|
279
351
|
}
|
|
@@ -35,7 +35,7 @@ The generated component schemas carry enough type information that strict valida
|
|
|
35
35
|
- **Logical q types survive database lowering** — `q.bool()` remains `boolean`, `q.timestamp()` remains an ISO date-time string, and `q.url()` retains its URI format even when D1 stores the value as text or integer.
|
|
36
36
|
- **Closed enums on `text(_, { enum: [...] })` columns** — emitted as `{ type: "string", enum: [...] }`, narrowing to a literal union in TS.
|
|
37
37
|
- **`Error.code` is a closed enum** — every `code` value the API can emit (`AUTH_MISSING`, `DB_UNIQUE_VIOLATION`, `BATCH_SIZE_EXCEEDED`, …) is enumerated so consumers can `switch` exhaustively.
|
|
38
|
-
- **ID `format`** — only emitted as `format: "uuid"` when your project
|
|
38
|
+
- **ID `format`** — only emitted as `format: "uuid"` when your project sets `generateId: "uuid"` explicitly. An unset `generateId` mints UUIDs too, but the table may still hold prefixed ids from before `"uuid"` became the default, so it gets no `format`. cuid2 / prefixed / nanoid / serial generators get plain `{ type: "string" }`, keeping strict OpenAPI validators happy.
|
|
39
39
|
|
|
40
40
|
### Action input and output schemas
|
|
41
41
|
|