mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
Refactor/sdk init (#2947)
* fixes for main * refactor package initialization * fixes from testing * more fixes * beta.21 * do not use instanceof * closes #2921 * beta22 * allow disabling kiosk * migration * fix /etc/shadow * actionRequest -> task * beta.23
This commit is contained in:
@@ -10,46 +10,34 @@ export type UpdateServiceInterfacesReceipt = {
|
||||
export type ServiceInterfacesReceipt = Array<T.AddressInfo[] & AddressReceipt>
|
||||
export type SetServiceInterfaces<Output extends ServiceInterfacesReceipt> =
|
||||
(opts: { effects: T.Effects }) => Promise<Output>
|
||||
export type UpdateServiceInterfaces<Output extends ServiceInterfacesReceipt> =
|
||||
(opts: {
|
||||
effects: T.Effects
|
||||
}) => Promise<Output & UpdateServiceInterfacesReceipt>
|
||||
export type UpdateServiceInterfaces = (effects: T.Effects) => Promise<null>
|
||||
export type SetupServiceInterfaces = <Output extends ServiceInterfacesReceipt>(
|
||||
fn: SetServiceInterfaces<Output>,
|
||||
) => UpdateServiceInterfaces<Output>
|
||||
) => UpdateServiceInterfaces
|
||||
export const NO_INTERFACE_CHANGES = {} as UpdateServiceInterfacesReceipt
|
||||
export const setupServiceInterfaces: SetupServiceInterfaces = <
|
||||
Output extends ServiceInterfacesReceipt,
|
||||
>(
|
||||
fn: SetServiceInterfaces<Output>,
|
||||
) => {
|
||||
const cell = {
|
||||
updater: (async (options: { effects: T.Effects }) =>
|
||||
[] as any as Output) as UpdateServiceInterfaces<Output>,
|
||||
}
|
||||
cell.updater = (async (options: { effects: T.Effects }) => {
|
||||
const childEffects = options.effects.child("setupInterfaces")
|
||||
childEffects.constRetry = once(() => {
|
||||
cell.updater({ effects: options.effects })
|
||||
})
|
||||
return (async (effects: T.Effects) => {
|
||||
const bindings: T.BindId[] = []
|
||||
const interfaces: T.ServiceInterfaceId[] = []
|
||||
const res = await fn({
|
||||
await fn({
|
||||
effects: {
|
||||
...childEffects,
|
||||
...effects,
|
||||
bind: (params: T.BindParams) => {
|
||||
bindings.push({ id: params.id, internalPort: params.internalPort })
|
||||
return childEffects.bind(params)
|
||||
return effects.bind(params)
|
||||
},
|
||||
exportServiceInterface: (params: T.ExportServiceInterfaceParams) => {
|
||||
interfaces.push(params.id)
|
||||
return childEffects.exportServiceInterface(params)
|
||||
return effects.exportServiceInterface(params)
|
||||
},
|
||||
},
|
||||
})
|
||||
await options.effects.clearBindings({ except: bindings })
|
||||
await options.effects.clearServiceInterfaces({ except: interfaces })
|
||||
return res
|
||||
}) as UpdateServiceInterfaces<Output>
|
||||
return cell.updater
|
||||
await effects.clearBindings({ except: bindings })
|
||||
await effects.clearServiceInterfaces({ except: interfaces })
|
||||
return null
|
||||
}) as UpdateServiceInterfaces
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user