rivetkit 2.0.27 → 2.0.29-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/file-system-driver/v3.ts +167 -0
- package/dist/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/{chunk-TJ2PJ5C7.cjs → chunk-2Q6FJITJ.cjs} +3 -3
- package/dist/tsup/{chunk-TJ2PJ5C7.cjs.map → chunk-2Q6FJITJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-GUH2PNPG.js → chunk-5RN6O2RW.js} +3 -3
- package/dist/tsup/{chunk-F3SQLO3X.cjs → chunk-AJ36VBHL.cjs} +13 -12
- package/dist/tsup/chunk-AJ36VBHL.cjs.map +1 -0
- package/dist/tsup/{chunk-4GJQDTAG.cjs → chunk-BAEMOCS7.cjs} +666 -342
- package/dist/tsup/chunk-BAEMOCS7.cjs.map +1 -0
- package/dist/tsup/chunk-CGIRSKRW.js +891 -0
- package/dist/tsup/chunk-CGIRSKRW.js.map +1 -0
- package/dist/tsup/{chunk-BBTOBXEO.js → chunk-CHPLLKNL.js} +579 -103
- package/dist/tsup/chunk-CHPLLKNL.js.map +1 -0
- package/dist/tsup/{chunk-D7A47BVR.js → chunk-EU7VV5PU.js} +2 -2
- package/dist/tsup/{chunk-2NNICHGY.js → chunk-EVQJYFFP.js} +2 -2
- package/dist/tsup/{chunk-C3UREFUI.js → chunk-HXWPIIEM.js} +15 -6
- package/dist/tsup/chunk-HXWPIIEM.js.map +1 -0
- package/dist/tsup/chunk-IRGPMCKQ.cjs +129 -0
- package/dist/tsup/chunk-IRGPMCKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-QC4AE54W.cjs → chunk-J3M5ATO5.cjs} +3 -3
- package/dist/tsup/{chunk-QC4AE54W.cjs.map → chunk-J3M5ATO5.cjs.map} +1 -1
- package/dist/tsup/{chunk-DRJCTDDT.cjs → chunk-J74MGKP5.cjs} +20 -11
- package/dist/tsup/chunk-J74MGKP5.cjs.map +1 -0
- package/dist/tsup/{chunk-XJMYGATE.cjs → chunk-MAQSR26X.cjs} +8 -3
- package/dist/tsup/chunk-MAQSR26X.cjs.map +1 -0
- package/dist/tsup/{chunk-XNKWXMIT.cjs → chunk-MG2TWYPF.cjs} +794 -318
- package/dist/tsup/chunk-MG2TWYPF.cjs.map +1 -0
- package/dist/tsup/{chunk-LQOCWGP6.js → chunk-P2RZJPYI.js} +1 -1
- package/dist/tsup/{chunk-XU4GGB6J.js → chunk-QKDCNAPW.js} +504 -181
- package/dist/tsup/chunk-QKDCNAPW.js.map +1 -0
- package/dist/tsup/{chunk-G7YZSSWV.cjs → chunk-QT7PPLSB.cjs} +6 -6
- package/dist/tsup/{chunk-G7YZSSWV.cjs.map → chunk-QT7PPLSB.cjs.map} +1 -1
- package/dist/tsup/{chunk-VRZNWBDK.js → chunk-SDJFBUFE.js} +45 -46
- package/dist/tsup/chunk-SDJFBUFE.js.map +1 -0
- package/dist/tsup/chunk-SE37OCA2.cjs +891 -0
- package/dist/tsup/chunk-SE37OCA2.cjs.map +1 -0
- package/dist/tsup/{chunk-6F2NCX7R.js → chunk-WUFUT7CZ.js} +2 -2
- package/dist/tsup/{chunk-LZADH4QA.cjs → chunk-XVBIJET6.cjs} +10 -10
- package/dist/tsup/{chunk-LZADH4QA.cjs.map → chunk-XVBIJET6.cjs.map} +1 -1
- package/dist/tsup/{chunk-KSQQU7NC.js → chunk-YJXB7BPR.js} +8 -7
- package/dist/tsup/chunk-YJXB7BPR.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +3 -2
- package/dist/tsup/client/mod.d.ts +3 -2
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.d.cts +9 -1
- package/dist/tsup/common/log.d.ts +9 -1
- 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/{config-Bo-blHpJ.d.ts → config-CcMdKDv9.d.ts} +301 -899
- package/dist/tsup/{config-BRDYDraU.d.cts → config-DxlmiJS1.d.cts} +301 -899
- package/dist/tsup/driver-helpers/mod.cjs +5 -5
- package/dist/tsup/driver-helpers/mod.d.cts +2 -1
- package/dist/tsup/driver-helpers/mod.d.ts +2 -1
- package/dist/tsup/driver-helpers/mod.js +4 -4
- package/dist/tsup/driver-test-suite/mod.cjs +74 -74
- package/dist/tsup/driver-test-suite/mod.d.cts +2 -1
- package/dist/tsup/driver-test-suite/mod.d.ts +2 -1
- package/dist/tsup/driver-test-suite/mod.js +11 -11
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.d.cts +5 -4
- package/dist/tsup/inspector/mod.d.ts +5 -4
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +10 -10
- package/dist/tsup/mod.d.cts +3 -2
- package/dist/tsup/mod.d.ts +3 -2
- package/dist/tsup/mod.js +9 -9
- package/dist/tsup/test/mod.cjs +12 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +2 -6
- package/dist/tsup/test/mod.d.ts +2 -6
- package/dist/tsup/test/mod.js +11 -10
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.js +2 -2
- package/package.json +7 -6
- package/src/actor/config.ts +21 -20
- package/src/actor/conn/mod.ts +5 -1
- package/src/actor/instance/connection-manager.ts +5 -1
- package/src/actor/instance/event-manager.ts +5 -1
- package/src/actor/instance/state-manager.ts +19 -3
- package/src/actor/protocol/old.ts +3 -0
- package/src/actor/protocol/serde.ts +5 -1
- package/src/actor/router-endpoints.ts +2 -0
- package/src/client/actor-conn.ts +2 -0
- package/src/client/actor-handle.ts +3 -0
- package/src/client/config.ts +1 -1
- package/src/client/utils.ts +4 -1
- package/src/common/router.ts +5 -1
- package/src/driver-helpers/utils.ts +8 -2
- package/src/drivers/engine/config.ts +6 -3
- package/src/drivers/file-system/global-state.ts +46 -1
- package/src/drivers/file-system/manager.ts +4 -0
- package/src/inspector/config.ts +1 -2
- package/src/manager/driver.ts +4 -0
- package/src/manager/router-schema.ts +7 -7
- package/src/manager/router.ts +4 -4
- package/src/registry/run-config.ts +9 -5
- package/src/remote-manager-driver/actor-http-client.ts +1 -1
- package/src/remote-manager-driver/api-utils.ts +2 -0
- package/src/schemas/actor-persist/versioned.ts +126 -54
- package/src/schemas/client-protocol/versioned.ts +173 -42
- package/src/schemas/file-system-driver/mod.ts +1 -1
- package/src/schemas/file-system-driver/versioned.ts +129 -45
- package/src/serde.ts +9 -2
- package/src/test/config.ts +13 -12
- package/src/test/mod.ts +56 -82
- package/dist/tsup/chunk-2TZH6VO6.cjs +0 -514
- package/dist/tsup/chunk-2TZH6VO6.cjs.map +0 -1
- package/dist/tsup/chunk-4GJQDTAG.cjs.map +0 -1
- package/dist/tsup/chunk-5YDKTW6Y.js +0 -514
- package/dist/tsup/chunk-5YDKTW6Y.js.map +0 -1
- package/dist/tsup/chunk-BBTOBXEO.js.map +0 -1
- package/dist/tsup/chunk-C3UREFUI.js.map +0 -1
- package/dist/tsup/chunk-DRJCTDDT.cjs.map +0 -1
- package/dist/tsup/chunk-F3SQLO3X.cjs.map +0 -1
- package/dist/tsup/chunk-FYZLEH57.cjs +0 -130
- package/dist/tsup/chunk-FYZLEH57.cjs.map +0 -1
- package/dist/tsup/chunk-KSQQU7NC.js.map +0 -1
- package/dist/tsup/chunk-VRZNWBDK.js.map +0 -1
- package/dist/tsup/chunk-XJMYGATE.cjs.map +0 -1
- package/dist/tsup/chunk-XNKWXMIT.cjs.map +0 -1
- package/dist/tsup/chunk-XU4GGB6J.js.map +0 -1
- package/src/common/versioned-data.ts +0 -95
- /package/dist/tsup/{chunk-GUH2PNPG.js.map → chunk-5RN6O2RW.js.map} +0 -0
- /package/dist/tsup/{chunk-D7A47BVR.js.map → chunk-EU7VV5PU.js.map} +0 -0
- /package/dist/tsup/{chunk-2NNICHGY.js.map → chunk-EVQJYFFP.js.map} +0 -0
- /package/dist/tsup/{chunk-LQOCWGP6.js.map → chunk-P2RZJPYI.js.map} +0 -0
- /package/dist/tsup/{chunk-6F2NCX7R.js.map → chunk-WUFUT7CZ.js.map} +0 -0
package/src/test/mod.ts
CHANGED
|
@@ -1,122 +1,96 @@
|
|
|
1
1
|
import { createServer } from "node:net";
|
|
2
|
-
import { serve as honoServe
|
|
2
|
+
import { serve as honoServe } from "@hono/node-server";
|
|
3
3
|
import { createNodeWebSocket } from "@hono/node-ws";
|
|
4
|
+
import invariant from "invariant";
|
|
4
5
|
import { type TestContext, vi } from "vitest";
|
|
5
|
-
import { ClientConfigSchema } from "@/client/config";
|
|
6
6
|
import { type Client, createClient } from "@/client/mod";
|
|
7
|
-
import { chooseDefaultDriver } from "@/drivers/default";
|
|
8
7
|
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
|
|
9
|
-
import {
|
|
10
|
-
configureInspectorAccessToken,
|
|
11
|
-
getInspectorUrl,
|
|
12
|
-
} from "@/inspector/utils";
|
|
8
|
+
import { configureInspectorAccessToken } from "@/inspector/utils";
|
|
13
9
|
import { createManagerRouter } from "@/manager/router";
|
|
14
|
-
import { createClientWithDriver } from "@/mod";
|
|
15
|
-
import
|
|
10
|
+
import { createClientWithDriver, type Registry, type RunConfig } from "@/mod";
|
|
11
|
+
import { ClientConfigSchema } from "@/client/config";
|
|
16
12
|
import { RunnerConfigSchema } from "@/registry/run-config";
|
|
17
|
-
import { ConfigSchema, type InputConfig } from "./config";
|
|
18
13
|
import { logger } from "./log";
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
export interface SetupTestResult<A extends Registry<any>> {
|
|
16
|
+
client: Client<A>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Must use `TestContext` since global hooks do not work when running concurrently
|
|
20
|
+
export async function setupTest<A extends Registry<any>>(
|
|
21
|
+
c: TestContext,
|
|
22
|
+
registry: A,
|
|
23
|
+
): Promise<SetupTestResult<A>> {
|
|
24
|
+
// Force enable test mode
|
|
25
|
+
registry.config.test.enabled = true;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
// Create driver
|
|
28
|
+
const driver = await createFileSystemOrMemoryDriver(
|
|
29
|
+
true,
|
|
30
|
+
`/tmp/rivetkit-test-${crypto.randomUUID()}`,
|
|
31
|
+
);
|
|
28
32
|
|
|
33
|
+
// Build driver config
|
|
34
|
+
// biome-ignore lint/style/useConst: Assigned later
|
|
29
35
|
let upgradeWebSocket: any;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
const config: RunConfig = RunnerConfigSchema.parse({
|
|
37
|
+
driver,
|
|
38
|
+
getUpgradeWebSocket: () => upgradeWebSocket!,
|
|
39
|
+
inspector: {
|
|
40
|
+
enabled: true,
|
|
41
|
+
token: () => "token",
|
|
42
|
+
},
|
|
43
|
+
});
|
|
33
44
|
|
|
34
45
|
// Create router
|
|
35
|
-
const runConfig = RunnerConfigSchema.parse(inputConfig);
|
|
36
|
-
const driver =
|
|
37
|
-
inputConfig.driver ?? (await createFileSystemOrMemoryDriver(false));
|
|
38
46
|
const managerDriver = driver.manager(registry.config, config);
|
|
39
|
-
const
|
|
47
|
+
const internalClient = createClientWithDriver(
|
|
40
48
|
managerDriver,
|
|
41
49
|
ClientConfigSchema.parse({}),
|
|
42
50
|
);
|
|
43
51
|
configureInspectorAccessToken(config, managerDriver);
|
|
44
52
|
const { router } = createManagerRouter(
|
|
45
53
|
registry.config,
|
|
46
|
-
|
|
54
|
+
config,
|
|
47
55
|
managerDriver,
|
|
48
56
|
driver,
|
|
49
|
-
|
|
57
|
+
internalClient,
|
|
50
58
|
);
|
|
51
59
|
|
|
52
60
|
// Inject WebSocket
|
|
53
61
|
const nodeWebSocket = createNodeWebSocket({ app: router });
|
|
54
62
|
upgradeWebSocket = nodeWebSocket.upgradeWebSocket;
|
|
55
63
|
|
|
64
|
+
// Start server
|
|
65
|
+
const port = await getPort();
|
|
56
66
|
const server = honoServe({
|
|
57
67
|
fetch: router.fetch,
|
|
58
|
-
hostname:
|
|
59
|
-
port
|
|
68
|
+
hostname: "127.0.0.1",
|
|
69
|
+
port,
|
|
60
70
|
});
|
|
71
|
+
invariant(
|
|
72
|
+
nodeWebSocket.injectWebSocket !== undefined,
|
|
73
|
+
"should have injectWebSocket",
|
|
74
|
+
);
|
|
61
75
|
nodeWebSocket.injectWebSocket(server);
|
|
76
|
+
const endpoint = `http://127.0.0.1:${port}`;
|
|
62
77
|
|
|
63
|
-
logger().info({
|
|
64
|
-
msg: "rivetkit started",
|
|
65
|
-
hostname: config.hostname,
|
|
66
|
-
port: config.port,
|
|
67
|
-
definitions: Object.keys(registry.config.use).length,
|
|
68
|
-
});
|
|
78
|
+
logger().info({ msg: "test server listening", port });
|
|
69
79
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
client: Client<A>;
|
|
75
|
-
mockDriver: {
|
|
76
|
-
actorDriver: {
|
|
77
|
-
setCreateVarsContext: (ctx: any) => void;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Must use `TestContext` since global hooks do not work when running concurrently
|
|
83
|
-
export async function setupTest<A extends Registry<any>>(
|
|
84
|
-
c: TestContext,
|
|
85
|
-
registry: A,
|
|
86
|
-
): Promise<SetupTestResult<A>> {
|
|
87
|
-
vi.useFakeTimers();
|
|
88
|
-
|
|
89
|
-
// Set up mock driver for testing createVars context
|
|
90
|
-
const mockDriverContext: any = {};
|
|
91
|
-
const setDriverContextFn = (ctx: any) => {
|
|
92
|
-
mockDriverContext.current = ctx;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// We don't need to modify the driver context anymore since we're testing with the actual context
|
|
80
|
+
// Cleanup on test finish
|
|
81
|
+
c.onTestFinished(async () => {
|
|
82
|
+
await new Promise((resolve) => server.close(() => resolve(undefined)));
|
|
83
|
+
});
|
|
96
84
|
|
|
97
|
-
//
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
85
|
+
// Create client
|
|
86
|
+
const client = createClient<A>({
|
|
87
|
+
endpoint,
|
|
88
|
+
namespace: "default",
|
|
89
|
+
runnerName: "default",
|
|
90
|
+
});
|
|
91
|
+
c.onTestFinished(async () => await client.dispose());
|
|
104
92
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// // TODO: Figure out how to make this the correct endpoint
|
|
108
|
-
// // Create client
|
|
109
|
-
// const client = createClient<A>(`http://127.0.0.1:${port}`);
|
|
110
|
-
// c.onTestFinished(async () => await client.dispose());
|
|
111
|
-
//
|
|
112
|
-
// return {
|
|
113
|
-
// client,
|
|
114
|
-
// mockDriver: {
|
|
115
|
-
// actorDriver: {
|
|
116
|
-
// setCreateVarsContext: setDriverContextFn,
|
|
117
|
-
// },
|
|
118
|
-
// },
|
|
119
|
-
// };
|
|
93
|
+
return { client };
|
|
120
94
|
}
|
|
121
95
|
|
|
122
96
|
export async function getPort(): Promise<number> {
|
|
@@ -1,514 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
var _chunkDRJCTDDTcjs = require('./chunk-DRJCTDDT.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _chunkF3SQLO3Xcjs = require('./chunk-F3SQLO3X.cjs');
|
|
10
|
-
|
|
11
|
-
// src/registry/run-config.ts
|
|
12
|
-
var _zod = require('zod'); var _zod2 = _interopRequireDefault(_zod);
|
|
13
|
-
|
|
14
|
-
// src/drivers/engine/config.ts
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// src/client/config.ts
|
|
18
|
-
|
|
19
|
-
var ClientConfigSchema = _zod2.default.object({
|
|
20
|
-
/** Endpoint to connect to for Rivet Engine or RivetKit manager API. */
|
|
21
|
-
endpoint: _zod2.default.string().optional().transform(
|
|
22
|
-
(x) => _nullishCoalesce(_nullishCoalesce(x, () => ( _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_ENGINE"))), () => ( _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_ENDPOINT")))
|
|
23
|
-
),
|
|
24
|
-
/** Token to use to authenticate with the API. */
|
|
25
|
-
token: _zod2.default.string().optional().transform((x) => _nullishCoalesce(x, () => ( _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_TOKEN")))),
|
|
26
|
-
/** Namespace to connect to. */
|
|
27
|
-
namespace: _zod2.default.string().default(() => _nullishCoalesce(_chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_NAMESPACE"), () => ( "default"))),
|
|
28
|
-
/** Name of the runner. This is used to group together runners in to different pools. */
|
|
29
|
-
runnerName: _zod2.default.string().default(() => _nullishCoalesce(_chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_RUNNER"), () => ( "default"))),
|
|
30
|
-
encoding: _chunkDRJCTDDTcjs.EncodingSchema.default("bare"),
|
|
31
|
-
headers: _zod2.default.record(_zod2.default.string()).optional().default({}),
|
|
32
|
-
// See RunConfig.getUpgradeWebSocket
|
|
33
|
-
getUpgradeWebSocket: _zod2.default.custom().optional(),
|
|
34
|
-
/** Whether to automatically perform health checks when the client is created. */
|
|
35
|
-
disableMetadataLookup: _zod2.default.boolean().optional().default(false)
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// src/drivers/engine/config.ts
|
|
39
|
-
var EngingConfigSchema = _zod.z.object({
|
|
40
|
-
/** Unique key for this runner. Runners connecting a given key will replace any other runner connected with the same key. */
|
|
41
|
-
runnerKey: _zod.z.string().optional().transform((x) => _nullishCoalesce(x, () => ( _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_RUNNER_KEY")))),
|
|
42
|
-
/** How many actors this runner can run. */
|
|
43
|
-
totalSlots: _zod.z.number().default(1e5)
|
|
44
|
-
}).merge(ClientConfigSchema).default({});
|
|
45
|
-
|
|
46
|
-
// src/inspector/config.ts
|
|
47
|
-
|
|
48
|
-
var defaultTokenFn = () => {
|
|
49
|
-
const envToken = _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVETKIT_INSPECTOR_TOKEN");
|
|
50
|
-
if (envToken) {
|
|
51
|
-
return envToken;
|
|
52
|
-
}
|
|
53
|
-
return "";
|
|
54
|
-
};
|
|
55
|
-
var defaultEnabled = () => {
|
|
56
|
-
return _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "NODE_ENV") !== "production" || !_chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVETKIT_INSPECTOR_DISABLE");
|
|
57
|
-
};
|
|
58
|
-
var InspectorConfigSchema = _zod.z.object({
|
|
59
|
-
enabled: _zod.z.boolean().or(
|
|
60
|
-
_zod.z.object({
|
|
61
|
-
actor: _zod.z.boolean().optional().default(true),
|
|
62
|
-
manager: _zod.z.boolean().optional().default(true)
|
|
63
|
-
})
|
|
64
|
-
).optional().default(defaultEnabled),
|
|
65
|
-
/**
|
|
66
|
-
* Token used to access the Inspector.
|
|
67
|
-
*/
|
|
68
|
-
token: _zod.z.function().returns(_zod.z.string()).optional().default(() => defaultTokenFn),
|
|
69
|
-
/**
|
|
70
|
-
* Default RivetKit server endpoint for Rivet Inspector to connect to. This should be the same endpoint as what you use for your Rivet client to connect to RivetKit.
|
|
71
|
-
*
|
|
72
|
-
* This is a convenience property just for printing out the inspector URL.
|
|
73
|
-
*/
|
|
74
|
-
defaultEndpoint: _zod.z.string().optional()
|
|
75
|
-
}).optional().default(() => ({
|
|
76
|
-
enabled: defaultEnabled(),
|
|
77
|
-
token: defaultTokenFn
|
|
78
|
-
}));
|
|
79
|
-
|
|
80
|
-
// src/registry/run-config.ts
|
|
81
|
-
var DriverConfigSchema = _zod.z.object({
|
|
82
|
-
/** Machine-readable name to identify this driver by. */
|
|
83
|
-
name: _zod.z.string(),
|
|
84
|
-
manager: _zod.z.custom(),
|
|
85
|
-
actor: _zod.z.custom()
|
|
86
|
-
});
|
|
87
|
-
var RunnerConfigSchema = _zod.z.object({
|
|
88
|
-
driver: DriverConfigSchema.optional(),
|
|
89
|
-
/** @experimental */
|
|
90
|
-
maxIncomingMessageSize: _zod.z.number().optional().default(65536),
|
|
91
|
-
/** @experimental */
|
|
92
|
-
inspector: InspectorConfigSchema,
|
|
93
|
-
/** @experimental */
|
|
94
|
-
disableDefaultServer: _zod.z.boolean().optional().default(false),
|
|
95
|
-
/** @experimental */
|
|
96
|
-
defaultServerPort: _zod.z.number().default(6420),
|
|
97
|
-
/** @experimental */
|
|
98
|
-
runEngine: _zod.z.boolean().optional().default(() => _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_RUN_ENGINE") === "1"),
|
|
99
|
-
/** @experimental */
|
|
100
|
-
runEngineVersion: _zod.z.string().optional().default(
|
|
101
|
-
() => _nullishCoalesce(_chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_RUN_ENGINE_VERSION"), () => ( _chunkF3SQLO3Xcjs.VERSION))
|
|
102
|
-
),
|
|
103
|
-
/** @experimental */
|
|
104
|
-
overrideServerAddress: _zod.z.string().optional(),
|
|
105
|
-
/** @experimental */
|
|
106
|
-
disableActorDriver: _zod.z.boolean().optional().default(false),
|
|
107
|
-
/**
|
|
108
|
-
* @experimental
|
|
109
|
-
*
|
|
110
|
-
* Whether to run runners normally or have them managed
|
|
111
|
-
* serverlessly (by the Rivet Engine for example).
|
|
112
|
-
*/
|
|
113
|
-
runnerKind: _zod.z.enum(["serverless", "normal"]).optional().default(
|
|
114
|
-
() => _chunkF3SQLO3Xcjs.getEnvUniversal.call(void 0, "RIVET_RUNNER_KIND") === "serverless" ? "serverless" : "normal"
|
|
115
|
-
),
|
|
116
|
-
totalSlots: _zod.z.number().optional(),
|
|
117
|
-
/**
|
|
118
|
-
* @experimental
|
|
119
|
-
*
|
|
120
|
-
* Base path for the router. This is used to prefix all routes.
|
|
121
|
-
* For example, if the base path is `/api`, then the route `/actors` will be
|
|
122
|
-
* available at `/api/actors`.
|
|
123
|
-
*/
|
|
124
|
-
basePath: _zod.z.string().optional().default("/"),
|
|
125
|
-
/**
|
|
126
|
-
* @experimental
|
|
127
|
-
*
|
|
128
|
-
* Disable welcome message.
|
|
129
|
-
* */
|
|
130
|
-
noWelcome: _zod.z.boolean().optional().default(false),
|
|
131
|
-
/**
|
|
132
|
-
* @experimental
|
|
133
|
-
* */
|
|
134
|
-
logging: _zod.z.object({
|
|
135
|
-
baseLogger: _zod.z.custom().optional(),
|
|
136
|
-
level: _chunkF3SQLO3Xcjs.LogLevelSchema.optional()
|
|
137
|
-
}).optional().default({}),
|
|
138
|
-
/**
|
|
139
|
-
* @experimental
|
|
140
|
-
*
|
|
141
|
-
* Automatically configure serverless runners in the engine.
|
|
142
|
-
* Can only be used when runnerKind is "serverless".
|
|
143
|
-
* If true, uses default configuration. Can also provide custom configuration.
|
|
144
|
-
*/
|
|
145
|
-
autoConfigureServerless: _zod.z.union([
|
|
146
|
-
_zod.z.boolean(),
|
|
147
|
-
_zod.z.object({
|
|
148
|
-
url: _zod.z.string().optional(),
|
|
149
|
-
headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional(),
|
|
150
|
-
maxRunners: _zod.z.number().optional(),
|
|
151
|
-
minRunners: _zod.z.number().optional(),
|
|
152
|
-
requestLifespan: _zod.z.number().optional(),
|
|
153
|
-
runnersMargin: _zod.z.number().optional(),
|
|
154
|
-
slotsPerRunner: _zod.z.number().optional(),
|
|
155
|
-
metadata: _zod.z.record(_zod.z.unknown()).optional()
|
|
156
|
-
})
|
|
157
|
-
]).optional(),
|
|
158
|
-
// This is a function to allow for lazy configuration of upgradeWebSocket on the
|
|
159
|
-
// fly. This is required since the dependencies that upgradeWebSocket
|
|
160
|
-
// (specifically Node.js) can sometimes only be specified after the router is
|
|
161
|
-
// created or must be imported async using `await import(...)`
|
|
162
|
-
getUpgradeWebSocket: _zod.z.custom().optional()
|
|
163
|
-
}).merge(EngingConfigSchema.removeDefault()).default({});
|
|
164
|
-
|
|
165
|
-
// src/driver-helpers/utils.ts
|
|
166
|
-
var _cborx = require('cbor-x'); var cbor = _interopRequireWildcard(_cborx);
|
|
167
|
-
|
|
168
|
-
// src/actor/instance/kv.ts
|
|
169
|
-
var KEYS = {
|
|
170
|
-
PERSIST_DATA: Uint8Array.from([1]),
|
|
171
|
-
CONN_PREFIX: Uint8Array.from([2]),
|
|
172
|
-
// Prefix for connection keys
|
|
173
|
-
INSPECTOR_TOKEN: Uint8Array.from([3])
|
|
174
|
-
// Inspector token key
|
|
175
|
-
};
|
|
176
|
-
function makeConnKey(connId) {
|
|
177
|
-
const encoder = new TextEncoder();
|
|
178
|
-
const connIdBytes = encoder.encode(connId);
|
|
179
|
-
const key = new Uint8Array(KEYS.CONN_PREFIX.length + connIdBytes.length);
|
|
180
|
-
key.set(KEYS.CONN_PREFIX, 0);
|
|
181
|
-
key.set(connIdBytes, KEYS.CONN_PREFIX.length);
|
|
182
|
-
return key;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// src/common/versioned-data.ts
|
|
186
|
-
var VersionedDataHandler = class {
|
|
187
|
-
constructor(config2) {
|
|
188
|
-
this.config = config2;
|
|
189
|
-
}
|
|
190
|
-
serializeWithEmbeddedVersion(data) {
|
|
191
|
-
const versioned = {
|
|
192
|
-
version: this.config.currentVersion,
|
|
193
|
-
data: this.config.serializeVersion(data)
|
|
194
|
-
};
|
|
195
|
-
return this.embedVersion(versioned);
|
|
196
|
-
}
|
|
197
|
-
deserializeWithEmbeddedVersion(bytes) {
|
|
198
|
-
const versioned = this.extractVersion(bytes);
|
|
199
|
-
return this.deserialize(versioned.data, versioned.version);
|
|
200
|
-
}
|
|
201
|
-
serialize(data, version) {
|
|
202
|
-
return this.config.serializeVersion(data);
|
|
203
|
-
}
|
|
204
|
-
deserialize(bytes, version) {
|
|
205
|
-
if (version === this.config.currentVersion) {
|
|
206
|
-
return this.config.deserializeVersion(bytes);
|
|
207
|
-
}
|
|
208
|
-
if (version > this.config.currentVersion) {
|
|
209
|
-
throw new Error(
|
|
210
|
-
`Cannot decode data from version ${version}, current version is ${this.config.currentVersion}`
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
let currentData = this.config.deserializeVersion(bytes);
|
|
214
|
-
let currentVersion = version;
|
|
215
|
-
while (currentVersion < this.config.currentVersion) {
|
|
216
|
-
const migration = this.config.migrations.get(currentVersion);
|
|
217
|
-
if (!migration) {
|
|
218
|
-
throw new Error(
|
|
219
|
-
`No migration found from version ${currentVersion} to ${currentVersion + 1}`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
currentData = migration(currentData);
|
|
223
|
-
currentVersion++;
|
|
224
|
-
}
|
|
225
|
-
return currentData;
|
|
226
|
-
}
|
|
227
|
-
embedVersion(data) {
|
|
228
|
-
const versionBytes = new Uint8Array(2);
|
|
229
|
-
new DataView(versionBytes.buffer).setUint16(0, data.version, true);
|
|
230
|
-
const result = new Uint8Array(versionBytes.length + data.data.length);
|
|
231
|
-
result.set(versionBytes);
|
|
232
|
-
result.set(data.data, versionBytes.length);
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
235
|
-
extractVersion(bytes) {
|
|
236
|
-
if (bytes.length < 2) {
|
|
237
|
-
throw new Error("Invalid versioned data: too short");
|
|
238
|
-
}
|
|
239
|
-
const version = new DataView(bytes.buffer, bytes.byteOffset).getUint16(
|
|
240
|
-
0,
|
|
241
|
-
true
|
|
242
|
-
);
|
|
243
|
-
const data = bytes.slice(2);
|
|
244
|
-
return { version, data };
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
function createVersionedDataHandler(config2) {
|
|
248
|
-
return new VersionedDataHandler(config2);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// dist/schemas/actor-persist/v3.ts
|
|
252
|
-
var _lib = require('@bare-ts/lib'); var bare = _interopRequireWildcard(_lib);
|
|
253
|
-
var config = /* @__PURE__ */ bare.Config({});
|
|
254
|
-
function readGatewayId(bc) {
|
|
255
|
-
return bare.readFixedData(bc, 4);
|
|
256
|
-
}
|
|
257
|
-
function writeGatewayId(bc, x) {
|
|
258
|
-
assert(x.byteLength === 4);
|
|
259
|
-
bare.writeFixedData(bc, x);
|
|
260
|
-
}
|
|
261
|
-
function readRequestId(bc) {
|
|
262
|
-
return bare.readFixedData(bc, 4);
|
|
263
|
-
}
|
|
264
|
-
function writeRequestId(bc, x) {
|
|
265
|
-
assert(x.byteLength === 4);
|
|
266
|
-
bare.writeFixedData(bc, x);
|
|
267
|
-
}
|
|
268
|
-
function readCbor(bc) {
|
|
269
|
-
return bare.readData(bc);
|
|
270
|
-
}
|
|
271
|
-
function writeCbor(bc, x) {
|
|
272
|
-
bare.writeData(bc, x);
|
|
273
|
-
}
|
|
274
|
-
function readSubscription(bc) {
|
|
275
|
-
return {
|
|
276
|
-
eventName: bare.readString(bc)
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
function writeSubscription(bc, x) {
|
|
280
|
-
bare.writeString(bc, x.eventName);
|
|
281
|
-
}
|
|
282
|
-
function read0(bc) {
|
|
283
|
-
const len = bare.readUintSafe(bc);
|
|
284
|
-
if (len === 0) {
|
|
285
|
-
return [];
|
|
286
|
-
}
|
|
287
|
-
const result = [readSubscription(bc)];
|
|
288
|
-
for (let i = 1; i < len; i++) {
|
|
289
|
-
result[i] = readSubscription(bc);
|
|
290
|
-
}
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
function write0(bc, x) {
|
|
294
|
-
bare.writeUintSafe(bc, x.length);
|
|
295
|
-
for (let i = 0; i < x.length; i++) {
|
|
296
|
-
writeSubscription(bc, x[i]);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
function read1(bc) {
|
|
300
|
-
const len = bare.readUintSafe(bc);
|
|
301
|
-
const result = /* @__PURE__ */ new Map();
|
|
302
|
-
for (let i = 0; i < len; i++) {
|
|
303
|
-
const offset = bc.offset;
|
|
304
|
-
const key = bare.readString(bc);
|
|
305
|
-
if (result.has(key)) {
|
|
306
|
-
bc.offset = offset;
|
|
307
|
-
throw new bare.BareError(offset, "duplicated key");
|
|
308
|
-
}
|
|
309
|
-
result.set(key, bare.readString(bc));
|
|
310
|
-
}
|
|
311
|
-
return result;
|
|
312
|
-
}
|
|
313
|
-
function write1(bc, x) {
|
|
314
|
-
bare.writeUintSafe(bc, x.size);
|
|
315
|
-
for (const kv of x) {
|
|
316
|
-
bare.writeString(bc, kv[0]);
|
|
317
|
-
bare.writeString(bc, kv[1]);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
function readConn(bc) {
|
|
321
|
-
return {
|
|
322
|
-
id: bare.readString(bc),
|
|
323
|
-
parameters: readCbor(bc),
|
|
324
|
-
state: readCbor(bc),
|
|
325
|
-
subscriptions: read0(bc),
|
|
326
|
-
gatewayId: readGatewayId(bc),
|
|
327
|
-
requestId: readRequestId(bc),
|
|
328
|
-
serverMessageIndex: bare.readU16(bc),
|
|
329
|
-
clientMessageIndex: bare.readU16(bc),
|
|
330
|
-
requestPath: bare.readString(bc),
|
|
331
|
-
requestHeaders: read1(bc)
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
function writeConn(bc, x) {
|
|
335
|
-
bare.writeString(bc, x.id);
|
|
336
|
-
writeCbor(bc, x.parameters);
|
|
337
|
-
writeCbor(bc, x.state);
|
|
338
|
-
write0(bc, x.subscriptions);
|
|
339
|
-
writeGatewayId(bc, x.gatewayId);
|
|
340
|
-
writeRequestId(bc, x.requestId);
|
|
341
|
-
bare.writeU16(bc, x.serverMessageIndex);
|
|
342
|
-
bare.writeU16(bc, x.clientMessageIndex);
|
|
343
|
-
bare.writeString(bc, x.requestPath);
|
|
344
|
-
write1(bc, x.requestHeaders);
|
|
345
|
-
}
|
|
346
|
-
function encodeConn(x) {
|
|
347
|
-
const bc = new bare.ByteCursor(
|
|
348
|
-
new Uint8Array(config.initialBufferLength),
|
|
349
|
-
config
|
|
350
|
-
);
|
|
351
|
-
writeConn(bc, x);
|
|
352
|
-
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
|
|
353
|
-
}
|
|
354
|
-
function decodeConn(bytes) {
|
|
355
|
-
const bc = new bare.ByteCursor(bytes, config);
|
|
356
|
-
const result = readConn(bc);
|
|
357
|
-
if (bc.offset < bc.view.byteLength) {
|
|
358
|
-
throw new bare.BareError(bc.offset, "remaining bytes");
|
|
359
|
-
}
|
|
360
|
-
return result;
|
|
361
|
-
}
|
|
362
|
-
function read2(bc) {
|
|
363
|
-
return bare.readBool(bc) ? readCbor(bc) : null;
|
|
364
|
-
}
|
|
365
|
-
function write2(bc, x) {
|
|
366
|
-
bare.writeBool(bc, x !== null);
|
|
367
|
-
if (x !== null) {
|
|
368
|
-
writeCbor(bc, x);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function readScheduleEvent(bc) {
|
|
372
|
-
return {
|
|
373
|
-
eventId: bare.readString(bc),
|
|
374
|
-
timestamp: bare.readI64(bc),
|
|
375
|
-
action: bare.readString(bc),
|
|
376
|
-
args: read2(bc)
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
function writeScheduleEvent(bc, x) {
|
|
380
|
-
bare.writeString(bc, x.eventId);
|
|
381
|
-
bare.writeI64(bc, x.timestamp);
|
|
382
|
-
bare.writeString(bc, x.action);
|
|
383
|
-
write2(bc, x.args);
|
|
384
|
-
}
|
|
385
|
-
function read3(bc) {
|
|
386
|
-
const len = bare.readUintSafe(bc);
|
|
387
|
-
if (len === 0) {
|
|
388
|
-
return [];
|
|
389
|
-
}
|
|
390
|
-
const result = [readScheduleEvent(bc)];
|
|
391
|
-
for (let i = 1; i < len; i++) {
|
|
392
|
-
result[i] = readScheduleEvent(bc);
|
|
393
|
-
}
|
|
394
|
-
return result;
|
|
395
|
-
}
|
|
396
|
-
function write3(bc, x) {
|
|
397
|
-
bare.writeUintSafe(bc, x.length);
|
|
398
|
-
for (let i = 0; i < x.length; i++) {
|
|
399
|
-
writeScheduleEvent(bc, x[i]);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
function readActor(bc) {
|
|
403
|
-
return {
|
|
404
|
-
input: read2(bc),
|
|
405
|
-
hasInitialized: bare.readBool(bc),
|
|
406
|
-
state: readCbor(bc),
|
|
407
|
-
scheduledEvents: read3(bc)
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
function writeActor(bc, x) {
|
|
411
|
-
write2(bc, x.input);
|
|
412
|
-
bare.writeBool(bc, x.hasInitialized);
|
|
413
|
-
writeCbor(bc, x.state);
|
|
414
|
-
write3(bc, x.scheduledEvents);
|
|
415
|
-
}
|
|
416
|
-
function encodeActor(x) {
|
|
417
|
-
const bc = new bare.ByteCursor(
|
|
418
|
-
new Uint8Array(config.initialBufferLength),
|
|
419
|
-
config
|
|
420
|
-
);
|
|
421
|
-
writeActor(bc, x);
|
|
422
|
-
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
|
|
423
|
-
}
|
|
424
|
-
function decodeActor(bytes) {
|
|
425
|
-
const bc = new bare.ByteCursor(bytes, config);
|
|
426
|
-
const result = readActor(bc);
|
|
427
|
-
if (bc.offset < bc.view.byteLength) {
|
|
428
|
-
throw new bare.BareError(bc.offset, "remaining bytes");
|
|
429
|
-
}
|
|
430
|
-
return result;
|
|
431
|
-
}
|
|
432
|
-
function assert(condition, message) {
|
|
433
|
-
if (!condition) throw new Error(_nullishCoalesce(message, () => ( "Assertion failed")));
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// src/schemas/actor-persist/versioned.ts
|
|
437
|
-
var CURRENT_VERSION = 3;
|
|
438
|
-
var migrations = /* @__PURE__ */ new Map([
|
|
439
|
-
[
|
|
440
|
-
1,
|
|
441
|
-
(v1Data) => ({
|
|
442
|
-
...v1Data,
|
|
443
|
-
connections: v1Data.connections.map((conn) => ({
|
|
444
|
-
...conn,
|
|
445
|
-
hibernatableRequestId: null
|
|
446
|
-
})),
|
|
447
|
-
hibernatableWebSockets: []
|
|
448
|
-
})
|
|
449
|
-
],
|
|
450
|
-
[
|
|
451
|
-
2,
|
|
452
|
-
(v2Data) => {
|
|
453
|
-
const scheduledEvents = v2Data.scheduledEvents.map((event) => {
|
|
454
|
-
if (event.kind.tag === "GenericPersistedScheduleEvent") {
|
|
455
|
-
return {
|
|
456
|
-
eventId: event.eventId,
|
|
457
|
-
timestamp: event.timestamp,
|
|
458
|
-
action: event.kind.val.action,
|
|
459
|
-
args: event.kind.val.args
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
throw new Error(
|
|
463
|
-
`Unknown schedule event kind: ${event.kind.tag}`
|
|
464
|
-
);
|
|
465
|
-
});
|
|
466
|
-
return {
|
|
467
|
-
input: v2Data.input,
|
|
468
|
-
hasInitialized: v2Data.hasInitialized,
|
|
469
|
-
state: v2Data.state,
|
|
470
|
-
scheduledEvents
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
]
|
|
474
|
-
]);
|
|
475
|
-
var ACTOR_VERSIONED = createVersionedDataHandler({
|
|
476
|
-
currentVersion: CURRENT_VERSION,
|
|
477
|
-
migrations,
|
|
478
|
-
serializeVersion: (data) => encodeActor(data),
|
|
479
|
-
deserializeVersion: (bytes) => decodeActor(bytes)
|
|
480
|
-
});
|
|
481
|
-
var CONN_VERSIONED = createVersionedDataHandler({
|
|
482
|
-
currentVersion: CURRENT_VERSION,
|
|
483
|
-
migrations: /* @__PURE__ */ new Map(),
|
|
484
|
-
serializeVersion: (data) => encodeConn(data),
|
|
485
|
-
deserializeVersion: (bytes) => decodeConn(bytes)
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
// src/driver-helpers/utils.ts
|
|
489
|
-
function serializeEmptyPersistData(input) {
|
|
490
|
-
const persistData = {
|
|
491
|
-
input: input !== void 0 ? _chunkF3SQLO3Xcjs.bufferToArrayBuffer.call(void 0, cbor.encode(input)) : null,
|
|
492
|
-
hasInitialized: false,
|
|
493
|
-
state: _chunkF3SQLO3Xcjs.bufferToArrayBuffer.call(void 0, cbor.encode(void 0)),
|
|
494
|
-
scheduledEvents: []
|
|
495
|
-
};
|
|
496
|
-
return ACTOR_VERSIONED.serializeWithEmbeddedVersion(persistData);
|
|
497
|
-
}
|
|
498
|
-
function getInitialActorKvState(input) {
|
|
499
|
-
const persistData = serializeEmptyPersistData(input);
|
|
500
|
-
return [[KEYS.PERSIST_DATA, persistData]];
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
exports.createVersionedDataHandler = createVersionedDataHandler; exports.ACTOR_VERSIONED = ACTOR_VERSIONED; exports.CONN_VERSIONED = CONN_VERSIONED; exports.KEYS = KEYS; exports.makeConnKey = makeConnKey; exports.ClientConfigSchema = ClientConfigSchema; exports.DriverConfigSchema = DriverConfigSchema; exports.RunnerConfigSchema = RunnerConfigSchema; exports.getInitialActorKvState = getInitialActorKvState;
|
|
514
|
-
//# sourceMappingURL=chunk-2TZH6VO6.cjs.map
|