mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
make service interfaces and hosts one to one
This commit is contained in:
@@ -55,7 +55,7 @@ type AddSslOptions = {
|
||||
addXForwardedHeaders?: boolean /** default: false */
|
||||
}
|
||||
type Security = { secure: false; ssl: false } | { secure: true; ssl: boolean }
|
||||
export type PortOptions = {
|
||||
export type BindOptions = {
|
||||
scheme: Scheme
|
||||
preferredExternalPort: number
|
||||
addSsl: AddSslOptions | null
|
||||
@@ -85,7 +85,7 @@ type PortOptionsByKnownProtocol =
|
||||
scheme?: Scheme
|
||||
addSsl?: AddSslOptions | null
|
||||
}
|
||||
type PortOptionsByProtocol = PortOptionsByKnownProtocol | PortOptions
|
||||
type PortOptionsByProtocol = PortOptionsByKnownProtocol | BindOptions
|
||||
|
||||
export type HostKind = "static" | "single" | "multi"
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Address } from "../types"
|
||||
import { Host, PortOptions } from "./Host"
|
||||
import { AddressInfo } from "../types"
|
||||
import { Host, BindOptions } from "./Host"
|
||||
|
||||
export class Origin<T extends Host> {
|
||||
constructor(
|
||||
readonly host: T,
|
||||
readonly options: PortOptions,
|
||||
readonly options: BindOptions,
|
||||
) {}
|
||||
|
||||
build({ username, path, search }: BuildOptions): Address {
|
||||
build({ username, path, search }: BuildOptions): AddressInfo {
|
||||
const qpEntries = Object.entries(search)
|
||||
.map(
|
||||
([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Address, Effects } from "../types"
|
||||
import { NetworkInterfaceType } from "../util/utils"
|
||||
import { AddressInfo, Effects } from "../types"
|
||||
import { ServiceInterfaceType } from "../util/utils"
|
||||
import { AddressReceipt } from "./AddressReceipt"
|
||||
import { Host } from "./Host"
|
||||
import { Origin } from "./Origin"
|
||||
@@ -15,7 +15,7 @@ import { Origin } from "./Origin"
|
||||
* @param options
|
||||
* @returns
|
||||
*/
|
||||
export class NetworkInterfaceBuilder {
|
||||
export class ServiceInterfaceBuilder {
|
||||
constructor(
|
||||
readonly options: {
|
||||
effects: Effects
|
||||
@@ -24,7 +24,7 @@ export class NetworkInterfaceBuilder {
|
||||
description: string
|
||||
hasPrimary: boolean
|
||||
disabled: boolean
|
||||
type: NetworkInterfaceType
|
||||
type: ServiceInterfaceType
|
||||
username: null | string
|
||||
path: string
|
||||
search: Record<string, string>
|
||||
@@ -36,12 +36,12 @@ export class NetworkInterfaceBuilder {
|
||||
*
|
||||
* The returned addressReceipt serves as proof that the addresses were registered
|
||||
*
|
||||
* @param addresses
|
||||
* @param addressInfo
|
||||
* @returns
|
||||
*/
|
||||
async export<Origins extends Origin<Host>[]>(
|
||||
origins: Origins,
|
||||
): Promise<Address[] & AddressReceipt> {
|
||||
async export<OriginForHost extends Origin<Host>>(
|
||||
origin: OriginForHost,
|
||||
): Promise<AddressInfo & AddressReceipt> {
|
||||
const {
|
||||
name,
|
||||
description,
|
||||
@@ -54,20 +54,18 @@ export class NetworkInterfaceBuilder {
|
||||
search,
|
||||
} = this.options
|
||||
|
||||
const addresses = Array.from(origins).map((o) =>
|
||||
o.build({ username, path, search, scheme: null }),
|
||||
)
|
||||
const addressInfo = origin.build({ username, path, search, scheme: null })
|
||||
|
||||
await this.options.effects.exportNetworkInterface({
|
||||
interfaceId: id,
|
||||
await this.options.effects.exportServiceInterface({
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
hasPrimary,
|
||||
disabled,
|
||||
addresses,
|
||||
addressInfo,
|
||||
type,
|
||||
})
|
||||
|
||||
return addresses as Address[] & AddressReceipt
|
||||
return addressInfo as AddressInfo & AddressReceipt
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Config } from "../config/builder/config"
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import { Address, Effects } from "../types"
|
||||
import { AddressInfo, Effects } from "../types"
|
||||
import { Utils } from "../util/utils"
|
||||
import { AddressReceipt } from "./AddressReceipt"
|
||||
|
||||
export type InterfacesReceipt = Array<Address[] & AddressReceipt>
|
||||
export type InterfacesReceipt = Array<AddressInfo[] & AddressReceipt>
|
||||
export type SetInterfaces<
|
||||
Manifest extends SDKManifest,
|
||||
Store,
|
||||
|
||||
Reference in New Issue
Block a user