@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.240 → 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 +55 -6
- package/dist/adapters/aws-lambda/index.js +111 -23
- package/dist/adapters/aws-lambda/index.mjs +95 -7
- package/dist/adapters/express.d.mts +19 -0
- package/dist/adapters/express.d.ts +10 -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 +12 -6
- package/dist/adapters/next.js +7 -9
- package/dist/adapters/next.mjs +3 -5
- 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} +22 -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 -9
- package/dist/adapters/node-http/content-type/json/index.mjs +44 -5
- 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 +12 -9
- package/dist/adapters/standalone.js +9 -6
- package/dist/adapters/standalone.mjs +2 -3
- package/dist/adapters/ws.d.mts +36 -0
- package/dist/adapters/ws.d.ts +12 -14
- package/dist/adapters/ws.js +33 -38
- package/dist/adapters/ws.mjs +12 -17
- package/dist/http.d.mts +1 -0
- package/dist/http.d.ts +1 -2
- package/dist/http.js +22 -12
- package/dist/http.mjs +1 -6
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +809 -23
- package/dist/index.mjs +798 -8
- package/dist/observable.d.mts +1 -0
- package/dist/observable.d.ts +1 -0
- package/dist/observable.js +30 -0
- package/dist/observable.mjs +1 -0
- package/dist/rpc.d.mts +1 -0
- package/dist/rpc.d.ts +1 -2
- package/dist/rpc.js +14 -7
- package/dist/rpc.mjs +1 -3
- package/dist/shared.d.mts +1 -0
- package/dist/shared.d.ts +1 -26
- package/dist/shared.js +10 -7
- package/dist/shared.mjs +1 -4
- package/dist/unstableDontImportMe.d.mts +1 -0
- package/dist/unstableDontImportMe.d.ts +1 -0
- package/dist/unstableDontImportMe.js +1549 -0
- package/dist/unstableDontImportMe.mjs +1514 -0
- package/package.json +138 -53
- package/src/@trpc-server/http.ts +2 -0
- package/src/adapters/aws-lambda/index.ts +5 -4
- package/src/adapters/aws-lambda/utils.ts +4 -3
- package/src/adapters/express.ts +3 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +4 -6
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +2 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +4 -6
- package/src/adapters/fetch/types.ts +3 -2
- package/src/adapters/next.ts +4 -2
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +4 -6
- package/src/adapters/node-http/types.ts +5 -4
- package/src/adapters/standalone.ts +2 -2
- package/src/adapters/ws.ts +13 -14
- package/src/http.ts +26 -1
- package/src/index.ts +106 -1
- package/src/observable.ts +16 -0
- package/src/rpc.ts +26 -1
- package/src/shared.ts +1 -1
- package/src/unstableDontImportMe.ts +146 -0
- package/unstableDontImportMe/index.d.ts +1 -0
- package/unstableDontImportMe/index.js +1 -0
- package/dist/@trpc/server/http.d.ts +0 -7
- package/dist/@trpc/server/http.d.ts.map +0 -1
- package/dist/@trpc/server/index.d.ts +0 -69
- package/dist/@trpc/server/index.d.ts.map +0 -1
- package/dist/@trpc/server/rpc.d.ts +0 -3
- package/dist/@trpc/server/rpc.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 -47
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -101
- package/dist/adapters/aws-lambda/utils.mjs +0 -94
- 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 -84
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -82
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +0 -21
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -50
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -48
- package/dist/adapters/fastify/index.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +0 -17
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +0 -120
- package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -118
- package/dist/adapters/fetch/index.d.ts.map +0 -1
- package/dist/adapters/fetch/types.d.ts +0 -30
- 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 -44
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -42
- 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 -13
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -111
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -109
- 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/bundle-analysis.json +0 -757
- 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/index.d.ts +0 -5
- package/dist/observable/index.d.ts.map +0 -1
- package/dist/observable/index.js +0 -13
- package/dist/observable/index.mjs +0 -2
- package/dist/observable/observable.d.ts +0 -13
- package/dist/observable/observable.d.ts.map +0 -1
- package/dist/observable/observable.js +0 -126
- package/dist/observable/observable.mjs +0 -122
- package/dist/observable/operators.d.ts +0 -8
- package/dist/observable/operators.d.ts.map +0 -1
- package/dist/observable/operators.js +0 -103
- package/dist/observable/operators.mjs +0 -99
- package/dist/observable/types.d.ts +0 -26
- package/dist/observable/types.d.ts.map +0 -1
- package/dist/rpc.d.ts.map +0 -1
- package/dist/shared.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +0 -6
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/createProxy.d.ts +0 -19
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/createProxy.js +0 -52
- package/dist/unstable-core-do-not-import/createProxy.mjs +0 -49
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +0 -13
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +0 -67
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +0 -63
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +0 -33
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/formatter.js +0 -7
- package/dist/unstable-core-do-not-import/error/formatter.mjs +0 -5
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +0 -15
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +0 -31
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +0 -29
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +0 -32
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +0 -30
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +0 -29
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +0 -54
- package/dist/unstable-core-do-not-import/http/contentType.mjs +0 -52
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +0 -5
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +0 -51
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +0 -48
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -7
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +0 -295
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +0 -293
- package/dist/unstable-core-do-not-import/http/types.d.ts +0 -96
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.d.ts +0 -37
- package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.js +0 -48
- package/dist/unstable-core-do-not-import/index.mjs +0 -16
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +0 -96
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/initTRPC.js +0 -95
- package/dist/unstable-core-do-not-import/initTRPC.mjs +0 -93
- package/dist/unstable-core-do-not-import/middleware.d.ts +0 -105
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/middleware.js +0 -95
- package/dist/unstable-core-do-not-import/middleware.mjs +0 -89
- package/dist/unstable-core-do-not-import/parser.d.ts +0 -30
- package/dist/unstable-core-do-not-import/parser.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/parser.js +0 -37
- package/dist/unstable-core-do-not-import/parser.mjs +0 -35
- package/dist/unstable-core-do-not-import/procedure.d.ts +0 -72
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedure.js +0 -9
- package/dist/unstable-core-do-not-import/procedure.mjs +0 -7
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +0 -101
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -176
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +0 -173
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -75
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rootConfig.js +0 -8
- package/dist/unstable-core-do-not-import/rootConfig.mjs +0 -6
- package/dist/unstable-core-do-not-import/router.d.ts +0 -85
- package/dist/unstable-core-do-not-import/router.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/router.js +0 -156
- package/dist/unstable-core-do-not-import/router.mjs +0 -151
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +0 -51
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/codes.js +0 -38
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +0 -35
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +0 -97
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +0 -59
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +0 -57
- package/dist/unstable-core-do-not-import/serialize.d.ts +0 -62
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/transformer.d.ts +0 -107
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/transformer.js +0 -107
- package/dist/unstable-core-do-not-import/transformer.mjs +0 -102
- package/dist/unstable-core-do-not-import/types.d.ts +0 -98
- package/dist/unstable-core-do-not-import/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +0 -27
- package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/utils.js +0 -44
- package/dist/unstable-core-do-not-import/utils.mjs +0 -39
- package/src/@trpc/server/http.ts +0 -26
- package/src/@trpc/server/index.ts +0 -105
- package/src/@trpc/server/rpc.ts +0 -26
- package/src/observable/index.ts +0 -10
- package/src/observable/observable.ts +0 -158
- package/src/observable/operators.ts +0 -119
- package/src/observable/types.ts +0 -76
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +0 -9
- package/src/unstable-core-do-not-import/createProxy.ts +0 -59
- package/src/unstable-core-do-not-import/error/TRPCError.ts +0 -82
- package/src/unstable-core-do-not-import/error/formatter.ts +0 -51
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +0 -36
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/http/contentType.ts +0 -99
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +0 -57
- package/src/unstable-core-do-not-import/http/index.ts +0 -23
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -458
- package/src/unstable-core-do-not-import/http/types.ts +0 -111
- package/src/unstable-core-do-not-import/index.ts +0 -110
- package/src/unstable-core-do-not-import/initTRPC.ts +0 -206
- package/src/unstable-core-do-not-import/middleware.ts +0 -233
- package/src/unstable-core-do-not-import/parser.ts +0 -94
- package/src/unstable-core-do-not-import/procedure.ts +0 -108
- package/src/unstable-core-do-not-import/procedureBuilder.ts +0 -458
- package/src/unstable-core-do-not-import/rootConfig.ts +0 -90
- package/src/unstable-core-do-not-import/router.ts +0 -370
- package/src/unstable-core-do-not-import/rpc/codes.ts +0 -44
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +0 -136
- package/src/unstable-core-do-not-import/rpc/index.ts +0 -21
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +0 -85
- package/src/unstable-core-do-not-import/serialize.ts +0 -122
- package/src/unstable-core-do-not-import/transformer.ts +0 -202
- package/src/unstable-core-do-not-import/types.ts +0 -151
- package/src/unstable-core-do-not-import/utils.ts +0 -59
- package/unstable-core-do-not-import/index.d.ts +0 -1
- package/unstable-core-do-not-import/index.js +0 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { AnyRouter, inferRouterContext } from '@trpc/server';
|
|
2
|
+
import { HTTPBaseHandlerOptions, MaybePromise, TRPCRequestInfo, BaseContentTypeHandler } from '@trpc/core';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from '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
|
*
|
|
8
|
+
* Do **not** import from `@trpc/core`
|
|
5
9
|
* @example
|
|
6
10
|
* ```ts
|
|
7
11
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
8
12
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
9
13
|
* ```
|
|
10
14
|
*/
|
|
11
|
-
|
|
12
|
-
import type { AnyRouter, inferRouterContext } from '../../@trpc/server';
|
|
13
|
-
import type { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../@trpc/server/http';
|
|
14
|
-
import type { MaybePromise } from '../../unstable-core-do-not-import';
|
|
15
|
-
import type { NodeHTTPContentTypeHandler } from './internals/contentType';
|
|
15
|
+
|
|
16
16
|
interface ParsedQs {
|
|
17
17
|
[key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
type NodeHTTPRequest = IncomingMessage & {
|
|
20
20
|
query?: ParsedQs;
|
|
21
21
|
body?: unknown;
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
type NodeHTTPResponse = ServerResponse & {
|
|
24
24
|
/**
|
|
25
25
|
* Force the partially-compressed response to be flushed to the client.
|
|
26
26
|
*
|
|
@@ -31,7 +31,7 @@ export type NodeHTTPResponse = ServerResponse & {
|
|
|
31
31
|
*/
|
|
32
32
|
flush?: () => void;
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TResponse> = object extends inferRouterContext<TRouter> ? {
|
|
35
35
|
/**
|
|
36
36
|
* @link https://trpc.io/docs/v11/context
|
|
37
37
|
**/
|
|
@@ -46,7 +46,7 @@ export type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TRe
|
|
|
46
46
|
* @internal
|
|
47
47
|
*/
|
|
48
48
|
type ConnectMiddleware<TRequest extends NodeHTTPRequest = NodeHTTPRequest, TResponse extends NodeHTTPResponse = NodeHTTPResponse> = (req: TRequest, res: TResponse, next: (err?: any) => any) => void;
|
|
49
|
-
|
|
49
|
+
type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse> & {
|
|
50
50
|
/**
|
|
51
51
|
* By default, http `OPTIONS` requests are not handled, and CORS headers are not returned.
|
|
52
52
|
*
|
|
@@ -67,16 +67,23 @@ export type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends N
|
|
|
67
67
|
maxBodySize?: number;
|
|
68
68
|
experimental_contentTypeHandlers?: NodeHTTPContentTypeHandler<TRequest, TResponse>[];
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = {
|
|
71
71
|
req: TRequest;
|
|
72
72
|
res: TResponse;
|
|
73
73
|
path: string;
|
|
74
74
|
} & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
|
|
75
|
-
|
|
75
|
+
type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
|
|
76
76
|
req: TRequest;
|
|
77
77
|
res: TResponse;
|
|
78
78
|
info: TRPCRequestInfo;
|
|
79
79
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
type NodeHTTPCreateContextFn<TRouter extends AnyRouter, TRequest, TResponse> = (opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>) => MaybePromise<inferRouterContext<TRouter>>;
|
|
81
|
+
|
|
82
|
+
interface NodeHTTPContentTypeHandler<TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> extends BaseContentTypeHandler<NodeHTTPRequestHandlerOptions<AnyRouter, TRequest, TResponse> & {
|
|
83
|
+
query: URLSearchParams;
|
|
84
|
+
}> {
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare const nodeHTTPJSONContentTypeHandler: <TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>() => NodeHTTPContentTypeHandler<TRequest, TResponse>;
|
|
88
|
+
|
|
89
|
+
export { nodeHTTPJSONContentTypeHandler };
|
|
@@ -1,2 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { AnyRouter, inferRouterContext } from '@trpc/server';
|
|
2
|
+
import { HTTPBaseHandlerOptions, MaybePromise, TRPCRequestInfo, BaseContentTypeHandler } from '@trpc/core';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from '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
|
+
interface ParsedQs {
|
|
17
|
+
[key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
|
|
18
|
+
}
|
|
19
|
+
type NodeHTTPRequest = IncomingMessage & {
|
|
20
|
+
query?: ParsedQs;
|
|
21
|
+
body?: unknown;
|
|
22
|
+
};
|
|
23
|
+
type NodeHTTPResponse = ServerResponse & {
|
|
24
|
+
/**
|
|
25
|
+
* Force the partially-compressed response to be flushed to the client.
|
|
26
|
+
*
|
|
27
|
+
* Added by compression middleware
|
|
28
|
+
* (depending on the environment,
|
|
29
|
+
* e.g. Next <= 12,
|
|
30
|
+
* e.g. Express w/ `compression()`)
|
|
31
|
+
*/
|
|
32
|
+
flush?: () => void;
|
|
33
|
+
};
|
|
34
|
+
type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TResponse> = object extends inferRouterContext<TRouter> ? {
|
|
35
|
+
/**
|
|
36
|
+
* @link https://trpc.io/docs/v11/context
|
|
37
|
+
**/
|
|
38
|
+
createContext?: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
|
|
39
|
+
} : {
|
|
40
|
+
/**
|
|
41
|
+
* @link https://trpc.io/docs/v11/context
|
|
42
|
+
**/
|
|
43
|
+
createContext: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
type ConnectMiddleware<TRequest extends NodeHTTPRequest = NodeHTTPRequest, TResponse extends NodeHTTPResponse = NodeHTTPResponse> = (req: TRequest, res: TResponse, next: (err?: any) => any) => void;
|
|
49
|
+
type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse> & {
|
|
50
|
+
/**
|
|
51
|
+
* By default, http `OPTIONS` requests are not handled, and CORS headers are not returned.
|
|
52
|
+
*
|
|
53
|
+
* This can be used to handle them manually or via the `cors` npm package: https://www.npmjs.com/package/cors
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import cors from 'cors'
|
|
57
|
+
*
|
|
58
|
+
* nodeHTTPRequestHandler({
|
|
59
|
+
* cors: cors()
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* You can also use it for other needs which a connect/node.js compatible middleware can solve,
|
|
64
|
+
* though you might wish to consider an alternative solution like the Express adapter if your needs are complex.
|
|
65
|
+
*/
|
|
66
|
+
middleware?: ConnectMiddleware;
|
|
67
|
+
maxBodySize?: number;
|
|
68
|
+
experimental_contentTypeHandlers?: NodeHTTPContentTypeHandler<TRequest, TResponse>[];
|
|
69
|
+
};
|
|
70
|
+
type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = {
|
|
71
|
+
req: TRequest;
|
|
72
|
+
res: TResponse;
|
|
73
|
+
path: string;
|
|
74
|
+
} & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
|
|
75
|
+
type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
|
|
76
|
+
req: TRequest;
|
|
77
|
+
res: TResponse;
|
|
78
|
+
info: TRPCRequestInfo;
|
|
79
|
+
};
|
|
80
|
+
type NodeHTTPCreateContextFn<TRouter extends AnyRouter, TRequest, TResponse> = (opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>) => MaybePromise<inferRouterContext<TRouter>>;
|
|
81
|
+
|
|
82
|
+
interface NodeHTTPContentTypeHandler<TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> extends BaseContentTypeHandler<NodeHTTPRequestHandlerOptions<AnyRouter, TRequest, TResponse> & {
|
|
83
|
+
query: URLSearchParams;
|
|
84
|
+
}> {
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare const nodeHTTPJSONContentTypeHandler: <TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>() => NodeHTTPContentTypeHandler<TRequest, TResponse>;
|
|
88
|
+
|
|
89
|
+
export { nodeHTTPJSONContentTypeHandler };
|
|
@@ -1,17 +1,56 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
require('
|
|
4
|
-
require('
|
|
5
|
-
var contentType$1 = require('../../../../unstable-core-do-not-import/http/contentType.js');
|
|
6
|
-
var contentType = require('../../internals/contentType.js');
|
|
7
|
-
var getPostBody = require('./getPostBody.js');
|
|
3
|
+
var http = require('@trpc/server/http');
|
|
4
|
+
var server = require('@trpc/server');
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
// @trpc/server
|
|
7
|
+
function createNodeHTTPContentTypeHandler(contentTypeHandler) {
|
|
8
|
+
return ()=>contentTypeHandler;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// @trpc/server
|
|
12
|
+
async function getPostBody(opts) {
|
|
13
|
+
const { req, maxBodySize = Infinity } = opts;
|
|
14
|
+
return new Promise((resolve)=>{
|
|
15
|
+
if ('body' in req) {
|
|
16
|
+
resolve({
|
|
17
|
+
ok: true,
|
|
18
|
+
data: req.body,
|
|
19
|
+
// If the request headers specifies a content-type, we assume that the body has been preprocessed
|
|
20
|
+
preprocessed: !!req.headers['content-type']?.startsWith('application/json')
|
|
21
|
+
});
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let body = '';
|
|
25
|
+
let hasBody = false;
|
|
26
|
+
req.on('data', function(data) {
|
|
27
|
+
body += data;
|
|
28
|
+
hasBody = true;
|
|
29
|
+
if (body.length > maxBodySize) {
|
|
30
|
+
resolve({
|
|
31
|
+
ok: false,
|
|
32
|
+
error: new server.TRPCError({
|
|
33
|
+
code: 'PAYLOAD_TOO_LARGE'
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
req.on('end', ()=>{
|
|
39
|
+
resolve({
|
|
40
|
+
ok: true,
|
|
41
|
+
data: hasBody ? body : undefined,
|
|
42
|
+
preprocessed: false
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const nodeHTTPJSONContentTypeHandler = createNodeHTTPContentTypeHandler({
|
|
10
49
|
isMatch (opts) {
|
|
11
50
|
return !!opts.req.headers['content-type']?.startsWith('application/json');
|
|
12
51
|
},
|
|
13
|
-
getBody: getPostBody
|
|
14
|
-
getInputs:
|
|
52
|
+
getBody: getPostBody,
|
|
53
|
+
getInputs: http.getJsonContentTypeInputs
|
|
15
54
|
});
|
|
16
55
|
|
|
17
56
|
exports.nodeHTTPJSONContentTypeHandler = nodeHTTPJSONContentTypeHandler;
|
|
@@ -1,8 +1,47 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { getJsonContentTypeInputs } from '@trpc/server/http';
|
|
2
|
+
import { TRPCError } from '@trpc/server';
|
|
3
|
+
|
|
4
|
+
// @trpc/server
|
|
5
|
+
function createNodeHTTPContentTypeHandler(contentTypeHandler) {
|
|
6
|
+
return ()=>contentTypeHandler;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// @trpc/server
|
|
10
|
+
async function getPostBody(opts) {
|
|
11
|
+
const { req, maxBodySize = Infinity } = opts;
|
|
12
|
+
return new Promise((resolve)=>{
|
|
13
|
+
if ('body' in req) {
|
|
14
|
+
resolve({
|
|
15
|
+
ok: true,
|
|
16
|
+
data: req.body,
|
|
17
|
+
// If the request headers specifies a content-type, we assume that the body has been preprocessed
|
|
18
|
+
preprocessed: !!req.headers['content-type']?.startsWith('application/json')
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let body = '';
|
|
23
|
+
let hasBody = false;
|
|
24
|
+
req.on('data', function(data) {
|
|
25
|
+
body += data;
|
|
26
|
+
hasBody = true;
|
|
27
|
+
if (body.length > maxBodySize) {
|
|
28
|
+
resolve({
|
|
29
|
+
ok: false,
|
|
30
|
+
error: new TRPCError({
|
|
31
|
+
code: 'PAYLOAD_TOO_LARGE'
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
req.on('end', ()=>{
|
|
37
|
+
resolve({
|
|
38
|
+
ok: true,
|
|
39
|
+
data: hasBody ? body : undefined,
|
|
40
|
+
preprocessed: false
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
6
45
|
|
|
7
46
|
const nodeHTTPJSONContentTypeHandler = createNodeHTTPContentTypeHandler({
|
|
8
47
|
isMatch (opts) {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AnyRouter, inferRouterContext } from '@trpc/server';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { BaseContentTypeHandler, HTTPBaseHandlerOptions, TRPCRequestInfo, MaybePromise } from '@trpc/core';
|
|
4
|
+
|
|
5
|
+
interface NodeHTTPContentTypeHandler<TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> extends BaseContentTypeHandler<NodeHTTPRequestHandlerOptions<AnyRouter, TRequest, TResponse> & {
|
|
6
|
+
query: URLSearchParams;
|
|
7
|
+
}> {
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 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`
|
|
12
|
+
*
|
|
13
|
+
* Do **not** import from `@trpc/core`
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
17
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
interface ParsedQs {
|
|
22
|
+
[key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
|
|
23
|
+
}
|
|
24
|
+
type NodeHTTPRequest = IncomingMessage & {
|
|
25
|
+
query?: ParsedQs;
|
|
26
|
+
body?: unknown;
|
|
27
|
+
};
|
|
28
|
+
type NodeHTTPResponse = ServerResponse & {
|
|
29
|
+
/**
|
|
30
|
+
* Force the partially-compressed response to be flushed to the client.
|
|
31
|
+
*
|
|
32
|
+
* Added by compression middleware
|
|
33
|
+
* (depending on the environment,
|
|
34
|
+
* e.g. Next <= 12,
|
|
35
|
+
* e.g. Express w/ `compression()`)
|
|
36
|
+
*/
|
|
37
|
+
flush?: () => void;
|
|
38
|
+
};
|
|
39
|
+
type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TResponse> = object extends inferRouterContext<TRouter> ? {
|
|
40
|
+
/**
|
|
41
|
+
* @link https://trpc.io/docs/v11/context
|
|
42
|
+
**/
|
|
43
|
+
createContext?: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
|
|
44
|
+
} : {
|
|
45
|
+
/**
|
|
46
|
+
* @link https://trpc.io/docs/v11/context
|
|
47
|
+
**/
|
|
48
|
+
createContext: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
type ConnectMiddleware<TRequest extends NodeHTTPRequest = NodeHTTPRequest, TResponse extends NodeHTTPResponse = NodeHTTPResponse> = (req: TRequest, res: TResponse, next: (err?: any) => any) => void;
|
|
54
|
+
type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse> & {
|
|
55
|
+
/**
|
|
56
|
+
* By default, http `OPTIONS` requests are not handled, and CORS headers are not returned.
|
|
57
|
+
*
|
|
58
|
+
* This can be used to handle them manually or via the `cors` npm package: https://www.npmjs.com/package/cors
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import cors from 'cors'
|
|
62
|
+
*
|
|
63
|
+
* nodeHTTPRequestHandler({
|
|
64
|
+
* cors: cors()
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* You can also use it for other needs which a connect/node.js compatible middleware can solve,
|
|
69
|
+
* though you might wish to consider an alternative solution like the Express adapter if your needs are complex.
|
|
70
|
+
*/
|
|
71
|
+
middleware?: ConnectMiddleware;
|
|
72
|
+
maxBodySize?: number;
|
|
73
|
+
experimental_contentTypeHandlers?: NodeHTTPContentTypeHandler<TRequest, TResponse>[];
|
|
74
|
+
};
|
|
75
|
+
type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = {
|
|
76
|
+
req: TRequest;
|
|
77
|
+
res: TResponse;
|
|
78
|
+
path: string;
|
|
79
|
+
} & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
|
|
80
|
+
type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
|
|
81
|
+
req: TRequest;
|
|
82
|
+
res: TResponse;
|
|
83
|
+
info: TRPCRequestInfo;
|
|
84
|
+
};
|
|
85
|
+
type NodeHTTPCreateContextFn<TRouter extends AnyRouter, TRequest, TResponse> = (opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>) => MaybePromise<inferRouterContext<TRouter>>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 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`
|
|
89
|
+
*
|
|
90
|
+
* Do **not** import from `@trpc/core`
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
94
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
declare function nodeHTTPRequestHandler<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
99
|
+
|
|
100
|
+
export { type NodeHTTPCreateContextFn, type NodeHTTPCreateContextFnOptions, type NodeHTTPCreateContextOption, type NodeHTTPHandlerOptions, type NodeHTTPRequest, type NodeHTTPRequestHandlerOptions, type NodeHTTPResponse, nodeHTTPRequestHandler };
|
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AnyRouter, inferRouterContext } from '@trpc/server';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { BaseContentTypeHandler, HTTPBaseHandlerOptions, TRPCRequestInfo, MaybePromise } from '@trpc/core';
|
|
4
|
+
|
|
5
|
+
interface NodeHTTPContentTypeHandler<TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> extends BaseContentTypeHandler<NodeHTTPRequestHandlerOptions<AnyRouter, TRequest, TResponse> & {
|
|
6
|
+
query: URLSearchParams;
|
|
7
|
+
}> {
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 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`
|
|
12
|
+
*
|
|
13
|
+
* Do **not** import from `@trpc/core`
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
17
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
interface ParsedQs {
|
|
22
|
+
[key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
|
|
23
|
+
}
|
|
24
|
+
type NodeHTTPRequest = IncomingMessage & {
|
|
25
|
+
query?: ParsedQs;
|
|
26
|
+
body?: unknown;
|
|
27
|
+
};
|
|
28
|
+
type NodeHTTPResponse = ServerResponse & {
|
|
29
|
+
/**
|
|
30
|
+
* Force the partially-compressed response to be flushed to the client.
|
|
31
|
+
*
|
|
32
|
+
* Added by compression middleware
|
|
33
|
+
* (depending on the environment,
|
|
34
|
+
* e.g. Next <= 12,
|
|
35
|
+
* e.g. Express w/ `compression()`)
|
|
36
|
+
*/
|
|
37
|
+
flush?: () => void;
|
|
38
|
+
};
|
|
39
|
+
type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TResponse> = object extends inferRouterContext<TRouter> ? {
|
|
40
|
+
/**
|
|
41
|
+
* @link https://trpc.io/docs/v11/context
|
|
42
|
+
**/
|
|
43
|
+
createContext?: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
|
|
44
|
+
} : {
|
|
45
|
+
/**
|
|
46
|
+
* @link https://trpc.io/docs/v11/context
|
|
47
|
+
**/
|
|
48
|
+
createContext: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
type ConnectMiddleware<TRequest extends NodeHTTPRequest = NodeHTTPRequest, TResponse extends NodeHTTPResponse = NodeHTTPResponse> = (req: TRequest, res: TResponse, next: (err?: any) => any) => void;
|
|
54
|
+
type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse> & {
|
|
55
|
+
/**
|
|
56
|
+
* By default, http `OPTIONS` requests are not handled, and CORS headers are not returned.
|
|
57
|
+
*
|
|
58
|
+
* This can be used to handle them manually or via the `cors` npm package: https://www.npmjs.com/package/cors
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import cors from 'cors'
|
|
62
|
+
*
|
|
63
|
+
* nodeHTTPRequestHandler({
|
|
64
|
+
* cors: cors()
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* You can also use it for other needs which a connect/node.js compatible middleware can solve,
|
|
69
|
+
* though you might wish to consider an alternative solution like the Express adapter if your needs are complex.
|
|
70
|
+
*/
|
|
71
|
+
middleware?: ConnectMiddleware;
|
|
72
|
+
maxBodySize?: number;
|
|
73
|
+
experimental_contentTypeHandlers?: NodeHTTPContentTypeHandler<TRequest, TResponse>[];
|
|
74
|
+
};
|
|
75
|
+
type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = {
|
|
76
|
+
req: TRequest;
|
|
77
|
+
res: TResponse;
|
|
78
|
+
path: string;
|
|
79
|
+
} & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
|
|
80
|
+
type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
|
|
81
|
+
req: TRequest;
|
|
82
|
+
res: TResponse;
|
|
83
|
+
info: TRPCRequestInfo;
|
|
84
|
+
};
|
|
85
|
+
type NodeHTTPCreateContextFn<TRouter extends AnyRouter, TRequest, TResponse> = (opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>) => MaybePromise<inferRouterContext<TRouter>>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 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`
|
|
89
|
+
*
|
|
90
|
+
* Do **not** import from `@trpc/core`
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
94
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
declare function nodeHTTPRequestHandler<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
99
|
+
|
|
100
|
+
export { type NodeHTTPCreateContextFn, type NodeHTTPCreateContextFnOptions, type NodeHTTPCreateContextOption, type NodeHTTPHandlerOptions, type NodeHTTPRequest, type NodeHTTPRequestHandlerOptions, type NodeHTTPResponse, nodeHTTPRequestHandler };
|
|
@@ -1,7 +1,109 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var http = require('@trpc/server/http');
|
|
4
|
+
var json = require('@trpc/server/adapters/node-http/content-type/json');
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* 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`
|
|
8
|
+
*
|
|
9
|
+
* Do **not** import from `@trpc/core`
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
13
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
14
|
+
* ```
|
|
15
|
+
*/ /* eslint-disable @typescript-eslint/no-non-null-assertion */ // @trpc/server
|
|
16
|
+
const defaultJSONContentTypeHandler = json.nodeHTTPJSONContentTypeHandler();
|
|
17
|
+
async function nodeHTTPRequestHandler(opts) {
|
|
18
|
+
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
|
|
19
|
+
return handleViaMiddleware(opts.req, opts.res, async (err)=>{
|
|
20
|
+
if (err) throw err;
|
|
21
|
+
//
|
|
22
|
+
// Build tRPC dependencies
|
|
23
|
+
const createContext = async (innerOpts)=>{
|
|
24
|
+
return await opts.createContext?.({
|
|
25
|
+
...opts,
|
|
26
|
+
...innerOpts
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
30
|
+
const jsonContentTypeHandler = defaultJSONContentTypeHandler;
|
|
31
|
+
const contentTypeHandlers = opts.experimental_contentTypeHandlers ?? [
|
|
32
|
+
jsonContentTypeHandler
|
|
33
|
+
];
|
|
34
|
+
const contentTypeHandler = contentTypeHandlers.find((handler)=>handler.isMatch({
|
|
35
|
+
...opts,
|
|
36
|
+
query
|
|
37
|
+
})) ?? // fallback to json
|
|
38
|
+
jsonContentTypeHandler;
|
|
39
|
+
const bodyResult = await contentTypeHandler.getBody({
|
|
40
|
+
...opts,
|
|
41
|
+
query
|
|
42
|
+
});
|
|
43
|
+
const req = {
|
|
44
|
+
method: opts.req.method,
|
|
45
|
+
headers: opts.req.headers,
|
|
46
|
+
query,
|
|
47
|
+
body: bodyResult.ok ? bodyResult.data : undefined
|
|
48
|
+
};
|
|
49
|
+
let isStream = false;
|
|
50
|
+
let formatter;
|
|
51
|
+
const unstable_onHead = (head, isStreaming)=>{
|
|
52
|
+
if ('status' in head && (!opts.res.statusCode || opts.res.statusCode === 200)) {
|
|
53
|
+
opts.res.statusCode = head.status;
|
|
54
|
+
}
|
|
55
|
+
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
56
|
+
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
opts.res.setHeader(key, value);
|
|
60
|
+
}
|
|
61
|
+
if (isStreaming) {
|
|
62
|
+
opts.res.setHeader('Transfer-Encoding', 'chunked');
|
|
63
|
+
const vary = opts.res.getHeader('Vary');
|
|
64
|
+
opts.res.setHeader('Vary', vary ? 'trpc-batch-mode, ' + vary : 'trpc-batch-mode');
|
|
65
|
+
isStream = true;
|
|
66
|
+
formatter = http.getBatchStreamFormatter();
|
|
67
|
+
opts.res.flushHeaders();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const unstable_onChunk = ([index, string])=>{
|
|
71
|
+
if (index === -1) {
|
|
72
|
+
/**
|
|
73
|
+
* Full response, no streaming. This can happen
|
|
74
|
+
* - if the response is an error
|
|
75
|
+
* - if response is empty (HEAD request)
|
|
76
|
+
*/ opts.res.end(string);
|
|
77
|
+
} else {
|
|
78
|
+
opts.res.write(formatter(index, string));
|
|
79
|
+
opts.res.flush?.();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
await http.resolveHTTPResponse({
|
|
83
|
+
batching: opts.batching,
|
|
84
|
+
responseMeta: opts.responseMeta,
|
|
85
|
+
path: opts.path,
|
|
86
|
+
createContext,
|
|
87
|
+
router: opts.router,
|
|
88
|
+
req,
|
|
89
|
+
error: bodyResult.ok ? null : bodyResult.error,
|
|
90
|
+
preprocessedBody: bodyResult.ok ? bodyResult.preprocessed : false,
|
|
91
|
+
onError (o) {
|
|
92
|
+
opts?.onError?.({
|
|
93
|
+
...o,
|
|
94
|
+
req: opts.req
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
contentTypeHandler,
|
|
98
|
+
unstable_onHead,
|
|
99
|
+
unstable_onChunk
|
|
100
|
+
});
|
|
101
|
+
if (isStream) {
|
|
102
|
+
opts.res.write(formatter.end());
|
|
103
|
+
opts.res.end();
|
|
104
|
+
}
|
|
105
|
+
return opts.res;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
5
108
|
|
|
6
|
-
|
|
7
|
-
exports.nodeHTTPRequestHandler = nodeHTTPRequestHandler.nodeHTTPRequestHandler;
|
|
109
|
+
exports.nodeHTTPRequestHandler = nodeHTTPRequestHandler;
|