Skip to content

Commit

Permalink
fix: [#4684] Update INodeSocket type (#4767)
Browse files Browse the repository at this point in the history
* Fix INodeSocket type

* Fix compat

* Remove unused import
  • Loading branch information
sw-joelmut authored Oct 29, 2024
1 parent 14fb6b5 commit f96195b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ export async function makeApp(
const adapter = services.mustMakeInstance<BotFrameworkHttpAdapter>('adapter');

try {
// TODO: Fix INodeSocket type. Related issue https://github.com/microsoft/botbuilder-js/issues/4684.
await adapter.process(req, socket as any, head, async (context) => {
await adapter.process(req, socket, head, async (context) => {
await bot.run(context);
});
} catch (err: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ export async function makeServer(
const adapter = services.mustMakeInstance<BotFrameworkHttpAdapter>('adapter');

try {
// TODO: Fix INodeSocket type. Related issue https://github.com/microsoft/botbuilder-js/issues/4684.
await adapter.process(req, socket as any, head, async (context) => {
await adapter.process(req, socket, head, async (context) => {
await bot.run(context);
});
} catch (err: any) {
Expand Down
3 changes: 3 additions & 0 deletions libraries/botbuilder/etc/botbuilder.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { HttpClient } from '@azure/core-http';
import { HttpOperationResponse } from '@azure/core-http';
import { ICredentialProvider } from 'botframework-connector';
import { INodeBuffer } from 'botframework-streaming';
import { INodeDuplex } from 'botframework-streaming';
import { INodeSocket } from 'botframework-streaming';
import { InvokeResponse } from 'botbuilder-core';
import { IReceiveRequest } from 'botframework-streaming';
Expand Down Expand Up @@ -187,6 +188,7 @@ export interface BotFrameworkAdapterSettings {
export interface BotFrameworkHttpAdapter {
process(req: Request_2, res: Response_2, logic: (context: TurnContext) => Promise<void>): Promise<void>;
process(req: Request_2, socket: INodeSocket, head: INodeBuffer, logic: (context: TurnContext) => Promise<void>): Promise<void>;
process(req: Request_2, socket: INodeDuplex, head: INodeBuffer, logic: (context: TurnContext) => Promise<void>): Promise<void>;
}

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

Expand Down
13 changes: 12 additions & 1 deletion libraries/botbuilder/src/botFrameworkHttpAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

Expand All @@ -26,4 +26,15 @@ export interface BotFrameworkHttpAdapter {
head: INodeBuffer,
logic: (context: TurnContext) => Promise<void>
): Promise<void>;

/**
* Handle a web socket connection by applying a logic callback function to
* each streaming request.
*/
process(
req: Request,
socket: INodeDuplex,
head: INodeBuffer,
logic: (context: TurnContext) => Promise<void>
): Promise<void>;
}
20 changes: 19 additions & 1 deletion libraries/botbuilder/src/cloudAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import {
INodeBuffer,
INodeSocket,
INodeDuplex,
IReceiveRequest,
IReceiveResponse,
IStreamingTransportServer,
Expand Down Expand Up @@ -80,12 +81,29 @@ export class CloudAdapter extends CloudAdapterBase implements BotFrameworkHttpAd
logic: (context: TurnContext) => Promise<void>
): Promise<void>;

/**
* Handle a web socket connection by applying a logic function to
* each streaming request.
*
* @param req An incoming HTTP [Request](xref:botbuilder.Request)
* @param socket The corresponding [INodeDuplex](xref:botframework-streaming.INodeDuplex)
* @param head The corresponding [INodeBuffer](xref:botframework-streaming.INodeBuffer)
* @param logic The logic function to apply
* @returns a promise representing the asynchronous operation.
*/
async process(
req: Request,
socket: INodeDuplex,
head: INodeBuffer,
logic: (context: TurnContext) => Promise<void>
): Promise<void>;

/**
* @internal
*/
async process(
req: Request,
resOrSocket: Response | INodeSocket,
resOrSocket: Response | INodeSocket | INodeDuplex,
logicOrHead: ((context: TurnContext) => Promise<void>) | INodeBuffer,
maybeLogic?: (context: TurnContext) => Promise<void>
): Promise<void> {
Expand Down
218 changes: 10 additions & 208 deletions libraries/botframework-streaming/etc/botframework-streaming.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Duplex } from 'stream';
import { DuplexOptions } from 'stream';
import { Socket } from 'net';
import { default as WebSocket_2 } from 'ws';

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

// @public
export interface INodeDuplex extends Duplex {
// (undocumented)
on(event: string | symbol, listener: (...args: any[]) => void): this;
// (undocumented)
on(event: 'data', listener: (chunk: INodeBuffer) => void): this;
}

// @public
export interface INodeIncomingMessage {
headers?: any;
method?: any;
}

// @public
export interface INodeSocket {
// (undocumented)
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
// (undocumented)
addListener(event: 'close', listener: () => void): this;
// (undocumented)
addListener(event: 'data', listener: (chunk: any) => void): this;
// (undocumented)
addListener(event: 'end', listener: () => void): this;
// (undocumented)
addListener(event: 'readable', listener: () => void): this;
// (undocumented)
addListener(event: 'error', listener: (err: Error) => void): this;
// (undocumented)
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
// Warning: (ae-forgotten-export) The symbol "AddressInfo" needs to be exported by the entry point index.d.ts
//
// (undocumented)
address(): AddressInfo | string;
// (undocumented)
readonly bufferSize: number;
// (undocumented)
readonly bytesRead: number;
// (undocumented)
readonly bytesWritten: number;
// (undocumented)
connect(options: any, connectionListener?: () => void): any;
// (undocumented)
connect(port: number, host: string, connectionListener?: () => void): any;
// (undocumented)
connect(port: number, connectionListener?: () => void): any;
// (undocumented)
connect(path: string, connectionListener?: () => void): any;
// (undocumented)
connecting: boolean;
// (undocumented)
cork(): void;
// (undocumented)
destroy(error?: Error): void;
// (undocumented)
_destroy(error: Error | null, callback: (error: Error | null) => void): void;
// (undocumented)
destroyed: boolean;
// (undocumented)
emit(event: 'close'): boolean;
// (undocumented)
emit(event: 'data', chunk: any): boolean;
// (undocumented)
emit(event: 'end'): boolean;
// (undocumented)
emit(event: 'readable'): boolean;
// (undocumented)
emit(event: 'error', err: Error): boolean;
// (undocumented)
emit(event: string | symbol, ...args: any[]): boolean;
// (undocumented)
end(cb?: () => void): void;
// (undocumented)
end(chunk: any, cb?: () => void): void;
// (undocumented)
end(chunk: any, encoding?: string, cb?: () => void): void;
// (undocumented)
eventNames(): Array<string | symbol>;
// (undocumented)
_final(callback: (error?: Error | null) => void): void;
// (undocumented)
getMaxListeners(): number;
// (undocumented)
isPaused(): boolean;
// (undocumented)
listenerCount(type: string | symbol): number;
// (undocumented)
listeners(event: string | symbol): Function[];
// (undocumented)
readonly localAddress: string;
// (undocumented)
readonly localPort: number;
// (undocumented)
off(event: string | symbol, listener: (...args: any[]) => void): this;
export interface INodeSocket extends Socket {
// (undocumented)
on(event: string, listener: (...args: any[]) => void): this;
// (undocumented)
on(event: 'close', listener: (had_error: boolean) => void): this;
// (undocumented)
on(event: 'connect', listener: () => void): this;
// (undocumented)
on(event: 'data', listener: (data: INodeBuffer) => void): this;
// (undocumented)
on(event: 'end', listener: () => void): this;
// (undocumented)
on(event: 'error', listener: (err: Error) => void): this;
// (undocumented)
once(event: 'close', listener: () => void): this;
// (undocumented)
once(event: 'data', listener: (chunk: any) => void): this;
// (undocumented)
once(event: 'end', listener: () => void): this;
// (undocumented)
once(event: 'readable', listener: () => void): this;
// (undocumented)
once(event: 'error', listener: (err: Error) => void): this;
// (undocumented)
once(event: string | symbol, listener: (...args: any[]) => void): this;
// (undocumented)
pause(): this;
// Warning: (ae-forgotten-export) The symbol "WritableStream_2" needs to be exported by the entry point index.d.ts
//
// (undocumented)
pipe<T extends WritableStream_2>(destination: T, options?: {
end?: boolean;
}): T;
// (undocumented)
prependListener(event: 'close', listener: () => void): this;
// (undocumented)
prependListener(event: 'data', listener: (chunk: any) => void): this;
// (undocumented)
prependListener(event: 'end', listener: () => void): this;
// (undocumented)
prependListener(event: 'readable', listener: () => void): this;
// (undocumented)
prependListener(event: 'error', listener: (err: Error) => void): this;
// (undocumented)
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
// (undocumented)
prependOnceListener(event: 'close', listener: () => void): this;
// (undocumented)
prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
// (undocumented)
prependOnceListener(event: 'end', listener: () => void): this;
// (undocumented)
prependOnceListener(event: 'readable', listener: () => void): this;
// (undocumented)
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
// (undocumented)
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
// (undocumented)
push(chunk: any, encoding?: string): boolean;
// (undocumented)
rawListeners(event: string | symbol): Function[];
// (undocumented)
read(size?: number): any;
// (undocumented)
_read(size: number): void;
// (undocumented)
readable: boolean;
// (undocumented)
readonly readableFlowing: boolean | null;
// (undocumented)
readonly readableHighWaterMark: number;
// (undocumented)
readonly readableLength: number;
// (undocumented)
ref(): any;
// (undocumented)
removeAllListeners(event?: string | symbol): this;
// (undocumented)
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
// (undocumented)
resume(): this;
// (undocumented)
setDefaultEncoding(encoding: string): this;
// (undocumented)
setEncoding(encoding: string): this;
// (undocumented)
setKeepAlive(enable?: boolean, initialDelay?: number): this;
// (undocumented)
setMaxListeners(n: number): this;
// (undocumented)
setNoDelay(noDelay?: boolean): this;
// (undocumented)
setTimeout(timeout: number, callback?: () => void): this;
// (undocumented)
uncork(): void;
// (undocumented)
unpipe(destination?: any): this;
// (undocumented)
unref(): any;
// (undocumented)
unshift(chunk: any): void;
// (undocumented)
wrap(oldStream: any): this;
// (undocumented)
writable: boolean;
// (undocumented)
readonly writableHighWaterMark: number;
// (undocumented)
readonly writableLength: number;
// Warning: (ae-forgotten-export) The symbol "ValidBuffer" needs to be exported by the entry point index.d.ts
//
// (undocumented)
write(buffer: ValidBuffer, cb?: (err?: Error) => void): boolean;
// (undocumented)
write(str: string, encoding?: string, cb?: Function): boolean;
// (undocumented)
write(buffer: ValidBuffer): boolean;
// (undocumented)
write(str: string, cb?: Function): boolean;
// (undocumented)
write(str: string, encoding?: string, fd?: string): boolean;
// (undocumented)
write(data: any, encoding?: string, callback?: Function): void;
// (undocumented)
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
// (undocumented)
write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
// (undocumented)
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
// (undocumented)
_writev?(chunks: Array<{
chunk: any;
encoding: string;
}>, callback: (error?: Error | null) => void): void;
}

// @public
Expand Down
1 change: 1 addition & 0 deletions libraries/botframework-streaming/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
INodeBuffer,
INodeIncomingMessage,
INodeSocket,
INodeDuplex,
IReceiveRequest,
IReceiveResponse,
ISocket,
Expand Down
21 changes: 21 additions & 0 deletions libraries/botframework-streaming/src/interfaces/INodeDuplex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
/**
* @module botframework-streaming
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import { Duplex } from 'stream';
import { INodeBuffer } from './INodeBuffer';

/**
* Represents a Duplex from the `stream` module in Node.js.
*
* This interface supports the framework and is not intended to be called directly for your code.
*/
export interface INodeDuplex extends Duplex {
on(event: string | symbol, listener: (...args: any[]) => void): this;
on(event: 'data', listener: (chunk: INodeBuffer) => void): this;
}
Loading

0 comments on commit f96195b

Please sign in to comment.