priority-pipeline 0.0.6 → 0.0.7

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.
package/dist/index.cjs CHANGED
@@ -152,9 +152,6 @@ var Component = class {
152
152
  return this.queue.length > 0;
153
153
  }
154
154
  give() {
155
- if (this.queue.length === 0) {
156
- throw new PipelineError("COMPONENT_DONE_WITH_NOTHING_TO_GIVE");
157
- }
158
155
  return this.queue.shift();
159
156
  }
160
157
  };
@@ -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 componentName: component.name,\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 public readonly name?: string;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority, name }: { priority?: number; name?: string } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n this.name = name;\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":";;;;;;;;;;;;;;;;;;;;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;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,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;;;ACtIA,IAAM,mBAAmB;AAElB,IAAe,YAAf,MAAyE;AAAA,EAI9D;AAAA,EACA;AAAA,EAEG,QAAa,CAAC;AAAA,EAEjC,YAAY,EAAE,UAAU,KAAK,IAA0C,CAAC,GAAG;AACzE,SAAK,WAAW,YAAY;AAC5B,SAAK,OAAO;AAAA,EACd;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\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 componentName: component.name,\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 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 public readonly name?: string;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority, name }: { priority?: number; name?: string } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n this.name = name;\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 | undefined {\n return this.queue.shift();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,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;;;ACdA,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,gBAAgB,KAAK;AAE/C,WAAO,MAAM;AACX,UAAI,uBAAuB;AAE3B,gBAAW,YAAW,eAAe,kBAAkB;AACrD,mBAAW,aAAa,YAAY,YAAY;AAC9C,cAAI,KAAK,eAAgB,OAAM,KAAK,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AAM,MAAM;AAAA,EAC1B;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- type PipelineErrorCode = "PIPELINE_STARTED_TWICE" | "COMPONENT_FAILED" | "COMPONENT_DONE_WITH_NOTHING_TO_GIVE";
1
+ type PipelineErrorCode = "PIPELINE_STARTED_TWICE" | "COMPONENT_FAILED";
2
2
  declare class PipelineError extends Error {
3
3
  readonly code: PipelineErrorCode;
4
4
  readonly details?: Record<string, unknown>;
@@ -20,7 +20,7 @@ interface ComponentInterface<I, O, S> {
20
20
  upstreamDone: boolean;
21
21
  }) => void | Promise<void>;
22
22
  readonly canGive: () => boolean;
23
- readonly give: () => O;
23
+ readonly give: () => O | undefined;
24
24
  readonly isDone: (ctx: {
25
25
  state: S;
26
26
  upstreamDone: boolean;
@@ -98,7 +98,7 @@ declare abstract class Component<I, O, S> implements ComponentInterface<I, O, S>
98
98
  state: S;
99
99
  }): void | Promise<void>;
100
100
  canGive(): boolean;
101
- give(): O;
101
+ give(): O | undefined;
102
102
  }
103
103
 
104
104
  export { type AnyComp, type ChainableAny, Component, type ComponentInterface, type First, type FirstInput, type In, type InputOf, type Last, type LastOutput, type NonEmpty, type NonEmptyComponents, type Orchestrator, type Out, type OutputOf, PipelineError, type PipelineErrorCode, type RunArgs, type SoftStateCheck, type State, createOrchestrator };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type PipelineErrorCode = "PIPELINE_STARTED_TWICE" | "COMPONENT_FAILED" | "COMPONENT_DONE_WITH_NOTHING_TO_GIVE";
1
+ type PipelineErrorCode = "PIPELINE_STARTED_TWICE" | "COMPONENT_FAILED";
2
2
  declare class PipelineError extends Error {
3
3
  readonly code: PipelineErrorCode;
4
4
  readonly details?: Record<string, unknown>;
@@ -20,7 +20,7 @@ interface ComponentInterface<I, O, S> {
20
20
  upstreamDone: boolean;
21
21
  }) => void | Promise<void>;
22
22
  readonly canGive: () => boolean;
23
- readonly give: () => O;
23
+ readonly give: () => O | undefined;
24
24
  readonly isDone: (ctx: {
25
25
  state: S;
26
26
  upstreamDone: boolean;
@@ -98,7 +98,7 @@ declare abstract class Component<I, O, S> implements ComponentInterface<I, O, S>
98
98
  state: S;
99
99
  }): void | Promise<void>;
100
100
  canGive(): boolean;
101
- give(): O;
101
+ give(): O | undefined;
102
102
  }
103
103
 
104
104
  export { type AnyComp, type ChainableAny, Component, type ComponentInterface, type First, type FirstInput, type In, type InputOf, type Last, type LastOutput, type NonEmpty, type NonEmptyComponents, type Orchestrator, type Out, type OutputOf, PipelineError, type PipelineErrorCode, type RunArgs, type SoftStateCheck, type State, createOrchestrator };
package/dist/index.js CHANGED
@@ -124,9 +124,6 @@ var Component = class {
124
124
  return this.queue.length > 0;
125
125
  }
126
126
  give() {
127
- if (this.queue.length === 0) {
128
- throw new PipelineError("COMPONENT_DONE_WITH_NOTHING_TO_GIVE");
129
- }
130
127
  return this.queue.shift();
131
128
  }
132
129
  };
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 componentName: component.name,\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 public readonly name?: string;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority, name }: { priority?: number; name?: string } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n this.name = name;\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"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,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;;;ACtIA,IAAM,mBAAmB;AAElB,IAAe,YAAf,MAAyE;AAAA,EAI9D;AAAA,EACA;AAAA,EAEG,QAAa,CAAC;AAAA,EAEjC,YAAY,EAAE,UAAU,KAAK,IAA0C,CAAC,GAAG;AACzE,SAAK,WAAW,YAAY;AAC5B,SAAK,OAAO;AAAA,EACd;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\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 componentName: component.name,\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 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 public readonly name?: string;\n\n protected readonly queue: O[] = [];\n\n constructor({ priority, name }: { priority?: number; name?: string } = {}) {\n this.priority = priority ?? DEFAULT_PRIORITY;\n this.name = name;\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 | undefined {\n return this.queue.shift();\n }\n}\n"],"mappings":";AAIO,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;;;ACdA,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,gBAAgB,KAAK;AAE/C,WAAO,MAAM;AACX,UAAI,uBAAuB;AAE3B,gBAAW,YAAW,eAAe,kBAAkB;AACrD,mBAAW,aAAa,YAAY,YAAY;AAC9C,cAAI,KAA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B;AACpB,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.6",
3
+ "version": "0.0.7",
4
4
  "description": "Typescript prioritized pipeline of workers",
5
5
  "type": "module",
6
6
  "sideEffects": false,