import { c as Factory, o as Awaitable, t as ParesJsonOption } from "../parse-ChhDUw7P.mjs"; import { CommonSpawnOptions } from "node:child_process"; import { PathLike } from "node:fs"; //#region src/node/exec.d.ts interface ExecOptions extends Omit { /** * default is false */ collectOutput?: boolean; /** * if collectOutput is true, then this is true, otherwise, this is false */ silent?: boolean; /** * default is `process.env` */ env?: NodeJS.ProcessEnv; } /** * * @example * * ```ts * await run('echo "hello world" && echo cool things') // will print `hello world\ncool\nthings\n` * ``` */ declare function exec(cmd: string, opt?: ExecOptions): Promise; //#endregion //#region src/node/fs.d.ts declare function readText(path: PathLike): Promise; interface ReadJsonOption extends ParesJsonOption {} /** * @returns Undefined if parse failed */ declare function readJson(path: PathLike, opt?: ReadJsonOption): Promise; //#endregion //#region src/node/context.d.ts type ContextImplementSymbol = symbol; type ContextImplement = [ContextImplementSymbol, Value]; interface ContextInstance { name: string; /** * Get current context */ get(): T; /** * Implement the context * @param service */ impl(service: T): ContextImplement; } type ContextRunFn = (fn: () => T, serviceImplements?: ContextImplement[]) => T; interface BindContext { /** * Run with context implements */ run: ContextRunFn; /** Bind the context implementations in advance ```ts const bind = Context.bind(() => [CounterService.impl({ count: 1 })]) bind.run(() => { const c = CounterService.get() // c.count === 1 }) ``` */ bind: (serviceImplements?: Factory) => BindContext; } declare namespace Context { /** Create a context instance, then you can use the instance to get the context in async scope @param name Context name @param defaultImpl The default implement will applied if the `run` function not provide the implement @returns */ function create(name: string, defaultImpl?: Factory): ContextInstance; /** Execute a function by provide context implements, support async scope. @example ```ts interface CounterService { count: number } const CounterService = Context.create('counter') const main = () => { const c = CounterService.get() console.log(c.count) // => 1 setTimeout(() => { const c1 = CounterService.get() console.log(c1.count) // => 1 }, 100) } Context.run(main, [ CounterService.impl({ count: 1, }), ]) ``` @param fn @param serviceImplements @returns */ function run(fn: () => T, serviceImplements?: ContextImplement[]): T; /** Exit the current context @example ```ts Context.run(() => { const c = CounterService.get() // Works Context.exit(() => { const c = CounterService.get() // This will throw error, because current scope is not in the context scope }) const c1 = CounterService.get() // Works }) ``` */ function exit(fn: () => Awaitable): Awaitable; /** Bind the context implementations in advance ```ts const bind = Context.bind(() => [CounterService.impl({ count: 1 })]) bind.run(() => { const c = CounterService.get() // c.count === 1 }) ``` */ function bind(serviceImplements?: Factory): BindContext; } //#endregion export { BindContext, Context, ContextImplement, ContextImplementSymbol, ContextInstance, ContextRunFn, type ExecOptions, ReadJsonOption, exec, readJson, readText }; //# sourceMappingURL=index.d.mts.map