rivetkit 2.0.24-rc.1 → 2.0.25-rc.1

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 (231) hide show
  1. package/dist/schemas/actor-persist/v1.ts +6 -0
  2. package/dist/schemas/actor-persist/v2.ts +9 -3
  3. package/dist/schemas/actor-persist/v3.ts +280 -0
  4. package/dist/schemas/client-protocol/v1.ts +6 -0
  5. package/dist/schemas/client-protocol/v2.ts +438 -0
  6. package/dist/schemas/file-system-driver/v1.ts +6 -0
  7. package/dist/schemas/file-system-driver/v2.ts +142 -0
  8. package/dist/tsup/actor/errors.cjs +2 -4
  9. package/dist/tsup/actor/errors.cjs.map +1 -1
  10. package/dist/tsup/actor/errors.d.cts +7 -10
  11. package/dist/tsup/actor/errors.d.ts +7 -10
  12. package/dist/tsup/actor/errors.js +9 -11
  13. package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.cts → actor-router-consts-DzI2szci.d.cts} +5 -9
  14. package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.ts → actor-router-consts-DzI2szci.d.ts} +5 -9
  15. package/dist/tsup/{chunk-ZTH3KYFH.cjs → chunk-3FG5OJ3G.cjs} +3 -3
  16. package/dist/tsup/{chunk-ZTH3KYFH.cjs.map → chunk-3FG5OJ3G.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-BLK27ES3.js → chunk-6JN6W6G3.js} +44 -56
  18. package/dist/tsup/chunk-6JN6W6G3.js.map +1 -0
  19. package/dist/tsup/chunk-7IBNNGQ2.js +514 -0
  20. package/dist/tsup/chunk-7IBNNGQ2.js.map +1 -0
  21. package/dist/tsup/{chunk-36JJ4IQB.cjs → chunk-AZATXPR4.cjs} +4 -8
  22. package/dist/tsup/chunk-AZATXPR4.cjs.map +1 -0
  23. package/dist/tsup/chunk-B7MENRD5.cjs +5694 -0
  24. package/dist/tsup/chunk-B7MENRD5.cjs.map +1 -0
  25. package/dist/tsup/{chunk-BOMZS2TJ.js → chunk-BBVFDEYD.js} +9 -9
  26. package/dist/tsup/chunk-BBVFDEYD.js.map +1 -0
  27. package/dist/tsup/{chunk-KSRXX3Z4.cjs → chunk-D6762AOA.cjs} +20 -25
  28. package/dist/tsup/chunk-D6762AOA.cjs.map +1 -0
  29. package/dist/tsup/{chunk-2JYPS5YM.cjs → chunk-E63WZNMR.cjs} +6 -6
  30. package/dist/tsup/chunk-E63WZNMR.cjs.map +1 -0
  31. package/dist/tsup/{chunk-YBG6R7LX.js → chunk-EDGN4OC7.js} +3 -7
  32. package/dist/tsup/chunk-EDGN4OC7.js.map +1 -0
  33. package/dist/tsup/{chunk-BYMKMOBS.js → chunk-FLOQ3UWM.js} +1844 -1681
  34. package/dist/tsup/chunk-FLOQ3UWM.js.map +1 -0
  35. package/dist/tsup/{chunk-7L65NNWP.cjs → chunk-H7GV5DIW.cjs} +187 -185
  36. package/dist/tsup/chunk-H7GV5DIW.cjs.map +1 -0
  37. package/dist/tsup/{chunk-227FEWMB.js → chunk-HZYZ7JSF.js} +3322 -2251
  38. package/dist/tsup/chunk-HZYZ7JSF.js.map +1 -0
  39. package/dist/tsup/{chunk-FX7TWFQR.js → chunk-IDJK7ILQ.js} +2 -6
  40. package/dist/tsup/chunk-IDJK7ILQ.js.map +1 -0
  41. package/dist/tsup/{chunk-VHGY7PU5.cjs → chunk-ILFXA4AL.cjs} +1900 -1737
  42. package/dist/tsup/chunk-ILFXA4AL.cjs.map +1 -0
  43. package/dist/tsup/chunk-MV6M3FDL.cjs +514 -0
  44. package/dist/tsup/chunk-MV6M3FDL.cjs.map +1 -0
  45. package/dist/tsup/{chunk-PLUN2NQT.js → chunk-NWBKMCWC.js} +189 -187
  46. package/dist/tsup/chunk-NWBKMCWC.js.map +1 -0
  47. package/dist/tsup/{chunk-CD33GT6Z.js → chunk-QIHBDXTO.js} +2 -2
  48. package/dist/tsup/{chunk-G64QUEDJ.js → chunk-W6RDS6NW.js} +23 -28
  49. package/dist/tsup/chunk-W6RDS6NW.js.map +1 -0
  50. package/dist/tsup/{chunk-INNFK746.cjs → chunk-WQU4M4ZC.cjs} +10 -14
  51. package/dist/tsup/chunk-WQU4M4ZC.cjs.map +1 -0
  52. package/dist/tsup/{chunk-SHVX2QUR.cjs → chunk-XKZA47XS.cjs} +17 -17
  53. package/dist/tsup/chunk-XKZA47XS.cjs.map +1 -0
  54. package/dist/tsup/{chunk-HHFKKVLR.cjs → chunk-YHWIOWVA.cjs} +45 -57
  55. package/dist/tsup/chunk-YHWIOWVA.cjs.map +1 -0
  56. package/dist/tsup/{chunk-YBHYXIP6.js → chunk-YVL6IRUM.js} +3 -3
  57. package/dist/tsup/chunk-YVL6IRUM.js.map +1 -0
  58. package/dist/tsup/client/mod.cjs +9 -9
  59. package/dist/tsup/client/mod.d.cts +5 -7
  60. package/dist/tsup/client/mod.d.ts +5 -7
  61. package/dist/tsup/client/mod.js +8 -8
  62. package/dist/tsup/common/log.cjs +3 -3
  63. package/dist/tsup/common/log.js +2 -2
  64. package/dist/tsup/common/websocket.cjs +4 -4
  65. package/dist/tsup/common/websocket.js +3 -3
  66. package/dist/tsup/{conn-B3Vhbgnd.d.ts → config-BRDYDraU.d.cts} +1119 -1047
  67. package/dist/tsup/{conn-DJWL3nGx.d.cts → config-Bo-blHpJ.d.ts} +1119 -1047
  68. package/dist/tsup/driver-helpers/mod.cjs +5 -13
  69. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  70. package/dist/tsup/driver-helpers/mod.d.cts +11 -9
  71. package/dist/tsup/driver-helpers/mod.d.ts +11 -9
  72. package/dist/tsup/driver-helpers/mod.js +14 -22
  73. package/dist/tsup/driver-test-suite/mod.cjs +474 -303
  74. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  75. package/dist/tsup/driver-test-suite/mod.d.cts +6 -9
  76. package/dist/tsup/driver-test-suite/mod.d.ts +6 -9
  77. package/dist/tsup/driver-test-suite/mod.js +1085 -914
  78. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  79. package/dist/tsup/inspector/mod.cjs +6 -6
  80. package/dist/tsup/inspector/mod.d.cts +5 -7
  81. package/dist/tsup/inspector/mod.d.ts +5 -7
  82. package/dist/tsup/inspector/mod.js +5 -5
  83. package/dist/tsup/mod.cjs +10 -16
  84. package/dist/tsup/mod.cjs.map +1 -1
  85. package/dist/tsup/mod.d.cts +23 -25
  86. package/dist/tsup/mod.d.ts +23 -25
  87. package/dist/tsup/mod.js +17 -23
  88. package/dist/tsup/test/mod.cjs +11 -11
  89. package/dist/tsup/test/mod.d.cts +4 -6
  90. package/dist/tsup/test/mod.d.ts +4 -6
  91. package/dist/tsup/test/mod.js +10 -10
  92. package/dist/tsup/utils.cjs +3 -5
  93. package/dist/tsup/utils.cjs.map +1 -1
  94. package/dist/tsup/utils.d.cts +1 -2
  95. package/dist/tsup/utils.d.ts +1 -2
  96. package/dist/tsup/utils.js +2 -4
  97. package/package.json +13 -6
  98. package/src/actor/config.ts +56 -44
  99. package/src/actor/conn/driver.ts +61 -0
  100. package/src/actor/conn/drivers/http.ts +17 -0
  101. package/src/actor/conn/drivers/raw-request.ts +24 -0
  102. package/src/actor/conn/drivers/raw-websocket.ts +65 -0
  103. package/src/actor/conn/drivers/websocket.ts +129 -0
  104. package/src/actor/conn/mod.ts +232 -0
  105. package/src/actor/conn/persisted.ts +81 -0
  106. package/src/actor/conn/state-manager.ts +196 -0
  107. package/src/actor/contexts/action.ts +23 -0
  108. package/src/actor/{context.ts → contexts/actor.ts} +19 -8
  109. package/src/actor/contexts/conn-init.ts +31 -0
  110. package/src/actor/contexts/conn.ts +48 -0
  111. package/src/actor/contexts/create-conn-state.ts +13 -0
  112. package/src/actor/contexts/on-before-connect.ts +13 -0
  113. package/src/actor/contexts/on-connect.ts +22 -0
  114. package/src/actor/contexts/request.ts +48 -0
  115. package/src/actor/contexts/websocket.ts +48 -0
  116. package/src/actor/definition.ts +3 -3
  117. package/src/actor/driver.ts +36 -5
  118. package/src/actor/errors.ts +19 -24
  119. package/src/actor/instance/connection-manager.ts +465 -0
  120. package/src/actor/instance/event-manager.ts +292 -0
  121. package/src/actor/instance/kv.ts +15 -0
  122. package/src/actor/instance/mod.ts +1107 -0
  123. package/src/actor/instance/persisted.ts +67 -0
  124. package/src/actor/instance/schedule-manager.ts +349 -0
  125. package/src/actor/instance/state-manager.ts +502 -0
  126. package/src/actor/mod.ts +13 -16
  127. package/src/actor/protocol/old.ts +131 -43
  128. package/src/actor/protocol/serde.ts +19 -4
  129. package/src/actor/router-endpoints.ts +61 -586
  130. package/src/actor/router-websocket-endpoints.ts +408 -0
  131. package/src/actor/router.ts +63 -197
  132. package/src/actor/schedule.ts +1 -1
  133. package/src/client/actor-conn.ts +183 -249
  134. package/src/client/actor-handle.ts +29 -6
  135. package/src/client/client.ts +0 -4
  136. package/src/client/config.ts +1 -4
  137. package/src/client/mod.ts +0 -1
  138. package/src/client/raw-utils.ts +3 -3
  139. package/src/client/utils.ts +85 -39
  140. package/src/common/actor-router-consts.ts +5 -12
  141. package/src/common/{inline-websocket-adapter2.ts → inline-websocket-adapter.ts} +26 -48
  142. package/src/common/log.ts +1 -1
  143. package/src/common/router.ts +28 -17
  144. package/src/common/utils.ts +2 -0
  145. package/src/driver-helpers/mod.ts +7 -10
  146. package/src/driver-helpers/utils.ts +18 -9
  147. package/src/driver-test-suite/mod.ts +26 -50
  148. package/src/driver-test-suite/test-inline-client-driver.ts +27 -51
  149. package/src/driver-test-suite/tests/actor-conn-hibernation.ts +150 -0
  150. package/src/driver-test-suite/tests/actor-conn-state.ts +1 -4
  151. package/src/driver-test-suite/tests/actor-conn.ts +5 -9
  152. package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
  153. package/src/driver-test-suite/tests/actor-driver.ts +0 -7
  154. package/src/driver-test-suite/tests/actor-handle.ts +12 -12
  155. package/src/driver-test-suite/tests/actor-metadata.ts +1 -1
  156. package/src/driver-test-suite/tests/manager-driver.ts +1 -1
  157. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +8 -8
  158. package/src/driver-test-suite/tests/raw-http-request-properties.ts +6 -5
  159. package/src/driver-test-suite/tests/raw-http.ts +5 -5
  160. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +7 -7
  161. package/src/driver-test-suite/tests/request-access.ts +4 -4
  162. package/src/driver-test-suite/utils.ts +6 -10
  163. package/src/drivers/engine/actor-driver.ts +614 -424
  164. package/src/drivers/engine/mod.ts +0 -1
  165. package/src/drivers/file-system/actor.ts +24 -12
  166. package/src/drivers/file-system/global-state.ts +427 -37
  167. package/src/drivers/file-system/manager.ts +71 -83
  168. package/src/drivers/file-system/mod.ts +3 -0
  169. package/src/drivers/file-system/utils.ts +18 -8
  170. package/src/engine-process/mod.ts +38 -38
  171. package/src/inspector/utils.ts +7 -5
  172. package/src/manager/driver.ts +11 -4
  173. package/src/manager/gateway.ts +4 -29
  174. package/src/manager/protocol/mod.ts +0 -2
  175. package/src/manager/protocol/query.ts +0 -4
  176. package/src/manager/router.ts +67 -64
  177. package/src/manager-api/actors.ts +13 -0
  178. package/src/mod.ts +1 -3
  179. package/src/registry/mod.ts +20 -20
  180. package/src/registry/serve.ts +9 -14
  181. package/src/remote-manager-driver/actor-websocket-client.ts +1 -16
  182. package/src/remote-manager-driver/api-endpoints.ts +13 -1
  183. package/src/remote-manager-driver/api-utils.ts +8 -0
  184. package/src/remote-manager-driver/metadata.ts +58 -0
  185. package/src/remote-manager-driver/mod.ts +47 -62
  186. package/src/remote-manager-driver/ws-proxy.ts +1 -1
  187. package/src/schemas/actor-persist/mod.ts +1 -1
  188. package/src/schemas/actor-persist/versioned.ts +56 -31
  189. package/src/schemas/client-protocol/mod.ts +1 -1
  190. package/src/schemas/client-protocol/versioned.ts +41 -21
  191. package/src/schemas/client-protocol-zod/mod.ts +103 -0
  192. package/src/schemas/file-system-driver/mod.ts +1 -1
  193. package/src/schemas/file-system-driver/versioned.ts +42 -19
  194. package/src/serde.ts +33 -11
  195. package/src/test/mod.ts +7 -3
  196. package/src/utils/node.ts +173 -0
  197. package/src/utils.ts +0 -4
  198. package/dist/tsup/chunk-227FEWMB.js.map +0 -1
  199. package/dist/tsup/chunk-2JYPS5YM.cjs.map +0 -1
  200. package/dist/tsup/chunk-36JJ4IQB.cjs.map +0 -1
  201. package/dist/tsup/chunk-7L65NNWP.cjs.map +0 -1
  202. package/dist/tsup/chunk-BLK27ES3.js.map +0 -1
  203. package/dist/tsup/chunk-BOMZS2TJ.js.map +0 -1
  204. package/dist/tsup/chunk-BYMKMOBS.js.map +0 -1
  205. package/dist/tsup/chunk-FX7TWFQR.js.map +0 -1
  206. package/dist/tsup/chunk-G64QUEDJ.js.map +0 -1
  207. package/dist/tsup/chunk-HHFKKVLR.cjs.map +0 -1
  208. package/dist/tsup/chunk-INNFK746.cjs.map +0 -1
  209. package/dist/tsup/chunk-KSRXX3Z4.cjs.map +0 -1
  210. package/dist/tsup/chunk-O44LFKSB.cjs +0 -4623
  211. package/dist/tsup/chunk-O44LFKSB.cjs.map +0 -1
  212. package/dist/tsup/chunk-PLUN2NQT.js.map +0 -1
  213. package/dist/tsup/chunk-S4UJG7ZE.js +0 -1119
  214. package/dist/tsup/chunk-S4UJG7ZE.js.map +0 -1
  215. package/dist/tsup/chunk-SHVX2QUR.cjs.map +0 -1
  216. package/dist/tsup/chunk-VFB23BYZ.cjs +0 -1119
  217. package/dist/tsup/chunk-VFB23BYZ.cjs.map +0 -1
  218. package/dist/tsup/chunk-VHGY7PU5.cjs.map +0 -1
  219. package/dist/tsup/chunk-YBG6R7LX.js.map +0 -1
  220. package/dist/tsup/chunk-YBHYXIP6.js.map +0 -1
  221. package/src/actor/action.ts +0 -178
  222. package/src/actor/conn-drivers.ts +0 -216
  223. package/src/actor/conn-socket.ts +0 -8
  224. package/src/actor/conn.ts +0 -272
  225. package/src/actor/instance.ts +0 -2336
  226. package/src/actor/persisted.ts +0 -49
  227. package/src/actor/unstable-react.ts +0 -110
  228. package/src/driver-test-suite/tests/actor-reconnect.ts +0 -170
  229. package/src/drivers/engine/kv.ts +0 -3
  230. package/src/manager/hono-websocket-adapter.ts +0 -393
  231. /package/dist/tsup/{chunk-CD33GT6Z.js.map → chunk-QIHBDXTO.js.map} +0 -0
@@ -1,49 +0,0 @@
1
- /** State object that gets automatically persisted to storage. */
2
- export interface PersistedActor<S, CP, CS, I> {
3
- input?: I;
4
- hasInitiated: boolean;
5
- state: S;
6
- connections: PersistedConn<CP, CS>[];
7
- scheduledEvents: PersistedScheduleEvent[];
8
- hibernatableWebSocket: PersistedHibernatableWebSocket[];
9
- }
10
-
11
- /** Object representing connection that gets persisted to storage. */
12
- export interface PersistedConn<CP, CS> {
13
- connId: string;
14
- token: string;
15
- params: CP;
16
- state: CS;
17
- subscriptions: PersistedSubscription[];
18
-
19
- /** Last time the socket was seen. This is set when disconnected so we can determine when we need to clean this up. */
20
- lastSeen: number;
21
-
22
- /** Request ID of the hibernatable WebSocket. See PersistedActor.hibernatableWebSocket */
23
- hibernatableRequestId?: ArrayBuffer;
24
- }
25
-
26
- export interface PersistedSubscription {
27
- eventName: string;
28
- }
29
-
30
- export interface GenericPersistedScheduleEvent {
31
- actionName: string;
32
- args: ArrayBuffer | null;
33
- }
34
-
35
- export type PersistedScheduleEventKind = {
36
- generic: GenericPersistedScheduleEvent;
37
- };
38
-
39
- export interface PersistedScheduleEvent {
40
- eventId: string;
41
- timestamp: number;
42
- kind: PersistedScheduleEventKind;
43
- }
44
-
45
- export interface PersistedHibernatableWebSocket {
46
- requestId: ArrayBuffer;
47
- lastSeenTimestamp: bigint;
48
- msgIndex: bigint;
49
- }
@@ -1,110 +0,0 @@
1
- //// @ts-expect-error we do not have types for this lib
2
- //import { renderToPipeableStream } from "@jogit/tmp-react-server-dom-nodeless";
3
- //import getStream from "get-stream";
4
- //import { isValidElement } from "react";
5
- //import { Actor } from "./actor";
6
- //
7
- ///**
8
- // * A React Server Components (RSC) actor.
9
- // *
10
- // * Supports rendering React elements as action responses.
11
- // *
12
- // * @see [Documentation](https://rivet.dev/docs/client/react)
13
- // * @experimental
14
- // */
15
- //export class RscActor<
16
- // State = undefined,
17
- // ConnParams = undefined,
18
- // ConnState = undefined,
19
- //> extends Actor<State, ConnParams, ConnState> {
20
- // /**
21
- // * Updates the RSCs for all connected clients.
22
- // */
23
- // public _updateRsc() {
24
- // // Broadcast a message to all connected clients, telling them to re-render
25
- // this._broadcast("__rsc");
26
- // }
27
- //
28
- // /**
29
- // * Overrides default behavior to update the RSCs when the state changes.
30
- // * @private
31
- // * @internal
32
- // */
33
- // override _onStateChange() {
34
- // this._updateRsc();
35
- // }
36
- //
37
- // /**
38
- // * Overrides default behavior to render React elements as RSC response.
39
- // * @private
40
- // * @internal
41
- // */
42
- // protected override _onBeforeActionResponse<Out>(
43
- // _name: string,
44
- // _args: unknown[],
45
- // output: Out,
46
- // ): Out {
47
- // if (!isValidElement(output)) {
48
- // return super._onBeforeActionResponse(_name, _args, output);
49
- // }
50
- //
51
- // // The output is a React element, so we need to transform it into a valid rsc message
52
- // const { readable, ...writable } = nodeStreamToWebStream();
53
- //
54
- // const stream = renderToPipeableStream(output);
55
- //
56
- // stream.pipe(writable);
57
- //
58
- // return getStream(readable) as Out;
59
- // }
60
- //}
61
- //
62
- //function nodeStreamToWebStream() {
63
- // const buffer: Uint8Array[] = [];
64
- // let writer: WritableStreamDefaultWriter<Uint8Array> | null = null;
65
- //
66
- // const writable = new WritableStream<Uint8Array>({
67
- // write(chunk) {
68
- // buffer.push(chunk);
69
- // },
70
- // close() {},
71
- // });
72
- //
73
- // const readable = new ReadableStream<Uint8Array>({
74
- // start() {},
75
- // async pull(controller) {
76
- // if (buffer.length > 0) {
77
- // const chunk = buffer.shift(); // Get the next chunk from the buffer
78
- // if (chunk) {
79
- // controller.enqueue(chunk); // Push it to the readable stream
80
- // }
81
- // } else {
82
- // if (writable.locked) {
83
- // await new Promise((resolve) => setTimeout(resolve, 10));
84
- // return this.pull?.(controller);
85
- // }
86
- // return controller.close();
87
- // }
88
- // },
89
- // cancel() {},
90
- // });
91
- //
92
- // return {
93
- // readable,
94
- // on: (str: string, fn: () => void) => {
95
- // if (str === "drain") {
96
- // writer = writable.getWriter();
97
- // fn();
98
- // }
99
- // },
100
- // write(chunk: Uint8Array) {
101
- // writer?.write(chunk);
102
- // },
103
- // flush() {
104
- // writer?.close();
105
- // },
106
- // end() {
107
- // writer?.releaseLock();
108
- // },
109
- // };
110
- //}
@@ -1,170 +0,0 @@
1
- import { describe, expect, test, vi } from "vitest";
2
- import type { ActorConnRaw } from "@/client/actor-conn";
3
- import type { DriverTestConfig } from "../mod";
4
- import { setupDriverTest } from "../utils";
5
-
6
- export function runActorReconnectTests(driverTestConfig: DriverTestConfig) {
7
- describe("Actor Reconnection Tests", () => {
8
- test("should reconnect and preserve connection state after non-clean disconnect", async (c) => {
9
- const { client, endpoint } = await setupDriverTest(
10
- c,
11
- driverTestConfig,
12
- );
13
-
14
- // Create actor and connect
15
- const handle = client.counterConn.getOrCreate(["test-reconnect"]);
16
- const connection = handle.connect();
17
-
18
- // Set an initial count on the connection
19
- await connection.increment(5);
20
-
21
- // Verify connection count is 1
22
- const connCount1 = await connection.getConnectionCount();
23
- expect(connCount1).toBe(1);
24
-
25
- // Force disconnect (non-clean) - simulates network failure
26
- const connRaw = connection as unknown as ActorConnRaw;
27
- await forceUncleanDisconnect(
28
- endpoint,
29
- connRaw.actorId!,
30
- connRaw.connectionId!,
31
- );
32
-
33
- // Wait a bit for the disconnection to be processed
34
- await vi.waitFor(
35
- async () => {
36
- const countAfterReconnect = await connection.getCount();
37
- expect(countAfterReconnect).toBe(5); // Should preserve the count
38
- },
39
- { timeout: 5000, interval: 100 },
40
- );
41
-
42
- // Verify connection count is still 1 (same connection reconnected)
43
- const connCount2 = await connection.getConnectionCount();
44
- expect(connCount2).toBe(1);
45
-
46
- // Verify we can still increment the counter
47
- const newCount = await connection.getCount();
48
- expect(newCount).toBe(5);
49
-
50
- // Clean up
51
- await connection.dispose();
52
- });
53
-
54
- test("should not preserve connection state after clean disconnect", async (c) => {
55
- const { client } = await setupDriverTest(c, driverTestConfig);
56
-
57
- // Create actor and connect
58
- const handle = client.counterConn.getOrCreate([
59
- "test-clean-disconnect",
60
- ]);
61
- const connection = handle.connect();
62
-
63
- // Set an initial count on the connection
64
- await connection.increment(10);
65
-
66
- // Verify connection count is 1
67
- const connCount1 = await connection.getConnectionCount();
68
- expect(connCount1).toBe(1);
69
-
70
- // Clean disconnect
71
- await connection.dispose();
72
-
73
- // Wait a bit to ensure disconnection is processed
74
- await vi.waitFor(
75
- async () => {
76
- // Check that connection count is now 0
77
- const handle2 = client.counterConn.get([
78
- "test-clean-disconnect",
79
- ]);
80
- const connCount = await handle2.getConnectionCount();
81
- // This counts the current action caller
82
- expect(connCount).toBe(1);
83
- },
84
- { timeout: 5000 },
85
- );
86
-
87
- // Create a new connection
88
- const connection2 = handle.connect();
89
-
90
- // The count should be reset since it's a new connection
91
- const countNewConnection = await connection2.getCount();
92
- expect(countNewConnection).toBe(0); // Should be reset
93
-
94
- // Verify connection count is 1 again (new connection)
95
- const connCount3 = await connection2.getConnectionCount();
96
- expect(connCount3).toBe(1);
97
-
98
- // Clean up
99
- await connection2.dispose();
100
- });
101
-
102
- test("should handle multiple non-clean disconnects and reconnects", async (c) => {
103
- const { client, endpoint } = await setupDriverTest(
104
- c,
105
- driverTestConfig,
106
- );
107
-
108
- // Create actor and connect
109
- const handle = client.counterConn.getOrCreate([
110
- "test-multiple-reconnect",
111
- ]);
112
- const connection = handle.connect();
113
-
114
- // Set an initial count
115
- await connection.setCount(100);
116
-
117
- // Perform multiple disconnect-reconnect cycles
118
- for (let i = 0; i < 3; i++) {
119
- // Increment before disconnect
120
- await connection.increment(1);
121
-
122
- // Force disconnect
123
- const connRaw = connection as unknown as ActorConnRaw;
124
- await forceUncleanDisconnect(
125
- endpoint,
126
- connRaw.actorId!,
127
- connRaw.connectionId!,
128
- );
129
-
130
- // Wait for reconnection and verify state is preserved
131
- await vi.waitFor(
132
- async () => {
133
- const countAfter = await connection.getCount();
134
- expect(countAfter).toBe(101 + i);
135
- },
136
- { timeout: 5000 },
137
- );
138
-
139
- // Verify connection count remains 1
140
- const connCount = await connection.getConnectionCount();
141
- expect(connCount).toBe(1);
142
- }
143
-
144
- // Final verification
145
- const finalCount = await connection.getCount();
146
- expect(finalCount).toBe(103);
147
-
148
- // Clean up
149
- await connection.dispose();
150
- });
151
- });
152
- }
153
-
154
- async function forceUncleanDisconnect(
155
- endpoint: string,
156
- actorId: string,
157
- connId: string,
158
- ): Promise<void> {
159
- const response = await fetch(
160
- `${endpoint}/.test/force-disconnect?actor=${actorId}&conn=${connId}`,
161
- {
162
- method: "POST",
163
- },
164
- );
165
-
166
- if (!response.ok) {
167
- const text = await response.text();
168
- throw new Error(`Failed to force disconnect: ${text}`);
169
- }
170
- }
@@ -1,3 +0,0 @@
1
- export const KEYS = {
2
- PERSIST_DATA: Uint8Array.from([1]),
3
- };