Skip to content

Commit

Permalink
Relaxed WebSocket types to accept anything reasonable
Browse files Browse the repository at this point in the history
  • Loading branch information
jawj committed Dec 18, 2024
1 parent 11d5525 commit afbca19
Show file tree
Hide file tree
Showing 14 changed files with 633 additions and 541 deletions.
6 changes: 2 additions & 4 deletions api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"mainEntryPointFilePath": "dist/dts/export/index.d.ts",
"newlineKind": "lf",
"enumMemberOrder": "preserve",
"bundledPackages": [
"subtls"
],
"bundledPackages": ["subtls"],
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "dist/dts/_extracted.d.ts"
Expand All @@ -25,4 +23,4 @@
}
}
}
}
}
14 changes: 13 additions & 1 deletion dist/dts/_extracted.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ declare interface SocketDefaults {
fetchEndpoint: string | ((host: string, port: number | string, options?: FetchEndpointOptions) => string);
fetchConnectionCache: boolean;
fetchFunction: any;
webSocketConstructor: typeof WebSocket | undefined;
webSocketConstructor: WebSocketConstructor | undefined;
wsProxy: string | ((host: string, port: number | string) => string);
useSecureWebSocket: boolean;
forceDisablePgSSL: boolean;
Expand Down Expand Up @@ -528,6 +528,18 @@ export { types }

declare function u8FromHex(hex: string): Uint8Array<ArrayBuffer>;

declare interface WebSocketConstructor {
new (...args: any[]): WebSocketLike;
}

declare interface WebSocketLike {
readonly readyState: number;
binaryType: string;
close(code?: number, reason?: string): void;
send(data: any): void;
addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (this: WebSocketLike, ev: any) => any, options?: any): void;
}

declare class WebSocketReadQueue extends ReadQueue {
private socket;
constructor(socket: WebSocket);
Expand Down
14 changes: 13 additions & 1 deletion dist/dts/_extracted.d.ts.orig
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ declare interface SocketDefaults {
fetchEndpoint: string | ((host: string, port: number | string, options?: FetchEndpointOptions) => string);
fetchConnectionCache: boolean;
fetchFunction: any;
webSocketConstructor: typeof WebSocket | undefined;
webSocketConstructor: WebSocketConstructor | undefined;
wsProxy: string | ((host: string, port: number | string) => string);
useSecureWebSocket: boolean;
forceDisablePgSSL: boolean;
Expand Down Expand Up @@ -528,6 +528,18 @@ export { types }

declare function u8FromHex(hex: string): Uint8Array<ArrayBuffer>;

declare interface WebSocketConstructor {
new (...args: any[]): WebSocketLike;
}

declare interface WebSocketLike {
readonly readyState: number;
binaryType: string;
close(code?: number, reason?: string): void;
send(data: any): void;
addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (this: WebSocketLike, ev: any) => any, options?: any): void;
}

declare class WebSocketReadQueue extends ReadQueue {
private socket;
constructor(socket: WebSocket);
Expand Down
12 changes: 11 additions & 1 deletion dist/dts/shims/net/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
*/
import { EventEmitter } from 'events';
import type * as subtls from 'subtls';
interface WebSocketLike {
readonly readyState: number;
binaryType: string;
close(code?: number, reason?: string): void;
send(data: any): void;
addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (this: WebSocketLike, ev: any) => any, options?: any): void;
}
interface WebSocketConstructor {
new (...args: any[]): WebSocketLike;
}
export declare function isIP(input: string): number;
interface FetchEndpointOptions {
jwtAuth?: boolean;
Expand All @@ -16,7 +26,7 @@ export interface SocketDefaults {
fetchEndpoint: string | ((host: string, port: number | string, options?: FetchEndpointOptions) => string);
fetchConnectionCache: boolean;
fetchFunction: any;
webSocketConstructor: typeof WebSocket | undefined;
webSocketConstructor: WebSocketConstructor | undefined;
wsProxy: string | ((host: string, port: number | string) => string);
useSecureWebSocket: boolean;
forceDisablePgSSL: boolean;
Expand Down
21 changes: 11 additions & 10 deletions dist/dts/shims/net/index.d.ts.orig
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import { EventEmitter } from 'events';
import type * as subtls from 'subtls';
declare global {
const debug: boolean;
interface WebSocket {
binaryType: 'arraybuffer' | 'blob';
accept?: () => void;
}
interface Response {
webSocket: WebSocket;
}
class __unstable_WebSocket extends WebSocket {
}
}
interface WebSocketLike {
readonly readyState: number;
binaryType: string;
close(code?: number, reason?: string): void;
send(data: any): void;
addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (this: WebSocketLike, ev: any) => any, options?: any): void;
}
interface WebSocketConstructor {
new (...args: any[]): WebSocketLike;
}
export declare function isIP(input: string): number;
interface FetchEndpointOptions {
Expand All @@ -28,7 +29,7 @@ export interface SocketDefaults {
fetchEndpoint: string | ((host: string, port: number | string, options?: FetchEndpointOptions) => string);
fetchConnectionCache: boolean;
fetchFunction: any;
webSocketConstructor: typeof WebSocket | undefined;
webSocketConstructor: WebSocketConstructor | undefined;
wsProxy: string | ((host: string, port: number | string) => string);
useSecureWebSocket: boolean;
forceDisablePgSSL: boolean;
Expand Down
14 changes: 13 additions & 1 deletion dist/jsr/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ declare interface SocketDefaults {
fetchEndpoint: string | ((host: string, port: number | string, options?: FetchEndpointOptions) => string);
fetchConnectionCache: boolean;
fetchFunction: any;
webSocketConstructor: typeof WebSocket | undefined;
webSocketConstructor: WebSocketConstructor | undefined;
wsProxy: string | ((host: string, port: number | string) => string);
useSecureWebSocket: boolean;
forceDisablePgSSL: boolean;
Expand Down Expand Up @@ -530,6 +530,18 @@ export { types }

declare function u8FromHex(hex: string): Uint8Array<ArrayBuffer>;

declare interface WebSocketConstructor {
new (...args: any[]): WebSocketLike;
}

declare interface WebSocketLike {
readonly readyState: number;
binaryType: string;
close(code?: number, reason?: string): void;
send(data: any): void;
addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (this: WebSocketLike, ev: any) => any, options?: any): void;
}

declare class WebSocketReadQueue extends ReadQueue {
private socket;
constructor(socket: WebSocket);
Expand Down
Loading

0 comments on commit afbca19

Please sign in to comment.