@trpc/server 11.0.0-rc.361 → 11.0.0-rc.363
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 -5
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +1 -2
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.d.ts +13 -0
- package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/getPlanner.js +143 -0
- package/dist/adapters/aws-lambda/getPlanner.mjs +141 -0
- package/dist/adapters/aws-lambda/index.d.ts +12 -9
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +8 -77
- package/dist/adapters/aws-lambda/index.mjs +9 -72
- package/dist/adapters/express.js +1 -0
- package/dist/adapters/express.mjs +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +19 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +22 -64
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +22 -64
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -0
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +2 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +29 -86
- package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -86
- package/dist/adapters/fetch/types.d.ts +2 -2
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +18 -0
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -0
- package/dist/adapters/node-http/incomingMessageToRequest.js +71 -0
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +69 -0
- package/dist/adapters/node-http/index.d.ts +1 -0
- package/dist/adapters/node-http/index.d.ts.map +1 -1
- package/dist/adapters/node-http/index.js +2 -0
- package/dist/adapters/node-http/index.mjs +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +28 -71
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -71
- package/dist/adapters/node-http/types.d.ts +7 -8
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +174 -271
- package/dist/http.js +4 -2
- package/dist/http.mjs +2 -1
- package/dist/index.js +2 -4
- package/dist/index.mjs +1 -2
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -20
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +180 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +178 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.js +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts +15 -0
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/{resolveHTTPResponse.js → resolveResponse.js} +119 -134
- package/dist/unstable-core-do-not-import/http/{resolveHTTPResponse.mjs → resolveResponse.mjs} +119 -134
- package/dist/unstable-core-do-not-import/http/types.d.ts +25 -27
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -9
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +3 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +2 -0
- package/dist/unstable-core-do-not-import/utils.mjs +2 -1
- package/dist/unstable-core-do-not-import.d.ts +9 -3
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +12 -8
- package/dist/unstable-core-do-not-import.mjs +7 -5
- package/package.json +3 -13
- package/src/@trpc/server/http.ts +7 -12
- package/src/@trpc/server/index.ts +0 -3
- package/src/adapters/aws-lambda/getPlanner.ts +191 -0
- package/src/adapters/aws-lambda/index.ts +43 -107
- package/src/adapters/express.ts +1 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +43 -90
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +4 -3
- package/src/adapters/fetch/fetchRequestHandler.ts +35 -111
- package/src/adapters/fetch/types.ts +4 -2
- package/src/adapters/next.ts +1 -1
- package/src/adapters/node-http/incomingMessageToRequest.ts +94 -0
- package/src/adapters/node-http/index.ts +1 -0
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +31 -97
- package/src/adapters/node-http/types.ts +27 -37
- package/src/adapters/standalone.ts +1 -1
- package/src/unstable-core-do-not-import/http/contentType.ts +214 -22
- package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +29 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +2 -2
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +386 -0
- package/src/unstable-core-do-not-import/http/types.ts +25 -30
- package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
- package/src/unstable-core-do-not-import/rootConfig.ts +0 -10
- package/src/unstable-core-do-not-import/utils.ts +4 -0
- package/src/unstable-core-do-not-import.ts +9 -3
- package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
- package/adapters/node-http/content-type/form-data/index.js +0 -1
- package/adapters/node-http/content-type/json/index.d.ts +0 -1
- package/adapters/node-http/content-type/json/index.js +0 -1
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts +0 -10
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/content-type/json/index.js +0 -62
- package/dist/adapters/aws-lambda/content-type/json/index.mjs +0 -60
- package/dist/adapters/aws-lambda/utils.d.ts +0 -31
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -111
- package/dist/adapters/aws-lambda/utils.mjs +0 -103
- package/dist/adapters/content-handlers/concurrentCache.d.ts +0 -7
- package/dist/adapters/content-handlers/concurrentCache.d.ts.map +0 -1
- package/dist/adapters/content-handlers/concurrentCache.js +0 -17
- package/dist/adapters/content-handlers/concurrentCache.mjs +0 -15
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +0 -10
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +0 -1
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +0 -33
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +0 -31
- package/dist/adapters/fastify/content-type/json/index.d.ts +0 -8
- package/dist/adapters/fastify/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/fastify/content-type/json/index.js +0 -62
- package/dist/adapters/fastify/content-type/json/index.mjs +0 -60
- package/dist/adapters/fastify/types.d.ts +0 -11
- package/dist/adapters/fastify/types.d.ts.map +0 -1
- package/dist/adapters/fetch/content-type/json/index.d.ts +0 -9
- package/dist/adapters/fetch/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/fetch/content-type/json/index.js +0 -55
- package/dist/adapters/fetch/content-type/json/index.mjs +0 -53
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -5
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +0 -32
- package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -30
- 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 -45
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -43
- package/dist/adapters/node-http/content-type/json/index.d.ts +0 -5
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/index.js +0 -68
- package/dist/adapters/node-http/content-type/json/index.mjs +0 -66
- package/dist/adapters/node-http/content-type/octet/index.d.ts +0 -5
- package/dist/adapters/node-http/content-type/octet/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/octet/index.js +0 -19
- package/dist/adapters/node-http/content-type/octet/index.mjs +0 -17
- package/dist/adapters/node-http/content-type/types.d.ts +0 -8
- package/dist/adapters/node-http/content-type/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +0 -16
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/contentTypeParsers.js +0 -23
- package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +0 -21
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -11
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
- package/src/adapters/aws-lambda/content-type/json/index.ts +0 -108
- package/src/adapters/aws-lambda/utils.ts +0 -170
- package/src/adapters/content-handlers/concurrentCache.ts +0 -16
- package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +0 -45
- package/src/adapters/fastify/content-type/json/index.ts +0 -106
- package/src/adapters/fastify/types.ts +0 -22
- package/src/adapters/fetch/content-type/json/index.ts +0 -90
- package/src/adapters/node-http/content-type/form-data/index.ts +0 -37
- package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -49
- package/src/adapters/node-http/content-type/json/index.ts +0 -100
- package/src/adapters/node-http/content-type/octet/index.ts +0 -27
- package/src/adapters/node-http/content-type/types.ts +0 -19
- package/src/unstable-core-do-not-import/contentTypeParsers.ts +0 -37
- package/src/unstable-core-do-not-import/http/index.ts +0 -28
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -461
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
-
import '../../../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
-
import { createConcurrentCache } from '../../../content-handlers/concurrentCache.mjs';
|
|
4
|
-
import { lambdaEventToHTTPBody } from '../../utils.mjs';
|
|
5
|
-
|
|
6
|
-
// @trpc/server
|
|
7
|
-
const getLambdaHTTPJSONContentTypeHandler = ()=>{
|
|
8
|
-
const cache = createConcurrentCache();
|
|
9
|
-
return {
|
|
10
|
-
name: 'lambda-json',
|
|
11
|
-
isMatch: (headers)=>{
|
|
12
|
-
return !!headers.get('content-type')?.startsWith('application/json');
|
|
13
|
-
},
|
|
14
|
-
getInputs: async (opts, info)=>{
|
|
15
|
-
function getRawProcedureInputOrThrow() {
|
|
16
|
-
const { event , req } = opts;
|
|
17
|
-
try {
|
|
18
|
-
if (req.query.has('input')) {
|
|
19
|
-
const input = req.query.get('input');
|
|
20
|
-
if (!input) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
return JSON.parse(input);
|
|
24
|
-
}
|
|
25
|
-
const body = lambdaEventToHTTPBody(opts.event);
|
|
26
|
-
if (typeof body === 'string') {
|
|
27
|
-
// A mutation with no inputs will have req.body === ''
|
|
28
|
-
return body.length === 0 ? undefined : JSON.parse(body);
|
|
29
|
-
}
|
|
30
|
-
return event.body;
|
|
31
|
-
} catch (cause) {
|
|
32
|
-
throw new TRPCError({
|
|
33
|
-
code: 'PARSE_ERROR',
|
|
34
|
-
cause
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const deserializeInputValue = (rawValue, transformer)=>{
|
|
39
|
-
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
40
|
-
};
|
|
41
|
-
const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
|
|
42
|
-
if (rawInput === undefined) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
const transformer = opts.router._def._config.transformer;
|
|
46
|
-
if (!info.isBatchCall) {
|
|
47
|
-
return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
|
|
48
|
-
}
|
|
49
|
-
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
50
|
-
throw new TRPCError({
|
|
51
|
-
code: 'BAD_REQUEST',
|
|
52
|
-
message: '"input" needs to be an object when doing a batch call'
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export { getLambdaHTTPJSONContentTypeHandler };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
7
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context as APIGWContext } from 'aws-lambda';
|
|
11
|
-
import type { AnyRouter, CreateContextCallback, inferRouterContext } from '../../@trpc/server';
|
|
12
|
-
import type { HTTPBaseHandlerOptions, HTTPHeaders, TRPCRequestInfo } from '../../@trpc/server/http';
|
|
13
|
-
export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
14
|
-
export type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
|
|
15
|
-
export type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
|
|
16
|
-
event: TEvent;
|
|
17
|
-
context: APIGWContext;
|
|
18
|
-
info: TRPCRequestInfo;
|
|
19
|
-
};
|
|
20
|
-
export type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({ event, context, info, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
21
|
-
export type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = HTTPBaseHandlerOptions<TRouter, TEvent> & CreateContextCallback<inferRouterContext<AnyRouter>, AWSLambdaCreateContextFn<TRouter, TEvent>>;
|
|
22
|
-
export declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
|
|
23
|
-
export declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
|
|
24
|
-
export declare function getHTTPMethod(event: APIGatewayEvent): string;
|
|
25
|
-
export declare function getPath(event: APIGatewayEvent): string;
|
|
26
|
-
export declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'];
|
|
27
|
-
export type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
|
|
28
|
-
export type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
|
|
29
|
-
export declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
|
|
30
|
-
export declare function lambdaEventToHTTPBody(event: APIGatewayEvent): string | null | undefined;
|
|
31
|
-
//# 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;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EACjC,OAAO,IAAI,YAAY,EACxB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EACX,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAEjC,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,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,GACrC,qBAAqB,CACnB,kBAAkB,CAAC,SAAS,CAAC,EAC7B,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAC1C,CAAC;AAER,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;AAE3G,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,eAAe,6BAS3D"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
|
-
require('../../unstable-core-do-not-import/rootConfig.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
|
-
*/ // import @trpc/server
|
|
15
|
-
// @trpc/server
|
|
16
|
-
function isPayloadV1(event) {
|
|
17
|
-
return determinePayloadFormat(event) == '1.0';
|
|
18
|
-
}
|
|
19
|
-
function isPayloadV2(event) {
|
|
20
|
-
return determinePayloadFormat(event) == '2.0';
|
|
21
|
-
}
|
|
22
|
-
function determinePayloadFormat(event) {
|
|
23
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
24
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
25
|
-
// If there is no version property, then the version is implied as 1.0
|
|
26
|
-
const unknownEvent = event;
|
|
27
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
28
|
-
return '1.0';
|
|
29
|
-
} else {
|
|
30
|
-
if ([
|
|
31
|
-
'1.0',
|
|
32
|
-
'2.0'
|
|
33
|
-
].includes(unknownEvent.version)) {
|
|
34
|
-
return unknownEvent.version;
|
|
35
|
-
} else {
|
|
36
|
-
return 'custom';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function getHTTPMethod(event) {
|
|
41
|
-
if (isPayloadV1(event)) {
|
|
42
|
-
return event.httpMethod;
|
|
43
|
-
}
|
|
44
|
-
if (isPayloadV2(event)) {
|
|
45
|
-
return event.requestContext.http.method;
|
|
46
|
-
}
|
|
47
|
-
throw new TRPCError.TRPCError({
|
|
48
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
49
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function getPath(event) {
|
|
53
|
-
if (isPayloadV1(event)) {
|
|
54
|
-
if (!event.pathParameters) {
|
|
55
|
-
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
56
|
-
return event.path.split('/').pop() ?? '';
|
|
57
|
-
}
|
|
58
|
-
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
59
|
-
for (const match of matches){
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
61
|
-
const group = match[1];
|
|
62
|
-
if (group.includes('+') && event.pathParameters) {
|
|
63
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return event.path.slice(1);
|
|
67
|
-
}
|
|
68
|
-
if (isPayloadV2(event)) {
|
|
69
|
-
const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
70
|
-
for (const match1 of matches1){
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
72
|
-
const group1 = match1[1];
|
|
73
|
-
if (group1.includes('+') && event.pathParameters) {
|
|
74
|
-
return event.pathParameters[group1.replace('+', '')] ?? '';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return event.rawPath.slice(1);
|
|
78
|
-
}
|
|
79
|
-
throw new TRPCError.TRPCError({
|
|
80
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
81
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function transformHeaders(headers) {
|
|
85
|
-
const obj = {};
|
|
86
|
-
for (const [key, value] of Object.entries(headers)){
|
|
87
|
-
if (typeof value === 'undefined') {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
91
|
-
}
|
|
92
|
-
return obj;
|
|
93
|
-
}
|
|
94
|
-
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';
|
|
95
|
-
function lambdaEventToHTTPBody(event) {
|
|
96
|
-
let body;
|
|
97
|
-
if (event.body && event.isBase64Encoded) {
|
|
98
|
-
body = Buffer.from(event.body, 'base64').toString('utf8');
|
|
99
|
-
} else {
|
|
100
|
-
body = event.body;
|
|
101
|
-
}
|
|
102
|
-
return body;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
|
|
106
|
-
exports.getHTTPMethod = getHTTPMethod;
|
|
107
|
-
exports.getPath = getPath;
|
|
108
|
-
exports.isPayloadV1 = isPayloadV1;
|
|
109
|
-
exports.isPayloadV2 = isPayloadV2;
|
|
110
|
-
exports.lambdaEventToHTTPBody = lambdaEventToHTTPBody;
|
|
111
|
-
exports.transformHeaders = transformHeaders;
|
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
*/ // import @trpc/server
|
|
13
|
-
// @trpc/server
|
|
14
|
-
function isPayloadV1(event) {
|
|
15
|
-
return determinePayloadFormat(event) == '1.0';
|
|
16
|
-
}
|
|
17
|
-
function isPayloadV2(event) {
|
|
18
|
-
return determinePayloadFormat(event) == '2.0';
|
|
19
|
-
}
|
|
20
|
-
function determinePayloadFormat(event) {
|
|
21
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
22
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
23
|
-
// If there is no version property, then the version is implied as 1.0
|
|
24
|
-
const unknownEvent = event;
|
|
25
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
26
|
-
return '1.0';
|
|
27
|
-
} else {
|
|
28
|
-
if ([
|
|
29
|
-
'1.0',
|
|
30
|
-
'2.0'
|
|
31
|
-
].includes(unknownEvent.version)) {
|
|
32
|
-
return unknownEvent.version;
|
|
33
|
-
} else {
|
|
34
|
-
return 'custom';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function getHTTPMethod(event) {
|
|
39
|
-
if (isPayloadV1(event)) {
|
|
40
|
-
return event.httpMethod;
|
|
41
|
-
}
|
|
42
|
-
if (isPayloadV2(event)) {
|
|
43
|
-
return event.requestContext.http.method;
|
|
44
|
-
}
|
|
45
|
-
throw new TRPCError({
|
|
46
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
47
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function getPath(event) {
|
|
51
|
-
if (isPayloadV1(event)) {
|
|
52
|
-
if (!event.pathParameters) {
|
|
53
|
-
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
54
|
-
return event.path.split('/').pop() ?? '';
|
|
55
|
-
}
|
|
56
|
-
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
57
|
-
for (const match of matches){
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
59
|
-
const group = match[1];
|
|
60
|
-
if (group.includes('+') && event.pathParameters) {
|
|
61
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return event.path.slice(1);
|
|
65
|
-
}
|
|
66
|
-
if (isPayloadV2(event)) {
|
|
67
|
-
const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
68
|
-
for (const match1 of matches1){
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
-
const group1 = match1[1];
|
|
71
|
-
if (group1.includes('+') && event.pathParameters) {
|
|
72
|
-
return event.pathParameters[group1.replace('+', '')] ?? '';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return event.rawPath.slice(1);
|
|
76
|
-
}
|
|
77
|
-
throw new TRPCError({
|
|
78
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
79
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function transformHeaders(headers) {
|
|
83
|
-
const obj = {};
|
|
84
|
-
for (const [key, value] of Object.entries(headers)){
|
|
85
|
-
if (typeof value === 'undefined') {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
89
|
-
}
|
|
90
|
-
return obj;
|
|
91
|
-
}
|
|
92
|
-
const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
|
|
93
|
-
function lambdaEventToHTTPBody(event) {
|
|
94
|
-
let body;
|
|
95
|
-
if (event.body && event.isBase64Encoded) {
|
|
96
|
-
body = Buffer.from(event.body, 'base64').toString('utf8');
|
|
97
|
-
} else {
|
|
98
|
-
body = event.body;
|
|
99
|
-
}
|
|
100
|
-
return body;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, lambdaEventToHTTPBody, transformHeaders };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple concurrent cache that ensures that only one promise is created for a given key.
|
|
3
|
-
*/
|
|
4
|
-
export declare function createConcurrentCache(): {
|
|
5
|
-
concurrentSafeGet<TValue>(key: string, setter: () => TValue): TValue;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=concurrentCache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concurrentCache.d.ts","sourceRoot":"","sources":["../../../src/adapters/content-handlers/concurrentCache.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,qBAAqB;mCAIF,MAAM,UAAU,MAAM,MAAM,GAAG,MAAM;EAQvE"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A simple concurrent cache that ensures that only one promise is created for a given key.
|
|
5
|
-
*/ function createConcurrentCache() {
|
|
6
|
-
const cache = new Map();
|
|
7
|
-
return {
|
|
8
|
-
concurrentSafeGet (key, setter) {
|
|
9
|
-
if (!cache.has(key)) {
|
|
10
|
-
cache.set(key, setter());
|
|
11
|
-
}
|
|
12
|
-
return cache.get(key);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.createConcurrentCache = createConcurrentCache;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple concurrent cache that ensures that only one promise is created for a given key.
|
|
3
|
-
*/ function createConcurrentCache() {
|
|
4
|
-
const cache = new Map();
|
|
5
|
-
return {
|
|
6
|
-
concurrentSafeGet (key, setter) {
|
|
7
|
-
if (!cache.has(key)) {
|
|
8
|
-
cache.set(key, setter());
|
|
9
|
-
}
|
|
10
|
-
return cache.get(key);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { createConcurrentCache };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TRPCError } from '../../@trpc/server';
|
|
2
|
-
import type { BaseContentTypeHandler, HTTPHeaders } from '../../@trpc/server/http';
|
|
3
|
-
interface MinimalHandlerOpts {
|
|
4
|
-
req: {
|
|
5
|
-
headers: HTTPHeaders | Headers;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export declare function selectContentHandlerOrUnsupportedMediaType<THandlerOpts extends MinimalHandlerOpts, THandler extends BaseContentTypeHandler<THandlerOpts>>(handlers: THandler[], opts: THandlerOpts): readonly [undefined, TRPCError] | readonly [THandler];
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=selectContentHandlerOrUnsupportedMediaType.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectContentHandlerOrUnsupportedMediaType.d.ts","sourceRoot":"","sources":["../../../src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAEjC,UAAU,kBAAkB;IAC1B,GAAG,EAAE;QAGH,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC;KAChC,CAAC;CACH;AAED,wBAAgB,0CAA0C,CACxD,YAAY,SAAS,kBAAkB,EACvC,QAAQ,SAAS,sBAAsB,CAAC,YAAY,CAAC,EACrD,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,YAAY,yDA2BzC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
|
-
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
|
-
|
|
6
|
-
function selectContentHandlerOrUnsupportedMediaType(handlers, opts) {
|
|
7
|
-
const headers = new Headers(opts.req.headers);
|
|
8
|
-
const contentType = headers.get('content-type');
|
|
9
|
-
if (contentType === null) {
|
|
10
|
-
return [
|
|
11
|
-
undefined,
|
|
12
|
-
new TRPCError.TRPCError({
|
|
13
|
-
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
14
|
-
message: 'No Content-Type header detected on the incoming request. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all'
|
|
15
|
-
})
|
|
16
|
-
];
|
|
17
|
-
}
|
|
18
|
-
const handler = handlers.find((handler)=>handler.isMatch(headers));
|
|
19
|
-
if (!handler) {
|
|
20
|
-
return [
|
|
21
|
-
undefined,
|
|
22
|
-
new TRPCError.TRPCError({
|
|
23
|
-
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
24
|
-
message: `Invalid Content-Type header '${contentType}'. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all`
|
|
25
|
-
})
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
return [
|
|
29
|
-
handler
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
exports.selectContentHandlerOrUnsupportedMediaType = selectContentHandlerOrUnsupportedMediaType;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
-
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
-
|
|
4
|
-
function selectContentHandlerOrUnsupportedMediaType(handlers, opts) {
|
|
5
|
-
const headers = new Headers(opts.req.headers);
|
|
6
|
-
const contentType = headers.get('content-type');
|
|
7
|
-
if (contentType === null) {
|
|
8
|
-
return [
|
|
9
|
-
undefined,
|
|
10
|
-
new TRPCError({
|
|
11
|
-
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
12
|
-
message: 'No Content-Type header detected on the incoming request. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all'
|
|
13
|
-
})
|
|
14
|
-
];
|
|
15
|
-
}
|
|
16
|
-
const handler = handlers.find((handler)=>handler.isMatch(headers));
|
|
17
|
-
if (!handler) {
|
|
18
|
-
return [
|
|
19
|
-
undefined,
|
|
20
|
-
new TRPCError({
|
|
21
|
-
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
22
|
-
message: `Invalid Content-Type header '${contentType}'. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all`
|
|
23
|
-
})
|
|
24
|
-
];
|
|
25
|
-
}
|
|
26
|
-
return [
|
|
27
|
-
handler
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { selectContentHandlerOrUnsupportedMediaType };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import type { AnyRouter } from '../../../../@trpc/server';
|
|
3
|
-
import type { BaseContentTypeHandler } from '../../../../@trpc/server/http';
|
|
4
|
-
import type { FastifyRequestHandlerOptions } from '../../types';
|
|
5
|
-
export interface FastifyHTTPContentTypeHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> extends BaseContentTypeHandler<FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>> {
|
|
6
|
-
}
|
|
7
|
-
export declare const getFastifyHTTPJSONContentTypeHandler: <TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>() => FastifyHTTPContentTypeHandler<TRouter, TRequest, TResponse>;
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/fastify/content-type/json/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,6BAA6B,CAC5C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,CAC9B,SAAQ,sBAAsB,CAC5B,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAC3D;CAAG;AAEN,eAAO,MAAM,oCAAoC,EAAE,CACjD,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,OACzB,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAkFhE,CAAC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var TRPCError = require('../../../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
|
-
require('../../../../unstable-core-do-not-import/rootConfig.js');
|
|
5
|
-
var concurrentCache = require('../../../content-handlers/concurrentCache.js');
|
|
6
|
-
|
|
7
|
-
// @trpc/server
|
|
8
|
-
const getFastifyHTTPJSONContentTypeHandler = ()=>{
|
|
9
|
-
const cache = concurrentCache.createConcurrentCache();
|
|
10
|
-
return {
|
|
11
|
-
name: 'fastify-json',
|
|
12
|
-
isMatch: (headers)=>{
|
|
13
|
-
return !!headers.get('content-type')?.startsWith('application/json');
|
|
14
|
-
},
|
|
15
|
-
getInputs: async (opts, info)=>{
|
|
16
|
-
async function getRawProcedureInputOrThrow() {
|
|
17
|
-
const { req } = opts;
|
|
18
|
-
try {
|
|
19
|
-
if (req.method === 'GET') {
|
|
20
|
-
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
21
|
-
const input = query.get('input');
|
|
22
|
-
if (!input) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
return JSON.parse(input);
|
|
26
|
-
}
|
|
27
|
-
const body = opts.req.body ?? 'null';
|
|
28
|
-
if (typeof body === 'string') {
|
|
29
|
-
// A mutation with no inputs will have req.body === ''
|
|
30
|
-
return body.length === 0 ? undefined : JSON.parse(body);
|
|
31
|
-
}
|
|
32
|
-
return body;
|
|
33
|
-
} catch (cause) {
|
|
34
|
-
throw new TRPCError.TRPCError({
|
|
35
|
-
code: 'PARSE_ERROR',
|
|
36
|
-
cause
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const deserializeInputValue = (rawValue, transformer)=>{
|
|
41
|
-
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
42
|
-
};
|
|
43
|
-
const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
|
|
44
|
-
if (rawInput === undefined) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
const transformer = opts.router._def._config.transformer;
|
|
48
|
-
if (!info.isBatchCall) {
|
|
49
|
-
return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
|
|
50
|
-
}
|
|
51
|
-
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
52
|
-
throw new TRPCError.TRPCError({
|
|
53
|
-
code: 'BAD_REQUEST',
|
|
54
|
-
message: '"input" needs to be an object when doing a batch call'
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
exports.getFastifyHTTPJSONContentTypeHandler = getFastifyHTTPJSONContentTypeHandler;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
-
import '../../../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
-
import { createConcurrentCache } from '../../../content-handlers/concurrentCache.mjs';
|
|
4
|
-
|
|
5
|
-
// @trpc/server
|
|
6
|
-
const getFastifyHTTPJSONContentTypeHandler = ()=>{
|
|
7
|
-
const cache = createConcurrentCache();
|
|
8
|
-
return {
|
|
9
|
-
name: 'fastify-json',
|
|
10
|
-
isMatch: (headers)=>{
|
|
11
|
-
return !!headers.get('content-type')?.startsWith('application/json');
|
|
12
|
-
},
|
|
13
|
-
getInputs: async (opts, info)=>{
|
|
14
|
-
async function getRawProcedureInputOrThrow() {
|
|
15
|
-
const { req } = opts;
|
|
16
|
-
try {
|
|
17
|
-
if (req.method === 'GET') {
|
|
18
|
-
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
19
|
-
const input = query.get('input');
|
|
20
|
-
if (!input) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
return JSON.parse(input);
|
|
24
|
-
}
|
|
25
|
-
const body = opts.req.body ?? 'null';
|
|
26
|
-
if (typeof body === 'string') {
|
|
27
|
-
// A mutation with no inputs will have req.body === ''
|
|
28
|
-
return body.length === 0 ? undefined : JSON.parse(body);
|
|
29
|
-
}
|
|
30
|
-
return body;
|
|
31
|
-
} catch (cause) {
|
|
32
|
-
throw new TRPCError({
|
|
33
|
-
code: 'PARSE_ERROR',
|
|
34
|
-
cause
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const deserializeInputValue = (rawValue, transformer)=>{
|
|
39
|
-
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
40
|
-
};
|
|
41
|
-
const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
|
|
42
|
-
if (rawInput === undefined) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
const transformer = opts.router._def._config.transformer;
|
|
46
|
-
if (!info.isBatchCall) {
|
|
47
|
-
return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
|
|
48
|
-
}
|
|
49
|
-
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
50
|
-
throw new TRPCError({
|
|
51
|
-
code: 'BAD_REQUEST',
|
|
52
|
-
message: '"input" needs to be an object when doing a batch call'
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export { getFastifyHTTPJSONContentTypeHandler };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import type { AnyRouter } from '../../@trpc/server';
|
|
3
|
-
import type { HTTPBaseHandlerOptions } from '../../@trpc/server/http';
|
|
4
|
-
import type { NodeHTTPConditionCreateContextOption } from '../node-http';
|
|
5
|
-
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPConditionCreateContextOption<TRouter, TRequest, TResponse>;
|
|
6
|
-
export 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
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,cAAc,CAAC;AAEzE,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,oCAAoC,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAErE,MAAM,MAAM,4BAA4B,CACtC,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"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AnyRouter } from '../../../../@trpc/server';
|
|
2
|
-
import type { BaseContentTypeHandler } from '../../../../@trpc/server/http';
|
|
3
|
-
import type { FetchHandlerRequestOptions } from '../../types';
|
|
4
|
-
export interface FetchHTTPContentTypeHandler<TRouter extends AnyRouter> extends BaseContentTypeHandler<FetchHandlerRequestOptions<TRouter> & {
|
|
5
|
-
url: URL;
|
|
6
|
-
}> {
|
|
7
|
-
}
|
|
8
|
-
export declare const getFetchHTTPJSONContentTypeHandler: <TRouter extends AnyRouter>() => FetchHTTPContentTypeHandler<TRouter>;
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/fetch/content-type/json/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,WAAW,2BAA2B,CAAC,OAAO,SAAS,SAAS,CACpE,SAAQ,sBAAsB,CAC5B,0BAA0B,CAAC,OAAO,CAAC,GAAG;IACpC,GAAG,EAAE,GAAG,CAAC;CACV,CACF;CAAG;AAEN,eAAO,MAAM,kCAAkC,EAAE,CAC/C,OAAO,SAAS,SAAS,OACpB,2BAA2B,CAAC,OAAO,CAsEzC,CAAC"}
|