@grlt-hub/app-compose
Version:
<p align="center"> <a href="https://grlt-hub.github.io/app-compose/"> <img src="https://github.com/user-attachments/assets/b9f87cf8-5af1-410b-8125-28689e668d47" height="150"> </a> </p> <h1 align="center"> App Compose </h1> <p align="center"> Compose modul
136 lines • 4 kB
TypeScript
//#region src/shared.d.ts
type AnyRecord = Record<string, unknown>;
type Eventual<T> = Promise<T> | T;
type NonEmptyArray<T = unknown> = [T, ...T[]];
type ReadonlyNonEmptyArray<T> = readonly [T, ...(readonly T[])];
//#endregion
//#region src/spot/spot.d.ts
declare const Spot$: unique symbol;
declare const Kind$: unique symbol;
declare const Optional$: unique symbol;
type Spot<T> = {
[Spot$]?: T;
};
type SpotKind<T> = {
[Kind$]: T;
};
type SpotOptional = {
[Optional$]: boolean;
};
//#endregion
//#region src/spot/context.d.ts
type KeyValue = Record<string, unknown> | Record<number, unknown>;
type SpotContext<T> = T extends KeyValue ? Spot<T> | SpotContextRecord<T> : Spot<T>;
type SpotContextRecord<T extends KeyValue> = { [Key in keyof T]: SpotContext<T[Key]> };
//#endregion
//#region src/spot/lens.d.ts
declare const RefID$: unique symbol;
declare const RefPath$: unique symbol;
type Lensable = {
[RefID$]: symbol;
[RefPath$]: string[];
};
//#endregion
//#region src/spot/literal.d.ts
declare const Literal$: unique symbol;
type Literal<T> = Spot<T> & SpotKind<"literal"> & {
[Literal$]: T;
};
declare const literal: <const T>(value: T) => Literal<T>;
//#endregion
//#region src/spot/modifier.d.ts
declare const optional: <T>(spot: Spot<T> & SpotOptional) => Spot<T | undefined>;
//#endregion
//#region src/spot/reference.d.ts
type Reference<T> = Spot<T> & SpotKind<"reference"> & SpotOptional & Lensable;
type ReferenceProvider<T> = T extends AnyRecord ? { [Key in keyof T]: ReferenceProvider<T[Key]> } & Reference<T> : Reference<T>;
//#endregion
//#region src/task/create.d.ts
declare const Task$: unique symbol;
type ContextOfRunner<Context> = Context extends void ? void : SpotContext<Context>;
type TaskInternal = {
id: {
value: symbol;
status: symbol;
};
run: (ctx: any) => Eventual<unknown>;
enabled?: (ctx: any) => Eventual<boolean>;
context: unknown;
};
type Task<Api$1> = ReferenceProvider<Api$1> & {
[Task$]: TaskInternal;
};
type AnyTask = Task<unknown>;
type TaskConfig<Context, Api$1> = {
id?: string;
run: {
fn: (ctx: Context) => Eventual<Api$1>;
} & (Context extends void ? {
context?: never;
} : {
context: ContextOfRunner<Context>;
});
enabled?: (ctx: Context) => Eventual<boolean>;
};
type TaskResult<T> = T extends Task<infer Api> ? Api : never;
declare const createTask: <Context = void, Api$1 = unknown>(config: TaskConfig<Context, Api$1>) => Task<Api$1>;
//#endregion
//#region src/task/status.d.ts
type TaskStatus = {
name: "done";
} | {
name: "skip";
} | {
name: "fail";
error: unknown;
};
declare const status: (task: Task<unknown>) => ReferenceProvider<TaskStatus>;
//#endregion
//#region src/tag/create.d.ts
declare const Tag$: unique symbol;
type Tag = {
[Tag$]: true;
};
type TagConfig = {
id?: string;
};
declare const createTag: <T = never>(config?: TagConfig) => ReferenceProvider<T> & Tag;
//#endregion
//#region src/tag/bind.d.ts
declare const Binding$: unique symbol;
type BindingInternal = {
id: symbol;
value: unknown;
};
type Binding = {
[Binding$]: BindingInternal;
};
declare const bind: <T>(tag: Tag & Reference<T>, value: SpotContext<T>) => Binding;
//#endregion
//#region src/compose/types.d.ts
type Stage = NonEmptyArray<AnyTask> | NonEmptyArray<Binding> | ReadonlyNonEmptyArray<AnyTask> | ReadonlyNonEmptyArray<Binding>;
//#endregion
//#region src/compose/logger.d.ts
type ContainerLogger = {
onTaskFail?: (event: {
id: symbol;
error: unknown;
}) => void;
};
//#endregion
//#region src/compose/index.d.ts
type ComposeConfig = {
log?: ContainerLogger;
};
type Container = {
get: <T>(task: Task<T>) => T | undefined;
};
type Composer = {
stage: (...stage: Stage[]) => Composer;
run: () => Promise<Container>;
guard: () => never;
};
declare const compose: (config?: ComposeConfig) => Composer;
//#endregion
export { type TaskResult, type TaskStatus, bind, compose, createTag, createTask, literal, optional, status };
//# sourceMappingURL=index.d.ts.map