@rivetkit/supabase 2.3.9 → 2.3.11-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.js +93 -305
- package/dist/mod.mjs +93 -305
- 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-ET2F6BXK.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-ET2F6BXK.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.11-rc.1",
|
|
13316
13316
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13317
13317
|
license: "Apache-2.0",
|
|
13318
13318
|
keywords: [
|
|
@@ -14605,7 +14605,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
14605
14605
|
};
|
|
14606
14606
|
}
|
|
14607
14607
|
|
|
14608
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14608
|
+
// ../rivetkit/dist/tsup/chunk-6ZPMYIZ6.js
|
|
14609
14609
|
var config2 = /* @__PURE__ */ Config({});
|
|
14610
14610
|
function readWorkflowCbor(bc) {
|
|
14611
14611
|
return readData(bc);
|
|
@@ -15478,7 +15478,7 @@ var AsyncMutex = class {
|
|
|
15478
15478
|
}
|
|
15479
15479
|
};
|
|
15480
15480
|
|
|
15481
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15481
|
+
// ../rivetkit/dist/tsup/chunk-5FVMFSBH.js
|
|
15482
15482
|
function logger() {
|
|
15483
15483
|
return getLogger("actor-client");
|
|
15484
15484
|
}
|
|
@@ -15516,7 +15516,7 @@ async function importWebSocket() {
|
|
|
15516
15516
|
return webSocketPromise;
|
|
15517
15517
|
}
|
|
15518
15518
|
|
|
15519
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15519
|
+
// ../rivetkit/dist/tsup/chunk-MMPE77KO.js
|
|
15520
15520
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15521
15521
|
|
|
15522
15522
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -15694,7 +15694,7 @@ function createVersionedDataHandler(config3) {
|
|
|
15694
15694
|
return new VersionedDataHandler(config3);
|
|
15695
15695
|
}
|
|
15696
15696
|
|
|
15697
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15697
|
+
// ../rivetkit/dist/tsup/chunk-MMPE77KO.js
|
|
15698
15698
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
15699
15699
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
15700
15700
|
var PATH_CONNECT = "/connect";
|
|
@@ -15703,7 +15703,6 @@ var PATH_WEBSOCKET_PREFIX = "/websocket/";
|
|
|
15703
15703
|
var HEADER_ACTOR_QUERY = "x-rivet-query";
|
|
15704
15704
|
var HEADER_ENCODING = "x-rivet-encoding";
|
|
15705
15705
|
var HEADER_CONN_PARAMS = "x-rivet-conn-params";
|
|
15706
|
-
var HEADER_ORIGINAL_REQUEST_URL = "x-rivet-internal-original-request-url";
|
|
15707
15706
|
var HEADER_ACTOR_ID = "x-rivet-actor";
|
|
15708
15707
|
var HEADER_ACTOR_GENERATION = "x-rivet-actor-generation";
|
|
15709
15708
|
var HEADER_ACTOR_KEY = "x-rivet-actor-key";
|
|
@@ -17756,18 +17755,6 @@ async function checkForSchedulingError(group, code, actorId, query, driver) {
|
|
|
17756
17755
|
}
|
|
17757
17756
|
return null;
|
|
17758
17757
|
}
|
|
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
17758
|
function* walkErrorChain(error46, maxDepth = 8) {
|
|
17772
17759
|
let current = error46;
|
|
17773
17760
|
let depth = 0;
|
|
@@ -18191,19 +18178,28 @@ function createQueueSender(senderOptions) {
|
|
|
18191
18178
|
send
|
|
18192
18179
|
};
|
|
18193
18180
|
}
|
|
18181
|
+
function isUrlLike(value) {
|
|
18182
|
+
return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
|
|
18183
|
+
}
|
|
18184
|
+
function isRequestLike(value) {
|
|
18185
|
+
return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
|
|
18186
|
+
}
|
|
18187
|
+
function isResponseLike(value) {
|
|
18188
|
+
return typeof value === "object" && value !== null && typeof value.status === "number" && isHeadersLike(value.headers) && typeof value.arrayBuffer === "function";
|
|
18189
|
+
}
|
|
18190
|
+
function isHeadersLike(value) {
|
|
18191
|
+
return typeof value === "object" && value !== null && typeof value.entries === "function";
|
|
18192
|
+
}
|
|
18194
18193
|
async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
18195
18194
|
let path2;
|
|
18196
|
-
let originalUrl;
|
|
18197
18195
|
let mergedInit = init || {};
|
|
18198
18196
|
if (typeof input === "string") {
|
|
18199
18197
|
path2 = input;
|
|
18200
18198
|
} else if (isUrlLike(input)) {
|
|
18201
18199
|
path2 = input.pathname + input.search;
|
|
18202
|
-
originalUrl = input.toString();
|
|
18203
18200
|
} else if (isRequestLike(input)) {
|
|
18204
18201
|
const url2 = new URL(input.url);
|
|
18205
18202
|
path2 = url2.pathname + url2.search;
|
|
18206
|
-
originalUrl = url2.toString();
|
|
18207
18203
|
const requestHeaders = new Headers(input.headers);
|
|
18208
18204
|
const initHeaders = new Headers((init == null ? void 0 : init.headers) || {});
|
|
18209
18205
|
const mergedHeaders = new Headers(requestHeaders);
|
|
@@ -18245,10 +18241,6 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
|
|
|
18245
18241
|
const normalizedPath = path2.startsWith("/") ? path2.slice(1) : path2;
|
|
18246
18242
|
const url2 = new URL(`http://actor/request/${normalizedPath}`);
|
|
18247
18243
|
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
18244
|
if (params) {
|
|
18253
18245
|
proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
18254
18246
|
}
|
|
@@ -18717,7 +18709,6 @@ var ActorHandleRaw = class {
|
|
|
18717
18709
|
async #fetchWithResolvedActor(input, init) {
|
|
18718
18710
|
const maxAttempts = this.#getDynamicQueryMaxAttempts();
|
|
18719
18711
|
let useQueryTarget = false;
|
|
18720
|
-
const retryableRequest = isRequestLike(input) ? input.clone() : void 0;
|
|
18721
18712
|
const { skipReadyWait, ...requestInit } = init ?? {};
|
|
18722
18713
|
const gatewayOptions = resolveActorGatewayOptions(
|
|
18723
18714
|
this.#gatewayOptions,
|
|
@@ -18737,7 +18728,7 @@ var ActorHandleRaw = class {
|
|
|
18737
18728
|
this.#driver,
|
|
18738
18729
|
target,
|
|
18739
18730
|
this.#params,
|
|
18740
|
-
|
|
18731
|
+
input,
|
|
18741
18732
|
requestInit,
|
|
18742
18733
|
gatewayOptions
|
|
18743
18734
|
);
|
|
@@ -20470,19 +20461,23 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, opt
|
|
|
20470
20461
|
if (actorRequest.bodyUsed) {
|
|
20471
20462
|
throw new Error("Request body has already been consumed");
|
|
20472
20463
|
}
|
|
20473
|
-
|
|
20474
|
-
|
|
20464
|
+
const reqBody = await actorRequest.arrayBuffer();
|
|
20465
|
+
if (reqBody.byteLength !== 0) {
|
|
20466
|
+
bodyToSend = reqBody;
|
|
20475
20467
|
guardHeaders.delete("transfer-encoding");
|
|
20476
20468
|
guardHeaders.delete("content-length");
|
|
20477
20469
|
}
|
|
20478
20470
|
}
|
|
20479
|
-
|
|
20471
|
+
const guardRequest = new Request(gatewayUrl, {
|
|
20480
20472
|
method: actorRequest.method,
|
|
20481
20473
|
headers: guardHeaders,
|
|
20482
20474
|
body: bodyToSend,
|
|
20483
|
-
signal: actorRequest.signal
|
|
20484
|
-
...bodyToSend ? { duplex: "half" } : {}
|
|
20475
|
+
signal: actorRequest.signal
|
|
20485
20476
|
});
|
|
20477
|
+
return mutableResponse(await fetch(guardRequest));
|
|
20478
|
+
}
|
|
20479
|
+
function mutableResponse(fetchRes) {
|
|
20480
|
+
return new Response(fetchRes.body, fetchRes);
|
|
20486
20481
|
}
|
|
20487
20482
|
function buildGuardHeaders(runConfig, actorRequest, options) {
|
|
20488
20483
|
const headers = new Headers();
|
|
@@ -23962,30 +23957,16 @@ function toNapiApplication(application) {
|
|
|
23962
23957
|
if (!request) {
|
|
23963
23958
|
throw new Error("application fetch callback received no request");
|
|
23964
23959
|
}
|
|
23965
|
-
const response = await application(
|
|
23966
|
-
|
|
23967
|
-
|
|
23968
|
-
|
|
23969
|
-
cancelToken: request.cancelToken
|
|
23970
|
-
},
|
|
23971
|
-
request.responseBodyStream ? fromNapiHttpResponseBodyStream(
|
|
23972
|
-
request.responseBodyStream
|
|
23973
|
-
) : void 0
|
|
23974
|
-
);
|
|
23960
|
+
const response = await application({
|
|
23961
|
+
...request,
|
|
23962
|
+
body: new Uint8Array(request.body)
|
|
23963
|
+
});
|
|
23975
23964
|
return {
|
|
23976
23965
|
...response,
|
|
23977
|
-
body:
|
|
23966
|
+
body: toNapiBuffer(response.body)
|
|
23978
23967
|
};
|
|
23979
23968
|
};
|
|
23980
23969
|
}
|
|
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
23970
|
function toNapiHttpRequest(request) {
|
|
23990
23971
|
if (!request) {
|
|
23991
23972
|
return request;
|
|
@@ -24497,135 +24478,6 @@ async function loadNapiRuntime() {
|
|
|
24497
24478
|
runtime: new NapiCoreRuntime(bindings)
|
|
24498
24479
|
};
|
|
24499
24480
|
}
|
|
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
24481
|
var CONN_PARAMS_KEY = "__conn_params__";
|
|
24630
24482
|
function validateActionArgs(schemas, name, args) {
|
|
24631
24483
|
if (!(schemas == null ? void 0 : schemas[name])) {
|
|
@@ -25752,7 +25604,7 @@ function toRuntimeBytes(value) {
|
|
|
25752
25604
|
function arrayBufferViewToRuntimeBytes(value) {
|
|
25753
25605
|
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
25754
25606
|
}
|
|
25755
|
-
function
|
|
25607
|
+
function runtimeBytesToArrayBuffer(value) {
|
|
25756
25608
|
return value.buffer.slice(
|
|
25757
25609
|
value.byteOffset,
|
|
25758
25610
|
value.byteOffset + value.byteLength
|
|
@@ -26082,6 +25934,24 @@ function decodeArgs(value) {
|
|
|
26082
25934
|
const decoded = decodeValue(value);
|
|
26083
25935
|
return normalizeArgs(decoded);
|
|
26084
25936
|
}
|
|
25937
|
+
function buildRequest(init) {
|
|
25938
|
+
const url2 = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
|
|
25939
|
+
const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
|
|
25940
|
+
return new Request(url2, {
|
|
25941
|
+
method: init.method,
|
|
25942
|
+
headers: init.headers,
|
|
25943
|
+
body
|
|
25944
|
+
});
|
|
25945
|
+
}
|
|
25946
|
+
async function toRuntimeHttpResponse(response) {
|
|
25947
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
25948
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
25949
|
+
return {
|
|
25950
|
+
status: response.status,
|
|
25951
|
+
headers,
|
|
25952
|
+
body
|
|
25953
|
+
};
|
|
25954
|
+
}
|
|
26085
25955
|
function toActorKey(segments) {
|
|
26086
25956
|
return segments.map(
|
|
26087
25957
|
(segment) => segment.kind === "number" ? String(segment.numberValue ?? 0) : segment.stringValue ?? ""
|
|
@@ -26746,7 +26616,7 @@ var NativeWebSocketAdapter = class {
|
|
|
26746
26616
|
this.#runtime.webSocketSetEventCallback(this.#ws, (event2) => {
|
|
26747
26617
|
if (event2.kind === "message") {
|
|
26748
26618
|
this.#virtual.triggerMessage(
|
|
26749
|
-
event2.binary ?
|
|
26619
|
+
event2.binary ? runtimeBytesToArrayBuffer(event2.data) : event2.data,
|
|
26750
26620
|
event2.messageIndex
|
|
26751
26621
|
);
|
|
26752
26622
|
return;
|
|
@@ -27978,14 +27848,12 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
27978
27848
|
onStateChange,
|
|
27979
27849
|
cancelToken
|
|
27980
27850
|
);
|
|
27981
|
-
const maybeHandleNativeInspectorRequest = async (ctx,
|
|
27851
|
+
const maybeHandleNativeInspectorRequest = async (ctx, _rawRequest, jsRequest) => {
|
|
27982
27852
|
var _a22, _b, _c, _d;
|
|
27983
|
-
const
|
|
27984
|
-
const url2 = new URL(rawUrl);
|
|
27853
|
+
const url2 = new URL(jsRequest.url);
|
|
27985
27854
|
if (!url2.pathname.startsWith("/inspector/")) {
|
|
27986
27855
|
return void 0;
|
|
27987
27856
|
}
|
|
27988
|
-
const jsRequest = buildNativeHttpRequest(rawRequest);
|
|
27989
27857
|
const jsonResponse = (body, init) => new Response(JSON.stringify(body), {
|
|
27990
27858
|
status: (init == null ? void 0 : init.status) ?? 200,
|
|
27991
27859
|
headers: {
|
|
@@ -28516,7 +28384,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28516
28384
|
);
|
|
28517
28385
|
const actorCtx = makeActorCtx(
|
|
28518
28386
|
ctx,
|
|
28519
|
-
request ?
|
|
28387
|
+
request ? buildRequest(request) : void 0
|
|
28520
28388
|
);
|
|
28521
28389
|
try {
|
|
28522
28390
|
await config3.onBeforeConnect(
|
|
@@ -28536,7 +28404,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28536
28404
|
const { ctx, conn, params, request } = unwrapTsfnPayload(error46, payload);
|
|
28537
28405
|
const actorCtx = makeActorCtx(
|
|
28538
28406
|
ctx,
|
|
28539
|
-
request ?
|
|
28407
|
+
request ? buildRequest(request) : void 0
|
|
28540
28408
|
);
|
|
28541
28409
|
const connAdapter = new NativeConnAdapter(
|
|
28542
28410
|
runtime,
|
|
@@ -28573,7 +28441,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28573
28441
|
);
|
|
28574
28442
|
const actorCtx = makeActorCtx(
|
|
28575
28443
|
ctx,
|
|
28576
|
-
request ?
|
|
28444
|
+
request ? buildRequest(request) : void 0
|
|
28577
28445
|
);
|
|
28578
28446
|
const connAdapter = new NativeConnAdapter(
|
|
28579
28447
|
runtime,
|
|
@@ -28678,45 +28546,27 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28678
28546
|
onRequest: wrapNativeCallback(
|
|
28679
28547
|
async (error46, payload) => {
|
|
28680
28548
|
try {
|
|
28681
|
-
const { ctx, request, cancelToken
|
|
28682
|
-
|
|
28549
|
+
const { ctx, request, cancelToken } = unwrapTsfnPayload(
|
|
28550
|
+
error46,
|
|
28551
|
+
payload
|
|
28552
|
+
);
|
|
28553
|
+
const jsRequest = buildRequest(request);
|
|
28554
|
+
const inspectorResponse = await maybeHandleNativeInspectorRequest(
|
|
28555
|
+
ctx,
|
|
28556
|
+
request,
|
|
28557
|
+
jsRequest
|
|
28558
|
+
);
|
|
28683
28559
|
if (inspectorResponse) {
|
|
28684
|
-
await
|
|
28685
|
-
return (await convertNativeHttpResponse(
|
|
28686
|
-
inspectorResponse,
|
|
28687
|
-
responseBodyStream
|
|
28688
|
-
)).response;
|
|
28560
|
+
return await toRuntimeHttpResponse(inspectorResponse);
|
|
28689
28561
|
}
|
|
28690
28562
|
if (typeof config3.onRequest !== "function") {
|
|
28691
|
-
await
|
|
28692
|
-
|
|
28693
|
-
|
|
28694
|
-
responseBodyStream
|
|
28695
|
-
)).response;
|
|
28563
|
+
return await toRuntimeHttpResponse(
|
|
28564
|
+
new Response(null, { status: 404 })
|
|
28565
|
+
);
|
|
28696
28566
|
}
|
|
28697
|
-
const
|
|
28698
|
-
const handlerRequest = buildNativeHttpRequest({
|
|
28699
|
-
...request,
|
|
28700
|
-
abortController: requestAbortController
|
|
28701
|
-
});
|
|
28702
|
-
const rawConnParams = handlerRequest.headers.get(HEADER_CONN_PARAMS);
|
|
28567
|
+
const rawConnParams = jsRequest.headers.get(HEADER_CONN_PARAMS);
|
|
28703
28568
|
let requestCtx;
|
|
28704
28569
|
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
28570
|
try {
|
|
28721
28571
|
const connParams = validateConnParams(
|
|
28722
28572
|
schemaConfig.connParamsSchema,
|
|
@@ -28732,56 +28582,23 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28732
28582
|
requestCtx = makeConnCtx(
|
|
28733
28583
|
ctx,
|
|
28734
28584
|
conn,
|
|
28735
|
-
|
|
28585
|
+
jsRequest,
|
|
28736
28586
|
cancelToken
|
|
28737
28587
|
);
|
|
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
28588
|
const response = await config3.onRequest(
|
|
28754
28589
|
requestCtx,
|
|
28755
|
-
|
|
28590
|
+
jsRequest
|
|
28756
28591
|
);
|
|
28757
28592
|
if (!isResponseLike(response)) {
|
|
28758
28593
|
throw new Error(
|
|
28759
28594
|
"onRequest handler must return a Response"
|
|
28760
28595
|
);
|
|
28761
28596
|
}
|
|
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;
|
|
28597
|
+
return await toRuntimeHttpResponse(response);
|
|
28776
28598
|
} finally {
|
|
28777
|
-
|
|
28778
|
-
|
|
28779
|
-
|
|
28780
|
-
);
|
|
28781
|
-
} finally {
|
|
28782
|
-
if (!cleanupDeferredToBody) {
|
|
28783
|
-
await cleanupRequest();
|
|
28784
|
-
}
|
|
28599
|
+
await (requestCtx == null ? void 0 : requestCtx.dispose());
|
|
28600
|
+
if (conn) {
|
|
28601
|
+
await runtime.connDisconnect(conn);
|
|
28785
28602
|
}
|
|
28786
28603
|
}
|
|
28787
28604
|
} catch (error210) {
|
|
@@ -28796,7 +28613,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28796
28613
|
onWebSocket: typeof config3.onWebSocket === "function" ? wrapNativeCallback(
|
|
28797
28614
|
async (error46, payload) => {
|
|
28798
28615
|
const { ctx, conn, ws, request } = unwrapTsfnPayload(error46, payload);
|
|
28799
|
-
const jsRequest = request ?
|
|
28616
|
+
const jsRequest = request ? buildRequest(request) : void 0;
|
|
28800
28617
|
const actorCtx = makeConnCtx(ctx, conn, jsRequest);
|
|
28801
28618
|
try {
|
|
28802
28619
|
await config3.onWebSocket(
|
|
@@ -28893,7 +28710,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
28893
28710
|
timeoutMs,
|
|
28894
28711
|
cancelToken
|
|
28895
28712
|
} = unwrapTsfnPayload(error46, payload);
|
|
28896
|
-
const jsRequest =
|
|
28713
|
+
const jsRequest = buildRequest(request);
|
|
28897
28714
|
const actorCtx = withConnContext(
|
|
28898
28715
|
runtime,
|
|
28899
28716
|
ctx,
|
|
@@ -29042,27 +28859,15 @@ function finishShutdownSignal(signal) {
|
|
|
29042
28859
|
}
|
|
29043
28860
|
process.kill(process.pid, signal);
|
|
29044
28861
|
}
|
|
29045
|
-
function createApplicationFetch(application
|
|
29046
|
-
return async (request
|
|
28862
|
+
function createApplicationFetch(application) {
|
|
28863
|
+
return async (request) => {
|
|
29047
28864
|
const method2 = request.method.toUpperCase();
|
|
29048
28865
|
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
28866
|
const response = await application.fetch(
|
|
29061
28867
|
new Request(request.url, {
|
|
29062
28868
|
method: method2,
|
|
29063
28869
|
headers: request.headers,
|
|
29064
|
-
body
|
|
29065
|
-
signal: abortController.signal
|
|
28870
|
+
body
|
|
29066
28871
|
})
|
|
29067
28872
|
);
|
|
29068
28873
|
if (!isResponseLike(response)) {
|
|
@@ -29070,23 +28875,10 @@ function createApplicationFetch(application, runtime) {
|
|
|
29070
28875
|
"registry.listen() application fetch must return a Response"
|
|
29071
28876
|
);
|
|
29072
28877
|
}
|
|
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
28878
|
return {
|
|
29086
|
-
status:
|
|
29087
|
-
headers:
|
|
29088
|
-
body:
|
|
29089
|
-
stream: conversion.response.stream
|
|
28879
|
+
status: response.status,
|
|
28880
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
28881
|
+
body: new Uint8Array(await response.arrayBuffer())
|
|
29090
28882
|
};
|
|
29091
28883
|
};
|
|
29092
28884
|
}
|
|
@@ -29344,7 +29136,8 @@ var Registry = class {
|
|
|
29344
29136
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
|
|
29345
29137
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
29346
29138
|
const config3 = this.parseConfig();
|
|
29347
|
-
|
|
29139
|
+
const application = opts.application ? createApplicationFetch(opts.application) : void 0;
|
|
29140
|
+
if (application && getRivetkitRuntimeMode() !== "serverless") {
|
|
29348
29141
|
if (config3.runtime === "wasm") {
|
|
29349
29142
|
throw new Error(
|
|
29350
29143
|
"registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
|
|
@@ -29363,18 +29156,13 @@ var Registry = class {
|
|
|
29363
29156
|
throw new Error("registry envoy startup did not initialize");
|
|
29364
29157
|
}
|
|
29365
29158
|
const { runtime: runtime2, registry: registry22, serveConfig: serveConfig2 } = await configuredRegistryPromise2;
|
|
29366
|
-
const application2 = createApplicationFetch(
|
|
29367
|
-
opts.application,
|
|
29368
|
-
runtime2
|
|
29369
|
-
);
|
|
29370
|
-
await readyPromise;
|
|
29371
29159
|
const listenerPromise = runtime2.serveApplicationListener(
|
|
29372
29160
|
registry22,
|
|
29373
29161
|
{
|
|
29374
29162
|
port,
|
|
29375
29163
|
host: opts.host,
|
|
29376
29164
|
publicDir,
|
|
29377
|
-
application
|
|
29165
|
+
application
|
|
29378
29166
|
},
|
|
29379
29167
|
serveConfig2
|
|
29380
29168
|
);
|
|
@@ -29386,12 +29174,13 @@ var Registry = class {
|
|
|
29386
29174
|
);
|
|
29387
29175
|
}
|
|
29388
29176
|
await Promise.all([
|
|
29177
|
+
readyPromise,
|
|
29389
29178
|
listenerPromise,
|
|
29390
29179
|
serveLifecyclePromise
|
|
29391
29180
|
]);
|
|
29392
29181
|
return;
|
|
29393
29182
|
}
|
|
29394
|
-
const configuredRegistryPromise =
|
|
29183
|
+
const configuredRegistryPromise = buildConfiguredRegistry(config3);
|
|
29395
29184
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
29396
29185
|
this.#runtimeServerlessPromise = configuredRegistryPromise;
|
|
29397
29186
|
this.#installSignalHandlers(config3);
|
|
@@ -29402,7 +29191,6 @@ var Registry = class {
|
|
|
29402
29191
|
});
|
|
29403
29192
|
this.#ensureServerlessPoolConfigured(config3);
|
|
29404
29193
|
const { runtime, registry: registry2, serveConfig } = await configuredRegistryPromise;
|
|
29405
|
-
const application = opts.application ? createApplicationFetch(opts.application, runtime) : void 0;
|
|
29406
29194
|
await runtime.serveListener(
|
|
29407
29195
|
registry2,
|
|
29408
29196
|
{
|