@trpc/server 11.0.0-rc.342 → 11.0.0-rc.345
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 +0 -1
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +2 -1
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts +10 -0
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/content-type/json/index.js +59 -0
- package/dist/adapters/aws-lambda/content-type/json/index.mjs +57 -0
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +19 -9
- package/dist/adapters/aws-lambda/index.mjs +19 -9
- package/dist/adapters/aws-lambda/utils.d.ts +3 -12
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +12 -1
- package/dist/adapters/aws-lambda/utils.mjs +12 -2
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +4 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +1 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +22 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +20 -0
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +0 -1
- package/dist/adapters/express.mjs +0 -1
- package/dist/adapters/fastify/content-type/json/index.d.ts +8 -0
- package/dist/adapters/fastify/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/fastify/content-type/json/index.js +59 -0
- package/dist/adapters/fastify/content-type/json/index.mjs +57 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +1 -9
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +10 -2
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +10 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/types.d.ts +11 -0
- package/dist/adapters/fastify/types.d.ts.map +1 -0
- package/dist/adapters/fetch/content-type/json/index.d.ts +9 -0
- package/dist/adapters/fetch/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/fetch/content-type/json/index.js +58 -0
- package/dist/adapters/fetch/content-type/json/index.mjs +56 -0
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -5
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +16 -2
- package/dist/adapters/fetch/fetchRequestHandler.mjs +16 -2
- package/dist/adapters/fetch/types.d.ts +9 -12
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +2 -7
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +0 -1
- package/dist/adapters/next.mjs +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -72
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +5 -76
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +5 -19
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +14 -39
- package/dist/adapters/node-http/content-type/form-data/index.mjs +15 -35
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +2 -2
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -12
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +1 -12
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +4 -12
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +4 -12
- package/dist/adapters/node-http/content-type/json/index.d.ts +4 -1
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/index.js +59 -10
- package/dist/adapters/node-http/content-type/json/index.mjs +59 -10
- package/dist/adapters/node-http/content-type/octet/index.d.ts +5 -0
- package/dist/adapters/node-http/content-type/octet/index.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/octet/index.js +19 -0
- package/dist/adapters/node-http/content-type/octet/index.mjs +17 -0
- package/dist/adapters/node-http/content-type/types.d.ts +8 -0
- package/dist/adapters/node-http/content-type/types.d.ts.map +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +19 -21
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +20 -22
- package/dist/adapters/node-http/types.d.ts +8 -19
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +0 -1
- package/dist/adapters/standalone.mjs +0 -1
- package/dist/adapters/ws.d.ts +2 -12
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/bundle-analysis.json +257 -198
- package/dist/http.js +0 -2
- package/dist/http.mjs +0 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +1 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +16 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.js +23 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +21 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +6 -14
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +5 -5
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +25 -22
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +25 -22
- package/dist/unstable-core-do-not-import/http/types.d.ts +0 -2
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +21 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +0 -2
- package/dist/unstable-core-do-not-import.mjs +0 -1
- package/package.json +3 -3
- package/src/@trpc/server/http.ts +0 -1
- package/src/@trpc/server/index.ts +4 -0
- package/src/adapters/aws-lambda/content-type/json/index.ts +99 -0
- package/src/adapters/aws-lambda/index.ts +24 -9
- package/src/adapters/aws-lambda/utils.ts +21 -15
- package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +21 -0
- package/src/adapters/express.ts +1 -6
- package/src/adapters/fastify/content-type/json/index.ts +97 -0
- package/src/adapters/fastify/fastifyRequestHandler.ts +15 -21
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fastify/types.ts +22 -0
- package/src/adapters/fetch/content-type/json/index.ts +96 -0
- package/src/adapters/fetch/fetchRequestHandler.ts +22 -10
- package/src/adapters/fetch/types.ts +22 -15
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +2 -9
- package/src/adapters/next.ts +1 -6
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +7 -7
- package/src/adapters/node-http/content-type/form-data/index.ts +29 -51
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +2 -2
- package/src/adapters/node-http/content-type/json/getPostBody.ts +9 -18
- package/src/adapters/node-http/content-type/json/index.ts +85 -5
- package/src/adapters/node-http/content-type/octet/index.ts +29 -0
- package/src/adapters/node-http/{internals/contentType.ts → content-type/types.ts} +2 -14
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +22 -35
- package/src/adapters/node-http/types.ts +46 -46
- package/src/adapters/standalone.ts +1 -2
- package/src/adapters/ws.ts +9 -14
- package/src/unstable-core-do-not-import/contentTypeParsers.ts +37 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +9 -84
- package/src/unstable-core-do-not-import/http/index.ts +0 -1
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +29 -28
- package/src/unstable-core-do-not-import/http/types.ts +0 -2
- package/src/unstable-core-do-not-import/rootConfig.ts +31 -0
- 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/unstable-core-do-not-import/http/contentType.js +0 -54
- package/dist/unstable-core-do-not-import/http/contentType.mjs +0 -52
|
@@ -3,6 +3,5 @@ export { resolveHTTPResponse } from '../../unstable-core-do-not-import';
|
|
|
3
3
|
export type { BaseHandlerOptions, HTTPBaseHandlerOptions, HTTPHeaders, HTTPRequest, HTTPResponse, OnErrorFunction, ProcedureCall, ResolveHTTPRequestOptionsContextFn, ResponseChunk, ResponseMeta, ResponseMetaFn, TRPCRequestInfo, } from '../../unstable-core-do-not-import';
|
|
4
4
|
export { getBatchStreamFormatter } from '../../unstable-core-do-not-import';
|
|
5
5
|
export type { BaseContentTypeHandler, BodyResult, } from '../../unstable-core-do-not-import';
|
|
6
|
-
export { getJsonContentTypeInputs } from '../../unstable-core-do-not-import';
|
|
7
6
|
export { toURL } from '../../unstable-core-do-not-import';
|
|
8
7
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,kCAAkC,EAClC,aAAa,EACb,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,YAAY,EACV,sBAAsB,EACtB,UAAU,GACX,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,kCAAkC,EAClC,aAAa,EACb,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,YAAY,EACV,sBAAsB,EACtB,UAAU,GACX,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -2,7 +2,7 @@ export { TRPCError,
|
|
|
2
2
|
/**
|
|
3
3
|
* @deprecated use `experimental_trpcMiddleware` instead
|
|
4
4
|
*/
|
|
5
|
-
experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, callProcedure as callTRPCProcedure, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferProcedureBuilderResolverOptions, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferClientTypes as inferTRPCClientTypes, type AnyClientTypes as AnyTRPCClientTypes, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type RouterRecord as TRPCRouterRecord, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, type ProcedureOptions as TRPCProcedureOptions, type MutationProcedure as TRPCMutationProcedure, type QueryProcedure as TRPCQueryProcedure, type SubscriptionProcedure as TRPCSubscriptionProcedure, } from '../../unstable-core-do-not-import';
|
|
5
|
+
experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, callProcedure as callTRPCProcedure, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferProcedureBuilderResolverOptions, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferClientTypes as inferTRPCClientTypes, type AnyClientTypes as AnyTRPCClientTypes, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type RouterRecord as TRPCRouterRecord, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, type ProcedureOptions as TRPCProcedureOptions, type CreateContextCallback, type WrapCreateContext, type MutationProcedure as TRPCMutationProcedure, type QueryProcedure as TRPCQueryProcedure, type SubscriptionProcedure as TRPCSubscriptionProcedure, } from '../../unstable-core-do-not-import';
|
|
6
6
|
export type {
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated use `AnyTRPCProcedure` instead
|
|
@@ -58,4 +58,5 @@ callProcedure, } from '../../unstable-core-do-not-import';
|
|
|
58
58
|
* Use `Awaited<ReturnType<typeof myFunction>>` instead
|
|
59
59
|
*/
|
|
60
60
|
export type inferAsyncReturnType<TFunction extends (...args: any[]) => any> = Awaited<ReturnType<TFunction>>;
|
|
61
|
+
export { parseOctetInput } from '../../unstable-core-do-not-import/contentTypeParsers';
|
|
61
62
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS;AACT;;GAEG;AACH,iCAAiC,EACjC,iCAAiC,IAAI,2BAA2B,EAChE,QAAQ,EAER,aAAa,IAAI,iBAAiB,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,IAAI,mBAAmB,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oCAAoC,EACzC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,IAAI,oBAAoB,EAC7C,KAAK,cAAc,IAAI,kBAAkB,EACzC,KAAK,+BAA+B,EACpC,KAAK,kCAAkC,EACvC,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,SAAS,IAAI,aAAa,EAC/B,KAAK,qBAAqB,IAAI,yBAAyB,EACvD,KAAK,uBAAuB,IAAI,2BAA2B,EAC3D,KAAK,aAAa,IAAI,iBAAiB,EACvC,KAAK,oBAAoB,IAAI,wBAAwB,EACrD,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,wBAAwB,IAAI,4BAA4B,EAC7D,KAAK,gBAAgB,IAAI,oBAAoB,EAC7C,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,cAAc,IAAI,kBAAkB,EACzC,KAAK,qBAAqB,IAAI,yBAAyB,GACxD,MAAM,mCAAmC,CAAC;AAE3C,YAAY;AACV;;GAEG;AACH,YAAY;AACZ;;GAEG;AACH,SAAS;AACT;;GAEG;AACH,qBAAqB;AACrB;;GAEG;AACH,uBAAuB;AAEvB;;GAEG;AACH,IAAI;AAEJ;;GAEG;AACH,WAAW;AACX;;GAEG;AACH,aAAa;AACb;;GAEG;AACH,oBAAoB;AAEpB;;GAEG;AACH,iBAAiB;AACjB;;GAEG;AACH,wBAAwB,GACzB,MAAM,mCAAmC,CAAC;AAE3C,OAAO;AACL;;GAEG;AACH,aAAa;AAEb;;GAEG;AACH,aAAa,GACd,MAAM,mCAAmC,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IACxE,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS;AACT;;GAEG;AACH,iCAAiC,EACjC,iCAAiC,IAAI,2BAA2B,EAChE,QAAQ,EAER,aAAa,IAAI,iBAAiB,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,IAAI,mBAAmB,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oCAAoC,EACzC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,IAAI,oBAAoB,EAC7C,KAAK,cAAc,IAAI,kBAAkB,EACzC,KAAK,+BAA+B,EACpC,KAAK,kCAAkC,EACvC,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,SAAS,IAAI,aAAa,EAC/B,KAAK,qBAAqB,IAAI,yBAAyB,EACvD,KAAK,uBAAuB,IAAI,2BAA2B,EAC3D,KAAK,aAAa,IAAI,iBAAiB,EACvC,KAAK,oBAAoB,IAAI,wBAAwB,EACrD,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,wBAAwB,IAAI,4BAA4B,EAC7D,KAAK,gBAAgB,IAAI,oBAAoB,EAC7C,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,cAAc,IAAI,kBAAkB,EACzC,KAAK,qBAAqB,IAAI,yBAAyB,GACxD,MAAM,mCAAmC,CAAC;AAE3C,YAAY;AACV;;GAEG;AACH,YAAY;AACZ;;GAEG;AACH,SAAS;AACT;;GAEG;AACH,qBAAqB;AACrB;;GAEG;AACH,uBAAuB;AAEvB;;GAEG;AACH,IAAI;AAEJ;;GAEG;AACH,WAAW;AACX;;GAEG;AACH,aAAa;AACb;;GAEG;AACH,oBAAoB;AAEpB;;GAEG;AACH,iBAAiB;AACjB;;GAEG;AACH,wBAAwB,GACzB,MAAM,mCAAmC,CAAC;AAE3C,OAAO;AACL;;GAEG;AACH,aAAa;AAEb;;GAEG;AACH,aAAa,GACd,MAAM,mCAAmC,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IACxE,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,sDAAsD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AnyRouter } from '../../../../@trpc/server';
|
|
2
|
+
import type { BaseContentTypeHandler, HTTPRequest } from '../../../../@trpc/server/http';
|
|
3
|
+
import { type APIGatewayEvent, type AWSLambdaOptions } from '../../utils';
|
|
4
|
+
export interface LambdaHTTPContentTypeHandler<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> extends BaseContentTypeHandler<AWSLambdaOptions<TRouter, TEvent> & {
|
|
5
|
+
event: TEvent;
|
|
6
|
+
req: HTTPRequest;
|
|
7
|
+
}> {
|
|
8
|
+
}
|
|
9
|
+
export declare const getLambdaHTTPJSONContentTypeHandler: <TRouter extends AnyRouter, TEvent extends APIGatewayEvent>() => LambdaHTTPContentTypeHandler<TRouter, TEvent>;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/aws-lambda/content-type/json/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,4BAA4B,CAC3C,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,CAC9B,SAAQ,sBAAsB,CAC5B,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,WAAW,CAAC;CAClB,CACF;CAAG;AAEN,eAAO,MAAM,mCAAmC,EAAE,CAChD,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,OACzB,4BAA4B,CAAC,OAAO,EAAE,MAAM,CAqEjD,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 utils = require('../../utils.js');
|
|
6
|
+
|
|
7
|
+
// @trpc/server
|
|
8
|
+
const getLambdaHTTPJSONContentTypeHandler = ()=>({
|
|
9
|
+
name: 'lambda-json',
|
|
10
|
+
isMatch (opts) {
|
|
11
|
+
return !!opts.event.headers['Content-Type']?.startsWith('application/json');
|
|
12
|
+
},
|
|
13
|
+
getInputs: async (opts, info)=>{
|
|
14
|
+
function getRawProcedureInputOrThrow() {
|
|
15
|
+
const { event , req } = opts;
|
|
16
|
+
try {
|
|
17
|
+
if (req.method === 'GET') {
|
|
18
|
+
const input = req.query.get('input');
|
|
19
|
+
if (!input) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return JSON.parse(input);
|
|
23
|
+
}
|
|
24
|
+
const body = utils.lambdaEventToHTTPBody(opts.event);
|
|
25
|
+
if (typeof body === 'string') {
|
|
26
|
+
// A mutation with no inputs will have req.body === ''
|
|
27
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
28
|
+
}
|
|
29
|
+
return event.body;
|
|
30
|
+
} catch (cause) {
|
|
31
|
+
throw new TRPCError.TRPCError({
|
|
32
|
+
code: 'PARSE_ERROR',
|
|
33
|
+
cause
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
38
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
39
|
+
};
|
|
40
|
+
const rawInput = getRawProcedureInputOrThrow();
|
|
41
|
+
if (rawInput === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const transformer = opts.router._def._config.transformer;
|
|
45
|
+
if (!info.isBatchCall) {
|
|
46
|
+
return deserializeInputValue(rawInput, transformer);
|
|
47
|
+
}
|
|
48
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
49
|
+
throw new TRPCError.TRPCError({
|
|
50
|
+
code: 'BAD_REQUEST',
|
|
51
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const rawValue = rawInput[info.batch];
|
|
55
|
+
return deserializeInputValue(rawValue, transformer);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
exports.getLambdaHTTPJSONContentTypeHandler = getLambdaHTTPJSONContentTypeHandler;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
import { lambdaEventToHTTPBody } from '../../utils.mjs';
|
|
4
|
+
|
|
5
|
+
// @trpc/server
|
|
6
|
+
const getLambdaHTTPJSONContentTypeHandler = ()=>({
|
|
7
|
+
name: 'lambda-json',
|
|
8
|
+
isMatch (opts) {
|
|
9
|
+
return !!opts.event.headers['Content-Type']?.startsWith('application/json');
|
|
10
|
+
},
|
|
11
|
+
getInputs: async (opts, info)=>{
|
|
12
|
+
function getRawProcedureInputOrThrow() {
|
|
13
|
+
const { event , req } = opts;
|
|
14
|
+
try {
|
|
15
|
+
if (req.method === 'GET') {
|
|
16
|
+
const input = req.query.get('input');
|
|
17
|
+
if (!input) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return JSON.parse(input);
|
|
21
|
+
}
|
|
22
|
+
const body = lambdaEventToHTTPBody(opts.event);
|
|
23
|
+
if (typeof body === 'string') {
|
|
24
|
+
// A mutation with no inputs will have req.body === ''
|
|
25
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
26
|
+
}
|
|
27
|
+
return event.body;
|
|
28
|
+
} catch (cause) {
|
|
29
|
+
throw new TRPCError({
|
|
30
|
+
code: 'PARSE_ERROR',
|
|
31
|
+
cause
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
36
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
37
|
+
};
|
|
38
|
+
const rawInput = getRawProcedureInputOrThrow();
|
|
39
|
+
if (rawInput === undefined) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const transformer = opts.router._def._config.transformer;
|
|
43
|
+
if (!info.isBatchCall) {
|
|
44
|
+
return deserializeInputValue(rawInput, transformer);
|
|
45
|
+
}
|
|
46
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
47
|
+
throw new TRPCError({
|
|
48
|
+
code: 'BAD_REQUEST',
|
|
49
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const rawValue = rawInput[info.batch];
|
|
53
|
+
return deserializeInputValue(rawValue, transformer);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { getLambdaHTTPJSONContentTypeHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;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,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;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,oBAAoB,CAAC;AAWpD,OAAO,KAAK,EACV,eAAe,EAEf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAUjB,cAAc,SAAS,CAAC;AA6CxB;;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,CA+C5D"}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
4
|
var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
5
5
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
6
|
+
var selectContentHandlerOrUnsupportedMediaType = require('../content-handlers/selectContentHandlerOrUnsupportedMediaType.js');
|
|
7
|
+
var index = require('./content-type/json/index.js');
|
|
6
8
|
var utils = require('./utils.js');
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -21,17 +23,10 @@ function lambdaEventToHTTPRequest(event) {
|
|
|
21
23
|
query.append(key, value);
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
|
-
let body;
|
|
25
|
-
if (event.body && event.isBase64Encoded) {
|
|
26
|
-
body = Buffer.from(event.body, 'base64').toString('utf8');
|
|
27
|
-
} else {
|
|
28
|
-
body = event.body;
|
|
29
|
-
}
|
|
30
26
|
return {
|
|
31
27
|
method: utils.getHTTPMethod(event),
|
|
32
28
|
query: query,
|
|
33
|
-
headers: event.headers
|
|
34
|
-
body: body
|
|
29
|
+
headers: event.headers
|
|
35
30
|
};
|
|
36
31
|
}
|
|
37
32
|
function tRPCOutputToAPIGatewayOutput(event, response) {
|
|
@@ -67,12 +62,26 @@ function awsLambdaRequestHandler(opts) {
|
|
|
67
62
|
...innerOpts
|
|
68
63
|
});
|
|
69
64
|
};
|
|
65
|
+
const [contentTypeHandler, unsupportedMediaTypeError] = selectContentHandlerOrUnsupportedMediaType.selectContentHandlerOrUnsupportedMediaType([
|
|
66
|
+
index.getLambdaHTTPJSONContentTypeHandler()
|
|
67
|
+
], {
|
|
68
|
+
...opts,
|
|
69
|
+
event,
|
|
70
|
+
req
|
|
71
|
+
});
|
|
70
72
|
const response = await resolveHTTPResponse.resolveHTTPResponse({
|
|
71
73
|
...opts,
|
|
72
74
|
createContext,
|
|
73
75
|
req,
|
|
74
76
|
path,
|
|
75
|
-
error:
|
|
77
|
+
error: unsupportedMediaTypeError,
|
|
78
|
+
async getInput (info) {
|
|
79
|
+
return await contentTypeHandler?.getInputs({
|
|
80
|
+
...opts,
|
|
81
|
+
event,
|
|
82
|
+
req
|
|
83
|
+
}, info);
|
|
84
|
+
},
|
|
76
85
|
onError (o) {
|
|
77
86
|
opts?.onError?.({
|
|
78
87
|
...o,
|
|
@@ -89,5 +98,6 @@ exports.getHTTPMethod = utils.getHTTPMethod;
|
|
|
89
98
|
exports.getPath = utils.getPath;
|
|
90
99
|
exports.isPayloadV1 = utils.isPayloadV1;
|
|
91
100
|
exports.isPayloadV2 = utils.isPayloadV2;
|
|
101
|
+
exports.lambdaEventToHTTPBody = utils.lambdaEventToHTTPBody;
|
|
92
102
|
exports.transformHeaders = utils.transformHeaders;
|
|
93
103
|
exports.awsLambdaRequestHandler = awsLambdaRequestHandler;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
2
|
import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
3
3
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
4
|
+
import { selectContentHandlerOrUnsupportedMediaType } from '../content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs';
|
|
5
|
+
import { getLambdaHTTPJSONContentTypeHandler } from './content-type/json/index.mjs';
|
|
4
6
|
import { getPath, getHTTPMethod, isPayloadV1, transformHeaders, isPayloadV2, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE } from './utils.mjs';
|
|
7
|
+
export { lambdaEventToHTTPBody } from './utils.mjs';
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* 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`
|
|
@@ -19,17 +22,10 @@ function lambdaEventToHTTPRequest(event) {
|
|
|
19
22
|
query.append(key, value);
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
|
-
let body;
|
|
23
|
-
if (event.body && event.isBase64Encoded) {
|
|
24
|
-
body = Buffer.from(event.body, 'base64').toString('utf8');
|
|
25
|
-
} else {
|
|
26
|
-
body = event.body;
|
|
27
|
-
}
|
|
28
25
|
return {
|
|
29
26
|
method: getHTTPMethod(event),
|
|
30
27
|
query: query,
|
|
31
|
-
headers: event.headers
|
|
32
|
-
body: body
|
|
28
|
+
headers: event.headers
|
|
33
29
|
};
|
|
34
30
|
}
|
|
35
31
|
function tRPCOutputToAPIGatewayOutput(event, response) {
|
|
@@ -65,12 +61,26 @@ function awsLambdaRequestHandler(opts) {
|
|
|
65
61
|
...innerOpts
|
|
66
62
|
});
|
|
67
63
|
};
|
|
64
|
+
const [contentTypeHandler, unsupportedMediaTypeError] = selectContentHandlerOrUnsupportedMediaType([
|
|
65
|
+
getLambdaHTTPJSONContentTypeHandler()
|
|
66
|
+
], {
|
|
67
|
+
...opts,
|
|
68
|
+
event,
|
|
69
|
+
req
|
|
70
|
+
});
|
|
68
71
|
const response = await resolveHTTPResponse({
|
|
69
72
|
...opts,
|
|
70
73
|
createContext,
|
|
71
74
|
req,
|
|
72
75
|
path,
|
|
73
|
-
error:
|
|
76
|
+
error: unsupportedMediaTypeError,
|
|
77
|
+
async getInput (info) {
|
|
78
|
+
return await contentTypeHandler?.getInputs({
|
|
79
|
+
...opts,
|
|
80
|
+
event,
|
|
81
|
+
req
|
|
82
|
+
}, info);
|
|
83
|
+
},
|
|
74
84
|
onError (o) {
|
|
75
85
|
opts?.onError?.({
|
|
76
86
|
...o,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
10
|
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context as APIGWContext } from 'aws-lambda';
|
|
11
|
-
import type { AnyRouter, inferRouterContext } from '../../@trpc/server';
|
|
11
|
+
import type { AnyRouter, CreateContextCallback, inferRouterContext } from '../../@trpc/server';
|
|
12
12
|
import type { HTTPBaseHandlerOptions, HTTPHeaders, TRPCRequestInfo } from '../../@trpc/server/http';
|
|
13
13
|
export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
14
14
|
export type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
|
|
@@ -18,17 +18,7 @@ export type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
|
|
|
18
18
|
info: TRPCRequestInfo;
|
|
19
19
|
};
|
|
20
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> &
|
|
22
|
-
/**
|
|
23
|
-
* @link https://trpc.io/docs/v11/context
|
|
24
|
-
**/
|
|
25
|
-
createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
26
|
-
} | {
|
|
27
|
-
/**
|
|
28
|
-
* @link https://trpc.io/docs/v11/context
|
|
29
|
-
**/
|
|
30
|
-
createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
31
|
-
});
|
|
21
|
+
export type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = HTTPBaseHandlerOptions<TRouter, TEvent> & CreateContextCallback<inferRouterContext<AnyRouter>, AWSLambdaCreateContextFn<TRouter, TEvent>>;
|
|
32
22
|
export declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
|
|
33
23
|
export declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
|
|
34
24
|
export declare function getHTTPMethod(event: APIGatewayEvent): string;
|
|
@@ -37,4 +27,5 @@ export declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult
|
|
|
37
27
|
export type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
|
|
38
28
|
export type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
|
|
39
29
|
export declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
|
|
30
|
+
export declare function lambdaEventToHTTPBody(event: APIGatewayEvent): string | null | undefined;
|
|
40
31
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
|
@@ -11,7 +11,8 @@ require('../../unstable-core-do-not-import/rootConfig.js');
|
|
|
11
11
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
12
12
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
13
|
* ```
|
|
14
|
-
*/ // @trpc/server
|
|
14
|
+
*/ // import @trpc/server
|
|
15
|
+
// @trpc/server
|
|
15
16
|
function isPayloadV1(event) {
|
|
16
17
|
return determinePayloadFormat(event) == '1.0';
|
|
17
18
|
}
|
|
@@ -91,10 +92,20 @@ function transformHeaders(headers) {
|
|
|
91
92
|
return obj;
|
|
92
93
|
}
|
|
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
|
+
}
|
|
94
104
|
|
|
95
105
|
exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
|
|
96
106
|
exports.getHTTPMethod = getHTTPMethod;
|
|
97
107
|
exports.getPath = getPath;
|
|
98
108
|
exports.isPayloadV1 = isPayloadV1;
|
|
99
109
|
exports.isPayloadV2 = isPayloadV2;
|
|
110
|
+
exports.lambdaEventToHTTPBody = lambdaEventToHTTPBody;
|
|
100
111
|
exports.transformHeaders = transformHeaders;
|
|
@@ -9,7 +9,8 @@ import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
|
9
9
|
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
10
10
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
11
11
|
* ```
|
|
12
|
-
*/ // @trpc/server
|
|
12
|
+
*/ // import @trpc/server
|
|
13
|
+
// @trpc/server
|
|
13
14
|
function isPayloadV1(event) {
|
|
14
15
|
return determinePayloadFormat(event) == '1.0';
|
|
15
16
|
}
|
|
@@ -89,5 +90,14 @@ function transformHeaders(headers) {
|
|
|
89
90
|
return obj;
|
|
90
91
|
}
|
|
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
|
+
}
|
|
92
102
|
|
|
93
|
-
export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
|
|
103
|
+
export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, lambdaEventToHTTPBody, transformHeaders };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TRPCError } from '../../@trpc/server';
|
|
2
|
+
import type { BaseContentTypeHandler } from '../../@trpc/server/http';
|
|
3
|
+
export declare function selectContentHandlerOrUnsupportedMediaType<THandlerOpts, THandler extends BaseContentTypeHandler<THandlerOpts>>(handlers: THandler[], opts: THandlerOpts): readonly [undefined, TRPCError] | readonly [THandler];
|
|
4
|
+
//# sourceMappingURL=selectContentHandlerOrUnsupportedMediaType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEtE,wBAAgB,0CAA0C,CACxD,YAAY,EACZ,QAAQ,SAAS,sBAAsB,CAAC,YAAY,CAAC,EACrD,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,YAAY,yDAczC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 handler = handlers.find((handler)=>handler.isMatch(opts));
|
|
8
|
+
if (!handler) {
|
|
9
|
+
return [
|
|
10
|
+
undefined,
|
|
11
|
+
new TRPCError.TRPCError({
|
|
12
|
+
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
13
|
+
message: 'Invalid Content-Type header. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all'
|
|
14
|
+
})
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
return [
|
|
18
|
+
handler
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.selectContentHandlerOrUnsupportedMediaType = selectContentHandlerOrUnsupportedMediaType;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 handler = handlers.find((handler)=>handler.isMatch(opts));
|
|
6
|
+
if (!handler) {
|
|
7
|
+
return [
|
|
8
|
+
undefined,
|
|
9
|
+
new TRPCError({
|
|
10
|
+
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
11
|
+
message: 'Invalid Content-Type header. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all'
|
|
12
|
+
})
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
return [
|
|
16
|
+
handler
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { selectContentHandlerOrUnsupportedMediaType };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,CACjB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvE,OAAO,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,CACjB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvE,OAAO,CAAC,OAAO,CAWjB"}
|
package/dist/adapters/express.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;AAC5E,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,CA0E/D,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
// @trpc/server
|
|
7
|
+
const getFastifyHTTPJSONContentTypeHandler = ()=>({
|
|
8
|
+
name: 'fastify-json',
|
|
9
|
+
isMatch (opts) {
|
|
10
|
+
return !!opts.req.headers['content-type']?.startsWith('application/json');
|
|
11
|
+
},
|
|
12
|
+
getInputs: async (opts, info)=>{
|
|
13
|
+
async function getRawProcedureInputOrThrow() {
|
|
14
|
+
const { req } = opts;
|
|
15
|
+
try {
|
|
16
|
+
if (req.method === 'GET') {
|
|
17
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
18
|
+
const input = query.get('input');
|
|
19
|
+
if (!input) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return JSON.parse(input);
|
|
23
|
+
}
|
|
24
|
+
const body = opts.req.body ?? 'null';
|
|
25
|
+
if (typeof body === 'string') {
|
|
26
|
+
// A mutation with no inputs will have req.body === ''
|
|
27
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
28
|
+
}
|
|
29
|
+
return body;
|
|
30
|
+
} catch (cause) {
|
|
31
|
+
throw new TRPCError.TRPCError({
|
|
32
|
+
code: 'PARSE_ERROR',
|
|
33
|
+
cause
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
38
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
39
|
+
};
|
|
40
|
+
const rawInput = await getRawProcedureInputOrThrow();
|
|
41
|
+
if (rawInput === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const transformer = opts.router._def._config.transformer;
|
|
45
|
+
if (!info.isBatchCall) {
|
|
46
|
+
return deserializeInputValue(rawInput, transformer);
|
|
47
|
+
}
|
|
48
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
49
|
+
throw new TRPCError.TRPCError({
|
|
50
|
+
code: 'BAD_REQUEST',
|
|
51
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const rawValue = rawInput[info.batch];
|
|
55
|
+
return deserializeInputValue(rawValue, transformer);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
exports.getFastifyHTTPJSONContentTypeHandler = getFastifyHTTPJSONContentTypeHandler;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
|
|
4
|
+
// @trpc/server
|
|
5
|
+
const getFastifyHTTPJSONContentTypeHandler = ()=>({
|
|
6
|
+
name: 'fastify-json',
|
|
7
|
+
isMatch (opts) {
|
|
8
|
+
return !!opts.req.headers['content-type']?.startsWith('application/json');
|
|
9
|
+
},
|
|
10
|
+
getInputs: async (opts, info)=>{
|
|
11
|
+
async function getRawProcedureInputOrThrow() {
|
|
12
|
+
const { req } = opts;
|
|
13
|
+
try {
|
|
14
|
+
if (req.method === 'GET') {
|
|
15
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
16
|
+
const input = query.get('input');
|
|
17
|
+
if (!input) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return JSON.parse(input);
|
|
21
|
+
}
|
|
22
|
+
const body = opts.req.body ?? 'null';
|
|
23
|
+
if (typeof body === 'string') {
|
|
24
|
+
// A mutation with no inputs will have req.body === ''
|
|
25
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
26
|
+
}
|
|
27
|
+
return body;
|
|
28
|
+
} catch (cause) {
|
|
29
|
+
throw new TRPCError({
|
|
30
|
+
code: 'PARSE_ERROR',
|
|
31
|
+
cause
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
36
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
37
|
+
};
|
|
38
|
+
const rawInput = await getRawProcedureInputOrThrow();
|
|
39
|
+
if (rawInput === undefined) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const transformer = opts.router._def._config.transformer;
|
|
43
|
+
if (!info.isBatchCall) {
|
|
44
|
+
return deserializeInputValue(rawInput, transformer);
|
|
45
|
+
}
|
|
46
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
47
|
+
throw new TRPCError({
|
|
48
|
+
code: 'BAD_REQUEST',
|
|
49
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const rawValue = rawInput[info.batch];
|
|
53
|
+
return deserializeInputValue(rawValue, transformer);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { getFastifyHTTPJSONContentTypeHandler };
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
2
|
import type { AnyRouter } from '../../@trpc/server';
|
|
3
|
-
import type {
|
|
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
|
-
};
|
|
3
|
+
import type { FastifyRequestHandlerOptions } from './types';
|
|
11
4
|
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<never>;
|
|
12
|
-
export {};
|
|
13
5
|
//# sourceMappingURL=fastifyRequestHandler.d.ts.map
|