@trpc/server 11.8.0 → 11.8.1-canary.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/adapters/aws-lambda/index.cjs +4 -4
- package/dist/adapters/aws-lambda/index.d.cts +1 -1
- package/dist/adapters/aws-lambda/index.d.mts +1 -1
- package/dist/adapters/aws-lambda/index.mjs +4 -4
- package/dist/adapters/express.cjs +9 -9
- package/dist/adapters/express.d.cts +2 -2
- package/dist/adapters/express.d.mts +2 -2
- package/dist/adapters/express.mjs +8 -8
- package/dist/adapters/fastify/index.cjs +9 -9
- package/dist/adapters/fastify/index.d.cts +2 -2
- package/dist/adapters/fastify/index.d.mts +2 -2
- package/dist/adapters/fastify/index.mjs +9 -9
- package/dist/adapters/fetch/index.cjs +4 -4
- package/dist/adapters/fetch/index.d.cts +1 -1
- package/dist/adapters/fetch/index.d.mts +1 -1
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/next-app-dir.cjs +7 -7
- package/dist/adapters/next-app-dir.d.cts +1 -1
- package/dist/adapters/next-app-dir.d.mts +1 -1
- package/dist/adapters/next-app-dir.mjs +7 -7
- package/dist/adapters/next.cjs +10 -10
- package/dist/adapters/next.d.cts +2 -2
- package/dist/adapters/next.d.mts +2 -2
- package/dist/adapters/next.mjs +8 -8
- package/dist/adapters/node-http/index.cjs +8 -8
- package/dist/adapters/node-http/index.d.cts +2 -2
- package/dist/adapters/node-http/index.d.mts +2 -2
- package/dist/adapters/node-http/index.mjs +8 -8
- package/dist/adapters/standalone.cjs +9 -9
- package/dist/adapters/standalone.d.cts +2 -2
- package/dist/adapters/standalone.d.mts +2 -2
- package/dist/adapters/standalone.mjs +8 -8
- package/dist/adapters/ws.cjs +9 -9
- package/dist/adapters/ws.d.cts +2 -2
- package/dist/adapters/ws.d.mts +2 -2
- package/dist/adapters/ws.mjs +9 -9
- package/dist/{utils-BqXzm3RP.cjs → codes-BfZsPdy-.cjs} +70 -70
- package/dist/{utils-CLZnJdb_.mjs → codes-DagpWZLc.mjs} +66 -66
- package/dist/codes-DagpWZLc.mjs.map +1 -0
- package/dist/{getErrorShape-BRalpqpM.cjs → getErrorShape-MR4DZeb7.cjs} +5 -5
- package/dist/{getErrorShape-BH60iMC2.mjs → getErrorShape-vC8mUXJD.mjs} +3 -3
- package/dist/getErrorShape-vC8mUXJD.mjs.map +1 -0
- package/dist/http.cjs +4 -4
- package/dist/http.d.cts +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +4 -4
- package/dist/index.cjs +4 -4
- package/dist/{index.d-VIbIrmxd.d.cts → index.d--uNJFzUS.d.cts} +2 -2
- package/dist/{index.d-DJGodwWi.d.mts.map → index.d--uNJFzUS.d.cts.map} +1 -1
- package/dist/{index.d-DJGodwWi.d.mts → index.d-D7vhS0-R.d.mts} +2 -2
- package/dist/{index.d-VIbIrmxd.d.cts.map → index.d-D7vhS0-R.d.mts.map} +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +4 -4
- package/dist/{initTRPC-Bq6NzC7R.cjs → initTRPC--HrEu8sH.cjs} +5 -5
- package/dist/{initTRPC-DGaJyg8t.mjs → initTRPC-T5bbc89W.mjs} +4 -4
- package/dist/{initTRPC-DGaJyg8t.mjs.map → initTRPC-T5bbc89W.mjs.map} +1 -1
- package/dist/{node-http-Cd7-CwtL.mjs → node-http-BEUst3IE.mjs} +5 -5
- package/dist/{node-http-Cd7-CwtL.mjs.map → node-http-BEUst3IE.mjs.map} +1 -1
- package/dist/{node-http-DWoBQ413.cjs → node-http-DR7b1Rn5.cjs} +5 -5
- package/dist/{parseTRPCMessage-Cdw5Sfhh.cjs → parseTRPCMessage-7Ltmq-Fb.cjs} +2 -2
- package/dist/{parseTRPCMessage-BlZeZ60t.mjs → parseTRPCMessage-CTow-umk.mjs} +2 -2
- package/dist/{parseTRPCMessage-BlZeZ60t.mjs.map → parseTRPCMessage-CTow-umk.mjs.map} +1 -1
- package/dist/{resolveResponse-BGrZsJDx.cjs → resolveResponse-ByfQ6olt.cjs} +57 -70
- package/dist/{resolveResponse-D7zvnoIM.mjs → resolveResponse-C7AcnFLN.mjs} +41 -48
- package/dist/resolveResponse-C7AcnFLN.mjs.map +1 -0
- package/dist/rpc.cjs +4 -4
- package/dist/rpc.d.cts +1 -1
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.mjs +2 -2
- package/dist/shared.cjs +2 -2
- package/dist/shared.d.cts +1 -1
- package/dist/shared.d.mts +1 -1
- package/dist/shared.mjs +2 -2
- package/dist/{tracked-DBSMdVzR.mjs → tracked-D4V22yc5.mjs} +6 -6
- package/dist/tracked-D4V22yc5.mjs.map +1 -0
- package/dist/{tracked-BJKHs06u.cjs → tracked-D4WGA_Z-.cjs} +11 -11
- package/dist/{unstable-core-do-not-import-DQoYSXto.mjs → unstable-core-do-not-import-9NNw8uQM.mjs} +5 -6
- package/dist/unstable-core-do-not-import-9NNw8uQM.mjs.map +1 -0
- package/dist/{unstable-core-do-not-import-Bo1JHRI3.cjs → unstable-core-do-not-import-fsjhEhgh.cjs} +3 -5
- package/dist/unstable-core-do-not-import.cjs +22 -23
- package/dist/{unstable-core-do-not-import.d-BJCeJk5P.d.cts → unstable-core-do-not-import.d-BXekdOPr.d.cts} +3 -9
- package/dist/unstable-core-do-not-import.d-BXekdOPr.d.cts.map +1 -0
- package/dist/{unstable-core-do-not-import.d-1RewV6pM.d.mts → unstable-core-do-not-import.d-CjQPvBRI.d.mts} +3 -9
- package/dist/unstable-core-do-not-import.d-CjQPvBRI.d.mts.map +1 -0
- package/dist/unstable-core-do-not-import.d.cts +2 -2
- package/dist/unstable-core-do-not-import.d.mts +2 -2
- package/dist/unstable-core-do-not-import.mjs +8 -8
- package/dist/{ws-1pBkKP_r.mjs → ws-BrdAS_fq.mjs} +7 -7
- package/dist/{ws-1pBkKP_r.mjs.map → ws-BrdAS_fq.mjs.map} +1 -1
- package/dist/{ws-C3Cua0Ig.cjs → ws-ZD8wclaD.cjs} +13 -13
- package/package.json +3 -3
- package/src/unstable-core-do-not-import/createProxy.ts +3 -1
- package/src/unstable-core-do-not-import/http/contentType.ts +7 -6
- package/src/unstable-core-do-not-import/http/formDataToObject.ts +4 -16
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +28 -2
- package/src/unstable-core-do-not-import/router.ts +4 -4
- package/src/unstable-core-do-not-import/stream/jsonl.ts +9 -3
- package/src/unstable-core-do-not-import/stream/sse.ts +3 -13
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +0 -30
- package/src/unstable-core-do-not-import/utils.ts +3 -5
- package/dist/getErrorShape-BH60iMC2.mjs.map +0 -1
- package/dist/resolveResponse-D7zvnoIM.mjs.map +0 -1
- package/dist/tracked-DBSMdVzR.mjs.map +0 -1
- package/dist/unstable-core-do-not-import-DQoYSXto.mjs.map +0 -1
- package/dist/unstable-core-do-not-import.d-1RewV6pM.d.mts.map +0 -1
- package/dist/unstable-core-do-not-import.d-BJCeJk5P.d.cts.map +0 -1
- package/dist/utils-CLZnJdb_.mjs.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const require_getErrorShape = require('./getErrorShape-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
const require_getErrorShape = require('./getErrorShape-MR4DZeb7.cjs');
|
|
2
|
+
const require_codes = require('./codes-BfZsPdy-.cjs');
|
|
3
|
+
const require_tracked = require('./tracked-D4WGA_Z-.cjs');
|
|
4
4
|
const require_observable = require('./observable-B1Nk6r1H.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/unstable-core-do-not-import/http/parseConnectionParams.ts
|
|
7
7
|
function parseConnectionParamsFromUnknown(parsed) {
|
|
8
8
|
try {
|
|
9
9
|
if (parsed === null) return null;
|
|
10
|
-
if (!
|
|
10
|
+
if (!require_codes.isObject(parsed)) throw new Error("Expected object");
|
|
11
11
|
const nonStringValues = Object.entries(parsed).filter(([_key, value]) => typeof value !== "string");
|
|
12
12
|
if (nonStringValues.length > 0) throw new Error(`Expected connectionParams to be string values. Got ${nonStringValues.map(([key, value]) => `${key}: ${typeof value}`).join(", ")}`);
|
|
13
13
|
return parsed;
|
|
@@ -81,13 +81,17 @@ const jsonContentTypeHandler = {
|
|
|
81
81
|
const queryInput = opts.searchParams.get("input");
|
|
82
82
|
if (queryInput) inputs = JSON.parse(queryInput);
|
|
83
83
|
} else inputs = await req.json();
|
|
84
|
-
if (inputs === void 0) return
|
|
85
|
-
if (!isBatchCall)
|
|
86
|
-
|
|
84
|
+
if (inputs === void 0) return require_codes.emptyObject();
|
|
85
|
+
if (!isBatchCall) {
|
|
86
|
+
const result = require_codes.emptyObject();
|
|
87
|
+
result[0] = opts.router._def._config.transformer.input.deserialize(inputs);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
if (!require_codes.isObject(inputs)) throw new require_tracked.TRPCError({
|
|
87
91
|
code: "BAD_REQUEST",
|
|
88
92
|
message: "\"input\" needs to be an object when doing a batch call"
|
|
89
93
|
});
|
|
90
|
-
const acc =
|
|
94
|
+
const acc = require_codes.emptyObject();
|
|
91
95
|
for (const index of paths.keys()) {
|
|
92
96
|
const input = inputs[index];
|
|
93
97
|
if (input !== void 0) acc[index] = opts.router._def._config.transformer.input.deserialize(input);
|
|
@@ -105,7 +109,7 @@ const jsonContentTypeHandler = {
|
|
|
105
109
|
if ((procedure === null || procedure === void 0 ? void 0 : procedure._def.type) === "subscription") {
|
|
106
110
|
var _ref, _opts$headers$get;
|
|
107
111
|
const lastEventId = (_ref = (_opts$headers$get = opts.headers.get("last-event-id")) !== null && _opts$headers$get !== void 0 ? _opts$headers$get : opts.searchParams.get("lastEventId")) !== null && _ref !== void 0 ? _ref : opts.searchParams.get("Last-Event-Id");
|
|
108
|
-
if (lastEventId) if (
|
|
112
|
+
if (lastEventId) if (require_codes.isObject(input)) input = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, input), {}, { lastEventId });
|
|
109
113
|
else {
|
|
110
114
|
var _input;
|
|
111
115
|
(_input = input) !== null && _input !== void 0 || (input = { lastEventId });
|
|
@@ -226,7 +230,7 @@ async function getRequestInfo(opts) {
|
|
|
226
230
|
//#endregion
|
|
227
231
|
//#region src/unstable-core-do-not-import/http/abortError.ts
|
|
228
232
|
function isAbortError(error) {
|
|
229
|
-
return
|
|
233
|
+
return require_codes.isObject(error) && error["name"] === "AbortError";
|
|
230
234
|
}
|
|
231
235
|
function throwAbortError(message = "AbortError") {
|
|
232
236
|
throw new DOMException(message, "AbortError");
|
|
@@ -708,49 +712,20 @@ function iteratorResource(iterable) {
|
|
|
708
712
|
});
|
|
709
713
|
}
|
|
710
714
|
/**
|
|
711
|
-
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically aborts after the specified duration.
|
|
712
|
-
*/
|
|
713
|
-
function withMaxDuration(_x, _x2) {
|
|
714
|
-
return _withMaxDuration.apply(this, arguments);
|
|
715
|
-
}
|
|
716
|
-
function _withMaxDuration() {
|
|
717
|
-
_withMaxDuration = (0, import_wrapAsyncGenerator$5.default)(function* (iterable, opts) {
|
|
718
|
-
try {
|
|
719
|
-
var _usingCtx$1 = (0, import_usingCtx$4.default)();
|
|
720
|
-
const iterator = _usingCtx$1.a(iteratorResource(iterable));
|
|
721
|
-
const timer = _usingCtx$1.u(timerResource(opts.maxDurationMs));
|
|
722
|
-
const timerPromise = timer.start();
|
|
723
|
-
let result;
|
|
724
|
-
while (true) {
|
|
725
|
-
result = yield (0, import_awaitAsyncGenerator$4.default)(Unpromise.race([iterator.next(), timerPromise]));
|
|
726
|
-
if (result === disposablePromiseTimerResult) throwAbortError();
|
|
727
|
-
if (result.done) return result;
|
|
728
|
-
yield result.value;
|
|
729
|
-
result = null;
|
|
730
|
-
}
|
|
731
|
-
} catch (_) {
|
|
732
|
-
_usingCtx$1.e = _;
|
|
733
|
-
} finally {
|
|
734
|
-
yield (0, import_awaitAsyncGenerator$4.default)(_usingCtx$1.d());
|
|
735
|
-
}
|
|
736
|
-
});
|
|
737
|
-
return _withMaxDuration.apply(this, arguments);
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
715
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
741
716
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
742
717
|
* values may still come through. After this period, the generator aborts.
|
|
743
718
|
*/
|
|
744
|
-
function takeWithGrace(
|
|
719
|
+
function takeWithGrace(_x, _x2) {
|
|
745
720
|
return _takeWithGrace.apply(this, arguments);
|
|
746
721
|
}
|
|
747
722
|
function _takeWithGrace() {
|
|
748
723
|
_takeWithGrace = (0, import_wrapAsyncGenerator$5.default)(function* (iterable, opts) {
|
|
749
724
|
try {
|
|
750
|
-
var
|
|
751
|
-
const iterator =
|
|
725
|
+
var _usingCtx$1 = (0, import_usingCtx$4.default)();
|
|
726
|
+
const iterator = _usingCtx$1.a(iteratorResource(iterable));
|
|
752
727
|
let result;
|
|
753
|
-
const timer =
|
|
728
|
+
const timer = _usingCtx$1.u(timerResource(opts.gracePeriodMs));
|
|
754
729
|
let count = opts.count;
|
|
755
730
|
let timerPromise = new Promise(() => {});
|
|
756
731
|
while (true) {
|
|
@@ -762,9 +737,9 @@ function _takeWithGrace() {
|
|
|
762
737
|
result = null;
|
|
763
738
|
}
|
|
764
739
|
} catch (_) {
|
|
765
|
-
|
|
740
|
+
_usingCtx$1.e = _;
|
|
766
741
|
} finally {
|
|
767
|
-
yield (0, import_awaitAsyncGenerator$4.default)(
|
|
742
|
+
yield (0, import_awaitAsyncGenerator$4.default)(_usingCtx$1.d());
|
|
768
743
|
}
|
|
769
744
|
});
|
|
770
745
|
return _takeWithGrace.apply(this, arguments);
|
|
@@ -1069,7 +1044,7 @@ const ASYNC_ITERABLE_STATUS_RETURN = 0;
|
|
|
1069
1044
|
const ASYNC_ITERABLE_STATUS_YIELD = 1;
|
|
1070
1045
|
const ASYNC_ITERABLE_STATUS_ERROR = 2;
|
|
1071
1046
|
function isPromise(value) {
|
|
1072
|
-
return (
|
|
1047
|
+
return (require_codes.isObject(value) || require_codes.isFunction(value)) && typeof (value === null || value === void 0 ? void 0 : value["then"]) === "function" && typeof (value === null || value === void 0 ? void 0 : value["catch"]) === "function";
|
|
1073
1048
|
}
|
|
1074
1049
|
var MaxDepthError = class extends Error {
|
|
1075
1050
|
constructor(path) {
|
|
@@ -1191,7 +1166,7 @@ function _createBatchStreamProducer() {
|
|
|
1191
1166
|
}
|
|
1192
1167
|
function encodeAsync(value, path) {
|
|
1193
1168
|
if (isPromise(value)) return [CHUNK_VALUE_TYPE_PROMISE, encodePromise(value, path)];
|
|
1194
|
-
if (
|
|
1169
|
+
if (require_codes.isAsyncIterable(value)) {
|
|
1195
1170
|
if (opts.maxDepth && path.length >= opts.maxDepth) throw new Error("Max depth reached");
|
|
1196
1171
|
return [CHUNK_VALUE_TYPE_ASYNC_ITERABLE, encodeAsyncIterable(value, path)];
|
|
1197
1172
|
}
|
|
@@ -1202,7 +1177,7 @@ function _createBatchStreamProducer() {
|
|
|
1202
1177
|
const reg = encodeAsync(value, path);
|
|
1203
1178
|
if (reg) return [[placeholder], [null, ...reg]];
|
|
1204
1179
|
if (!isPlainObject(value)) return [[value]];
|
|
1205
|
-
const newObj =
|
|
1180
|
+
const newObj = require_codes.emptyObject();
|
|
1206
1181
|
const asyncValues = [];
|
|
1207
1182
|
for (const [key, item] of Object.entries(value)) {
|
|
1208
1183
|
const transformed = encodeAsync(item, [...path, key]);
|
|
@@ -1215,7 +1190,7 @@ function _createBatchStreamProducer() {
|
|
|
1215
1190
|
}
|
|
1216
1191
|
return [[newObj], ...asyncValues];
|
|
1217
1192
|
}
|
|
1218
|
-
const newHead =
|
|
1193
|
+
const newHead = require_codes.emptyObject();
|
|
1219
1194
|
for (const [key, item] of Object.entries(data)) newHead[key] = encode(item, [key]);
|
|
1220
1195
|
yield newHead;
|
|
1221
1196
|
let iterable = mergedIterables;
|
|
@@ -1401,7 +1376,7 @@ async function jsonlStreamConsumer(opts) {
|
|
|
1401
1376
|
const [_path, type, chunkId] = value;
|
|
1402
1377
|
const controller = streamManager.getOrCreate(chunkId);
|
|
1403
1378
|
switch (type) {
|
|
1404
|
-
case CHUNK_VALUE_TYPE_PROMISE: return
|
|
1379
|
+
case CHUNK_VALUE_TYPE_PROMISE: return require_codes.run(async () => {
|
|
1405
1380
|
try {
|
|
1406
1381
|
var _usingCtx3 = (0, import_usingCtx$1.default)();
|
|
1407
1382
|
const reader = _usingCtx3.u(controller.getReaderResource());
|
|
@@ -1419,7 +1394,7 @@ async function jsonlStreamConsumer(opts) {
|
|
|
1419
1394
|
_usingCtx3.d();
|
|
1420
1395
|
}
|
|
1421
1396
|
});
|
|
1422
|
-
case CHUNK_VALUE_TYPE_ASYNC_ITERABLE: return
|
|
1397
|
+
case CHUNK_VALUE_TYPE_ASYNC_ITERABLE: return require_codes.run((0, import_wrapAsyncGenerator$2.default)(function* () {
|
|
1423
1398
|
try {
|
|
1424
1399
|
var _usingCtx4 = (0, import_usingCtx$1.default)();
|
|
1425
1400
|
const reader = _usingCtx4.u(controller.getReaderResource());
|
|
@@ -1530,7 +1505,7 @@ const RETURN_EVENT = "return";
|
|
|
1530
1505
|
*/
|
|
1531
1506
|
function sseStreamProducer(opts) {
|
|
1532
1507
|
var _opts$ping$enabled, _opts$ping, _opts$ping$intervalMs, _opts$ping2, _opts$client;
|
|
1533
|
-
const { serialize =
|
|
1508
|
+
const { serialize = require_codes.identity } = opts;
|
|
1534
1509
|
const ping = {
|
|
1535
1510
|
enabled: (_opts$ping$enabled = (_opts$ping = opts.ping) === null || _opts$ping === void 0 ? void 0 : _opts$ping.enabled) !== null && _opts$ping$enabled !== void 0 ? _opts$ping$enabled : false,
|
|
1536
1511
|
intervalMs: (_opts$ping$intervalMs = (_opts$ping2 = opts.ping) === null || _opts$ping2 === void 0 ? void 0 : _opts$ping2.intervalMs) !== null && _opts$ping$intervalMs !== void 0 ? _opts$ping$intervalMs : 1e3
|
|
@@ -1551,7 +1526,6 @@ function sseStreamProducer(opts) {
|
|
|
1551
1526
|
count: 1,
|
|
1552
1527
|
gracePeriodMs: 1
|
|
1553
1528
|
});
|
|
1554
|
-
if (opts.maxDurationMs && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) iterable = withMaxDuration(iterable, { maxDurationMs: opts.maxDurationMs });
|
|
1555
1529
|
if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) iterable = withPing(iterable, ping.intervalMs);
|
|
1556
1530
|
let value;
|
|
1557
1531
|
let chunk;
|
|
@@ -1643,7 +1617,7 @@ async function withTimeout(opts) {
|
|
|
1643
1617
|
*/
|
|
1644
1618
|
function sseStreamConsumer(opts) {
|
|
1645
1619
|
const { deserialize = (v) => v } = opts;
|
|
1646
|
-
let clientOptions =
|
|
1620
|
+
let clientOptions = require_codes.emptyObject();
|
|
1647
1621
|
const signal = opts.signal;
|
|
1648
1622
|
let _es = null;
|
|
1649
1623
|
const createStream = () => new ReadableStream({
|
|
@@ -1734,7 +1708,7 @@ function sseStreamConsumer(opts) {
|
|
|
1734
1708
|
}
|
|
1735
1709
|
}, dispose);
|
|
1736
1710
|
};
|
|
1737
|
-
return
|
|
1711
|
+
return require_codes.run((0, import_wrapAsyncGenerator$1.default)(function* () {
|
|
1738
1712
|
try {
|
|
1739
1713
|
var _usingCtx3 = (0, import_usingCtx.default)();
|
|
1740
1714
|
const stream = _usingCtx3.a(getStreamResource());
|
|
@@ -1780,10 +1754,18 @@ const sseHeaders = {
|
|
|
1780
1754
|
var import_wrapAsyncGenerator = require_getErrorShape.__toESM(require_wrapAsyncGenerator(), 1);
|
|
1781
1755
|
var import_objectSpread2 = require_getErrorShape.__toESM(require_getErrorShape.require_objectSpread2(), 1);
|
|
1782
1756
|
function errorToAsyncIterable(err) {
|
|
1783
|
-
return
|
|
1757
|
+
return require_codes.run((0, import_wrapAsyncGenerator.default)(function* () {
|
|
1784
1758
|
throw err;
|
|
1785
1759
|
}));
|
|
1786
1760
|
}
|
|
1761
|
+
function combinedAbortController(signal) {
|
|
1762
|
+
const controller = new AbortController();
|
|
1763
|
+
const combinedSignal = require_codes.abortSignalsAnyPonyfill([signal, controller.signal]);
|
|
1764
|
+
return {
|
|
1765
|
+
signal: combinedSignal,
|
|
1766
|
+
controller
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1787
1769
|
const TYPE_ACCEPTED_METHOD_MAP = {
|
|
1788
1770
|
mutation: ["POST"],
|
|
1789
1771
|
query: ["GET"],
|
|
@@ -1857,9 +1839,9 @@ function caughtErrorToData(cause, errorOpts) {
|
|
|
1857
1839
|
* - if it's an object with async iterables or promises
|
|
1858
1840
|
*/
|
|
1859
1841
|
function isDataStream(v) {
|
|
1860
|
-
if (!
|
|
1861
|
-
if (
|
|
1862
|
-
return Object.values(v).some(isPromise) || Object.values(v).some(
|
|
1842
|
+
if (!require_codes.isObject(v)) return false;
|
|
1843
|
+
if (require_codes.isAsyncIterable(v)) return true;
|
|
1844
|
+
return Object.values(v).some(isPromise) || Object.values(v).some(require_codes.isAsyncIterable);
|
|
1863
1845
|
}
|
|
1864
1846
|
async function resolveResponse(opts) {
|
|
1865
1847
|
var _ref, _opts$allowBatching, _opts$batching, _opts$allowMethodOver, _config$sse$enabled, _config$sse;
|
|
@@ -1870,7 +1852,7 @@ async function resolveResponse(opts) {
|
|
|
1870
1852
|
if (req.method === "HEAD") return new Response(null, { status: 204 });
|
|
1871
1853
|
const allowBatching = (_ref = (_opts$allowBatching = opts.allowBatching) !== null && _opts$allowBatching !== void 0 ? _opts$allowBatching : (_opts$batching = opts.batching) === null || _opts$batching === void 0 ? void 0 : _opts$batching.enabled) !== null && _ref !== void 0 ? _ref : true;
|
|
1872
1854
|
const allowMethodOverride = ((_opts$allowMethodOver = opts.allowMethodOverride) !== null && _opts$allowMethodOver !== void 0 ? _opts$allowMethodOver : false) && req.method === "POST";
|
|
1873
|
-
const infoTuple = await
|
|
1855
|
+
const infoTuple = await require_codes.run(async () => {
|
|
1874
1856
|
try {
|
|
1875
1857
|
return [void 0, await getRequestInfo({
|
|
1876
1858
|
req,
|
|
@@ -1884,7 +1866,7 @@ async function resolveResponse(opts) {
|
|
|
1884
1866
|
return [require_tracked.getTRPCErrorFromUnknown(cause), void 0];
|
|
1885
1867
|
}
|
|
1886
1868
|
});
|
|
1887
|
-
const ctxManager =
|
|
1869
|
+
const ctxManager = require_codes.run(() => {
|
|
1888
1870
|
let result = void 0;
|
|
1889
1871
|
return {
|
|
1890
1872
|
valueOrUndefined: () => {
|
|
@@ -1928,6 +1910,7 @@ async function resolveResponse(opts) {
|
|
|
1928
1910
|
await ctxManager.create(info);
|
|
1929
1911
|
const rpcCalls = info.calls.map(async (call) => {
|
|
1930
1912
|
const proc = call.procedure;
|
|
1913
|
+
const combinedAbort = combinedAbortController(opts.req.signal);
|
|
1931
1914
|
try {
|
|
1932
1915
|
if (opts.error) throw opts.error;
|
|
1933
1916
|
if (!proc) throw new require_tracked.TRPCError({
|
|
@@ -1939,18 +1922,28 @@ async function resolveResponse(opts) {
|
|
|
1939
1922
|
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`
|
|
1940
1923
|
});
|
|
1941
1924
|
if (proc._def.type === "subscription") {
|
|
1925
|
+
var _config$sse2;
|
|
1942
1926
|
/* istanbul ignore if -- @preserve */
|
|
1943
1927
|
if (info.isBatchCall) throw new require_tracked.TRPCError({
|
|
1944
1928
|
code: "BAD_REQUEST",
|
|
1945
1929
|
message: `Cannot batch subscription calls`
|
|
1946
1930
|
});
|
|
1931
|
+
if ((_config$sse2 = config.sse) === null || _config$sse2 === void 0 ? void 0 : _config$sse2.maxDurationMs) {
|
|
1932
|
+
function cleanup() {
|
|
1933
|
+
clearTimeout(timer);
|
|
1934
|
+
combinedAbort.signal.removeEventListener("abort", cleanup);
|
|
1935
|
+
combinedAbort.controller.abort();
|
|
1936
|
+
}
|
|
1937
|
+
const timer = setTimeout(cleanup, config.sse.maxDurationMs);
|
|
1938
|
+
combinedAbort.signal.addEventListener("abort", cleanup);
|
|
1939
|
+
}
|
|
1947
1940
|
}
|
|
1948
1941
|
const data = await proc({
|
|
1949
1942
|
path: call.path,
|
|
1950
1943
|
getRawInput: call.getRawInput,
|
|
1951
1944
|
ctx: ctxManager.value(),
|
|
1952
1945
|
type: proc._def.type,
|
|
1953
|
-
signal:
|
|
1946
|
+
signal: combinedAbort.signal
|
|
1954
1947
|
});
|
|
1955
1948
|
return [void 0, { data }];
|
|
1956
1949
|
} catch (cause) {
|
|
@@ -2002,13 +1995,13 @@ async function resolveResponse(opts) {
|
|
|
2002
1995
|
});
|
|
2003
1996
|
}
|
|
2004
1997
|
case "subscription": {
|
|
2005
|
-
const iterable =
|
|
1998
|
+
const iterable = require_codes.run(() => {
|
|
2006
1999
|
if (error) return errorToAsyncIterable(error);
|
|
2007
2000
|
if (!experimentalSSE) return errorToAsyncIterable(new require_tracked.TRPCError({
|
|
2008
2001
|
code: "METHOD_NOT_SUPPORTED",
|
|
2009
2002
|
message: "Missing experimental flag \"sseSubscriptions\""
|
|
2010
2003
|
}));
|
|
2011
|
-
if (!require_observable.isObservable(result.data) && !
|
|
2004
|
+
if (!require_observable.isObservable(result.data) && !require_codes.isAsyncIterable(result.data)) return errorToAsyncIterable(new require_tracked.TRPCError({
|
|
2012
2005
|
message: `Subscription ${call.path} did not return an observable or a AsyncGenerator`,
|
|
2013
2006
|
code: "INTERNAL_SERVER_ERROR"
|
|
2014
2007
|
}));
|
|
@@ -2310,10 +2303,4 @@ Object.defineProperty(exports, 'throwAbortError', {
|
|
|
2310
2303
|
get: function () {
|
|
2311
2304
|
return throwAbortError;
|
|
2312
2305
|
}
|
|
2313
|
-
});
|
|
2314
|
-
Object.defineProperty(exports, 'withMaxDuration', {
|
|
2315
|
-
enumerable: true,
|
|
2316
|
-
get: function () {
|
|
2317
|
-
return withMaxDuration;
|
|
2318
|
-
}
|
|
2319
2306
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { __commonJS, __toESM, getErrorShape, getHTTPStatusCode, require_defineProperty, require_objectSpread2 } from "./getErrorShape-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { __commonJS, __toESM, getErrorShape, getHTTPStatusCode, require_defineProperty, require_objectSpread2 } from "./getErrorShape-vC8mUXJD.mjs";
|
|
2
|
+
import { abortSignalsAnyPonyfill, emptyObject, identity, isAsyncIterable, isFunction, isObject, run } from "./codes-DagpWZLc.mjs";
|
|
3
|
+
import { TRPCError, getProcedureAtPath, getTRPCErrorFromUnknown, isTrackedEnvelope, transformTRPCResponse } from "./tracked-D4V22yc5.mjs";
|
|
4
4
|
import { isObservable, observableToAsyncIterable } from "./observable-UMO3vUa_.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/unstable-core-do-not-import/http/parseConnectionParams.ts
|
|
@@ -81,13 +81,17 @@ const jsonContentTypeHandler = {
|
|
|
81
81
|
const queryInput = opts.searchParams.get("input");
|
|
82
82
|
if (queryInput) inputs = JSON.parse(queryInput);
|
|
83
83
|
} else inputs = await req.json();
|
|
84
|
-
if (inputs === void 0) return
|
|
85
|
-
if (!isBatchCall)
|
|
84
|
+
if (inputs === void 0) return emptyObject();
|
|
85
|
+
if (!isBatchCall) {
|
|
86
|
+
const result = emptyObject();
|
|
87
|
+
result[0] = opts.router._def._config.transformer.input.deserialize(inputs);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
86
90
|
if (!isObject(inputs)) throw new TRPCError({
|
|
87
91
|
code: "BAD_REQUEST",
|
|
88
92
|
message: "\"input\" needs to be an object when doing a batch call"
|
|
89
93
|
});
|
|
90
|
-
const acc =
|
|
94
|
+
const acc = emptyObject();
|
|
91
95
|
for (const index of paths.keys()) {
|
|
92
96
|
const input = inputs[index];
|
|
93
97
|
if (input !== void 0) acc[index] = opts.router._def._config.transformer.input.deserialize(input);
|
|
@@ -708,49 +712,20 @@ function iteratorResource(iterable) {
|
|
|
708
712
|
});
|
|
709
713
|
}
|
|
710
714
|
/**
|
|
711
|
-
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically aborts after the specified duration.
|
|
712
|
-
*/
|
|
713
|
-
function withMaxDuration(_x, _x2) {
|
|
714
|
-
return _withMaxDuration.apply(this, arguments);
|
|
715
|
-
}
|
|
716
|
-
function _withMaxDuration() {
|
|
717
|
-
_withMaxDuration = (0, import_wrapAsyncGenerator$5.default)(function* (iterable, opts) {
|
|
718
|
-
try {
|
|
719
|
-
var _usingCtx$1 = (0, import_usingCtx$4.default)();
|
|
720
|
-
const iterator = _usingCtx$1.a(iteratorResource(iterable));
|
|
721
|
-
const timer = _usingCtx$1.u(timerResource(opts.maxDurationMs));
|
|
722
|
-
const timerPromise = timer.start();
|
|
723
|
-
let result;
|
|
724
|
-
while (true) {
|
|
725
|
-
result = yield (0, import_awaitAsyncGenerator$4.default)(Unpromise.race([iterator.next(), timerPromise]));
|
|
726
|
-
if (result === disposablePromiseTimerResult) throwAbortError();
|
|
727
|
-
if (result.done) return result;
|
|
728
|
-
yield result.value;
|
|
729
|
-
result = null;
|
|
730
|
-
}
|
|
731
|
-
} catch (_) {
|
|
732
|
-
_usingCtx$1.e = _;
|
|
733
|
-
} finally {
|
|
734
|
-
yield (0, import_awaitAsyncGenerator$4.default)(_usingCtx$1.d());
|
|
735
|
-
}
|
|
736
|
-
});
|
|
737
|
-
return _withMaxDuration.apply(this, arguments);
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
715
|
* Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
|
|
741
716
|
* {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
|
|
742
717
|
* values may still come through. After this period, the generator aborts.
|
|
743
718
|
*/
|
|
744
|
-
function takeWithGrace(
|
|
719
|
+
function takeWithGrace(_x, _x2) {
|
|
745
720
|
return _takeWithGrace.apply(this, arguments);
|
|
746
721
|
}
|
|
747
722
|
function _takeWithGrace() {
|
|
748
723
|
_takeWithGrace = (0, import_wrapAsyncGenerator$5.default)(function* (iterable, opts) {
|
|
749
724
|
try {
|
|
750
|
-
var
|
|
751
|
-
const iterator =
|
|
725
|
+
var _usingCtx$1 = (0, import_usingCtx$4.default)();
|
|
726
|
+
const iterator = _usingCtx$1.a(iteratorResource(iterable));
|
|
752
727
|
let result;
|
|
753
|
-
const timer =
|
|
728
|
+
const timer = _usingCtx$1.u(timerResource(opts.gracePeriodMs));
|
|
754
729
|
let count = opts.count;
|
|
755
730
|
let timerPromise = new Promise(() => {});
|
|
756
731
|
while (true) {
|
|
@@ -762,9 +737,9 @@ function _takeWithGrace() {
|
|
|
762
737
|
result = null;
|
|
763
738
|
}
|
|
764
739
|
} catch (_) {
|
|
765
|
-
|
|
740
|
+
_usingCtx$1.e = _;
|
|
766
741
|
} finally {
|
|
767
|
-
yield (0, import_awaitAsyncGenerator$4.default)(
|
|
742
|
+
yield (0, import_awaitAsyncGenerator$4.default)(_usingCtx$1.d());
|
|
768
743
|
}
|
|
769
744
|
});
|
|
770
745
|
return _takeWithGrace.apply(this, arguments);
|
|
@@ -1202,7 +1177,7 @@ function _createBatchStreamProducer() {
|
|
|
1202
1177
|
const reg = encodeAsync(value, path);
|
|
1203
1178
|
if (reg) return [[placeholder], [null, ...reg]];
|
|
1204
1179
|
if (!isPlainObject(value)) return [[value]];
|
|
1205
|
-
const newObj =
|
|
1180
|
+
const newObj = emptyObject();
|
|
1206
1181
|
const asyncValues = [];
|
|
1207
1182
|
for (const [key, item] of Object.entries(value)) {
|
|
1208
1183
|
const transformed = encodeAsync(item, [...path, key]);
|
|
@@ -1215,7 +1190,7 @@ function _createBatchStreamProducer() {
|
|
|
1215
1190
|
}
|
|
1216
1191
|
return [[newObj], ...asyncValues];
|
|
1217
1192
|
}
|
|
1218
|
-
const newHead =
|
|
1193
|
+
const newHead = emptyObject();
|
|
1219
1194
|
for (const [key, item] of Object.entries(data)) newHead[key] = encode(item, [key]);
|
|
1220
1195
|
yield newHead;
|
|
1221
1196
|
let iterable = mergedIterables;
|
|
@@ -1551,7 +1526,6 @@ function sseStreamProducer(opts) {
|
|
|
1551
1526
|
count: 1,
|
|
1552
1527
|
gracePeriodMs: 1
|
|
1553
1528
|
});
|
|
1554
|
-
if (opts.maxDurationMs && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) iterable = withMaxDuration(iterable, { maxDurationMs: opts.maxDurationMs });
|
|
1555
1529
|
if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) iterable = withPing(iterable, ping.intervalMs);
|
|
1556
1530
|
let value;
|
|
1557
1531
|
let chunk;
|
|
@@ -1643,7 +1617,7 @@ async function withTimeout(opts) {
|
|
|
1643
1617
|
*/
|
|
1644
1618
|
function sseStreamConsumer(opts) {
|
|
1645
1619
|
const { deserialize = (v) => v } = opts;
|
|
1646
|
-
let clientOptions =
|
|
1620
|
+
let clientOptions = emptyObject();
|
|
1647
1621
|
const signal = opts.signal;
|
|
1648
1622
|
let _es = null;
|
|
1649
1623
|
const createStream = () => new ReadableStream({
|
|
@@ -1784,6 +1758,14 @@ function errorToAsyncIterable(err) {
|
|
|
1784
1758
|
throw err;
|
|
1785
1759
|
}));
|
|
1786
1760
|
}
|
|
1761
|
+
function combinedAbortController(signal) {
|
|
1762
|
+
const controller = new AbortController();
|
|
1763
|
+
const combinedSignal = abortSignalsAnyPonyfill([signal, controller.signal]);
|
|
1764
|
+
return {
|
|
1765
|
+
signal: combinedSignal,
|
|
1766
|
+
controller
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1787
1769
|
const TYPE_ACCEPTED_METHOD_MAP = {
|
|
1788
1770
|
mutation: ["POST"],
|
|
1789
1771
|
query: ["GET"],
|
|
@@ -1928,6 +1910,7 @@ async function resolveResponse(opts) {
|
|
|
1928
1910
|
await ctxManager.create(info);
|
|
1929
1911
|
const rpcCalls = info.calls.map(async (call) => {
|
|
1930
1912
|
const proc = call.procedure;
|
|
1913
|
+
const combinedAbort = combinedAbortController(opts.req.signal);
|
|
1931
1914
|
try {
|
|
1932
1915
|
if (opts.error) throw opts.error;
|
|
1933
1916
|
if (!proc) throw new TRPCError({
|
|
@@ -1939,18 +1922,28 @@ async function resolveResponse(opts) {
|
|
|
1939
1922
|
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`
|
|
1940
1923
|
});
|
|
1941
1924
|
if (proc._def.type === "subscription") {
|
|
1925
|
+
var _config$sse2;
|
|
1942
1926
|
/* istanbul ignore if -- @preserve */
|
|
1943
1927
|
if (info.isBatchCall) throw new TRPCError({
|
|
1944
1928
|
code: "BAD_REQUEST",
|
|
1945
1929
|
message: `Cannot batch subscription calls`
|
|
1946
1930
|
});
|
|
1931
|
+
if ((_config$sse2 = config.sse) === null || _config$sse2 === void 0 ? void 0 : _config$sse2.maxDurationMs) {
|
|
1932
|
+
function cleanup() {
|
|
1933
|
+
clearTimeout(timer);
|
|
1934
|
+
combinedAbort.signal.removeEventListener("abort", cleanup);
|
|
1935
|
+
combinedAbort.controller.abort();
|
|
1936
|
+
}
|
|
1937
|
+
const timer = setTimeout(cleanup, config.sse.maxDurationMs);
|
|
1938
|
+
combinedAbort.signal.addEventListener("abort", cleanup);
|
|
1939
|
+
}
|
|
1947
1940
|
}
|
|
1948
1941
|
const data = await proc({
|
|
1949
1942
|
path: call.path,
|
|
1950
1943
|
getRawInput: call.getRawInput,
|
|
1951
1944
|
ctx: ctxManager.value(),
|
|
1952
1945
|
type: proc._def.type,
|
|
1953
|
-
signal:
|
|
1946
|
+
signal: combinedAbort.signal
|
|
1954
1947
|
});
|
|
1955
1948
|
return [void 0, { data }];
|
|
1956
1949
|
} catch (cause) {
|
|
@@ -2197,5 +2190,5 @@ async function resolveResponse(opts) {
|
|
|
2197
2190
|
}
|
|
2198
2191
|
|
|
2199
2192
|
//#endregion
|
|
2200
|
-
export { Unpromise, createDeferred, getRequestInfo, isAbortError, isPromise, iteratorResource, jsonlStreamConsumer, jsonlStreamProducer, makeAsyncResource, makeResource, parseConnectionParamsFromString, parseConnectionParamsFromUnknown, require_usingCtx, resolveResponse, sseHeaders, sseStreamConsumer, sseStreamProducer, takeWithGrace, throwAbortError
|
|
2201
|
-
//# sourceMappingURL=resolveResponse-
|
|
2193
|
+
export { Unpromise, createDeferred, getRequestInfo, isAbortError, isPromise, iteratorResource, jsonlStreamConsumer, jsonlStreamProducer, makeAsyncResource, makeResource, parseConnectionParamsFromString, parseConnectionParamsFromUnknown, require_usingCtx, resolveResponse, sseHeaders, sseStreamConsumer, sseStreamProducer, takeWithGrace, throwAbortError };
|
|
2194
|
+
//# sourceMappingURL=resolveResponse-C7AcnFLN.mjs.map
|