rivetkit 2.0.22-rc.2 → 2.0.23
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.
- package/dist/schemas/actor-persist/v2.ts +29 -26
- package/dist/tsup/{chunk-FLVL7RGH.js → chunk-3I6ZIJVJ.js} +3 -3
- package/dist/tsup/{chunk-GXIO5YOT.cjs → chunk-3JYSUFET.cjs} +24 -10
- package/dist/tsup/chunk-3JYSUFET.cjs.map +1 -0
- package/dist/tsup/{chunk-NDOG6IQ5.cjs → chunk-54DVMQPT.cjs} +6 -6
- package/dist/tsup/{chunk-NDOG6IQ5.cjs.map → chunk-54DVMQPT.cjs.map} +1 -1
- package/dist/tsup/{chunk-7RUROQAZ.js → chunk-5PKKNNNS.js} +279 -9
- package/dist/tsup/chunk-5PKKNNNS.js.map +1 -0
- package/dist/tsup/{chunk-F7WVJXPB.js → chunk-5UJQWWO3.js} +2 -2
- package/dist/tsup/{chunk-YUBR6XCJ.cjs → chunk-C56XVVV4.cjs} +280 -10
- package/dist/tsup/chunk-C56XVVV4.cjs.map +1 -0
- package/dist/tsup/{chunk-Q5CAVEKC.cjs → chunk-D6PCH7FR.cjs} +561 -487
- package/dist/tsup/chunk-D6PCH7FR.cjs.map +1 -0
- package/dist/tsup/{chunk-C4FPCW7T.js → chunk-DLYZKFRY.js} +2 -2
- package/dist/tsup/{chunk-AMK3AACS.js → chunk-FTQ62XTN.js} +373 -299
- package/dist/tsup/chunk-FTQ62XTN.js.map +1 -0
- package/dist/tsup/{chunk-LFP446KS.cjs → chunk-HNYF4T36.cjs} +14 -14
- package/dist/tsup/{chunk-LFP446KS.cjs.map → chunk-HNYF4T36.cjs.map} +1 -1
- package/dist/tsup/{chunk-5TRXLS6X.cjs → chunk-JMLTKMJ7.cjs} +48 -44
- package/dist/tsup/chunk-JMLTKMJ7.cjs.map +1 -0
- package/dist/tsup/{chunk-ZY4DKLMT.cjs → chunk-NCUALX2Q.cjs} +3 -3
- package/dist/tsup/{chunk-ZY4DKLMT.cjs.map → chunk-NCUALX2Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-HLZT5C6A.js → chunk-NOZSCUPQ.js} +99 -50
- package/dist/tsup/chunk-NOZSCUPQ.js.map +1 -0
- package/dist/tsup/{chunk-CVLO2OOK.js → chunk-PHNIVSG5.js} +19 -5
- package/dist/tsup/chunk-PHNIVSG5.js.map +1 -0
- package/dist/tsup/{chunk-BHLQTKOD.js → chunk-RUTBXBRR.js} +27 -23
- package/dist/tsup/{chunk-BHLQTKOD.js.map → chunk-RUTBXBRR.js.map} +1 -1
- package/dist/tsup/{chunk-MQDXPGNE.js → chunk-RVVUS4X6.js} +6 -6
- package/dist/tsup/{chunk-UBMUBNS2.cjs → chunk-SN4KWTRA.cjs} +12 -12
- package/dist/tsup/{chunk-UBMUBNS2.cjs.map → chunk-SN4KWTRA.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZL6NSKF2.cjs → chunk-XSDSNHSE.cjs} +3 -3
- package/dist/tsup/{chunk-ZL6NSKF2.cjs.map → chunk-XSDSNHSE.cjs.map} +1 -1
- package/dist/tsup/{chunk-YLWF6RFL.cjs → chunk-XYK5PY3B.cjs} +283 -234
- package/dist/tsup/chunk-XYK5PY3B.cjs.map +1 -0
- package/dist/tsup/{chunk-EJXZYQ3N.js → chunk-YAYNBR37.js} +2 -2
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +2 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.js +1 -2
- package/dist/tsup/common/websocket.cjs +3 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +2 -3
- package/dist/tsup/{conn-BYXlxnh0.d.ts → conn-B3Vhbgnd.d.ts} +5 -1
- package/dist/tsup/{conn-BiazosE_.d.cts → conn-DJWL3nGx.d.cts} +5 -1
- package/dist/tsup/driver-helpers/mod.cjs +4 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +1 -1
- package/dist/tsup/driver-helpers/mod.d.ts +1 -1
- package/dist/tsup/driver-helpers/mod.js +3 -4
- package/dist/tsup/driver-test-suite/mod.cjs +70 -72
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +1 -1
- package/dist/tsup/driver-test-suite/mod.d.ts +1 -1
- package/dist/tsup/driver-test-suite/mod.js +11 -13
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +5 -6
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +2 -2
- package/dist/tsup/inspector/mod.d.ts +2 -2
- package/dist/tsup/inspector/mod.js +4 -5
- package/dist/tsup/mod.cjs +9 -10
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +8 -9
- package/dist/tsup/test/mod.cjs +10 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +9 -10
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/package.json +2 -2
- package/src/actor/conn-drivers.ts +0 -32
- package/src/actor/conn-socket.ts +2 -0
- package/src/actor/conn.ts +13 -12
- package/src/actor/instance.ts +164 -36
- package/src/actor/persisted.ts +4 -1
- package/src/actor/router-endpoints.ts +14 -0
- package/src/actor/router.ts +2 -0
- package/src/actor/utils.test.ts +48 -0
- package/src/actor/utils.ts +23 -0
- package/src/drivers/engine/actor-driver.ts +97 -35
- package/src/drivers/file-system/manager.ts +4 -0
- package/src/schemas/actor-persist/versioned.ts +4 -0
- package/src/utils.ts +15 -6
- package/dist/tsup/chunk-5N6F5PXD.cjs +0 -269
- package/dist/tsup/chunk-5N6F5PXD.cjs.map +0 -1
- package/dist/tsup/chunk-5TRXLS6X.cjs.map +0 -1
- package/dist/tsup/chunk-7RUROQAZ.js.map +0 -1
- package/dist/tsup/chunk-AMK3AACS.js.map +0 -1
- package/dist/tsup/chunk-CVLO2OOK.js.map +0 -1
- package/dist/tsup/chunk-GXIO5YOT.cjs.map +0 -1
- package/dist/tsup/chunk-HLZT5C6A.js.map +0 -1
- package/dist/tsup/chunk-Q5CAVEKC.cjs.map +0 -1
- package/dist/tsup/chunk-VMFBKBJL.js +0 -269
- package/dist/tsup/chunk-VMFBKBJL.js.map +0 -1
- package/dist/tsup/chunk-YLWF6RFL.cjs.map +0 -1
- package/dist/tsup/chunk-YUBR6XCJ.cjs.map +0 -1
- /package/dist/tsup/{chunk-FLVL7RGH.js.map → chunk-3I6ZIJVJ.js.map} +0 -0
- /package/dist/tsup/{chunk-F7WVJXPB.js.map → chunk-5UJQWWO3.js.map} +0 -0
- /package/dist/tsup/{chunk-C4FPCW7T.js.map → chunk-DLYZKFRY.js.map} +0 -0
- /package/dist/tsup/{chunk-MQDXPGNE.js.map → chunk-RVVUS4X6.js.map} +0 -0
- /package/dist/tsup/{chunk-EJXZYQ3N.js.map → chunk-YAYNBR37.js.map} +0 -0
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkSN4KWTRAcjs = require('./chunk-SN4KWTRA.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkNCUALX2Qcjs = require('./chunk-NCUALX2Q.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
@@ -18,7 +18,7 @@ var _chunkZY4DKLMTcjs = require('./chunk-ZY4DKLMT.cjs');
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkJMLTKMJ7cjs = require('./chunk-JMLTKMJ7.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -46,12 +46,11 @@ var _chunk5TRXLS6Xcjs = require('./chunk-5TRXLS6X.cjs');
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
var _chunkGXIO5YOTcjs = require('./chunk-GXIO5YOT.cjs');
|
|
50
49
|
|
|
51
50
|
|
|
51
|
+
var _chunk3JYSUFETcjs = require('./chunk-3JYSUFET.cjs');
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
var _chunk5N6F5PXDcjs = require('./chunk-5N6F5PXD.cjs');
|
|
55
54
|
|
|
56
55
|
|
|
57
56
|
|
|
@@ -66,7 +65,9 @@ var _chunk5N6F5PXDcjs = require('./chunk-5N6F5PXD.cjs');
|
|
|
66
65
|
|
|
67
66
|
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
var _chunkC56XVVV4cjs = require('./chunk-C56XVVV4.cjs');
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
|
|
@@ -83,7 +84,7 @@ var _chunkYUBR6XCJcjs = require('./chunk-YUBR6XCJ.cjs');
|
|
|
83
84
|
var _chunkKSRXX3Z4cjs = require('./chunk-KSRXX3Z4.cjs');
|
|
84
85
|
|
|
85
86
|
// src/actor/conn.ts
|
|
86
|
-
var _cborx = require('cbor-x'); var
|
|
87
|
+
var _cborx = require('cbor-x'); var cbor2 = _interopRequireWildcard(_cborx); var cbor = _interopRequireWildcard(_cborx); var cbor5 = _interopRequireWildcard(_cborx); var cbor4 = _interopRequireWildcard(_cborx); var cbor3 = _interopRequireWildcard(_cborx); var cbor6 = _interopRequireWildcard(_cborx);
|
|
87
88
|
|
|
88
89
|
// src/actor/conn-drivers.ts
|
|
89
90
|
var WEBSOCKET_DRIVER = {
|
|
@@ -139,21 +140,12 @@ var WEBSOCKET_DRIVER = {
|
|
|
139
140
|
},
|
|
140
141
|
getConnectionReadyState: (_actor, _conn, state) => {
|
|
141
142
|
return state.websocket.readyState;
|
|
142
|
-
},
|
|
143
|
-
isHibernatable(_actor, _conn, state) {
|
|
144
|
-
if (state.websocket.raw) {
|
|
145
|
-
const raw = state.websocket.raw;
|
|
146
|
-
if (typeof raw.isHibernatable === "boolean") {
|
|
147
|
-
return raw.isHibernatable;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return false;
|
|
151
143
|
}
|
|
152
144
|
};
|
|
153
145
|
var SSE_DRIVER = {
|
|
154
146
|
sendMessage: (_actor, _conn, state, message) => {
|
|
155
147
|
state.stream.writeSSE({
|
|
156
|
-
data:
|
|
148
|
+
data: _chunk3JYSUFETcjs.encodeDataToString.call(void 0, message.serialize(state.encoding))
|
|
157
149
|
});
|
|
158
150
|
},
|
|
159
151
|
disconnect: async (_actor, _conn, state, _reason) => {
|
|
@@ -164,9 +156,6 @@ var SSE_DRIVER = {
|
|
|
164
156
|
return 3 /* CLOSED */;
|
|
165
157
|
}
|
|
166
158
|
return 1 /* OPEN */;
|
|
167
|
-
},
|
|
168
|
-
isHibernatable() {
|
|
169
|
-
return false;
|
|
170
159
|
}
|
|
171
160
|
};
|
|
172
161
|
var HTTP_DRIVER = {
|
|
@@ -174,9 +163,6 @@ var HTTP_DRIVER = {
|
|
|
174
163
|
return 1 /* OPEN */;
|
|
175
164
|
},
|
|
176
165
|
disconnect: async () => {
|
|
177
|
-
},
|
|
178
|
-
isHibernatable() {
|
|
179
|
-
return false;
|
|
180
166
|
}
|
|
181
167
|
};
|
|
182
168
|
var CONN_DRIVERS = {
|
|
@@ -188,222 +174,9 @@ function getConnDriverKindFromState(state) {
|
|
|
188
174
|
if (0 /* WEBSOCKET */ in state) return 0 /* WEBSOCKET */;
|
|
189
175
|
else if (1 /* SSE */ in state) return 1 /* SSE */;
|
|
190
176
|
else if (2 /* HTTP */ in state) return 2 /* HTTP */;
|
|
191
|
-
else
|
|
177
|
+
else _chunkC56XVVV4cjs.assertUnreachable.call(void 0, state);
|
|
192
178
|
}
|
|
193
179
|
|
|
194
|
-
// src/actor/conn.ts
|
|
195
|
-
function generateConnId() {
|
|
196
|
-
return crypto.randomUUID();
|
|
197
|
-
}
|
|
198
|
-
function generateConnToken() {
|
|
199
|
-
return _chunkGXIO5YOTcjs.generateSecureToken.call(void 0, 32);
|
|
200
|
-
}
|
|
201
|
-
function generateConnRequestId() {
|
|
202
|
-
return crypto.randomUUID();
|
|
203
|
-
}
|
|
204
|
-
var Conn = (_class = class {
|
|
205
|
-
__init() {this.subscriptions = /* @__PURE__ */ new Set()}
|
|
206
|
-
// TODO: Remove this cyclical reference
|
|
207
|
-
#actor;
|
|
208
|
-
/**
|
|
209
|
-
* The proxied state that notifies of changes automatically.
|
|
210
|
-
*
|
|
211
|
-
* Any data that should be stored indefinitely should be held within this object.
|
|
212
|
-
*/
|
|
213
|
-
|
|
214
|
-
get __driverState() {
|
|
215
|
-
var _a;
|
|
216
|
-
return (_a = this.__socket) == null ? void 0 : _a.driverState;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Socket connected to this connection.
|
|
220
|
-
*
|
|
221
|
-
* If undefined, then nothing is connected to this.
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
get __status() {
|
|
225
|
-
if (this.__socket) {
|
|
226
|
-
return "connected";
|
|
227
|
-
} else {
|
|
228
|
-
return "reconnecting";
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
get params() {
|
|
232
|
-
return this.__persist.params;
|
|
233
|
-
}
|
|
234
|
-
get __stateEnabled() {
|
|
235
|
-
return this.#actor.connStateEnabled;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Gets the current state of the connection.
|
|
239
|
-
*
|
|
240
|
-
* Throws an error if the state is not enabled.
|
|
241
|
-
*/
|
|
242
|
-
get state() {
|
|
243
|
-
this.#validateStateEnabled();
|
|
244
|
-
if (!this.__persist.state) throw new Error("state should exists");
|
|
245
|
-
return this.__persist.state;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Sets the state of the connection.
|
|
249
|
-
*
|
|
250
|
-
* Throws an error if the state is not enabled.
|
|
251
|
-
*/
|
|
252
|
-
set state(value) {
|
|
253
|
-
this.#validateStateEnabled();
|
|
254
|
-
this.__persist.state = value;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Unique identifier for the connection.
|
|
258
|
-
*/
|
|
259
|
-
get id() {
|
|
260
|
-
return this.__persist.connId;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Token used to authenticate this request.
|
|
264
|
-
*/
|
|
265
|
-
get _token() {
|
|
266
|
-
return this.__persist.token;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Status of the connection.
|
|
270
|
-
*/
|
|
271
|
-
get status() {
|
|
272
|
-
return this.__status;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* @experimental
|
|
276
|
-
*
|
|
277
|
-
* If the underlying connection can hibernate.
|
|
278
|
-
*/
|
|
279
|
-
get isHibernatable() {
|
|
280
|
-
if (this.__driverState) {
|
|
281
|
-
const driverKind = getConnDriverKindFromState(this.__driverState);
|
|
282
|
-
const driver = CONN_DRIVERS[driverKind];
|
|
283
|
-
return driver.isHibernatable(
|
|
284
|
-
this.#actor,
|
|
285
|
-
this,
|
|
286
|
-
this.__driverState[driverKind]
|
|
287
|
-
);
|
|
288
|
-
} else {
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Timestamp of the last time the connection was seen, i.e. the last time the connection was active and checked for liveness.
|
|
294
|
-
*/
|
|
295
|
-
get lastSeen() {
|
|
296
|
-
return this.__persist.lastSeen;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Initializes a new instance of the Connection class.
|
|
300
|
-
*
|
|
301
|
-
* This should only be constructed by {@link Actor}.
|
|
302
|
-
*
|
|
303
|
-
* @protected
|
|
304
|
-
*/
|
|
305
|
-
constructor(actor, persist) {;_class.prototype.__init.call(this);
|
|
306
|
-
this.#actor = actor;
|
|
307
|
-
this.__persist = persist;
|
|
308
|
-
}
|
|
309
|
-
#validateStateEnabled() {
|
|
310
|
-
if (!this.__stateEnabled) {
|
|
311
|
-
throw new (0, _chunkKSRXX3Z4cjs.ConnStateNotEnabled)();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Sends a WebSocket message to the client.
|
|
316
|
-
*
|
|
317
|
-
* @param message - The message to send.
|
|
318
|
-
*
|
|
319
|
-
* @protected
|
|
320
|
-
*/
|
|
321
|
-
_sendMessage(message) {
|
|
322
|
-
if (this.__driverState) {
|
|
323
|
-
const driverKind = getConnDriverKindFromState(this.__driverState);
|
|
324
|
-
const driver = CONN_DRIVERS[driverKind];
|
|
325
|
-
if (driver.sendMessage) {
|
|
326
|
-
driver.sendMessage(
|
|
327
|
-
this.#actor,
|
|
328
|
-
this,
|
|
329
|
-
this.__driverState[driverKind],
|
|
330
|
-
message
|
|
331
|
-
);
|
|
332
|
-
} else {
|
|
333
|
-
this.#actor.rLog.debug({
|
|
334
|
-
msg: "conn driver does not support sending messages",
|
|
335
|
-
conn: this.id
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
} else {
|
|
339
|
-
this.#actor.rLog.warn({
|
|
340
|
-
msg: "missing connection driver state for send message",
|
|
341
|
-
conn: this.id
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Sends an event with arguments to the client.
|
|
347
|
-
*
|
|
348
|
-
* @param eventName - The name of the event.
|
|
349
|
-
* @param args - The arguments for the event.
|
|
350
|
-
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
351
|
-
*/
|
|
352
|
-
send(eventName, ...args) {
|
|
353
|
-
this.#actor.inspector.emitter.emit("eventFired", {
|
|
354
|
-
type: "event",
|
|
355
|
-
eventName,
|
|
356
|
-
args,
|
|
357
|
-
connId: this.id
|
|
358
|
-
});
|
|
359
|
-
this._sendMessage(
|
|
360
|
-
new (0, _chunkGXIO5YOTcjs.CachedSerializer)(
|
|
361
|
-
{
|
|
362
|
-
body: {
|
|
363
|
-
tag: "Event",
|
|
364
|
-
val: {
|
|
365
|
-
name: eventName,
|
|
366
|
-
args: _chunkYUBR6XCJcjs.bufferToArrayBuffer.call(void 0, cbor.encode(args))
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
_chunk5TRXLS6Xcjs.TO_CLIENT_VERSIONED
|
|
371
|
-
)
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Disconnects the client with an optional reason.
|
|
376
|
-
*
|
|
377
|
-
* @param reason - The reason for disconnection.
|
|
378
|
-
*/
|
|
379
|
-
async disconnect(reason) {
|
|
380
|
-
if (this.__socket && this.__driverState) {
|
|
381
|
-
const driverKind = getConnDriverKindFromState(this.__driverState);
|
|
382
|
-
const driver = CONN_DRIVERS[driverKind];
|
|
383
|
-
if (driver.disconnect) {
|
|
384
|
-
driver.disconnect(
|
|
385
|
-
this.#actor,
|
|
386
|
-
this,
|
|
387
|
-
this.__driverState[driverKind],
|
|
388
|
-
reason
|
|
389
|
-
);
|
|
390
|
-
} else {
|
|
391
|
-
this.#actor.rLog.debug({
|
|
392
|
-
msg: "no disconnect handler for conn driver",
|
|
393
|
-
conn: this.id
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
this.#actor.__connDisconnected(this, true, this.__socket.requestId);
|
|
397
|
-
} else {
|
|
398
|
-
this.#actor.rLog.warn({
|
|
399
|
-
msg: "missing connection driver state for disconnect",
|
|
400
|
-
conn: this.id
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
this.__socket = void 0;
|
|
404
|
-
}
|
|
405
|
-
}, _class);
|
|
406
|
-
|
|
407
180
|
// src/actor/instance.ts
|
|
408
181
|
|
|
409
182
|
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
|
|
@@ -434,7 +207,7 @@ function createActorInspectorRouter() {
|
|
|
434
207
|
"/state",
|
|
435
208
|
_standardvalidator.sValidator.call(void 0,
|
|
436
209
|
"json",
|
|
437
|
-
_v42.default.object({ patch:
|
|
210
|
+
_v42.default.object({ patch: _chunkSN4KWTRAcjs.PatchSchema }).or(_v42.default.object({ replace: _v42.default.any() }))
|
|
438
211
|
),
|
|
439
212
|
async (c) => {
|
|
440
213
|
if (!await c.var.inspector.accessors.isStateEnabled()) {
|
|
@@ -484,7 +257,7 @@ function createActorInspectorRouter() {
|
|
|
484
257
|
});
|
|
485
258
|
}
|
|
486
259
|
);
|
|
487
|
-
const { promise } =
|
|
260
|
+
const { promise } = _chunkC56XVVV4cjs.promiseWithResolvers.call(void 0, );
|
|
488
261
|
return promise;
|
|
489
262
|
},
|
|
490
263
|
async () => {
|
|
@@ -512,7 +285,7 @@ function createActorInspectorRouter() {
|
|
|
512
285
|
});
|
|
513
286
|
}
|
|
514
287
|
);
|
|
515
|
-
const { promise } =
|
|
288
|
+
const { promise } = _chunkC56XVVV4cjs.promiseWithResolvers.call(void 0, );
|
|
516
289
|
return promise;
|
|
517
290
|
},
|
|
518
291
|
async () => {
|
|
@@ -540,7 +313,7 @@ function createActorInspectorRouter() {
|
|
|
540
313
|
id: String(id++)
|
|
541
314
|
});
|
|
542
315
|
});
|
|
543
|
-
const { promise } =
|
|
316
|
+
const { promise } = _chunkC56XVVV4cjs.promiseWithResolvers.call(void 0, );
|
|
544
317
|
return promise;
|
|
545
318
|
},
|
|
546
319
|
async () => {
|
|
@@ -556,7 +329,7 @@ function createActorInspectorRouter() {
|
|
|
556
329
|
}
|
|
557
330
|
const db = await c.var.inspector.accessors.getDb();
|
|
558
331
|
const rows = await db.execute(`PRAGMA table_list`);
|
|
559
|
-
const tables =
|
|
332
|
+
const tables = _chunkSN4KWTRAcjs.TablesSchema.parse(rows).filter(
|
|
560
333
|
(table) => table.schema !== "temp" && !table.name.startsWith("sqlite_")
|
|
561
334
|
);
|
|
562
335
|
const tablesInfo = await Promise.all(
|
|
@@ -564,14 +337,14 @@ function createActorInspectorRouter() {
|
|
|
564
337
|
(table) => db.execute(`PRAGMA table_info(${table.name})`)
|
|
565
338
|
)
|
|
566
339
|
);
|
|
567
|
-
const columns = tablesInfo.map((def) =>
|
|
340
|
+
const columns = tablesInfo.map((def) => _chunkSN4KWTRAcjs.ColumnsSchema.parse(def));
|
|
568
341
|
const foreignKeysList = await Promise.all(
|
|
569
342
|
tables.map(
|
|
570
343
|
(table) => db.execute(`PRAGMA foreign_key_list(${table.name})`)
|
|
571
344
|
)
|
|
572
345
|
);
|
|
573
346
|
const foreignKeys = foreignKeysList.map(
|
|
574
|
-
(def) =>
|
|
347
|
+
(def) => _chunkSN4KWTRAcjs.ForeignKeysSchema.parse(def)
|
|
575
348
|
);
|
|
576
349
|
const countInfo = await Promise.all(
|
|
577
350
|
tables.map(
|
|
@@ -639,14 +412,14 @@ function createActorInspectorRouter() {
|
|
|
639
412
|
}
|
|
640
413
|
);
|
|
641
414
|
}
|
|
642
|
-
var ActorInspector = (
|
|
415
|
+
var ActorInspector = (_class = class {
|
|
643
416
|
|
|
644
|
-
|
|
417
|
+
__init() {this.emitter = _nanoevents.createNanoEvents.call(void 0, )}
|
|
645
418
|
#lastRealtimeEvents = [];
|
|
646
419
|
get lastRealtimeEvents() {
|
|
647
420
|
return this.#lastRealtimeEvents;
|
|
648
421
|
}
|
|
649
|
-
constructor(accessors) {;
|
|
422
|
+
constructor(accessors) {;_class.prototype.__init.call(this);
|
|
650
423
|
this.accessors = accessors();
|
|
651
424
|
this.emitter.on("eventFired", (event) => {
|
|
652
425
|
this.#lastRealtimeEvents.push({
|
|
@@ -659,7 +432,7 @@ var ActorInspector = (_class2 = class {
|
|
|
659
432
|
}
|
|
660
433
|
});
|
|
661
434
|
}
|
|
662
|
-
},
|
|
435
|
+
}, _class);
|
|
663
436
|
|
|
664
437
|
// src/actor/context.ts
|
|
665
438
|
var ActorContext = class {
|
|
@@ -883,8 +656,8 @@ var ActorInstance = class {
|
|
|
883
656
|
}
|
|
884
657
|
/** Raw state without the proxy wrapper */
|
|
885
658
|
#persistRaw;
|
|
886
|
-
#persistWriteQueue = new (0,
|
|
887
|
-
#alarmWriteQueue = new (0,
|
|
659
|
+
#persistWriteQueue = new (0, _chunkC56XVVV4cjs.SinglePromiseQueue)();
|
|
660
|
+
#alarmWriteQueue = new (0, _chunkC56XVVV4cjs.SinglePromiseQueue)();
|
|
888
661
|
#lastSaveTime = 0;
|
|
889
662
|
#pendingSaveTimeout;
|
|
890
663
|
#vars;
|
|
@@ -930,21 +703,18 @@ var ActorInstance = class {
|
|
|
930
703
|
},
|
|
931
704
|
getConnections: async () => {
|
|
932
705
|
return Array.from(this.#connections.entries()).map(
|
|
933
|
-
([id, conn]) => {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
driver: conn.__driverState ? getConnDriverKindFromState(conn.__driverState) : void 0
|
|
946
|
-
};
|
|
947
|
-
}
|
|
706
|
+
([id, conn]) => ({
|
|
707
|
+
id,
|
|
708
|
+
params: conn.params,
|
|
709
|
+
state: conn.__stateEnabled ? conn.state : void 0,
|
|
710
|
+
status: conn.status,
|
|
711
|
+
subscriptions: conn.subscriptions.size,
|
|
712
|
+
lastSeen: conn.lastSeen,
|
|
713
|
+
stateEnabled: conn.__stateEnabled,
|
|
714
|
+
isHibernatable: conn.isHibernatable,
|
|
715
|
+
hibernatableRequestId: conn.__persist.hibernatableRequestId ? _chunkC56XVVV4cjs.idToStr.call(void 0, conn.__persist.hibernatableRequestId) : void 0,
|
|
716
|
+
driver: conn.__driverState ? getConnDriverKindFromState(conn.__driverState) : void 0
|
|
717
|
+
})
|
|
948
718
|
);
|
|
949
719
|
},
|
|
950
720
|
setState: async (state) => {
|
|
@@ -957,6 +727,7 @@ var ActorInstance = class {
|
|
|
957
727
|
const conn = await this.createConn(
|
|
958
728
|
{
|
|
959
729
|
requestId,
|
|
730
|
+
hibernatable: false,
|
|
960
731
|
driverState: { [2 /* HTTP */]: {} }
|
|
961
732
|
},
|
|
962
733
|
void 0,
|
|
@@ -964,7 +735,7 @@ var ActorInstance = class {
|
|
|
964
735
|
);
|
|
965
736
|
try {
|
|
966
737
|
return await this.executeAction(
|
|
967
|
-
new (0,
|
|
738
|
+
new (0, _chunkJMLTKMJ7cjs.ActionContext)(this.actorContext, conn),
|
|
968
739
|
name,
|
|
969
740
|
params || []
|
|
970
741
|
);
|
|
@@ -1006,15 +777,15 @@ var ActorInstance = class {
|
|
|
1006
777
|
};
|
|
1007
778
|
const extraLogParams = (_a = actorDriver.getExtraActorLogParams) == null ? void 0 : _a.call(actorDriver);
|
|
1008
779
|
if (extraLogParams) Object.assign(logParams, extraLogParams);
|
|
1009
|
-
this.#log =
|
|
780
|
+
this.#log = _chunkC56XVVV4cjs.getBaseLogger.call(void 0, ).child(
|
|
1010
781
|
Object.assign(
|
|
1011
|
-
|
|
782
|
+
_chunkC56XVVV4cjs.getIncludeTarget.call(void 0, ) ? { target: "actor" } : {},
|
|
1012
783
|
logParams
|
|
1013
784
|
)
|
|
1014
785
|
);
|
|
1015
|
-
this.#rLog =
|
|
786
|
+
this.#rLog = _chunkC56XVVV4cjs.getBaseLogger.call(void 0, ).child(
|
|
1016
787
|
Object.assign(
|
|
1017
|
-
|
|
788
|
+
_chunkC56XVVV4cjs.getIncludeTarget.call(void 0, ) ? { target: "actor-runtime" } : {},
|
|
1018
789
|
logParams
|
|
1019
790
|
)
|
|
1020
791
|
);
|
|
@@ -1034,7 +805,7 @@ var ActorInstance = class {
|
|
|
1034
805
|
this.#actorDriver.getContext(this.#actorId)
|
|
1035
806
|
);
|
|
1036
807
|
if (dataOrPromise instanceof Promise) {
|
|
1037
|
-
vars = await
|
|
808
|
+
vars = await _chunk3JYSUFETcjs.deadline.call(void 0,
|
|
1038
809
|
dataOrPromise,
|
|
1039
810
|
this.#config.options.createVarsTimeout
|
|
1040
811
|
);
|
|
@@ -1167,12 +938,12 @@ var ActorInstance = class {
|
|
|
1167
938
|
`Alarm function lookup for ${event.kind.generic.actionName} returned ${typeof fn}`
|
|
1168
939
|
);
|
|
1169
940
|
try {
|
|
1170
|
-
const args = event.kind.generic.args ?
|
|
941
|
+
const args = event.kind.generic.args ? cbor.decode(new Uint8Array(event.kind.generic.args)) : [];
|
|
1171
942
|
await fn.call(void 0, this.actorContext, ...args);
|
|
1172
943
|
} catch (error) {
|
|
1173
944
|
this.actorContext.log.error({
|
|
1174
945
|
msg: "error while running event",
|
|
1175
|
-
error:
|
|
946
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error),
|
|
1176
947
|
event: event.eventId,
|
|
1177
948
|
timestamp: event.timestamp,
|
|
1178
949
|
action: event.kind.generic.actionName
|
|
@@ -1181,7 +952,7 @@ var ActorInstance = class {
|
|
|
1181
952
|
} catch (error) {
|
|
1182
953
|
this.actorContext.log.error({
|
|
1183
954
|
msg: "internal error while running event",
|
|
1184
|
-
error:
|
|
955
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error),
|
|
1185
956
|
...event
|
|
1186
957
|
});
|
|
1187
958
|
}
|
|
@@ -1194,7 +965,7 @@ var ActorInstance = class {
|
|
|
1194
965
|
kind: {
|
|
1195
966
|
generic: {
|
|
1196
967
|
actionName: action,
|
|
1197
|
-
args:
|
|
968
|
+
args: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor.encode(args))
|
|
1198
969
|
}
|
|
1199
970
|
}
|
|
1200
971
|
});
|
|
@@ -1250,7 +1021,7 @@ var ActorInstance = class {
|
|
|
1250
1021
|
);
|
|
1251
1022
|
await this.#actorDriver.writePersistedData(
|
|
1252
1023
|
this.#actorId,
|
|
1253
|
-
|
|
1024
|
+
_chunkJMLTKMJ7cjs.PERSISTED_ACTOR_VERSIONED.serializeWithEmbeddedVersion(
|
|
1254
1025
|
bareData
|
|
1255
1026
|
)
|
|
1256
1027
|
);
|
|
@@ -1260,6 +1031,10 @@ var ActorInstance = class {
|
|
|
1260
1031
|
}
|
|
1261
1032
|
(_a = this.#onPersistSavedPromise) == null ? void 0 : _a.resolve();
|
|
1262
1033
|
} catch (error) {
|
|
1034
|
+
this.#rLog.error({
|
|
1035
|
+
msg: "error saving persist",
|
|
1036
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1037
|
+
});
|
|
1263
1038
|
(_b = this.#onPersistSavedPromise) == null ? void 0 : _b.reject(error);
|
|
1264
1039
|
throw error;
|
|
1265
1040
|
}
|
|
@@ -1276,7 +1051,7 @@ var ActorInstance = class {
|
|
|
1276
1051
|
this.#persistRaw = target;
|
|
1277
1052
|
if (target === null || typeof target !== "object") {
|
|
1278
1053
|
let invalidPath = "";
|
|
1279
|
-
if (!
|
|
1054
|
+
if (!_chunkC56XVVV4cjs.isCborSerializable.call(void 0,
|
|
1280
1055
|
target,
|
|
1281
1056
|
(path) => {
|
|
1282
1057
|
invalidPath = path;
|
|
@@ -1294,27 +1069,34 @@ var ActorInstance = class {
|
|
|
1294
1069
|
target,
|
|
1295
1070
|
// biome-ignore lint/suspicious/noExplicitAny: Don't know types in proxy
|
|
1296
1071
|
(path, value, _previousValue, _applyData) => {
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1072
|
+
const actorStatePath = _chunk3JYSUFETcjs.isStatePath.call(void 0, path);
|
|
1073
|
+
const connStatePath = _chunk3JYSUFETcjs.isConnStatePath.call(void 0, path);
|
|
1074
|
+
if (actorStatePath || connStatePath) {
|
|
1075
|
+
let invalidPath = "";
|
|
1076
|
+
if (!_chunkC56XVVV4cjs.isCborSerializable.call(void 0,
|
|
1077
|
+
value,
|
|
1078
|
+
(invalidPathPart) => {
|
|
1079
|
+
invalidPath = invalidPathPart;
|
|
1080
|
+
},
|
|
1081
|
+
""
|
|
1082
|
+
)) {
|
|
1083
|
+
throw new (0, _chunkKSRXX3Z4cjs.InvalidStateType)({
|
|
1084
|
+
path: path + (invalidPath ? `.${invalidPath}` : "")
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1311
1087
|
}
|
|
1088
|
+
this.#rLog.debug({
|
|
1089
|
+
msg: "onChange triggered, setting persistChanged=true",
|
|
1090
|
+
path
|
|
1091
|
+
});
|
|
1312
1092
|
this.#persistChanged = true;
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1093
|
+
if (actorStatePath) {
|
|
1094
|
+
this.inspector.emitter.emit(
|
|
1095
|
+
"stateUpdated",
|
|
1096
|
+
this.#persist.state
|
|
1097
|
+
);
|
|
1098
|
+
}
|
|
1099
|
+
if (actorStatePath && this.#config.onStateChange && this.#ready && !this.#isInOnStateChange) {
|
|
1318
1100
|
try {
|
|
1319
1101
|
this.#isInOnStateChange = true;
|
|
1320
1102
|
this.#config.onStateChange(
|
|
@@ -1324,7 +1106,7 @@ var ActorInstance = class {
|
|
|
1324
1106
|
} catch (error) {
|
|
1325
1107
|
this.#rLog.error({
|
|
1326
1108
|
msg: "error in `_onStateChange`",
|
|
1327
|
-
error:
|
|
1109
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1328
1110
|
});
|
|
1329
1111
|
} finally {
|
|
1330
1112
|
this.#isInOnStateChange = false;
|
|
@@ -1342,14 +1124,15 @@ var ActorInstance = class {
|
|
|
1342
1124
|
persistDataBuffer !== void 0,
|
|
1343
1125
|
"persist data has not been set, it should be set when initialized"
|
|
1344
1126
|
);
|
|
1345
|
-
const bareData =
|
|
1127
|
+
const bareData = _chunkJMLTKMJ7cjs.PERSISTED_ACTOR_VERSIONED.deserializeWithEmbeddedVersion(
|
|
1346
1128
|
persistDataBuffer
|
|
1347
1129
|
);
|
|
1348
1130
|
const persistData = this.#convertFromBarePersisted(bareData);
|
|
1349
1131
|
if (persistData.hasInitiated) {
|
|
1350
1132
|
this.#rLog.info({
|
|
1351
1133
|
msg: "actor restoring",
|
|
1352
|
-
connections: persistData.connections.length
|
|
1134
|
+
connections: persistData.connections.length,
|
|
1135
|
+
hibernatableWebSockets: persistData.hibernatableWebSocket.length
|
|
1353
1136
|
});
|
|
1354
1137
|
this.#setPersist(persistData);
|
|
1355
1138
|
for (const connPersist of this.#persist.connections) {
|
|
@@ -1386,7 +1169,7 @@ var ActorInstance = class {
|
|
|
1386
1169
|
const bareData2 = this.#convertToBarePersisted(persistData);
|
|
1387
1170
|
await this.#actorDriver.writePersistedData(
|
|
1388
1171
|
this.#actorId,
|
|
1389
|
-
|
|
1172
|
+
_chunkJMLTKMJ7cjs.PERSISTED_ACTOR_VERSIONED.serializeWithEmbeddedVersion(
|
|
1390
1173
|
bareData2
|
|
1391
1174
|
)
|
|
1392
1175
|
);
|
|
@@ -1462,14 +1245,14 @@ var ActorInstance = class {
|
|
|
1462
1245
|
result.catch((error) => {
|
|
1463
1246
|
this.#rLog.error({
|
|
1464
1247
|
msg: "error in `onDisconnect`",
|
|
1465
|
-
error:
|
|
1248
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1466
1249
|
});
|
|
1467
1250
|
});
|
|
1468
1251
|
}
|
|
1469
1252
|
} catch (error) {
|
|
1470
1253
|
this.#rLog.error({
|
|
1471
1254
|
msg: "error in `onDisconnect`",
|
|
1472
|
-
error:
|
|
1255
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1473
1256
|
});
|
|
1474
1257
|
}
|
|
1475
1258
|
}
|
|
@@ -1480,6 +1263,55 @@ var ActorInstance = class {
|
|
|
1480
1263
|
*/
|
|
1481
1264
|
async createConn(socket, params, request, connectionId, connectionToken) {
|
|
1482
1265
|
this.#assertReady();
|
|
1266
|
+
if (socket.requestIdBuf && socket.hibernatable) {
|
|
1267
|
+
this.rLog.debug({
|
|
1268
|
+
msg: "checking for hibernatable websocket connection",
|
|
1269
|
+
requestId: socket.requestId,
|
|
1270
|
+
existingConnectionsCount: this.#connections.size
|
|
1271
|
+
});
|
|
1272
|
+
const existingConn = Array.from(this.#connections.values()).find(
|
|
1273
|
+
(conn2) => conn2.__persist.hibernatableRequestId && _chunkC56XVVV4cjs.arrayBuffersEqual.call(void 0,
|
|
1274
|
+
conn2.__persist.hibernatableRequestId,
|
|
1275
|
+
socket.requestIdBuf
|
|
1276
|
+
)
|
|
1277
|
+
);
|
|
1278
|
+
if (existingConn) {
|
|
1279
|
+
this.rLog.debug({
|
|
1280
|
+
msg: "reconnecting hibernatable websocket connection",
|
|
1281
|
+
connectionId: existingConn.id,
|
|
1282
|
+
requestId: socket.requestId
|
|
1283
|
+
});
|
|
1284
|
+
if (existingConn.__driverState) {
|
|
1285
|
+
this.#rLog.warn({
|
|
1286
|
+
msg: "found existing driver state on hibernatable websocket",
|
|
1287
|
+
connectionId: existingConn.id,
|
|
1288
|
+
requestId: socket.requestId
|
|
1289
|
+
});
|
|
1290
|
+
const driverKind = getConnDriverKindFromState(
|
|
1291
|
+
existingConn.__driverState
|
|
1292
|
+
);
|
|
1293
|
+
const driver = CONN_DRIVERS[driverKind];
|
|
1294
|
+
if (driver.disconnect) {
|
|
1295
|
+
driver.disconnect(
|
|
1296
|
+
this,
|
|
1297
|
+
existingConn,
|
|
1298
|
+
existingConn.__driverState[driverKind],
|
|
1299
|
+
"Reconnecting hibernatable websocket with new driver state"
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
existingConn.__socket = socket;
|
|
1304
|
+
existingConn.__persist.lastSeen = Date.now();
|
|
1305
|
+
this.#resetSleepTimer();
|
|
1306
|
+
this.inspector.emitter.emit("connectionUpdated");
|
|
1307
|
+
return existingConn;
|
|
1308
|
+
} else {
|
|
1309
|
+
this.rLog.debug({
|
|
1310
|
+
msg: "no existing hibernatable connection found, creating new connection",
|
|
1311
|
+
requestId: socket.requestId
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1483
1315
|
if (connectionId && connectionToken) {
|
|
1484
1316
|
this.rLog.debug({
|
|
1485
1317
|
msg: "checking for existing connection",
|
|
@@ -1510,7 +1342,7 @@ var ActorInstance = class {
|
|
|
1510
1342
|
this.#resetSleepTimer();
|
|
1511
1343
|
this.inspector.emitter.emit("connectionUpdated");
|
|
1512
1344
|
existingConn._sendMessage(
|
|
1513
|
-
new (0,
|
|
1345
|
+
new (0, _chunk3JYSUFETcjs.CachedSerializer)(
|
|
1514
1346
|
{
|
|
1515
1347
|
body: {
|
|
1516
1348
|
tag: "Init",
|
|
@@ -1521,15 +1353,16 @@ var ActorInstance = class {
|
|
|
1521
1353
|
}
|
|
1522
1354
|
}
|
|
1523
1355
|
},
|
|
1524
|
-
|
|
1356
|
+
_chunkJMLTKMJ7cjs.TO_CLIENT_VERSIONED
|
|
1525
1357
|
)
|
|
1526
1358
|
);
|
|
1527
1359
|
return existingConn;
|
|
1360
|
+
} else {
|
|
1361
|
+
this.rLog.debug({
|
|
1362
|
+
msg: "connection not found or token mismatch, creating new connection",
|
|
1363
|
+
connectionId
|
|
1364
|
+
});
|
|
1528
1365
|
}
|
|
1529
|
-
this.rLog.debug({
|
|
1530
|
-
msg: "connection not found or token mismatch, creating new connection",
|
|
1531
|
-
connectionId
|
|
1532
|
-
});
|
|
1533
1366
|
}
|
|
1534
1367
|
const newConnId = generateConnId();
|
|
1535
1368
|
const newConnToken = generateConnToken();
|
|
@@ -1555,7 +1388,7 @@ var ActorInstance = class {
|
|
|
1555
1388
|
params
|
|
1556
1389
|
);
|
|
1557
1390
|
if (dataOrPromise instanceof Promise) {
|
|
1558
|
-
connState = await
|
|
1391
|
+
connState = await _chunk3JYSUFETcjs.deadline.call(void 0,
|
|
1559
1392
|
dataOrPromise,
|
|
1560
1393
|
this.#config.options.createConnStateTimeout
|
|
1561
1394
|
);
|
|
@@ -1578,6 +1411,14 @@ var ActorInstance = class {
|
|
|
1578
1411
|
lastSeen: Date.now(),
|
|
1579
1412
|
subscriptions: []
|
|
1580
1413
|
};
|
|
1414
|
+
if (socket.requestIdBuf) {
|
|
1415
|
+
const isHibernatable = this.#persist.hibernatableWebSocket.findIndex(
|
|
1416
|
+
(ws) => _chunkC56XVVV4cjs.arrayBuffersEqual.call(void 0, ws.requestId, socket.requestIdBuf)
|
|
1417
|
+
) !== -1;
|
|
1418
|
+
if (isHibernatable) {
|
|
1419
|
+
persist.hibernatableRequestId = socket.requestIdBuf;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1581
1422
|
const conn = new Conn(this, persist);
|
|
1582
1423
|
conn.__socket = socket;
|
|
1583
1424
|
this.#connections.set(conn.id, conn);
|
|
@@ -1588,7 +1429,7 @@ var ActorInstance = class {
|
|
|
1588
1429
|
try {
|
|
1589
1430
|
const result = this.#config.onConnect(this.actorContext, conn);
|
|
1590
1431
|
if (result instanceof Promise) {
|
|
1591
|
-
|
|
1432
|
+
_chunk3JYSUFETcjs.deadline.call(void 0,
|
|
1592
1433
|
result,
|
|
1593
1434
|
this.#config.options.onConnectTimeout
|
|
1594
1435
|
).catch((error) => {
|
|
@@ -1602,14 +1443,14 @@ var ActorInstance = class {
|
|
|
1602
1443
|
} catch (error) {
|
|
1603
1444
|
this.#rLog.error({
|
|
1604
1445
|
msg: "error in `onConnect`",
|
|
1605
|
-
error:
|
|
1446
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1606
1447
|
});
|
|
1607
1448
|
conn == null ? void 0 : conn.disconnect("`onConnect` failed");
|
|
1608
1449
|
}
|
|
1609
1450
|
}
|
|
1610
1451
|
this.inspector.emitter.emit("connectionUpdated");
|
|
1611
1452
|
conn._sendMessage(
|
|
1612
|
-
new (0,
|
|
1453
|
+
new (0, _chunk3JYSUFETcjs.CachedSerializer)(
|
|
1613
1454
|
{
|
|
1614
1455
|
body: {
|
|
1615
1456
|
tag: "Init",
|
|
@@ -1620,14 +1461,14 @@ var ActorInstance = class {
|
|
|
1620
1461
|
}
|
|
1621
1462
|
}
|
|
1622
1463
|
},
|
|
1623
|
-
|
|
1464
|
+
_chunkJMLTKMJ7cjs.TO_CLIENT_VERSIONED
|
|
1624
1465
|
)
|
|
1625
1466
|
);
|
|
1626
1467
|
return conn;
|
|
1627
1468
|
}
|
|
1628
1469
|
// MARK: Messages
|
|
1629
1470
|
async processMessage(message, conn) {
|
|
1630
|
-
await
|
|
1471
|
+
await _chunkJMLTKMJ7cjs.processMessage.call(void 0, message, this, conn, {
|
|
1631
1472
|
onExecuteAction: async (ctx, name, args) => {
|
|
1632
1473
|
this.inspector.emitter.emit("eventFired", {
|
|
1633
1474
|
type: "action",
|
|
@@ -1814,7 +1655,7 @@ var ActorInstance = class {
|
|
|
1814
1655
|
msg: "awaiting async action",
|
|
1815
1656
|
actionName
|
|
1816
1657
|
});
|
|
1817
|
-
output = await
|
|
1658
|
+
output = await _chunk3JYSUFETcjs.deadline.call(void 0,
|
|
1818
1659
|
outputOrPromise,
|
|
1819
1660
|
this.#config.options.actionTimeout
|
|
1820
1661
|
);
|
|
@@ -1849,7 +1690,7 @@ var ActorInstance = class {
|
|
|
1849
1690
|
} catch (error) {
|
|
1850
1691
|
this.#rLog.error({
|
|
1851
1692
|
msg: "error in `onBeforeActionResponse`",
|
|
1852
|
-
error:
|
|
1693
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1853
1694
|
});
|
|
1854
1695
|
}
|
|
1855
1696
|
}
|
|
@@ -1861,13 +1702,13 @@ var ActorInstance = class {
|
|
|
1861
1702
|
});
|
|
1862
1703
|
return output;
|
|
1863
1704
|
} catch (error) {
|
|
1864
|
-
if (error instanceof
|
|
1705
|
+
if (error instanceof _chunk3JYSUFETcjs.DeadlineError) {
|
|
1865
1706
|
throw new (0, _chunkKSRXX3Z4cjs.ActionTimedOut)();
|
|
1866
1707
|
}
|
|
1867
1708
|
this.#rLog.error({
|
|
1868
1709
|
msg: "action error",
|
|
1869
1710
|
actionName,
|
|
1870
|
-
error:
|
|
1711
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1871
1712
|
});
|
|
1872
1713
|
throw error;
|
|
1873
1714
|
} finally {
|
|
@@ -1901,7 +1742,7 @@ var ActorInstance = class {
|
|
|
1901
1742
|
} catch (error) {
|
|
1902
1743
|
this.#rLog.error({
|
|
1903
1744
|
msg: "onFetch error",
|
|
1904
|
-
error:
|
|
1745
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
1905
1746
|
});
|
|
1906
1747
|
throw error;
|
|
1907
1748
|
} finally {
|
|
@@ -1927,7 +1768,7 @@ var ActorInstance = class {
|
|
|
1927
1768
|
if (rivetRequestId) {
|
|
1928
1769
|
const rivetRequestIdLocal = rivetRequestId;
|
|
1929
1770
|
persistedHibernatableWebSocket = this.#persist.hibernatableWebSocket.find(
|
|
1930
|
-
(ws) =>
|
|
1771
|
+
(ws) => _chunkC56XVVV4cjs.arrayBuffersEqual.call(void 0,
|
|
1931
1772
|
ws.requestId,
|
|
1932
1773
|
rivetRequestIdLocal
|
|
1933
1774
|
)
|
|
@@ -1963,7 +1804,7 @@ var ActorInstance = class {
|
|
|
1963
1804
|
if (rivetRequestId) {
|
|
1964
1805
|
const rivetRequestIdLocal = rivetRequestId;
|
|
1965
1806
|
const wsIndex = this.#persist.hibernatableWebSocket.findIndex(
|
|
1966
|
-
(ws) =>
|
|
1807
|
+
(ws) => _chunkC56XVVV4cjs.arrayBuffersEqual.call(void 0,
|
|
1967
1808
|
ws.requestId,
|
|
1968
1809
|
rivetRequestIdLocal
|
|
1969
1810
|
)
|
|
@@ -2016,7 +1857,7 @@ var ActorInstance = class {
|
|
|
2016
1857
|
} catch (error) {
|
|
2017
1858
|
this.#rLog.error({
|
|
2018
1859
|
msg: "onWebSocket error",
|
|
2019
|
-
error:
|
|
1860
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
2020
1861
|
});
|
|
2021
1862
|
throw error;
|
|
2022
1863
|
} finally {
|
|
@@ -2111,17 +1952,17 @@ var ActorInstance = class {
|
|
|
2111
1952
|
});
|
|
2112
1953
|
const subscriptions = this.#subscriptionIndex.get(name);
|
|
2113
1954
|
if (!subscriptions) return;
|
|
2114
|
-
const toClientSerializer = new (0,
|
|
1955
|
+
const toClientSerializer = new (0, _chunk3JYSUFETcjs.CachedSerializer)(
|
|
2115
1956
|
{
|
|
2116
1957
|
body: {
|
|
2117
1958
|
tag: "Event",
|
|
2118
1959
|
val: {
|
|
2119
1960
|
name,
|
|
2120
|
-
args:
|
|
1961
|
+
args: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor.encode(args))
|
|
2121
1962
|
}
|
|
2122
1963
|
}
|
|
2123
1964
|
},
|
|
2124
|
-
|
|
1965
|
+
_chunkJMLTKMJ7cjs.TO_CLIENT_VERSIONED
|
|
2125
1966
|
);
|
|
2126
1967
|
for (const connection of subscriptions) {
|
|
2127
1968
|
connection._sendMessage(toClientSerializer);
|
|
@@ -2142,7 +1983,7 @@ var ActorInstance = class {
|
|
|
2142
1983
|
}).catch((error) => {
|
|
2143
1984
|
this.#rLog.error({
|
|
2144
1985
|
msg: "wait until promise failed",
|
|
2145
|
-
error:
|
|
1986
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
2146
1987
|
});
|
|
2147
1988
|
});
|
|
2148
1989
|
this.#backgroundPromises.push(nonfailablePromise);
|
|
@@ -2157,12 +1998,18 @@ var ActorInstance = class {
|
|
|
2157
1998
|
*/
|
|
2158
1999
|
async saveState(opts) {
|
|
2159
2000
|
this.#assertReady(opts.allowStoppingState);
|
|
2001
|
+
this.#rLog.debug({
|
|
2002
|
+
msg: "saveState called",
|
|
2003
|
+
persistChanged: this.#persistChanged,
|
|
2004
|
+
allowStoppingState: opts.allowStoppingState,
|
|
2005
|
+
immediate: opts.immediate
|
|
2006
|
+
});
|
|
2160
2007
|
if (this.#persistChanged) {
|
|
2161
2008
|
if (opts.immediate) {
|
|
2162
2009
|
await this.#savePersistInner();
|
|
2163
2010
|
} else {
|
|
2164
2011
|
if (!this.#onPersistSavedPromise) {
|
|
2165
|
-
this.#onPersistSavedPromise =
|
|
2012
|
+
this.#onPersistSavedPromise = _chunkC56XVVV4cjs.promiseWithResolvers.call(void 0, );
|
|
2166
2013
|
}
|
|
2167
2014
|
this.#savePersistThrottled();
|
|
2168
2015
|
await this.#onPersistSavedPromise.promise;
|
|
@@ -2185,7 +2032,7 @@ var ActorInstance = class {
|
|
|
2185
2032
|
this.#activeHonoHttpRequests = 0;
|
|
2186
2033
|
this.#rLog.warn({
|
|
2187
2034
|
msg: "active hono requests went below 0, this is a RivetKit bug",
|
|
2188
|
-
...
|
|
2035
|
+
..._chunkC56XVVV4cjs.EXTRA_ERROR_LOG
|
|
2189
2036
|
});
|
|
2190
2037
|
}
|
|
2191
2038
|
this.#resetSleepTimer();
|
|
@@ -2203,6 +2050,7 @@ var ActorInstance = class {
|
|
|
2203
2050
|
**/
|
|
2204
2051
|
#resetSleepTimer() {
|
|
2205
2052
|
if (this.#config.options.noSleep || !this.#sleepingSupported) return;
|
|
2053
|
+
if (this.#stopCalled) return;
|
|
2206
2054
|
const canSleep = this.#canSleep();
|
|
2207
2055
|
this.#rLog.debug({
|
|
2208
2056
|
msg: "resetting sleep timer",
|
|
@@ -2244,8 +2092,16 @@ var ActorInstance = class {
|
|
|
2244
2092
|
**/
|
|
2245
2093
|
_startSleep() {
|
|
2246
2094
|
var _a;
|
|
2095
|
+
if (this.#stopCalled) {
|
|
2096
|
+
this.#rLog.debug({
|
|
2097
|
+
msg: "cannot call _startSleep if actor already stopping"
|
|
2098
|
+
});
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2247
2101
|
if (this.#sleepCalled) {
|
|
2248
|
-
this.#rLog.warn({
|
|
2102
|
+
this.#rLog.warn({
|
|
2103
|
+
msg: "cannot call _startSleep twice, actor already sleeping"
|
|
2104
|
+
});
|
|
2249
2105
|
return;
|
|
2250
2106
|
}
|
|
2251
2107
|
this.#sleepCalled = true;
|
|
@@ -2287,29 +2143,34 @@ var ActorInstance = class {
|
|
|
2287
2143
|
this.#rLog.debug({ msg: "calling onStop" });
|
|
2288
2144
|
const result = this.#config.onStop(this.actorContext);
|
|
2289
2145
|
if (result instanceof Promise) {
|
|
2290
|
-
await
|
|
2146
|
+
await _chunk3JYSUFETcjs.deadline.call(void 0, result, this.#config.options.onStopTimeout);
|
|
2291
2147
|
}
|
|
2292
2148
|
this.#rLog.debug({ msg: "onStop completed" });
|
|
2293
2149
|
} catch (error) {
|
|
2294
|
-
if (error instanceof
|
|
2150
|
+
if (error instanceof _chunk3JYSUFETcjs.DeadlineError) {
|
|
2295
2151
|
this.#rLog.error({ msg: "onStop timed out" });
|
|
2296
2152
|
} else {
|
|
2297
2153
|
this.#rLog.error({
|
|
2298
2154
|
msg: "error in onStop",
|
|
2299
|
-
error:
|
|
2155
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
2300
2156
|
});
|
|
2301
2157
|
}
|
|
2302
2158
|
}
|
|
2303
2159
|
}
|
|
2304
2160
|
const promises = [];
|
|
2305
2161
|
for (const connection of this.#connections.values()) {
|
|
2306
|
-
|
|
2162
|
+
if (!connection.isHibernatable) {
|
|
2163
|
+
this.#rLog.debug({
|
|
2164
|
+
msg: "disconnecting non-hibernatable connection on actor stop",
|
|
2165
|
+
connId: connection.id
|
|
2166
|
+
});
|
|
2167
|
+
promises.push(connection.disconnect());
|
|
2168
|
+
}
|
|
2307
2169
|
}
|
|
2308
2170
|
await this.#waitBackgroundPromises(
|
|
2309
2171
|
this.#config.options.waitUntilTimeout
|
|
2310
2172
|
);
|
|
2311
2173
|
if (this.#pendingSaveTimeout) clearTimeout(this.#pendingSaveTimeout);
|
|
2312
|
-
if (this.#sleepTimeout) clearTimeout(this.#sleepTimeout);
|
|
2313
2174
|
if (this.#checkConnLivenessInterval)
|
|
2314
2175
|
clearInterval(this.#checkConnLivenessInterval);
|
|
2315
2176
|
await this.saveState({ immediate: true, allowStoppingState: true });
|
|
@@ -2359,18 +2220,19 @@ var ActorInstance = class {
|
|
|
2359
2220
|
// MARK: BARE Conversion Helpers
|
|
2360
2221
|
#convertToBarePersisted(persist) {
|
|
2361
2222
|
return {
|
|
2362
|
-
input: persist.input !== void 0 ?
|
|
2223
|
+
input: persist.input !== void 0 ? _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor.encode(persist.input)) : null,
|
|
2363
2224
|
hasInitialized: persist.hasInitiated,
|
|
2364
|
-
state:
|
|
2225
|
+
state: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor.encode(persist.state)),
|
|
2365
2226
|
connections: persist.connections.map((conn) => ({
|
|
2366
2227
|
id: conn.connId,
|
|
2367
2228
|
token: conn.token,
|
|
2368
|
-
parameters:
|
|
2369
|
-
state:
|
|
2229
|
+
parameters: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor.encode(conn.params || {})),
|
|
2230
|
+
state: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor.encode(conn.state || {})),
|
|
2370
2231
|
subscriptions: conn.subscriptions.map((sub) => ({
|
|
2371
2232
|
eventName: sub.eventName
|
|
2372
2233
|
})),
|
|
2373
|
-
lastSeen: BigInt(conn.lastSeen)
|
|
2234
|
+
lastSeen: BigInt(conn.lastSeen),
|
|
2235
|
+
hibernatableRequestId: _nullishCoalesce(conn.hibernatableRequestId, () => ( null))
|
|
2374
2236
|
})),
|
|
2375
2237
|
scheduledEvents: persist.scheduledEvents.map((event) => ({
|
|
2376
2238
|
eventId: event.eventId,
|
|
@@ -2392,18 +2254,19 @@ var ActorInstance = class {
|
|
|
2392
2254
|
}
|
|
2393
2255
|
#convertFromBarePersisted(bareData) {
|
|
2394
2256
|
return {
|
|
2395
|
-
input: bareData.input ?
|
|
2257
|
+
input: bareData.input ? cbor.decode(new Uint8Array(bareData.input)) : void 0,
|
|
2396
2258
|
hasInitiated: bareData.hasInitialized,
|
|
2397
|
-
state:
|
|
2259
|
+
state: cbor.decode(new Uint8Array(bareData.state)),
|
|
2398
2260
|
connections: bareData.connections.map((conn) => ({
|
|
2399
2261
|
connId: conn.id,
|
|
2400
2262
|
token: conn.token,
|
|
2401
|
-
params:
|
|
2402
|
-
state:
|
|
2263
|
+
params: cbor.decode(new Uint8Array(conn.parameters)),
|
|
2264
|
+
state: cbor.decode(new Uint8Array(conn.state)),
|
|
2403
2265
|
subscriptions: conn.subscriptions.map((sub) => ({
|
|
2404
2266
|
eventName: sub.eventName
|
|
2405
2267
|
})),
|
|
2406
|
-
lastSeen: Number(conn.lastSeen)
|
|
2268
|
+
lastSeen: Number(conn.lastSeen),
|
|
2269
|
+
hibernatableRequestId: _nullishCoalesce(conn.hibernatableRequestId, () => ( void 0))
|
|
2407
2270
|
})),
|
|
2408
2271
|
scheduledEvents: bareData.scheduledEvents.map((event) => ({
|
|
2409
2272
|
eventId: event.eventId,
|
|
@@ -2424,6 +2287,217 @@ var ActorInstance = class {
|
|
|
2424
2287
|
}
|
|
2425
2288
|
};
|
|
2426
2289
|
|
|
2290
|
+
// src/actor/conn.ts
|
|
2291
|
+
function generateConnId() {
|
|
2292
|
+
return crypto.randomUUID();
|
|
2293
|
+
}
|
|
2294
|
+
function generateConnToken() {
|
|
2295
|
+
return _chunk3JYSUFETcjs.generateSecureToken.call(void 0, 32);
|
|
2296
|
+
}
|
|
2297
|
+
function generateConnRequestId() {
|
|
2298
|
+
return crypto.randomUUID();
|
|
2299
|
+
}
|
|
2300
|
+
var Conn = (_class2 = class {
|
|
2301
|
+
__init2() {this.subscriptions = /* @__PURE__ */ new Set()}
|
|
2302
|
+
// TODO: Remove this cyclical reference
|
|
2303
|
+
#actor;
|
|
2304
|
+
/**
|
|
2305
|
+
* The proxied state that notifies of changes automatically.
|
|
2306
|
+
*
|
|
2307
|
+
* Any data that should be stored indefinitely should be held within this object.
|
|
2308
|
+
*/
|
|
2309
|
+
|
|
2310
|
+
get __driverState() {
|
|
2311
|
+
var _a;
|
|
2312
|
+
return (_a = this.__socket) == null ? void 0 : _a.driverState;
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
* Socket connected to this connection.
|
|
2316
|
+
*
|
|
2317
|
+
* If undefined, then nothing is connected to this.
|
|
2318
|
+
*/
|
|
2319
|
+
|
|
2320
|
+
get __status() {
|
|
2321
|
+
if (this.__socket || this.isHibernatable) {
|
|
2322
|
+
return "connected";
|
|
2323
|
+
} else {
|
|
2324
|
+
return "reconnecting";
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
get params() {
|
|
2328
|
+
return this.__persist.params;
|
|
2329
|
+
}
|
|
2330
|
+
get __stateEnabled() {
|
|
2331
|
+
return this.#actor.connStateEnabled;
|
|
2332
|
+
}
|
|
2333
|
+
/**
|
|
2334
|
+
* Gets the current state of the connection.
|
|
2335
|
+
*
|
|
2336
|
+
* Throws an error if the state is not enabled.
|
|
2337
|
+
*/
|
|
2338
|
+
get state() {
|
|
2339
|
+
this.#validateStateEnabled();
|
|
2340
|
+
if (!this.__persist.state) throw new Error("state should exists");
|
|
2341
|
+
return this.__persist.state;
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Sets the state of the connection.
|
|
2345
|
+
*
|
|
2346
|
+
* Throws an error if the state is not enabled.
|
|
2347
|
+
*/
|
|
2348
|
+
set state(value) {
|
|
2349
|
+
this.#validateStateEnabled();
|
|
2350
|
+
this.__persist.state = value;
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Unique identifier for the connection.
|
|
2354
|
+
*/
|
|
2355
|
+
get id() {
|
|
2356
|
+
return this.__persist.connId;
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Token used to authenticate this request.
|
|
2360
|
+
*/
|
|
2361
|
+
get _token() {
|
|
2362
|
+
return this.__persist.token;
|
|
2363
|
+
}
|
|
2364
|
+
/**
|
|
2365
|
+
* Status of the connection.
|
|
2366
|
+
*/
|
|
2367
|
+
get status() {
|
|
2368
|
+
return this.__status;
|
|
2369
|
+
}
|
|
2370
|
+
/**
|
|
2371
|
+
* @experimental
|
|
2372
|
+
*
|
|
2373
|
+
* If the underlying connection can hibernate.
|
|
2374
|
+
*/
|
|
2375
|
+
get isHibernatable() {
|
|
2376
|
+
if (!this.__persist.hibernatableRequestId) {
|
|
2377
|
+
return false;
|
|
2378
|
+
}
|
|
2379
|
+
return this.#actor[PERSIST_SYMBOL].hibernatableWebSocket.findIndex(
|
|
2380
|
+
(x) => _chunkC56XVVV4cjs.arrayBuffersEqual.call(void 0,
|
|
2381
|
+
x.requestId,
|
|
2382
|
+
this.__persist.hibernatableRequestId
|
|
2383
|
+
)
|
|
2384
|
+
) > -1;
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Timestamp of the last time the connection was seen, i.e. the last time the connection was active and checked for liveness.
|
|
2388
|
+
*/
|
|
2389
|
+
get lastSeen() {
|
|
2390
|
+
return this.__persist.lastSeen;
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* Initializes a new instance of the Connection class.
|
|
2394
|
+
*
|
|
2395
|
+
* This should only be constructed by {@link Actor}.
|
|
2396
|
+
*
|
|
2397
|
+
* @protected
|
|
2398
|
+
*/
|
|
2399
|
+
constructor(actor, persist) {;_class2.prototype.__init2.call(this);
|
|
2400
|
+
this.#actor = actor;
|
|
2401
|
+
this.__persist = persist;
|
|
2402
|
+
}
|
|
2403
|
+
#validateStateEnabled() {
|
|
2404
|
+
if (!this.__stateEnabled) {
|
|
2405
|
+
throw new (0, _chunkKSRXX3Z4cjs.ConnStateNotEnabled)();
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* Sends a WebSocket message to the client.
|
|
2410
|
+
*
|
|
2411
|
+
* @param message - The message to send.
|
|
2412
|
+
*
|
|
2413
|
+
* @protected
|
|
2414
|
+
*/
|
|
2415
|
+
_sendMessage(message) {
|
|
2416
|
+
if (this.__driverState) {
|
|
2417
|
+
const driverKind = getConnDriverKindFromState(this.__driverState);
|
|
2418
|
+
const driver = CONN_DRIVERS[driverKind];
|
|
2419
|
+
if (driver.sendMessage) {
|
|
2420
|
+
driver.sendMessage(
|
|
2421
|
+
this.#actor,
|
|
2422
|
+
this,
|
|
2423
|
+
this.__driverState[driverKind],
|
|
2424
|
+
message
|
|
2425
|
+
);
|
|
2426
|
+
} else {
|
|
2427
|
+
this.#actor.rLog.debug({
|
|
2428
|
+
msg: "conn driver does not support sending messages",
|
|
2429
|
+
conn: this.id
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
} else {
|
|
2433
|
+
this.#actor.rLog.warn({
|
|
2434
|
+
msg: "missing connection driver state for send message",
|
|
2435
|
+
conn: this.id
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Sends an event with arguments to the client.
|
|
2441
|
+
*
|
|
2442
|
+
* @param eventName - The name of the event.
|
|
2443
|
+
* @param args - The arguments for the event.
|
|
2444
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
2445
|
+
*/
|
|
2446
|
+
send(eventName, ...args) {
|
|
2447
|
+
this.#actor.inspector.emitter.emit("eventFired", {
|
|
2448
|
+
type: "event",
|
|
2449
|
+
eventName,
|
|
2450
|
+
args,
|
|
2451
|
+
connId: this.id
|
|
2452
|
+
});
|
|
2453
|
+
this._sendMessage(
|
|
2454
|
+
new (0, _chunk3JYSUFETcjs.CachedSerializer)(
|
|
2455
|
+
{
|
|
2456
|
+
body: {
|
|
2457
|
+
tag: "Event",
|
|
2458
|
+
val: {
|
|
2459
|
+
name: eventName,
|
|
2460
|
+
args: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor2.encode(args))
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
},
|
|
2464
|
+
_chunkJMLTKMJ7cjs.TO_CLIENT_VERSIONED
|
|
2465
|
+
)
|
|
2466
|
+
);
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Disconnects the client with an optional reason.
|
|
2470
|
+
*
|
|
2471
|
+
* @param reason - The reason for disconnection.
|
|
2472
|
+
*/
|
|
2473
|
+
async disconnect(reason) {
|
|
2474
|
+
if (this.__socket && this.__driverState) {
|
|
2475
|
+
const driverKind = getConnDriverKindFromState(this.__driverState);
|
|
2476
|
+
const driver = CONN_DRIVERS[driverKind];
|
|
2477
|
+
if (driver.disconnect) {
|
|
2478
|
+
driver.disconnect(
|
|
2479
|
+
this.#actor,
|
|
2480
|
+
this,
|
|
2481
|
+
this.__driverState[driverKind],
|
|
2482
|
+
reason
|
|
2483
|
+
);
|
|
2484
|
+
} else {
|
|
2485
|
+
this.#actor.rLog.debug({
|
|
2486
|
+
msg: "no disconnect handler for conn driver",
|
|
2487
|
+
conn: this.id
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
this.#actor.__connDisconnected(this, true, this.__socket.requestId);
|
|
2491
|
+
} else {
|
|
2492
|
+
this.#actor.rLog.warn({
|
|
2493
|
+
msg: "missing connection driver state for disconnect",
|
|
2494
|
+
conn: this.id
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
this.__socket = void 0;
|
|
2498
|
+
}
|
|
2499
|
+
}, _class2);
|
|
2500
|
+
|
|
2427
2501
|
// src/actor/definition.ts
|
|
2428
2502
|
var ActorDefinition = class {
|
|
2429
2503
|
#config;
|
|
@@ -2498,7 +2572,7 @@ async function importEventSource() {
|
|
|
2498
2572
|
moduleName
|
|
2499
2573
|
)));
|
|
2500
2574
|
_EventSource = es.EventSource;
|
|
2501
|
-
|
|
2575
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug("using eventsource from npm");
|
|
2502
2576
|
} catch (err) {
|
|
2503
2577
|
_EventSource = class MockEventSource {
|
|
2504
2578
|
constructor() {
|
|
@@ -2507,7 +2581,7 @@ async function importEventSource() {
|
|
|
2507
2581
|
);
|
|
2508
2582
|
}
|
|
2509
2583
|
};
|
|
2510
|
-
|
|
2584
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug("using mock eventsource");
|
|
2511
2585
|
}
|
|
2512
2586
|
return _EventSource;
|
|
2513
2587
|
})();
|
|
@@ -2516,7 +2590,7 @@ async function importEventSource() {
|
|
|
2516
2590
|
|
|
2517
2591
|
// src/client/actor-query.ts
|
|
2518
2592
|
async function queryActor(c, query, managerDriver) {
|
|
2519
|
-
|
|
2593
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "querying actor", query: JSON.stringify(query) });
|
|
2520
2594
|
let actorOutput;
|
|
2521
2595
|
if ("getForId" in query) {
|
|
2522
2596
|
const output = await managerDriver.getForId({
|
|
@@ -2563,7 +2637,7 @@ async function queryActor(c, query, managerDriver) {
|
|
|
2563
2637
|
} else {
|
|
2564
2638
|
throw new (0, _chunkKSRXX3Z4cjs.InvalidRequest)("Invalid query format");
|
|
2565
2639
|
}
|
|
2566
|
-
|
|
2640
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "actor query result", actorId: actorOutput.actorId });
|
|
2567
2641
|
return { actorId: actorOutput.actorId };
|
|
2568
2642
|
}
|
|
2569
2643
|
|
|
@@ -2613,13 +2687,13 @@ async function rawHttpFetch(driver, actorQuery, params, input, init) {
|
|
|
2613
2687
|
}
|
|
2614
2688
|
try {
|
|
2615
2689
|
const { actorId } = await queryActor(void 0, actorQuery, driver);
|
|
2616
|
-
|
|
2690
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "found actor for raw http", actorId });
|
|
2617
2691
|
_invariant2.default.call(void 0, actorId, "Missing actor ID");
|
|
2618
2692
|
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
2619
2693
|
const url = new URL(`http://actor/raw/http/${normalizedPath}`);
|
|
2620
2694
|
const proxyRequestHeaders = new Headers(mergedInit.headers);
|
|
2621
2695
|
if (params) {
|
|
2622
|
-
proxyRequestHeaders.set(
|
|
2696
|
+
proxyRequestHeaders.set(_chunk3JYSUFETcjs.HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
2623
2697
|
}
|
|
2624
2698
|
const proxyRequest = new Request(url, {
|
|
2625
2699
|
...mergedInit,
|
|
@@ -2627,9 +2701,9 @@ async function rawHttpFetch(driver, actorQuery, params, input, init) {
|
|
|
2627
2701
|
});
|
|
2628
2702
|
return driver.sendRequest(actorId, proxyRequest);
|
|
2629
2703
|
} catch (err) {
|
|
2630
|
-
const { group, code, message, metadata } =
|
|
2704
|
+
const { group, code, message, metadata } = _chunkC56XVVV4cjs.deconstructError.call(void 0,
|
|
2631
2705
|
err,
|
|
2632
|
-
|
|
2706
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ),
|
|
2633
2707
|
{},
|
|
2634
2708
|
true
|
|
2635
2709
|
);
|
|
@@ -2639,7 +2713,7 @@ async function rawHttpFetch(driver, actorQuery, params, input, init) {
|
|
|
2639
2713
|
async function rawWebSocket(driver, actorQuery, params, path, protocols) {
|
|
2640
2714
|
const encoding = "bare";
|
|
2641
2715
|
const { actorId } = await queryActor(void 0, actorQuery, driver);
|
|
2642
|
-
|
|
2716
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "found actor for action", actorId });
|
|
2643
2717
|
_invariant2.default.call(void 0, actorId, "Missing actor ID");
|
|
2644
2718
|
let pathPortion = "";
|
|
2645
2719
|
let queryPortion = "";
|
|
@@ -2655,8 +2729,8 @@ async function rawWebSocket(driver, actorQuery, params, path, protocols) {
|
|
|
2655
2729
|
pathPortion = pathPortion.slice(1);
|
|
2656
2730
|
}
|
|
2657
2731
|
}
|
|
2658
|
-
const fullPath = `${
|
|
2659
|
-
|
|
2732
|
+
const fullPath = `${_chunk3JYSUFETcjs.PATH_RAW_WEBSOCKET_PREFIX}${pathPortion}${queryPortion}`;
|
|
2733
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
2660
2734
|
msg: "opening websocket",
|
|
2661
2735
|
actorId,
|
|
2662
2736
|
encoding,
|
|
@@ -2682,10 +2756,10 @@ function messageLength(message) {
|
|
|
2682
2756
|
if (typeof message === "string") {
|
|
2683
2757
|
return message.length;
|
|
2684
2758
|
}
|
|
2685
|
-
|
|
2759
|
+
_chunkC56XVVV4cjs.assertUnreachable.call(void 0, message);
|
|
2686
2760
|
}
|
|
2687
2761
|
async function sendHttpRequest(opts) {
|
|
2688
|
-
|
|
2762
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
2689
2763
|
msg: "sending http request",
|
|
2690
2764
|
url: opts.url,
|
|
2691
2765
|
encoding: opts.encoding
|
|
@@ -2694,8 +2768,8 @@ async function sendHttpRequest(opts) {
|
|
|
2694
2768
|
let bodyData;
|
|
2695
2769
|
if (opts.method === "POST" || opts.method === "PUT") {
|
|
2696
2770
|
_invariant2.default.call(void 0, opts.body !== void 0, "missing body");
|
|
2697
|
-
contentType =
|
|
2698
|
-
bodyData =
|
|
2771
|
+
contentType = _chunk3JYSUFETcjs.contentTypeForEncoding.call(void 0, opts.encoding);
|
|
2772
|
+
bodyData = _chunk3JYSUFETcjs.serializeWithEncoding.call(void 0,
|
|
2699
2773
|
opts.encoding,
|
|
2700
2774
|
opts.body,
|
|
2701
2775
|
opts.requestVersionedDataHandler
|
|
@@ -2711,7 +2785,7 @@ async function sendHttpRequest(opts) {
|
|
|
2711
2785
|
...contentType ? {
|
|
2712
2786
|
"Content-Type": contentType
|
|
2713
2787
|
} : {},
|
|
2714
|
-
"User-Agent":
|
|
2788
|
+
"User-Agent": _chunkC56XVVV4cjs.httpUserAgent.call(void 0, )
|
|
2715
2789
|
},
|
|
2716
2790
|
body: bodyData,
|
|
2717
2791
|
credentials: "include",
|
|
@@ -2727,10 +2801,10 @@ async function sendHttpRequest(opts) {
|
|
|
2727
2801
|
const bufferResponse = await response.arrayBuffer();
|
|
2728
2802
|
let responseData;
|
|
2729
2803
|
try {
|
|
2730
|
-
responseData =
|
|
2804
|
+
responseData = _chunk3JYSUFETcjs.deserializeWithEncoding.call(void 0,
|
|
2731
2805
|
opts.encoding,
|
|
2732
2806
|
new Uint8Array(bufferResponse),
|
|
2733
|
-
|
|
2807
|
+
_chunkJMLTKMJ7cjs.HTTP_RESPONSE_ERROR_VERSIONED
|
|
2734
2808
|
);
|
|
2735
2809
|
} catch (error) {
|
|
2736
2810
|
const textResponse = new TextDecoder("utf-8", {
|
|
@@ -2750,7 +2824,7 @@ ${textResponse}`
|
|
|
2750
2824
|
}
|
|
2751
2825
|
}
|
|
2752
2826
|
let decodedMetadata;
|
|
2753
|
-
if (responseData.metadata &&
|
|
2827
|
+
if (responseData.metadata && _chunk3JYSUFETcjs.encodingIsBinary.call(void 0, opts.encoding)) {
|
|
2754
2828
|
decodedMetadata = cbor3.decode(
|
|
2755
2829
|
new Uint8Array(responseData.metadata)
|
|
2756
2830
|
);
|
|
@@ -2767,7 +2841,7 @@ ${textResponse}`
|
|
|
2767
2841
|
}
|
|
2768
2842
|
try {
|
|
2769
2843
|
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
2770
|
-
return
|
|
2844
|
+
return _chunk3JYSUFETcjs.deserializeWithEncoding.call(void 0,
|
|
2771
2845
|
opts.encoding,
|
|
2772
2846
|
buffer,
|
|
2773
2847
|
opts.responseVersionedDataHandler
|
|
@@ -2814,9 +2888,9 @@ var ActorHandleRaw = class {
|
|
|
2814
2888
|
this.#actorQuery,
|
|
2815
2889
|
this.#driver
|
|
2816
2890
|
);
|
|
2817
|
-
|
|
2891
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "found actor for action", actorId });
|
|
2818
2892
|
_invariant2.default.call(void 0, actorId, "Missing actor ID");
|
|
2819
|
-
|
|
2893
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
2820
2894
|
msg: "handling action",
|
|
2821
2895
|
name: opts.name,
|
|
2822
2896
|
encoding: this.#encoding
|
|
@@ -2825,11 +2899,11 @@ var ActorHandleRaw = class {
|
|
|
2825
2899
|
url: `http://actor/action/${encodeURIComponent(opts.name)}`,
|
|
2826
2900
|
method: "POST",
|
|
2827
2901
|
headers: {
|
|
2828
|
-
[
|
|
2829
|
-
...this.#params !== void 0 ? { [
|
|
2902
|
+
[_chunk3JYSUFETcjs.HEADER_ENCODING]: this.#encoding,
|
|
2903
|
+
...this.#params !== void 0 ? { [_chunk3JYSUFETcjs.HEADER_CONN_PARAMS]: JSON.stringify(this.#params) } : {}
|
|
2830
2904
|
},
|
|
2831
2905
|
body: {
|
|
2832
|
-
args:
|
|
2906
|
+
args: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor4.encode(opts.args))
|
|
2833
2907
|
},
|
|
2834
2908
|
encoding: this.#encoding,
|
|
2835
2909
|
customFetch: this.#driver.sendRequest.bind(
|
|
@@ -2837,14 +2911,14 @@ var ActorHandleRaw = class {
|
|
|
2837
2911
|
actorId
|
|
2838
2912
|
),
|
|
2839
2913
|
signal: opts == null ? void 0 : opts.signal,
|
|
2840
|
-
requestVersionedDataHandler:
|
|
2841
|
-
responseVersionedDataHandler:
|
|
2914
|
+
requestVersionedDataHandler: _chunkJMLTKMJ7cjs.HTTP_ACTION_REQUEST_VERSIONED,
|
|
2915
|
+
responseVersionedDataHandler: _chunkJMLTKMJ7cjs.HTTP_ACTION_RESPONSE_VERSIONED
|
|
2842
2916
|
});
|
|
2843
2917
|
return cbor4.decode(new Uint8Array(responseData.output));
|
|
2844
2918
|
} catch (err) {
|
|
2845
|
-
const { group, code, message, metadata } =
|
|
2919
|
+
const { group, code, message, metadata } = _chunkC56XVVV4cjs.deconstructError.call(void 0,
|
|
2846
2920
|
err,
|
|
2847
|
-
|
|
2921
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ),
|
|
2848
2922
|
{},
|
|
2849
2923
|
true
|
|
2850
2924
|
);
|
|
@@ -2858,7 +2932,7 @@ var ActorHandleRaw = class {
|
|
|
2858
2932
|
* @returns {ActorConn<AD>} A connection to the actor.
|
|
2859
2933
|
*/
|
|
2860
2934
|
connect() {
|
|
2861
|
-
|
|
2935
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
2862
2936
|
msg: "establishing connection from handle",
|
|
2863
2937
|
query: this.#actorQuery
|
|
2864
2938
|
});
|
|
@@ -2918,7 +2992,7 @@ var ActorHandleRaw = class {
|
|
|
2918
2992
|
} else if ("getOrCreateForKey" in this.#actorQuery) {
|
|
2919
2993
|
name = this.#actorQuery.getOrCreateForKey.name;
|
|
2920
2994
|
} else {
|
|
2921
|
-
|
|
2995
|
+
_chunk3JYSUFETcjs.assertUnreachable.call(void 0, this.#actorQuery);
|
|
2922
2996
|
}
|
|
2923
2997
|
const { actorId } = await queryActor(
|
|
2924
2998
|
void 0,
|
|
@@ -2932,7 +3006,7 @@ var ActorHandleRaw = class {
|
|
|
2932
3006
|
} else if ("create" in this.#actorQuery) {
|
|
2933
3007
|
_invariant2.default.call(void 0, false, "actorQuery cannot be create");
|
|
2934
3008
|
} else {
|
|
2935
|
-
|
|
3009
|
+
_chunk3JYSUFETcjs.assertUnreachable.call(void 0, this.#actorQuery);
|
|
2936
3010
|
}
|
|
2937
3011
|
}
|
|
2938
3012
|
};
|
|
@@ -2965,7 +3039,7 @@ var ClientRaw = (_class4 = class {
|
|
|
2965
3039
|
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2966
3040
|
*/
|
|
2967
3041
|
getForId(name, actorId, opts) {
|
|
2968
|
-
|
|
3042
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
2969
3043
|
msg: "get handle to actor with id",
|
|
2970
3044
|
name,
|
|
2971
3045
|
actorId,
|
|
@@ -2991,7 +3065,7 @@ var ClientRaw = (_class4 = class {
|
|
|
2991
3065
|
*/
|
|
2992
3066
|
get(name, key, opts) {
|
|
2993
3067
|
const keyArray = typeof key === "string" ? [key] : key || [];
|
|
2994
|
-
|
|
3068
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
2995
3069
|
msg: "get handle to actor",
|
|
2996
3070
|
name,
|
|
2997
3071
|
key: keyArray,
|
|
@@ -3017,7 +3091,7 @@ var ClientRaw = (_class4 = class {
|
|
|
3017
3091
|
*/
|
|
3018
3092
|
getOrCreate(name, key, opts) {
|
|
3019
3093
|
const keyArray = typeof key === "string" ? [key] : key || [];
|
|
3020
|
-
|
|
3094
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3021
3095
|
msg: "get or create handle to actor",
|
|
3022
3096
|
name,
|
|
3023
3097
|
key: keyArray,
|
|
@@ -3055,7 +3129,7 @@ var ClientRaw = (_class4 = class {
|
|
|
3055
3129
|
key: keyArray
|
|
3056
3130
|
}
|
|
3057
3131
|
};
|
|
3058
|
-
|
|
3132
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3059
3133
|
msg: "create actor handle",
|
|
3060
3134
|
name,
|
|
3061
3135
|
key: keyArray,
|
|
@@ -3067,7 +3141,7 @@ var ClientRaw = (_class4 = class {
|
|
|
3067
3141
|
createQuery,
|
|
3068
3142
|
this.#driver
|
|
3069
3143
|
);
|
|
3070
|
-
|
|
3144
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3071
3145
|
msg: "created actor with ID",
|
|
3072
3146
|
name,
|
|
3073
3147
|
key: keyArray,
|
|
@@ -3104,11 +3178,11 @@ var ClientRaw = (_class4 = class {
|
|
|
3104
3178
|
*/
|
|
3105
3179
|
async dispose() {
|
|
3106
3180
|
if (this.#disposed) {
|
|
3107
|
-
|
|
3181
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({ msg: "client already disconnected" });
|
|
3108
3182
|
return;
|
|
3109
3183
|
}
|
|
3110
3184
|
this.#disposed = true;
|
|
3111
|
-
|
|
3185
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "disposing client" });
|
|
3112
3186
|
const disposePromises = [];
|
|
3113
3187
|
for (const conn of this[ACTOR_CONNS_SYMBOL].values()) {
|
|
3114
3188
|
disposePromises.push(conn.dispose());
|
|
@@ -3268,10 +3342,10 @@ var ActorConnRaw = class {
|
|
|
3268
3342
|
* @returns {Promise<Response>} - A promise that resolves to the response of the action function.
|
|
3269
3343
|
*/
|
|
3270
3344
|
async action(opts) {
|
|
3271
|
-
|
|
3345
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "action", name: opts.name, args: opts.args });
|
|
3272
3346
|
const actionId = this.#actionIdCounter;
|
|
3273
3347
|
this.#actionIdCounter += 1;
|
|
3274
|
-
const { promise, resolve, reject } =
|
|
3348
|
+
const { promise, resolve, reject } = _chunkC56XVVV4cjs.promiseWithResolvers.call(void 0, );
|
|
3275
3349
|
this.#actionsInFlight.set(actionId, {
|
|
3276
3350
|
name: opts.name,
|
|
3277
3351
|
resolve,
|
|
@@ -3283,7 +3357,7 @@ var ActorConnRaw = class {
|
|
|
3283
3357
|
val: {
|
|
3284
3358
|
id: BigInt(actionId),
|
|
3285
3359
|
name: opts.name,
|
|
3286
|
-
args:
|
|
3360
|
+
args: _chunkC56XVVV4cjs.bufferToArrayBuffer.call(void 0, cbor5.encode(opts.args))
|
|
3287
3361
|
}
|
|
3288
3362
|
}
|
|
3289
3363
|
});
|
|
@@ -3312,10 +3386,10 @@ var ActorConnRaw = class {
|
|
|
3312
3386
|
minTimeout: 250,
|
|
3313
3387
|
maxTimeout: 3e4,
|
|
3314
3388
|
onFailedAttempt: (error) => {
|
|
3315
|
-
|
|
3389
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({
|
|
3316
3390
|
msg: "failed to reconnect",
|
|
3317
3391
|
attempt: error.attemptNumber,
|
|
3318
|
-
error:
|
|
3392
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
3319
3393
|
});
|
|
3320
3394
|
},
|
|
3321
3395
|
// Cancel retry if aborted
|
|
@@ -3323,7 +3397,7 @@ var ActorConnRaw = class {
|
|
|
3323
3397
|
});
|
|
3324
3398
|
} catch (err) {
|
|
3325
3399
|
if (err.name === "AbortError") {
|
|
3326
|
-
|
|
3400
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).info({ msg: "connection retry aborted" });
|
|
3327
3401
|
return;
|
|
3328
3402
|
} else {
|
|
3329
3403
|
throw err;
|
|
@@ -3335,13 +3409,13 @@ var ActorConnRaw = class {
|
|
|
3335
3409
|
try {
|
|
3336
3410
|
if (this.#onOpenPromise)
|
|
3337
3411
|
throw new Error("#onOpenPromise already defined");
|
|
3338
|
-
this.#onOpenPromise =
|
|
3412
|
+
this.#onOpenPromise = _chunkC56XVVV4cjs.promiseWithResolvers.call(void 0, );
|
|
3339
3413
|
if (this.#client[TRANSPORT_SYMBOL] === "websocket") {
|
|
3340
3414
|
await this.#connectWebSocket();
|
|
3341
3415
|
} else if (this.#client[TRANSPORT_SYMBOL] === "sse") {
|
|
3342
3416
|
await this.#connectSse();
|
|
3343
3417
|
} else {
|
|
3344
|
-
|
|
3418
|
+
_chunkC56XVVV4cjs.assertUnreachable.call(void 0, this.#client[TRANSPORT_SYMBOL]);
|
|
3345
3419
|
}
|
|
3346
3420
|
await this.#onOpenPromise.promise;
|
|
3347
3421
|
} finally {
|
|
@@ -3356,13 +3430,13 @@ var ActorConnRaw = class {
|
|
|
3356
3430
|
);
|
|
3357
3431
|
const isReconnection = this.#connectionId && this.#connectionToken;
|
|
3358
3432
|
if (isReconnection) {
|
|
3359
|
-
|
|
3433
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3360
3434
|
msg: "attempting websocket reconnection",
|
|
3361
3435
|
connectionId: this.#connectionId
|
|
3362
3436
|
});
|
|
3363
3437
|
}
|
|
3364
3438
|
const ws = await this.#driver.openWebSocket(
|
|
3365
|
-
|
|
3439
|
+
_chunk3JYSUFETcjs.PATH_CONNECT_WEBSOCKET,
|
|
3366
3440
|
actorId,
|
|
3367
3441
|
this.#encoding,
|
|
3368
3442
|
this.#params,
|
|
@@ -3370,7 +3444,7 @@ var ActorConnRaw = class {
|
|
|
3370
3444
|
isReconnection ? this.#connectionId : void 0,
|
|
3371
3445
|
isReconnection ? this.#connectionToken : void 0
|
|
3372
3446
|
);
|
|
3373
|
-
|
|
3447
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3374
3448
|
msg: "transport set to new websocket",
|
|
3375
3449
|
connectionId: this.#connectionId,
|
|
3376
3450
|
readyState: ws.readyState,
|
|
@@ -3378,7 +3452,7 @@ var ActorConnRaw = class {
|
|
|
3378
3452
|
});
|
|
3379
3453
|
this.#transport = { websocket: ws };
|
|
3380
3454
|
ws.addEventListener("open", () => {
|
|
3381
|
-
|
|
3455
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3382
3456
|
msg: "client websocket open",
|
|
3383
3457
|
connectionId: this.#connectionId
|
|
3384
3458
|
});
|
|
@@ -3387,9 +3461,9 @@ var ActorConnRaw = class {
|
|
|
3387
3461
|
try {
|
|
3388
3462
|
await this.#handleOnMessage(ev.data);
|
|
3389
3463
|
} catch (err) {
|
|
3390
|
-
|
|
3464
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).error({
|
|
3391
3465
|
msg: "error in websocket message handler",
|
|
3392
|
-
error:
|
|
3466
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, err)
|
|
3393
3467
|
});
|
|
3394
3468
|
}
|
|
3395
3469
|
});
|
|
@@ -3397,9 +3471,9 @@ var ActorConnRaw = class {
|
|
|
3397
3471
|
try {
|
|
3398
3472
|
this.#handleOnClose(ev);
|
|
3399
3473
|
} catch (err) {
|
|
3400
|
-
|
|
3474
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).error({
|
|
3401
3475
|
msg: "error in websocket close handler",
|
|
3402
|
-
error:
|
|
3476
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, err)
|
|
3403
3477
|
});
|
|
3404
3478
|
}
|
|
3405
3479
|
});
|
|
@@ -3407,9 +3481,9 @@ var ActorConnRaw = class {
|
|
|
3407
3481
|
try {
|
|
3408
3482
|
this.#handleOnError();
|
|
3409
3483
|
} catch (err) {
|
|
3410
|
-
|
|
3484
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).error({
|
|
3411
3485
|
msg: "error in websocket error handler",
|
|
3412
|
-
error:
|
|
3486
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, err)
|
|
3413
3487
|
});
|
|
3414
3488
|
}
|
|
3415
3489
|
});
|
|
@@ -3421,9 +3495,9 @@ var ActorConnRaw = class {
|
|
|
3421
3495
|
this.#actorQuery,
|
|
3422
3496
|
this.#driver
|
|
3423
3497
|
);
|
|
3424
|
-
|
|
3498
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "found actor for sse connection", actorId });
|
|
3425
3499
|
_invariant2.default.call(void 0, actorId, "Missing actor ID");
|
|
3426
|
-
|
|
3500
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3427
3501
|
msg: "opening sse connection",
|
|
3428
3502
|
actorId,
|
|
3429
3503
|
encoding: this.#encoding
|
|
@@ -3437,16 +3511,16 @@ var ActorConnRaw = class {
|
|
|
3437
3511
|
...init,
|
|
3438
3512
|
headers: {
|
|
3439
3513
|
...init == null ? void 0 : init.headers,
|
|
3440
|
-
"User-Agent":
|
|
3441
|
-
[
|
|
3514
|
+
"User-Agent": _chunkC56XVVV4cjs.httpUserAgent.call(void 0, ),
|
|
3515
|
+
[_chunk3JYSUFETcjs.HEADER_ENCODING]: this.#encoding,
|
|
3442
3516
|
...this.#params !== void 0 ? {
|
|
3443
|
-
[
|
|
3517
|
+
[_chunk3JYSUFETcjs.HEADER_CONN_PARAMS]: JSON.stringify(
|
|
3444
3518
|
this.#params
|
|
3445
3519
|
)
|
|
3446
3520
|
} : {},
|
|
3447
3521
|
...isReconnection ? {
|
|
3448
|
-
[
|
|
3449
|
-
[
|
|
3522
|
+
[_chunk3JYSUFETcjs.HEADER_CONN_ID]: this.#connectionId,
|
|
3523
|
+
[_chunk3JYSUFETcjs.HEADER_CONN_TOKEN]: this.#connectionToken
|
|
3450
3524
|
} : {}
|
|
3451
3525
|
}
|
|
3452
3526
|
})
|
|
@@ -3464,7 +3538,7 @@ var ActorConnRaw = class {
|
|
|
3464
3538
|
}
|
|
3465
3539
|
/** Called by the onopen event from drivers. */
|
|
3466
3540
|
#handleOnOpen() {
|
|
3467
|
-
|
|
3541
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3468
3542
|
msg: "socket open",
|
|
3469
3543
|
messageQueueLength: this.#messageQueue.length,
|
|
3470
3544
|
connectionId: this.#connectionId
|
|
@@ -3472,14 +3546,14 @@ var ActorConnRaw = class {
|
|
|
3472
3546
|
if (this.#onOpenPromise) {
|
|
3473
3547
|
this.#onOpenPromise.resolve(void 0);
|
|
3474
3548
|
} else {
|
|
3475
|
-
|
|
3549
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({ msg: "#onOpenPromise is undefined" });
|
|
3476
3550
|
}
|
|
3477
3551
|
for (const eventName of this.#eventSubscriptions.keys()) {
|
|
3478
3552
|
this.#sendSubscription(eventName, true);
|
|
3479
3553
|
}
|
|
3480
3554
|
const queue = this.#messageQueue;
|
|
3481
3555
|
this.#messageQueue = [];
|
|
3482
|
-
|
|
3556
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3483
3557
|
msg: "flushing message queue",
|
|
3484
3558
|
queueLength: queue.length
|
|
3485
3559
|
});
|
|
@@ -3489,24 +3563,24 @@ var ActorConnRaw = class {
|
|
|
3489
3563
|
}
|
|
3490
3564
|
/** Called by the onmessage event from drivers. */
|
|
3491
3565
|
async #handleOnMessage(data) {
|
|
3492
|
-
|
|
3566
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace({
|
|
3493
3567
|
msg: "received message",
|
|
3494
3568
|
dataType: typeof data,
|
|
3495
3569
|
isBlob: data instanceof Blob,
|
|
3496
3570
|
isArrayBuffer: data instanceof ArrayBuffer
|
|
3497
3571
|
});
|
|
3498
3572
|
const response = await this.#parseMessage(data);
|
|
3499
|
-
|
|
3500
|
-
|
|
3573
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace(
|
|
3574
|
+
_chunkC56XVVV4cjs.getEnvUniversal.call(void 0, "_RIVETKIT_LOG_MESSAGE") ? {
|
|
3501
3575
|
msg: "parsed message",
|
|
3502
|
-
message:
|
|
3576
|
+
message: _chunk3JYSUFETcjs.jsonStringifyCompat.call(void 0, response).substring(0, 100) + "..."
|
|
3503
3577
|
} : { msg: "parsed message" }
|
|
3504
3578
|
);
|
|
3505
3579
|
if (response.body.tag === "Init") {
|
|
3506
3580
|
this.#actorId = response.body.val.actorId;
|
|
3507
3581
|
this.#connectionId = response.body.val.connectionId;
|
|
3508
3582
|
this.#connectionToken = response.body.val.connectionToken;
|
|
3509
|
-
|
|
3583
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace({
|
|
3510
3584
|
msg: "received init message",
|
|
3511
3585
|
actorId: this.#actorId,
|
|
3512
3586
|
connectionId: this.#connectionId
|
|
@@ -3516,7 +3590,7 @@ var ActorConnRaw = class {
|
|
|
3516
3590
|
const { group, code, message, metadata, actionId } = response.body.val;
|
|
3517
3591
|
if (actionId) {
|
|
3518
3592
|
const inFlight = this.#takeActionInFlight(Number(actionId));
|
|
3519
|
-
|
|
3593
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({
|
|
3520
3594
|
msg: "action error",
|
|
3521
3595
|
actionId,
|
|
3522
3596
|
actionName: inFlight == null ? void 0 : inFlight.name,
|
|
@@ -3529,7 +3603,7 @@ var ActorConnRaw = class {
|
|
|
3529
3603
|
new ActorError(group, code, message, metadata)
|
|
3530
3604
|
);
|
|
3531
3605
|
} else {
|
|
3532
|
-
|
|
3606
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({
|
|
3533
3607
|
msg: "connection error",
|
|
3534
3608
|
group,
|
|
3535
3609
|
code,
|
|
@@ -3553,25 +3627,25 @@ var ActorConnRaw = class {
|
|
|
3553
3627
|
}
|
|
3554
3628
|
} else if (response.body.tag === "ActionResponse") {
|
|
3555
3629
|
const { id: actionId } = response.body.val;
|
|
3556
|
-
|
|
3630
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace({
|
|
3557
3631
|
msg: "received action response",
|
|
3558
3632
|
actionId
|
|
3559
3633
|
});
|
|
3560
3634
|
const inFlight = this.#takeActionInFlight(Number(actionId));
|
|
3561
|
-
|
|
3635
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace({
|
|
3562
3636
|
msg: "resolving action promise",
|
|
3563
3637
|
actionId,
|
|
3564
3638
|
actionName: inFlight == null ? void 0 : inFlight.name
|
|
3565
3639
|
});
|
|
3566
3640
|
inFlight.resolve(response.body.val);
|
|
3567
3641
|
} else if (response.body.tag === "Event") {
|
|
3568
|
-
|
|
3642
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace({
|
|
3569
3643
|
msg: "received event",
|
|
3570
3644
|
name: response.body.val.name
|
|
3571
3645
|
});
|
|
3572
3646
|
this.#dispatchEvent(response.body.val);
|
|
3573
3647
|
} else {
|
|
3574
|
-
|
|
3648
|
+
_chunkC56XVVV4cjs.assertUnreachable.call(void 0, response.body);
|
|
3575
3649
|
}
|
|
3576
3650
|
}
|
|
3577
3651
|
/** Called by the onclose event from drivers. */
|
|
@@ -3585,7 +3659,7 @@ var ActorConnRaw = class {
|
|
|
3585
3659
|
)
|
|
3586
3660
|
);
|
|
3587
3661
|
}
|
|
3588
|
-
|
|
3662
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).info({
|
|
3589
3663
|
msg: "socket closed",
|
|
3590
3664
|
code: closeEvent.code,
|
|
3591
3665
|
reason: closeEvent.reason,
|
|
@@ -3595,7 +3669,7 @@ var ActorConnRaw = class {
|
|
|
3595
3669
|
actionsInFlight: this.#actionsInFlight.size
|
|
3596
3670
|
});
|
|
3597
3671
|
if (this.#actionsInFlight.size > 0) {
|
|
3598
|
-
|
|
3672
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3599
3673
|
msg: "rejecting in-flight actions after disconnect",
|
|
3600
3674
|
count: this.#actionsInFlight.size,
|
|
3601
3675
|
connectionId: this.#connectionId,
|
|
@@ -3611,7 +3685,7 @@ var ActorConnRaw = class {
|
|
|
3611
3685
|
}
|
|
3612
3686
|
this.#transport = void 0;
|
|
3613
3687
|
if (!this.#disposed && !this.#connecting) {
|
|
3614
|
-
|
|
3688
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3615
3689
|
msg: "triggering reconnect",
|
|
3616
3690
|
connectionId: this.#connectionId,
|
|
3617
3691
|
messageQueueLength: this.#messageQueue.length
|
|
@@ -3622,7 +3696,7 @@ var ActorConnRaw = class {
|
|
|
3622
3696
|
/** Called by the onerror event from drivers. */
|
|
3623
3697
|
#handleOnError() {
|
|
3624
3698
|
if (this.#disposed) return;
|
|
3625
|
-
|
|
3699
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn("socket error");
|
|
3626
3700
|
}
|
|
3627
3701
|
#takeActionInFlight(id) {
|
|
3628
3702
|
const inFlight = this.#actionsInFlight.get(id);
|
|
@@ -3652,9 +3726,9 @@ var ActorConnRaw = class {
|
|
|
3652
3726
|
try {
|
|
3653
3727
|
handler(error);
|
|
3654
3728
|
} catch (err) {
|
|
3655
|
-
|
|
3729
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).error({
|
|
3656
3730
|
msg: "error in connection error handler",
|
|
3657
|
-
error:
|
|
3731
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, err)
|
|
3658
3732
|
});
|
|
3659
3733
|
}
|
|
3660
3734
|
}
|
|
@@ -3725,11 +3799,11 @@ var ActorConnRaw = class {
|
|
|
3725
3799
|
}
|
|
3726
3800
|
let queueMessage = false;
|
|
3727
3801
|
if (!this.#transport) {
|
|
3728
|
-
|
|
3802
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "no transport, queueing message" });
|
|
3729
3803
|
queueMessage = true;
|
|
3730
3804
|
} else if ("websocket" in this.#transport) {
|
|
3731
3805
|
const readyState = this.#transport.websocket.readyState;
|
|
3732
|
-
|
|
3806
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3733
3807
|
msg: "websocket send attempt",
|
|
3734
3808
|
readyState,
|
|
3735
3809
|
readyStateString: readyState === 0 ? "CONNECTING" : readyState === 1 ? "OPEN" : readyState === 2 ? "CLOSING" : "CLOSED",
|
|
@@ -3739,18 +3813,18 @@ var ActorConnRaw = class {
|
|
|
3739
3813
|
});
|
|
3740
3814
|
if (readyState === 1) {
|
|
3741
3815
|
try {
|
|
3742
|
-
const messageSerialized =
|
|
3816
|
+
const messageSerialized = _chunk3JYSUFETcjs.serializeWithEncoding.call(void 0,
|
|
3743
3817
|
this.#encoding,
|
|
3744
3818
|
message,
|
|
3745
|
-
|
|
3819
|
+
_chunkJMLTKMJ7cjs.TO_SERVER_VERSIONED
|
|
3746
3820
|
);
|
|
3747
3821
|
this.#transport.websocket.send(messageSerialized);
|
|
3748
|
-
|
|
3822
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace({
|
|
3749
3823
|
msg: "sent websocket message",
|
|
3750
3824
|
len: messageLength(messageSerialized)
|
|
3751
3825
|
});
|
|
3752
3826
|
} catch (error) {
|
|
3753
|
-
|
|
3827
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({
|
|
3754
3828
|
msg: "failed to send message, added to queue",
|
|
3755
3829
|
error,
|
|
3756
3830
|
connectionId: this.#connectionId
|
|
@@ -3758,7 +3832,7 @@ var ActorConnRaw = class {
|
|
|
3758
3832
|
queueMessage = true;
|
|
3759
3833
|
}
|
|
3760
3834
|
} else {
|
|
3761
|
-
|
|
3835
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3762
3836
|
msg: "websocket not open, queueing message",
|
|
3763
3837
|
readyState
|
|
3764
3838
|
});
|
|
@@ -3771,11 +3845,11 @@ var ActorConnRaw = class {
|
|
|
3771
3845
|
queueMessage = true;
|
|
3772
3846
|
}
|
|
3773
3847
|
} else {
|
|
3774
|
-
|
|
3848
|
+
_chunkC56XVVV4cjs.assertUnreachable.call(void 0, this.#transport);
|
|
3775
3849
|
}
|
|
3776
3850
|
if (!(opts == null ? void 0 : opts.ephemeral) && queueMessage) {
|
|
3777
3851
|
this.#messageQueue.push(message);
|
|
3778
|
-
|
|
3852
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3779
3853
|
msg: "queued connection message",
|
|
3780
3854
|
queueLength: this.#messageQueue.length,
|
|
3781
3855
|
connectionId: this.#connectionId,
|
|
@@ -3790,13 +3864,13 @@ var ActorConnRaw = class {
|
|
|
3790
3864
|
throw new InternalError2(
|
|
3791
3865
|
"Missing connection ID or token."
|
|
3792
3866
|
);
|
|
3793
|
-
|
|
3794
|
-
|
|
3867
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).trace(
|
|
3868
|
+
_chunkC56XVVV4cjs.getEnvUniversal.call(void 0, "_RIVETKIT_LOG_MESSAGE") ? {
|
|
3795
3869
|
msg: "sent http message",
|
|
3796
|
-
message: `${
|
|
3870
|
+
message: `${_chunk3JYSUFETcjs.jsonStringifyCompat.call(void 0, message).substring(0, 100)}...`
|
|
3797
3871
|
} : { msg: "sent http message" }
|
|
3798
3872
|
);
|
|
3799
|
-
|
|
3873
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({
|
|
3800
3874
|
msg: "sending http message",
|
|
3801
3875
|
actorId: this.#actorId,
|
|
3802
3876
|
connectionId: this.#connectionId
|
|
@@ -3805,9 +3879,9 @@ var ActorConnRaw = class {
|
|
|
3805
3879
|
url: "http://actor/connections/message",
|
|
3806
3880
|
method: "POST",
|
|
3807
3881
|
headers: {
|
|
3808
|
-
[
|
|
3809
|
-
[
|
|
3810
|
-
[
|
|
3882
|
+
[_chunk3JYSUFETcjs.HEADER_ENCODING]: this.#encoding,
|
|
3883
|
+
[_chunk3JYSUFETcjs.HEADER_CONN_ID]: this.#connectionId,
|
|
3884
|
+
[_chunk3JYSUFETcjs.HEADER_CONN_TOKEN]: this.#connectionToken
|
|
3811
3885
|
},
|
|
3812
3886
|
body: message,
|
|
3813
3887
|
encoding: this.#encoding,
|
|
@@ -3816,11 +3890,11 @@ var ActorConnRaw = class {
|
|
|
3816
3890
|
this.#driver,
|
|
3817
3891
|
this.#actorId
|
|
3818
3892
|
),
|
|
3819
|
-
requestVersionedDataHandler:
|
|
3820
|
-
responseVersionedDataHandler:
|
|
3893
|
+
requestVersionedDataHandler: _chunkJMLTKMJ7cjs.TO_SERVER_VERSIONED,
|
|
3894
|
+
responseVersionedDataHandler: _chunkJMLTKMJ7cjs.TO_CLIENT_VERSIONED
|
|
3821
3895
|
});
|
|
3822
3896
|
} catch (error) {
|
|
3823
|
-
|
|
3897
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({
|
|
3824
3898
|
msg: "failed to send message, added to queue",
|
|
3825
3899
|
error
|
|
3826
3900
|
});
|
|
@@ -3831,7 +3905,7 @@ var ActorConnRaw = class {
|
|
|
3831
3905
|
}
|
|
3832
3906
|
async #parseMessage(data) {
|
|
3833
3907
|
_invariant2.default.call(void 0, this.#transport, "transport must be defined");
|
|
3834
|
-
if (
|
|
3908
|
+
if (_chunk3JYSUFETcjs.encodingIsBinary.call(void 0, this.#encoding) && "sse" in this.#transport) {
|
|
3835
3909
|
if (typeof data === "string") {
|
|
3836
3910
|
const binaryString = atob(data);
|
|
3837
3911
|
data = new Uint8Array(
|
|
@@ -3843,11 +3917,11 @@ var ActorConnRaw = class {
|
|
|
3843
3917
|
);
|
|
3844
3918
|
}
|
|
3845
3919
|
}
|
|
3846
|
-
const buffer = await
|
|
3847
|
-
return
|
|
3920
|
+
const buffer = await _chunkJMLTKMJ7cjs.inputDataToBuffer.call(void 0, data);
|
|
3921
|
+
return _chunk3JYSUFETcjs.deserializeWithEncoding.call(void 0,
|
|
3848
3922
|
this.#encoding,
|
|
3849
3923
|
buffer,
|
|
3850
|
-
|
|
3924
|
+
_chunkJMLTKMJ7cjs.TO_CLIENT_VERSIONED
|
|
3851
3925
|
);
|
|
3852
3926
|
}
|
|
3853
3927
|
/**
|
|
@@ -3871,39 +3945,39 @@ var ActorConnRaw = class {
|
|
|
3871
3945
|
*/
|
|
3872
3946
|
async dispose() {
|
|
3873
3947
|
if (this.#disposed) {
|
|
3874
|
-
|
|
3948
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({ msg: "connection already disconnected" });
|
|
3875
3949
|
return;
|
|
3876
3950
|
}
|
|
3877
3951
|
this.#disposed = true;
|
|
3878
|
-
|
|
3952
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "disposing actor conn" });
|
|
3879
3953
|
clearInterval(this.#keepNodeAliveInterval);
|
|
3880
3954
|
this.#abortController.abort();
|
|
3881
3955
|
this.#client[ACTOR_CONNS_SYMBOL].delete(this);
|
|
3882
3956
|
if (!this.#transport) {
|
|
3883
3957
|
} else if ("websocket" in this.#transport) {
|
|
3884
|
-
|
|
3958
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug("closing ws");
|
|
3885
3959
|
const ws = this.#transport.websocket;
|
|
3886
3960
|
if (ws.readyState === 2 || ws.readyState === 3) {
|
|
3887
|
-
|
|
3961
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "ws already closed or closing" });
|
|
3888
3962
|
} else {
|
|
3889
|
-
const { promise, resolve } =
|
|
3963
|
+
const { promise, resolve } = _chunkC56XVVV4cjs.promiseWithResolvers.call(void 0, );
|
|
3890
3964
|
ws.addEventListener("close", () => {
|
|
3891
|
-
|
|
3965
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug({ msg: "ws closed" });
|
|
3892
3966
|
resolve(void 0);
|
|
3893
3967
|
});
|
|
3894
3968
|
ws.close(1e3, "Normal closure");
|
|
3895
3969
|
await promise;
|
|
3896
3970
|
}
|
|
3897
3971
|
} else if ("sse" in this.#transport) {
|
|
3898
|
-
|
|
3972
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).debug("closing sse");
|
|
3899
3973
|
if (this.#connectionId && this.#connectionToken) {
|
|
3900
3974
|
try {
|
|
3901
3975
|
await sendHttpRequest({
|
|
3902
3976
|
url: "http://actor/connections/close",
|
|
3903
3977
|
method: "POST",
|
|
3904
3978
|
headers: {
|
|
3905
|
-
[
|
|
3906
|
-
[
|
|
3979
|
+
[_chunk3JYSUFETcjs.HEADER_CONN_ID]: this.#connectionId,
|
|
3980
|
+
[_chunk3JYSUFETcjs.HEADER_CONN_TOKEN]: this.#connectionToken
|
|
3907
3981
|
},
|
|
3908
3982
|
encoding: this.#encoding,
|
|
3909
3983
|
skipParseResponse: true,
|
|
@@ -3911,11 +3985,11 @@ var ActorConnRaw = class {
|
|
|
3911
3985
|
this.#driver,
|
|
3912
3986
|
this.#actorId
|
|
3913
3987
|
),
|
|
3914
|
-
requestVersionedDataHandler:
|
|
3915
|
-
responseVersionedDataHandler:
|
|
3988
|
+
requestVersionedDataHandler: _chunkJMLTKMJ7cjs.TO_SERVER_VERSIONED,
|
|
3989
|
+
responseVersionedDataHandler: _chunkJMLTKMJ7cjs.TO_CLIENT_VERSIONED
|
|
3916
3990
|
});
|
|
3917
3991
|
} catch (error) {
|
|
3918
|
-
|
|
3992
|
+
_chunkNCUALX2Qcjs.logger.call(void 0, ).warn({
|
|
3919
3993
|
msg: "failed to send close request",
|
|
3920
3994
|
error
|
|
3921
3995
|
});
|
|
@@ -3923,7 +3997,7 @@ var ActorConnRaw = class {
|
|
|
3923
3997
|
}
|
|
3924
3998
|
this.#transport.sse.close();
|
|
3925
3999
|
} else {
|
|
3926
|
-
|
|
4000
|
+
_chunkC56XVVV4cjs.assertUnreachable.call(void 0, this.#transport);
|
|
3927
4001
|
}
|
|
3928
4002
|
this.#transport = void 0;
|
|
3929
4003
|
}
|
|
@@ -3949,7 +4023,7 @@ var ActorConnRaw = class {
|
|
|
3949
4023
|
|
|
3950
4024
|
// src/remote-manager-driver/log.ts
|
|
3951
4025
|
function logger2() {
|
|
3952
|
-
return
|
|
4026
|
+
return _chunkC56XVVV4cjs.getLogger.call(void 0, "remote-manager-driver");
|
|
3953
4027
|
}
|
|
3954
4028
|
|
|
3955
4029
|
// src/remote-manager-driver/api-utils.ts
|
|
@@ -3966,7 +4040,7 @@ function getEndpoint(config) {
|
|
|
3966
4040
|
}
|
|
3967
4041
|
async function apiCall(config, method, path, body) {
|
|
3968
4042
|
const endpoint = getEndpoint(config);
|
|
3969
|
-
const url =
|
|
4043
|
+
const url = _chunkC56XVVV4cjs.combineUrlPath.call(void 0, endpoint, path, {
|
|
3970
4044
|
namespace: config.namespace
|
|
3971
4045
|
});
|
|
3972
4046
|
logger2().debug({ msg: "making api call", method, url });
|
|
@@ -3992,7 +4066,7 @@ async function apiCall(config, method, path, body) {
|
|
|
3992
4066
|
async function sendHttpRequestToActor(runConfig, actorId, actorRequest) {
|
|
3993
4067
|
const url = new URL(actorRequest.url);
|
|
3994
4068
|
const endpoint = getEndpoint(runConfig);
|
|
3995
|
-
const guardUrl =
|
|
4069
|
+
const guardUrl = _chunkC56XVVV4cjs.combineUrlPath.call(void 0,
|
|
3996
4070
|
endpoint,
|
|
3997
4071
|
`/gateway/${actorId}${url.pathname}${url.search}`
|
|
3998
4072
|
);
|
|
@@ -4033,16 +4107,16 @@ function buildGuardHeadersForHttp(runConfig, actorRequest, actorId) {
|
|
|
4033
4107
|
headers.set(key, value);
|
|
4034
4108
|
}
|
|
4035
4109
|
if (runConfig.token) {
|
|
4036
|
-
headers.set(
|
|
4110
|
+
headers.set(_chunk3JYSUFETcjs.HEADER_RIVET_TOKEN, runConfig.token);
|
|
4037
4111
|
}
|
|
4038
4112
|
return headers;
|
|
4039
4113
|
}
|
|
4040
4114
|
|
|
4041
4115
|
// src/remote-manager-driver/actor-websocket-client.ts
|
|
4042
4116
|
async function openWebSocketToActor(runConfig, path, actorId, encoding, params, connId, connToken) {
|
|
4043
|
-
const WebSocket2 = await
|
|
4117
|
+
const WebSocket2 = await _chunkNCUALX2Qcjs.importWebSocket.call(void 0, );
|
|
4044
4118
|
const endpoint = getEndpoint(runConfig);
|
|
4045
|
-
const guardUrl =
|
|
4119
|
+
const guardUrl = _chunkC56XVVV4cjs.combineUrlPath.call(void 0, endpoint, `/gateway/${actorId}${path}`);
|
|
4046
4120
|
logger2().debug({
|
|
4047
4121
|
msg: "opening websocket to actor via guard",
|
|
4048
4122
|
actorId,
|
|
@@ -4059,21 +4133,21 @@ async function openWebSocketToActor(runConfig, path, actorId, encoding, params,
|
|
|
4059
4133
|
}
|
|
4060
4134
|
function buildWebSocketProtocols(runConfig, encoding, params, connId, connToken) {
|
|
4061
4135
|
const protocols = [];
|
|
4062
|
-
protocols.push(
|
|
4063
|
-
protocols.push(`${
|
|
4136
|
+
protocols.push(_chunk3JYSUFETcjs.WS_PROTOCOL_STANDARD);
|
|
4137
|
+
protocols.push(`${_chunk3JYSUFETcjs.WS_PROTOCOL_ENCODING}${encoding}`);
|
|
4064
4138
|
if (runConfig.token) {
|
|
4065
|
-
protocols.push(`${
|
|
4139
|
+
protocols.push(`${_chunk3JYSUFETcjs.WS_PROTOCOL_TOKEN}${runConfig.token}`);
|
|
4066
4140
|
}
|
|
4067
4141
|
if (params) {
|
|
4068
4142
|
protocols.push(
|
|
4069
|
-
`${
|
|
4143
|
+
`${_chunk3JYSUFETcjs.WS_PROTOCOL_CONN_PARAMS}${encodeURIComponent(JSON.stringify(params))}`
|
|
4070
4144
|
);
|
|
4071
4145
|
}
|
|
4072
4146
|
if (connId) {
|
|
4073
|
-
protocols.push(`${
|
|
4147
|
+
protocols.push(`${_chunk3JYSUFETcjs.WS_PROTOCOL_CONN_ID}${connId}`);
|
|
4074
4148
|
}
|
|
4075
4149
|
if (connToken) {
|
|
4076
|
-
protocols.push(`${
|
|
4150
|
+
protocols.push(`${_chunk3JYSUFETcjs.WS_PROTOCOL_CONN_TOKEN}${connToken}`);
|
|
4077
4151
|
}
|
|
4078
4152
|
return protocols;
|
|
4079
4153
|
}
|
|
@@ -4134,7 +4208,7 @@ async function updateRunnerConfig(config, runnerName, request) {
|
|
|
4134
4208
|
|
|
4135
4209
|
// src/remote-manager-driver/ws-proxy.ts
|
|
4136
4210
|
async function createWebSocketProxy(c, targetUrl, protocols) {
|
|
4137
|
-
const WebSocket2 = await
|
|
4211
|
+
const WebSocket2 = await _chunkNCUALX2Qcjs.importWebSocket.call(void 0, );
|
|
4138
4212
|
const state = {};
|
|
4139
4213
|
return {
|
|
4140
4214
|
onOpen: async (event, clientWs) => {
|
|
@@ -4197,7 +4271,7 @@ async function createWebSocketProxy(c, targetUrl, protocols) {
|
|
|
4197
4271
|
logger2().error({
|
|
4198
4272
|
msg: "target websocket error",
|
|
4199
4273
|
targetUrl,
|
|
4200
|
-
error:
|
|
4274
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
4201
4275
|
});
|
|
4202
4276
|
closeWebSocketIfOpen(clientWs, 1011, "Target WebSocket error");
|
|
4203
4277
|
});
|
|
@@ -4277,7 +4351,7 @@ var RemoteManagerDriver = class {
|
|
|
4277
4351
|
#config;
|
|
4278
4352
|
#metadataPromise;
|
|
4279
4353
|
constructor(runConfig) {
|
|
4280
|
-
if (
|
|
4354
|
+
if (_chunkC56XVVV4cjs.getEnvUniversal.call(void 0, "NEXT_PHASE") === "phase-production-build") {
|
|
4281
4355
|
logger2().info(
|
|
4282
4356
|
"detected next.js build phase, disabling health check"
|
|
4283
4357
|
);
|
|
@@ -4320,7 +4394,7 @@ var RemoteManagerDriver = class {
|
|
|
4320
4394
|
logger2().error({
|
|
4321
4395
|
msg: "health check failed, validate the Rivet endpoint is configured correctly",
|
|
4322
4396
|
endpoint,
|
|
4323
|
-
error:
|
|
4397
|
+
error: _chunkC56XVVV4cjs.stringifyError.call(void 0, error)
|
|
4324
4398
|
});
|
|
4325
4399
|
}
|
|
4326
4400
|
})();
|
|
@@ -4403,7 +4477,7 @@ var RemoteManagerDriver = class {
|
|
|
4403
4477
|
name,
|
|
4404
4478
|
key: serializeActorKey(key),
|
|
4405
4479
|
runner_name_selector: this.#config.runnerName,
|
|
4406
|
-
input: actorInput ?
|
|
4480
|
+
input: actorInput ? _chunk3JYSUFETcjs.uint8ArrayToBase64.call(void 0, cbor6.encode(actorInput)) : void 0,
|
|
4407
4481
|
crash_policy: "sleep"
|
|
4408
4482
|
});
|
|
4409
4483
|
const actorId = actor.actor_id;
|
|
@@ -4436,7 +4510,7 @@ var RemoteManagerDriver = class {
|
|
|
4436
4510
|
name,
|
|
4437
4511
|
runner_name_selector: this.#config.runnerName,
|
|
4438
4512
|
key: serializeActorKey(key),
|
|
4439
|
-
input: input ?
|
|
4513
|
+
input: input ? _chunk3JYSUFETcjs.uint8ArrayToBase64.call(void 0, cbor6.encode(input)) : void 0,
|
|
4440
4514
|
crash_policy: "sleep"
|
|
4441
4515
|
});
|
|
4442
4516
|
const actorId = result.actor.actor_id;
|
|
@@ -4497,7 +4571,7 @@ var RemoteManagerDriver = class {
|
|
|
4497
4571
|
const upgradeWebSocket = (_b = (_a = this.#config).getUpgradeWebSocket) == null ? void 0 : _b.call(_a);
|
|
4498
4572
|
_invariant2.default.call(void 0, upgradeWebSocket, "missing getUpgradeWebSocket");
|
|
4499
4573
|
const endpoint = getEndpoint(this.#config);
|
|
4500
|
-
const guardUrl =
|
|
4574
|
+
const guardUrl = _chunkC56XVVV4cjs.combineUrlPath.call(void 0, endpoint, path);
|
|
4501
4575
|
const wsGuardUrl = guardUrl.replace("http://", "ws://");
|
|
4502
4576
|
logger2().debug({
|
|
4503
4577
|
msg: "forwarding websocket to actor via guard",
|
|
@@ -4513,13 +4587,13 @@ var RemoteManagerDriver = class {
|
|
|
4513
4587
|
connToken
|
|
4514
4588
|
);
|
|
4515
4589
|
const args = await createWebSocketProxy(c, wsGuardUrl, protocols);
|
|
4516
|
-
return await upgradeWebSocket(() => args)(c,
|
|
4590
|
+
return await upgradeWebSocket(() => args)(c, _chunkC56XVVV4cjs.noopNext.call(void 0, ));
|
|
4517
4591
|
}
|
|
4518
4592
|
displayInformation() {
|
|
4519
4593
|
return { name: "Remote", properties: {} };
|
|
4520
4594
|
}
|
|
4521
4595
|
getOrCreateInspectorAccessToken() {
|
|
4522
|
-
return
|
|
4596
|
+
return _chunk3JYSUFETcjs.generateRandomString.call(void 0, );
|
|
4523
4597
|
}
|
|
4524
4598
|
};
|
|
4525
4599
|
|
|
@@ -4545,5 +4619,5 @@ var RemoteManagerDriver = class {
|
|
|
4545
4619
|
|
|
4546
4620
|
|
|
4547
4621
|
|
|
4548
|
-
exports.
|
|
4549
|
-
//# sourceMappingURL=chunk-
|
|
4622
|
+
exports.createActorInspectorRouter = createActorInspectorRouter; exports.serializeActorKey = serializeActorKey; exports.deserializeActorKey = deserializeActorKey; exports.PERSIST_SYMBOL = PERSIST_SYMBOL; exports.generateConnId = generateConnId; exports.generateConnToken = generateConnToken; exports.generateConnRequestId = generateConnRequestId; exports.ActorDefinition = ActorDefinition; exports.lookupInRegistry = lookupInRegistry; exports.ActorClientError = ActorClientError; exports.InternalError = InternalError2; exports.ManagerError = ManagerError; exports.MalformedResponseMessage = MalformedResponseMessage; exports.ActorError = ActorError; exports.getEndpoint = getEndpoint; exports.ActorConnRaw = ActorConnRaw; exports.ActorHandleRaw = ActorHandleRaw; exports.createClientWithDriver = createClientWithDriver; exports.getDatacenters = getDatacenters; exports.updateRunnerConfig = updateRunnerConfig; exports.RemoteManagerDriver = RemoteManagerDriver;
|
|
4623
|
+
//# sourceMappingURL=chunk-D6PCH7FR.cjs.map
|