@@ -8,9 +8,9 @@ import type {
8
8
APIGatewayProxyResult ,
9
9
Context ,
10
10
} from 'aws-lambda' ;
11
- import type { ResponseStream as LambdaResponseStream } from 'lambda-stream' ;
12
11
import type { HttpStatusCodes , HttpVerbs } from '../rest/constants.js' ;
13
12
import type { Route } from '../rest/Route.js' ;
13
+ import type { HttpResponseStream } from '../rest/utils.js' ;
14
14
import type { ResolveOptions } from './common.js' ;
15
15
16
16
type RequestContext = {
@@ -65,10 +65,6 @@ type ExtendedAPIGatewayProxyResult = Omit<APIGatewayProxyResult, 'body'> & {
65
65
body : ExtendedAPIGatewayProxyResultBody ;
66
66
} ;
67
67
68
- type ResponseStream = LambdaResponseStream & {
69
- _onBeforeFirstWrite ?: ( write : ( data : Uint8Array | string ) => void ) => void ;
70
- } ;
71
-
72
68
type HandlerResponse = Response | JSONObject | ExtendedAPIGatewayProxyResult ;
73
69
74
70
type RouteHandler < TReturn = HandlerResponse > = (
@@ -126,6 +122,51 @@ type ValidationResult = {
126
122
issues : string [ ] ;
127
123
} ;
128
124
125
+ type ResponseStream = InstanceType < typeof HttpResponseStream > & {
126
+ _onBeforeFirstWrite ?: ( write : ( data : Uint8Array | string ) => void ) => void ;
127
+ } ;
128
+
129
+ /**
130
+ * Object to pass to the {@link Router.resolveStream | `Router.resolveStream()`} method.
131
+ */
132
+ type ResolveStreamOptions = {
133
+ /**
134
+ * Reference to `this` instance of the class that is calling the `resolveStream` method.
135
+ *
136
+ * This parameter should be used only when using {@link Router} route decorators like
137
+ * {@link Router.get | `Router.get()`}, {@link Router.post | `Router.post()`}, etc. as class method decorators, and
138
+ * it's used to bind the decorated methods to your class instance.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import { Router } from '@aws-lambda-powertools/event-handler/experimental-rest';
143
+ *
144
+ * const app = new Router();
145
+ *
146
+ * class Lambda {
147
+ * public scope = 'scoped';
148
+ *
149
+ * @app .get('/test')
150
+ * public async getTest() {
151
+ * return { message: `${this.scope}: success` };
152
+ * }
153
+ *
154
+ * public async handler(event: unknown, context: Context, responseStream: ResponseStream) {
155
+ * return app.resolveStream(event, context, { scope: this, responseStream });
156
+ * }
157
+ * }
158
+ * const lambda = new Lambda();
159
+ * const handler = lambda.handler.bind(lambda);
160
+ * ```
161
+ */
162
+ scope ?: unknown ;
163
+ /**
164
+ * The Lambda response stream used for streaming responses directly to the client.
165
+ * This stream is provided by the AWS Lambda runtime for response streaming.
166
+ */
167
+ responseStream : ResponseStream ;
168
+ } ;
169
+
129
170
/**
130
171
* Configuration options for CORS middleware
131
172
*/
@@ -190,8 +231,9 @@ export type {
190
231
Path ,
191
232
RequestContext ,
192
233
RestRouterOptions ,
193
- ResponseStream ,
194
234
RouteHandler ,
235
+ ResolveStreamOptions ,
236
+ ResponseStream ,
195
237
RestRouteOptions ,
196
238
RestRouteHandlerOptions ,
197
239
RouteRegistryOptions ,
0 commit comments