| import { WorkflowState } from "../interfaces"; | ||
| import { WorkflowStateRepository } from "../repository/interfaces"; | ||
| import { Graph } from "./renderGraph"; | ||
| import { WorkflowNode } from "./workflowNode"; | ||
| export declare class GraphWorkflow<Input, Output> { | ||
| #private; | ||
| constructor(params: { | ||
| id: string; | ||
| input: Input; | ||
| name: string; | ||
| repository: WorkflowStateRepository; | ||
| stepResults?: Map<string, unknown>; | ||
| }); | ||
| get state(): WorkflowState<Input>; | ||
| protected build(builder: (input: Input) => WorkflowNode<any, Output>): void; | ||
| execute(): Promise<Output | undefined>; | ||
| onChanges(handler: (event: { | ||
| step: string; | ||
| status: "IN_PROGRESS"; | ||
| } | { | ||
| step: string; | ||
| status: "DONE"; | ||
| } | { | ||
| step: string; | ||
| status: "FAILED"; | ||
| error: Error; | ||
| }) => void): void; | ||
| getGraph(): Graph; | ||
| get name(): string; | ||
| } | ||
| //# sourceMappingURL=graphWorkflow.d.ts.map |
| {"version":3,"file":"graphWorkflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/graph/graphWorkflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAkC,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBAAa,aAAa,CAAC,KAAK,EAAE,MAAM;;gBAW1B,MAAM,EAAE;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,uBAAuB,CAAC;QACpC,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC;IAeD,IAAI,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAEhC;IAED,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI;IAMrE,OAAO;IAuBb,SAAS,CACP,OAAO,EAAE,CACP,KAAK,EACD;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,GACvC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAChC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,KACjD,IAAI;IAMX,QAAQ,IAAI,KAAK;IAqBjB,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.GraphWorkflow = void 0; | ||
| const renderGraph_1 = require("./renderGraph"); | ||
| class GraphWorkflow { | ||
| #repository; | ||
| #rootNode; | ||
| #state; | ||
| #onChangesHandler; | ||
| constructor(params) { | ||
| const { id, name, input, repository, stepResults } = params; | ||
| this.#repository = repository; | ||
| this.#onChangesHandler = () => { }; | ||
| this.#state = { | ||
| id, | ||
| name, | ||
| input, | ||
| status: "TODO", | ||
| stepResults: stepResults ? stepResults : new Map(), | ||
| error: undefined, | ||
| }; | ||
| } | ||
| get state() { | ||
| return this.#state; | ||
| } | ||
| build(builder) { | ||
| this.#rootNode = builder(this.#state.input); | ||
| this.#rootNode.setContext(this.#state); | ||
| } | ||
| async execute() { | ||
| if (!this.#rootNode) { | ||
| return; | ||
| } | ||
| await this.#repository.save(this.#state); | ||
| const output = await this.#rootNode.execute(); | ||
| if (this.#state.status !== "FAILED") { | ||
| this.#state.status = "DONE"; | ||
| } | ||
| await this.#repository.save(this.#state); | ||
| // We do this after having saved the state. This way if the onChangesHandler throw we don't lose the state. | ||
| if (this.#state.status !== "FAILED") { | ||
| this.#onChangesHandler({ step: this.name, status: this.#state.status }); | ||
| } | ||
| return output; | ||
| } | ||
| onChanges(handler) { | ||
| this.#onChangesHandler = handler; | ||
| this.#rootNode?.onChanges(handler); | ||
| } | ||
| getGraph() { | ||
| const child = this.#rootNode?.getGraph(); | ||
| const childs = []; | ||
| if (child) { | ||
| childs.push(child); | ||
| } | ||
| return { | ||
| name: this.name, | ||
| status: this.#state.status, | ||
| childs, | ||
| toString: (opts) => (0, renderGraph_1.renderGraph)({ name: this.name, status: this.#state.status, childs }, opts), | ||
| }; | ||
| } | ||
| get name() { | ||
| return this.#state.name; | ||
| } | ||
| } | ||
| exports.GraphWorkflow = GraphWorkflow; | ||
| //# sourceMappingURL=graphWorkflow.js.map |
| {"version":3,"file":"graphWorkflow.js","sourceRoot":"","sources":["../../../src/workflows/graph/graphWorkflow.ts"],"names":[],"mappings":";;;AAEA,+CAAsE;AAGtE,MAAa,aAAa;IACxB,WAAW,CAA0B;IACrC,SAAS,CAAqC;IAC9C,MAAM,CAAuB;IAC7B,iBAAiB,CAKP;IAEV,YAAY,MAMX;QACC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,iBAAiB,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAElC,IAAI,CAAC,MAAM,GAAG;YACZ,EAAE;YACF,IAAI;YACJ,KAAK;YACL,MAAM,EAAE,MAAM;YACd,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,GAAG,EAAmB;YACnE,KAAK,EAAE,SAAS;SACjB,CAAC;IACJ,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAES,KAAK,CAAC,OAAoD;QAClE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE5C,IAAI,CAAC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1B,MAAM;YACN,QAAQ,EAAE,CAAC,IAAuB,EAAE,EAAE,CACpC,IAAA,yBAAW,EACT,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EACvD,IAAI,CACL;SACJ,CAAC;IACJ,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;CACF;AArGD,sCAqGC"} |
| export { GraphWorkflow } from "./graphWorkflow"; | ||
| export { WorkflowNode } from "./workflowNode"; | ||
| export { type RenderTreeOptions, type Graph } from "./renderGraph"; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/workflows/graph/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WorkflowNode = exports.GraphWorkflow = void 0; | ||
| var graphWorkflow_1 = require("./graphWorkflow"); | ||
| Object.defineProperty(exports, "GraphWorkflow", { enumerable: true, get: function () { return graphWorkflow_1.GraphWorkflow; } }); | ||
| var workflowNode_1 = require("./workflowNode"); | ||
| Object.defineProperty(exports, "WorkflowNode", { enumerable: true, get: function () { return workflowNode_1.WorkflowNode; } }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workflows/graph/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,+CAA8C;AAArC,4GAAA,YAAY,OAAA"} |
| import { WorkflowStatus } from "../interfaces"; | ||
| export type Graph = { | ||
| name: string; | ||
| childs: Graph[]; | ||
| status: WorkflowStatus; | ||
| toString(options?: RenderTreeOptions): string; | ||
| }; | ||
| type TreeStyle = "thin" | "heavy"; | ||
| export type RenderTreeOptions = { | ||
| indent?: number; | ||
| verticalSpace?: boolean; | ||
| style?: TreeStyle; | ||
| color?: boolean; | ||
| }; | ||
| export declare function renderGraph(graph: Graph, options?: RenderTreeOptions): string; | ||
| export {}; | ||
| //# sourceMappingURL=renderGraph.d.ts.map |
| {"version":3,"file":"renderGraph.d.ts","sourceRoot":"","sources":["../../../src/workflows/graph/renderGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC;CAC/C,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAElC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAwBF,wBAAgB,WAAW,CACzB,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,iBAAsB,GAC9B,MAAM,CASR"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.renderGraph = renderGraph; | ||
| const GLYPH_SETS = { | ||
| thin: { tee: "├", ell: "└", pipe: "│", dash: "─" }, | ||
| heavy: { tee: "┣", ell: "┗", pipe: "┃", dash: "━" }, | ||
| }; | ||
| const ANSI_RESET = "\x1b[0m"; | ||
| const ANSI_BY_STATUS = { | ||
| TODO: "\x1b[90m", // gray | ||
| IN_PROGRESS: "\x1b[38;5;208m", // orange (256-color) | ||
| DONE: "\x1b[32m", // green | ||
| FAILED: "\x1b[31m", // red | ||
| }; | ||
| function renderGraph(graph, options = {}) { | ||
| const resolved = { | ||
| indent: Math.max(2, options.indent ?? 4), | ||
| verticalSpace: options.verticalSpace ?? true, | ||
| glyphs: GLYPH_SETS[options.style ?? "thin"], | ||
| color: options.color ?? false, | ||
| }; | ||
| return renderTree(graph, "", true, true, resolved); | ||
| } | ||
| function renderTree(graph, prefix, isLast, isRoot, opts) { | ||
| const { indent, verticalSpace, glyphs } = opts; | ||
| const dashes = glyphs.dash.repeat(indent - 2); | ||
| const branch = isRoot | ||
| ? "" | ||
| : (isLast ? glyphs.ell : glyphs.tee) + dashes + " "; | ||
| const name = opts.color | ||
| ? `${ANSI_BY_STATUS[graph.status]}${graph.name}${ANSI_RESET}` | ||
| : graph.name; | ||
| const lines = [prefix + branch + name]; | ||
| const childPrefix = prefix + | ||
| (isRoot ? "" : (isLast ? " " : glyphs.pipe) + " ".repeat(indent - 1)); | ||
| graph.childs.forEach((child, i) => { | ||
| if (verticalSpace) { | ||
| lines.push(childPrefix + glyphs.pipe); | ||
| } | ||
| lines.push(renderTree(child, childPrefix, i === graph.childs.length - 1, false, opts)); | ||
| }); | ||
| return lines.join("\n"); | ||
| } | ||
| //# sourceMappingURL=renderGraph.js.map |
| {"version":3,"file":"renderGraph.js","sourceRoot":"","sources":["../../../src/workflows/graph/renderGraph.ts"],"names":[],"mappings":";;AAwCA,kCAYC;AAhCD,MAAM,UAAU,GAA8B;IAC5C,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;IAClD,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;CACpD,CAAC;AAEF,MAAM,UAAU,G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;QAC7D,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;IACf,MAAM,KAAK,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;IAEvC,MAAM,WAAW,GACf,MAAM;QACN,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAExE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAChC,IAAI,aAAa,EAAE,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;QACD,KAAK,CAAC,IAAI,CACR,UAAU,CACR,KAAK,EACL,WAAW,EACX,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAC7B,KAAK,EACL,IAAI,CACL,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"} |
| import { WorkflowState } from "../interfaces"; | ||
| import { Graph } from "./renderGraph"; | ||
| type ChildrenOutputs<C extends Record<string, WorkflowNode<any, any>>> = { | ||
| [K in keyof C]: C[K] extends WorkflowNode<any, infer O> ? O : never; | ||
| }; | ||
| export declare class WorkflowNode<Children extends Record<string, WorkflowNode<any, any>>, Output> { | ||
| #private; | ||
| constructor(params: { | ||
| name: string; | ||
| children: Children; | ||
| handler: (input: ChildrenOutputs<Children>) => Promise<Output>; | ||
| }); | ||
| onChanges(handler: (event: { | ||
| step: string; | ||
| status: "IN_PROGRESS"; | ||
| } | { | ||
| step: string; | ||
| status: "DONE"; | ||
| } | { | ||
| step: string; | ||
| status: "FAILED"; | ||
| error: Error; | ||
| }) => void): void; | ||
| setContext(context: WorkflowState<unknown>): void; | ||
| execute(): Promise<Output>; | ||
| getGraph(): Graph; | ||
| get name(): string; | ||
| } | ||
| export {}; | ||
| //# sourceMappingURL=workflowNode.d.ts.map |
| {"version":3,"file":"workflowNode.d.ts","sourceRoot":"","sources":["../../../src/workflows/graph/workflowNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAkB,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAkC,MAAM,eAAe,CAAC;AAEtE,KAAK,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI;KACtE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACpE,CAAC;AAEF,qBAAa,YAAY,CACvB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EACvD,MAAM;;gBAeM,MAAM,EAAE;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,QAAQ,CAAC;QACnB,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;KAChE;IAiBD,SAAS,CACP,OAAO,EAAE,CACP,KAAK,EACD;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,GACvC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAChC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,KACjD,IAAI;IASX,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI;IAQ3C,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAsEhC,QAAQ,IAAI,KAAK;IAcjB,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WorkflowNode = void 0; | ||
| const node_crypto_1 = require("node:crypto"); | ||
| const renderGraph_1 = require("./renderGraph"); | ||
| class WorkflowNode { | ||
| #name; | ||
| #children; | ||
| #handler; | ||
| #context; | ||
| #status; | ||
| #onChanges; | ||
| constructor(params) { | ||
| this.#name = params.name; | ||
| this.#children = params.children; | ||
| this.#handler = params.handler; | ||
| this.#onChanges = () => { }; | ||
| this.#status = "TODO"; | ||
| this.#context = { | ||
| // Set a default context | ||
| id: (0, node_crypto_1.randomUUID)(), | ||
| name: this.name, | ||
| status: "TODO", | ||
| stepResults: new Map(), | ||
| input: {}, | ||
| error: undefined, | ||
| }; | ||
| } | ||
| onChanges(handler) { | ||
| this.#onChanges = handler; | ||
| Object.entries(this.#children).map(async ([_name, child]) => { | ||
| child.onChanges(this.#onChanges); | ||
| }); | ||
| } | ||
| setContext(context) { | ||
| this.#context = context; | ||
| Object.entries(this.#children).map(async ([_name, child]) => { | ||
| child.setContext(context); | ||
| }); | ||
| } | ||
| async execute() { | ||
| this.#context.status = "IN_PROGRESS"; | ||
| if (this.#context.stepResults.has(this.#name)) { | ||
| this.#status = "DONE"; | ||
| this.#onChanges({ step: this.#name, status: "DONE" }); | ||
| return this.#context.stepResults.get(this.#name); | ||
| } | ||
| const entries = await Promise.all(Object.entries(this.#children).map(async ([name, child]) => { | ||
| return [name, await child.execute()]; | ||
| })); | ||
| const input = Object.fromEntries(entries); | ||
| this.#status = "IN_PROGRESS"; | ||
| this.#onChanges({ step: this.#name, status: "IN_PROGRESS" }); | ||
| try { | ||
| const output = await this.#handler(input); | ||
| this.#context.stepResults.set(this.#name, output); | ||
| this.#status = "DONE"; | ||
| this.#onChanges({ step: this.#name, status: "DONE" }); | ||
| return output; | ||
| } | ||
| catch (err) { | ||
| const error = this.#handleError(err); | ||
| throw error; | ||
| } | ||
| } | ||
| #handleError(err) { | ||
| let message = "unknown error"; | ||
| let name = "Unknown Error"; | ||
| if (err instanceof Error) { | ||
| message = err.message; | ||
| name = err.name; | ||
| } | ||
| const error = new Error(`Step: ${this.#name} failed with: ${name} ${message}`, { | ||
| cause: err, | ||
| }); | ||
| // Mark the workflow as failed | ||
| this.#context.status = "FAILED"; | ||
| // Mark this node as failed | ||
| this.#status = "FAILED"; | ||
| this.#context.error = { | ||
| step: this.#name, | ||
| error: error.message, | ||
| name: error.name, | ||
| }; | ||
| this.#onChanges({ step: this.#name, status: "FAILED", error }); | ||
| return error; | ||
| } | ||
| getGraph() { | ||
| const childs = Object.values(this.#children).map((child) => child.getGraph()); | ||
| return { | ||
| name: this.#name, | ||
| status: this.#status, | ||
| childs, | ||
| toString: (opts) => (0, renderGraph_1.renderGraph)({ name: this.#name, status: this.#status, childs }, opts), | ||
| }; | ||
| } | ||
| get name() { | ||
| return this.#name; | ||
| } | ||
| } | ||
| exports.WorkflowNode = WorkflowNode; | ||
| //# sourceMappingURL=workflowNode.js.map |
| {"version":3,"file":"workflowNode.js","sourceRoot":"","sources":["../../../src/workflows/graph/workflowNode.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAEzC,+CAAsE;AAMtE,MAAa,YAAY;IAIvB,KAAK,CAAS;IACd,SAAS,CAAW;IACpB,QAAQ,CAAwD;IAChE,QAAQ,CAAyB;IACjC,OAAO,CAAiB;IAExB,UAAU,CAKA;IAEV,YAAY,MAIX;QACC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QA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owState<Input> { | ||
| id: string; | ||
| name: string; | ||
| input: Input; | ||
| stepResults: Map<string, unknown>; | ||
| error: { | ||
| step: string; | ||
| error: string; | ||
| name: string; | ||
| } | undefined; | ||
| status: WorkflowStatus; | ||
| } | ||
| export type WorkflowStatus = "TODO" | "IN_PROGRESS" | "FAILED" | "DONE"; | ||
| //# sourceMappingURL=interfaces.d.ts.map |
| {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/workflows/interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,KAAK;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACjE,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,GAAG,MAAM,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=interfaces.js.map |
| {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/workflows/interfaces.ts"],"names":[],"mappings":""} |
| export { InMemoryWorkflowStateRepository } from "./inMemoryWorkflowStateRepository"; | ||
| export { type WorkflowStateRepository } from "./interfaces"; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/workflows/repository/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.InMemoryWorkflowStateRepository = void 0; | ||
| var inMemoryWorkflowStateRepository_1 = require("./inMemoryWorkflowStateRepository"); | ||
| Object.defineProperty(exports, "InMemoryWorkflowStateRepository", { enumerable: true, get: function () { return inMemoryWorkflowStateRepository_1.InMemoryWorkflowStateRepository; } }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workflows/repository/index.ts"],"names":[],"mappings":";;;AAAA,qFAAoF;AAA3E,kJAAA,+BAA+B,OAAA"} |
| import { WorkflowState } from "../interfaces"; | ||
| export interface WorkflowStateRepository { | ||
| save: (state: WorkflowState<unknown>) => Promise<void>; | ||
| getById: (id: string) => Promise<WorkflowState<unknown> | undefined>; | ||
| } | ||
| //# sourceMappingURL=interfaces.d.ts.map |
| {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/workflows/repository/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;CACtE"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=interfaces.js.map |
| {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/workflows/repository/interfaces.ts"],"names":[],"mappings":""} |
| import { EventEmitter } from "node:events"; | ||
| import { AggregateOutput } from "./parallelStep"; | ||
| import { WorkflowState } from "../interfaces"; | ||
| import { WorkflowStateRepository } from "../repository/interfaces"; | ||
| export declare class ComposableWorkflowStep<Input, Output> { | ||
| #private; | ||
| constructor(params: { | ||
| name: string; | ||
| handler: StepHandler<Input, Output>; | ||
| previousStep: PreviousStepHandler<Input>; | ||
| workflowState: WorkflowState<unknown>; | ||
| eventEmitter: EventEmitter; | ||
| }); | ||
| addStep<NextOutput>(params: { | ||
| name: string; | ||
| handler: StepHandler<Output, NextOutput>; | ||
| }): ComposableWorkflowStep<Output, NextOutput>; | ||
| addStepWithSubtasks<const Substasks extends readonly { | ||
| name: string; | ||
| handler: (input: Output) => Promise<unknown>; | ||
| }[]>(params: { | ||
| name: string; | ||
| subtasks: Substasks; | ||
| }): ComposableWorkflowStep<Output, AggregateOutput<Substasks>>; | ||
| execute(repository?: Pick<WorkflowStateRepository, "save">): Promise<Output>; | ||
| results(): Map<string, unknown>; | ||
| status(): import("../interfaces").WorkflowStatus; | ||
| onChanges(handler: (event: { | ||
| step: string; | ||
| status: "IN_PROGRESS"; | ||
| } | { | ||
| step: string; | ||
| status: "DONE"; | ||
| } | { | ||
| step: string; | ||
| status: "FAILED"; | ||
| error: Error; | ||
| }) => void): void; | ||
| get name(): string; | ||
| } | ||
| export type StepHandler<Input, Output> = (input: Input) => Promise<Output>; | ||
| export type PreviousStepHandler<Output> = () => Promise<Output>; | ||
| //# sourceMappingURL=composableWorkflowStep.d.ts.map |
| {"version":3,"file":"composableWorkflowStep.d.ts","sourceRoot":"","sources":["../../../src/workflows/step/composableWorkflowStep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAqB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,qBAAa,sBAAsB,CAAC,KAAK,EAAE,MAAM;;gBAQnC,MAAM,EAAE;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpC,YAAY,EAAE,mBAAmB,CAAC,KAA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AE3E,MAAM,MAAM,mBAAmB,CAAC,MAAM,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ComposableWorkflowStep = void 0; | ||
| const parallelStep_1 = require("./parallelStep"); | ||
| class ComposableWorkflowStep { | ||
| #name; | ||
| #handler; | ||
| #previousStep; | ||
| #workflowState; | ||
| #isLast; | ||
| #eventEmitter; | ||
| constructor(params) { | ||
| const { name, handler, previousStep, workflowState, eventEmitter } = params; | ||
| this.#name = name; | ||
| this.#handler = handler; | ||
| this.#previousStep = previousStep; | ||
| this.#workflowState = workflowState; | ||
| this.#isLast = true; | ||
| this.#eventEmitter = eventEmitter; | ||
| } | ||
| addStep(params) { | ||
| const { name, handler } = params; | ||
| this.#isLast = false; | ||
| return new ComposableWorkflowStep({ | ||
| name, | ||
| handler, | ||
| previousStep: () => this.execute(), | ||
| workflowState: this.#workflowState, | ||
| eventEmitter: this.#eventEmitter, | ||
| }); | ||
| } | ||
| addStepWithSubtasks(params) { | ||
| const { name, subtasks } = params; | ||
| return new ComposableWorkflowStep({ | ||
| workflowState: this.#workflowState, | ||
| eventEmitter: this.#eventEmitter, | ||
| name: name, | ||
| previousStep: () => this.execute(), | ||
| handler: async (input) => { | ||
| const result = await (0, parallelStep_1.aggregateFunction)(subtasks, input, this.#eventEmitter); | ||
| return result; | ||
| }, | ||
| }); | ||
| } | ||
| async execute(repository) { | ||
| this.#workflowState.status = "IN_PROGRESS"; | ||
| // Save initial state | ||
| if (repository) { | ||
| await repository.save(this.#workflowState); | ||
| } | ||
| let result = this.#workflowState.stepResults.get(this.#name); | ||
| if (result !== undefined) { | ||
| return result; | ||
| } | ||
| const input = await this.#previousStep(); | ||
| this.#eventEmitter.emit("change", { | ||
| step: this.#name, | ||
| status: "IN_PROGRESS", | ||
| }); | ||
| try { | ||
| const output = await this.#handler(input); | ||
| this.#workflowState.stepResults.set(this.#name, output); | ||
| if (this.#isLast) { | ||
| this.#workflowState.status = "DONE"; | ||
| } | ||
| this.#eventEmitter.emit("change", { step: this.#name, status: "DONE" }); | ||
| return output; | ||
| } | ||
| catch (err) { | ||
| const error = this.#handleError(err); | ||
| throw error; | ||
| } | ||
| finally { | ||
| // Save state from either a success or a failure | ||
| if (repository) { | ||
| await repository.save(this.#workflowState); | ||
| } | ||
| } | ||
| } | ||
| #handleError(err) { | ||
| let message = "unknown error"; | ||
| let name = "Unknown Error"; | ||
| if (err instanceof Error) { | ||
| message = err.message; | ||
| name = err.name; | ||
| } | ||
| const error = new Error(`Step: ${this.#name} failed with: ${name} ${message}`, { | ||
| cause: err, | ||
| }); | ||
| this.#workflowState.status = "FAILED"; | ||
| this.#workflowState.error = { | ||
| step: this.#name, | ||
| error: error.message, | ||
| name: error.name, | ||
| }; | ||
| this.#eventEmitter.emit("change", { | ||
| step: this.#name, | ||
| status: "FAILED", | ||
| error, | ||
| }); | ||
| return error; | ||
| } | ||
| results() { | ||
| return this.#workflowState.stepResults; | ||
| } | ||
| status() { | ||
| return this.#workflowState.status; | ||
| } | ||
| onChanges(handler) { | ||
| this.#eventEmitter.on("change", handler); | ||
| } | ||
| get name() { | ||
| return this.#workflowState.name; | ||
| } | ||
| } | ||
| exports.ComposableWorkflowStep = ComposableWorkflowStep; | ||
| //# sourceMappingURL=composableWorkflowStep.js.map |
| {"version":3,"file":"composableWorkflowStep.js","sourceRoot":"","sources":["../../../src/workflows/step/composableWorkflowStep.ts"],"names":[],"mappings":";;;AACA,iDAAoE;AAIpE,MAAa,sBAAsB;IACjC,KAAK,CAAS;IACd,QAAQ,CAA6B;IACrC,aAAa,CAA6B;IAC1C,cAAc,CAAyB;IACvC,OAAO,CAAU;IACjB,aAAa,CAAe;IAE5B,YAAY,MAMX;QACC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAC5E,IAAI,CAAC,KAAK,GAAG,IAAI,CA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AAC;QAC9B,IAAI,IAAI,GAAG,eAAe,CAAC;QAE3B,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;YACzB,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;YACtB,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QAClB,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,KAAK,CACrB,SAAS,IAAI,CAAC,KAAK,iBAAiB,IAAI,IAAI,OAAO,EAAE,EACrD;YACE,KAAK,EAAE,GAAG;SACX,CACF,CAAC;QAEF,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,QAAQ,CAAC;QAEtC,IAAI,CAAC,cAAc,CAAC,KAAK,GAAG;YAC1B,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,KAAK,EAAE,KAAK,CAAC,OAAO;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC;QAEF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE;YAChC,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,MAAM,EAAE,QAAQ;YAChB,KAAK;SACN,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;IACzC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;IACpC,CAAC;IAED,SAAS,CACP,OAKS;QAET,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;IAClC,CAAC;CACF;AA3KD,wDA2KC"} |
| export { WorkflowBuilder, type WorkflowStep } from "./workflow"; | ||
| export { defineSubTask } from "./parallelStep"; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/workflows/step/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.defineSubTask = exports.WorkflowBuilder = void 0; | ||
| var workflow_1 = require("./workflow"); | ||
| Object.defineProperty(exports, "WorkflowBuilder", { enumerable: true, get: function () { return workflow_1.WorkflowBuilder; } }); | ||
| var parallelStep_1 = require("./parallelStep"); | ||
| Object.defineProperty(exports, "defineSubTask", { enumerable: true, get: function () { return parallelStep_1.defineSubTask; } }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workflows/step/index.ts"],"names":[],"mappings":";;;AAAA,uCAAgE;AAAvD,2GAAA,eAAe,OAAA;AACxB,+CAA+C;AAAtC,6GAAA,aAAa,OAAA"} |
| import { EventEmitter } from "node:events"; | ||
| export declare function defineSubTask<const N extends string, Input, Output>(task: { | ||
| name: N; | ||
| handler: (input: Input) => Promise<Output>; | ||
| }): { | ||
| name: N; | ||
| handler: (input: Input) => Promise<Output>; | ||
| }; | ||
| export type AggregateOutput<H extends readonly { | ||
| name: string; | ||
| handler: (input: any) => Promise<any>; | ||
| }[]> = { | ||
| [E in H[number] as E["name"]]: E["handler"] extends (input: any) => Promise<infer O> ? O : never; | ||
| }; | ||
| export declare function aggregateFunction<Input, const H extends readonly { | ||
| name: string; | ||
| handler: (input: Input) => Promise<unknown>; | ||
| }[]>(handlers: H, input: Input, eventEmitter: EventEmitter): Promise<AggregateOutput<H>>; | ||
| //# sourceMappingURL=parallelStep.d.ts.map |
| {"version":3,"file":"parallelStep.d.ts","sourceRoot":"","sources":["../../../src/workflows/step/parallelStep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,wBAAgB,aAAa,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IACzE,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C,GAAG;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAE1D;AAED,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;CAAE,EAAE,IAC1E;KACD,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,SAAS,CAClD,KAAK,EAAE,GAAG,KACP,OAAO,CAAC,MAAM,CAAC,CAAC,GACjB,CAAC,GACD,KAAK;CACV,CAAC;AAEF,wBAAsB,iBAAiB,CACrC,KAAK,EACL,KAAK,CAAC,CAAC,SAAS,SAAS;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7C,EAAE,EAEH,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAc7B"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.defineSubTask = defineSubTask; | ||
| exports.aggregateFunction = aggregateFunction; | ||
| function defineSubTask(task) { | ||
| return task; | ||
| } | ||
| async function aggregateFunction(handlers, input, eventEmitter) { | ||
| const entries = await Promise.all(handlers.map(async ({ name, handler }) => { | ||
| eventEmitter.emit("change", { step: name, status: "START" }); | ||
| const result = await handler(input); | ||
| eventEmitter.emit("change", { step: name, status: "DONE" }); | ||
| return [name, result]; | ||
| })); | ||
| return Object.fromEntries(entries); | ||
| } | ||
| //# sourceMappingURL=parallelStep.js.map |
| {"version":3,"file":"parallelStep.js","sourceRoot":"","sources":["../../../src/workflows/step/parallelStep.ts"],"names":[],"mappings":";;AAEA,sCAKC;AAYD,8CAwBC;AAzCD,SAAgB,aAAa,CAAwC,IAGpE;IACC,OAAO,IAAI,CAAC;AACd,CAAC;AAYM,KAAK,UAAU,iBAAiB,CAOrC,QAAW,EACX,KAAY,EACZ,YAA0B;IAE1B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;QACvC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAE7D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;QAEpC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAE5D,OAAO,CAAC,IAAI,EAAE,MAAM,CAAU,CAAC;IACjC,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAuB,CAAC;AAC3D,CAAC"} |
| import { ComposableWorkflowStep, StepHandler } from "./composableWorkflowStep"; | ||
| import { AggregateOutput } from "./parallelStep"; | ||
| export interface WorkflowStep<Input, Output> { | ||
| name: string; | ||
| handler: StepHandler<Input, Output>; | ||
| } | ||
| export declare class WorkflowBuilder<Input> { | ||
| #private; | ||
| constructor(params: { | ||
| id: string; | ||
| name: string; | ||
| input: Input; | ||
| stepResult?: Map<string, unknown>; | ||
| }); | ||
| addStep<Output>(step: WorkflowStep<Input, Output>): ComposableWorkflowStep<Input, Output>; | ||
| addStepWithSubtasks<const Substasks extends readonly { | ||
| name: string; | ||
| handler: (input: Input) => Promise<unknown>; | ||
| }[]>(params: { | ||
| name: string; | ||
| subtasks: Substasks; | ||
| }): ComposableWorkflowStep<Input, AggregateOutput<Substasks>>; | ||
| onChanges(handler: (event: { | ||
| step: string; | ||
| status: "IN_PROGRESS"; | ||
| } | { | ||
| step: string; | ||
| status: "DONE"; | ||
| } | { | ||
| step: string; | ||
| status: "FAILED"; | ||
| error: Error; | ||
| }) => void): void; | ||
| get name(): string; | ||
| } | ||
| //# sourceMappingURL=workflow.d.ts.map |
| {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/step/workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAqB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGpE,MAAM,WAAW,YAAY,CAAC,KAAK,EAAE,MAAM;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,qBAAa,eAAe,CAAC,KAAK;;gBAIpB,MAAM,EAAE;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,KAAK,CAAC;QACb,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC;IAkBD,OAAO,CAAC,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,GAChC,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC;IAUxC,mBAAmB,CACjB,KAAK,CAAC,SAAS,SAAS,SAAS;QAC/B,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;KAC7C,EAAE,EACH,MAAM,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,SAAS,CAAC;KACrB,GAAG,sBAAsB,CAAC,KAAK,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IAmB7D,SAAS,CACP,OAAO,EAAE,CACP,KAAK,EACD;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,GACvC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAChC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,KACjD,IAAI;IAKX,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WorkflowBuilder = void 0; | ||
| const node_events_1 = require("node:events"); | ||
| const composableWorkflowStep_1 = require("./composableWorkflowStep"); | ||
| const parallelStep_1 = require("./parallelStep"); | ||
| class WorkflowBuilder { | ||
| #state; | ||
| #eventEmitter; | ||
| constructor(params) { | ||
| const state = { | ||
| status: "TODO", | ||
| name: params.name, | ||
| id: params.id, | ||
| input: params.input, | ||
| stepResults: params.stepResult | ||
| ? params.stepResult | ||
| : new Map(), | ||
| error: undefined, | ||
| }; | ||
| this.#state = state; | ||
| this.#eventEmitter = new node_events_1.EventEmitter({ | ||
| captureRejections: true, | ||
| }); | ||
| } | ||
| addStep(step) { | ||
| return new composableWorkflowStep_1.ComposableWorkflowStep({ | ||
| name: step.name, | ||
| handler: step.handler, | ||
| workflowState: this.#state, | ||
| eventEmitter: this.#eventEmitter, | ||
| previousStep: async () => await Promise.resolve(this.#state.input), | ||
| }); | ||
| } | ||
| addStepWithSubtasks(params) { | ||
| const { name, subtasks } = params; | ||
| return new composableWorkflowStep_1.ComposableWorkflowStep({ | ||
| workflowState: this.#state, | ||
| eventEmitter: this.#eventEmitter, | ||
| name: name, | ||
| previousStep: async () => await Promise.resolve(this.#state.input), | ||
| handler: async (input) => { | ||
| const result = await (0, parallelStep_1.aggregateFunction)(subtasks, input, this.#eventEmitter); | ||
| return result; | ||
| }, | ||
| }); | ||
| } | ||
| onChanges(handler) { | ||
| this.#eventEmitter.on("change", handler); | ||
| } | ||
| get name() { | ||
| return this.#state.name; | ||
| } | ||
| } | ||
| exports.WorkflowBuilder = WorkflowBuilder; | ||
| //# sourceMappingURL=workflow.js.map |
| {"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../../src/workflows/step/workflow.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,qEAA+E;AAC/E,iDAAoE;AAQpE,MAAa,eAAe;IAC1B,MAAM,CAAuB;IAC7B,aAAa,CAAe;IAE5B,YAAY,MAKX;QACC,MAAM,KAAK,GAAyB;YAClC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,WAAW,EAAE,MAAM,CAAC,UAAU;gBAC5B,CAAC,CAAC,MAAM,CAAC,UAAU;gBACnB,CAAC,CAAC,IAAI,GAAG,EAAmB;YAC9B,KAAK,EAAE,SAAS;SACjB,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,IAAI,0BAAY,CAAC;YACpC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CACL,IAAiC;QAEjC,OAAO,IAAI,+CAAsB,CAAC;YAChC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,aAAa,EAAE,IAAI,CAAC,MAAM;YAC1B,YAAY,EAAE,IAAI,CAAC,aAAa;YAChC,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;SACnE,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAKjB,MAGD;QACC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QAElC,OAAO,IAAI,+CAAsB,CAAC;YAChC,aAAa,EAAE,IAAI,CAAC,MAAM;YAC1B,YAAY,EAAE,IAAI,CAAC,aAAa;YAChC,IAAI,EAAE,IAAI;YACV,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YAClE,OAAO,EAAE,KAAK,EAAE,KAAY,EAAuC,EAAE;gBACnE,MAAM,MAAM,GAAG,MAAM,IAAA,gCAAiB,EACpC,QAAQ,EACR,KAAK,EACL,IAAI,CAAC,aAAa,CACnB,CAAC;gBACF,OAAO,MAAoC,CAAC;YAC9C,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CACP,OAKS;QAET,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;CACF;AAhFD,0CAgFC"} |
+1
-0
@@ -11,2 +11,3 @@ export * from "./domainError"; | ||
| export * from "./switchGuard"; | ||
| export * from "./workflows"; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"} |
+1
-0
@@ -27,2 +27,3 @@ "use strict"; | ||
| __exportStar(require("./switchGuard"), exports); | ||
| __exportStar(require("./workflows"), exports); | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,iDAA+B;AAC/B,+CAA6B;AAC7B,2CAAyB;AACzB,oDAAkC;AAClC,8CAA4B;AAC5B,iDAA+B;AAC/B,uDAAqC;AACrC,gDAA8B"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,iDAA+B;AAC/B,+CAA6B;AAC7B,2CAAyB;AACzB,oDAAkC;AAClC,8CAA4B;AAC5B,iDAA+B;AAC/B,uDAAqC;AACrC,gDAA8B;AAC9B,8CAA4B"} |
@@ -1,4 +0,5 @@ | ||
| export { WorkflowBuilder, type WorkflowStep } from "./workflow"; | ||
| export { InMemoryWorkflowStateRepository } from "./repository/inMemoryWorkflowStateRepository"; | ||
| export type { WorkflowStateRepository } from "./composableWorkflowStep"; | ||
| export * from "./step"; | ||
| export * from "./graph"; | ||
| export * from "./repository"; | ||
| export * from "./interfaces"; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,YAAY,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"} |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.InMemoryWorkflowStateRepository = exports.WorkflowBuilder = void 0; | ||
| var workflow_1 = require("./workflow"); | ||
| Object.defineProperty(exports, "WorkflowBuilder", { enumerable: true, get: function () { return workflow_1.WorkflowBuilder; } }); | ||
| var inMemoryWorkflowStateRepository_1 = require("./repository/inMemoryWorkflowStateRepository"); | ||
| Object.defineProperty(exports, "InMemoryWorkflowStateRepository", { enumerable: true, get: function () { return inMemoryWorkflowStateRepository_1.InMemoryWorkflowStateRepository; } }); | ||
| __exportStar(require("./step"), exports); | ||
| __exportStar(require("./graph"), exports); | ||
| __exportStar(require("./repository"), exports); | ||
| __exportStar(require("./interfaces"), exports); | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":";;;AAAA,uCAAgE;AAAvD,2GAAA,eAAe,OAAA;AACxB,gGAA+F;AAAtF,kJAAA,+BAA+B,OAAA"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,+CAA6B;AAC7B,+CAA6B"} |
@@ -1,3 +0,3 @@ | ||
| import { WorkflowStateRepository } from "../composableWorkflowStep"; | ||
| import { WorkflowState } from "../workflow"; | ||
| import { WorkflowState } from "../interfaces"; | ||
| import { WorkflowStateRepository } from "./interfaces"; | ||
| export declare class InMemoryWorkflowStateRepository implements WorkflowStateRepository { | ||
@@ -4,0 +4,0 @@ #private; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"inMemoryWorkflowStateRepository.d.ts","sourceRoot":"","sources":["../../../src/workflows/repository/inMemoryWorkflowStateRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,qBAAa,+BACX,YAAW,uBAAuB;;;IAQ5B,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;CAIvE"} | ||
| {"version":3,"file":"inMemoryWorkflowStateRepository.d.ts","sourceRoot":"","sources":["../../../src/workflows/repository/inMemoryWorkflowStateRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,qBAAa,+BAAgC,YAAW,uBAAuB;;;IAOvE,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;CAIvE"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"inMemoryWorkflowStateRepository.js","sourceRoot":"","sources":["../../../src/workflows/repository/inMemoryWorkflowStateRepository.ts"],"names":[],"mappings":";;;AAGA,MAAa,+BAA+B;IAG1C,OAAO,CAAsC;IAE7C;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAA6B;QACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC;CACF;AAjBD,0EAiBC"} | ||
| {"version":3,"file":"inMemoryWorkflowStateRepository.js","sourceRoot":"","sources":["../../../src/workflows/repository/inMemoryWorkflowStateRepository.ts"],"names":[],"mappings":";;;AAIA,MAAa,+BAA+B;IAC1C,OAAO,CAAsC;IAE7C;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAA6B;QACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC;CACF;AAfD,0EAeC"} |
+3
-2
| { | ||
| "name": "ontologic", | ||
| "version": "1.4.1", | ||
| "version": "1.5.0", | ||
| "description": "Model What Matters: Domain Entities, Invariant, Domain Events, and much more.", | ||
@@ -48,4 +48,5 @@ "main": "dist/index.js", | ||
| "build:release": "tsc --project tsconfig-release.json", | ||
| "example:sepa": "npx tsx src/examples/workflows/sepaPayment.ts" | ||
| "example:step": "npx tsx src/examples/workflows/step-workflow-sepaPayment.ts", | ||
| "example:graph": "npx tsx src/examples/workflows/graph-workflow.ts" | ||
| } | ||
| } |
| import { WorkflowState } from "./workflow"; | ||
| export declare class ComposableWorkflowStep<Input, Output> { | ||
| #private; | ||
| constructor(params: { | ||
| name: string; | ||
| handler: StepHandler<Input, Output>; | ||
| previousStep: PreviousStepHandler<Input>; | ||
| workflowState: WorkflowState<unknown>; | ||
| }); | ||
| addStep<NextOutput>(params: { | ||
| name: string; | ||
| handler: StepHandler<Output, NextOutput>; | ||
| }): ComposableWorkflowStep<Output, NextOutput>; | ||
| execute(repository?: Pick<WorkflowStateRepository, "save">): Promise<Output>; | ||
| results(): Map<string, unknown>; | ||
| status(): "IN_PROGRESS" | "FAILED" | "TODO" | "DONE"; | ||
| get name(): string; | ||
| } | ||
| export type StepHandler<Input, Output> = (input: Input) => Promise<Output>; | ||
| type PreviousStepHandler<Output> = () => Promise<Output>; | ||
| export interface WorkflowStateRepository { | ||
| save: (state: WorkflowState<unknown>) => Promise<void>; | ||
| getById: (id: string) => Promise<WorkflowState<unknown> | undefined>; | ||
| } | ||
| export {}; | ||
| //# sourceMappingURL=composableWorkflowStep.d.ts.map |
| {"version":3,"file":"composableWorkflowStep.d.ts","sourceRoot":"","sources":["../../src/workflows/composableWorkflowStep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,qBAAa,sBAAsB,CAAC,KAAK,EAAE,MAAM;;gBAOnC,MAAM,EAAE;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpC,YAAY,EAAE,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACzC,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;KACvC;IASD,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC1C,GAAG,sBAAsB,CAAC,MAAM,EAAE,UAAU,CAAC;IAaxC,OAAO,CACX,UAAU,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,GACjD,OAAO,CAAC,MAAM,CAAC;IAgElB,OAAO,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAI/B,MAAM;IAIN,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAED,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAE3E,KAAK,mBAAmB,CAAC,MAAM,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;AAEzD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;CACtE"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ComposableWorkflowStep = void 0; | ||
| class ComposableWorkflowStep { | ||
| #name; | ||
| #handler; | ||
| #previousStep; | ||
| #workflowState; | ||
| #isLast; | ||
| constructor(params) { | ||
| const { name, handler, previousStep, workflowState } = params; | ||
| this.#name = name; | ||
| this.#handler = handler; | ||
| this.#previousStep = previousStep; | ||
| this.#workflowState = workflowState; | ||
| this.#isLast = true; | ||
| } | ||
| addStep(params) { | ||
| const { name, handler } = params; | ||
| this.#isLast = false; | ||
| return new ComposableWorkflowStep({ | ||
| name, | ||
| handler, | ||
| previousStep: () => this.execute(), | ||
| workflowState: this.#workflowState, | ||
| }); | ||
| } | ||
| async execute(repository) { | ||
| this.#workflowState.status = "IN_PROGRESS"; | ||
| // Save initial state | ||
| if (repository) { | ||
| await repository.save(this.#workflowState); | ||
| } | ||
| let result = this.#workflowState.stepResults.get(this.#name); | ||
| if (result !== undefined) { | ||
| return result; | ||
| } | ||
| const input = await this.#previousStep(); | ||
| try { | ||
| const output = await this.#handler(input); | ||
| this.#workflowState.stepResults.set(this.#name, output); | ||
| if (this.#isLast) { | ||
| this.#workflowState.status = "DONE"; | ||
| } | ||
| return output; | ||
| } | ||
| catch (err) { | ||
| const error = this.#handleError(err); | ||
| throw error; | ||
| } | ||
| finally { | ||
| // Save state from either a success or a failure | ||
| if (repository) { | ||
| await repository.save(this.#workflowState); | ||
| } | ||
| } | ||
| } | ||
| #handleError(err) { | ||
| let message = "unknown error"; | ||
| let name = "Unknown Error"; | ||
| if (err instanceof Error) { | ||
| message = err.message; | ||
| name = err.name; | ||
| } | ||
| const error = new Error(`Step: ${this.#name} failed with: ${name} ${message}`, { | ||
| cause: err, | ||
| }); | ||
| this.#workflowState.status = "FAILED"; | ||
| this.#workflowState.error = { | ||
| step: this.#name, | ||
| error: error.message, | ||
| name: error.name, | ||
| }; | ||
| return error; | ||
| } | ||
| results() { | ||
| return this.#workflowState.stepResults; | ||
| } | ||
| status() { | ||
| return this.#workflowState.status; | ||
| } | ||
| get name() { | ||
| return this.#workflowState.name; | ||
| } | ||
| } | ||
| exports.ComposableWorkflowStep = ComposableWorkflowStep; | ||
| //# sourceMappingURL=composableWorkflowStep.js.map |
| {"version":3,"file":"composableWorkflowStep.js","sourceRoot":"","sources":["../../src/workflows/composableWorkflowStep.ts"],"names":[],"mappings":";;;AAEA,MAAa,sBAAsB;IACjC,KAAK,CAAS;IACd,QAAQ,CAA6B;IACrC,aAAa,CAA6B;IAC1C,cAAc,CAAyB;IACvC,OAAO,CAAU;IAEjB,YAAY,MAKX;QACC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;QAC9D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,OAAO,CAAa,MAGnB;QACC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QAEjC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAErB,OAAO,IAAI,sBAAsB,CAAC;YAChC,IAAI;YACJ,OAAO;YACP,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;YAClC,aAAa,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CACX,UAAkD;QAElD,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,aAAa,CAAC;QA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KAAK,GAAG,IAAI,KAAK,CACrB,SAAS,IAAI,CAAC,KAAK,iBAAiB,IAAI,IAAI,OAAO,EAAE,EACrD;YACE,KAAK,EAAE,GAAG;SACX,CACF,CAAC;QAEF,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,QAAQ,CAAC;QAEtC,IAAI,CAAC,cAAc,CAAC,KAAK,GAAG;YAC1B,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,KAAK,EAAE,KAAK,CAAC,OAAO;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;IACzC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;IAClC,CAAC;CACF;AAlHD,wDAkHC"} |
| import { ComposableWorkflowStep, StepHandler } from "./composableWorkflowStep"; | ||
| export interface WorkflowState<Input> { | ||
| id: string; | ||
| name: string; | ||
| input: Input; | ||
| stepResults: Map<string, unknown>; | ||
| error: { | ||
| step: string; | ||
| error: string; | ||
| name: string; | ||
| } | undefined; | ||
| status: "TODO" | "IN_PROGRESS" | "FAILED" | "DONE"; | ||
| } | ||
| export declare class WorkflowBuilder<Input> { | ||
| #private; | ||
| constructor(params: { | ||
| id: string; | ||
| name: string; | ||
| input: Input; | ||
| stepResult?: Map<string, unknown>; | ||
| }); | ||
| addStep<Output>(step: WorkflowStep<Input, Output>): ComposableWorkflowStep<Input, Output>; | ||
| get name(): string; | ||
| } | ||
| export interface WorkflowStep<Input, Output> { | ||
| name: string; | ||
| handler: StepHandler<Input, Output>; | ||
| } | ||
| //# sourceMappingURL=workflow.d.ts.map |
| {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/workflows/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE/E,MAAM,WAAW,aAAa,CAAC,KAAK;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACjE,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,QAAQ,GAAG,MAAM,CAAC;CACpD;AAED,qBAAa,eAAe,CAAC,KAAK;;gBAGpB,MAAM,EAAE;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,KAAK,CAAC;QACb,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC;IAeD,OAAO,CAAC,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,GAChC,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC;IASxC,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAED,MAAM,WAAW,YAAY,CAAC,KAAK,EAAE,MAAM;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CACrC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WorkflowBuilder = void 0; | ||
| const composableWorkflowStep_1 = require("./composableWorkflowStep"); | ||
| class WorkflowBuilder { | ||
| #state; | ||
| constructor(params) { | ||
| const state = { | ||
| status: "TODO", | ||
| name: params.name, | ||
| id: params.id, | ||
| input: params.input, | ||
| stepResults: params.stepResult | ||
| ? params.stepResult | ||
| : new Map(), | ||
| error: undefined, | ||
| }; | ||
| this.#state = state; | ||
| } | ||
| addStep(step) { | ||
| return new composableWorkflowStep_1.ComposableWorkflowStep({ | ||
| name: step.name, | ||
| handler: step.handler, | ||
| workflowState: this.#state, | ||
| previousStep: async () => await Promise.resolve(this.#state.input), | ||
| }); | ||
| } | ||
| get name() { | ||
| return this.#state.name; | ||
| } | ||
| } | ||
| exports.WorkflowBuilder = WorkflowBuilder; | ||
| //# sourceMappingURL=workflow.js.map |
| {"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/workflows/workflow.ts"],"names":[],"mappings":";;;AAAA,qEAA+E;AAW/E,MAAa,eAAe;IAC1B,MAAM,CAAuB;IAE7B,YAAY,MAKX;QACC,MAAM,KAAK,GAAyB;YAClC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,WAAW,EAAE,MAAM,CAAC,UAAU;gBAC5B,CAAC,CAAC,MAAM,CAAC,UAAU;gBACnB,CAAC,CAAC,IAAI,GAAG,EAAmB;YAC9B,KAAK,EAAE,SAAS;SACjB,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,CACL,IAAiC;QAEjC,OAAO,IAAI,+CAAsB,CAAC;YAChC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,aAAa,EAAE,IAAI,CAAC,MAAM;YAC1B,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;SACnE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;CACF;AArCD,0CAqCC"} |
143734
31.09%175
25.9%1932
31.34%