create-knit 0.9.1 → 0.11.0
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/index.mjs +24 -24
- package/package.json +1 -1
- package/template/base/AGENTS.md +9 -0
- package/template/base/apps/web/.env.example +18 -0
- package/template/base/llms.txt +9 -8
- package/template/examples/layers/example-blog/admin.ts +2 -9
- package/template/examples/layers/example-blog/server/database/schema.ts +6 -0
- package/template/examples/layers/example-blog/server/resources/comments.ts +0 -2
- package/template/examples/layers/example-blog/server/resources/posts.ts +0 -1
- package/template/examples/layers/example-dashboard/app/pages/dashboard.vue +19 -0
- package/template/examples/layers/example-dashboard/i18n/locales/de.json +3 -1
- package/template/examples/layers/example-dashboard/i18n/locales/en.json +3 -1
- package/template/examples/layers/example-dashboard/i18n/locales/es.json +3 -1
- package/template/versions.json +1 -1
package/index.mjs
CHANGED
|
@@ -61,7 +61,7 @@ function localPackages() {
|
|
|
61
61
|
const dir = process.env.KNIT_CREATE_TARBALLS
|
|
62
62
|
if (!dir) return undefined
|
|
63
63
|
const files = readdirSync(dir)
|
|
64
|
-
const find = prefix => {
|
|
64
|
+
const find = (prefix) => {
|
|
65
65
|
const file = files.find(f => f.startsWith(prefix) && f.endsWith('.tgz'))
|
|
66
66
|
// internal: KNIT_CREATE_TARBALLS is only set by Knit's own tests
|
|
67
67
|
if (!file) throw new Error(`KNIT_CREATE_TARBALLS: no ${prefix}*.tgz in ${dir}`)
|
|
@@ -91,15 +91,15 @@ function writeProject(target, name, examples) {
|
|
|
91
91
|
packageManager: versions.packageManager,
|
|
92
92
|
engines: { node: '>=22' },
|
|
93
93
|
scripts: {
|
|
94
|
-
manage: 'knit',
|
|
95
|
-
dev: 'pnpm --filter web dev',
|
|
96
|
-
build: 'pnpm --filter web build',
|
|
94
|
+
'manage': 'knit',
|
|
95
|
+
'dev': 'pnpm --filter web dev',
|
|
96
|
+
'build': 'pnpm --filter web build',
|
|
97
97
|
// The app (and every layer it extends), then tests and commands, which run outside Nuxt.
|
|
98
|
-
typecheck: 'pnpm -r typecheck && tsc -p tsconfig.test.json',
|
|
99
|
-
lint: 'eslint .',
|
|
100
|
-
check: 'knit check',
|
|
101
|
-
test: 'knit test',
|
|
102
|
-
services: 'docker compose up -d',
|
|
98
|
+
'typecheck': 'pnpm -r typecheck && tsc -p tsconfig.test.json',
|
|
99
|
+
'lint': 'eslint .',
|
|
100
|
+
'check': 'knit check',
|
|
101
|
+
'test': 'knit test',
|
|
102
|
+
'services': 'docker compose up -d',
|
|
103
103
|
'services:down': 'docker compose down',
|
|
104
104
|
},
|
|
105
105
|
devDependencies: {
|
|
@@ -109,10 +109,10 @@ function writeProject(target, name, examples) {
|
|
|
109
109
|
'@nuxt/test-utils': versions.testUtils,
|
|
110
110
|
'@types/node': versions.typesNode,
|
|
111
111
|
'@types/pg': versions.typesPg,
|
|
112
|
-
eslint: versions.eslint,
|
|
113
|
-
pg: versions.pg,
|
|
114
|
-
typescript: versions.typescript,
|
|
115
|
-
vitest: versions.vitest,
|
|
112
|
+
'eslint': versions.eslint,
|
|
113
|
+
'pg': versions.pg,
|
|
114
|
+
'typescript': versions.typescript,
|
|
115
|
+
'vitest': versions.vitest,
|
|
116
116
|
},
|
|
117
117
|
// Project settings, read by the `knit` CLI and the core layer.
|
|
118
118
|
knit: { app: 'apps/web', layersDir: 'layers', migrationsDir: 'server/database/migrations', template: versions.knit },
|
|
@@ -126,8 +126,8 @@ function writeProject(target, name, examples) {
|
|
|
126
126
|
'allowBuilds:',
|
|
127
127
|
' esbuild: true',
|
|
128
128
|
' vue-demi: true',
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
' \'@parcel/watcher\': true',
|
|
130
|
+
' \'@tailwindcss/oxide\': true',
|
|
131
131
|
' unrs-resolver: true',
|
|
132
132
|
' # Pulled in by OpenTelemetry\'s exporter (docs/observability.md); its script only prints a notice.',
|
|
133
133
|
' protobufjs: false',
|
|
@@ -145,21 +145,21 @@ function writeProject(target, name, examples) {
|
|
|
145
145
|
dependencies: {
|
|
146
146
|
'@knit-framework/core': core,
|
|
147
147
|
...Object.fromEntries(exampleLayers.map(l => [l, 'workspace:*'])),
|
|
148
|
-
nuxt: versions.nuxt,
|
|
148
|
+
'nuxt': versions.nuxt,
|
|
149
149
|
},
|
|
150
|
-
devDependencies: { '@nuxt/eslint': versions.nuxtEslint, eslint: versions.eslint, typescript: versions.typescript, 'vue-tsc': versions.vueTsc },
|
|
150
|
+
devDependencies: { '@nuxt/eslint': versions.nuxtEslint, 'eslint': versions.eslint, 'typescript': versions.typescript, 'vue-tsc': versions.vueTsc },
|
|
151
151
|
}))
|
|
152
152
|
writeFileSync(join(target, 'apps/web/nuxt.config.ts'), [
|
|
153
|
-
|
|
153
|
+
'import { fileURLToPath } from \'node:url\'',
|
|
154
154
|
'',
|
|
155
155
|
'export default defineNuxtConfig({',
|
|
156
156
|
' // Installed apps. `pnpm manage startapp <name>` adds new ones here.',
|
|
157
157
|
` extends: [${['@knit-framework/core', ...exampleLayers.map(l => `../../layers/${l}`)].map(e => `'${e}'`).join(', ')}],`,
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
' modules: [\'@nuxt/eslint\'],',
|
|
159
|
+
' compatibilityDate: \'2026-11-01\',',
|
|
160
160
|
' devtools: { enabled: true },',
|
|
161
161
|
' // `pnpm lint` runs from the workspace root (eslint.config.mjs there), so layers are linted too.',
|
|
162
|
-
|
|
162
|
+
' eslint: { config: { rootDir: fileURLToPath(new URL(\'../..\', import.meta.url)), autoInit: false } },',
|
|
163
163
|
'})',
|
|
164
164
|
'',
|
|
165
165
|
].join('\n'))
|
|
@@ -173,7 +173,7 @@ function writeProject(target, name, examples) {
|
|
|
173
173
|
writeFileSync(join(target, 'layers/.gitkeep'), '')
|
|
174
174
|
|
|
175
175
|
writeFileSync(join(target, 'vitest.config.ts'), [
|
|
176
|
-
|
|
176
|
+
'import { defineConfig } from \'vitest/config\'',
|
|
177
177
|
'',
|
|
178
178
|
'// `pnpm test` (= `knit test`): unit tests of your apps, and e2e tests that build apps/web.',
|
|
179
179
|
'export default defineConfig({',
|
|
@@ -181,8 +181,8 @@ function writeProject(target, name, examples) {
|
|
|
181
181
|
' // A project without tests yet is not a failure.',
|
|
182
182
|
' passWithNoTests: true,',
|
|
183
183
|
' projects: [',
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
' { test: { name: \'unit\', environment: \'node\', include: [\'layers/*/test/**/*.test.ts\', \'apps/*/test/unit/**/*.test.ts\'] } },',
|
|
185
|
+
' { test: { name: \'e2e\', environment: \'node\', include: [\'apps/*/test/e2e/**/*.test.ts\'], testTimeout: 60_000, hookTimeout: 300_000, fileParallelism: false } },',
|
|
186
186
|
' ],',
|
|
187
187
|
' },',
|
|
188
188
|
'})',
|
package/package.json
CHANGED
package/template/base/AGENTS.md
CHANGED
|
@@ -29,6 +29,7 @@ Don't read files to find out what exists. Ask Knit:
|
|
|
29
29
|
| A new app | `pnpm manage startapp <name>` → `layers/<name>/` with a model, admin, API, page, seed, command and test (adds it to `apps/web/nuxt.config.ts` `extends`) |
|
|
30
30
|
| One more file in an app | `pnpm manage generate <resource\|task\|channel\|command\|test\|page> <app> <name> [--table <export>]`: start from the generated file instead of writing it from scratch |
|
|
31
31
|
| Models | `layers/<app>/server/database/schema.ts` (tables named `<app>_<model>`, `relations()` next to them) |
|
|
32
|
+
| Model options | `defineModelMeta(table, { verboseName, ordering, searchFields, softDelete, history, search, policy })` below the tables in `schema.ts`. Say them once: the admin and every resource use the names, order and search fields unless they set their own |
|
|
32
33
|
| Admin | `layers/<app>/admin.ts` → `registerAdminModel(table, { listDisplay, searchFields, … })`; `registerAdminPage`, `registerDashboardCard`; your admin components in `layers/<app>/app/admin/*.vue` (widgets, computed columns, panels, cards) |
|
|
33
34
|
| A public REST API + forms | `layers/<app>/server/resources/<name>.ts` → `export default defineResource(table, { permissions, … })`; `<KnitModelForm resource="…">` in pages |
|
|
34
35
|
| Pages / components | `layers/<app>/app/pages/**`, `app/components/**` (Nuxt conventions) |
|
|
@@ -48,6 +49,10 @@ Don't edit `node_modules/@knit-framework/*`: override instead (a page, component
|
|
|
48
49
|
- **Cross-app references** import the table: `import { user } from '@knit-framework/core/schema'`.
|
|
49
50
|
- **Permissions on the server:** `requirePermission(event, 'shop.change_product')`. In the UI, `useAuth().can(perm)` is display-only.
|
|
50
51
|
- **Row-level rules** ("users change only their own rows") are a `policy` in the model's meta, not checks in each route. In your own routes, act as the user so it applies: `useModel(table).as(await requestActor(event))`; plain `useModel(table)` and `useDB()` skip it. See `node_modules/@knit-framework/core/docs/permissions.md`.
|
|
52
|
+
- **Soft delete:** a model with `softDelete` in its meta keeps deleted rows in the table. `useModel`, the admin and resources skip them; a raw `useDB()` query does not, so add `notDeletedWhere(table)` to its `where` (`pnpm manage describe` shows which models: `soft delete (deletedAt)`).
|
|
53
|
+
- **Sessions are cached for reads** (60 s, `NUXT_KNIT_AUTH_SESSION_CACHE`): `requireAuth`/`requirePermission` in a `GET` handler may see a session up to a minute old; writes, the admin API and anything after the user's own write are always fresh. See `node_modules/@knit-framework/core/docs/auth.md#session-cache` before relying on an instant ban in a `GET`.
|
|
54
|
+
- **Which permission goes where** (model permissions, admin switches, resource and endpoint rules, row policies): the table at the top of `node_modules/@knit-framework/core/docs/permissions.md`.
|
|
55
|
+
- **Public API only:** use what the API reference lists (`knit_reference`, `node_modules/@knit-framework/core/docs/reference/`). An export tagged `@internal` or missing from the reference is Knit's plumbing and may change in any release; one marked Experimental may change in a minor release.
|
|
51
56
|
- **Custom JSON routes use `defineEndpoint`**, not a bare `defineEventHandler`: it requires a `permission`, validates `body`/`query`/`params` with zod (`z` comes from `@knit-framework/core/endpoints`; query and params arrive as strings, so `z.coerce`), answers with the same 422 `data.issues` as model validation, and lists the route in `/api/r/openapi.json`. Plain handlers are for non-JSON routes (downloads, redirects, raw-body webhooks). See `node_modules/@knit-framework/core/docs/endpoints.md`.
|
|
52
57
|
- **Resources default to deny for writes.** List `fields` explicitly for public APIs. Server-set values (e.g. `authorId`) belong in `beforeCreate`.
|
|
53
58
|
- **Files outside Nitro** (tasks, commands, seeds) don't get auto-imports: import from `@knit-framework/core/*` and use the `db`/`ctx.db` you are given.
|
|
@@ -92,6 +97,10 @@ pnpm manage test --unit # fast; pnpm test runs e2e too (builds
|
|
|
92
97
|
- **Resources** must be *exported*. `_choices` for a foreign key goes through the target table's resource (no resource, no choices).
|
|
93
98
|
- **Realtime channels are default-deny:** a channel without `authorize` needs a signed-in user. `broadcastModel` fires after commit, for `useModel` writes only.
|
|
94
99
|
- **CSRF:** cookie-carrying cross-site `POST`/`PUT`/`PATCH`/`DELETE` to `/api/**` get 403. With curl, send no `Origin` or the server's own origin. Webhooks go in `NUXT_KNIT_SECURITY_CSRF_EXEMPT`.
|
|
100
|
+
- **Writes are rate limited:** 120 a minute per caller on resources and endpoints, 30 uploads; over it is a 429 with `Retry-After`. A route's own `rateLimit` replaces the default; a test suite that hammers writes sets `NUXT_KNIT_RATE_LIMIT_ENABLED=false`.
|
|
101
|
+
- **API tokens** (`Authorization: Bearer knit_…`, off until `NUXT_KNIT_AUTH_API_TOKENS_ENABLED=true`) act as a user, ignore cookies, and are refused on `/api/_admin`, `/api/auth` and realtime. Your handlers need no changes: `requireAuth`, permissions and policies see the token's user.
|
|
102
|
+
- **`queueMail()` in requests, `sendMail()` in scripts:** `sendMail()` throws when the mailer fails; `queueMail()` and `template.queue()` never do.
|
|
103
|
+
- **Cursor pages have no `total`:** `?cursor=`, `paginateCursor()` and `useResource().infinite()` return `next` instead. Keep `list()` / `paginate()` where you show page numbers.
|
|
95
104
|
- **Vue's `useModel` shadows Knit's** in typechecking. In server files, import it explicitly from `@knit-framework/core/models`.
|
|
96
105
|
- **Two dev servers on `localhost`** share cookies across ports. Use `http://<name>.localhost:<port>`.
|
|
97
106
|
- **Drizzle renders columns unqualified inside `` sql`…` ``.** In correlated subqueries, write table-qualified names.
|
|
@@ -44,6 +44,22 @@ NUXT_BETTER_AUTH_URL=
|
|
|
44
44
|
# Behind a reverse proxy, read the client IP from X-Forwarded-For: false (default) | true
|
|
45
45
|
# NUXT_BETTER_AUTH_TRUST_PROXY=false
|
|
46
46
|
|
|
47
|
+
# Rate limits for resources, endpoints and uploads, per caller (docs/security.md#rate-limiting).
|
|
48
|
+
# NUXT_KNIT_RATE_LIMIT_ENABLED=true
|
|
49
|
+
# Where counts are kept: database (default, shared by every instance) | memory (per process)
|
|
50
|
+
# NUXT_KNIT_RATE_LIMIT_STORE=database
|
|
51
|
+
# Requests per minute and caller; 0 is no limit. A route's own `rateLimit` replaces these.
|
|
52
|
+
# NUXT_KNIT_RATE_LIMIT_WRITES=120
|
|
53
|
+
# NUXT_KNIT_RATE_LIMIT_UPLOADS=30
|
|
54
|
+
# NUXT_KNIT_RATE_LIMIT_READS=0
|
|
55
|
+
|
|
56
|
+
# API tokens for scripts, apps and other servers (docs/api-tokens.md): false (default) | true
|
|
57
|
+
# NUXT_KNIT_AUTH_API_TOKENS_ENABLED=false
|
|
58
|
+
# Who may create tokens on the account page: authenticated (default) | staff
|
|
59
|
+
# NUXT_KNIT_AUTH_API_TOKENS_CREATE=authenticated
|
|
60
|
+
# Longest lifetime of a token in days; 0 (default) is no limit
|
|
61
|
+
# NUXT_KNIT_AUTH_API_TOKENS_MAX_LIFETIME=0
|
|
62
|
+
|
|
47
63
|
# Sign-in options (docs/auth.md#sign-in-options). A provider is on when both its id and secret are
|
|
48
64
|
# set; register the callback URL <site>/api/auth/callback/<provider> at the provider.
|
|
49
65
|
# NUXT_KNIT_AUTH_PROVIDERS_GITHUB_CLIENT_ID=
|
|
@@ -67,6 +83,8 @@ NUXT_BETTER_AUTH_URL=
|
|
|
67
83
|
# NUXT_KNIT_AUTH_TWO_FACTOR=optional
|
|
68
84
|
# Passkeys (WebAuthn): true (default) | false
|
|
69
85
|
# NUXT_KNIT_AUTH_PASSKEYS=true
|
|
86
|
+
# Seconds a session read may come from a signed cookie instead of the database (0 = always ask)
|
|
87
|
+
# NUXT_KNIT_AUTH_SESSION_CACHE=60
|
|
70
88
|
# Organizations (docs/organizations.md): users create them, invite members and switch the active one
|
|
71
89
|
# NUXT_KNIT_AUTH_ORGANIZATIONS_ENABLED=false
|
|
72
90
|
# NUXT_KNIT_AUTH_ORGANIZATIONS_ALLOW_USER_TO_CREATE=true
|
package/template/base/llms.txt
CHANGED
|
@@ -14,16 +14,17 @@ Agents working in a Knit project: read AGENTS.md, and use the `knit` MCP server
|
|
|
14
14
|
|
|
15
15
|
- [Development environment](node_modules/@knit-framework/core/docs/development.md): Native Node, or Docker Compose with Postgres and Mailpit
|
|
16
16
|
- [Getting started](node_modules/@knit-framework/core/docs/getting-started.md): Install, project layout, your first app end to end
|
|
17
|
-
- [Models & data](node_modules/@knit-framework/core/docs/models.md): Tables, migrations, `useModel`, validators, `clean()`, signals, Postgres
|
|
17
|
+
- [Models & data](node_modules/@knit-framework/core/docs/models.md): Tables, migrations, `useModel`, `defineModelMeta` (names, ordering, search fields), validators, `clean()`, signals, soft delete, change history, full-text search, Postgres
|
|
18
18
|
- [Resources & forms](node_modules/@knit-framework/core/docs/resources.md): `defineResource` REST APIs, permissions, scoping, OpenAPI, `useResource`, `<KnitModelForm>`
|
|
19
19
|
- [Custom endpoints](node_modules/@knit-framework/core/docs/endpoints.md): `defineEndpoint` routes with a permission, validated input and an entry in the OpenAPI document
|
|
20
20
|
- [Rendering modes](node_modules/@knit-framework/core/docs/rendering.md): SSR by default; SPA per route, per path or per layer; prerender and caching
|
|
21
|
-
- [Admin](node_modules/@knit-framework/core/docs/admin.md): `registerAdminModel` options, filters, actions, inlines, history, user tools, REST API
|
|
22
|
-
- [Auth & permissions](node_modules/@knit-framework/core/docs/auth.md): Users, staff, superusers, groups, permissions, `/accounts/*` pages
|
|
23
|
-
- [Row-level permissions](node_modules/@knit-framework/core/docs/permissions.md): `defineModelMeta(table, { policy })`, `useModel(table).as(actor)`, what the admin, resources and realtime apply
|
|
21
|
+
- [Admin](node_modules/@knit-framework/core/docs/admin.md): `registerAdminModel` options, filters, actions, inlines, history, trash, custom pages, dashboard cards, panels, computed columns and widgets, user tools, REST API
|
|
22
|
+
- [Auth & permissions](node_modules/@knit-framework/core/docs/auth.md): Users, staff, superusers, groups, permissions, `/accounts/*` pages, sign-in options, the session cache
|
|
23
|
+
- [Row-level permissions](node_modules/@knit-framework/core/docs/permissions.md): which permission goes where (model permissions, admin switches, resource rules, policies), `defineModelMeta(table, { policy })`, `useModel(table).as(actor)`, what the admin, resources and realtime apply
|
|
24
24
|
- [Organizations](node_modules/@knit-framework/core/docs/organizations.md): `NUXT_KNIT_AUTH_ORGANIZATIONS_ENABLED`, invitations, roles, `inActiveOrganization` / `hasOrganizationRole` / `assignOrganization`, `useOrganization()`, `switchOrganization()` in tests
|
|
25
|
+
- [API tokens](node_modules/@knit-framework/core/docs/api-tokens.md): `NUXT_KNIT_AUTH_API_TOKENS_ENABLED`, `Authorization: Bearer knit_…`, tokens act as a user with optional narrower permissions, `pnpm manage createtoken`, `createTestClient(url, { token })`
|
|
25
26
|
- [Internationalization](node_modules/@knit-framework/core/docs/i18n.md): Translations, locales per layer, translating models, the language switcher
|
|
26
|
-
- [Email](node_modules/@knit-framework/core/docs/email.md): `sendMail()`, mailers, templates, auth emails
|
|
27
|
+
- [Email](node_modules/@knit-framework/core/docs/email.md): `sendMail()`, `queueMail()` (does not fail the request, retries on the database task backend), mailers, templates, auth emails
|
|
27
28
|
- [Background tasks](node_modules/@knit-framework/core/docs/tasks.md): `defineTask`, `enqueue`, the worker, cron schedules
|
|
28
29
|
- [Realtime](node_modules/@knit-framework/core/docs/realtime.md): Channels over SSE and WebSocket, `publish`, `broadcastModel`, `useRealtime`, scaling with Postgres
|
|
29
30
|
- [Files & uploads](node_modules/@knit-framework/core/docs/files.md): `fileColumn`, uploads, disk/S3 storage
|
|
@@ -31,14 +32,14 @@ Agents working in a Knit project: read AGENTS.md, and use the `knit` MCP server
|
|
|
31
32
|
- [Sitemaps & feeds](node_modules/@knit-framework/core/docs/sitemaps-and-feeds.md): `/sitemap.xml`, RSS and Atom
|
|
32
33
|
- [Observability](node_modules/@knit-framework/core/docs/observability.md): OpenTelemetry traces (NUXT_KNIT_TELEMETRY_ENABLED), what each span contains, `withSpan`
|
|
33
34
|
- [Logging](node_modules/@knit-framework/core/docs/logging.md): LogLayer: pretty dev output, JSON in production, request logs, redaction
|
|
34
|
-
- [Security](node_modules/@knit-framework/core/docs/security.md): CSRF, security headers, CSP
|
|
35
|
-
- [Testing](node_modules/@knit-framework/core/docs/testing.md): Test databases, factories, the HTTP client, `pnpm test`
|
|
35
|
+
- [Security](node_modules/@knit-framework/core/docs/security.md): CSRF, security headers, CSP, rate limiting (`rateLimit` on resources and endpoints, `assertRateLimit`, `NUXT_KNIT_RATE_LIMIT_*`, 429 with `Retry-After`)
|
|
36
|
+
- [Testing](node_modules/@knit-framework/core/docs/testing.md): Test databases (PGlite, or Postgres with `KNIT_TEST_DATABASE_URL`), factories, the HTTP client, `pnpm test`
|
|
36
37
|
- [Knit in Nuxt DevTools](node_modules/@knit-framework/core/docs/devtools.md): the dev-only Knit tab (models, routes, tasks, mail, realtime, errors, migrations), its actions and who may read it
|
|
37
38
|
- [`manage` CLI](node_modules/@knit-framework/core/docs/cli.md): Every command, `startapp` and `generate`, JSON output for scripts and agents, seeds, custom commands
|
|
38
39
|
- [Configuration](node_modules/@knit-framework/core/docs/configuration.md): Every environment variable and setting
|
|
39
40
|
- [Deployment](node_modules/@knit-framework/core/docs/deployment/index.md): production checklist, what Knit needs from a host, and one page per host (Docker, VPS with systemd and Caddy, Fly.io, Railway, Render; Vercel and Netlify with limits; Cloudflare not supported)
|
|
40
41
|
- [Postgres in production](node_modules/@knit-framework/core/docs/postgres.md): moving off PGlite, DATABASE_DIRECT_URL and poolers, zero-downtime migrations, backups, several instances
|
|
41
|
-
- [Upgrading](node_modules/@knit-framework/core/docs/upgrading.md): updating the @knit-framework packages, migrating Knit's tables, removing the examples
|
|
42
|
+
- [Upgrading](node_modules/@knit-framework/core/docs/upgrading.md): updating the @knit-framework packages, migrating Knit's tables, what counts as public API, removing the examples
|
|
42
43
|
- [How Knit works](node_modules/@knit-framework/core/docs/architecture.md): Discovery, generated modules, request lifecycle
|
|
43
44
|
- [Working with AI agents](node_modules/@knit-framework/core/docs/ai-agents.md): `AGENTS.md`, the `knit` MCP server (tools, resources, write tools), `describe`, `routes`, `openapi`, skills
|
|
44
45
|
- [Troubleshooting](node_modules/@knit-framework/core/docs/troubleshooting.md): Common errors and fixes
|
|
@@ -3,14 +3,11 @@ import { manyToMany, registerAdminModel, registerAdminPage, registerDashboardCar
|
|
|
3
3
|
import { useModel, type ModelDatabase } from '@knit-framework/core/models'
|
|
4
4
|
import { category, comment, post, postTag, tag } from './server/database/schema'
|
|
5
5
|
|
|
6
|
+
// Labels, the default order and the search fields come from each model's defineModelMeta (schema.ts).
|
|
6
7
|
registerAdminModel(category, {
|
|
7
8
|
icon: 'i-lucide-folder',
|
|
8
|
-
label: 'Category',
|
|
9
|
-
labelPlural: 'Categories',
|
|
10
9
|
listDisplay: ['name', 'slug', 'createdAt'],
|
|
11
10
|
listEditable: ['slug'],
|
|
12
|
-
searchFields: ['name', 'slug'],
|
|
13
|
-
ordering: ['name'],
|
|
14
11
|
displayField: 'name',
|
|
15
12
|
readonlyFields: ['createdAt'],
|
|
16
13
|
prepopulatedFields: { slug: 'name' },
|
|
@@ -53,8 +50,6 @@ registerAdminModel(post, {
|
|
|
53
50
|
listEditable: ['published'],
|
|
54
51
|
listFilter: ['published', 'categoryId', 'authorId', 'publishedAt'],
|
|
55
52
|
dateHierarchy: 'publishedAt',
|
|
56
|
-
searchFields: ['title', 'slug', 'body'],
|
|
57
|
-
ordering: ['-createdAt'],
|
|
58
53
|
displayField: 'title',
|
|
59
54
|
readonlyFields: ['createdAt', 'updatedAt'],
|
|
60
55
|
prepopulatedFields: { slug: 'title' },
|
|
@@ -107,8 +102,6 @@ registerAdminModel(post, {
|
|
|
107
102
|
registerAdminModel(tag, {
|
|
108
103
|
icon: 'i-lucide-tag',
|
|
109
104
|
listDisplay: ['name'],
|
|
110
|
-
searchFields: ['name'],
|
|
111
|
-
ordering: ['name'],
|
|
112
105
|
displayField: 'name',
|
|
113
106
|
})
|
|
114
107
|
|
|
@@ -117,7 +110,7 @@ registerAdminModel(comment, {
|
|
|
117
110
|
listDisplay: ['body', 'postId', 'authorId', 'approved', 'createdAt'],
|
|
118
111
|
listFilter: ['approved', 'postId', 'createdAt'],
|
|
119
112
|
listEditable: ['approved'],
|
|
120
|
-
|
|
113
|
+
// Newest first here; the model's own order (oldest first) is for reading a thread.
|
|
121
114
|
ordering: ['-createdAt'],
|
|
122
115
|
displayField: 'body',
|
|
123
116
|
readonlyFields: ['createdAt', 'updatedAt'],
|
|
@@ -117,11 +117,16 @@ defineModelMeta(category, {
|
|
|
117
117
|
verboseName: 'category',
|
|
118
118
|
verboseNamePlural: 'categories',
|
|
119
119
|
ordering: ['name'],
|
|
120
|
+
searchFields: ['name', 'slug'],
|
|
120
121
|
validators: { slug: [slugValidator] },
|
|
121
122
|
})
|
|
122
123
|
|
|
124
|
+
defineModelMeta(tag, { ordering: ['name'], searchFields: ['name'] })
|
|
125
|
+
|
|
123
126
|
defineModelMeta(post, {
|
|
124
127
|
ordering: ['-createdAt'],
|
|
128
|
+
// What the admin search box and the posts API's `?q=` match when the search vector can't be used.
|
|
129
|
+
searchFields: ['title', 'slug', 'body'],
|
|
125
130
|
// Deleting moves a post to the trash (restore it from the admin); every change is recorded, field by
|
|
126
131
|
// field, in the change history; `useModel(post).search()` and `?q=` use the search vector.
|
|
127
132
|
softDelete: 'deletedAt',
|
|
@@ -150,6 +155,7 @@ defineModelMeta(post, {
|
|
|
150
155
|
|
|
151
156
|
defineModelMeta(comment, {
|
|
152
157
|
ordering: ['createdAt'],
|
|
158
|
+
searchFields: ['body'],
|
|
153
159
|
// Moderation, declared once: the comments API, the admin and the live comments channel all apply it.
|
|
154
160
|
// Moderators (`blog.change_comment`) see every comment; signed-in users see approved comments and
|
|
155
161
|
// their own pending ones; visitors see approved comments. Authors edit and delete their own.
|
|
@@ -19,8 +19,6 @@ export default defineResource(comment, {
|
|
|
19
19
|
readonlyFields: ['authorId', 'approved', 'createdAt', 'updatedAt'],
|
|
20
20
|
labels: { body: 'Comment' },
|
|
21
21
|
filterFields: ['postId', 'approved'],
|
|
22
|
-
searchFields: ['body'],
|
|
23
|
-
ordering: ['createdAt'],
|
|
24
22
|
perPage: 50,
|
|
25
23
|
|
|
26
24
|
permissions: {
|
|
@@ -10,7 +10,6 @@ export default defineResource(post, {
|
|
|
10
10
|
slug: 'posts',
|
|
11
11
|
fields: ['id', 'title', 'slug', 'body', 'cover', 'published', 'publishedAt', 'categoryId'],
|
|
12
12
|
readonlyFields: ['publishedAt'],
|
|
13
|
-
searchFields: ['title', 'body'],
|
|
14
13
|
filterFields: ['categoryId', 'publishedAt'],
|
|
15
14
|
ordering: ['-publishedAt'],
|
|
16
15
|
perPage: 10,
|
|
@@ -11,6 +11,9 @@ useHead({ title: () => t('dashboard.title') })
|
|
|
11
11
|
|
|
12
12
|
const posts = useResource<typeof post>('posts').list({ perPage: 100, key: 'dashboard-posts' })
|
|
13
13
|
|
|
14
|
+
// A list that grows: five posts now, five more per click. It pages by cursor, so the server counts nothing.
|
|
15
|
+
const recent = useResource<typeof post>('posts').infinite({ perPage: 5, key: 'dashboard-recent' })
|
|
16
|
+
|
|
14
17
|
const browser = reactive({
|
|
15
18
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
16
19
|
online: navigator.onLine,
|
|
@@ -63,5 +66,21 @@ const latest = computed(() => posts.items.value[0])
|
|
|
63
66
|
</p>
|
|
64
67
|
</UCard>
|
|
65
68
|
</div>
|
|
69
|
+
|
|
70
|
+
<UCard data-testid="recent-posts">
|
|
71
|
+
<template #header>
|
|
72
|
+
<h2 class="font-semibold text-highlighted">{{ t('dashboard.recent') }}</h2>
|
|
73
|
+
</template>
|
|
74
|
+
<ul class="divide-y divide-default">
|
|
75
|
+
<li v-for="item in recent.items.value" :key="item.id" class="flex items-center justify-between gap-3 py-2">
|
|
76
|
+
<ULink :to="`/blog/${item.slug}`" class="min-w-0 truncate font-medium">{{ item.title }}</ULink>
|
|
77
|
+
<NuxtTime v-if="item.publishedAt" :datetime="item.publishedAt" :locale="locale" date-style="medium" class="shrink-0 text-sm text-muted" />
|
|
78
|
+
</li>
|
|
79
|
+
</ul>
|
|
80
|
+
<p v-if="!recent.items.value.length" class="text-sm text-muted">—</p>
|
|
81
|
+
<template v-if="recent.hasMore.value" #footer>
|
|
82
|
+
<UButton :label="t('dashboard.loadMore')" icon="i-lucide-chevrons-down" color="neutral" variant="subtle" :loading="recent.loadingMore.value" data-testid="load-more" @click="recent.loadMore()" />
|
|
83
|
+
</template>
|
|
84
|
+
</UCard>
|
|
66
85
|
</UContainer>
|
|
67
86
|
</template>
|
package/template/versions.json
CHANGED