@rivetkit/supabase 2.3.9 → 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/mod.js +79 -420
- package/dist/mod.mjs +79 -420
- package/package.json +3 -3
package/dist/mod.mjs
CHANGED
|
@@ -471,7 +471,7 @@ function unsupportedFeature(feature) {
|
|
|
471
471
|
);
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
474
|
+
// ../rivetkit/dist/tsup/chunk-X7XY6NCU.js
|
|
475
475
|
import {
|
|
476
476
|
pino,
|
|
477
477
|
stdTimeFunctions
|
|
@@ -13147,7 +13147,7 @@ var classic_default = external_exports;
|
|
|
13147
13147
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
13148
13148
|
var v4_default = classic_default;
|
|
13149
13149
|
|
|
13150
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
13150
|
+
// ../rivetkit/dist/tsup/chunk-X7XY6NCU.js
|
|
13151
13151
|
var import_invariant = __toESM(require_invariant(), 1);
|
|
13152
13152
|
import * as cbor from "cbor-x";
|
|
13153
13153
|
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
@@ -13312,7 +13312,7 @@ function noopNext() {
|
|
|
13312
13312
|
}
|
|
13313
13313
|
var package_default = {
|
|
13314
13314
|
name: "rivetkit",
|
|
13315
|
-
version: "2.3.
|
|
13315
|
+
version: "2.3.10",
|
|
13316
13316
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13317
13317
|
license: "Apache-2.0",
|
|
13318
13318
|
keywords: [
|
|
@@ -14063,10 +14063,7 @@ function jsonStringifyCompat(input, space) {
|
|
|
14063
14063
|
return [JSON_COMPAT_BIGINT, value.toString()];
|
|
14064
14064
|
}
|
|
14065
14065
|
if (value instanceof ArrayBuffer) {
|
|
14066
|
-
return [
|
|
14067
|
-
JSON_COMPAT_ARRAY_BUFFER,
|
|
14068
|
-
base64EncodeArrayBuffer(value)
|
|
14069
|
-
];
|
|
14066
|
+
return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(value)];
|
|
14070
14067
|
}
|
|
14071
14068
|
if (value instanceof Uint8Array) {
|
|
14072
14069
|
return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
|
|
@@ -14605,7 +14602,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
14605
14602
|
};
|
|
14606
14603
|
}
|
|
14607
14604
|
|
|
14608
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14605
|
+
// ../rivetkit/dist/tsup/chunk-XSPAARQ5.js
|
|
14609
14606
|
var config2 = /* @__PURE__ */ Config({});
|
|
14610
14607
|
function readWorkflowCbor(bc) {
|
|
14611
14608
|
return readData(bc);
|
|
@@ -15478,7 +15475,7 @@ var AsyncMutex = class {
|
|
|
15478
15475
|
}
|
|
15479
15476
|
};
|
|
15480
15477
|
|
|
15481
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15478
|
+
// ../rivetkit/dist/tsup/chunk-Q5H37KNQ.js
|
|
15482
15479
|
function logger() {
|
|
15483
15480
|
return getLogger("actor-client");
|
|
15484
15481
|
}
|
|
@@ -15516,7 +15513,7 @@ async function importWebSocket() {
|
|
|
15516
15513
|
return webSocketPromise;
|
|
15517
15514
|
}
|
|
15518
15515
|
|
|
15519
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15516
|
+
// ../rivetkit/dist/tsup/chunk-DPM73GAL.js
|
|
15520
15517
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15521
15518
|
|
|
15522
15519
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -15694,7 +15691,7 @@ function createVersionedDataHandler(config3) {
|
|
|
15694
15691
|
return new VersionedDataHandler(config3);
|
|
15695
15692
|
}
|
|
15696
15693
|
|
|
15697
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15694
|
+
// ../rivetkit/dist/tsup/chunk-DPM73GAL.js
|
|
15698
15695
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
15699
15696
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
15700
15697
|
var PATH_CONNECT = "/connect";
|
|
@@ -15703,7 +15700,6 @@ var PATH_WEBSOCKET_PREFIX = "/websocket/";
|
|
|
15703
15700
|
var HEADER_ACTOR_QUERY = "x-rivet-query";
|
|
15704
15701
|
var HEADER_ENCODING = "x-rivet-encoding";
|
|
15705
15702
|
var HEADER_CONN_PARAMS = "x-rivet-conn-params";
|
|
15706
|
-
var HEADER_ORIGINAL_REQUEST_URL = "x-rivet-internal-original-request-url";
|
|
15707
15703
|
var HEADER_ACTOR_ID = "x-rivet-actor";
|
|
15708
15704
|
var HEADER_ACTOR_GENERATION = "x-rivet-actor-generation";
|
|
15709
15705
|
var HEADER_ACTOR_KEY = "x-rivet-actor-key";
|
|
@@ -17756,18 +17752,6 @@ async function checkForSchedulingError(group, code, actorId, query, driver) {
|
|
|
17756
17752
|
}
|
|
17757
17753
|
return null;
|
|
17758
17754
|
}
|
|
17759
|
-
function isUrlLike(value) {
|
|
17760
|
-
return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
|
|
17761
|
-
}
|
|
17762
|
-
function isRequestLike(value) {
|
|
17763
|
-
return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
|
|
17764
|
-
}
|
|
17765
|
-
function isResponseLike(value) {
|
|
17766
|
-
return typeof value === "object" && value !== null && typeof value.status === "number" && isHeadersLike(value.headers) && typeof value.arrayBuffer === "function";
|
|
17767
|
-
}
|
|
17768
|
-
function isHeadersLike(value) {
|
|
17769
|
-
return typeof value === "object" && value !== null && typeof value.entries === "function";
|
|
17770
|
-
}
|
|
17771
17755
|
function* walkErrorChain(error46, maxDepth = 8) {
|
|
17772
17756
|
let current = error46;
|
|
17773
17757
|
let depth = 0;
|
|
@@ -18193,17 +18177,14 @@ function createQueueSender(senderOptions) {
|
|
|
18193
18177
|
}
|
|
18194
18178
|
async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
18195
18179
|
let path2;
|
|
18196
|
-
let originalUrl;
|
|
18197
18180
|
let mergedInit = init || {};
|
|
18198
18181
|
if (typeof input === "string") {
|
|
18199
18182
|
path2 = input;
|
|
18200
|
-
} else if (
|
|
18183
|
+
} else if (input instanceof URL) {
|
|
18201
18184
|
path2 = input.pathname + input.search;
|
|
18202
|
-
|
|
18203
|
-
} else if (isRequestLike(input)) {
|
|
18185
|
+
} else if (input instanceof Request) {
|
|
18204
18186
|
const url2 = new URL(input.url);
|
|
18205
18187
|
path2 = url2.pathname + url2.search;
|
|
18206
|
-
originalUrl = url2.toString();
|
|
18207
18188
|
const requestHeaders = new Headers(input.headers);
|
|
18208
18189
|
const initHeaders = new Headers((init == null ? void 0 : init.headers) || {});
|
|
18209
18190
|
const mergedHeaders = new Headers(requestHeaders);
|
|
@@ -18245,10 +18226,6 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
|
18245
18226
|
const normalizedPath = path2.startsWith("/") ? path2.slice(1) : path2;
|
|
18246
18227
|
const url2 = new URL(`http://actor/request/${normalizedPath}`);
|
|
18247
18228
|
const proxyRequestHeaders = new Headers(mergedInit.headers);
|
|
18248
|
-
proxyRequestHeaders.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
18249
|
-
if (originalUrl) {
|
|
18250
|
-
proxyRequestHeaders.set(HEADER_ORIGINAL_REQUEST_URL, originalUrl);
|
|
18251
|
-
}
|
|
18252
18229
|
if (params) {
|
|
18253
18230
|
proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
18254
18231
|
}
|
|
@@ -18717,7 +18694,6 @@ var ActorHandleRaw = class {
|
|
|
18717
18694
|
async #fetchWithResolvedActor(input, init) {
|
|
18718
18695
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
18719
18696
|
let useQueryTarget = false;
|
|
18720
|
-
const retryableRequest = isRequestLike(input) ? input.clone() : void 0;
|
|
18721
18697
|
const { skipReadyWait, ...requestInit } = init ?? {};
|
|
18722
18698
|
const gatewayOptions = resolveActorGatewayOptions(
|
|
18723
18699
|
this.#gatewayOptions,
|
|
@@ -18737,7 +18713,7 @@ var ActorHandleRaw = class {
|
|
|
18737
18713
|
this.#driver,
|
|
18738
18714
|
target,
|
|
18739
18715
|
this.#params,
|
|
18740
|
-
|
|
18716
|
+
input,
|
|
18741
18717
|
requestInit,
|
|
18742
18718
|
gatewayOptions
|
|
18743
18719
|
);
|
|
@@ -20470,19 +20446,23 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, opt
|
|
|
20470
20446
|
if (actorRequest.bodyUsed) {
|
|
20471
20447
|
throw new Error("Request body has already been consumed");
|
|
20472
20448
|
}
|
|
20473
|
-
|
|
20474
|
-
|
|
20449
|
+
const reqBody = await actorRequest.arrayBuffer();
|
|
20450
|
+
if (reqBody.byteLength !== 0) {
|
|
20451
|
+
bodyToSend = reqBody;
|
|
20475
20452
|
guardHeaders.delete("transfer-encoding");
|
|
20476
20453
|
guardHeaders.delete("content-length");
|
|
20477
20454
|
}
|
|
20478
20455
|
}
|
|
20479
|
-
|
|
20456
|
+
const guardRequest = new Request(gatewayUrl, {
|
|
20480
20457
|
method: actorRequest.method,
|
|
20481
20458
|
headers: guardHeaders,
|
|
20482
20459
|
body: bodyToSend,
|
|
20483
|
-
signal: actorRequest.signal
|
|
20484
|
-
...bodyToSend ? { duplex: "half" } : {}
|
|
20460
|
+
signal: actorRequest.signal
|
|
20485
20461
|
});
|
|
20462
|
+
return mutableResponse(await fetch(guardRequest));
|
|
20463
|
+
}
|
|
20464
|
+
function mutableResponse(fetchRes) {
|
|
20465
|
+
return new Response(fetchRes.body, fetchRes);
|
|
20486
20466
|
}
|
|
20487
20467
|
function buildGuardHeaders(runConfig, actorRequest, options) {
|
|
20488
20468
|
const headers = new Headers();
|
|
@@ -23956,36 +23936,6 @@ function toNapiSqlBatchStatement(statement) {
|
|
|
23956
23936
|
function toNapiBuffer(value) {
|
|
23957
23937
|
return Buffer.from(value);
|
|
23958
23938
|
}
|
|
23959
|
-
function toNapiApplication(application) {
|
|
23960
|
-
return async (error46, request) => {
|
|
23961
|
-
if (error46) throw error46;
|
|
23962
|
-
if (!request) {
|
|
23963
|
-
throw new Error("application fetch callback received no request");
|
|
23964
|
-
}
|
|
23965
|
-
const response = await application(
|
|
23966
|
-
{
|
|
23967
|
-
...request,
|
|
23968
|
-
body: new Uint8Array(request.body),
|
|
23969
|
-
cancelToken: request.cancelToken
|
|
23970
|
-
},
|
|
23971
|
-
request.responseBodyStream ? fromNapiHttpResponseBodyStream(
|
|
23972
|
-
request.responseBodyStream
|
|
23973
|
-
) : void 0
|
|
23974
|
-
);
|
|
23975
|
-
return {
|
|
23976
|
-
...response,
|
|
23977
|
-
body: response.body === void 0 ? void 0 : toNapiBuffer(response.body)
|
|
23978
|
-
};
|
|
23979
|
-
};
|
|
23980
|
-
}
|
|
23981
|
-
function fromNapiHttpResponseBodyStream(stream) {
|
|
23982
|
-
return {
|
|
23983
|
-
cancelled: () => stream.cancelled(),
|
|
23984
|
-
write: (chunk) => stream.write(Buffer.from(chunk)),
|
|
23985
|
-
end: () => stream.end(),
|
|
23986
|
-
error: (message) => stream.error(message)
|
|
23987
|
-
};
|
|
23988
|
-
}
|
|
23989
23939
|
function toNapiHttpRequest(request) {
|
|
23990
23940
|
if (!request) {
|
|
23991
23941
|
return request;
|
|
@@ -24092,25 +24042,12 @@ var NapiCoreRuntime = class {
|
|
|
24092
24042
|
);
|
|
24093
24043
|
}
|
|
24094
24044
|
async serveListener(registry2, listener, config3) {
|
|
24095
|
-
const application = listener.application ? toNapiApplication(listener.application) : void 0;
|
|
24096
24045
|
await asNativeRegistry(registry2).serveListener(
|
|
24097
24046
|
{
|
|
24098
24047
|
port: listener.port,
|
|
24099
24048
|
host: listener.host,
|
|
24100
24049
|
publicDir: listener.publicDir
|
|
24101
24050
|
},
|
|
24102
|
-
config3,
|
|
24103
|
-
application
|
|
24104
|
-
);
|
|
24105
|
-
}
|
|
24106
|
-
async serveApplicationListener(registry2, listener, config3) {
|
|
24107
|
-
await asNativeRegistry(registry2).serveApplicationListener(
|
|
24108
|
-
{
|
|
24109
|
-
port: listener.port,
|
|
24110
|
-
host: listener.host,
|
|
24111
|
-
publicDir: listener.publicDir
|
|
24112
|
-
},
|
|
24113
|
-
toNapiApplication(listener.application),
|
|
24114
24051
|
config3
|
|
24115
24052
|
);
|
|
24116
24053
|
}
|
|
@@ -24497,135 +24434,6 @@ async function loadNapiRuntime() {
|
|
|
24497
24434
|
runtime: new NapiCoreRuntime(bindings)
|
|
24498
24435
|
};
|
|
24499
24436
|
}
|
|
24500
|
-
var HTTP_BODY_CHUNK_SIZE = 64 * 1024;
|
|
24501
|
-
function runtimeBytesToArrayBuffer(value) {
|
|
24502
|
-
return value.buffer.slice(
|
|
24503
|
-
value.byteOffset,
|
|
24504
|
-
value.byteOffset + value.byteLength
|
|
24505
|
-
);
|
|
24506
|
-
}
|
|
24507
|
-
function buildNativeHttpRequest(init) {
|
|
24508
|
-
var _a2;
|
|
24509
|
-
const headers = new Headers(init.headers);
|
|
24510
|
-
const originalUrl = headers.get(HEADER_ORIGINAL_REQUEST_URL);
|
|
24511
|
-
headers.delete(HEADER_ORIGINAL_REQUEST_URL);
|
|
24512
|
-
const url2 = originalUrl ?? (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString());
|
|
24513
|
-
const method2 = init.method.toUpperCase();
|
|
24514
|
-
const bodyForbidden = method2 === "GET" || method2 === "HEAD";
|
|
24515
|
-
const body = bodyForbidden ? void 0 : init.bodyStream ? new ReadableStream({
|
|
24516
|
-
async pull(controller) {
|
|
24517
|
-
var _a22, _b;
|
|
24518
|
-
try {
|
|
24519
|
-
if (init.body && init.body.length > 0) {
|
|
24520
|
-
controller.enqueue(new Uint8Array(init.body));
|
|
24521
|
-
init.body = void 0;
|
|
24522
|
-
return;
|
|
24523
|
-
}
|
|
24524
|
-
const chunk = await ((_a22 = init.bodyStream) == null ? void 0 : _a22.read());
|
|
24525
|
-
if (!chunk) {
|
|
24526
|
-
controller.close();
|
|
24527
|
-
} else {
|
|
24528
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
24529
|
-
}
|
|
24530
|
-
} catch (error46) {
|
|
24531
|
-
(_b = init.abortController) == null ? void 0 : _b.abort(error46);
|
|
24532
|
-
controller.error(error46);
|
|
24533
|
-
}
|
|
24534
|
-
},
|
|
24535
|
-
async cancel() {
|
|
24536
|
-
var _a22;
|
|
24537
|
-
await ((_a22 = init.bodyStream) == null ? void 0 : _a22.cancel());
|
|
24538
|
-
}
|
|
24539
|
-
}) : init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
24540
|
-
const streamInit = init.bodyStream && !bodyForbidden ? { duplex: "half" } : {};
|
|
24541
|
-
return new Request(url2, {
|
|
24542
|
-
method: method2,
|
|
24543
|
-
headers,
|
|
24544
|
-
body,
|
|
24545
|
-
signal: ((_a2 = init.abortController) == null ? void 0 : _a2.signal) ?? init.signal,
|
|
24546
|
-
...streamInit
|
|
24547
|
-
});
|
|
24548
|
-
}
|
|
24549
|
-
async function cancelNativeHttpRequestBody(bodyStream) {
|
|
24550
|
-
await (bodyStream == null ? void 0 : bodyStream.cancel());
|
|
24551
|
-
}
|
|
24552
|
-
async function writeResponseChunk(stream, chunk) {
|
|
24553
|
-
for (let offset = 0; offset < chunk.byteLength; offset += HTTP_BODY_CHUNK_SIZE) {
|
|
24554
|
-
await stream.write(
|
|
24555
|
-
chunk.subarray(offset, offset + HTTP_BODY_CHUNK_SIZE)
|
|
24556
|
-
);
|
|
24557
|
-
}
|
|
24558
|
-
}
|
|
24559
|
-
async function pumpResponseBody(reader, stream) {
|
|
24560
|
-
var _a2;
|
|
24561
|
-
const cancelled = stream.cancelled().then(() => ({ cancelled: true }));
|
|
24562
|
-
try {
|
|
24563
|
-
for (; ; ) {
|
|
24564
|
-
const read = reader.read().then((next2) => ({ cancelled: false, next: next2 }));
|
|
24565
|
-
const result = await Promise.race([read, cancelled]);
|
|
24566
|
-
if (result.cancelled) {
|
|
24567
|
-
await reader.cancel(
|
|
24568
|
-
new Error("native http response stream receiver dropped")
|
|
24569
|
-
);
|
|
24570
|
-
return;
|
|
24571
|
-
}
|
|
24572
|
-
const { next } = result;
|
|
24573
|
-
if (next.done) {
|
|
24574
|
-
await stream.end();
|
|
24575
|
-
return;
|
|
24576
|
-
}
|
|
24577
|
-
if ((_a2 = next.value) == null ? void 0 : _a2.byteLength) {
|
|
24578
|
-
await writeResponseChunk(stream, next.value);
|
|
24579
|
-
}
|
|
24580
|
-
}
|
|
24581
|
-
} catch (error46) {
|
|
24582
|
-
try {
|
|
24583
|
-
await stream.error(stringifyError(error46));
|
|
24584
|
-
} catch (streamError) {
|
|
24585
|
-
logger22().debug({
|
|
24586
|
-
msg: "failed to report native http response stream error",
|
|
24587
|
-
error: streamError
|
|
24588
|
-
});
|
|
24589
|
-
}
|
|
24590
|
-
try {
|
|
24591
|
-
await reader.cancel(error46);
|
|
24592
|
-
} catch {
|
|
24593
|
-
}
|
|
24594
|
-
} finally {
|
|
24595
|
-
reader.releaseLock();
|
|
24596
|
-
}
|
|
24597
|
-
}
|
|
24598
|
-
async function convertNativeHttpResponse(response, responseBodyStream) {
|
|
24599
|
-
const headers = Object.fromEntries(response.headers.entries());
|
|
24600
|
-
if (!response.body) {
|
|
24601
|
-
return {
|
|
24602
|
-
response: {
|
|
24603
|
-
status: response.status,
|
|
24604
|
-
headers,
|
|
24605
|
-
body: new Uint8Array()
|
|
24606
|
-
}
|
|
24607
|
-
};
|
|
24608
|
-
}
|
|
24609
|
-
if (responseBodyStream) {
|
|
24610
|
-
const reader = response.body.getReader();
|
|
24611
|
-
const bodyCompletion = pumpResponseBody(reader, responseBodyStream);
|
|
24612
|
-
return {
|
|
24613
|
-
response: {
|
|
24614
|
-
status: response.status,
|
|
24615
|
-
headers,
|
|
24616
|
-
stream: true
|
|
24617
|
-
},
|
|
24618
|
-
bodyCompletion
|
|
24619
|
-
};
|
|
24620
|
-
}
|
|
24621
|
-
return {
|
|
24622
|
-
response: {
|
|
24623
|
-
status: response.status,
|
|
24624
|
-
headers,
|
|
24625
|
-
body: new Uint8Array(await response.arrayBuffer())
|
|
24626
|
-
}
|
|
24627
|
-
};
|
|
24628
|
-
}
|
|
24629
24437
|
var CONN_PARAMS_KEY = "__conn_params__";
|
|
24630
24438
|
function validateActionArgs(schemas, name, args) {
|
|
24631
24439
|
if (!(schemas == null ? void 0 : schemas[name])) {
|
|
@@ -24895,11 +24703,6 @@ var WasmCoreRuntime = class {
|
|
|
24895
24703
|
"registry.listen() is not supported on the wasm runtime; use registry.serve() and mount the handler in your platform's HTTP server instead"
|
|
24896
24704
|
);
|
|
24897
24705
|
}
|
|
24898
|
-
async serveApplicationListener(_registry, _listener, _config) {
|
|
24899
|
-
throw new Error(
|
|
24900
|
-
"registry.listen() is not supported on the wasm runtime; use an application-owned HTTP server instead"
|
|
24901
|
-
);
|
|
24902
|
-
}
|
|
24903
24706
|
createActorFactory(callbacks, config3) {
|
|
24904
24707
|
return callWasmSync(
|
|
24905
24708
|
() => asActorFactoryHandle2(
|
|
@@ -25752,7 +25555,7 @@ function toRuntimeBytes(value) {
|
|
|
25752
25555
|
function arrayBufferViewToRuntimeBytes(value) {
|
|
25753
25556
|
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
25754
25557
|
}
|
|
25755
|
-
function
|
|
25558
|
+
function runtimeBytesToArrayBuffer(value) {
|
|
25756
25559
|
return value.buffer.slice(
|
|
25757
25560
|
value.byteOffset,
|
|
25758
25561
|
value.byteOffset + value.byteLength
|
|
@@ -26082,6 +25885,24 @@ function decodeArgs(value) {
|
|
|
26082
25885
|
const decoded = decodeValue(value);
|
|
26083
25886
|
return normalizeArgs(decoded);
|
|
26084
25887
|
}
|
|
25888
|
+
function buildRequest(init) {
|
|
25889
|
+
const url2 = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
|
|
25890
|
+
const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
25891
|
+
return new Request(url2, {
|
|
25892
|
+
method: init.method,
|
|
25893
|
+
headers: init.headers,
|
|
25894
|
+
body
|
|
25895
|
+
});
|
|
25896
|
+
}
|
|
25897
|
+
async function toRuntimeHttpResponse(response) {
|
|
25898
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
25899
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
25900
|
+
return {
|
|
25901
|
+
status: response.status,
|
|
25902
|
+
headers,
|
|
25903
|
+
body
|
|
25904
|
+
};
|
|
25905
|
+
}
|
|
26085
25906
|
function toActorKey(segments) {
|
|
26086
25907
|
return segments.map(
|
|
26087
25908
|
(segment) => segment.kind === "number" ? String(segment.numberValue ?? 0) : segment.stringValue ?? ""
|
|
@@ -26746,7 +26567,7 @@ var NativeWebSocketAdapter = class {
|
|
|
26746
26567
|
this.#runtime.webSocketSetEventCallback(this.#ws, (event2) => {
|
|
26747
26568
|
if (event2.kind === "message") {
|
|
26748
26569
|
this.#virtual.triggerMessage(
|
|
26749
|
-
event2.binary ?
|
|
26570
|
+
event2.binary ? runtimeBytesToArrayBuffer(event2.data) : event2.data,
|
|
26750
26571
|
event2.messageIndex
|
|
26751
26572
|
);
|
|
26752
26573
|
return;
|
|
@@ -27978,14 +27799,12 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
27978
27799
|
onStateChange,
|
|
27979
27800
|
cancelToken
|
|
27980
27801
|
);
|
|
27981
|
-
const maybeHandleNativeInspectorRequest = async (ctx,
|
|
27802
|
+
const maybeHandleNativeInspectorRequest = async (ctx, _rawRequest, jsRequest) => {
|
|
27982
27803
|
var _a22, _b, _c, _d;
|
|
27983
|
-
const
|
|
27984
|
-
const url2 = new URL(rawUrl);
|
|
27804
|
+
const url2 = new URL(jsRequest.url);
|
|
27985
27805
|
if (!url2.pathname.startsWith("/inspector/")) {
|
|
27986
27806
|
return void 0;
|
|
27987
27807
|
}
|
|
27988
|
-
const jsRequest = buildNativeHttpRequest(rawRequest);
|
|
27989
27808
|
const jsonResponse = (body, init) => new Response(JSON.stringify(body), {
|
|
27990
27809
|
status: (init == null ? void 0 : init.status) ?? 200,
|
|
27991
27810
|
headers: {
|
|
@@ -28516,7 +28335,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28516
28335
|
);
|
|
28517
28336
|
const actorCtx = makeActorCtx(
|
|
28518
28337
|
ctx,
|
|
28519
|
-
request ?
|
|
28338
|
+
request ? buildRequest(request) : void 0
|
|
28520
28339
|
);
|
|
28521
28340
|
try {
|
|
28522
28341
|
await config3.onBeforeConnect(
|
|
@@ -28536,7 +28355,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28536
28355
|
const { ctx, conn, params, request } = unwrapTsfnPayload(error46, payload);
|
|
28537
28356
|
const actorCtx = makeActorCtx(
|
|
28538
28357
|
ctx,
|
|
28539
|
-
request ?
|
|
28358
|
+
request ? buildRequest(request) : void 0
|
|
28540
28359
|
);
|
|
28541
28360
|
const connAdapter = new NativeConnAdapter(
|
|
28542
28361
|
runtime,
|
|
@@ -28573,7 +28392,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28573
28392
|
);
|
|
28574
28393
|
const actorCtx = makeActorCtx(
|
|
28575
28394
|
ctx,
|
|
28576
|
-
request ?
|
|
28395
|
+
request ? buildRequest(request) : void 0
|
|
28577
28396
|
);
|
|
28578
28397
|
const connAdapter = new NativeConnAdapter(
|
|
28579
28398
|
runtime,
|
|
@@ -28678,45 +28497,27 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28678
28497
|
onRequest: wrapNativeCallback(
|
|
28679
28498
|
async (error46, payload) => {
|
|
28680
28499
|
try {
|
|
28681
|
-
const { ctx, request, cancelToken
|
|
28682
|
-
|
|
28500
|
+
const { ctx, request, cancelToken } = unwrapTsfnPayload(
|
|
28501
|
+
error46,
|
|
28502
|
+
payload
|
|
28503
|
+
);
|
|
28504
|
+
const jsRequest = buildRequest(request);
|
|
28505
|
+
const inspectorResponse = await maybeHandleNativeInspectorRequest(
|
|
28506
|
+
ctx,
|
|
28507
|
+
request,
|
|
28508
|
+
jsRequest
|
|
28509
|
+
);
|
|
28683
28510
|
if (inspectorResponse) {
|
|
28684
|
-
await
|
|
28685
|
-
return (await convertNativeHttpResponse(
|
|
28686
|
-
inspectorResponse,
|
|
28687
|
-
responseBodyStream
|
|
28688
|
-
)).response;
|
|
28511
|
+
return await toRuntimeHttpResponse(inspectorResponse);
|
|
28689
28512
|
}
|
|
28690
28513
|
if (typeof config3.onRequest !== "function") {
|
|
28691
|
-
await
|
|
28692
|
-
|
|
28693
|
-
|
|
28694
|
-
responseBodyStream
|
|
28695
|
-
)).response;
|
|
28514
|
+
return await toRuntimeHttpResponse(
|
|
28515
|
+
new Response(null, { status: 404 })
|
|
28516
|
+
);
|
|
28696
28517
|
}
|
|
28697
|
-
const
|
|
28698
|
-
const handlerRequest = buildNativeHttpRequest({
|
|
28699
|
-
...request,
|
|
28700
|
-
abortController: requestAbortController
|
|
28701
|
-
});
|
|
28702
|
-
const rawConnParams = handlerRequest.headers.get(HEADER_CONN_PARAMS);
|
|
28518
|
+
const rawConnParams = jsRequest.headers.get(HEADER_CONN_PARAMS);
|
|
28703
28519
|
let requestCtx;
|
|
28704
28520
|
let conn;
|
|
28705
|
-
let removeRequestAbortListener;
|
|
28706
|
-
let cleanupDeferredToBody = false;
|
|
28707
|
-
let cleanedUp = false;
|
|
28708
|
-
const cleanupRequest = async () => {
|
|
28709
|
-
if (cleanedUp) return;
|
|
28710
|
-
cleanedUp = true;
|
|
28711
|
-
removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
|
|
28712
|
-
try {
|
|
28713
|
-
await (requestCtx == null ? void 0 : requestCtx.dispose());
|
|
28714
|
-
} finally {
|
|
28715
|
-
if (conn) {
|
|
28716
|
-
await runtime.connDisconnect(conn);
|
|
28717
|
-
}
|
|
28718
|
-
}
|
|
28719
|
-
};
|
|
28720
28521
|
try {
|
|
28721
28522
|
const connParams = validateConnParams(
|
|
28722
28523
|
schemaConfig.connParamsSchema,
|
|
@@ -28732,56 +28533,23 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28732
28533
|
requestCtx = makeConnCtx(
|
|
28733
28534
|
ctx,
|
|
28734
28535
|
conn,
|
|
28735
|
-
|
|
28536
|
+
jsRequest,
|
|
28736
28537
|
cancelToken
|
|
28737
28538
|
);
|
|
28738
|
-
const ctxAbortSignal = requestCtx.abortSignal;
|
|
28739
|
-
const abortRequest = () => requestAbortController.abort(ctxAbortSignal.reason);
|
|
28740
|
-
if (ctxAbortSignal.aborted) {
|
|
28741
|
-
abortRequest();
|
|
28742
|
-
} else {
|
|
28743
|
-
ctxAbortSignal.addEventListener(
|
|
28744
|
-
"abort",
|
|
28745
|
-
abortRequest,
|
|
28746
|
-
{ once: true }
|
|
28747
|
-
);
|
|
28748
|
-
removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
|
|
28749
|
-
"abort",
|
|
28750
|
-
abortRequest
|
|
28751
|
-
);
|
|
28752
|
-
}
|
|
28753
28539
|
const response = await config3.onRequest(
|
|
28754
28540
|
requestCtx,
|
|
28755
|
-
|
|
28541
|
+
jsRequest
|
|
28756
28542
|
);
|
|
28757
|
-
if (!
|
|
28543
|
+
if (!(response instanceof Response)) {
|
|
28758
28544
|
throw new Error(
|
|
28759
28545
|
"onRequest handler must return a Response"
|
|
28760
28546
|
);
|
|
28761
28547
|
}
|
|
28762
|
-
|
|
28763
|
-
response,
|
|
28764
|
-
responseBodyStream
|
|
28765
|
-
);
|
|
28766
|
-
if (conversion.bodyCompletion) {
|
|
28767
|
-
cleanupDeferredToBody = true;
|
|
28768
|
-
void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
|
|
28769
|
-
logger22().error({
|
|
28770
|
-
msg: "failed to clean up native streaming http request",
|
|
28771
|
-
error: cleanupError
|
|
28772
|
-
});
|
|
28773
|
-
});
|
|
28774
|
-
}
|
|
28775
|
-
return conversion.response;
|
|
28548
|
+
return await toRuntimeHttpResponse(response);
|
|
28776
28549
|
} finally {
|
|
28777
|
-
|
|
28778
|
-
|
|
28779
|
-
|
|
28780
|
-
);
|
|
28781
|
-
} finally {
|
|
28782
|
-
if (!cleanupDeferredToBody) {
|
|
28783
|
-
await cleanupRequest();
|
|
28784
|
-
}
|
|
28550
|
+
await (requestCtx == null ? void 0 : requestCtx.dispose());
|
|
28551
|
+
if (conn) {
|
|
28552
|
+
await runtime.connDisconnect(conn);
|
|
28785
28553
|
}
|
|
28786
28554
|
}
|
|
28787
28555
|
} catch (error210) {
|
|
@@ -28796,7 +28564,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28796
28564
|
onWebSocket: typeof config3.onWebSocket === "function" ? wrapNativeCallback(
|
|
28797
28565
|
async (error46, payload) => {
|
|
28798
28566
|
const { ctx, conn, ws, request } = unwrapTsfnPayload(error46, payload);
|
|
28799
|
-
const jsRequest = request ?
|
|
28567
|
+
const jsRequest = request ? buildRequest(request) : void 0;
|
|
28800
28568
|
const actorCtx = makeConnCtx(ctx, conn, jsRequest);
|
|
28801
28569
|
try {
|
|
28802
28570
|
await config3.onWebSocket(
|
|
@@ -28893,7 +28661,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28893
28661
|
timeoutMs,
|
|
28894
28662
|
cancelToken
|
|
28895
28663
|
} = unwrapTsfnPayload(error46, payload);
|
|
28896
|
-
const jsRequest =
|
|
28664
|
+
const jsRequest = buildRequest(request);
|
|
28897
28665
|
const actorCtx = withConnContext(
|
|
28898
28666
|
runtime,
|
|
28899
28667
|
ctx,
|
|
@@ -29042,54 +28810,6 @@ function finishShutdownSignal(signal) {
|
|
|
29042
28810
|
}
|
|
29043
28811
|
process.kill(process.pid, signal);
|
|
29044
28812
|
}
|
|
29045
|
-
function createApplicationFetch(application, runtime) {
|
|
29046
|
-
return async (request, responseBodyStream) => {
|
|
29047
|
-
const method2 = request.method.toUpperCase();
|
|
29048
|
-
const body = method2 === "GET" || method2 === "HEAD" || request.body.length === 0 ? void 0 : Uint8Array.from(request.body).buffer;
|
|
29049
|
-
const abortController = new AbortController();
|
|
29050
|
-
if (request.cancelToken) {
|
|
29051
|
-
if (runtime.cancellationTokenAborted(request.cancelToken)) {
|
|
29052
|
-
abortController.abort();
|
|
29053
|
-
} else {
|
|
29054
|
-
runtime.onCancellationTokenCancelled(
|
|
29055
|
-
request.cancelToken,
|
|
29056
|
-
() => abortController.abort()
|
|
29057
|
-
);
|
|
29058
|
-
}
|
|
29059
|
-
}
|
|
29060
|
-
const response = await application.fetch(
|
|
29061
|
-
new Request(request.url, {
|
|
29062
|
-
method: method2,
|
|
29063
|
-
headers: request.headers,
|
|
29064
|
-
body,
|
|
29065
|
-
signal: abortController.signal
|
|
29066
|
-
})
|
|
29067
|
-
);
|
|
29068
|
-
if (!isResponseLike(response)) {
|
|
29069
|
-
throw new TypeError(
|
|
29070
|
-
"registry.listen() application fetch must return a Response"
|
|
29071
|
-
);
|
|
29072
|
-
}
|
|
29073
|
-
const conversion = await convertNativeHttpResponse(
|
|
29074
|
-
response,
|
|
29075
|
-
responseBodyStream
|
|
29076
|
-
);
|
|
29077
|
-
if (conversion.bodyCompletion) {
|
|
29078
|
-
void conversion.bodyCompletion.catch((error46) => {
|
|
29079
|
-
logger22().error({
|
|
29080
|
-
msg: "application response stream failed",
|
|
29081
|
-
error: error46
|
|
29082
|
-
});
|
|
29083
|
-
});
|
|
29084
|
-
}
|
|
29085
|
-
return {
|
|
29086
|
-
status: conversion.response.status ?? response.status,
|
|
29087
|
-
headers: conversion.response.headers ?? Object.fromEntries(response.headers.entries()),
|
|
29088
|
-
body: conversion.response.body,
|
|
29089
|
-
stream: conversion.response.stream
|
|
29090
|
-
};
|
|
29091
|
-
};
|
|
29092
|
-
}
|
|
29093
28813
|
var Registry = class {
|
|
29094
28814
|
#config;
|
|
29095
28815
|
#buildConfiguredRegistry;
|
|
@@ -29105,7 +28825,6 @@ var Registry = class {
|
|
|
29105
28825
|
#runtimeReadyPromise;
|
|
29106
28826
|
#runtimeServeConfiguredPromise;
|
|
29107
28827
|
#runtimeServerlessPromise;
|
|
29108
|
-
#applicationListenerPromise;
|
|
29109
28828
|
#configureServerlessPoolPromise;
|
|
29110
28829
|
#welcomePrinted = false;
|
|
29111
28830
|
#shutdownInstalled = false;
|
|
@@ -29331,67 +29050,18 @@ var Registry = class {
|
|
|
29331
29050
|
* @param opts.host Address to bind. Defaults to `0.0.0.0`.
|
|
29332
29051
|
* @param opts.publicDir If set, serves static files from this directory
|
|
29333
29052
|
* as a fallback below the framework routes.
|
|
29334
|
-
* @param opts.application If set, handles requests that do not match a
|
|
29335
|
-
* framework route.
|
|
29336
29053
|
*
|
|
29337
29054
|
* @example
|
|
29338
29055
|
* ```ts
|
|
29339
29056
|
* await registry.listen();
|
|
29340
|
-
* await registry.listen({
|
|
29057
|
+
* await registry.listen({ port: 8080, publicDir: "./public" });
|
|
29341
29058
|
* ```
|
|
29342
29059
|
*/
|
|
29343
29060
|
async listen(opts = {}) {
|
|
29344
29061
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
|
|
29345
29062
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
29346
29063
|
const config3 = this.parseConfig();
|
|
29347
|
-
|
|
29348
|
-
if (config3.runtime === "wasm") {
|
|
29349
|
-
throw new Error(
|
|
29350
|
-
"registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
|
|
29351
|
-
);
|
|
29352
|
-
}
|
|
29353
|
-
this.#installSignalHandlers(config3);
|
|
29354
|
-
this.#printWelcome(config3, "serverful", {
|
|
29355
|
-
port,
|
|
29356
|
-
host: opts.host,
|
|
29357
|
-
publicDir
|
|
29358
|
-
});
|
|
29359
|
-
this.#startEnvoy(config3, true);
|
|
29360
|
-
const readyPromise = this.startAndWait();
|
|
29361
|
-
const configuredRegistryPromise2 = this.#runtimeServeConfiguredPromise;
|
|
29362
|
-
if (!configuredRegistryPromise2) {
|
|
29363
|
-
throw new Error("registry envoy startup did not initialize");
|
|
29364
|
-
}
|
|
29365
|
-
const { runtime: runtime2, registry: registry22, serveConfig: serveConfig2 } = await configuredRegistryPromise2;
|
|
29366
|
-
const application2 = createApplicationFetch(
|
|
29367
|
-
opts.application,
|
|
29368
|
-
runtime2
|
|
29369
|
-
);
|
|
29370
|
-
await readyPromise;
|
|
29371
|
-
const listenerPromise = runtime2.serveApplicationListener(
|
|
29372
|
-
registry22,
|
|
29373
|
-
{
|
|
29374
|
-
port,
|
|
29375
|
-
host: opts.host,
|
|
29376
|
-
publicDir,
|
|
29377
|
-
application: application2
|
|
29378
|
-
},
|
|
29379
|
-
serveConfig2
|
|
29380
|
-
);
|
|
29381
|
-
this.#applicationListenerPromise = listenerPromise;
|
|
29382
|
-
const serveLifecyclePromise = this.#runtimeServeLifecyclePromise;
|
|
29383
|
-
if (!serveLifecyclePromise) {
|
|
29384
|
-
throw new Error(
|
|
29385
|
-
"registry envoy serve lifecycle did not initialize"
|
|
29386
|
-
);
|
|
29387
|
-
}
|
|
29388
|
-
await Promise.all([
|
|
29389
|
-
listenerPromise,
|
|
29390
|
-
serveLifecyclePromise
|
|
29391
|
-
]);
|
|
29392
|
-
return;
|
|
29393
|
-
}
|
|
29394
|
-
const configuredRegistryPromise = this.#buildConfiguredRegistry(config3);
|
|
29064
|
+
const configuredRegistryPromise = buildConfiguredRegistry(config3);
|
|
29395
29065
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
29396
29066
|
this.#runtimeServerlessPromise = configuredRegistryPromise;
|
|
29397
29067
|
this.#installSignalHandlers(config3);
|
|
@@ -29402,15 +29072,9 @@ var Registry = class {
|
|
|
29402
29072
|
});
|
|
29403
29073
|
this.#ensureServerlessPoolConfigured(config3);
|
|
29404
29074
|
const { runtime, registry: registry2, serveConfig } = await configuredRegistryPromise;
|
|
29405
|
-
const application = opts.application ? createApplicationFetch(opts.application, runtime) : void 0;
|
|
29406
29075
|
await runtime.serveListener(
|
|
29407
29076
|
registry2,
|
|
29408
|
-
{
|
|
29409
|
-
port,
|
|
29410
|
-
host: opts.host,
|
|
29411
|
-
publicDir,
|
|
29412
|
-
application
|
|
29413
|
-
},
|
|
29077
|
+
{ port, host: opts.host, publicDir },
|
|
29414
29078
|
serveConfig
|
|
29415
29079
|
);
|
|
29416
29080
|
}
|
|
@@ -29510,9 +29174,11 @@ var Registry = class {
|
|
|
29510
29174
|
await runtime.serveRegistry(registry2, serveConfig);
|
|
29511
29175
|
}
|
|
29512
29176
|
);
|
|
29513
|
-
this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch(
|
|
29514
|
-
|
|
29515
|
-
|
|
29177
|
+
this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch(
|
|
29178
|
+
(error46) => {
|
|
29179
|
+
logger22().warn({ error: error46 }, "runtime registry serve errored");
|
|
29180
|
+
}
|
|
29181
|
+
);
|
|
29516
29182
|
this.#installSignalHandlers(config3);
|
|
29517
29183
|
}
|
|
29518
29184
|
if (printWelcome) {
|
|
@@ -29619,9 +29285,6 @@ var Registry = class {
|
|
|
29619
29285
|
if (runtimeServePromise !== void 0) {
|
|
29620
29286
|
await runtimeServePromise.catch(() => void 0);
|
|
29621
29287
|
}
|
|
29622
|
-
if (this.#applicationListenerPromise !== void 0) {
|
|
29623
|
-
await this.#applicationListenerPromise.catch(() => void 0);
|
|
29624
|
-
}
|
|
29625
29288
|
};
|
|
29626
29289
|
await Promise.race([
|
|
29627
29290
|
drain(),
|
|
@@ -29672,9 +29335,7 @@ var Registry = class {
|
|
|
29672
29335
|
startAndWait() {
|
|
29673
29336
|
if (this.#shutdownInFlight !== null) {
|
|
29674
29337
|
return Promise.reject(
|
|
29675
|
-
new Error(
|
|
29676
|
-
"registry.startAndWait() cannot run after shutdown has begun"
|
|
29677
|
-
)
|
|
29338
|
+
new Error("registry.startAndWait() cannot run after shutdown has begun")
|
|
29678
29339
|
);
|
|
29679
29340
|
}
|
|
29680
29341
|
if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
|
|
@@ -29715,9 +29376,7 @@ var Registry = class {
|
|
|
29715
29376
|
const readinessPromise = (async () => {
|
|
29716
29377
|
const { runtime, registry: registry2 } = await configuredRegistryPromise;
|
|
29717
29378
|
const stoppedBeforeReady = serveLifecyclePromise.then(() => {
|
|
29718
|
-
throw new Error(
|
|
29719
|
-
"RivetKit registry stopped before becoming ready"
|
|
29720
|
-
);
|
|
29379
|
+
throw new Error("RivetKit registry stopped before becoming ready");
|
|
29721
29380
|
});
|
|
29722
29381
|
await Promise.race([
|
|
29723
29382
|
runtime.waitRegistryReady(registry2),
|