feat: add autoConfig/ better types for wrapperData

This commit is contained in:
BluJ
2023-04-19 17:23:16 -06:00
parent 7c4f94ba8f
commit e279711f8e
39 changed files with 431 additions and 291 deletions

View File

@@ -7,7 +7,7 @@ import { InterfaceReceipt } from "./interfaceReceipt";
type Daemon<
Ids extends string | never,
Command extends string,
Id extends string
Id extends string,
> = {
id: Id;
command: ValidIfNoStupidEscape<Command> | [string, ...string[]];
@@ -52,7 +52,7 @@ export class Daemons<Ids extends string | never> {
private constructor(
readonly effects: Effects,
readonly started: (onTerm: () => void) => null,
readonly daemons?: Daemon<Ids, "command", Ids>[]
readonly daemons?: Daemon<Ids, "command", Ids>[],
) {}
static of(config: {
@@ -64,7 +64,7 @@ export class Daemons<Ids extends string | never> {
return new Daemons<never>(config.effects, config.started);
}
addDaemon<Id extends string, Command extends string>(
newDaemon: Daemon<Ids, Command, Id>
newDaemon: Daemon<Ids, Command, Id>,
) {
const daemons = ((this?.daemons ?? []) as any[]).concat(newDaemon);
return new Daemons<Ids | Id>(this.effects, this.started, daemons);
@@ -76,7 +76,7 @@ export class Daemons<Ids extends string | never> {
const daemons = this.daemons ?? [];
for (const daemon of daemons) {
const requiredPromise = Promise.all(
daemon.requires?.map((id) => daemonsStarted[id]) ?? []
daemon.requires?.map((id) => daemonsStarted[id]) ?? [],
);
daemonsStarted[daemon.id] = requiredPromise.then(async () => {
const { command } = daemon;
@@ -100,15 +100,15 @@ export class Daemons<Ids extends string | never> {
async term() {
await Promise.all(
Object.values<Promise<DaemonReturned>>(daemonsStarted).map((x) =>
x.then((x) => x.term())
)
x.then((x) => x.term()),
),
);
},
async wait() {
await Promise.all(
Object.values<Promise<DaemonReturned>>(daemonsStarted).map((x) =>
x.then((x) => x.wait())
)
x.then((x) => x.wait()),
),
);
},
};

View File

@@ -13,7 +13,7 @@ export class NetworkInterfaceBuilder {
basic?: null | { password: string; username: string };
path?: string;
search?: Record<string, string>;
}
},
) {}
async exportAddresses(addresses: Iterable<Origin>) {

View File

@@ -8,7 +8,7 @@ export class Origin {
username: string;
}
| null
| undefined
| undefined,
) {
// prettier-ignore
const urlAuth = !!(origin) ? `${origin.username}:${origin.password}@` :

View File

@@ -25,7 +25,7 @@ export const runningMain: (
fn: (o: {
effects: Effects;
started(onTerm: () => void): null;
}) => Promise<Daemons<any>>
}) => Promise<Daemons<any>>,
) => ExpectedExports.main = (fn) => {
return async (options) => {
const result = await fn(options);