Skip to content

Commit f96195b

Browse files
authored
fix: [#4684] Update INodeSocket type (#4767)
* Fix INodeSocket type * Fix compat * Remove unused import
1 parent 14fb6b5 commit f96195b

File tree

12 files changed

+82
-360
lines changed

12 files changed

+82
-360
lines changed

libraries/botbuilder-dialogs-adaptive-runtime-integration-express/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ export async function makeApp(
207207
const adapter = services.mustMakeInstance<BotFrameworkHttpAdapter>('adapter');
208208

209209
try {
210-
// TODO: Fix INodeSocket type. Related issue https://github.com/microsoft/botbuilder-js/issues/4684.
211-
await adapter.process(req, socket as any, head, async (context) => {
210+
await adapter.process(req, socket, head, async (context) => {
212211
await bot.run(context);
213212
});
214213
} catch (err: any) {

libraries/botbuilder-dialogs-adaptive-runtime-integration-restify/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ export async function makeServer(
194194
const adapter = services.mustMakeInstance<BotFrameworkHttpAdapter>('adapter');
195195

196196
try {
197-
// TODO: Fix INodeSocket type. Related issue https://github.com/microsoft/botbuilder-js/issues/4684.
198-
await adapter.process(req, socket as any, head, async (context) => {
197+
await adapter.process(req, socket, head, async (context) => {
199198
await bot.run(context);
200199
});
201200
} catch (err: any) {

libraries/botbuilder/etc/botbuilder.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { HttpClient } from '@azure/core-http';
4545
import { HttpOperationResponse } from '@azure/core-http';
4646
import { ICredentialProvider } from 'botframework-connector';
4747
import { INodeBuffer } from 'botframework-streaming';
48+
import { INodeDuplex } from 'botframework-streaming';
4849
import { INodeSocket } from 'botframework-streaming';
4950
import { InvokeResponse } from 'botbuilder-core';
5051
import { IReceiveRequest } from 'botframework-streaming';
@@ -187,6 +188,7 @@ export interface BotFrameworkAdapterSettings {
187188
export interface BotFrameworkHttpAdapter {
188189
process(req: Request_2, res: Response_2, logic: (context: TurnContext) => Promise<void>): Promise<void>;
189190
process(req: Request_2, socket: INodeSocket, head: INodeBuffer, logic: (context: TurnContext) => Promise<void>): Promise<void>;
191+
process(req: Request_2, socket: INodeDuplex, head: INodeBuffer, logic: (context: TurnContext) => Promise<void>): Promise<void>;
190192
}
191193

192194
// @public @deprecated (undocumented)
@@ -250,6 +252,7 @@ export class CloudAdapter extends CloudAdapterBase implements BotFrameworkHttpAd
250252
connectNamedPipe(pipeName: string, logic: (context: TurnContext) => Promise<void>, appId: string, audience: string, callerId?: string, retryCount?: number): Promise<void>;
251253
process(req: Request_2, res: Response_2, logic: (context: TurnContext) => Promise<void>): Promise<void>;
252254
process(req: Request_2, socket: INodeSocket, head: INodeBuffer, logic: (context: TurnContext) => Promise<void>): Promise<void>;
255+
process(req: Request_2, socket: INodeDuplex, head: INodeBuffer, logic: (context: TurnContext) => Promise<void>): Promise<void>;
253256
processActivityDirect(authorization: string | AuthenticateRequestResult, activity: Activity, logic: (context: TurnContext) => Promise<void>): Promise<void>;
254257
}
255258

libraries/botbuilder/src/botFrameworkHttpAdapter.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import type { INodeBuffer, INodeSocket } from 'botframework-streaming';
4+
import type { INodeBuffer, INodeDuplex, INodeSocket } from 'botframework-streaming';
55
import type { Request, Response } from './interfaces';
66
import type { TurnContext } from 'botbuilder-core';
77

@@ -26,4 +26,15 @@ export interface BotFrameworkHttpAdapter {
2626
head: INodeBuffer,
2727
logic: (context: TurnContext) => Promise<void>
2828
): Promise<void>;
29+
30+
/**
31+
* Handle a web socket connection by applying a logic callback function to
32+
* each streaming request.
33+
*/
34+
process(
35+
req: Request,
36+
socket: INodeDuplex,
37+
head: INodeBuffer,
38+
logic: (context: TurnContext) => Promise<void>
39+
): Promise<void>;
2940
}

libraries/botbuilder/src/cloudAdapter.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import {
2727
INodeBuffer,
2828
INodeSocket,
29+
INodeDuplex,
2930
IReceiveRequest,
3031
IReceiveResponse,
3132
IStreamingTransportServer,
@@ -80,12 +81,29 @@ export class CloudAdapter extends CloudAdapterBase implements BotFrameworkHttpAd
8081
logic: (context: TurnContext) => Promise<void>
8182
): Promise<void>;
8283

84+
/**
85+
* Handle a web socket connection by applying a logic function to
86+
* each streaming request.
87+
*
88+
* @param req An incoming HTTP [Request](xref:botbuilder.Request)
89+
* @param socket The corresponding [INodeDuplex](xref:botframework-streaming.INodeDuplex)
90+
* @param head The corresponding [INodeBuffer](xref:botframework-streaming.INodeBuffer)
91+
* @param logic The logic function to apply
92+
* @returns a promise representing the asynchronous operation.
93+
*/
94+
async process(
95+
req: Request,
96+
socket: INodeDuplex,
97+
head: INodeBuffer,
98+
logic: (context: TurnContext) => Promise<void>
99+
): Promise<void>;
100+
83101
/**
84102
* @internal
85103
*/
86104
async process(
87105
req: Request,
88-
resOrSocket: Response | INodeSocket,
106+
resOrSocket: Response | INodeSocket | INodeDuplex,
89107
logicOrHead: ((context: TurnContext) => Promise<void>) | INodeBuffer,
90108
maybeLogic?: (context: TurnContext) => Promise<void>
91109
): Promise<void> {

libraries/botframework-streaming/etc/botframework-streaming.api.md

Lines changed: 10 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { Duplex } from 'stream';
1010
import { DuplexOptions } from 'stream';
11+
import { Socket } from 'net';
1112
import { default as WebSocket_2 } from 'ws';
1213

1314
// @public
@@ -144,225 +145,26 @@ export interface INodeBuffer extends Uint8Array {
144145
writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
145146
}
146147

148+
// @public
149+
export interface INodeDuplex extends Duplex {
150+
// (undocumented)
151+
on(event: string | symbol, listener: (...args: any[]) => void): this;
152+
// (undocumented)
153+
on(event: 'data', listener: (chunk: INodeBuffer) => void): this;
154+
}
155+
147156
// @public
148157
export interface INodeIncomingMessage {
149158
headers?: any;
150159
method?: any;
151160
}
152161

153162
// @public
154-
export interface INodeSocket {
155-
// (undocumented)
156-
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
157-
// (undocumented)
158-
addListener(event: 'close', listener: () => void): this;
159-
// (undocumented)
160-
addListener(event: 'data', listener: (chunk: any) => void): this;
161-
// (undocumented)
162-
addListener(event: 'end', listener: () => void): this;
163-
// (undocumented)
164-
addListener(event: 'readable', listener: () => void): this;
165-
// (undocumented)
166-
addListener(event: 'error', listener: (err: Error) => void): this;
167-
// (undocumented)
168-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
169-
// Warning: (ae-forgotten-export) The symbol "AddressInfo" needs to be exported by the entry point index.d.ts
170-
//
171-
// (undocumented)
172-
address(): AddressInfo | string;
173-
// (undocumented)
174-
readonly bufferSize: number;
175-
// (undocumented)
176-
readonly bytesRead: number;
177-
// (undocumented)
178-
readonly bytesWritten: number;
179-
// (undocumented)
180-
connect(options: any, connectionListener?: () => void): any;
181-
// (undocumented)
182-
connect(port: number, host: string, connectionListener?: () => void): any;
183-
// (undocumented)
184-
connect(port: number, connectionListener?: () => void): any;
185-
// (undocumented)
186-
connect(path: string, connectionListener?: () => void): any;
187-
// (undocumented)
188-
connecting: boolean;
189-
// (undocumented)
190-
cork(): void;
191-
// (undocumented)
192-
destroy(error?: Error): void;
193-
// (undocumented)
194-
_destroy(error: Error | null, callback: (error: Error | null) => void): void;
195-
// (undocumented)
196-
destroyed: boolean;
197-
// (undocumented)
198-
emit(event: 'close'): boolean;
199-
// (undocumented)
200-
emit(event: 'data', chunk: any): boolean;
201-
// (undocumented)
202-
emit(event: 'end'): boolean;
203-
// (undocumented)
204-
emit(event: 'readable'): boolean;
205-
// (undocumented)
206-
emit(event: 'error', err: Error): boolean;
207-
// (undocumented)
208-
emit(event: string | symbol, ...args: any[]): boolean;
209-
// (undocumented)
210-
end(cb?: () => void): void;
211-
// (undocumented)
212-
end(chunk: any, cb?: () => void): void;
213-
// (undocumented)
214-
end(chunk: any, encoding?: string, cb?: () => void): void;
215-
// (undocumented)
216-
eventNames(): Array<string | symbol>;
217-
// (undocumented)
218-
_final(callback: (error?: Error | null) => void): void;
219-
// (undocumented)
220-
getMaxListeners(): number;
221-
// (undocumented)
222-
isPaused(): boolean;
223-
// (undocumented)
224-
listenerCount(type: string | symbol): number;
225-
// (undocumented)
226-
listeners(event: string | symbol): Function[];
227-
// (undocumented)
228-
readonly localAddress: string;
229-
// (undocumented)
230-
readonly localPort: number;
231-
// (undocumented)
232-
off(event: string | symbol, listener: (...args: any[]) => void): this;
163+
export interface INodeSocket extends Socket {
233164
// (undocumented)
234165
on(event: string, listener: (...args: any[]) => void): this;
235166
// (undocumented)
236-
on(event: 'close', listener: (had_error: boolean) => void): this;
237-
// (undocumented)
238-
on(event: 'connect', listener: () => void): this;
239-
// (undocumented)
240167
on(event: 'data', listener: (data: INodeBuffer) => void): this;
241-
// (undocumented)
242-
on(event: 'end', listener: () => void): this;
243-
// (undocumented)
244-
on(event: 'error', listener: (err: Error) => void): this;
245-
// (undocumented)
246-
once(event: 'close', listener: () => void): this;
247-
// (undocumented)
248-
once(event: 'data', listener: (chunk: any) => void): this;
249-
// (undocumented)
250-
once(event: 'end', listener: () => void): this;
251-
// (undocumented)
252-
once(event: 'readable', listener: () => void): this;
253-
// (undocumented)
254-
once(event: 'error', listener: (err: Error) => void): this;
255-
// (undocumented)
256-
once(event: string | symbol, listener: (...args: any[]) => void): this;
257-
// (undocumented)
258-
pause(): this;
259-
// Warning: (ae-forgotten-export) The symbol "WritableStream_2" needs to be exported by the entry point index.d.ts
260-
//
261-
// (undocumented)
262-
pipe<T extends WritableStream_2>(destination: T, options?: {
263-
end?: boolean;
264-
}): T;
265-
// (undocumented)
266-
prependListener(event: 'close', listener: () => void): this;
267-
// (undocumented)
268-
prependListener(event: 'data', listener: (chunk: any) => void): this;
269-
// (undocumented)
270-
prependListener(event: 'end', listener: () => void): this;
271-
// (undocumented)
272-
prependListener(event: 'readable', listener: () => void): this;
273-
// (undocumented)
274-
prependListener(event: 'error', listener: (err: Error) => void): this;
275-
// (undocumented)
276-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
277-
// (undocumented)
278-
prependOnceListener(event: 'close', listener: () => void): this;
279-
// (undocumented)
280-
prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
281-
// (undocumented)
282-
prependOnceListener(event: 'end', listener: () => void): this;
283-
// (undocumented)
284-
prependOnceListener(event: 'readable', listener: () => void): this;
285-
// (undocumented)
286-
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
287-
// (undocumented)
288-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
289-
// (undocumented)
290-
push(chunk: any, encoding?: string): boolean;
291-
// (undocumented)
292-
rawListeners(event: string | symbol): Function[];
293-
// (undocumented)
294-
read(size?: number): any;
295-
// (undocumented)
296-
_read(size: number): void;
297-
// (undocumented)
298-
readable: boolean;
299-
// (undocumented)
300-
readonly readableFlowing: boolean | null;
301-
// (undocumented)
302-
readonly readableHighWaterMark: number;
303-
// (undocumented)
304-
readonly readableLength: number;
305-
// (undocumented)
306-
ref(): any;
307-
// (undocumented)
308-
removeAllListeners(event?: string | symbol): this;
309-
// (undocumented)
310-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
311-
// (undocumented)
312-
resume(): this;
313-
// (undocumented)
314-
setDefaultEncoding(encoding: string): this;
315-
// (undocumented)
316-
setEncoding(encoding: string): this;
317-
// (undocumented)
318-
setKeepAlive(enable?: boolean, initialDelay?: number): this;
319-
// (undocumented)
320-
setMaxListeners(n: number): this;
321-
// (undocumented)
322-
setNoDelay(noDelay?: boolean): this;
323-
// (undocumented)
324-
setTimeout(timeout: number, callback?: () => void): this;
325-
// (undocumented)
326-
uncork(): void;
327-
// (undocumented)
328-
unpipe(destination?: any): this;
329-
// (undocumented)
330-
unref(): any;
331-
// (undocumented)
332-
unshift(chunk: any): void;
333-
// (undocumented)
334-
wrap(oldStream: any): this;
335-
// (undocumented)
336-
writable: boolean;
337-
// (undocumented)
338-
readonly writableHighWaterMark: number;
339-
// (undocumented)
340-
readonly writableLength: number;
341-
// Warning: (ae-forgotten-export) The symbol "ValidBuffer" needs to be exported by the entry point index.d.ts
342-
//
343-
// (undocumented)
344-
write(buffer: ValidBuffer, cb?: (err?: Error) => void): boolean;
345-
// (undocumented)
346-
write(str: string, encoding?: string, cb?: Function): boolean;
347-
// (undocumented)
348-
write(buffer: ValidBuffer): boolean;
349-
// (undocumented)
350-
write(str: string, cb?: Function): boolean;
351-
// (undocumented)
352-
write(str: string, encoding?: string, fd?: string): boolean;
353-
// (undocumented)
354-
write(data: any, encoding?: string, callback?: Function): void;
355-
// (undocumented)
356-
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
357-
// (undocumented)
358-
write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
359-
// (undocumented)
360-
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
361-
// (undocumented)
362-
_writev?(chunks: Array<{
363-
chunk: any;
364-
encoding: string;
365-
}>, callback: (error?: Error | null) => void): void;
366168
}
367169

368170
// @public

libraries/botframework-streaming/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export {
1212
INodeBuffer,
1313
INodeIncomingMessage,
1414
INodeSocket,
15+
INodeDuplex,
1516
IReceiveRequest,
1617
IReceiveResponse,
1718
ISocket,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
2+
/**
3+
* @module botframework-streaming
4+
*/
5+
/**
6+
* Copyright (c) Microsoft Corporation. All rights reserved.
7+
* Licensed under the MIT License.
8+
*/
9+
10+
import { Duplex } from 'stream';
11+
import { INodeBuffer } from './INodeBuffer';
12+
13+
/**
14+
* Represents a Duplex from the `stream` module in Node.js.
15+
*
16+
* This interface supports the framework and is not intended to be called directly for your code.
17+
*/
18+
export interface INodeDuplex extends Duplex {
19+
on(event: string | symbol, listener: (...args: any[]) => void): this;
20+
on(event: 'data', listener: (chunk: INodeBuffer) => void): this;
21+
}

0 commit comments

Comments
 (0)