mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
chore: Make some things lazy
This commit is contained in:
@@ -3,14 +3,16 @@ import { ActionMetaData } from "../types"
|
|||||||
import { CreatedAction } from "./createAction"
|
import { CreatedAction } from "./createAction"
|
||||||
|
|
||||||
export function setupActions(...createdActions: CreatedAction<any, any>[]) {
|
export function setupActions(...createdActions: CreatedAction<any, any>[]) {
|
||||||
const actions: Record<string, ExportedAction> = {}
|
|
||||||
for (const action of createdActions) {
|
|
||||||
actions[action.metaData.id] = action.exportedAction
|
|
||||||
}
|
|
||||||
|
|
||||||
const actionsMetadata = createdActions.map((x) => x.metaData)
|
|
||||||
return {
|
return {
|
||||||
actions,
|
get actions() {
|
||||||
actionsMetadata,
|
const actions: Record<string, ExportedAction> = {}
|
||||||
|
for (const action of createdActions) {
|
||||||
|
actions[action.metaData.id] = action.exportedAction
|
||||||
|
}
|
||||||
|
return actions
|
||||||
|
},
|
||||||
|
get actionsMetadata() {
|
||||||
|
return createdActions.map((x) => x.metaData)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,20 @@ export const ipv6 = once(
|
|||||||
export class LocalBinding {
|
export class LocalBinding {
|
||||||
constructor(readonly localHost: string, readonly ipHosts: string[]) {}
|
constructor(readonly localHost: string, readonly ipHosts: string[]) {}
|
||||||
createOrigins(protocol: string) {
|
createOrigins(protocol: string) {
|
||||||
|
const ipHosts = this.ipHosts
|
||||||
return {
|
return {
|
||||||
local: new Origin(protocol, this.localHost),
|
local: new Origin(protocol, this.localHost),
|
||||||
ip: this.ipHosts.map((x) => new Origin(protocol, x)),
|
get ip() {
|
||||||
ipv4: this.ipHosts
|
return ipHosts.map((x) => new Origin(protocol, x))
|
||||||
.filter(regexToTestIp4().test)
|
},
|
||||||
.map((x) => new Origin(protocol, x)),
|
get ipv4() {
|
||||||
ipv6: this.ipHosts
|
return ipHosts
|
||||||
.filter(ipv6().test)
|
.filter(regexToTestIp4().test)
|
||||||
.map((x) => new Origin(protocol, x)),
|
.map((x) => new Origin(protocol, x))
|
||||||
|
},
|
||||||
|
get ipv6() {
|
||||||
|
return ipHosts.filter(ipv6().test).map((x) => new Origin(protocol, x))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user