@quickback-dev/cli 0.10.2 → 0.10.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.
- package/dist/commands/compile.d.ts +9 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +56 -16
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/create.js +108 -55
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +22 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/cursor/quickback.mdc +61 -46
- package/dist/docs/content.js +18 -18
- package/dist/docs/content.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/api-client.d.ts +34 -2
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js +31 -2
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/api-client.test.js +58 -0
- package/dist/lib/api-client.test.js.map +1 -1
- package/dist/lib/config-sync.d.ts +55 -0
- package/dist/lib/config-sync.d.ts.map +1 -0
- package/dist/lib/config-sync.js +207 -0
- package/dist/lib/config-sync.js.map +1 -0
- package/dist/lib/config-sync.test.d.ts +2 -0
- package/dist/lib/config-sync.test.d.ts.map +1 -0
- package/dist/lib/config-sync.test.js +151 -0
- package/dist/lib/config-sync.test.js.map +1 -0
- package/dist/lib/file-loader.d.ts +39 -5
- package/dist/lib/file-loader.d.ts.map +1 -1
- package/dist/lib/file-loader.js +226 -63
- package/dist/lib/file-loader.js.map +1 -1
- package/dist/lib/file-loader.test.js +212 -1
- package/dist/lib/file-loader.test.js.map +1 -1
- package/dist/lib/prepare-output.d.ts +31 -0
- package/dist/lib/prepare-output.d.ts.map +1 -0
- package/dist/lib/prepare-output.js +95 -0
- package/dist/lib/prepare-output.js.map +1 -0
- package/dist/lib/prepare-output.test.d.ts +2 -0
- package/dist/lib/prepare-output.test.d.ts.map +1 -0
- package/dist/lib/prepare-output.test.js +105 -0
- package/dist/lib/prepare-output.test.js.map +1 -0
- package/dist/lib/sweep-stale.d.ts +25 -0
- package/dist/lib/sweep-stale.d.ts.map +1 -0
- package/dist/lib/sweep-stale.js +179 -0
- package/dist/lib/sweep-stale.js.map +1 -0
- package/dist/lib/sweep-stale.test.d.ts +2 -0
- package/dist/lib/sweep-stale.test.d.ts.map +1 -0
- package/dist/lib/sweep-stale.test.js +130 -0
- package/dist/lib/sweep-stale.test.js.map +1 -0
- package/dist/skill/SKILL.md +327 -103
- package/dist/skill/agents/quickback-specialist/AGENT.md +93 -81
- package/package.json +14 -14
- package/src/cursor/quickback.mdc +61 -46
- package/src/skill/SKILL.md +327 -103
- package/src/skill/agents/quickback-specialist/AGENT.md +93 -81
|
@@ -16,7 +16,7 @@ You deeply understand:
|
|
|
16
16
|
- **Access**: Role-based and record-level permissions (deny by default)
|
|
17
17
|
- **Guards**: Field protection (createable, updatable, immutable, protected)
|
|
18
18
|
- **Masking**: PII redaction with role-based visibility and auto-detection
|
|
19
|
-
- **Actions**: Custom endpoints using `
|
|
19
|
+
- **Actions**: Custom endpoints using `defineAction()` (one file per action under `actions/`)
|
|
20
20
|
- **Views**: Column-level security with named projections
|
|
21
21
|
- **Validation**: Field-level validation rules
|
|
22
22
|
- **Layouts**: CMS record page field grouping with sections, columns, and collapsed state
|
|
@@ -33,7 +33,7 @@ You deeply understand:
|
|
|
33
33
|
3. **Generate complete configuration** including:
|
|
34
34
|
- Drizzle schema with correct dialect
|
|
35
35
|
- `defineTable()` with all security layers in a single file
|
|
36
|
-
- Actions via `
|
|
36
|
+
- Actions via `defineAction()` — one file per action under `actions/<name>.ts` (if needed)
|
|
37
37
|
4. **Validate the configuration** - Check for common mistakes
|
|
38
38
|
5. **Explain your decisions** - Help users understand the security model
|
|
39
39
|
|
|
@@ -43,8 +43,8 @@ Schema + security config in a single file using `defineTable()`.
|
|
|
43
43
|
|
|
44
44
|
Generate files in `quickback/features/{name}/`:
|
|
45
45
|
- `{table}.ts` - Drizzle schema + security config via `defineTable()` (DO NOT add audit fields - they're auto-injected)
|
|
46
|
-
- `actions.ts` -
|
|
47
|
-
- `
|
|
46
|
+
- `actions/{action}.ts` - One file per custom action via `defineAction()` (if needed)
|
|
47
|
+
- `lib/` - Shared Zod schemas / helpers, copied verbatim into the generated output (if needed)
|
|
48
48
|
|
|
49
49
|
When explaining compile outputs:
|
|
50
50
|
- Runtime outputs remain in `build.outputDir`.
|
|
@@ -55,68 +55,72 @@ Detect the database dialect from `quickback.config.ts`:
|
|
|
55
55
|
- Cloudflare D1 / SQLite: Use `sqliteTable`, `text`, `integer` from `drizzle-orm/sqlite-core`
|
|
56
56
|
- Supabase / PostgreSQL: Use `pgTable`, `text`, `boolean`, `timestamp` from `drizzle-orm/pg-core`
|
|
57
57
|
|
|
58
|
-
### Table Definition Pattern
|
|
58
|
+
### Table Definition Pattern (recommended: `feature()` + `q.scope()`)
|
|
59
59
|
|
|
60
60
|
```typescript
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
export default defineTable(todos, {
|
|
73
|
-
firewall: {
|
|
74
|
-
organization: {}, // Auto-detects 'organizationId' column
|
|
75
|
-
owner: {}, // Auto-detects 'userId' column
|
|
61
|
+
import { feature, q } from "@quickback/compiler";
|
|
62
|
+
|
|
63
|
+
export default feature("todos", {
|
|
64
|
+
columns: {
|
|
65
|
+
id: q.id(),
|
|
66
|
+
title: q.text().required(),
|
|
67
|
+
completed: q.bool().default(false),
|
|
68
|
+
ownerId: q.scope("owner"), // → ctx.userId, auto-firewalled, auto-populated
|
|
69
|
+
organizationId: q.scope("organization"), // → ctx.activeOrgId, same
|
|
76
70
|
},
|
|
71
|
+
// firewall block omitted — q.scope() auto-derives:
|
|
72
|
+
// [{ field: 'organizationId', equals: 'ctx.activeOrgId' },
|
|
73
|
+
// { field: 'ownerId', equals: 'ctx.userId' },
|
|
74
|
+
// { field: 'deletedAt', isNull: true }]
|
|
75
|
+
read: { access: { roles: ["member", "admin"] } },
|
|
77
76
|
crud: {
|
|
78
|
-
list: { access: { roles: ["member", "admin"] } },
|
|
79
|
-
get: { access: { roles: ["member", "admin"] } },
|
|
80
77
|
create: { access: { roles: ["member", "admin"] } },
|
|
81
78
|
update: { access: { roles: ["admin"] } },
|
|
82
79
|
delete: { access: { roles: ["admin"] }, mode: "soft" },
|
|
83
80
|
},
|
|
84
81
|
guards: {
|
|
85
82
|
createable: ["title", "completed"],
|
|
86
|
-
updatable:
|
|
87
|
-
},
|
|
88
|
-
masking: {
|
|
89
|
-
userId: { type: "redact", show: { roles: ["admin"] } },
|
|
83
|
+
updatable: ["title", "completed"],
|
|
90
84
|
},
|
|
91
85
|
});
|
|
92
86
|
```
|
|
93
87
|
|
|
88
|
+
For Drizzle interop (bringing forward existing schemas), use `sqliteTable` + `defineTable` and rely on auto-detection by column name (`organizationId`, `userId`, `ownerId`, `teamId`).
|
|
89
|
+
|
|
94
90
|
### Actions Pattern
|
|
95
91
|
|
|
92
|
+
One file per action under `actions/<name>.ts`. The filename (sans `.ts`) is the action name AND URL segment. Per-action permissions live under `access:` (same shape as resource-level access). Use `whereRecord(table)` for protected-field writes — it AND-merges firewall + soft-delete + the record id in one expression.
|
|
93
|
+
|
|
94
|
+
`actions/<name>.ts` binds to the feature's primary table (the `<feature>.ts` file). For multi-table features, use `actions/<table>/<name>.ts` to bind to a sibling table. Setting `path:` makes the action standalone.
|
|
95
|
+
|
|
96
96
|
```typescript
|
|
97
|
-
// quickback/features/todos/actions.ts
|
|
98
|
-
import {
|
|
99
|
-
import {
|
|
100
|
-
import
|
|
101
|
-
|
|
102
|
-
export default
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
97
|
+
// quickback/features/todos/actions/complete.ts
|
|
98
|
+
import { z } from "zod";
|
|
99
|
+
import { defineAction } from "../.quickback/define-action";
|
|
100
|
+
import todos from "../todos"; // default import: feature() exports
|
|
101
|
+
|
|
102
|
+
export default defineAction({
|
|
103
|
+
description: "Mark todo as complete",
|
|
104
|
+
input: z.object({
|
|
105
|
+
completedAt: z.string().datetime().optional(),
|
|
106
|
+
}),
|
|
107
|
+
access: {
|
|
108
|
+
roles: ["member", "admin"],
|
|
109
|
+
record: { completed: { equals: false } },
|
|
110
|
+
},
|
|
111
|
+
async execute({ db, record, whereRecord, auditFields }) {
|
|
112
|
+
await db.update(todos)
|
|
113
|
+
.set({ completed: true, modifiedAt: auditFields!.modifiedAt })
|
|
114
|
+
.where(whereRecord!(todos));
|
|
115
|
+
return { success: true };
|
|
116
116
|
},
|
|
117
117
|
});
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
For state-machine fields (status, lifecycle), add `transition: { field, via|to, fromTo }` so the runtime enforces the from→to pair and returns 409 `ACCESS_ACTION_NOT_ALLOWED_FOR_STATE` on illegal transitions. For cross-tenant or platform-level work, use `unsafe: { reason, adminOnly, crossTenant, targetScope }` (object form, auto-injects audit logging).
|
|
121
|
+
|
|
122
|
+
**Retired** (rejected at load time): bundled `actions.ts`, `_feature.ts`, `handlers/` directory, `defineActions()`, `*-actions.ts` filenames.
|
|
123
|
+
|
|
120
124
|
## Security Principles
|
|
121
125
|
|
|
122
126
|
1. **Secure by default** - Nothing is accessible until explicitly opened
|
|
@@ -128,17 +132,21 @@ export default defineActions(todos, {
|
|
|
128
132
|
|
|
129
133
|
### Multi-tenant resource
|
|
130
134
|
```typescript
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
// Auto-derived if organizationId is the only isolation column in the schema —
|
|
136
|
+
// you can omit `firewall:` entirely. Equivalent explicit form:
|
|
137
|
+
firewall: [
|
|
138
|
+
{ field: 'organizationId', equals: 'ctx.activeOrgId' },
|
|
139
|
+
{ field: 'deletedAt', isNull: true },
|
|
140
|
+
]
|
|
134
141
|
```
|
|
135
142
|
|
|
136
|
-
### Owner-scoped
|
|
143
|
+
### Owner-scoped, org-aware
|
|
137
144
|
```typescript
|
|
138
|
-
firewall:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
145
|
+
firewall: [
|
|
146
|
+
{ field: 'organizationId', equals: 'ctx.activeOrgId' },
|
|
147
|
+
{ field: 'ownerId', equals: 'ctx.userId' },
|
|
148
|
+
{ field: 'deletedAt', isNull: true },
|
|
149
|
+
]
|
|
142
150
|
```
|
|
143
151
|
|
|
144
152
|
### Workflow with protected status
|
|
@@ -146,7 +154,7 @@ firewall: {
|
|
|
146
154
|
guards: {
|
|
147
155
|
protected: { status: ['approve', 'reject'] }
|
|
148
156
|
}
|
|
149
|
-
// Plus
|
|
157
|
+
// Plus actions/approve.ts and actions/reject.ts via defineAction()
|
|
150
158
|
```
|
|
151
159
|
|
|
152
160
|
### PII masking
|
|
@@ -174,50 +182,54 @@ views: {
|
|
|
174
182
|
> Use `+` suffix with `auth.roleHierarchy` configured (e.g., `['member', 'admin', 'owner']`) to expand roles at compile time. `"member+"` → `["member", "admin", "owner"]`.
|
|
175
183
|
|
|
176
184
|
### Standalone actions (not record-based)
|
|
185
|
+
Setting `path:` makes an action standalone — no record loading or firewall preload.
|
|
177
186
|
```typescript
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
187
|
+
// features/sessions/actions/chat.ts
|
|
188
|
+
import { z } from "zod";
|
|
189
|
+
import { defineAction } from "../.quickback/define-action";
|
|
190
|
+
|
|
191
|
+
export default defineAction({
|
|
192
|
+
description: "AI chat",
|
|
181
193
|
path: "/chat",
|
|
182
194
|
method: "POST",
|
|
183
195
|
responseType: "stream",
|
|
184
196
|
input: z.object({ message: z.string() }),
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
197
|
+
access: { roles: ["member"] },
|
|
198
|
+
async execute({ input, c }) { /* … */ },
|
|
199
|
+
});
|
|
188
200
|
```
|
|
189
201
|
|
|
190
202
|
### Actions-only features (no tables)
|
|
203
|
+
A feature directory with no top-level `*.ts` files is "tableless" — every action under `actions/` must be standalone.
|
|
191
204
|
```typescript
|
|
192
|
-
// quickback/features/utilities/actions.ts
|
|
193
|
-
import {
|
|
194
|
-
import {
|
|
195
|
-
|
|
196
|
-
export default
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
guard: { roles: ["member", "admin"] },
|
|
204
|
-
handler: "./handlers/health-check",
|
|
205
|
-
},
|
|
205
|
+
// quickback/features/utilities/actions/health-check.ts
|
|
206
|
+
import { z } from "zod";
|
|
207
|
+
import { defineAction } from "../.quickback/define-action";
|
|
208
|
+
|
|
209
|
+
export default defineAction({
|
|
210
|
+
description: "Health check endpoint",
|
|
211
|
+
path: "/health",
|
|
212
|
+
method: "GET",
|
|
213
|
+
input: z.object({}),
|
|
214
|
+
access: { roles: ["member", "admin"] },
|
|
215
|
+
async execute() { return { ok: true }; },
|
|
206
216
|
});
|
|
207
217
|
```
|
|
208
|
-
All actions must have `standalone: true` when there is no table.
|
|
209
218
|
|
|
210
219
|
### Public actions (no auth required)
|
|
211
220
|
Use `roles: ["PUBLIC"]` for unauthenticated endpoints. Every invocation is mandatory audit logged.
|
|
212
221
|
```typescript
|
|
213
|
-
submit
|
|
214
|
-
|
|
215
|
-
|
|
222
|
+
// features/contact/actions/submit.ts
|
|
223
|
+
import { z } from "zod";
|
|
224
|
+
import { defineAction } from "../.quickback/define-action";
|
|
225
|
+
|
|
226
|
+
export default defineAction({
|
|
216
227
|
description: "Public contact form",
|
|
228
|
+
path: "/submit",
|
|
217
229
|
input: z.object({ name: z.string(), email: z.string().email(), message: z.string() }),
|
|
218
230
|
access: { roles: ["PUBLIC"] },
|
|
219
|
-
|
|
220
|
-
}
|
|
231
|
+
async execute({ db, input }) { /* persist submission */ return { ok: true }; },
|
|
232
|
+
});
|
|
221
233
|
```
|
|
222
234
|
The wildcard `"*"` is NOT supported and will throw a compile error. Use `"PUBLIC"` explicitly.
|
|
223
235
|
|
|
@@ -274,7 +286,7 @@ Before finishing, verify:
|
|
|
274
286
|
- [ ] Layouts for CMS record page field grouping (if needed)
|
|
275
287
|
- [ ] No audit fields in schema (auto-injected)
|
|
276
288
|
- [ ] Using `defineTable()` (not separate schema.ts + resource.ts)
|
|
277
|
-
- [ ] Actions use `
|
|
289
|
+
- [ ] Actions use `defineAction()` (one file per action under `actions/`) with Zod schemas (not JSON schema)
|
|
278
290
|
- [ ] Account UI configured if auth UI needed (`account: true` or `account: { ... }`)
|
|
279
291
|
|
|
280
292
|
## Accessing Documentation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quickback-dev/cli",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.5",
|
|
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",
|
|
@@ -41,18 +41,6 @@
|
|
|
41
41
|
"README.md",
|
|
42
42
|
"LICENSE"
|
|
43
43
|
],
|
|
44
|
-
"scripts": {
|
|
45
|
-
"prebuild": "npx tsx scripts/inject-version.ts && npm run bundle:docs && npm run bundle:skill && npm run bundle:examples",
|
|
46
|
-
"build": "tsc",
|
|
47
|
-
"postbuild": "npx tsx scripts/bundle-cursor.ts && rm -rf dist/skill dist/examples && cp -r src/skill dist/skill && cp -r src/examples dist/examples",
|
|
48
|
-
"dev": "tsc --watch",
|
|
49
|
-
"test": "bun test",
|
|
50
|
-
"typecheck": "tsc --noEmit",
|
|
51
|
-
"bundle:docs": "npx tsx scripts/bundle-docs.ts",
|
|
52
|
-
"bundle:skill": "npx tsx scripts/bundle-skill.ts",
|
|
53
|
-
"bundle:cursor": "npx tsx scripts/bundle-cursor.ts",
|
|
54
|
-
"bundle:examples": "npx tsx scripts/bundle-examples.ts"
|
|
55
|
-
},
|
|
56
44
|
"dependencies": {
|
|
57
45
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
|
58
46
|
"esbuild": "^0.27.2",
|
|
@@ -77,5 +65,17 @@
|
|
|
77
65
|
},
|
|
78
66
|
"engines": {
|
|
79
67
|
"node": ">=18.0.0"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"prebuild": "npx tsx scripts/inject-version.ts && npm run bundle:docs && npm run bundle:skill && npm run bundle:examples",
|
|
71
|
+
"build": "tsc",
|
|
72
|
+
"postbuild": "npx tsx scripts/bundle-cursor.ts && rm -rf dist/skill dist/examples && cp -r src/skill dist/skill && cp -r src/examples dist/examples",
|
|
73
|
+
"dev": "tsc --watch",
|
|
74
|
+
"test": "bun test",
|
|
75
|
+
"typecheck": "tsc --noEmit",
|
|
76
|
+
"bundle:docs": "npx tsx scripts/bundle-docs.ts",
|
|
77
|
+
"bundle:skill": "npx tsx scripts/bundle-skill.ts",
|
|
78
|
+
"bundle:cursor": "npx tsx scripts/bundle-cursor.ts",
|
|
79
|
+
"bundle:examples": "npx tsx scripts/bundle-examples.ts"
|
|
80
80
|
}
|
|
81
|
-
}
|
|
81
|
+
}
|
package/src/cursor/quickback.mdc
CHANGED
|
@@ -21,8 +21,10 @@ my-app/
|
|
|
21
21
|
│ └── features/
|
|
22
22
|
│ └── {feature-name}/
|
|
23
23
|
│ ├── {table}.ts # Schema + security (defineTable)
|
|
24
|
-
│ ├── actions
|
|
25
|
-
│
|
|
24
|
+
│ ├── actions/ # One file per action — defineAction({...}) (optional)
|
|
25
|
+
│ │ ├── {action}.ts # Binds to primary table (or standalone if path: is set)
|
|
26
|
+
│ │ └── {table}/{action}.ts # Binds to sibling <table>.ts (multi-table features)
|
|
27
|
+
│ └── lib/ # Feature-local helpers, copied verbatim (optional)
|
|
26
28
|
└── ...
|
|
27
29
|
```
|
|
28
30
|
|
|
@@ -63,10 +65,13 @@ export const todos = sqliteTable("todos", {
|
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
export default defineTable(todos, {
|
|
66
|
-
firewall:
|
|
68
|
+
firewall: [
|
|
69
|
+
{ field: "organizationId", equals: "ctx.activeOrgId" },
|
|
70
|
+
{ field: "userId", equals: "ctx.userId" },
|
|
71
|
+
{ field: "deletedAt", isNull: true },
|
|
72
|
+
],
|
|
73
|
+
read: { access: { roles: ["member", "admin"] } },
|
|
67
74
|
crud: {
|
|
68
|
-
list: { access: { roles: ["member", "admin"] } },
|
|
69
|
-
get: { access: { roles: ["member", "admin"] } },
|
|
70
75
|
create: { access: { roles: ["member", "admin"] } },
|
|
71
76
|
update: { access: { roles: ["admin"] } },
|
|
72
77
|
delete: { access: { roles: ["admin"] }, mode: "soft" },
|
|
@@ -87,25 +92,30 @@ Every request passes through: `Request → Firewall → Access → Guards → Da
|
|
|
87
92
|
|
|
88
93
|
### 1. Firewall — Data Isolation
|
|
89
94
|
|
|
90
|
-
Auto WHERE clauses for tenant isolation:
|
|
95
|
+
Auto WHERE clauses for tenant isolation. Predicates are AND'd:
|
|
91
96
|
|
|
92
97
|
```typescript
|
|
93
|
-
firewall:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
firewall: [
|
|
99
|
+
{ field: 'organizationId', equals: 'ctx.activeOrgId' }, // WHERE organizationId = ctx.activeOrgId
|
|
100
|
+
{ field: 'ownerId', equals: 'ctx.userId' }, // AND ownerId = ctx.userId
|
|
101
|
+
{ field: 'teamId', equals: 'ctx.activeTeamId' }, // AND teamId = ctx.activeTeamId
|
|
102
|
+
{ field: 'deletedAt', isNull: true }, // AND deletedAt IS NULL
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
// Public/system resources opt out of tenant scoping (soft-delete still applied):
|
|
106
|
+
firewall: [{ exception: true }]
|
|
100
107
|
```
|
|
101
108
|
|
|
109
|
+
Auto-derived when omitted: scans the schema for `organizationId` / `ownerId` / `teamId` and emits matching predicates. Two or more isolation columns → declare explicitly.
|
|
110
|
+
|
|
102
111
|
### 2. Access — Permission Checks
|
|
103
112
|
|
|
104
|
-
Role-based and record-based (deny by default)
|
|
113
|
+
Role-based and record-based (deny by default). Reads (`GET /` and `GET /:id`) gate via `read.access`; mutations gate via `crud.{create,update,delete}.access`.
|
|
105
114
|
|
|
106
115
|
```typescript
|
|
116
|
+
read: { access: { roles: ['member'] } }, // gates GET / and GET /:id
|
|
107
117
|
crud: {
|
|
108
|
-
|
|
118
|
+
create: { access: { roles: ['admin'] } },
|
|
109
119
|
update: {
|
|
110
120
|
access: {
|
|
111
121
|
or: [
|
|
@@ -114,9 +124,12 @@ crud: {
|
|
|
114
124
|
],
|
|
115
125
|
},
|
|
116
126
|
},
|
|
127
|
+
delete: { access: { roles: ['admin'] } },
|
|
117
128
|
}
|
|
118
129
|
```
|
|
119
130
|
|
|
131
|
+
> **DSL v2:** `crud.list` and `crud.get` are rejected at compile time. Move them to `read.access`.
|
|
132
|
+
|
|
120
133
|
Operators: `equals`, `notEquals`, `in`, `notIn`, `greaterThan`, `lessThan`
|
|
121
134
|
Context: `$ctx.userId`, `$ctx.activeOrgId`, `$ctx.roles`
|
|
122
135
|
|
|
@@ -164,50 +177,52 @@ validation: {
|
|
|
164
177
|
|
|
165
178
|
## Actions — Custom Business Logic
|
|
166
179
|
|
|
167
|
-
|
|
180
|
+
One file per action under `actions/<name>.ts`. The filename is the action name AND URL segment. `actions/<name>.ts` binds to the feature's primary table; `actions/<table>/<name>.ts` binds to a sibling table. Setting `path:` makes the action standalone.
|
|
168
181
|
|
|
169
182
|
```typescript
|
|
170
|
-
|
|
171
|
-
import {
|
|
172
|
-
import {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
// features/todos/actions/complete.ts
|
|
184
|
+
import { z } from "zod";
|
|
185
|
+
import { eq } from "drizzle-orm";
|
|
186
|
+
import { defineAction } from "../.quickback/define-action";
|
|
187
|
+
import { todos } from "../todos";
|
|
188
|
+
|
|
189
|
+
export default defineAction({
|
|
190
|
+
description: "Mark todo as complete",
|
|
191
|
+
input: z.object({ completedAt: z.string().datetime().optional() }),
|
|
192
|
+
access: { roles: ["member", "admin"], record: { completed: { equals: false } } },
|
|
193
|
+
async execute({ db, record, auditFields }) {
|
|
194
|
+
await db.update(todos)
|
|
195
|
+
.set({ completed: true, modifiedAt: auditFields!.modifiedAt })
|
|
196
|
+
.where(eq(todos.id, record.id));
|
|
197
|
+
return { success: true };
|
|
183
198
|
},
|
|
184
199
|
});
|
|
185
200
|
```
|
|
186
201
|
|
|
187
|
-
Record-based: `POST /api/v1/{resource}/:id/{action}`
|
|
188
|
-
Standalone
|
|
202
|
+
Record-based (no `path:`): `POST /api/v1/{resource}/:id/{action}`
|
|
203
|
+
Standalone (`path:` set): custom `path` and `method`
|
|
204
|
+
|
|
205
|
+
`execute:` must be an `async (ctx) => { … }` arrow function. Retired (rejected at load time): bundled `actions.ts`, `_feature.ts`, `handlers/` directory, `defineActions()`.
|
|
189
206
|
|
|
190
207
|
### Actions-Only Features (no tables)
|
|
191
208
|
|
|
209
|
+
A feature with no top-level `*.ts` files is "tableless" — every action must be standalone (have `path:`).
|
|
210
|
+
|
|
192
211
|
```typescript
|
|
193
|
-
// quickback/features/utilities/actions.ts
|
|
194
|
-
import {
|
|
195
|
-
import {
|
|
196
|
-
|
|
197
|
-
export default
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
handler: "./handlers/health-check",
|
|
205
|
-
},
|
|
212
|
+
// quickback/features/utilities/actions/health-check.ts
|
|
213
|
+
import { z } from "zod";
|
|
214
|
+
import { defineAction } from "../.quickback/define-action";
|
|
215
|
+
|
|
216
|
+
export default defineAction({
|
|
217
|
+
description: "Health check",
|
|
218
|
+
path: "/health",
|
|
219
|
+
method: "GET",
|
|
220
|
+
input: z.object({}),
|
|
221
|
+
access: { roles: ["member", "admin"] },
|
|
222
|
+
async execute() { return { ok: true }; },
|
|
206
223
|
});
|
|
207
224
|
```
|
|
208
225
|
|
|
209
|
-
All actions must have `standalone: true` when there is no table.
|
|
210
|
-
|
|
211
226
|
### Public Actions
|
|
212
227
|
|
|
213
228
|
Use `roles: ["PUBLIC"]` for unauthenticated endpoints. Mandatory audit logged. The wildcard `"*"` is not supported.
|