Skip to content

Commit ea90f8b

Browse files
committed
address PR feedback
1 parent fdfc4c2 commit ea90f8b

File tree

4 files changed

+74
-36
lines changed

4 files changed

+74
-36
lines changed

packages/event-handler/src/rest/utils.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Duplex, Readable, Writable } from 'node:stream';
1+
import { Duplex, Readable } from 'node:stream';
22
import {
33
isRecord,
44
isRegExp,
@@ -18,9 +18,9 @@ import type {
1818
HandlerResponse,
1919
HttpMethod,
2020
HttpStatusCode,
21-
ResponseStream as IResponseStream,
2221
Middleware,
2322
Path,
23+
ResponseStream,
2424
ValidationResult,
2525
} from '../types/rest.js';
2626
import {
@@ -306,35 +306,35 @@ export const resolvePrefixedPath = (path: Path, prefix?: Path): Path => {
306306
return `${prefix}${path}`.replace(/\/$/, '') as Path;
307307
};
308308

309-
export class ResponseStream extends Writable implements IResponseStream {
310-
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: This is how the Lambda RIC implements it
311-
#contentType: string | undefined;
312-
readonly #chunks: Buffer[] = [];
313-
public _onBeforeFirstWrite?: (
314-
write: (data: Uint8Array | string) => void
315-
) => void;
316-
#firstWrite = true;
317-
318-
setContentType(contentType: string) {
319-
this.#contentType = contentType;
320-
}
321-
322-
_write(chunk: Buffer, _encoding: string, callback: () => void): void {
323-
/* v8 ignore else -- @preserve */
324-
if (this.#firstWrite && this._onBeforeFirstWrite) {
325-
this._onBeforeFirstWrite((data: Uint8Array | string) => {
326-
this.#chunks.push(Buffer.from(data));
327-
});
328-
this.#firstWrite = false;
329-
}
330-
this.#chunks.push(chunk);
331-
callback();
332-
}
333-
334-
public getBuffer(): Buffer {
335-
return Buffer.concat(this.#chunks);
336-
}
337-
}
309+
// export class ResponseStream extends Writable implements IResponseStream {
310+
// // biome-ignore lint/correctness/noUnusedPrivateClassMembers: This is how the Lambda RIC implements it
311+
// #contentType: string | undefined;
312+
// readonly #chunks: Buffer[] = [];
313+
// public _onBeforeFirstWrite?: (
314+
// write: (data: Uint8Array | string) => void
315+
// ) => void;
316+
// #firstWrite = true;
317+
//
318+
// setContentType(contentType: string) {
319+
// this.#contentType = contentType;
320+
// }
321+
//
322+
// _write(chunk: Buffer, _encoding: string, callback: () => void): void {
323+
// /* v8 ignore else -- @preserve */
324+
// if (this.#firstWrite && this._onBeforeFirstWrite) {
325+
// this._onBeforeFirstWrite((data: Uint8Array | string) => {
326+
// this.#chunks.push(Buffer.from(data));
327+
// });
328+
// this.#firstWrite = false;
329+
// }
330+
// this.#chunks.push(chunk);
331+
// callback();
332+
// }
333+
//
334+
// public getBuffer(): Buffer {
335+
// return Buffer.concat(this.#chunks);
336+
// }
337+
// }
338338

339339
export const HttpResponseStream =
340340
globalThis.awslambda?.HttpResponseStream ??
@@ -428,7 +428,7 @@ const streamifyResponse =
428428

429429
/* v8 ignore next -- @preserve */
430430
const output: Buffer =
431-
(responseStream as IResponseStream).getBuffer?.() ?? Buffer.from([]);
431+
(responseStream as ResponseStream).getBuffer?.() ?? Buffer.from([]);
432432
const nullBytes = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]);
433433
const separatorIndex = output.indexOf(nullBytes);
434434

packages/event-handler/tests/unit/rest/Router/decorators.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
streamify,
1010
UnauthorizedError,
1111
} from '../../../../src/rest/index.js';
12-
import { ResponseStream } from '../../../../src/rest/utils.js';
1312
import type { RequestContext } from '../../../../src/types/rest.js';
1413
import {
1514
createHandler,
@@ -18,6 +17,7 @@ import {
1817
createTestEventV2,
1918
createTestLambdaClass,
2019
createTrackingMiddleware,
20+
ResponseStream,
2121
} from '../helpers.js';
2222

2323
describe.each([

packages/event-handler/tests/unit/rest/Router/streaming.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
streamify,
77
UnauthorizedError,
88
} from '../../../../src/rest/index.js';
9-
import { ResponseStream } from '../../../../src/rest/utils.js';
10-
import { createTestEvent, createTestEventV2 } from '../helpers.js';
9+
import {
10+
createTestEvent,
11+
createTestEventV2,
12+
ResponseStream,
13+
} from '../helpers.js';
1114

1215
describe.each([
1316
{ version: 'V1', createEvent: createTestEvent },

packages/event-handler/tests/unit/rest/helpers.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Writable } from 'node:stream';
12
import type {
23
APIGatewayProxyEvent,
34
APIGatewayProxyEventV2,
@@ -6,7 +7,11 @@ import type {
67
Context,
78
} from 'aws-lambda';
89
import type { Router } from '../../../src/rest/Router.js';
9-
import type { HandlerResponse, Middleware } from '../../../src/types/rest.js';
10+
import type {
11+
HandlerResponse,
12+
ResponseStream as IResponseStream,
13+
Middleware,
14+
} from '../../../src/types/rest.js';
1015

1116
export const createTestEvent = (
1217
path: string,
@@ -128,6 +133,36 @@ export const createHeaderCheckMiddleware = (headers: {
128133
};
129134
};
130135

136+
export class ResponseStream extends Writable implements IResponseStream {
137+
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: This is how the Lambda RIC implements it
138+
#contentType: string | undefined;
139+
readonly #chunks: Buffer[] = [];
140+
public _onBeforeFirstWrite?: (
141+
write: (data: Uint8Array | string) => void
142+
) => void;
143+
#firstWrite = true;
144+
145+
setContentType(contentType: string) {
146+
this.#contentType = contentType;
147+
}
148+
149+
_write(chunk: Buffer, _encoding: string, callback: () => void): void {
150+
/* v8 ignore else -- @preserve */
151+
if (this.#firstWrite && this._onBeforeFirstWrite) {
152+
this._onBeforeFirstWrite((data: Uint8Array | string) => {
153+
this.#chunks.push(Buffer.from(data));
154+
});
155+
this.#firstWrite = false;
156+
}
157+
this.#chunks.push(chunk);
158+
callback();
159+
}
160+
161+
public getBuffer(): Buffer {
162+
return Buffer.concat(this.#chunks);
163+
}
164+
}
165+
131166
// Create a handler function from the Router instance
132167
export const createHandler = (app: Router) => {
133168
function handler(

0 commit comments

Comments
 (0)