create-wervt 0.2.3 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wervt",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Create a new wervt app: Nuxt 5, Postgres with Drizzle, live data with Electric.",
5
5
  "homepage": "https://wervt.app",
6
6
  "license": "MIT",
@@ -99,15 +99,61 @@ const { data: todos, isLive } = await useShape<Todo>('/api/shapes/todos')
99
99
  - For your own state (anonymous visitors too), use `useSession(event, { name })` from
100
100
  `nuxt/server`. The secret is set by wervt.
101
101
 
102
+ ## Files
103
+
104
+ Store uploads with ablage (`pnpm add ablage`, add `'ablage'` to `modules`). wervt gives the app its
105
+ own bucket and `@wervt/nuxt` connects it; don't configure a provider or S3 credentials.
106
+
107
+ - `readUploadedFile(event, { types, maxSize })`, `useFileStorage().put/get/list/remove` and
108
+ `sendStoredFile(event, ref)` (route files without a method suffix) from `#imports`.
109
+ - Keep files to a few tens of MB: they pass through the isolate (150 MB memory). No tus uploads
110
+ and no `transform` / sharp: they need a disk and native modules.
111
+ - Check access in the route before serving a file.
112
+
113
+ ## Tasks (cron)
114
+
115
+ Periodic work (cleanup, syncs, renewals) goes into tasks, not into requests:
116
+
117
+ ```ts
118
+ // server/tasks/presence/sweep.ts → task "presence:sweep"
119
+ import { defineTask, useDb } from '@wervt/nuxt/server'
120
+ import { lt } from 'drizzle-orm'
121
+ import { presence } from '../../db/schema'
122
+
123
+ export default defineTask({
124
+ meta: { description: 'Remove presence older than 5 minutes' },
125
+ async run() {
126
+ await useDb()
127
+ .delete(presence)
128
+ .where(lt(presence.seenAt, new Date(Date.now() - 5 * 60_000)))
129
+ return { result: 'ok' }
130
+ },
131
+ })
132
+ ```
133
+
134
+ ```ts
135
+ // nuxt.config.ts
136
+ nitro: { scheduledTasks: { '*/5 * * * *': ['presence:sweep'] } },
137
+ wervt: { timezone: 'Europe/Berlin' }, // optional, UTC by default
138
+ ```
139
+
140
+ - wervt runs scheduled tasks; `nuxt dev` runs them locally. Import `defineTask` from
141
+ `@wervt/nuxt/server`.
142
+ - A run has the limits of a request (5 minutes, limited CPU). Keep tasks short and idempotent:
143
+ a run that's still going when the next one is due is skipped, and runs missed while wervt was
144
+ down aren't caught up.
145
+ - At most once a minute. Tasks without a schedule can still be run by hand (dashboard or
146
+ `pnpm exec wervt tasks <app> --run <name>`), e.g. for a backfill.
147
+ - Every run is logged: `pnpm exec wervt logs <app> 'type:=Task'`.
148
+
102
149
  ## Don'ts
103
150
 
104
151
  - No Node-only APIs that Deno lacks (`child_process`, native addons, writing to the filesystem).
105
- Store data in Postgres.
152
+ Store data in Postgres and files with ablage.
106
153
  - No long-running work in requests (CPU is limited per request) and no in-memory state that must
107
154
  survive: isolates are started and stopped on demand.
108
- - No WebSockets, SSE hubs or timers that push to clients. Write to the database and let clients
109
- read live data through shapes. No background jobs or cron either: do periodic cleanup lazily in
110
- requests.
155
+ - No WebSockets, SSE hubs or timers (`setInterval`) that push to clients. Write to the database
156
+ and let clients read live data through shapes. For periodic work, use a task (above).
111
157
  - No secrets in client code. Server env vars come from wervt; don't hardcode credentials.
112
158
 
113
159
  ## Logs
@@ -9,13 +9,13 @@
9
9
  "postinstall": "nuxt prepare"
10
10
  },
11
11
  "dependencies": {
12
- "@wervt/nuxt": "^0.2.1",
12
+ "@wervt/nuxt": "^0.2.3",
13
13
  "drizzle-orm": "1.0.0-rc.4",
14
14
  "nuxt": "npm:nuxt-nightly@5x",
15
15
  "valibot": "^1.5.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@wervt/cli": "^0.2.1",
18
+ "@wervt/cli": "^0.2.5",
19
19
  "drizzle-kit": "1.0.0-rc.4",
20
20
  "vite-plus": "^1.0.0"
21
21
  }