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,259 +0,0 @@
1
- /**
2
- * WASM dev server: envelope codec (byte-for-byte against the ABI shared with
3
- * `server/runtime/envelope.ts` and the edge's `envelope.rs`) and real dispatch
4
- * into the example project's ToilScript-compiled server wasm.
5
- */
6
- import fs from 'node:fs';
7
- import os from 'node:os';
8
- import path from 'node:path';
9
- import { fileURLToPath } from 'node:url';
10
-
11
- import { describe, expect, it } from 'vitest';
12
-
13
- import {
14
- decodeResponseEnvelope,
15
- encodeRequestEnvelope,
16
- unpackHandleResult,
17
- WasmServerModule,
18
- } from '../src/devserver/index.js';
19
- import { resolveStaticFile } from '../src/devserver/http/runtime.js';
20
-
21
- const EXAMPLE_WASM = path.resolve(
22
- path.dirname(fileURLToPath(import.meta.url)),
23
- '../examples/basic/build/server/release.wasm',
24
- );
25
-
26
- describe('request envelope encoding', () => {
27
- it('encodes a minimal GET / exactly like the edge', () => {
28
- const out = encodeRequestEnvelope({
29
- method: 'GET',
30
- path: '/',
31
- headers: [],
32
- body: new Uint8Array(0),
33
- });
34
- // Mirrors envelope.rs `encode_minimal_get`.
35
- expect(out.length).toBe(10);
36
- expect(out[0]).toBe(0); // method GET
37
- expect(out.readUInt16LE(1)).toBe(1); // path_len
38
- expect(out.toString('utf8', 3, 4)).toBe('/');
39
- expect(out.readUInt16LE(4)).toBe(0); // n_headers
40
- expect(out.readUInt32LE(6)).toBe(0); // body_len
41
- });
42
-
43
- it('encodes a POST with a header and body exactly like the edge', () => {
44
- const out = encodeRequestEnvelope({
45
- method: 'POST',
46
- path: '/api',
47
- headers: [['host', 'example.com']],
48
- body: new TextEncoder().encode('hi'),
49
- });
50
- // Mirrors envelope.rs `encode_post_with_body_and_host`.
51
- expect(out[0]).toBe(1); // method POST
52
- expect(out.readUInt16LE(1)).toBe(4);
53
- expect(out.toString('utf8', 3, 7)).toBe('/api');
54
- expect(out.readUInt16LE(7)).toBe(1); // n_headers
55
- expect(out.readUInt16LE(9)).toBe(4); // name_len
56
- expect(out.readUInt16LE(11)).toBe(11); // val_len
57
- expect(out.toString('utf8', 13, 17)).toBe('host');
58
- expect(out.toString('utf8', 17, 28)).toBe('example.com');
59
- expect(out.readUInt32LE(28)).toBe(2); // body_len
60
- expect(out.toString('utf8', 32, 34)).toBe('hi');
61
- });
62
-
63
- it('rejects an unsupported method and oversized fields', () => {
64
- const base = { path: '/', headers: [], body: new Uint8Array(0) } as const;
65
- expect(() => encodeRequestEnvelope({ ...base, method: 'TRACE' })).toThrow(/unsupported/);
66
- expect(() =>
67
- encodeRequestEnvelope({ ...base, method: 'GET', path: '/'.repeat(0x10000) }),
68
- ).toThrow(/path too long/);
69
- expect(() =>
70
- encodeRequestEnvelope({
71
- ...base,
72
- method: 'GET',
73
- headers: [['x', 'y'.repeat(0x10000)]],
74
- }),
75
- ).toThrow(/header too long/);
76
- });
77
- });
78
-
79
- /** Hand-builds a response envelope (the layout the guest writes). */
80
- function buildResponse(status: number, headers: [string, string][], body: Uint8Array): Buffer {
81
- const parts: Buffer[] = [];
82
- const u16 = (v: number): Buffer => {
83
- const b = Buffer.allocUnsafe(2);
84
- b.writeUInt16LE(v);
85
- return b;
86
- };
87
- const u32 = (v: number): Buffer => {
88
- const b = Buffer.allocUnsafe(4);
89
- b.writeUInt32LE(v);
90
- return b;
91
- };
92
- parts.push(u16(status), u16(headers.length));
93
- for (const [n, v] of headers) {
94
- parts.push(u16(Buffer.byteLength(n)), u16(Buffer.byteLength(v)));
95
- parts.push(Buffer.from(n), Buffer.from(v));
96
- }
97
- parts.push(u32(body.length), Buffer.from(body));
98
- return Buffer.concat(parts);
99
- }
100
-
101
- describe('response envelope decoding', () => {
102
- it('round-trips status, headers and body', () => {
103
- const buf = buildResponse(
104
- 201,
105
- [
106
- ['content-type', 'application/json'],
107
- ['x-trace', 'abc'],
108
- ],
109
- new TextEncoder().encode('{"ok":true}'),
110
- );
111
- const resp = decodeResponseEnvelope(buf);
112
- expect(resp.status).toBe(201);
113
- expect(resp.headers).toEqual([
114
- ['content-type', 'application/json'],
115
- ['x-trace', 'abc'],
116
- ]);
117
- expect(Buffer.from(resp.body).toString()).toBe('{"ok":true}');
118
- });
119
-
120
- it('rejects truncation, zero status, and overflowing lengths', () => {
121
- expect(() => decodeResponseEnvelope(new Uint8Array([1]))).toThrow(/truncated/);
122
- expect(() => decodeResponseEnvelope(buildResponse(0, [], new Uint8Array(0)))).toThrow(
123
- /status 0/,
124
- );
125
- // Claim a huge header name with too few bytes behind it.
126
- const bad = Buffer.concat([Buffer.from([200, 0, 1, 0, 255, 255, 0, 0]), Buffer.from('hi')]);
127
- expect(() => decodeResponseEnvelope(bad)).toThrow(/truncated/);
128
- });
129
- });
130
-
131
- describe('handle() result unpacking', () => {
132
- it('splits the packed i64 into pointer and length', () => {
133
- expect(unpackHandleResult((65536n << 32n) | 8n)).toEqual({ ptr: 65536, len: 8 });
134
- expect(unpackHandleResult(0n)).toEqual({ ptr: 0, len: 0 });
135
- expect(unpackHandleResult(0xffffffff_ffffffffn)).toEqual({
136
- ptr: 0xffffffff,
137
- len: 0xffffffff,
138
- });
139
- });
140
- });
141
-
142
- describe('static file resolver', () => {
143
- it('resolves absolute request paths inside the static root', () => {
144
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'toil-static-'));
145
- const file = path.join(root, 'assets', 'app.css');
146
- try {
147
- fs.mkdirSync(path.dirname(file), { recursive: true });
148
- fs.writeFileSync(file, 'body{}');
149
-
150
- expect(resolveStaticFile(root, '/assets/app.css')).toBe(file);
151
- expect(resolveStaticFile(root, '/missing.css')).toBeNull();
152
- expect(resolveStaticFile(root, '/../app.css')).toBeNull();
153
- } finally {
154
- fs.rmSync(root, { recursive: true, force: true });
155
- }
156
- });
157
- });
158
-
159
- describe.skipIf(!fs.existsSync(EXAMPLE_WASM))('dispatch into the example server wasm', () => {
160
- const load = (): WasmServerModule => {
161
- const m = new WasmServerModule(EXAMPLE_WASM);
162
- m.refresh();
163
- return m;
164
- };
165
- const get = (m: WasmServerModule, p: string) =>
166
- m.dispatch({
167
- method: 'GET',
168
- path: p,
169
- headers: [['host', 'localhost:3000']],
170
- body: new Uint8Array(0),
171
- });
172
-
173
- it('serves a plain route', () => {
174
- const r = get(load(), '/json');
175
- expect(r.status).toBe(200);
176
- expect(r.unhandled).toBe(false);
177
- expect(Buffer.from(r.body).toString()).toBe('{"hello":"toiljs"}\n');
178
- });
179
-
180
- it('serves a @rest route with its content-type', () => {
181
- const r = get(load(), '/leaderboard');
182
- expect(r.status).toBe(200);
183
- expect(r.headers.some(([n, v]) => n === 'content-type' && v.includes('json'))).toBe(true);
184
- });
185
-
186
- it('marks a route miss as unhandled and strips the marker header', () => {
187
- const r = get(load(), '/definitely-missing');
188
- expect(r.status).toBe(404);
189
- expect(r.unhandled).toBe(true);
190
- expect(r.headers.some(([n]) => n === 'x-toil-unhandled')).toBe(false);
191
- });
192
-
193
- it('dispatches a POST body through the envelope', () => {
194
- const m = load();
195
- const r = m.dispatch({
196
- method: 'POST',
197
- path: '/players',
198
- headers: [
199
- ['host', 'localhost:3000'],
200
- ['content-type', 'application/json'],
201
- ],
202
- body: new TextEncoder().encode('{"name":"ada"}'),
203
- });
204
- expect(r.unhandled).toBe(false);
205
- expect(r.status).toBe(200);
206
- // u256 id and i64 score cross JSON as decimal strings, exact at any size (3 seeded
207
- // players, so the new player's id is 4).
208
- expect(Buffer.from(r.body).toString()).toBe('{"id":"4","name":"ada","score":"0"}');
209
- });
210
-
211
- it('keeps requests isolated across instances (fresh state per dispatch)', () => {
212
- const m = load();
213
- const a = get(m, '/json');
214
- const b = get(m, '/json');
215
- expect(Buffer.from(a.body).toString()).toBe(Buffer.from(b.body).toString());
216
- });
217
-
218
- // Exercises `SecureCookies` (HMAC-SHA256) end-to-end through the real
219
- // toilscript-compiled wasm with the Node-backed `env.crypto.*` host imports:
220
- // `/api/cookies/set` seals a signed `__Host-session`, `/api/cookies/inspect`
221
- // parses + verifies it. (as-pect cannot compile the crypto std, so this is its coverage.)
222
- const sessionCookie = (m: WasmServerModule): string => {
223
- const res = get(m, '/api/cookies/set');
224
- expect(res.status).toBe(200);
225
- const pair = res.headers
226
- .filter(([n]) => n === 'set-cookie')
227
- .map(([, v]) => v.split(';')[0])
228
- .find((v) => v.startsWith('__Host-session='));
229
- expect(pair).toBeDefined();
230
- return pair!; // "__Host-session=<sealed>"
231
- };
232
- const inspect = (m: WasmServerModule, cookie: string): string =>
233
- Buffer.from(
234
- m.dispatch({
235
- method: 'GET',
236
- path: '/api/cookies/inspect',
237
- headers: [
238
- ['host', 'localhost:3000'],
239
- ['cookie', cookie],
240
- ],
241
- body: new Uint8Array(0),
242
- }).body,
243
- ).toString();
244
-
245
- it('round-trips a signed cookie (SecureCookies sign -> unsign)', () => {
246
- const m = load();
247
- expect(inspect(m, sessionCookie(m))).toContain('"session":"user-42"');
248
- });
249
-
250
- it('rejects a tampered signed cookie', () => {
251
- const m = load();
252
- const pair = sessionCookie(m);
253
- const eq = pair.indexOf('=');
254
- const name = pair.slice(0, eq);
255
- const val = pair.slice(eq + 1);
256
- const tampered = `${name}=${val[0] === 'A' ? 'B' : 'A'}${val.slice(1)}`;
257
- expect(inspect(m, tampered)).toContain('"session":null');
258
- });
259
- });
@@ -1,298 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import {
4
- checkAuthSecrets,
5
- checkBasePath,
6
- checkDevScripts,
7
- checkDuplicatePatterns,
8
- type CheckGroup,
9
- checkMigrationsDir,
10
- checkMountSlots,
11
- checkNode,
12
- checkPeer,
13
- checkPrettierPlugin,
14
- checkRelativeAssets,
15
- checkRestDispatch,
16
- checkRootElement,
17
- checkRpcWiring,
18
- checkSeoUrl,
19
- checkServerTsPlugin,
20
- checkStyling,
21
- checkTypeScript,
22
- findRelativeAssets,
23
- rangeMajor,
24
- satisfiesMin,
25
- summarize,
26
- } from '../src/cli/diagnostics';
27
-
28
- describe('satisfiesMin', () => {
29
- it('compares against a >= minimum, ignoring range prefixes', () => {
30
- expect(satisfiesMin('25.8.0', '>=24.0.0')).toBe(true);
31
- expect(satisfiesMin('20.0.0', '>=24.0.0')).toBe(false);
32
- expect(satisfiesMin('^19.2.6', '>=18.0.0')).toBe(true); // declared caret range, compared by floor
33
- expect(satisfiesMin('6.0.0', '>=6.0.0')).toBe(true);
34
- expect(satisfiesMin('5.9.9', '>=6.0.0')).toBe(false);
35
- });
36
- });
37
-
38
- describe('checkMountSlots', () => {
39
- it('warns when mount() omits slots, passes when present', () => {
40
- expect(checkMountSlots('Toil.mount(routes, layout, notFound, globalError);').status).toBe(
41
- 'warn',
42
- );
43
- expect(
44
- checkMountSlots('Toil.mount(routes, layout, notFound, globalError, slots);').status,
45
- ).toBe('pass');
46
- });
47
-
48
- it('warns when there is no entry or no mount() call', () => {
49
- expect(checkMountSlots(null).status).toBe('warn');
50
- expect(checkMountSlots('export const x = 1;').status).toBe('warn');
51
- });
52
- });
53
-
54
- describe('findRelativeAssets / checkRelativeAssets', () => {
55
- it('flags root-relative asset paths but not absolute, url, or expression refs', () => {
56
- const issues = findRelativeAssets([
57
- {
58
- path: 'client/components/Header.tsx',
59
- source: [
60
- '<img src="images/logo.svg" />', // broken: relative asset
61
- '<img src="/images/logo.svg" />', // ok: root-absolute
62
- '<img src="https://cdn/x.png" />', // ok: url
63
- '<img src={logo} />', // ok: expression (not a string literal)
64
- '<a href="/about">about</a>', // ok: no extension, route
65
- ].join('\n'),
66
- },
67
- ]);
68
- expect(issues).toHaveLength(1);
69
- expect(issues[0]).toMatchObject({ line: 1, value: 'images/logo.svg' });
70
- expect(checkRelativeAssets(issues).status).toBe('warn');
71
- expect(checkRelativeAssets([]).status).toBe('pass');
72
- });
73
- });
74
-
75
- describe('config + environment checks', () => {
76
- it('checkBasePath: root or wrapped in slashes passes, otherwise warns', () => {
77
- expect(checkBasePath('/').status).toBe('pass');
78
- expect(checkBasePath('/app/').status).toBe('pass');
79
- expect(checkBasePath('/app').status).toBe('warn');
80
- });
81
-
82
- it('checkSeoUrl: warns only when seo is configured without a url', () => {
83
- expect(checkSeoUrl(false, false).status).toBe('pass');
84
- expect(checkSeoUrl(true, true).status).toBe('pass');
85
- expect(checkSeoUrl(true, false).status).toBe('warn');
86
- });
87
-
88
- it('checkNode / checkPeer reflect version satisfaction', () => {
89
- expect(checkNode('25.0.0', '>=24.0.0').status).toBe('pass');
90
- expect(checkNode('18.0.0', '>=24.0.0').status).toBe('fail');
91
- expect(checkPeer('react', null, '>=18.0.0').status).toBe('fail');
92
- expect(checkPeer('react', '^17.0.0', '>=18.0.0').status).toBe('warn');
93
- expect(checkPeer('react', '^19.0.0', '>=18.0.0').status).toBe('pass');
94
- });
95
-
96
- it('checkTypeScript fails an installed 7.x (the native port, no compiler API)', () => {
97
- const check = checkTypeScript('7.0.2', '^7.0.2');
98
- expect(check.status).toBe('fail');
99
- expect(check.detail).toContain('7.0.2');
100
- expect(check.fix).toContain('^6.0.3');
101
- });
102
-
103
- it('checkTypeScript fails a declared 7.x even while a supported copy is installed', () => {
104
- // The installed copy still works, but the next install would pull the native port.
105
- expect(checkTypeScript('6.0.3', '^7.0.0').status).toBe('fail');
106
- expect(checkTypeScript('6.0.3', '>=7').status).toBe('fail');
107
- });
108
-
109
- it('checkTypeScript passes a supported 6.x and warns below the floor', () => {
110
- expect(checkTypeScript('6.0.3', '^6.0.3').status).toBe('pass');
111
- expect(checkTypeScript('5.9.3', '^5.9.0').status).toBe('warn');
112
- expect(checkTypeScript(null, null).status).toBe('fail');
113
- });
114
-
115
- it('rangeMajor reads the major a range floats to, ignoring comparators', () => {
116
- expect(rangeMajor('^7.0.2')).toBe(7);
117
- expect(rangeMajor('>=6.0.0 <7.0.0')).toBe(6);
118
- expect(rangeMajor('~6.0')).toBe(6);
119
- expect(rangeMajor('*')).toBe(null);
120
- });
121
-
122
- it('checkDuplicatePatterns flags repeated route URLs', () => {
123
- expect(checkDuplicatePatterns(['/', '/about', '/blog/:id']).status).toBe('pass');
124
- expect(checkDuplicatePatterns(['/a', '/a']).status).toBe('warn');
125
- });
126
-
127
- it('checkRootElement requires an id="root" mount target', () => {
128
- expect(checkRootElement('<div id="root"></div>').status).toBe('pass');
129
- expect(checkRootElement('<div id="app"></div>').status).toBe('fail');
130
- expect(checkRootElement(null).status).toBe('fail');
131
- });
132
-
133
- it('checkStyling fails when an imported preprocessor/Tailwind is not installed', () => {
134
- expect(
135
- checkStyling({
136
- preprocessorImported: 'sass',
137
- preprocessorInstalled: false,
138
- tailwindImported: false,
139
- tailwindInstalled: false,
140
- }).status,
141
- ).toBe('fail');
142
- expect(
143
- checkStyling({
144
- preprocessorImported: 'sass',
145
- preprocessorInstalled: true,
146
- tailwindImported: true,
147
- tailwindInstalled: false,
148
- }).status,
149
- ).toBe('fail');
150
- expect(
151
- checkStyling({
152
- preprocessorImported: 'css',
153
- preprocessorInstalled: true,
154
- tailwindImported: false,
155
- tailwindInstalled: false,
156
- }).status,
157
- ).toBe('pass');
158
- });
159
- });
160
-
161
- describe('checkRpcWiring', () => {
162
- const wired = {
163
- buildServerWired: true,
164
- tsconfigWired: true,
165
- gitignoreWired: true,
166
- toilscriptOk: true,
167
- };
168
-
169
- it('passes when fully wired', () => {
170
- expect(checkRpcWiring(wired).status).toBe('pass');
171
- });
172
-
173
- it('warns and lists every missing piece', () => {
174
- const c = checkRpcWiring({
175
- buildServerWired: false,
176
- tsconfigWired: false,
177
- gitignoreWired: false,
178
- toilscriptOk: false,
179
- });
180
- expect(c.status).toBe('warn');
181
- expect(c.detail).toContain('toilscript');
182
- expect(c.detail).toContain('--rpcModule');
183
- expect(c.detail).toContain('tsconfig');
184
- expect(c.detail).toContain('.gitignore');
185
- expect(c.fix).toContain('--fix');
186
- });
187
-
188
- it('warns on a single missing piece', () => {
189
- const c = checkRpcWiring({ ...wired, gitignoreWired: false });
190
- expect(c.status).toBe('warn');
191
- expect(c.detail).toContain('.gitignore');
192
- });
193
- });
194
-
195
- describe('checkRestDispatch', () => {
196
- it('passes when there are no @rest controllers', () => {
197
- expect(checkRestDispatch({ hasControllers: false, dispatched: false }).status).toBe('pass');
198
- });
199
-
200
- it('passes when controllers are dispatched', () => {
201
- expect(checkRestDispatch({ hasControllers: true, dispatched: true }).status).toBe('pass');
202
- });
203
-
204
- it('warns when controllers exist but nothing dispatches them', () => {
205
- const c = checkRestDispatch({ hasControllers: true, dispatched: false });
206
- expect(c.status).toBe('warn');
207
- expect(c.detail).toContain('Rest.dispatch');
208
- expect(c.fix).toContain('RestHandler');
209
- });
210
- });
211
-
212
- describe('checkPrettierPlugin', () => {
213
- it('passes when present', () => {
214
- expect(checkPrettierPlugin(true).status).toBe('pass');
215
- });
216
- it('warns (not fails) when missing, pointing at --fix', () => {
217
- const c = checkPrettierPlugin(false);
218
- expect(c.status).toBe('warn');
219
- expect(c.fix).toContain('--fix');
220
- });
221
- });
222
-
223
- describe('checkServerTsPlugin', () => {
224
- it('passes when the toilscript LS plugin is wired', () => {
225
- expect(checkServerTsPlugin(true).status).toBe('pass');
226
- });
227
- it('warns (not fails) when missing, naming the TS2339 false positive and --fix', () => {
228
- const c = checkServerTsPlugin(false);
229
- expect(c.status).toBe('warn');
230
- expect(c.detail).toContain('TS2339');
231
- expect(c.fix).toContain('--fix');
232
- });
233
- });
234
-
235
- describe('checkAuthSecrets', () => {
236
- it('passes when auth is not used', () => {
237
- expect(checkAuthSecrets({ usesAuth: false, sessionSecretSet: false }).status).toBe('pass');
238
- });
239
- it('passes when auth is used and the session secret is set', () => {
240
- expect(checkAuthSecrets({ usesAuth: true, sessionSecretSet: true }).status).toBe('pass');
241
- });
242
- it('warns about session forgery when auth is used but the secret is unset', () => {
243
- const c = checkAuthSecrets({ usesAuth: true, sessionSecretSet: false });
244
- expect(c.status).toBe('warn');
245
- expect(c.detail).toContain('AUTH_SESSION_SECRET');
246
- expect(c.detail).toContain('forge');
247
- expect(c.fix).toContain('.env.secrets');
248
- });
249
- });
250
-
251
- describe('checkMigrationsDir', () => {
252
- it('passes when the server/migrations/ folder exists', () => {
253
- expect(checkMigrationsDir(true).status).toBe('pass');
254
- });
255
- it('warns (not fails) when missing, naming the convention and the update fix', () => {
256
- const c = checkMigrationsDir(false);
257
- expect(c.status).toBe('warn');
258
- expect(c.detail).toContain('migration.ts');
259
- expect(c.fix).toContain('toiljs update');
260
- });
261
- });
262
-
263
- describe('summarize', () => {
264
- it('tallies pass/warn/fail across groups', () => {
265
- const groups: CheckGroup[] = [
266
- {
267
- title: 'A',
268
- checks: [
269
- { id: '1', label: 'x', status: 'pass' },
270
- { id: '2', label: 'y', status: 'warn' },
271
- ],
272
- },
273
- { title: 'B', checks: [{ id: '3', label: 'z', status: 'fail' }] },
274
- ];
275
- expect(summarize(groups)).toEqual({ pass: 1, warn: 1, fail: 1 });
276
- });
277
- });
278
-
279
- describe('checkDevScripts', () => {
280
- it('passes when no script wraps toiljs in npx', () => {
281
- const c = checkDevScripts({ dev: 'toiljs dev', build: 'toiljs build' });
282
- expect(c.status).toBe('pass');
283
- });
284
-
285
- it('warns and names the offending scripts using npx toiljs', () => {
286
- const c = checkDevScripts({ dev: 'npx toiljs dev', build: 'toiljs build' });
287
- expect(c.status).toBe('warn');
288
- expect(c.detail).toContain('dev');
289
- expect(c.detail).not.toContain('build');
290
- expect(c.fix).toMatch(/toiljs <cmd>/);
291
- });
292
-
293
- it('does not flag unrelated npx usage or substrings', () => {
294
- expect(checkDevScripts({ x: 'npx create-toiljs my-app' }).status).toBe('pass');
295
- expect(checkDevScripts({ x: 'echo npxtoiljs' }).status).toBe('pass');
296
- expect(checkDevScripts({}).status).toBe('pass');
297
- });
298
- });