mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
feat: get system smtp in utils
This commit is contained in:
40
lib/util/GetSystemSmtp.ts
Normal file
40
lib/util/GetSystemSmtp.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Parser } from "ts-matches"
|
||||
import { Effects, EnsureWrapperDataPath, ExtractWrapperData } from "../types"
|
||||
import { NoAny } from "."
|
||||
|
||||
export class GetSystemSmtp {
|
||||
constructor(readonly effects: Effects) {}
|
||||
|
||||
/** This should be used as the primary method in main since it allows the main to
|
||||
* restart if the wrapper data changes
|
||||
*/
|
||||
const() {
|
||||
return this.effects.getSystemSmtp({
|
||||
callback: this.effects.restart,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Returns the wrapper data once and then never again
|
||||
* Doesn't restart the server when the wrapper data changes
|
||||
*/
|
||||
once() {
|
||||
return this.effects.getSystemSmtp({
|
||||
callback: () => {},
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Keeps giving the latest wrapper data as it changes
|
||||
*/
|
||||
async *watch() {
|
||||
while (true) {
|
||||
let callback: () => void
|
||||
const waitForNext = new Promise<void>((resolve) => {
|
||||
callback = resolve
|
||||
})
|
||||
yield await this.effects.getSystemSmtp({
|
||||
callback: () => callback(),
|
||||
})
|
||||
await waitForNext
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "../health/checkFns"
|
||||
import { LocalBinding, LocalPort, NetworkBuilder, TorHostname } from "../mainFn"
|
||||
import { ExtractWrapperData } from "../types"
|
||||
import { GetSystemSmtp } from "./GetSystemSmtp"
|
||||
|
||||
export { default as nullIfEmpty } from "./nullIfEmpty"
|
||||
export { FileHelper } from "./fileHelper"
|
||||
@@ -59,6 +60,7 @@ export type Utils<WD, WrapperOverWrite = { const: never }> = {
|
||||
fileHelper: FileHelper<A>,
|
||||
data: A,
|
||||
) => ReturnType<FileHelper<A>["write"]>
|
||||
getSystemSmtp: () => GetSystemSmtp & WrapperOverWrite
|
||||
getWrapperData: <Path extends string>(
|
||||
packageId: string,
|
||||
path: T.EnsureWrapperDataPath<WD, Path>,
|
||||
@@ -96,6 +98,8 @@ export type Utils<WD, WrapperOverWrite = { const: never }> = {
|
||||
export const utils = <WrapperData = never, WrapperOverWrite = { const: never }>(
|
||||
effects: T.Effects,
|
||||
): Utils<WrapperData, WrapperOverWrite> => ({
|
||||
getSystemSmtp: () =>
|
||||
new GetSystemSmtp(effects) as GetSystemSmtp & WrapperOverWrite,
|
||||
readFile: <A>(fileHelper: FileHelper<A>) => fileHelper.read(effects),
|
||||
writeFile: <A>(fileHelper: FileHelper<A>, data: A) =>
|
||||
fileHelper.write(data, effects),
|
||||
|
||||
Reference in New Issue
Block a user