mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
fix export interface stuff
This commit is contained in:
@@ -21,9 +21,9 @@ export class NetworkInterfaceBuilder {
|
||||
id: string
|
||||
description: string
|
||||
ui: boolean
|
||||
basic?: null | { password: null | string; username: string }
|
||||
path?: string
|
||||
search?: Record<string, string>
|
||||
basic: null | { password: null | string; username: string }
|
||||
path: string
|
||||
search: Record<string, string>
|
||||
},
|
||||
) {}
|
||||
|
||||
@@ -35,20 +35,21 @@ export class NetworkInterfaceBuilder {
|
||||
* @param addresses
|
||||
* @returns
|
||||
*/
|
||||
async exportAddresses(addresses: Iterable<Origin>) {
|
||||
const { name, description, id, ui, path, search } = this.options
|
||||
for (const origin of addresses) {
|
||||
const address = origin.withAuth(this.options.basic)
|
||||
await this.options.effects.exportAddress({
|
||||
name,
|
||||
description,
|
||||
address,
|
||||
id,
|
||||
ui,
|
||||
path,
|
||||
search,
|
||||
})
|
||||
}
|
||||
async export(origins: Iterable<Origin>) {
|
||||
const { name, description, id, ui, basic, path, search } = this.options
|
||||
|
||||
const addresses = Array.from(origins).map((o) =>
|
||||
o.build({ basic, path, search }),
|
||||
)
|
||||
|
||||
await this.options.effects.exportNetworkInterface({
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
addresses,
|
||||
ui,
|
||||
})
|
||||
|
||||
return {} as AddressReceipt
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
export class Origin {
|
||||
constructor(readonly protocol: string | null, readonly host: string) {}
|
||||
|
||||
withAuth(
|
||||
origin?:
|
||||
| {
|
||||
password: null | string
|
||||
username: string
|
||||
}
|
||||
| null
|
||||
| undefined,
|
||||
) {
|
||||
build({ basic, path, search }: BuildOptions) {
|
||||
// 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}://` : ""
|
||||
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,
|
||||
| { unionSelectKey: "a"; unionValueKey: { b: boolean } }
|
||||
| { unionSelectKey: "b"; unionValueKey: { b: boolean } }
|
||||
| null
|
||||
| undefined
|
||||
>()(null)
|
||||
|
||||
const built = await value.build({} as any)
|
||||
|
||||
30
lib/types.ts
30
lib/types.ts
@@ -165,30 +165,18 @@ export type ActionMetaData = {
|
||||
group?: string
|
||||
}
|
||||
|
||||
export type AddressType = {
|
||||
export type NetworkInterface = {
|
||||
id: string
|
||||
/** The title of this field to be dsimplayed */
|
||||
name: string
|
||||
/** Human readable description, used as tooltip usually */
|
||||
description: string
|
||||
/** URI location */
|
||||
address: string
|
||||
id: string
|
||||
/** All URIs */
|
||||
addresses: string[]
|
||||
/** Defaults to false, but describes if this address can be opened in a browser as an
|
||||
* ui interface
|
||||
*/
|
||||
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 */
|
||||
@@ -376,7 +364,7 @@ export type Effects = {
|
||||
/** When we want to create a link in the front end interfaces, and example is
|
||||
* 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
|
||||
@@ -384,10 +372,10 @@ export type Effects = {
|
||||
*
|
||||
* Note: any auth should be filtered out already
|
||||
*/
|
||||
getAddresses(options: {
|
||||
id?: PackageId
|
||||
addressId?: string
|
||||
}): Promise<AddressType>
|
||||
getInterface(options: {
|
||||
serviceId?: PackageId
|
||||
interfaceId?: string
|
||||
}): Promise<NetworkInterface>
|
||||
|
||||
/**
|
||||
*Remove an address that was exported. Used problably during main or during setConfig.
|
||||
|
||||
Reference in New Issue
Block a user