@n8n/engine 0.12.0 → 0.14.0

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.
Files changed (116) hide show
  1. package/dist/admittance/admittance-rejected.error.d.ts +4 -0
  2. package/dist/admittance/admittance-rejected.error.js +13 -0
  3. package/dist/admittance/admittance-rejected.error.js.map +1 -0
  4. package/dist/admittance/admittance.types.d.ts +12 -0
  5. package/dist/admittance/admittance.types.js +3 -0
  6. package/dist/admittance/admittance.types.js.map +1 -0
  7. package/dist/admittance/allow-all-admittance.d.ts +4 -0
  8. package/dist/admittance/allow-all-admittance.js +10 -0
  9. package/dist/admittance/allow-all-admittance.js.map +1 -0
  10. package/dist/admittance/index.d.ts +3 -0
  11. package/dist/admittance/index.js +8 -0
  12. package/dist/admittance/index.js.map +1 -0
  13. package/dist/build.tsbuildinfo +1 -1
  14. package/dist/common/errors.d.ts +3 -0
  15. package/dist/common/errors.js +11 -0
  16. package/dist/common/errors.js.map +1 -0
  17. package/dist/common/index.d.ts +2 -0
  18. package/dist/common/index.js +6 -0
  19. package/dist/common/index.js.map +1 -0
  20. package/dist/common/json.d.ts +4 -0
  21. package/dist/common/json.js +3 -0
  22. package/dist/common/json.js.map +1 -0
  23. package/dist/database/data-source.d.ts +3 -0
  24. package/dist/database/data-source.js +19 -0
  25. package/dist/database/data-source.js.map +1 -0
  26. package/dist/database/entities/index.d.ts +5 -0
  27. package/dist/database/entities/index.js +9 -0
  28. package/dist/database/entities/index.js.map +1 -0
  29. package/dist/database/entities/workflow-execution.entity.d.ts +15 -0
  30. package/dist/database/entities/workflow-execution.entity.js +78 -0
  31. package/dist/database/entities/workflow-execution.entity.js.map +1 -0
  32. package/dist/database/entities/workflow-step-execution.entity.d.ts +14 -0
  33. package/dist/database/entities/workflow-step-execution.entity.js +72 -0
  34. package/dist/database/entities/workflow-step-execution.entity.js.map +1 -0
  35. package/dist/database/generate-id.d.ts +1 -0
  36. package/dist/database/generate-id.js +8 -0
  37. package/dist/database/generate-id.js.map +1 -0
  38. package/dist/database/index.d.ts +4 -0
  39. package/dist/database/index.js +13 -0
  40. package/dist/database/index.js.map +1 -0
  41. package/dist/database/migrations/1778529600000-CreateWorkflowExecution.d.ts +5 -0
  42. package/dist/database/migrations/1778529600000-CreateWorkflowExecution.js +48 -0
  43. package/dist/database/migrations/1778529600000-CreateWorkflowExecution.js.map +1 -0
  44. package/dist/database/migrations/1784890100000-CreateWorkflowStepExecution.d.ts +5 -0
  45. package/dist/database/migrations/1784890100000-CreateWorkflowStepExecution.js +67 -0
  46. package/dist/database/migrations/1784890100000-CreateWorkflowStepExecution.js.map +1 -0
  47. package/dist/database/migrations/index.d.ts +2 -0
  48. package/dist/database/migrations/index.js +10 -0
  49. package/dist/database/migrations/index.js.map +1 -0
  50. package/dist/database/typeorm-execution-store.d.ts +13 -0
  51. package/dist/database/typeorm-execution-store.js +27 -0
  52. package/dist/database/typeorm-execution-store.js.map +1 -0
  53. package/dist/database/typeorm-step-store.d.ts +17 -0
  54. package/dist/database/typeorm-step-store.js +51 -0
  55. package/dist/database/typeorm-step-store.js.map +1 -0
  56. package/dist/dependencies/external-dependencies.d.ts +23 -0
  57. package/dist/dependencies/external-dependencies.js +3 -0
  58. package/dist/dependencies/external-dependencies.js.map +1 -0
  59. package/dist/dependencies/index.d.ts +1 -0
  60. package/dist/dependencies/index.js +3 -0
  61. package/dist/dependencies/index.js.map +1 -0
  62. package/dist/execution/execution-start-handler.d.ts +10 -0
  63. package/dist/execution/execution-start-handler.js +43 -0
  64. package/dist/execution/execution-start-handler.js.map +1 -0
  65. package/dist/execution/execution-store.d.ts +29 -0
  66. package/dist/execution/execution-store.js +13 -0
  67. package/dist/execution/execution-store.js.map +1 -0
  68. package/dist/execution/execution.types.d.ts +3 -0
  69. package/dist/execution/execution.types.js +3 -0
  70. package/dist/execution/execution.types.js.map +1 -0
  71. package/dist/execution/index.d.ts +9 -0
  72. package/dist/execution/index.js +14 -0
  73. package/dist/execution/index.js.map +1 -0
  74. package/dist/execution/orchestration-worker.d.ts +9 -0
  75. package/dist/execution/orchestration-worker.js +28 -0
  76. package/dist/execution/orchestration-worker.js.map +1 -0
  77. package/dist/execution/start-execution.service.d.ts +22 -0
  78. package/dist/execution/start-execution.service.js +34 -0
  79. package/dist/execution/start-execution.service.js.map +1 -0
  80. package/dist/execution/step-store.d.ts +35 -0
  81. package/dist/execution/step-store.js +13 -0
  82. package/dist/execution/step-store.js.map +1 -0
  83. package/dist/graph/index.d.ts +2 -0
  84. package/dist/graph/index.js +7 -0
  85. package/dist/graph/index.js.map +1 -0
  86. package/dist/graph/workflow-graph-queries.d.ts +3 -0
  87. package/dist/graph/workflow-graph-queries.js +17 -0
  88. package/dist/graph/workflow-graph-queries.js.map +1 -0
  89. package/dist/graph/workflow-graph.d.ts +19 -0
  90. package/dist/graph/workflow-graph.js +3 -0
  91. package/dist/graph/workflow-graph.js.map +1 -0
  92. package/dist/index.d.ts +11 -0
  93. package/dist/index.js +15 -1
  94. package/dist/index.js.map +1 -1
  95. package/dist/queue/in-memory-work-queue.d.ts +12 -0
  96. package/dist/queue/in-memory-work-queue.js +53 -0
  97. package/dist/queue/in-memory-work-queue.js.map +1 -0
  98. package/dist/queue/index.d.ts +2 -0
  99. package/dist/queue/index.js +6 -0
  100. package/dist/queue/index.js.map +1 -0
  101. package/dist/queue/work-queue.types.d.ts +16 -0
  102. package/dist/queue/work-queue.types.js +3 -0
  103. package/dist/queue/work-queue.types.js.map +1 -0
  104. package/dist/serve.js +56 -19
  105. package/dist/serve.js.map +1 -1
  106. package/dist/server/create-engine-server.d.ts +9 -1
  107. package/dist/server/create-engine-server.js +10 -1
  108. package/dist/server/create-engine-server.js.map +1 -1
  109. package/dist/server/index.d.ts +1 -0
  110. package/dist/server/routes/workflow-executions.d.ts +3 -0
  111. package/dist/server/routes/workflow-executions.js +65 -0
  112. package/dist/server/routes/workflow-executions.js.map +1 -0
  113. package/dist/testing/start-engine-server.d.ts +2 -1
  114. package/dist/testing/start-engine-server.js +2 -2
  115. package/dist/testing/start-engine-server.js.map +1 -1
  116. package/package.json +9 -2
@@ -0,0 +1,23 @@
1
+ import type { JsonValue } from '../common';
2
+ import type { ExecutionMode } from '../execution';
3
+ import type { GraphNode } from '../graph';
4
+ export interface StepExecutionContext {
5
+ executionId: string;
6
+ stepId: string;
7
+ workflowId: string;
8
+ mode: ExecutionMode;
9
+ }
10
+ export interface StepExecutionRequest {
11
+ node: GraphNode;
12
+ inputs: JsonValue;
13
+ context: StepExecutionContext;
14
+ }
15
+ export interface StepExecutionResult {
16
+ outputs: JsonValue;
17
+ }
18
+ export interface IStepExecutor {
19
+ execute(request: StepExecutionRequest): Promise<StepExecutionResult>;
20
+ }
21
+ export interface ExternalDependencies {
22
+ v1StepExecutor?: IStepExecutor;
23
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=external-dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external-dependencies.js","sourceRoot":"","sources":["../../src/dependencies/external-dependencies.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export type { ExternalDependencies, IStepExecutor, StepExecutionContext, StepExecutionRequest, StepExecutionResult, } from './external-dependencies';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dependencies/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { ExecutionEnqueuedEvent, StepMessage, WorkQueue } from '../queue';
2
+ import type { ExecutionStore } from './execution-store';
3
+ import type { StepStore } from './step-store';
4
+ export declare class ExecutionStartHandler {
5
+ private readonly executionStore;
6
+ private readonly stepStore;
7
+ private readonly stepQueue;
8
+ constructor(executionStore: ExecutionStore, stepStore: StepStore, stepQueue: WorkQueue<StepMessage>);
9
+ handle(event: ExecutionEnqueuedEvent): Promise<void>;
10
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExecutionStartHandler = void 0;
4
+ const graph_1 = require("../graph");
5
+ class ExecutionStartHandler {
6
+ executionStore;
7
+ stepStore;
8
+ stepQueue;
9
+ constructor(executionStore, stepStore, stepQueue) {
10
+ this.executionStore = executionStore;
11
+ this.stepStore = stepStore;
12
+ this.stepQueue = stepQueue;
13
+ }
14
+ async handle(event) {
15
+ const claimed = await this.executionStore.transitionStatus(event.executionId, 'queued', 'running');
16
+ if (!claimed)
17
+ return;
18
+ const execution = await this.executionStore.loadExecution(event.executionId);
19
+ const trigger = (0, graph_1.findTriggerNode)(execution.graph);
20
+ if (!trigger) {
21
+ await this.executionStore.transitionStatus(event.executionId, 'running', 'failed');
22
+ return;
23
+ }
24
+ const successorNodeIds = (0, graph_1.getSuccessorNodeIds)(execution.graph, trigger.id);
25
+ const [, ...successorSteps] = await this.stepStore.createSteps([
26
+ { executionId: event.executionId, nodeId: trigger.id, status: 'completed' },
27
+ ...successorNodeIds.map((nodeId) => ({
28
+ executionId: event.executionId,
29
+ nodeId,
30
+ status: 'queued',
31
+ })),
32
+ ]);
33
+ for (const { id: stepId } of successorSteps) {
34
+ await this.stepQueue.publish({
35
+ type: 'step:ready',
36
+ executionId: event.executionId,
37
+ stepId,
38
+ });
39
+ }
40
+ }
41
+ }
42
+ exports.ExecutionStartHandler = ExecutionStartHandler;
43
+ //# sourceMappingURL=execution-start-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-start-handler.js","sourceRoot":"","sources":["../../src/execution/execution-start-handler.ts"],"names":[],"mappings":";;;AAAA,oCAAgE;AAUhE;IAEmB,cAAc;IACd,SAAS;IACT,SAAS;IAH3B,YACkB,cAA8B,EAC9B,SAAoB,EACpB,SAAiC;8BAFjC,cAAc;yBACd,SAAS;yBACT,SAAS;IACxB,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,KAA6B;QAEzC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,gBAAgB,CACzD,KAAK,CAAC,WAAW,EACjB,QAAQ,EACR,SAAS,CACT,CAAC;QACF,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAE7E,MAAM,OAAO,GAAG,IAAA,uBAAe,EAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,EAAE,CAAC;YAEd,MAAM,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;YACnF,OAAO;QACR,CAAC;QAKD,MAAM,gBAAgB,GAAG,IAAA,2BAAmB,EAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAC1E,MAAM,CAAC,EAAE,GAAG,cAAc,CAAC,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;YAC9D,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;YAC3E,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBACpC,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,MAAM;gBACN,MAAM,EAAE,QAAiB;aACzB,CAAC,CAAC;SACH,CAAC,CAAC;QAGH,KAAK,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,cAAc,EAAE,CAAC;YAC7C,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gBAC5B,IAAI,EAAE,YAAY;gBAClB,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,MAAM;aACN,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,29 @@
1
+ import type { JsonObject } from '../common';
2
+ import type { WorkflowGraph } from '../graph';
3
+ import type { ExecutionMode, ExecutionStatus } from './execution.types';
4
+ export interface NewExecutionRecord {
5
+ workflowId: string;
6
+ status: ExecutionStatus;
7
+ mode: ExecutionMode;
8
+ graph: WorkflowGraph;
9
+ triggerPayload: JsonObject | null;
10
+ }
11
+ export interface ExecutionRecord {
12
+ id: string;
13
+ workflowId: string;
14
+ status: ExecutionStatus;
15
+ mode: ExecutionMode;
16
+ graph: WorkflowGraph;
17
+ triggerPayload: JsonObject | null;
18
+ }
19
+ export declare class ExecutionNotFoundError extends Error {
20
+ readonly executionId: string;
21
+ constructor(executionId: string);
22
+ }
23
+ export interface ExecutionStore {
24
+ createExecution(record: NewExecutionRecord): Promise<{
25
+ id: string;
26
+ }>;
27
+ loadExecution(id: string): Promise<ExecutionRecord>;
28
+ transitionStatus(id: string, from: ExecutionStatus, to: ExecutionStatus): Promise<boolean>;
29
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExecutionNotFoundError = void 0;
4
+ class ExecutionNotFoundError extends Error {
5
+ executionId;
6
+ constructor(executionId) {
7
+ super(`Execution not found: ${executionId}`);
8
+ this.executionId = executionId;
9
+ this.name = 'ExecutionNotFoundError';
10
+ }
11
+ }
12
+ exports.ExecutionNotFoundError = ExecutionNotFoundError;
13
+ //# sourceMappingURL=execution-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-store.js","sourceRoot":"","sources":["../../src/execution/execution-store.ts"],"names":[],"mappings":";;;AAwBA,4BAAoC,SAAQ,KAAK;IAC3B,WAAW;IAAhC,YAAqB,WAAmB;QACvC,KAAK,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAC;2BADzB,WAAW;QAE/B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACtC,CAAC;CACD"}
@@ -0,0 +1,3 @@
1
+ export type ExecutionStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
2
+ export type ExecutionMode = 'production' | 'manual';
3
+ export type StepStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=execution.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.types.js","sourceRoot":"","sources":["../../src/execution/execution.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export { StartExecutionService } from './start-execution.service';
2
+ export type { StartExecutionRequest, StartExecutionResult, } from './start-execution.service';
3
+ export type { ExecutionMode, ExecutionStatus, StepStatus } from './execution.types';
4
+ export { ExecutionNotFoundError } from './execution-store';
5
+ export type { ExecutionRecord, ExecutionStore, NewExecutionRecord } from './execution-store';
6
+ export { StepNotFoundError } from './step-store';
7
+ export type { NewStepRecord, StepError, StepRecord, StepStore } from './step-store';
8
+ export { ExecutionStartHandler } from './execution-start-handler';
9
+ export { OrchestrationWorker } from './orchestration-worker';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrchestrationWorker = exports.ExecutionStartHandler = exports.StepNotFoundError = exports.ExecutionNotFoundError = exports.StartExecutionService = void 0;
4
+ var start_execution_service_1 = require("./start-execution.service");
5
+ Object.defineProperty(exports, "StartExecutionService", { enumerable: true, get: function () { return start_execution_service_1.StartExecutionService; } });
6
+ var execution_store_1 = require("./execution-store");
7
+ Object.defineProperty(exports, "ExecutionNotFoundError", { enumerable: true, get: function () { return execution_store_1.ExecutionNotFoundError; } });
8
+ var step_store_1 = require("./step-store");
9
+ Object.defineProperty(exports, "StepNotFoundError", { enumerable: true, get: function () { return step_store_1.StepNotFoundError; } });
10
+ var execution_start_handler_1 = require("./execution-start-handler");
11
+ Object.defineProperty(exports, "ExecutionStartHandler", { enumerable: true, get: function () { return execution_start_handler_1.ExecutionStartHandler; } });
12
+ var orchestration_worker_1 = require("./orchestration-worker");
13
+ Object.defineProperty(exports, "OrchestrationWorker", { enumerable: true, get: function () { return orchestration_worker_1.OrchestrationWorker; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/execution/index.ts"],"names":[],"mappings":";;;AAAA,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAM9B,qDAA2D;AAAlD,yHAAA,sBAAsB,OAAA;AAE/B,2CAAiD;AAAxC,+GAAA,iBAAiB,OAAA;AAE1B,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,+DAA6D;AAApD,2HAAA,mBAAmB,OAAA"}
@@ -0,0 +1,9 @@
1
+ import type { OrchestrationMessage, WorkQueue } from '../queue';
2
+ import type { ExecutionStartHandler } from './execution-start-handler';
3
+ export declare class OrchestrationWorker {
4
+ private readonly orchestrationQueue;
5
+ private readonly startHandler;
6
+ constructor(orchestrationQueue: WorkQueue<OrchestrationMessage>, startHandler: ExecutionStartHandler);
7
+ start(): void;
8
+ stop(): Promise<void>;
9
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrchestrationWorker = void 0;
4
+ const common_1 = require("../common");
5
+ class OrchestrationWorker {
6
+ orchestrationQueue;
7
+ startHandler;
8
+ constructor(orchestrationQueue, startHandler) {
9
+ this.orchestrationQueue = orchestrationQueue;
10
+ this.startHandler = startHandler;
11
+ }
12
+ start() {
13
+ this.orchestrationQueue.start(async (message) => {
14
+ switch (message.type) {
15
+ case 'execution:enqueued':
16
+ await this.startHandler.handle(message);
17
+ break;
18
+ default:
19
+ throw new common_1.UnimplementedError(`orchestration worker received an unimplemented message type: ${String(message.type)}`);
20
+ }
21
+ });
22
+ }
23
+ async stop() {
24
+ await this.orchestrationQueue.stop();
25
+ }
26
+ }
27
+ exports.OrchestrationWorker = OrchestrationWorker;
28
+ //# sourceMappingURL=orchestration-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-worker.js","sourceRoot":"","sources":["../../src/execution/orchestration-worker.ts"],"names":[],"mappings":";;;AAAA,sCAA+C;AAO/C;IAEmB,kBAAkB;IAClB,YAAY;IAF9B,YACkB,kBAAmD,EACnD,YAAmC;kCADnC,kBAAkB;4BAClB,YAAY;IAC3B,CAAC;IAEJ,KAAK;QACJ,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAC/C,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;gBACtB,KAAK,oBAAoB;oBACxB,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;oBACxC,MAAM;gBACP;oBACC,MAAM,IAAI,2BAAkB,CAC3B,gEAAgE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CACtF,CAAC;YACJ,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI;QACT,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;CACD"}
@@ -0,0 +1,22 @@
1
+ import { type AdmittanceService } from '../admittance';
2
+ import type { JsonObject } from '../common';
3
+ import type { WorkflowGraph } from '../graph';
4
+ import type { OrchestrationMessage, WorkQueue } from '../queue';
5
+ import type { ExecutionStore } from './execution-store';
6
+ import type { ExecutionMode } from './execution.types';
7
+ export interface StartExecutionRequest {
8
+ workflowId: string;
9
+ graph: WorkflowGraph;
10
+ triggerPayload?: JsonObject | null;
11
+ mode?: ExecutionMode;
12
+ }
13
+ export interface StartExecutionResult {
14
+ executionId: string;
15
+ }
16
+ export declare class StartExecutionService {
17
+ private readonly admittance;
18
+ private readonly executionStore;
19
+ private readonly workQueue;
20
+ constructor(admittance: AdmittanceService, executionStore: ExecutionStore, workQueue: WorkQueue<OrchestrationMessage>);
21
+ start(request: StartExecutionRequest): Promise<StartExecutionResult>;
22
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartExecutionService = void 0;
4
+ const admittance_1 = require("../admittance");
5
+ class StartExecutionService {
6
+ admittance;
7
+ executionStore;
8
+ workQueue;
9
+ constructor(admittance, executionStore, workQueue) {
10
+ this.admittance = admittance;
11
+ this.executionStore = executionStore;
12
+ this.workQueue = workQueue;
13
+ }
14
+ async start(request) {
15
+ const decision = await this.admittance.evaluate({ workflowId: request.workflowId });
16
+ if (!decision.accept) {
17
+ throw new admittance_1.AdmittanceRejectedError(decision.reason);
18
+ }
19
+ const { id } = await this.executionStore.createExecution({
20
+ workflowId: request.workflowId,
21
+ status: 'queued',
22
+ mode: request.mode ?? 'production',
23
+ graph: request.graph,
24
+ triggerPayload: request.triggerPayload ?? null,
25
+ });
26
+ await this.workQueue.publish({
27
+ type: 'execution:enqueued',
28
+ executionId: id,
29
+ });
30
+ return { executionId: id };
31
+ }
32
+ }
33
+ exports.StartExecutionService = StartExecutionService;
34
+ //# sourceMappingURL=start-execution.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-execution.service.js","sourceRoot":"","sources":["../../src/execution/start-execution.service.ts"],"names":[],"mappings":";;;AAAA,8CAAgF;AAkBhF;IAEmB,UAAU;IACV,cAAc;IACd,SAAS;IAH3B,YACkB,UAA6B,EAC7B,cAA8B,EAC9B,SAA0C;0BAF1C,UAAU;8BACV,cAAc;yBACd,SAAS;IACxB,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,OAA8B;QACzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QACpF,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,IAAI,oCAAuB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACpD,CAAC;QAED,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC;YACxD,UAAU,EAAE,OAAO,CAAC,UAAU;YAE9B,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,YAAY;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,IAAI;SAC9C,CAAC,CAAC;QAKH,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;YAC5B,IAAI,EAAE,oBAAoB;YAC1B,WAAW,EAAE,EAAE;SACf,CAAC,CAAC;QAEH,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IAC5B,CAAC;CACD"}
@@ -0,0 +1,35 @@
1
+ import type { JsonValue } from '../common';
2
+ import type { StepStatus } from './execution.types';
3
+ export interface NewStepRecord {
4
+ executionId: string;
5
+ nodeId: string;
6
+ status: StepStatus;
7
+ }
8
+ export interface StepError {
9
+ name: string;
10
+ message: string;
11
+ stack?: string;
12
+ details?: JsonValue;
13
+ }
14
+ export interface StepRecord {
15
+ id: string;
16
+ executionId: string;
17
+ nodeId: string;
18
+ status: StepStatus;
19
+ outputs: JsonValue | null;
20
+ error: StepError | null;
21
+ }
22
+ export declare class StepNotFoundError extends Error {
23
+ readonly stepId: string;
24
+ constructor(stepId: string);
25
+ }
26
+ export interface StepStore {
27
+ createSteps(records: NewStepRecord[]): Promise<Array<{
28
+ id: string;
29
+ }>>;
30
+ loadStep(id: string): Promise<StepRecord>;
31
+ claimStep(id: string): Promise<boolean>;
32
+ completeStep(id: string, outputs: JsonValue): Promise<boolean>;
33
+ failStep(id: string, error: StepError): Promise<boolean>;
34
+ loadStepOutputs(executionId: string, nodeIds: string[]): Promise<Record<string, JsonValue | null>>;
35
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StepNotFoundError = void 0;
4
+ class StepNotFoundError extends Error {
5
+ stepId;
6
+ constructor(stepId) {
7
+ super(`Step not found: ${stepId}`);
8
+ this.stepId = stepId;
9
+ this.name = 'StepNotFoundError';
10
+ }
11
+ }
12
+ exports.StepNotFoundError = StepNotFoundError;
13
+ //# sourceMappingURL=step-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-store.js","sourceRoot":"","sources":["../../src/execution/step-store.ts"],"names":[],"mappings":";;;AAoCA,uBAA+B,SAAQ,KAAK;IACtB,MAAM;IAA3B,YAAqB,MAAc;QAClC,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;sBADf,MAAM;QAE1B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD"}
@@ -0,0 +1,2 @@
1
+ export type { GraphEdge, GraphNode, StepConfig, StepType, WorkflowGraph, } from './workflow-graph';
2
+ export { findTriggerNode, getSuccessorNodeIds } from './workflow-graph-queries';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSuccessorNodeIds = exports.findTriggerNode = void 0;
4
+ var workflow_graph_queries_1 = require("./workflow-graph-queries");
5
+ Object.defineProperty(exports, "findTriggerNode", { enumerable: true, get: function () { return workflow_graph_queries_1.findTriggerNode; } });
6
+ Object.defineProperty(exports, "getSuccessorNodeIds", { enumerable: true, get: function () { return workflow_graph_queries_1.getSuccessorNodeIds; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":";;;AAOA,mEAAgF;AAAvE,yHAAA,eAAe,OAAA;AAAE,6HAAA,mBAAmB,OAAA"}
@@ -0,0 +1,3 @@
1
+ import type { GraphNode, WorkflowGraph } from './workflow-graph';
2
+ export declare function findTriggerNode(graph: WorkflowGraph): GraphNode | undefined;
3
+ export declare function getSuccessorNodeIds(graph: WorkflowGraph, nodeId: string): string[];
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findTriggerNode = findTriggerNode;
4
+ exports.getSuccessorNodeIds = getSuccessorNodeIds;
5
+ function findTriggerNode(graph) {
6
+ return graph.nodes.find((node) => node.type === 'trigger');
7
+ }
8
+ function getSuccessorNodeIds(graph, nodeId) {
9
+ const successors = [];
10
+ for (const edge of graph.edges) {
11
+ if (edge.from === nodeId && !successors.includes(edge.to)) {
12
+ successors.push(edge.to);
13
+ }
14
+ }
15
+ return successors;
16
+ }
17
+ //# sourceMappingURL=workflow-graph-queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-graph-queries.js","sourceRoot":"","sources":["../../src/graph/workflow-graph-queries.ts"],"names":[],"mappings":";;;;AAGA,yBAAgC,KAAoB;IACnD,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AAC5D,CAAC;AAOD,6BAAoC,KAAoB,EAAE,MAAc;IACvE,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3D,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC;IACD,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,19 @@
1
+ export type StepType = 'trigger' | 'v1-node' | 'wait' | 'subworkflow' | 'batch';
2
+ export type StepConfig = unknown;
3
+ export interface GraphNode {
4
+ id: string;
5
+ name: string;
6
+ type: StepType;
7
+ config?: StepConfig;
8
+ }
9
+ export interface GraphEdge {
10
+ from: string;
11
+ to: string;
12
+ outputIndex: number;
13
+ inputIndex: number;
14
+ isBackEdge?: boolean;
15
+ }
16
+ export interface WorkflowGraph {
17
+ nodes: GraphNode[];
18
+ edges: GraphEdge[];
19
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=workflow-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-graph.js","sourceRoot":"","sources":["../../src/graph/workflow-graph.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1 +1,12 @@
1
1
  export { createEngineServer } from './server';
2
+ export type { EngineServerDeps } from './server';
3
+ export type { JsonObject, JsonValue } from './common';
4
+ export type { GraphEdge, GraphNode, StepConfig, StepType, WorkflowGraph, } from './graph';
5
+ export type { ExternalDependencies, IStepExecutor, StepExecutionContext, StepExecutionRequest, StepExecutionResult, } from './dependencies';
6
+ export { AllowAllAdmittance, AdmittanceRejectedError } from './admittance';
7
+ export type { AdmittanceDecision, AdmittanceRequest, AdmittanceService, } from './admittance';
8
+ export { InMemoryWorkQueue } from './queue';
9
+ export type { ExecutionEnqueuedEvent, OrchestrationMessage, StepMessage, StepReadyEvent, WorkQueue, } from './queue';
10
+ export { ExecutionNotFoundError, ExecutionStartHandler, OrchestrationWorker, StepNotFoundError, } from './execution';
11
+ export type { ExecutionMode, ExecutionRecord, ExecutionStatus, ExecutionStore, NewExecutionRecord, NewStepRecord, StepError, StepRecord, StepStatus, StepStore, } from './execution';
12
+ export { createDataSource, TypeOrmExecutionStore, TypeOrmStepStore } from './database';
package/dist/index.js CHANGED
@@ -1,6 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEngineServer = void 0;
3
+ exports.TypeOrmStepStore = exports.TypeOrmExecutionStore = exports.createDataSource = exports.StepNotFoundError = exports.OrchestrationWorker = exports.ExecutionStartHandler = exports.ExecutionNotFoundError = exports.InMemoryWorkQueue = exports.AdmittanceRejectedError = exports.AllowAllAdmittance = exports.createEngineServer = void 0;
4
4
  var server_1 = require("./server");
5
5
  Object.defineProperty(exports, "createEngineServer", { enumerable: true, get: function () { return server_1.createEngineServer; } });
6
+ var admittance_1 = require("./admittance");
7
+ Object.defineProperty(exports, "AllowAllAdmittance", { enumerable: true, get: function () { return admittance_1.AllowAllAdmittance; } });
8
+ Object.defineProperty(exports, "AdmittanceRejectedError", { enumerable: true, get: function () { return admittance_1.AdmittanceRejectedError; } });
9
+ var queue_1 = require("./queue");
10
+ Object.defineProperty(exports, "InMemoryWorkQueue", { enumerable: true, get: function () { return queue_1.InMemoryWorkQueue; } });
11
+ var execution_1 = require("./execution");
12
+ Object.defineProperty(exports, "ExecutionNotFoundError", { enumerable: true, get: function () { return execution_1.ExecutionNotFoundError; } });
13
+ Object.defineProperty(exports, "ExecutionStartHandler", { enumerable: true, get: function () { return execution_1.ExecutionStartHandler; } });
14
+ Object.defineProperty(exports, "OrchestrationWorker", { enumerable: true, get: function () { return execution_1.OrchestrationWorker; } });
15
+ Object.defineProperty(exports, "StepNotFoundError", { enumerable: true, get: function () { return execution_1.StepNotFoundError; } });
16
+ var database_1 = require("./database");
17
+ Object.defineProperty(exports, "createDataSource", { enumerable: true, get: function () { return database_1.createDataSource; } });
18
+ Object.defineProperty(exports, "TypeOrmExecutionStore", { enumerable: true, get: function () { return database_1.TypeOrmExecutionStore; } });
19
+ Object.defineProperty(exports, "TypeOrmStepStore", { enumerable: true, get: function () { return database_1.TypeOrmStepStore; } });
6
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA8C;AAArC,4GAAA,kBAAkB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA8C;AAArC,4GAAA,kBAAkB,OAAA;AAqB3B,2CAA2E;AAAlE,gHAAA,kBAAkB,OAAA;AAAE,qHAAA,uBAAuB,OAAA;AAOpD,iCAA4C;AAAnC,0GAAA,iBAAiB,OAAA;AAS1B,yCAKqB;AAJpB,mHAAA,sBAAsB,OAAA;AACtB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AACnB,8GAAA,iBAAiB,OAAA;AAelB,uCAAuF;AAA9E,4GAAA,gBAAgB,OAAA;AAAE,iHAAA,qBAAqB,OAAA;AAAE,4GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,12 @@
1
+ import type { WorkQueue } from './work-queue.types';
2
+ export declare class InMemoryWorkQueue<TMessage> implements WorkQueue<TMessage> {
3
+ private pending;
4
+ private handler;
5
+ private dispatching;
6
+ private idleWaiters;
7
+ publish(message: TMessage): Promise<void>;
8
+ start(handler: (message: TMessage) => Promise<void>): void;
9
+ stop(): Promise<void>;
10
+ private startDispatchLoop;
11
+ private dispatchPending;
12
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryWorkQueue = void 0;
4
+ class InMemoryWorkQueue {
5
+ pending = [];
6
+ handler;
7
+ dispatching = false;
8
+ idleWaiters = [];
9
+ async publish(message) {
10
+ this.pending.push(message);
11
+ this.startDispatchLoop();
12
+ }
13
+ start(handler) {
14
+ this.handler = handler;
15
+ this.startDispatchLoop();
16
+ }
17
+ async stop() {
18
+ this.handler = undefined;
19
+ if (!this.dispatching)
20
+ return;
21
+ await new Promise((resolve) => this.idleWaiters.push(resolve));
22
+ }
23
+ startDispatchLoop() {
24
+ if (this.dispatching || !this.handler || this.pending.length === 0)
25
+ return;
26
+ this.dispatching = true;
27
+ this.dispatchPending().catch((error) => {
28
+ console.error('engine: work queue dispatch failed', error);
29
+ });
30
+ }
31
+ async dispatchPending() {
32
+ try {
33
+ while (this.handler && this.pending.length > 0) {
34
+ const [message] = this.pending.splice(0, 1);
35
+ try {
36
+ await this.handler(message);
37
+ }
38
+ catch (error) {
39
+ console.error('engine: work queue handler failed', error);
40
+ }
41
+ }
42
+ }
43
+ finally {
44
+ this.dispatching = false;
45
+ const waiters = this.idleWaiters;
46
+ this.idleWaiters = [];
47
+ for (const resolve of waiters)
48
+ resolve();
49
+ }
50
+ }
51
+ }
52
+ exports.InMemoryWorkQueue = InMemoryWorkQueue;
53
+ //# sourceMappingURL=in-memory-work-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-work-queue.js","sourceRoot":"","sources":["../../src/queue/in-memory-work-queue.ts"],"names":[],"mappings":";;;AAMA;IACS,OAAO,GAAe,EAAE,CAAC;IAEzB,OAAO,CAAqD;IAE5D,WAAW,GAAG,KAAK,CAAC;IAEpB,WAAW,GAAsB,EAAE,CAAC;IAG5C,KAAK,CAAC,OAAO,CAAC,OAAiB;QAC9B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAA6C;QAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,IAAI;QACT,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QAGzB,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO;QAC9B,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACtE,CAAC;IAMO,iBAAiB;QACxB,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC3E,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YAC/C,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,eAAe;QAC5B,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChD,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC;oBACJ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC7B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAEhB,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;gBAC3D,CAAC;YACF,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC;YACjC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;YACtB,KAAK,MAAM,OAAO,IAAI,OAAO;gBAAE,OAAO,EAAE,CAAC;QAC1C,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,2 @@
1
+ export type { ExecutionEnqueuedEvent, OrchestrationMessage, StepMessage, StepReadyEvent, WorkQueue, } from './work-queue.types';
2
+ export { InMemoryWorkQueue } from './in-memory-work-queue';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryWorkQueue = void 0;
4
+ var in_memory_work_queue_1 = require("./in-memory-work-queue");
5
+ Object.defineProperty(exports, "InMemoryWorkQueue", { enumerable: true, get: function () { return in_memory_work_queue_1.InMemoryWorkQueue; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":";;;AAOA,+DAA2D;AAAlD,yHAAA,iBAAiB,OAAA"}
@@ -0,0 +1,16 @@
1
+ export interface ExecutionEnqueuedEvent {
2
+ type: 'execution:enqueued';
3
+ executionId: string;
4
+ }
5
+ export type OrchestrationMessage = ExecutionEnqueuedEvent;
6
+ export interface StepReadyEvent {
7
+ type: 'step:ready';
8
+ executionId: string;
9
+ stepId: string;
10
+ }
11
+ export type StepMessage = StepReadyEvent;
12
+ export interface WorkQueue<TMessage> {
13
+ publish(message: TMessage): Promise<void>;
14
+ start(handler: (message: TMessage) => Promise<void>): void;
15
+ stop(): Promise<void>;
16
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=work-queue.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-queue.types.js","sourceRoot":"","sources":["../../src/queue/work-queue.types.ts"],"names":[],"mappings":""}