diff --git a/src/index.d.ts b/src/index.d.ts index fa05d87..949d90d 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,98 +1,119 @@ export type PlanType = - | "replacement" - | "value" - | "number" - | "rawValue" - | "instance" - | "function" - | "class" - | "function*" - | "function**" - | "module" - | "work" - | "step-in" - | "step-out"; + | "replacement" + | "value" + | "number" + | "rawValue" + | "instance" + | "function" + | "class" + | "function*" + | "function**" + | "module" + | "work" + | "step-in" + | "step-out"; export interface EntryOptions { - private?: boolean; + private?: boolean; } export interface PackageEntryOptions extends EntryOptions { - if?: boolean | string; + if?: boolean | string; } export interface NumberEntryOptions extends EntryOptions { - min?: number; - max?: number; - default?: number; - nullable?: boolean; + min?: number; + max?: number; + default?: number; + nullable?: boolean; } export interface ClassEntryOptions extends EntryOptions { - /** @deprecated use packages instead */ - map?: (dependencies: T) => TReturn; + /** @deprecated use packages instead */ + map?: (dependencies: T) => TReturn; } export interface PlanEntry { - path: string; - type: PlanType; - name: string; - value: T; - options?: EntryOptions; + path: string; + type: PlanType; + name: string; + value: T; + options?: EntryOptions; } -declare class Context {} +declare class Context { +} declare class Plan { - constructor(entries: PlanEntry[], verbose?: boolean); - static newPlan(entries: PlanEntry[], verbose?: boolean): Plan; - static makeWriteFilesystem(basePath: string): (entries: PlanEntry[]) => void; - static makeDotWrite(basePath: string): (entries: PlanEntry[]) => void; - - static init(item: PlanDefinition, verbose?: boolean): void; - /** @deprecated avoid singleton and prefer use execute instead of init/inject */ - static inject(): T; - static execute( - plan: PlanDefinition, - context: Context, - verbose?: boolean - ): T; - static applyEntry(entry: PlanEntry, context: Plan); - - replace(relativePath: string, value: T, options?: EntryOptions): Plan; - - addPackage(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan; - addStep(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan; - addValue(name: string, value: T, options?: EntryOptions): Plan; - addAlias(name: string, aliasOf: string, options?: EntryOptions): Plan; - addNumber(name: string, value: number, options?: NumberEntryOptions): Plan; - addInstance(name: string, value: T, options?: EntryOptions): Plan; - addFunction( - name: string, - value: T, - options?: EntryOptions - ): Plan; - addUsingClass( - name: string, - value: (new (...args: any[]) => T) | (() => new (...args: any[]) => T), - options?: ClassEntryOptions - ): Plan; - /** @deprecated use addUsingClass instead */ - addClass(Class: new (...args: any[]) => T, options?: EntryOptions): Plan; - addUsingFunction( - name: string, - factoryFunction: (...args: any[]) => T, - option?: EntryOptions - ): Plan; - addUsingFunctionStack( - name: string, - factoryFunctionList: Array<(...args: any[]) => any>, - options?: EntryOptions - ): Plan; - addModule(name: string, module: () => T, options?: EntryOptions): Plan; - addAllKeysFrom(object: Record, options?: EntryOptions): Plan; - with(name: string, work: (entry: T) => void, options?: EntryOptions): Plan; - addMetadataHook(hook): Plan; + constructor(entries: PlanEntry[], verbose?: boolean); + + static newPlan(entries: PlanEntry[], verbose?: boolean): Plan; + + static makeWriteFilesystem(basePath: string): (entries: PlanEntry[]) => void; + + static makeDotWrite(basePath: string): (entries: PlanEntry[]) => void; + + static init(item: PlanDefinition, verbose?: boolean): void; + + /** @deprecated avoid singleton and prefer use execute instead of init/inject */ + static inject(): T; + + static execute( + plan: PlanDefinition, + context: Context, + verbose?: boolean + ): T; + + static applyEntry(entry: PlanEntry, context: Plan); + + replace(relativePath: string, value: T, options?: EntryOptions): Plan; + + addPackage(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan; + + addStep(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan; + + addValue(name: string, value: T, options?: EntryOptions): Plan; + + addAlias(name: string, aliasOf: string, options?: EntryOptions): Plan; + + addNumber(name: string, value: number, options?: NumberEntryOptions): Plan; + + addInstance(name: string, value: T, options?: EntryOptions): Plan; + + addFunction( + name: string, + value: T, + options?: EntryOptions + ): Plan; + + addUsingClass( + name: string, + value: (new (...args: any[]) => T) | (() => new (...args: any[]) => T), + options?: ClassEntryOptions + ): Plan; + + /** @deprecated use addUsingClass instead */ + addClass(Class: new (...args: any[]) => T, options?: EntryOptions): Plan; + + addUsingFunction( + name: string, + factoryFunction: (...args: any[]) => T, + option?: EntryOptions + ): Plan; + + addUsingFunctionStack( + name: string, + factoryFunctionList: Array<(...args: any[]) => any>, + options?: EntryOptions + ): Plan; + + addModule(name: string, module: () => T, options?: EntryOptions): Plan; + + addAllKeysFrom(object: Record, options?: EntryOptions): Plan; + + with(name: string | string [], work: (entry: T) => void, options?: EntryOptions): Plan; + + addMetadataHook(hook): Plan; } export type PlanFactory = (plan: Plan) => Plan; @@ -101,12 +122,14 @@ export type PlanDefinition = Plan | PlanFactory | Array(): T; + export function execute( - plan: PlanDefinition, - context?: Context, - verbose?: boolean + plan: PlanDefinition, + context?: Context, + verbose?: boolean ): T; export type AssertPresent = (dependencies: Record) => void