@trpc/server 11.0.0-alpha-tmp-export-from-main.221 → 11.0.0-alpha-tmp-export-from-main.222
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/aws-lambda/index.d.mts +68 -0
- package/dist/adapters/aws-lambda/index.d.ts +54 -6
- package/dist/adapters/aws-lambda/index.js +110 -20
- package/dist/adapters/aws-lambda/index.mjs +94 -4
- package/dist/adapters/express.d.mts +19 -0
- package/dist/adapters/express.d.ts +9 -6
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/index.d.mts +33 -0
- package/dist/adapters/fastify/index.d.ts +33 -3
- package/dist/adapters/fastify/index.js +124 -5
- package/dist/adapters/fastify/index.mjs +125 -2
- package/dist/adapters/fetch/index.d.mts +51 -0
- package/dist/adapters/fetch/index.d.ts +51 -3
- package/dist/adapters/fetch/index.js +115 -4
- package/dist/adapters/fetch/index.mjs +116 -1
- package/dist/adapters/next.d.mts +21 -0
- package/dist/adapters/next.d.ts +11 -7
- package/dist/adapters/next.js +6 -6
- package/dist/adapters/next.mjs +2 -2
- package/dist/adapters/node-http/content-type/form-data/index.d.mts +219 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +201 -10
- package/dist/adapters/node-http/content-type/form-data/index.js +662 -23
- package/dist/adapters/node-http/content-type/form-data/index.mjs +646 -10
- package/dist/adapters/node-http/{types.d.ts → content-type/json/index.d.mts} +21 -15
- package/dist/adapters/node-http/content-type/json/index.d.ts +89 -2
- package/dist/adapters/node-http/content-type/json/index.js +48 -7
- package/dist/adapters/node-http/content-type/json/index.mjs +44 -3
- package/dist/adapters/node-http/index.d.mts +100 -0
- package/dist/adapters/node-http/index.d.ts +100 -3
- package/dist/adapters/node-http/index.js +106 -4
- package/dist/adapters/node-http/index.mjs +107 -1
- package/dist/adapters/standalone.d.mts +21 -0
- package/dist/adapters/standalone.d.ts +11 -9
- package/dist/adapters/standalone.js +9 -5
- package/dist/adapters/standalone.mjs +2 -2
- package/dist/adapters/ws.d.mts +36 -0
- package/dist/adapters/ws.d.ts +12 -13
- package/dist/adapters/ws.js +30 -28
- package/dist/adapters/ws.mjs +12 -10
- package/dist/http.d.mts +1 -0
- package/dist/http.d.ts +1 -7
- package/dist/http.js +7 -7
- package/dist/http.mjs +1 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +5 -65
- package/dist/index.js +809 -46
- package/dist/index.mjs +798 -1
- package/dist/observable.d.mts +1 -0
- package/dist/observable.d.ts +1 -3
- package/dist/observable.js +8 -8
- package/dist/observable.mjs +1 -1
- package/dist/rpc.d.mts +1 -0
- package/dist/rpc.d.ts +1 -3
- package/dist/rpc.js +5 -5
- package/dist/rpc.mjs +1 -1
- package/dist/shared.d.mts +1 -0
- package/dist/shared.d.ts +1 -26
- package/dist/shared.js +4 -4
- package/dist/shared.mjs +1 -1
- package/dist/unstableDontImportMe.d.mts +1 -0
- package/dist/unstableDontImportMe.d.ts +1 -10
- package/dist/unstableDontImportMe.js +1549 -142
- package/dist/unstableDontImportMe.mjs +1514 -1
- package/package.json +6 -4
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.d.ts +0 -48
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -100
- package/dist/adapters/aws-lambda/utils.mjs +0 -93
- package/dist/adapters/express.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +0 -13
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +0 -81
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -79
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +0 -22
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -51
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -49
- package/dist/adapters/fastify/index.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +0 -18
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +0 -118
- package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -116
- package/dist/adapters/fetch/index.d.ts.map +0 -1
- package/dist/adapters/fetch/types.d.ts +0 -31
- package/dist/adapters/fetch/types.d.ts.map +0 -1
- package/dist/adapters/next.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -70
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -42
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -40
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/index.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
- package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.js +0 -8
- package/dist/adapters/node-http/internals/contentType.mjs +0 -6
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +0 -14
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -109
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -107
- package/dist/adapters/node-http/types.d.ts.map +0 -1
- package/dist/adapters/standalone.d.ts.map +0 -1
- package/dist/adapters/ws.d.ts.map +0 -1
- package/dist/http.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +0 -203
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +0 -201
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +0 -167
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +0 -163
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +0 -35
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +0 -30
- package/dist/observable.d.ts.map +0 -1
- package/dist/rpc.d.ts.map +0 -1
- package/dist/shared.d.ts.map +0 -1
- package/dist/unstableDontImportMe.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "11.0.0-alpha-tmp-export-from-main.
|
|
3
|
+
"version": "11.0.0-alpha-tmp-export-from-main.222+af7867f57",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"directory": "packages/server"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "
|
|
17
|
+
"build": "bunchee",
|
|
18
|
+
"build-r": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
|
|
18
19
|
"dev": "pnpm build --watch",
|
|
19
20
|
"codegen-entrypoints": "tsx entrypoints.script.ts",
|
|
20
21
|
"benchmark": "tsc --project tsconfig.benchmark.json",
|
|
@@ -201,7 +202,7 @@
|
|
|
201
202
|
"access": "public"
|
|
202
203
|
},
|
|
203
204
|
"dependencies": {
|
|
204
|
-
"@trpc/core": "11.0.0-alpha-tmp-export-from-main.
|
|
205
|
+
"@trpc/core": "11.0.0-alpha-tmp-export-from-main.222+af7867f57"
|
|
205
206
|
},
|
|
206
207
|
"devDependencies": {
|
|
207
208
|
"@fastify/websocket": "^7.1.2",
|
|
@@ -215,6 +216,7 @@
|
|
|
215
216
|
"@types/ws": "^8.2.0",
|
|
216
217
|
"@web3-storage/multipart-parser": "^1.0.0",
|
|
217
218
|
"aws-lambda": "^1.0.7",
|
|
219
|
+
"bunchee": "4.4.1",
|
|
218
220
|
"devalue": "^4.0.0",
|
|
219
221
|
"eslint": "^8.40.0",
|
|
220
222
|
"express": "^4.17.1",
|
|
@@ -240,5 +242,5 @@
|
|
|
240
242
|
"funding": [
|
|
241
243
|
"https://trpc.io/sponsor"
|
|
242
244
|
],
|
|
243
|
-
"gitHead": "
|
|
245
|
+
"gitHead": "af7867f578c243ea1e10f0a8357094d43756d7d4"
|
|
244
246
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/@trpc-server/http.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EACjC,OAAO,IAAI,YAAY,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASvC,OAAO,KAAK,EACV,eAAe,EAEf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAUjB,cAAc,SAAS,CAAC;AAqDxB;;IAEI;AACJ,KAAK,gBAAgB,CAAC,KAAK,IAAI,KAAK,SAAS,oBAAoB,GAC7D,qBAAqB,GACrB,KAAK,SAAS,sBAAsB,GACpC,iCAAiC,GACjC,KAAK,CAAC;AACV,wBAAgB,uBAAuB,CACrC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAExC,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GACtC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,CA4B5D"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
3
|
-
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
8
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context as APIGWContext } from 'aws-lambda';
|
|
12
|
-
import type { AnyRouter, inferRouterContext } from '../..';
|
|
13
|
-
import type { HTTPHeaders, OnErrorFunction, ResponseMetaFn, TRPCRequestInfo } from '../../http';
|
|
14
|
-
export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
15
|
-
export type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
|
|
16
|
-
export type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
|
|
17
|
-
event: TEvent;
|
|
18
|
-
context: APIGWContext;
|
|
19
|
-
info: TRPCRequestInfo;
|
|
20
|
-
};
|
|
21
|
-
export type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({ event, context, info, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
22
|
-
export type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = {
|
|
23
|
-
router: TRouter;
|
|
24
|
-
batching?: {
|
|
25
|
-
enabled: boolean;
|
|
26
|
-
};
|
|
27
|
-
onError?: OnErrorFunction<TRouter, TEvent>;
|
|
28
|
-
responseMeta?: ResponseMetaFn<TRouter>;
|
|
29
|
-
} & ({
|
|
30
|
-
/**
|
|
31
|
-
* @link https://trpc.io/docs/v11/context
|
|
32
|
-
**/
|
|
33
|
-
createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
34
|
-
} | {
|
|
35
|
-
/**
|
|
36
|
-
* @link https://trpc.io/docs/v11/context
|
|
37
|
-
**/
|
|
38
|
-
createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
39
|
-
});
|
|
40
|
-
export declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
|
|
41
|
-
export declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
|
|
42
|
-
export declare function getHTTPMethod(event: APIGatewayEvent): string;
|
|
43
|
-
export declare function getPath(event: APIGatewayEvent): string;
|
|
44
|
-
export declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'];
|
|
45
|
-
export type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
|
|
46
|
-
export type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
|
|
47
|
-
export declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
|
|
48
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EACjC,OAAO,IAAI,YAAY,EACxB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAI3D,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;AAC5E,MAAM,MAAM,gBAAgB,GACxB,qBAAqB,GACrB,iCAAiC,CAAC;AAEtC,MAAM,MAAM,6BAA6B,CAAC,MAAM,SAAS,eAAe,IAAI;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,wBAAwB,CAClC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,IAC5B,CAAC,EACH,KAAK,EACL,OAAO,EACP,IAAI,GACL,EAAE,6BAA6B,CAAC,MAAM,CAAC,KACpC,kBAAkB,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzC,MAAM,MAAM,gBAAgB,CAC1B,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,IAE5B;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3C,YAAY,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CACxC,GAAG,CACA;IACE;;QAEI;IACJ,aAAa,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAC1D,GACD;IACE;;QAEI;IACJ,aAAa,CAAC,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAC3D,CACJ,CAAC;AAEN,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,oBAAoB,CAE/B;AACD,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,sBAAsB,CAEjC;AAoBD,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,UAWnD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe,UA+B7C;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,WAAW,GACnB,gBAAgB,CAAC,SAAS,CAAC,CAU7B;AAED,MAAM,MAAM,+BAA+B,GAAG,KAAK,GAAG,KAAK,CAAC;AAC5D,MAAM,MAAM,8BAA8B,GACtC,+BAA+B,GAC/B,QAAQ,CAAC;AAEb,eAAO,MAAM,4CAA4C,QAEiD,CAAC"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@trpc/core');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
7
|
-
*
|
|
8
|
-
* Do **not** import from `@trpc/core`
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
12
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
|
-
* ```
|
|
14
|
-
*/ // @trpc/server
|
|
15
|
-
function isPayloadV1(event) {
|
|
16
|
-
return determinePayloadFormat(event) == '1.0';
|
|
17
|
-
}
|
|
18
|
-
function isPayloadV2(event) {
|
|
19
|
-
return determinePayloadFormat(event) == '2.0';
|
|
20
|
-
}
|
|
21
|
-
function determinePayloadFormat(event) {
|
|
22
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
23
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
24
|
-
// If there is no version property, then the version is implied as 1.0
|
|
25
|
-
const unknownEvent = event;
|
|
26
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
27
|
-
return '1.0';
|
|
28
|
-
} else {
|
|
29
|
-
if ([
|
|
30
|
-
'1.0',
|
|
31
|
-
'2.0'
|
|
32
|
-
].includes(unknownEvent.version)) {
|
|
33
|
-
return unknownEvent.version;
|
|
34
|
-
} else {
|
|
35
|
-
return 'custom';
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function getHTTPMethod(event) {
|
|
40
|
-
if (isPayloadV1(event)) {
|
|
41
|
-
return event.httpMethod;
|
|
42
|
-
}
|
|
43
|
-
if (isPayloadV2(event)) {
|
|
44
|
-
return event.requestContext.http.method;
|
|
45
|
-
}
|
|
46
|
-
throw new core.TRPCError({
|
|
47
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
48
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function getPath(event) {
|
|
52
|
-
if (isPayloadV1(event)) {
|
|
53
|
-
if (!event.pathParameters) {
|
|
54
|
-
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
55
|
-
return event.path.split('/').pop() ?? '';
|
|
56
|
-
}
|
|
57
|
-
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
58
|
-
for (const match of matches){
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
|
-
const group = match[1];
|
|
61
|
-
if (group.includes('+') && event.pathParameters) {
|
|
62
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return event.path.slice(1);
|
|
66
|
-
}
|
|
67
|
-
if (isPayloadV2(event)) {
|
|
68
|
-
const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
69
|
-
for (const match1 of matches1){
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
71
|
-
const group1 = match1[1];
|
|
72
|
-
if (group1.includes('+') && event.pathParameters) {
|
|
73
|
-
return event.pathParameters[group1.replace('+', '')] ?? '';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return event.rawPath.slice(1);
|
|
77
|
-
}
|
|
78
|
-
throw new core.TRPCError({
|
|
79
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
80
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function transformHeaders(headers) {
|
|
84
|
-
const obj = {};
|
|
85
|
-
for (const [key, value] of Object.entries(headers)){
|
|
86
|
-
if (typeof value === 'undefined') {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
90
|
-
}
|
|
91
|
-
return obj;
|
|
92
|
-
}
|
|
93
|
-
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';
|
|
94
|
-
|
|
95
|
-
exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
|
|
96
|
-
exports.getHTTPMethod = getHTTPMethod;
|
|
97
|
-
exports.getPath = getPath;
|
|
98
|
-
exports.isPayloadV1 = isPayloadV1;
|
|
99
|
-
exports.isPayloadV2 = isPayloadV2;
|
|
100
|
-
exports.transformHeaders = transformHeaders;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { TRPCError } from '@trpc/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 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`
|
|
5
|
-
*
|
|
6
|
-
* Do **not** import from `@trpc/core`
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,CACjB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvE,OAAO,CAAC,OAAO,CAgBjB"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import type { AnyRouter } from '../..';
|
|
3
|
-
import type { HTTPBaseHandlerOptions } from '../../http';
|
|
4
|
-
import type { NodeHTTPCreateContextOption } from '../node-http';
|
|
5
|
-
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
6
|
-
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
7
|
-
req: TRequest;
|
|
8
|
-
res: TResponse;
|
|
9
|
-
path: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<never>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=fastifyRequestHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EACV,sBAAsB,EAKvB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE5D,KAAK,4BAA4B,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,EAC9B,IAAI,EAAE,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,kBAyFjE"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_stream = require('node:stream');
|
|
4
|
-
var core = require('@trpc/core');
|
|
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 node_stream.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 = core.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
|
-
core.resolveHTTPResponse({
|
|
54
|
-
req,
|
|
55
|
-
createContext,
|
|
56
|
-
path: opts.path,
|
|
57
|
-
router: opts.router,
|
|
58
|
-
batching: opts.batching,
|
|
59
|
-
responseMeta: opts.responseMeta,
|
|
60
|
-
onError (o) {
|
|
61
|
-
opts?.onError?.({
|
|
62
|
-
...o,
|
|
63
|
-
req: opts.req
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
unstable_onHead,
|
|
67
|
-
unstable_onChunk
|
|
68
|
-
}).then(()=>{
|
|
69
|
-
if (isStream) {
|
|
70
|
-
stream.push(formatter.end());
|
|
71
|
-
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
72
|
-
}
|
|
73
|
-
}).catch(()=>{
|
|
74
|
-
if (isStream) {
|
|
75
|
-
stream.push(null);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return promise;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
|
-
import { resolveHTTPResponse, getBatchStreamFormatter } from '@trpc/core';
|
|
3
|
-
|
|
4
|
-
async function fastifyRequestHandler(opts) {
|
|
5
|
-
const createContext = async (innerOpts)=>{
|
|
6
|
-
return await opts.createContext?.({
|
|
7
|
-
...opts,
|
|
8
|
-
...innerOpts
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
12
|
-
const req = {
|
|
13
|
-
query,
|
|
14
|
-
method: opts.req.method,
|
|
15
|
-
headers: opts.req.headers,
|
|
16
|
-
body: opts.req.body ?? 'null'
|
|
17
|
-
};
|
|
18
|
-
let resolve;
|
|
19
|
-
const promise = new Promise((r)=>resolve = r);
|
|
20
|
-
let isStream = false;
|
|
21
|
-
let stream;
|
|
22
|
-
let formatter;
|
|
23
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
24
|
-
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
25
|
-
opts.res.statusCode = head.status;
|
|
26
|
-
}
|
|
27
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
28
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
void opts.res.header(key, value);
|
|
32
|
-
}
|
|
33
|
-
if (isStreaming) {
|
|
34
|
-
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
35
|
-
void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
|
|
36
|
-
stream = new Readable();
|
|
37
|
-
stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
38
|
-
resolve(opts.res.send(stream));
|
|
39
|
-
isStream = true;
|
|
40
|
-
formatter = getBatchStreamFormatter();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const unstable_onChunk = ([index, string])=>{
|
|
44
|
-
if (index === -1) {
|
|
45
|
-
// full response, no streaming
|
|
46
|
-
resolve(opts.res.send(string));
|
|
47
|
-
} else {
|
|
48
|
-
stream.push(formatter(index, string));
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
resolveHTTPResponse({
|
|
52
|
-
req,
|
|
53
|
-
createContext,
|
|
54
|
-
path: opts.path,
|
|
55
|
-
router: opts.router,
|
|
56
|
-
batching: opts.batching,
|
|
57
|
-
responseMeta: opts.responseMeta,
|
|
58
|
-
onError (o) {
|
|
59
|
-
opts?.onError?.({
|
|
60
|
-
...o,
|
|
61
|
-
req: opts.req
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
unstable_onHead,
|
|
65
|
-
unstable_onChunk
|
|
66
|
-
}).then(()=>{
|
|
67
|
-
if (isStream) {
|
|
68
|
-
stream.push(formatter.end());
|
|
69
|
-
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
70
|
-
}
|
|
71
|
-
}).catch(()=>{
|
|
72
|
-
if (isStream) {
|
|
73
|
-
stream.push(null);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return promise;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { fastifyRequestHandler };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
3
|
-
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
8
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
12
|
-
import type { FastifyHandlerOptions } from '.';
|
|
13
|
-
import type { AnyRouter } from '../..';
|
|
14
|
-
import type { NodeHTTPCreateContextFnOptions } from '../node-http';
|
|
15
|
-
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
16
|
-
prefix?: string;
|
|
17
|
-
useWSS?: boolean;
|
|
18
|
-
trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply>;
|
|
19
|
-
}
|
|
20
|
-
export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
21
|
-
export declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
22
|
-
//# sourceMappingURL=fastifyTRPCPlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyTRPCPlugin.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;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,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAKnE,MAAM,WAAW,wBAAwB,CAAC,OAAO,SAAS,SAAS;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;CAC3E;AAED,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,cAAc,EACd,YAAY,CACb,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACvC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,QAkC5B"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var ws = require('../ws.js');
|
|
4
|
-
var fastifyRequestHandler = require('./fastifyRequestHandler.js');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
8
|
-
*
|
|
9
|
-
* Do **not** import from `@trpc/core`
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
13
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
14
|
-
* ```
|
|
15
|
-
*/ /// <reference types="@fastify/websocket" />
|
|
16
|
-
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
17
|
-
fastify.removeContentTypeParser('application/json');
|
|
18
|
-
fastify.addContentTypeParser('application/json', {
|
|
19
|
-
parseAs: 'string'
|
|
20
|
-
}, function(_, body, _done) {
|
|
21
|
-
_done(null, body);
|
|
22
|
-
});
|
|
23
|
-
let prefix = opts.prefix ?? '';
|
|
24
|
-
// https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
|
|
25
|
-
// @ts-expect-error property 'default' does not exists on type ...
|
|
26
|
-
if (typeof fastifyTRPCPlugin.default !== 'function') {
|
|
27
|
-
prefix = ''; // handled by fastify internally
|
|
28
|
-
}
|
|
29
|
-
fastify.all(`${prefix}/:path`, async (req, res)=>{
|
|
30
|
-
const path = req.params.path;
|
|
31
|
-
await fastifyRequestHandler.fastifyRequestHandler({
|
|
32
|
-
...opts.trpcOptions,
|
|
33
|
-
req,
|
|
34
|
-
res,
|
|
35
|
-
path
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
if (opts.useWSS) {
|
|
39
|
-
ws.applyWSSHandler({
|
|
40
|
-
...opts.trpcOptions,
|
|
41
|
-
wss: fastify.websocketServer
|
|
42
|
-
});
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
44
|
-
fastify.get(prefix ?? '/', {
|
|
45
|
-
websocket: true
|
|
46
|
-
}, ()=>{});
|
|
47
|
-
}
|
|
48
|
-
done();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { applyWSSHandler } from '../ws.mjs';
|
|
2
|
-
import { fastifyRequestHandler } from './fastifyRequestHandler.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
6
|
-
*
|
|
7
|
-
* Do **not** import from `@trpc/core`
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
11
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
12
|
-
* ```
|
|
13
|
-
*/ /// <reference types="@fastify/websocket" />
|
|
14
|
-
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
15
|
-
fastify.removeContentTypeParser('application/json');
|
|
16
|
-
fastify.addContentTypeParser('application/json', {
|
|
17
|
-
parseAs: 'string'
|
|
18
|
-
}, function(_, body, _done) {
|
|
19
|
-
_done(null, body);
|
|
20
|
-
});
|
|
21
|
-
let prefix = opts.prefix ?? '';
|
|
22
|
-
// https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11
|
|
23
|
-
// @ts-expect-error property 'default' does not exists on type ...
|
|
24
|
-
if (typeof fastifyTRPCPlugin.default !== 'function') {
|
|
25
|
-
prefix = ''; // handled by fastify internally
|
|
26
|
-
}
|
|
27
|
-
fastify.all(`${prefix}/:path`, async (req, res)=>{
|
|
28
|
-
const path = req.params.path;
|
|
29
|
-
await fastifyRequestHandler({
|
|
30
|
-
...opts.trpcOptions,
|
|
31
|
-
req,
|
|
32
|
-
res,
|
|
33
|
-
path
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
if (opts.useWSS) {
|
|
37
|
-
applyWSSHandler({
|
|
38
|
-
...opts.trpcOptions,
|
|
39
|
-
wss: fastify.websocketServer
|
|
40
|
-
});
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
42
|
-
fastify.get(prefix ?? '/', {
|
|
43
|
-
websocket: true
|
|
44
|
-
}, ()=>{});
|
|
45
|
-
}
|
|
46
|
-
done();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { fastifyTRPCPlugin };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
3
|
-
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
8
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
import type { AnyRouter } from '../..';
|
|
12
|
-
import type { FetchHandlerOptions } from './types';
|
|
13
|
-
export type FetchHandlerRequestOptions<TRouter extends AnyRouter> = FetchHandlerOptions<TRouter> & {
|
|
14
|
-
req: Request;
|
|
15
|
-
endpoint: string;
|
|
16
|
-
};
|
|
17
|
-
export declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerRequestOptions<TRouter>): Promise<Response>;
|
|
18
|
-
//# sourceMappingURL=fetchRequestHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQvC,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"}
|