rivetkit 2.3.8 → 2.3.10
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 +6 -34
- package/dist/browser/client.js +14 -33
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +1 -1
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +6 -34
- package/dist/tsup/agent-os/index.d.ts +6 -34
- package/dist/tsup/agent-os/index.js +1 -1
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-YFXQ7DBH.js → chunk-6UHZLL6S.js} +3 -3
- package/dist/tsup/{chunk-BL6ERZQO.js → chunk-DPM73GAL.js} +18 -39
- package/dist/tsup/chunk-DPM73GAL.js.map +1 -0
- package/dist/tsup/{chunk-MY6BRV3S.js → chunk-E6IEX6AP.js} +3 -3
- package/dist/tsup/{chunk-IJMVVULS.cjs → chunk-G6XA2OSW.cjs} +4 -4
- package/dist/tsup/{chunk-IJMVVULS.cjs.map → chunk-G6XA2OSW.cjs.map} +1 -1
- package/dist/tsup/{chunk-F6GCLL5Z.cjs → chunk-INXPYXN6.cjs} +7 -7
- package/dist/tsup/{chunk-F6GCLL5Z.cjs.map → chunk-INXPYXN6.cjs.map} +1 -1
- package/dist/tsup/{chunk-5MJPN3QU.cjs → chunk-LCWHS6K7.cjs} +152 -173
- package/dist/tsup/chunk-LCWHS6K7.cjs.map +1 -0
- package/dist/tsup/{chunk-7TNEDX3Y.cjs → chunk-PCJSDS7N.cjs} +3 -3
- package/dist/tsup/{chunk-7TNEDX3Y.cjs.map → chunk-PCJSDS7N.cjs.map} +1 -1
- package/dist/tsup/{chunk-V7PJYBA5.js → chunk-Q5H37KNQ.js} +2 -2
- package/dist/tsup/{chunk-TMTJPSHQ.cjs → chunk-U2A3Y7OK.cjs} +9 -9
- package/dist/tsup/{chunk-TMTJPSHQ.cjs.map → chunk-U2A3Y7OK.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZKDZW5DQ.js → chunk-X7XY6NCU.js} +3 -6
- package/dist/tsup/chunk-X7XY6NCU.js.map +1 -0
- package/dist/tsup/{chunk-HWBISPRP.js → chunk-XSPAARQ5.js} +2 -2
- package/dist/tsup/{chunk-NUMGL52R.cjs → chunk-Z2ESFE5Z.cjs} +3 -6
- package/dist/tsup/chunk-Z2ESFE5Z.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +4 -4
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-CUymbyM6.d.ts → config-BRpVbJCD.d.ts} +7 -35
- package/dist/tsup/{config-CpB-e4I9.d.cts → config-BobvQpex.d.cts} +7 -35
- package/dist/tsup/{context-YBUBTwTS.d.ts → context-Cj-DFyiy.d.ts} +1 -1
- package/dist/tsup/{context-c-6G4mjk.d.cts → context-YEBNJrws.d.cts} +1 -1
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +2 -2
- package/dist/tsup/db/mod.js +1 -1
- package/dist/tsup/dynamic/mod.d.cts +1 -1
- package/dist/tsup/dynamic/mod.d.ts +1 -1
- package/dist/tsup/inspector/mod.cjs +4 -4
- package/dist/tsup/inspector/mod.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +2 -2
- package/dist/tsup/inspector-tab/mod.d.ts +2 -2
- package/dist/tsup/mod.cjs +124 -449
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +3 -3
- package/dist/tsup/mod.d.ts +3 -3
- package/dist/tsup/mod.js +63 -388
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +6 -6
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +4 -4
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +6 -6
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +3 -3
- package/package.json +8 -8
- package/src/client/actor-handle.ts +1 -3
- package/src/client/raw-utils.ts +2 -11
- package/src/common/actor-router-consts.ts +0 -1
- package/src/common/encoding.ts +1 -4
- package/src/engine-client/actor-http-client.ts +22 -6
- package/src/registry/index.ts +14 -159
- package/src/registry/napi-runtime.ts +0 -74
- package/src/registry/native.ts +63 -111
- package/src/registry/runtime.ts +0 -35
- package/src/registry/wasm-runtime.ts +0 -11
- package/dist/tsup/chunk-5MJPN3QU.cjs.map +0 -1
- package/dist/tsup/chunk-BL6ERZQO.js.map +0 -1
- package/dist/tsup/chunk-NUMGL52R.cjs.map +0 -1
- package/dist/tsup/chunk-ZKDZW5DQ.js.map +0 -1
- package/src/common/fetch-like.ts +0 -49
- package/src/registry/native-http.ts +0 -208
- /package/dist/tsup/{chunk-YFXQ7DBH.js.map → chunk-6UHZLL6S.js.map} +0 -0
- /package/dist/tsup/{chunk-MY6BRV3S.js.map → chunk-E6IEX6AP.js.map} +0 -0
- /package/dist/tsup/{chunk-V7PJYBA5.js.map → chunk-Q5H37KNQ.js.map} +0 -0
- /package/dist/tsup/{chunk-HWBISPRP.js.map → chunk-XSPAARQ5.js.map} +0 -0
package/dist/tsup/mod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decodeWorkflowHistoryTransport
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XSPAARQ5.js";
|
|
4
4
|
import {
|
|
5
5
|
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
6
6
|
ActorConfigSchema,
|
|
@@ -16,21 +16,19 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
ALLOWED_PUBLIC_HEADERS,
|
|
18
18
|
HEADER_CONN_PARAMS,
|
|
19
|
-
HEADER_ORIGINAL_REQUEST_URL,
|
|
20
19
|
RemoteEngineControlClient,
|
|
21
20
|
convertRegistryConfigToClientConfig,
|
|
22
21
|
createClientWithDriver,
|
|
23
22
|
getDatacenters,
|
|
24
|
-
isResponseLike,
|
|
25
23
|
tryParseEndpoint,
|
|
26
24
|
updateRunnerConfig
|
|
27
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-DPM73GAL.js";
|
|
28
26
|
import {
|
|
29
27
|
makePrefixedKey,
|
|
30
28
|
removePrefixFromKey
|
|
31
29
|
} from "./chunk-JI6GZ2C2.js";
|
|
32
|
-
import "./chunk-V7PJYBA5.js";
|
|
33
30
|
import "./chunk-7AFZMFPQ.js";
|
|
31
|
+
import "./chunk-Q5H37KNQ.js";
|
|
34
32
|
import {
|
|
35
33
|
LogLevelSchema,
|
|
36
34
|
VERSION,
|
|
@@ -63,7 +61,7 @@ import {
|
|
|
63
61
|
parsePortEnv,
|
|
64
62
|
stringifyError,
|
|
65
63
|
toUint8Array
|
|
66
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-X7XY6NCU.js";
|
|
67
65
|
import {
|
|
68
66
|
INTERNAL_ERROR_CODE,
|
|
69
67
|
RivetError,
|
|
@@ -1435,36 +1433,6 @@ function toNapiSqlBatchStatement(statement) {
|
|
|
1435
1433
|
function toNapiBuffer(value) {
|
|
1436
1434
|
return Buffer.from(value);
|
|
1437
1435
|
}
|
|
1438
|
-
function toNapiApplication(application) {
|
|
1439
|
-
return async (error, request) => {
|
|
1440
|
-
if (error) throw error;
|
|
1441
|
-
if (!request) {
|
|
1442
|
-
throw new Error("application fetch callback received no request");
|
|
1443
|
-
}
|
|
1444
|
-
const response = await application(
|
|
1445
|
-
{
|
|
1446
|
-
...request,
|
|
1447
|
-
body: new Uint8Array(request.body),
|
|
1448
|
-
cancelToken: request.cancelToken
|
|
1449
|
-
},
|
|
1450
|
-
request.responseBodyStream ? fromNapiHttpResponseBodyStream(
|
|
1451
|
-
request.responseBodyStream
|
|
1452
|
-
) : void 0
|
|
1453
|
-
);
|
|
1454
|
-
return {
|
|
1455
|
-
...response,
|
|
1456
|
-
body: response.body === void 0 ? void 0 : toNapiBuffer(response.body)
|
|
1457
|
-
};
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
function fromNapiHttpResponseBodyStream(stream) {
|
|
1461
|
-
return {
|
|
1462
|
-
cancelled: () => stream.cancelled(),
|
|
1463
|
-
write: (chunk) => stream.write(Buffer.from(chunk)),
|
|
1464
|
-
end: () => stream.end(),
|
|
1465
|
-
error: (message) => stream.error(message)
|
|
1466
|
-
};
|
|
1467
|
-
}
|
|
1468
1436
|
function toNapiHttpRequest(request) {
|
|
1469
1437
|
if (!request) {
|
|
1470
1438
|
return request;
|
|
@@ -1571,25 +1539,12 @@ var NapiCoreRuntime = class {
|
|
|
1571
1539
|
);
|
|
1572
1540
|
}
|
|
1573
1541
|
async serveListener(registry, listener, config) {
|
|
1574
|
-
const application = listener.application ? toNapiApplication(listener.application) : void 0;
|
|
1575
1542
|
await asNativeRegistry(registry).serveListener(
|
|
1576
1543
|
{
|
|
1577
1544
|
port: listener.port,
|
|
1578
1545
|
host: listener.host,
|
|
1579
1546
|
publicDir: listener.publicDir
|
|
1580
1547
|
},
|
|
1581
|
-
config,
|
|
1582
|
-
application
|
|
1583
|
-
);
|
|
1584
|
-
}
|
|
1585
|
-
async serveApplicationListener(registry, listener, config) {
|
|
1586
|
-
await asNativeRegistry(registry).serveApplicationListener(
|
|
1587
|
-
{
|
|
1588
|
-
port: listener.port,
|
|
1589
|
-
host: listener.host,
|
|
1590
|
-
publicDir: listener.publicDir
|
|
1591
|
-
},
|
|
1592
|
-
toNapiApplication(listener.application),
|
|
1593
1548
|
config
|
|
1594
1549
|
);
|
|
1595
1550
|
}
|
|
@@ -1977,137 +1932,6 @@ async function loadNapiRuntime() {
|
|
|
1977
1932
|
};
|
|
1978
1933
|
}
|
|
1979
1934
|
|
|
1980
|
-
// src/registry/native-http.ts
|
|
1981
|
-
var HTTP_BODY_CHUNK_SIZE = 64 * 1024;
|
|
1982
|
-
function runtimeBytesToArrayBuffer(value) {
|
|
1983
|
-
return value.buffer.slice(
|
|
1984
|
-
value.byteOffset,
|
|
1985
|
-
value.byteOffset + value.byteLength
|
|
1986
|
-
);
|
|
1987
|
-
}
|
|
1988
|
-
function buildNativeHttpRequest(init) {
|
|
1989
|
-
var _a;
|
|
1990
|
-
const headers = new Headers(init.headers);
|
|
1991
|
-
const originalUrl = headers.get(HEADER_ORIGINAL_REQUEST_URL);
|
|
1992
|
-
headers.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
1993
|
-
const url = originalUrl ?? (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString());
|
|
1994
|
-
const method2 = init.method.toUpperCase();
|
|
1995
|
-
const bodyForbidden = method2 === "GET" || method2 === "HEAD";
|
|
1996
|
-
const body = bodyForbidden ? void 0 : init.bodyStream ? new ReadableStream({
|
|
1997
|
-
async pull(controller) {
|
|
1998
|
-
var _a2, _b;
|
|
1999
|
-
try {
|
|
2000
|
-
if (init.body && init.body.length > 0) {
|
|
2001
|
-
controller.enqueue(new Uint8Array(init.body));
|
|
2002
|
-
init.body = void 0;
|
|
2003
|
-
return;
|
|
2004
|
-
}
|
|
2005
|
-
const chunk = await ((_a2 = init.bodyStream) == null ? void 0 : _a2.read());
|
|
2006
|
-
if (!chunk) {
|
|
2007
|
-
controller.close();
|
|
2008
|
-
} else {
|
|
2009
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
2010
|
-
}
|
|
2011
|
-
} catch (error) {
|
|
2012
|
-
(_b = init.abortController) == null ? void 0 : _b.abort(error);
|
|
2013
|
-
controller.error(error);
|
|
2014
|
-
}
|
|
2015
|
-
},
|
|
2016
|
-
async cancel() {
|
|
2017
|
-
var _a2;
|
|
2018
|
-
await ((_a2 = init.bodyStream) == null ? void 0 : _a2.cancel());
|
|
2019
|
-
}
|
|
2020
|
-
}) : init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
2021
|
-
const streamInit = init.bodyStream && !bodyForbidden ? { duplex: "half" } : {};
|
|
2022
|
-
return new Request(url, {
|
|
2023
|
-
method: method2,
|
|
2024
|
-
headers,
|
|
2025
|
-
body,
|
|
2026
|
-
signal: ((_a = init.abortController) == null ? void 0 : _a.signal) ?? init.signal,
|
|
2027
|
-
...streamInit
|
|
2028
|
-
});
|
|
2029
|
-
}
|
|
2030
|
-
async function cancelNativeHttpRequestBody(bodyStream) {
|
|
2031
|
-
await (bodyStream == null ? void 0 : bodyStream.cancel());
|
|
2032
|
-
}
|
|
2033
|
-
async function writeResponseChunk(stream, chunk) {
|
|
2034
|
-
for (let offset = 0; offset < chunk.byteLength; offset += HTTP_BODY_CHUNK_SIZE) {
|
|
2035
|
-
await stream.write(
|
|
2036
|
-
chunk.subarray(offset, offset + HTTP_BODY_CHUNK_SIZE)
|
|
2037
|
-
);
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
async function pumpResponseBody(reader, stream) {
|
|
2041
|
-
var _a;
|
|
2042
|
-
const cancelled = stream.cancelled().then(() => ({ cancelled: true }));
|
|
2043
|
-
try {
|
|
2044
|
-
for (; ; ) {
|
|
2045
|
-
const read = reader.read().then((next2) => ({ cancelled: false, next: next2 }));
|
|
2046
|
-
const result = await Promise.race([read, cancelled]);
|
|
2047
|
-
if (result.cancelled) {
|
|
2048
|
-
await reader.cancel(
|
|
2049
|
-
new Error("native http response stream receiver dropped")
|
|
2050
|
-
);
|
|
2051
|
-
return;
|
|
2052
|
-
}
|
|
2053
|
-
const { next } = result;
|
|
2054
|
-
if (next.done) {
|
|
2055
|
-
await stream.end();
|
|
2056
|
-
return;
|
|
2057
|
-
}
|
|
2058
|
-
if ((_a = next.value) == null ? void 0 : _a.byteLength) {
|
|
2059
|
-
await writeResponseChunk(stream, next.value);
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
} catch (error) {
|
|
2063
|
-
try {
|
|
2064
|
-
await stream.error(stringifyError(error));
|
|
2065
|
-
} catch (streamError) {
|
|
2066
|
-
logger2().debug({
|
|
2067
|
-
msg: "failed to report native http response stream error",
|
|
2068
|
-
error: streamError
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
try {
|
|
2072
|
-
await reader.cancel(error);
|
|
2073
|
-
} catch {
|
|
2074
|
-
}
|
|
2075
|
-
} finally {
|
|
2076
|
-
reader.releaseLock();
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
async function convertNativeHttpResponse(response, responseBodyStream) {
|
|
2080
|
-
const headers = Object.fromEntries(response.headers.entries());
|
|
2081
|
-
if (!response.body) {
|
|
2082
|
-
return {
|
|
2083
|
-
response: {
|
|
2084
|
-
status: response.status,
|
|
2085
|
-
headers,
|
|
2086
|
-
body: new Uint8Array()
|
|
2087
|
-
}
|
|
2088
|
-
};
|
|
2089
|
-
}
|
|
2090
|
-
if (responseBodyStream) {
|
|
2091
|
-
const reader = response.body.getReader();
|
|
2092
|
-
const bodyCompletion = pumpResponseBody(reader, responseBodyStream);
|
|
2093
|
-
return {
|
|
2094
|
-
response: {
|
|
2095
|
-
status: response.status,
|
|
2096
|
-
headers,
|
|
2097
|
-
stream: true
|
|
2098
|
-
},
|
|
2099
|
-
bodyCompletion
|
|
2100
|
-
};
|
|
2101
|
-
}
|
|
2102
|
-
return {
|
|
2103
|
-
response: {
|
|
2104
|
-
status: response.status,
|
|
2105
|
-
headers,
|
|
2106
|
-
body: new Uint8Array(await response.arrayBuffer())
|
|
2107
|
-
}
|
|
2108
|
-
};
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
1935
|
// src/registry/native-validation.ts
|
|
2112
1936
|
var CONN_PARAMS_KEY = "__conn_params__";
|
|
2113
1937
|
function validateActionArgs(schemas, name, args) {
|
|
@@ -2380,11 +2204,6 @@ var WasmCoreRuntime = class {
|
|
|
2380
2204
|
"registry.listen() is not supported on the wasm runtime; use registry.serve() and mount the handler in your platform's HTTP server instead"
|
|
2381
2205
|
);
|
|
2382
2206
|
}
|
|
2383
|
-
async serveApplicationListener(_registry, _listener, _config) {
|
|
2384
|
-
throw new Error(
|
|
2385
|
-
"registry.listen() is not supported on the wasm runtime; use an application-owned HTTP server instead"
|
|
2386
|
-
);
|
|
2387
|
-
}
|
|
2388
2207
|
createActorFactory(callbacks, config) {
|
|
2389
2208
|
return callWasmSync(
|
|
2390
2209
|
() => asActorFactoryHandle2(
|
|
@@ -3242,7 +3061,7 @@ function toRuntimeBytes(value) {
|
|
|
3242
3061
|
function arrayBufferViewToRuntimeBytes(value) {
|
|
3243
3062
|
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
3244
3063
|
}
|
|
3245
|
-
function
|
|
3064
|
+
function runtimeBytesToArrayBuffer(value) {
|
|
3246
3065
|
return value.buffer.slice(
|
|
3247
3066
|
value.byteOffset,
|
|
3248
3067
|
value.byteOffset + value.byteLength
|
|
@@ -3572,6 +3391,24 @@ function decodeArgs(value) {
|
|
|
3572
3391
|
const decoded = decodeValue(value);
|
|
3573
3392
|
return normalizeArgs(decoded);
|
|
3574
3393
|
}
|
|
3394
|
+
function buildRequest(init) {
|
|
3395
|
+
const url = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
|
|
3396
|
+
const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
3397
|
+
return new Request(url, {
|
|
3398
|
+
method: init.method,
|
|
3399
|
+
headers: init.headers,
|
|
3400
|
+
body
|
|
3401
|
+
});
|
|
3402
|
+
}
|
|
3403
|
+
async function toRuntimeHttpResponse(response) {
|
|
3404
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
3405
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
3406
|
+
return {
|
|
3407
|
+
status: response.status,
|
|
3408
|
+
headers,
|
|
3409
|
+
body
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3575
3412
|
function toActorKey(segments) {
|
|
3576
3413
|
return segments.map(
|
|
3577
3414
|
(segment) => segment.kind === "number" ? String(segment.numberValue ?? 0) : segment.stringValue ?? ""
|
|
@@ -4236,7 +4073,7 @@ var NativeWebSocketAdapter = class {
|
|
|
4236
4073
|
this.#runtime.webSocketSetEventCallback(this.#ws, (event2) => {
|
|
4237
4074
|
if (event2.kind === "message") {
|
|
4238
4075
|
this.#virtual.triggerMessage(
|
|
4239
|
-
event2.binary ?
|
|
4076
|
+
event2.binary ? runtimeBytesToArrayBuffer(event2.data) : event2.data,
|
|
4240
4077
|
event2.messageIndex
|
|
4241
4078
|
);
|
|
4242
4079
|
return;
|
|
@@ -5468,14 +5305,12 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
5468
5305
|
onStateChange,
|
|
5469
5306
|
cancelToken
|
|
5470
5307
|
);
|
|
5471
|
-
const maybeHandleNativeInspectorRequest = async (ctx,
|
|
5308
|
+
const maybeHandleNativeInspectorRequest = async (ctx, _rawRequest, jsRequest) => {
|
|
5472
5309
|
var _a2, _b, _c, _d;
|
|
5473
|
-
const
|
|
5474
|
-
const url = new URL(rawUrl);
|
|
5310
|
+
const url = new URL(jsRequest.url);
|
|
5475
5311
|
if (!url.pathname.startsWith("/inspector/")) {
|
|
5476
5312
|
return void 0;
|
|
5477
5313
|
}
|
|
5478
|
-
const jsRequest = buildNativeHttpRequest(rawRequest);
|
|
5479
5314
|
const jsonResponse = (body, init) => new Response(JSON.stringify(body), {
|
|
5480
5315
|
status: (init == null ? void 0 : init.status) ?? 200,
|
|
5481
5316
|
headers: {
|
|
@@ -6006,7 +5841,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6006
5841
|
);
|
|
6007
5842
|
const actorCtx = makeActorCtx(
|
|
6008
5843
|
ctx,
|
|
6009
|
-
request ?
|
|
5844
|
+
request ? buildRequest(request) : void 0
|
|
6010
5845
|
);
|
|
6011
5846
|
try {
|
|
6012
5847
|
await config.onBeforeConnect(
|
|
@@ -6026,7 +5861,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6026
5861
|
const { ctx, conn, params, request } = unwrapTsfnPayload(error, payload);
|
|
6027
5862
|
const actorCtx = makeActorCtx(
|
|
6028
5863
|
ctx,
|
|
6029
|
-
request ?
|
|
5864
|
+
request ? buildRequest(request) : void 0
|
|
6030
5865
|
);
|
|
6031
5866
|
const connAdapter = new NativeConnAdapter(
|
|
6032
5867
|
runtime,
|
|
@@ -6063,7 +5898,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6063
5898
|
);
|
|
6064
5899
|
const actorCtx = makeActorCtx(
|
|
6065
5900
|
ctx,
|
|
6066
|
-
request ?
|
|
5901
|
+
request ? buildRequest(request) : void 0
|
|
6067
5902
|
);
|
|
6068
5903
|
const connAdapter = new NativeConnAdapter(
|
|
6069
5904
|
runtime,
|
|
@@ -6168,45 +6003,27 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6168
6003
|
onRequest: wrapNativeCallback(
|
|
6169
6004
|
async (error, payload) => {
|
|
6170
6005
|
try {
|
|
6171
|
-
const { ctx, request, cancelToken
|
|
6172
|
-
|
|
6006
|
+
const { ctx, request, cancelToken } = unwrapTsfnPayload(
|
|
6007
|
+
error,
|
|
6008
|
+
payload
|
|
6009
|
+
);
|
|
6010
|
+
const jsRequest = buildRequest(request);
|
|
6011
|
+
const inspectorResponse = await maybeHandleNativeInspectorRequest(
|
|
6012
|
+
ctx,
|
|
6013
|
+
request,
|
|
6014
|
+
jsRequest
|
|
6015
|
+
);
|
|
6173
6016
|
if (inspectorResponse) {
|
|
6174
|
-
await
|
|
6175
|
-
return (await convertNativeHttpResponse(
|
|
6176
|
-
inspectorResponse,
|
|
6177
|
-
responseBodyStream
|
|
6178
|
-
)).response;
|
|
6017
|
+
return await toRuntimeHttpResponse(inspectorResponse);
|
|
6179
6018
|
}
|
|
6180
6019
|
if (typeof config.onRequest !== "function") {
|
|
6181
|
-
await
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
responseBodyStream
|
|
6185
|
-
)).response;
|
|
6020
|
+
return await toRuntimeHttpResponse(
|
|
6021
|
+
new Response(null, { status: 404 })
|
|
6022
|
+
);
|
|
6186
6023
|
}
|
|
6187
|
-
const
|
|
6188
|
-
const handlerRequest = buildNativeHttpRequest({
|
|
6189
|
-
...request,
|
|
6190
|
-
abortController: requestAbortController
|
|
6191
|
-
});
|
|
6192
|
-
const rawConnParams = handlerRequest.headers.get(HEADER_CONN_PARAMS);
|
|
6024
|
+
const rawConnParams = jsRequest.headers.get(HEADER_CONN_PARAMS);
|
|
6193
6025
|
let requestCtx;
|
|
6194
6026
|
let conn;
|
|
6195
|
-
let removeRequestAbortListener;
|
|
6196
|
-
let cleanupDeferredToBody = false;
|
|
6197
|
-
let cleanedUp = false;
|
|
6198
|
-
const cleanupRequest = async () => {
|
|
6199
|
-
if (cleanedUp) return;
|
|
6200
|
-
cleanedUp = true;
|
|
6201
|
-
removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
|
|
6202
|
-
try {
|
|
6203
|
-
await (requestCtx == null ? void 0 : requestCtx.dispose());
|
|
6204
|
-
} finally {
|
|
6205
|
-
if (conn) {
|
|
6206
|
-
await runtime.connDisconnect(conn);
|
|
6207
|
-
}
|
|
6208
|
-
}
|
|
6209
|
-
};
|
|
6210
6027
|
try {
|
|
6211
6028
|
const connParams = validateConnParams(
|
|
6212
6029
|
schemaConfig.connParamsSchema,
|
|
@@ -6222,56 +6039,23 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6222
6039
|
requestCtx = makeConnCtx(
|
|
6223
6040
|
ctx,
|
|
6224
6041
|
conn,
|
|
6225
|
-
|
|
6042
|
+
jsRequest,
|
|
6226
6043
|
cancelToken
|
|
6227
6044
|
);
|
|
6228
|
-
const ctxAbortSignal = requestCtx.abortSignal;
|
|
6229
|
-
const abortRequest = () => requestAbortController.abort(ctxAbortSignal.reason);
|
|
6230
|
-
if (ctxAbortSignal.aborted) {
|
|
6231
|
-
abortRequest();
|
|
6232
|
-
} else {
|
|
6233
|
-
ctxAbortSignal.addEventListener(
|
|
6234
|
-
"abort",
|
|
6235
|
-
abortRequest,
|
|
6236
|
-
{ once: true }
|
|
6237
|
-
);
|
|
6238
|
-
removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
|
|
6239
|
-
"abort",
|
|
6240
|
-
abortRequest
|
|
6241
|
-
);
|
|
6242
|
-
}
|
|
6243
6045
|
const response = await config.onRequest(
|
|
6244
6046
|
requestCtx,
|
|
6245
|
-
|
|
6047
|
+
jsRequest
|
|
6246
6048
|
);
|
|
6247
|
-
if (!
|
|
6049
|
+
if (!(response instanceof Response)) {
|
|
6248
6050
|
throw new Error(
|
|
6249
6051
|
"onRequest handler must return a Response"
|
|
6250
6052
|
);
|
|
6251
6053
|
}
|
|
6252
|
-
|
|
6253
|
-
response,
|
|
6254
|
-
responseBodyStream
|
|
6255
|
-
);
|
|
6256
|
-
if (conversion.bodyCompletion) {
|
|
6257
|
-
cleanupDeferredToBody = true;
|
|
6258
|
-
void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
|
|
6259
|
-
logger2().error({
|
|
6260
|
-
msg: "failed to clean up native streaming http request",
|
|
6261
|
-
error: cleanupError
|
|
6262
|
-
});
|
|
6263
|
-
});
|
|
6264
|
-
}
|
|
6265
|
-
return conversion.response;
|
|
6054
|
+
return await toRuntimeHttpResponse(response);
|
|
6266
6055
|
} finally {
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
);
|
|
6271
|
-
} finally {
|
|
6272
|
-
if (!cleanupDeferredToBody) {
|
|
6273
|
-
await cleanupRequest();
|
|
6274
|
-
}
|
|
6056
|
+
await (requestCtx == null ? void 0 : requestCtx.dispose());
|
|
6057
|
+
if (conn) {
|
|
6058
|
+
await runtime.connDisconnect(conn);
|
|
6275
6059
|
}
|
|
6276
6060
|
}
|
|
6277
6061
|
} catch (error2) {
|
|
@@ -6286,7 +6070,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6286
6070
|
onWebSocket: typeof config.onWebSocket === "function" ? wrapNativeCallback(
|
|
6287
6071
|
async (error, payload) => {
|
|
6288
6072
|
const { ctx, conn, ws, request } = unwrapTsfnPayload(error, payload);
|
|
6289
|
-
const jsRequest = request ?
|
|
6073
|
+
const jsRequest = request ? buildRequest(request) : void 0;
|
|
6290
6074
|
const actorCtx = makeConnCtx(ctx, conn, jsRequest);
|
|
6291
6075
|
try {
|
|
6292
6076
|
await config.onWebSocket(
|
|
@@ -6383,7 +6167,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6383
6167
|
timeoutMs,
|
|
6384
6168
|
cancelToken
|
|
6385
6169
|
} = unwrapTsfnPayload(error, payload);
|
|
6386
|
-
const jsRequest =
|
|
6170
|
+
const jsRequest = buildRequest(request);
|
|
6387
6171
|
const actorCtx = withConnContext(
|
|
6388
6172
|
runtime,
|
|
6389
6173
|
ctx,
|
|
@@ -6534,54 +6318,6 @@ function finishShutdownSignal(signal) {
|
|
|
6534
6318
|
}
|
|
6535
6319
|
process.kill(process.pid, signal);
|
|
6536
6320
|
}
|
|
6537
|
-
function createApplicationFetch(application, runtime) {
|
|
6538
|
-
return async (request, responseBodyStream) => {
|
|
6539
|
-
const method2 = request.method.toUpperCase();
|
|
6540
|
-
const body = method2 === "GET" || method2 === "HEAD" || request.body.length === 0 ? void 0 : Uint8Array.from(request.body).buffer;
|
|
6541
|
-
const abortController = new AbortController();
|
|
6542
|
-
if (request.cancelToken) {
|
|
6543
|
-
if (runtime.cancellationTokenAborted(request.cancelToken)) {
|
|
6544
|
-
abortController.abort();
|
|
6545
|
-
} else {
|
|
6546
|
-
runtime.onCancellationTokenCancelled(
|
|
6547
|
-
request.cancelToken,
|
|
6548
|
-
() => abortController.abort()
|
|
6549
|
-
);
|
|
6550
|
-
}
|
|
6551
|
-
}
|
|
6552
|
-
const response = await application.fetch(
|
|
6553
|
-
new Request(request.url, {
|
|
6554
|
-
method: method2,
|
|
6555
|
-
headers: request.headers,
|
|
6556
|
-
body,
|
|
6557
|
-
signal: abortController.signal
|
|
6558
|
-
})
|
|
6559
|
-
);
|
|
6560
|
-
if (!isResponseLike(response)) {
|
|
6561
|
-
throw new TypeError(
|
|
6562
|
-
"registry.listen() application fetch must return a Response"
|
|
6563
|
-
);
|
|
6564
|
-
}
|
|
6565
|
-
const conversion = await convertNativeHttpResponse(
|
|
6566
|
-
response,
|
|
6567
|
-
responseBodyStream
|
|
6568
|
-
);
|
|
6569
|
-
if (conversion.bodyCompletion) {
|
|
6570
|
-
void conversion.bodyCompletion.catch((error) => {
|
|
6571
|
-
logger2().error({
|
|
6572
|
-
msg: "application response stream failed",
|
|
6573
|
-
error
|
|
6574
|
-
});
|
|
6575
|
-
});
|
|
6576
|
-
}
|
|
6577
|
-
return {
|
|
6578
|
-
status: conversion.response.status ?? response.status,
|
|
6579
|
-
headers: conversion.response.headers ?? Object.fromEntries(response.headers.entries()),
|
|
6580
|
-
body: conversion.response.body,
|
|
6581
|
-
stream: conversion.response.stream
|
|
6582
|
-
};
|
|
6583
|
-
};
|
|
6584
|
-
}
|
|
6585
6321
|
var Registry = class {
|
|
6586
6322
|
#config;
|
|
6587
6323
|
#buildConfiguredRegistry;
|
|
@@ -6597,7 +6333,6 @@ var Registry = class {
|
|
|
6597
6333
|
#runtimeReadyPromise;
|
|
6598
6334
|
#runtimeServeConfiguredPromise;
|
|
6599
6335
|
#runtimeServerlessPromise;
|
|
6600
|
-
#applicationListenerPromise;
|
|
6601
6336
|
#configureServerlessPoolPromise;
|
|
6602
6337
|
#welcomePrinted = false;
|
|
6603
6338
|
#shutdownInstalled = false;
|
|
@@ -6823,67 +6558,18 @@ var Registry = class {
|
|
|
6823
6558
|
* @param opts.host Address to bind. Defaults to `0.0.0.0`.
|
|
6824
6559
|
* @param opts.publicDir If set, serves static files from this directory
|
|
6825
6560
|
* as a fallback below the framework routes.
|
|
6826
|
-
* @param opts.application If set, handles requests that do not match a
|
|
6827
|
-
* framework route.
|
|
6828
6561
|
*
|
|
6829
6562
|
* @example
|
|
6830
6563
|
* ```ts
|
|
6831
6564
|
* await registry.listen();
|
|
6832
|
-
* await registry.listen({
|
|
6565
|
+
* await registry.listen({ port: 8080, publicDir: "./public" });
|
|
6833
6566
|
* ```
|
|
6834
6567
|
*/
|
|
6835
6568
|
async listen(opts = {}) {
|
|
6836
6569
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
|
|
6837
6570
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
6838
6571
|
const config = this.parseConfig();
|
|
6839
|
-
|
|
6840
|
-
if (config.runtime === "wasm") {
|
|
6841
|
-
throw new Error(
|
|
6842
|
-
"registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
|
|
6843
|
-
);
|
|
6844
|
-
}
|
|
6845
|
-
this.#installSignalHandlers(config);
|
|
6846
|
-
this.#printWelcome(config, "serverful", {
|
|
6847
|
-
port,
|
|
6848
|
-
host: opts.host,
|
|
6849
|
-
publicDir
|
|
6850
|
-
});
|
|
6851
|
-
this.#startEnvoy(config, true);
|
|
6852
|
-
const readyPromise = this.startAndWait();
|
|
6853
|
-
const configuredRegistryPromise2 = this.#runtimeServeConfiguredPromise;
|
|
6854
|
-
if (!configuredRegistryPromise2) {
|
|
6855
|
-
throw new Error("registry envoy startup did not initialize");
|
|
6856
|
-
}
|
|
6857
|
-
const { runtime: runtime2, registry: registry2, serveConfig: serveConfig2 } = await configuredRegistryPromise2;
|
|
6858
|
-
const application2 = createApplicationFetch(
|
|
6859
|
-
opts.application,
|
|
6860
|
-
runtime2
|
|
6861
|
-
);
|
|
6862
|
-
await readyPromise;
|
|
6863
|
-
const listenerPromise = runtime2.serveApplicationListener(
|
|
6864
|
-
registry2,
|
|
6865
|
-
{
|
|
6866
|
-
port,
|
|
6867
|
-
host: opts.host,
|
|
6868
|
-
publicDir,
|
|
6869
|
-
application: application2
|
|
6870
|
-
},
|
|
6871
|
-
serveConfig2
|
|
6872
|
-
);
|
|
6873
|
-
this.#applicationListenerPromise = listenerPromise;
|
|
6874
|
-
const serveLifecyclePromise = this.#runtimeServeLifecyclePromise;
|
|
6875
|
-
if (!serveLifecyclePromise) {
|
|
6876
|
-
throw new Error(
|
|
6877
|
-
"registry envoy serve lifecycle did not initialize"
|
|
6878
|
-
);
|
|
6879
|
-
}
|
|
6880
|
-
await Promise.all([
|
|
6881
|
-
listenerPromise,
|
|
6882
|
-
serveLifecyclePromise
|
|
6883
|
-
]);
|
|
6884
|
-
return;
|
|
6885
|
-
}
|
|
6886
|
-
const configuredRegistryPromise = this.#buildConfiguredRegistry(config);
|
|
6572
|
+
const configuredRegistryPromise = buildConfiguredRegistry(config);
|
|
6887
6573
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
6888
6574
|
this.#runtimeServerlessPromise = configuredRegistryPromise;
|
|
6889
6575
|
this.#installSignalHandlers(config);
|
|
@@ -6894,15 +6580,9 @@ var Registry = class {
|
|
|
6894
6580
|
});
|
|
6895
6581
|
this.#ensureServerlessPoolConfigured(config);
|
|
6896
6582
|
const { runtime, registry, serveConfig } = await configuredRegistryPromise;
|
|
6897
|
-
const application = opts.application ? createApplicationFetch(opts.application, runtime) : void 0;
|
|
6898
6583
|
await runtime.serveListener(
|
|
6899
6584
|
registry,
|
|
6900
|
-
{
|
|
6901
|
-
port,
|
|
6902
|
-
host: opts.host,
|
|
6903
|
-
publicDir,
|
|
6904
|
-
application
|
|
6905
|
-
},
|
|
6585
|
+
{ port, host: opts.host, publicDir },
|
|
6906
6586
|
serveConfig
|
|
6907
6587
|
);
|
|
6908
6588
|
}
|
|
@@ -7002,9 +6682,11 @@ var Registry = class {
|
|
|
7002
6682
|
await runtime.serveRegistry(registry, serveConfig);
|
|
7003
6683
|
}
|
|
7004
6684
|
);
|
|
7005
|
-
this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch(
|
|
7006
|
-
|
|
7007
|
-
|
|
6685
|
+
this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch(
|
|
6686
|
+
(error) => {
|
|
6687
|
+
logger2().warn({ error }, "runtime registry serve errored");
|
|
6688
|
+
}
|
|
6689
|
+
);
|
|
7008
6690
|
this.#installSignalHandlers(config);
|
|
7009
6691
|
}
|
|
7010
6692
|
if (printWelcome) {
|
|
@@ -7111,9 +6793,6 @@ var Registry = class {
|
|
|
7111
6793
|
if (runtimeServePromise !== void 0) {
|
|
7112
6794
|
await runtimeServePromise.catch(() => void 0);
|
|
7113
6795
|
}
|
|
7114
|
-
if (this.#applicationListenerPromise !== void 0) {
|
|
7115
|
-
await this.#applicationListenerPromise.catch(() => void 0);
|
|
7116
|
-
}
|
|
7117
6796
|
};
|
|
7118
6797
|
await Promise.race([
|
|
7119
6798
|
drain(),
|
|
@@ -7164,9 +6843,7 @@ var Registry = class {
|
|
|
7164
6843
|
startAndWait() {
|
|
7165
6844
|
if (this.#shutdownInFlight !== null) {
|
|
7166
6845
|
return Promise.reject(
|
|
7167
|
-
new Error(
|
|
7168
|
-
"registry.startAndWait() cannot run after shutdown has begun"
|
|
7169
|
-
)
|
|
6846
|
+
new Error("registry.startAndWait() cannot run after shutdown has begun")
|
|
7170
6847
|
);
|
|
7171
6848
|
}
|
|
7172
6849
|
if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
|
|
@@ -7207,9 +6884,7 @@ var Registry = class {
|
|
|
7207
6884
|
const readinessPromise = (async () => {
|
|
7208
6885
|
const { runtime, registry } = await configuredRegistryPromise;
|
|
7209
6886
|
const stoppedBeforeReady = serveLifecyclePromise.then(() => {
|
|
7210
|
-
throw new Error(
|
|
7211
|
-
"RivetKit registry stopped before becoming ready"
|
|
7212
|
-
);
|
|
6887
|
+
throw new Error("RivetKit registry stopped before becoming ready");
|
|
7213
6888
|
});
|
|
7214
6889
|
await Promise.race([
|
|
7215
6890
|
runtime.waitRegistryReady(registry),
|