@pikku/core 0.10.2 → 0.11.1

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 (138) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/errors/errors.d.ts +1 -1
  3. package/dist/errors/errors.js +3 -3
  4. package/dist/function/function-runner.d.ts +6 -7
  5. package/dist/function/function-runner.js +35 -16
  6. package/dist/function/functions.types.d.ts +23 -30
  7. package/dist/function/functions.types.js +9 -6
  8. package/dist/handle-error.d.ts +1 -1
  9. package/dist/handle-error.js +1 -1
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +2 -0
  12. package/dist/middleware/auth-apikey.d.ts +1 -0
  13. package/dist/middleware/auth-apikey.js +3 -3
  14. package/dist/middleware/auth-bearer.d.ts +1 -0
  15. package/dist/middleware/auth-bearer.js +3 -3
  16. package/dist/middleware/auth-cookie.d.ts +1 -0
  17. package/dist/middleware/auth-cookie.js +5 -5
  18. package/dist/middleware/timeout.d.ts +1 -0
  19. package/dist/middleware/timeout.js +3 -2
  20. package/dist/middleware-runner.d.ts +3 -6
  21. package/dist/middleware-runner.js +11 -11
  22. package/dist/permissions.d.ts +6 -6
  23. package/dist/permissions.js +15 -15
  24. package/dist/pikku-state.d.ts +7 -2
  25. package/dist/pikku-state.js +4 -0
  26. package/dist/services/index.d.ts +1 -0
  27. package/dist/services/index.js +1 -0
  28. package/dist/services/scheduler-service.d.ts +63 -0
  29. package/dist/services/scheduler-service.js +6 -0
  30. package/dist/services/user-session-service.d.ts +7 -3
  31. package/dist/services/user-session-service.js +8 -1
  32. package/dist/time-utils.d.ts +14 -0
  33. package/dist/time-utils.js +62 -0
  34. package/dist/types/core.types.d.ts +48 -35
  35. package/dist/types/core.types.js +3 -13
  36. package/dist/utils.d.ts +1 -1
  37. package/dist/utils.js +3 -3
  38. package/dist/wirings/channel/channel-common.js +2 -3
  39. package/dist/wirings/channel/channel-handler.d.ts +3 -2
  40. package/dist/wirings/channel/channel-handler.js +6 -9
  41. package/dist/wirings/channel/channel-runner.d.ts +2 -2
  42. package/dist/wirings/channel/channel.types.d.ts +10 -5
  43. package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
  44. package/dist/wirings/channel/local/local-channel-runner.js +19 -26
  45. package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
  46. package/dist/wirings/channel/serverless/serverless-channel-runner.js +41 -46
  47. package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
  48. package/dist/wirings/cli/cli-runner.d.ts +5 -5
  49. package/dist/wirings/cli/cli-runner.js +11 -29
  50. package/dist/wirings/cli/cli.types.d.ts +15 -11
  51. package/dist/wirings/http/http-runner.d.ts +6 -6
  52. package/dist/wirings/http/http-runner.js +25 -39
  53. package/dist/wirings/http/http.types.d.ts +5 -10
  54. package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
  55. package/dist/wirings/mcp/mcp-runner.js +12 -19
  56. package/dist/wirings/mcp/mcp.types.d.ts +6 -0
  57. package/dist/wirings/queue/queue-runner.d.ts +3 -3
  58. package/dist/wirings/queue/queue-runner.js +7 -14
  59. package/dist/wirings/queue/queue.types.d.ts +4 -13
  60. package/dist/wirings/rpc/index.d.ts +1 -1
  61. package/dist/wirings/rpc/index.js +1 -1
  62. package/dist/wirings/rpc/rpc-runner.d.ts +13 -7
  63. package/dist/wirings/rpc/rpc-runner.js +50 -26
  64. package/dist/wirings/rpc/rpc-types.d.ts +1 -0
  65. package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
  66. package/dist/wirings/scheduler/scheduler-runner.js +13 -24
  67. package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
  68. package/dist/wirings/workflow/index.d.ts +15 -0
  69. package/dist/wirings/workflow/index.js +14 -0
  70. package/dist/wirings/workflow/pikku-workflow-service.d.ts +160 -0
  71. package/dist/wirings/workflow/pikku-workflow-service.js +430 -0
  72. package/dist/wirings/workflow/workflow-runner.d.ts +34 -0
  73. package/dist/wirings/workflow/workflow-runner.js +65 -0
  74. package/dist/wirings/workflow/workflow.types.d.ts +332 -0
  75. package/dist/wirings/workflow/workflow.types.js +1 -0
  76. package/package.json +3 -4
  77. package/src/errors/errors.ts +3 -3
  78. package/src/factory-functions.test.ts +9 -36
  79. package/src/function/function-runner.test.ts +57 -68
  80. package/src/function/function-runner.ts +51 -28
  81. package/src/function/function-runner.ts.bak +188 -0
  82. package/src/function/functions.types.ts +69 -51
  83. package/src/handle-error.ts +1 -1
  84. package/src/index.ts +2 -0
  85. package/src/middleware/auth-apikey.test.ts +360 -0
  86. package/src/middleware/auth-apikey.ts +3 -7
  87. package/src/middleware/auth-bearer.test.ts +447 -0
  88. package/src/middleware/auth-bearer.ts +27 -33
  89. package/src/middleware/auth-cookie.test.ts +525 -0
  90. package/src/middleware/auth-cookie.ts +6 -6
  91. package/src/middleware/timeout.ts +4 -2
  92. package/src/middleware-runner.test.ts +58 -127
  93. package/src/middleware-runner.ts +13 -15
  94. package/src/permissions.test.ts +41 -45
  95. package/src/permissions.ts +21 -20
  96. package/src/pikku-state.ts +14 -2
  97. package/src/services/index.ts +1 -0
  98. package/src/services/scheduler-service.ts +76 -0
  99. package/src/services/user-session-service.ts +14 -4
  100. package/src/time-utils.ts +75 -0
  101. package/src/types/core.types.ts +92 -51
  102. package/src/utils.ts +4 -4
  103. package/src/wirings/channel/channel-common.ts +4 -7
  104. package/src/wirings/channel/channel-handler.ts +16 -22
  105. package/src/wirings/channel/channel-runner.ts +2 -2
  106. package/src/wirings/channel/channel.types.ts +14 -11
  107. package/src/wirings/channel/local/local-channel-runner.test.ts +5 -3
  108. package/src/wirings/channel/local/local-channel-runner.ts +23 -38
  109. package/src/wirings/channel/serverless/serverless-channel-runner.ts +51 -77
  110. package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
  111. package/src/wirings/cli/cli-runner.test.ts +7 -7
  112. package/src/wirings/cli/cli-runner.ts +25 -63
  113. package/src/wirings/cli/cli.types.ts +22 -16
  114. package/src/wirings/http/http-runner.test.ts +8 -8
  115. package/src/wirings/http/http-runner.ts +29 -56
  116. package/src/wirings/http/http.types.ts +5 -14
  117. package/src/wirings/mcp/mcp-runner.ts +23 -48
  118. package/src/wirings/mcp/mcp.types.ts +6 -0
  119. package/src/wirings/queue/queue-runner.test.ts +641 -0
  120. package/src/wirings/queue/queue-runner.ts +10 -24
  121. package/src/wirings/queue/queue.types.ts +5 -15
  122. package/src/wirings/rpc/index.ts +1 -1
  123. package/src/wirings/rpc/rpc-runner.ts +71 -32
  124. package/src/wirings/rpc/rpc-types.ts +1 -0
  125. package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
  126. package/src/wirings/scheduler/scheduler-runner.ts +24 -50
  127. package/src/wirings/scheduler/scheduler.types.ts +3 -9
  128. package/src/wirings/workflow/index.ts +43 -0
  129. package/src/wirings/workflow/pikku-workflow-service.ts +746 -0
  130. package/src/wirings/workflow/workflow-runner.ts +72 -0
  131. package/src/wirings/workflow/workflow.types.ts +422 -0
  132. package/tsconfig.tsbuildinfo +1 -1
  133. package/dist/services/file-channel-store.d.ts +0 -19
  134. package/dist/services/file-channel-store.js +0 -69
  135. package/dist/services/file-eventhub-store.d.ts +0 -17
  136. package/dist/services/file-eventhub-store.js +0 -71
  137. package/src/services/file-channel-store.ts +0 -86
  138. package/src/services/file-eventhub-store.ts +0 -90
@@ -1,4 +1,3 @@
1
- import { PikkuWiringTypes, } from '../../types/core.types.js';
2
1
  import { runPikkuFunc } from '../../function/function-runner.js';
3
2
  import { pikkuState } from '../../pikku-state.js';
4
3
  import { ForbiddenError } from '../../errors/errors.js';
@@ -13,11 +12,11 @@ const getPikkuFunctionName = (rpcName) => {
13
12
  // Context-aware RPC client for use within services
14
13
  export class ContextAwareRPCService {
15
14
  services;
16
- interaction;
15
+ wire;
17
16
  options;
18
- constructor(services, interaction, options) {
17
+ constructor(services, wire, options) {
19
18
  this.services = services;
20
- this.interaction = interaction;
19
+ this.wire = wire;
21
20
  this.options = options;
22
21
  }
23
22
  async rpcExposed(funcName, data) {
@@ -31,27 +30,54 @@ export class ContextAwareRPCService {
31
30
  return await this.rpc(funcName, data);
32
31
  }
33
32
  async rpc(funcName, data) {
34
- const rpcDepth = this.services.rpc?.depth || 0;
35
- const pikkuFuncName = getPikkuFunctionName(funcName);
36
- return runPikkuFunc(PikkuWiringTypes.rpc, pikkuFuncName, pikkuFuncName, {
33
+ const rpcDepth = this.wire.rpc?.depth || 0;
34
+ const updatedWire = {
35
+ ...this.wire,
36
+ rpc: this.wire.rpc
37
+ ? {
38
+ ...this.wire.rpc,
39
+ depth: rpcDepth + 1,
40
+ global: false,
41
+ }
42
+ : undefined,
43
+ };
44
+ return runPikkuFunc('rpc', funcName, getPikkuFunctionName(funcName), {
37
45
  auth: this.options.requiresAuth,
46
+ // TODO: this is a hack since services have already been created
47
+ // but is valid since we don't want to keep creating new wire services
38
48
  singletonServices: this.services,
39
- getAllServices: () => {
40
- this.services.rpc = this.services.rpc
41
- ? {
42
- ...this.services.rpc,
43
- depth: rpcDepth + 1,
44
- global: false,
45
- }
46
- : undefined;
47
- return this.services;
48
- },
49
49
  data: () => data,
50
- userSession: this.services.userSession,
51
50
  coerceDataFromSchema: this.options.coerceDataFromSchema,
52
- interaction: this.interaction,
51
+ wire: updatedWire,
53
52
  });
54
53
  }
54
+ async rpcWithWire(rpcName, data, wire) {
55
+ const rpcDepth = this.wire.rpc?.depth || 0;
56
+ const mergedWire = {
57
+ ...this.wire,
58
+ ...wire,
59
+ rpc: this.wire.rpc
60
+ ? {
61
+ ...this.wire.rpc,
62
+ depth: rpcDepth + 1,
63
+ global: false,
64
+ }
65
+ : undefined,
66
+ };
67
+ return runPikkuFunc('rpc', rpcName, getPikkuFunctionName(rpcName), {
68
+ auth: this.options.requiresAuth,
69
+ singletonServices: this.services,
70
+ data: () => data,
71
+ coerceDataFromSchema: this.options.coerceDataFromSchema,
72
+ wire: mergedWire,
73
+ });
74
+ }
75
+ async startWorkflow(workflowName, input) {
76
+ if (!this.services.workflowService) {
77
+ throw new Error('WorkflowService service not available');
78
+ }
79
+ return this.services.workflowService.startWorkflow(workflowName, input, this);
80
+ }
55
81
  }
56
82
  // RPC Service class for the global interface
57
83
  export class PikkuRPCService {
@@ -61,21 +87,19 @@ export class PikkuRPCService {
61
87
  this.config = config;
62
88
  }
63
89
  // Convenience function for initializing
64
- injectRPCService(services, interaction, requiresAuth, depth = 0) {
65
- const serviceCopy = {
66
- ...services,
67
- };
68
- const serviceRPC = new ContextAwareRPCService(serviceCopy, interaction, {
90
+ getContextRPCService(services, wire, requiresAuth, depth = 0) {
91
+ const serviceRPC = new ContextAwareRPCService(services, wire, {
69
92
  coerceDataFromSchema: this.config?.coerceDataFromSchema,
70
93
  requiresAuth,
71
94
  });
72
- serviceCopy.rpc = {
95
+ return {
73
96
  depth,
74
97
  global: false,
75
98
  invoke: serviceRPC.rpc.bind(serviceRPC),
76
99
  invokeExposed: serviceRPC.rpc.bind(serviceRPC),
100
+ startWorkflow: serviceRPC.startWorkflow.bind(serviceRPC),
101
+ rpcWithWire: serviceRPC.rpcWithWire.bind(serviceRPC),
77
102
  };
78
- return serviceCopy;
79
103
  }
80
104
  }
81
105
  // Create a singleton instance
@@ -6,6 +6,7 @@ export type PikkuRPC<invoke extends Function = any> = {
6
6
  export type RPCMeta = {
7
7
  pikkuFuncName: string;
8
8
  expose: boolean;
9
+ internal?: boolean;
9
10
  };
10
11
  /**
11
12
  * Type for RPC handlers
@@ -1,12 +1,12 @@
1
- import { type CoreServices, type CoreSingletonServices, type CoreUserSession, type CreateSessionServices } from '../../types/core.types.js';
1
+ import { type CoreServices, type CoreSingletonServices, type CoreUserSession, type CreateWireServices } from '../../types/core.types.js';
2
2
  import type { CoreScheduledTask } from './scheduler.types.js';
3
3
  import { CorePikkuFunctionConfig, CorePikkuFunctionSessionless } from '../../function/functions.types.js';
4
4
  export type RunScheduledTasksParams = {
5
5
  name: string;
6
6
  session?: CoreUserSession;
7
7
  singletonServices: CoreSingletonServices;
8
- createSessionServices?: CreateSessionServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession>;
8
+ createWireServices?: CreateWireServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession>;
9
9
  };
10
10
  export declare const wireScheduler: <PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunctionSessionless<void, void>>>(scheduledTask: CoreScheduledTask<PikkuFunctionConfig>) => void;
11
- export declare function runScheduledTask({ name, session, singletonServices, createSessionServices, }: RunScheduledTasksParams): Promise<void>;
11
+ export declare function runScheduledTask({ name, session, singletonServices, createWireServices, }: RunScheduledTasksParams): Promise<void>;
12
12
  export declare const getScheduledTasks: () => Map<string, CoreScheduledTask>;
@@ -1,10 +1,8 @@
1
- import { PikkuWiringTypes, } from '../../types/core.types.js';
2
1
  import { getErrorResponse, PikkuError } from '../../errors/error-handler.js';
3
- import { closeSessionServices } from '../../utils.js';
2
+ import { closeWireServices } from '../../utils.js';
4
3
  import { pikkuState } from '../../pikku-state.js';
5
4
  import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
6
- import { rpcService } from '../rpc/rpc-runner.js';
7
- import { PikkuUserSessionService } from '../../services/user-session-service.js';
5
+ import { PikkuSessionService } from '../../services/user-session-service.js';
8
6
  export const wireScheduler = (scheduledTask) => {
9
7
  const meta = pikkuState('scheduler', 'meta');
10
8
  const taskMeta = meta[scheduledTask.name];
@@ -17,7 +15,6 @@ export const wireScheduler = (scheduledTask) => {
17
15
  permissions: scheduledTask.func.permissions,
18
16
  middleware: scheduledTask.func.middleware,
19
17
  tags: scheduledTask.func.tags,
20
- docs: scheduledTask.func.docs,
21
18
  });
22
19
  const tasks = pikkuState('scheduler', 'tasks');
23
20
  if (tasks.has(scheduledTask.name)) {
@@ -36,11 +33,11 @@ class ScheduledTaskSkippedError extends PikkuError {
36
33
  this.name = 'ScheduledTaskSkippedError';
37
34
  }
38
35
  }
39
- export async function runScheduledTask({ name, session, singletonServices, createSessionServices, }) {
40
- let sessionServices;
36
+ export async function runScheduledTask({ name, session, singletonServices, createWireServices, }) {
37
+ let wireServices;
41
38
  const task = pikkuState('scheduler', 'tasks').get(name);
42
39
  const meta = pikkuState('scheduler', 'meta')[name];
43
- const userSession = new PikkuUserSessionService();
40
+ const userSession = new PikkuSessionService();
44
41
  if (session) {
45
42
  userSession.set(session);
46
43
  }
@@ -50,8 +47,8 @@ export async function runScheduledTask({ name, session, singletonServices, creat
50
47
  if (!meta) {
51
48
  throw new ScheduledTaskNotFoundError(`Scheduled task meta not found: ${name}`);
52
49
  }
53
- // Create the scheduled task interaction object
54
- const interaction = {
50
+ // Create the scheduled task wire object
51
+ const wire = {
55
52
  scheduledTask: {
56
53
  name,
57
54
  schedule: task.schedule,
@@ -60,28 +57,20 @@ export async function runScheduledTask({ name, session, singletonServices, creat
60
57
  throw new ScheduledTaskSkippedError(name, reason);
61
58
  },
62
59
  },
60
+ session: userSession,
63
61
  };
64
62
  try {
65
63
  singletonServices.logger.info(`Running schedule task: ${name} | schedule: ${task.schedule}`);
66
- const getAllServices = async () => {
67
- sessionServices = await createSessionServices?.(singletonServices, interaction, session);
68
- return rpcService.injectRPCService({
69
- ...singletonServices,
70
- ...sessionServices,
71
- }, interaction);
72
- };
73
- const result = await runPikkuFunc(PikkuWiringTypes.scheduler, meta.name, meta.pikkuFuncName, {
64
+ await runPikkuFunc('scheduler', meta.name, meta.pikkuFuncName, {
74
65
  singletonServices,
75
- getAllServices,
76
- userSession,
66
+ createWireServices,
77
67
  auth: false,
78
68
  data: () => undefined,
79
69
  inheritedMiddleware: meta.middleware,
80
70
  wireMiddleware: task.middleware,
81
71
  tags: task.tags,
82
- interaction,
72
+ wire,
83
73
  });
84
- return result;
85
74
  }
86
75
  catch (e) {
87
76
  const errorResponse = getErrorResponse(e);
@@ -91,8 +80,8 @@ export async function runScheduledTask({ name, session, singletonServices, creat
91
80
  throw e;
92
81
  }
93
82
  finally {
94
- if (sessionServices) {
95
- await closeSessionServices(singletonServices.logger, sessionServices);
83
+ if (wireServices) {
84
+ await closeWireServices(singletonServices.logger, wireServices);
96
85
  }
97
86
  }
98
87
  }
@@ -1,16 +1,12 @@
1
- import { PikkuDocs, CoreUserSession, CorePikkuMiddleware, MiddlewareMetadata } from '../../types/core.types.js';
1
+ import { CoreUserSession, CorePikkuMiddleware, CommonWireMeta } from '../../types/core.types.js';
2
2
  import { CorePikkuFunctionConfig, CorePikkuFunctionSessionless } from '../../function/functions.types.js';
3
3
  /**
4
4
  * Represents metadata for scheduled tasks, including title, schedule, and documentation.
5
5
  */
6
- export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Record<string, {
7
- pikkuFuncName: string;
6
+ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Record<string, CommonWireMeta & {
8
7
  name: string;
9
8
  schedule: string;
10
9
  session?: UserSession;
11
- docs?: PikkuDocs;
12
- tags?: string[];
13
- middleware?: MiddlewareMetadata[];
14
10
  }>;
15
11
  /**
16
12
  * Represents a core scheduled task.
@@ -19,12 +15,11 @@ export type CoreScheduledTask<PikkuFunctionConfig = CorePikkuFunctionConfig<Core
19
15
  name: string;
20
16
  schedule: string;
21
17
  func: PikkuFunctionConfig;
22
- docs?: PikkuDocs;
23
18
  tags?: string[];
24
19
  middleware?: PikkuMiddleware[];
25
20
  };
26
21
  /**
27
- * Represents a scheduled task interaction object for middleware
22
+ * Represents a scheduled task wire object for middleware
28
23
  * Provides information about the current scheduled task execution
29
24
  */
30
25
  export interface PikkuScheduledTask {
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Workflow module exports
3
+ */
4
+ export type { CoreWorkflow, WorkflowStepOptions, WorkflowStepMeta, RpcStepMeta, BranchStepMeta, ParallelGroupStepMeta, FanoutStepMeta, ReturnStepMeta, InlineStepMeta, SleepStepMeta, CancelStepMeta, InputSource, OutputBinding, PikkuWorkflowWire, PikkuWorkflow, WorkflowsMeta, WorkflowRun, StepState, WorkflowStatus, StepStatus, } from './workflow.types.js';
5
+ export { PikkuWorkflowService } from './pikku-workflow-service.js';
6
+ export { addWorkflow } from './workflow-runner.js';
7
+ /**
8
+ * @deprecated This function is no longer used and will be removed in a future release.
9
+ * It exists only for backwards compatibility with generated code.
10
+ * TODO: Remove this export in a future release after updating code generation
11
+ */
12
+ export declare const wireWorkflow: <T extends {
13
+ name: string;
14
+ func: any;
15
+ }>(workflow: T) => void;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Workflow module exports
3
+ */
4
+ export { PikkuWorkflowService } from './pikku-workflow-service.js';
5
+ // Internal registration function (used by generated code)
6
+ export { addWorkflow } from './workflow-runner.js';
7
+ /**
8
+ * @deprecated This function is no longer used and will be removed in a future release.
9
+ * It exists only for backwards compatibility with generated code.
10
+ * TODO: Remove this export in a future release after updating code generation
11
+ */
12
+ export const wireWorkflow = (workflow) => {
13
+ // Empty function - no longer used, kept for backwards compatibility
14
+ };
@@ -0,0 +1,160 @@
1
+ import { CoreConfig, CoreSingletonServices, CreateWireServices, SerializedError } from '../../types/core.types.js';
2
+ import type { StepState, WorkflowRun, WorkflowStatus, WorkflowService, WorkflowStepOptions } from './workflow.types.js';
3
+ export declare class WorkflowServiceNotInitialized extends Error {
4
+ }
5
+ export declare class WorkflowStepNameNotString extends Error {
6
+ constructor(stepName: any);
7
+ }
8
+ /**
9
+ * Abstract workflow state service
10
+ * Implementations provide pluggable storage backends (SQLite, PostgreSQL, etc.)
11
+ * Combines orchestration and step execution
12
+ */
13
+ export declare abstract class PikkuWorkflowService implements WorkflowService {
14
+ private config;
15
+ private singletonServices;
16
+ private createWireServices;
17
+ constructor();
18
+ setServices(singletonServices: CoreSingletonServices, createWireServices: CreateWireServices, { workflow }: CoreConfig): void;
19
+ /**
20
+ * Create a new workflow run
21
+ * @param name - Workflow name
22
+ * @param input - Input data for the workflow
23
+ * @returns Run ID
24
+ */
25
+ abstract createRun(workflowName: string, input: any): Promise<string>;
26
+ /**
27
+ * Get a workflow run by ID
28
+ * @param id - Run ID
29
+ * @returns Workflow run or null if not found
30
+ */
31
+ abstract getRun(id: string): Promise<WorkflowRun | null>;
32
+ /**
33
+ * Get workflow run history (all step attempts in chronological order)
34
+ * @param runId - Run ID
35
+ * @returns Array of step states with step names, ordered oldest to newest
36
+ */
37
+ abstract getRunHistory(runId: string): Promise<Array<StepState & {
38
+ stepName: string;
39
+ }>>;
40
+ /**
41
+ * Update workflow run status
42
+ * @param id - Run ID
43
+ * @param status - New status
44
+ */
45
+ abstract updateRunStatus(id: string, status: WorkflowStatus, output?: any, error?: SerializedError): Promise<void>;
46
+ /**
47
+ * Insert initial step state (called by orchestrator)
48
+ * Creates pending step in both workflow_step and workflow_step_history
49
+ * @param runId - Run ID
50
+ * @param stepName - Step cache key
51
+ * @param rpcName - RPC function name
52
+ * @param data - Step input data
53
+ * @param stepOptions - Step options (retries, retryDelay)
54
+ * @returns Step state with generated stepId
55
+ */
56
+ abstract insertStepState(runId: string, stepName: string, rpcName: string | null, data: any, stepOptions?: WorkflowStepOptions): Promise<StepState>;
57
+ /**
58
+ * Get step state by cache key (read-only)
59
+ * @param runId - Run ID
60
+ * @param stepName - Step cache key (from workflow.do)
61
+ * @returns Step state with attemptCount calculated from history
62
+ */
63
+ abstract getStepState(runId: string, stepName: string): Promise<StepState>;
64
+ /**
65
+ * Mark step as running
66
+ * Updates both workflow_step and workflow_step_history
67
+ * @param stepId - Step ID
68
+ */
69
+ abstract setStepRunning(stepId: string): Promise<void>;
70
+ /**
71
+ * Mark step as scheduled (queued for execution)
72
+ * Updates both workflow_step and workflow_step_history
73
+ * @param stepId - Step ID
74
+ */
75
+ abstract setStepScheduled(stepId: string): Promise<void>;
76
+ /**
77
+ * Store step result and mark as succeeded
78
+ * Updates both workflow_step and workflow_step_history
79
+ * @param stepId - Step ID
80
+ * @param result - Step result
81
+ */
82
+ abstract setStepResult(stepId: string, result: any): Promise<void>;
83
+ /**
84
+ * Store step error and mark as failed
85
+ * Updates both workflow_step and workflow_step_history
86
+ * @param stepId - Step ID
87
+ * @param error - Error object
88
+ */
89
+ abstract setStepError(stepId: string, error: Error): Promise<void>;
90
+ /**
91
+ * Create a new retry attempt for a failed step
92
+ * Inserts new pending step in both workflow_step and workflow_step_history
93
+ * Resets status to 'pending' with new stepId
94
+ * Copies metadata (rpcName, data, retries, retryDelay) from failed attempt
95
+ * @param failedStepId - Failed step ID to copy from
96
+ * @returns New step state for the retry attempt
97
+ */
98
+ abstract createRetryAttempt(failedStepId: string, status: 'pending' | 'running'): Promise<StepState>;
99
+ /**
100
+ * Execute function within a run lock to prevent concurrent modifications
101
+ * @param id - Run ID
102
+ * @param fn - Function to execute
103
+ * @returns Function result
104
+ */
105
+ abstract withRunLock<T>(id: string, fn: () => Promise<T>): Promise<T>;
106
+ /**
107
+ * Execute function within a step lock to prevent concurrent step execution
108
+ * @param runId - Run ID
109
+ * @param stepName - Step name
110
+ * @param fn - Function to execute
111
+ * @returns Function result
112
+ */
113
+ abstract withStepLock<T>(runId: string, stepName: string, fn: () => Promise<T>): Promise<T>;
114
+ /**
115
+ * Close any open connections
116
+ */
117
+ abstract close(): Promise<void>;
118
+ /**
119
+ * Resume a paused workflow by triggering the orchestrator
120
+ * @param runId - Run ID
121
+ */
122
+ resumeWorkflow(runId: string): Promise<void>;
123
+ /**
124
+ * Execute a workflow sleep step completion
125
+ * Sets the step result to null and resumes the workflow
126
+ * @param data - Sleeper input data
127
+ */
128
+ executeWorkflowSleep(runId: string, stepId: string): Promise<void>;
129
+ /**
130
+ * Schedule orchestrator retry with delay
131
+ * @param runId - Run ID
132
+ * @param retryDelay - Delay in milliseconds or duration string (optional)
133
+ */
134
+ protected scheduleOrchestratorRetry(runId: string, retryDelay?: number | string): Promise<void>;
135
+ /**
136
+ * Start a new workflow run
137
+ */
138
+ startWorkflow<I>(name: string, input: I, rpcService: any): Promise<{
139
+ runId: string;
140
+ }>;
141
+ runWorkflowJob(runId: string, rpcService: any): Promise<void>;
142
+ /**
143
+ * Execute a single workflow step (called by worker)
144
+ * Handles idempotency, RPC execution, result storage, retry logic, and orchestrator triggering
145
+ */
146
+ executeWorkflowStep(runId: string, stepName: string, rpcName: string, data: any, rpcService: any): Promise<void>;
147
+ /**
148
+ * Orchestrate workflow execution (called by orchestrator)
149
+ * Runs workflow job and handles async exceptions
150
+ */
151
+ orchestrateWorkflow(runId: string, rpcService: any): Promise<void>;
152
+ private verifyQueueService;
153
+ private rpcStep;
154
+ private inlineStep;
155
+ private sleepStep;
156
+ private cancelWorkflow;
157
+ private createWorkflowWire;
158
+ private verifyStepName;
159
+ private getConfig;
160
+ }