-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a bunch of explicit types on 'public' interface
- Loading branch information
Showing
7 changed files
with
85 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { map } from "https://deno.land/x/[email protected]/transforms/map.ts"; | ||
import { EOF, external } from "https://deno.land/x/[email protected]/sources/external.ts"; | ||
|
||
import { KubernetesTunnel, RequestOptions } from "../lib/contract.ts"; | ||
import { JSONValue, KubernetesTunnel, RequestOptions } from "../lib/contract.ts"; | ||
import { KubeConfigRestClient } from "../transports/via-kubeconfig.ts"; | ||
|
||
/** | ||
|
@@ -28,7 +28,12 @@ import { KubeConfigRestClient } from "../transports/via-kubeconfig.ts"; | |
* Upstream work: https://github.com/kubernetes/kubernetes/pull/119157 | ||
*/ | ||
export class WebsocketRestClient extends KubeConfigRestClient { | ||
async performRequest<Tproto extends string>(opts: RequestOptions & {expectTunnel?: Tproto[]}) { | ||
performRequest(opts: RequestOptions & {expectTunnel: string[]}): Promise<KubernetesTunnel>; | ||
performRequest(opts: RequestOptions & {expectStream: true; expectJson: true}): Promise<ReadableStream<JSONValue>>; | ||
performRequest(opts: RequestOptions & {expectStream: true}): Promise<ReadableStream<Uint8Array>>; | ||
performRequest(opts: RequestOptions & {expectJson: true}): Promise<JSONValue>; | ||
performRequest(opts: RequestOptions): Promise<Uint8Array>; | ||
async performRequest<Tproto extends string>(opts: RequestOptions & {expectTunnel?: Tproto[]}): Promise<unknown> { | ||
const requestedProtocols = opts.expectTunnel; | ||
if (!requestedProtocols) { | ||
return super.performRequest(opts); | ||
|
@@ -95,7 +100,7 @@ export class WebsocketTunnel implements KubernetesTunnel { | |
} | ||
}); | ||
} | ||
readonly transportProtocol = "WebSocket"; | ||
readonly transportProtocol: "WebSocket" = "WebSocket"; | ||
readonly subProtocol: string; | ||
readonly done: Promise<void>; | ||
|
||
|
@@ -107,7 +112,10 @@ export class WebsocketTunnel implements KubernetesTunnel { | |
streamIndex?: number | undefined; | ||
readable: Treadable; | ||
writable: Twritable; | ||
}) { | ||
}): Promise<{ | ||
writable: Twritable extends true ? WritableStream<Uint8Array> : null; | ||
readable: Treadable extends true ? ReadableStream<Uint8Array> : null; | ||
}> { | ||
const { streamIndex } = opts; | ||
if (typeof streamIndex !== 'number') { | ||
throw new Error("Cannot get a WebSocket channel without a streamIndex."); | ||
|
@@ -134,7 +142,7 @@ export class WebsocketTunnel implements KubernetesTunnel { | |
return Promise.resolve(); | ||
} | ||
|
||
stop() { | ||
stop(): Promise<void> { | ||
this.wss.close(); | ||
return Promise.resolve(); | ||
} | ||
|