mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
fix export interface stuff
This commit is contained in:
@@ -21,9 +21,9 @@ export class NetworkInterfaceBuilder {
|
|||||||
id: string
|
id: string
|
||||||
description: string
|
description: string
|
||||||
ui: boolean
|
ui: boolean
|
||||||
basic?: null | { password: null | string; username: string }
|
basic: null | { password: null | string; username: string }
|
||||||
path?: string
|
path: string
|
||||||
search?: Record<string, string>
|
search: Record<string, string>
|
||||||
},
|
},
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -35,20 +35,21 @@ export class NetworkInterfaceBuilder {
|
|||||||
* @param addresses
|
* @param addresses
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async exportAddresses(addresses: Iterable<Origin>) {
|
async export(origins: Iterable<Origin>) {
|
||||||
const { name, description, id, ui, path, search } = this.options
|
const { name, description, id, ui, basic, path, search } = this.options
|
||||||
for (const origin of addresses) {
|
|
||||||
const address = origin.withAuth(this.options.basic)
|
const addresses = Array.from(origins).map((o) =>
|
||||||
await this.options.effects.exportAddress({
|
o.build({ basic, path, search }),
|
||||||
name,
|
)
|
||||||
description,
|
|
||||||
address,
|
await this.options.effects.exportNetworkInterface({
|
||||||
id,
|
id,
|
||||||
ui,
|
name,
|
||||||
path,
|
description,
|
||||||
search,
|
addresses,
|
||||||
})
|
ui,
|
||||||
}
|
})
|
||||||
|
|
||||||
return {} as AddressReceipt
|
return {} as AddressReceipt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,26 @@
|
|||||||
export class Origin {
|
export class Origin {
|
||||||
constructor(readonly protocol: string | null, readonly host: string) {}
|
constructor(readonly protocol: string | null, readonly host: string) {}
|
||||||
|
|
||||||
withAuth(
|
build({ basic, path, search }: BuildOptions) {
|
||||||
origin?:
|
|
||||||
| {
|
|
||||||
password: null | string
|
|
||||||
username: string
|
|
||||||
}
|
|
||||||
| null
|
|
||||||
| undefined,
|
|
||||||
) {
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const urlAuth = !!(origin) ? `${origin.username}${origin.password != null ?`:${origin.password}`:''}@` :
|
const urlAuth = !!(basic) ? `${basic.username}${basic.password != null ?`:${basic.password}`:''}@` :
|
||||||
'';
|
'';
|
||||||
const protocolSection = this.protocol != null ? `${this.protocol}://` : ""
|
const protocolSection = this.protocol != null ? `${this.protocol}://` : ""
|
||||||
return `${protocolSection}${urlAuth}${this.host}`
|
|
||||||
|
const qpEntries = Object.entries(search)
|
||||||
|
.map(
|
||||||
|
([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`,
|
||||||
|
)
|
||||||
|
.join("&")
|
||||||
|
|
||||||
|
const qp = qpEntries.length ? `?${qpEntries}` : ""
|
||||||
|
|
||||||
|
return `${protocolSection}${urlAuth}${this.host}${path}${qp}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BuildOptions = {
|
||||||
|
basic: { username: string; password: string | null } | null
|
||||||
|
path: string
|
||||||
|
search: Record<string, string>
|
||||||
|
}
|
||||||
|
|||||||
@@ -541,8 +541,6 @@ describe("values", () => {
|
|||||||
Test,
|
Test,
|
||||||
| { unionSelectKey: "a"; unionValueKey: { b: boolean } }
|
| { unionSelectKey: "a"; unionValueKey: { b: boolean } }
|
||||||
| { unionSelectKey: "b"; unionValueKey: { b: boolean } }
|
| { unionSelectKey: "b"; unionValueKey: { b: boolean } }
|
||||||
| null
|
|
||||||
| undefined
|
|
||||||
>()(null)
|
>()(null)
|
||||||
|
|
||||||
const built = await value.build({} as any)
|
const built = await value.build({} as any)
|
||||||
|
|||||||
30
lib/types.ts
30
lib/types.ts
@@ -165,30 +165,18 @@ export type ActionMetaData = {
|
|||||||
group?: string
|
group?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddressType = {
|
export type NetworkInterface = {
|
||||||
|
id: string
|
||||||
/** The title of this field to be dsimplayed */
|
/** The title of this field to be dsimplayed */
|
||||||
name: string
|
name: string
|
||||||
/** Human readable description, used as tooltip usually */
|
/** Human readable description, used as tooltip usually */
|
||||||
description: string
|
description: string
|
||||||
/** URI location */
|
/** All URIs */
|
||||||
address: string
|
addresses: string[]
|
||||||
id: string
|
|
||||||
/** Defaults to false, but describes if this address can be opened in a browser as an
|
/** Defaults to false, but describes if this address can be opened in a browser as an
|
||||||
* ui interface
|
* ui interface
|
||||||
*/
|
*/
|
||||||
ui?: boolean
|
ui?: boolean
|
||||||
/**
|
|
||||||
* The id is that a path will create a link in the ui that can go to specific pages, like
|
|
||||||
* admin, or settings, or something like that.
|
|
||||||
* Default = ''
|
|
||||||
*/
|
|
||||||
path?: string
|
|
||||||
/**
|
|
||||||
* This is the query params in the url, and is a map of key value pairs
|
|
||||||
* Default = {}
|
|
||||||
* if empty then will not be added to the url
|
|
||||||
*/
|
|
||||||
search?: Record<string, string>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used to reach out from the pure js runtime */
|
/** Used to reach out from the pure js runtime */
|
||||||
@@ -376,7 +364,7 @@ export type Effects = {
|
|||||||
/** When we want to create a link in the front end interfaces, and example is
|
/** When we want to create a link in the front end interfaces, and example is
|
||||||
* exposing a url to view a web service
|
* exposing a url to view a web service
|
||||||
*/
|
*/
|
||||||
exportAddress(options: AddressType): Promise<string>
|
exportNetworkInterface(options: NetworkInterface): Promise<string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There are times that we want to see the addresses that where exported
|
* There are times that we want to see the addresses that where exported
|
||||||
@@ -384,10 +372,10 @@ export type Effects = {
|
|||||||
*
|
*
|
||||||
* Note: any auth should be filtered out already
|
* Note: any auth should be filtered out already
|
||||||
*/
|
*/
|
||||||
getAddresses(options: {
|
getInterface(options: {
|
||||||
id?: PackageId
|
serviceId?: PackageId
|
||||||
addressId?: string
|
interfaceId?: string
|
||||||
}): Promise<AddressType>
|
}): Promise<NetworkInterface>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Remove an address that was exported. Used problably during main or during setConfig.
|
*Remove an address that was exported. Used problably during main or during setConfig.
|
||||||
|
|||||||
Reference in New Issue
Block a user