@mstuercke/api-utils 5.0.1 → 5.1.0
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/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {PostToConnectionCommand} from '@aws-sdk/client-apigatewaymanagementapi';
|
|
2
|
-
import {AnyTRPCRouter, callTRPCProcedure} from '@trpc/server';
|
|
2
|
+
import {AnyTRPCRouter, callTRPCProcedure, inferRouterContext} from '@trpc/server';
|
|
3
3
|
import type {APIGatewayResult} from '@trpc/server/adapters/aws-lambda';
|
|
4
4
|
import type {Observable} from '@trpc/server/observable';
|
|
5
5
|
import {APIGatewayProxyEvent} from 'aws-lambda';
|
|
@@ -10,8 +10,9 @@ import {TrpcSubscriptionResponse} from './TrpcSubscriptionResponse';
|
|
|
10
10
|
|
|
11
11
|
export const awsLambdaTrpcSubscriptionRequestHandler = <Router extends AnyTRPCRouter>(opts: {
|
|
12
12
|
router: Router
|
|
13
|
+
createContext?: (event: APIGatewayProxyEvent) => Promise<inferRouterContext<Router>>
|
|
13
14
|
}) => {
|
|
14
|
-
const {router} = opts;
|
|
15
|
+
const {router, createContext} = opts;
|
|
15
16
|
|
|
16
17
|
return async (event: APIGatewayProxyEvent): Promise<APIGatewayResult> => {
|
|
17
18
|
const connection = getConnection(event);
|
|
@@ -51,7 +52,7 @@ export const awsLambdaTrpcSubscriptionRequestHandler = <Router extends AnyTRPCRo
|
|
|
51
52
|
procedures: router._def.procedures,
|
|
52
53
|
path: request.params.path,
|
|
53
54
|
type: 'subscription',
|
|
54
|
-
ctx: {},
|
|
55
|
+
ctx: createContext?.(event) || {},
|
|
55
56
|
getRawInput: async () => request.params.input,
|
|
56
57
|
})) as Observable<unknown, unknown>;
|
|
57
58
|
|
|
@@ -94,7 +95,7 @@ export const awsLambdaTrpcSubscriptionRequestHandler = <Router extends AnyTRPCRo
|
|
|
94
95
|
}
|
|
95
96
|
} catch (err) {
|
|
96
97
|
console.error(err);
|
|
97
|
-
await stopConnection()
|
|
98
|
+
await stopConnection();
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
return {
|