mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
feat: Create the setupInterfaces types
This commit is contained in:
29
lib/interfaces/Origin.ts
Normal file
29
lib/interfaces/Origin.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Address } from "../types"
|
||||
import { Host, PortOptions } from "./Host"
|
||||
|
||||
export class Origin<T extends Host> {
|
||||
constructor(readonly host: T, readonly options: PortOptions) {}
|
||||
|
||||
build({ username, path, search }: BuildOptions): Address {
|
||||
const qpEntries = Object.entries(search)
|
||||
.map(
|
||||
([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`,
|
||||
)
|
||||
.join("&")
|
||||
|
||||
const qp = qpEntries.length ? `?${qpEntries}` : ""
|
||||
|
||||
return {
|
||||
hostId: this.host.options.id,
|
||||
options: this.options,
|
||||
suffix: `${path}${qp}`,
|
||||
username,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type BuildOptions = {
|
||||
username: string | null
|
||||
path: string
|
||||
search: Record<string, string>
|
||||
}
|
||||
Reference in New Issue
Block a user