@trpc/server 11.0.0-alpha-tmp-export-from-main.221 → 11.0.0-alpha-tmp-export-from-main.222
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.d.mts +68 -0
- package/dist/adapters/aws-lambda/index.d.ts +54 -6
- package/dist/adapters/aws-lambda/index.js +110 -20
- package/dist/adapters/aws-lambda/index.mjs +94 -4
- package/dist/adapters/express.d.mts +19 -0
- package/dist/adapters/express.d.ts +9 -6
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/index.d.mts +33 -0
- package/dist/adapters/fastify/index.d.ts +33 -3
- package/dist/adapters/fastify/index.js +124 -5
- package/dist/adapters/fastify/index.mjs +125 -2
- package/dist/adapters/fetch/index.d.mts +51 -0
- package/dist/adapters/fetch/index.d.ts +51 -3
- package/dist/adapters/fetch/index.js +115 -4
- package/dist/adapters/fetch/index.mjs +116 -1
- package/dist/adapters/next.d.mts +21 -0
- package/dist/adapters/next.d.ts +11 -7
- package/dist/adapters/next.js +6 -6
- package/dist/adapters/next.mjs +2 -2
- package/dist/adapters/node-http/content-type/form-data/index.d.mts +219 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +201 -10
- package/dist/adapters/node-http/content-type/form-data/index.js +662 -23
- package/dist/adapters/node-http/content-type/form-data/index.mjs +646 -10
- package/dist/adapters/node-http/{types.d.ts → content-type/json/index.d.mts} +21 -15
- package/dist/adapters/node-http/content-type/json/index.d.ts +89 -2
- package/dist/adapters/node-http/content-type/json/index.js +48 -7
- package/dist/adapters/node-http/content-type/json/index.mjs +44 -3
- package/dist/adapters/node-http/index.d.mts +100 -0
- package/dist/adapters/node-http/index.d.ts +100 -3
- package/dist/adapters/node-http/index.js +106 -4
- package/dist/adapters/node-http/index.mjs +107 -1
- package/dist/adapters/standalone.d.mts +21 -0
- package/dist/adapters/standalone.d.ts +11 -9
- package/dist/adapters/standalone.js +9 -5
- package/dist/adapters/standalone.mjs +2 -2
- package/dist/adapters/ws.d.mts +36 -0
- package/dist/adapters/ws.d.ts +12 -13
- package/dist/adapters/ws.js +30 -28
- package/dist/adapters/ws.mjs +12 -10
- package/dist/http.d.mts +1 -0
- package/dist/http.d.ts +1 -7
- package/dist/http.js +7 -7
- package/dist/http.mjs +1 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +5 -65
- package/dist/index.js +809 -46
- package/dist/index.mjs +798 -1
- package/dist/observable.d.mts +1 -0
- package/dist/observable.d.ts +1 -3
- package/dist/observable.js +8 -8
- package/dist/observable.mjs +1 -1
- package/dist/rpc.d.mts +1 -0
- package/dist/rpc.d.ts +1 -3
- package/dist/rpc.js +5 -5
- package/dist/rpc.mjs +1 -1
- package/dist/shared.d.mts +1 -0
- package/dist/shared.d.ts +1 -26
- package/dist/shared.js +4 -4
- package/dist/shared.mjs +1 -1
- package/dist/unstableDontImportMe.d.mts +1 -0
- package/dist/unstableDontImportMe.d.ts +1 -10
- package/dist/unstableDontImportMe.js +1549 -142
- package/dist/unstableDontImportMe.mjs +1514 -1
- package/package.json +6 -4
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.d.ts +0 -48
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -100
- package/dist/adapters/aws-lambda/utils.mjs +0 -93
- package/dist/adapters/express.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +0 -13
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +0 -81
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -79
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +0 -22
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -51
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -49
- package/dist/adapters/fastify/index.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +0 -18
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +0 -118
- package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -116
- package/dist/adapters/fetch/index.d.ts.map +0 -1
- package/dist/adapters/fetch/types.d.ts +0 -31
- package/dist/adapters/fetch/types.d.ts.map +0 -1
- package/dist/adapters/next.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -70
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -42
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -40
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/index.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
- package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.js +0 -8
- package/dist/adapters/node-http/internals/contentType.mjs +0 -6
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +0 -14
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -109
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -107
- package/dist/adapters/node-http/types.d.ts.map +0 -1
- package/dist/adapters/standalone.d.ts.map +0 -1
- package/dist/adapters/ws.d.ts.map +0 -1
- package/dist/http.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +0 -203
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +0 -201
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +0 -167
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +0 -163
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +0 -35
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +0 -30
- package/dist/observable.d.ts.map +0 -1
- package/dist/rpc.d.ts.map +0 -1
- package/dist/shared.d.ts.map +0 -1
- package/dist/unstableDontImportMe.d.ts.map +0 -1
|
@@ -1 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolveHTTPResponse, getBatchStreamFormatter } from '@trpc/server/http';
|
|
2
|
+
import { nodeHTTPJSONContentTypeHandler } from '@trpc/server/adapters/node-http/content-type/json';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
6
|
+
*
|
|
7
|
+
* Do **not** import from `@trpc/core`
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
11
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
12
|
+
* ```
|
|
13
|
+
*/ /* eslint-disable @typescript-eslint/no-non-null-assertion */ // @trpc/server
|
|
14
|
+
const defaultJSONContentTypeHandler = nodeHTTPJSONContentTypeHandler();
|
|
15
|
+
async function nodeHTTPRequestHandler(opts) {
|
|
16
|
+
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
|
|
17
|
+
return handleViaMiddleware(opts.req, opts.res, async (err)=>{
|
|
18
|
+
if (err) throw err;
|
|
19
|
+
//
|
|
20
|
+
// Build tRPC dependencies
|
|
21
|
+
const createContext = async (innerOpts)=>{
|
|
22
|
+
return await opts.createContext?.({
|
|
23
|
+
...opts,
|
|
24
|
+
...innerOpts
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
28
|
+
const jsonContentTypeHandler = defaultJSONContentTypeHandler;
|
|
29
|
+
const contentTypeHandlers = opts.experimental_contentTypeHandlers ?? [
|
|
30
|
+
jsonContentTypeHandler
|
|
31
|
+
];
|
|
32
|
+
const contentTypeHandler = contentTypeHandlers.find((handler)=>handler.isMatch({
|
|
33
|
+
...opts,
|
|
34
|
+
query
|
|
35
|
+
})) ?? // fallback to json
|
|
36
|
+
jsonContentTypeHandler;
|
|
37
|
+
const bodyResult = await contentTypeHandler.getBody({
|
|
38
|
+
...opts,
|
|
39
|
+
query
|
|
40
|
+
});
|
|
41
|
+
const req = {
|
|
42
|
+
method: opts.req.method,
|
|
43
|
+
headers: opts.req.headers,
|
|
44
|
+
query,
|
|
45
|
+
body: bodyResult.ok ? bodyResult.data : undefined
|
|
46
|
+
};
|
|
47
|
+
let isStream = false;
|
|
48
|
+
let formatter;
|
|
49
|
+
const unstable_onHead = (head, isStreaming)=>{
|
|
50
|
+
if ('status' in head && (!opts.res.statusCode || opts.res.statusCode === 200)) {
|
|
51
|
+
opts.res.statusCode = head.status;
|
|
52
|
+
}
|
|
53
|
+
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
54
|
+
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
opts.res.setHeader(key, value);
|
|
58
|
+
}
|
|
59
|
+
if (isStreaming) {
|
|
60
|
+
opts.res.setHeader('Transfer-Encoding', 'chunked');
|
|
61
|
+
const vary = opts.res.getHeader('Vary');
|
|
62
|
+
opts.res.setHeader('Vary', vary ? 'trpc-batch-mode, ' + vary : 'trpc-batch-mode');
|
|
63
|
+
isStream = true;
|
|
64
|
+
formatter = getBatchStreamFormatter();
|
|
65
|
+
opts.res.flushHeaders();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const unstable_onChunk = ([index, string])=>{
|
|
69
|
+
if (index === -1) {
|
|
70
|
+
/**
|
|
71
|
+
* Full response, no streaming. This can happen
|
|
72
|
+
* - if the response is an error
|
|
73
|
+
* - if response is empty (HEAD request)
|
|
74
|
+
*/ opts.res.end(string);
|
|
75
|
+
} else {
|
|
76
|
+
opts.res.write(formatter(index, string));
|
|
77
|
+
opts.res.flush?.();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
await resolveHTTPResponse({
|
|
81
|
+
batching: opts.batching,
|
|
82
|
+
responseMeta: opts.responseMeta,
|
|
83
|
+
path: opts.path,
|
|
84
|
+
createContext,
|
|
85
|
+
router: opts.router,
|
|
86
|
+
req,
|
|
87
|
+
error: bodyResult.ok ? null : bodyResult.error,
|
|
88
|
+
preprocessedBody: bodyResult.ok ? bodyResult.preprocessed : false,
|
|
89
|
+
onError (o) {
|
|
90
|
+
opts?.onError?.({
|
|
91
|
+
...o,
|
|
92
|
+
req: opts.req
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
contentTypeHandler,
|
|
96
|
+
unstable_onHead,
|
|
97
|
+
unstable_onChunk
|
|
98
|
+
});
|
|
99
|
+
if (isStream) {
|
|
100
|
+
opts.res.write(formatter.end());
|
|
101
|
+
opts.res.end();
|
|
102
|
+
}
|
|
103
|
+
return opts.res;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { nodeHTTPRequestHandler };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import { AnyRouter } from '@trpc/server';
|
|
3
|
+
import { NodeHTTPHandlerOptions, NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
7
|
+
*
|
|
8
|
+
* Do **not** import from `@trpc/core`
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
12
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
|
|
17
|
+
type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<http.IncomingMessage, http.ServerResponse>;
|
|
18
|
+
declare function createHTTPHandler<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
19
|
+
declare function createHTTPServer<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
20
|
+
|
|
21
|
+
export { type CreateHTTPContextOptions, type CreateHTTPHandlerOptions, createHTTPHandler, createHTTPServer };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import { AnyRouter } from '@trpc/server';
|
|
3
|
+
import { NodeHTTPHandlerOptions, NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
4
7
|
*
|
|
@@ -9,11 +12,10 @@
|
|
|
9
12
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
10
13
|
* ```
|
|
11
14
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export
|
|
19
|
-
//# sourceMappingURL=standalone.d.ts.map
|
|
15
|
+
|
|
16
|
+
type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
|
|
17
|
+
type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<http.IncomingMessage, http.ServerResponse>;
|
|
18
|
+
declare function createHTTPHandler<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
19
|
+
declare function createHTTPServer<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
20
|
+
|
|
21
|
+
export { type CreateHTTPContextOptions, type CreateHTTPHandlerOptions, createHTTPHandler, createHTTPServer };
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
var http = require('
|
|
4
|
-
var
|
|
3
|
+
var http = require('http');
|
|
4
|
+
var nodeHttp = require('@trpc/server/adapters/node-http');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var http__default = /*#__PURE__*/_interopDefault(http);
|
|
5
9
|
|
|
6
10
|
function createHTTPHandler(opts) {
|
|
7
11
|
return async (req, res)=>{
|
|
8
12
|
// Get procedure path and remove the leading slash, `/procedure -> procedure`
|
|
9
13
|
// Use dummy hostname if one is not provided.
|
|
10
14
|
const path = new URL(req.url, 'http://127.0.0.1').pathname.slice(1);
|
|
11
|
-
await
|
|
15
|
+
await nodeHttp.nodeHTTPRequestHandler({
|
|
12
16
|
// FIXME: no typecasting should be needed here
|
|
13
17
|
...opts,
|
|
14
18
|
req,
|
|
@@ -19,7 +23,7 @@ function createHTTPHandler(opts) {
|
|
|
19
23
|
}
|
|
20
24
|
function createHTTPServer(opts) {
|
|
21
25
|
const handler = createHTTPHandler(opts);
|
|
22
|
-
return
|
|
26
|
+
return http__default.default.createServer(handler);
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
exports.createHTTPHandler = createHTTPHandler;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import http from '
|
|
2
|
-
import { nodeHTTPRequestHandler } from '
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import { nodeHTTPRequestHandler } from '@trpc/server/adapters/node-http';
|
|
3
3
|
|
|
4
4
|
function createHTTPHandler(opts) {
|
|
5
5
|
return async (req, res)=>{
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IncomingMessage } from 'http';
|
|
2
|
+
import { MaybePromise, BaseHandlerOptions } from '@trpc/core';
|
|
3
|
+
import ws from 'ws';
|
|
4
|
+
import { AnyRouter, inferRouterContext } from '@trpc/server';
|
|
5
|
+
import { NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
type CreateWSSContextFnOptions = Omit<NodeHTTPCreateContextFnOptions<IncomingMessage, ws.WebSocket>, 'info'>;
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
type CreateWSSContextFn<TRouter extends AnyRouter> = (opts: CreateWSSContextFnOptions) => MaybePromise<inferRouterContext<TRouter>>;
|
|
15
|
+
/**
|
|
16
|
+
* Web socket server handler
|
|
17
|
+
*/
|
|
18
|
+
type WSSHandlerOptions<TRouter extends AnyRouter> = BaseHandlerOptions<TRouter, IncomingMessage> & (object extends inferRouterContext<TRouter> ? {
|
|
19
|
+
/**
|
|
20
|
+
* @link https://trpc.io/docs/v11/context
|
|
21
|
+
**/
|
|
22
|
+
createContext?: CreateWSSContextFn<TRouter>;
|
|
23
|
+
} : {
|
|
24
|
+
/**
|
|
25
|
+
* @link https://trpc.io/docs/v11/context
|
|
26
|
+
**/
|
|
27
|
+
createContext: CreateWSSContextFn<TRouter>;
|
|
28
|
+
}) & {
|
|
29
|
+
wss: ws.WebSocketServer;
|
|
30
|
+
process?: NodeJS.Process;
|
|
31
|
+
};
|
|
32
|
+
declare function applyWSSHandler<TRouter extends AnyRouter>(opts: WSSHandlerOptions<TRouter>): {
|
|
33
|
+
broadcastReconnectNotification: () => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { type CreateWSSContextFn, type CreateWSSContextFnOptions, type WSSHandlerOptions, applyWSSHandler };
|
package/dist/adapters/ws.d.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import type { AnyRouter, inferRouterContext } from '..';
|
|
8
|
-
import type { NodeHTTPCreateContextFnOptions } from './node-http';
|
|
1
|
+
import { IncomingMessage } from 'http';
|
|
2
|
+
import { MaybePromise, BaseHandlerOptions } from '@trpc/core';
|
|
3
|
+
import ws from 'ws';
|
|
4
|
+
import { AnyRouter, inferRouterContext } from '@trpc/server';
|
|
5
|
+
import { NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
|
|
6
|
+
|
|
9
7
|
/**
|
|
10
8
|
* @public
|
|
11
9
|
*/
|
|
12
|
-
|
|
10
|
+
type CreateWSSContextFnOptions = Omit<NodeHTTPCreateContextFnOptions<IncomingMessage, ws.WebSocket>, 'info'>;
|
|
13
11
|
/**
|
|
14
12
|
* @public
|
|
15
13
|
*/
|
|
16
|
-
|
|
14
|
+
type CreateWSSContextFn<TRouter extends AnyRouter> = (opts: CreateWSSContextFnOptions) => MaybePromise<inferRouterContext<TRouter>>;
|
|
17
15
|
/**
|
|
18
16
|
* Web socket server handler
|
|
19
17
|
*/
|
|
20
|
-
|
|
18
|
+
type WSSHandlerOptions<TRouter extends AnyRouter> = BaseHandlerOptions<TRouter, IncomingMessage> & (object extends inferRouterContext<TRouter> ? {
|
|
21
19
|
/**
|
|
22
20
|
* @link https://trpc.io/docs/v11/context
|
|
23
21
|
**/
|
|
@@ -31,7 +29,8 @@ export type WSSHandlerOptions<TRouter extends AnyRouter> = BaseHandlerOptions<TR
|
|
|
31
29
|
wss: ws.WebSocketServer;
|
|
32
30
|
process?: NodeJS.Process;
|
|
33
31
|
};
|
|
34
|
-
|
|
32
|
+
declare function applyWSSHandler<TRouter extends AnyRouter>(opts: WSSHandlerOptions<TRouter>): {
|
|
35
33
|
broadcastReconnectNotification: () => void;
|
|
36
34
|
};
|
|
37
|
-
|
|
35
|
+
|
|
36
|
+
export { type CreateWSSContextFn, type CreateWSSContextFnOptions, type WSSHandlerOptions, applyWSSHandler };
|
package/dist/adapters/ws.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var server = require('@trpc/server');
|
|
4
|
+
var observable = require('@trpc/server/observable');
|
|
5
|
+
var rpc = require('@trpc/server/rpc');
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Importing ws causes a build error
|
|
7
9
|
* @link https://github.com/trpc/trpc/pull/5279
|
|
8
10
|
*/ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
|
|
9
11
|
function applyWSSHandler(opts) {
|
|
10
|
-
const { wss
|
|
11
|
-
const { transformer
|
|
12
|
+
const { wss, createContext, router } = opts;
|
|
13
|
+
const { transformer } = router._def._config;
|
|
12
14
|
wss.on('connection', async (client, req)=>{
|
|
13
15
|
const clientSubscriptions = new Map();
|
|
14
16
|
function respond(untransformedJSON) {
|
|
15
|
-
client.send(JSON.stringify(
|
|
17
|
+
client.send(JSON.stringify(server.transformTRPCResponse(router._def._config, untransformedJSON)));
|
|
16
18
|
}
|
|
17
|
-
function stopSubscription(subscription, { id
|
|
19
|
+
function stopSubscription(subscription, { id, jsonrpc }) {
|
|
18
20
|
subscription.unsubscribe();
|
|
19
21
|
respond({
|
|
20
22
|
id,
|
|
@@ -30,9 +32,9 @@ function applyWSSHandler(opts) {
|
|
|
30
32
|
});
|
|
31
33
|
let ctx = undefined;
|
|
32
34
|
async function handleRequest(msg) {
|
|
33
|
-
const { id
|
|
35
|
+
const { id, jsonrpc } = msg;
|
|
34
36
|
/* istanbul ignore next -- @preserve */ if (id === null) {
|
|
35
|
-
throw new
|
|
37
|
+
throw new server.TRPCError({
|
|
36
38
|
code: 'BAD_REQUEST',
|
|
37
39
|
message: '`id` is required'
|
|
38
40
|
});
|
|
@@ -48,11 +50,11 @@ function applyWSSHandler(opts) {
|
|
|
48
50
|
clientSubscriptions.delete(id);
|
|
49
51
|
return;
|
|
50
52
|
}
|
|
51
|
-
const { path
|
|
53
|
+
const { path, input } = msg.params;
|
|
52
54
|
const type = msg.method;
|
|
53
55
|
try {
|
|
54
56
|
await ctxPromise; // asserts context has been set
|
|
55
|
-
const result = await
|
|
57
|
+
const result = await server.callProcedure({
|
|
56
58
|
procedures: router._def.procedures,
|
|
57
59
|
path,
|
|
58
60
|
getRawInput: async ()=>input,
|
|
@@ -60,8 +62,8 @@ function applyWSSHandler(opts) {
|
|
|
60
62
|
type
|
|
61
63
|
});
|
|
62
64
|
if (type === 'subscription') {
|
|
63
|
-
if (!
|
|
64
|
-
throw new
|
|
65
|
+
if (!observable.isObservable(result)) {
|
|
66
|
+
throw new server.TRPCError({
|
|
65
67
|
message: `Subscription ${path} did not return an observable`,
|
|
66
68
|
code: 'INTERNAL_SERVER_ERROR'
|
|
67
69
|
});
|
|
@@ -78,8 +80,8 @@ function applyWSSHandler(opts) {
|
|
|
78
80
|
});
|
|
79
81
|
return;
|
|
80
82
|
}
|
|
81
|
-
const observable = result;
|
|
82
|
-
const
|
|
83
|
+
const observable$1 = result;
|
|
84
|
+
const sub = observable$1.subscribe({
|
|
83
85
|
next (data) {
|
|
84
86
|
respond({
|
|
85
87
|
id,
|
|
@@ -91,7 +93,7 @@ function applyWSSHandler(opts) {
|
|
|
91
93
|
});
|
|
92
94
|
},
|
|
93
95
|
error (err) {
|
|
94
|
-
const error =
|
|
96
|
+
const error = server.getTRPCErrorFromUnknown(err);
|
|
95
97
|
opts.onError?.({
|
|
96
98
|
error,
|
|
97
99
|
path,
|
|
@@ -103,7 +105,7 @@ function applyWSSHandler(opts) {
|
|
|
103
105
|
respond({
|
|
104
106
|
id,
|
|
105
107
|
jsonrpc,
|
|
106
|
-
error:
|
|
108
|
+
error: server.getErrorShape({
|
|
107
109
|
config: router._def._config,
|
|
108
110
|
error,
|
|
109
111
|
type,
|
|
@@ -126,21 +128,21 @@ function applyWSSHandler(opts) {
|
|
|
126
128
|
/* istanbul ignore next -- @preserve */ if (client.readyState !== WEBSOCKET_OPEN) {
|
|
127
129
|
// if the client got disconnected whilst initializing the subscription
|
|
128
130
|
// no need to send stopped message if the client is disconnected
|
|
129
|
-
|
|
131
|
+
sub.unsubscribe();
|
|
130
132
|
return;
|
|
131
133
|
}
|
|
132
134
|
/* istanbul ignore next -- @preserve */ if (clientSubscriptions.has(id)) {
|
|
133
135
|
// duplicate request ids for client
|
|
134
|
-
stopSubscription(
|
|
136
|
+
stopSubscription(sub, {
|
|
135
137
|
id,
|
|
136
138
|
jsonrpc
|
|
137
139
|
});
|
|
138
|
-
throw new
|
|
140
|
+
throw new server.TRPCError({
|
|
139
141
|
message: `Duplicate id ${id}`,
|
|
140
142
|
code: 'BAD_REQUEST'
|
|
141
143
|
});
|
|
142
144
|
}
|
|
143
|
-
clientSubscriptions.set(id,
|
|
145
|
+
clientSubscriptions.set(id, sub);
|
|
144
146
|
respond({
|
|
145
147
|
id,
|
|
146
148
|
jsonrpc,
|
|
@@ -150,7 +152,7 @@ function applyWSSHandler(opts) {
|
|
|
150
152
|
});
|
|
151
153
|
} catch (cause) /* istanbul ignore next -- @preserve */ {
|
|
152
154
|
// procedure threw an error
|
|
153
|
-
const error =
|
|
155
|
+
const error = server.getTRPCErrorFromUnknown(cause);
|
|
154
156
|
opts.onError?.({
|
|
155
157
|
error,
|
|
156
158
|
path,
|
|
@@ -162,7 +164,7 @@ function applyWSSHandler(opts) {
|
|
|
162
164
|
respond({
|
|
163
165
|
id,
|
|
164
166
|
jsonrpc,
|
|
165
|
-
error:
|
|
167
|
+
error: server.getErrorShape({
|
|
166
168
|
config: router._def._config,
|
|
167
169
|
error,
|
|
168
170
|
type,
|
|
@@ -180,16 +182,16 @@ function applyWSSHandler(opts) {
|
|
|
180
182
|
const msgs = Array.isArray(msgJSON) ? msgJSON : [
|
|
181
183
|
msgJSON
|
|
182
184
|
];
|
|
183
|
-
const promises = msgs.map((raw)=>
|
|
185
|
+
const promises = msgs.map((raw)=>rpc.parseTRPCMessage(raw, transformer)).map(handleRequest);
|
|
184
186
|
await Promise.all(promises);
|
|
185
187
|
} catch (cause) {
|
|
186
|
-
const error = new
|
|
188
|
+
const error = new server.TRPCError({
|
|
187
189
|
code: 'PARSE_ERROR',
|
|
188
190
|
cause
|
|
189
191
|
});
|
|
190
192
|
respond({
|
|
191
193
|
id: null,
|
|
192
|
-
error:
|
|
194
|
+
error: server.getErrorShape({
|
|
193
195
|
config: router._def._config,
|
|
194
196
|
error,
|
|
195
197
|
type: 'unknown',
|
|
@@ -207,7 +209,7 @@ function applyWSSHandler(opts) {
|
|
|
207
209
|
client.on('error', (cause)=>{
|
|
208
210
|
opts.onError?.({
|
|
209
211
|
ctx,
|
|
210
|
-
error:
|
|
212
|
+
error: server.getTRPCErrorFromUnknown(cause),
|
|
211
213
|
input: undefined,
|
|
212
214
|
path: undefined,
|
|
213
215
|
type: 'unknown',
|
|
@@ -224,7 +226,7 @@ function applyWSSHandler(opts) {
|
|
|
224
226
|
try {
|
|
225
227
|
ctx = await ctxPromise;
|
|
226
228
|
} catch (cause) {
|
|
227
|
-
const error =
|
|
229
|
+
const error = server.getTRPCErrorFromUnknown(cause);
|
|
228
230
|
opts.onError?.({
|
|
229
231
|
error,
|
|
230
232
|
path: undefined,
|
|
@@ -235,7 +237,7 @@ function applyWSSHandler(opts) {
|
|
|
235
237
|
});
|
|
236
238
|
respond({
|
|
237
239
|
id: null,
|
|
238
|
-
error:
|
|
240
|
+
error: server.getErrorShape({
|
|
239
241
|
config: router._def._config,
|
|
240
242
|
error,
|
|
241
243
|
type: 'unknown',
|
package/dist/adapters/ws.mjs
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TRPCError, getErrorShape, getTRPCErrorFromUnknown, transformTRPCResponse, callProcedure } from '@trpc/server';
|
|
2
|
+
import { isObservable } from '@trpc/server/observable';
|
|
3
|
+
import { parseTRPCMessage } from '@trpc/server/rpc';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Importing ws causes a build error
|
|
5
7
|
* @link https://github.com/trpc/trpc/pull/5279
|
|
6
8
|
*/ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
|
|
7
9
|
function applyWSSHandler(opts) {
|
|
8
|
-
const { wss
|
|
9
|
-
const { transformer
|
|
10
|
+
const { wss, createContext, router } = opts;
|
|
11
|
+
const { transformer } = router._def._config;
|
|
10
12
|
wss.on('connection', async (client, req)=>{
|
|
11
13
|
const clientSubscriptions = new Map();
|
|
12
14
|
function respond(untransformedJSON) {
|
|
13
15
|
client.send(JSON.stringify(transformTRPCResponse(router._def._config, untransformedJSON)));
|
|
14
16
|
}
|
|
15
|
-
function stopSubscription(subscription, { id
|
|
17
|
+
function stopSubscription(subscription, { id, jsonrpc }) {
|
|
16
18
|
subscription.unsubscribe();
|
|
17
19
|
respond({
|
|
18
20
|
id,
|
|
@@ -28,7 +30,7 @@ function applyWSSHandler(opts) {
|
|
|
28
30
|
});
|
|
29
31
|
let ctx = undefined;
|
|
30
32
|
async function handleRequest(msg) {
|
|
31
|
-
const { id
|
|
33
|
+
const { id, jsonrpc } = msg;
|
|
32
34
|
/* istanbul ignore next -- @preserve */ if (id === null) {
|
|
33
35
|
throw new TRPCError({
|
|
34
36
|
code: 'BAD_REQUEST',
|
|
@@ -46,7 +48,7 @@ function applyWSSHandler(opts) {
|
|
|
46
48
|
clientSubscriptions.delete(id);
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
49
|
-
const { path
|
|
51
|
+
const { path, input } = msg.params;
|
|
50
52
|
const type = msg.method;
|
|
51
53
|
try {
|
|
52
54
|
await ctxPromise; // asserts context has been set
|
|
@@ -77,7 +79,7 @@ function applyWSSHandler(opts) {
|
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
79
81
|
const observable = result;
|
|
80
|
-
const
|
|
82
|
+
const sub = observable.subscribe({
|
|
81
83
|
next (data) {
|
|
82
84
|
respond({
|
|
83
85
|
id,
|
|
@@ -124,12 +126,12 @@ function applyWSSHandler(opts) {
|
|
|
124
126
|
/* istanbul ignore next -- @preserve */ if (client.readyState !== WEBSOCKET_OPEN) {
|
|
125
127
|
// if the client got disconnected whilst initializing the subscription
|
|
126
128
|
// no need to send stopped message if the client is disconnected
|
|
127
|
-
|
|
129
|
+
sub.unsubscribe();
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
130
132
|
/* istanbul ignore next -- @preserve */ if (clientSubscriptions.has(id)) {
|
|
131
133
|
// duplicate request ids for client
|
|
132
|
-
stopSubscription(
|
|
134
|
+
stopSubscription(sub, {
|
|
133
135
|
id,
|
|
134
136
|
jsonrpc
|
|
135
137
|
});
|
|
@@ -138,7 +140,7 @@ function applyWSSHandler(opts) {
|
|
|
138
140
|
code: 'BAD_REQUEST'
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
|
-
clientSubscriptions.set(id,
|
|
143
|
+
clientSubscriptions.set(id, sub);
|
|
142
144
|
respond({
|
|
143
145
|
id,
|
|
144
146
|
jsonrpc,
|
package/dist/http.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BaseContentTypeHandler, BaseHandlerOptions, BodyResult, HTTPBaseHandlerOptions, HTTPHeaders, HTTPRequest, HTTPResponse, OnErrorFunction, ProcedureCall, ResolveHTTPRequestOptionsContextFn, ResponseChunk, ResponseMeta, ResponseMetaFn, TRPCRequestInfo, getBatchStreamFormatter, getHTTPStatusCode, getHTTPStatusCodeFromError, getJsonContentTypeInputs, resolveHTTPResponse } from '@trpc/server/unstableDontImportMe';
|
package/dist/http.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export { getHTTPStatusCode, getHTTPStatusCodeFromError, } from '
|
|
2
|
-
export { resolveHTTPResponse } from './unstableDontImportMe';
|
|
3
|
-
export type { BaseHandlerOptions, HTTPBaseHandlerOptions, HTTPHeaders, HTTPRequest, HTTPResponse, OnErrorFunction, ProcedureCall, ResolveHTTPRequestOptionsContextFn, ResponseChunk, ResponseMeta, ResponseMetaFn, TRPCRequestInfo, } from './unstableDontImportMe';
|
|
4
|
-
export { getBatchStreamFormatter } from './unstableDontImportMe';
|
|
5
|
-
export type { BaseContentTypeHandler, BodyResult, } from './unstableDontImportMe';
|
|
6
|
-
export { getJsonContentTypeInputs } from './unstableDontImportMe';
|
|
7
|
-
//# sourceMappingURL=http.d.ts.map
|
|
1
|
+
export { BaseContentTypeHandler, BaseHandlerOptions, BodyResult, HTTPBaseHandlerOptions, HTTPHeaders, HTTPRequest, HTTPResponse, OnErrorFunction, ProcedureCall, ResolveHTTPRequestOptionsContextFn, ResponseChunk, ResponseMeta, ResponseMetaFn, TRPCRequestInfo, getBatchStreamFormatter, getHTTPStatusCode, getHTTPStatusCodeFromError, getJsonContentTypeInputs, resolveHTTPResponse } from '@trpc/server/unstableDontImportMe';
|
package/dist/http.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var unstableDontImportMe = require('@trpc/server/unstableDontImportMe');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "getBatchStreamFormatter", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return unstableDontImportMe.getBatchStreamFormatter; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "getHTTPStatusCode", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return unstableDontImportMe.getHTTPStatusCode; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "getHTTPStatusCodeFromError", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return unstableDontImportMe.getHTTPStatusCodeFromError; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "getJsonContentTypeInputs", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return unstableDontImportMe.getJsonContentTypeInputs; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "resolveHTTPResponse", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return unstableDontImportMe.resolveHTTPResponse; }
|
|
26
26
|
});
|
package/dist/http.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getBatchStreamFormatter, getHTTPStatusCode, getHTTPStatusCodeFromError, getJsonContentTypeInputs, resolveHTTPResponse } from '@trpc/
|
|
1
|
+
export { getBatchStreamFormatter, getHTTPStatusCode, getHTTPStatusCodeFromError, getJsonContentTypeInputs, resolveHTTPResponse } from '@trpc/server/unstableDontImportMe';
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { AnyMiddlewareFunction, AnyMutationProcedure, AnyProcedure, AnyQueryProcedure, AnyRouter, AnySubscriptionProcedure, AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, AnyMutationProcedure as AnyTRPCMutationProcedure, AnyProcedure as AnyTRPCProcedure, AnyQueryProcedure as AnyTRPCQueryProcedure, AnyRouter as AnyTRPCRouter, AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, CombinedDataTransformer, DeepPartial, Dict, ProcedureArgs, ProcedureRouterRecord, ProcedureType, CombinedDataTransformer as TRPCCombinedDataTransformer, TRPCError, ProcedureArgs as TRPCProcedureArgs, ProcedureRouterRecord as TRPCProcedureRouterRecord, ProcedureType as TRPCProcedureType, callProcedure, callProcedure as callTRPCProcedure, createFlatProxy as createTRPCFlatProxy, experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, getErrorShape, getTRPCErrorFromUnknown, inferProcedureInput, inferProcedureOutput, inferRouterContext, inferRouterError, inferRouterInputs, inferRouterOutputs, inferTransformedProcedureOutput, inferTransformedSubscriptionOutput, initTRPC, transformTRPCResponse } from '@trpc/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
* Use `Awaited<ReturnType<typeof myFunction>>` instead
|
|
6
|
+
*/
|
|
7
|
+
type inferAsyncReturnType<TFunction extends (...args: any[]) => any> = Awaited<ReturnType<TFunction>>;
|
|
8
|
+
|
|
9
|
+
export type { inferAsyncReturnType };
|