toiljs 0.0.85 → 0.0.87

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.
Files changed (132) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +2 -2
  3. package/build/cli/.tsbuildinfo +1 -1
  4. package/build/cli/index.js +303 -293
  5. package/build/compiler/.tsbuildinfo +1 -1
  6. package/build/compiler/config.d.ts +2 -0
  7. package/build/compiler/config.js +1 -0
  8. package/build/compiler/docs.js +8 -24
  9. package/build/compiler/generate.js +4 -2
  10. package/build/compiler/index.d.ts +1 -1
  11. package/build/compiler/index.js +69 -6
  12. package/build/compiler/toil-docs.generated.js +64 -22
  13. package/build/devserver/.tsbuildinfo +1 -1
  14. package/build/devserver/analytics/index.js +7 -3
  15. package/build/devserver/db/database.d.ts +4 -0
  16. package/build/devserver/db/database.js +43 -1
  17. package/build/devserver/db/index.d.ts +1 -1
  18. package/build/devserver/db/index.js +1 -1
  19. package/build/devserver/db/types.d.ts +3 -0
  20. package/build/devserver/db/types.js +2 -0
  21. package/build/devserver/runtime/module.js +4 -1
  22. package/docs/README.md +104 -65
  23. package/docs/auth/README.md +102 -0
  24. package/docs/auth/configuration.md +94 -0
  25. package/docs/auth/extending.md +202 -0
  26. package/docs/auth/how-it-works.md +138 -0
  27. package/docs/auth/usage.md +188 -0
  28. package/docs/backend/README.md +143 -0
  29. package/docs/backend/data.md +351 -0
  30. package/docs/backend/rest.md +402 -0
  31. package/docs/backend/rpc.md +226 -0
  32. package/docs/background/README.md +114 -0
  33. package/docs/background/daemons.md +230 -0
  34. package/docs/background/derive.md +179 -0
  35. package/docs/cli/README.md +377 -0
  36. package/docs/concepts/config.md +416 -0
  37. package/docs/concepts/decorators.md +127 -0
  38. package/docs/concepts/security.md +108 -0
  39. package/docs/concepts/tiers.md +166 -0
  40. package/docs/concepts/types.md +216 -0
  41. package/docs/database/README.md +143 -0
  42. package/docs/database/capacity.md +350 -0
  43. package/docs/database/counters.md +174 -0
  44. package/docs/database/documents.md +255 -0
  45. package/docs/database/events.md +307 -0
  46. package/docs/database/membership.md +246 -0
  47. package/docs/database/setup.md +155 -0
  48. package/docs/database/unique.md +216 -0
  49. package/docs/database/views.md +246 -0
  50. package/docs/frontend/README.md +101 -0
  51. package/docs/frontend/data-fetching.md +243 -0
  52. package/docs/frontend/images.md +148 -0
  53. package/docs/frontend/metadata.md +344 -0
  54. package/docs/frontend/rendering.md +236 -0
  55. package/docs/frontend/routing.md +344 -0
  56. package/docs/frontend/scripts.md +118 -0
  57. package/docs/frontend/search.md +191 -0
  58. package/docs/frontend/styling.md +147 -0
  59. package/docs/getting-started/README.md +81 -0
  60. package/docs/getting-started/create-project.md +131 -0
  61. package/docs/getting-started/deploy.md +101 -0
  62. package/docs/getting-started/first-app.md +215 -0
  63. package/docs/getting-started/installation.md +106 -0
  64. package/docs/getting-started/migrating.md +125 -0
  65. package/docs/getting-started/project-structure.md +163 -0
  66. package/docs/introduction/README.md +41 -0
  67. package/docs/introduction/design-principles.md +55 -0
  68. package/docs/introduction/distributed.md +74 -0
  69. package/docs/introduction/how-it-works.md +74 -0
  70. package/docs/introduction/hyperscale.md +51 -0
  71. package/docs/introduction/modern-stack.md +36 -0
  72. package/docs/introduction/vs-other-frameworks.md +48 -0
  73. package/docs/introduction/why-toil.md +93 -0
  74. package/docs/llms.txt +90 -0
  75. package/docs/realtime/README.md +102 -0
  76. package/docs/realtime/channels.md +211 -0
  77. package/docs/realtime/streams.md +369 -0
  78. package/docs/services/README.md +60 -0
  79. package/docs/services/analytics.md +268 -0
  80. package/docs/services/caching.md +175 -0
  81. package/docs/services/cookies.md +235 -0
  82. package/docs/services/crypto.md +209 -0
  83. package/docs/services/email.md +289 -0
  84. package/docs/services/environment.md +141 -0
  85. package/docs/services/ratelimit.md +174 -0
  86. package/docs/services/time.md +85 -0
  87. package/examples/basic/client/routes/analytics.tsx +13 -12
  88. package/examples/basic/server/models/SiteAnalytics.ts +29 -17
  89. package/examples/basic/server/routes/Analytics.ts +15 -17
  90. package/examples/basic/server/routes/UserId.ts +22 -0
  91. package/package.json +15 -11
  92. package/scripts/gen-toil-docs.mjs +24 -35
  93. package/server/auth/AuthController.ts +336 -0
  94. package/server/auth/AuthUser.ts +23 -0
  95. package/server/auth/index.ts +16 -0
  96. package/server/globals/auth.ts +31 -0
  97. package/server/globals/userid.ts +107 -0
  98. package/src/compiler/config.ts +13 -0
  99. package/src/compiler/docs.ts +16 -33
  100. package/src/compiler/generate.ts +6 -2
  101. package/src/compiler/index.ts +114 -6
  102. package/src/compiler/toil-docs.generated.ts +64 -22
  103. package/src/devserver/analytics/index.ts +10 -4
  104. package/src/devserver/db/database.ts +67 -1
  105. package/src/devserver/db/index.ts +1 -0
  106. package/src/devserver/db/types.ts +13 -0
  107. package/src/devserver/runtime/module.ts +7 -0
  108. package/test/analytics-dev.test.ts +2 -1
  109. package/test/devserver-database.test.ts +113 -0
  110. package/docs/auth-todo.md +0 -149
  111. package/docs/auth.md +0 -322
  112. package/docs/caching.md +0 -115
  113. package/docs/cli.md +0 -17
  114. package/docs/client.md +0 -39
  115. package/docs/cookies.md +0 -457
  116. package/docs/crypto.md +0 -130
  117. package/docs/daemon.md +0 -123
  118. package/docs/data.md +0 -131
  119. package/docs/derive.md +0 -159
  120. package/docs/email.md +0 -326
  121. package/docs/environment.md +0 -97
  122. package/docs/getting-started.md +0 -128
  123. package/docs/index.md +0 -30
  124. package/docs/ratelimit.md +0 -95
  125. package/docs/routing.md +0 -259
  126. package/docs/rpc.md +0 -149
  127. package/docs/server.md +0 -61
  128. package/docs/ssr.md +0 -632
  129. package/docs/streams.md +0 -178
  130. package/docs/styling.md +0 -22
  131. package/docs/tiers.md +0 -133
  132. package/docs/time.md +0 -43
@@ -0,0 +1,377 @@
1
+ # The toiljs CLI
2
+
3
+ The `toiljs` command is how you scaffold, run, build, self-host, and diagnose a toiljs app. This page lists every command and every flag, with copy-pasteable examples.
4
+
5
+ ## What it is
6
+
7
+ When you install the `toiljs` package, it adds one executable to your project: `toiljs`. Everything you do day to day (start the dev server, produce a production build, check your setup) goes through it.
8
+
9
+ You almost never type the full path. A freshly scaffolded project already has npm scripts that call it, so you run `npm run dev` and `npm run build`. When you want a command that has no script (like `doctor` or `db`), run it with `npx`:
10
+
11
+ ```bash
12
+ npx toiljs doctor
13
+ ```
14
+
15
+ `toiljs` needs **Node.js 24 or newer** (older versions will not run it).
16
+
17
+ ## Command overview
18
+
19
+ | Command | What it does |
20
+ | --- | --- |
21
+ | `toiljs create [name]` | Scaffold a brand new toiljs app in a new folder. |
22
+ | `toiljs dev` | Start the local development server with hot reload. |
23
+ | `toiljs build` | Produce the optimized production build (client bundle + server WebAssembly). |
24
+ | `toiljs start` | Self-host the built app on a fast production HTTP server. |
25
+ | `toiljs configure` | Turn styling features (Sass/Less/Stylus, Tailwind) on or off in an existing project. |
26
+ | `toiljs doctor` | Diagnose your project setup and (with `--fix`) repair common wiring. |
27
+ | `toiljs update` | Check npm for newer dependency versions and apply the ones you pick. |
28
+ | `toiljs db <action>` | Inspect, reset, snapshot, or restore the local dev database. |
29
+ | `toiljs help` | Print the built-in help. Also `--help` or `-h`. |
30
+ | `toiljs --version` | Print the installed toiljs version. Also `-v`. |
31
+
32
+ Run `toiljs help` any time to see this list in your terminal.
33
+
34
+ ## Global behavior
35
+
36
+ A few things apply to every command.
37
+
38
+ - **`--root <dir>`**: run the command against a project in another directory instead of the current one. Every command accepts it.
39
+ - **Automatic update check**: on every run (including `npm run dev`, which calls the CLI under the hood), toiljs quietly asks the npm registry whether a newer `toiljs` exists and prints a one-line notice on stderr if you are behind. It never blocks or slows the command in a meaningful way (the answer is cached for an hour and the network call is capped at two seconds). To turn it off, set the environment variable `TOILJS_NO_UPDATE_CHECK=1`. It also respects the common `NO_UPDATE_NOTIFIER` and `CI` variables.
40
+
41
+ ```bash
42
+ # Run any command against a project in another folder.
43
+ toiljs build --root ./apps/marketing
44
+
45
+ # Silence the "newer version available" notice.
46
+ TOILJS_NO_UPDATE_CHECK=1 toiljs dev
47
+ ```
48
+
49
+ ## `toiljs create`
50
+
51
+ Scaffolds a new project into a new folder. By default it is interactive: it asks a short series of questions (project name, template, styling, and so on), then writes the files and installs dependencies. Pass flags to skip questions, or `-y` to accept every default and run with no questions at all.
52
+
53
+ ```bash
54
+ # Interactive: answer the prompts.
55
+ npx toiljs create
56
+
57
+ # Give it a name up front.
58
+ npx toiljs create my-app
59
+
60
+ # Fully non-interactive (great for scripts and CI).
61
+ npx toiljs create my-app --yes --template app --style css
62
+ ```
63
+
64
+ ### What it sets up
65
+
66
+ Every new project comes wired for you: the enforced TypeScript, ESLint, and Prettier presets, file-based routing, a `toil.config.ts`, a `toilconfig.json` (the server compiler settings), a `.gitignore`, and the editor settings that make the toilscript language plugin work. It also scaffolds a `server/migrations/` folder (where ToilDB schema migrations live) and, unless you opt out, a set of AI assistant helper files.
67
+
68
+ The scaffolded `package.json` includes these scripts:
69
+
70
+ | Script | Runs |
71
+ | --- | --- |
72
+ | `npm run dev` | `toiljs dev` |
73
+ | `npm run build` | `toiljs build` |
74
+ | `npm run build:server` | `toiljs build --server` |
75
+ | `npm run lint` | `eslint client` |
76
+ | `npm run typecheck` | `tsc --noEmit` |
77
+ | `npm run format` | `prettier --write ...` |
78
+
79
+ ### Generated docs and AI-assistant pointers
80
+
81
+ Every project carries a full copy of this documentation set at `.toil/docs/`. You do not maintain it: toiljs regenerates it from the installed toiljs version on every `toiljs dev` and `toiljs build`, so it always matches the version you are on. Do not edit those files by hand (your changes are overwritten on the next dev or build).
82
+
83
+ Unless you opt out, `toiljs create` also writes small **pointer files** at the project root that tell AI coding assistants to read `.toil/docs/` before touching the project: `CLAUDE.md` (Claude Code), `AGENTS.md` (Codex and others), `.cursor/rules/toiljs.mdc` (Cursor), and `.github/copilot-instructions.md` (GitHub Copilot). These are written once, committed, and yours to edit. Control them with `--ai` / `--no-ai` (when you pass neither, `create` asks).
84
+
85
+ ### create options
86
+
87
+ | Flag | Meaning |
88
+ | --- | --- |
89
+ | `[name]` | The project folder name (a positional argument). If omitted, you are asked. |
90
+ | `-t, --template <app\|minimal>` | `app` is the full starter (landing page, layout, styles, demo routes). `minimal` is just a layout and a home route. Default `app`. |
91
+ | `--style <css\|sass\|less\|stylus>` | Which CSS flavor to set up. Default `css` (plain CSS). |
92
+ | `--tailwind` / `--no-tailwind` | Add or skip Tailwind CSS (v4). Off by default. |
93
+ | `--ai` / `--no-ai` | Include or skip AI assistant files (like `CLAUDE.md`). When omitted, you are asked. |
94
+ | `--images` / `--no-images` | Enable or skip build-time image optimization. On by default. |
95
+ | `--git` / `--no-git` | Initialize a git repository. When omitted, you are asked (default yes). |
96
+ | `--install` / `--no-install` | Install dependencies after scaffolding. When omitted, you are asked (default yes). |
97
+ | `--pm <npm\|pnpm\|yarn\|bun>` | Which package manager to install with. Default `npm`. |
98
+ | `-y, --yes` | Accept all defaults and skip every prompt. |
99
+
100
+ For a walkthrough, see [Create a project](../getting-started/create-project.md).
101
+
102
+ ## `toiljs dev`
103
+
104
+ Starts the local development server with hot reload, so you edit a file and the browser updates in place. This is the command you leave running while you build.
105
+
106
+ ```bash
107
+ npm run dev
108
+ # or, to pick a port:
109
+ npx toiljs dev --port 4000
110
+ ```
111
+
112
+ ### What the dev server emulates
113
+
114
+ The whole point of the dev server is to run your app locally the same way the real Dacely edge runs it in production, so what you see locally is what you ship. It emulates three things:
115
+
116
+ 1. **The edge.** For a project with a server (any project with a `toilconfig.json`), a small local HTTP server takes the public port and dispatches incoming requests into your compiled `server.wasm` using the exact same request envelope the production edge uses. Anything your server does not claim (page routes, static assets, the hot-reload websocket) is proxied to Vite behind the scenes. So your React frontend and your WebAssembly backend run together, on one URL, exactly like production.
117
+ 2. **The database.** ToilDB runs in-process as a local emulator. Every family (documents, views, unique, events, counters, membership, capacity) works, and the data is written to `.toil/devdata.json` so it survives restarts. You manage that file with [`toiljs db`](#toiljs-db).
118
+ 3. **The host functions.** The platform services your server code calls (email, environment variables and secrets, time, crypto, rate limiting, auth) are wired up locally so they behave like the edge. Email actually sends if you configure a provider (see [Email](../services/email.md)).
119
+
120
+ A **client-only** project (no `toilconfig.json`) just gets the plain Vite dev server on your port, unchanged.
121
+
122
+ ### How hot reload works
123
+
124
+ ```mermaid
125
+ flowchart TD
126
+ E["You edit a file"] --> Q{"Which file?"}
127
+ Q -->|"client/ (React, CSS)"| V["Vite hot-swaps it in the browser"]
128
+ Q -->|"server/ (a @rest / @data / @service file)"| S["toilscript recompiles the server"]
129
+ S --> G["shared/server.ts is regenerated"]
130
+ G --> V2["Vite hot-swaps the new typed client"]
131
+ S --> W["the dev server hot-swaps the new server.wasm"]
132
+ V --> B["Browser updates, no full reload"]
133
+ V2 --> B
134
+ W --> B
135
+ ```
136
+
137
+ Client edits go straight through Vite's hot module replacement. Server edits trigger a toilscript rebuild: toiljs recompiles your backend, regenerates `shared/server.ts` (the typed client the browser imports to call your server), and hot-swaps the recompiled WebAssembly, all without you touching the browser. Rebuilds are debounced (grouped over about 150 milliseconds) so a "save all" or a formatter pass does not trigger a storm of builds.
138
+
139
+ If your project has an `emails/` folder, the dev server also prints an email-preview URL at `/__toil/emails`.
140
+
141
+ ### dev options
142
+
143
+ | Flag | Meaning |
144
+ | --- | --- |
145
+ | `--port <n>` | Port to listen on. Default `3000` (or `client.port` from your config). |
146
+ | `--root <dir>` | Run against a project in another directory. |
147
+
148
+ Press `Ctrl+C` to stop. toiljs restores your terminal and force-exits even if a native listener is slow to close, so you never end up with an orphaned dev server rebuilding in the background.
149
+
150
+ ## `toiljs build`
151
+
152
+ Produces the optimized production build. Run this before you deploy or before `toiljs start`.
153
+
154
+ ```bash
155
+ npm run build
156
+ # or build only the server:
157
+ npx toiljs build --server
158
+ ```
159
+
160
+ ### What it produces
161
+
162
+ A full build runs in a careful order so the pieces line up:
163
+
164
+ ```mermaid
165
+ flowchart LR
166
+ A["Your project"] --> S["1. Compile the server<br/>(toilscript)"]
167
+ S --> W["build/server/release.wasm"]
168
+ S --> R["shared/server.ts<br/>(typed client, regenerated)"]
169
+ R --> C["2. Bundle the client<br/>(Vite)"]
170
+ C --> O["build/client/<br/>(HTML, JS, CSS, assets)"]
171
+ C --> X["3. Prerender + SEO<br/>(SSG pages, robots.txt,<br/>sitemap.xml, llms.txt)"]
172
+ ```
173
+
174
+ 1. **The server is built first.** toilscript compiles every decorated server file (not just the entry) into `build/server/release.wasm`, and regenerates `shared/server.ts`. Doing this first means the client always bundles against a current, correct typed server client. A project that also declares `@stream` or `@daemon` surfaces compiles those into their own artifacts (`release-stream.wasm`, `release-cold.wasm`).
175
+ 2. **The client is bundled** by Vite into `build/client/` (your HTML, JavaScript, CSS, and optimized assets). The dev toolbar and error overlay are stripped out of the production bundle.
176
+ 3. **Static pages and SEO files are generated**: any route that opts into static generation is prerendered to HTML, and if you configured `client.seo`, toiljs writes `robots.txt`, `sitemap.xml`, and `llms.txt`. Routes that opt into server-side rendering get their HTML-with-holes templates baked for the edge.
177
+
178
+ ### build options
179
+
180
+ | Flag | Meaning |
181
+ | --- | --- |
182
+ | `--server` | Build **only** the server (recompile the wasm and regenerate `shared/server.ts`), and skip the client bundle. Fast when you only touched backend code. This is what `npm run build:server` runs. |
183
+ | `--root <dir>` | Run against a project in another directory. |
184
+
185
+ A client-only project (no `toilconfig.json`) skips step 1 and just bundles the client.
186
+
187
+ ## `toiljs start`
188
+
189
+ Self-hosts the app you just built, on a fast production HTTP server (hyper-express, backed by uWebSockets.js). It serves your static client, runs your `server.wasm` for dynamic requests, does server-side rendering, supports daemons, and exposes a `/_toil` websocket channel. Use it to run your app on your own machine or server instead of deploying to the Dacely edge.
190
+
191
+ ```bash
192
+ npm run build # start needs a build to serve
193
+ npx toiljs start
194
+ npx toiljs start --port 8080 --host 0.0.0.0 --threads 4
195
+ ```
196
+
197
+ `start` fails fast if there is no build yet (it looks for `build/client/index.html`), so run `toiljs build` first.
198
+
199
+ ### start options
200
+
201
+ | Flag | Meaning |
202
+ | --- | --- |
203
+ | `--port <n>` | Port to listen on. Default `3000` (or `client.port`). |
204
+ | `--host <host>` | Address to bind. Default `127.0.0.1` (loopback only). Pass `0.0.0.0` to accept connections from other machines. |
205
+ | `--threads <n>` | Number of HTTP worker processes. Default is automatic (one per available CPU). Pass `1` to disable the worker pool. `--workers` is an accepted alias. This can also be set as `server.threads` in your config. |
206
+ | `--root <dir>` | Run against a project in another directory. |
207
+
208
+ ## `toiljs configure`
209
+
210
+ Toggles a project's client styling features (the CSS preprocessor and Tailwind) after the fact, on an existing app. It detects your current setup, asks what you want, then rewrites the stylesheets and your app entry's imports, edits `package.json`, and syncs `node_modules` so removed packages are actually uninstalled.
211
+
212
+ ```bash
213
+ # Interactive.
214
+ npx toiljs configure
215
+
216
+ # Non-interactive: switch to Sass and turn Tailwind on.
217
+ npx toiljs configure --style sass --tailwind
218
+ ```
219
+
220
+ ### configure options
221
+
222
+ | Flag | Meaning |
223
+ | --- | --- |
224
+ | `--style <css\|sass\|less\|stylus>` | Switch the CSS preprocessor. |
225
+ | `--tailwind` / `--no-tailwind` | Turn Tailwind on or off. |
226
+ | `--images` / `--no-images` | Turn build-time image optimization on or off (sets `client.images` in your config). |
227
+ | `--no-install` | Edit the files but do not run the package manager. You then run install yourself. |
228
+ | `--root <dir>` | Run against a project in another directory. |
229
+
230
+ Passing any of `--style`, `--tailwind`, or `--images` makes the command non-interactive (it skips the prompts you did not answer with a flag). See [Styling](../frontend/styling.md) for the full picture.
231
+
232
+ ## `toiljs doctor`
233
+
234
+ Read-only project diagnostics. It gathers facts from disk (your `package.json`, lockfiles, the resolved config, your app entry, `index.html`, your routes, and the server target), runs a set of checks, and prints a grouped report. It never changes anything unless you pass `--fix`, and it never crashes on a partial or non-toiljs project (missing pieces just become warnings or failures). It exits with a non-zero status when any check **fails** (warnings do not fail), so it is safe to run in CI.
235
+
236
+ ```bash
237
+ # Human-readable report.
238
+ npx toiljs doctor
239
+
240
+ # Machine-readable, for CI.
241
+ npx toiljs doctor --json
242
+
243
+ # Auto-repair the common wiring.
244
+ npx toiljs doctor --fix
245
+ ```
246
+
247
+ ### What it checks
248
+
249
+ The report is grouped:
250
+
251
+ | Group | Example checks |
252
+ | --- | --- |
253
+ | **Environment** | Node.js version, that `toiljs` and its peer dependencies (React, TypeScript, and so on) are installed and new enough, that a lockfile exists, and that your scripts do not wrap `toiljs` in a stray `npx`. |
254
+ | **Project + routing** | The `client/` and `routes/` folders exist, `index.html` has a `<div id="root">`, your app entry calls `mount(...)` with the `slots` argument, at least one route exists, no two routes collide on the same URL, and no asset paths are written in a way that 404s on nested routes. |
255
+ | **Config + assets** | Your `toil.config` loads, the base path is well formed, `client.seo` has a `url` if SEO is configured, and your styling packages are actually installed. |
256
+ | **Server / WASM** | The `toilconfig.json` and its entry files exist, `toilscript` is installed, a compiled `.wasm` exists, the typed-RPC wiring is in place, your `@rest` controllers are actually dispatched, the Prettier and editor plugins are wired, and a `migrations/` folder exists. |
257
+ | **Security** | If your server uses auth, whether `AUTH_SESSION_SECRET` is set (an unset secret means sessions fall back to a published dev key, which is forgeable). |
258
+
259
+ ### What `--fix` repairs
260
+
261
+ `--fix` only touches a server project (one with a `toilconfig.json`), and it repairs the wiring that is easy to get wrong or that older projects predate:
262
+
263
+ - adds `--rpcModule shared/server.ts` to your server build scripts,
264
+ - adds `shared` and the `shared/*` path alias to `tsconfig.json`,
265
+ - adds `shared/server.ts` to `.gitignore`,
266
+ - lifts the `toilscript` version floor if it is too old,
267
+ - adds the `toiljs/prettier-plugin` to your Prettier config (so Prettier does not choke on server decorators),
268
+ - adds the toilscript language-service plugin to your server `tsconfig.json` and points VS Code at the workspace TypeScript (so the editor stops false-flagging `@database` collections and `@data` members),
269
+ - refreshes the editor-only server globals declaration file.
270
+
271
+ It is idempotent: it only writes files it actually needs to change, and it tells you which ones changed and which need a manual edit (for example a `tsconfig.json` that contains comments). If it changed `package.json`, run your installer afterward.
272
+
273
+ ### doctor options
274
+
275
+ | Flag | Meaning |
276
+ | --- | --- |
277
+ | `--json` | Emit machine-readable JSON instead of the human report (the banner is suppressed so stdout stays valid JSON). |
278
+ | `--fix` | Repair the server wiring in place, as above. |
279
+ | `--root <dir>` | Run against a project in another directory. |
280
+
281
+ ## `toiljs update`
282
+
283
+ A friendly wrapper over `npm-check-updates`. It checks the registry for newer versions of your dependencies, groups them by how big the jump is (major, minor, patch), lets you pick which to apply (or `-y` to apply all), bumps `package.json`, and runs your package manager's install. It also makes sure your `server/migrations/` folder exists (older projects predate it). `npm-check-updates` runs via `npx`, so it never becomes a permanent dependency of your project.
284
+
285
+ ```bash
286
+ # Interactive picker.
287
+ npx toiljs update
288
+
289
+ # Apply everything, non-interactively.
290
+ npx toiljs update --yes
291
+
292
+ # Only patch-level updates.
293
+ npx toiljs update --target patch
294
+ ```
295
+
296
+ ### update options
297
+
298
+ | Flag | Meaning |
299
+ | --- | --- |
300
+ | `-y, --yes` | Apply all available updates without the picker. |
301
+ | `--target <latest\|minor\|patch\|newest\|greatest>` | How far to bump. Default `latest`. |
302
+ | `--root <dir>` | Run against a project in another directory. |
303
+
304
+ ## `toiljs db`
305
+
306
+ Manages the local dev database: the on-disk ToilDB store your dev server writes to `.toil/devdata.json`. Use it to inspect data, wipe a corrupt state, save a snapshot to share as a fixture, or restore one. The snapshot is exactly the JSON the dev database uses, so an exported file imports cleanly.
307
+
308
+ ```bash
309
+ # See what is stored.
310
+ npx toiljs db status
311
+
312
+ # Wipe all dev data.
313
+ npx toiljs db reset
314
+
315
+ # Save a snapshot (to a file, or to stdout if you omit the file).
316
+ npx toiljs db export fixture.json
317
+
318
+ # Restore a snapshot.
319
+ npx toiljs db import fixture.json
320
+
321
+ # Print the on-disk path (scriptable).
322
+ npx toiljs db path
323
+ ```
324
+
325
+ ### db actions
326
+
327
+ | Action | What it does |
328
+ | --- | --- |
329
+ | `status` (alias `info`) | Show the database path, its size, and per-family row counts. |
330
+ | `reset` (alias `purge`) | Delete all dev data (removes `devdata.json`). |
331
+ | `export [file]` | Write a formatted snapshot to `file`, or to stdout if you omit it (pipe-friendly). |
332
+ | `import <file>` | Replace the dev database with the snapshot in `file`. It refuses a file that is not a valid snapshot. |
333
+ | `path` | Print the `devdata.json` path and nothing else. |
334
+
335
+ The dev database is per-project and lives under `.toil/`, which is gitignored. See [Database setup](../database/setup.md) for what actually populates it.
336
+
337
+ ## The dev, build, and deploy flow
338
+
339
+ Here is how the commands fit together across your workflow.
340
+
341
+ ```mermaid
342
+ flowchart LR
343
+ subgraph Develop
344
+ D["toiljs dev<br/>(hot reload, local edge + DB)"]
345
+ end
346
+ subgraph Ship
347
+ B["toiljs build<br/>(client bundle + server.wasm)"]
348
+ end
349
+ subgraph Run
350
+ ST["toiljs start<br/>(self-host locally)"]
351
+ DP["deploy to the Dacely edge"]
352
+ end
353
+ D --> B
354
+ B --> ST
355
+ B --> DP
356
+ ```
357
+
358
+ - **Develop** with `toiljs dev`. Everything runs locally and reloads as you type.
359
+ - **Ship** with `toiljs build`. This produces the artifacts: the client bundle in `build/client/` and the server WebAssembly in `build/server/`.
360
+ - **Run** the build two ways: `toiljs start` self-hosts it on your own machine, or you deploy the same build to the Dacely edge to serve it worldwide.
361
+
362
+ ## Gotchas
363
+
364
+ - **`start` needs a build.** `toiljs start` serves what is in `build/`. Run `toiljs build` first, or it exits with an error.
365
+ - **Run `toiljs`, not `npx toiljs`, inside npm scripts.** Under `npm run`, `node_modules/.bin` is already on your PATH, so an extra `npx` layer is redundant and can leave your terminal in a broken input mode after `Ctrl+C`. `doctor` warns about this; the scaffold gets it right.
366
+ - **`--host` and `--threads` are `start`-only.** `toiljs dev` always binds locally and does not take `--host` or `--threads`.
367
+ - **`--server` builds the backend only.** Use it while iterating on server code, but run a full `toiljs build` before you deploy so the client bundle is current.
368
+ - **The update notice is not an error.** The "newer toiljs available" line is informational and prints to stderr. Set `TOILJS_NO_UPDATE_CHECK=1` to hide it.
369
+
370
+ ## Related
371
+
372
+ - [Installation](../getting-started/installation.md) and [Create a project](../getting-started/create-project.md)
373
+ - [Project structure](../getting-started/project-structure.md)
374
+ - [Configuration reference (`toil.config.ts`)](../concepts/config.md)
375
+ - [Styling](../frontend/styling.md)
376
+ - [Database setup](../database/setup.md) and the [database overview](../database/README.md)
377
+ - [Compute tiers (L1 to L4)](../concepts/tiers.md)