priority-pipeline 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/error.ts","../src/orchestrator.ts","../src/component.ts"],"sourcesContent":["export * from \"./orchestrator\";\nexport * from \"./component\";\nexport * from \"./error\";\nexport * from \"./models\";\n","export type PipelineErrorCode =\n | \"PIPELINE_STARTED_TWICE\"\n | \"COMPONENT_FAILED\"\n | \"COMPONENT_DONE_WITH_NOTHING_TO_GIVE\";\n\nexport class PipelineError extends Error {\n readonly code: PipelineErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(\n code: PipelineErrorCode,\n opts?: { cause?: unknown; details?: Record<string, unknown> },\n ) {\n super(code, { cause: opts?.cause });\n this.name = new.target.name;\n this.code = code;\n this.details = opts?.details;\n }\n}","import { PipelineError } from \"./error\";\nimport { ComponentInterface, Orchestrator, NonEmpty, AnyComp, ChainableAny, SoftStateCheck } from \"./models\";\n\nclass OrchestratorImpl<S, T extends NonEmpty<AnyComp<S>>> {\n private hasStarted = false;\n private componentError: { component: AnyComp<S>; error: unknown } | undefined;\n\n constructor(\n private readonly state: S,\n private readonly components: T\n ) { }\n\n public async run(input?: T): Promise<T> {\n if (this.hasStarted) {\n throw new PipelineError('PIPELINE_STARTED_TWICE');\n }\n\n this.hasStarted = true;\n\n const priorities = Array.from(new Set(this.components.map(c => c.priority))).sort((a, b) => b - a);\n\n const tieredComponents = priorities.map((p) => ({\n components: this.components.filter(c => c.priority === p),\n anyCouldRun: this.components.some(c => c === this.firstComponent) // First component in pipeline must run first\n }));\n\n this.tryRunComponent(this.firstComponent, input);\n\n while (true) {\n let anyUpperTierCouldRun = false;\n\n outerLoop: for (const compsInTier of tieredComponents) {\n for (const component of compsInTier.components) {\n if (this.componentError) await this.handleError(this.componentError.component, this.componentError.error);\n\n if (this.getDone(component) && this.isLast(component)) return component.give();\n\n if (anyUpperTierCouldRun) break outerLoop;\n\n const canRun = component.canRun({\n state: this.state,\n upstreamCanGive: this.getUpstream(component)?.canGive() ?? true,\n });\n compsInTier.anyCouldRun = compsInTier.anyCouldRun || canRun;\n\n if (canRun) {\n this.tryRunComponent(component);\n }\n }\n\n anyUpperTierCouldRun = compsInTier.anyCouldRun;\n compsInTier.anyCouldRun = false;\n }\n\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n }\n\n private getDone(component: AnyComp<S>): boolean {\n for (let comp: AnyComp<S> | undefined = this.firstComponent; (comp ? this.getIndex(comp) : Infinity) <= this.getIndex(component); comp = this.getDownstream(comp!)) {\n if (!comp!.isDone({\n state: this.state,\n upstreamDone: true,\n upstreamCanGive: this.getUpstream(comp!)?.canGive() ?? true,\n })) return false;\n }\n\n return true;\n }\n\n private tryRunComponent(component: AnyComp<S>, input?: T) {\n const upstreamComponent = this.getUpstream(component);\n\n try {\n const maybePromise = component.run(input ?? upstreamComponent?.give(), {\n state: this.state,\n upstreamDone: upstreamComponent ? this.getDone(upstreamComponent) : true,\n });\n\n if (maybePromise instanceof Promise) {\n maybePromise.catch((error) => this.componentError = { component, error });\n }\n } catch (error) {\n this.componentError = { component, error };\n }\n }\n\n private async handleError(component: AnyComp<S>, error: unknown) {\n const pipelineError = new PipelineError('COMPONENT_FAILED', {\n cause: error,\n details: {\n componentIndex: this.getIndex(component),\n }\n });\n\n await Promise.all(this.components.map(c => c.onPipelineError?.(pipelineError, { state: this.state })));\n\n throw pipelineError;\n }\n\n private getUpstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) - 1];\n }\n\n private getDownstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) + 1];\n }\n\n private isLast(component: AnyComp<S>) {\n return this.getIndex(component) === this.components.length - 1;\n }\n\n private get firstComponent() {\n return this.components[0];\n }\n\n private getIndex(component: AnyComp<S>) {\n return this.components.indexOf(component);\n }\n}\n\nexport function createOrchestrator<\n S,\n const T extends readonly [\n ComponentInterface<any, any, any>,\n ...ComponentInterface<any, any, any>[]\n ]\n>(\n state: S,\n ...components: T\n & ChainableAny<T>\n & SoftStateCheck<S, T>\n): Orchestrator<T> {\n return new OrchestratorImpl<S, any>(\n state,\n components as any\n ) as unknown as Orchestrator<T>;\n}\n","import { PipelineError } from \"./error\";\n\nimport type { ComponentInterface } from \"./models\";\n\nconst DEFAULT_PRIORITY = 0;\n\nexport abstract class Component<I, O, S> implements ComponentInterface<I, O, S> {\n declare readonly __input?: I;\n declare readonly __output?: O;\n\n public readonly priority: number;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority }: { priority?: number } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n }\n\n abstract isDone(ctx: { upstreamDone: boolean; upstreamCanGive: boolean, state: S }): boolean;\n abstract canRun(ctx: { upstreamCanGive: boolean, state: S }): boolean;\n abstract run(input: I, ctx: { upstreamDone: boolean, state: S }): void | Promise<void>;\n\n canGive(): boolean {\n return this.queue.length > 0;\n }\n\n give(): O {\n if (this.queue.length === 0) {\n throw new PipelineError('COMPONENT_DONE_WITH_NOTHING_TO_GIVE');\n }\n\n // It is legitimate that O == undefined\n return this.queue.shift() as O;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YACE,MACA,MACA;AACA,UAAM,MAAM,EAAE,OAAO,MAAM,MAAM,CAAC;AAClC,SAAK,OAAO,WAAW;AACvB,SAAK,OAAO;AACZ,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;;;ACfA,IAAM,mBAAN,MAA0D;AAAA,EAIxD,YACmB,OACA,YACjB;AAFiB;AACA;AAAA,EACf;AAAA,EANI,aAAa;AAAA,EACb;AAAA,EAOR,MAAa,IAAI,OAAuB;AACtC,QAAI,KAAK,YAAY;AACnB,YAAM,IAAI,cAAc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B;AAC3B,WAAO,KAAK,WAAW,CAAC;AAAA,EAC1B;AAAA,EAEQ,SAAS,WAAuB;AACtC,WAAO,KAAK,WAAW,QAAQ,SAAS;AAAA,EAC1C;AACF;AAEO,SAAS,mBAOd,UACG,YAGc;AACjB,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;;;ACrIA,IAAM,mBAAmB;AAElB,IAAe,YAAf,MAAyE;AAAA,EAI9D;AAAA,EAEG,QAAa,CAAC;AAAA,EAEjC,YAAY,EAAE,SAAS,IAA2B,CAAC,GAAG;AACpD,SAAK,WAAW,YAAY;AAAA,EAC9B;AAAA,EAMA,UAAmB;AACjB,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAEA,OAAU;AACR,QAAI,KAAK,MAAM,WAAW,GAAG;AAC3B,YAAM,IAAI,cAAc,qCAAqC;AAAA,IAC/D;AAGA,WAAO,KAAK,MAAM,MAAM;AAAA,EAC1B;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/error.ts","../src/orchestrator.ts","../src/component.ts"],"sourcesContent":["export * from \"./orchestrator\";\nexport * from \"./component\";\nexport * from \"./error\";\nexport * from \"./models\";\n","export type PipelineErrorCode =\n | \"PIPELINE_STARTED_TWICE\"\n | \"COMPONENT_FAILED\"\n | \"COMPONENT_DONE_WITH_NOTHING_TO_GIVE\";\n\nexport class PipelineError extends Error {\n readonly code: PipelineErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(\n code: PipelineErrorCode,\n opts?: { cause?: unknown; details?: Record<string, unknown> },\n ) {\n super(code, { cause: opts?.cause });\n this.name = new.target.name;\n this.code = code;\n this.details = opts?.details;\n }\n}","import { PipelineError } from \"./error\";\nimport { ComponentInterface, Orchestrator, NonEmpty, AnyComp, ChainableAny, SoftStateCheck } from \"./models\";\n\nclass OrchestratorImpl<S, T extends NonEmpty<AnyComp<S>>> {\n private hasStarted = false;\n private componentError: { component: AnyComp<S>; error: unknown } | undefined;\n\n constructor(\n private readonly state: S,\n private readonly components: T\n ) { }\n\n public async run(input?: T): Promise<T> {\n if (this.hasStarted) {\n throw new PipelineError('PIPELINE_STARTED_TWICE');\n }\n\n this.hasStarted = true;\n\n const priorities = Array.from(new Set(this.components.map(c => c.priority))).sort((a, b) => b - a);\n\n const tieredComponents = priorities.map((p) => ({\n components: this.components.filter(c => c.priority === p),\n anyCouldRun: this.components.some(c => c === this.firstComponent) // First component in pipeline must run first\n }));\n\n this.tryRunComponent(this.firstComponent, input);\n\n while (true) {\n let anyUpperTierCouldRun = false;\n\n outerLoop: for (const compsInTier of tieredComponents) {\n for (const component of compsInTier.components) {\n if (this.componentError) await this.handleError(this.componentError.component, this.componentError.error);\n\n if (this.getDone(component) && this.isLast(component)) return component.give();\n\n if (anyUpperTierCouldRun) break outerLoop;\n\n const canRun = component.canRun({\n state: this.state,\n upstreamCanGive: this.getUpstream(component)?.canGive() ?? true,\n });\n compsInTier.anyCouldRun = compsInTier.anyCouldRun || canRun;\n\n if (canRun) {\n this.tryRunComponent(component);\n }\n }\n\n anyUpperTierCouldRun = compsInTier.anyCouldRun;\n compsInTier.anyCouldRun = false;\n }\n\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n }\n\n private getDone(component: AnyComp<S>): boolean {\n for (let comp: AnyComp<S> | undefined = this.firstComponent; (comp ? this.getIndex(comp) : Infinity) <= this.getIndex(component); comp = this.getDownstream(comp!)) {\n if (!comp!.isDone({\n state: this.state,\n upstreamDone: true,\n upstreamCanGive: this.getUpstream(comp!)?.canGive() ?? true,\n })) return false;\n }\n\n return true;\n }\n\n private tryRunComponent(component: AnyComp<S>, input?: T) {\n const upstreamComponent = this.getUpstream(component);\n\n try {\n const maybePromise = component.run(input ?? upstreamComponent?.give(), {\n state: this.state,\n upstreamDone: upstreamComponent ? this.getDone(upstreamComponent) : true,\n });\n\n if (maybePromise instanceof Promise) {\n maybePromise.catch((error) => this.componentError = { component, error });\n }\n } catch (error) {\n this.componentError = { component, error };\n }\n }\n\n private async handleError(component: AnyComp<S>, error: unknown) {\n const pipelineError = new PipelineError('COMPONENT_FAILED', {\n cause: error,\n details: {\n componentIndex: this.getIndex(component),\n }\n });\n\n await Promise.all(this.components.map(c => c.onPipelineError?.(pipelineError, { state: this.state })));\n\n throw pipelineError;\n }\n\n private getUpstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) - 1];\n }\n\n private getDownstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) + 1];\n }\n\n private isLast(component: AnyComp<S>) {\n return this.getIndex(component) === this.components.length - 1;\n }\n\n private get firstComponent() {\n return this.components[0];\n }\n\n private getIndex(component: AnyComp<S>) {\n return this.components.indexOf(component);\n }\n}\n\nexport function createOrchestrator<\n S,\n const T extends readonly [\n ComponentInterface<any, any, any>,\n ...ComponentInterface<any, any, any>[]\n ]\n>(\n state: S,\n ...components: T\n & ChainableAny<T>\n & SoftStateCheck<S, T>\n): Orchestrator<T> {\n return new OrchestratorImpl<S, any>(\n state,\n components as any\n ) as unknown as Orchestrator<T>;\n}\n","import { PipelineError } from \"./error\";\n\nimport type { ComponentInterface } from \"./models\";\n\nconst DEFAULT_PRIORITY = 0;\n\nexport abstract class Component<I, O, S> implements ComponentInterface<I, O, S> {\n declare readonly __input?: I;\n declare readonly __output?: O;\n\n public readonly priority: number;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority }: { priority?: number } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n }\n\n abstract isDone(ctx: { upstreamDone: boolean; upstreamCanGive: boolean, state: S }): boolean;\n abstract canRun(ctx: { upstreamCanGive: boolean, state: S }): boolean;\n abstract run(input: I | undefined, ctx: { upstreamDone: boolean, state: S }): void | Promise<void>;\n\n canGive(): boolean {\n return this.queue.length > 0;\n }\n\n give(): O {\n if (this.queue.length === 0) {\n throw new PipelineError('COMPONENT_DONE_WITH_NOTHING_TO_GIVE');\n }\n\n // It is legitimate that O == undefined\n return this.queue.shift()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AAgB,KAAK,SAAS,SAAS;AAAA,MACzC;AAAA,IACF,CAAC;AAED,UAAM,QAAQ,IAAI,KAAK,WAAW,IAAI,OAAK,EAAE,kBAAkB,eAAe,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC;AAErG,UAAM;AAAA,EACR;AAAA,EAEQ,YAAY,WAA+C;AACjE,WAAO,KAAK,WAAW,KAAK,SAAS,SAAS,IAAI,CAAC;AAAA,EACrD;AAAA,EAEQ,cAAc,WAA+C;AACnE,WAAO,KAAK,WAAW,KAAK,SAAS,SAAS,IAAI,CAAC;AAAA,EACrD;AAAA,EAEQ,OAAO,WAAuB;AACpC,WAAO,KAAK,SAAS,SAAS,MAAM,KAAK,WAAW,SAAS;AAAA,EAC/D;AAAA,EAEA,IAAY,iBAAiB;AAC3B,WAAO,KAAK,WAAW,CAAC;AAAA,EAC1B;AAAA,EAEQ,SAAS,WAAuB;AACtC,WAAO,KAAK,WAAW,QAAQ,SAAS;AAAA,EAC1C;AACF;AAEO,SAAS,mBAOd,UACG,YAGc;AACjB,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;;;ACrIA,IAAM,mBAAmB;AAElB,IAAe,YAAf,MAAyE;AAAA,EAI9D;AAAA,EAEG,QAAa,CAAC;AAAA,EAEjC,YAAY,EAAE,SAAS,IAA2B,CAAC,GAAG;AACpD,SAAK,WAAW,YAAY;AAAA,EAC9B;AAAA,EAMA,UAAmB;AACjB,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAEA,OAAU;AACR,QAAI,KAAK,MAAM,WAAW,GAAG;AAC3B,YAAM,IAAI,cAAc,qCAAqC;AAAA,IAC/D;AAGA,WAAO,KAAK,MAAM,MAAM;AAAA,EAC1B;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -14,7 +14,7 @@ interface ComponentInterface<I, O, S> {
14
14
  state: S;
15
15
  upstreamCanGive: boolean;
16
16
  }) => boolean;
17
- readonly run: (input: I, ctx: {
17
+ readonly run: (input: I | undefined, ctx: {
18
18
  state: S;
19
19
  upstreamDone: boolean;
20
20
  }) => void | Promise<void>;
@@ -90,7 +90,7 @@ declare abstract class Component<I, O, S> implements ComponentInterface<I, O, S>
90
90
  upstreamCanGive: boolean;
91
91
  state: S;
92
92
  }): boolean;
93
- abstract run(input: I, ctx: {
93
+ abstract run(input: I | undefined, ctx: {
94
94
  upstreamDone: boolean;
95
95
  state: S;
96
96
  }): void | Promise<void>;
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ interface ComponentInterface<I, O, S> {
14
14
  state: S;
15
15
  upstreamCanGive: boolean;
16
16
  }) => boolean;
17
- readonly run: (input: I, ctx: {
17
+ readonly run: (input: I | undefined, ctx: {
18
18
  state: S;
19
19
  upstreamDone: boolean;
20
20
  }) => void | Promise<void>;
@@ -90,7 +90,7 @@ declare abstract class Component<I, O, S> implements ComponentInterface<I, O, S>
90
90
  upstreamCanGive: boolean;
91
91
  state: S;
92
92
  }): boolean;
93
- abstract run(input: I, ctx: {
93
+ abstract run(input: I | undefined, ctx: {
94
94
  upstreamDone: boolean;
95
95
  state: S;
96
96
  }): void | Promise<void>;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/error.ts","../src/orchestrator.ts","../src/component.ts"],"sourcesContent":["export type PipelineErrorCode =\n | \"PIPELINE_STARTED_TWICE\"\n | \"COMPONENT_FAILED\"\n | \"COMPONENT_DONE_WITH_NOTHING_TO_GIVE\";\n\nexport class PipelineError extends Error {\n readonly code: PipelineErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(\n code: PipelineErrorCode,\n opts?: { cause?: unknown; details?: Record<string, unknown> },\n ) {\n super(code, { cause: opts?.cause });\n this.name = new.target.name;\n this.code = code;\n this.details = opts?.details;\n }\n}","import { PipelineError } from \"./error\";\nimport { ComponentInterface, Orchestrator, NonEmpty, AnyComp, ChainableAny, SoftStateCheck } from \"./models\";\n\nclass OrchestratorImpl<S, T extends NonEmpty<AnyComp<S>>> {\n private hasStarted = false;\n private componentError: { component: AnyComp<S>; error: unknown } | undefined;\n\n constructor(\n private readonly state: S,\n private readonly components: T\n ) { }\n\n public async run(input?: T): Promise<T> {\n if (this.hasStarted) {\n throw new PipelineError('PIPELINE_STARTED_TWICE');\n }\n\n this.hasStarted = true;\n\n const priorities = Array.from(new Set(this.components.map(c => c.priority))).sort((a, b) => b - a);\n\n const tieredComponents = priorities.map((p) => ({\n components: this.components.filter(c => c.priority === p),\n anyCouldRun: this.components.some(c => c === this.firstComponent) // First component in pipeline must run first\n }));\n\n this.tryRunComponent(this.firstComponent, input);\n\n while (true) {\n let anyUpperTierCouldRun = false;\n\n outerLoop: for (const compsInTier of tieredComponents) {\n for (const component of compsInTier.components) {\n if (this.componentError) await this.handleError(this.componentError.component, this.componentError.error);\n\n if (this.getDone(component) && this.isLast(component)) return component.give();\n\n if (anyUpperTierCouldRun) break outerLoop;\n\n const canRun = component.canRun({\n state: this.state,\n upstreamCanGive: this.getUpstream(component)?.canGive() ?? true,\n });\n compsInTier.anyCouldRun = compsInTier.anyCouldRun || canRun;\n\n if (canRun) {\n this.tryRunComponent(component);\n }\n }\n\n anyUpperTierCouldRun = compsInTier.anyCouldRun;\n compsInTier.anyCouldRun = false;\n }\n\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n }\n\n private getDone(component: AnyComp<S>): boolean {\n for (let comp: AnyComp<S> | undefined = this.firstComponent; (comp ? this.getIndex(comp) : Infinity) <= this.getIndex(component); comp = this.getDownstream(comp!)) {\n if (!comp!.isDone({\n state: this.state,\n upstreamDone: true,\n upstreamCanGive: this.getUpstream(comp!)?.canGive() ?? true,\n })) return false;\n }\n\n return true;\n }\n\n private tryRunComponent(component: AnyComp<S>, input?: T) {\n const upstreamComponent = this.getUpstream(component);\n\n try {\n const maybePromise = component.run(input ?? upstreamComponent?.give(), {\n state: this.state,\n upstreamDone: upstreamComponent ? this.getDone(upstreamComponent) : true,\n });\n\n if (maybePromise instanceof Promise) {\n maybePromise.catch((error) => this.componentError = { component, error });\n }\n } catch (error) {\n this.componentError = { component, error };\n }\n }\n\n private async handleError(component: AnyComp<S>, error: unknown) {\n const pipelineError = new PipelineError('COMPONENT_FAILED', {\n cause: error,\n details: {\n componentIndex: this.getIndex(component),\n }\n });\n\n await Promise.all(this.components.map(c => c.onPipelineError?.(pipelineError, { state: this.state })));\n\n throw pipelineError;\n }\n\n private getUpstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) - 1];\n }\n\n private getDownstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) + 1];\n }\n\n private isLast(component: AnyComp<S>) {\n return this.getIndex(component) === this.components.length - 1;\n }\n\n private get firstComponent() {\n return this.components[0];\n }\n\n private getIndex(component: AnyComp<S>) {\n return this.components.indexOf(component);\n }\n}\n\nexport function createOrchestrator<\n S,\n const T extends readonly [\n ComponentInterface<any, any, any>,\n ...ComponentInterface<any, any, any>[]\n ]\n>(\n state: S,\n ...components: T\n & ChainableAny<T>\n & SoftStateCheck<S, T>\n): Orchestrator<T> {\n return new OrchestratorImpl<S, any>(\n state,\n components as any\n ) as unknown as Orchestrator<T>;\n}\n","import { PipelineError } from \"./error\";\n\nimport type { ComponentInterface } from \"./models\";\n\nconst DEFAULT_PRIORITY = 0;\n\nexport abstract class Component<I, O, S> implements ComponentInterface<I, O, S> {\n declare readonly __input?: I;\n declare readonly __output?: O;\n\n public readonly priority: number;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority }: { priority?: number } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n }\n\n abstract isDone(ctx: { upstreamDone: boolean; upstreamCanGive: boolean, state: S }): boolean;\n abstract canRun(ctx: { upstreamCanGive: boolean, state: S }): boolean;\n abstract run(input: I, ctx: { upstreamDone: boolean, state: S }): void | Promise<void>;\n\n canGive(): boolean {\n return this.queue.length > 0;\n }\n\n give(): O {\n if (this.queue.length === 0) {\n throw new PipelineError('COMPON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AAgB,KAAK,SAAS,SAAS;AAAA,MACzC;AAAA,IACF,CAAC;AAED,UAAM,QAAQ,IAAI,KAAK,WAAW,IAAI,OAAK,EAAE,kBAAkB,eAAe,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC;AAErG,UAAM;AAAA,EACR;AAAA,EAEQ,YAAY,WAA+C;AACjE,WAAO,KAAK,WAAW,KAAK,SAAS,SAAS,IAAI,CAAC;AAAA,EACrD;AAAA,EAEQ,cAAc,WAA+C;AACnE,WAAO,KAAK,WAAW,KAAK,SAAS,SAAS,IAAI,CAAC;AAAA,EACrD;AAAA,EAEQ,OAAO,WAAuB;AACpC,WAAO,KAAK,SAAS,SAAS,MAAM,KAAK,WAAW,SAAS;AAAA,EAC/D;AAAA,EAEA,IAAY,iBAAiB;AAC3B,WAAO,KAAK,WAAW,CAAC;AAAA,EAC1B;AAAA,EAEQ,SAAS,WAAuB;AACtC,WAAO,KAAK,WAAW,QAAQ,SAAS;AAAA,EAC1C;AACF;AAEO,SAAS,mBAOd,UACG,YAGc;AACjB,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;;;ACrIA,IAAM,mBAAmB;AAElB,IAAe,YAAf,MAAyE;AAAA,EAI9D;AAAA,EAEG,QAAa,CAAC;AAAA,EAEjC,YAAY,EAAE,SAAS,IAA2B,CAAC,GAAG;AACpD,SAAK,WAAW,YAAY;AAAA,EAC9B;AAAA,EAMA,UAAmB;AACjB,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAEA,OAAU;AACR,QAAI,KAAK,MAAM,WAAW,GAAG;AAC3B,YAAM,IAAI,cAAc,qCAAqC;AAAA,IAC/D;AAGA,WAAO,KAAK,MAAM,MAAM;AAAA,EAC1B;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/error.ts","../src/orchestrator.ts","../src/component.ts"],"sourcesContent":["export type PipelineErrorCode =\n | \"PIPELINE_STARTED_TWICE\"\n | \"COMPONENT_FAILED\"\n | \"COMPONENT_DONE_WITH_NOTHING_TO_GIVE\";\n\nexport class PipelineError extends Error {\n readonly code: PipelineErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(\n code: PipelineErrorCode,\n opts?: { cause?: unknown; details?: Record<string, unknown> },\n ) {\n super(code, { cause: opts?.cause });\n this.name = new.target.name;\n this.code = code;\n this.details = opts?.details;\n }\n}","import { PipelineError } from \"./error\";\nimport { ComponentInterface, Orchestrator, NonEmpty, AnyComp, ChainableAny, SoftStateCheck } from \"./models\";\n\nclass OrchestratorImpl<S, T extends NonEmpty<AnyComp<S>>> {\n private hasStarted = false;\n private componentError: { component: AnyComp<S>; error: unknown } | undefined;\n\n constructor(\n private readonly state: S,\n private readonly components: T\n ) { }\n\n public async run(input?: T): Promise<T> {\n if (this.hasStarted) {\n throw new PipelineError('PIPELINE_STARTED_TWICE');\n }\n\n this.hasStarted = true;\n\n const priorities = Array.from(new Set(this.components.map(c => c.priority))).sort((a, b) => b - a);\n\n const tieredComponents = priorities.map((p) => ({\n components: this.components.filter(c => c.priority === p),\n anyCouldRun: this.components.some(c => c === this.firstComponent) // First component in pipeline must run first\n }));\n\n this.tryRunComponent(this.firstComponent, input);\n\n while (true) {\n let anyUpperTierCouldRun = false;\n\n outerLoop: for (const compsInTier of tieredComponents) {\n for (const component of compsInTier.components) {\n if (this.componentError) await this.handleError(this.componentError.component, this.componentError.error);\n\n if (this.getDone(component) && this.isLast(component)) return component.give();\n\n if (anyUpperTierCouldRun) break outerLoop;\n\n const canRun = component.canRun({\n state: this.state,\n upstreamCanGive: this.getUpstream(component)?.canGive() ?? true,\n });\n compsInTier.anyCouldRun = compsInTier.anyCouldRun || canRun;\n\n if (canRun) {\n this.tryRunComponent(component);\n }\n }\n\n anyUpperTierCouldRun = compsInTier.anyCouldRun;\n compsInTier.anyCouldRun = false;\n }\n\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n }\n\n private getDone(component: AnyComp<S>): boolean {\n for (let comp: AnyComp<S> | undefined = this.firstComponent; (comp ? this.getIndex(comp) : Infinity) <= this.getIndex(component); comp = this.getDownstream(comp!)) {\n if (!comp!.isDone({\n state: this.state,\n upstreamDone: true,\n upstreamCanGive: this.getUpstream(comp!)?.canGive() ?? true,\n })) return false;\n }\n\n return true;\n }\n\n private tryRunComponent(component: AnyComp<S>, input?: T) {\n const upstreamComponent = this.getUpstream(component);\n\n try {\n const maybePromise = component.run(input ?? upstreamComponent?.give(), {\n state: this.state,\n upstreamDone: upstreamComponent ? this.getDone(upstreamComponent) : true,\n });\n\n if (maybePromise instanceof Promise) {\n maybePromise.catch((error) => this.componentError = { component, error });\n }\n } catch (error) {\n this.componentError = { component, error };\n }\n }\n\n private async handleError(component: AnyComp<S>, error: unknown) {\n const pipelineError = new PipelineError('COMPONENT_FAILED', {\n cause: error,\n details: {\n componentIndex: this.getIndex(component),\n }\n });\n\n await Promise.all(this.components.map(c => c.onPipelineError?.(pipelineError, { state: this.state })));\n\n throw pipelineError;\n }\n\n private getUpstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) - 1];\n }\n\n private getDownstream(component: AnyComp<S>): AnyComp<S> | undefined {\n return this.components[this.getIndex(component) + 1];\n }\n\n private isLast(component: AnyComp<S>) {\n return this.getIndex(component) === this.components.length - 1;\n }\n\n private get firstComponent() {\n return this.components[0];\n }\n\n private getIndex(component: AnyComp<S>) {\n return this.components.indexOf(component);\n }\n}\n\nexport function createOrchestrator<\n S,\n const T extends readonly [\n ComponentInterface<any, any, any>,\n ...ComponentInterface<any, any, any>[]\n ]\n>(\n state: S,\n ...components: T\n & ChainableAny<T>\n & SoftStateCheck<S, T>\n): Orchestrator<T> {\n return new OrchestratorImpl<S, any>(\n state,\n components as any\n ) as unknown as Orchestrator<T>;\n}\n","import { PipelineError } from \"./error\";\n\nimport type { ComponentInterface } from \"./models\";\n\nconst DEFAULT_PRIORITY = 0;\n\nexport abstract class Component<I, O, S> implements ComponentInterface<I, O, S> {\n declare readonly __input?: I;\n declare readonly __output?: O;\n\n public readonly priority: number;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority }: { priority?: number } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n }\n\n abstract isDone(ctx: { upstreamDone: boolean; upstreamCanGive: boolean, state: S }): boolean;\n abstract canRun(ctx: { upstreamCanGive: boolean, state: S }): boolean;\n abstract run(input: I | undefined, ctx: { upstreamDone: boolean, state: S }): void | Promise<void>;\n\n canGive(): boolean {\n return this.queue.length > 0;\n }\n\n give(): O {\n if (this.queue.length === 0) {\n throw new PipelineError('COMPONENT_DONE_WITH_NOTHING_TO_GIVE');\n }\n\n // It is legitimate that O == undefined\n return this.queue.shift() as O;\n }\n}\n"],"mappings":";AAKO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YACE,MACA,MACA;AACA,UAAM,MAAM,EAAE,OAAO,MAAM,MAAM,CAAC;AAClC,SAAK,OAAO,WAAW;AACvB,SAAK,OAAO;AACZ,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;;;ACfA,IAAM,mBAAN,MAA0D;AAAA,EAIxD,YACmB,OACA,YACjB;AAFiB;AACA;AAAA,EACf;AAAA,EANI,aAAa;AAAA,EACb;AAAA,EAOR,MAAa,IAAI,OAAuB;AACtC,QAAI,KAAK,YAAY;AACnB,YAAM,IAAI,cAAc,wBAAwB;AAAA,IAClD;AAEA,SAAK,aAAa;AAElB,UAAM,aAAa,MAAM,KAAK,IAAI,IAAI,KAAK,WAAW,IAAI,OAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAEjG,UAAM,mBAAmB,WAAW,IAAI,CAAC,OAAO;AAAA,MAC9C,YAAY,KAAK,WAAW,OAAO,OAAK,EAAE,aAAa,CAAC;AAAA,MACxD,aAAa,KAAK,WAAW,KAAK,OAAK,MAAM,KAAK,cAAc;AAAA;AAAA,IAClE,EAAE;AAEF,SAAK,gBAAgB,KAAK,g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A,EAMA,UAAmB;AACjB,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAEA,OAAU;AACR,QAAI,KAAK,MAAM,WAAW,GAAG;AAC3B,YAAM,IAAI,cAAc,qCAAqC;AAAA,IAC/D;AAGA,WAAO,KAAK,MAAM,MAAM;AAAA,EAC1B;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "priority-pipeline",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Typescript prioritized pipeline of workers",
5
5
  "type": "module",
6
6
  "sideEffects": false,