rivetkit 2.0.3 → 2.0.4

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 (233) hide show
  1. package/README.md +11 -0
  2. package/dist/schemas/actor-persist/v1.ts +21 -24
  3. package/dist/schemas/client-protocol/v1.ts +6 -0
  4. package/dist/tsup/actor/errors.cjs +10 -2
  5. package/dist/tsup/actor/errors.cjs.map +1 -1
  6. package/dist/tsup/actor/errors.d.cts +17 -4
  7. package/dist/tsup/actor/errors.d.ts +17 -4
  8. package/dist/tsup/actor/errors.js +11 -3
  9. package/dist/tsup/{chunk-6PDXBYI5.js → chunk-3F2YSRJL.js} +8 -23
  10. package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
  11. package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
  12. package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
  13. package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
  14. package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
  15. package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-6LJT3QRL.cjs} +39 -25
  16. package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
  17. package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-GICQ3YCU.cjs} +143 -141
  18. package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
  19. package/dist/tsup/{chunk-FLMTTN27.js → chunk-H26RP6GD.js} +15 -8
  20. package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
  21. package/dist/tsup/chunk-HI3HWJRC.js +20 -0
  22. package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
  23. package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-HLLF4B4Q.js} +116 -114
  24. package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
  25. package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-IH6CKNDW.cjs} +12 -27
  26. package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
  27. package/dist/tsup/chunk-LV2S3OU3.js +250 -0
  28. package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
  29. package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LWNKVZG5.cjs} +20 -13
  30. package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
  31. package/dist/tsup/{chunk-INGJP237.js → chunk-NFU2BBT5.js} +102 -43
  32. package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
  33. package/dist/tsup/{chunk-3H7O2A7I.js → chunk-PQY7KKTL.js} +33 -19
  34. package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
  35. package/dist/tsup/{chunk-PO4VLDWA.js → chunk-QK72M5JB.js} +3 -5
  36. package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
  37. package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-QNNXFOQV.cjs} +3 -5
  38. package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
  39. package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-SBHHJ6QS.cjs} +102 -43
  40. package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
  41. package/dist/tsup/chunk-TQ62L3X7.js +325 -0
  42. package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
  43. package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
  44. package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
  45. package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
  46. package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
  47. package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
  48. package/dist/tsup/chunk-XJQHKJ4P.js.map +1 -0
  49. package/dist/tsup/client/mod.cjs +10 -10
  50. package/dist/tsup/client/mod.d.cts +7 -13
  51. package/dist/tsup/client/mod.d.ts +7 -13
  52. package/dist/tsup/client/mod.js +9 -9
  53. package/dist/tsup/common/log.cjs +12 -4
  54. package/dist/tsup/common/log.cjs.map +1 -1
  55. package/dist/tsup/common/log.d.cts +23 -17
  56. package/dist/tsup/common/log.d.ts +23 -17
  57. package/dist/tsup/common/log.js +15 -7
  58. package/dist/tsup/common/websocket.cjs +5 -5
  59. package/dist/tsup/common/websocket.js +4 -4
  60. package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
  61. package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
  62. package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BI-6UIBJ.d.ts} +196 -226
  63. package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-Dyd4NLGW.d.cts} +196 -226
  64. package/dist/tsup/driver-helpers/mod.cjs +6 -9
  65. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  66. package/dist/tsup/driver-helpers/mod.d.cts +5 -6
  67. package/dist/tsup/driver-helpers/mod.d.ts +5 -6
  68. package/dist/tsup/driver-helpers/mod.js +6 -9
  69. package/dist/tsup/driver-test-suite/mod.cjs +155 -1363
  70. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  71. package/dist/tsup/driver-test-suite/mod.d.cts +11 -5
  72. package/dist/tsup/driver-test-suite/mod.d.ts +11 -5
  73. package/dist/tsup/driver-test-suite/mod.js +876 -2084
  74. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  75. package/dist/tsup/inspector/mod.cjs +6 -8
  76. package/dist/tsup/inspector/mod.cjs.map +1 -1
  77. package/dist/tsup/inspector/mod.d.cts +3 -3
  78. package/dist/tsup/inspector/mod.d.ts +3 -3
  79. package/dist/tsup/inspector/mod.js +8 -10
  80. package/dist/tsup/mod.cjs +9 -15
  81. package/dist/tsup/mod.cjs.map +1 -1
  82. package/dist/tsup/mod.d.cts +47 -42
  83. package/dist/tsup/mod.d.ts +47 -42
  84. package/dist/tsup/mod.js +10 -16
  85. package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-BTe_Rsdn.d.cts} +2 -3
  86. package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-CBSrKHmo.d.ts} +2 -3
  87. package/dist/tsup/test/mod.cjs +10 -14
  88. package/dist/tsup/test/mod.cjs.map +1 -1
  89. package/dist/tsup/test/mod.d.cts +4 -5
  90. package/dist/tsup/test/mod.d.ts +4 -5
  91. package/dist/tsup/test/mod.js +9 -13
  92. package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
  93. package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
  94. package/dist/tsup/utils.cjs +3 -3
  95. package/dist/tsup/utils.d.cts +1 -1
  96. package/dist/tsup/utils.d.ts +1 -1
  97. package/dist/tsup/utils.js +2 -2
  98. package/package.json +4 -4
  99. package/src/actor/action.ts +1 -5
  100. package/src/actor/config.ts +27 -295
  101. package/src/actor/connection.ts +9 -12
  102. package/src/actor/context.ts +1 -4
  103. package/src/actor/definition.ts +7 -11
  104. package/src/actor/errors.ts +97 -35
  105. package/src/actor/generic-conn-driver.ts +28 -16
  106. package/src/actor/instance.ts +177 -133
  107. package/src/actor/log.ts +4 -13
  108. package/src/actor/mod.ts +0 -5
  109. package/src/actor/protocol/old.ts +42 -26
  110. package/src/actor/protocol/serde.ts +1 -1
  111. package/src/actor/router-endpoints.ts +41 -38
  112. package/src/actor/router.ts +20 -18
  113. package/src/actor/unstable-react.ts +1 -1
  114. package/src/actor/utils.ts +6 -2
  115. package/src/client/actor-common.ts +1 -1
  116. package/src/client/actor-conn.ts +152 -91
  117. package/src/client/actor-handle.ts +85 -25
  118. package/src/client/actor-query.ts +65 -0
  119. package/src/client/client.ts +29 -98
  120. package/src/client/config.ts +44 -0
  121. package/src/client/errors.ts +1 -0
  122. package/src/client/log.ts +2 -4
  123. package/src/client/mod.ts +16 -12
  124. package/src/client/raw-utils.ts +82 -25
  125. package/src/client/utils.ts +5 -3
  126. package/src/common/fake-event-source.ts +10 -9
  127. package/src/common/inline-websocket-adapter2.ts +39 -30
  128. package/src/common/log.ts +176 -101
  129. package/src/common/logfmt.ts +21 -30
  130. package/src/common/router.ts +12 -19
  131. package/src/common/utils.ts +27 -13
  132. package/src/common/websocket.ts +0 -1
  133. package/src/driver-helpers/mod.ts +1 -1
  134. package/src/driver-test-suite/log.ts +1 -3
  135. package/src/driver-test-suite/mod.ts +86 -60
  136. package/src/driver-test-suite/tests/actor-handle.ts +33 -0
  137. package/src/driver-test-suite/tests/manager-driver.ts +5 -3
  138. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
  139. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
  140. package/src/driver-test-suite/tests/request-access.ts +112 -126
  141. package/src/driver-test-suite/utils.ts +13 -10
  142. package/src/drivers/default.ts +7 -4
  143. package/src/drivers/engine/actor-driver.ts +22 -13
  144. package/src/drivers/engine/config.ts +2 -10
  145. package/src/drivers/engine/kv.ts +1 -1
  146. package/src/drivers/engine/log.ts +1 -3
  147. package/src/drivers/engine/mod.ts +2 -3
  148. package/src/drivers/file-system/actor.ts +1 -1
  149. package/src/drivers/file-system/global-state.ts +33 -20
  150. package/src/drivers/file-system/log.ts +1 -3
  151. package/src/drivers/file-system/manager.ts +31 -8
  152. package/src/inspector/config.ts +9 -4
  153. package/src/inspector/log.ts +1 -1
  154. package/src/inspector/manager.ts +2 -2
  155. package/src/inspector/utils.ts +1 -1
  156. package/src/manager/driver.ts +10 -2
  157. package/src/manager/hono-websocket-adapter.ts +21 -12
  158. package/src/manager/log.ts +2 -4
  159. package/src/manager/mod.ts +1 -1
  160. package/src/manager/router.ts +277 -1657
  161. package/src/manager-api/routes/actors-create.ts +16 -0
  162. package/src/manager-api/routes/actors-delete.ts +4 -0
  163. package/src/manager-api/routes/actors-get-by-id.ts +7 -0
  164. package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
  165. package/src/manager-api/routes/actors-get.ts +7 -0
  166. package/src/manager-api/routes/common.ts +18 -0
  167. package/src/mod.ts +0 -2
  168. package/src/registry/config.ts +1 -1
  169. package/src/registry/log.ts +2 -4
  170. package/src/registry/mod.ts +57 -24
  171. package/src/registry/run-config.ts +31 -33
  172. package/src/registry/serve.ts +4 -5
  173. package/src/remote-manager-driver/actor-http-client.ts +72 -0
  174. package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
  175. package/src/remote-manager-driver/api-endpoints.ts +79 -0
  176. package/src/remote-manager-driver/api-utils.ts +43 -0
  177. package/src/remote-manager-driver/log.ts +5 -0
  178. package/src/remote-manager-driver/mod.ts +274 -0
  179. package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
  180. package/src/serde.ts +8 -2
  181. package/src/test/log.ts +1 -3
  182. package/src/test/mod.ts +17 -16
  183. package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
  184. package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
  185. package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
  186. package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
  187. package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
  188. package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
  189. package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
  190. package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
  191. package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
  192. package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
  193. package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
  194. package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
  195. package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
  196. package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
  197. package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
  198. package/dist/tsup/chunk-INGJP237.js.map +0 -1
  199. package/dist/tsup/chunk-KJCJLKRM.js +0 -116
  200. package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
  201. package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
  202. package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
  203. package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
  204. package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
  205. package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
  206. package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
  207. package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
  208. package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
  209. package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
  210. package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
  211. package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
  212. package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
  213. package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
  214. package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
  215. package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
  216. package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
  217. package/dist/tsup/chunk-UVUPOS46.js +0 -230
  218. package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
  219. package/dist/tsup/chunk-VRRHBNJC.js +0 -189
  220. package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
  221. package/dist/tsup/chunk-XFSS33EQ.js +0 -202
  222. package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
  223. package/src/client/http-client-driver.ts +0 -326
  224. package/src/driver-test-suite/test-inline-client-driver.ts +0 -402
  225. package/src/driver-test-suite/tests/actor-auth.ts +0 -591
  226. package/src/drivers/engine/api-endpoints.ts +0 -128
  227. package/src/drivers/engine/api-utils.ts +0 -70
  228. package/src/drivers/engine/manager-driver.ts +0 -391
  229. package/src/inline-client-driver/log.ts +0 -7
  230. package/src/inline-client-driver/mod.ts +0 -385
  231. package/src/manager/auth.ts +0 -121
  232. /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
  233. /package/src/{drivers/engine → actor}/keys.ts +0 -0
@@ -3,7 +3,7 @@ import invariant from "invariant";
3
3
  import onChange from "on-change";
4
4
  import type { ActorKey } from "@/actor/mod";
5
5
  import type { Client } from "@/client/client";
6
- import type { Logger } from "@/common/log";
6
+ import { getBaseLogger, getIncludeTarget, type Logger } from "@/common/log";
7
7
  import { isCborSerializable, stringifyError } from "@/common/utils";
8
8
  import type { UniversalWebSocket } from "@/common/websocket-interface";
9
9
  import { ActorInspector } from "@/inspector/actor";
@@ -12,7 +12,11 @@ import type * as bareSchema from "@/schemas/actor-persist/mod";
12
12
  import { PERSISTED_ACTOR_VERSIONED } from "@/schemas/actor-persist/versioned";
13
13
  import type * as protocol from "@/schemas/client-protocol/mod";
14
14
  import { TO_CLIENT_VERSIONED } from "@/schemas/client-protocol/versioned";
15
- import { bufferToArrayBuffer, SinglePromiseQueue } from "@/utils";
15
+ import {
16
+ bufferToArrayBuffer,
17
+ getEnvUniversal,
18
+ SinglePromiseQueue,
19
+ } from "@/utils";
16
20
  import type { ActionContext } from "./action";
17
21
  import type { ActorConfig, OnConnectOptions } from "./config";
18
22
  import {
@@ -25,7 +29,8 @@ import { ActorContext } from "./context";
25
29
  import type { AnyDatabaseProvider, InferDatabaseClient } from "./database";
26
30
  import type { ActorDriver, ConnDriver, ConnectionDriversMap } from "./driver";
27
31
  import * as errors from "./errors";
28
- import { instanceLogger, logger } from "./log";
32
+ import { serializeActorKey } from "./keys";
33
+ import { loggerWithoutContext } from "./log";
29
34
  import type {
30
35
  PersistedActor,
31
36
  PersistedConn,
@@ -61,8 +66,6 @@ export type AnyActorInstance = ActorInstance<
61
66
  // biome-ignore lint/suspicious/noExplicitAny: Needs to be used in `extends`
62
67
  any,
63
68
  // biome-ignore lint/suspicious/noExplicitAny: Needs to be used in `extends`
64
- any,
65
- // biome-ignore lint/suspicious/noExplicitAny: Needs to be used in `extends`
66
69
  any
67
70
  >;
68
71
 
@@ -78,8 +81,6 @@ export type ExtractActorState<A extends AnyActorInstance> =
78
81
  // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
79
82
  any,
80
83
  // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
81
- any,
82
- // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
83
84
  any
84
85
  >
85
86
  ? State
@@ -97,8 +98,6 @@ export type ExtractActorConnParams<A extends AnyActorInstance> =
97
98
  // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
98
99
  any,
99
100
  // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
100
- any,
101
- // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
102
101
  any
103
102
  >
104
103
  ? ConnParams
@@ -116,24 +115,21 @@ export type ExtractActorConnState<A extends AnyActorInstance> =
116
115
  // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
117
116
  any,
118
117
  // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
119
- any,
120
- // biome-ignore lint/suspicious/noExplicitAny: Must be used for `extends`
121
118
  any
122
119
  >
123
120
  ? ConnState
124
121
  : never;
125
122
 
126
- export class ActorInstance<
127
- S,
128
- CP,
129
- CS,
130
- V,
131
- I,
132
- AD,
133
- DB extends AnyDatabaseProvider,
134
- > {
123
+ export class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
135
124
  // Shared actor context for this instance
136
- actorContext: ActorContext<S, CP, CS, V, I, AD, DB>;
125
+ actorContext: ActorContext<S, CP, CS, V, I, DB>;
126
+
127
+ /** Actor log, intended for the user to call */
128
+ #log!: Logger;
129
+
130
+ /** Runtime log, intended for internal actor logs */
131
+ #rLog!: Logger;
132
+
137
133
  #sleepCalled = false;
138
134
  #stopCalled = false;
139
135
 
@@ -164,7 +160,7 @@ export class ActorInstance<
164
160
 
165
161
  #backgroundPromises: Promise<void>[] = [];
166
162
  #abortController = new AbortController();
167
- #config: ActorConfig<S, CP, CS, V, I, AD, DB>;
163
+ #config: ActorConfig<S, CP, CS, V, I, DB>;
168
164
  #connectionDrivers!: ConnectionDriversMap;
169
165
  #actorDriver!: ActorDriver;
170
166
  #inlineClient!: Client<Registry<any>>;
@@ -174,8 +170,8 @@ export class ActorInstance<
174
170
  #region!: string;
175
171
  #ready = false;
176
172
 
177
- #connections = new Map<ConnId, Conn<S, CP, CS, V, I, AD, DB>>();
178
- #subscriptionIndex = new Map<string, Set<Conn<S, CP, CS, V, I, AD, DB>>>();
173
+ #connections = new Map<ConnId, Conn<S, CP, CS, V, I, DB>>();
174
+ #subscriptionIndex = new Map<string, Set<Conn<S, CP, CS, V, I, DB>>>();
179
175
  #checkConnLivenessInterval?: NodeJS.Timeout;
180
176
 
181
177
  #sleepTimeout?: NodeJS.Timeout;
@@ -213,7 +209,6 @@ export class ActorInstance<
213
209
  stateEnabled: conn._stateEnabled,
214
210
  params: conn.params as {},
215
211
  state: conn._stateEnabled ? conn.state : undefined,
216
- auth: conn.auth as {},
217
212
  }));
218
213
  },
219
214
  setState: async (state: unknown) => {
@@ -253,7 +248,7 @@ export class ActorInstance<
253
248
  *
254
249
  * @private
255
250
  */
256
- constructor(config: ActorConfig<S, CP, CS, V, I, AD, DB>) {
251
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB>) {
257
252
  this.#config = config;
258
253
  this.actorContext = new ActorContext(this);
259
254
  }
@@ -267,6 +262,22 @@ export class ActorInstance<
267
262
  key: ActorKey,
268
263
  region: string,
269
264
  ) {
265
+ const logParams = {
266
+ actor: name,
267
+ key: serializeActorKey(key),
268
+ actorId,
269
+ };
270
+
271
+ this.#log = getBaseLogger().child(
272
+ Object.assign(getIncludeTarget() ? { target: "actor" } : {}, logParams),
273
+ );
274
+ this.#rLog = getBaseLogger().child(
275
+ Object.assign(
276
+ getIncludeTarget() ? { target: "actor-runtime" } : {},
277
+ logParams,
278
+ ),
279
+ );
280
+
270
281
  this.#connectionDrivers = connectionDrivers;
271
282
  this.#actorDriver = actorDriver;
272
283
  this.#inlineClient = inlineClient;
@@ -292,7 +303,6 @@ export class ActorInstance<
292
303
  undefined,
293
304
  undefined,
294
305
  undefined,
295
- undefined,
296
306
  any
297
307
  >,
298
308
  this.#actorDriver.getContext(this.#actorId),
@@ -314,7 +324,7 @@ export class ActorInstance<
314
324
  }
315
325
 
316
326
  // TODO: Exit process if this errors
317
- logger().info("actor starting");
327
+ this.#rLog.info({ msg: "actor starting" });
318
328
  if (this.#config.onStart) {
319
329
  const result = this.#config.onStart(this.actorContext);
320
330
  if (result instanceof Promise) {
@@ -327,9 +337,9 @@ export class ActorInstance<
327
337
  const client = await this.#config.db.createClient({
328
338
  getDatabase: () => actorDriver.getDatabase(this.#actorId),
329
339
  });
330
- logger().info("database migration starting");
340
+ this.#rLog.info({ msg: "database migration starting" });
331
341
  await this.#config.db.onMigrate?.(client);
332
- logger().info("database migration complete");
342
+ this.#rLog.info({ msg: "database migration complete" });
333
343
  this.#db = client;
334
344
  }
335
345
 
@@ -338,7 +348,7 @@ export class ActorInstance<
338
348
  await this.#queueSetAlarm(this.#persist.scheduledEvents[0].timestamp);
339
349
  }
340
350
 
341
- logger().info("actor ready");
351
+ this.#rLog.info({ msg: "actor ready" });
342
352
  this.#ready = true;
343
353
 
344
354
  // Must be called after setting `#ready` or else it will not schedule sleep
@@ -365,7 +375,7 @@ export class ActorInstance<
365
375
  }
366
376
 
367
377
  async #scheduleEventInner(newEvent: PersistedScheduleEvent) {
368
- this.actorContext.log.info("scheduling event", newEvent);
378
+ this.actorContext.log.info({ msg: "scheduling event", ...newEvent });
369
379
 
370
380
  // Insert event in to index
371
381
  const insertIndex = this.#persist.scheduledEvents.findIndex(
@@ -381,7 +391,8 @@ export class ActorInstance<
381
391
  // - this is the newest event (i.e. at beginning of array) or
382
392
  // - this is the only event (i.e. the only event in the array)
383
393
  if (insertIndex === 0 || this.#persist.scheduledEvents.length === 1) {
384
- this.actorContext.log.info("setting alarm", {
394
+ this.actorContext.log.info({
395
+ msg: "setting alarm",
385
396
  timestamp: newEvent.timestamp,
386
397
  eventCount: this.#persist.scheduledEvents.length,
387
398
  });
@@ -391,7 +402,8 @@ export class ActorInstance<
391
402
 
392
403
  async _onAlarm() {
393
404
  const now = Date.now();
394
- this.actorContext.log.debug("alarm triggered", {
405
+ this.actorContext.log.debug({
406
+ msg: "alarm triggered",
395
407
  now,
396
408
  events: this.#persist.scheduledEvents.length,
397
409
  });
@@ -408,34 +420,34 @@ export class ActorInstance<
408
420
  if (runIndex === -1) {
409
421
  // No events are due yet. This will happen if timers fire slightly early.
410
422
  // Ensure we reschedule the alarm for the next upcoming event to avoid losing it.
411
- logger().warn("no events are due yet, time may have broken");
423
+ this.#rLog.warn({ msg: "no events are due yet, time may have broken" });
412
424
  if (this.#persist.scheduledEvents.length > 0) {
413
425
  const nextTs = this.#persist.scheduledEvents[0].timestamp;
414
- this.actorContext.log.warn(
415
- "alarm fired early, rescheduling for next event",
416
- {
417
- now,
418
- nextTs,
419
- delta: nextTs - now,
420
- },
421
- );
426
+ this.actorContext.log.warn({
427
+ msg: "alarm fired early, rescheduling for next event",
428
+ now,
429
+ nextTs,
430
+ delta: nextTs - now,
431
+ });
422
432
  await this.#queueSetAlarm(nextTs);
423
433
  }
424
- this.actorContext.log.debug("no events to run", { now });
434
+ this.actorContext.log.debug({ msg: "no events to run", now });
425
435
  return;
426
436
  }
427
437
  const scheduleEvents = this.#persist.scheduledEvents.splice(
428
438
  0,
429
439
  runIndex + 1,
430
440
  );
431
- this.actorContext.log.debug("running events", {
441
+ this.actorContext.log.debug({
442
+ msg: "running events",
432
443
  count: scheduleEvents.length,
433
444
  });
434
445
 
435
446
  // Set alarm for next event
436
447
  if (this.#persist.scheduledEvents.length > 0) {
437
448
  const nextTs = this.#persist.scheduledEvents[0].timestamp;
438
- this.actorContext.log.info("setting next alarm", {
449
+ this.actorContext.log.info({
450
+ msg: "setting next alarm",
439
451
  nextTs,
440
452
  remainingEvents: this.#persist.scheduledEvents.length,
441
453
  });
@@ -445,7 +457,8 @@ export class ActorInstance<
445
457
  // Iterate by event key in order to ensure we call the events in order
446
458
  for (const event of scheduleEvents) {
447
459
  try {
448
- this.actorContext.log.info("running action for event", {
460
+ this.actorContext.log.info({
461
+ msg: "running action for event",
449
462
  event: event.eventId,
450
463
  timestamp: event.timestamp,
451
464
  action: event.kind.generic.actionName,
@@ -470,7 +483,8 @@ export class ActorInstance<
470
483
  : [];
471
484
  await fn.call(undefined, this.actorContext, ...args);
472
485
  } catch (error) {
473
- this.actorContext.log.error("error while running event", {
486
+ this.actorContext.log.error({
487
+ msg: "error while running event",
474
488
  error: stringifyError(error),
475
489
  event: event.eventId,
476
490
  timestamp: event.timestamp,
@@ -478,7 +492,8 @@ export class ActorInstance<
478
492
  });
479
493
  }
480
494
  } catch (error) {
481
- this.actorContext.log.error("internal error while running event", {
495
+ this.actorContext.log.error({
496
+ msg: "internal error while running event",
482
497
  error: stringifyError(error),
483
498
  ...event,
484
499
  });
@@ -557,7 +572,7 @@ export class ActorInstance<
557
572
 
558
573
  if (this.#persistChanged) {
559
574
  const finished = this.#persistWriteQueue.enqueue(async () => {
560
- logger().debug("saving persist");
575
+ this.#rLog.debug({ msg: "saving persist" });
561
576
 
562
577
  // There might be more changes while we're writing, so we set this
563
578
  // before writing to KV in order to avoid a race condition.
@@ -570,7 +585,7 @@ export class ActorInstance<
570
585
  PERSISTED_ACTOR_VERSIONED.serializeWithEmbeddedVersion(bareData),
571
586
  );
572
587
 
573
- logger().debug("persist saved");
588
+ this.#rLog.debug({ msg: "persist saved" });
574
589
  });
575
590
 
576
591
  await finished;
@@ -662,7 +677,8 @@ export class ActorInstance<
662
677
  this.#persistRaw.state,
663
678
  );
664
679
  } catch (error) {
665
- logger().error("error in `_onStateChange`", {
680
+ this.#rLog.error({
681
+ msg: "error in `_onStateChange`",
666
682
  error: stringifyError(error),
667
683
  });
668
684
  } finally {
@@ -692,7 +708,8 @@ export class ActorInstance<
692
708
  const persistData = this.#convertFromBarePersisted(bareData);
693
709
 
694
710
  if (persistData.hasInitiated) {
695
- logger().info("actor restoring", {
711
+ this.#rLog.info({
712
+ msg: "actor restoring",
696
713
  connections: persistData.connections.length,
697
714
  });
698
715
 
@@ -703,7 +720,7 @@ export class ActorInstance<
703
720
  for (const connPersist of this.#persist.connections) {
704
721
  // Create connections
705
722
  const driver = this.__getConnDriver(connPersist.connDriver);
706
- const conn = new Conn<S, CP, CS, V, I, AD, DB>(
723
+ const conn = new Conn<S, CP, CS, V, I, DB>(
707
724
  this,
708
725
  connPersist,
709
726
  driver,
@@ -717,12 +734,12 @@ export class ActorInstance<
717
734
  }
718
735
  }
719
736
  } else {
720
- logger().info("actor creating");
737
+ this.#rLog.info({ msg: "actor creating" });
721
738
 
722
739
  // Initialize actor state
723
740
  let stateData: unknown;
724
741
  if (this.stateEnabled) {
725
- logger().info("actor state initializing");
742
+ this.#rLog.info({ msg: "actor state initializing" });
726
743
 
727
744
  if ("createState" in this.#config) {
728
745
  this.#config.createState;
@@ -735,7 +752,6 @@ export class ActorInstance<
735
752
  undefined,
736
753
  undefined,
737
754
  undefined,
738
- undefined,
739
755
  undefined
740
756
  >,
741
757
  persistData.input!,
@@ -746,7 +762,7 @@ export class ActorInstance<
746
762
  throw new Error("Both 'createState' or 'state' were not defined");
747
763
  }
748
764
  } else {
749
- logger().debug("state not enabled");
765
+ this.#rLog.debug({ msg: "state not enabled" });
750
766
  }
751
767
 
752
768
  // Save state and mark as initialized
@@ -754,7 +770,7 @@ export class ActorInstance<
754
770
  persistData.hasInitiated = true;
755
771
 
756
772
  // Update state
757
- logger().debug("writing state");
773
+ this.#rLog.debug({ msg: "writing state" });
758
774
  const bareData = this.#convertToBarePersisted(persistData);
759
775
  await this.#actorDriver.writePersistedData(
760
776
  this.#actorId,
@@ -770,16 +786,16 @@ export class ActorInstance<
770
786
  }
771
787
  }
772
788
 
773
- __getConnForId(id: string): Conn<S, CP, CS, V, I, AD, DB> | undefined {
789
+ __getConnForId(id: string): Conn<S, CP, CS, V, I, DB> | undefined {
774
790
  return this.#connections.get(id);
775
791
  }
776
792
 
777
793
  /**
778
794
  * Removes a connection and cleans up its resources.
779
795
  */
780
- __removeConn(conn: Conn<S, CP, CS, V, I, AD, DB> | undefined) {
796
+ __removeConn(conn: Conn<S, CP, CS, V, I, DB> | undefined) {
781
797
  if (!conn) {
782
- logger().warn("`conn` does not exist");
798
+ this.#rLog.warn({ msg: "`conn` does not exist" });
783
799
  return;
784
800
  }
785
801
 
@@ -791,7 +807,8 @@ export class ActorInstance<
791
807
  this.#persist.connections.splice(connIdx, 1);
792
808
  this.saveState({ immediate: true, allowStoppingState: true });
793
809
  } else {
794
- logger().warn("could not find persisted connection to remove", {
810
+ this.#rLog.warn({
811
+ msg: "could not find persisted connection to remove",
795
812
  connId: conn.id,
796
813
  });
797
814
  }
@@ -811,13 +828,15 @@ export class ActorInstance<
811
828
  if (result instanceof Promise) {
812
829
  // Handle promise but don't await it to prevent blocking
813
830
  result.catch((error) => {
814
- logger().error("error in `onDisconnect`", {
831
+ this.#rLog.error({
832
+ msg: "error in `onDisconnect`",
815
833
  error: stringifyError(error),
816
834
  });
817
835
  });
818
836
  }
819
837
  } catch (error) {
820
- logger().error("error in `onDisconnect`", {
838
+ this.#rLog.error({
839
+ msg: "error in `onDisconnect`",
821
840
  error: stringifyError(error),
822
841
  });
823
842
  }
@@ -856,7 +875,6 @@ export class ActorInstance<
856
875
  undefined,
857
876
  undefined,
858
877
  undefined,
859
- undefined,
860
878
  undefined
861
879
  >,
862
880
  onBeforeConnectOpts,
@@ -900,7 +918,7 @@ export class ActorInstance<
900
918
  driverId: ConnectionDriver,
901
919
  driverState: unknown,
902
920
  authData: unknown,
903
- ): Promise<Conn<S, CP, CS, V, I, AD, DB>> {
921
+ ): Promise<Conn<S, CP, CS, V, I, DB>> {
904
922
  this.#assertReady();
905
923
 
906
924
  if (this.#connections.has(connectionId)) {
@@ -920,7 +938,7 @@ export class ActorInstance<
920
938
  lastSeen: Date.now(),
921
939
  subscriptions: [],
922
940
  };
923
- const conn = new Conn<S, CP, CS, V, I, AD, DB>(
941
+ const conn = new Conn<S, CP, CS, V, I, DB>(
924
942
  this,
925
943
  persist,
926
944
  driver,
@@ -944,7 +962,8 @@ export class ActorInstance<
944
962
  if (result instanceof Promise) {
945
963
  deadline(result, this.#config.options.onConnectTimeout).catch(
946
964
  (error) => {
947
- logger().error("error in `onConnect`, closing socket", {
965
+ this.#rLog.error({
966
+ msg: "error in `onConnect`, closing socket",
948
967
  error,
949
968
  });
950
969
  conn?.disconnect("`onConnect` failed");
@@ -952,7 +971,8 @@ export class ActorInstance<
952
971
  );
953
972
  }
954
973
  } catch (error) {
955
- logger().error("error in `onConnect`", {
974
+ this.#rLog.error({
975
+ msg: "error in `onConnect`",
956
976
  error: stringifyError(error),
957
977
  });
958
978
  conn?.disconnect("`onConnect` failed");
@@ -984,7 +1004,7 @@ export class ActorInstance<
984
1004
  // MARK: Messages
985
1005
  async processMessage(
986
1006
  message: protocol.ToServer,
987
- conn: Conn<S, CP, CS, V, I, AD, DB>,
1007
+ conn: Conn<S, CP, CS, V, I, DB>,
988
1008
  ) {
989
1009
  await processMessage(message, this, conn, {
990
1010
  onExecuteAction: async (ctx, name, args) => {
@@ -1018,11 +1038,14 @@ export class ActorInstance<
1018
1038
  // MARK: Events
1019
1039
  #addSubscription(
1020
1040
  eventName: string,
1021
- connection: Conn<S, CP, CS, V, I, AD, DB>,
1041
+ connection: Conn<S, CP, CS, V, I, DB>,
1022
1042
  fromPersist: boolean,
1023
1043
  ) {
1024
1044
  if (connection.subscriptions.has(eventName)) {
1025
- logger().debug("connection already has subscription", { eventName });
1045
+ this.#rLog.debug({
1046
+ msg: "connection already has subscription",
1047
+ eventName,
1048
+ });
1026
1049
  return;
1027
1050
  }
1028
1051
 
@@ -1048,11 +1071,14 @@ export class ActorInstance<
1048
1071
 
1049
1072
  #removeSubscription(
1050
1073
  eventName: string,
1051
- connection: Conn<S, CP, CS, V, I, AD, DB>,
1074
+ connection: Conn<S, CP, CS, V, I, DB>,
1052
1075
  fromRemoveConn: boolean,
1053
1076
  ) {
1054
1077
  if (!connection.subscriptions.has(eventName)) {
1055
- logger().warn("connection does not have subscription", { eventName });
1078
+ this.#rLog.warn({
1079
+ msg: "connection does not have subscription",
1080
+ eventName,
1081
+ });
1056
1082
  return;
1057
1083
  }
1058
1084
 
@@ -1068,7 +1094,10 @@ export class ActorInstance<
1068
1094
  if (subIdx !== -1) {
1069
1095
  connection.__persist.subscriptions.splice(subIdx, 1);
1070
1096
  } else {
1071
- logger().warn("subscription does not exist with name", { eventName });
1097
+ this.#rLog.warn({
1098
+ msg: "subscription does not exist with name",
1099
+ eventName,
1100
+ });
1072
1101
  }
1073
1102
 
1074
1103
  this.saveState({ immediate: true });
@@ -1097,17 +1126,18 @@ export class ActorInstance<
1097
1126
  * Sets up a recurring check based on the configured interval.
1098
1127
  */
1099
1128
  #checkConnectionsLiveness() {
1100
- logger().debug("checking connections liveness");
1129
+ this.#rLog.debug({ msg: "checking connections liveness" });
1101
1130
 
1102
1131
  for (const conn of this.#connections.values()) {
1103
1132
  const liveness = conn[CONNECTION_CHECK_LIVENESS_SYMBOL]();
1104
1133
  if (liveness.status === "connected") {
1105
- logger().debug("connection is alive", { connId: conn.id });
1134
+ this.#rLog.debug({ msg: "connection is alive", connId: conn.id });
1106
1135
  } else {
1107
1136
  const lastSeen = liveness.lastSeen;
1108
1137
  const sinceLastSeen = Date.now() - lastSeen;
1109
1138
  if (sinceLastSeen < this.#config.options.connectionLivenessTimeout) {
1110
- logger().debug("connection might be alive, will check later", {
1139
+ this.#rLog.debug({
1140
+ msg: "connection might be alive, will check later",
1111
1141
  connId: conn.id,
1112
1142
  lastSeen,
1113
1143
  sinceLastSeen,
@@ -1116,7 +1146,8 @@ export class ActorInstance<
1116
1146
  }
1117
1147
 
1118
1148
  // Connection is dead, remove it
1119
- logger().warn("connection is dead, removing", {
1149
+ this.#rLog.warn({
1150
+ msg: "connection is dead, removing",
1120
1151
  connId: conn.id,
1121
1152
  lastSeen,
1122
1153
  });
@@ -1154,7 +1185,7 @@ export class ActorInstance<
1154
1185
  * @internal
1155
1186
  */
1156
1187
  async executeAction(
1157
- ctx: ActionContext<S, CP, CS, V, I, AD, DB>,
1188
+ ctx: ActionContext<S, CP, CS, V, I, DB>,
1158
1189
  actionName: string,
1159
1190
  args: unknown[],
1160
1191
  ): Promise<unknown> {
@@ -1162,14 +1193,15 @@ export class ActorInstance<
1162
1193
 
1163
1194
  // Prevent calling private or reserved methods
1164
1195
  if (!(actionName in this.#config.actions)) {
1165
- logger().warn("action does not exist", { actionName });
1196
+ this.#rLog.warn({ msg: "action does not exist", actionName });
1166
1197
  throw new errors.ActionNotFound(actionName);
1167
1198
  }
1168
1199
 
1169
1200
  // Check if the method exists on this object
1170
1201
  const actionFunction = this.#config.actions[actionName];
1171
1202
  if (typeof actionFunction !== "function") {
1172
- logger().warn("action is not a function", {
1203
+ this.#rLog.warn({
1204
+ msg: "action is not a function",
1173
1205
  actionName: actionName,
1174
1206
  type: typeof actionFunction,
1175
1207
  });
@@ -1181,13 +1213,20 @@ export class ActorInstance<
1181
1213
  // Call the function on this object with those arguments
1182
1214
  try {
1183
1215
  // Log when we start executing the action
1184
- logger().debug("executing action", { actionName: actionName, args });
1216
+ this.#rLog.debug({
1217
+ msg: "executing action",
1218
+ actionName: actionName,
1219
+ args,
1220
+ });
1185
1221
 
1186
1222
  const outputOrPromise = actionFunction.call(undefined, ctx, ...args);
1187
1223
  let output: unknown;
1188
1224
  if (outputOrPromise instanceof Promise) {
1189
1225
  // Log that we're waiting for an async action
1190
- logger().debug("awaiting async action", { actionName: actionName });
1226
+ this.#rLog.debug({
1227
+ msg: "awaiting async action",
1228
+ actionName: actionName,
1229
+ });
1191
1230
 
1192
1231
  output = await deadline(
1193
1232
  outputOrPromise,
@@ -1195,7 +1234,10 @@ export class ActorInstance<
1195
1234
  );
1196
1235
 
1197
1236
  // Log that async action completed
1198
- logger().debug("async action completed", { actionName: actionName });
1237
+ this.#rLog.debug({
1238
+ msg: "async action completed",
1239
+ actionName: actionName,
1240
+ });
1199
1241
  } else {
1200
1242
  output = outputOrPromise;
1201
1243
  }
@@ -1210,25 +1252,29 @@ export class ActorInstance<
1210
1252
  output,
1211
1253
  );
1212
1254
  if (processedOutput instanceof Promise) {
1213
- logger().debug("awaiting onBeforeActionResponse", {
1255
+ this.#rLog.debug({
1256
+ msg: "awaiting onBeforeActionResponse",
1214
1257
  actionName: actionName,
1215
1258
  });
1216
1259
  output = await processedOutput;
1217
- logger().debug("onBeforeActionResponse completed", {
1260
+ this.#rLog.debug({
1261
+ msg: "onBeforeActionResponse completed",
1218
1262
  actionName: actionName,
1219
1263
  });
1220
1264
  } else {
1221
1265
  output = processedOutput;
1222
1266
  }
1223
1267
  } catch (error) {
1224
- logger().error("error in `onBeforeActionResponse`", {
1268
+ this.#rLog.error({
1269
+ msg: "error in `onBeforeActionResponse`",
1225
1270
  error: stringifyError(error),
1226
1271
  });
1227
1272
  }
1228
1273
  }
1229
1274
 
1230
1275
  // Log the output before returning
1231
- logger().debug("action completed", {
1276
+ this.#rLog.debug({
1277
+ msg: "action completed",
1232
1278
  actionName: actionName,
1233
1279
  outputType: typeof output,
1234
1280
  isPromise: output instanceof Promise,
@@ -1242,7 +1288,8 @@ export class ActorInstance<
1242
1288
  if (error instanceof DeadlineError) {
1243
1289
  throw new errors.ActionTimedOut();
1244
1290
  }
1245
- logger().error("action error", {
1291
+ this.#rLog.error({
1292
+ msg: "action error",
1246
1293
  actionName: actionName,
1247
1294
  error: stringifyError(error),
1248
1295
  });
@@ -1262,7 +1309,7 @@ export class ActorInstance<
1262
1309
  /**
1263
1310
  * Handles raw HTTP requests to the actor.
1264
1311
  */
1265
- async handleFetch(request: Request, opts: { auth: AD }): Promise<Response> {
1312
+ async handleFetch(request: Request, opts: {}): Promise<Response> {
1266
1313
  this.#assertReady();
1267
1314
 
1268
1315
  if (!this.#config.onFetch) {
@@ -1284,9 +1331,7 @@ export class ActorInstance<
1284
1331
  }
1285
1332
  return response;
1286
1333
  } catch (error) {
1287
- logger().error("onFetch error", {
1288
- error: stringifyError(error),
1289
- });
1334
+ this.#rLog.error({ msg: "onFetch error", error: stringifyError(error) });
1290
1335
  throw error;
1291
1336
  } finally {
1292
1337
  // Decrement active raw fetch counter and re-evaluate sleep
@@ -1301,7 +1346,7 @@ export class ActorInstance<
1301
1346
  */
1302
1347
  async handleWebSocket(
1303
1348
  websocket: UniversalWebSocket,
1304
- opts: { request: Request; auth: AD },
1349
+ opts: { request: Request },
1305
1350
  ): Promise<void> {
1306
1351
  this.#assertReady();
1307
1352
 
@@ -1340,7 +1385,8 @@ export class ActorInstance<
1340
1385
  await this.saveState({ immediate: true });
1341
1386
  }
1342
1387
  } catch (error) {
1343
- logger().error("onWebSocket error", {
1388
+ this.#rLog.error({
1389
+ msg: "onWebSocket error",
1344
1390
  error: stringifyError(error),
1345
1391
  });
1346
1392
  throw error;
@@ -1352,11 +1398,14 @@ export class ActorInstance<
1352
1398
  // MARK: Lifecycle hooks
1353
1399
 
1354
1400
  // MARK: Exposed methods
1355
- /**
1356
- * Gets the logger instance.
1357
- */
1358
1401
  get log(): Logger {
1359
- return instanceLogger();
1402
+ invariant(this.#log, "log not configured");
1403
+ return this.#log;
1404
+ }
1405
+
1406
+ get rLog(): Logger {
1407
+ invariant(this.#rLog, "log not configured");
1408
+ return this.#rLog;
1360
1409
  }
1361
1410
 
1362
1411
  /**
@@ -1390,7 +1439,7 @@ export class ActorInstance<
1390
1439
  /**
1391
1440
  * Gets the map of connections.
1392
1441
  */
1393
- get conns(): Map<ConnId, Conn<S, CP, CS, V, I, AD, DB>> {
1442
+ get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB>> {
1394
1443
  return this.#connections;
1395
1444
  }
1396
1445
 
@@ -1484,10 +1533,11 @@ export class ActorInstance<
1484
1533
  // Add logging to promise and make it non-failable
1485
1534
  const nonfailablePromise = promise
1486
1535
  .then(() => {
1487
- logger().debug("wait until promise complete");
1536
+ this.#rLog.debug({ msg: "wait until promise complete" });
1488
1537
  })
1489
1538
  .catch((error) => {
1490
- logger().error("wait until promise failed", {
1539
+ this.#rLog.error({
1540
+ msg: "wait until promise failed",
1491
1541
  error: stringifyError(error),
1492
1542
  });
1493
1543
  });
@@ -1540,7 +1590,8 @@ export class ActorInstance<
1540
1590
 
1541
1591
  const canSleep = this.#canSleep();
1542
1592
 
1543
- logger().debug("resetting sleep timer", {
1593
+ this.#rLog.debug({
1594
+ msg: "resetting sleep timer",
1544
1595
  canSleep,
1545
1596
  existingTimeout: !!this.#sleepTimeout,
1546
1597
  });
@@ -1556,7 +1607,8 @@ export class ActorInstance<
1556
1607
  if (canSleep) {
1557
1608
  this.#sleepTimeout = setTimeout(() => {
1558
1609
  this._sleep().catch((error) => {
1559
- logger().error("error during sleep", {
1610
+ this.#rLog.error({
1611
+ msg: "error during sleep",
1560
1612
  error: stringifyError(error),
1561
1613
  });
1562
1614
  });
@@ -1592,12 +1644,12 @@ export class ActorInstance<
1592
1644
  invariant(sleep, "no sleep on driver");
1593
1645
 
1594
1646
  if (this.#sleepCalled) {
1595
- logger().warn("already sleeping actor");
1647
+ this.#rLog.warn({ msg: "already sleeping actor" });
1596
1648
  return;
1597
1649
  }
1598
1650
  this.#sleepCalled = true;
1599
1651
 
1600
- logger().info("actor sleeping");
1652
+ this.#rLog.info({ msg: "actor sleeping" });
1601
1653
 
1602
1654
  // Schedule sleep to happen on the next tick. This allows for any action that calls _sleep to complete.
1603
1655
  setImmediate(async () => {
@@ -1611,12 +1663,12 @@ export class ActorInstance<
1611
1663
  // MARK: Stop
1612
1664
  async _stop() {
1613
1665
  if (this.#stopCalled) {
1614
- logger().warn("already stopping actor");
1666
+ this.#rLog.warn({ msg: "already stopping actor" });
1615
1667
  return;
1616
1668
  }
1617
1669
  this.#stopCalled = true;
1618
1670
 
1619
- logger().info("actor stopping");
1671
+ this.#rLog.info({ msg: "actor stopping" });
1620
1672
 
1621
1673
  // Abort any listeners waiting for shutdown
1622
1674
  try {
@@ -1626,17 +1678,18 @@ export class ActorInstance<
1626
1678
  // Call onStop lifecycle hook if defined
1627
1679
  if (this.#config.onStop) {
1628
1680
  try {
1629
- logger().debug("calling onStop");
1681
+ this.#rLog.debug({ msg: "calling onStop" });
1630
1682
  const result = this.#config.onStop(this.actorContext);
1631
1683
  if (result instanceof Promise) {
1632
1684
  await deadline(result, this.#config.options.onStopTimeout);
1633
1685
  }
1634
- logger().debug("onStop completed");
1686
+ this.#rLog.debug({ msg: "onStop completed" });
1635
1687
  } catch (error) {
1636
1688
  if (error instanceof DeadlineError) {
1637
- logger().error("onStop timed out");
1689
+ this.#rLog.error({ msg: "onStop timed out" });
1638
1690
  } else {
1639
- logger().error("error in onStop", {
1691
+ this.#rLog.error({
1692
+ msg: "error in onStop",
1640
1693
  error: stringifyError(error),
1641
1694
  });
1642
1695
  }
@@ -1672,9 +1725,9 @@ export class ActorInstance<
1672
1725
  ]);
1673
1726
 
1674
1727
  if (await res) {
1675
- logger().warn(
1676
- "timed out waiting for connections to close, shutting down anyway",
1677
- );
1728
+ this.#rLog.warn({
1729
+ msg: "timed out waiting for connections to close, shutting down anyway",
1730
+ });
1678
1731
  }
1679
1732
 
1680
1733
  // Wait for queues to finish
@@ -1693,7 +1746,7 @@ export class ActorInstance<
1693
1746
  async #waitBackgroundPromises(timeoutMs: number) {
1694
1747
  const pending = this.#backgroundPromises;
1695
1748
  if (pending.length === 0) {
1696
- logger().debug("no background promises");
1749
+ this.#rLog.debug({ msg: "no background promises" });
1697
1750
  return;
1698
1751
  }
1699
1752
 
@@ -1706,15 +1759,13 @@ export class ActorInstance<
1706
1759
  ]);
1707
1760
 
1708
1761
  if (timedOut) {
1709
- logger().error(
1710
- "timed out waiting for background tasks, background promises may have leaked",
1711
- {
1712
- count: pending.length,
1713
- timeoutMs,
1714
- },
1715
- );
1762
+ this.#rLog.error({
1763
+ msg: "timed out waiting for background tasks, background promises may have leaked",
1764
+ count: pending.length,
1765
+ timeoutMs,
1766
+ });
1716
1767
  } else {
1717
- logger().debug("background promises finished");
1768
+ this.#rLog.debug({ msg: "background promises finished" });
1718
1769
  }
1719
1770
  }
1720
1771
 
@@ -1738,10 +1789,6 @@ export class ActorInstance<
1738
1789
  ),
1739
1790
  parameters: bufferToArrayBuffer(cbor.encode(conn.params || {})),
1740
1791
  state: bufferToArrayBuffer(cbor.encode(conn.state || {})),
1741
- auth:
1742
- conn.authData !== undefined
1743
- ? bufferToArrayBuffer(cbor.encode(conn.authData))
1744
- : null,
1745
1792
  subscriptions: conn.subscriptions.map((sub) => ({
1746
1793
  eventName: sub.eventName,
1747
1794
  })),
@@ -1777,9 +1824,6 @@ export class ActorInstance<
1777
1824
  connDriverState: cbor.decode(new Uint8Array(conn.driverState)),
1778
1825
  params: cbor.decode(new Uint8Array(conn.parameters)),
1779
1826
  state: cbor.decode(new Uint8Array(conn.state)),
1780
- authData: conn.auth
1781
- ? cbor.decode(new Uint8Array(conn.auth))
1782
- : undefined,
1783
1827
  subscriptions: conn.subscriptions.map((sub) => ({
1784
1828
  eventName: sub.eventName,
1785
1829
  })),