@trpc/server 11.0.0-alpha-tmp-export-from-main.213 → 11.0.0-alpha-tmp-export-from-main-nuke-core.236
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/@trpc/server/http.d.ts +7 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/@trpc/server/index.d.ts +69 -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 +1 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +20 -109
- package/dist/adapters/aws-lambda/index.mjs +5 -92
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +101 -0
- package/dist/adapters/aws-lambda/utils.mjs +94 -0
- package/dist/adapters/express.d.ts +1 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +1 -6
- package/dist/adapters/express.mjs +1 -4
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +84 -0
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +82 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +50 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +48 -0
- package/dist/adapters/fastify/index.js +4 -125
- package/dist/adapters/fastify/index.mjs +2 -125
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +120 -0
- package/dist/adapters/fetch/fetchRequestHandler.mjs +118 -0
- package/dist/adapters/fetch/index.js +2 -115
- package/dist/adapters/fetch/index.mjs +1 -116
- package/dist/adapters/fetch/types.d.ts +2 -3
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +1 -2
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +7 -9
- package/dist/adapters/next.mjs +5 -5
- 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.js +20 -646
- package/dist/adapters/node-http/content-type/form-data/index.mjs +9 -631
- 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.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.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 +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +44 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +42 -0
- package/dist/adapters/node-http/content-type/json/index.js +7 -43
- package/dist/adapters/node-http/content-type/json/index.mjs +5 -39
- package/dist/adapters/node-http/index.js +1 -6
- package/dist/adapters/node-http/index.mjs +1 -4
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/{contentType-72ed9df5.mjs → adapters/node-http/internals/contentType.mjs} +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-55f05150.js → adapters/node-http/nodeHTTPRequestHandler.js} +8 -6
- package/dist/{nodeHTTPRequestHandler-2d5c8791.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +6 -4
- package/dist/adapters/node-http/types.d.ts +3 -4
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +3 -11
- package/dist/adapters/standalone.mjs +3 -5
- package/dist/adapters/ws.d.ts +3 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +33 -28
- package/dist/adapters/ws.mjs +8 -1
- package/dist/bundle-analysis.json +757 -0
- package/dist/http.d.ts +1 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -23
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -68
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -43
- package/dist/index.mjs +8 -1
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +203 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +201 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +167 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +163 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +35 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +30 -0
- package/dist/observable/index.d.ts +5 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +13 -0
- package/dist/observable/index.mjs +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/observable.js +126 -0
- package/dist/observable/observable.mjs +122 -0
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +103 -0
- package/dist/observable/operators.mjs +99 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/rpc.d.ts +1 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -15
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +6 -11
- package/dist/shared.mjs +4 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +52 -0
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
- 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 +24 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
- 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 +51 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.d.ts +37 -0
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.js +48 -0
- package/dist/unstable-core-do-not-import/index.mjs +16 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +95 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
- package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
- 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 +72 -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 +101 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
- 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 +85 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +156 -0
- package/dist/unstable-core-do-not-import/router.mjs +151 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
- 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 +5 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +107 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
- package/dist/unstable-core-do-not-import/types.d.ts +98 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +44 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -0
- package/package.json +54 -126
- package/src/@trpc/server/http.ts +26 -0
- package/src/@trpc/server/index.ts +105 -0
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +4 -5
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
- package/src/adapters/fetch/types.ts +2 -3
- package/src/adapters/next.ts +2 -3
- 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 +6 -4
- package/src/adapters/node-http/types.ts +4 -5
- package/src/adapters/standalone.ts +3 -3
- package/src/adapters/ws.ts +14 -13
- package/src/http.ts +1 -26
- package/src/index.ts +1 -105
- package/src/observable/index.ts +10 -0
- package/src/observable/observable.ts +158 -0
- package/src/observable/operators.ts +119 -0
- package/src/observable/types.ts +76 -0
- package/src/rpc.ts +1 -26
- package/src/shared.ts +1 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
- package/src/unstable-core-do-not-import/createProxy.ts +59 -0
- package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
- package/src/unstable-core-do-not-import/http/index.ts +23 -0
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
- package/src/unstable-core-do-not-import/http/types.ts +111 -0
- package/src/unstable-core-do-not-import/index.ts +110 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
- package/src/unstable-core-do-not-import/middleware.ts +233 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +108 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
- package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
- package/src/unstable-core-do-not-import/router.ts +370 -0
- package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
- package/src/unstable-core-do-not-import/serialize.ts +122 -0
- package/src/unstable-core-do-not-import/transformer.ts +202 -0
- package/src/unstable-core-do-not-import/types.ts +151 -0
- package/src/unstable-core-do-not-import/utils.ts +59 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -10
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/contentType-24c44bba.js +0 -5
- package/dist/nodeHTTPRequestHandler-7691fc79.js +0 -105
- package/dist/observable.d.ts +0 -3
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -32
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -16
- /package/dist/{contentType-d9d22104.js → adapters/node-http/internals/contentType.js} +0 -0
package/dist/adapters/express.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-55f05150.js');
|
|
6
|
-
require('@trpc/core');
|
|
7
|
-
require('./node-http/content-type/json/index.js');
|
|
8
|
-
require('../contentType-d9d22104.js');
|
|
3
|
+
var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
|
|
9
4
|
|
|
10
5
|
function createExpressMiddleware(opts) {
|
|
11
6
|
return async (req, res)=>{
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '@trpc/core';
|
|
3
|
-
import './node-http/content-type/json/index.mjs';
|
|
4
|
-
import '../contentType-72ed9df5.mjs';
|
|
1
|
+
import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
|
|
5
2
|
|
|
6
3
|
function createExpressMiddleware(opts) {
|
|
7
4
|
return async (req, res)=>{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import type { AnyRouter } from '
|
|
3
|
-
import type { HTTPBaseHandlerOptions } from '
|
|
2
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
3
|
+
import type { HTTPBaseHandlerOptions } from '../../@trpc/server/http';
|
|
4
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> & {
|
|
@@ -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,kBAyFjE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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;
|
|
@@ -0,0 +1,82 @@
|
|
|
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,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
@@ -10,7 +9,7 @@
|
|
|
10
9
|
*/
|
|
11
10
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
12
11
|
import type { FastifyHandlerOptions } from '.';
|
|
13
|
-
import type { AnyRouter } from '
|
|
12
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
14
13
|
import type { NodeHTTPCreateContextFnOptions } from '../node-http';
|
|
15
14
|
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
16
15
|
prefix?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyTRPCPlugin.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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;
|
|
@@ -0,0 +1,48 @@
|
|
|
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,130 +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
|
-
var core = require('@trpc/core');
|
|
7
|
-
var adapters_ws = require('../ws.js');
|
|
8
6
|
|
|
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 = core.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
|
-
core.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
7
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
* Do **not** import from `@trpc/core`
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
91
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
92
|
-
* ```
|
|
93
|
-
*/ /// <reference types="@fastify/websocket" />
|
|
94
|
-
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
95
|
-
fastify.removeContentTypeParser('application/json');
|
|
96
|
-
fastify.addContentTypeParser('application/json', {
|
|
97
|
-
parseAs: 'string'
|
|
98
|
-
}, function(_, body, _done) {
|
|
99
|
-
_done(null, body);
|
|
100
|
-
});
|
|
101
|
-
let prefix = opts.prefix ?? '';
|
|
102
|
-
// https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
|
|
103
|
-
// @ts-expect-error property 'default' does not exists on type ...
|
|
104
|
-
if (typeof fastifyTRPCPlugin.default !== 'function') {
|
|
105
|
-
prefix = ''; // handled by fastify internally
|
|
106
|
-
}
|
|
107
|
-
fastify.all(`${prefix}/:path`, async (req, res)=>{
|
|
108
|
-
const path = req.params.path;
|
|
109
|
-
await fastifyRequestHandler({
|
|
110
|
-
...opts.trpcOptions,
|
|
111
|
-
req,
|
|
112
|
-
res,
|
|
113
|
-
path
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
if (opts.useWSS) {
|
|
117
|
-
adapters_ws.applyWSSHandler({
|
|
118
|
-
...opts.trpcOptions,
|
|
119
|
-
wss: fastify.websocketServer
|
|
120
|
-
});
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
122
|
-
fastify.get(prefix ?? '/', {
|
|
123
|
-
websocket: true
|
|
124
|
-
}, ()=>{});
|
|
125
|
-
}
|
|
126
|
-
done();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
130
|
-
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
8
|
+
exports.fastifyRequestHandler = fastifyRequestHandler.fastifyRequestHandler;
|
|
9
|
+
exports.fastifyTRPCPlugin = fastifyTRPCPlugin.fastifyTRPCPlugin;
|
|
@@ -1,125 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { applyWSSHandler } from '../ws.mjs';
|
|
4
|
-
|
|
5
|
-
async function fastifyRequestHandler(opts) {
|
|
6
|
-
const createContext = async (innerOpts)=>{
|
|
7
|
-
return await opts.createContext?.({
|
|
8
|
-
...opts,
|
|
9
|
-
...innerOpts
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
13
|
-
const req = {
|
|
14
|
-
query,
|
|
15
|
-
method: opts.req.method,
|
|
16
|
-
headers: opts.req.headers,
|
|
17
|
-
body: opts.req.body ?? 'null'
|
|
18
|
-
};
|
|
19
|
-
let resolve;
|
|
20
|
-
const promise = new Promise((r)=>resolve = r);
|
|
21
|
-
let isStream = false;
|
|
22
|
-
let stream;
|
|
23
|
-
let formatter;
|
|
24
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
25
|
-
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
26
|
-
opts.res.statusCode = head.status;
|
|
27
|
-
}
|
|
28
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
29
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
void opts.res.header(key, value);
|
|
33
|
-
}
|
|
34
|
-
if (isStreaming) {
|
|
35
|
-
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
36
|
-
void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
|
|
37
|
-
stream = new Readable();
|
|
38
|
-
stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
39
|
-
resolve(opts.res.send(stream));
|
|
40
|
-
isStream = true;
|
|
41
|
-
formatter = getBatchStreamFormatter();
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const unstable_onChunk = ([index, string])=>{
|
|
45
|
-
if (index === -1) {
|
|
46
|
-
// full response, no streaming
|
|
47
|
-
resolve(opts.res.send(string));
|
|
48
|
-
} else {
|
|
49
|
-
stream.push(formatter(index, string));
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
resolveHTTPResponse({
|
|
53
|
-
req,
|
|
54
|
-
createContext,
|
|
55
|
-
path: opts.path,
|
|
56
|
-
router: opts.router,
|
|
57
|
-
batching: opts.batching,
|
|
58
|
-
responseMeta: opts.responseMeta,
|
|
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
|
-
/**
|
|
81
|
-
* 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`
|
|
82
|
-
*
|
|
83
|
-
* Do **not** import from `@trpc/core`
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
87
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
88
|
-
* ```
|
|
89
|
-
*/ /// <reference types="@fastify/websocket" />
|
|
90
|
-
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
91
|
-
fastify.removeContentTypeParser('application/json');
|
|
92
|
-
fastify.addContentTypeParser('application/json', {
|
|
93
|
-
parseAs: 'string'
|
|
94
|
-
}, function(_, body, _done) {
|
|
95
|
-
_done(null, body);
|
|
96
|
-
});
|
|
97
|
-
let prefix = opts.prefix ?? '';
|
|
98
|
-
// https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
|
|
99
|
-
// @ts-expect-error property 'default' does not exists on type ...
|
|
100
|
-
if (typeof fastifyTRPCPlugin.default !== 'function') {
|
|
101
|
-
prefix = ''; // handled by fastify internally
|
|
102
|
-
}
|
|
103
|
-
fastify.all(`${prefix}/:path`, async (req, res)=>{
|
|
104
|
-
const path = req.params.path;
|
|
105
|
-
await fastifyRequestHandler({
|
|
106
|
-
...opts.trpcOptions,
|
|
107
|
-
req,
|
|
108
|
-
res,
|
|
109
|
-
path
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
if (opts.useWSS) {
|
|
113
|
-
applyWSSHandler({
|
|
114
|
-
...opts.trpcOptions,
|
|
115
|
-
wss: fastify.websocketServer
|
|
116
|
-
});
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
118
|
-
fastify.get(prefix ?? '/', {
|
|
119
|
-
websocket: true
|
|
120
|
-
}, ()=>{});
|
|
121
|
-
}
|
|
122
|
-
done();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export { fastifyRequestHandler, fastifyTRPCPlugin };
|
|
1
|
+
export { fastifyRequestHandler } from './fastifyRequestHandler.mjs';
|
|
2
|
+
export { fastifyTRPCPlugin } from './fastifyTRPCPlugin.mjs';
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
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
3
|
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
6
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
8
7
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
9
8
|
* ```
|
|
10
9
|
*/
|
|
11
|
-
import type { AnyRouter } from '
|
|
10
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
12
11
|
import type { FetchHandlerOptions } from './types';
|
|
13
12
|
export type FetchHandlerRequestOptions<TRouter extends AnyRouter> = FetchHandlerOptions<TRouter> & {
|
|
14
13
|
req: Request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|