@trpc/server 11.0.0-rc.619 → 11.0.0-rc.630
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/getPlanner.js +2 -2
- package/dist/adapters/aws-lambda/getPlanner.mjs +2 -2
- package/dist/adapters/aws-lambda/index.js +1 -0
- package/dist/adapters/aws-lambda/index.mjs +1 -0
- package/dist/adapters/express.js +1 -0
- package/dist/adapters/express.mjs +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.js +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +7 -6
- package/dist/adapters/fetch/fetchRequestHandler.mjs +7 -6
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +5 -4
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +5 -4
- package/dist/adapters/next-app-dir/notFound.js +1 -0
- package/dist/adapters/next-app-dir/notFound.mjs +1 -0
- package/dist/adapters/next-app-dir/redirect.js +3 -1
- package/dist/adapters/next-app-dir/redirect.mjs +3 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.js +1 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +1 -1
- package/dist/adapters/next.js +1 -0
- package/dist/adapters/next.mjs +1 -0
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +7 -2
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +7 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +5 -4
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +5 -4
- package/dist/adapters/standalone.js +1 -0
- package/dist/adapters/standalone.mjs +1 -0
- package/dist/adapters/ws.js +9 -9
- package/dist/adapters/ws.mjs +9 -9
- package/dist/bundle-analysis.json +122 -105
- package/dist/http.js +1 -0
- package/dist/http.mjs +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js +11 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs +9 -0
- package/dist/observable/observable.js +1 -1
- package/dist/observable/observable.mjs +1 -1
- package/dist/rpc.js +1 -0
- package/dist/rpc.mjs +1 -0
- package/dist/shared.js +1 -0
- package/dist/shared.mjs +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +1 -1
- package/dist/unstable-core-do-not-import/createProxy.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +4 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +4 -1
- package/dist/unstable-core-do-not-import/error/formatter.js +1 -1
- package/dist/unstable-core-do-not-import/error/formatter.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +2 -2
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +2 -2
- package/dist/unstable-core-do-not-import/http/contentType.js +3 -3
- package/dist/unstable-core-do-not-import/http/contentType.mjs +3 -3
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +24 -24
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +24 -24
- package/dist/unstable-core-do-not-import/middleware.js +1 -1
- package/dist/unstable-core-do-not-import/middleware.mjs +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -1
- package/dist/unstable-core-do-not-import/router.js +2 -2
- package/dist/unstable-core-do-not-import/router.mjs +2 -2
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +2 -2
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +2 -2
- package/dist/unstable-core-do-not-import/stream/jsonl.js +14 -15
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +14 -15
- package/dist/unstable-core-do-not-import/stream/sse.js +2 -2
- package/dist/unstable-core-do-not-import/stream/sse.mjs +2 -2
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +1 -1
- package/dist/vendor/unpromise/unpromise.js +21 -16
- package/dist/vendor/unpromise/unpromise.mjs +21 -16
- package/package.json +11 -4
- package/src/adapters/node-http/incomingMessageToRequest.ts +7 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _memo, _cacheKey;
|
|
4
3
|
const noop = ()=>{
|
|
5
4
|
// noop
|
|
6
5
|
};
|
|
@@ -10,6 +9,7 @@ const freezeIfAvailable = (obj)=>{
|
|
|
10
9
|
}
|
|
11
10
|
};
|
|
12
11
|
function createInnerProxy(callback, path, memo) {
|
|
12
|
+
var _memo, _cacheKey;
|
|
13
13
|
const cacheKey = path.join('.');
|
|
14
14
|
(_memo = memo)[_cacheKey = cacheKey] ?? (_memo[_cacheKey] = new Proxy(noop, {
|
|
15
15
|
get (_obj, key) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var _memo, _cacheKey;
|
|
2
1
|
const noop = ()=>{
|
|
3
2
|
// noop
|
|
4
3
|
};
|
|
@@ -8,6 +7,7 @@ const freezeIfAvailable = (obj)=>{
|
|
|
8
7
|
}
|
|
9
8
|
};
|
|
10
9
|
function createInnerProxy(callback, path, memo) {
|
|
10
|
+
var _memo, _cacheKey;
|
|
11
11
|
const cacheKey = path.join('.');
|
|
12
12
|
(_memo = memo)[_cacheKey = cacheKey] ?? (_memo[_cacheKey] = new Proxy(noop, {
|
|
13
13
|
get (_obj, key) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _define_property = require('../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js');
|
|
3
4
|
var utils = require('../utils.js');
|
|
4
5
|
|
|
5
6
|
class UnknownCauseError extends Error {
|
|
@@ -52,7 +53,9 @@ class TRPCError extends Error {
|
|
|
52
53
|
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
53
54
|
super(message, {
|
|
54
55
|
cause
|
|
55
|
-
})
|
|
56
|
+
}), // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
57
|
+
// @ts-ignore override doesn't work in all environments due to "This member cannot have an 'override' modifier because it is not declared in the base class 'Error'"
|
|
58
|
+
_define_property._(this, "cause", void 0), _define_property._(this, "code", void 0);
|
|
56
59
|
this.code = opts.code;
|
|
57
60
|
this.name = 'TRPCError';
|
|
58
61
|
if (!this.cause) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as _define_property } from '../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs';
|
|
1
2
|
import { isObject } from '../utils.mjs';
|
|
2
3
|
|
|
3
4
|
class UnknownCauseError extends Error {
|
|
@@ -50,7 +51,9 @@ class TRPCError extends Error {
|
|
|
50
51
|
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
51
52
|
super(message, {
|
|
52
53
|
cause
|
|
53
|
-
})
|
|
54
|
+
}), // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
55
|
+
// @ts-ignore override doesn't work in all environments due to "This member cannot have an 'override' modifier because it is not declared in the base class 'Error'"
|
|
56
|
+
_define_property(this, "cause", void 0), _define_property(this, "code", void 0);
|
|
54
57
|
this.code = opts.code;
|
|
55
58
|
this.name = 'TRPCError';
|
|
56
59
|
if (!this.cause) {
|
|
@@ -6,8 +6,8 @@ var codes = require('../rpc/codes.js');
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/ function getErrorShape(opts) {
|
|
9
|
-
const { path
|
|
10
|
-
const { code
|
|
9
|
+
const { path, error, config } = opts;
|
|
10
|
+
const { code } = opts.error;
|
|
11
11
|
const shape = {
|
|
12
12
|
message: error.message,
|
|
13
13
|
code: codes.TRPC_ERROR_CODES_BY_KEY[code],
|
|
@@ -4,8 +4,8 @@ import { TRPC_ERROR_CODES_BY_KEY } from '../rpc/codes.mjs';
|
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/ function getErrorShape(opts) {
|
|
7
|
-
const { path
|
|
8
|
-
const { code
|
|
7
|
+
const { path, error, config } = opts;
|
|
8
|
+
const { code } = opts.error;
|
|
9
9
|
const shape = {
|
|
10
10
|
message: error.message,
|
|
11
11
|
code: TRPC_ERROR_CODES_BY_KEY[code],
|
|
@@ -46,7 +46,7 @@ const jsonContentTypeHandler = {
|
|
|
46
46
|
return !!req.headers.get('content-type')?.startsWith('application/json');
|
|
47
47
|
},
|
|
48
48
|
parse (opts) {
|
|
49
|
-
const { req
|
|
49
|
+
const { req } = opts;
|
|
50
50
|
const isBatchCall = opts.searchParams.get('batch') === '1';
|
|
51
51
|
const paths = isBatchCall ? opts.path.split(',') : [
|
|
52
52
|
opts.path
|
|
@@ -139,7 +139,7 @@ const formDataContentTypeHandler = {
|
|
|
139
139
|
return !!req.headers.get('content-type')?.startsWith('multipart/form-data');
|
|
140
140
|
},
|
|
141
141
|
parse (opts) {
|
|
142
|
-
const { req
|
|
142
|
+
const { req } = opts;
|
|
143
143
|
if (req.method !== 'POST') {
|
|
144
144
|
throw new TRPCError.TRPCError({
|
|
145
145
|
code: 'METHOD_NOT_SUPPORTED',
|
|
@@ -172,7 +172,7 @@ const octetStreamContentTypeHandler = {
|
|
|
172
172
|
return !!req.headers.get('content-type')?.startsWith('application/octet-stream');
|
|
173
173
|
},
|
|
174
174
|
parse (opts) {
|
|
175
|
-
const { req
|
|
175
|
+
const { req } = opts;
|
|
176
176
|
if (req.method !== 'POST') {
|
|
177
177
|
throw new TRPCError.TRPCError({
|
|
178
178
|
code: 'METHOD_NOT_SUPPORTED',
|
|
@@ -44,7 +44,7 @@ const jsonContentTypeHandler = {
|
|
|
44
44
|
return !!req.headers.get('content-type')?.startsWith('application/json');
|
|
45
45
|
},
|
|
46
46
|
parse (opts) {
|
|
47
|
-
const { req
|
|
47
|
+
const { req } = opts;
|
|
48
48
|
const isBatchCall = opts.searchParams.get('batch') === '1';
|
|
49
49
|
const paths = isBatchCall ? opts.path.split(',') : [
|
|
50
50
|
opts.path
|
|
@@ -137,7 +137,7 @@ const formDataContentTypeHandler = {
|
|
|
137
137
|
return !!req.headers.get('content-type')?.startsWith('multipart/form-data');
|
|
138
138
|
},
|
|
139
139
|
parse (opts) {
|
|
140
|
-
const { req
|
|
140
|
+
const { req } = opts;
|
|
141
141
|
if (req.method !== 'POST') {
|
|
142
142
|
throw new TRPCError({
|
|
143
143
|
code: 'METHOD_NOT_SUPPORTED',
|
|
@@ -170,7 +170,7 @@ const octetStreamContentTypeHandler = {
|
|
|
170
170
|
return !!req.headers.get('content-type')?.startsWith('application/octet-stream');
|
|
171
171
|
},
|
|
172
172
|
parse (opts) {
|
|
173
|
-
const { req
|
|
173
|
+
const { req } = opts;
|
|
174
174
|
if (req.method !== 'POST') {
|
|
175
175
|
throw new TRPCError({
|
|
176
176
|
code: 'METHOD_NOT_SUPPORTED',
|
|
@@ -47,7 +47,7 @@ const TYPE_ACCEPTED_METHOD_MAP_WITH_METHOD_OVERRIDE = {
|
|
|
47
47
|
]
|
|
48
48
|
};
|
|
49
49
|
function initResponse(initOpts) {
|
|
50
|
-
const { ctx
|
|
50
|
+
const { ctx, info, responseMeta, untransformedJSON, errors = [], headers } = initOpts;
|
|
51
51
|
let status = untransformedJSON ? getHTTPStatusCode.getHTTPStatusCode(untransformedJSON) : 200;
|
|
52
52
|
const eagerGeneration = !untransformedJSON;
|
|
53
53
|
const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
|
|
@@ -70,13 +70,13 @@ function initResponse(initOpts) {
|
|
|
70
70
|
} else {
|
|
71
71
|
/**
|
|
72
72
|
* @deprecated, delete in v12
|
|
73
|
-
*/ for (const [
|
|
74
|
-
if (Array.isArray(
|
|
75
|
-
for (const v of
|
|
76
|
-
headers.append(
|
|
73
|
+
*/ for (const [key, value] of Object.entries(meta.headers)){
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
for (const v of value){
|
|
76
|
+
headers.append(key, v);
|
|
77
77
|
}
|
|
78
|
-
} else if (typeof
|
|
79
|
-
headers.set(
|
|
78
|
+
} else if (typeof value === 'string') {
|
|
79
|
+
headers.set(key, value);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -89,7 +89,7 @@ function initResponse(initOpts) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
function caughtErrorToData(cause, errorOpts) {
|
|
92
|
-
const { router
|
|
92
|
+
const { router, req, onError } = errorOpts.opts;
|
|
93
93
|
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
94
94
|
onError?.({
|
|
95
95
|
error,
|
|
@@ -131,7 +131,7 @@ function caughtErrorToData(cause, errorOpts) {
|
|
|
131
131
|
return Object.values(v).some(jsonl.isPromise) || Object.values(v).some(utils.isAsyncIterable);
|
|
132
132
|
}
|
|
133
133
|
async function resolveResponse(opts) {
|
|
134
|
-
const { router
|
|
134
|
+
const { router, req } = opts;
|
|
135
135
|
const headers = new Headers([
|
|
136
136
|
[
|
|
137
137
|
'vary',
|
|
@@ -391,7 +391,7 @@ async function resolveResponse(opts) {
|
|
|
391
391
|
for (const [key, value] of Object.entries(sse.sseHeaders)){
|
|
392
392
|
headers.set(key, value);
|
|
393
393
|
}
|
|
394
|
-
const
|
|
394
|
+
const headResponse = initResponse({
|
|
395
395
|
ctx: ctxManager.valueOrUndefined(),
|
|
396
396
|
info,
|
|
397
397
|
responseMeta: opts.responseMeta,
|
|
@@ -401,7 +401,7 @@ async function resolveResponse(opts) {
|
|
|
401
401
|
});
|
|
402
402
|
return new Response(stream, {
|
|
403
403
|
headers,
|
|
404
|
-
status:
|
|
404
|
+
status: headResponse.status
|
|
405
405
|
});
|
|
406
406
|
}
|
|
407
407
|
}
|
|
@@ -411,7 +411,7 @@ async function resolveResponse(opts) {
|
|
|
411
411
|
// httpBatchStreamLink
|
|
412
412
|
headers.set('content-type', 'application/json');
|
|
413
413
|
headers.set('transfer-encoding', 'chunked');
|
|
414
|
-
const
|
|
414
|
+
const headResponse = initResponse({
|
|
415
415
|
ctx: ctxManager.valueOrUndefined(),
|
|
416
416
|
info,
|
|
417
417
|
responseMeta: opts.responseMeta,
|
|
@@ -419,7 +419,7 @@ async function resolveResponse(opts) {
|
|
|
419
419
|
headers,
|
|
420
420
|
untransformedJSON: null
|
|
421
421
|
});
|
|
422
|
-
const
|
|
422
|
+
const stream = jsonl.jsonlStreamProducer({
|
|
423
423
|
/**
|
|
424
424
|
* Example structure for `maxDepth: 4`:
|
|
425
425
|
* {
|
|
@@ -487,9 +487,9 @@ async function resolveResponse(opts) {
|
|
|
487
487
|
return shape;
|
|
488
488
|
}
|
|
489
489
|
});
|
|
490
|
-
return new Response(
|
|
490
|
+
return new Response(stream, {
|
|
491
491
|
headers,
|
|
492
|
-
status:
|
|
492
|
+
status: headResponse.status
|
|
493
493
|
});
|
|
494
494
|
}
|
|
495
495
|
// httpBatchLink
|
|
@@ -536,7 +536,7 @@ async function resolveResponse(opts) {
|
|
|
536
536
|
};
|
|
537
537
|
});
|
|
538
538
|
const errors = results.map(([error])=>error).filter(Boolean);
|
|
539
|
-
const
|
|
539
|
+
const headResponse = initResponse({
|
|
540
540
|
ctx: ctxManager.valueOrUndefined(),
|
|
541
541
|
info,
|
|
542
542
|
responseMeta: opts.responseMeta,
|
|
@@ -545,11 +545,11 @@ async function resolveResponse(opts) {
|
|
|
545
545
|
headers
|
|
546
546
|
});
|
|
547
547
|
return new Response(JSON.stringify(transformer.transformTRPCResponse(config, resultAsRPCResponse)), {
|
|
548
|
-
status:
|
|
548
|
+
status: headResponse.status,
|
|
549
549
|
headers
|
|
550
550
|
});
|
|
551
551
|
} catch (cause) {
|
|
552
|
-
const [_infoError,
|
|
552
|
+
const [_infoError, info] = infoTuple;
|
|
553
553
|
const ctx = ctxManager.valueOrUndefined();
|
|
554
554
|
// we get here if
|
|
555
555
|
// - batching is called when it's not enabled
|
|
@@ -558,23 +558,23 @@ async function resolveResponse(opts) {
|
|
|
558
558
|
// - post body is too large
|
|
559
559
|
// - input deserialization fails
|
|
560
560
|
// - `errorFormatter` return value is malformed
|
|
561
|
-
const { error
|
|
561
|
+
const { error, untransformedJSON, body } = caughtErrorToData(cause, {
|
|
562
562
|
opts,
|
|
563
563
|
ctx: ctxManager.valueOrUndefined(),
|
|
564
|
-
type:
|
|
564
|
+
type: info?.type ?? 'unknown'
|
|
565
565
|
});
|
|
566
|
-
const
|
|
566
|
+
const headResponse = initResponse({
|
|
567
567
|
ctx,
|
|
568
|
-
info
|
|
568
|
+
info,
|
|
569
569
|
responseMeta: opts.responseMeta,
|
|
570
570
|
untransformedJSON,
|
|
571
571
|
errors: [
|
|
572
|
-
|
|
572
|
+
error
|
|
573
573
|
],
|
|
574
574
|
headers
|
|
575
575
|
});
|
|
576
576
|
return new Response(body, {
|
|
577
|
-
status:
|
|
577
|
+
status: headResponse.status,
|
|
578
578
|
headers
|
|
579
579
|
});
|
|
580
580
|
}
|
|
@@ -45,7 +45,7 @@ const TYPE_ACCEPTED_METHOD_MAP_WITH_METHOD_OVERRIDE = {
|
|
|
45
45
|
]
|
|
46
46
|
};
|
|
47
47
|
function initResponse(initOpts) {
|
|
48
|
-
const { ctx
|
|
48
|
+
const { ctx, info, responseMeta, untransformedJSON, errors = [], headers } = initOpts;
|
|
49
49
|
let status = untransformedJSON ? getHTTPStatusCode(untransformedJSON) : 200;
|
|
50
50
|
const eagerGeneration = !untransformedJSON;
|
|
51
51
|
const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
|
|
@@ -68,13 +68,13 @@ function initResponse(initOpts) {
|
|
|
68
68
|
} else {
|
|
69
69
|
/**
|
|
70
70
|
* @deprecated, delete in v12
|
|
71
|
-
*/ for (const [
|
|
72
|
-
if (Array.isArray(
|
|
73
|
-
for (const v of
|
|
74
|
-
headers.append(
|
|
71
|
+
*/ for (const [key, value] of Object.entries(meta.headers)){
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
for (const v of value){
|
|
74
|
+
headers.append(key, v);
|
|
75
75
|
}
|
|
76
|
-
} else if (typeof
|
|
77
|
-
headers.set(
|
|
76
|
+
} else if (typeof value === 'string') {
|
|
77
|
+
headers.set(key, value);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -87,7 +87,7 @@ function initResponse(initOpts) {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
function caughtErrorToData(cause, errorOpts) {
|
|
90
|
-
const { router
|
|
90
|
+
const { router, req, onError } = errorOpts.opts;
|
|
91
91
|
const error = getTRPCErrorFromUnknown(cause);
|
|
92
92
|
onError?.({
|
|
93
93
|
error,
|
|
@@ -129,7 +129,7 @@ function caughtErrorToData(cause, errorOpts) {
|
|
|
129
129
|
return Object.values(v).some(isPromise) || Object.values(v).some(isAsyncIterable);
|
|
130
130
|
}
|
|
131
131
|
async function resolveResponse(opts) {
|
|
132
|
-
const { router
|
|
132
|
+
const { router, req } = opts;
|
|
133
133
|
const headers = new Headers([
|
|
134
134
|
[
|
|
135
135
|
'vary',
|
|
@@ -389,7 +389,7 @@ async function resolveResponse(opts) {
|
|
|
389
389
|
for (const [key, value] of Object.entries(sseHeaders)){
|
|
390
390
|
headers.set(key, value);
|
|
391
391
|
}
|
|
392
|
-
const
|
|
392
|
+
const headResponse = initResponse({
|
|
393
393
|
ctx: ctxManager.valueOrUndefined(),
|
|
394
394
|
info,
|
|
395
395
|
responseMeta: opts.responseMeta,
|
|
@@ -399,7 +399,7 @@ async function resolveResponse(opts) {
|
|
|
399
399
|
});
|
|
400
400
|
return new Response(stream, {
|
|
401
401
|
headers,
|
|
402
|
-
status:
|
|
402
|
+
status: headResponse.status
|
|
403
403
|
});
|
|
404
404
|
}
|
|
405
405
|
}
|
|
@@ -409,7 +409,7 @@ async function resolveResponse(opts) {
|
|
|
409
409
|
// httpBatchStreamLink
|
|
410
410
|
headers.set('content-type', 'application/json');
|
|
411
411
|
headers.set('transfer-encoding', 'chunked');
|
|
412
|
-
const
|
|
412
|
+
const headResponse = initResponse({
|
|
413
413
|
ctx: ctxManager.valueOrUndefined(),
|
|
414
414
|
info,
|
|
415
415
|
responseMeta: opts.responseMeta,
|
|
@@ -417,7 +417,7 @@ async function resolveResponse(opts) {
|
|
|
417
417
|
headers,
|
|
418
418
|
untransformedJSON: null
|
|
419
419
|
});
|
|
420
|
-
const
|
|
420
|
+
const stream = jsonlStreamProducer({
|
|
421
421
|
/**
|
|
422
422
|
* Example structure for `maxDepth: 4`:
|
|
423
423
|
* {
|
|
@@ -485,9 +485,9 @@ async function resolveResponse(opts) {
|
|
|
485
485
|
return shape;
|
|
486
486
|
}
|
|
487
487
|
});
|
|
488
|
-
return new Response(
|
|
488
|
+
return new Response(stream, {
|
|
489
489
|
headers,
|
|
490
|
-
status:
|
|
490
|
+
status: headResponse.status
|
|
491
491
|
});
|
|
492
492
|
}
|
|
493
493
|
// httpBatchLink
|
|
@@ -534,7 +534,7 @@ async function resolveResponse(opts) {
|
|
|
534
534
|
};
|
|
535
535
|
});
|
|
536
536
|
const errors = results.map(([error])=>error).filter(Boolean);
|
|
537
|
-
const
|
|
537
|
+
const headResponse = initResponse({
|
|
538
538
|
ctx: ctxManager.valueOrUndefined(),
|
|
539
539
|
info,
|
|
540
540
|
responseMeta: opts.responseMeta,
|
|
@@ -543,11 +543,11 @@ async function resolveResponse(opts) {
|
|
|
543
543
|
headers
|
|
544
544
|
});
|
|
545
545
|
return new Response(JSON.stringify(transformTRPCResponse(config, resultAsRPCResponse)), {
|
|
546
|
-
status:
|
|
546
|
+
status: headResponse.status,
|
|
547
547
|
headers
|
|
548
548
|
});
|
|
549
549
|
} catch (cause) {
|
|
550
|
-
const [_infoError,
|
|
550
|
+
const [_infoError, info] = infoTuple;
|
|
551
551
|
const ctx = ctxManager.valueOrUndefined();
|
|
552
552
|
// we get here if
|
|
553
553
|
// - batching is called when it's not enabled
|
|
@@ -556,23 +556,23 @@ async function resolveResponse(opts) {
|
|
|
556
556
|
// - post body is too large
|
|
557
557
|
// - input deserialization fails
|
|
558
558
|
// - `errorFormatter` return value is malformed
|
|
559
|
-
const { error
|
|
559
|
+
const { error, untransformedJSON, body } = caughtErrorToData(cause, {
|
|
560
560
|
opts,
|
|
561
561
|
ctx: ctxManager.valueOrUndefined(),
|
|
562
|
-
type:
|
|
562
|
+
type: info?.type ?? 'unknown'
|
|
563
563
|
});
|
|
564
|
-
const
|
|
564
|
+
const headResponse = initResponse({
|
|
565
565
|
ctx,
|
|
566
|
-
info
|
|
566
|
+
info,
|
|
567
567
|
responseMeta: opts.responseMeta,
|
|
568
568
|
untransformedJSON,
|
|
569
569
|
errors: [
|
|
570
|
-
|
|
570
|
+
error
|
|
571
571
|
],
|
|
572
572
|
headers
|
|
573
573
|
});
|
|
574
574
|
return new Response(body, {
|
|
575
|
-
status:
|
|
575
|
+
status: headResponse.status,
|
|
576
576
|
headers
|
|
577
577
|
});
|
|
578
578
|
}
|
|
@@ -65,7 +65,7 @@ var utils = require('./utils.js');
|
|
|
65
65
|
/**
|
|
66
66
|
* @internal
|
|
67
67
|
*/ function createOutputMiddleware(parse) {
|
|
68
|
-
const outputMiddleware = async function outputValidatorMiddleware({ next
|
|
68
|
+
const outputMiddleware = async function outputValidatorMiddleware({ next }) {
|
|
69
69
|
const result = await next();
|
|
70
70
|
if (!result.ok) {
|
|
71
71
|
// pass through failures without validating
|
|
@@ -63,7 +63,7 @@ import { isObject } from './utils.mjs';
|
|
|
63
63
|
/**
|
|
64
64
|
* @internal
|
|
65
65
|
*/ function createOutputMiddleware(parse) {
|
|
66
|
-
const outputMiddleware = async function outputValidatorMiddleware({ next
|
|
66
|
+
const outputMiddleware = async function outputValidatorMiddleware({ next }) {
|
|
67
67
|
const result = await next();
|
|
68
68
|
if (!result.ok) {
|
|
69
69
|
// pass through failures without validating
|
|
@@ -6,7 +6,7 @@ var parser = require('./parser.js');
|
|
|
6
6
|
var utils = require('./utils.js');
|
|
7
7
|
|
|
8
8
|
function createNewBuilder(def1, def2) {
|
|
9
|
-
const { middlewares =[]
|
|
9
|
+
const { middlewares = [], inputs, meta, ...rest } = def2;
|
|
10
10
|
// TODO: maybe have a fn here to warn about calls
|
|
11
11
|
return createBuilder({
|
|
12
12
|
...utils.mergeWithoutOverrides(def1, rest),
|
|
@@ -4,7 +4,7 @@ import { getParseFn } from './parser.mjs';
|
|
|
4
4
|
import { mergeWithoutOverrides } from './utils.mjs';
|
|
5
5
|
|
|
6
6
|
function createNewBuilder(def1, def2) {
|
|
7
|
-
const { middlewares =[]
|
|
7
|
+
const { middlewares = [], inputs, meta, ...rest } = def2;
|
|
8
8
|
// TODO: maybe have a fn here to warn about calls
|
|
9
9
|
return createBuilder({
|
|
10
10
|
...mergeWithoutOverrides(def1, rest),
|
|
@@ -94,7 +94,7 @@ function isProcedure(procedureOrRouter) {
|
|
|
94
94
|
/**
|
|
95
95
|
* @internal
|
|
96
96
|
*/ function callProcedure(opts) {
|
|
97
|
-
const { type
|
|
97
|
+
const { type, path } = opts;
|
|
98
98
|
const proc = opts.procedures[path];
|
|
99
99
|
if (!proc || !isProcedure(proc) || proc._def.type !== type && !opts.allowMethodOverride) {
|
|
100
100
|
throw new TRPCError.TRPCError({
|
|
@@ -114,7 +114,7 @@ function createCallerFactory() {
|
|
|
114
114
|
return function createCallerInner(router) {
|
|
115
115
|
const _def = router._def;
|
|
116
116
|
return function createCaller(ctxOrCallback, opts) {
|
|
117
|
-
return createProxy.createRecursiveProxy(async ({ path
|
|
117
|
+
return createProxy.createRecursiveProxy(async ({ path, args })=>{
|
|
118
118
|
const fullPath = path.join('.');
|
|
119
119
|
if (path.length === 1 && path[0] === '_def') {
|
|
120
120
|
return _def;
|
|
@@ -92,7 +92,7 @@ function isProcedure(procedureOrRouter) {
|
|
|
92
92
|
/**
|
|
93
93
|
* @internal
|
|
94
94
|
*/ function callProcedure(opts) {
|
|
95
|
-
const { type
|
|
95
|
+
const { type, path } = opts;
|
|
96
96
|
const proc = opts.procedures[path];
|
|
97
97
|
if (!proc || !isProcedure(proc) || proc._def.type !== type && !opts.allowMethodOverride) {
|
|
98
98
|
throw new TRPCError({
|
|
@@ -112,7 +112,7 @@ function createCallerFactory() {
|
|
|
112
112
|
return function createCallerInner(router) {
|
|
113
113
|
const _def = router._def;
|
|
114
114
|
return function createCaller(ctxOrCallback, opts) {
|
|
115
|
-
return createRecursiveProxy(async ({ path
|
|
115
|
+
return createRecursiveProxy(async ({ path, args })=>{
|
|
116
116
|
const fullPath = path.join('.');
|
|
117
117
|
if (path.length === 1 && path[0] === '_def') {
|
|
118
118
|
return _def;
|
|
@@ -30,7 +30,7 @@ var utils = require('../utils.js');
|
|
|
30
30
|
}
|
|
31
31
|
/** @public */ function parseTRPCMessage(obj, transformer) {
|
|
32
32
|
assertIsObject(obj);
|
|
33
|
-
const { id
|
|
33
|
+
const { id, jsonrpc, method, params } = obj;
|
|
34
34
|
assertIsRequestId(id);
|
|
35
35
|
assertIsJSONRPC2OrUndefined(jsonrpc);
|
|
36
36
|
if (method === 'subscription.stop') {
|
|
@@ -42,7 +42,7 @@ var utils = require('../utils.js');
|
|
|
42
42
|
}
|
|
43
43
|
assertIsProcedureType(method);
|
|
44
44
|
assertIsObject(params);
|
|
45
|
-
const { input: rawInput
|
|
45
|
+
const { input: rawInput, path, lastEventId } = params;
|
|
46
46
|
assertIsString(path);
|
|
47
47
|
if (lastEventId !== undefined) {
|
|
48
48
|
assertIsString(lastEventId);
|
|
@@ -28,7 +28,7 @@ import { isObject } from '../utils.mjs';
|
|
|
28
28
|
}
|
|
29
29
|
/** @public */ function parseTRPCMessage(obj, transformer) {
|
|
30
30
|
assertIsObject(obj);
|
|
31
|
-
const { id
|
|
31
|
+
const { id, jsonrpc, method, params } = obj;
|
|
32
32
|
assertIsRequestId(id);
|
|
33
33
|
assertIsJSONRPC2OrUndefined(jsonrpc);
|
|
34
34
|
if (method === 'subscription.stop') {
|
|
@@ -40,7 +40,7 @@ import { isObject } from '../utils.mjs';
|
|
|
40
40
|
}
|
|
41
41
|
assertIsProcedureType(method);
|
|
42
42
|
assertIsObject(params);
|
|
43
|
-
const { input: rawInput
|
|
43
|
+
const { input: rawInput, path, lastEventId } = params;
|
|
44
44
|
assertIsString(path);
|
|
45
45
|
if (lastEventId !== undefined) {
|
|
46
46
|
assertIsString(lastEventId);
|