@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.240 → 11.0.0-alpha-tmp-export-from-main.223
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 +811 -23
- package/dist/index.mjs +799 -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 +107 -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,94 +0,0 @@
|
|
|
1
|
-
import '../../unstable-core-do-not-import/rpc/codes.mjs';
|
|
2
|
-
import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
3
|
-
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
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
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
11
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
12
|
-
* ```
|
|
13
|
-
*/ // @trpc/server
|
|
14
|
-
function isPayloadV1(event) {
|
|
15
|
-
return determinePayloadFormat(event) == '1.0';
|
|
16
|
-
}
|
|
17
|
-
function isPayloadV2(event) {
|
|
18
|
-
return determinePayloadFormat(event) == '2.0';
|
|
19
|
-
}
|
|
20
|
-
function determinePayloadFormat(event) {
|
|
21
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
22
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
23
|
-
// If there is no version property, then the version is implied as 1.0
|
|
24
|
-
const unknownEvent = event;
|
|
25
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
26
|
-
return '1.0';
|
|
27
|
-
} else {
|
|
28
|
-
if ([
|
|
29
|
-
'1.0',
|
|
30
|
-
'2.0'
|
|
31
|
-
].includes(unknownEvent.version)) {
|
|
32
|
-
return unknownEvent.version;
|
|
33
|
-
} else {
|
|
34
|
-
return 'custom';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function getHTTPMethod(event) {
|
|
39
|
-
if (isPayloadV1(event)) {
|
|
40
|
-
return event.httpMethod;
|
|
41
|
-
}
|
|
42
|
-
if (isPayloadV2(event)) {
|
|
43
|
-
return event.requestContext.http.method;
|
|
44
|
-
}
|
|
45
|
-
throw new TRPCError({
|
|
46
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
47
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function getPath(event) {
|
|
51
|
-
if (isPayloadV1(event)) {
|
|
52
|
-
if (!event.pathParameters) {
|
|
53
|
-
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
54
|
-
return event.path.split('/').pop() ?? '';
|
|
55
|
-
}
|
|
56
|
-
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
57
|
-
for (const match of matches){
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
59
|
-
const group = match[1];
|
|
60
|
-
if (group.includes('+') && event.pathParameters) {
|
|
61
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return event.path.slice(1);
|
|
65
|
-
}
|
|
66
|
-
if (isPayloadV2(event)) {
|
|
67
|
-
const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
68
|
-
for (const match1 of matches1){
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
-
const group1 = match1[1];
|
|
71
|
-
if (group1.includes('+') && event.pathParameters) {
|
|
72
|
-
return event.pathParameters[group1.replace('+', '')] ?? '';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return event.rawPath.slice(1);
|
|
76
|
-
}
|
|
77
|
-
throw new TRPCError({
|
|
78
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
79
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function transformHeaders(headers) {
|
|
83
|
-
const obj = {};
|
|
84
|
-
for (const [key, value] of Object.entries(headers)){
|
|
85
|
-
if (typeof value === 'undefined') {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
89
|
-
}
|
|
90
|
-
return obj;
|
|
91
|
-
}
|
|
92
|
-
const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
|
|
93
|
-
|
|
94
|
-
export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,CACjB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvE,OAAO,CAAC,OAAO,CAgBjB"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import type { AnyRouter } from '../../@trpc/server';
|
|
3
|
-
import type { HTTPBaseHandlerOptions } from '../../@trpc/server/http';
|
|
4
|
-
import type { NodeHTTPCreateContextOption } from '../node-http';
|
|
5
|
-
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
6
|
-
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
7
|
-
req: TRequest;
|
|
8
|
-
res: TResponse;
|
|
9
|
-
path: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<never>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=fastifyRequestHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EACV,sBAAsB,EAKvB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE5D,KAAK,4BAA4B,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,EAC9B,IAAI,EAAE,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,kBAyFjE"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_stream = require('node:stream');
|
|
4
|
-
require('../../unstable-core-do-not-import/rpc/codes.js');
|
|
5
|
-
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
6
|
-
var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
7
|
-
var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
|
|
8
|
-
|
|
9
|
-
async function fastifyRequestHandler(opts) {
|
|
10
|
-
const createContext = async (innerOpts)=>{
|
|
11
|
-
return await opts.createContext?.({
|
|
12
|
-
...opts,
|
|
13
|
-
...innerOpts
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
17
|
-
const req = {
|
|
18
|
-
query,
|
|
19
|
-
method: opts.req.method,
|
|
20
|
-
headers: opts.req.headers,
|
|
21
|
-
body: opts.req.body ?? 'null'
|
|
22
|
-
};
|
|
23
|
-
let resolve;
|
|
24
|
-
const promise = new Promise((r)=>resolve = r);
|
|
25
|
-
let isStream = false;
|
|
26
|
-
let stream;
|
|
27
|
-
let formatter;
|
|
28
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
29
|
-
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
30
|
-
opts.res.statusCode = head.status;
|
|
31
|
-
}
|
|
32
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
33
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
void opts.res.header(key, value);
|
|
37
|
-
}
|
|
38
|
-
if (isStreaming) {
|
|
39
|
-
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
40
|
-
void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
|
|
41
|
-
stream = new node_stream.Readable();
|
|
42
|
-
stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
43
|
-
resolve(opts.res.send(stream));
|
|
44
|
-
isStream = true;
|
|
45
|
-
formatter = batchStreamFormatter.getBatchStreamFormatter();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const unstable_onChunk = ([index, string])=>{
|
|
49
|
-
if (index === -1) {
|
|
50
|
-
// full response, no streaming
|
|
51
|
-
resolve(opts.res.send(string));
|
|
52
|
-
} else {
|
|
53
|
-
stream.push(formatter(index, string));
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
resolveHTTPResponse.resolveHTTPResponse({
|
|
57
|
-
req,
|
|
58
|
-
createContext,
|
|
59
|
-
path: opts.path,
|
|
60
|
-
router: opts.router,
|
|
61
|
-
batching: opts.batching,
|
|
62
|
-
responseMeta: opts.responseMeta,
|
|
63
|
-
onError (o) {
|
|
64
|
-
opts?.onError?.({
|
|
65
|
-
...o,
|
|
66
|
-
req: opts.req
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
unstable_onHead,
|
|
70
|
-
unstable_onChunk
|
|
71
|
-
}).then(()=>{
|
|
72
|
-
if (isStream) {
|
|
73
|
-
stream.push(formatter.end());
|
|
74
|
-
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
75
|
-
}
|
|
76
|
-
}).catch(()=>{
|
|
77
|
-
if (isStream) {
|
|
78
|
-
stream.push(null);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return promise;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
|
-
import '../../unstable-core-do-not-import/rpc/codes.mjs';
|
|
3
|
-
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
4
|
-
import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
5
|
-
import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
|
|
6
|
-
|
|
7
|
-
async function fastifyRequestHandler(opts) {
|
|
8
|
-
const createContext = async (innerOpts)=>{
|
|
9
|
-
return await opts.createContext?.({
|
|
10
|
-
...opts,
|
|
11
|
-
...innerOpts
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
15
|
-
const req = {
|
|
16
|
-
query,
|
|
17
|
-
method: opts.req.method,
|
|
18
|
-
headers: opts.req.headers,
|
|
19
|
-
body: opts.req.body ?? 'null'
|
|
20
|
-
};
|
|
21
|
-
let resolve;
|
|
22
|
-
const promise = new Promise((r)=>resolve = r);
|
|
23
|
-
let isStream = false;
|
|
24
|
-
let stream;
|
|
25
|
-
let formatter;
|
|
26
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
27
|
-
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
28
|
-
opts.res.statusCode = head.status;
|
|
29
|
-
}
|
|
30
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
31
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
void opts.res.header(key, value);
|
|
35
|
-
}
|
|
36
|
-
if (isStreaming) {
|
|
37
|
-
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
38
|
-
void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
|
|
39
|
-
stream = new Readable();
|
|
40
|
-
stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
41
|
-
resolve(opts.res.send(stream));
|
|
42
|
-
isStream = true;
|
|
43
|
-
formatter = getBatchStreamFormatter();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const unstable_onChunk = ([index, string])=>{
|
|
47
|
-
if (index === -1) {
|
|
48
|
-
// full response, no streaming
|
|
49
|
-
resolve(opts.res.send(string));
|
|
50
|
-
} else {
|
|
51
|
-
stream.push(formatter(index, string));
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
resolveHTTPResponse({
|
|
55
|
-
req,
|
|
56
|
-
createContext,
|
|
57
|
-
path: opts.path,
|
|
58
|
-
router: opts.router,
|
|
59
|
-
batching: opts.batching,
|
|
60
|
-
responseMeta: opts.responseMeta,
|
|
61
|
-
onError (o) {
|
|
62
|
-
opts?.onError?.({
|
|
63
|
-
...o,
|
|
64
|
-
req: opts.req
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
unstable_onHead,
|
|
68
|
-
unstable_onChunk
|
|
69
|
-
}).then(()=>{
|
|
70
|
-
if (isStream) {
|
|
71
|
-
stream.push(formatter.end());
|
|
72
|
-
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
73
|
-
}
|
|
74
|
-
}).catch(()=>{
|
|
75
|
-
if (isStream) {
|
|
76
|
-
stream.push(null);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return promise;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { fastifyRequestHandler };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 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`
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
7
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
11
|
-
import type { FastifyHandlerOptions } from '.';
|
|
12
|
-
import type { AnyRouter } from '../../@trpc/server';
|
|
13
|
-
import type { NodeHTTPCreateContextFnOptions } from '../node-http';
|
|
14
|
-
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
15
|
-
prefix?: string;
|
|
16
|
-
useWSS?: boolean;
|
|
17
|
-
trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply>;
|
|
18
|
-
}
|
|
19
|
-
export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
20
|
-
export declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
21
|
-
//# sourceMappingURL=fastifyTRPCPlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyTRPCPlugin.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAKnE,MAAM,WAAW,wBAAwB,CAAC,OAAO,SAAS,SAAS;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;CAC3E;AAED,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,cAAc,EACd,YAAY,CACb,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACvC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,QAkC5B"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var ws = require('../ws.js');
|
|
4
|
-
var fastifyRequestHandler = require('./fastifyRequestHandler.js');
|
|
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
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
12
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
|
-
* ```
|
|
14
|
-
*/ /// <reference types="@fastify/websocket" />
|
|
15
|
-
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
16
|
-
fastify.removeContentTypeParser('application/json');
|
|
17
|
-
fastify.addContentTypeParser('application/json', {
|
|
18
|
-
parseAs: 'string'
|
|
19
|
-
}, function(_, body, _done) {
|
|
20
|
-
_done(null, body);
|
|
21
|
-
});
|
|
22
|
-
let prefix = opts.prefix ?? '';
|
|
23
|
-
// https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
|
|
24
|
-
// @ts-expect-error property 'default' does not exists on type ...
|
|
25
|
-
if (typeof fastifyTRPCPlugin.default !== 'function') {
|
|
26
|
-
prefix = ''; // handled by fastify internally
|
|
27
|
-
}
|
|
28
|
-
fastify.all(`${prefix}/:path`, async (req, res)=>{
|
|
29
|
-
const path = req.params.path;
|
|
30
|
-
await fastifyRequestHandler.fastifyRequestHandler({
|
|
31
|
-
...opts.trpcOptions,
|
|
32
|
-
req,
|
|
33
|
-
res,
|
|
34
|
-
path
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
if (opts.useWSS) {
|
|
38
|
-
ws.applyWSSHandler({
|
|
39
|
-
...opts.trpcOptions,
|
|
40
|
-
wss: fastify.websocketServer
|
|
41
|
-
});
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
43
|
-
fastify.get(prefix ?? '/', {
|
|
44
|
-
websocket: true
|
|
45
|
-
}, ()=>{});
|
|
46
|
-
}
|
|
47
|
-
done();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { applyWSSHandler } from '../ws.mjs';
|
|
2
|
-
import { fastifyRequestHandler } from './fastifyRequestHandler.mjs';
|
|
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
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
10
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
11
|
-
* ```
|
|
12
|
-
*/ /// <reference types="@fastify/websocket" />
|
|
13
|
-
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
14
|
-
fastify.removeContentTypeParser('application/json');
|
|
15
|
-
fastify.addContentTypeParser('application/json', {
|
|
16
|
-
parseAs: 'string'
|
|
17
|
-
}, function(_, body, _done) {
|
|
18
|
-
_done(null, body);
|
|
19
|
-
});
|
|
20
|
-
let prefix = opts.prefix ?? '';
|
|
21
|
-
// https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
|
|
22
|
-
// @ts-expect-error property 'default' does not exists on type ...
|
|
23
|
-
if (typeof fastifyTRPCPlugin.default !== 'function') {
|
|
24
|
-
prefix = ''; // handled by fastify internally
|
|
25
|
-
}
|
|
26
|
-
fastify.all(`${prefix}/:path`, async (req, res)=>{
|
|
27
|
-
const path = req.params.path;
|
|
28
|
-
await fastifyRequestHandler({
|
|
29
|
-
...opts.trpcOptions,
|
|
30
|
-
req,
|
|
31
|
-
res,
|
|
32
|
-
path
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
if (opts.useWSS) {
|
|
36
|
-
applyWSSHandler({
|
|
37
|
-
...opts.trpcOptions,
|
|
38
|
-
wss: fastify.websocketServer
|
|
39
|
-
});
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
41
|
-
fastify.get(prefix ?? '/', {
|
|
42
|
-
websocket: true
|
|
43
|
-
}, ()=>{});
|
|
44
|
-
}
|
|
45
|
-
done();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { fastifyTRPCPlugin };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 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`
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
7
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
import type { AnyRouter } from '../../@trpc/server';
|
|
11
|
-
import type { FetchHandlerOptions } from './types';
|
|
12
|
-
export type FetchHandlerRequestOptions<TRouter extends AnyRouter> = FetchHandlerOptions<TRouter> & {
|
|
13
|
-
req: Request;
|
|
14
|
-
endpoint: string;
|
|
15
|
-
};
|
|
16
|
-
export declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerRequestOptions<TRouter>): Promise<Response>;
|
|
17
|
-
//# sourceMappingURL=fetchRequestHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAWpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,mBAAmB,CAAC,OAAO,CAAC,GAAG;IAC7B,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AASJ,wBAAsB,mBAAmB,CAAC,OAAO,SAAS,SAAS,EACjE,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,GACxC,OAAO,CAAC,QAAQ,CAAC,CAyGnB"}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('../../unstable-core-do-not-import/rpc/codes.js');
|
|
4
|
-
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
|
-
var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
6
|
-
var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 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`
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
14
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
15
|
-
* ```
|
|
16
|
-
*/ // @trpc/server
|
|
17
|
-
const trimSlashes = (path)=>{
|
|
18
|
-
path = path.startsWith('/') ? path.slice(1) : path;
|
|
19
|
-
path = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
20
|
-
return path;
|
|
21
|
-
};
|
|
22
|
-
async function fetchRequestHandler(opts) {
|
|
23
|
-
const resHeaders = new Headers();
|
|
24
|
-
const createContext = async (innerOpts)=>{
|
|
25
|
-
return opts.createContext?.({
|
|
26
|
-
req: opts.req,
|
|
27
|
-
resHeaders,
|
|
28
|
-
...innerOpts
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
const url = new URL(opts.req.url);
|
|
32
|
-
const pathname = trimSlashes(url.pathname);
|
|
33
|
-
const endpoint = trimSlashes(opts.endpoint);
|
|
34
|
-
const path = trimSlashes(pathname.slice(endpoint.length));
|
|
35
|
-
const req = {
|
|
36
|
-
query: url.searchParams,
|
|
37
|
-
method: opts.req.method,
|
|
38
|
-
headers: Object.fromEntries(opts.req.headers),
|
|
39
|
-
body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
|
|
40
|
-
};
|
|
41
|
-
let resolve;
|
|
42
|
-
const promise = new Promise((r)=>resolve = r);
|
|
43
|
-
let status = 200;
|
|
44
|
-
let isStream = false;
|
|
45
|
-
let controller;
|
|
46
|
-
let encoder;
|
|
47
|
-
let formatter;
|
|
48
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
49
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
50
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (typeof value === 'string') {
|
|
54
|
-
resHeaders.set(key, value);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
for (const v of value){
|
|
58
|
-
resHeaders.append(key, v);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
status = head.status;
|
|
62
|
-
if (isStreaming) {
|
|
63
|
-
resHeaders.set('Transfer-Encoding', 'chunked');
|
|
64
|
-
resHeaders.append('Vary', 'trpc-batch-mode');
|
|
65
|
-
const stream = new ReadableStream({
|
|
66
|
-
start (c) {
|
|
67
|
-
controller = c;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const response = new Response(stream, {
|
|
71
|
-
status,
|
|
72
|
-
headers: resHeaders
|
|
73
|
-
});
|
|
74
|
-
resolve(response);
|
|
75
|
-
encoder = new TextEncoder();
|
|
76
|
-
formatter = batchStreamFormatter.getBatchStreamFormatter();
|
|
77
|
-
isStream = true;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const unstable_onChunk = ([index, string])=>{
|
|
81
|
-
if (index === -1) {
|
|
82
|
-
// full response, no streaming
|
|
83
|
-
const response = new Response(string || null, {
|
|
84
|
-
status,
|
|
85
|
-
headers: resHeaders
|
|
86
|
-
});
|
|
87
|
-
resolve(response);
|
|
88
|
-
} else {
|
|
89
|
-
controller.enqueue(encoder.encode(formatter(index, string)));
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
resolveHTTPResponse.resolveHTTPResponse({
|
|
93
|
-
req,
|
|
94
|
-
createContext,
|
|
95
|
-
path,
|
|
96
|
-
router: opts.router,
|
|
97
|
-
batching: opts.batching,
|
|
98
|
-
responseMeta: opts.responseMeta,
|
|
99
|
-
onError (o) {
|
|
100
|
-
opts?.onError?.({
|
|
101
|
-
...o,
|
|
102
|
-
req: opts.req
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
unstable_onHead,
|
|
106
|
-
unstable_onChunk
|
|
107
|
-
}).then(()=>{
|
|
108
|
-
if (isStream) {
|
|
109
|
-
controller.enqueue(encoder.encode(formatter.end()));
|
|
110
|
-
controller.close();
|
|
111
|
-
}
|
|
112
|
-
}).catch(()=>{
|
|
113
|
-
if (isStream) {
|
|
114
|
-
controller.close();
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
return promise;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
exports.fetchRequestHandler = fetchRequestHandler;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import '../../unstable-core-do-not-import/rpc/codes.mjs';
|
|
2
|
-
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
-
import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
4
|
-
import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
|
|
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
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
12
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
|
-
* ```
|
|
14
|
-
*/ // @trpc/server
|
|
15
|
-
const trimSlashes = (path)=>{
|
|
16
|
-
path = path.startsWith('/') ? path.slice(1) : path;
|
|
17
|
-
path = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
18
|
-
return path;
|
|
19
|
-
};
|
|
20
|
-
async function fetchRequestHandler(opts) {
|
|
21
|
-
const resHeaders = new Headers();
|
|
22
|
-
const createContext = async (innerOpts)=>{
|
|
23
|
-
return opts.createContext?.({
|
|
24
|
-
req: opts.req,
|
|
25
|
-
resHeaders,
|
|
26
|
-
...innerOpts
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
const url = new URL(opts.req.url);
|
|
30
|
-
const pathname = trimSlashes(url.pathname);
|
|
31
|
-
const endpoint = trimSlashes(opts.endpoint);
|
|
32
|
-
const path = trimSlashes(pathname.slice(endpoint.length));
|
|
33
|
-
const req = {
|
|
34
|
-
query: url.searchParams,
|
|
35
|
-
method: opts.req.method,
|
|
36
|
-
headers: Object.fromEntries(opts.req.headers),
|
|
37
|
-
body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
|
|
38
|
-
};
|
|
39
|
-
let resolve;
|
|
40
|
-
const promise = new Promise((r)=>resolve = r);
|
|
41
|
-
let status = 200;
|
|
42
|
-
let isStream = false;
|
|
43
|
-
let controller;
|
|
44
|
-
let encoder;
|
|
45
|
-
let formatter;
|
|
46
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
47
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
48
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (typeof value === 'string') {
|
|
52
|
-
resHeaders.set(key, value);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
for (const v of value){
|
|
56
|
-
resHeaders.append(key, v);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
status = head.status;
|
|
60
|
-
if (isStreaming) {
|
|
61
|
-
resHeaders.set('Transfer-Encoding', 'chunked');
|
|
62
|
-
resHeaders.append('Vary', 'trpc-batch-mode');
|
|
63
|
-
const stream = new ReadableStream({
|
|
64
|
-
start (c) {
|
|
65
|
-
controller = c;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
const response = new Response(stream, {
|
|
69
|
-
status,
|
|
70
|
-
headers: resHeaders
|
|
71
|
-
});
|
|
72
|
-
resolve(response);
|
|
73
|
-
encoder = new TextEncoder();
|
|
74
|
-
formatter = getBatchStreamFormatter();
|
|
75
|
-
isStream = true;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const unstable_onChunk = ([index, string])=>{
|
|
79
|
-
if (index === -1) {
|
|
80
|
-
// full response, no streaming
|
|
81
|
-
const response = new Response(string || null, {
|
|
82
|
-
status,
|
|
83
|
-
headers: resHeaders
|
|
84
|
-
});
|
|
85
|
-
resolve(response);
|
|
86
|
-
} else {
|
|
87
|
-
controller.enqueue(encoder.encode(formatter(index, string)));
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
resolveHTTPResponse({
|
|
91
|
-
req,
|
|
92
|
-
createContext,
|
|
93
|
-
path,
|
|
94
|
-
router: opts.router,
|
|
95
|
-
batching: opts.batching,
|
|
96
|
-
responseMeta: opts.responseMeta,
|
|
97
|
-
onError (o) {
|
|
98
|
-
opts?.onError?.({
|
|
99
|
-
...o,
|
|
100
|
-
req: opts.req
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
unstable_onHead,
|
|
104
|
-
unstable_onChunk
|
|
105
|
-
}).then(()=>{
|
|
106
|
-
if (isStream) {
|
|
107
|
-
controller.enqueue(encoder.encode(formatter.end()));
|
|
108
|
-
controller.close();
|
|
109
|
-
}
|
|
110
|
-
}).catch(()=>{
|
|
111
|
-
if (isStream) {
|
|
112
|
-
controller.close();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return promise;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export { fetchRequestHandler };
|