From c9484418ff89c26dc0b4b342d60bfb313d43648f Mon Sep 17 00:00:00 2001 From: Blu-J Date: Wed, 2 Aug 2023 12:26:07 -0600 Subject: [PATCH] feat: Update the type of the network interface to type --- lib/interfaces/NetworkInterfaceBuilder.ts | 7 ++++--- lib/test/host.test.ts | 2 +- lib/types.ts | 8 ++++---- lib/util/getNetworkInterface.ts | 8 ++++---- lib/util/utils.ts | 6 ++++-- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/interfaces/NetworkInterfaceBuilder.ts b/lib/interfaces/NetworkInterfaceBuilder.ts index ff9e430..8f47dea 100644 --- a/lib/interfaces/NetworkInterfaceBuilder.ts +++ b/lib/interfaces/NetworkInterfaceBuilder.ts @@ -1,4 +1,5 @@ import { Address, Effects } from "../types" +import { NetworkInterfaceType } from "../util/utils" import { AddressReceipt } from "./AddressReceipt" import { Host } from "./Host" import { Origin } from "./Origin" @@ -23,7 +24,7 @@ export class NetworkInterfaceBuilder { description: string hasPrimary: boolean disabled: boolean - ui: boolean + type: NetworkInterfaceType username: null | string path: string search: Record @@ -47,7 +48,7 @@ export class NetworkInterfaceBuilder { hasPrimary, disabled, id, - ui, + type, username, path, search, @@ -64,7 +65,7 @@ export class NetworkInterfaceBuilder { hasPrimary, disabled, addresses, - ui, + type, }) return addresses as Address[] & AddressReceipt diff --git a/lib/test/host.test.ts b/lib/test/host.test.ts index 559c4cc..01ce6f3 100644 --- a/lib/test/host.test.ts +++ b/lib/test/host.test.ts @@ -15,7 +15,7 @@ describe("host", () => { description: "A Foo", hasPrimary: false, disabled: false, - ui: true, + type: "ui", username: "bar", path: "/baz", search: { qux: "yes" }, diff --git a/lib/types.ts b/lib/types.ts index 285f7cb..066039c 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -3,6 +3,7 @@ import { InputSpec } from "./config/configTypes" import { DependenciesReceipt } from "./config/setupConfig" import { PortOptions } from "./interfaces/Host" import { UrlString } from "./util/getNetworkInterface" +import { NetworkInterfaceType } from "./util/utils" export type ExportedAction = (options: { effects: Effects @@ -186,10 +187,9 @@ export type NetworkInterface = { disabled: boolean /** All URIs */ addresses: Address[] - /** Defaults to false, but describes if this address can be opened in a browser as an - * ui interface - */ - ui: boolean + + /** The netowrk interface could be serveral types, something like ui, p2p, or network */ + type: NetworkInterfaceType } // prettier-ignore export type ExposeAllServicePaths = diff --git a/lib/util/getNetworkInterface.ts b/lib/util/getNetworkInterface.ts index e76b7f3..9e26c46 100644 --- a/lib/util/getNetworkInterface.ts +++ b/lib/util/getNetworkInterface.ts @@ -1,5 +1,6 @@ import { Address, Effects, HostName, NetworkInterface } from "../types" import * as regexes from "./regexes" +import { NetworkInterfaceType } from "./utils" export type UrlString = string export type HostId = string @@ -45,10 +46,9 @@ export type NetworkInterfaceFilled = { disabled: boolean /** All URIs */ addresses: FilledAddress[] - /** Defaults to false, but describes if this address can be opened in a browser as an - * ui interface - */ - ui: boolean + + /** Indicates if we are a ui/ p2p/ api/ other for the kind of interface that this is representing */ + type: NetworkInterfaceType primaryHostname: HostName | null primaryUrl: UrlString | null diff --git a/lib/util/utils.ts b/lib/util/utils.ts index d8b5e64..ccfcb6c 100644 --- a/lib/util/utils.ts +++ b/lib/util/utils.ts @@ -43,6 +43,8 @@ const childProcess = { execFile: promisify(CP.execFile), } +export type NetworkInterfaceType = "ui" | "p2p" | "api" | "other" + export type Utils = { checkPortListening( port: number, @@ -68,7 +70,7 @@ export type Utils = { description: string hasPrimary: boolean disabled: boolean - ui: boolean + type: NetworkInterfaceType username: null | string path: string search: Record @@ -128,7 +130,7 @@ export const utils = ( description: string hasPrimary: boolean disabled: boolean - ui: boolean + type: NetworkInterfaceType username: null | string path: string search: Record