rivetkit 2.3.0-rc.8 → 2.3.0
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/browser/client.d.ts +481 -74
- package/dist/browser/client.js +174 -148
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +47 -18
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/agent-os/index.cjs +2160 -2086
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +479 -73
- package/dist/tsup/agent-os/index.d.ts +479 -73
- package/dist/tsup/agent-os/index.js +2160 -2086
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-KY3CERZR.js → chunk-2OTRTA3J.js} +7 -21
- package/dist/tsup/chunk-2OTRTA3J.js.map +1 -0
- package/dist/tsup/{chunk-HGW6PBWR.cjs → chunk-3677IIOV.cjs} +11 -25
- package/dist/tsup/chunk-3677IIOV.cjs.map +1 -0
- package/dist/tsup/{chunk-OT7FF6GB.cjs → chunk-47HHIEXH.cjs} +24 -9
- package/dist/tsup/chunk-47HHIEXH.cjs.map +1 -0
- package/dist/tsup/{chunk-EMFKMVJR.js → chunk-4JDSFJS5.js} +69 -58
- package/dist/tsup/chunk-4JDSFJS5.js.map +1 -0
- package/dist/tsup/{chunk-7HLFSAJP.cjs → chunk-7QKCIVAY.cjs} +225 -214
- package/dist/tsup/chunk-7QKCIVAY.cjs.map +1 -0
- package/dist/tsup/{chunk-AWTPTUQ7.cjs → chunk-B6VUNZUD.cjs} +10 -10
- package/dist/tsup/{chunk-AWTPTUQ7.cjs.map → chunk-B6VUNZUD.cjs.map} +1 -1
- package/dist/tsup/{chunk-D3T3ZBSY.js → chunk-BEI24WTI.js} +2 -2
- package/dist/tsup/{chunk-TMLOKTRB.js → chunk-BRP62GZC.js} +1 -1
- package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
- package/dist/tsup/{chunk-D5G75T7J.js → chunk-DPIMKYNB.js} +61 -2
- package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
- package/dist/tsup/{chunk-BATTOVHF.cjs → chunk-DXXJPH55.cjs} +40 -13
- package/dist/tsup/chunk-DXXJPH55.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-4BPKKZJO.cjs → chunk-I4LN3FNT.cjs} +10 -10
- package/dist/tsup/chunk-I4LN3FNT.cjs.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-KORQB2IR.cjs} +1 -1
- package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
- package/dist/tsup/{chunk-6TQSSJ4F.cjs → chunk-LVTBW2RE.cjs} +3 -3
- package/dist/tsup/{chunk-6TQSSJ4F.cjs.map → chunk-LVTBW2RE.cjs.map} +1 -1
- package/dist/tsup/{chunk-4JU3IPG2.js → chunk-MEHBWPLJ.js} +6 -6
- package/dist/tsup/chunk-MEHBWPLJ.js.map +1 -0
- package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-NIY3RSPX.cjs} +62 -3
- package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
- package/dist/tsup/{chunk-UZXQEGVJ.js → chunk-P2GNQ4RN.js} +4 -4
- package/dist/tsup/{chunk-UZXQEGVJ.js.map → chunk-P2GNQ4RN.js.map} +1 -1
- package/dist/tsup/{chunk-VUGENVIK.js → chunk-UMZVD6DQ.js} +22 -7
- package/dist/tsup/chunk-UMZVD6DQ.js.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
- package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
- package/dist/tsup/{chunk-GBG63SUG.js → chunk-VTTFNQQI.js} +32 -5
- package/dist/tsup/chunk-VTTFNQQI.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +5 -5
- package/dist/tsup/client/mod.d.ts +5 -5
- 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/{config-Ak1lv4gF.d.ts → config-BxWAw3iH.d.ts} +512 -27
- package/dist/tsup/{config-DU_xj4qZ.d.cts → config-CZQQ-mso.d.cts} +512 -27
- package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.cts} +1 -2
- package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.ts} +1 -2
- package/dist/tsup/{context-DAAp4Lpg.d.ts → context-Bw7xq8w3.d.cts} +8 -8
- package/dist/tsup/{context-Dt_L55q8.d.cts → context-D8QA76sV.d.ts} +8 -8
- package/dist/tsup/db/drizzle.cjs +3 -3
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +2 -2
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/inspector-tab/mod.cjs +173 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +250 -0
- package/dist/tsup/inspector-tab/mod.d.ts +250 -0
- package/dist/tsup/inspector-tab/mod.js +173 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +615 -348
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +511 -244
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -4
- package/dist/tsup/test/mod.d.ts +4 -4
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.cts} +1 -1
- package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.ts} +1 -1
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +279 -279
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +6 -6
- package/dist/tsup/workflow/mod.d.ts +6 -6
- package/dist/tsup/workflow/mod.js +380 -380
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +29 -9
- package/src/actor/config.ts +156 -51
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +17 -19
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +8 -2
- package/src/actor/instance/mod.ts +26 -34
- package/src/actor/keys.ts +1 -1
- package/src/actor/mod.ts +22 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/client/actor-common.ts +87 -54
- package/src/client/actor-conn.ts +11 -11
- package/src/client/actor-handle.ts +69 -52
- package/src/client/actor-query.ts +5 -5
- package/src/client/errors.ts +1 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -4
- package/src/client/raw-utils.ts +8 -6
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +2 -6
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/transport/v1.ts +659 -543
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +2 -8
- package/src/common/database/native-database.ts +1 -1
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +13 -17
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +3 -2
- package/src/common/router.ts +13 -17
- package/src/common/utils.ts +1 -2
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/mod.ts +1 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/drivers/engine/actor-driver.ts +48 -46
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +5 -5
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +1 -1
- package/src/engine-client/mod.ts +5 -3
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +5 -11
- package/src/inspector/mod.ts +1 -3
- package/src/inspector-tab/mod.ts +315 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +40 -16
- package/src/registry/index.ts +226 -83
- package/src/registry/napi-runtime.ts +46 -12
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +307 -164
- package/src/registry/process-metrics.ts +90 -23
- package/src/registry/runtime.ts +53 -6
- package/src/registry/wasm-runtime.ts +30 -3
- package/src/serde.ts +1 -1
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +11 -8
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +6 -0
- package/src/utils/router.ts +1 -1
- package/src/utils/serve.ts +4 -5
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +30 -29
- package/src/workflow/driver.ts +4 -6
- package/src/workflow/inspector.ts +2 -2
- package/src/workflow/mod.ts +15 -17
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-4BPKKZJO.cjs.map +0 -1
- package/dist/tsup/chunk-4JU3IPG2.js.map +0 -1
- package/dist/tsup/chunk-7HLFSAJP.cjs.map +0 -1
- package/dist/tsup/chunk-BATTOVHF.cjs.map +0 -1
- package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
- package/dist/tsup/chunk-EMFKMVJR.js.map +0 -1
- package/dist/tsup/chunk-GBG63SUG.js.map +0 -1
- package/dist/tsup/chunk-HGW6PBWR.cjs.map +0 -1
- package/dist/tsup/chunk-KY3CERZR.js.map +0 -1
- package/dist/tsup/chunk-OT7FF6GB.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
- package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
- package/dist/tsup/chunk-VUGENVIK.js.map +0 -1
- package/dist/tsup/process-metrics-NW754INA.js +0 -118
- package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
- package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
- package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
- /package/dist/tsup/{chunk-D3T3ZBSY.js.map → chunk-BEI24WTI.js.map} +0 -0
package/dist/tsup/mod.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
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(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2; var _class3;
|
|
2
2
|
|
|
3
|
+
var _chunk47HHIEXHcjs = require('./chunk-47HHIEXH.cjs');
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
var _chunkSRNOPUC6cjs = require('./chunk-SRNOPUC6.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkNIY3RSPXcjs = require('./chunk-NIY3RSPX.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ var _chunkOT7FF6GBcjs = require('./chunk-OT7FF6GB.cjs');
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _chunk7QKCIVAYcjs = require('./chunk-7QKCIVAY.cjs');
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
@@ -27,15 +27,15 @@ var _chunk7HLFSAJPcjs = require('./chunk-7HLFSAJP.cjs');
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
var
|
|
30
|
+
var _chunkVE2X4KMGcjs = require('./chunk-VE2X4KMG.cjs');
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
var _chunk3677IIOVcjs = require('./chunk-3677IIOV.cjs');
|
|
36
|
+
require('./chunk-ZA7FLHKH.cjs');
|
|
37
|
+
require('./chunk-LVTBW2RE.cjs');
|
|
35
38
|
|
|
36
|
-
var _chunkHGW6PBWRcjs = require('./chunk-HGW6PBWR.cjs');
|
|
37
|
-
require('./chunk-2NDZ7JCR.cjs');
|
|
38
|
-
require('./chunk-6TQSSJ4F.cjs');
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
@@ -60,8 +60,8 @@ require('./chunk-6TQSSJ4F.cjs');
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
var _chunkBATTOVHFcjs = require('./chunk-BATTOVHF.cjs');
|
|
64
63
|
|
|
64
|
+
var _chunkDXXJPH55cjs = require('./chunk-DXXJPH55.cjs');
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
|
|
@@ -71,11 +71,12 @@ var _chunkBATTOVHFcjs = require('./chunk-BATTOVHF.cjs');
|
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
|
|
75
|
+
var _chunkKORQB2IRcjs = require('./chunk-KORQB2IR.cjs');
|
|
75
76
|
|
|
76
77
|
// src/actor/log.ts
|
|
77
78
|
function loggerWithoutContext() {
|
|
78
|
-
return
|
|
79
|
+
return _chunkDXXJPH55cjs.getLogger.call(void 0, "actor-runtime");
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
// src/actor/definition.ts
|
|
@@ -108,7 +109,7 @@ function actor(input) {
|
|
|
108
109
|
warnDeprecatedShutdownTimeoutKeys(
|
|
109
110
|
input == null ? void 0 : input.options
|
|
110
111
|
);
|
|
111
|
-
const config =
|
|
112
|
+
const config = _chunkNIY3RSPXcjs.ActorConfigSchema.parse(input);
|
|
112
113
|
return new ActorDefinition(config);
|
|
113
114
|
}
|
|
114
115
|
function isStaticActorDefinition(definition) {
|
|
@@ -143,7 +144,7 @@ function hasSchemaConfigKey(schemas, key) {
|
|
|
143
144
|
if (!schemas) {
|
|
144
145
|
return false;
|
|
145
146
|
}
|
|
146
|
-
return Object.
|
|
147
|
+
return Object.hasOwn(schemas, key);
|
|
147
148
|
}
|
|
148
149
|
function getEventCanSubscribe(schemas, key) {
|
|
149
150
|
const schema = schemas == null ? void 0 : schemas[key];
|
|
@@ -190,7 +191,7 @@ function validateSchemaSync(schemas, key, data) {
|
|
|
190
191
|
if (isStandardSchema(schema)) {
|
|
191
192
|
const result = schema["~standard"].validate(data);
|
|
192
193
|
if (isPromiseLike(result)) {
|
|
193
|
-
throw
|
|
194
|
+
throw _chunkKORQB2IRcjs.unsupportedFeature.call(void 0, "async schema validation");
|
|
194
195
|
}
|
|
195
196
|
if (result.issues) {
|
|
196
197
|
return { success: false, issues: [...result.issues] };
|
|
@@ -204,10 +205,10 @@ function validateSchemaSync(schemas, key, data) {
|
|
|
204
205
|
}
|
|
205
206
|
|
|
206
207
|
// src/common/inline-websocket-adapter.ts
|
|
207
|
-
var _ws = require('hono/ws');
|
|
208
208
|
var _virtualwebsocket = require('@rivetkit/virtual-websocket');
|
|
209
|
+
var _ws = require('hono/ws');
|
|
209
210
|
function logger() {
|
|
210
|
-
return
|
|
211
|
+
return _chunkDXXJPH55cjs.getLogger.call(void 0, "inline-websocket-adapter");
|
|
211
212
|
}
|
|
212
213
|
var InlineWebSocketAdapter = class {
|
|
213
214
|
#handler;
|
|
@@ -361,12 +362,27 @@ var InlineWebSocketAdapter = class {
|
|
|
361
362
|
var _hono = require('hono');
|
|
362
363
|
|
|
363
364
|
// src/common/engine.ts
|
|
365
|
+
var ENGINE_HOST = "127.0.0.1";
|
|
364
366
|
var ENGINE_PORT = 6420;
|
|
365
|
-
var ENGINE_ENDPOINT =
|
|
367
|
+
var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
|
|
368
|
+
function buildEngineEndpoint(host, port) {
|
|
369
|
+
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
370
|
+
return `http://${urlHost}:${port}`;
|
|
371
|
+
}
|
|
372
|
+
function isLocalEngineEndpoint(endpoint) {
|
|
373
|
+
let url;
|
|
374
|
+
try {
|
|
375
|
+
url = new URL(endpoint);
|
|
376
|
+
} catch (e) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
const hostname = url.hostname.toLowerCase();
|
|
380
|
+
return hostname === "localhost" || hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]" || hostname === "::1" || hostname === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname);
|
|
381
|
+
}
|
|
366
382
|
|
|
367
383
|
// src/registry/log.ts
|
|
368
384
|
function logger2() {
|
|
369
|
-
return
|
|
385
|
+
return _chunkDXXJPH55cjs.getLogger.call(void 0, "registry");
|
|
370
386
|
}
|
|
371
387
|
|
|
372
388
|
// src/serverless/configure.ts
|
|
@@ -377,10 +393,13 @@ function sleep(ms) {
|
|
|
377
393
|
}
|
|
378
394
|
function configureTimeoutMs() {
|
|
379
395
|
const value = process.env.RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS;
|
|
380
|
-
if (value === void 0 || value === "")
|
|
396
|
+
if (value === void 0 || value === "")
|
|
397
|
+
return DEFAULT_CONFIGURE_TIMEOUT_MS;
|
|
381
398
|
const parsed = Number(value);
|
|
382
399
|
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
383
|
-
throw new Error(
|
|
400
|
+
throw new Error(
|
|
401
|
+
"RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS must be a finite non-negative number"
|
|
402
|
+
);
|
|
384
403
|
}
|
|
385
404
|
return parsed;
|
|
386
405
|
}
|
|
@@ -394,17 +413,23 @@ async function configureServerlessPool(config) {
|
|
|
394
413
|
attempts += 1;
|
|
395
414
|
try {
|
|
396
415
|
if (!config.namespace) {
|
|
397
|
-
throw new Error(
|
|
416
|
+
throw new Error(
|
|
417
|
+
"namespace is required for serverless configuration"
|
|
418
|
+
);
|
|
398
419
|
}
|
|
399
420
|
if (!config.endpoint) {
|
|
400
|
-
throw new Error(
|
|
421
|
+
throw new Error(
|
|
422
|
+
"endpoint is required for serverless configuration"
|
|
423
|
+
);
|
|
401
424
|
}
|
|
402
425
|
if (!config.configurePool) {
|
|
403
|
-
throw new Error(
|
|
426
|
+
throw new Error(
|
|
427
|
+
"configurePool is required for serverless configuration"
|
|
428
|
+
);
|
|
404
429
|
}
|
|
405
430
|
const customConfig = config.configurePool;
|
|
406
|
-
const clientConfig =
|
|
407
|
-
const dcsRes = await
|
|
431
|
+
const clientConfig = _chunk7QKCIVAYcjs.convertRegistryConfigToClientConfig.call(void 0, config);
|
|
432
|
+
const dcsRes = await _chunk7QKCIVAYcjs.getDatacenters.call(void 0, clientConfig);
|
|
408
433
|
const poolName = _nullishCoalesce(customConfig.name, () => ( "default"));
|
|
409
434
|
const serverlessToken = _nullishCoalesce(config.token, () => ( config.publicToken));
|
|
410
435
|
const headers = {
|
|
@@ -426,7 +451,7 @@ async function configureServerlessPool(config) {
|
|
|
426
451
|
metadata: _nullishCoalesce(customConfig.metadata, () => ( {})),
|
|
427
452
|
drain_on_version_upgrade: _nullishCoalesce(customConfig.drainOnVersionUpgrade, () => ( true))
|
|
428
453
|
};
|
|
429
|
-
await
|
|
454
|
+
await _chunk7QKCIVAYcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
|
|
430
455
|
datacenters: Object.fromEntries(
|
|
431
456
|
dcsRes.datacenters.map((dc) => [dc.name, serverlessConfig])
|
|
432
457
|
)
|
|
@@ -443,7 +468,7 @@ async function configureServerlessPool(config) {
|
|
|
443
468
|
logger2().warn({
|
|
444
469
|
msg: "serverless pool configuration attempt failed",
|
|
445
470
|
attempts,
|
|
446
|
-
error:
|
|
471
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, error)
|
|
447
472
|
});
|
|
448
473
|
await sleep(CONFIGURE_RETRY_DELAY_MS);
|
|
449
474
|
}
|
|
@@ -451,7 +476,7 @@ async function configureServerlessPool(config) {
|
|
|
451
476
|
logger2().error({
|
|
452
477
|
msg: "failed to configure serverless pool, validate endpoint is configured correctly then restart this process",
|
|
453
478
|
attempts,
|
|
454
|
-
error:
|
|
479
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, lastError)
|
|
455
480
|
});
|
|
456
481
|
throw lastError;
|
|
457
482
|
}
|
|
@@ -459,7 +484,7 @@ async function configureServerlessPool(config) {
|
|
|
459
484
|
// src/utils/serve.ts
|
|
460
485
|
var _getport = require('get-port'); var _getport2 = _interopRequireDefault(_getport);
|
|
461
486
|
var serveStaticLoaderPromises = {};
|
|
462
|
-
async function crossPlatformServe(config, httpPort, app, runtime =
|
|
487
|
+
async function crossPlatformServe(config, httpPort, app, runtime = _chunkDXXJPH55cjs.detectRuntime.call(void 0, )) {
|
|
463
488
|
logger2().debug({ msg: "detected runtime for serve", runtime });
|
|
464
489
|
switch (runtime) {
|
|
465
490
|
case "deno":
|
|
@@ -510,7 +535,7 @@ async function serveNode(config, httpPort, app) {
|
|
|
510
535
|
} catch (err) {
|
|
511
536
|
logger2().error({
|
|
512
537
|
msg: "failed to import @hono/node-server. please run 'npm install @hono/node-server @hono/node-ws'",
|
|
513
|
-
error:
|
|
538
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, err)
|
|
514
539
|
});
|
|
515
540
|
process.exit(1);
|
|
516
541
|
}
|
|
@@ -525,7 +550,7 @@ async function serveNode(config, httpPort, app) {
|
|
|
525
550
|
} catch (err) {
|
|
526
551
|
logger2().error({
|
|
527
552
|
msg: "failed to import @hono/node-ws. please run 'npm install @hono/node-server @hono/node-ws'",
|
|
528
|
-
error:
|
|
553
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, err)
|
|
529
554
|
});
|
|
530
555
|
process.exit(1);
|
|
531
556
|
}
|
|
@@ -556,7 +581,7 @@ async function serveDeno(config, httpPort, app) {
|
|
|
556
581
|
} catch (err) {
|
|
557
582
|
logger2().error({
|
|
558
583
|
msg: "failed to import hono/deno",
|
|
559
|
-
error:
|
|
584
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, err)
|
|
560
585
|
});
|
|
561
586
|
process.exit(1);
|
|
562
587
|
}
|
|
@@ -578,7 +603,7 @@ async function serveBun(config, httpPort, app) {
|
|
|
578
603
|
} catch (err) {
|
|
579
604
|
logger2().error({
|
|
580
605
|
msg: "failed to import hono/bun",
|
|
581
|
-
error:
|
|
606
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, err)
|
|
582
607
|
});
|
|
583
608
|
process.exit(1);
|
|
584
609
|
}
|
|
@@ -602,20 +627,20 @@ var _zod = require('zod');
|
|
|
602
627
|
var _v4 = require('zod/v4');
|
|
603
628
|
var warnedMissingVersion = false;
|
|
604
629
|
var EnvoyConfigSchema = _v4.z.object({
|
|
605
|
-
poolName: _v4.z.string().default(() => _nullishCoalesce(
|
|
630
|
+
poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkDXXJPH55cjs.getRivetPool.call(void 0, ), () => ( "default"))),
|
|
606
631
|
version: _v4.z.number().default(() => {
|
|
607
|
-
const version =
|
|
632
|
+
const version = _chunkDXXJPH55cjs.getRivetEnvoyVersion.call(void 0, );
|
|
608
633
|
if (version !== void 0) return version;
|
|
609
|
-
if (
|
|
634
|
+
if (_chunkDXXJPH55cjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
|
|
610
635
|
warnedMissingVersion = true;
|
|
611
|
-
|
|
636
|
+
_chunkDXXJPH55cjs.getLogger.call(void 0, "rivetkit").error(
|
|
612
637
|
"RIVET_ENVOY_VERSION is not set. Actors will not be versioned, which means they won't be drained on deploy. This is only needed when self-hosting or using a custom envoy (not needed for Rivet Compute). Set this as a build arg in your Dockerfile. See https://rivet.dev/docs/actors/versions"
|
|
613
638
|
);
|
|
614
639
|
}
|
|
615
640
|
return 1;
|
|
616
641
|
}),
|
|
617
642
|
// Deprecated.
|
|
618
|
-
totalSlots: _v4.z.number().default(() => _nullishCoalesce(
|
|
643
|
+
totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkDXXJPH55cjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
|
|
619
644
|
envoyKey: _v4.z.string().optional()
|
|
620
645
|
});
|
|
621
646
|
|
|
@@ -653,7 +678,7 @@ var ServerlessConfigSchema = _v4.z.object({
|
|
|
653
678
|
*
|
|
654
679
|
* Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
|
|
655
680
|
*/
|
|
656
|
-
publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => (
|
|
681
|
+
publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkDXXJPH55cjs.getRivetPublicEndpoint.call(void 0, )))),
|
|
657
682
|
/**
|
|
658
683
|
* Token that clients should use when connecting via the public endpoint.
|
|
659
684
|
*
|
|
@@ -661,7 +686,7 @@ var ServerlessConfigSchema = _v4.z.object({
|
|
|
661
686
|
*
|
|
662
687
|
* Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
|
|
663
688
|
*/
|
|
664
|
-
publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => (
|
|
689
|
+
publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkDXXJPH55cjs.getRivetPublicToken.call(void 0, ))))
|
|
665
690
|
// There is no publicNamespace config option because the frontend and backend
|
|
666
691
|
// cannot use different namespaces. The namespace is extracted from the
|
|
667
692
|
// publicEndpoint URL auth syntax if provided.
|
|
@@ -715,7 +740,7 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
715
740
|
* Runtime binding to use for RivetKit core.
|
|
716
741
|
* */
|
|
717
742
|
runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
|
|
718
|
-
const rawRuntime = _nullishCoalesce(val, () => (
|
|
743
|
+
const rawRuntime = _nullishCoalesce(val, () => ( _chunkDXXJPH55cjs.getRivetkitRuntime.call(void 0, )));
|
|
719
744
|
if (rawRuntime === void 0) {
|
|
720
745
|
return "auto";
|
|
721
746
|
}
|
|
@@ -752,7 +777,7 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
752
777
|
* */
|
|
753
778
|
logging: _zod.z.object({
|
|
754
779
|
baseLogger: _zod.z.custom().optional(),
|
|
755
|
-
level:
|
|
780
|
+
level: _chunkDXXJPH55cjs.LogLevelSchema.optional()
|
|
756
781
|
}).optional().default(() => ({})),
|
|
757
782
|
// MARK: Routing
|
|
758
783
|
// // This is a function to allow for lazy configuration of upgradeWebSocket on the
|
|
@@ -770,9 +795,9 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
770
795
|
*
|
|
771
796
|
* Can also be set via RIVET_ENDPOINT environment variables.
|
|
772
797
|
*/
|
|
773
|
-
endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => (
|
|
774
|
-
token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => (
|
|
775
|
-
namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => (
|
|
798
|
+
endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkDXXJPH55cjs.getRivetEngine.call(void 0, ))), () => ( _chunkDXXJPH55cjs.getRivetEndpoint.call(void 0, )))),
|
|
799
|
+
token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkDXXJPH55cjs.getRivetToken.call(void 0, )))),
|
|
800
|
+
namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkDXXJPH55cjs.getRivetNamespace.call(void 0, )))),
|
|
776
801
|
headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
|
|
777
802
|
// MARK: Client
|
|
778
803
|
// TODO:
|
|
@@ -812,9 +837,21 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
812
837
|
*
|
|
813
838
|
* Starts the full Rust engine process locally.
|
|
814
839
|
*/
|
|
815
|
-
startEngine: _zod.z.boolean().default(() =>
|
|
840
|
+
startEngine: _zod.z.boolean().default(() => _chunkDXXJPH55cjs.getRivetRunEngine.call(void 0, )),
|
|
841
|
+
/**
|
|
842
|
+
* @experimental
|
|
843
|
+
*
|
|
844
|
+
* Host to bind the spawned local engine process to.
|
|
845
|
+
*/
|
|
846
|
+
engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkDXXJPH55cjs.getRivetRunEngineHost.call(void 0, ), () => ( ENGINE_HOST))),
|
|
847
|
+
/**
|
|
848
|
+
* @experimental
|
|
849
|
+
*
|
|
850
|
+
* Port to bind the spawned local engine process to.
|
|
851
|
+
*/
|
|
852
|
+
enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunkDXXJPH55cjs.getRivetRunEnginePort.call(void 0, ), () => ( ENGINE_PORT))),
|
|
816
853
|
/** @experimental */
|
|
817
|
-
engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(
|
|
854
|
+
engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkDXXJPH55cjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkDXXJPH55cjs.VERSION))),
|
|
818
855
|
/**
|
|
819
856
|
* @experimental
|
|
820
857
|
*
|
|
@@ -848,7 +885,7 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
848
885
|
* after calling `CoreRegistry::shutdown()`. Defaults to the
|
|
849
886
|
* engine-provided actor stop threshold once the envoy connects.
|
|
850
887
|
*
|
|
851
|
-
* Must be
|
|
888
|
+
* Must be long enough for rivetkit-core to drain the envoy.
|
|
852
889
|
*/
|
|
853
890
|
gracePeriodMs: _zod.z.number().int().min(1e3).optional(),
|
|
854
891
|
/**
|
|
@@ -862,7 +899,7 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
862
899
|
}))
|
|
863
900
|
}).transform((config, ctx) => {
|
|
864
901
|
var _a, _b, _c;
|
|
865
|
-
const isDevEnv =
|
|
902
|
+
const isDevEnv = _chunkDXXJPH55cjs.isDev.call(void 0, );
|
|
866
903
|
const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
|
|
867
904
|
if (config.runtime === "wasm" && sqliteBackend === "local") {
|
|
868
905
|
ctx.addIssue({
|
|
@@ -872,7 +909,7 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
872
909
|
});
|
|
873
910
|
}
|
|
874
911
|
const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
|
|
875
|
-
const parsedEndpoint = config.endpoint ?
|
|
912
|
+
const parsedEndpoint = config.endpoint ? _chunk7QKCIVAYcjs.tryParseEndpoint.call(void 0, ctx, {
|
|
876
913
|
endpoint: config.endpoint,
|
|
877
914
|
path: ["endpoint"],
|
|
878
915
|
namespace: config.namespace,
|
|
@@ -890,13 +927,17 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
890
927
|
message: "configurePool requires either endpoint or startEngine"
|
|
891
928
|
});
|
|
892
929
|
}
|
|
893
|
-
const
|
|
930
|
+
const localEngineEndpoint = buildEngineEndpoint(
|
|
931
|
+
config.engineHost,
|
|
932
|
+
config.enginePort
|
|
933
|
+
);
|
|
934
|
+
const endpoint = config.startEngine ? localEngineEndpoint : _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint), () => ( (isDevEnv ? buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT) : void 0)));
|
|
894
935
|
const validateServerlessEndpoint = Boolean(
|
|
895
936
|
config.startEngine || parsedEndpoint
|
|
896
937
|
);
|
|
897
938
|
const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
|
|
898
939
|
const token = _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token));
|
|
899
|
-
const parsedPublicEndpoint = config.serverless.publicEndpoint ?
|
|
940
|
+
const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunk7QKCIVAYcjs.tryParseEndpoint.call(void 0, ctx, {
|
|
900
941
|
endpoint: config.serverless.publicEndpoint,
|
|
901
942
|
path: ["serverless", "publicEndpoint"]
|
|
902
943
|
}) : void 0;
|
|
@@ -907,7 +948,7 @@ var RegistryConfigSchema = _zod.z.object({
|
|
|
907
948
|
path: ["serverless", "publicEndpoint"]
|
|
908
949
|
});
|
|
909
950
|
}
|
|
910
|
-
const publicEndpoint = _nullishCoalesce((parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.endpoint), () => ( (isDevEnv && config.startEngine ?
|
|
951
|
+
const publicEndpoint = _nullishCoalesce((parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.endpoint), () => ( (isDevEnv && config.startEngine ? endpoint : void 0)));
|
|
911
952
|
const publicNamespace = parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.namespace;
|
|
912
953
|
const publicToken = _nullishCoalesce((parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.token), () => ( config.serverless.publicToken));
|
|
913
954
|
return {
|
|
@@ -931,30 +972,30 @@ function buildActorNames(config) {
|
|
|
931
972
|
Object.keys(config.use).map((actorName) => {
|
|
932
973
|
const definition = config.use[actorName];
|
|
933
974
|
const options = _nullishCoalesce(definition.config.options, () => ( {}));
|
|
934
|
-
const runMeta =
|
|
975
|
+
const runMeta = _chunkNIY3RSPXcjs.getRunMetadata.call(void 0, definition.config.run);
|
|
935
976
|
const metadata = {};
|
|
936
977
|
metadata.icon = _nullishCoalesce(options.icon, () => ( runMeta.icon));
|
|
937
978
|
metadata.name = _nullishCoalesce(options.name, () => ( runMeta.name));
|
|
938
979
|
metadata.preload = {
|
|
939
980
|
keys: [
|
|
940
|
-
Array.from(
|
|
941
|
-
Array.from(
|
|
942
|
-
Array.from(
|
|
943
|
-
Array.from(
|
|
981
|
+
Array.from(_chunkVE2X4KMGcjs.KEYS.PERSIST_DATA),
|
|
982
|
+
Array.from(_chunkVE2X4KMGcjs.KEYS.INSPECTOR_TOKEN),
|
|
983
|
+
Array.from(_chunkVE2X4KMGcjs.queueMetadataKey.call(void 0, )),
|
|
984
|
+
Array.from(_chunkVE2X4KMGcjs.KEYS.LAST_PUSHED_ALARM)
|
|
944
985
|
],
|
|
945
986
|
prefixes: [
|
|
946
987
|
{
|
|
947
|
-
prefix: Array.from(
|
|
988
|
+
prefix: Array.from(_chunkVE2X4KMGcjs.workflowStoragePrefix.call(void 0, )),
|
|
948
989
|
maxBytes: _nullishCoalesce(options.preloadMaxWorkflowBytes, () => ( 131072)),
|
|
949
990
|
partial: false
|
|
950
991
|
},
|
|
951
992
|
{
|
|
952
|
-
prefix: Array.from(
|
|
993
|
+
prefix: Array.from(_chunkVE2X4KMGcjs.KEYS.CONN_PREFIX),
|
|
953
994
|
maxBytes: _nullishCoalesce(options.preloadMaxConnectionsBytes, () => ( 65536)),
|
|
954
995
|
partial: false
|
|
955
996
|
},
|
|
956
997
|
{
|
|
957
|
-
prefix: Array.from(
|
|
998
|
+
prefix: Array.from(_chunkVE2X4KMGcjs.queueMessagesPrefix.call(void 0, )),
|
|
958
999
|
maxBytes: 65536,
|
|
959
1000
|
partial: false
|
|
960
1001
|
}
|
|
@@ -1024,7 +1065,7 @@ var DocRegistryConfigSchema = _zod.z.object({
|
|
|
1024
1065
|
noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
|
|
1025
1066
|
sqlite: DocSqliteConfigSchema,
|
|
1026
1067
|
logging: _zod.z.object({
|
|
1027
|
-
level:
|
|
1068
|
+
level: _chunkDXXJPH55cjs.LogLevelSchema.optional().describe(
|
|
1028
1069
|
"Log level for RivetKit. Default: 'warn'"
|
|
1029
1070
|
)
|
|
1030
1071
|
}).optional().describe("Logging configuration."),
|
|
@@ -1069,7 +1110,7 @@ function shouldAttachNativeKvError(message) {
|
|
|
1069
1110
|
function enrichNativeDatabaseError(database, error) {
|
|
1070
1111
|
var _a;
|
|
1071
1112
|
const bridgeReason = typeof error === "string" ? error : error instanceof Error ? error.message : void 0;
|
|
1072
|
-
const bridged = bridgeReason === void 0 ? void 0 :
|
|
1113
|
+
const bridged = bridgeReason === void 0 ? void 0 : _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
|
|
1073
1114
|
if (bridged) {
|
|
1074
1115
|
throw bridged;
|
|
1075
1116
|
}
|
|
@@ -1299,29 +1340,6 @@ function lastInsertRowIdColumnName(sql) {
|
|
|
1299
1340
|
return alias;
|
|
1300
1341
|
}
|
|
1301
1342
|
|
|
1302
|
-
// src/registry/write-through-proxy.ts
|
|
1303
|
-
var _onchange = require('@rivetkit/on-change'); var _onchange2 = _interopRequireDefault(_onchange);
|
|
1304
|
-
function createWriteThroughProxy(value, commit, beforeChange) {
|
|
1305
|
-
if (!value || typeof value !== "object") {
|
|
1306
|
-
return value;
|
|
1307
|
-
}
|
|
1308
|
-
return _onchange2.default.call(void 0,
|
|
1309
|
-
value,
|
|
1310
|
-
() => {
|
|
1311
|
-
commit(value);
|
|
1312
|
-
},
|
|
1313
|
-
{
|
|
1314
|
-
// Rejection is throw-based: beforeChange throws to prevent the
|
|
1315
|
-
// mutation. We always return true so on-change applies the change
|
|
1316
|
-
// if beforeChange did not throw.
|
|
1317
|
-
onValidate(_path, newValue) {
|
|
1318
|
-
beforeChange == null ? void 0 : beforeChange(newValue);
|
|
1319
|
-
return true;
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
);
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
1343
|
// src/registry/runtime.ts
|
|
1326
1344
|
function normalizeRuntimeSqlExecuteResult(result) {
|
|
1327
1345
|
return result;
|
|
@@ -1442,15 +1460,32 @@ var NapiCoreRuntime = (_class = class {
|
|
|
1442
1460
|
async shutdownRegistry(registry) {
|
|
1443
1461
|
await asNativeRegistry(registry).shutdown();
|
|
1444
1462
|
}
|
|
1445
|
-
async
|
|
1446
|
-
|
|
1463
|
+
async registryActorStopThresholdMs(registry) {
|
|
1464
|
+
return await _asyncNullishCoalesce(await asNativeRegistry(registry).actorStopThresholdMs(), async () => ( void 0));
|
|
1465
|
+
}
|
|
1466
|
+
async registryHealth(registry) {
|
|
1467
|
+
const response = await asNativeRegistry(registry).health();
|
|
1447
1468
|
return {
|
|
1448
|
-
|
|
1449
|
-
|
|
1469
|
+
status: response.status,
|
|
1470
|
+
headers: response.headers,
|
|
1471
|
+
body: response.body
|
|
1450
1472
|
};
|
|
1451
1473
|
}
|
|
1452
|
-
async
|
|
1453
|
-
|
|
1474
|
+
async registryMetadata(registry) {
|
|
1475
|
+
const response = asNativeRegistry(registry).metadata();
|
|
1476
|
+
return {
|
|
1477
|
+
status: response.status,
|
|
1478
|
+
headers: response.headers,
|
|
1479
|
+
body: response.body
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
async registryMetrics(registry) {
|
|
1483
|
+
const response = asNativeRegistry(registry).metrics();
|
|
1484
|
+
return {
|
|
1485
|
+
status: response.status,
|
|
1486
|
+
headers: response.headers,
|
|
1487
|
+
body: response.body
|
|
1488
|
+
};
|
|
1454
1489
|
}
|
|
1455
1490
|
async handleServerlessRequest(registry, req, onStreamEvent, cancelToken, config) {
|
|
1456
1491
|
return await asNativeRegistry(registry).handleServerlessRequest(
|
|
@@ -1575,6 +1610,9 @@ var NapiCoreRuntime = (_class = class {
|
|
|
1575
1610
|
async actorWaitForTrackedShutdownWork(ctx) {
|
|
1576
1611
|
return await asNativeActorContext(ctx).waitForTrackedShutdownWork();
|
|
1577
1612
|
}
|
|
1613
|
+
async actorWaitForTrackedShutdownWorkUnbounded(ctx) {
|
|
1614
|
+
await asNativeActorContext(ctx).waitForTrackedShutdownWorkUnbounded();
|
|
1615
|
+
}
|
|
1578
1616
|
actorKeepAwake(ctx, promise) {
|
|
1579
1617
|
asNativeActorContext(ctx).keepAwake(promise);
|
|
1580
1618
|
}
|
|
@@ -1686,8 +1724,12 @@ var NapiCoreRuntime = (_class = class {
|
|
|
1686
1724
|
)
|
|
1687
1725
|
);
|
|
1688
1726
|
}
|
|
1689
|
-
async actorQueueWaitForNamesAvailable(ctx, names, options) {
|
|
1690
|
-
await asNativeActorContext(ctx).queue().waitForNamesAvailable(
|
|
1727
|
+
async actorQueueWaitForNamesAvailable(ctx, names, options, signal) {
|
|
1728
|
+
await asNativeActorContext(ctx).queue().waitForNamesAvailable(
|
|
1729
|
+
names,
|
|
1730
|
+
options,
|
|
1731
|
+
signal ? asNativeCancellationToken(signal) : signal
|
|
1732
|
+
);
|
|
1691
1733
|
}
|
|
1692
1734
|
async actorQueueEnqueueAndWait(ctx, name, body, options, signal) {
|
|
1693
1735
|
return await asNativeActorContext(ctx).queue().enqueueAndWait(
|
|
@@ -1821,20 +1863,18 @@ function validateQueueComplete(schemas, name, response) {
|
|
|
1821
1863
|
response
|
|
1822
1864
|
);
|
|
1823
1865
|
if (!result.success) {
|
|
1824
|
-
throw validationError(
|
|
1866
|
+
throw validationError(
|
|
1867
|
+
`queue \`${name}\` completion response`,
|
|
1868
|
+
result.issues
|
|
1869
|
+
);
|
|
1825
1870
|
}
|
|
1826
1871
|
return result.data;
|
|
1827
1872
|
}
|
|
1828
1873
|
function validationError(target, issues) {
|
|
1829
|
-
return new (0,
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
{
|
|
1834
|
-
public: true,
|
|
1835
|
-
metadata: { issues }
|
|
1836
|
-
}
|
|
1837
|
-
);
|
|
1874
|
+
return new (0, _chunkKORQB2IRcjs.RivetError)("actor", "validation_error", `Invalid ${target}`, {
|
|
1875
|
+
public: true,
|
|
1876
|
+
metadata: { issues }
|
|
1877
|
+
});
|
|
1838
1878
|
}
|
|
1839
1879
|
|
|
1840
1880
|
// src/registry/wasm-runtime.ts
|
|
@@ -1900,16 +1940,16 @@ function normalizeQueueMessage(message) {
|
|
|
1900
1940
|
}
|
|
1901
1941
|
function normalizeWasmBridgeError(error) {
|
|
1902
1942
|
if (typeof error === "string") {
|
|
1903
|
-
return _nullishCoalesce(
|
|
1943
|
+
return _nullishCoalesce(_chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
|
|
1904
1944
|
}
|
|
1905
1945
|
if (error instanceof Error) {
|
|
1906
|
-
const bridged =
|
|
1946
|
+
const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.message);
|
|
1907
1947
|
if (bridged) {
|
|
1908
1948
|
return bridged;
|
|
1909
1949
|
}
|
|
1910
1950
|
}
|
|
1911
1951
|
if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
|
|
1912
|
-
const bridged =
|
|
1952
|
+
const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.reason);
|
|
1913
1953
|
if (bridged) {
|
|
1914
1954
|
return bridged;
|
|
1915
1955
|
}
|
|
@@ -1931,7 +1971,7 @@ function callWasmSync(invoke) {
|
|
|
1931
1971
|
}
|
|
1932
1972
|
}
|
|
1933
1973
|
function unsupportedWasmMethod(method2) {
|
|
1934
|
-
throw new (0,
|
|
1974
|
+
throw new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
1935
1975
|
"runtime",
|
|
1936
1976
|
"unsupported",
|
|
1937
1977
|
`Unsupported wasm runtime method: ${method2}`,
|
|
@@ -1992,8 +2032,18 @@ var WasmCoreRuntime = (_class2 = class {
|
|
|
1992
2032
|
async shutdownRegistry(registry) {
|
|
1993
2033
|
await callWasm(() => asWasmRegistry(registry).shutdown());
|
|
1994
2034
|
}
|
|
1995
|
-
async
|
|
1996
|
-
return {
|
|
2035
|
+
async registryHealth() {
|
|
2036
|
+
return {
|
|
2037
|
+
status: 200,
|
|
2038
|
+
headers: { "content-type": "application/json" },
|
|
2039
|
+
body: new TextEncoder().encode(
|
|
2040
|
+
JSON.stringify({
|
|
2041
|
+
status: "ok",
|
|
2042
|
+
runtime: "rivetkit",
|
|
2043
|
+
version: "wasm"
|
|
2044
|
+
})
|
|
2045
|
+
)
|
|
2046
|
+
};
|
|
1997
2047
|
}
|
|
1998
2048
|
async handleServerlessRequest(registry, req, onStreamEvent, cancelToken, config) {
|
|
1999
2049
|
return await callHandleAsync(
|
|
@@ -2148,6 +2198,12 @@ var WasmCoreRuntime = (_class2 = class {
|
|
|
2148
2198
|
"waitForTrackedShutdownWork"
|
|
2149
2199
|
);
|
|
2150
2200
|
}
|
|
2201
|
+
async actorWaitForTrackedShutdownWorkUnbounded(ctx) {
|
|
2202
|
+
await callHandle(
|
|
2203
|
+
asWasmActorContext(ctx),
|
|
2204
|
+
"waitForTrackedShutdownWorkUnbounded"
|
|
2205
|
+
);
|
|
2206
|
+
}
|
|
2151
2207
|
actorKeepAwake(ctx, promise) {
|
|
2152
2208
|
const wasmCtx = asWasmActorContext(ctx);
|
|
2153
2209
|
const regionId = callHandle(wasmCtx, "beginKeepAwake");
|
|
@@ -2295,9 +2351,15 @@ var WasmCoreRuntime = (_class2 = class {
|
|
|
2295
2351
|
)
|
|
2296
2352
|
);
|
|
2297
2353
|
}
|
|
2298
|
-
async actorQueueWaitForNamesAvailable(ctx, names, options) {
|
|
2354
|
+
async actorQueueWaitForNamesAvailable(ctx, names, options, signal) {
|
|
2299
2355
|
const queue2 = childHandle(asWasmActorContext(ctx), "queue");
|
|
2300
|
-
await callHandleAsync(
|
|
2356
|
+
await callHandleAsync(
|
|
2357
|
+
queue2,
|
|
2358
|
+
"waitForNamesAvailable",
|
|
2359
|
+
names,
|
|
2360
|
+
options,
|
|
2361
|
+
signal
|
|
2362
|
+
);
|
|
2301
2363
|
}
|
|
2302
2364
|
async actorQueueEnqueueAndWait(ctx, name, body, options, signal) {
|
|
2303
2365
|
const queue2 = childHandle(asWasmActorContext(ctx), "queue");
|
|
@@ -2389,6 +2451,33 @@ async function loadWasmRuntime(config) {
|
|
|
2389
2451
|
};
|
|
2390
2452
|
}
|
|
2391
2453
|
|
|
2454
|
+
// src/registry/native.ts
|
|
2455
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
2456
|
+
var _path2 = require('path'); var _path3 = _interopRequireDefault(_path2);
|
|
2457
|
+
|
|
2458
|
+
// src/registry/write-through-proxy.ts
|
|
2459
|
+
var _onchange = require('@rivetkit/on-change'); var _onchange2 = _interopRequireDefault(_onchange);
|
|
2460
|
+
function createWriteThroughProxy(value, commit, beforeChange) {
|
|
2461
|
+
if (!value || typeof value !== "object") {
|
|
2462
|
+
return value;
|
|
2463
|
+
}
|
|
2464
|
+
return _onchange2.default.call(void 0,
|
|
2465
|
+
value,
|
|
2466
|
+
() => {
|
|
2467
|
+
commit(value);
|
|
2468
|
+
},
|
|
2469
|
+
{
|
|
2470
|
+
// Rejection is throw-based: beforeChange throws to prevent the
|
|
2471
|
+
// mutation. We always return true so on-change applies the change
|
|
2472
|
+
// if beforeChange did not throw.
|
|
2473
|
+
onValidate(_path, newValue) {
|
|
2474
|
+
beforeChange == null ? void 0 : beforeChange(newValue);
|
|
2475
|
+
return true;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
);
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2392
2481
|
// src/registry/native.ts
|
|
2393
2482
|
var textEncoder = new TextEncoder();
|
|
2394
2483
|
var textDecoder = new TextDecoder();
|
|
@@ -2401,7 +2490,7 @@ function trySetProcessEnv(key, value) {
|
|
|
2401
2490
|
if (typeof process === "undefined") return;
|
|
2402
2491
|
try {
|
|
2403
2492
|
process.env[key] = value;
|
|
2404
|
-
} catch (
|
|
2493
|
+
} catch (e2) {
|
|
2405
2494
|
}
|
|
2406
2495
|
}
|
|
2407
2496
|
function detectRuntimeHost() {
|
|
@@ -2422,7 +2511,7 @@ function loadedRuntimeKind(runtime) {
|
|
|
2422
2511
|
case "wasm":
|
|
2423
2512
|
return "wasm";
|
|
2424
2513
|
}
|
|
2425
|
-
throw new (0,
|
|
2514
|
+
throw new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2426
2515
|
"config",
|
|
2427
2516
|
"unknown_runtime",
|
|
2428
2517
|
"RivetKit runtime must be NAPI or wasm.",
|
|
@@ -2438,7 +2527,7 @@ async function loadAutoRuntime(config, loaders = defaultRuntimeLoaders) {
|
|
|
2438
2527
|
}
|
|
2439
2528
|
try {
|
|
2440
2529
|
return (await loaders.loadNative()).runtime;
|
|
2441
|
-
} catch (
|
|
2530
|
+
} catch (e3) {
|
|
2442
2531
|
return (await loaders.loadWasm(config.wasm)).runtime;
|
|
2443
2532
|
}
|
|
2444
2533
|
}
|
|
@@ -2462,7 +2551,7 @@ function normalizeRuntimeConfigForKind(config, runtimeKind) {
|
|
|
2462
2551
|
return config;
|
|
2463
2552
|
}
|
|
2464
2553
|
if (sqliteBackendForConfig(config) === "local") {
|
|
2465
|
-
throw new (0,
|
|
2554
|
+
throw new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2466
2555
|
"config",
|
|
2467
2556
|
"wasm_local_sqlite",
|
|
2468
2557
|
"WebAssembly runtime cannot use local SQLite. Use remote SQLite instead.",
|
|
@@ -2528,14 +2617,14 @@ function getNativeConnPersistState(runtime, ctx, conn) {
|
|
|
2528
2617
|
return connState;
|
|
2529
2618
|
}
|
|
2530
2619
|
function stateMutationReentrantError() {
|
|
2531
|
-
return new (0,
|
|
2620
|
+
return new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2532
2621
|
"actor",
|
|
2533
2622
|
"state_mutation_reentrant",
|
|
2534
2623
|
"State mutations are not allowed inside onStateChange."
|
|
2535
2624
|
);
|
|
2536
2625
|
}
|
|
2537
2626
|
function databaseNotConfiguredError() {
|
|
2538
|
-
return new (0,
|
|
2627
|
+
return new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2539
2628
|
"actor",
|
|
2540
2629
|
"database_not_configured",
|
|
2541
2630
|
"database is not configured for this actor",
|
|
@@ -2543,7 +2632,7 @@ function databaseNotConfiguredError() {
|
|
|
2543
2632
|
);
|
|
2544
2633
|
}
|
|
2545
2634
|
function databaseClientNotReadyError() {
|
|
2546
|
-
return new (0,
|
|
2635
|
+
return new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2547
2636
|
"actor",
|
|
2548
2637
|
"database_client_not_ready",
|
|
2549
2638
|
"actor database client was not initialized before user code ran. this is an internal lifecycle error; the migration callback should have pre-warmed the client. file an issue if you can reproduce.",
|
|
@@ -2551,7 +2640,7 @@ function databaseClientNotReadyError() {
|
|
|
2551
2640
|
);
|
|
2552
2641
|
}
|
|
2553
2642
|
function stateNotEnabledError() {
|
|
2554
|
-
return new (0,
|
|
2643
|
+
return new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2555
2644
|
"actor",
|
|
2556
2645
|
"state_not_enabled",
|
|
2557
2646
|
"State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
|
|
@@ -2559,7 +2648,7 @@ function stateNotEnabledError() {
|
|
|
2559
2648
|
);
|
|
2560
2649
|
}
|
|
2561
2650
|
function nativeClientNotConfiguredError() {
|
|
2562
|
-
return new (0,
|
|
2651
|
+
return new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2563
2652
|
"native",
|
|
2564
2653
|
"client_not_configured",
|
|
2565
2654
|
"native actor client is not configured",
|
|
@@ -2567,7 +2656,7 @@ function nativeClientNotConfiguredError() {
|
|
|
2567
2656
|
);
|
|
2568
2657
|
}
|
|
2569
2658
|
function nativeEndpointNotConfiguredError() {
|
|
2570
|
-
return new (0,
|
|
2659
|
+
return new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
2571
2660
|
"native",
|
|
2572
2661
|
"endpoint_not_configured",
|
|
2573
2662
|
"registry endpoint is required for native envoy startup",
|
|
@@ -2601,21 +2690,23 @@ function resolveNativeDestroy(runtime, ctx) {
|
|
|
2601
2690
|
function clearNativeRuntimeState(runtime, ctx) {
|
|
2602
2691
|
callNativeSync(() => runtime.actorClearRuntimeState(ctx));
|
|
2603
2692
|
}
|
|
2604
|
-
async function cleanupNativeSleepRuntimeState(runtime, ctx) {
|
|
2605
|
-
const waitStarted = Date.now();
|
|
2693
|
+
async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrained) {
|
|
2606
2694
|
const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2695
|
+
if (!drained) {
|
|
2696
|
+
await closeNativeDatabaseClient(runtime, ctx);
|
|
2697
|
+
await closeNativeSqlDatabase(runtime, ctx);
|
|
2698
|
+
void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
|
|
2699
|
+
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
2700
|
+
clearNativeRuntimeState(runtime, ctx);
|
|
2701
|
+
}).catch((error) => {
|
|
2702
|
+
logger2().warn({
|
|
2703
|
+
msg: "deferred native sleep cleanup failed",
|
|
2704
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, error)
|
|
2705
|
+
});
|
|
2617
2706
|
});
|
|
2707
|
+
return;
|
|
2618
2708
|
}
|
|
2709
|
+
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
2619
2710
|
await closeNativeDatabaseClient(runtime, ctx);
|
|
2620
2711
|
await closeNativeSqlDatabase(runtime, ctx);
|
|
2621
2712
|
clearNativeRuntimeState(runtime, ctx);
|
|
@@ -2720,10 +2811,13 @@ function decodeValue(value) {
|
|
|
2720
2811
|
if (!value || value.length === 0) {
|
|
2721
2812
|
return void 0;
|
|
2722
2813
|
}
|
|
2723
|
-
return
|
|
2814
|
+
return _chunk3677IIOVcjs.decodeCborCompat.call(void 0, value);
|
|
2724
2815
|
}
|
|
2725
2816
|
function encodeValue(value) {
|
|
2726
|
-
return
|
|
2817
|
+
return _chunk3677IIOVcjs.encodeCborCompat.call(void 0, value);
|
|
2818
|
+
}
|
|
2819
|
+
function normalizeArgs(value) {
|
|
2820
|
+
return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
|
|
2727
2821
|
}
|
|
2728
2822
|
function unwrapTsfnPayload(error, payload) {
|
|
2729
2823
|
if (error !== null && error !== void 0) {
|
|
@@ -2733,16 +2827,16 @@ function unwrapTsfnPayload(error, payload) {
|
|
|
2733
2827
|
}
|
|
2734
2828
|
function normalizeNativeBridgeError(error) {
|
|
2735
2829
|
if (typeof error === "string") {
|
|
2736
|
-
return _nullishCoalesce(
|
|
2830
|
+
return _nullishCoalesce(_chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
|
|
2737
2831
|
}
|
|
2738
2832
|
if (error instanceof Error) {
|
|
2739
|
-
const bridged =
|
|
2833
|
+
const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.message);
|
|
2740
2834
|
if (bridged) {
|
|
2741
2835
|
return bridged;
|
|
2742
2836
|
}
|
|
2743
2837
|
}
|
|
2744
2838
|
if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
|
|
2745
|
-
const bridged =
|
|
2839
|
+
const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.reason);
|
|
2746
2840
|
if (bridged) {
|
|
2747
2841
|
return bridged;
|
|
2748
2842
|
}
|
|
@@ -2750,14 +2844,14 @@ function normalizeNativeBridgeError(error) {
|
|
|
2750
2844
|
return error;
|
|
2751
2845
|
}
|
|
2752
2846
|
function isStructuredBridgeError(error) {
|
|
2753
|
-
if (error instanceof
|
|
2847
|
+
if (error instanceof _chunkKORQB2IRcjs.RivetError) {
|
|
2754
2848
|
return true;
|
|
2755
2849
|
}
|
|
2756
|
-
return
|
|
2850
|
+
return _chunkKORQB2IRcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
|
|
2757
2851
|
}
|
|
2758
2852
|
function encodeNativeCallbackError(error) {
|
|
2759
|
-
const structuredError = isStructuredBridgeError(error) ? error :
|
|
2760
|
-
const bridgeError = new Error(
|
|
2853
|
+
const structuredError = isStructuredBridgeError(error) ? error : _chunkDXXJPH55cjs.deconstructError.call(void 0, error, true);
|
|
2854
|
+
const bridgeError = new Error(_chunkKORQB2IRcjs.encodeBridgeRivetError.call(void 0, structuredError), {
|
|
2761
2855
|
cause: error instanceof Error ? error : void 0
|
|
2762
2856
|
});
|
|
2763
2857
|
return Object.assign(bridgeError, {
|
|
@@ -2780,16 +2874,10 @@ function callNativeSync(invoke) {
|
|
|
2780
2874
|
throw normalizeNativeBridgeError(error);
|
|
2781
2875
|
}
|
|
2782
2876
|
}
|
|
2783
|
-
function actorAbortedError() {
|
|
2784
|
-
return Object.assign(new Error("Actor aborted"), {
|
|
2785
|
-
group: "actor",
|
|
2786
|
-
code: "aborted"
|
|
2787
|
-
});
|
|
2788
|
-
}
|
|
2789
2877
|
function isClosedTaskRegistrationError(error) {
|
|
2790
|
-
const metadata = error instanceof
|
|
2878
|
+
const metadata = error instanceof _chunkKORQB2IRcjs.RivetError ? error.metadata : void 0;
|
|
2791
2879
|
const metadataError = metadata && typeof metadata === "object" && "error" in metadata ? metadata.error : void 0;
|
|
2792
|
-
return error instanceof
|
|
2880
|
+
return error instanceof _chunkKORQB2IRcjs.RivetError && error.group === "core" && error.code === _chunkKORQB2IRcjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
|
|
2793
2881
|
}
|
|
2794
2882
|
async function createCancellationTokenHandle(runtime, signal) {
|
|
2795
2883
|
if (!signal) {
|
|
@@ -2812,8 +2900,8 @@ function decodeWorkflowCbor(data) {
|
|
|
2812
2900
|
return null;
|
|
2813
2901
|
}
|
|
2814
2902
|
try {
|
|
2815
|
-
return
|
|
2816
|
-
} catch (
|
|
2903
|
+
return _chunk3677IIOVcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
|
|
2904
|
+
} catch (e4) {
|
|
2817
2905
|
return null;
|
|
2818
2906
|
}
|
|
2819
2907
|
}
|
|
@@ -2917,8 +3005,8 @@ function serializeWorkflowHistoryForJson(data) {
|
|
|
2917
3005
|
if (data === null) {
|
|
2918
3006
|
return null;
|
|
2919
3007
|
}
|
|
2920
|
-
const history =
|
|
2921
|
-
return {
|
|
3008
|
+
const history = _chunk47HHIEXHcjs.decodeWorkflowHistoryTransport.call(void 0, data);
|
|
3009
|
+
return jsonSafe({
|
|
2922
3010
|
nameRegistry: [...history.nameRegistry],
|
|
2923
3011
|
entries: history.entries.map((entry) => ({
|
|
2924
3012
|
id: entry.id,
|
|
@@ -2942,7 +3030,7 @@ function serializeWorkflowHistoryForJson(data) {
|
|
|
2942
3030
|
]
|
|
2943
3031
|
)
|
|
2944
3032
|
)
|
|
2945
|
-
};
|
|
3033
|
+
});
|
|
2946
3034
|
}
|
|
2947
3035
|
function toHttpJsonCompatible(value) {
|
|
2948
3036
|
return JSON.parse(
|
|
@@ -2993,7 +3081,7 @@ function wrapNativeCallback(callback) {
|
|
|
2993
3081
|
}
|
|
2994
3082
|
function decodeArgs(value) {
|
|
2995
3083
|
const decoded = decodeValue(value);
|
|
2996
|
-
return
|
|
3084
|
+
return normalizeArgs(decoded);
|
|
2997
3085
|
}
|
|
2998
3086
|
function buildRequest(init) {
|
|
2999
3087
|
const url = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
|
|
@@ -3030,7 +3118,7 @@ var NativeConnAdapter = class {
|
|
|
3030
3118
|
this.#schemas = schemas;
|
|
3031
3119
|
this.#ctx = ctx;
|
|
3032
3120
|
this.#queueHibernationRemoval = queueHibernationRemoval;
|
|
3033
|
-
this[
|
|
3121
|
+
this[_chunkNIY3RSPXcjs.CONN_STATE_MANAGER_SYMBOL] = {
|
|
3034
3122
|
stateEnabled: true,
|
|
3035
3123
|
get state() {
|
|
3036
3124
|
return thisConn.state;
|
|
@@ -3047,19 +3135,23 @@ var NativeConnAdapter = class {
|
|
|
3047
3135
|
decodeValue(this.#runtime.connParams(this.#conn))
|
|
3048
3136
|
);
|
|
3049
3137
|
}
|
|
3050
|
-
[
|
|
3138
|
+
[_chunkNIY3RSPXcjs.RAW_STATE_SYMBOL]() {
|
|
3051
3139
|
return this.#readState();
|
|
3052
3140
|
}
|
|
3053
3141
|
get state() {
|
|
3054
3142
|
const nextState = this.#readState();
|
|
3055
|
-
return createWriteThroughProxy(
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3143
|
+
return createWriteThroughProxy(
|
|
3144
|
+
nextState,
|
|
3145
|
+
(nextValue) => {
|
|
3146
|
+
this.#writeState(nextValue, { writeNative: true });
|
|
3147
|
+
},
|
|
3148
|
+
(newValue) => {
|
|
3149
|
+
_chunk3677IIOVcjs.assertJsonCompatValue.call(void 0, newValue);
|
|
3150
|
+
}
|
|
3151
|
+
);
|
|
3060
3152
|
}
|
|
3061
3153
|
set state(value) {
|
|
3062
|
-
|
|
3154
|
+
_chunk3677IIOVcjs.assertJsonCompatValue.call(void 0, value);
|
|
3063
3155
|
this.#writeState(value, { writeNative: true });
|
|
3064
3156
|
}
|
|
3065
3157
|
initializeState(value) {
|
|
@@ -3164,7 +3256,7 @@ var NativeKvAdapter = class {
|
|
|
3164
3256
|
const value = await callNative(
|
|
3165
3257
|
() => this.#runtime.actorKvGet(
|
|
3166
3258
|
this.#ctx,
|
|
3167
|
-
|
|
3259
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
|
|
3168
3260
|
)
|
|
3169
3261
|
);
|
|
3170
3262
|
return value ? decodeNativeKvValue(new Uint8Array(value), options) : null;
|
|
@@ -3173,7 +3265,7 @@ var NativeKvAdapter = class {
|
|
|
3173
3265
|
await callNative(
|
|
3174
3266
|
() => this.#runtime.actorKvPut(
|
|
3175
3267
|
this.#ctx,
|
|
3176
|
-
|
|
3268
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key)),
|
|
3177
3269
|
toRuntimeBytes(value)
|
|
3178
3270
|
)
|
|
3179
3271
|
);
|
|
@@ -3182,7 +3274,7 @@ var NativeKvAdapter = class {
|
|
|
3182
3274
|
await callNative(
|
|
3183
3275
|
() => this.#runtime.actorKvDelete(
|
|
3184
3276
|
this.#ctx,
|
|
3185
|
-
|
|
3277
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
|
|
3186
3278
|
)
|
|
3187
3279
|
);
|
|
3188
3280
|
}
|
|
@@ -3190,8 +3282,8 @@ var NativeKvAdapter = class {
|
|
|
3190
3282
|
await callNative(
|
|
3191
3283
|
() => this.#runtime.actorKvDeleteRange(
|
|
3192
3284
|
this.#ctx,
|
|
3193
|
-
|
|
3194
|
-
|
|
3285
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(start)),
|
|
3286
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(end))
|
|
3195
3287
|
)
|
|
3196
3288
|
);
|
|
3197
3289
|
}
|
|
@@ -3204,7 +3296,7 @@ var NativeKvAdapter = class {
|
|
|
3204
3296
|
const entries = await callNative(
|
|
3205
3297
|
() => this.#runtime.actorKvListPrefix(
|
|
3206
3298
|
this.#ctx,
|
|
3207
|
-
|
|
3299
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
|
|
3208
3300
|
encodeNativeKvUserKey(
|
|
3209
3301
|
prefix,
|
|
3210
3302
|
options == null ? void 0 : options.keyType
|
|
@@ -3218,7 +3310,7 @@ var NativeKvAdapter = class {
|
|
|
3218
3310
|
);
|
|
3219
3311
|
return entries.map((entry) => [
|
|
3220
3312
|
decodeNativeKvKey(
|
|
3221
|
-
|
|
3313
|
+
_chunkVE2X4KMGcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
|
|
3222
3314
|
options == null ? void 0 : options.keyType
|
|
3223
3315
|
),
|
|
3224
3316
|
decodeNativeKvValue(new Uint8Array(entry.value), options)
|
|
@@ -3237,13 +3329,13 @@ var NativeKvAdapter = class {
|
|
|
3237
3329
|
const entries = await callNative(
|
|
3238
3330
|
() => this.#runtime.actorKvListRange(
|
|
3239
3331
|
this.#ctx,
|
|
3240
|
-
|
|
3332
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
|
|
3241
3333
|
encodeNativeKvUserKey(
|
|
3242
3334
|
start,
|
|
3243
3335
|
options == null ? void 0 : options.keyType
|
|
3244
3336
|
)
|
|
3245
3337
|
),
|
|
3246
|
-
|
|
3338
|
+
_chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
|
|
3247
3339
|
encodeNativeKvUserKey(
|
|
3248
3340
|
end,
|
|
3249
3341
|
options == null ? void 0 : options.keyType
|
|
@@ -3257,7 +3349,7 @@ var NativeKvAdapter = class {
|
|
|
3257
3349
|
);
|
|
3258
3350
|
return entries.map((entry) => [
|
|
3259
3351
|
decodeNativeKvKey(
|
|
3260
|
-
|
|
3352
|
+
_chunkVE2X4KMGcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
|
|
3261
3353
|
options == null ? void 0 : options.keyType
|
|
3262
3354
|
),
|
|
3263
3355
|
decodeNativeKvValue(new Uint8Array(entry.value), options)
|
|
@@ -3349,7 +3441,7 @@ var NativeQueueAdapter = class {
|
|
|
3349
3441
|
async nextBatch(options) {
|
|
3350
3442
|
const completable = (options == null ? void 0 : options.completable) === true;
|
|
3351
3443
|
if (this.#pendingCompletableMessageIds.size > 0) {
|
|
3352
|
-
throw new (0,
|
|
3444
|
+
throw new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
3353
3445
|
"queue",
|
|
3354
3446
|
"previous_message_not_completed",
|
|
3355
3447
|
"Previous completable queue message is not completed. Call `message.complete(...)` before receiving the next message.",
|
|
@@ -3411,44 +3503,23 @@ var NativeQueueAdapter = class {
|
|
|
3411
3503
|
}
|
|
3412
3504
|
}
|
|
3413
3505
|
async waitForNamesAvailable(names, options) {
|
|
3414
|
-
|
|
3506
|
+
const { token, cleanup } = await createCancellationTokenHandle(
|
|
3507
|
+
this.#runtime,
|
|
3508
|
+
options == null ? void 0 : options.signal
|
|
3509
|
+
);
|
|
3510
|
+
try {
|
|
3415
3511
|
await callNative(
|
|
3416
3512
|
() => this.#runtime.actorQueueWaitForNamesAvailable(
|
|
3417
3513
|
this.#ctx,
|
|
3418
3514
|
[...names],
|
|
3419
3515
|
{
|
|
3420
3516
|
timeoutMs: options == null ? void 0 : options.timeout
|
|
3421
|
-
}
|
|
3517
|
+
},
|
|
3518
|
+
token
|
|
3422
3519
|
)
|
|
3423
3520
|
);
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
const deadline = options.timeout === void 0 ? void 0 : Date.now() + options.timeout;
|
|
3427
|
-
for (; ; ) {
|
|
3428
|
-
if (options.signal.aborted) {
|
|
3429
|
-
throw actorAbortedError();
|
|
3430
|
-
}
|
|
3431
|
-
const remainingTimeout = deadline === void 0 ? void 0 : Math.max(0, deadline - Date.now());
|
|
3432
|
-
const sliceTimeout = remainingTimeout === void 0 ? 100 : Math.min(remainingTimeout, 100);
|
|
3433
|
-
try {
|
|
3434
|
-
await callNative(
|
|
3435
|
-
() => this.#runtime.actorQueueWaitForNamesAvailable(
|
|
3436
|
-
this.#ctx,
|
|
3437
|
-
[...names],
|
|
3438
|
-
{
|
|
3439
|
-
timeoutMs: sliceTimeout
|
|
3440
|
-
}
|
|
3441
|
-
)
|
|
3442
|
-
);
|
|
3443
|
-
return;
|
|
3444
|
-
} catch (error) {
|
|
3445
|
-
if (error.group === "queue" && error.code === "timed_out") {
|
|
3446
|
-
if (remainingTimeout === void 0 || remainingTimeout > 100) {
|
|
3447
|
-
continue;
|
|
3448
|
-
}
|
|
3449
|
-
}
|
|
3450
|
-
throw error;
|
|
3451
|
-
}
|
|
3521
|
+
} finally {
|
|
3522
|
+
cleanup == null ? void 0 : cleanup();
|
|
3452
3523
|
}
|
|
3453
3524
|
}
|
|
3454
3525
|
async enqueueAndWait(name, body, options) {
|
|
@@ -3518,7 +3589,7 @@ var NativeQueueAdapter = class {
|
|
|
3518
3589
|
}
|
|
3519
3590
|
yield message;
|
|
3520
3591
|
} catch (error) {
|
|
3521
|
-
if (
|
|
3592
|
+
if (_chunkKORQB2IRcjs.isRivetErrorLike.call(void 0, error) && error.group === "actor" && error.code === "aborted") {
|
|
3522
3593
|
return;
|
|
3523
3594
|
}
|
|
3524
3595
|
throw error;
|
|
@@ -3539,7 +3610,7 @@ var NativeQueueAdapter = class {
|
|
|
3539
3610
|
...message,
|
|
3540
3611
|
complete: async (response) => {
|
|
3541
3612
|
if (typeof message.complete !== "function") {
|
|
3542
|
-
throw new (0,
|
|
3613
|
+
throw new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
3543
3614
|
"queue",
|
|
3544
3615
|
"complete_not_configured",
|
|
3545
3616
|
`Queue '${message.name}' does not support completion responses.`,
|
|
@@ -3551,7 +3622,7 @@ var NativeQueueAdapter = class {
|
|
|
3551
3622
|
);
|
|
3552
3623
|
}
|
|
3553
3624
|
if (completed) {
|
|
3554
|
-
throw new (0,
|
|
3625
|
+
throw new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
3555
3626
|
"queue",
|
|
3556
3627
|
"already_completed",
|
|
3557
3628
|
"Queue message was already completed.",
|
|
@@ -3911,9 +3982,7 @@ var NativeConnectionMap = (_class3 = class {
|
|
|
3911
3982
|
}
|
|
3912
3983
|
get(key) {
|
|
3913
3984
|
const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
|
|
3914
|
-
const conn = conns.find(
|
|
3915
|
-
(c) => this.#runtime.connId(c) === key
|
|
3916
|
-
);
|
|
3985
|
+
const conn = conns.find((c) => this.#runtime.connId(c) === key);
|
|
3917
3986
|
if (!conn) return void 0;
|
|
3918
3987
|
return this.#connToAdapter(conn);
|
|
3919
3988
|
}
|
|
@@ -3980,7 +4049,7 @@ var ActorContextHandleAdapter = class {
|
|
|
3980
4049
|
this.#databaseProvider = databaseProvider;
|
|
3981
4050
|
}
|
|
3982
4051
|
this.#request = request;
|
|
3983
|
-
this[
|
|
4052
|
+
this[_chunkNIY3RSPXcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
|
|
3984
4053
|
this
|
|
3985
4054
|
);
|
|
3986
4055
|
}
|
|
@@ -4011,7 +4080,7 @@ var ActorContextHandleAdapter = class {
|
|
|
4011
4080
|
}
|
|
4012
4081
|
throw databaseClientNotReadyError();
|
|
4013
4082
|
}
|
|
4014
|
-
[
|
|
4083
|
+
[_chunkNIY3RSPXcjs.RAW_STATE_SYMBOL]() {
|
|
4015
4084
|
if (!this.#stateEnabled) {
|
|
4016
4085
|
throw stateNotEnabledError();
|
|
4017
4086
|
}
|
|
@@ -4021,24 +4090,29 @@ var ActorContextHandleAdapter = class {
|
|
|
4021
4090
|
if (!this.#stateEnabled) {
|
|
4022
4091
|
throw stateNotEnabledError();
|
|
4023
4092
|
}
|
|
4093
|
+
const actorState = getNativePersistState(this.#runtime, this.#ctx);
|
|
4024
4094
|
const nextState = this.#readState();
|
|
4025
|
-
|
|
4026
|
-
nextState
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4095
|
+
if (actorState.stateProxy === void 0 || actorState.stateProxyTarget !== nextState) {
|
|
4096
|
+
actorState.stateProxyTarget = nextState;
|
|
4097
|
+
actorState.stateProxy = createWriteThroughProxy(
|
|
4098
|
+
nextState,
|
|
4099
|
+
(nextValue) => {
|
|
4100
|
+
this.#writeState(nextValue, { scheduleSave: true });
|
|
4101
|
+
},
|
|
4102
|
+
(newValue) => {
|
|
4103
|
+
this.#assertCanMutateState();
|
|
4104
|
+
_chunk3677IIOVcjs.assertJsonCompatValue.call(void 0, newValue);
|
|
4105
|
+
}
|
|
4106
|
+
);
|
|
4107
|
+
}
|
|
4108
|
+
return actorState.stateProxy;
|
|
4035
4109
|
}
|
|
4036
4110
|
set state(value) {
|
|
4037
4111
|
if (!this.#stateEnabled) {
|
|
4038
4112
|
throw stateNotEnabledError();
|
|
4039
4113
|
}
|
|
4040
4114
|
this.#assertCanMutateState();
|
|
4041
|
-
|
|
4115
|
+
_chunk3677IIOVcjs.assertJsonCompatValue.call(void 0, value);
|
|
4042
4116
|
this.#writeState(value, { scheduleSave: true });
|
|
4043
4117
|
}
|
|
4044
4118
|
initializeState(value) {
|
|
@@ -4096,7 +4170,11 @@ var ActorContextHandleAdapter = class {
|
|
|
4096
4170
|
}
|
|
4097
4171
|
get conns() {
|
|
4098
4172
|
if (!this.#connMap) {
|
|
4099
|
-
this.#connMap = new NativeConnectionMap(
|
|
4173
|
+
this.#connMap = new NativeConnectionMap(
|
|
4174
|
+
this.#runtime,
|
|
4175
|
+
this.#ctx,
|
|
4176
|
+
this.#schemas
|
|
4177
|
+
);
|
|
4100
4178
|
}
|
|
4101
4179
|
return this.#connMap;
|
|
4102
4180
|
}
|
|
@@ -4296,39 +4374,20 @@ var ActorContextHandleAdapter = class {
|
|
|
4296
4374
|
});
|
|
4297
4375
|
}
|
|
4298
4376
|
keepAwake(promise) {
|
|
4299
|
-
const
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
() => {
|
|
4306
|
-
logger2().debug({
|
|
4307
|
-
msg: "keepAwake promise resolved",
|
|
4308
|
-
durationMs: Date.now() - startedAt
|
|
4309
|
-
});
|
|
4310
|
-
},
|
|
4311
|
-
(error) => {
|
|
4312
|
-
logger2().warn({
|
|
4313
|
-
msg: "keepAwake promise rejected",
|
|
4314
|
-
durationMs: Date.now() - startedAt,
|
|
4315
|
-
error: _chunkBATTOVHFcjs.stringifyError.call(void 0, error)
|
|
4316
|
-
});
|
|
4317
|
-
}
|
|
4318
|
-
).then(() => null);
|
|
4377
|
+
const trackedPromise = Promise.resolve(promise).catch((error) => {
|
|
4378
|
+
logger2().warn({
|
|
4379
|
+
msg: "keepAwake promise rejected",
|
|
4380
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, error)
|
|
4381
|
+
});
|
|
4382
|
+
}).then(() => null);
|
|
4319
4383
|
try {
|
|
4320
4384
|
callNativeSync(
|
|
4321
4385
|
() => this.#runtime.actorKeepAwake(this.#ctx, trackedPromise)
|
|
4322
4386
|
);
|
|
4323
4387
|
} catch (error) {
|
|
4324
|
-
if (isClosedTaskRegistrationError(error)) {
|
|
4325
|
-
|
|
4326
|
-
msg: "keepAwake registration dropped (teardown already started); promise will not delay grace",
|
|
4327
|
-
error: _chunkBATTOVHFcjs.stringifyError.call(void 0, error)
|
|
4328
|
-
});
|
|
4329
|
-
return promise;
|
|
4388
|
+
if (!isClosedTaskRegistrationError(error)) {
|
|
4389
|
+
throw error;
|
|
4330
4390
|
}
|
|
4331
|
-
throw error;
|
|
4332
4391
|
}
|
|
4333
4392
|
return promise;
|
|
4334
4393
|
}
|
|
@@ -4394,6 +4453,7 @@ var ActorContextHandleAdapter = class {
|
|
|
4394
4453
|
return false;
|
|
4395
4454
|
}
|
|
4396
4455
|
sleep() {
|
|
4456
|
+
this.#flushStateChange();
|
|
4397
4457
|
callNativeSync(() => this.#runtime.actorSleep(this.#ctx));
|
|
4398
4458
|
}
|
|
4399
4459
|
destroy() {
|
|
@@ -4411,6 +4471,7 @@ var ActorContextHandleAdapter = class {
|
|
|
4411
4471
|
}
|
|
4412
4472
|
async dispose() {
|
|
4413
4473
|
var _a;
|
|
4474
|
+
this.#flushStateChange();
|
|
4414
4475
|
(_a = this.#abortSignalCleanup) == null ? void 0 : _a.call(this);
|
|
4415
4476
|
this.#sql = void 0;
|
|
4416
4477
|
}
|
|
@@ -4438,13 +4499,12 @@ var ActorContextHandleAdapter = class {
|
|
|
4438
4499
|
return actorState.state;
|
|
4439
4500
|
}
|
|
4440
4501
|
#writeState(value, options) {
|
|
4441
|
-
encodeValue(value);
|
|
4442
4502
|
const actorState = getNativePersistState(this.#runtime, this.#ctx);
|
|
4443
4503
|
actorState.state = value;
|
|
4444
4504
|
if (!options.scheduleSave) {
|
|
4445
4505
|
return;
|
|
4446
4506
|
}
|
|
4447
|
-
this.#
|
|
4507
|
+
this.#scheduleSave();
|
|
4448
4508
|
}
|
|
4449
4509
|
#assertCanMutateState() {
|
|
4450
4510
|
const actorState = getNativePersistState(this.#runtime, this.#ctx);
|
|
@@ -4452,9 +4512,31 @@ var ActorContextHandleAdapter = class {
|
|
|
4452
4512
|
throw stateMutationReentrantError();
|
|
4453
4513
|
}
|
|
4454
4514
|
}
|
|
4455
|
-
|
|
4515
|
+
// Coalesce the request-save and onStateChange work to once per event loop
|
|
4516
|
+
// tick. A synchronous burst of mutations (for example
|
|
4517
|
+
// `Object.assign(c.state, ...)`) would otherwise cross the NAPI boundary and
|
|
4518
|
+
// run onStateChange once per field, re-serializing the whole state each time
|
|
4519
|
+
// and pinning the event loop on large state.
|
|
4520
|
+
#scheduleSave() {
|
|
4456
4521
|
const actorState = getNativePersistState(this.#runtime, this.#ctx);
|
|
4457
|
-
|
|
4522
|
+
if (actorState.saveScheduled) {
|
|
4523
|
+
return;
|
|
4524
|
+
}
|
|
4525
|
+
actorState.saveScheduled = true;
|
|
4526
|
+
actorState.pendingSaveHandle = setImmediate(() => {
|
|
4527
|
+
this.#flushStateChange();
|
|
4528
|
+
});
|
|
4529
|
+
}
|
|
4530
|
+
#flushStateChange() {
|
|
4531
|
+
const actorState = getNativePersistState(this.#runtime, this.#ctx);
|
|
4532
|
+
if (!actorState.saveScheduled) {
|
|
4533
|
+
return;
|
|
4534
|
+
}
|
|
4535
|
+
actorState.saveScheduled = false;
|
|
4536
|
+
if (actorState.pendingSaveHandle !== void 0) {
|
|
4537
|
+
clearImmediate(actorState.pendingSaveHandle);
|
|
4538
|
+
actorState.pendingSaveHandle = void 0;
|
|
4539
|
+
}
|
|
4458
4540
|
callNativeSync(
|
|
4459
4541
|
() => this.#runtime.actorRequestSave(this.#ctx, { immediate: false })
|
|
4460
4542
|
);
|
|
@@ -4661,9 +4743,62 @@ function buildActorConfig(definition, registryConfig) {
|
|
|
4661
4743
|
maxOutgoingMessageSize: registryConfig.maxOutgoingMessageSize,
|
|
4662
4744
|
preloadMaxWorkflowBytes: options.preloadMaxWorkflowBytes,
|
|
4663
4745
|
preloadMaxConnectionsBytes: options.preloadMaxConnectionsBytes,
|
|
4664
|
-
actions: Object.keys(_nullishCoalesce(config.actions, () => ( {}))).sort().map((name) => ({ name }))
|
|
4746
|
+
actions: Object.keys(_nullishCoalesce(config.actions, () => ( {}))).sort().map((name) => ({ name })),
|
|
4747
|
+
inspectorTabs: buildInspectorTabs(config.inspector)
|
|
4665
4748
|
};
|
|
4666
4749
|
}
|
|
4750
|
+
function buildInspectorTabs(inspector) {
|
|
4751
|
+
if (!inspector || typeof inspector !== "object") return void 0;
|
|
4752
|
+
const tabs = inspector.tabs;
|
|
4753
|
+
if (!Array.isArray(tabs) || tabs.length === 0) return void 0;
|
|
4754
|
+
return tabs.map((raw) => {
|
|
4755
|
+
const entry = raw;
|
|
4756
|
+
if (entry.hidden === true) {
|
|
4757
|
+
return { id: entry.id, hidden: true };
|
|
4758
|
+
}
|
|
4759
|
+
const resolved = entry.source !== void 0 ? _path3.default.resolve(entry.source) : void 0;
|
|
4760
|
+
if (resolved !== void 0) {
|
|
4761
|
+
validateInspectorTabSource(entry.id, resolved);
|
|
4762
|
+
}
|
|
4763
|
+
return {
|
|
4764
|
+
id: entry.id,
|
|
4765
|
+
label: entry.label,
|
|
4766
|
+
icon: entry.icon,
|
|
4767
|
+
source: resolved
|
|
4768
|
+
};
|
|
4769
|
+
});
|
|
4770
|
+
}
|
|
4771
|
+
function validateInspectorTabSource(tabId, resolved) {
|
|
4772
|
+
if (resolved === _path3.default.parse(resolved).root) {
|
|
4773
|
+
throw new Error(
|
|
4774
|
+
`inspector.tabs[id="${tabId}"].source resolves to the filesystem root (${resolved}). Point it at the tab's own static-asset directory instead.`
|
|
4775
|
+
);
|
|
4776
|
+
}
|
|
4777
|
+
let stat;
|
|
4778
|
+
try {
|
|
4779
|
+
stat = _fs2.default.statSync(resolved);
|
|
4780
|
+
} catch (err) {
|
|
4781
|
+
const code = err == null ? void 0 : err.code;
|
|
4782
|
+
if (code === "ENOENT") {
|
|
4783
|
+
throw new Error(
|
|
4784
|
+
`inspector.tabs[id="${tabId}"].source (${resolved}) does not exist.`
|
|
4785
|
+
);
|
|
4786
|
+
}
|
|
4787
|
+
if (code === "EACCES") {
|
|
4788
|
+
throw new Error(
|
|
4789
|
+
`inspector.tabs[id="${tabId}"].source (${resolved}) is not readable (EACCES).`
|
|
4790
|
+
);
|
|
4791
|
+
}
|
|
4792
|
+
throw new Error(
|
|
4793
|
+
`inspector.tabs[id="${tabId}"].source (${resolved}) could not be stat'd: ${_nullishCoalesce((err == null ? void 0 : err.message), () => ( err))}`
|
|
4794
|
+
);
|
|
4795
|
+
}
|
|
4796
|
+
if (!stat.isDirectory()) {
|
|
4797
|
+
throw new Error(
|
|
4798
|
+
`inspector.tabs[id="${tabId}"].source (${resolved}) must be a directory, got ${stat.isFile() ? "file" : "non-directory"}.`
|
|
4799
|
+
);
|
|
4800
|
+
}
|
|
4801
|
+
}
|
|
4667
4802
|
function buildNativeFactory(runtime, registryConfig, definition) {
|
|
4668
4803
|
var _a;
|
|
4669
4804
|
const config = definition.config;
|
|
@@ -4677,9 +4812,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
4677
4812
|
const actionHandlers = Object.fromEntries(
|
|
4678
4813
|
Object.entries(_nullishCoalesce(config.actions, () => ( {}))).map(([name, handler]) => [name, handler])
|
|
4679
4814
|
);
|
|
4680
|
-
const createClient = () =>
|
|
4681
|
-
new (0,
|
|
4682
|
-
|
|
4815
|
+
const createClient = () => _chunk7QKCIVAYcjs.createClientWithDriver.call(void 0,
|
|
4816
|
+
new (0, _chunk7QKCIVAYcjs.RemoteEngineControlClient)(
|
|
4817
|
+
_chunk7QKCIVAYcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
|
|
4683
4818
|
),
|
|
4684
4819
|
{ encoding: "bare" }
|
|
4685
4820
|
);
|
|
@@ -4689,7 +4824,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
4689
4824
|
), () => ( false));
|
|
4690
4825
|
const getNativeWorkflowInspector = (ctx) => {
|
|
4691
4826
|
var _a2;
|
|
4692
|
-
return (_a2 =
|
|
4827
|
+
return (_a2 = _chunkNIY3RSPXcjs.getRunInspectorConfig.call(void 0,
|
|
4693
4828
|
config.run,
|
|
4694
4829
|
callNativeSync(() => runtime.actorId(ctx))
|
|
4695
4830
|
)) == null ? void 0 : _a2.workflow;
|
|
@@ -4742,7 +4877,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
4742
4877
|
}
|
|
4743
4878
|
});
|
|
4744
4879
|
const errorResponse = (error, status) => {
|
|
4745
|
-
const rivetError =
|
|
4880
|
+
const rivetError = _chunkKORQB2IRcjs.toRivetError.call(void 0, error);
|
|
4746
4881
|
return jsonResponse(
|
|
4747
4882
|
{
|
|
4748
4883
|
group: rivetError.group,
|
|
@@ -4987,7 +5122,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
4987
5122
|
const action = actionHandlers[actionName];
|
|
4988
5123
|
if (!action) {
|
|
4989
5124
|
return errorResponse(
|
|
4990
|
-
new (0,
|
|
5125
|
+
new (0, _chunkKORQB2IRcjs.RivetError)(
|
|
4991
5126
|
"action",
|
|
4992
5127
|
"action_not_found",
|
|
4993
5128
|
`Action ${actionName} not found`
|
|
@@ -4996,13 +5131,26 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
4996
5131
|
);
|
|
4997
5132
|
}
|
|
4998
5133
|
const body = await jsRequest.json();
|
|
5134
|
+
if (body.args !== void 0 && body.properties !== void 0) {
|
|
5135
|
+
return jsonResponse(
|
|
5136
|
+
{ error: "use either args or properties, not both" },
|
|
5137
|
+
{ status: 400 }
|
|
5138
|
+
);
|
|
5139
|
+
}
|
|
5140
|
+
if (body.properties !== void 0 && (body.properties === null || typeof body.properties !== "object" || Array.isArray(body.properties))) {
|
|
5141
|
+
return jsonResponse(
|
|
5142
|
+
{ error: "properties must be an object" },
|
|
5143
|
+
{ status: 400 }
|
|
5144
|
+
);
|
|
5145
|
+
}
|
|
5146
|
+
const args = body.properties !== void 0 ? [body.properties] : normalizeArgs(body.args);
|
|
4999
5147
|
try {
|
|
5000
5148
|
const output = await action(
|
|
5001
5149
|
actorCtx,
|
|
5002
5150
|
...validateActionArgs(
|
|
5003
5151
|
schemaConfig.actionInputSchemas,
|
|
5004
5152
|
actionName,
|
|
5005
|
-
|
|
5153
|
+
args
|
|
5006
5154
|
)
|
|
5007
5155
|
);
|
|
5008
5156
|
return jsonResponse({ output });
|
|
@@ -5150,24 +5298,30 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5150
5298
|
async (error, payload) => {
|
|
5151
5299
|
const { ctx } = unwrapTsfnPayload(error, payload);
|
|
5152
5300
|
const actorCtx = makeActorCtx(ctx);
|
|
5301
|
+
const saveActorState = async () => {
|
|
5302
|
+
if (runtime.kind === "wasm") {
|
|
5303
|
+
await runtime.actorSaveState(
|
|
5304
|
+
ctx,
|
|
5305
|
+
actorCtx.serializeForTick("save")
|
|
5306
|
+
);
|
|
5307
|
+
} else {
|
|
5308
|
+
await actorCtx.saveState({
|
|
5309
|
+
immediate: true
|
|
5310
|
+
});
|
|
5311
|
+
}
|
|
5312
|
+
};
|
|
5153
5313
|
try {
|
|
5154
5314
|
if (onSleep) {
|
|
5155
|
-
|
|
5156
|
-
await onSleep(actorCtx);
|
|
5157
|
-
} finally {
|
|
5158
|
-
if (runtime.kind === "wasm") {
|
|
5159
|
-
await runtime.actorSaveState(
|
|
5160
|
-
ctx,
|
|
5161
|
-
actorCtx.serializeForTick("save")
|
|
5162
|
-
);
|
|
5163
|
-
} else {
|
|
5164
|
-
await actorCtx.saveState({ immediate: true });
|
|
5165
|
-
}
|
|
5166
|
-
}
|
|
5315
|
+
await onSleep(actorCtx);
|
|
5167
5316
|
}
|
|
5317
|
+
await saveActorState();
|
|
5168
5318
|
} finally {
|
|
5169
5319
|
try {
|
|
5170
|
-
await cleanupNativeSleepRuntimeState(
|
|
5320
|
+
await cleanupNativeSleepRuntimeState(
|
|
5321
|
+
runtime,
|
|
5322
|
+
ctx,
|
|
5323
|
+
saveActorState
|
|
5324
|
+
);
|
|
5171
5325
|
} finally {
|
|
5172
5326
|
await actorCtx.dispose();
|
|
5173
5327
|
}
|
|
@@ -5332,7 +5486,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5332
5486
|
);
|
|
5333
5487
|
}
|
|
5334
5488
|
if (!result) {
|
|
5335
|
-
throw
|
|
5489
|
+
throw _chunkKORQB2IRcjs.forbiddenError.call(void 0, );
|
|
5336
5490
|
}
|
|
5337
5491
|
} finally {
|
|
5338
5492
|
await actorCtx.dispose();
|
|
@@ -5378,7 +5532,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5378
5532
|
new Response(null, { status: 404 })
|
|
5379
5533
|
);
|
|
5380
5534
|
}
|
|
5381
|
-
const rawConnParams = jsRequest.headers.get(
|
|
5535
|
+
const rawConnParams = jsRequest.headers.get(_chunk7QKCIVAYcjs.HEADER_CONN_PARAMS);
|
|
5382
5536
|
let requestCtx;
|
|
5383
5537
|
let conn;
|
|
5384
5538
|
try {
|
|
@@ -5443,7 +5597,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5443
5597
|
}
|
|
5444
5598
|
) : void 0,
|
|
5445
5599
|
run: (() => {
|
|
5446
|
-
const run =
|
|
5600
|
+
const run = _chunkNIY3RSPXcjs.getRunFunction.call(void 0, config.run);
|
|
5447
5601
|
if (!run) {
|
|
5448
5602
|
return void 0;
|
|
5449
5603
|
}
|
|
@@ -5462,7 +5616,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5462
5616
|
}
|
|
5463
5617
|
);
|
|
5464
5618
|
})(),
|
|
5465
|
-
getWorkflowHistory:
|
|
5619
|
+
getWorkflowHistory: _chunkNIY3RSPXcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
|
|
5466
5620
|
async (error, payload) => {
|
|
5467
5621
|
var _a2;
|
|
5468
5622
|
const { ctx } = unwrapTsfnPayload(error, payload);
|
|
@@ -5470,7 +5624,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5470
5624
|
return history == null ? void 0 : encodeValue(history);
|
|
5471
5625
|
}
|
|
5472
5626
|
) : void 0,
|
|
5473
|
-
replayWorkflow:
|
|
5627
|
+
replayWorkflow: _chunkNIY3RSPXcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
|
|
5474
5628
|
async (error, payload) => {
|
|
5475
5629
|
const { ctx, entryId } = unwrapTsfnPayload(
|
|
5476
5630
|
error,
|
|
@@ -5545,7 +5699,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5545
5699
|
name
|
|
5546
5700
|
);
|
|
5547
5701
|
if (canPublish && !await canPublish(actorCtx)) {
|
|
5548
|
-
throw
|
|
5702
|
+
throw _chunkKORQB2IRcjs.forbiddenError.call(void 0, );
|
|
5549
5703
|
}
|
|
5550
5704
|
const decodedBody = decodeValue(body);
|
|
5551
5705
|
if (wait) {
|
|
@@ -5605,25 +5759,32 @@ async function buildServeConfig(config) {
|
|
|
5605
5759
|
poolName: config.envoy.poolName,
|
|
5606
5760
|
handleInspectorHttpInRuntime: true,
|
|
5607
5761
|
serverlessBasePath: config.serverless.basePath,
|
|
5608
|
-
serverlessPackageVersion:
|
|
5762
|
+
serverlessPackageVersion: _chunkDXXJPH55cjs.VERSION,
|
|
5609
5763
|
serverlessClientEndpoint: config.publicEndpoint,
|
|
5610
5764
|
serverlessClientNamespace: config.publicNamespace,
|
|
5611
5765
|
serverlessClientToken: config.publicToken,
|
|
5612
5766
|
serverlessValidateEndpoint: config.validateServerlessEndpoint,
|
|
5613
5767
|
serverlessMaxStartPayloadBytes: config.serverless.maxStartPayloadBytes
|
|
5614
5768
|
};
|
|
5615
|
-
|
|
5769
|
+
try {
|
|
5616
5770
|
const { getEnginePath } = await loadEngineCli();
|
|
5617
5771
|
serveConfig.engineBinaryPath = getEnginePath();
|
|
5772
|
+
} catch (error) {
|
|
5773
|
+
logger2().warn({
|
|
5774
|
+
msg: "could not resolve a local engine binary; if a local engine must be spawned it will fail with engine.binary_unavailable \u2014 set RIVET_ENGINE_BINARY_PATH or install the @rivetkit/engine-cli platform package",
|
|
5775
|
+
error: _chunkDXXJPH55cjs.stringifyError.call(void 0, error)
|
|
5776
|
+
});
|
|
5618
5777
|
}
|
|
5778
|
+
serveConfig.engineHost = config.engineHost;
|
|
5779
|
+
serveConfig.enginePort = config.enginePort;
|
|
5619
5780
|
if ((_a = config.test) == null ? void 0 : _a.enabled) {
|
|
5620
|
-
serveConfig.inspectorTestToken = _nullishCoalesce(
|
|
5781
|
+
serveConfig.inspectorTestToken = _nullishCoalesce(_chunkDXXJPH55cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
|
|
5621
5782
|
}
|
|
5622
5783
|
return serveConfig;
|
|
5623
5784
|
}
|
|
5624
5785
|
async function buildRegistryWithRuntime(config, runtime) {
|
|
5625
5786
|
var _a;
|
|
5626
|
-
if (((_a = config.test) == null ? void 0 : _a.enabled) &&
|
|
5787
|
+
if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkDXXJPH55cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
|
|
5627
5788
|
trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
|
|
5628
5789
|
}
|
|
5629
5790
|
const registry = runtime.createRegistry();
|
|
@@ -5642,10 +5803,6 @@ async function buildRegistryWithRuntime(config, runtime) {
|
|
|
5642
5803
|
}
|
|
5643
5804
|
async function buildConfiguredRegistry(config) {
|
|
5644
5805
|
const runtime = await loadConfiguredRuntime(config);
|
|
5645
|
-
if (runtime.kind === "napi") {
|
|
5646
|
-
const { startProcessMetrics } = await Promise.resolve().then(() => _interopRequireWildcard(require("./process-metrics-TYAGKCEJ.cjs")));
|
|
5647
|
-
startProcessMetrics();
|
|
5648
|
-
}
|
|
5649
5806
|
return buildRegistryWithRuntime(
|
|
5650
5807
|
normalizeRuntimeConfig(config, runtime),
|
|
5651
5808
|
runtime
|
|
@@ -5669,6 +5826,8 @@ function finishShutdownSignal(signal) {
|
|
|
5669
5826
|
}
|
|
5670
5827
|
var Registry = class {
|
|
5671
5828
|
#config;
|
|
5829
|
+
#buildConfiguredRegistry;
|
|
5830
|
+
|
|
5672
5831
|
get config() {
|
|
5673
5832
|
return this.#config;
|
|
5674
5833
|
}
|
|
@@ -5683,18 +5842,24 @@ var Registry = class {
|
|
|
5683
5842
|
#shutdownInstalled = false;
|
|
5684
5843
|
#shutdownInFlight = null;
|
|
5685
5844
|
#signalHandlers = {};
|
|
5686
|
-
constructor(config) {
|
|
5845
|
+
constructor(config, deps) {
|
|
5687
5846
|
this.#config = config;
|
|
5847
|
+
this.#buildConfiguredRegistry = _nullishCoalesce((deps == null ? void 0 : deps.buildConfiguredRegistry), () => ( buildConfiguredRegistry));
|
|
5848
|
+
this.routes = {
|
|
5849
|
+
health: () => this.#healthRoute(),
|
|
5850
|
+
metadata: () => this.#metadataRoute(),
|
|
5851
|
+
prometheusMetrics: (request) => this.#prometheusMetricsRoute(request)
|
|
5852
|
+
};
|
|
5688
5853
|
}
|
|
5689
5854
|
#ensureServerlessPoolConfigured(config) {
|
|
5690
5855
|
if (!config.configurePool) return void 0;
|
|
5691
5856
|
if (!this.#configureServerlessPoolPromise) {
|
|
5692
|
-
this.#configureServerlessPoolPromise = configureServerlessPool(
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
);
|
|
5857
|
+
this.#configureServerlessPoolPromise = configureServerlessPool(
|
|
5858
|
+
config
|
|
5859
|
+
).catch((error) => {
|
|
5860
|
+
this.#configureServerlessPoolPromise = void 0;
|
|
5861
|
+
throw error;
|
|
5862
|
+
});
|
|
5698
5863
|
this.#configureServerlessPoolPromise.catch(() => {
|
|
5699
5864
|
});
|
|
5700
5865
|
}
|
|
@@ -5715,7 +5880,7 @@ var Registry = class {
|
|
|
5715
5880
|
const config = this.parseConfig();
|
|
5716
5881
|
this.#printWelcome(config, "serverless");
|
|
5717
5882
|
if (!this.#runtimeServerlessPromise) {
|
|
5718
|
-
this.#runtimeServerlessPromise = buildConfiguredRegistry(config);
|
|
5883
|
+
this.#runtimeServerlessPromise = this.#buildConfiguredRegistry(config);
|
|
5719
5884
|
}
|
|
5720
5885
|
const { runtime, registry, serveConfig } = await this.#runtimeServerlessPromise;
|
|
5721
5886
|
const isStartRequest = isServerlessStartRequest(
|
|
@@ -5730,7 +5895,7 @@ var Registry = class {
|
|
|
5730
5895
|
if (isStartRequest) {
|
|
5731
5896
|
try {
|
|
5732
5897
|
await this.#ensureServerlessPoolConfigured(config);
|
|
5733
|
-
} catch (
|
|
5898
|
+
} catch (_error) {
|
|
5734
5899
|
return new Response(
|
|
5735
5900
|
JSON.stringify({
|
|
5736
5901
|
group: "guard",
|
|
@@ -5844,7 +6009,7 @@ var Registry = class {
|
|
|
5844
6009
|
if (isMetadataRequest && !isEngineMetadataRequest) {
|
|
5845
6010
|
try {
|
|
5846
6011
|
await this.#ensureServerlessPoolConfigured(config);
|
|
5847
|
-
} catch (
|
|
6012
|
+
} catch (_error) {
|
|
5848
6013
|
return new Response(
|
|
5849
6014
|
JSON.stringify({
|
|
5850
6015
|
group: "guard",
|
|
@@ -5895,7 +6060,7 @@ var Registry = class {
|
|
|
5895
6060
|
async listen(opts = {}) {
|
|
5896
6061
|
const port = _nullishCoalesce(opts.port, () => ( 3e3));
|
|
5897
6062
|
const config = this.parseConfig();
|
|
5898
|
-
const runtime =
|
|
6063
|
+
const runtime = _chunkDXXJPH55cjs.detectRuntime.call(void 0, );
|
|
5899
6064
|
const app = new (0, _hono.Hono)();
|
|
5900
6065
|
if (opts.publicDir) {
|
|
5901
6066
|
const serveStatic = await loadRuntimeServeStatic(runtime);
|
|
@@ -5904,40 +6069,109 @@ var Registry = class {
|
|
|
5904
6069
|
app.all("*", (c) => this.handler(c.req.raw));
|
|
5905
6070
|
await crossPlatformServe(config, port, app, runtime);
|
|
5906
6071
|
}
|
|
5907
|
-
|
|
5908
|
-
|
|
6072
|
+
/**
|
|
6073
|
+
* Returns a health response suitable for mounting in a user-owned router.
|
|
6074
|
+
*/
|
|
6075
|
+
async #healthRoute() {
|
|
6076
|
+
const configured = await this.#activeConfiguredRegistry();
|
|
6077
|
+
if (!configured) {
|
|
6078
|
+
return jsonRouteResponse(503, {
|
|
6079
|
+
status: "not_started",
|
|
6080
|
+
runtime: "rivetkit",
|
|
6081
|
+
version: _chunkDXXJPH55cjs.VERSION
|
|
6082
|
+
});
|
|
6083
|
+
}
|
|
6084
|
+
const { runtime, registry } = configured;
|
|
6085
|
+
if (!runtime.registryHealth) {
|
|
6086
|
+
return jsonRouteResponse(501, {
|
|
6087
|
+
status: "unsupported",
|
|
6088
|
+
runtime: "rivetkit",
|
|
6089
|
+
version: _chunkDXXJPH55cjs.VERSION
|
|
6090
|
+
});
|
|
6091
|
+
}
|
|
6092
|
+
const response = await runtime.registryHealth(registry);
|
|
6093
|
+
return new Response(new Uint8Array(response.body), {
|
|
6094
|
+
status: response.status,
|
|
6095
|
+
headers: response.headers
|
|
6096
|
+
});
|
|
6097
|
+
}
|
|
6098
|
+
/**
|
|
6099
|
+
* Returns serverless metadata suitable for mounting in a user-owned router.
|
|
6100
|
+
*/
|
|
6101
|
+
async #metadataRoute() {
|
|
6102
|
+
const configured = await this.#activeConfiguredRegistry();
|
|
6103
|
+
if (!configured) {
|
|
6104
|
+
return new Response("registry not started\n", {
|
|
6105
|
+
status: 503,
|
|
6106
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
6107
|
+
});
|
|
6108
|
+
}
|
|
6109
|
+
const { runtime, registry } = configured;
|
|
6110
|
+
if (!runtime.registryMetadata) {
|
|
6111
|
+
return new Response("metadata is not supported by this runtime\n", {
|
|
6112
|
+
status: 501,
|
|
6113
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
6114
|
+
});
|
|
6115
|
+
}
|
|
6116
|
+
const response = await runtime.registryMetadata(registry);
|
|
6117
|
+
return new Response(new Uint8Array(response.body), {
|
|
6118
|
+
status: response.status,
|
|
6119
|
+
headers: response.headers
|
|
6120
|
+
});
|
|
6121
|
+
}
|
|
6122
|
+
/**
|
|
6123
|
+
* Returns a Prometheus metrics response suitable for mounting in a user-owned router.
|
|
6124
|
+
*/
|
|
6125
|
+
async #prometheusMetricsRoute(_request) {
|
|
6126
|
+
const configured = await this.#activeConfiguredRegistry();
|
|
6127
|
+
if (!configured) {
|
|
6128
|
+
return new Response("registry not started\n", {
|
|
6129
|
+
status: 503,
|
|
6130
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
6131
|
+
});
|
|
6132
|
+
}
|
|
6133
|
+
const { runtime, registry } = configured;
|
|
6134
|
+
if (!runtime.registryMetrics) {
|
|
6135
|
+
return new Response("metrics are not supported by this runtime\n", {
|
|
6136
|
+
status: 501,
|
|
6137
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
6138
|
+
});
|
|
6139
|
+
}
|
|
6140
|
+
const response = await runtime.registryMetrics(registry);
|
|
6141
|
+
return new Response(new Uint8Array(response.body), {
|
|
6142
|
+
status: response.status,
|
|
6143
|
+
headers: response.headers
|
|
6144
|
+
});
|
|
6145
|
+
}
|
|
6146
|
+
async #activeConfiguredRegistry() {
|
|
5909
6147
|
const candidates = [
|
|
5910
6148
|
this.#runtimeServerlessPromise,
|
|
5911
6149
|
this.#runtimeServeConfiguredPromise
|
|
5912
6150
|
].filter(
|
|
5913
6151
|
(candidate) => candidate !== void 0
|
|
5914
6152
|
);
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
const diagnostics = await ((_a = runtime.registryDiagnostics) == null ? void 0 : _a.call(runtime, registry));
|
|
5918
|
-
if (diagnostics) return diagnostics;
|
|
5919
|
-
}
|
|
5920
|
-
return { mode: "not_started", envoyActiveActorCount: null };
|
|
6153
|
+
if (candidates.length === 0) return void 0;
|
|
6154
|
+
return await candidates[0];
|
|
5921
6155
|
}
|
|
5922
6156
|
/**
|
|
5923
6157
|
* Starts an actor envoy for standalone server deployments.
|
|
5924
6158
|
*/
|
|
5925
6159
|
#startEnvoy(config, printWelcome) {
|
|
5926
6160
|
if (!this.#runtimeServePromise) {
|
|
5927
|
-
const configuredRegistryPromise = buildConfiguredRegistry(config);
|
|
6161
|
+
const configuredRegistryPromise = this.#buildConfiguredRegistry(config);
|
|
5928
6162
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
5929
6163
|
this.#runtimeServePromise = configuredRegistryPromise.then(async ({ runtime, registry, serveConfig }) => {
|
|
5930
6164
|
await runtime.serveRegistry(registry, serveConfig);
|
|
5931
6165
|
}).catch((error) => {
|
|
5932
6166
|
logger2().warn({ error }, "runtime registry serve errored");
|
|
5933
6167
|
});
|
|
5934
|
-
this.#installSignalHandlers(config
|
|
6168
|
+
this.#installSignalHandlers(config);
|
|
5935
6169
|
}
|
|
5936
6170
|
if (printWelcome) {
|
|
5937
6171
|
this.#printWelcome(config, "serverful");
|
|
5938
6172
|
}
|
|
5939
6173
|
}
|
|
5940
|
-
#installSignalHandlers(config
|
|
6174
|
+
#installSignalHandlers(config) {
|
|
5941
6175
|
var _a;
|
|
5942
6176
|
if (this.#shutdownInstalled) return;
|
|
5943
6177
|
if ((_a = config.shutdown) == null ? void 0 : _a.disableSignalHandlers) return;
|
|
@@ -5946,54 +6180,82 @@ var Registry = class {
|
|
|
5946
6180
|
}
|
|
5947
6181
|
this.#shutdownInstalled = true;
|
|
5948
6182
|
const install = (signal) => {
|
|
5949
|
-
const handler = () => this.#onShutdownSignal(
|
|
5950
|
-
signal,
|
|
5951
|
-
config,
|
|
5952
|
-
configuredRegistryPromise
|
|
5953
|
-
);
|
|
6183
|
+
const handler = () => this.#onShutdownSignal(signal, config);
|
|
5954
6184
|
this.#signalHandlers[signal] = handler;
|
|
5955
6185
|
process.on(signal, handler);
|
|
5956
6186
|
};
|
|
5957
6187
|
install("SIGINT");
|
|
5958
6188
|
install("SIGTERM");
|
|
5959
6189
|
}
|
|
5960
|
-
#onShutdownSignal(signal, config
|
|
6190
|
+
#onShutdownSignal(signal, config) {
|
|
5961
6191
|
if (this.#shutdownInFlight !== null) {
|
|
5962
6192
|
this.#removeSignalHandlers();
|
|
5963
6193
|
finishShutdownSignal(signal);
|
|
5964
6194
|
return;
|
|
5965
6195
|
}
|
|
5966
|
-
this.#shutdownInFlight = this.#
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
6196
|
+
this.#shutdownInFlight = this.#drain(config).catch((err) => {
|
|
6197
|
+
logger2().warn({ err }, "shutdown error");
|
|
6198
|
+
}).then(() => {
|
|
6199
|
+
this.#removeSignalHandlers();
|
|
6200
|
+
finishShutdownSignal(signal);
|
|
6201
|
+
});
|
|
6202
|
+
}
|
|
6203
|
+
/**
|
|
6204
|
+
* Gracefully drains all live registries.
|
|
6205
|
+
*
|
|
6206
|
+
* Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
|
|
6207
|
+
* every live `CoreRegistry` (both `start()` and `handler()` modes) and
|
|
6208
|
+
* waits for the serve promise to resolve, all bounded by the shutdown
|
|
6209
|
+
* grace period. Unlike a signal-driven shutdown, this does not re-raise a
|
|
6210
|
+
* signal or exit the process. The caller owns process lifetime.
|
|
6211
|
+
*
|
|
6212
|
+
* Idempotent: concurrent or repeated calls share a single drain. Safe to
|
|
6213
|
+
* call even if nothing has been started.
|
|
6214
|
+
*
|
|
6215
|
+
* @example
|
|
6216
|
+
* ```ts
|
|
6217
|
+
* const registry = setup({ use: { counter } });
|
|
6218
|
+
* registry.start();
|
|
6219
|
+
* // ...later, on your own shutdown trigger:
|
|
6220
|
+
* await registry.shutdown();
|
|
6221
|
+
* ```
|
|
6222
|
+
*/
|
|
6223
|
+
async shutdown() {
|
|
6224
|
+
if (this.#shutdownInFlight !== null) return this.#shutdownInFlight;
|
|
6225
|
+
const config = this.parseConfig();
|
|
6226
|
+
this.#removeSignalHandlers();
|
|
6227
|
+
this.#shutdownInFlight = this.#drain(config).catch((err) => {
|
|
6228
|
+
logger2().warn({ err }, "shutdown error");
|
|
5972
6229
|
});
|
|
6230
|
+
return this.#shutdownInFlight;
|
|
5973
6231
|
}
|
|
5974
|
-
async #
|
|
6232
|
+
async #drain(config) {
|
|
5975
6233
|
var _a;
|
|
5976
|
-
const
|
|
6234
|
+
const modeAPromise = this.#runtimeServeConfiguredPromise;
|
|
6235
|
+
const modeBPromise = this.#runtimeServerlessPromise;
|
|
6236
|
+
const gracePeriodMs = await _asyncNullishCoalesce(await _asyncNullishCoalesce(((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs), async () => ( await this.#actorStopThresholdMs(_nullishCoalesce(modeAPromise, () => ( modeBPromise))))), async () => ( 30 * 60 * 1e3));
|
|
5977
6237
|
const drain = async () => {
|
|
5978
|
-
const registries = [
|
|
5979
|
-
|
|
5980
|
-
try {
|
|
5981
|
-
const { runtime, registry } = await configuredRegistryPromise;
|
|
5982
|
-
await runtime.shutdownRegistry(registry);
|
|
5983
|
-
} catch (error) {
|
|
5984
|
-
logger2().warn(
|
|
5985
|
-
{ error },
|
|
5986
|
-
"runtime registry shutdown errored (mode A)"
|
|
5987
|
-
);
|
|
5988
|
-
}
|
|
5989
|
-
})()
|
|
5990
|
-
];
|
|
5991
|
-
const runtimeServerlessPromise = this.#runtimeServerlessPromise;
|
|
5992
|
-
if (runtimeServerlessPromise !== void 0) {
|
|
6238
|
+
const registries = [];
|
|
6239
|
+
if (modeAPromise !== void 0) {
|
|
5993
6240
|
registries.push(
|
|
5994
6241
|
(async () => {
|
|
5995
6242
|
try {
|
|
5996
|
-
const { runtime, registry } = await
|
|
6243
|
+
const { runtime, registry } = await modeAPromise;
|
|
6244
|
+
await runtime.shutdownRegistry(registry);
|
|
6245
|
+
} catch (err) {
|
|
6246
|
+
logger2().warn(
|
|
6247
|
+
{ err },
|
|
6248
|
+
"runtime registry shutdown errored (mode A)"
|
|
6249
|
+
);
|
|
6250
|
+
}
|
|
6251
|
+
})()
|
|
6252
|
+
);
|
|
6253
|
+
}
|
|
6254
|
+
if (modeBPromise !== void 0) {
|
|
6255
|
+
registries.push(
|
|
6256
|
+
(async () => {
|
|
6257
|
+
try {
|
|
6258
|
+
const { runtime, registry } = await modeBPromise;
|
|
5997
6259
|
await runtime.shutdownRegistry(registry);
|
|
5998
6260
|
} catch (err) {
|
|
5999
6261
|
logger2().warn(
|
|
@@ -6019,11 +6281,10 @@ var Registry = class {
|
|
|
6019
6281
|
}
|
|
6020
6282
|
)
|
|
6021
6283
|
]);
|
|
6022
|
-
this.#removeSignalHandlers();
|
|
6023
|
-
finishShutdownSignal(signal);
|
|
6024
6284
|
}
|
|
6025
6285
|
async #actorStopThresholdMs(configuredRegistryPromise) {
|
|
6026
6286
|
var _a;
|
|
6287
|
+
if (configuredRegistryPromise === void 0) return void 0;
|
|
6027
6288
|
try {
|
|
6028
6289
|
const { runtime, registry } = await configuredRegistryPromise;
|
|
6029
6290
|
const thresholdMs = await ((_a = runtime.registryActorStopThresholdMs) == null ? void 0 : _a.call(runtime, registry));
|
|
@@ -6071,13 +6332,13 @@ var Registry = class {
|
|
|
6071
6332
|
};
|
|
6072
6333
|
console.log();
|
|
6073
6334
|
console.log(
|
|
6074
|
-
` RivetKit ${
|
|
6335
|
+
` RivetKit ${_chunkDXXJPH55cjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
|
|
6075
6336
|
);
|
|
6076
6337
|
if (config.namespace !== "default") {
|
|
6077
6338
|
logLine("Namespace", config.namespace);
|
|
6078
6339
|
}
|
|
6079
6340
|
if (config.endpoint) {
|
|
6080
|
-
const endpointType = config.
|
|
6341
|
+
const endpointType = config.startEngine || isLocalEngineEndpoint(config.endpoint) ? "local native" : "remote";
|
|
6081
6342
|
logLine("Endpoint", `${config.endpoint} (${endpointType})`);
|
|
6082
6343
|
}
|
|
6083
6344
|
if (kind === "serverless" && config.publicEndpoint) {
|
|
@@ -6099,6 +6360,12 @@ function isServerlessMetadataRequest(request, basePath) {
|
|
|
6099
6360
|
const normalizedBase = basePath === "/" ? "" : `/${basePath.replace(/^\/+|\/+$/g, "")}`;
|
|
6100
6361
|
return parsed.pathname === `${normalizedBase}/metadata`;
|
|
6101
6362
|
}
|
|
6363
|
+
function jsonRouteResponse(status, body) {
|
|
6364
|
+
return new Response(JSON.stringify(body), {
|
|
6365
|
+
status,
|
|
6366
|
+
headers: { "content-type": "application/json" }
|
|
6367
|
+
});
|
|
6368
|
+
}
|
|
6102
6369
|
function setup(input) {
|
|
6103
6370
|
return new Registry(input);
|
|
6104
6371
|
}
|
|
@@ -6133,5 +6400,5 @@ function setup(input) {
|
|
|
6133
6400
|
|
|
6134
6401
|
|
|
6135
6402
|
|
|
6136
|
-
exports.ALLOWED_PUBLIC_HEADERS =
|
|
6403
|
+
exports.ALLOWED_PUBLIC_HEADERS = _chunk7QKCIVAYcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkKORQB2IRcjs.RivetError; exports.ActorsSchema = ActorsSchema; exports.DocConfigurePoolSchema = DocConfigurePoolSchema; exports.DocEnvoyConfigSchema = DocEnvoyConfigSchema; exports.DocRegistryConfigSchema = DocRegistryConfigSchema; exports.DocServerlessConfigSchema = DocServerlessConfigSchema; exports.DocSqliteConfigSchema = DocSqliteConfigSchema; exports.InlineWebSocketAdapter = InlineWebSocketAdapter; exports.Registry = Registry; exports.RegistryConfigSchema = RegistryConfigSchema; exports.RivetError = _chunkKORQB2IRcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkKORQB2IRcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunk7QKCIVAYcjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkDXXJPH55cjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkDXXJPH55cjs.toUint8Array;
|
|
6137
6404
|
//# sourceMappingURL=mod.cjs.map
|