@trpc/server 9.20.2 → 9.22.0
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/adapters/express/dist/trpc-server-adapters-express.cjs.dev.js +5 -5
- package/adapters/express/dist/trpc-server-adapters-express.cjs.prod.js +5 -5
- package/adapters/express/dist/trpc-server-adapters-express.esm.js +5 -5
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +16 -9
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +16 -9
- package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +16 -9
- package/adapters/next/dist/trpc-server-adapters-next.cjs.dev.js +3 -3
- package/adapters/next/dist/trpc-server-adapters-next.cjs.prod.js +3 -3
- package/adapters/next/dist/trpc-server-adapters-next.esm.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.dev.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.prod.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.esm.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.dev.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.prod.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.esm.js +3 -3
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.dev.js +4 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.prod.js +4 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.esm.js +4 -4
- package/dist/declarations/src/TRPCError.d.ts.map +1 -1
- package/dist/declarations/src/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/declarations/src/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/declarations/src/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/declarations/src/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/declarations/src/adapters/next.d.ts +1 -1
- package/dist/declarations/src/adapters/next.d.ts.map +1 -1
- package/dist/declarations/src/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/declarations/src/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/declarations/src/adapters/standalone.d.ts.map +1 -1
- package/dist/declarations/src/adapters/ws.d.ts.map +1 -1
- package/dist/declarations/src/deprecated/createHttpServer.d.ts +1 -1
- package/dist/declarations/src/deprecated/createHttpServer.d.ts.map +1 -1
- package/dist/declarations/src/deprecated/requestHandler.d.ts +1 -1
- package/dist/declarations/src/deprecated/requestHandler.d.ts.map +1 -1
- package/dist/declarations/src/http/internals/getHTTPStatusCode.d.ts +1 -1
- package/dist/declarations/src/http/internals/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/declarations/src/http/internals/types.d.ts +1 -1
- package/dist/declarations/src/http/internals/types.d.ts.map +1 -1
- package/dist/declarations/src/http/resolveHTTPResponse.d.ts +2 -2
- package/dist/declarations/src/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/declarations/src/internals/BaseHandlerOptions.d.ts +1 -1
- package/dist/declarations/src/internals/BaseHandlerOptions.d.ts.map +1 -1
- package/dist/declarations/src/internals/OnErrorFunction.d.ts +1 -1
- package/dist/declarations/src/internals/OnErrorFunction.d.ts.map +1 -1
- package/dist/declarations/src/internals/middlewares.d.ts +3 -2
- package/dist/declarations/src/internals/middlewares.d.ts.map +1 -1
- package/dist/declarations/src/internals/procedure.d.ts +44 -32
- package/dist/declarations/src/internals/procedure.d.ts.map +1 -1
- package/dist/declarations/src/router.d.ts +34 -30
- package/dist/declarations/src/router.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-2cc444d8.cjs.dev.js → nodeHTTPRequestHandler-620da2b7.cjs.dev.js} +2 -2
- package/dist/{nodeHTTPRequestHandler-d00c1126.esm.js → nodeHTTPRequestHandler-87105aef.esm.js} +2 -2
- package/dist/{nodeHTTPRequestHandler-8ddacc19.cjs.prod.js → nodeHTTPRequestHandler-9cfa7523.cjs.prod.js} +2 -2
- package/dist/{resolveHTTPResponse-85f3f5df.esm.js → resolveHTTPResponse-12cc3012.esm.js} +1 -1
- package/dist/{resolveHTTPResponse-3867844c.cjs.dev.js → resolveHTTPResponse-780f5cab.cjs.dev.js} +1 -1
- package/dist/{resolveHTTPResponse-562c3d62.cjs.prod.js → resolveHTTPResponse-d1d2695d.cjs.prod.js} +1 -1
- package/dist/{subscription-fbda2888.esm.js → subscription-2ea469a3.esm.js} +2 -2
- package/dist/{subscription-c2e0bfbc.cjs.prod.js → subscription-7de48383.cjs.dev.js} +2 -2
- package/dist/{subscription-b8831081.cjs.dev.js → subscription-f03bec71.cjs.prod.js} +2 -2
- package/dist/{transformTRPCResponse-8248515e.cjs.dev.js → transformTRPCResponse-1e125b28.cjs.prod.js} +38 -38
- package/dist/{transformTRPCResponse-f73dc4a2.esm.js → transformTRPCResponse-45c225c3.esm.js} +38 -38
- package/dist/{transformTRPCResponse-dcbf66c5.cjs.prod.js → transformTRPCResponse-c654ea92.cjs.dev.js} +38 -38
- package/dist/trpc-server.cjs.dev.js +44 -18
- package/dist/trpc-server.cjs.prod.js +44 -18
- package/dist/trpc-server.esm.js +46 -20
- package/package.json +2 -5
- package/src/TRPCError.ts +1 -1
- package/src/adapters/express.ts +2 -2
- package/src/adapters/fastify/fastifyRequestHandler.ts +7 -8
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +14 -6
- package/src/adapters/next.ts +6 -2
- package/src/adapters/node-http/internals/getPostBody.test.ts +2 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +5 -5
- package/src/adapters/standalone.ts +1 -0
- package/src/adapters/ws.ts +4 -4
- package/src/deprecated/createHttpServer.ts +2 -2
- package/src/deprecated/requestHandler.ts +2 -2
- package/src/http/internals/getHTTPStatusCode.ts +1 -1
- package/src/http/internals/types.ts +2 -2
- package/src/http/resolveHTTPResponse.ts +3 -3
- package/src/internals/BaseHandlerOptions.ts +1 -1
- package/src/internals/OnErrorFunction.ts +1 -1
- package/src/internals/middlewares.ts +3 -2
- package/src/internals/procedure.ts +173 -66
- package/src/router.ts +172 -52
- package/src/subscription.ts +1 -1
- package/ws/dist/trpc-server-ws.cjs.dev.js +2 -2
- package/ws/dist/trpc-server-ws.cjs.prod.js +2 -2
- package/ws/dist/trpc-server-ws.esm.js +2 -2
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
path,
|
|
7
|
-
input
|
|
8
|
-
} = opts;
|
|
9
|
-
const caller = opts.router.createCaller(opts.ctx);
|
|
10
|
-
|
|
11
|
-
if (type === 'query') {
|
|
12
|
-
return caller.query(path, input);
|
|
3
|
+
function getMessageFromUnkownError(err, fallback) {
|
|
4
|
+
if (typeof err === 'string') {
|
|
5
|
+
return err;
|
|
13
6
|
}
|
|
14
7
|
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
8
|
+
if (err instanceof Error && typeof err.message === 'string') {
|
|
9
|
+
return err.message;
|
|
17
10
|
}
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
function getErrorFromUnknown(cause) {
|
|
15
|
+
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
16
|
+
// ref https://github.com/trpc/trpc/issues/331
|
|
17
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
18
|
+
return cause;
|
|
22
19
|
}
|
|
23
|
-
/* istanbul ignore next */
|
|
24
20
|
|
|
21
|
+
const err = new TRPCError({
|
|
22
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
23
|
+
cause
|
|
24
|
+
}); // take stack trace from cause
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
if (cause instanceof Error) {
|
|
27
|
+
err.stack = cause.stack;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return err;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
class TRPCError extends Error {
|
|
@@ -52,34 +56,30 @@ class TRPCError extends Error {
|
|
|
52
56
|
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
async function callProcedure(opts) {
|
|
60
|
+
const {
|
|
61
|
+
type,
|
|
62
|
+
path,
|
|
63
|
+
input
|
|
64
|
+
} = opts;
|
|
65
|
+
const caller = opts.router.createCaller(opts.ctx);
|
|
59
66
|
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
67
|
+
if (type === 'query') {
|
|
68
|
+
return caller.query(path, input);
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function getErrorFromUnknown(cause) {
|
|
67
|
-
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
68
|
-
// ref https://github.com/trpc/trpc/issues/331
|
|
69
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
70
|
-
return cause;
|
|
71
|
+
if (type === 'mutation') {
|
|
72
|
+
return caller.mutation(path, input);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}); // take stack trace from cause
|
|
77
|
-
|
|
78
|
-
if (cause instanceof Error) {
|
|
79
|
-
err.stack = cause.stack;
|
|
75
|
+
if (type === 'subscription') {
|
|
76
|
+
const sub = await caller.subscription(path, input);
|
|
77
|
+
return sub;
|
|
80
78
|
}
|
|
79
|
+
/* istanbul ignore next */
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
|
|
82
|
+
throw new Error(`Unknown procedure type ${type}`);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function transformTRPCResponseItem(router, item) {
|
package/dist/{transformTRPCResponse-f73dc4a2.esm.js → transformTRPCResponse-45c225c3.esm.js}
RENAMED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
path,
|
|
5
|
-
input
|
|
6
|
-
} = opts;
|
|
7
|
-
const caller = opts.router.createCaller(opts.ctx);
|
|
8
|
-
|
|
9
|
-
if (type === 'query') {
|
|
10
|
-
return caller.query(path, input);
|
|
1
|
+
function getMessageFromUnkownError(err, fallback) {
|
|
2
|
+
if (typeof err === 'string') {
|
|
3
|
+
return err;
|
|
11
4
|
}
|
|
12
5
|
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
6
|
+
if (err instanceof Error && typeof err.message === 'string') {
|
|
7
|
+
return err.message;
|
|
15
8
|
}
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
return fallback;
|
|
11
|
+
}
|
|
12
|
+
function getErrorFromUnknown(cause) {
|
|
13
|
+
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
14
|
+
// ref https://github.com/trpc/trpc/issues/331
|
|
15
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
16
|
+
return cause;
|
|
20
17
|
}
|
|
21
|
-
/* istanbul ignore next */
|
|
22
18
|
|
|
19
|
+
const err = new TRPCError({
|
|
20
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
21
|
+
cause
|
|
22
|
+
}); // take stack trace from cause
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
if (cause instanceof Error) {
|
|
25
|
+
err.stack = cause.stack;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return err;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
class TRPCError extends Error {
|
|
@@ -50,34 +54,30 @@ class TRPCError extends Error {
|
|
|
50
54
|
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
async function callProcedure(opts) {
|
|
58
|
+
const {
|
|
59
|
+
type,
|
|
60
|
+
path,
|
|
61
|
+
input
|
|
62
|
+
} = opts;
|
|
63
|
+
const caller = opts.router.createCaller(opts.ctx);
|
|
57
64
|
|
|
58
|
-
if (
|
|
59
|
-
return
|
|
65
|
+
if (type === 'query') {
|
|
66
|
+
return caller.query(path, input);
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
function getErrorFromUnknown(cause) {
|
|
65
|
-
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
66
|
-
// ref https://github.com/trpc/trpc/issues/331
|
|
67
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
68
|
-
return cause;
|
|
69
|
+
if (type === 'mutation') {
|
|
70
|
+
return caller.mutation(path, input);
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}); // take stack trace from cause
|
|
75
|
-
|
|
76
|
-
if (cause instanceof Error) {
|
|
77
|
-
err.stack = cause.stack;
|
|
73
|
+
if (type === 'subscription') {
|
|
74
|
+
const sub = await caller.subscription(path, input);
|
|
75
|
+
return sub;
|
|
78
76
|
}
|
|
77
|
+
/* istanbul ignore next */
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
|
|
80
|
+
throw new Error(`Unknown procedure type ${type}`);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
function transformTRPCResponseItem(router, item) {
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
path,
|
|
7
|
-
input
|
|
8
|
-
} = opts;
|
|
9
|
-
const caller = opts.router.createCaller(opts.ctx);
|
|
10
|
-
|
|
11
|
-
if (type === 'query') {
|
|
12
|
-
return caller.query(path, input);
|
|
3
|
+
function getMessageFromUnkownError(err, fallback) {
|
|
4
|
+
if (typeof err === 'string') {
|
|
5
|
+
return err;
|
|
13
6
|
}
|
|
14
7
|
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
8
|
+
if (err instanceof Error && typeof err.message === 'string') {
|
|
9
|
+
return err.message;
|
|
17
10
|
}
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
function getErrorFromUnknown(cause) {
|
|
15
|
+
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
16
|
+
// ref https://github.com/trpc/trpc/issues/331
|
|
17
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
18
|
+
return cause;
|
|
22
19
|
}
|
|
23
|
-
/* istanbul ignore next */
|
|
24
20
|
|
|
21
|
+
const err = new TRPCError({
|
|
22
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
23
|
+
cause
|
|
24
|
+
}); // take stack trace from cause
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
if (cause instanceof Error) {
|
|
27
|
+
err.stack = cause.stack;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return err;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
class TRPCError extends Error {
|
|
@@ -52,34 +56,30 @@ class TRPCError extends Error {
|
|
|
52
56
|
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
async function callProcedure(opts) {
|
|
60
|
+
const {
|
|
61
|
+
type,
|
|
62
|
+
path,
|
|
63
|
+
input
|
|
64
|
+
} = opts;
|
|
65
|
+
const caller = opts.router.createCaller(opts.ctx);
|
|
59
66
|
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
67
|
+
if (type === 'query') {
|
|
68
|
+
return caller.query(path, input);
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function getErrorFromUnknown(cause) {
|
|
67
|
-
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
68
|
-
// ref https://github.com/trpc/trpc/issues/331
|
|
69
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
70
|
-
return cause;
|
|
71
|
+
if (type === 'mutation') {
|
|
72
|
+
return caller.mutation(path, input);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}); // take stack trace from cause
|
|
77
|
-
|
|
78
|
-
if (cause instanceof Error) {
|
|
79
|
-
err.stack = cause.stack;
|
|
75
|
+
if (type === 'subscription') {
|
|
76
|
+
const sub = await caller.subscription(path, input);
|
|
77
|
+
return sub;
|
|
80
78
|
}
|
|
79
|
+
/* istanbul ignore next */
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
|
|
82
|
+
throw new Error(`Unknown procedure type ${type}`);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function transformTRPCResponseItem(router, item) {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var resolveHTTPResponse = require('./resolveHTTPResponse-
|
|
6
|
-
var subscription = require('./subscription-
|
|
7
|
-
var transformTRPCResponse = require('./transformTRPCResponse-
|
|
5
|
+
var resolveHTTPResponse = require('./resolveHTTPResponse-780f5cab.cjs.dev.js');
|
|
6
|
+
var subscription = require('./subscription-7de48383.cjs.dev.js');
|
|
7
|
+
var transformTRPCResponse = require('./transformTRPCResponse-c654ea92.cjs.dev.js');
|
|
8
8
|
var adapters_standalone_dist_trpcServerAdaptersStandalone = require('../adapters/standalone/dist/trpc-server-adapters-standalone.cjs.dev.js');
|
|
9
|
-
var nodeHTTPRequestHandler = require('./nodeHTTPRequestHandler-
|
|
9
|
+
var nodeHTTPRequestHandler = require('./nodeHTTPRequestHandler-620da2b7.cjs.dev.js');
|
|
10
10
|
var codes = require('./codes-33cef953.cjs.dev.js');
|
|
11
11
|
require('events');
|
|
12
12
|
require('http');
|
|
@@ -32,6 +32,7 @@ const createHttpHandler = adapters_standalone_dist_trpcServerAdaptersStandalone.
|
|
|
32
32
|
/**
|
|
33
33
|
* @deprecated use `nodeHTTPRequestHandler` from `@trpc/server/adapters/node-http`
|
|
34
34
|
*/
|
|
35
|
+
|
|
35
36
|
const requestHandler = nodeHTTPRequestHandler.nodeHTTPRequestHandler;
|
|
36
37
|
/**
|
|
37
38
|
* @deprecated use `NodeHTTPCreateContextFn` from `@trpc/server/adapters/node-http`
|
|
@@ -61,31 +62,31 @@ async function wrapCallSafe(fn) {
|
|
|
61
62
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
62
63
|
resolveHTTPResponse.assertNotBrowser();
|
|
63
64
|
|
|
64
|
-
function getParseFn(
|
|
65
|
-
const parser =
|
|
65
|
+
function getParseFn(procedureParser) {
|
|
66
|
+
const parser = procedureParser;
|
|
66
67
|
|
|
67
68
|
if (typeof parser === 'function') {
|
|
68
|
-
//
|
|
69
|
+
// ProcedureParserCustomValidatorEsque
|
|
69
70
|
return parser;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
if (typeof parser.parseAsync === 'function') {
|
|
73
|
-
//
|
|
74
|
+
// ProcedureParserZodEsque
|
|
74
75
|
return parser.parseAsync.bind(parser);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
if (typeof parser.parse === 'function') {
|
|
78
|
-
//
|
|
79
|
+
// ProcedureParserZodEsque
|
|
79
80
|
return parser.parse.bind(parser);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
if (typeof parser.validateSync === 'function') {
|
|
83
|
-
//
|
|
84
|
+
// ProcedureParserYupEsque
|
|
84
85
|
return parser.validateSync.bind(parser);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
if (typeof parser.create === 'function') {
|
|
88
|
-
//
|
|
89
|
+
// ProcedureParserSuperstructEsque
|
|
89
90
|
return parser.create.bind(parser);
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -101,16 +102,22 @@ class Procedure {
|
|
|
101
102
|
this.middlewares = void 0;
|
|
102
103
|
this.resolver = void 0;
|
|
103
104
|
this.inputParser = void 0;
|
|
104
|
-
this.
|
|
105
|
+
this.parseInputFn = void 0;
|
|
106
|
+
this.outputParser = void 0;
|
|
107
|
+
this.parseOutputFn = void 0;
|
|
108
|
+
this.meta = void 0;
|
|
105
109
|
this.middlewares = opts.middlewares;
|
|
106
110
|
this.resolver = opts.resolver;
|
|
107
111
|
this.inputParser = opts.inputParser;
|
|
108
|
-
this.
|
|
112
|
+
this.parseInputFn = getParseFn(this.inputParser);
|
|
113
|
+
this.outputParser = opts.outputParser;
|
|
114
|
+
this.parseOutputFn = getParseFn(this.outputParser);
|
|
115
|
+
this.meta = opts.meta;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
async parseInput(rawInput) {
|
|
112
119
|
try {
|
|
113
|
-
return await this.
|
|
120
|
+
return await this.parseInputFn(rawInput);
|
|
114
121
|
} catch (cause) {
|
|
115
122
|
throw new transformTRPCResponse.TRPCError({
|
|
116
123
|
code: 'BAD_REQUEST',
|
|
@@ -118,8 +125,20 @@ class Procedure {
|
|
|
118
125
|
});
|
|
119
126
|
}
|
|
120
127
|
}
|
|
128
|
+
|
|
129
|
+
async parseOutput(rawOutput) {
|
|
130
|
+
try {
|
|
131
|
+
return await this.parseOutputFn(rawOutput);
|
|
132
|
+
} catch (cause) {
|
|
133
|
+
throw new transformTRPCResponse.TRPCError({
|
|
134
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
135
|
+
cause,
|
|
136
|
+
message: 'Output validation failed'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
121
140
|
/**
|
|
122
|
-
* Trigger middlewares in order, parse raw input &
|
|
141
|
+
* Trigger middlewares in order, parse raw input, call resolver & parse raw output
|
|
123
142
|
* @internal
|
|
124
143
|
*/
|
|
125
144
|
|
|
@@ -130,10 +149,11 @@ class Procedure {
|
|
|
130
149
|
ctx
|
|
131
150
|
}) => {
|
|
132
151
|
const input = await this.parseInput(opts.rawInput);
|
|
133
|
-
const
|
|
152
|
+
const rawOutput = await this.resolver({ ...opts,
|
|
134
153
|
ctx,
|
|
135
154
|
input
|
|
136
155
|
});
|
|
156
|
+
const data = await this.parseOutput(rawOutput);
|
|
137
157
|
return {
|
|
138
158
|
marker: middlewareMarker,
|
|
139
159
|
ok: true,
|
|
@@ -149,6 +169,7 @@ class Procedure {
|
|
|
149
169
|
type: opts.type,
|
|
150
170
|
path: opts.path,
|
|
151
171
|
rawInput: opts.rawInput,
|
|
172
|
+
meta: this.meta,
|
|
152
173
|
next: nextFns[index + 1]
|
|
153
174
|
}));
|
|
154
175
|
|
|
@@ -190,7 +211,9 @@ class Procedure {
|
|
|
190
211
|
const instance = new Constructor({
|
|
191
212
|
middlewares: [...middlewares, ...this.middlewares],
|
|
192
213
|
resolver: this.resolver,
|
|
193
|
-
inputParser: this.inputParser
|
|
214
|
+
inputParser: this.inputParser,
|
|
215
|
+
outputParser: this.outputParser,
|
|
216
|
+
meta: this.meta
|
|
194
217
|
});
|
|
195
218
|
return instance;
|
|
196
219
|
}
|
|
@@ -207,10 +230,13 @@ function createProcedure(opts) {
|
|
|
207
230
|
|
|
208
231
|
return undefined;
|
|
209
232
|
};
|
|
233
|
+
const outputParser = 'output' in opts && opts.output ? opts.output : output => output;
|
|
210
234
|
return new Procedure({
|
|
211
235
|
inputParser: inputParser,
|
|
212
236
|
resolver: opts.resolve,
|
|
213
|
-
middlewares: []
|
|
237
|
+
middlewares: [],
|
|
238
|
+
outputParser: outputParser,
|
|
239
|
+
meta: opts.meta
|
|
214
240
|
});
|
|
215
241
|
}
|
|
216
242
|
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var resolveHTTPResponse = require('./resolveHTTPResponse-
|
|
6
|
-
var subscription = require('./subscription-
|
|
7
|
-
var transformTRPCResponse = require('./transformTRPCResponse-
|
|
5
|
+
var resolveHTTPResponse = require('./resolveHTTPResponse-d1d2695d.cjs.prod.js');
|
|
6
|
+
var subscription = require('./subscription-f03bec71.cjs.prod.js');
|
|
7
|
+
var transformTRPCResponse = require('./transformTRPCResponse-1e125b28.cjs.prod.js');
|
|
8
8
|
var adapters_standalone_dist_trpcServerAdaptersStandalone = require('../adapters/standalone/dist/trpc-server-adapters-standalone.cjs.prod.js');
|
|
9
|
-
var nodeHTTPRequestHandler = require('./nodeHTTPRequestHandler-
|
|
9
|
+
var nodeHTTPRequestHandler = require('./nodeHTTPRequestHandler-9cfa7523.cjs.prod.js');
|
|
10
10
|
var codes = require('./codes-e0df67c4.cjs.prod.js');
|
|
11
11
|
require('events');
|
|
12
12
|
require('http');
|
|
@@ -32,6 +32,7 @@ const createHttpHandler = adapters_standalone_dist_trpcServerAdaptersStandalone.
|
|
|
32
32
|
/**
|
|
33
33
|
* @deprecated use `nodeHTTPRequestHandler` from `@trpc/server/adapters/node-http`
|
|
34
34
|
*/
|
|
35
|
+
|
|
35
36
|
const requestHandler = nodeHTTPRequestHandler.nodeHTTPRequestHandler;
|
|
36
37
|
/**
|
|
37
38
|
* @deprecated use `NodeHTTPCreateContextFn` from `@trpc/server/adapters/node-http`
|
|
@@ -61,31 +62,31 @@ async function wrapCallSafe(fn) {
|
|
|
61
62
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
62
63
|
resolveHTTPResponse.assertNotBrowser();
|
|
63
64
|
|
|
64
|
-
function getParseFn(
|
|
65
|
-
const parser =
|
|
65
|
+
function getParseFn(procedureParser) {
|
|
66
|
+
const parser = procedureParser;
|
|
66
67
|
|
|
67
68
|
if (typeof parser === 'function') {
|
|
68
|
-
//
|
|
69
|
+
// ProcedureParserCustomValidatorEsque
|
|
69
70
|
return parser;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
if (typeof parser.parseAsync === 'function') {
|
|
73
|
-
//
|
|
74
|
+
// ProcedureParserZodEsque
|
|
74
75
|
return parser.parseAsync.bind(parser);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
if (typeof parser.parse === 'function') {
|
|
78
|
-
//
|
|
79
|
+
// ProcedureParserZodEsque
|
|
79
80
|
return parser.parse.bind(parser);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
if (typeof parser.validateSync === 'function') {
|
|
83
|
-
//
|
|
84
|
+
// ProcedureParserYupEsque
|
|
84
85
|
return parser.validateSync.bind(parser);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
if (typeof parser.create === 'function') {
|
|
88
|
-
//
|
|
89
|
+
// ProcedureParserSuperstructEsque
|
|
89
90
|
return parser.create.bind(parser);
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -101,16 +102,22 @@ class Procedure {
|
|
|
101
102
|
this.middlewares = void 0;
|
|
102
103
|
this.resolver = void 0;
|
|
103
104
|
this.inputParser = void 0;
|
|
104
|
-
this.
|
|
105
|
+
this.parseInputFn = void 0;
|
|
106
|
+
this.outputParser = void 0;
|
|
107
|
+
this.parseOutputFn = void 0;
|
|
108
|
+
this.meta = void 0;
|
|
105
109
|
this.middlewares = opts.middlewares;
|
|
106
110
|
this.resolver = opts.resolver;
|
|
107
111
|
this.inputParser = opts.inputParser;
|
|
108
|
-
this.
|
|
112
|
+
this.parseInputFn = getParseFn(this.inputParser);
|
|
113
|
+
this.outputParser = opts.outputParser;
|
|
114
|
+
this.parseOutputFn = getParseFn(this.outputParser);
|
|
115
|
+
this.meta = opts.meta;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
async parseInput(rawInput) {
|
|
112
119
|
try {
|
|
113
|
-
return await this.
|
|
120
|
+
return await this.parseInputFn(rawInput);
|
|
114
121
|
} catch (cause) {
|
|
115
122
|
throw new transformTRPCResponse.TRPCError({
|
|
116
123
|
code: 'BAD_REQUEST',
|
|
@@ -118,8 +125,20 @@ class Procedure {
|
|
|
118
125
|
});
|
|
119
126
|
}
|
|
120
127
|
}
|
|
128
|
+
|
|
129
|
+
async parseOutput(rawOutput) {
|
|
130
|
+
try {
|
|
131
|
+
return await this.parseOutputFn(rawOutput);
|
|
132
|
+
} catch (cause) {
|
|
133
|
+
throw new transformTRPCResponse.TRPCError({
|
|
134
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
135
|
+
cause,
|
|
136
|
+
message: 'Output validation failed'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
121
140
|
/**
|
|
122
|
-
* Trigger middlewares in order, parse raw input &
|
|
141
|
+
* Trigger middlewares in order, parse raw input, call resolver & parse raw output
|
|
123
142
|
* @internal
|
|
124
143
|
*/
|
|
125
144
|
|
|
@@ -130,10 +149,11 @@ class Procedure {
|
|
|
130
149
|
ctx
|
|
131
150
|
}) => {
|
|
132
151
|
const input = await this.parseInput(opts.rawInput);
|
|
133
|
-
const
|
|
152
|
+
const rawOutput = await this.resolver({ ...opts,
|
|
134
153
|
ctx,
|
|
135
154
|
input
|
|
136
155
|
});
|
|
156
|
+
const data = await this.parseOutput(rawOutput);
|
|
137
157
|
return {
|
|
138
158
|
marker: middlewareMarker,
|
|
139
159
|
ok: true,
|
|
@@ -149,6 +169,7 @@ class Procedure {
|
|
|
149
169
|
type: opts.type,
|
|
150
170
|
path: opts.path,
|
|
151
171
|
rawInput: opts.rawInput,
|
|
172
|
+
meta: this.meta,
|
|
152
173
|
next: nextFns[index + 1]
|
|
153
174
|
}));
|
|
154
175
|
|
|
@@ -190,7 +211,9 @@ class Procedure {
|
|
|
190
211
|
const instance = new Constructor({
|
|
191
212
|
middlewares: [...middlewares, ...this.middlewares],
|
|
192
213
|
resolver: this.resolver,
|
|
193
|
-
inputParser: this.inputParser
|
|
214
|
+
inputParser: this.inputParser,
|
|
215
|
+
outputParser: this.outputParser,
|
|
216
|
+
meta: this.meta
|
|
194
217
|
});
|
|
195
218
|
return instance;
|
|
196
219
|
}
|
|
@@ -207,10 +230,13 @@ function createProcedure(opts) {
|
|
|
207
230
|
|
|
208
231
|
return undefined;
|
|
209
232
|
};
|
|
233
|
+
const outputParser = 'output' in opts && opts.output ? opts.output : output => output;
|
|
210
234
|
return new Procedure({
|
|
211
235
|
inputParser: inputParser,
|
|
212
236
|
resolver: opts.resolve,
|
|
213
|
-
middlewares: []
|
|
237
|
+
middlewares: [],
|
|
238
|
+
outputParser: outputParser,
|
|
239
|
+
meta: opts.meta
|
|
214
240
|
});
|
|
215
241
|
}
|
|
216
242
|
|