@@ -8,9 +8,9 @@ import type {
88 APIGatewayProxyResult ,
99 Context ,
1010} from 'aws-lambda' ;
11- import type { ResponseStream as LambdaResponseStream } from 'lambda-stream' ;
1211import type { HttpStatusCodes , HttpVerbs } from '../rest/constants.js' ;
1312import type { Route } from '../rest/Route.js' ;
13+ import type { HttpResponseStream } from '../rest/utils.js' ;
1414import type { ResolveOptions } from './common.js' ;
1515
1616type RequestContext = {
@@ -65,10 +65,6 @@ type ExtendedAPIGatewayProxyResult = Omit<APIGatewayProxyResult, 'body'> & {
6565 body : ExtendedAPIGatewayProxyResultBody ;
6666} ;
6767
68- type ResponseStream = LambdaResponseStream & {
69- _onBeforeFirstWrite ?: ( write : ( data : Uint8Array | string ) => void ) => void ;
70- } ;
71-
7268type HandlerResponse = Response | JSONObject | ExtendedAPIGatewayProxyResult ;
7369
7470type RouteHandler < TReturn = HandlerResponse > = (
@@ -126,6 +122,51 @@ type ValidationResult = {
126122 issues : string [ ] ;
127123} ;
128124
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+
129170/**
130171 * Configuration options for CORS middleware
131172 */
@@ -190,8 +231,9 @@ export type {
190231 Path ,
191232 RequestContext ,
192233 RestRouterOptions ,
193- ResponseStream ,
194234 RouteHandler ,
235+ ResolveStreamOptions ,
236+ ResponseStream ,
195237 RestRouteOptions ,
196238 RestRouteHandlerOptions ,
197239 RouteRegistryOptions ,
0 commit comments