Skip to content

Commit

Permalink
fix: with command type (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimee authored Sep 26, 2024
1 parent 1b405be commit abf0df2
Showing 1 changed file with 102 additions and 79 deletions.
181 changes: 102 additions & 79 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -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?: <T, TReturn>(dependencies: T) => TReturn;
/** @deprecated use packages instead */
map?: <T, TReturn>(dependencies: T) => TReturn;
}

export interface PlanEntry<T = any> {
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>(): T;
static execute<T>(
plan: PlanDefinition,
context: Context,
verbose?: boolean
): T;
static applyEntry(entry: PlanEntry, context: Plan);

replace<T>(relativePath: string, value: T, options?: EntryOptions): Plan;

addPackage(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan;
addStep(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan;
addValue<T>(name: string, value: T, options?: EntryOptions): Plan;
addAlias(name: string, aliasOf: string, options?: EntryOptions): Plan;
addNumber(name: string, value: number, options?: NumberEntryOptions): Plan;
addInstance<T>(name: string, value: T, options?: EntryOptions): Plan;
addFunction<T extends Function>(
name: string,
value: T,
options?: EntryOptions
): Plan;
addUsingClass<T>(
name: string,
value: (new (...args: any[]) => T) | (() => new (...args: any[]) => T),
options?: ClassEntryOptions
): Plan;
/** @deprecated use addUsingClass instead */
addClass<T>(Class: new (...args: any[]) => T, options?: EntryOptions): Plan;
addUsingFunction<T>(
name: string,
factoryFunction: (...args: any[]) => T,
option?: EntryOptions
): Plan;
addUsingFunctionStack(
name: string,
factoryFunctionList: Array<(...args: any[]) => any>,
options?: EntryOptions
): Plan;
addModule<T>(name: string, module: () => T, options?: EntryOptions): Plan;
addAllKeysFrom(object: Record<string, any>, options?: EntryOptions): Plan;
with<T>(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>(): T;

static execute<T>(
plan: PlanDefinition,
context: Context,
verbose?: boolean
): T;

static applyEntry(entry: PlanEntry, context: Plan);

replace<T>(relativePath: string, value: T, options?: EntryOptions): Plan;

addPackage(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan;

addStep(name: string, item: PlanDefinition, options?: PackageEntryOptions): Plan;

addValue<T>(name: string, value: T, options?: EntryOptions): Plan;

addAlias(name: string, aliasOf: string, options?: EntryOptions): Plan;

addNumber(name: string, value: number, options?: NumberEntryOptions): Plan;

addInstance<T>(name: string, value: T, options?: EntryOptions): Plan;

addFunction<T extends Function>(
name: string,
value: T,
options?: EntryOptions
): Plan;

addUsingClass<T>(
name: string,
value: (new (...args: any[]) => T) | (() => new (...args: any[]) => T),
options?: ClassEntryOptions
): Plan;

/** @deprecated use addUsingClass instead */
addClass<T>(Class: new (...args: any[]) => T, options?: EntryOptions): Plan;

addUsingFunction<T>(
name: string,
factoryFunction: (...args: any[]) => T,
option?: EntryOptions
): Plan;

addUsingFunctionStack(
name: string,
factoryFunctionList: Array<(...args: any[]) => any>,
options?: EntryOptions
): Plan;

addModule<T>(name: string, module: () => T, options?: EntryOptions): Plan;

addAllKeysFrom(object: Record<string, any>, options?: EntryOptions): Plan;

with<T>(name: string | string [], work: (entry: T) => void, options?: EntryOptions): Plan;

addMetadataHook(hook): Plan;
}

export type PlanFactory = (plan: Plan) => Plan;
Expand All @@ -101,12 +122,14 @@ export type PlanDefinition = Plan | PlanFactory | Array<Plan | PlanFactory | Pla

/** @deprecated use "execute" function instead to avoid singleton creation. */
export function init(item: PlanDefinition, verbose?: boolean): void;

/** @deprecated prefer adding the component in the context */
export function inject<T>(): T;

export function execute<T>(
plan: PlanDefinition,
context?: Context,
verbose?: boolean
plan: PlanDefinition,
context?: Context,
verbose?: boolean
): T;

export type AssertPresent = (dependencies: Record<string, unknown>) => void

0 comments on commit abf0df2

Please sign in to comment.