@trpc/server 10.0.0-alpha.17 → 10.0.0-alpha.18
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.d.ts +1 -11
- package/adapters/express/dist/trpc-server-adapters-express.cjs.dev.js +23 -0
- package/adapters/express/dist/trpc-server-adapters-express.cjs.js +6 -15
- package/adapters/express/dist/trpc-server-adapters-express.cjs.prod.js +23 -0
- package/adapters/express/dist/trpc-server-adapters-express.esm.js +19 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.d.ts +1 -11
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +102 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.js +6 -15
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +102 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +97 -0
- package/adapters/next/dist/trpc-server-adapters-next.cjs.d.ts +1 -11
- package/adapters/next/dist/trpc-server-adapters-next.cjs.dev.js +56 -0
- package/adapters/next/dist/trpc-server-adapters-next.cjs.js +6 -15
- package/adapters/next/dist/trpc-server-adapters-next.cjs.prod.js +56 -0
- package/adapters/next/dist/trpc-server-adapters-next.esm.js +52 -0
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.d.ts +1 -11
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.dev.js +13 -0
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.js +6 -15
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.prod.js +13 -0
- package/adapters/node-http/dist/trpc-server-adapters-node-http.esm.js +5 -0
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.d.ts +1 -11
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.dev.js +46 -0
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.js +6 -15
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.prod.js +46 -0
- package/adapters/standalone/dist/trpc-server-adapters-standalone.esm.js +36 -0
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.d.ts +1 -11
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.dev.js +347 -0
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.js +6 -15
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.prod.js +347 -0
- package/adapters/ws/dist/trpc-server-adapters-ws.esm.js +343 -0
- package/package.json +2 -2
- package/rpc/dist/trpc-server-rpc.cjs.d.ts +1 -11
- package/rpc/dist/trpc-server-rpc.cjs.dev.js +10 -0
- package/rpc/dist/trpc-server-rpc.cjs.js +6 -15
- package/rpc/dist/trpc-server-rpc.cjs.prod.js +10 -0
- package/rpc/dist/trpc-server-rpc.esm.js +1 -0
- package/ws/dist/trpc-server-ws.cjs.d.ts +1 -11
- package/ws/dist/trpc-server-ws.cjs.dev.js +15 -0
- package/ws/dist/trpc-server-ws.cjs.js +6 -15
- package/ws/dist/trpc-server-ws.cjs.prod.js +15 -0
- package/ws/dist/trpc-server-ws.esm.js +11 -0
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../../../src/adapters/express";
|
|
1
|
+
export * from "../../../dist/declarations/src/adapters/express";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var nodeHTTPRequestHandler = require('../../../dist/nodeHTTPRequestHandler-2cc444d8.cjs.dev.js');
|
|
6
|
+
require('url');
|
|
7
|
+
require('../../../dist/resolveHTTPResponse-3867844c.cjs.dev.js');
|
|
8
|
+
require('../../../dist/transformTRPCResponse-8248515e.cjs.dev.js');
|
|
9
|
+
require('../../../dist/codes-33cef953.cjs.dev.js');
|
|
10
|
+
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
function createExpressMiddleware(opts) {
|
|
13
|
+
return (req, res) => {
|
|
14
|
+
const endpoint = req.path.slice(1);
|
|
15
|
+
nodeHTTPRequestHandler.nodeHTTPRequestHandler({ ...opts,
|
|
16
|
+
req,
|
|
17
|
+
res,
|
|
18
|
+
path: endpoint
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.createExpressMiddleware = createExpressMiddleware;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./trpc-server-adapters-express.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./trpc-server-adapters-express.cjs.dev.js");
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var nodeHTTPRequestHandler = require('../../../dist/nodeHTTPRequestHandler-8ddacc19.cjs.prod.js');
|
|
6
|
+
require('url');
|
|
7
|
+
require('../../../dist/resolveHTTPResponse-562c3d62.cjs.prod.js');
|
|
8
|
+
require('../../../dist/transformTRPCResponse-dcbf66c5.cjs.prod.js');
|
|
9
|
+
require('../../../dist/codes-e0df67c4.cjs.prod.js');
|
|
10
|
+
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
function createExpressMiddleware(opts) {
|
|
13
|
+
return (req, res) => {
|
|
14
|
+
const endpoint = req.path.slice(1);
|
|
15
|
+
nodeHTTPRequestHandler.nodeHTTPRequestHandler({ ...opts,
|
|
16
|
+
req,
|
|
17
|
+
res,
|
|
18
|
+
path: endpoint
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.createExpressMiddleware = createExpressMiddleware;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { n as nodeHTTPRequestHandler } from '../../../dist/nodeHTTPRequestHandler-d00c1126.esm.js';
|
|
2
|
+
import 'url';
|
|
3
|
+
import '../../../dist/resolveHTTPResponse-85f3f5df.esm.js';
|
|
4
|
+
import '../../../dist/transformTRPCResponse-f73dc4a2.esm.js';
|
|
5
|
+
import '../../../dist/codes-fe07bf82.esm.js';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
function createExpressMiddleware(opts) {
|
|
9
|
+
return (req, res) => {
|
|
10
|
+
const endpoint = req.path.slice(1);
|
|
11
|
+
nodeHTTPRequestHandler({ ...opts,
|
|
12
|
+
req,
|
|
13
|
+
res,
|
|
14
|
+
path: endpoint
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { createExpressMiddleware };
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../../../src/adapters/fastify/index";
|
|
1
|
+
export * from "../../../dist/declarations/src/adapters/fastify/index";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var url = require('url');
|
|
6
|
+
var resolveHTTPResponse = require('../../../dist/resolveHTTPResponse-3867844c.cjs.dev.js');
|
|
7
|
+
var adapters_ws_dist_trpcServerAdaptersWs = require('../../ws/dist/trpc-server-adapters-ws.cjs.dev.js');
|
|
8
|
+
require('../../../dist/transformTRPCResponse-8248515e.cjs.dev.js');
|
|
9
|
+
require('../../../dist/codes-33cef953.cjs.dev.js');
|
|
10
|
+
require('../../../dist/subscription-b8831081.cjs.dev.js');
|
|
11
|
+
require('events');
|
|
12
|
+
|
|
13
|
+
resolveHTTPResponse.assertNotBrowser();
|
|
14
|
+
async function fastifyRequestHandler(opts) {
|
|
15
|
+
var _opts$req$body;
|
|
16
|
+
|
|
17
|
+
const createContext = async function _createContext() {
|
|
18
|
+
var _opts$createContext;
|
|
19
|
+
|
|
20
|
+
return (_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, opts);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const query = opts.req.query ? new url.URLSearchParams(opts.req.query) : new url.URLSearchParams(opts.req.url.split('?')[1]);
|
|
24
|
+
const req = {
|
|
25
|
+
query,
|
|
26
|
+
method: opts.req.method,
|
|
27
|
+
headers: opts.req.headers,
|
|
28
|
+
body: (_opts$req$body = opts.req.body) !== null && _opts$req$body !== void 0 ? _opts$req$body : 'null'
|
|
29
|
+
};
|
|
30
|
+
const result = await resolveHTTPResponse.resolveHTTPResponse({
|
|
31
|
+
req,
|
|
32
|
+
createContext,
|
|
33
|
+
path: opts.path,
|
|
34
|
+
router: opts.router,
|
|
35
|
+
batching: opts.batching,
|
|
36
|
+
responseMeta: opts.responseMeta,
|
|
37
|
+
|
|
38
|
+
onError(o) {
|
|
39
|
+
var _opts$onError;
|
|
40
|
+
|
|
41
|
+
opts === null || opts === void 0 ? void 0 : (_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, { ...o,
|
|
42
|
+
req: opts.req
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
const {
|
|
48
|
+
res
|
|
49
|
+
} = opts;
|
|
50
|
+
|
|
51
|
+
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
52
|
+
res.statusCode = result.status;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const [key, value] of Object.entries((_result$headers = result.headers) !== null && _result$headers !== void 0 ? _result$headers : {})) {
|
|
56
|
+
var _result$headers;
|
|
57
|
+
|
|
58
|
+
if (typeof value === 'undefined') {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
res.header(key, value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
res.send(result.body);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// <reference types="fastify-websocket" />
|
|
69
|
+
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
70
|
+
var _opts$prefix;
|
|
71
|
+
|
|
72
|
+
fastify.addContentTypeParser('application/json', {
|
|
73
|
+
parseAs: 'string'
|
|
74
|
+
}, function (_, body, _done) {
|
|
75
|
+
_done(null, body);
|
|
76
|
+
});
|
|
77
|
+
fastify.all(`${(_opts$prefix = opts.prefix) !== null && _opts$prefix !== void 0 ? _opts$prefix : ''}/:path`, (req, res) => {
|
|
78
|
+
const path = req.params.path;
|
|
79
|
+
fastifyRequestHandler({ ...opts.trpcOptions,
|
|
80
|
+
req,
|
|
81
|
+
res,
|
|
82
|
+
path
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (opts.useWSS) {
|
|
87
|
+
var _opts$prefix2;
|
|
88
|
+
|
|
89
|
+
adapters_ws_dist_trpcServerAdaptersWs.applyWSSHandler({ ...opts.trpcOptions,
|
|
90
|
+
wss: fastify.websocketServer
|
|
91
|
+
}); // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
92
|
+
|
|
93
|
+
fastify.get((_opts$prefix2 = opts.prefix) !== null && _opts$prefix2 !== void 0 ? _opts$prefix2 : '/', {
|
|
94
|
+
websocket: true
|
|
95
|
+
}, () => {});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
done();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
102
|
+
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./trpc-server-adapters-fastify.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./trpc-server-adapters-fastify.cjs.dev.js");
|
|
7
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var url = require('url');
|
|
6
|
+
var resolveHTTPResponse = require('../../../dist/resolveHTTPResponse-562c3d62.cjs.prod.js');
|
|
7
|
+
var adapters_ws_dist_trpcServerAdaptersWs = require('../../ws/dist/trpc-server-adapters-ws.cjs.prod.js');
|
|
8
|
+
require('../../../dist/transformTRPCResponse-dcbf66c5.cjs.prod.js');
|
|
9
|
+
require('../../../dist/codes-e0df67c4.cjs.prod.js');
|
|
10
|
+
require('../../../dist/subscription-c2e0bfbc.cjs.prod.js');
|
|
11
|
+
require('events');
|
|
12
|
+
|
|
13
|
+
resolveHTTPResponse.assertNotBrowser();
|
|
14
|
+
async function fastifyRequestHandler(opts) {
|
|
15
|
+
var _opts$req$body;
|
|
16
|
+
|
|
17
|
+
const createContext = async function _createContext() {
|
|
18
|
+
var _opts$createContext;
|
|
19
|
+
|
|
20
|
+
return (_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, opts);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const query = opts.req.query ? new url.URLSearchParams(opts.req.query) : new url.URLSearchParams(opts.req.url.split('?')[1]);
|
|
24
|
+
const req = {
|
|
25
|
+
query,
|
|
26
|
+
method: opts.req.method,
|
|
27
|
+
headers: opts.req.headers,
|
|
28
|
+
body: (_opts$req$body = opts.req.body) !== null && _opts$req$body !== void 0 ? _opts$req$body : 'null'
|
|
29
|
+
};
|
|
30
|
+
const result = await resolveHTTPResponse.resolveHTTPResponse({
|
|
31
|
+
req,
|
|
32
|
+
createContext,
|
|
33
|
+
path: opts.path,
|
|
34
|
+
router: opts.router,
|
|
35
|
+
batching: opts.batching,
|
|
36
|
+
responseMeta: opts.responseMeta,
|
|
37
|
+
|
|
38
|
+
onError(o) {
|
|
39
|
+
var _opts$onError;
|
|
40
|
+
|
|
41
|
+
opts === null || opts === void 0 ? void 0 : (_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, { ...o,
|
|
42
|
+
req: opts.req
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
const {
|
|
48
|
+
res
|
|
49
|
+
} = opts;
|
|
50
|
+
|
|
51
|
+
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
52
|
+
res.statusCode = result.status;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const [key, value] of Object.entries((_result$headers = result.headers) !== null && _result$headers !== void 0 ? _result$headers : {})) {
|
|
56
|
+
var _result$headers;
|
|
57
|
+
|
|
58
|
+
if (typeof value === 'undefined') {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
res.header(key, value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
res.send(result.body);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// <reference types="fastify-websocket" />
|
|
69
|
+
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
70
|
+
var _opts$prefix;
|
|
71
|
+
|
|
72
|
+
fastify.addContentTypeParser('application/json', {
|
|
73
|
+
parseAs: 'string'
|
|
74
|
+
}, function (_, body, _done) {
|
|
75
|
+
_done(null, body);
|
|
76
|
+
});
|
|
77
|
+
fastify.all(`${(_opts$prefix = opts.prefix) !== null && _opts$prefix !== void 0 ? _opts$prefix : ''}/:path`, (req, res) => {
|
|
78
|
+
const path = req.params.path;
|
|
79
|
+
fastifyRequestHandler({ ...opts.trpcOptions,
|
|
80
|
+
req,
|
|
81
|
+
res,
|
|
82
|
+
path
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (opts.useWSS) {
|
|
87
|
+
var _opts$prefix2;
|
|
88
|
+
|
|
89
|
+
adapters_ws_dist_trpcServerAdaptersWs.applyWSSHandler({ ...opts.trpcOptions,
|
|
90
|
+
wss: fastify.websocketServer
|
|
91
|
+
}); // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
92
|
+
|
|
93
|
+
fastify.get((_opts$prefix2 = opts.prefix) !== null && _opts$prefix2 !== void 0 ? _opts$prefix2 : '/', {
|
|
94
|
+
websocket: true
|
|
95
|
+
}, () => {});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
done();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
102
|
+
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { URLSearchParams } from 'url';
|
|
2
|
+
import { a as assertNotBrowser, r as resolveHTTPResponse } from '../../../dist/resolveHTTPResponse-85f3f5df.esm.js';
|
|
3
|
+
import { applyWSSHandler } from '../../ws/dist/trpc-server-adapters-ws.esm.js';
|
|
4
|
+
import '../../../dist/transformTRPCResponse-f73dc4a2.esm.js';
|
|
5
|
+
import '../../../dist/codes-fe07bf82.esm.js';
|
|
6
|
+
import '../../../dist/subscription-fbda2888.esm.js';
|
|
7
|
+
import 'events';
|
|
8
|
+
|
|
9
|
+
assertNotBrowser();
|
|
10
|
+
async function fastifyRequestHandler(opts) {
|
|
11
|
+
var _opts$req$body;
|
|
12
|
+
|
|
13
|
+
const createContext = async function _createContext() {
|
|
14
|
+
var _opts$createContext;
|
|
15
|
+
|
|
16
|
+
return (_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, opts);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
20
|
+
const req = {
|
|
21
|
+
query,
|
|
22
|
+
method: opts.req.method,
|
|
23
|
+
headers: opts.req.headers,
|
|
24
|
+
body: (_opts$req$body = opts.req.body) !== null && _opts$req$body !== void 0 ? _opts$req$body : 'null'
|
|
25
|
+
};
|
|
26
|
+
const result = await resolveHTTPResponse({
|
|
27
|
+
req,
|
|
28
|
+
createContext,
|
|
29
|
+
path: opts.path,
|
|
30
|
+
router: opts.router,
|
|
31
|
+
batching: opts.batching,
|
|
32
|
+
responseMeta: opts.responseMeta,
|
|
33
|
+
|
|
34
|
+
onError(o) {
|
|
35
|
+
var _opts$onError;
|
|
36
|
+
|
|
37
|
+
opts === null || opts === void 0 ? void 0 : (_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, { ...o,
|
|
38
|
+
req: opts.req
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
});
|
|
43
|
+
const {
|
|
44
|
+
res
|
|
45
|
+
} = opts;
|
|
46
|
+
|
|
47
|
+
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
48
|
+
res.statusCode = result.status;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const [key, value] of Object.entries((_result$headers = result.headers) !== null && _result$headers !== void 0 ? _result$headers : {})) {
|
|
52
|
+
var _result$headers;
|
|
53
|
+
|
|
54
|
+
if (typeof value === 'undefined') {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
res.header(key, value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
res.send(result.body);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// <reference types="fastify-websocket" />
|
|
65
|
+
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
66
|
+
var _opts$prefix;
|
|
67
|
+
|
|
68
|
+
fastify.addContentTypeParser('application/json', {
|
|
69
|
+
parseAs: 'string'
|
|
70
|
+
}, function (_, body, _done) {
|
|
71
|
+
_done(null, body);
|
|
72
|
+
});
|
|
73
|
+
fastify.all(`${(_opts$prefix = opts.prefix) !== null && _opts$prefix !== void 0 ? _opts$prefix : ''}/:path`, (req, res) => {
|
|
74
|
+
const path = req.params.path;
|
|
75
|
+
fastifyRequestHandler({ ...opts.trpcOptions,
|
|
76
|
+
req,
|
|
77
|
+
res,
|
|
78
|
+
path
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (opts.useWSS) {
|
|
83
|
+
var _opts$prefix2;
|
|
84
|
+
|
|
85
|
+
applyWSSHandler({ ...opts.trpcOptions,
|
|
86
|
+
wss: fastify.websocketServer
|
|
87
|
+
}); // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
88
|
+
|
|
89
|
+
fastify.get((_opts$prefix2 = opts.prefix) !== null && _opts$prefix2 !== void 0 ? _opts$prefix2 : '/', {
|
|
90
|
+
websocket: true
|
|
91
|
+
}, () => {});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
done();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { fastifyRequestHandler, fastifyTRPCPlugin };
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../../../src/adapters/next";
|
|
1
|
+
export * from "../../../dist/declarations/src/adapters/next";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var transformTRPCResponse = require('../../../dist/transformTRPCResponse-8248515e.cjs.dev.js');
|
|
6
|
+
var nodeHTTPRequestHandler = require('../../../dist/nodeHTTPRequestHandler-2cc444d8.cjs.dev.js');
|
|
7
|
+
require('url');
|
|
8
|
+
require('../../../dist/resolveHTTPResponse-3867844c.cjs.dev.js');
|
|
9
|
+
require('../../../dist/codes-33cef953.cjs.dev.js');
|
|
10
|
+
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
function createNextApiHandler(opts) {
|
|
13
|
+
return async (req, res) => {
|
|
14
|
+
function getPath() {
|
|
15
|
+
if (typeof req.query.trpc === 'string') {
|
|
16
|
+
return req.query.trpc;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (Array.isArray(req.query.trpc)) {
|
|
20
|
+
return req.query.trpc.join('/');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const path = getPath();
|
|
27
|
+
|
|
28
|
+
if (path === null) {
|
|
29
|
+
const error = opts.router.getErrorShape({
|
|
30
|
+
error: new transformTRPCResponse.TRPCError({
|
|
31
|
+
message: 'Query "trpc" not found - is the file named `[trpc]`.ts or `[...trpc].ts`?',
|
|
32
|
+
code: 'INTERNAL_SERVER_ERROR'
|
|
33
|
+
}),
|
|
34
|
+
type: 'unknown',
|
|
35
|
+
ctx: undefined,
|
|
36
|
+
path: undefined,
|
|
37
|
+
input: undefined
|
|
38
|
+
});
|
|
39
|
+
const json = {
|
|
40
|
+
id: -1,
|
|
41
|
+
error
|
|
42
|
+
};
|
|
43
|
+
res.statusCode = 500;
|
|
44
|
+
res.json(json);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await nodeHTTPRequestHandler.nodeHTTPRequestHandler({ ...opts,
|
|
49
|
+
req,
|
|
50
|
+
res,
|
|
51
|
+
path
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.createNextApiHandler = createNextApiHandler;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
1
|
+
'use strict';
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unregister();
|
|
3
|
+
if (process.env.NODE_ENV === "production") {
|
|
4
|
+
module.exports = require("./trpc-server-adapters-next.cjs.prod.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./trpc-server-adapters-next.cjs.dev.js");
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var transformTRPCResponse = require('../../../dist/transformTRPCResponse-dcbf66c5.cjs.prod.js');
|
|
6
|
+
var nodeHTTPRequestHandler = require('../../../dist/nodeHTTPRequestHandler-8ddacc19.cjs.prod.js');
|
|
7
|
+
require('url');
|
|
8
|
+
require('../../../dist/resolveHTTPResponse-562c3d62.cjs.prod.js');
|
|
9
|
+
require('../../../dist/codes-e0df67c4.cjs.prod.js');
|
|
10
|
+
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
function createNextApiHandler(opts) {
|
|
13
|
+
return async (req, res) => {
|
|
14
|
+
function getPath() {
|
|
15
|
+
if (typeof req.query.trpc === 'string') {
|
|
16
|
+
return req.query.trpc;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (Array.isArray(req.query.trpc)) {
|
|
20
|
+
return req.query.trpc.join('/');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const path = getPath();
|
|
27
|
+
|
|
28
|
+
if (path === null) {
|
|
29
|
+
const error = opts.router.getErrorShape({
|
|
30
|
+
error: new transformTRPCResponse.TRPCError({
|
|
31
|
+
message: 'Query "trpc" not found - is the file named `[trpc]`.ts or `[...trpc].ts`?',
|
|
32
|
+
code: 'INTERNAL_SERVER_ERROR'
|
|
33
|
+
}),
|
|
34
|
+
type: 'unknown',
|
|
35
|
+
ctx: undefined,
|
|
36
|
+
path: undefined,
|
|
37
|
+
input: undefined
|
|
38
|
+
});
|
|
39
|
+
const json = {
|
|
40
|
+
id: -1,
|
|
41
|
+
error
|
|
42
|
+
};
|
|
43
|
+
res.statusCode = 500;
|
|
44
|
+
res.json(json);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await nodeHTTPRequestHandler.nodeHTTPRequestHandler({ ...opts,
|
|
49
|
+
req,
|
|
50
|
+
res,
|
|
51
|
+
path
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.createNextApiHandler = createNextApiHandler;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { T as TRPCError } from '../../../dist/transformTRPCResponse-f73dc4a2.esm.js';
|
|
2
|
+
import { n as nodeHTTPRequestHandler } from '../../../dist/nodeHTTPRequestHandler-d00c1126.esm.js';
|
|
3
|
+
import 'url';
|
|
4
|
+
import '../../../dist/resolveHTTPResponse-85f3f5df.esm.js';
|
|
5
|
+
import '../../../dist/codes-fe07bf82.esm.js';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
function createNextApiHandler(opts) {
|
|
9
|
+
return async (req, res) => {
|
|
10
|
+
function getPath() {
|
|
11
|
+
if (typeof req.query.trpc === 'string') {
|
|
12
|
+
return req.query.trpc;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(req.query.trpc)) {
|
|
16
|
+
return req.query.trpc.join('/');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const path = getPath();
|
|
23
|
+
|
|
24
|
+
if (path === null) {
|
|
25
|
+
const error = opts.router.getErrorShape({
|
|
26
|
+
error: new TRPCError({
|
|
27
|
+
message: 'Query "trpc" not found - is the file named `[trpc]`.ts or `[...trpc].ts`?',
|
|
28
|
+
code: 'INTERNAL_SERVER_ERROR'
|
|
29
|
+
}),
|
|
30
|
+
type: 'unknown',
|
|
31
|
+
ctx: undefined,
|
|
32
|
+
path: undefined,
|
|
33
|
+
input: undefined
|
|
34
|
+
});
|
|
35
|
+
const json = {
|
|
36
|
+
id: -1,
|
|
37
|
+
error
|
|
38
|
+
};
|
|
39
|
+
res.statusCode = 500;
|
|
40
|
+
res.json(json);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await nodeHTTPRequestHandler({ ...opts,
|
|
45
|
+
req,
|
|
46
|
+
res,
|
|
47
|
+
path
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { createNextApiHandler };
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../../../src/adapters/node-http/index";
|
|
1
|
+
export * from "../../../dist/declarations/src/adapters/node-http/index";
|