toiljs 0.0.116 → 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 (325) hide show
  1. package/CHANGELOG.md +5 -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/dev/devtools.js +1 -1
  8. package/build/client/dev/error-overlay.js +1 -1
  9. package/build/client/routing/mount.js +1 -1
  10. package/build/compiler/.tsbuildinfo +1 -1
  11. package/build/compiler/auth-emails.js +7 -3
  12. package/build/compiler/emails.js +1 -1
  13. package/build/compiler/index.d.ts +1 -0
  14. package/build/compiler/index.js +25 -4
  15. package/build/compiler/pages.js +2 -3
  16. package/build/compiler/prerender.d.ts +3 -8
  17. package/build/compiler/prerender.js +88 -127
  18. package/build/compiler/ssg.js +3 -4
  19. package/build/compiler/template-build.js +3 -4
  20. package/build/compiler/toil-docs.generated.js +6 -5
  21. package/build/compiler/vite.js +3 -6
  22. package/build/devserver/.tsbuildinfo +1 -1
  23. package/build/devserver/db/database.js +7 -3
  24. package/build/devserver/db/types.js +1 -1
  25. package/build/devserver/production.js +4 -3
  26. package/build/devserver/runtime/crypto.d.ts +1 -1
  27. package/build/io/.tsbuildinfo +1 -1
  28. package/build/logger/.tsbuildinfo +1 -1
  29. package/build/shared/.tsbuildinfo +1 -1
  30. package/examples/basic/client/routes/analytics.tsx +7 -5
  31. package/examples/basic/server/tsconfig.json +1 -3
  32. package/package.json +45 -44
  33. package/presets/no-uint8array-tostring.js +120 -153
  34. package/presets/oxlint.d.ts +5 -0
  35. package/presets/oxlint.js +224 -0
  36. package/server/runtime/tsconfig.json +1 -3
  37. package/tsconfig.json +2 -11
  38. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  39. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  40. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  41. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  42. package/.github/PULL_REQUEST_TEMPLATE.md +0 -43
  43. package/.github/changelog-config.json +0 -45
  44. package/.github/dependabot.yml +0 -27
  45. package/.github/workflows/ci.yml +0 -222
  46. package/.vscode/settings.json +0 -10
  47. package/docs/README.md +0 -107
  48. package/docs/auth/README.md +0 -104
  49. package/docs/auth/configuration.md +0 -105
  50. package/docs/auth/emails.md +0 -92
  51. package/docs/auth/extending.md +0 -202
  52. package/docs/auth/how-it-works.md +0 -138
  53. package/docs/auth/usage.md +0 -188
  54. package/docs/backend/README.md +0 -143
  55. package/docs/backend/data.md +0 -351
  56. package/docs/backend/rest.md +0 -402
  57. package/docs/backend/rpc.md +0 -226
  58. package/docs/background/README.md +0 -114
  59. package/docs/background/daemons.md +0 -276
  60. package/docs/background/derive.md +0 -179
  61. package/docs/cli/README.md +0 -379
  62. package/docs/concepts/ai-guide.md +0 -132
  63. package/docs/concepts/config.md +0 -416
  64. package/docs/concepts/decorators.md +0 -127
  65. package/docs/concepts/security.md +0 -108
  66. package/docs/concepts/tiers.md +0 -166
  67. package/docs/concepts/types.md +0 -216
  68. package/docs/database/README.md +0 -143
  69. package/docs/database/capacity.md +0 -350
  70. package/docs/database/counters.md +0 -174
  71. package/docs/database/documents.md +0 -277
  72. package/docs/database/events.md +0 -307
  73. package/docs/database/membership.md +0 -246
  74. package/docs/database/setup.md +0 -155
  75. package/docs/database/unique.md +0 -216
  76. package/docs/database/views.md +0 -246
  77. package/docs/frontend/README.md +0 -104
  78. package/docs/frontend/components.md +0 -286
  79. package/docs/frontend/data-fetching.md +0 -260
  80. package/docs/frontend/images.md +0 -148
  81. package/docs/frontend/metadata.md +0 -344
  82. package/docs/frontend/navigation.md +0 -296
  83. package/docs/frontend/rendering.md +0 -236
  84. package/docs/frontend/routing.md +0 -346
  85. package/docs/frontend/scripts.md +0 -118
  86. package/docs/frontend/search.md +0 -191
  87. package/docs/frontend/styling.md +0 -147
  88. package/docs/frontend/toil-global.md +0 -216
  89. package/docs/getting-started/README.md +0 -81
  90. package/docs/getting-started/create-project.md +0 -131
  91. package/docs/getting-started/deploy.md +0 -101
  92. package/docs/getting-started/first-app.md +0 -215
  93. package/docs/getting-started/installation.md +0 -124
  94. package/docs/getting-started/migrating.md +0 -125
  95. package/docs/getting-started/project-structure.md +0 -163
  96. package/docs/introduction/README.md +0 -66
  97. package/docs/introduction/design-principles.md +0 -81
  98. package/docs/introduction/distributed.md +0 -91
  99. package/docs/introduction/how-it-works.md +0 -121
  100. package/docs/introduction/hyperscale.md +0 -70
  101. package/docs/introduction/modern-stack.md +0 -85
  102. package/docs/introduction/vs-other-frameworks.md +0 -64
  103. package/docs/introduction/why-toil.md +0 -99
  104. package/docs/llms.txt +0 -95
  105. package/docs/realtime/README.md +0 -102
  106. package/docs/realtime/channels.md +0 -211
  107. package/docs/realtime/streams.md +0 -369
  108. package/docs/services/README.md +0 -60
  109. package/docs/services/analytics.md +0 -279
  110. package/docs/services/caching.md +0 -175
  111. package/docs/services/cookies.md +0 -235
  112. package/docs/services/crypto.md +0 -209
  113. package/docs/services/email.md +0 -289
  114. package/docs/services/environment.md +0 -141
  115. package/docs/services/ratelimit.md +0 -174
  116. package/docs/services/time.md +0 -85
  117. package/eslint.config.js +0 -57
  118. package/examples/basic/client/routes/docs/[...slug].tsx +0 -12
  119. package/presets/eslint.js +0 -88
  120. package/src/backend/index.ts +0 -204
  121. package/src/cli/configure.ts +0 -363
  122. package/src/cli/create.ts +0 -924
  123. package/src/cli/db.ts +0 -158
  124. package/src/cli/diagnostics.ts +0 -665
  125. package/src/cli/doctor.ts +0 -982
  126. package/src/cli/features.ts +0 -170
  127. package/src/cli/index.ts +0 -326
  128. package/src/cli/notify.ts +0 -120
  129. package/src/cli/proc.ts +0 -56
  130. package/src/cli/ui.ts +0 -169
  131. package/src/cli/update.ts +0 -248
  132. package/src/cli/updates.ts +0 -92
  133. package/src/cli/validate.ts +0 -31
  134. package/src/cli/version-check.ts +0 -125
  135. package/src/client/auth.ts +0 -869
  136. package/src/client/channel/channel.ts +0 -146
  137. package/src/client/components/Form.tsx +0 -65
  138. package/src/client/components/Image.tsx +0 -160
  139. package/src/client/components/Script.tsx +0 -113
  140. package/src/client/components/Slot.tsx +0 -21
  141. package/src/client/dev/devtools.tsx +0 -1089
  142. package/src/client/dev/error-overlay.tsx +0 -225
  143. package/src/client/errors.ts +0 -11
  144. package/src/client/head/head.ts +0 -182
  145. package/src/client/head/metadata.ts +0 -110
  146. package/src/client/index.ts +0 -130
  147. package/src/client/navigation/Link.tsx +0 -108
  148. package/src/client/navigation/NavLink.tsx +0 -86
  149. package/src/client/navigation/navigation.ts +0 -235
  150. package/src/client/navigation/prefetch.ts +0 -169
  151. package/src/client/navigation/scroll.ts +0 -53
  152. package/src/client/routing/Router.tsx +0 -216
  153. package/src/client/routing/action.ts +0 -122
  154. package/src/client/routing/error-boundary.tsx +0 -43
  155. package/src/client/routing/hooks.ts +0 -140
  156. package/src/client/routing/lazy.ts +0 -77
  157. package/src/client/routing/loader.ts +0 -381
  158. package/src/client/routing/match.ts +0 -47
  159. package/src/client/routing/mount.tsx +0 -90
  160. package/src/client/routing/params-context.ts +0 -10
  161. package/src/client/routing/slot-context.ts +0 -7
  162. package/src/client/rpc.ts +0 -97
  163. package/src/client/search/search.ts +0 -189
  164. package/src/client/search/use-page-search.ts +0 -73
  165. package/src/client/ssr/markers.tsx +0 -172
  166. package/src/client/stream/client.ts +0 -237
  167. package/src/client/types.ts +0 -73
  168. package/src/compiler/auth-emails.ts +0 -312
  169. package/src/compiler/config.ts +0 -369
  170. package/src/compiler/docs.ts +0 -127
  171. package/src/compiler/email-preview.ts +0 -314
  172. package/src/compiler/emails.ts +0 -404
  173. package/src/compiler/fonts.ts +0 -89
  174. package/src/compiler/generate.ts +0 -471
  175. package/src/compiler/image-blur.ts +0 -42
  176. package/src/compiler/image-report.ts +0 -88
  177. package/src/compiler/index.ts +0 -1362
  178. package/src/compiler/pages.ts +0 -49
  179. package/src/compiler/plugin.ts +0 -391
  180. package/src/compiler/prerender.ts +0 -263
  181. package/src/compiler/routes.ts +0 -170
  182. package/src/compiler/seo.ts +0 -415
  183. package/src/compiler/sri.ts +0 -144
  184. package/src/compiler/ssg.ts +0 -177
  185. package/src/compiler/ssr-codegen.ts +0 -85
  186. package/src/compiler/template-build.ts +0 -676
  187. package/src/compiler/template.ts +0 -262
  188. package/src/compiler/toil-docs.generated.ts +0 -77
  189. package/src/compiler/vite.ts +0 -245
  190. package/src/devserver/analytics/index.ts +0 -317
  191. package/src/devserver/config/dotenv.ts +0 -102
  192. package/src/devserver/config/env.ts +0 -30
  193. package/src/devserver/config/ratelimit.ts +0 -123
  194. package/src/devserver/daemon/catalog.ts +0 -120
  195. package/src/devserver/daemon/cron.ts +0 -87
  196. package/src/devserver/daemon/host.ts +0 -134
  197. package/src/devserver/daemon/index.ts +0 -369
  198. package/src/devserver/daemon/runtime.ts +0 -48
  199. package/src/devserver/db/catalog.ts +0 -109
  200. package/src/devserver/db/database.ts +0 -1834
  201. package/src/devserver/db/derives.ts +0 -121
  202. package/src/devserver/db/index.ts +0 -20
  203. package/src/devserver/db/routeKinds.ts +0 -191
  204. package/src/devserver/db/types.ts +0 -168
  205. package/src/devserver/email/caps.ts +0 -0
  206. package/src/devserver/email/config.ts +0 -141
  207. package/src/devserver/email/console.ts +0 -348
  208. package/src/devserver/email/index.ts +0 -155
  209. package/src/devserver/email/providers.ts +0 -131
  210. package/src/devserver/email/status.ts +0 -23
  211. package/src/devserver/email/validate.ts +0 -37
  212. package/src/devserver/email/wire.ts +0 -55
  213. package/src/devserver/http/cache.ts +0 -0
  214. package/src/devserver/http/envelope.ts +0 -157
  215. package/src/devserver/http/proxy.ts +0 -172
  216. package/src/devserver/http/runtime.ts +0 -387
  217. package/src/devserver/index.ts +0 -43
  218. package/src/devserver/production-ipc.ts +0 -63
  219. package/src/devserver/production-worker.ts +0 -83
  220. package/src/devserver/production.ts +0 -718
  221. package/src/devserver/runtime/crypto.ts +0 -587
  222. package/src/devserver/runtime/host.ts +0 -427
  223. package/src/devserver/runtime/module.ts +0 -442
  224. package/src/devserver/server.ts +0 -251
  225. package/src/devserver/ssr.ts +0 -208
  226. package/src/devserver/stream/catalog.ts +0 -106
  227. package/src/devserver/stream/host.ts +0 -42
  228. package/src/devserver/stream/index.ts +0 -301
  229. package/src/devserver/stream/manager.ts +0 -167
  230. package/src/devserver/stream/router.ts +0 -101
  231. package/src/devserver/stream/wire.ts +0 -58
  232. package/src/devserver/stream/ws.ts +0 -78
  233. package/src/devserver/wasm/sections.ts +0 -59
  234. package/src/devserver/wasm/surface.ts +0 -115
  235. package/src/io/FastMap.ts +0 -151
  236. package/src/io/FastSet.ts +0 -113
  237. package/src/io/codec.ts +0 -362
  238. package/src/io/index.ts +0 -10
  239. package/src/io/lengths.ts +0 -14
  240. package/src/io/types.ts +0 -19
  241. package/src/logger/index.ts +0 -22
  242. package/src/shared/index.ts +0 -46
  243. package/test/analytics-dev.test.ts +0 -113
  244. package/test/assembly/aspect-shim.ts +0 -33
  245. package/test/assembly/cookie.spec.ts +0 -303
  246. package/test/assembly/example.spec.ts +0 -22
  247. package/test/assembly/ssr.spec.ts +0 -95
  248. package/test/assembly.test.ts +0 -59
  249. package/test/auth-emails.test.ts +0 -118
  250. package/test/built-ssr.test.ts +0 -148
  251. package/test/channel.test.ts +0 -21
  252. package/test/config-host-port.test.ts +0 -59
  253. package/test/configure.test.ts +0 -94
  254. package/test/daemon-build.test.ts +0 -278
  255. package/test/daemon-catalog.test.ts +0 -349
  256. package/test/daemon-emulation.test.ts +0 -256
  257. package/test/db.test.ts +0 -0
  258. package/test/devserver-database.test.ts +0 -1102
  259. package/test/devserver-email.test.ts +0 -306
  260. package/test/devserver-pqauth.test.ts +0 -93
  261. package/test/devserver-secrets.test.ts +0 -63
  262. package/test/devserver.test.ts +0 -259
  263. package/test/doctor.test.ts +0 -298
  264. package/test/dom/Image.test.tsx +0 -144
  265. package/test/dom/Link.test.tsx +0 -67
  266. package/test/dom/NavLink.test.tsx +0 -37
  267. package/test/dom/Script.test.tsx +0 -48
  268. package/test/dom/action.test.tsx +0 -146
  269. package/test/dom/error-overlay.test.tsx +0 -44
  270. package/test/dom/loader.test.tsx +0 -121
  271. package/test/dom/navigation.test.ts +0 -59
  272. package/test/dom/revalidate.test.tsx +0 -38
  273. package/test/dom/route-head.test.tsx +0 -56
  274. package/test/dom/router-loading.test.tsx +0 -44
  275. package/test/dom/scroll.test.ts +0 -56
  276. package/test/dom/slot.test.tsx +0 -131
  277. package/test/dom/use-metadata.test.tsx +0 -58
  278. package/test/dom/view-transitions.test.tsx +0 -53
  279. package/test/dynamic-routing.test.ts +0 -132
  280. package/test/email-console.test.ts +0 -86
  281. package/test/email-preview.test.ts +0 -73
  282. package/test/emails.test.ts +0 -58
  283. package/test/errors.test.ts +0 -21
  284. package/test/example-guestbook.test.ts +0 -123
  285. package/test/features.test.ts +0 -149
  286. package/test/fixtures/bignum-wire/spec.ts +0 -25
  287. package/test/fixtures/daemon-app.ts +0 -65
  288. package/test/fixtures/stream-echo.ts +0 -26
  289. package/test/fixtures/stream-gate.ts +0 -28
  290. package/test/fixtures/stream-trap.ts +0 -18
  291. package/test/fixtures/stream-typed.ts +0 -41
  292. package/test/fonts.test.ts +0 -28
  293. package/test/global-setup.ts +0 -17
  294. package/test/head.test.ts +0 -42
  295. package/test/image-blur.test.ts +0 -50
  296. package/test/io.test.ts +0 -117
  297. package/test/metadata.test.ts +0 -40
  298. package/test/navlink.test.ts +0 -28
  299. package/test/pages.test.ts +0 -105
  300. package/test/placeholder.test.ts +0 -9
  301. package/test/pqauth-e2e.test.ts +0 -216
  302. package/test/pqauth-email.test.ts +0 -801
  303. package/test/prerender.test.ts +0 -116
  304. package/test/prettier-plugin.test.ts +0 -46
  305. package/test/routes.test.ts +0 -76
  306. package/test/rpc-bignum-wire.test.ts +0 -164
  307. package/test/rpc-dispatch.test.ts +0 -132
  308. package/test/rpc-kinds.test.ts +0 -18
  309. package/test/rpc.test.ts +0 -66
  310. package/test/search.test.ts +0 -114
  311. package/test/seo.test.ts +0 -175
  312. package/test/slot-layouts.test.ts +0 -69
  313. package/test/sri.test.ts +0 -129
  314. package/test/ssg.test.ts +0 -36
  315. package/test/ssr-hydration.test.tsx +0 -122
  316. package/test/ssr-render.test.ts +0 -197
  317. package/test/ssr-template.test.tsx +0 -482
  318. package/test/stream-emulation.test.ts +0 -479
  319. package/test/ui.test.ts +0 -40
  320. package/test/update.test.ts +0 -58
  321. package/test/validate.test.ts +0 -42
  322. package/test/version-check.test.ts +0 -130
  323. package/tests/data-parity/generated-parity.ts +0 -99
  324. package/tests/data-parity/parity.ts +0 -80
  325. package/tests/data-parity/spec.ts +0 -46
@@ -1,73 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import path from 'node:path';
3
-
4
- import { createServer } from 'vite';
5
- import { describe, expect, it } from 'vitest';
6
-
7
- import { loadConfig } from '../src/compiler/config';
8
- import {
9
- emailsVersion,
10
- listEmails,
11
- previewShellHtml,
12
- renderEmailByName,
13
- } from '../src/compiler/email-preview';
14
- import { createViteConfig } from '../src/compiler/vite';
15
-
16
- const EXAMPLE = path.resolve(__dirname, '../examples/basic');
17
-
18
- // Drives a Vite server over examples/basic; skip where the example's deps are
19
- // not installed (e.g. CI without the example set up).
20
- describe.skipIf(!existsSync(path.join(EXAMPLE, 'node_modules')))(
21
- 'email preview end-to-end (examples/basic)',
22
- () => {
23
- it('lists Welcome and inlines its emails/styles/email.css; client/* alias resolves', async () => {
24
- const cfg = await loadConfig({ root: EXAMPLE });
25
- const items = listEmails(cfg);
26
- expect(items.map((i) => i.name)).toContain('Welcome');
27
-
28
- const server = await createServer({
29
- ...(await createViteConfig(cfg)),
30
- server: { middlewareMode: true, hmr: false },
31
- appType: 'custom',
32
- logLevel: 'silent',
33
- });
34
- try {
35
- const r = await renderEmailByName(server, cfg, 'Welcome');
36
- if (!r) throw new Error('Welcome did not render');
37
- // tokens discovered from props
38
- expect(r.tokens).toEqual(['code', 'name']);
39
- // subject token template
40
- expect(r.subject).toBe('Welcome to toiljs, {{name}}');
41
- // .email-title { color: #f5f6fa } from emails/styles/email.css inlined onto the <h1>
42
- expect(r.html).toMatch(/<h1[^>]*style="[^"]*color:\s*#f5f6fa/i);
43
- // .email-card { background-color: #0e1520 } inlined onto the card <table>
44
- expect(r.html).toMatch(/<table[^>]*style="[^"]*background-color:\s*#0e1520/i);
45
-
46
- // The `client/*` reuse alias still resolves project CSS (the documented
47
- // `import 'client/styles/…'` path), independent of where the demo keeps its styles.
48
- const aliased = (await server.ssrLoadModule('client/styles/main.css?inline')) as {
49
- default?: unknown;
50
- };
51
- expect(typeof aliased.default).toBe('string');
52
- } finally {
53
- await server.close();
54
- }
55
- }, 30000);
56
-
57
- it('emailsVersion is a non-empty mtime:count fingerprint', async () => {
58
- const cfg = await loadConfig({ root: EXAMPLE });
59
- const v = emailsVersion(cfg);
60
- expect(v).toMatch(/^\d+(\.\d+)?:\d+$/);
61
- // at least Welcome.tsx + the client CSS files were counted
62
- expect(Number(v.split(':')[1])).toBeGreaterThan(1);
63
- });
64
-
65
- it('the preview shell wires the dev endpoints', () => {
66
- const html = previewShellHtml();
67
- expect(html).toContain("var BASE = '/__toil/emails'");
68
- for (const frag of ["BASE + '/list'", "BASE + '/render?name='", "BASE + '/version'"]) {
69
- expect(html).toContain(frag);
70
- }
71
- expect(html).toContain('/__toil/open?file='); // open-in-editor
72
- });
73
- });
@@ -1,58 +0,0 @@
1
- import { createElement, type ReactElement } from 'react';
2
- import { renderToStaticMarkup } from 'react-dom/server';
3
- import { describe, expect, it } from 'vitest';
4
-
5
- import { __test } from '../src/compiler/emails';
6
-
7
- const render = (el: unknown): string => renderToStaticMarkup(el as ReactElement);
8
-
9
- describe('renderModule', () => {
10
- it('discovers props as {{tokens}} and renders placeholders (alpha-sorted, deduped)', async () => {
11
- const mod = {
12
- default: (p: { name: string; code: string }) =>
13
- createElement('p', null, `Hi ${p.name}, code ${p.code}`),
14
- };
15
- const r = await __test.renderModule('Welcome', mod, render);
16
- if (!r) throw new Error('expected a rendered email');
17
- expect(r.tokens).toEqual(['code', 'name']);
18
- expect(r.html).toContain('{{name}}');
19
- expect(r.html).toContain('{{code}}');
20
- });
21
-
22
- it('returns null when there is no default-exported component', async () => {
23
- expect(await __test.renderModule('X', { default: 'nope' }, render)).toBeNull();
24
- });
25
-
26
- it('inlines imported CSS into element style="" (the reuse path)', async () => {
27
- const mod = { default: () => createElement('h1', { className: 'email-title' }, 'Hello') };
28
- const css = '.email-title { color: #111827; font-size: 22px; }';
29
- const r = await __test.renderModule('Styled', mod, render, css);
30
- if (!r) throw new Error('expected a rendered email');
31
- // The class rule is moved onto the element as an inline style by the inliner.
32
- expect(r.html).toMatch(/<h1[^>]*style="[^"]*color:\s*#111827/i);
33
- expect(r.html).toMatch(/font-size:\s*22px/i);
34
- });
35
- });
36
-
37
- describe('renderModuleSource', () => {
38
- it('generates a typed Emails.<Name>.send with alpha-sorted token params', () => {
39
- const src = __test.renderModuleSource([
40
- {
41
- name: 'Welcome',
42
- subject: 'Welcome, {{name}}!',
43
- html: '<p>{{code}}</p>',
44
- text: 'code {{code}}',
45
- tokens: ['code', 'name'],
46
- purpose: 'welcome',
47
- },
48
- ]);
49
- expect(src).toContain('export namespace Emails {');
50
- expect(src).toContain('export namespace Welcome {');
51
- expect(src).toContain(
52
- 'export function send(to: string, code: string, name: string, purpose: string = "welcome")',
53
- );
54
- expect(src).toContain(
55
- 'return new EmailTemplate(SUBJECT, TEXT, HTML).send(to, __v, purpose);',
56
- );
57
- });
58
- });
@@ -1,21 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import { parseError } from '../src/client/errors';
4
-
5
- describe('parseError', () => {
6
- it('returns the message of an Error', () => {
7
- expect(parseError(new Error('boom'))).toBe('boom');
8
- });
9
-
10
- it('stringifies non-Error values', () => {
11
- expect(parseError('plain string')).toBe('plain string');
12
- expect(parseError(42)).toBe('42');
13
- expect(parseError(null)).toBe('null');
14
- expect(parseError(undefined)).toBe('undefined');
15
- });
16
-
17
- it('reads the message of an Error subclass', () => {
18
- class HttpError extends Error {}
19
- expect(parseError(new HttpError('not found'))).toBe('not found');
20
- });
21
- });
@@ -1,123 +0,0 @@
1
- /**
2
- * The `examples/basic` Guestbook demo: a @rest controller backed by ToilDB
3
- * (`events` + `counter`). Each dispatch runs a FRESH wasm instance (linear
4
- * memory resets between requests), so the only thing that can carry a signature
5
- * from one request to the next is ToilDB - which is exactly what the demo shows.
6
- * Contrast the `Players` route, whose own comment notes "memory resets next
7
- * request". Skips until the example server wasm is built (`npm run build:server`).
8
- */
9
- import fs from 'node:fs';
10
- import os from 'node:os';
11
- import path from 'node:path';
12
- import { fileURLToPath } from 'node:url';
13
-
14
- import { describe, expect, it, beforeEach } from 'vitest';
15
-
16
- import { WasmServerModule } from '../src/devserver/index.js';
17
- import { __resetDbForTests, configureDbPersistence } from '../src/devserver/db/index.js';
18
-
19
- const EXAMPLE_WASM = path.resolve(
20
- path.dirname(fileURLToPath(import.meta.url)),
21
- '../examples/basic/build/server/release.wasm',
22
- );
23
- const haveWasm = fs.existsSync(EXAMPLE_WASM);
24
-
25
- function load(): WasmServerModule {
26
- const m = new WasmServerModule(EXAMPLE_WASM);
27
- m.refresh();
28
- return m;
29
- }
30
- function sign(m: WasmServerModule, author: string, message: string) {
31
- return m.dispatch({
32
- method: 'POST',
33
- path: '/guestbook',
34
- headers: [
35
- ['host', 'localhost:3000'],
36
- ['content-type', 'application/json'],
37
- ],
38
- body: new TextEncoder().encode(JSON.stringify({ author, message })),
39
- });
40
- }
41
- function list(m: WasmServerModule) {
42
- return m.dispatch({
43
- method: 'GET',
44
- path: '/guestbook',
45
- headers: [['host', 'localhost:3000']],
46
- body: new Uint8Array(0),
47
- });
48
- }
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- const json = (r: { body: Uint8Array }): any => JSON.parse(Buffer.from(r.body).toString());
51
-
52
- describe.skipIf(!haveWasm)('guestbook demo: ToilDB events + counter persist across requests', () => {
53
- beforeEach(() => __resetDbForTests());
54
-
55
- it('starts empty after a reset', () => {
56
- const v = json(list(load()));
57
- expect(v.total).toBe('0'); // i64 rides JSON as a decimal string
58
- expect(v.entries.length).toBe(0);
59
- });
60
-
61
- it('signatures persist across separate requests (a fresh instance each time)', () => {
62
- let r = sign(load(), 'Ada', 'first!');
63
- expect(r.status).toBe(200);
64
- expect(json(r).total).toBe('1');
65
-
66
- // A brand-new wasm instance - its memory is empty - still sees the prior
67
- // signature, because it lives in ToilDB, not module state. The action
68
- // acks with the running total; the entries list is served by the GET.
69
- r = sign(load(), 'Linus', 'second');
70
- expect(json(r).total).toBe('2');
71
-
72
- // The newest entries are served by GET /guestbook from the materialized
73
- // view that the @derive republishes after each signature (events.latest
74
- // is a scan, barred in the request handlers, so it runs in the derive).
75
- const v = json(list(load()));
76
- expect(v.total).toBe('2');
77
- expect(v.entries.length).toBe(2);
78
- expect(v.entries[0].author).toBe('Linus'); // events.latest is newest-first
79
- expect(v.entries[1].author).toBe('Ada');
80
- expect(v.entries[1].message).toBe('first!');
81
- });
82
-
83
- // End-to-end proof that the `server/migrations/GuestEntry.migration.ts` demo
84
- // actually RUNS: write an entry under the current shape, downgrade it on disk to
85
- // the original pre-`at` `GuestEntryV1` layout (drop the trailing u64 + re-stamp
86
- // with v1's schema_version), then `list()` and confirm the woven decoder ran the
87
- // `@migrate` - the entry comes back with the new `at` field defaulted to 0.
88
- it('migrates an on-disk pre-`at` entry on read (the GuestEntry.migration demo fires)', () => {
89
- const GUEST_ENTRY_V1_VERSION = 631968986; // layoutHash({author:string, message:string})
90
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gb-mig-'));
91
- const file = path.join(dir, 'devdata.json');
92
- try {
93
- // 1. sign under the CURRENT shape (author, message, at); persistence flushes it.
94
- configureDbPersistence(file);
95
- expect(sign(load(), 'Ada', 'from the old days').status).toBe(200);
96
-
97
- // 2. downgrade that event on disk to the v1 shape: GuestEntry encodes
98
- // author + message + at(u64), so dropping the trailing 8 bytes yields a
99
- // valid GuestEntryV1; re-stamp it with v1's schema_version.
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- const snap: any = JSON.parse(fs.readFileSync(file, 'utf8'));
102
- const evKey = Object.keys(snap.events)[0];
103
- const buf = Buffer.from(snap.events[evKey][0].v, 'base64');
104
- snap.events[evKey][0] = {
105
- v: buf.subarray(0, buf.length - 8).toString('base64'),
106
- sv: GUEST_ENTRY_V1_VERSION,
107
- };
108
- fs.writeFileSync(file, JSON.stringify(snap));
109
-
110
- // 3. reload + list: the read surfaces v1's version, so the guest's woven
111
- // decoder runs the @migrate, copying author/message and defaulting at=0.
112
- __resetDbForTests();
113
- configureDbPersistence(file);
114
- const v = json(list(load()));
115
- expect(v.entries.length).toBe(1);
116
- expect(v.entries[0].author).toBe('Ada');
117
- expect(v.entries[0].message).toBe('from the old days');
118
- expect(String(v.entries[0].at)).toBe('0'); // the migrated-in field
119
- } finally {
120
- fs.rmSync(dir, { recursive: true, force: true });
121
- }
122
- });
123
- });
@@ -1,149 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import {
4
- defaultConfigSource,
5
- detectPreprocessor,
6
- detectTailwind,
7
- packageDiff,
8
- preprocessorForExt,
9
- requiredPackages,
10
- setConfigImages,
11
- setStyleImports,
12
- styleEntry,
13
- type StyleFeatures,
14
- styleImportLines,
15
- } from '../src/cli/features';
16
-
17
- const CSS: StyleFeatures = { preprocessor: 'css', tailwind: false };
18
- const SASS_TW: StyleFeatures = { preprocessor: 'sass', tailwind: true };
19
-
20
- describe('styleEntry / preprocessorForExt', () => {
21
- it('maps preprocessors to stylesheet paths', () => {
22
- expect(styleEntry('css')).toBe('styles/main.css');
23
- expect(styleEntry('sass')).toBe('styles/main.scss');
24
- expect(styleEntry('less')).toBe('styles/main.less');
25
- expect(styleEntry('stylus')).toBe('styles/main.styl');
26
- });
27
-
28
- it('reverses extensions back to preprocessors', () => {
29
- expect(preprocessorForExt('scss')).toBe('sass');
30
- expect(preprocessorForExt('.sass')).toBe('sass');
31
- expect(preprocessorForExt('less')).toBe('less');
32
- expect(preprocessorForExt('styl')).toBe('stylus');
33
- expect(preprocessorForExt('css')).toBe('css');
34
- expect(preprocessorForExt('txt')).toBeNull();
35
- });
36
- });
37
-
38
- describe('requiredPackages / packageDiff', () => {
39
- it('lists packages for a feature set', () => {
40
- expect(requiredPackages(CSS)).toEqual([]);
41
- expect(requiredPackages({ preprocessor: 'sass', tailwind: false })).toEqual(['sass']);
42
- expect(requiredPackages({ preprocessor: 'css', tailwind: true })).toEqual([
43
- 'tailwindcss',
44
- '@tailwindcss/vite',
45
- ]);
46
- });
47
-
48
- it('diffs add/remove between two setups', () => {
49
- expect(packageDiff(CSS, SASS_TW)).toEqual({
50
- add: ['sass', 'tailwindcss', '@tailwindcss/vite'],
51
- remove: [],
52
- });
53
- expect(packageDiff(SASS_TW, CSS)).toEqual({
54
- add: [],
55
- remove: ['sass', 'tailwindcss', '@tailwindcss/vite'],
56
- });
57
- expect(
58
- packageDiff(
59
- { preprocessor: 'sass', tailwind: false },
60
- { preprocessor: 'less', tailwind: false },
61
- ),
62
- ).toEqual({ add: ['less'], remove: ['sass'] });
63
- });
64
- });
65
-
66
- describe('styleImportLines / setStyleImports', () => {
67
- it('orders Tailwind before the main stylesheet', () => {
68
- expect(styleImportLines(CSS)).toEqual(["import './styles/main.css';"]);
69
- expect(styleImportLines(SASS_TW)).toEqual([
70
- "import './styles/tailwind.css';",
71
- "import './styles/main.scss';",
72
- ]);
73
- });
74
-
75
- it('rewrites the app entry imports, preserving the rest', () => {
76
- const src = [
77
- "import { routes, layout, notFound } from 'toiljs/routes';",
78
- '',
79
- "import './styles/main.css';",
80
- '',
81
- 'Toil.mount(routes, layout, notFound);',
82
- '',
83
- ].join('\n');
84
-
85
- const out = setStyleImports(src, SASS_TW);
86
- expect(out).toContain("import './styles/tailwind.css';");
87
- expect(out).toContain("import './styles/main.scss';");
88
- expect(out).not.toContain("import './styles/main.css';");
89
- expect(out).toContain("from 'toiljs/routes'");
90
- expect(out).toContain('Toil.mount(routes, layout, notFound);');
91
- });
92
-
93
- it('round-trips back to plain CSS (drops Tailwind import)', () => {
94
- const src = [
95
- "import { routes, layout, notFound } from 'toiljs/routes';",
96
- "import './styles/tailwind.css';",
97
- "import './styles/main.scss';",
98
- 'Toil.mount(routes, layout, notFound);',
99
- ].join('\n');
100
-
101
- const out = setStyleImports(src, CSS);
102
- expect(out).toContain("import './styles/main.css';");
103
- expect(out).not.toContain('tailwind.css');
104
- expect(out).not.toContain('main.scss');
105
- });
106
- });
107
-
108
- describe('detect from dependencies', () => {
109
- it('finds the active preprocessor and Tailwind', () => {
110
- expect(detectPreprocessor({ sass: '^1' })).toBe('sass');
111
- expect(detectPreprocessor({ less: '^4' })).toBe('less');
112
- expect(detectPreprocessor({})).toBe('css');
113
- expect(detectTailwind({ '@tailwindcss/vite': '^4' })).toBe(true);
114
- expect(detectTailwind({ react: '^19' })).toBe(false);
115
- });
116
- });
117
-
118
- describe('setConfigImages / defaultConfigSource', () => {
119
- it('flips an existing images flag', () => {
120
- const src =
121
- 'export default defineConfig({\n client: {\n images: true,\n },\n});\n';
122
- expect(setConfigImages(src, false)).toContain('images: false');
123
- expect(setConfigImages(src, false)).not.toContain('images: true');
124
- });
125
-
126
- it('adds images to an existing client block', () => {
127
- const out = setConfigImages(
128
- 'export default defineConfig({ client: { base: "/" } });',
129
- false,
130
- );
131
- expect(out).toContain('images: false');
132
- expect(out).toContain('base: "/"');
133
- });
134
-
135
- it('adds a client block to a bare config', () => {
136
- const out = setConfigImages('export default defineConfig({});', false);
137
- expect(out).toContain('client: { images: false }');
138
- });
139
-
140
- it('returns null when the shape is unrecognized', () => {
141
- expect(setConfigImages('const x = 1;', false)).toBeNull();
142
- });
143
-
144
- it('round-trips through defaultConfigSource', () => {
145
- const src = defaultConfigSource(false);
146
- expect(src).toContain('images: false');
147
- expect(setConfigImages(src, true)).toContain('images: true');
148
- });
149
- });
@@ -1,25 +0,0 @@
1
- // Fixture for the generated-client JSON wire-format test (test/rpc-bignum-wire.test.ts).
2
- // Compiled by the installed toilscript with --rpcModule, then the generated TS client is
3
- // imported and exercised. Covers every JSON bignum width plus a nested @data so the
4
- // recursive toJSONValue path is hit.
5
-
6
- @data
7
- class Wallet {
8
- u: u64 = 0;
9
- i: i64 = 0;
10
- a: u128 = u128.Zero;
11
- b: i128 = i128.Zero;
12
- c: u256 = u256.Zero;
13
- d: i256 = i256.Zero;
14
- label: string = '';
15
- }
16
-
17
- @data
18
- class Account {
19
- main: Wallet = new Wallet();
20
- ids: u256[] = [];
21
- }
22
-
23
- // The two @data classes above ARE the surface: buildServerModule emits their codec + the bignum
24
- // helpers for any @data. (No @remote here - a @remote injects a server-side Rpc registration that
25
- // needs the full server runtime, which this `--runtime stub` fixture deliberately does not link.)
@@ -1,65 +0,0 @@
1
- // A minimal @daemon fixture for the dev daemon-emulation test. It declares the
2
- // daemon host imports directly (so it needs no toiljs globals lib) and records
3
- // its activity into resident daemon wasm memory. Compiled with `--targetMode cold`
4
- // by the test.
5
- //
6
- // onStart() -> increments `started` and stamps the lease epoch
7
- // tick() @scheduled -> increments `tickFast` (1s interval)
8
- // sixHourly() cron -> increments `tickCron` (0 */6 * * *)
9
- //
10
- // The imports live in the `daemon` wasm module with BARE names, as the edge
11
- // registers them; they are not dotted names under `env`. toilscript's stdlib
12
- // exposes the same surface as the ambient `Daemon` class (`~lib/daemon`), which
13
- // real daemons should use instead of hand-declaring these.
14
-
15
- // @ts-nocheck — this is AssemblyScript source compiled by toilscript, not TS.
16
-
17
- @external("daemon", "is_leader")
18
- declare function daemonIsLeader(): i32;
19
-
20
- @external("daemon", "current_epoch")
21
- declare function daemonCurrentEpoch(): i64;
22
-
23
- @external("daemon", "task_count")
24
- declare function daemonTaskCount(): i32;
25
-
26
- let started: i32 = 0;
27
- let leaderSeen: i32 = 0;
28
- let epochNonneg: i32 = 0;
29
- let taskcount2: i32 = 0;
30
- let tickFast: i32 = 0;
31
- let tickCron: i32 = 0;
32
-
33
- @daemon
34
- class Jobs {
35
- onStart(): void {
36
- // Prove leader=true and that the epoch import is callable; record both so
37
- // the test can assert the stubs from outside.
38
- started += 1;
39
- if (daemonIsLeader() == 1) leaderSeen += 1;
40
- let epoch = daemonCurrentEpoch();
41
- if (epoch >= 0) epochNonneg += 1;
42
- if (daemonTaskCount() == 2) taskcount2 += 1;
43
- }
44
-
45
- @scheduled("1s")
46
- tick(): void {
47
- tickFast += 1;
48
- }
49
-
50
- @scheduled("0 */6 * * *")
51
- sixHourly(): void {
52
- tickCron += 1;
53
- }
54
- }
55
-
56
- export function startedCount(): i32 { return started; }
57
- export function leaderCount(): i32 { return leaderSeen; }
58
- export function epochNonnegCount(): i32 { return epochNonneg; }
59
- export function taskcount2Count(): i32 { return taskcount2; }
60
- export function tickFastCount(): i32 { return tickFast; }
61
- export function tickCronCount(): i32 { return tickCron; }
62
-
63
- export function probe(): i32 {
64
- return 1;
65
- }
@@ -1,26 +0,0 @@
1
- // Dev-stream emulation fixture: a `@stream('echo')` whose raw `@message` bridge echoes the inbound
2
- // bytes back through the egress ring, rejects an 'X'-prefixed frame (0x0210), and `empty()`s a
3
- // zero-length frame. Compiled by the dev test with the LOCAL toilscript (`--targetMode hot`), then
4
- // driven through `DevStreamBox`. Mirrors toil-backend's `tests/fixtures/stream/echo_src.ts`.
5
-
6
- let __count: i32 = 0;
7
-
8
- // Observable so the @message hook's residency can be asserted across events.
9
- export function messageCount(): i32 {
10
- return __count;
11
- }
12
-
13
- @stream('echo')
14
- class Echo {
15
- @message reply(p: StreamPacket): StreamOutbound {
16
- __count = __count + 1;
17
- const n = p.length;
18
- if (n == 0) return StreamOutbound.empty();
19
- if (p.at(0) == 0x58) return StreamOutbound.reject(0x0210); // 'X' -> reject
20
- return StreamOutbound.reply(p.bytes());
21
- }
22
- }
23
-
24
- export function probe(): i32 {
25
- return 1;
26
- }
@@ -1,28 +0,0 @@
1
- // Dev @connect-bridge fixture: a `@stream('gate')` whose `@connect(c: StreamInbound): StreamOutbound`
2
- // reads the host-written connect context (the path) and REJECTS "/blocked" with 0x0211, ACCEPTING any
3
- // other path; a "/greet" path stages an egress frame DURING @connect (the host returns it as initial
4
- // egress and drains the ring so it does not contaminate the first @message reply). A @message echoes. Mirrors toil-backend's connect_src.ts;
5
- // exercises the whole @connect bridge (stream_info block -> StreamInbound.path() -> accept/reject).
6
-
7
- @stream('gate')
8
- class Gate {
9
- @connect onConnect(c: StreamInbound): StreamOutbound {
10
- if (c.path() == '/blocked') return StreamOutbound.reject(0x0211);
11
- if (c.path() == '/greet') {
12
- const g = new Uint8Array(3);
13
- g[0] = 0x47;
14
- g[1] = 0x48;
15
- g[2] = 0x49; // "GHI"
16
- StreamOutbound.reply(g);
17
- return StreamOutbound.accept();
18
- }
19
- return StreamOutbound.accept();
20
- }
21
- @message reply(p: StreamPacket): StreamOutbound {
22
- return StreamOutbound.reply(p.bytes());
23
- }
24
- }
25
-
26
- export function probe(): i32 {
27
- return 1;
28
- }
@@ -1,18 +0,0 @@
1
- // Dev trap fixture: a `@stream('trap')` whose `@message` deliberately TRAPS (the wasm `unreachable`
2
- // instruction). The dev has no gas-metering middleware, so this stands in for the edge's gas-kill: a
3
- // real trap makes the dispatch throw, which StreamDevHost turns into a STREAM_HOOK_TRAPPED close that
4
- // discards the poisoned box (mirrors toil-backend's poisoned-box containment, 05 7.4).
5
- //
6
- // The trap sits behind an always-true guard so the `return` stays reachable to the type checker.
7
-
8
- @stream('trap')
9
- class Trap {
10
- @message boom(p: StreamPacket): StreamOutbound {
11
- if (p.length >= 0) {
12
- unreachable();
13
- }
14
- return StreamOutbound.empty();
15
- }
16
- }
17
-
18
- export function probe(): i32 { return 1; }
@@ -1,41 +0,0 @@
1
- // A TYPED @stream fixture: @stream({ message: ChatMsg }) makes @message receive the DECODED @data
2
- // (doc 03 2.5), not raw bytes. The hook replies with the decoded text's length, so a host round-trip
3
- // proves the @data decode ran at runtime (not just compiled). The seed* exports hand the host a real
4
- // ChatMsg.encode() payload so the test never hand-crafts the @data wire format.
5
-
6
- @data
7
- class ChatMsg {
8
- text: string = '';
9
- }
10
-
11
- @stream({ message: ChatMsg })
12
- class TypedChat {
13
- @message
14
- onMsg(m: ChatMsg): StreamOutbound {
15
- // Reply with the DECODED text length (one byte): "hi" -> 2 proves the decode produced the string.
16
- const r = new Uint8Array(1);
17
- r[0] = <u8>m.text.length;
18
- return StreamOutbound.reply(r);
19
- }
20
- }
21
-
22
- // Seed buffer: the guest encodes a ChatMsg the host feeds back, so the host never hand-crafts @data
23
- // bytes (the encode/decode pair is the wire contract). A StaticArray<u8>'s pointer IS its data start.
24
- let seedBuf = new StaticArray<u8>(64);
25
- let seedLen: i32 = 0;
26
-
27
- export function seedHi(): void {
28
- const m = new ChatMsg();
29
- m.text = 'hi';
30
- const b = m.encode();
31
- seedLen = b.length;
32
- for (let i = 0, n = b.length; i < n; i++) seedBuf[i] = b[i];
33
- }
34
-
35
- export function seedOffset(): i32 {
36
- return changetype<i32>(seedBuf);
37
- }
38
-
39
- export function seedLength(): i32 {
40
- return seedLen;
41
- }
@@ -1,28 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import { fontPreloadTags } from '../src/compiler/fonts';
4
-
5
- describe('fontPreloadTags', () => {
6
- it('builds a crossorigin preload link per font, skipping non-fonts', () => {
7
- const tags = fontPreloadTags(['fonts/a-abc.woff2', 'assets/x-1.js', 'fonts/b.ttf'], '/');
8
- expect(tags).toHaveLength(2);
9
- expect(tags[0]).toEqual({
10
- tag: 'link',
11
- attrs: {
12
- rel: 'preload',
13
- as: 'font',
14
- type: 'font/woff2',
15
- href: '/fonts/a-abc.woff2',
16
- crossorigin: '',
17
- },
18
- injectTo: 'head',
19
- });
20
- expect(tags[1].attrs?.type).toBe('font/ttf');
21
- });
22
-
23
- it('respects a non-root base path', () => {
24
- expect(fontPreloadTags(['fonts/a.woff2'], '/app/')[0].attrs?.href).toBe(
25
- '/app/fonts/a.woff2',
26
- );
27
- });
28
- });