@trpc/server 11.0.0-next.92 → 11.0.0-rc.330
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/README.md +6 -6
- package/adapters/next-app-dir/index.d.ts +1 -0
- package/adapters/next-app-dir/index.js +1 -0
- package/dist/@trpc/server/http.d.ts +8 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/@trpc/server/index.d.ts +61 -0
- package/dist/@trpc/server/index.d.ts.map +1 -0
- package/dist/@trpc/server/rpc.d.ts +3 -0
- package/dist/@trpc/server/rpc.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +11 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +27 -106
- package/dist/adapters/aws-lambda/index.mjs +14 -91
- package/dist/adapters/aws-lambda/utils.d.ts +14 -14
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +100 -0
- package/dist/adapters/aws-lambda/utils.mjs +93 -0
- package/dist/adapters/express.d.ts +11 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +2 -14
- package/dist/adapters/express.mjs +2 -12
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +4 -4
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +80 -0
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +78 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +13 -4
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +48 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +46 -0
- package/dist/adapters/fastify/index.js +4 -126
- package/dist/adapters/fastify/index.mjs +2 -126
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +11 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +118 -0
- package/dist/adapters/fetch/fetchRequestHandler.mjs +116 -0
- package/dist/adapters/fetch/index.js +2 -106
- package/dist/adapters/fetch/index.mjs +1 -107
- package/dist/adapters/fetch/types.d.ts +13 -4
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/formDataToObject.d.ts +2 -0
- package/dist/adapters/next-app-dir/formDataToObject.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/formDataToObject.js +34 -0
- package/dist/adapters/next-app-dir/formDataToObject.mjs +32 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +24 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +85 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +83 -0
- package/dist/adapters/next-app-dir/notFound.d.ts +7 -0
- package/dist/adapters/next-app-dir/notFound.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/notFound.js +15 -0
- package/dist/adapters/next-app-dir/notFound.mjs +13 -0
- package/dist/adapters/next-app-dir/redirect.d.ts +18 -0
- package/dist/adapters/next-app-dir/redirect.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/redirect.js +33 -0
- package/dist/adapters/next-app-dir/redirect.mjs +30 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts +6 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.js +23 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +21 -0
- package/dist/adapters/next-app-dir.d.ts +4 -0
- package/dist/adapters/next-app-dir.d.ts.map +1 -0
- package/dist/adapters/next-app-dir.js +11 -0
- package/dist/adapters/next-app-dir.mjs +3 -0
- package/dist/adapters/next.d.ts +16 -3
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +19 -19
- package/dist/adapters/next.mjs +18 -16
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +6 -3
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +6 -8
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +21 -647
- package/dist/adapters/node-http/content-type/form-data/index.mjs +10 -632
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +2 -2
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +2 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +2 -2
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +2 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +53 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +51 -0
- package/dist/adapters/node-http/content-type/json/index.js +5 -42
- package/dist/adapters/node-http/content-type/json/index.mjs +4 -39
- package/dist/adapters/node-http/index.js +1 -14
- package/dist/adapters/node-http/index.mjs +1 -12
- package/dist/adapters/node-http/internals/contentType.d.ts +3 -3
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/{contentType-8c16408e.js → adapters/node-http/internals/contentType.js} +1 -0
- package/dist/{contentType-3194ed5f.mjs → adapters/node-http/internals/contentType.mjs} +2 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +11 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-18f3370e.js → adapters/node-http/nodeHTTPRequestHandler.js} +18 -10
- package/dist/{nodeHTTPRequestHandler-0986c5a1.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +18 -10
- package/dist/adapters/node-http/types.d.ts +18 -9
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +11 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +9 -22
- package/dist/adapters/standalone.mjs +9 -16
- package/dist/adapters/ws.d.ts +18 -17
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +34 -22
- package/dist/adapters/ws.mjs +27 -14
- package/dist/bundle-analysis.json +382 -495
- package/dist/http.d.ts +2 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +17 -0
- package/dist/http.mjs +6 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -86
- package/dist/index.mjs +8 -81
- package/dist/observable/index.d.ts +4 -4
- package/dist/observable/index.d.ts.map +1 -1
- package/dist/observable/index.js +6 -149
- package/dist/observable/index.mjs +2 -147
- package/dist/observable/observable.d.ts +9 -1
- package/dist/observable/observable.d.ts.map +1 -1
- package/dist/{observable-464116ac.js → observable/observable.js} +50 -20
- package/dist/{observable-ade1bad8.mjs → observable/observable.mjs} +50 -21
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +99 -0
- package/dist/observable/operators.mjs +95 -0
- package/dist/observable/types.d.ts +2 -5
- package/dist/observable/types.d.ts.map +1 -1
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/{rpc/index.js → rpc.js} +3 -4
- package/dist/rpc.mjs +3 -0
- package/dist/shared.d.ts +26 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +10 -0
- package/dist/shared.mjs +3 -0
- package/dist/unstable-core-do-not-import/clientish/inference.d.ts +17 -0
- package/dist/unstable-core-do-not-import/clientish/inference.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/clientish/inferrable.d.ts +32 -0
- package/dist/unstable-core-do-not-import/clientish/inferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/clientish/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/clientish/serialize.d.ts.map +1 -0
- package/dist/{shared/createProxy/index.d.ts → unstable-core-do-not-import/createProxy.d.ts} +1 -1
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/{index-784ff647.js → unstable-core-do-not-import/createProxy.js} +0 -51
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/{error → unstable-core-do-not-import/error}/TRPCError.d.ts +3 -2
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/{TRPCError-ae7b67e8.js → unstable-core-do-not-import/error/TRPCError.js} +25 -25
- package/dist/{TRPCError-816ff32e.mjs → unstable-core-do-not-import/error/TRPCError.mjs} +24 -25
- package/dist/{error → unstable-core-do-not-import/error}/formatter.d.ts +11 -6
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
- package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/{batchStreamFormatter-fc1ffb26.mjs → unstable-core-do-not-import/http/batchStreamFormatter.mjs} +1 -1
- package/dist/{http → unstable-core-do-not-import/http}/contentType.d.ts +3 -3
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/{contentType-90bad7bb.js → unstable-core-do-not-import/http/contentType.js} +1 -1
- package/dist/{contentType-93515a46.mjs → unstable-core-do-not-import/http/contentType.mjs} +2 -2
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +52 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +49 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +12 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/{http → unstable-core-do-not-import/http}/resolveHTTPResponse.d.ts +4 -5
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/{resolveHTTPResponse-5def1b0c.js → unstable-core-do-not-import/http/resolveHTTPResponse.js} +60 -63
- package/dist/{resolveHTTPResponse-55c648bd.mjs → unstable-core-do-not-import/http/resolveHTTPResponse.mjs} +54 -57
- package/dist/unstable-core-do-not-import/http/toURL.d.ts +2 -0
- package/dist/unstable-core-do-not-import/http/toURL.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/toURL.js +8 -0
- package/dist/unstable-core-do-not-import/http/toURL.mjs +6 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +109 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +102 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +81 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +79 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +106 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +96 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +90 -0
- package/dist/{core → unstable-core-do-not-import}/parser.d.ts +3 -7
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/parser.js +37 -0
- package/dist/unstable-core-do-not-import/parser.mjs +35 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +75 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedure.js +9 -0
- package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +134 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +204 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +201 -0
- package/dist/{core/internals/config.d.ts → unstable-core-do-not-import/rootConfig.d.ts} +19 -27
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
- package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/dist/unstable-core-do-not-import/router.d.ts +81 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +168 -0
- package/dist/unstable-core-do-not-import/router.mjs +163 -0
- package/dist/{rpc → unstable-core-do-not-import/rpc}/codes.d.ts +8 -16
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/{codes-87f6824b.js → unstable-core-do-not-import/rpc/codes.js} +19 -13
- package/dist/{codes-c924c3db.mjs → unstable-core-do-not-import/rpc/codes.mjs} +20 -13
- package/dist/{rpc → unstable-core-do-not-import/rpc}/envelopes.d.ts +6 -4
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/{parseTRPCMessage-1377f305.js → unstable-core-do-not-import/rpc/parseTRPCMessage.js} +5 -2
- package/dist/{parseTRPCMessage-a0f17853.mjs → unstable-core-do-not-import/rpc/parseTRPCMessage.mjs} +6 -3
- package/dist/unstable-core-do-not-import/transformer.d.ts +101 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +106 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +101 -0
- package/dist/unstable-core-do-not-import/types.d.ts +103 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/types.js +11 -0
- package/dist/unstable-core-do-not-import/types.mjs +9 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +19 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +37 -0
- package/dist/unstable-core-do-not-import/utils.mjs +32 -0
- package/dist/unstable-core-do-not-import.d.ts +31 -0
- package/dist/unstable-core-do-not-import.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import.js +66 -0
- package/dist/unstable-core-do-not-import.mjs +21 -0
- package/package.json +51 -69
- package/src/@trpc/server/http.ts +27 -0
- package/src/@trpc/server/index.ts +100 -0
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +21 -10
- package/src/adapters/aws-lambda/utils.ts +33 -26
- package/src/adapters/express.ts +18 -4
- package/src/adapters/fastify/fastifyRequestHandler.ts +22 -12
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +21 -9
- package/src/adapters/fetch/fetchRequestHandler.ts +36 -12
- package/src/adapters/fetch/types.ts +18 -4
- package/src/adapters/next-app-dir/formDataToObject.ts +36 -0
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +129 -0
- package/src/adapters/next-app-dir/notFound.ts +12 -0
- package/src/adapters/next-app-dir/redirect.ts +30 -0
- package/src/adapters/next-app-dir/rethrowNextErrors.ts +25 -0
- package/src/adapters/next-app-dir.ts +3 -0
- package/src/adapters/next.ts +30 -14
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +11 -4
- package/src/adapters/node-http/content-type/form-data/index.ts +18 -18
- package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +3 -2
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +7 -2
- package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +2 -2
- package/src/adapters/node-http/content-type/json/getPostBody.ts +20 -3
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +5 -3
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +28 -16
- package/src/adapters/node-http/types.ts +24 -9
- package/src/adapters/standalone.ts +22 -8
- package/src/adapters/ws.ts +68 -39
- package/src/http.ts +1 -0
- package/src/index.ts +1 -20
- package/src/observable/index.ts +10 -4
- package/src/observable/observable.ts +63 -3
- package/src/observable/operators.ts +114 -0
- package/src/observable/types.ts +1 -5
- package/src/rpc.ts +1 -0
- package/src/shared.ts +26 -0
- package/src/unstable-core-do-not-import/clientish/inference.ts +60 -0
- package/src/unstable-core-do-not-import/clientish/inferrable.ts +49 -0
- package/src/unstable-core-do-not-import/clientish/serialize.ts +122 -0
- package/src/{error → unstable-core-do-not-import/error}/TRPCError.ts +33 -27
- package/src/{error → unstable-core-do-not-import/error}/formatter.ts +12 -19
- package/src/{shared → unstable-core-do-not-import/error}/getErrorShape.ts +8 -8
- package/src/{http → unstable-core-do-not-import/http}/contentType.ts +4 -4
- package/src/{http → unstable-core-do-not-import/http}/getHTTPStatusCode.ts +8 -8
- package/src/unstable-core-do-not-import/http/index.ts +29 -0
- package/src/{http → unstable-core-do-not-import/http}/resolveHTTPResponse.ts +69 -69
- package/src/unstable-core-do-not-import/http/toURL.ts +7 -0
- package/src/unstable-core-do-not-import/http/types.ts +126 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +151 -0
- package/src/unstable-core-do-not-import/middleware.ts +238 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +94 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +623 -0
- package/src/{core/internals/config.ts → unstable-core-do-not-import/rootConfig.ts} +22 -33
- package/src/unstable-core-do-not-import/router.ts +363 -0
- package/src/{rpc → unstable-core-do-not-import/rpc}/codes.ts +30 -3
- package/src/{rpc → unstable-core-do-not-import/rpc}/envelopes.ts +6 -9
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/{rpc → unstable-core-do-not-import/rpc}/parseTRPCMessage.ts +4 -3
- package/src/unstable-core-do-not-import/transformer.ts +194 -0
- package/src/unstable-core-do-not-import/types.ts +157 -0
- package/src/unstable-core-do-not-import/utils.ts +43 -0
- package/src/unstable-core-do-not-import.ts +30 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/TRPCError-efecb077.js +0 -63
- package/dist/batchStreamFormatter-2c1405a1.js +0 -31
- package/dist/codes-e5bb4d58.js +0 -48
- package/dist/config-5de7eae5.js +0 -10
- package/dist/config-60fc2667.js +0 -7
- package/dist/config-ab4c1c6b.mjs +0 -5
- package/dist/contentType-24c44bba.js +0 -5
- package/dist/contentType-9940f5d7.js +0 -58
- package/dist/core/index.d.ts +0 -9
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/initTRPC.d.ts +0 -105
- package/dist/core/initTRPC.d.ts.map +0 -1
- package/dist/core/internals/builderTypes.d.ts +0 -11
- package/dist/core/internals/builderTypes.d.ts.map +0 -1
- package/dist/core/internals/config.d.ts.map +0 -1
- package/dist/core/internals/getParseFn.d.ts +0 -4
- package/dist/core/internals/getParseFn.d.ts.map +0 -1
- package/dist/core/internals/mergeRouters.d.ts +0 -15
- package/dist/core/internals/mergeRouters.d.ts.map +0 -1
- package/dist/core/internals/mergeWithoutOverrides.d.ts +0 -5
- package/dist/core/internals/mergeWithoutOverrides.d.ts.map +0 -1
- package/dist/core/internals/omitPrototype.d.ts +0 -6
- package/dist/core/internals/omitPrototype.d.ts.map +0 -1
- package/dist/core/internals/procedureBuilder.d.ts +0 -113
- package/dist/core/internals/procedureBuilder.d.ts.map +0 -1
- package/dist/core/internals/utils.d.ts +0 -51
- package/dist/core/internals/utils.d.ts.map +0 -1
- package/dist/core/middleware.d.ts +0 -158
- package/dist/core/middleware.d.ts.map +0 -1
- package/dist/core/parser.d.ts.map +0 -1
- package/dist/core/procedure.d.ts +0 -72
- package/dist/core/procedure.d.ts.map +0 -1
- package/dist/core/router.d.ts +0 -65
- package/dist/core/router.d.ts.map +0 -1
- package/dist/core/types.d.ts +0 -24
- package/dist/core/types.d.ts.map +0 -1
- package/dist/error/TRPCError.d.ts.map +0 -1
- package/dist/error/formatter.d.ts.map +0 -1
- package/dist/error/utils.d.ts +0 -9
- package/dist/error/utils.d.ts.map +0 -1
- package/dist/http/batchStreamFormatter.d.ts.map +0 -1
- package/dist/http/contentType.d.ts.map +0 -1
- package/dist/http/getHTTPStatusCode.d.ts +0 -24
- package/dist/http/getHTTPStatusCode.d.ts.map +0 -1
- package/dist/http/index.d.ts +0 -5
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -21
- package/dist/http/index.mjs +0 -9
- package/dist/http/internals/types.d.ts +0 -32
- package/dist/http/internals/types.d.ts.map +0 -1
- package/dist/http/resolveHTTPResponse.d.ts.map +0 -1
- package/dist/http/types.d.ts +0 -46
- package/dist/http/types.d.ts.map +0 -1
- package/dist/index-46cb3130.js +0 -94
- package/dist/index-f91d720c.mjs +0 -97
- package/dist/internals/invert.d.ts +0 -12
- package/dist/internals/invert.d.ts.map +0 -1
- package/dist/internals/types.d.ts +0 -26
- package/dist/internals/types.d.ts.map +0 -1
- package/dist/nodeHTTPRequestHandler-388f5fce.js +0 -107
- package/dist/observable/internals/identity.d.ts +0 -2
- package/dist/observable/internals/identity.d.ts.map +0 -1
- package/dist/observable/internals/observableToPromise.d.ts +0 -10
- package/dist/observable/internals/observableToPromise.d.ts.map +0 -1
- package/dist/observable/internals/pipe.d.ts +0 -4
- package/dist/observable/internals/pipe.d.ts.map +0 -1
- package/dist/observable/operators/index.d.ts +0 -4
- package/dist/observable/operators/index.d.ts.map +0 -1
- package/dist/observable/operators/map.d.ts +0 -3
- package/dist/observable/operators/map.d.ts.map +0 -1
- package/dist/observable/operators/share.d.ts +0 -6
- package/dist/observable/operators/share.d.ts.map +0 -1
- package/dist/observable/operators/tap.d.ts +0 -3
- package/dist/observable/operators/tap.d.ts.map +0 -1
- package/dist/observable-15588f28.js +0 -83
- package/dist/parseTRPCMessage-95955211.js +0 -63
- package/dist/resolveHTTPResponse-8d474952.js +0 -267
- package/dist/router-3c22fe56.js +0 -159
- package/dist/router-5274e533.mjs +0 -153
- package/dist/router-a1635eab.js +0 -147
- package/dist/rpc/codes.d.ts.map +0 -1
- package/dist/rpc/envelopes.d.ts.map +0 -1
- package/dist/rpc/index.d.ts +0 -4
- package/dist/rpc/index.d.ts.map +0 -1
- package/dist/rpc/index.mjs +0 -2
- package/dist/rpc/parseTRPCMessage.d.ts.map +0 -1
- package/dist/shared/createProxy/index.d.ts.map +0 -1
- package/dist/shared/getErrorShape.d.ts +0 -15
- package/dist/shared/getErrorShape.d.ts.map +0 -1
- package/dist/shared/index.d.ts +0 -7
- package/dist/shared/index.d.ts.map +0 -1
- package/dist/shared/index.js +0 -14
- package/dist/shared/index.mjs +0 -3
- package/dist/shared/internal/serialize.d.ts +0 -30
- package/dist/shared/internal/serialize.d.ts.map +0 -1
- package/dist/shared/jsonify.d.ts +0 -11
- package/dist/shared/jsonify.d.ts.map +0 -1
- package/dist/shared/transformTRPCResponse.d.ts +0 -9
- package/dist/shared/transformTRPCResponse.d.ts.map +0 -1
- package/dist/shared/types.d.ts +0 -6
- package/dist/shared/types.d.ts.map +0 -1
- package/dist/transformTRPCResponse-1153b421.mjs +0 -53
- package/dist/transformTRPCResponse-20ce3b68.js +0 -54
- package/dist/transformTRPCResponse-e65f34e9.js +0 -56
- package/dist/transformer.d.ts +0 -74
- package/dist/transformer.d.ts.map +0 -1
- package/dist/types.d.ts +0 -83
- package/dist/types.d.ts.map +0 -1
- package/dist/unstableInternalsExport-10cc2bae.mjs +0 -353
- package/dist/unstableInternalsExport-a064a7dd.js +0 -349
- package/dist/unstableInternalsExport-bf8496ea.js +0 -363
- package/dist/unstableInternalsExport.d.ts +0 -11
- package/dist/unstableInternalsExport.d.ts.map +0 -1
- package/dist/unstableInternalsExport.js +0 -16
- package/dist/unstableInternalsExport.mjs +0 -5
- package/src/core/index.ts +0 -28
- package/src/core/initTRPC.ts +0 -169
- package/src/core/internals/builderTypes.ts +0 -11
- package/src/core/internals/getParseFn.ts +0 -43
- package/src/core/internals/mergeRouters.ts +0 -90
- package/src/core/internals/mergeWithoutOverrides.ts +0 -19
- package/src/core/internals/omitPrototype.ts +0 -9
- package/src/core/internals/procedureBuilder.ts +0 -394
- package/src/core/internals/utils.ts +0 -84
- package/src/core/middleware.ts +0 -295
- package/src/core/parser.ts +0 -57
- package/src/core/procedure.ts +0 -88
- package/src/core/router.ts +0 -226
- package/src/core/types.ts +0 -67
- package/src/error/utils.ts +0 -23
- package/src/http/index.ts +0 -4
- package/src/http/internals/types.ts +0 -40
- package/src/http/types.ts +0 -51
- package/src/internals/invert.ts +0 -21
- package/src/internals/types.ts +0 -27
- package/src/observable/internals/identity.ts +0 -3
- package/src/observable/internals/observableToPromise.ts +0 -49
- package/src/observable/internals/pipe.ts +0 -23
- package/src/observable/operators/index.ts +0 -3
- package/src/observable/operators/map.ts +0 -25
- package/src/observable/operators/share.ts +0 -65
- package/src/observable/operators/tap.ts +0 -26
- package/src/rpc/index.ts +0 -3
- package/src/shared/index.ts +0 -10
- package/src/shared/internal/serialize.ts +0 -65
- package/src/shared/jsonify.ts +0 -22
- package/src/shared/transformTRPCResponse.ts +0 -40
- package/src/shared/types.ts +0 -9
- package/src/transformer.ts +0 -94
- package/src/types.ts +0 -125
- package/src/unstableInternalsExport.ts +0 -10
- package/subscription/index.d.ts +0 -1
- package/subscription/index.js +0 -1
- package/unstableInternalsExport/index.d.ts +0 -1
- package/unstableInternalsExport/index.js +0 -1
- /package/dist/{http → unstable-core-do-not-import/http}/batchStreamFormatter.d.ts +0 -0
- /package/dist/{batchStreamFormatter-93cdcdd4.js → unstable-core-do-not-import/http/batchStreamFormatter.js} +0 -0
- /package/dist/{rpc → unstable-core-do-not-import/rpc}/parseTRPCMessage.d.ts +0 -0
- /package/src/{shared/createProxy/index.ts → unstable-core-do-not-import/createProxy.ts} +0 -0
- /package/src/{http → unstable-core-do-not-import/http}/batchStreamFormatter.ts +0 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../unstable-core-do-not-import/rootConfig.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
|
+
*/ // @trpc/server
|
|
13
|
+
function isPayloadV1(event) {
|
|
14
|
+
return determinePayloadFormat(event) == '1.0';
|
|
15
|
+
}
|
|
16
|
+
function isPayloadV2(event) {
|
|
17
|
+
return determinePayloadFormat(event) == '2.0';
|
|
18
|
+
}
|
|
19
|
+
function determinePayloadFormat(event) {
|
|
20
|
+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
21
|
+
// According to AWS support, version is is extracted from the version property in the event.
|
|
22
|
+
// If there is no version property, then the version is implied as 1.0
|
|
23
|
+
const unknownEvent = event;
|
|
24
|
+
if (typeof unknownEvent.version === 'undefined') {
|
|
25
|
+
return '1.0';
|
|
26
|
+
} else {
|
|
27
|
+
if ([
|
|
28
|
+
'1.0',
|
|
29
|
+
'2.0'
|
|
30
|
+
].includes(unknownEvent.version)) {
|
|
31
|
+
return unknownEvent.version;
|
|
32
|
+
} else {
|
|
33
|
+
return 'custom';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function getHTTPMethod(event) {
|
|
38
|
+
if (isPayloadV1(event)) {
|
|
39
|
+
return event.httpMethod;
|
|
40
|
+
}
|
|
41
|
+
if (isPayloadV2(event)) {
|
|
42
|
+
return event.requestContext.http.method;
|
|
43
|
+
}
|
|
44
|
+
throw new TRPCError({
|
|
45
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
46
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function getPath(event) {
|
|
50
|
+
if (isPayloadV1(event)) {
|
|
51
|
+
if (!event.pathParameters) {
|
|
52
|
+
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
53
|
+
return event.path.split('/').pop() ?? '';
|
|
54
|
+
}
|
|
55
|
+
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
56
|
+
for (const match of matches){
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
58
|
+
const group = match[1];
|
|
59
|
+
if (group.includes('+') && event.pathParameters) {
|
|
60
|
+
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return event.path.slice(1);
|
|
64
|
+
}
|
|
65
|
+
if (isPayloadV2(event)) {
|
|
66
|
+
const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
67
|
+
for (const match1 of matches1){
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
69
|
+
const group1 = match1[1];
|
|
70
|
+
if (group1.includes('+') && event.pathParameters) {
|
|
71
|
+
return event.pathParameters[group1.replace('+', '')] ?? '';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return event.rawPath.slice(1);
|
|
75
|
+
}
|
|
76
|
+
throw new TRPCError({
|
|
77
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
78
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function transformHeaders(headers) {
|
|
82
|
+
const obj = {};
|
|
83
|
+
for (const [key, value] of Object.entries(headers)){
|
|
84
|
+
if (typeof value === 'undefined') {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
88
|
+
}
|
|
89
|
+
return obj;
|
|
90
|
+
}
|
|
91
|
+
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';
|
|
92
|
+
|
|
93
|
+
export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
|
|
@@ -1,6 +1,15 @@
|
|
|
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
|
+
*/
|
|
1
10
|
import type * as express from 'express';
|
|
2
|
-
import { AnyRouter } from '
|
|
3
|
-
import { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from './node-http';
|
|
11
|
+
import type { AnyRouter } from '../@trpc/server';
|
|
12
|
+
import type { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from './node-http';
|
|
4
13
|
export type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<express.Request, express.Response>;
|
|
5
14
|
export declare function createExpressMiddleware<TRouter extends AnyRouter>(opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>): express.Handler;
|
|
6
15
|
//# sourceMappingURL=express.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
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"}
|
package/dist/adapters/express.js
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-18f3370e.js');
|
|
6
|
-
require('../index-784ff647.js');
|
|
7
|
-
require('../codes-87f6824b.js');
|
|
8
|
-
require('../resolveHTTPResponse-5def1b0c.js');
|
|
9
|
-
require('../router-3c22fe56.js');
|
|
10
|
-
require('../TRPCError-ae7b67e8.js');
|
|
11
|
-
require('../config-60fc2667.js');
|
|
12
|
-
require('../transformTRPCResponse-e65f34e9.js');
|
|
13
|
-
require('../contentType-90bad7bb.js');
|
|
14
|
-
require('../batchStreamFormatter-93cdcdd4.js');
|
|
15
|
-
require('./node-http/content-type/json/index.js');
|
|
16
|
-
require('../contentType-8c16408e.js');
|
|
3
|
+
var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
|
|
17
4
|
|
|
18
5
|
function createExpressMiddleware(opts) {
|
|
19
6
|
return async (req, res)=>{
|
|
20
7
|
const endpoint = req.path.slice(1);
|
|
21
8
|
await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
|
|
9
|
+
// FIXME: no typecasting should be needed here
|
|
22
10
|
...opts,
|
|
23
11
|
req,
|
|
24
12
|
res,
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../index-f91d720c.mjs';
|
|
3
|
-
import '../codes-c924c3db.mjs';
|
|
4
|
-
import '../resolveHTTPResponse-55c648bd.mjs';
|
|
5
|
-
import '../router-5274e533.mjs';
|
|
6
|
-
import '../TRPCError-816ff32e.mjs';
|
|
7
|
-
import '../config-ab4c1c6b.mjs';
|
|
8
|
-
import '../transformTRPCResponse-1153b421.mjs';
|
|
9
|
-
import '../contentType-93515a46.mjs';
|
|
10
|
-
import '../batchStreamFormatter-fc1ffb26.mjs';
|
|
11
|
-
import './node-http/content-type/json/index.mjs';
|
|
12
|
-
import '../contentType-3194ed5f.mjs';
|
|
1
|
+
import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
|
|
13
2
|
|
|
14
3
|
function createExpressMiddleware(opts) {
|
|
15
4
|
return async (req, res)=>{
|
|
16
5
|
const endpoint = req.path.slice(1);
|
|
17
6
|
await nodeHTTPRequestHandler({
|
|
7
|
+
// FIXME: no typecasting should be needed here
|
|
18
8
|
...opts,
|
|
19
9
|
req,
|
|
20
10
|
res,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import { AnyRouter } from '
|
|
3
|
-
import { HTTPBaseHandlerOptions } from '
|
|
4
|
-
import { NodeHTTPCreateContextOption } from '../node-http';
|
|
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
5
|
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
6
6
|
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
7
7
|
req: TRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"
|
|
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,kBAsFjE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_stream = require('node:stream');
|
|
4
|
+
var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
5
|
+
var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
|
|
6
|
+
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
7
|
+
|
|
8
|
+
async function fastifyRequestHandler(opts) {
|
|
9
|
+
const createContext = async (innerOpts)=>{
|
|
10
|
+
return await opts.createContext?.({
|
|
11
|
+
...opts,
|
|
12
|
+
...innerOpts
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
16
|
+
const req = {
|
|
17
|
+
query,
|
|
18
|
+
method: opts.req.method,
|
|
19
|
+
headers: opts.req.headers,
|
|
20
|
+
body: opts.req.body ?? 'null'
|
|
21
|
+
};
|
|
22
|
+
let resolve;
|
|
23
|
+
const promise = new Promise((r)=>resolve = r);
|
|
24
|
+
let isStream = false;
|
|
25
|
+
let stream;
|
|
26
|
+
let formatter;
|
|
27
|
+
const unstable_onHead = (head, isStreaming)=>{
|
|
28
|
+
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
29
|
+
opts.res.statusCode = head.status;
|
|
30
|
+
}
|
|
31
|
+
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
32
|
+
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
void opts.res.header(key, value);
|
|
36
|
+
}
|
|
37
|
+
if (isStreaming) {
|
|
38
|
+
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
39
|
+
void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
|
|
40
|
+
stream = new node_stream.Readable();
|
|
41
|
+
stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
42
|
+
resolve(opts.res.send(stream));
|
|
43
|
+
isStream = true;
|
|
44
|
+
formatter = batchStreamFormatter.getBatchStreamFormatter();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const unstable_onChunk = ([index, string])=>{
|
|
48
|
+
if (index === -1) {
|
|
49
|
+
// full response, no streaming
|
|
50
|
+
resolve(opts.res.send(string));
|
|
51
|
+
} else {
|
|
52
|
+
stream.push(formatter(index, string));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
resolveHTTPResponse.resolveHTTPResponse({
|
|
56
|
+
...opts,
|
|
57
|
+
req,
|
|
58
|
+
createContext,
|
|
59
|
+
onError (o) {
|
|
60
|
+
opts?.onError?.({
|
|
61
|
+
...o,
|
|
62
|
+
req: opts.req
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
unstable_onHead,
|
|
66
|
+
unstable_onChunk
|
|
67
|
+
}).then(()=>{
|
|
68
|
+
if (isStream) {
|
|
69
|
+
stream.push(formatter.end());
|
|
70
|
+
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
71
|
+
}
|
|
72
|
+
}).catch(()=>{
|
|
73
|
+
if (isStream) {
|
|
74
|
+
stream.push(null);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return promise;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
3
|
+
import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
|
|
4
|
+
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
5
|
+
|
|
6
|
+
async function fastifyRequestHandler(opts) {
|
|
7
|
+
const createContext = async (innerOpts)=>{
|
|
8
|
+
return await opts.createContext?.({
|
|
9
|
+
...opts,
|
|
10
|
+
...innerOpts
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
14
|
+
const req = {
|
|
15
|
+
query,
|
|
16
|
+
method: opts.req.method,
|
|
17
|
+
headers: opts.req.headers,
|
|
18
|
+
body: opts.req.body ?? 'null'
|
|
19
|
+
};
|
|
20
|
+
let resolve;
|
|
21
|
+
const promise = new Promise((r)=>resolve = r);
|
|
22
|
+
let isStream = false;
|
|
23
|
+
let stream;
|
|
24
|
+
let formatter;
|
|
25
|
+
const unstable_onHead = (head, isStreaming)=>{
|
|
26
|
+
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
27
|
+
opts.res.statusCode = head.status;
|
|
28
|
+
}
|
|
29
|
+
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
30
|
+
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
void opts.res.header(key, value);
|
|
34
|
+
}
|
|
35
|
+
if (isStreaming) {
|
|
36
|
+
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
37
|
+
void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
|
|
38
|
+
stream = new Readable();
|
|
39
|
+
stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
40
|
+
resolve(opts.res.send(stream));
|
|
41
|
+
isStream = true;
|
|
42
|
+
formatter = getBatchStreamFormatter();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const unstable_onChunk = ([index, string])=>{
|
|
46
|
+
if (index === -1) {
|
|
47
|
+
// full response, no streaming
|
|
48
|
+
resolve(opts.res.send(string));
|
|
49
|
+
} else {
|
|
50
|
+
stream.push(formatter(index, string));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
resolveHTTPResponse({
|
|
54
|
+
...opts,
|
|
55
|
+
req,
|
|
56
|
+
createContext,
|
|
57
|
+
onError (o) {
|
|
58
|
+
opts?.onError?.({
|
|
59
|
+
...o,
|
|
60
|
+
req: opts.req
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
unstable_onHead,
|
|
64
|
+
unstable_onChunk
|
|
65
|
+
}).then(()=>{
|
|
66
|
+
if (isStream) {
|
|
67
|
+
stream.push(formatter.end());
|
|
68
|
+
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
69
|
+
}
|
|
70
|
+
}).catch(()=>{
|
|
71
|
+
if (isStream) {
|
|
72
|
+
stream.push(null);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return promise;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { fastifyRequestHandler };
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
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';
|
|
5
14
|
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
6
15
|
prefix?: string;
|
|
7
16
|
useWSS?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyTRPCPlugin.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"names":[],"mappings":"
|
|
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,QAmC5B"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
const onConnection = ws.getWSConnectionHandler({
|
|
39
|
+
...opts.trpcOptions
|
|
40
|
+
});
|
|
41
|
+
fastify.get(prefix ?? '/', {
|
|
42
|
+
websocket: true
|
|
43
|
+
}, (socket, req)=>onConnection(socket, req.raw));
|
|
44
|
+
}
|
|
45
|
+
done();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getWSConnectionHandler } 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
|
+
const onConnection = getWSConnectionHandler({
|
|
37
|
+
...opts.trpcOptions
|
|
38
|
+
});
|
|
39
|
+
fastify.get(prefix ?? '/', {
|
|
40
|
+
websocket: true
|
|
41
|
+
}, (socket, req)=>onConnection(socket, req.raw));
|
|
42
|
+
}
|
|
43
|
+
done();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { fastifyTRPCPlugin };
|
|
@@ -1,131 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var fastifyRequestHandler = require('./fastifyRequestHandler.js');
|
|
4
|
+
var fastifyTRPCPlugin = require('./fastifyTRPCPlugin.js');
|
|
4
5
|
|
|
5
|
-
var node_stream = require('node:stream');
|
|
6
|
-
require('../../index-784ff647.js');
|
|
7
|
-
var resolveHTTPResponse = require('../../resolveHTTPResponse-5def1b0c.js');
|
|
8
|
-
var batchStreamFormatter = require('../../batchStreamFormatter-93cdcdd4.js');
|
|
9
|
-
var adapters_ws = require('../ws.js');
|
|
10
|
-
require('../../codes-87f6824b.js');
|
|
11
|
-
require('../../router-3c22fe56.js');
|
|
12
|
-
require('../../TRPCError-ae7b67e8.js');
|
|
13
|
-
require('../../config-60fc2667.js');
|
|
14
|
-
require('../../transformTRPCResponse-e65f34e9.js');
|
|
15
|
-
require('../../contentType-90bad7bb.js');
|
|
16
|
-
require('../../observable-464116ac.js');
|
|
17
|
-
require('../../parseTRPCMessage-1377f305.js');
|
|
18
6
|
|
|
19
|
-
async function fastifyRequestHandler(opts) {
|
|
20
|
-
const createContext = async (innerOpts)=>{
|
|
21
|
-
return await opts.createContext?.({
|
|
22
|
-
...opts,
|
|
23
|
-
...innerOpts
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
27
|
-
const req = {
|
|
28
|
-
query,
|
|
29
|
-
method: opts.req.method,
|
|
30
|
-
headers: opts.req.headers,
|
|
31
|
-
body: opts.req.body ?? 'null'
|
|
32
|
-
};
|
|
33
|
-
let resolve;
|
|
34
|
-
const promise = new Promise((r)=>resolve = r);
|
|
35
|
-
let isStream = false;
|
|
36
|
-
let stream;
|
|
37
|
-
let formatter;
|
|
38
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
39
|
-
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
40
|
-
opts.res.statusCode = head.status;
|
|
41
|
-
}
|
|
42
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
43
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
void opts.res.header(key, value);
|
|
47
|
-
}
|
|
48
|
-
if (isStreaming) {
|
|
49
|
-
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
50
|
-
void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
|
|
51
|
-
stream = new node_stream.Readable();
|
|
52
|
-
stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
53
|
-
resolve(opts.res.send(stream));
|
|
54
|
-
isStream = true;
|
|
55
|
-
formatter = batchStreamFormatter.getBatchStreamFormatter();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const unstable_onChunk = ([index, string])=>{
|
|
59
|
-
if (index === -1) {
|
|
60
|
-
// full response, no streaming
|
|
61
|
-
resolve(opts.res.send(string));
|
|
62
|
-
} else {
|
|
63
|
-
stream.push(formatter(index, string));
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
resolveHTTPResponse.resolveHTTPResponse({
|
|
67
|
-
req,
|
|
68
|
-
createContext,
|
|
69
|
-
path: opts.path,
|
|
70
|
-
router: opts.router,
|
|
71
|
-
batching: opts.batching,
|
|
72
|
-
responseMeta: opts.responseMeta,
|
|
73
|
-
onError (o) {
|
|
74
|
-
opts?.onError?.({
|
|
75
|
-
...o,
|
|
76
|
-
req: opts.req
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
unstable_onHead,
|
|
80
|
-
unstable_onChunk
|
|
81
|
-
}).then(()=>{
|
|
82
|
-
if (isStream) {
|
|
83
|
-
stream.push(formatter.end());
|
|
84
|
-
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
85
|
-
}
|
|
86
|
-
}).catch(()=>{
|
|
87
|
-
if (isStream) {
|
|
88
|
-
stream.push(null);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return promise;
|
|
92
|
-
}
|
|
93
7
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
fastify.removeContentTypeParser('application/json');
|
|
97
|
-
fastify.addContentTypeParser('application/json', {
|
|
98
|
-
parseAs: 'string'
|
|
99
|
-
}, function(_, body, _done) {
|
|
100
|
-
_done(null, body);
|
|
101
|
-
});
|
|
102
|
-
let prefix = opts.prefix ?? '';
|
|
103
|
-
// https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
|
|
104
|
-
// @ts-expect-error property 'default' does not exists on type ...
|
|
105
|
-
if (typeof fastifyTRPCPlugin.default !== 'function') {
|
|
106
|
-
prefix = ''; // handled by fastify internally
|
|
107
|
-
}
|
|
108
|
-
fastify.all(`${prefix}/:path`, async (req, res)=>{
|
|
109
|
-
const path = req.params.path;
|
|
110
|
-
await fastifyRequestHandler({
|
|
111
|
-
...opts.trpcOptions,
|
|
112
|
-
req,
|
|
113
|
-
res,
|
|
114
|
-
path
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
if (opts.useWSS) {
|
|
118
|
-
adapters_ws.applyWSSHandler({
|
|
119
|
-
...opts.trpcOptions,
|
|
120
|
-
wss: fastify.websocketServer
|
|
121
|
-
});
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
123
|
-
fastify.get(prefix ?? '/', {
|
|
124
|
-
websocket: true
|
|
125
|
-
}, ()=>{});
|
|
126
|
-
}
|
|
127
|
-
done();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
131
|
-
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
8
|
+
exports.fastifyRequestHandler = fastifyRequestHandler.fastifyRequestHandler;
|
|
9
|
+
exports.fastifyTRPCPlugin = fastifyTRPCPlugin.fastifyTRPCPlugin;
|