@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.
Files changed (3) hide show
  1. package/dist/mod.js +93 -305
  2. package/dist/mod.mjs +93 -305
  3. package/package.json +3 -3
package/dist/mod.js CHANGED
@@ -508,7 +508,7 @@ function unsupportedFeature(feature) {
508
508
  );
509
509
  }
510
510
 
511
- // ../rivetkit/dist/tsup/chunk-UBYPRYJR.js
511
+ // ../rivetkit/dist/tsup/chunk-ET2F6BXK.js
512
512
  var import_pino = require("pino");
513
513
 
514
514
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
@@ -13181,7 +13181,7 @@ var classic_default = external_exports;
13181
13181
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
13182
13182
  var v4_default = classic_default;
13183
13183
 
13184
- // ../rivetkit/dist/tsup/chunk-UBYPRYJR.js
13184
+ // ../rivetkit/dist/tsup/chunk-ET2F6BXK.js
13185
13185
  var cbor = __toESM(require("cbor-x"), 1);
13186
13186
  var import_invariant = __toESM(require_invariant(), 1);
13187
13187
  var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
@@ -13346,7 +13346,7 @@ function noopNext() {
13346
13346
  }
13347
13347
  var package_default = {
13348
13348
  name: "rivetkit",
13349
- version: "2.3.9",
13349
+ version: "2.3.11-rc.1",
13350
13350
  description: "Lightweight libraries for building stateful actors on edge platforms",
13351
13351
  license: "Apache-2.0",
13352
13352
  keywords: [
@@ -14639,7 +14639,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
14639
14639
  };
14640
14640
  }
14641
14641
 
14642
- // ../rivetkit/dist/tsup/chunk-CQ23UFQ4.js
14642
+ // ../rivetkit/dist/tsup/chunk-6ZPMYIZ6.js
14643
14643
  var config2 = /* @__PURE__ */ Config({});
14644
14644
  function readWorkflowCbor(bc) {
14645
14645
  return readData(bc);
@@ -15512,7 +15512,7 @@ var AsyncMutex = class {
15512
15512
  }
15513
15513
  };
15514
15514
 
15515
- // ../rivetkit/dist/tsup/chunk-X25YYVFL.js
15515
+ // ../rivetkit/dist/tsup/chunk-5FVMFSBH.js
15516
15516
  function logger() {
15517
15517
  return getLogger("actor-client");
15518
15518
  }
@@ -15550,7 +15550,7 @@ async function importWebSocket() {
15550
15550
  return webSocketPromise;
15551
15551
  }
15552
15552
 
15553
- // ../rivetkit/dist/tsup/chunk-MQDQ3A72.js
15553
+ // ../rivetkit/dist/tsup/chunk-MMPE77KO.js
15554
15554
  var import_invariant2 = __toESM(require_invariant(), 1);
15555
15555
 
15556
15556
  // ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
@@ -15728,7 +15728,7 @@ function createVersionedDataHandler(config3) {
15728
15728
  return new VersionedDataHandler(config3);
15729
15729
  }
15730
15730
 
15731
- // ../rivetkit/dist/tsup/chunk-MQDQ3A72.js
15731
+ // ../rivetkit/dist/tsup/chunk-MMPE77KO.js
15732
15732
  var import_invariant3 = __toESM(require_invariant(), 1);
15733
15733
  var import_invariant4 = __toESM(require_invariant(), 1);
15734
15734
  var PATH_CONNECT = "/connect";
@@ -15737,7 +15737,6 @@ var PATH_WEBSOCKET_PREFIX = "/websocket/";
15737
15737
  var HEADER_ACTOR_QUERY = "x-rivet-query";
15738
15738
  var HEADER_ENCODING = "x-rivet-encoding";
15739
15739
  var HEADER_CONN_PARAMS = "x-rivet-conn-params";
15740
- var HEADER_ORIGINAL_REQUEST_URL = "x-rivet-internal-original-request-url";
15741
15740
  var HEADER_ACTOR_ID = "x-rivet-actor";
15742
15741
  var HEADER_ACTOR_GENERATION = "x-rivet-actor-generation";
15743
15742
  var HEADER_ACTOR_KEY = "x-rivet-actor-key";
@@ -17790,18 +17789,6 @@ async function checkForSchedulingError(group, code, actorId, query, driver) {
17790
17789
  }
17791
17790
  return null;
17792
17791
  }
17793
- function isUrlLike(value) {
17794
- return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
17795
- }
17796
- function isRequestLike(value) {
17797
- return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
17798
- }
17799
- function isResponseLike(value) {
17800
- return typeof value === "object" && value !== null && typeof value.status === "number" && isHeadersLike(value.headers) && typeof value.arrayBuffer === "function";
17801
- }
17802
- function isHeadersLike(value) {
17803
- return typeof value === "object" && value !== null && typeof value.entries === "function";
17804
- }
17805
17792
  function* walkErrorChain(error46, maxDepth = 8) {
17806
17793
  let current = error46;
17807
17794
  let depth = 0;
@@ -18225,19 +18212,28 @@ function createQueueSender(senderOptions) {
18225
18212
  send
18226
18213
  };
18227
18214
  }
18215
+ function isUrlLike(value) {
18216
+ return typeof value === "object" && value !== null && typeof value.href === "string" && typeof value.pathname === "string" && typeof value.search === "string";
18217
+ }
18218
+ function isRequestLike(value) {
18219
+ return typeof value === "object" && value !== null && typeof value.url === "string" && typeof value.method === "string" && isHeadersLike(value.headers);
18220
+ }
18221
+ function isResponseLike(value) {
18222
+ return typeof value === "object" && value !== null && typeof value.status === "number" && isHeadersLike(value.headers) && typeof value.arrayBuffer === "function";
18223
+ }
18224
+ function isHeadersLike(value) {
18225
+ return typeof value === "object" && value !== null && typeof value.entries === "function";
18226
+ }
18228
18227
  async function rawHttpFetch(driver, target, params, input, init, options = {}) {
18229
18228
  let path2;
18230
- let originalUrl;
18231
18229
  let mergedInit = init || {};
18232
18230
  if (typeof input === "string") {
18233
18231
  path2 = input;
18234
18232
  } else if (isUrlLike(input)) {
18235
18233
  path2 = input.pathname + input.search;
18236
- originalUrl = input.toString();
18237
18234
  } else if (isRequestLike(input)) {
18238
18235
  const url2 = new URL(input.url);
18239
18236
  path2 = url2.pathname + url2.search;
18240
- originalUrl = url2.toString();
18241
18237
  const requestHeaders = new Headers(input.headers);
18242
18238
  const initHeaders = new Headers((init == null ? void 0 : init.headers) || {});
18243
18239
  const mergedHeaders = new Headers(requestHeaders);
@@ -18279,10 +18275,6 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}) {
18279
18275
  const normalizedPath = path2.startsWith("/") ? path2.slice(1) : path2;
18280
18276
  const url2 = new URL(`http://actor/request/${normalizedPath}`);
18281
18277
  const proxyRequestHeaders = new Headers(mergedInit.headers);
18282
- proxyRequestHeaders.delete(HEADER_ORIGINAL_REQUEST_URL);
18283
- if (originalUrl) {
18284
- proxyRequestHeaders.set(HEADER_ORIGINAL_REQUEST_URL, originalUrl);
18285
- }
18286
18278
  if (params) {
18287
18279
  proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
18288
18280
  }
@@ -18751,7 +18743,6 @@ var ActorHandleRaw = class {
18751
18743
  async #fetchWithResolvedActor(input, init) {
18752
18744
  const maxAttempts = this.#getDynamicQueryMaxAttempts();
18753
18745
  let useQueryTarget = false;
18754
- const retryableRequest = isRequestLike(input) ? input.clone() : void 0;
18755
18746
  const { skipReadyWait, ...requestInit } = init ?? {};
18756
18747
  const gatewayOptions = resolveActorGatewayOptions(
18757
18748
  this.#gatewayOptions,
@@ -18771,7 +18762,7 @@ var ActorHandleRaw = class {
18771
18762
  this.#driver,
18772
18763
  target,
18773
18764
  this.#params,
18774
- retryableRequest ? retryableRequest.clone() : input,
18765
+ input,
18775
18766
  requestInit,
18776
18767
  gatewayOptions
18777
18768
  );
@@ -20504,19 +20495,23 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, opt
20504
20495
  if (actorRequest.bodyUsed) {
20505
20496
  throw new Error("Request body has already been consumed");
20506
20497
  }
20507
- if (actorRequest.body) {
20508
- bodyToSend = actorRequest.body;
20498
+ const reqBody = await actorRequest.arrayBuffer();
20499
+ if (reqBody.byteLength !== 0) {
20500
+ bodyToSend = reqBody;
20509
20501
  guardHeaders.delete("transfer-encoding");
20510
20502
  guardHeaders.delete("content-length");
20511
20503
  }
20512
20504
  }
20513
- return fetch(gatewayUrl, {
20505
+ const guardRequest = new Request(gatewayUrl, {
20514
20506
  method: actorRequest.method,
20515
20507
  headers: guardHeaders,
20516
20508
  body: bodyToSend,
20517
- signal: actorRequest.signal,
20518
- ...bodyToSend ? { duplex: "half" } : {}
20509
+ signal: actorRequest.signal
20519
20510
  });
20511
+ return mutableResponse(await fetch(guardRequest));
20512
+ }
20513
+ function mutableResponse(fetchRes) {
20514
+ return new Response(fetchRes.body, fetchRes);
20520
20515
  }
20521
20516
  function buildGuardHeaders(runConfig, actorRequest, options) {
20522
20517
  const headers = new Headers();
@@ -23997,30 +23992,16 @@ function toNapiApplication(application) {
23997
23992
  if (!request) {
23998
23993
  throw new Error("application fetch callback received no request");
23999
23994
  }
24000
- const response = await application(
24001
- {
24002
- ...request,
24003
- body: new Uint8Array(request.body),
24004
- cancelToken: request.cancelToken
24005
- },
24006
- request.responseBodyStream ? fromNapiHttpResponseBodyStream(
24007
- request.responseBodyStream
24008
- ) : void 0
24009
- );
23995
+ const response = await application({
23996
+ ...request,
23997
+ body: new Uint8Array(request.body)
23998
+ });
24010
23999
  return {
24011
24000
  ...response,
24012
- body: response.body === void 0 ? void 0 : toNapiBuffer(response.body)
24001
+ body: toNapiBuffer(response.body)
24013
24002
  };
24014
24003
  };
24015
24004
  }
24016
- function fromNapiHttpResponseBodyStream(stream) {
24017
- return {
24018
- cancelled: () => stream.cancelled(),
24019
- write: (chunk) => stream.write(Buffer.from(chunk)),
24020
- end: () => stream.end(),
24021
- error: (message) => stream.error(message)
24022
- };
24023
- }
24024
24005
  function toNapiHttpRequest(request) {
24025
24006
  if (!request) {
24026
24007
  return request;
@@ -24532,135 +24513,6 @@ async function loadNapiRuntime() {
24532
24513
  runtime: new NapiCoreRuntime(bindings)
24533
24514
  };
24534
24515
  }
24535
- var HTTP_BODY_CHUNK_SIZE = 64 * 1024;
24536
- function runtimeBytesToArrayBuffer(value) {
24537
- return value.buffer.slice(
24538
- value.byteOffset,
24539
- value.byteOffset + value.byteLength
24540
- );
24541
- }
24542
- function buildNativeHttpRequest(init) {
24543
- var _a2;
24544
- const headers = new Headers(init.headers);
24545
- const originalUrl = headers.get(HEADER_ORIGINAL_REQUEST_URL);
24546
- headers.delete(HEADER_ORIGINAL_REQUEST_URL);
24547
- const url2 = originalUrl ?? (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString());
24548
- const method2 = init.method.toUpperCase();
24549
- const bodyForbidden = method2 === "GET" || method2 === "HEAD";
24550
- const body = bodyForbidden ? void 0 : init.bodyStream ? new ReadableStream({
24551
- async pull(controller) {
24552
- var _a22, _b;
24553
- try {
24554
- if (init.body && init.body.length > 0) {
24555
- controller.enqueue(new Uint8Array(init.body));
24556
- init.body = void 0;
24557
- return;
24558
- }
24559
- const chunk = await ((_a22 = init.bodyStream) == null ? void 0 : _a22.read());
24560
- if (!chunk) {
24561
- controller.close();
24562
- } else {
24563
- controller.enqueue(new Uint8Array(chunk));
24564
- }
24565
- } catch (error46) {
24566
- (_b = init.abortController) == null ? void 0 : _b.abort(error46);
24567
- controller.error(error46);
24568
- }
24569
- },
24570
- async cancel() {
24571
- var _a22;
24572
- await ((_a22 = init.bodyStream) == null ? void 0 : _a22.cancel());
24573
- }
24574
- }) : init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
24575
- const streamInit = init.bodyStream && !bodyForbidden ? { duplex: "half" } : {};
24576
- return new Request(url2, {
24577
- method: method2,
24578
- headers,
24579
- body,
24580
- signal: ((_a2 = init.abortController) == null ? void 0 : _a2.signal) ?? init.signal,
24581
- ...streamInit
24582
- });
24583
- }
24584
- async function cancelNativeHttpRequestBody(bodyStream) {
24585
- await (bodyStream == null ? void 0 : bodyStream.cancel());
24586
- }
24587
- async function writeResponseChunk(stream, chunk) {
24588
- for (let offset = 0; offset < chunk.byteLength; offset += HTTP_BODY_CHUNK_SIZE) {
24589
- await stream.write(
24590
- chunk.subarray(offset, offset + HTTP_BODY_CHUNK_SIZE)
24591
- );
24592
- }
24593
- }
24594
- async function pumpResponseBody(reader, stream) {
24595
- var _a2;
24596
- const cancelled = stream.cancelled().then(() => ({ cancelled: true }));
24597
- try {
24598
- for (; ; ) {
24599
- const read = reader.read().then((next2) => ({ cancelled: false, next: next2 }));
24600
- const result = await Promise.race([read, cancelled]);
24601
- if (result.cancelled) {
24602
- await reader.cancel(
24603
- new Error("native http response stream receiver dropped")
24604
- );
24605
- return;
24606
- }
24607
- const { next } = result;
24608
- if (next.done) {
24609
- await stream.end();
24610
- return;
24611
- }
24612
- if ((_a2 = next.value) == null ? void 0 : _a2.byteLength) {
24613
- await writeResponseChunk(stream, next.value);
24614
- }
24615
- }
24616
- } catch (error46) {
24617
- try {
24618
- await stream.error(stringifyError(error46));
24619
- } catch (streamError) {
24620
- logger22().debug({
24621
- msg: "failed to report native http response stream error",
24622
- error: streamError
24623
- });
24624
- }
24625
- try {
24626
- await reader.cancel(error46);
24627
- } catch {
24628
- }
24629
- } finally {
24630
- reader.releaseLock();
24631
- }
24632
- }
24633
- async function convertNativeHttpResponse(response, responseBodyStream) {
24634
- const headers = Object.fromEntries(response.headers.entries());
24635
- if (!response.body) {
24636
- return {
24637
- response: {
24638
- status: response.status,
24639
- headers,
24640
- body: new Uint8Array()
24641
- }
24642
- };
24643
- }
24644
- if (responseBodyStream) {
24645
- const reader = response.body.getReader();
24646
- const bodyCompletion = pumpResponseBody(reader, responseBodyStream);
24647
- return {
24648
- response: {
24649
- status: response.status,
24650
- headers,
24651
- stream: true
24652
- },
24653
- bodyCompletion
24654
- };
24655
- }
24656
- return {
24657
- response: {
24658
- status: response.status,
24659
- headers,
24660
- body: new Uint8Array(await response.arrayBuffer())
24661
- }
24662
- };
24663
- }
24664
24516
  var CONN_PARAMS_KEY = "__conn_params__";
24665
24517
  function validateActionArgs(schemas, name, args) {
24666
24518
  if (!(schemas == null ? void 0 : schemas[name])) {
@@ -25787,7 +25639,7 @@ function toRuntimeBytes(value) {
25787
25639
  function arrayBufferViewToRuntimeBytes(value) {
25788
25640
  return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
25789
25641
  }
25790
- function runtimeBytesToArrayBuffer2(value) {
25642
+ function runtimeBytesToArrayBuffer(value) {
25791
25643
  return value.buffer.slice(
25792
25644
  value.byteOffset,
25793
25645
  value.byteOffset + value.byteLength
@@ -26117,6 +25969,24 @@ function decodeArgs(value) {
26117
25969
  const decoded = decodeValue(value);
26118
25970
  return normalizeArgs(decoded);
26119
25971
  }
25972
+ function buildRequest(init) {
25973
+ const url2 = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
25974
+ const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
25975
+ return new Request(url2, {
25976
+ method: init.method,
25977
+ headers: init.headers,
25978
+ body
25979
+ });
25980
+ }
25981
+ async function toRuntimeHttpResponse(response) {
25982
+ const headers = Object.fromEntries(response.headers.entries());
25983
+ const body = new Uint8Array(await response.arrayBuffer());
25984
+ return {
25985
+ status: response.status,
25986
+ headers,
25987
+ body
25988
+ };
25989
+ }
26120
25990
  function toActorKey(segments) {
26121
25991
  return segments.map(
26122
25992
  (segment) => segment.kind === "number" ? String(segment.numberValue ?? 0) : segment.stringValue ?? ""
@@ -26781,7 +26651,7 @@ var NativeWebSocketAdapter = class {
26781
26651
  this.#runtime.webSocketSetEventCallback(this.#ws, (event2) => {
26782
26652
  if (event2.kind === "message") {
26783
26653
  this.#virtual.triggerMessage(
26784
- event2.binary ? runtimeBytesToArrayBuffer2(event2.data) : event2.data,
26654
+ event2.binary ? runtimeBytesToArrayBuffer(event2.data) : event2.data,
26785
26655
  event2.messageIndex
26786
26656
  );
26787
26657
  return;
@@ -28013,14 +27883,12 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28013
27883
  onStateChange,
28014
27884
  cancelToken
28015
27885
  );
28016
- const maybeHandleNativeInspectorRequest = async (ctx, rawRequest) => {
27886
+ const maybeHandleNativeInspectorRequest = async (ctx, _rawRequest, jsRequest) => {
28017
27887
  var _a22, _b, _c, _d;
28018
- const rawUrl = rawRequest.uri.startsWith("http") ? rawRequest.uri : new URL(rawRequest.uri, "http://127.0.0.1").toString();
28019
- const url2 = new URL(rawUrl);
27888
+ const url2 = new URL(jsRequest.url);
28020
27889
  if (!url2.pathname.startsWith("/inspector/")) {
28021
27890
  return void 0;
28022
27891
  }
28023
- const jsRequest = buildNativeHttpRequest(rawRequest);
28024
27892
  const jsonResponse = (body, init) => new Response(JSON.stringify(body), {
28025
27893
  status: (init == null ? void 0 : init.status) ?? 200,
28026
27894
  headers: {
@@ -28551,7 +28419,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28551
28419
  );
28552
28420
  const actorCtx = makeActorCtx(
28553
28421
  ctx,
28554
- request ? buildNativeHttpRequest(request) : void 0
28422
+ request ? buildRequest(request) : void 0
28555
28423
  );
28556
28424
  try {
28557
28425
  await config3.onBeforeConnect(
@@ -28571,7 +28439,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28571
28439
  const { ctx, conn, params, request } = unwrapTsfnPayload(error46, payload);
28572
28440
  const actorCtx = makeActorCtx(
28573
28441
  ctx,
28574
- request ? buildNativeHttpRequest(request) : void 0
28442
+ request ? buildRequest(request) : void 0
28575
28443
  );
28576
28444
  const connAdapter = new NativeConnAdapter(
28577
28445
  runtime,
@@ -28608,7 +28476,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28608
28476
  );
28609
28477
  const actorCtx = makeActorCtx(
28610
28478
  ctx,
28611
- request ? buildNativeHttpRequest(request) : void 0
28479
+ request ? buildRequest(request) : void 0
28612
28480
  );
28613
28481
  const connAdapter = new NativeConnAdapter(
28614
28482
  runtime,
@@ -28713,45 +28581,27 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28713
28581
  onRequest: wrapNativeCallback(
28714
28582
  async (error46, payload) => {
28715
28583
  try {
28716
- const { ctx, request, cancelToken, responseBodyStream } = unwrapTsfnPayload(error46, payload);
28717
- const inspectorResponse = await maybeHandleNativeInspectorRequest(ctx, request);
28584
+ const { ctx, request, cancelToken } = unwrapTsfnPayload(
28585
+ error46,
28586
+ payload
28587
+ );
28588
+ const jsRequest = buildRequest(request);
28589
+ const inspectorResponse = await maybeHandleNativeInspectorRequest(
28590
+ ctx,
28591
+ request,
28592
+ jsRequest
28593
+ );
28718
28594
  if (inspectorResponse) {
28719
- await cancelNativeHttpRequestBody(request.bodyStream);
28720
- return (await convertNativeHttpResponse(
28721
- inspectorResponse,
28722
- responseBodyStream
28723
- )).response;
28595
+ return await toRuntimeHttpResponse(inspectorResponse);
28724
28596
  }
28725
28597
  if (typeof config3.onRequest !== "function") {
28726
- await cancelNativeHttpRequestBody(request.bodyStream);
28727
- return (await convertNativeHttpResponse(
28728
- new Response(null, { status: 404 }),
28729
- responseBodyStream
28730
- )).response;
28598
+ return await toRuntimeHttpResponse(
28599
+ new Response(null, { status: 404 })
28600
+ );
28731
28601
  }
28732
- const requestAbortController = new AbortController();
28733
- const handlerRequest = buildNativeHttpRequest({
28734
- ...request,
28735
- abortController: requestAbortController
28736
- });
28737
- const rawConnParams = handlerRequest.headers.get(HEADER_CONN_PARAMS);
28602
+ const rawConnParams = jsRequest.headers.get(HEADER_CONN_PARAMS);
28738
28603
  let requestCtx;
28739
28604
  let conn;
28740
- let removeRequestAbortListener;
28741
- let cleanupDeferredToBody = false;
28742
- let cleanedUp = false;
28743
- const cleanupRequest = async () => {
28744
- if (cleanedUp) return;
28745
- cleanedUp = true;
28746
- removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
28747
- try {
28748
- await (requestCtx == null ? void 0 : requestCtx.dispose());
28749
- } finally {
28750
- if (conn) {
28751
- await runtime.connDisconnect(conn);
28752
- }
28753
- }
28754
- };
28755
28605
  try {
28756
28606
  const connParams = validateConnParams(
28757
28607
  schemaConfig.connParamsSchema,
@@ -28767,56 +28617,23 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28767
28617
  requestCtx = makeConnCtx(
28768
28618
  ctx,
28769
28619
  conn,
28770
- handlerRequest,
28620
+ jsRequest,
28771
28621
  cancelToken
28772
28622
  );
28773
- const ctxAbortSignal = requestCtx.abortSignal;
28774
- const abortRequest = () => requestAbortController.abort(ctxAbortSignal.reason);
28775
- if (ctxAbortSignal.aborted) {
28776
- abortRequest();
28777
- } else {
28778
- ctxAbortSignal.addEventListener(
28779
- "abort",
28780
- abortRequest,
28781
- { once: true }
28782
- );
28783
- removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
28784
- "abort",
28785
- abortRequest
28786
- );
28787
- }
28788
28623
  const response = await config3.onRequest(
28789
28624
  requestCtx,
28790
- handlerRequest
28625
+ jsRequest
28791
28626
  );
28792
28627
  if (!isResponseLike(response)) {
28793
28628
  throw new Error(
28794
28629
  "onRequest handler must return a Response"
28795
28630
  );
28796
28631
  }
28797
- const conversion = await convertNativeHttpResponse(
28798
- response,
28799
- responseBodyStream
28800
- );
28801
- if (conversion.bodyCompletion) {
28802
- cleanupDeferredToBody = true;
28803
- void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
28804
- logger22().error({
28805
- msg: "failed to clean up native streaming http request",
28806
- error: cleanupError
28807
- });
28808
- });
28809
- }
28810
- return conversion.response;
28632
+ return await toRuntimeHttpResponse(response);
28811
28633
  } finally {
28812
- try {
28813
- await cancelNativeHttpRequestBody(
28814
- request.bodyStream
28815
- );
28816
- } finally {
28817
- if (!cleanupDeferredToBody) {
28818
- await cleanupRequest();
28819
- }
28634
+ await (requestCtx == null ? void 0 : requestCtx.dispose());
28635
+ if (conn) {
28636
+ await runtime.connDisconnect(conn);
28820
28637
  }
28821
28638
  }
28822
28639
  } catch (error210) {
@@ -28831,7 +28648,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28831
28648
  onWebSocket: typeof config3.onWebSocket === "function" ? wrapNativeCallback(
28832
28649
  async (error46, payload) => {
28833
28650
  const { ctx, conn, ws, request } = unwrapTsfnPayload(error46, payload);
28834
- const jsRequest = request ? buildNativeHttpRequest(request) : void 0;
28651
+ const jsRequest = request ? buildRequest(request) : void 0;
28835
28652
  const actorCtx = makeConnCtx(ctx, conn, jsRequest);
28836
28653
  try {
28837
28654
  await config3.onWebSocket(
@@ -28928,7 +28745,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
28928
28745
  timeoutMs,
28929
28746
  cancelToken
28930
28747
  } = unwrapTsfnPayload(error46, payload);
28931
- const jsRequest = buildNativeHttpRequest(request);
28748
+ const jsRequest = buildRequest(request);
28932
28749
  const actorCtx = withConnContext(
28933
28750
  runtime,
28934
28751
  ctx,
@@ -29077,27 +28894,15 @@ function finishShutdownSignal(signal) {
29077
28894
  }
29078
28895
  process.kill(process.pid, signal);
29079
28896
  }
29080
- function createApplicationFetch(application, runtime) {
29081
- return async (request, responseBodyStream) => {
28897
+ function createApplicationFetch(application) {
28898
+ return async (request) => {
29082
28899
  const method2 = request.method.toUpperCase();
29083
28900
  const body = method2 === "GET" || method2 === "HEAD" || request.body.length === 0 ? void 0 : Uint8Array.from(request.body).buffer;
29084
- const abortController = new AbortController();
29085
- if (request.cancelToken) {
29086
- if (runtime.cancellationTokenAborted(request.cancelToken)) {
29087
- abortController.abort();
29088
- } else {
29089
- runtime.onCancellationTokenCancelled(
29090
- request.cancelToken,
29091
- () => abortController.abort()
29092
- );
29093
- }
29094
- }
29095
28901
  const response = await application.fetch(
29096
28902
  new Request(request.url, {
29097
28903
  method: method2,
29098
28904
  headers: request.headers,
29099
- body,
29100
- signal: abortController.signal
28905
+ body
29101
28906
  })
29102
28907
  );
29103
28908
  if (!isResponseLike(response)) {
@@ -29105,23 +28910,10 @@ function createApplicationFetch(application, runtime) {
29105
28910
  "registry.listen() application fetch must return a Response"
29106
28911
  );
29107
28912
  }
29108
- const conversion = await convertNativeHttpResponse(
29109
- response,
29110
- responseBodyStream
29111
- );
29112
- if (conversion.bodyCompletion) {
29113
- void conversion.bodyCompletion.catch((error46) => {
29114
- logger22().error({
29115
- msg: "application response stream failed",
29116
- error: error46
29117
- });
29118
- });
29119
- }
29120
28913
  return {
29121
- status: conversion.response.status ?? response.status,
29122
- headers: conversion.response.headers ?? Object.fromEntries(response.headers.entries()),
29123
- body: conversion.response.body,
29124
- stream: conversion.response.stream
28914
+ status: response.status,
28915
+ headers: Object.fromEntries(response.headers.entries()),
28916
+ body: new Uint8Array(await response.arrayBuffer())
29125
28917
  };
29126
28918
  };
29127
28919
  }
@@ -29379,7 +29171,8 @@ var Registry = class {
29379
29171
  const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
29380
29172
  const publicDir = opts.publicDir ?? getRivetkitPublicDir();
29381
29173
  const config3 = this.parseConfig();
29382
- if (opts.application && getRivetkitRuntimeMode() !== "serverless") {
29174
+ const application = opts.application ? createApplicationFetch(opts.application) : void 0;
29175
+ if (application && getRivetkitRuntimeMode() !== "serverless") {
29383
29176
  if (config3.runtime === "wasm") {
29384
29177
  throw new Error(
29385
29178
  "registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
@@ -29398,18 +29191,13 @@ var Registry = class {
29398
29191
  throw new Error("registry envoy startup did not initialize");
29399
29192
  }
29400
29193
  const { runtime: runtime2, registry: registry22, serveConfig: serveConfig2 } = await configuredRegistryPromise2;
29401
- const application2 = createApplicationFetch(
29402
- opts.application,
29403
- runtime2
29404
- );
29405
- await readyPromise;
29406
29194
  const listenerPromise = runtime2.serveApplicationListener(
29407
29195
  registry22,
29408
29196
  {
29409
29197
  port,
29410
29198
  host: opts.host,
29411
29199
  publicDir,
29412
- application: application2
29200
+ application
29413
29201
  },
29414
29202
  serveConfig2
29415
29203
  );
@@ -29421,12 +29209,13 @@ var Registry = class {
29421
29209
  );
29422
29210
  }
29423
29211
  await Promise.all([
29212
+ readyPromise,
29424
29213
  listenerPromise,
29425
29214
  serveLifecyclePromise
29426
29215
  ]);
29427
29216
  return;
29428
29217
  }
29429
- const configuredRegistryPromise = this.#buildConfiguredRegistry(config3);
29218
+ const configuredRegistryPromise = buildConfiguredRegistry(config3);
29430
29219
  this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
29431
29220
  this.#runtimeServerlessPromise = configuredRegistryPromise;
29432
29221
  this.#installSignalHandlers(config3);
@@ -29437,7 +29226,6 @@ var Registry = class {
29437
29226
  });
29438
29227
  this.#ensureServerlessPoolConfigured(config3);
29439
29228
  const { runtime, registry: registry2, serveConfig } = await configuredRegistryPromise;
29440
- const application = opts.application ? createApplicationFetch(opts.application, runtime) : void 0;
29441
29229
  await runtime.serveListener(
29442
29230
  registry2,
29443
29231
  {