rivetkit 2.0.5 → 2.0.7-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schemas/actor-persist/v1.ts +0 -6
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.cts +28 -0
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.ts +28 -0
- package/dist/tsup/{chunk-5YTI25C3.cjs → chunk-3MBP4WNC.cjs} +7 -7
- package/dist/tsup/{chunk-5YTI25C3.cjs.map → chunk-3MBP4WNC.cjs.map} +1 -1
- package/dist/tsup/chunk-3Y45CIF4.cjs +3726 -0
- package/dist/tsup/chunk-3Y45CIF4.cjs.map +1 -0
- package/dist/tsup/chunk-4GP7BZSR.js +102 -0
- package/dist/tsup/chunk-4GP7BZSR.js.map +1 -0
- package/dist/tsup/chunk-5ZOHIKWG.cjs +4071 -0
- package/dist/tsup/chunk-5ZOHIKWG.cjs.map +1 -0
- package/dist/tsup/{chunk-WADSS5X4.cjs → chunk-6EUWRXLT.cjs} +21 -7
- package/dist/tsup/chunk-6EUWRXLT.cjs.map +1 -0
- package/dist/tsup/{chunk-D7NWUCRK.cjs → chunk-6OVKCDSH.cjs} +6 -6
- package/dist/tsup/{chunk-D7NWUCRK.cjs.map → chunk-6OVKCDSH.cjs.map} +1 -1
- package/dist/tsup/{chunk-I5VTWPHW.js → chunk-7N56ZUC7.js} +3 -3
- package/dist/tsup/{chunk-LZIBTLEY.cjs → chunk-B3TLRM4Q.cjs} +13 -25
- package/dist/tsup/chunk-B3TLRM4Q.cjs.map +1 -0
- package/dist/tsup/chunk-BW5DPM6Z.js +4071 -0
- package/dist/tsup/chunk-BW5DPM6Z.js.map +1 -0
- package/dist/tsup/chunk-DFS77KAA.cjs +1046 -0
- package/dist/tsup/chunk-DFS77KAA.cjs.map +1 -0
- package/dist/tsup/{chunk-PG3K2LI7.js → chunk-E4UVJKSV.js} +2 -2
- package/dist/tsup/chunk-G4ABMAQY.cjs +102 -0
- package/dist/tsup/chunk-G4ABMAQY.cjs.map +1 -0
- package/dist/tsup/{chunk-CKA54YQN.js → chunk-GZVBFXBI.js} +3 -15
- package/dist/tsup/chunk-GZVBFXBI.js.map +1 -0
- package/dist/tsup/chunk-HPT3I7UU.js +3726 -0
- package/dist/tsup/chunk-HPT3I7UU.js.map +1 -0
- package/dist/tsup/chunk-JD54PXWP.js +1046 -0
- package/dist/tsup/chunk-JD54PXWP.js.map +1 -0
- package/dist/tsup/{chunk-PHSQJ6QI.cjs → chunk-K4ENQCC4.cjs} +3 -3
- package/dist/tsup/{chunk-PHSQJ6QI.cjs.map → chunk-K4ENQCC4.cjs.map} +1 -1
- package/dist/tsup/{chunk-WNGOBAA7.js → chunk-PUSQNDJG.js} +2 -2
- package/dist/tsup/{chunk-CFFKMUYH.js → chunk-RVP5RUSC.js} +20 -6
- package/dist/tsup/chunk-RVP5RUSC.js.map +1 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs +259 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs.map +1 -0
- package/dist/tsup/{chunk-YW6Y6VNE.js → chunk-SBKRVQS2.js} +9 -5
- package/dist/tsup/chunk-SBKRVQS2.js.map +1 -0
- package/dist/tsup/{chunk-FGFT4FVX.cjs → chunk-TZGUSEIJ.cjs} +14 -10
- package/dist/tsup/chunk-TZGUSEIJ.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4XQYPM.js +259 -0
- package/dist/tsup/chunk-YQ4XQYPM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +7 -8
- package/dist/tsup/client/mod.d.ts +7 -8
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{connection-BvE-Oq7t.d.ts → conn-DCSQgIlw.d.ts} +1605 -1353
- package/dist/tsup/{connection-DTzmWwU5.d.cts → conn-DdzHTm2E.d.cts} +1605 -1353
- package/dist/tsup/driver-helpers/mod.cjs +31 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +7 -8
- package/dist/tsup/driver-helpers/mod.d.ts +7 -8
- package/dist/tsup/driver-helpers/mod.js +33 -7
- package/dist/tsup/driver-test-suite/mod.cjs +319 -216
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +7 -7
- package/dist/tsup/driver-test-suite/mod.d.ts +7 -7
- package/dist/tsup/driver-test-suite/mod.js +588 -485
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +17 -5
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +34 -7
- package/dist/tsup/inspector/mod.d.ts +34 -7
- package/dist/tsup/inspector/mod.js +20 -8
- package/dist/tsup/mod.cjs +10 -17
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +56 -9
- package/dist/tsup/mod.d.ts +56 -9
- package/dist/tsup/mod.js +17 -24
- package/dist/tsup/test/mod.cjs +11 -9
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -7
- package/dist/tsup/test/mod.d.ts +6 -7
- package/dist/tsup/test/mod.js +10 -8
- package/dist/tsup/utils.cjs +4 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +11 -1
- package/dist/tsup/utils.d.ts +11 -1
- package/dist/tsup/utils.js +3 -1
- package/package.json +8 -4
- package/src/actor/action.ts +1 -1
- package/src/actor/config.ts +1 -1
- package/src/actor/conn-drivers.ts +205 -0
- package/src/actor/conn-socket.ts +6 -0
- package/src/actor/{connection.ts → conn.ts} +78 -84
- package/src/actor/context.ts +1 -1
- package/src/actor/driver.ts +4 -43
- package/src/actor/instance.ts +162 -86
- package/src/actor/mod.ts +6 -14
- package/src/actor/persisted.ts +2 -5
- package/src/actor/protocol/old.ts +1 -1
- package/src/actor/router-endpoints.ts +147 -138
- package/src/actor/router.ts +89 -52
- package/src/actor/utils.ts +5 -1
- package/src/client/actor-conn.ts +163 -31
- package/src/client/actor-handle.ts +0 -1
- package/src/client/client.ts +2 -2
- package/src/client/config.ts +7 -0
- package/src/client/raw-utils.ts +1 -1
- package/src/client/utils.ts +1 -1
- package/src/common/actor-router-consts.ts +59 -0
- package/src/common/router.ts +2 -1
- package/src/common/versioned-data.ts +5 -5
- package/src/driver-helpers/mod.ts +15 -2
- package/src/driver-test-suite/mod.ts +11 -2
- package/src/driver-test-suite/test-inline-client-driver.ts +40 -22
- package/src/driver-test-suite/tests/actor-conn-state.ts +66 -22
- package/src/driver-test-suite/tests/actor-conn.ts +65 -126
- package/src/driver-test-suite/tests/actor-reconnect.ts +160 -0
- package/src/driver-test-suite/tests/actor-sleep.ts +0 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +0 -35
- package/src/driver-test-suite/utils.ts +8 -3
- package/src/drivers/default.ts +8 -7
- package/src/drivers/engine/actor-driver.ts +67 -44
- package/src/drivers/engine/config.ts +4 -0
- package/src/drivers/file-system/actor.ts +0 -6
- package/src/drivers/file-system/global-state.ts +3 -14
- package/src/drivers/file-system/manager.ts +12 -8
- package/src/inspector/actor.ts +4 -3
- package/src/inspector/config.ts +10 -1
- package/src/inspector/mod.ts +1 -0
- package/src/inspector/utils.ts +23 -4
- package/src/manager/driver.ts +12 -2
- package/src/manager/gateway.ts +407 -0
- package/src/manager/protocol/query.ts +1 -1
- package/src/manager/router.ts +269 -468
- package/src/manager-api/actors.ts +61 -0
- package/src/manager-api/common.ts +4 -0
- package/src/mod.ts +1 -1
- package/src/registry/mod.ts +126 -12
- package/src/registry/serve.ts +8 -3
- package/src/remote-manager-driver/actor-http-client.ts +30 -19
- package/src/remote-manager-driver/actor-websocket-client.ts +45 -18
- package/src/remote-manager-driver/api-endpoints.ts +19 -21
- package/src/remote-manager-driver/api-utils.ts +10 -1
- package/src/remote-manager-driver/mod.ts +53 -53
- package/src/remote-manager-driver/ws-proxy.ts +2 -9
- package/src/test/mod.ts +6 -2
- package/src/utils.ts +21 -2
- package/dist/tsup/chunk-2MD57QF4.js +0 -1794
- package/dist/tsup/chunk-2MD57QF4.js.map +0 -1
- package/dist/tsup/chunk-B2QGJGZQ.js +0 -338
- package/dist/tsup/chunk-B2QGJGZQ.js.map +0 -1
- package/dist/tsup/chunk-CFFKMUYH.js.map +0 -1
- package/dist/tsup/chunk-CKA54YQN.js.map +0 -1
- package/dist/tsup/chunk-FGFT4FVX.cjs.map +0 -1
- package/dist/tsup/chunk-IRMBWX36.cjs +0 -1794
- package/dist/tsup/chunk-IRMBWX36.cjs.map +0 -1
- package/dist/tsup/chunk-L7QRXNWP.js +0 -6562
- package/dist/tsup/chunk-L7QRXNWP.js.map +0 -1
- package/dist/tsup/chunk-LZIBTLEY.cjs.map +0 -1
- package/dist/tsup/chunk-MRZS2J4X.cjs +0 -6562
- package/dist/tsup/chunk-MRZS2J4X.cjs.map +0 -1
- package/dist/tsup/chunk-RM2SVURR.cjs +0 -338
- package/dist/tsup/chunk-RM2SVURR.cjs.map +0 -1
- package/dist/tsup/chunk-WADSS5X4.cjs.map +0 -1
- package/dist/tsup/chunk-YW6Y6VNE.js.map +0 -1
- package/dist/tsup/common-CXCe7s6i.d.cts +0 -218
- package/dist/tsup/common-CXCe7s6i.d.ts +0 -218
- package/dist/tsup/router-endpoints-CctffZNL.d.cts +0 -65
- package/dist/tsup/router-endpoints-DFm1BglJ.d.ts +0 -65
- package/src/actor/generic-conn-driver.ts +0 -246
- package/src/common/fake-event-source.ts +0 -267
- package/src/manager-api/routes/actors-create.ts +0 -16
- package/src/manager-api/routes/actors-delete.ts +0 -4
- package/src/manager-api/routes/actors-get-by-id.ts +0 -7
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +0 -29
- package/src/manager-api/routes/actors-get.ts +0 -7
- package/src/manager-api/routes/common.ts +0 -18
- /package/dist/tsup/{chunk-I5VTWPHW.js.map → chunk-7N56ZUC7.js.map} +0 -0
- /package/dist/tsup/{chunk-PG3K2LI7.js.map → chunk-E4UVJKSV.js.map} +0 -0
- /package/dist/tsup/{chunk-WNGOBAA7.js.map → chunk-PUSQNDJG.js.map} +0 -0
package/dist/tsup/test/mod.cjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-
|
|
9
|
-
require('../chunk-
|
|
10
|
-
require('../chunk-
|
|
11
|
-
require('../chunk-
|
|
4
|
+
var _chunkTZGUSEIJcjs = require('../chunk-TZGUSEIJ.cjs');
|
|
5
|
+
require('../chunk-3Y45CIF4.cjs');
|
|
6
|
+
require('../chunk-G4ABMAQY.cjs');
|
|
7
|
+
require('../chunk-5ZOHIKWG.cjs');
|
|
8
|
+
require('../chunk-B3TLRM4Q.cjs');
|
|
9
|
+
require('../chunk-K4ENQCC4.cjs');
|
|
10
|
+
require('../chunk-DFS77KAA.cjs');
|
|
11
|
+
require('../chunk-SAZCNSVY.cjs');
|
|
12
|
+
require('../chunk-3MBP4WNC.cjs');
|
|
13
|
+
require('../chunk-6EUWRXLT.cjs');
|
|
12
14
|
require('../chunk-5QGQK44L.cjs');
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
|
|
16
|
-
exports.getPort =
|
|
18
|
+
exports.getPort = _chunkTZGUSEIJcjs.getPort; exports.setupTest = _chunkTZGUSEIJcjs.setupTest;
|
|
17
19
|
//# sourceMappingURL=mod.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/test/mod.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,6FAAC","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/test/mod.cjs"}
|
|
1
|
+
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/test/mod.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,6FAAC","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/test/mod.cjs"}
|
package/dist/tsup/test/mod.d.cts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import 'hono';
|
|
2
|
+
import { K as Registry, C as Client } from '../conn-DdzHTm2E.cjs';
|
|
3
|
+
import 'hono/streaming';
|
|
4
|
+
import 'hono/ws';
|
|
6
5
|
import '../utils.cjs';
|
|
7
6
|
import '../utils-fwx3o3K9.cjs';
|
|
7
|
+
import 'hono';
|
|
8
8
|
import 'hono/utils/http-status';
|
|
9
|
+
import 'zod';
|
|
10
|
+
import 'pino';
|
|
9
11
|
import 'nanoevents';
|
|
10
|
-
import '../common-CXCe7s6i.cjs';
|
|
11
12
|
import 'zod/v4';
|
|
12
|
-
import 'hono/streaming';
|
|
13
|
-
import 'hono/ws';
|
|
14
13
|
|
|
15
14
|
interface SetupTestResult<A extends Registry<any>> {
|
|
16
15
|
client: Client<A>;
|
package/dist/tsup/test/mod.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import 'hono';
|
|
2
|
+
import { K as Registry, C as Client } from '../conn-DCSQgIlw.js';
|
|
3
|
+
import 'hono/streaming';
|
|
4
|
+
import 'hono/ws';
|
|
6
5
|
import '../utils.js';
|
|
7
6
|
import '../utils-fwx3o3K9.js';
|
|
7
|
+
import 'hono';
|
|
8
8
|
import 'hono/utils/http-status';
|
|
9
|
+
import 'zod';
|
|
10
|
+
import 'pino';
|
|
9
11
|
import 'nanoevents';
|
|
10
|
-
import '../common-CXCe7s6i.js';
|
|
11
12
|
import 'zod/v4';
|
|
12
|
-
import 'hono/streaming';
|
|
13
|
-
import 'hono/ws';
|
|
14
13
|
|
|
15
14
|
interface SetupTestResult<A extends Registry<any>> {
|
|
16
15
|
client: Client<A>;
|
package/dist/tsup/test/mod.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getPort,
|
|
3
3
|
setupTest
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-SBKRVQS2.js";
|
|
5
|
+
import "../chunk-HPT3I7UU.js";
|
|
6
|
+
import "../chunk-4GP7BZSR.js";
|
|
7
|
+
import "../chunk-BW5DPM6Z.js";
|
|
8
|
+
import "../chunk-GZVBFXBI.js";
|
|
9
|
+
import "../chunk-E4UVJKSV.js";
|
|
10
|
+
import "../chunk-JD54PXWP.js";
|
|
11
|
+
import "../chunk-YQ4XQYPM.js";
|
|
12
|
+
import "../chunk-PUSQNDJG.js";
|
|
13
|
+
import "../chunk-RVP5RUSC.js";
|
|
12
14
|
import "../chunk-YPZFLUO6.js";
|
|
13
15
|
export {
|
|
14
16
|
getPort,
|
package/dist/tsup/utils.cjs
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
var _chunk6EUWRXLTcjs = require('./chunk-6EUWRXLT.cjs');
|
|
14
15
|
require('./chunk-5QGQK44L.cjs');
|
|
15
16
|
|
|
16
17
|
|
|
@@ -24,5 +25,6 @@ require('./chunk-5QGQK44L.cjs');
|
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
exports.SinglePromiseQueue = _chunk6EUWRXLTcjs.SinglePromiseQueue; exports.VERSION = _chunk6EUWRXLTcjs.VERSION; exports.assertUnreachable = _chunk6EUWRXLTcjs.assertUnreachable; exports.bufferToArrayBuffer = _chunk6EUWRXLTcjs.bufferToArrayBuffer; exports.combineUrlPath = _chunk6EUWRXLTcjs.combineUrlPath; exports.dbg = _chunk6EUWRXLTcjs.dbg; exports.getEnvUniversal = _chunk6EUWRXLTcjs.getEnvUniversal; exports.httpUserAgent = _chunk6EUWRXLTcjs.httpUserAgent; exports.promiseWithResolvers = _chunk6EUWRXLTcjs.promiseWithResolvers; exports.setLongTimeout = _chunk6EUWRXLTcjs.setLongTimeout; exports.stringifyError = _chunk6EUWRXLTcjs.stringifyError; exports.toUint8Array = _chunk6EUWRXLTcjs.toUint8Array;
|
|
28
30
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/tsup/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/utils.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF
|
|
1
|
+
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/utils.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,+rBAAC","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/utils.cjs"}
|
package/dist/tsup/utils.d.cts
CHANGED
|
@@ -18,6 +18,16 @@ declare function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array;
|
|
|
18
18
|
type LongTimeoutHandle = {
|
|
19
19
|
abort: () => void;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Polyfill for Promise.withResolvers().
|
|
23
|
+
*
|
|
24
|
+
* This is specifically for Cloudflare Workers. Their implementation of Promise.withResolvers does not work correctly.
|
|
25
|
+
*/
|
|
26
|
+
declare function promiseWithResolvers<T>(): {
|
|
27
|
+
promise: Promise<T>;
|
|
28
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
29
|
+
reject: (reason?: any) => void;
|
|
30
|
+
};
|
|
21
31
|
declare function setLongTimeout(listener: () => void, after: number): LongTimeoutHandle;
|
|
22
32
|
/**
|
|
23
33
|
* A tiny utility that coalesces/enqueues async operations so only the latest
|
|
@@ -50,4 +60,4 @@ declare function bufferToArrayBuffer(buf: Buffer | Uint8Array): ArrayBuffer;
|
|
|
50
60
|
*/
|
|
51
61
|
declare function combineUrlPath(endpoint: string, path: string, queryParams?: Record<string, string | undefined>): string;
|
|
52
62
|
|
|
53
|
-
export { type LongTimeoutHandle, SinglePromiseQueue, type UpgradeWebSocket, VERSION, bufferToArrayBuffer, combineUrlPath, dbg, getEnvUniversal, httpUserAgent, setLongTimeout, toUint8Array };
|
|
63
|
+
export { type LongTimeoutHandle, SinglePromiseQueue, type UpgradeWebSocket, VERSION, bufferToArrayBuffer, combineUrlPath, dbg, getEnvUniversal, httpUserAgent, promiseWithResolvers, setLongTimeout, toUint8Array };
|
package/dist/tsup/utils.d.ts
CHANGED
|
@@ -18,6 +18,16 @@ declare function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array;
|
|
|
18
18
|
type LongTimeoutHandle = {
|
|
19
19
|
abort: () => void;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Polyfill for Promise.withResolvers().
|
|
23
|
+
*
|
|
24
|
+
* This is specifically for Cloudflare Workers. Their implementation of Promise.withResolvers does not work correctly.
|
|
25
|
+
*/
|
|
26
|
+
declare function promiseWithResolvers<T>(): {
|
|
27
|
+
promise: Promise<T>;
|
|
28
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
29
|
+
reject: (reason?: any) => void;
|
|
30
|
+
};
|
|
21
31
|
declare function setLongTimeout(listener: () => void, after: number): LongTimeoutHandle;
|
|
22
32
|
/**
|
|
23
33
|
* A tiny utility that coalesces/enqueues async operations so only the latest
|
|
@@ -50,4 +60,4 @@ declare function bufferToArrayBuffer(buf: Buffer | Uint8Array): ArrayBuffer;
|
|
|
50
60
|
*/
|
|
51
61
|
declare function combineUrlPath(endpoint: string, path: string, queryParams?: Record<string, string | undefined>): string;
|
|
52
62
|
|
|
53
|
-
export { type LongTimeoutHandle, SinglePromiseQueue, type UpgradeWebSocket, VERSION, bufferToArrayBuffer, combineUrlPath, dbg, getEnvUniversal, httpUserAgent, setLongTimeout, toUint8Array };
|
|
63
|
+
export { type LongTimeoutHandle, SinglePromiseQueue, type UpgradeWebSocket, VERSION, bufferToArrayBuffer, combineUrlPath, dbg, getEnvUniversal, httpUserAgent, promiseWithResolvers, setLongTimeout, toUint8Array };
|
package/dist/tsup/utils.js
CHANGED
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
dbg,
|
|
8
8
|
getEnvUniversal,
|
|
9
9
|
httpUserAgent,
|
|
10
|
+
promiseWithResolvers,
|
|
10
11
|
setLongTimeout,
|
|
11
12
|
stringifyError,
|
|
12
13
|
toUint8Array
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-RVP5RUSC.js";
|
|
14
15
|
import "./chunk-YPZFLUO6.js";
|
|
15
16
|
export {
|
|
16
17
|
SinglePromiseQueue,
|
|
@@ -21,6 +22,7 @@ export {
|
|
|
21
22
|
dbg,
|
|
22
23
|
getEnvUniversal,
|
|
23
24
|
httpUserAgent,
|
|
25
|
+
promiseWithResolvers,
|
|
24
26
|
setLongTimeout,
|
|
25
27
|
stringifyError,
|
|
26
28
|
toUint8Array
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rivetkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7-rc.1",
|
|
4
4
|
"description": "Lightweight libraries for building stateful actors on edge platforms",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -147,12 +147,15 @@
|
|
|
147
147
|
"engines": {
|
|
148
148
|
"node": ">=22.0.0"
|
|
149
149
|
},
|
|
150
|
-
"sideEffects":
|
|
150
|
+
"sideEffects": [
|
|
151
|
+
"./dist/tsup/chunk-*.js",
|
|
152
|
+
"./dist/tsup/chunk-*.cjs"
|
|
153
|
+
],
|
|
151
154
|
"dependencies": {
|
|
152
155
|
"@bare-ts/lib": "~0.3.0",
|
|
153
156
|
"@hono/standard-validator": "^0.1.3",
|
|
154
157
|
"@hono/zod-openapi": "^0.19.10",
|
|
155
|
-
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@
|
|
158
|
+
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@3002",
|
|
156
159
|
"@rivetkit/fast-json-patch": "^3.1.2",
|
|
157
160
|
"cbor-x": "^1.6.0",
|
|
158
161
|
"hono": "^4.7.0",
|
|
@@ -177,7 +180,8 @@
|
|
|
177
180
|
"tsx": "^4.19.4",
|
|
178
181
|
"typescript": "^5.7.3",
|
|
179
182
|
"vitest": "^3.1.1",
|
|
180
|
-
"ws": "^8.18.1"
|
|
183
|
+
"ws": "^8.18.1",
|
|
184
|
+
"bufferutil": "^4.0.9"
|
|
181
185
|
},
|
|
182
186
|
"peerDependencies": {
|
|
183
187
|
"@hono/node-server": "^1.14.0",
|
package/src/actor/action.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ActorKey } from "@/actor/mod";
|
|
|
2
2
|
import type { Client } from "@/client/client";
|
|
3
3
|
import type { Logger } from "@/common/log";
|
|
4
4
|
import type { Registry } from "@/registry/mod";
|
|
5
|
-
import type { Conn, ConnId } from "./
|
|
5
|
+
import type { Conn, ConnId } from "./conn";
|
|
6
6
|
import type { ActorContext } from "./context";
|
|
7
7
|
import type { AnyDatabaseProvider, InferDatabaseClient } from "./database";
|
|
8
8
|
import type { SaveStateOptions } from "./instance";
|
package/src/actor/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { UniversalWebSocket } from "@/common/websocket-interface";
|
|
3
3
|
import type { ActionContext } from "./action";
|
|
4
|
-
import type { Conn } from "./
|
|
4
|
+
import type { Conn } from "./conn";
|
|
5
5
|
import type { ActorContext } from "./context";
|
|
6
6
|
import type { AnyDatabaseProvider } from "./database";
|
|
7
7
|
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { SSEStreamingApi } from "hono/streaming";
|
|
2
|
+
import type { WSContext } from "hono/ws";
|
|
3
|
+
import type { WebSocket } from "ws";
|
|
4
|
+
import type { AnyConn } from "@/actor/conn";
|
|
5
|
+
import type { AnyActorInstance } from "@/actor/instance";
|
|
6
|
+
import type { CachedSerializer, Encoding } from "@/actor/protocol/serde";
|
|
7
|
+
import { encodeDataToString } from "@/actor/protocol/serde";
|
|
8
|
+
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
9
|
+
import { assertUnreachable, type promiseWithResolvers } from "@/utils";
|
|
10
|
+
|
|
11
|
+
export enum ConnDriverKind {
|
|
12
|
+
WEBSOCKET = 0,
|
|
13
|
+
SSE = 1,
|
|
14
|
+
HTTP = 2,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export enum ConnReadyState {
|
|
18
|
+
UNKNOWN = -1,
|
|
19
|
+
CONNECTING = 0,
|
|
20
|
+
OPEN = 1,
|
|
21
|
+
CLOSING = 2,
|
|
22
|
+
CLOSED = 3,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ConnDriverWebSocketState {
|
|
26
|
+
encoding: Encoding;
|
|
27
|
+
websocket: WSContext;
|
|
28
|
+
closePromise: ReturnType<typeof promiseWithResolvers<void>>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ConnDriverSseState {
|
|
32
|
+
encoding: Encoding;
|
|
33
|
+
stream: SSEStreamingApi;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ConnDriverHttpState = Record<never, never>;
|
|
37
|
+
|
|
38
|
+
export type ConnDriverState =
|
|
39
|
+
| { [ConnDriverKind.WEBSOCKET]: ConnDriverWebSocketState }
|
|
40
|
+
| { [ConnDriverKind.SSE]: ConnDriverSseState }
|
|
41
|
+
| { [ConnDriverKind.HTTP]: ConnDriverHttpState };
|
|
42
|
+
|
|
43
|
+
export interface ConnDriver<State> {
|
|
44
|
+
sendMessage?(
|
|
45
|
+
actor: AnyActorInstance,
|
|
46
|
+
conn: AnyConn,
|
|
47
|
+
state: State,
|
|
48
|
+
message: CachedSerializer<protocol.ToClient>,
|
|
49
|
+
): void;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* This returns a promise since we commonly disconnect at the end of a program, and not waiting will cause the socket to not close cleanly.
|
|
53
|
+
*/
|
|
54
|
+
disconnect(
|
|
55
|
+
actor: AnyActorInstance,
|
|
56
|
+
conn: AnyConn,
|
|
57
|
+
state: State,
|
|
58
|
+
reason?: string,
|
|
59
|
+
): Promise<void>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns the ready state of the connection.
|
|
63
|
+
* This is used to determine if the connection is ready to send messages, or if the connection is stale.
|
|
64
|
+
*/
|
|
65
|
+
getConnectionReadyState(
|
|
66
|
+
actor: AnyActorInstance,
|
|
67
|
+
conn: AnyConn,
|
|
68
|
+
state: State,
|
|
69
|
+
): ConnReadyState | undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// MARK: WebSocket
|
|
73
|
+
const WEBSOCKET_DRIVER: ConnDriver<ConnDriverWebSocketState> = {
|
|
74
|
+
sendMessage: (
|
|
75
|
+
actor: AnyActorInstance,
|
|
76
|
+
_conn: AnyConn,
|
|
77
|
+
state: ConnDriverWebSocketState,
|
|
78
|
+
message: CachedSerializer<protocol.ToClient>,
|
|
79
|
+
) => {
|
|
80
|
+
const serialized = message.serialize(state.encoding);
|
|
81
|
+
|
|
82
|
+
actor.rLog.debug({
|
|
83
|
+
msg: "sending websocket message",
|
|
84
|
+
encoding: state.encoding,
|
|
85
|
+
dataType: typeof serialized,
|
|
86
|
+
isUint8Array: serialized instanceof Uint8Array,
|
|
87
|
+
isArrayBuffer: serialized instanceof ArrayBuffer,
|
|
88
|
+
dataLength: (serialized as any).byteLength || (serialized as any).length,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Convert Uint8Array to ArrayBuffer for proper transmission
|
|
92
|
+
if (serialized instanceof Uint8Array) {
|
|
93
|
+
const buffer = serialized.buffer.slice(
|
|
94
|
+
serialized.byteOffset,
|
|
95
|
+
serialized.byteOffset + serialized.byteLength,
|
|
96
|
+
);
|
|
97
|
+
// Handle SharedArrayBuffer case
|
|
98
|
+
if (buffer instanceof SharedArrayBuffer) {
|
|
99
|
+
const arrayBuffer = new ArrayBuffer(buffer.byteLength);
|
|
100
|
+
new Uint8Array(arrayBuffer).set(new Uint8Array(buffer));
|
|
101
|
+
actor.rLog.debug({
|
|
102
|
+
msg: "converted SharedArrayBuffer to ArrayBuffer",
|
|
103
|
+
byteLength: arrayBuffer.byteLength,
|
|
104
|
+
});
|
|
105
|
+
state.websocket.send(arrayBuffer);
|
|
106
|
+
} else {
|
|
107
|
+
actor.rLog.debug({
|
|
108
|
+
msg: "sending ArrayBuffer",
|
|
109
|
+
byteLength: buffer.byteLength,
|
|
110
|
+
});
|
|
111
|
+
state.websocket.send(buffer);
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
actor.rLog.debug({
|
|
115
|
+
msg: "sending string data",
|
|
116
|
+
length: (serialized as string).length,
|
|
117
|
+
});
|
|
118
|
+
state.websocket.send(serialized);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
disconnect: async (
|
|
123
|
+
_actor: AnyActorInstance,
|
|
124
|
+
_conn: AnyConn,
|
|
125
|
+
state: ConnDriverWebSocketState,
|
|
126
|
+
reason?: string,
|
|
127
|
+
) => {
|
|
128
|
+
// Close socket
|
|
129
|
+
state.websocket.close(1000, reason);
|
|
130
|
+
|
|
131
|
+
// Create promise to wait for socket to close gracefully
|
|
132
|
+
await state.closePromise.promise;
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
getConnectionReadyState: (
|
|
136
|
+
_actor: AnyActorInstance,
|
|
137
|
+
_conn: AnyConn,
|
|
138
|
+
state: ConnDriverWebSocketState,
|
|
139
|
+
): ConnReadyState | undefined => {
|
|
140
|
+
return state.websocket.readyState;
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// MARK: SSE
|
|
145
|
+
const SSE_DRIVER: ConnDriver<ConnDriverSseState> = {
|
|
146
|
+
sendMessage: (
|
|
147
|
+
_actor: AnyActorInstance,
|
|
148
|
+
_conn: AnyConn,
|
|
149
|
+
state: ConnDriverSseState,
|
|
150
|
+
message: CachedSerializer<protocol.ToClient>,
|
|
151
|
+
) => {
|
|
152
|
+
state.stream.writeSSE({
|
|
153
|
+
data: encodeDataToString(message.serialize(state.encoding)),
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
disconnect: async (
|
|
158
|
+
_actor: AnyActorInstance,
|
|
159
|
+
_conn: AnyConn,
|
|
160
|
+
state: ConnDriverSseState,
|
|
161
|
+
_reason?: string,
|
|
162
|
+
) => {
|
|
163
|
+
state.stream.close();
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
getConnectionReadyState: (
|
|
167
|
+
_actor: AnyActorInstance,
|
|
168
|
+
_conn: AnyConn,
|
|
169
|
+
state: ConnDriverSseState,
|
|
170
|
+
): ConnReadyState | undefined => {
|
|
171
|
+
if (state.stream.aborted || state.stream.closed) {
|
|
172
|
+
return ConnReadyState.CLOSED;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return ConnReadyState.OPEN;
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// MARK: HTTP
|
|
180
|
+
const HTTP_DRIVER: ConnDriver<ConnDriverHttpState> = {
|
|
181
|
+
getConnectionReadyState(_actor, _conn) {
|
|
182
|
+
// TODO: This might not be the correct logic
|
|
183
|
+
return ConnReadyState.OPEN;
|
|
184
|
+
},
|
|
185
|
+
disconnect: async () => {
|
|
186
|
+
// Noop
|
|
187
|
+
// TODO: Abort the request
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** List of all connection drivers. */
|
|
192
|
+
export const CONN_DRIVERS: Record<ConnDriverKind, ConnDriver<unknown>> = {
|
|
193
|
+
[ConnDriverKind.WEBSOCKET]: WEBSOCKET_DRIVER,
|
|
194
|
+
[ConnDriverKind.SSE]: SSE_DRIVER,
|
|
195
|
+
[ConnDriverKind.HTTP]: HTTP_DRIVER,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export function getConnDriverKindFromState(
|
|
199
|
+
state: ConnDriverState,
|
|
200
|
+
): ConnDriverKind {
|
|
201
|
+
if (ConnDriverKind.WEBSOCKET in state) return ConnDriverKind.WEBSOCKET;
|
|
202
|
+
else if (ConnDriverKind.SSE in state) return ConnDriverKind.SSE;
|
|
203
|
+
else if (ConnDriverKind.HTTP in state) return ConnDriverKind.HTTP;
|
|
204
|
+
else assertUnreachable(state);
|
|
205
|
+
}
|