toiljs 0.0.62 → 0.0.64

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 (37) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/cli/.tsbuildinfo +1 -1
  3. package/build/client/.tsbuildinfo +1 -1
  4. package/build/client/index.d.ts +1 -1
  5. package/build/client/index.js +1 -1
  6. package/build/client/routing/hooks.d.ts +1 -0
  7. package/build/client/routing/hooks.js +7 -1
  8. package/build/client/ssr/markers.js +1 -1
  9. package/build/compiler/.tsbuildinfo +1 -1
  10. package/build/compiler/index.d.ts +4 -1
  11. package/build/compiler/index.js +47 -18
  12. package/build/compiler/template-build.d.ts +3 -2
  13. package/build/compiler/template-build.js +16 -5
  14. package/build/compiler/toil-docs.generated.js +4 -1
  15. package/build/devserver/.tsbuildinfo +1 -1
  16. package/build/devserver/runtime/module.d.ts +3 -0
  17. package/build/devserver/runtime/module.js +5 -7
  18. package/docs/daemon.md +123 -0
  19. package/docs/index.md +5 -1
  20. package/docs/streams.md +147 -0
  21. package/docs/tiers.md +127 -0
  22. package/examples/basic/server/services/Stats.ts +2 -3
  23. package/examples/basic/server/services/remotes.ts +2 -2
  24. package/package.json +2 -2
  25. package/scripts/gen-toil-docs.mjs +3 -0
  26. package/src/client/index.ts +1 -0
  27. package/src/client/routing/hooks.ts +16 -3
  28. package/src/client/ssr/markers.tsx +4 -1
  29. package/src/compiler/index.ts +109 -53
  30. package/src/compiler/template-build.ts +38 -7
  31. package/src/compiler/toil-docs.generated.ts +4 -1
  32. package/src/devserver/runtime/module.ts +12 -14
  33. package/test/daemon-build.test.ts +31 -12
  34. package/test/devserver-database.test.ts +26 -0
  35. package/test/ssr-hydration.test.tsx +20 -5
  36. package/test/ssr-template.test.tsx +5 -3
  37. package/examples/basic/server/streams/Echo.ts +0 -49
@@ -1,49 +0,0 @@
1
- /**
2
- * A `@stream` protocol handler mounted at `/echo`, running as a RESIDENT wasm box
3
- * per WebTransport connection on the Toil edge - distributed across the eligible
4
- * L2/L3 nodes and pinned to ONE worker for the connection's lifetime via QUIC
5
- * connection-id steering.
6
- *
7
- * The defining property of a `@stream` (vs a `@rest` handler): the box is
8
- * RESIDENT, so instance state PERSISTS across events on the same connection. Here
9
- * `count` survives every `@message` because the box is never reset between events
10
- * - unlike a `@rest` handler, which is fresh per request. On the client:
11
- *
12
- * const stream = await Server.STREAM.echo.connect();
13
- * stream.send(new TextEncoder().encode('hi'));
14
- *
15
- * Lifecycle hooks: `@connect` (open), `@message` (an inbound frame), `@close`
16
- * (graceful close), `@disconnect` (abrupt transport loss).
17
- *
18
- * NOTE: reading the inbound frame and replying is the NEXT increment (the
19
- * `StreamPacket` / `StreamOutbound` message bridge). The intended shape is:
20
- *
21
- * @message reply(packet: StreamPacket): StreamOutbound {
22
- * return StreamOutbound.reply(packet.bytes()); // echo the bytes back
23
- * }
24
- *
25
- * Until that lands, the hooks run on the connection lifecycle; this example counts
26
- * frames to demonstrate that the resident box keeps state across them.
27
- */
28
- @stream('echo')
29
- class Echo {
30
- // Resident per-connection state: survives across events (ResetMode::None).
31
- private count: i32 = 0;
32
-
33
- @connect
34
- onConnect(): void {
35
- // A fresh connection: its dedicated box starts the counter at 0.
36
- this.count = 0;
37
- }
38
-
39
- @message
40
- onMessage(): void {
41
- // Persists across frames because the box is resident, not reset per event.
42
- this.count = this.count + 1;
43
- }
44
-
45
- @close
46
- onClose(): void {
47
- // Graceful close: the per-connection box is torn down after this hook.
48
- }
49
- }