toiljs 0.0.116 → 0.0.118

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 (337) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +16 -7
  3. package/build/backend/.tsbuildinfo +1 -1
  4. package/build/cli/.tsbuildinfo +1 -1
  5. package/build/cli/index.js +2375 -258
  6. package/build/client/.tsbuildinfo +1 -1
  7. package/build/client/auth.d.ts +3 -0
  8. package/build/client/auth.js +19 -10
  9. package/build/client/dev/devtools.js +1 -1
  10. package/build/client/dev/error-overlay.js +1 -1
  11. package/build/client/index.d.ts +1 -1
  12. package/build/client/index.js +1 -1
  13. package/build/client/navigation/navigation.js +28 -3
  14. package/build/client/routing/Router.js +5 -2
  15. package/build/client/routing/mount.js +1 -1
  16. package/build/compiler/.tsbuildinfo +1 -1
  17. package/build/compiler/auth-emails.js +7 -3
  18. package/build/compiler/emails.js +1 -1
  19. package/build/compiler/index.d.ts +1 -0
  20. package/build/compiler/index.js +26 -5
  21. package/build/compiler/pages.js +2 -3
  22. package/build/compiler/prerender.d.ts +3 -8
  23. package/build/compiler/prerender.js +88 -127
  24. package/build/compiler/ssg.js +3 -4
  25. package/build/compiler/template-build.js +3 -4
  26. package/build/compiler/toil-docs.generated.js +8 -7
  27. package/build/compiler/vite.js +4 -6
  28. package/build/devserver/.tsbuildinfo +1 -1
  29. package/build/devserver/db/database.js +7 -3
  30. package/build/devserver/db/types.js +1 -1
  31. package/build/devserver/production.js +4 -3
  32. package/build/devserver/runtime/crypto.d.ts +1 -1
  33. package/build/io/.tsbuildinfo +1 -1
  34. package/build/logger/.tsbuildinfo +1 -1
  35. package/build/shared/.tsbuildinfo +1 -1
  36. package/examples/basic/client/routes/analytics.tsx +7 -5
  37. package/examples/basic/client/routes/pq.tsx +2 -1
  38. package/examples/basic/server/tsconfig.json +1 -3
  39. package/package.json +45 -44
  40. package/presets/no-uint8array-tostring.js +120 -153
  41. package/presets/oxlint.d.ts +5 -0
  42. package/presets/oxlint.js +224 -0
  43. package/server/auth/AuthController.ts +53 -14
  44. package/server/auth/FactorSettings.ts +41 -0
  45. package/server/auth/SessionEpochs.ts +58 -0
  46. package/server/auth/SessionRevocations.ts +13 -0
  47. package/server/globals/auth.ts +27 -2
  48. package/server/runtime/tsconfig.json +1 -3
  49. package/tsconfig.json +2 -11
  50. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  51. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  52. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  53. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  54. package/.github/PULL_REQUEST_TEMPLATE.md +0 -43
  55. package/.github/changelog-config.json +0 -45
  56. package/.github/dependabot.yml +0 -27
  57. package/.github/workflows/ci.yml +0 -222
  58. package/.vscode/settings.json +0 -10
  59. package/docs/README.md +0 -107
  60. package/docs/auth/README.md +0 -104
  61. package/docs/auth/configuration.md +0 -105
  62. package/docs/auth/emails.md +0 -92
  63. package/docs/auth/extending.md +0 -202
  64. package/docs/auth/how-it-works.md +0 -138
  65. package/docs/auth/usage.md +0 -188
  66. package/docs/backend/README.md +0 -143
  67. package/docs/backend/data.md +0 -351
  68. package/docs/backend/rest.md +0 -402
  69. package/docs/backend/rpc.md +0 -226
  70. package/docs/background/README.md +0 -114
  71. package/docs/background/daemons.md +0 -276
  72. package/docs/background/derive.md +0 -179
  73. package/docs/cli/README.md +0 -379
  74. package/docs/concepts/ai-guide.md +0 -132
  75. package/docs/concepts/config.md +0 -416
  76. package/docs/concepts/decorators.md +0 -127
  77. package/docs/concepts/security.md +0 -108
  78. package/docs/concepts/tiers.md +0 -166
  79. package/docs/concepts/types.md +0 -216
  80. package/docs/database/README.md +0 -143
  81. package/docs/database/capacity.md +0 -350
  82. package/docs/database/counters.md +0 -174
  83. package/docs/database/documents.md +0 -277
  84. package/docs/database/events.md +0 -307
  85. package/docs/database/membership.md +0 -246
  86. package/docs/database/setup.md +0 -155
  87. package/docs/database/unique.md +0 -216
  88. package/docs/database/views.md +0 -246
  89. package/docs/frontend/README.md +0 -104
  90. package/docs/frontend/components.md +0 -286
  91. package/docs/frontend/data-fetching.md +0 -260
  92. package/docs/frontend/images.md +0 -148
  93. package/docs/frontend/metadata.md +0 -344
  94. package/docs/frontend/navigation.md +0 -296
  95. package/docs/frontend/rendering.md +0 -236
  96. package/docs/frontend/routing.md +0 -346
  97. package/docs/frontend/scripts.md +0 -118
  98. package/docs/frontend/search.md +0 -191
  99. package/docs/frontend/styling.md +0 -147
  100. package/docs/frontend/toil-global.md +0 -216
  101. package/docs/getting-started/README.md +0 -81
  102. package/docs/getting-started/create-project.md +0 -131
  103. package/docs/getting-started/deploy.md +0 -101
  104. package/docs/getting-started/first-app.md +0 -215
  105. package/docs/getting-started/installation.md +0 -124
  106. package/docs/getting-started/migrating.md +0 -125
  107. package/docs/getting-started/project-structure.md +0 -163
  108. package/docs/introduction/README.md +0 -66
  109. package/docs/introduction/design-principles.md +0 -81
  110. package/docs/introduction/distributed.md +0 -91
  111. package/docs/introduction/how-it-works.md +0 -121
  112. package/docs/introduction/hyperscale.md +0 -70
  113. package/docs/introduction/modern-stack.md +0 -85
  114. package/docs/introduction/vs-other-frameworks.md +0 -64
  115. package/docs/introduction/why-toil.md +0 -99
  116. package/docs/llms.txt +0 -95
  117. package/docs/realtime/README.md +0 -102
  118. package/docs/realtime/channels.md +0 -211
  119. package/docs/realtime/streams.md +0 -369
  120. package/docs/services/README.md +0 -60
  121. package/docs/services/analytics.md +0 -279
  122. package/docs/services/caching.md +0 -175
  123. package/docs/services/cookies.md +0 -235
  124. package/docs/services/crypto.md +0 -209
  125. package/docs/services/email.md +0 -289
  126. package/docs/services/environment.md +0 -141
  127. package/docs/services/ratelimit.md +0 -174
  128. package/docs/services/time.md +0 -85
  129. package/eslint.config.js +0 -57
  130. package/examples/basic/client/routes/docs/[...slug].tsx +0 -12
  131. package/presets/eslint.js +0 -88
  132. package/src/backend/index.ts +0 -204
  133. package/src/cli/configure.ts +0 -363
  134. package/src/cli/create.ts +0 -924
  135. package/src/cli/db.ts +0 -158
  136. package/src/cli/diagnostics.ts +0 -665
  137. package/src/cli/doctor.ts +0 -982
  138. package/src/cli/features.ts +0 -170
  139. package/src/cli/index.ts +0 -326
  140. package/src/cli/notify.ts +0 -120
  141. package/src/cli/proc.ts +0 -56
  142. package/src/cli/ui.ts +0 -169
  143. package/src/cli/update.ts +0 -248
  144. package/src/cli/updates.ts +0 -92
  145. package/src/cli/validate.ts +0 -31
  146. package/src/cli/version-check.ts +0 -125
  147. package/src/client/auth.ts +0 -869
  148. package/src/client/channel/channel.ts +0 -146
  149. package/src/client/components/Form.tsx +0 -65
  150. package/src/client/components/Image.tsx +0 -160
  151. package/src/client/components/Script.tsx +0 -113
  152. package/src/client/components/Slot.tsx +0 -21
  153. package/src/client/dev/devtools.tsx +0 -1089
  154. package/src/client/dev/error-overlay.tsx +0 -225
  155. package/src/client/errors.ts +0 -11
  156. package/src/client/head/head.ts +0 -182
  157. package/src/client/head/metadata.ts +0 -110
  158. package/src/client/index.ts +0 -130
  159. package/src/client/navigation/Link.tsx +0 -108
  160. package/src/client/navigation/NavLink.tsx +0 -86
  161. package/src/client/navigation/navigation.ts +0 -235
  162. package/src/client/navigation/prefetch.ts +0 -169
  163. package/src/client/navigation/scroll.ts +0 -53
  164. package/src/client/routing/Router.tsx +0 -216
  165. package/src/client/routing/action.ts +0 -122
  166. package/src/client/routing/error-boundary.tsx +0 -43
  167. package/src/client/routing/hooks.ts +0 -140
  168. package/src/client/routing/lazy.ts +0 -77
  169. package/src/client/routing/loader.ts +0 -381
  170. package/src/client/routing/match.ts +0 -47
  171. package/src/client/routing/mount.tsx +0 -90
  172. package/src/client/routing/params-context.ts +0 -10
  173. package/src/client/routing/slot-context.ts +0 -7
  174. package/src/client/rpc.ts +0 -97
  175. package/src/client/search/search.ts +0 -189
  176. package/src/client/search/use-page-search.ts +0 -73
  177. package/src/client/ssr/markers.tsx +0 -172
  178. package/src/client/stream/client.ts +0 -237
  179. package/src/client/types.ts +0 -73
  180. package/src/compiler/auth-emails.ts +0 -312
  181. package/src/compiler/config.ts +0 -369
  182. package/src/compiler/docs.ts +0 -127
  183. package/src/compiler/email-preview.ts +0 -314
  184. package/src/compiler/emails.ts +0 -404
  185. package/src/compiler/fonts.ts +0 -89
  186. package/src/compiler/generate.ts +0 -471
  187. package/src/compiler/image-blur.ts +0 -42
  188. package/src/compiler/image-report.ts +0 -88
  189. package/src/compiler/index.ts +0 -1362
  190. package/src/compiler/pages.ts +0 -49
  191. package/src/compiler/plugin.ts +0 -391
  192. package/src/compiler/prerender.ts +0 -263
  193. package/src/compiler/routes.ts +0 -170
  194. package/src/compiler/seo.ts +0 -415
  195. package/src/compiler/sri.ts +0 -144
  196. package/src/compiler/ssg.ts +0 -177
  197. package/src/compiler/ssr-codegen.ts +0 -85
  198. package/src/compiler/template-build.ts +0 -676
  199. package/src/compiler/template.ts +0 -262
  200. package/src/compiler/toil-docs.generated.ts +0 -77
  201. package/src/compiler/vite.ts +0 -245
  202. package/src/devserver/analytics/index.ts +0 -317
  203. package/src/devserver/config/dotenv.ts +0 -102
  204. package/src/devserver/config/env.ts +0 -30
  205. package/src/devserver/config/ratelimit.ts +0 -123
  206. package/src/devserver/daemon/catalog.ts +0 -120
  207. package/src/devserver/daemon/cron.ts +0 -87
  208. package/src/devserver/daemon/host.ts +0 -134
  209. package/src/devserver/daemon/index.ts +0 -369
  210. package/src/devserver/daemon/runtime.ts +0 -48
  211. package/src/devserver/db/catalog.ts +0 -109
  212. package/src/devserver/db/database.ts +0 -1834
  213. package/src/devserver/db/derives.ts +0 -121
  214. package/src/devserver/db/index.ts +0 -20
  215. package/src/devserver/db/routeKinds.ts +0 -191
  216. package/src/devserver/db/types.ts +0 -168
  217. package/src/devserver/email/caps.ts +0 -0
  218. package/src/devserver/email/config.ts +0 -141
  219. package/src/devserver/email/console.ts +0 -348
  220. package/src/devserver/email/index.ts +0 -155
  221. package/src/devserver/email/providers.ts +0 -131
  222. package/src/devserver/email/status.ts +0 -23
  223. package/src/devserver/email/validate.ts +0 -37
  224. package/src/devserver/email/wire.ts +0 -55
  225. package/src/devserver/http/cache.ts +0 -0
  226. package/src/devserver/http/envelope.ts +0 -157
  227. package/src/devserver/http/proxy.ts +0 -172
  228. package/src/devserver/http/runtime.ts +0 -387
  229. package/src/devserver/index.ts +0 -43
  230. package/src/devserver/production-ipc.ts +0 -63
  231. package/src/devserver/production-worker.ts +0 -83
  232. package/src/devserver/production.ts +0 -718
  233. package/src/devserver/runtime/crypto.ts +0 -587
  234. package/src/devserver/runtime/host.ts +0 -427
  235. package/src/devserver/runtime/module.ts +0 -442
  236. package/src/devserver/server.ts +0 -251
  237. package/src/devserver/ssr.ts +0 -208
  238. package/src/devserver/stream/catalog.ts +0 -106
  239. package/src/devserver/stream/host.ts +0 -42
  240. package/src/devserver/stream/index.ts +0 -301
  241. package/src/devserver/stream/manager.ts +0 -167
  242. package/src/devserver/stream/router.ts +0 -101
  243. package/src/devserver/stream/wire.ts +0 -58
  244. package/src/devserver/stream/ws.ts +0 -78
  245. package/src/devserver/wasm/sections.ts +0 -59
  246. package/src/devserver/wasm/surface.ts +0 -115
  247. package/src/io/FastMap.ts +0 -151
  248. package/src/io/FastSet.ts +0 -113
  249. package/src/io/codec.ts +0 -362
  250. package/src/io/index.ts +0 -10
  251. package/src/io/lengths.ts +0 -14
  252. package/src/io/types.ts +0 -19
  253. package/src/logger/index.ts +0 -22
  254. package/src/shared/index.ts +0 -46
  255. package/test/analytics-dev.test.ts +0 -113
  256. package/test/assembly/aspect-shim.ts +0 -33
  257. package/test/assembly/cookie.spec.ts +0 -303
  258. package/test/assembly/example.spec.ts +0 -22
  259. package/test/assembly/ssr.spec.ts +0 -95
  260. package/test/assembly.test.ts +0 -59
  261. package/test/auth-emails.test.ts +0 -118
  262. package/test/built-ssr.test.ts +0 -148
  263. package/test/channel.test.ts +0 -21
  264. package/test/config-host-port.test.ts +0 -59
  265. package/test/configure.test.ts +0 -94
  266. package/test/daemon-build.test.ts +0 -278
  267. package/test/daemon-catalog.test.ts +0 -349
  268. package/test/daemon-emulation.test.ts +0 -256
  269. package/test/db.test.ts +0 -0
  270. package/test/devserver-database.test.ts +0 -1102
  271. package/test/devserver-email.test.ts +0 -306
  272. package/test/devserver-pqauth.test.ts +0 -93
  273. package/test/devserver-secrets.test.ts +0 -63
  274. package/test/devserver.test.ts +0 -259
  275. package/test/doctor.test.ts +0 -298
  276. package/test/dom/Image.test.tsx +0 -144
  277. package/test/dom/Link.test.tsx +0 -67
  278. package/test/dom/NavLink.test.tsx +0 -37
  279. package/test/dom/Script.test.tsx +0 -48
  280. package/test/dom/action.test.tsx +0 -146
  281. package/test/dom/error-overlay.test.tsx +0 -44
  282. package/test/dom/loader.test.tsx +0 -121
  283. package/test/dom/navigation.test.ts +0 -59
  284. package/test/dom/revalidate.test.tsx +0 -38
  285. package/test/dom/route-head.test.tsx +0 -56
  286. package/test/dom/router-loading.test.tsx +0 -44
  287. package/test/dom/scroll.test.ts +0 -56
  288. package/test/dom/slot.test.tsx +0 -131
  289. package/test/dom/use-metadata.test.tsx +0 -58
  290. package/test/dom/view-transitions.test.tsx +0 -53
  291. package/test/dynamic-routing.test.ts +0 -132
  292. package/test/email-console.test.ts +0 -86
  293. package/test/email-preview.test.ts +0 -73
  294. package/test/emails.test.ts +0 -58
  295. package/test/errors.test.ts +0 -21
  296. package/test/example-guestbook.test.ts +0 -123
  297. package/test/features.test.ts +0 -149
  298. package/test/fixtures/bignum-wire/spec.ts +0 -25
  299. package/test/fixtures/daemon-app.ts +0 -65
  300. package/test/fixtures/stream-echo.ts +0 -26
  301. package/test/fixtures/stream-gate.ts +0 -28
  302. package/test/fixtures/stream-trap.ts +0 -18
  303. package/test/fixtures/stream-typed.ts +0 -41
  304. package/test/fonts.test.ts +0 -28
  305. package/test/global-setup.ts +0 -17
  306. package/test/head.test.ts +0 -42
  307. package/test/image-blur.test.ts +0 -50
  308. package/test/io.test.ts +0 -117
  309. package/test/metadata.test.ts +0 -40
  310. package/test/navlink.test.ts +0 -28
  311. package/test/pages.test.ts +0 -105
  312. package/test/placeholder.test.ts +0 -9
  313. package/test/pqauth-e2e.test.ts +0 -216
  314. package/test/pqauth-email.test.ts +0 -801
  315. package/test/prerender.test.ts +0 -116
  316. package/test/prettier-plugin.test.ts +0 -46
  317. package/test/routes.test.ts +0 -76
  318. package/test/rpc-bignum-wire.test.ts +0 -164
  319. package/test/rpc-dispatch.test.ts +0 -132
  320. package/test/rpc-kinds.test.ts +0 -18
  321. package/test/rpc.test.ts +0 -66
  322. package/test/search.test.ts +0 -114
  323. package/test/seo.test.ts +0 -175
  324. package/test/slot-layouts.test.ts +0 -69
  325. package/test/sri.test.ts +0 -129
  326. package/test/ssg.test.ts +0 -36
  327. package/test/ssr-hydration.test.tsx +0 -122
  328. package/test/ssr-render.test.ts +0 -197
  329. package/test/ssr-template.test.tsx +0 -482
  330. package/test/stream-emulation.test.ts +0 -479
  331. package/test/ui.test.ts +0 -40
  332. package/test/update.test.ts +0 -58
  333. package/test/validate.test.ts +0 -42
  334. package/test/version-check.test.ts +0 -130
  335. package/tests/data-parity/generated-parity.ts +0 -99
  336. package/tests/data-parity/parity.ts +0 -80
  337. package/tests/data-parity/spec.ts +0 -46
@@ -1,369 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { fileURLToPath, pathToFileURL } from 'node:url';
4
-
5
- import { type InlineConfig } from 'vite';
6
- import { type EmailBackendConfig } from 'toiljs/shared';
7
-
8
- import { type SeoConfig } from './seo.js';
9
-
10
- export type { SeoConfig } from './seo.js';
11
- export type { EmailBackendConfig, SmtpBackendConfig } from 'toiljs/shared';
12
-
13
- /** Built-in AI providers the dev toolbar can proxy to. */
14
- export enum AiProvider {
15
- Anthropic = 'anthropic',
16
- OpenAI = 'openai',
17
- }
18
-
19
- /** Dev toolbar AI integration (dev only; the key stays server-side). */
20
- export interface DevtoolsAiConfig {
21
- /** Built-in provider. With `endpoint` set, that takes precedence. */
22
- readonly provider?: AiProvider;
23
- /** Model id (e.g. `claude-sonnet-4-6`, `gpt-4o`). */
24
- readonly model?: string;
25
- /** Name of the env var holding the API key (read by the dev server, never sent to the client). */
26
- readonly apiKeyEnv?: string;
27
- /** Custom POST endpoint (`{ prompt }` in, `{ text }` out); overrides `provider`. */
28
- readonly endpoint?: string;
29
- }
30
-
31
- /** Dev toolbar configuration. */
32
- export interface DevtoolsConfig {
33
- readonly ai?: DevtoolsAiConfig;
34
- }
35
-
36
- /**
37
- * Client-side (TSX/React/Vite) configuration. All fields optional; sensible defaults applied.
38
- */
39
- export interface ClientConfig {
40
- /** Client source directory, relative to root. Default `client`. */
41
- readonly srcDir?: string;
42
- /** Routes directory, relative to `srcDir`. Default `routes`. */
43
- readonly routesDir?: string;
44
- /**
45
- * Static assets directory, relative to root. Default `<srcDir>/public` (e.g. `client/public`).
46
- * Holds the `index.html` template (owned and edited by you) plus any files served as-is at the
47
- * base path (favicons, images, and the like).
48
- */
49
- readonly publicDir?: string;
50
- /** Production output directory, relative to root. Default `build/client`. */
51
- readonly outDir?: string;
52
- /** Public base path. Default `/`. */
53
- readonly base?: string;
54
- /** Port the dev server AND the self-host (`toiljs start`) listen on. Default `3000`.
55
- * Overridden by the `--port` CLI flag and the `PORT` env var (in that precedence). */
56
- readonly port?: number;
57
- /** Bind host for the dev server AND the self-host. Default `127.0.0.1` (loopback only).
58
- * Set to `0.0.0.0` (or a specific interface) to accept LAN / public connections.
59
- * Overridden by the `--host` CLI flag and the `HOST` env var (in that precedence). */
60
- readonly host?: string;
61
- /**
62
- * Optimize imported images at build time (resize/convert via `vite-imagetools` + sharp): an
63
- * import like `logo.png?w=400;800&format=webp&as=srcset` emits resized, compressed variants.
64
- * Default `true`. Set `false` to disable the pipeline (images are then served as-is).
65
- */
66
- readonly images?: boolean;
67
- /**
68
- * Preload bundled fonts at build time: injects `<link rel="preload" as="font">` for each
69
- * `@font-face` font so it loads in parallel with the CSS (faster text paint). Default `true`.
70
- */
71
- readonly fonts?: boolean;
72
- /**
73
- * Animate cross-page navigations with the browser View Transitions API (a crossfade by default;
74
- * add `view-transition-name` in CSS for shared-element transitions). Respects
75
- * `prefers-reduced-motion`. Default `false`.
76
- */
77
- readonly viewTransitions?: boolean;
78
- /**
79
- * Wrap client navigations in a React transition, keeping the current page visible while the next
80
- * route's loader runs instead of showing its `loading.tsx` right away. Default `false` (a
81
- * navigation commits eagerly, so the loading state appears immediately).
82
- */
83
- readonly transitions?: boolean;
84
- /**
85
- * The dev toolbar (a floating panel in `toiljs dev` with route/build info, errors, and live
86
- * controls). `true` (default) / `false` to disable, or an object to configure its AI integration.
87
- * Never included in production builds. The AI key is read server-side from `apiKeyEnv` and never
88
- * reaches the browser; the toolbar always offers Claude/ChatGPT hand-off links regardless.
89
- */
90
- readonly devtools?: boolean | DevtoolsConfig;
91
- /**
92
- * Build-time SEO: bakes site-level metadata into the HTML `<head>` (so JS-less crawlers and AI
93
- * bots see real tags) and generates `robots.txt`, `sitemap.xml`, and `llms.txt`. Omit to skip.
94
- */
95
- readonly seo?: SeoConfig;
96
- /**
97
- * Raw Vite escape hatch, deep-merged over the framework's opinionated config.
98
- * This is NOT the client config itself, toil owns the Vite setup; use this only
99
- * to override specific Vite options.
100
- */
101
- readonly vite?: InlineConfig;
102
- }
103
-
104
- /**
105
- * Dev node mode: which layer the single dev process emulates. `hot` runs only the
106
- * request path (today's behavior); `regional`/`continental` would run streams off
107
- * `release-hot.wasm` (Phase 4); `daemon` runs `release-cold.wasm`; `all` runs every
108
- * surface in one process (the default for a full local run). DEV / self-host knob;
109
- * the production edge reads the authoritative role from per-host TCF + the plan.
110
- */
111
- export type DevNodeMode = 'hot' | 'regional' | 'continental' | 'daemon' | 'all';
112
-
113
- /** Daemon (L4) config mirror (dev / self-host). All optional. */
114
- export interface DaemonConfig {
115
- /** Region the daemon is pinned to (informational in dev; the dev process is leader). */
116
- readonly region?: string;
117
- /** Warm standby region (informational in dev). */
118
- readonly standbyRegion?: string;
119
- /** Default `@scheduled` interval (ms) when a task declares none. Default 60000. */
120
- readonly defaultIntervalMs?: number;
121
- /** Per-tick wall-clock budget (ms) before the dev scheduler logs an overrun. Default 30000. */
122
- readonly tickBudgetMs?: number;
123
- /** Per-tick gas cap (dev stub; charged-then-ignored). Mirrors `plan.gas_scheduled`. */
124
- readonly gasTick?: number;
125
- /** Max number of `@scheduled` tasks (mirrors `max_scheduled_tasks`). Default 64. */
126
- readonly maxTasks?: number;
127
- }
128
-
129
- /**
130
- * Server-side (toilscript → WASM) configuration.
131
- */
132
- export interface ServerConfig {
133
- /** Server source directory, relative to root. Default `server`. */
134
- readonly srcDir?: string;
135
- /** Server build output directory, relative to root. Default `build/server`. */
136
- readonly outDir?: string;
137
- /**
138
- * Email backend config (the dev server and the future Node self-host). The
139
- * non-secret pieces — provider, `from`, send caps, SMTP host/port/user. The
140
- * API key / SMTP password is a SECRET and lives ONLY in `.env.secrets`
141
- * (`TOIL_EMAIL_API_KEY`); any `TOIL_EMAIL_*` env var overrides the matching
142
- * field here. The production edge ignores this (it reads `TOIL_EMAIL_*` from
143
- * the per-tenant env store); this drives `toiljs dev` / self-host.
144
- */
145
- readonly email?: EmailBackendConfig;
146
- /** Which layer the dev process emulates. Default `all`. */
147
- readonly nodeMode?: DevNodeMode;
148
- /**
149
- * Built-in auth. `true` opts into the framework's post-quantum login: the
150
- * build appends a shipped `@rest('auth')` controller + its `@user` shape to
151
- * the toilscript entry set, so the app gets the full `/auth/register|login`
152
- * API + sessions (`/auth/me`, `/auth/logout`) with no hand-written boilerplate.
153
- * Default `false`. (The escape hatch `import 'toiljs/server/auth'` in
154
- * `server/main.ts` does the same without this flag.) An app that opts in must
155
- * NOT declare its own `@user` — the built-in owns the single per-program one.
156
- */
157
- readonly auth?: boolean;
158
- /** Daemon (L4) config mirror (dev / self-host). */
159
- readonly daemon?: DaemonConfig;
160
- /**
161
- * Self-host HTTP worker count for `toiljs start`. Default `auto`
162
- * (`os.availableParallelism()`). Set `1` to disable the worker pool.
163
- */
164
- readonly threads?: number | 'auto';
165
- }
166
-
167
- /** Fully-resolved {@link DaemonConfig}; every field non-optional, defaults applied. */
168
- export interface ResolvedDaemonConfig {
169
- readonly region: string | null;
170
- readonly standbyRegion: string | null;
171
- readonly defaultIntervalMs: number;
172
- readonly tickBudgetMs: number;
173
- readonly gasTick: number;
174
- readonly maxTasks: number;
175
- }
176
-
177
- /**
178
- * The `toil.config` schema. All fields optional; sensible defaults applied.
179
- * Client and server are configured in separate sections.
180
- */
181
- export interface ToilConfig {
182
- /** Project root. Defaults to the current working directory. */
183
- readonly root?: string;
184
- /** Client (TSX/React/Vite) configuration. */
185
- readonly client?: ClientConfig;
186
- /** Server (toilscript/WASM) configuration. */
187
- readonly server?: ServerConfig;
188
- }
189
-
190
- /** Fully-resolved config with absolute paths, used internally by the compiler. */
191
- export interface ResolvedToilConfig {
192
- readonly root: string;
193
- readonly srcDir: string;
194
- readonly clientAbsDir: string;
195
- readonly routesAbsDir: string;
196
- /** Absolute path to the static-assets dir (holds the `index.html` template). */
197
- readonly publicDir: string;
198
- readonly toilDir: string;
199
- readonly outDir: string;
200
- readonly base: string;
201
- readonly port: number;
202
- /** Bind host for the dev server + self-host (`toiljs start`). Default `127.0.0.1`. */
203
- readonly host: string;
204
- /** Whether build-time image optimization (`vite-imagetools`) is enabled. */
205
- readonly images: boolean;
206
- /** Whether build-time font preloading is enabled. */
207
- readonly fonts: boolean;
208
- /** Whether animated View Transitions are enabled for navigation. */
209
- readonly viewTransitions: boolean;
210
- /** Whether navigations are wrapped in a React transition (keep current page while loading). */
211
- readonly transitions: boolean;
212
- /** Whether the dev toolbar is enabled (dev only). */
213
- readonly devtools: boolean;
214
- /** Dev toolbar AI config (dev only), or `null` when not configured. */
215
- readonly devtoolsAi: DevtoolsAiConfig | null;
216
- /** Build-time SEO config, or `null` when not configured. */
217
- readonly seo: SeoConfig | null;
218
- /** The `server.email` backend config (dev / self-host), or `null` when unset. */
219
- readonly email: EmailBackendConfig | null;
220
- /** Which layer the dev process emulates (dev / self-host). Default `all`. */
221
- readonly nodeMode: DevNodeMode;
222
- /** Whether the built-in `/auth/*` PQ-login controller is compiled + mounted. */
223
- readonly auth: boolean;
224
- /** Daemon (L4) config mirror (dev / self-host), every field resolved. */
225
- readonly daemon: ResolvedDaemonConfig;
226
- /** Self-host HTTP worker count for `toiljs start`. */
227
- readonly threads: number | 'auto';
228
- /** Absolute path to the framework client runtime (`toiljs/client`). */
229
- readonly runtimePath: string;
230
- readonly vite: InlineConfig;
231
- }
232
-
233
- /** Identity helper for typed config files: `export default defineConfig({ ... })`. */
234
- export function defineConfig(config: ToilConfig): ToilConfig {
235
- return config;
236
- }
237
-
238
- const CONFIG_NAMES = [
239
- 'toil.config.ts',
240
- 'toil.config.mts',
241
- 'toil.config.js',
242
- 'toil.config.mjs',
243
- 'toiljs.config.ts',
244
- 'toiljs.config.mts',
245
- 'toiljs.config.js',
246
- 'toiljs.config.mjs',
247
- ];
248
-
249
- /** Path to the built client runtime (`build/client/index.js`), sibling to `build/compiler`. */
250
- function resolveRuntimePath(): string {
251
- return path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../client/index.js');
252
- }
253
-
254
- /** Finds and loads `toil.config.*` or `toiljs.config.*` from `root`, then resolves defaults. */
255
- export async function loadConfig(
256
- opts: { root?: string; port?: number; host?: string } = {},
257
- ): Promise<ResolvedToilConfig> {
258
- const root = path.resolve(opts.root ?? process.cwd());
259
-
260
- let user: ToilConfig = {};
261
- for (const name of CONFIG_NAMES) {
262
- const candidate = path.join(root, name);
263
- if (fs.existsSync(candidate)) {
264
- const loaded = (await import(pathToFileURL(candidate).href)) as {
265
- default?: ToilConfig;
266
- };
267
- if (loaded.default) user = loaded.default;
268
- break;
269
- }
270
- }
271
-
272
- const client = user.client ?? {};
273
- const srcDir = client.srcDir ?? 'client';
274
- const routesDir = client.routesDir ?? 'routes';
275
- const clientAbsDir = path.join(root, srcDir);
276
-
277
- return {
278
- root,
279
- srcDir,
280
- clientAbsDir,
281
- routesAbsDir: path.join(clientAbsDir, routesDir),
282
- publicDir: client.publicDir
283
- ? path.resolve(root, client.publicDir)
284
- : path.join(clientAbsDir, 'public'),
285
- toilDir: path.join(root, '.toil'),
286
- outDir: client.outDir ?? 'build/client',
287
- base: client.base ?? '/',
288
- // Port + bind host for the dev server and the self-host, resolved with the
289
- // precedence: CLI flag (opts) > env (PORT/HOST) > config (client.*) > default.
290
- // `PORT`/`HOST` are the conventional PaaS env vars; a platform that injects
291
- // `PORT` (Heroku, Render, Fly, containers) works with zero config.
292
- port: opts.port ?? envPort() ?? client.port ?? 3000,
293
- host: opts.host ?? envHost() ?? client.host ?? '127.0.0.1',
294
- images: client.images ?? true,
295
- fonts: client.fonts ?? true,
296
- viewTransitions: client.viewTransitions ?? false,
297
- transitions: client.transitions ?? false,
298
- devtools: client.devtools !== false,
299
- devtoolsAi:
300
- client.devtools != null && typeof client.devtools === 'object'
301
- ? (client.devtools.ai ?? null)
302
- : null,
303
- seo: client.seo ?? null,
304
- email: user.server?.email ?? null,
305
- nodeMode: resolveNodeMode(user.server?.nodeMode),
306
- auth: user.server?.auth === true,
307
- daemon: resolveDaemonConfig(user.server?.daemon),
308
- threads: resolveThreads(user.server?.threads),
309
- runtimePath: resolveRuntimePath(),
310
- vite: client.vite ?? {},
311
- };
312
- }
313
-
314
- /** The `PORT` env var as a positive integer, or `undefined` when unset/invalid
315
- * (so it falls through to the config value / default rather than binding to 0). */
316
- function envPort(): number | undefined {
317
- const v = process.env.PORT;
318
- if (v == null || v.trim() === '') return undefined;
319
- const n = Number(v);
320
- return Number.isFinite(n) && n > 0 ? Math.floor(n) : undefined;
321
- }
322
-
323
- /** The `HOST` env var (trimmed), or `undefined` when unset/blank. */
324
- function envHost(): string | undefined {
325
- const v = process.env.HOST;
326
- return v != null && v.trim() !== '' ? v.trim() : undefined;
327
- }
328
-
329
- const DEV_NODE_MODES: readonly DevNodeMode[] = ['hot', 'regional', 'continental', 'daemon', 'all'];
330
-
331
- /** A `nodeMode` outside the enum falls back to `all` with a warning (fail-soft:
332
- * the authoritative role is the edge's TCF + plan, so dev never bricks on it). */
333
- function resolveNodeMode(mode: DevNodeMode | undefined): DevNodeMode {
334
- if (mode === undefined) return 'all';
335
- if (DEV_NODE_MODES.includes(mode)) return mode;
336
- process.stdout.write(
337
- ` ! server.nodeMode '${mode}' is not a valid node mode; falling back to 'all'\n`,
338
- );
339
- return 'all';
340
- }
341
-
342
- /** Resolve the daemon config with defaults + light, fail-soft clamping (never
343
- * throws; the authoritative caps are the edge's). */
344
- function resolveDaemonConfig(d: DaemonConfig | undefined): ResolvedDaemonConfig {
345
- // The dev scheduler uses setInterval; a sub-second loop floods the console.
346
- let defaultIntervalMs = d?.defaultIntervalMs ?? 60000;
347
- if (defaultIntervalMs < 1000) {
348
- process.stdout.write(
349
- ` ! server.daemon.defaultIntervalMs ${String(defaultIntervalMs)} < 1000; clamping to 1000\n`,
350
- );
351
- defaultIntervalMs = 1000;
352
- }
353
- let maxTasks = d?.maxTasks ?? 64;
354
- if (maxTasks <= 0 || maxTasks > 1024) maxTasks = Math.min(1024, Math.max(1, maxTasks || 64));
355
- return {
356
- region: d?.region ?? null,
357
- standbyRegion: d?.standbyRegion ?? null,
358
- defaultIntervalMs,
359
- tickBudgetMs: d?.tickBudgetMs ?? 30000,
360
- gasTick: d?.gasTick ?? 0,
361
- maxTasks,
362
- };
363
- }
364
-
365
- function resolveThreads(threads: number | 'auto' | undefined): number | 'auto' {
366
- if (threads === undefined || threads === 'auto') return 'auto';
367
- if (!Number.isFinite(threads)) return 'auto';
368
- return Math.max(1, Math.min(128, Math.floor(threads)));
369
- }
@@ -1,127 +0,0 @@
1
- /**
2
- * AI-assistant helper files. `toiljs create` writes a small pointer file for each tool at the
3
- * project root (committed, yours to edit); the real documentation lives under `.toil/docs/`,
4
- * regenerated on every `toiljs dev` / `toiljs build` so it stays in sync with the installed
5
- * toiljs version. The pointer files just tell the agent to read `.toil/docs/`.
6
- */
7
- import fs from 'node:fs';
8
- import path from 'node:path';
9
- import { TOIL_DOCS } from './toil-docs.generated.js';
10
-
11
- export { TOIL_DOCS };
12
-
13
- /** First-level `# ` heading of a Markdown doc, used as the bullet label. */
14
- function docTitle(content: string): string {
15
- const m = content.match(/^#\s+(.+)$/m);
16
- return m ? m[1].trim() : '';
17
- }
18
-
19
- /**
20
- * The pointer files' navigation list, derived from the generated `TOIL_DOCS` map so it never
21
- * drifts from the docs actually written into `.toil/docs/` (no second hand-kept list). We list
22
- * the section landing pages (each folder's `README.md`, plus the root one) rather than all
23
- * fifty-plus pages; every landing links onward to its own topic pages, and
24
- * `.toil/docs/README.md` is the root map.
25
- */
26
- const DOC_POINTERS = Object.keys(TOIL_DOCS)
27
- .filter((name) => name === 'README.md' || name.endsWith('/README.md'))
28
- .map((name) => {
29
- const summary = docTitle(TOIL_DOCS[name]);
30
- return `- \`.toil/docs/${name}\`${summary ? `, ${summary}` : ''}`;
31
- })
32
- .join('\n');
33
-
34
- /** Shared body for the per-tool pointer files. */
35
- const POINTER_BODY = `# toiljs, AI assistant guide
36
-
37
- This is a **toiljs** project, a full-stack React framework (React + Vite client, file-based
38
- routing, and a toilscript→WebAssembly server).
39
-
40
- **Before editing this project, read the generated documentation in \`.toil/docs/\`, starting at
41
- \`.toil/docs/README.md\`.** It describes the conventions you must follow. The sections, each a
42
- folder whose \`README.md\` links onward to its topic pages:
43
-
44
- ${DOC_POINTERS}
45
-
46
- ## Rules you must follow
47
-
48
- Read \`.toil/docs/concepts/ai-guide.md\` first, it is the concise correct-usage cheat-sheet. The essentials:
49
-
50
- - **Never call the toiljs backend with raw \`fetch\`.** Use the generated typed client:
51
- \`Server.REST.<controller>.<route>(args)\` for \`@rest\` HTTP controllers, or
52
- \`Server.<service>.<method>(args)\` / \`Server.<remote>(args)\` for \`@service\` / \`@remote\` RPC. \`Server\` is a
53
- global (no import). Raw \`fetch\` to your own backend throws away type safety and the wire codec and
54
- breaks silently on a rename. Wrong: \`await fetch('/account/session', { method: 'POST' })\`. Right:
55
- \`await Server.REST.account.session()\`. \`fetch\` is only for third-party URLs.
56
- - Use the ambient \`Toil.*\` globals with NO import (\`Toil.Link\`, \`Toil.useLoaderData\`, \`Toil.Image\`,
57
- \`Toil.Form\`, \`Toil.useHead\`, ...). \`Server\`, \`FastMap\`, \`FastSet\`, \`DataWriter\`, \`DataReader\` are bare
58
- globals too. Load page data with \`export const loader\` + \`Toil.useLoaderData(loader)\`, NOT a \`useEffect\`
59
- fetch; mutate with \`Toil.useAction\` / \`<Toil.Form>\` then revalidate.
60
- - Client \`getUser()\` is DISPLAY-ONLY and forgeable, never gate real access on it. Enforce access on the
61
- SERVER with \`@auth\` (it re-verifies the signed session, so inside an \`@auth\` handler
62
- \`AuthService.getUser()!\` is guaranteed non-null).
63
- - Server code is strict AssemblyScript: explicit value types (\`i32\`/\`u32\`/\`i64\`/\`u64\`/\`f64\`/\`bool\`/
64
- \`string\`/\`Uint8Array\`), no \`any\`, no plain \`number\`, no usable \`RegExp\`. Structured values are \`@data\`
65
- classes; exactly one \`@user\` per project; read config with \`Environment.get\` and secrets with
66
- \`Environment.getSecure\`.
67
- - Never hand-edit \`shared/server.ts\` or anything under \`.toil/\` (both are generated).
68
-
69
- See \`.toil/docs/frontend/data-fetching.md\`, \`.toil/docs/frontend/toil-global.md\`, and
70
- \`.toil/docs/concepts/decorators.md\` for detail.
71
-
72
- \`.toil/docs/\` is regenerated by toiljs; do not edit it by hand. This pointer file is yours to edit.
73
- `;
74
-
75
- /** A selectable AI coding-tool helper: its id, label, and the root pointer file(s) it scaffolds. */
76
- export interface AiHelper {
77
- readonly id: string;
78
- readonly label: string;
79
- readonly files: Record<string, string>;
80
- }
81
-
82
- /**
83
- * Per-tool pointer files, individually selectable in `toiljs create`. Each tool reads its own
84
- * conventional file: Claude Code → CLAUDE.md, Codex / others → AGENTS.md, Cursor → .cursor/rules,
85
- * GitHub Copilot → .github/copilot-instructions.md. Written once by `create`; not regenerated.
86
- */
87
- export const AI_HELPERS: readonly AiHelper[] = [
88
- { id: 'claude', label: 'Claude Code (CLAUDE.md)', files: { 'CLAUDE.md': POINTER_BODY } },
89
- { id: 'codex', label: 'Codex / AGENTS.md', files: { 'AGENTS.md': POINTER_BODY } },
90
- {
91
- id: 'cursor',
92
- label: 'Cursor (.cursor/rules)',
93
- files: {
94
- '.cursor/rules/toiljs.mdc': `---\ndescription: toiljs project conventions\nalwaysApply: true\n---\n\n${POINTER_BODY}`,
95
- },
96
- },
97
- {
98
- id: 'copilot',
99
- label: 'GitHub Copilot (.github/copilot-instructions.md)',
100
- files: { '.github/copilot-instructions.md': POINTER_BODY },
101
- },
102
- ];
103
-
104
- /** All AI helper ids (the default selection). */
105
- export const AI_HELPER_IDS: readonly string[] = AI_HELPERS.map((h) => h.id);
106
-
107
- /** Merges the pointer files for the given helper ids into one path → content map. */
108
- export function aiHelperFiles(ids: readonly string[]): Record<string, string> {
109
- const out: Record<string, string> = {};
110
- for (const helper of AI_HELPERS) {
111
- if (ids.includes(helper.id)) Object.assign(out, helper.files);
112
- }
113
- return out;
114
- }
115
-
116
- /** Writes the framework docs into `<toilDir>/docs/`. Called by `generate` each dev/build. */
117
- export function writeDocs(toilDir: string): void {
118
- const dir = path.join(toilDir, 'docs');
119
- fs.mkdirSync(dir, { recursive: true });
120
- for (const [name, content] of Object.entries(TOIL_DOCS)) {
121
- const dest = path.join(dir, name);
122
- // Doc keys can be nested (e.g. "auth/configuration.md"), so ensure the
123
- // file's parent directory exists before writing it.
124
- fs.mkdirSync(path.dirname(dest), { recursive: true });
125
- fs.writeFileSync(dest, content);
126
- }
127
- }