toiljs 0.0.115 → 0.0.117

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 (326) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +16 -7
  3. package/TYPESCRIPT_LAW.md +1946 -2073
  4. package/build/backend/.tsbuildinfo +1 -1
  5. package/build/cli/.tsbuildinfo +1 -1
  6. package/build/cli/index.js +2375 -258
  7. package/build/client/.tsbuildinfo +1 -1
  8. package/build/client/dev/devtools.js +1 -1
  9. package/build/client/dev/error-overlay.js +1 -1
  10. package/build/client/routing/mount.js +1 -1
  11. package/build/compiler/.tsbuildinfo +1 -1
  12. package/build/compiler/auth-emails.js +7 -3
  13. package/build/compiler/emails.js +1 -1
  14. package/build/compiler/index.d.ts +1 -0
  15. package/build/compiler/index.js +25 -4
  16. package/build/compiler/pages.js +2 -3
  17. package/build/compiler/prerender.d.ts +3 -8
  18. package/build/compiler/prerender.js +88 -127
  19. package/build/compiler/ssg.js +3 -4
  20. package/build/compiler/template-build.js +3 -4
  21. package/build/compiler/toil-docs.generated.js +6 -5
  22. package/build/compiler/vite.js +3 -6
  23. package/build/devserver/.tsbuildinfo +1 -1
  24. package/build/devserver/db/database.js +7 -3
  25. package/build/devserver/db/types.js +1 -1
  26. package/build/devserver/production.js +4 -3
  27. package/build/devserver/runtime/crypto.d.ts +1 -1
  28. package/build/io/.tsbuildinfo +1 -1
  29. package/build/logger/.tsbuildinfo +1 -1
  30. package/build/shared/.tsbuildinfo +1 -1
  31. package/examples/basic/client/routes/analytics.tsx +7 -5
  32. package/examples/basic/server/tsconfig.json +1 -3
  33. package/package.json +45 -44
  34. package/presets/no-uint8array-tostring.js +120 -153
  35. package/presets/oxlint.d.ts +5 -0
  36. package/presets/oxlint.js +224 -0
  37. package/server/runtime/tsconfig.json +1 -3
  38. package/tsconfig.json +2 -11
  39. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  40. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  41. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  42. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  43. package/.github/PULL_REQUEST_TEMPLATE.md +0 -43
  44. package/.github/changelog-config.json +0 -45
  45. package/.github/dependabot.yml +0 -27
  46. package/.github/workflows/ci.yml +0 -222
  47. package/.vscode/settings.json +0 -10
  48. package/docs/README.md +0 -107
  49. package/docs/auth/README.md +0 -104
  50. package/docs/auth/configuration.md +0 -105
  51. package/docs/auth/emails.md +0 -92
  52. package/docs/auth/extending.md +0 -202
  53. package/docs/auth/how-it-works.md +0 -138
  54. package/docs/auth/usage.md +0 -188
  55. package/docs/backend/README.md +0 -143
  56. package/docs/backend/data.md +0 -351
  57. package/docs/backend/rest.md +0 -402
  58. package/docs/backend/rpc.md +0 -226
  59. package/docs/background/README.md +0 -114
  60. package/docs/background/daemons.md +0 -276
  61. package/docs/background/derive.md +0 -179
  62. package/docs/cli/README.md +0 -379
  63. package/docs/concepts/ai-guide.md +0 -132
  64. package/docs/concepts/config.md +0 -416
  65. package/docs/concepts/decorators.md +0 -127
  66. package/docs/concepts/security.md +0 -108
  67. package/docs/concepts/tiers.md +0 -166
  68. package/docs/concepts/types.md +0 -216
  69. package/docs/database/README.md +0 -143
  70. package/docs/database/capacity.md +0 -350
  71. package/docs/database/counters.md +0 -174
  72. package/docs/database/documents.md +0 -277
  73. package/docs/database/events.md +0 -307
  74. package/docs/database/membership.md +0 -246
  75. package/docs/database/setup.md +0 -155
  76. package/docs/database/unique.md +0 -216
  77. package/docs/database/views.md +0 -246
  78. package/docs/frontend/README.md +0 -104
  79. package/docs/frontend/components.md +0 -286
  80. package/docs/frontend/data-fetching.md +0 -260
  81. package/docs/frontend/images.md +0 -148
  82. package/docs/frontend/metadata.md +0 -344
  83. package/docs/frontend/navigation.md +0 -296
  84. package/docs/frontend/rendering.md +0 -236
  85. package/docs/frontend/routing.md +0 -346
  86. package/docs/frontend/scripts.md +0 -118
  87. package/docs/frontend/search.md +0 -191
  88. package/docs/frontend/styling.md +0 -147
  89. package/docs/frontend/toil-global.md +0 -216
  90. package/docs/getting-started/README.md +0 -81
  91. package/docs/getting-started/create-project.md +0 -131
  92. package/docs/getting-started/deploy.md +0 -101
  93. package/docs/getting-started/first-app.md +0 -215
  94. package/docs/getting-started/installation.md +0 -124
  95. package/docs/getting-started/migrating.md +0 -125
  96. package/docs/getting-started/project-structure.md +0 -163
  97. package/docs/introduction/README.md +0 -66
  98. package/docs/introduction/design-principles.md +0 -81
  99. package/docs/introduction/distributed.md +0 -91
  100. package/docs/introduction/how-it-works.md +0 -121
  101. package/docs/introduction/hyperscale.md +0 -70
  102. package/docs/introduction/modern-stack.md +0 -85
  103. package/docs/introduction/vs-other-frameworks.md +0 -64
  104. package/docs/introduction/why-toil.md +0 -99
  105. package/docs/llms.txt +0 -95
  106. package/docs/realtime/README.md +0 -102
  107. package/docs/realtime/channels.md +0 -211
  108. package/docs/realtime/streams.md +0 -369
  109. package/docs/services/README.md +0 -60
  110. package/docs/services/analytics.md +0 -279
  111. package/docs/services/caching.md +0 -175
  112. package/docs/services/cookies.md +0 -235
  113. package/docs/services/crypto.md +0 -209
  114. package/docs/services/email.md +0 -289
  115. package/docs/services/environment.md +0 -141
  116. package/docs/services/ratelimit.md +0 -174
  117. package/docs/services/time.md +0 -85
  118. package/eslint.config.js +0 -57
  119. package/examples/basic/client/routes/docs/[...slug].tsx +0 -12
  120. package/presets/eslint.js +0 -88
  121. package/src/backend/index.ts +0 -204
  122. package/src/cli/configure.ts +0 -363
  123. package/src/cli/create.ts +0 -924
  124. package/src/cli/db.ts +0 -158
  125. package/src/cli/diagnostics.ts +0 -665
  126. package/src/cli/doctor.ts +0 -982
  127. package/src/cli/features.ts +0 -170
  128. package/src/cli/index.ts +0 -326
  129. package/src/cli/notify.ts +0 -120
  130. package/src/cli/proc.ts +0 -56
  131. package/src/cli/ui.ts +0 -169
  132. package/src/cli/update.ts +0 -248
  133. package/src/cli/updates.ts +0 -92
  134. package/src/cli/validate.ts +0 -31
  135. package/src/cli/version-check.ts +0 -125
  136. package/src/client/auth.ts +0 -869
  137. package/src/client/channel/channel.ts +0 -146
  138. package/src/client/components/Form.tsx +0 -65
  139. package/src/client/components/Image.tsx +0 -160
  140. package/src/client/components/Script.tsx +0 -113
  141. package/src/client/components/Slot.tsx +0 -21
  142. package/src/client/dev/devtools.tsx +0 -1089
  143. package/src/client/dev/error-overlay.tsx +0 -225
  144. package/src/client/errors.ts +0 -11
  145. package/src/client/head/head.ts +0 -182
  146. package/src/client/head/metadata.ts +0 -110
  147. package/src/client/index.ts +0 -130
  148. package/src/client/navigation/Link.tsx +0 -108
  149. package/src/client/navigation/NavLink.tsx +0 -86
  150. package/src/client/navigation/navigation.ts +0 -235
  151. package/src/client/navigation/prefetch.ts +0 -169
  152. package/src/client/navigation/scroll.ts +0 -53
  153. package/src/client/routing/Router.tsx +0 -216
  154. package/src/client/routing/action.ts +0 -122
  155. package/src/client/routing/error-boundary.tsx +0 -43
  156. package/src/client/routing/hooks.ts +0 -140
  157. package/src/client/routing/lazy.ts +0 -77
  158. package/src/client/routing/loader.ts +0 -381
  159. package/src/client/routing/match.ts +0 -47
  160. package/src/client/routing/mount.tsx +0 -90
  161. package/src/client/routing/params-context.ts +0 -10
  162. package/src/client/routing/slot-context.ts +0 -7
  163. package/src/client/rpc.ts +0 -97
  164. package/src/client/search/search.ts +0 -189
  165. package/src/client/search/use-page-search.ts +0 -73
  166. package/src/client/ssr/markers.tsx +0 -172
  167. package/src/client/stream/client.ts +0 -237
  168. package/src/client/types.ts +0 -73
  169. package/src/compiler/auth-emails.ts +0 -312
  170. package/src/compiler/config.ts +0 -369
  171. package/src/compiler/docs.ts +0 -127
  172. package/src/compiler/email-preview.ts +0 -314
  173. package/src/compiler/emails.ts +0 -404
  174. package/src/compiler/fonts.ts +0 -89
  175. package/src/compiler/generate.ts +0 -471
  176. package/src/compiler/image-blur.ts +0 -42
  177. package/src/compiler/image-report.ts +0 -88
  178. package/src/compiler/index.ts +0 -1362
  179. package/src/compiler/pages.ts +0 -49
  180. package/src/compiler/plugin.ts +0 -391
  181. package/src/compiler/prerender.ts +0 -263
  182. package/src/compiler/routes.ts +0 -170
  183. package/src/compiler/seo.ts +0 -415
  184. package/src/compiler/sri.ts +0 -144
  185. package/src/compiler/ssg.ts +0 -177
  186. package/src/compiler/ssr-codegen.ts +0 -85
  187. package/src/compiler/template-build.ts +0 -676
  188. package/src/compiler/template.ts +0 -262
  189. package/src/compiler/toil-docs.generated.ts +0 -77
  190. package/src/compiler/vite.ts +0 -245
  191. package/src/devserver/analytics/index.ts +0 -317
  192. package/src/devserver/config/dotenv.ts +0 -102
  193. package/src/devserver/config/env.ts +0 -30
  194. package/src/devserver/config/ratelimit.ts +0 -123
  195. package/src/devserver/daemon/catalog.ts +0 -120
  196. package/src/devserver/daemon/cron.ts +0 -87
  197. package/src/devserver/daemon/host.ts +0 -134
  198. package/src/devserver/daemon/index.ts +0 -369
  199. package/src/devserver/daemon/runtime.ts +0 -48
  200. package/src/devserver/db/catalog.ts +0 -109
  201. package/src/devserver/db/database.ts +0 -1834
  202. package/src/devserver/db/derives.ts +0 -121
  203. package/src/devserver/db/index.ts +0 -20
  204. package/src/devserver/db/routeKinds.ts +0 -191
  205. package/src/devserver/db/types.ts +0 -168
  206. package/src/devserver/email/caps.ts +0 -0
  207. package/src/devserver/email/config.ts +0 -141
  208. package/src/devserver/email/console.ts +0 -348
  209. package/src/devserver/email/index.ts +0 -155
  210. package/src/devserver/email/providers.ts +0 -131
  211. package/src/devserver/email/status.ts +0 -23
  212. package/src/devserver/email/validate.ts +0 -37
  213. package/src/devserver/email/wire.ts +0 -55
  214. package/src/devserver/http/cache.ts +0 -0
  215. package/src/devserver/http/envelope.ts +0 -157
  216. package/src/devserver/http/proxy.ts +0 -172
  217. package/src/devserver/http/runtime.ts +0 -387
  218. package/src/devserver/index.ts +0 -43
  219. package/src/devserver/production-ipc.ts +0 -63
  220. package/src/devserver/production-worker.ts +0 -83
  221. package/src/devserver/production.ts +0 -718
  222. package/src/devserver/runtime/crypto.ts +0 -587
  223. package/src/devserver/runtime/host.ts +0 -427
  224. package/src/devserver/runtime/module.ts +0 -442
  225. package/src/devserver/server.ts +0 -251
  226. package/src/devserver/ssr.ts +0 -208
  227. package/src/devserver/stream/catalog.ts +0 -106
  228. package/src/devserver/stream/host.ts +0 -42
  229. package/src/devserver/stream/index.ts +0 -301
  230. package/src/devserver/stream/manager.ts +0 -167
  231. package/src/devserver/stream/router.ts +0 -101
  232. package/src/devserver/stream/wire.ts +0 -58
  233. package/src/devserver/stream/ws.ts +0 -78
  234. package/src/devserver/wasm/sections.ts +0 -59
  235. package/src/devserver/wasm/surface.ts +0 -115
  236. package/src/io/FastMap.ts +0 -151
  237. package/src/io/FastSet.ts +0 -113
  238. package/src/io/codec.ts +0 -362
  239. package/src/io/index.ts +0 -10
  240. package/src/io/lengths.ts +0 -14
  241. package/src/io/types.ts +0 -19
  242. package/src/logger/index.ts +0 -22
  243. package/src/shared/index.ts +0 -46
  244. package/test/analytics-dev.test.ts +0 -113
  245. package/test/assembly/aspect-shim.ts +0 -33
  246. package/test/assembly/cookie.spec.ts +0 -303
  247. package/test/assembly/example.spec.ts +0 -22
  248. package/test/assembly/ssr.spec.ts +0 -95
  249. package/test/assembly.test.ts +0 -59
  250. package/test/auth-emails.test.ts +0 -118
  251. package/test/built-ssr.test.ts +0 -148
  252. package/test/channel.test.ts +0 -21
  253. package/test/config-host-port.test.ts +0 -59
  254. package/test/configure.test.ts +0 -94
  255. package/test/daemon-build.test.ts +0 -278
  256. package/test/daemon-catalog.test.ts +0 -349
  257. package/test/daemon-emulation.test.ts +0 -256
  258. package/test/db.test.ts +0 -0
  259. package/test/devserver-database.test.ts +0 -1102
  260. package/test/devserver-email.test.ts +0 -306
  261. package/test/devserver-pqauth.test.ts +0 -93
  262. package/test/devserver-secrets.test.ts +0 -63
  263. package/test/devserver.test.ts +0 -259
  264. package/test/doctor.test.ts +0 -298
  265. package/test/dom/Image.test.tsx +0 -144
  266. package/test/dom/Link.test.tsx +0 -67
  267. package/test/dom/NavLink.test.tsx +0 -37
  268. package/test/dom/Script.test.tsx +0 -48
  269. package/test/dom/action.test.tsx +0 -146
  270. package/test/dom/error-overlay.test.tsx +0 -44
  271. package/test/dom/loader.test.tsx +0 -121
  272. package/test/dom/navigation.test.ts +0 -59
  273. package/test/dom/revalidate.test.tsx +0 -38
  274. package/test/dom/route-head.test.tsx +0 -56
  275. package/test/dom/router-loading.test.tsx +0 -44
  276. package/test/dom/scroll.test.ts +0 -56
  277. package/test/dom/slot.test.tsx +0 -131
  278. package/test/dom/use-metadata.test.tsx +0 -58
  279. package/test/dom/view-transitions.test.tsx +0 -53
  280. package/test/dynamic-routing.test.ts +0 -132
  281. package/test/email-console.test.ts +0 -86
  282. package/test/email-preview.test.ts +0 -73
  283. package/test/emails.test.ts +0 -58
  284. package/test/errors.test.ts +0 -21
  285. package/test/example-guestbook.test.ts +0 -123
  286. package/test/features.test.ts +0 -149
  287. package/test/fixtures/bignum-wire/spec.ts +0 -25
  288. package/test/fixtures/daemon-app.ts +0 -65
  289. package/test/fixtures/stream-echo.ts +0 -26
  290. package/test/fixtures/stream-gate.ts +0 -28
  291. package/test/fixtures/stream-trap.ts +0 -18
  292. package/test/fixtures/stream-typed.ts +0 -41
  293. package/test/fonts.test.ts +0 -28
  294. package/test/global-setup.ts +0 -17
  295. package/test/head.test.ts +0 -42
  296. package/test/image-blur.test.ts +0 -50
  297. package/test/io.test.ts +0 -117
  298. package/test/metadata.test.ts +0 -40
  299. package/test/navlink.test.ts +0 -28
  300. package/test/pages.test.ts +0 -105
  301. package/test/placeholder.test.ts +0 -9
  302. package/test/pqauth-e2e.test.ts +0 -216
  303. package/test/pqauth-email.test.ts +0 -801
  304. package/test/prerender.test.ts +0 -116
  305. package/test/prettier-plugin.test.ts +0 -46
  306. package/test/routes.test.ts +0 -76
  307. package/test/rpc-bignum-wire.test.ts +0 -164
  308. package/test/rpc-dispatch.test.ts +0 -132
  309. package/test/rpc-kinds.test.ts +0 -18
  310. package/test/rpc.test.ts +0 -66
  311. package/test/search.test.ts +0 -114
  312. package/test/seo.test.ts +0 -175
  313. package/test/slot-layouts.test.ts +0 -69
  314. package/test/sri.test.ts +0 -129
  315. package/test/ssg.test.ts +0 -36
  316. package/test/ssr-hydration.test.tsx +0 -122
  317. package/test/ssr-render.test.ts +0 -197
  318. package/test/ssr-template.test.tsx +0 -482
  319. package/test/stream-emulation.test.ts +0 -479
  320. package/test/ui.test.ts +0 -40
  321. package/test/update.test.ts +0 -58
  322. package/test/validate.test.ts +0 -42
  323. package/test/version-check.test.ts +0 -130
  324. package/tests/data-parity/generated-parity.ts +0 -99
  325. package/tests/data-parity/parity.ts +0 -80
  326. package/tests/data-parity/spec.ts +0 -46
@@ -1,379 +0,0 @@
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 and so on) are installed and new enough, that your TypeScript is a supported 6.x rather than the unsupported native 7.x, 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` pins an unsupported TypeScript (the native 7.x, which ships no compiler API) back to `^6.0.3` in any project. The rest only touch a server project (one with a `toilconfig.json`), repairing 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
- Upgrades into a major toiljs does not support are held back and listed separately, so neither the picker nor `-y` can install one. Today that means **TypeScript 7**, the native port, which ships no JavaScript compiler API (see [Installation](../getting-started/installation.md)). Bumps inside TypeScript 6 are still offered.
286
-
287
- ```bash
288
- # Interactive picker.
289
- npx toiljs update
290
-
291
- # Apply everything, non-interactively.
292
- npx toiljs update --yes
293
-
294
- # Only patch-level updates.
295
- npx toiljs update --target patch
296
- ```
297
-
298
- ### update options
299
-
300
- | Flag | Meaning |
301
- | --- | --- |
302
- | `-y, --yes` | Apply all available updates without the picker. |
303
- | `--target <latest\|minor\|patch\|newest\|greatest>` | How far to bump. Default `latest`. |
304
- | `--root <dir>` | Run against a project in another directory. |
305
-
306
- ## `toiljs db`
307
-
308
- 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.
309
-
310
- ```bash
311
- # See what is stored.
312
- npx toiljs db status
313
-
314
- # Wipe all dev data.
315
- npx toiljs db reset
316
-
317
- # Save a snapshot (to a file, or to stdout if you omit the file).
318
- npx toiljs db export fixture.json
319
-
320
- # Restore a snapshot.
321
- npx toiljs db import fixture.json
322
-
323
- # Print the on-disk path (scriptable).
324
- npx toiljs db path
325
- ```
326
-
327
- ### db actions
328
-
329
- | Action | What it does |
330
- | --- | --- |
331
- | `status` (alias `info`) | Show the database path, its size, and per-family row counts. |
332
- | `reset` (alias `purge`) | Delete all dev data (removes `devdata.json`). |
333
- | `export [file]` | Write a formatted snapshot to `file`, or to stdout if you omit it (pipe-friendly). |
334
- | `import <file>` | Replace the dev database with the snapshot in `file`. It refuses a file that is not a valid snapshot. |
335
- | `path` | Print the `devdata.json` path and nothing else. |
336
-
337
- The dev database is per-project and lives under `.toil/`, which is gitignored. See [Database setup](../database/setup.md) for what actually populates it.
338
-
339
- ## The dev, build, and deploy flow
340
-
341
- Here is how the commands fit together across your workflow.
342
-
343
- ```mermaid
344
- flowchart LR
345
- subgraph Develop
346
- D["toiljs dev<br/>(hot reload, local edge + DB)"]
347
- end
348
- subgraph Ship
349
- B["toiljs build<br/>(client bundle + server.wasm)"]
350
- end
351
- subgraph Run
352
- ST["toiljs start<br/>(self-host locally)"]
353
- DP["deploy to the Dacely edge"]
354
- end
355
- D --> B
356
- B --> ST
357
- B --> DP
358
- ```
359
-
360
- - **Develop** with `toiljs dev`. Everything runs locally and reloads as you type.
361
- - **Ship** with `toiljs build`. This produces the artifacts: the client bundle in `build/client/` and the server WebAssembly in `build/server/`.
362
- - **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.
363
-
364
- ## Gotchas
365
-
366
- - **`start` needs a build.** `toiljs start` serves what is in `build/`. Run `toiljs build` first, or it exits with an error.
367
- - **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.
368
- - **`--host` and `--threads` are `start`-only.** `toiljs dev` always binds locally and does not take `--host` or `--threads`.
369
- - **`--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.
370
- - **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.
371
-
372
- ## Related
373
-
374
- - [Installation](../getting-started/installation.md) and [Create a project](../getting-started/create-project.md)
375
- - [Project structure](../getting-started/project-structure.md)
376
- - [Configuration reference (`toil.config.ts`)](../concepts/config.md)
377
- - [Styling](../frontend/styling.md)
378
- - [Database setup](../database/setup.md) and the [database overview](../database/README.md)
379
- - [Compute tiers (L1 to L4)](../concepts/tiers.md)
@@ -1,132 +0,0 @@
1
- # Writing toiljs correctly
2
-
3
- This is a fast, high-signal cheat-sheet for writing toiljs and toilscript code that compiles and behaves. It is aimed at AI assistants generating code (and at humans in a hurry): the patterns to follow, the mistakes to avoid, and a link to the deep page whenever you need more. It does not re-teach the framework; each section points you at the authoritative doc.
4
-
5
- ## Project shape
6
-
7
- A toiljs project has three top-level folders, and knowing which one a file belongs to tells you which rules apply:
8
-
9
- - **`client/`**: your React app that runs in the browser. Pages live under `client/routes/`, one file per URL, and each route file `export default`s its component. See [Frontend](../frontend/README.md) and [Routing](../frontend/routing.md).
10
- - **`shared/`**: a generated typed bridge (`shared/server.ts`) that lets the browser call the backend with full types. It is regenerated on every build, so **never hand-edit it**.
11
- - **`server/`**: your backend, written in TypeScript but compiled by **toilscript** to WebAssembly. It runs on the Dacely edge, not in Node or the browser. See [Backend](../backend/README.md).
12
-
13
- Most code runs on the L1 request tier. Long-lived connections (`@stream`) and scheduled work (`@daemon`) are opt-in tiers in their own entry files. See [Compute tiers](./tiers.md).
14
-
15
- ## Client rules (the browser, React side)
16
-
17
- **Call the backend only through the generated `Server` client.** This is the number one rule. Use `Server.REST.<controller>.<route>(args)` for `@rest` HTTP controllers, or `Server.<service>.<method>(args)` / `Server.<remote>(args)` for RPC. Raw `fetch` to your own backend throws away the type safety, the argument and result decoding, and the binary wire codec, and it silently breaks when a route is renamed. `fetch` is only for third-party URLs (an external API, a CDN). See [Fetching data](../frontend/data-fetching.md).
18
-
19
- ```ts
20
- // WRONG: raw fetch to your own backend
21
- await fetch('/account/session', { method: 'POST' });
22
-
23
- // RIGHT: the typed client (renames become compile errors; args + result typed)
24
- await Server.REST.account.session();
25
- ```
26
-
27
- **Use the ambient `Toil.*` globals with no import.** `Toil` is the `toiljs/client` package exposed as a global and typed via a generated `toil-env.d.ts`, so it autocompletes with no import: `Toil.Link` / `Toil.NavLink` for navigation, `Toil.useParams`, `Toil.useLoaderData`, `Toil.Image`, `Toil.useHead` / `Toil.Head`, `Toil.Form` / `Toil.useAction`, and more. `Server` and `parseError` are also bare globals; `FastMap`, `FastSet`, `DataWriter`, and `DataReader` are bare globals too (write `new DataWriter()`, not `new Toil.DataWriter()`). Full index: [The Toil global](../frontend/toil-global.md).
28
-
29
- **Load page data with a `loader`, not a `useEffect` fetch.** A route file exports a `loader`, and the component reads its result with `Toil.useLoaderData`. The loader runs on navigation in parallel with the route chunk, integrates with `loading.tsx`, caching, and SSR hydration. A `useEffect` fetch runs only after mount (slower, invisible to the server).
30
-
31
- ```tsx
32
- // client/routes/blog/[id].tsx
33
- export const loader = async ({ params }: Toil.LoaderArgs) => {
34
- return Server.REST.blog.get({ params: { id: params.id } });
35
- };
36
-
37
- export default function BlogPost() {
38
- const post = Toil.useLoaderData<typeof loader>();
39
- return <article><h1>{post.title}</h1></article>;
40
- }
41
- ```
42
-
43
- **Mutate with `Toil.useAction` or `<Toil.Form>`, then revalidate.** Both track pending and error state and refetch the affected loader data on success, so the page updates without a manual refetch. Use `<Toil.Form>` for form submits, `useAction` for anything else (a delete button, a toggle). Reach for `Toil.revalidate()` / `router.revalidate()` after a write that these do not cover.
44
-
45
- **Per-route SEO with `export const metadata`** (or `Toil.useHead` / `<Toil.Head>` from inside a component). Opt a route into edge SSR with `export const ssr = true`. See [Metadata and SEO](../frontend/metadata.md) and [Rendering and SSR](../frontend/rendering.md).
46
-
47
- **Typed hrefs.** `Toil.Link` `href`, `Toil.navigate`, and `router.push` are all type-checked against your real routes, so a typo is a compile error. Use `Toil.href(str)` only when a URL is assembled from data and TypeScript cannot prove it is a real route. See [Navigation](../frontend/navigation.md).
48
-
49
- **`getUser()` on the client is display-only.** It reads a readable session cookie with no network call, so it is instant but **forgeable**. Use it to render "logged in as ...", never to gate real access. The authoritative check is a server route guarded with `@auth`. See [Auth usage](../auth/usage.md).
50
-
51
- ## Server rules (toilscript, compiles to WASM)
52
-
53
- The decorators, each doing one job (full list in [Decorators](./decorators.md)):
54
-
55
- - **`@data`** on a class: generates the binary and JSON codec so the value can cross the wire and the database. Every field needs a default; field order **is** the binary layout, so add new fields at the end. See [Data types](../backend/data.md).
56
- - **`@rest('name')`** on a class mounts an HTTP controller at `/name`; **`@get`/`@post`/`@put`/`@del`/`@patch`** on its methods declare routes (`@del`, not `@delete`, which is reserved). See [REST](../backend/rest.md).
57
- - **`@service`** + **`@remote`** expose typed RPC callable from your own frontend as `Server.<service>.<method>()`. See [RPC](../backend/rpc.md).
58
- - **`@user`** declares the authenticated-user shape and enables `AuthService.getUser()`. **Exactly one `@user` per project.** **`@auth`** guards a route or a whole `@rest` class. See [Auth](../auth/README.md).
59
- - **`@ratelimit(strategy, limit, window)`** caps how often a caller may hit a route, rejected at the edge before your code runs. See [Security](./security.md).
60
- - **`@database`** + **`@collection`** declare a ToilDB schema (below).
61
-
62
- ```ts
63
- @rest('players')
64
- class Players {
65
- @get('/:id')
66
- public get(ctx: RouteContext): Response {
67
- const id = ctx.param('id');
68
- return Response.json(`{"id":"${id}"}`);
69
- }
70
- }
71
- ```
72
-
73
- **`@auth` rejects with 401 before your handler runs.** So inside an `@auth`-guarded handler, `AuthService.getUser()!` is guaranteed non-null and safe to assert. Without `@auth`, `getUser()` can be null, so null-check it instead. Either way the server re-verifies the signed session, so it (not the client cookie) is the real authorization boundary.
74
-
75
- ```ts
76
- @auth
77
- @get('/settings')
78
- public settings(): Response {
79
- const user = AuthService.getUser()!; // safe: @auth guarantees a session
80
- return Response.text('hi ' + user.username);
81
- }
82
- ```
83
-
84
- **Server code is a strict, WASM-targeted dialect (AssemblyScript), not full TypeScript.** The real constraints, verified against the toilscript standard library:
85
-
86
- - **Use explicit value types**, never `number`: `i32` / `u32` / `i64` / `u64` / `f64` (and `i8`/`u8`/`i16`/`u16`/`f32`, plus `u128`..`u256`), `bool`, `string`, `Uint8Array`. Plain `number` resolves to `f64`, which is wrong for ids and counts. Integer math **wraps** on overflow (it never throws), and integer `/` truncates. See [The type system](./types.md).
87
- - **No `any`.** Every value has a concrete type; that is what lets it compile to WASM.
88
- - **No arbitrary npm.** Only the toilscript standard library plus the toiljs host APIs.
89
- - **Use `null`, not `undefined`** for "no value" (`T | null`, narrowed with `if (x != null)` or a `!` assertion).
90
- - **No usable built-in `RegExp`** (it is a host stub that throws). Parse strings by hand.
91
- - **Structured values are `@data` classes, not object literals.** Encode and decode raw binary with `DataWriter` / `DataReader` (imported on the server from the `data` module: `import { DataWriter, DataReader } from 'data';`). For dynamic JSON, use the ambient `JSON` value tree.
92
- - **Read config with `Environment.get(key)` and secrets with `Environment.getSecure(key)`** (each returns `string | null`; the two buckets are disjoint so a secret can never leak through `get`). See [Environment](../services/environment.md).
93
- - **Return a runtime `Response`** (`Response.json` / `.text` / `.html` / `.bytes` / `.notFound` / ...), or return a `@data` value and let toiljs serialize it.
94
-
95
- **ToilDB has seven collection families; pick the one that matches the job** (do not force everything into one). Declare each as a `static` `@collection` field on a `@database` class, typed by its family, and reach it statically (`AppDb.users.get(...)`). See [The database](../database/README.md) and [Setup](../database/setup.md).
96
-
97
- - **`Documents<K,V>`**: the default record store, looked up by id (users, posts, orders).
98
- - **`Unique<K,V>`**: a globally one-of-a-kind claim (usernames, emails, slugs).
99
- - **`Counter<K>`**: a running total many callers bump at once (likes, views); `add` a delta only.
100
- - **`Events<K,V>`**: an append-only log kept in order (feeds, audit trails).
101
- - **`Capacity<K>`**: a limited quantity handed out without overselling (tickets, seats).
102
- - **`Membership<K,M>`**: sets of who belongs to what (followers, tags, room members).
103
- - **`View<K,V>`**: a precomputed read-optimized snapshot (leaderboards, home pages).
104
-
105
- **Data access is gated by function kind.** A `@get` route is a read-only **Query**; a `@post` route is an **Action** (may write); a plain `@remote` defaults to read-only Query, so add **`@action`** to let it write. Scans (`events.latest`, `membership.list`) are barred from request handlers: do them in a `@derive` and have the request read the resulting `View`. The compiler enforces this and the edge re-checks it.
106
-
107
- ## Common mistakes
108
-
109
- A short do-not list. Every one of these is a real, avoidable error:
110
-
111
- - **Raw `fetch` to your own backend.** Go through `Server.*` instead.
112
- - **Importing `Toil.*`.** They are ambient globals; importing them is wrong.
113
- - **Fetching page data in a `useEffect`.** Use a route `loader` + `Toil.useLoaderData`.
114
- - **A plain `<a>` for in-app links.** Use `Toil.Link` (a bare `<a>` triggers a full reload).
115
- - **More than one `@user`.** Exactly one per project.
116
- - **Trusting client `getUser()` for authorization.** It is display-only and forgeable; enforce on the server with `@auth`.
117
- - **`any`, `number`, or `RegExp` in server code.** Use explicit value types; there is no usable `RegExp`.
118
- - **Reordering `@data` fields** (or changing a field type) on a stored type. Field order is the layout; add at the end and use `@migrate` to evolve. See [Data types](../backend/data.md).
119
- - **Writing from a plain `@remote` or `@get`.** Reads are the default; a write needs `@action`.
120
- - **Calling a scan (`events.latest`, `membership.list`) from a request handler.** Do it in a `@derive`.
121
- - **Hand-editing `shared/server.ts` or `.toil/`.** They are generated; rebuild instead.
122
-
123
- ## Where to go deeper
124
-
125
- - Concepts: [Decorators](./decorators.md), [Type system](./types.md), [Security](./security.md), [Compute tiers](./tiers.md).
126
- - Backend: [Overview](../backend/README.md), [REST](../backend/rest.md), [RPC](../backend/rpc.md), [Data types](../backend/data.md).
127
- - Frontend: [Overview](../frontend/README.md), [Fetching data](../frontend/data-fetching.md), [Routing](../frontend/routing.md), [Navigation](../frontend/navigation.md), [The Toil global](../frontend/toil-global.md).
128
- - Database: [ToilDB overview](../database/README.md), [Setup](../database/setup.md).
129
- - Auth: [Overview](../auth/README.md), [Usage](../auth/usage.md).
130
- - Services: [Environment](../services/environment.md), [Rate limiting](../services/ratelimit.md).
131
- </content>
132
- </invoke>