@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.
- package/CHANGELOG.md +19 -0
- package/dist/errors/errors.d.ts +1 -1
- package/dist/errors/errors.js +3 -3
- package/dist/function/function-runner.d.ts +6 -7
- package/dist/function/function-runner.js +35 -16
- package/dist/function/functions.types.d.ts +23 -30
- package/dist/function/functions.types.js +9 -6
- package/dist/handle-error.d.ts +1 -1
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/middleware/auth-apikey.d.ts +1 -0
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -0
- package/dist/middleware/auth-bearer.js +3 -3
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/auth-cookie.js +5 -5
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/middleware/timeout.js +3 -2
- package/dist/middleware-runner.d.ts +3 -6
- package/dist/middleware-runner.js +11 -11
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +15 -15
- package/dist/pikku-state.d.ts +7 -2
- package/dist/pikku-state.js +4 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/scheduler-service.d.ts +63 -0
- package/dist/services/scheduler-service.js +6 -0
- package/dist/services/user-session-service.d.ts +7 -3
- package/dist/services/user-session-service.js +8 -1
- package/dist/time-utils.d.ts +14 -0
- package/dist/time-utils.js +62 -0
- package/dist/types/core.types.d.ts +48 -35
- package/dist/types/core.types.js +3 -13
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/dist/wirings/channel/channel-common.js +2 -3
- package/dist/wirings/channel/channel-handler.d.ts +3 -2
- package/dist/wirings/channel/channel-handler.js +6 -9
- package/dist/wirings/channel/channel-runner.d.ts +2 -2
- package/dist/wirings/channel/channel.types.d.ts +10 -5
- package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/local/local-channel-runner.js +19 -26
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +41 -46
- package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +5 -5
- package/dist/wirings/cli/cli-runner.js +11 -29
- package/dist/wirings/cli/cli.types.d.ts +15 -11
- package/dist/wirings/http/http-runner.d.ts +6 -6
- package/dist/wirings/http/http-runner.js +25 -39
- package/dist/wirings/http/http.types.d.ts +5 -10
- package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
- package/dist/wirings/mcp/mcp-runner.js +12 -19
- package/dist/wirings/mcp/mcp.types.d.ts +6 -0
- package/dist/wirings/queue/queue-runner.d.ts +3 -3
- package/dist/wirings/queue/queue-runner.js +7 -14
- package/dist/wirings/queue/queue.types.d.ts +4 -13
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +13 -7
- package/dist/wirings/rpc/rpc-runner.js +50 -26
- package/dist/wirings/rpc/rpc-types.d.ts +1 -0
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
- package/dist/wirings/scheduler/scheduler-runner.js +13 -24
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
- package/dist/wirings/workflow/index.d.ts +15 -0
- package/dist/wirings/workflow/index.js +14 -0
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +160 -0
- package/dist/wirings/workflow/pikku-workflow-service.js +430 -0
- package/dist/wirings/workflow/workflow-runner.d.ts +34 -0
- package/dist/wirings/workflow/workflow-runner.js +65 -0
- package/dist/wirings/workflow/workflow.types.d.ts +332 -0
- package/dist/wirings/workflow/workflow.types.js +1 -0
- package/package.json +3 -4
- package/src/errors/errors.ts +3 -3
- package/src/factory-functions.test.ts +9 -36
- package/src/function/function-runner.test.ts +57 -68
- package/src/function/function-runner.ts +51 -28
- package/src/function/function-runner.ts.bak +188 -0
- package/src/function/functions.types.ts +69 -51
- package/src/handle-error.ts +1 -1
- package/src/index.ts +2 -0
- package/src/middleware/auth-apikey.test.ts +360 -0
- package/src/middleware/auth-apikey.ts +3 -7
- package/src/middleware/auth-bearer.test.ts +447 -0
- package/src/middleware/auth-bearer.ts +27 -33
- package/src/middleware/auth-cookie.test.ts +525 -0
- package/src/middleware/auth-cookie.ts +6 -6
- package/src/middleware/timeout.ts +4 -2
- package/src/middleware-runner.test.ts +58 -127
- package/src/middleware-runner.ts +13 -15
- package/src/permissions.test.ts +41 -45
- package/src/permissions.ts +21 -20
- package/src/pikku-state.ts +14 -2
- package/src/services/index.ts +1 -0
- package/src/services/scheduler-service.ts +76 -0
- package/src/services/user-session-service.ts +14 -4
- package/src/time-utils.ts +75 -0
- package/src/types/core.types.ts +92 -51
- package/src/utils.ts +4 -4
- package/src/wirings/channel/channel-common.ts +4 -7
- package/src/wirings/channel/channel-handler.ts +16 -22
- package/src/wirings/channel/channel-runner.ts +2 -2
- package/src/wirings/channel/channel.types.ts +14 -11
- package/src/wirings/channel/local/local-channel-runner.test.ts +5 -3
- package/src/wirings/channel/local/local-channel-runner.ts +23 -38
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +51 -77
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +7 -7
- package/src/wirings/cli/cli-runner.ts +25 -63
- package/src/wirings/cli/cli.types.ts +22 -16
- package/src/wirings/http/http-runner.test.ts +8 -8
- package/src/wirings/http/http-runner.ts +29 -56
- package/src/wirings/http/http.types.ts +5 -14
- package/src/wirings/mcp/mcp-runner.ts +23 -48
- package/src/wirings/mcp/mcp.types.ts +6 -0
- package/src/wirings/queue/queue-runner.test.ts +641 -0
- package/src/wirings/queue/queue-runner.ts +10 -24
- package/src/wirings/queue/queue.types.ts +5 -15
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +71 -32
- package/src/wirings/rpc/rpc-types.ts +1 -0
- package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
- package/src/wirings/scheduler/scheduler-runner.ts +24 -50
- package/src/wirings/scheduler/scheduler.types.ts +3 -9
- package/src/wirings/workflow/index.ts +43 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +746 -0
- package/src/wirings/workflow/workflow-runner.ts +72 -0
- package/src/wirings/workflow/workflow.types.ts +422 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/services/file-channel-store.d.ts +0 -19
- package/dist/services/file-channel-store.js +0 -69
- package/dist/services/file-eventhub-store.d.ts +0 -17
- package/dist/services/file-eventhub-store.js +0 -71
- package/src/services/file-channel-store.ts +0 -86
- package/src/services/file-eventhub-store.ts +0 -90
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { SerializedError, CoreSingletonServices, CreateWireServices, CoreConfig, CommonWireMeta } from '../../types/core.types.js';
|
|
2
|
+
import { CorePikkuFunctionConfig } from '../../function/functions.types.js';
|
|
3
|
+
export interface WorkflowServiceConfig {
|
|
4
|
+
retries: number;
|
|
5
|
+
retryDelay: number;
|
|
6
|
+
orchestratorQueueName: string;
|
|
7
|
+
stepWorkerQueueName: string;
|
|
8
|
+
sleeperRPCName: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Workflow run status
|
|
12
|
+
*/
|
|
13
|
+
export type WorkflowStatus = 'running' | 'completed' | 'failed' | 'cancelled';
|
|
14
|
+
/**
|
|
15
|
+
* Workflow step status
|
|
16
|
+
*/
|
|
17
|
+
export type StepStatus = 'pending' | 'running' | 'scheduled' | 'succeeded' | 'failed';
|
|
18
|
+
/**
|
|
19
|
+
* Workflow run representation
|
|
20
|
+
*/
|
|
21
|
+
export interface WorkflowRun {
|
|
22
|
+
/** Unique run ID */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Workflow name */
|
|
25
|
+
workflow: string;
|
|
26
|
+
/** Current status */
|
|
27
|
+
status: WorkflowStatus;
|
|
28
|
+
/** Input data */
|
|
29
|
+
input: any;
|
|
30
|
+
/** Output data (if completed) */
|
|
31
|
+
output?: any;
|
|
32
|
+
/** Error (if failed) */
|
|
33
|
+
error?: SerializedError;
|
|
34
|
+
/** Creation timestamp */
|
|
35
|
+
createdAt: Date;
|
|
36
|
+
/** Last update timestamp */
|
|
37
|
+
updatedAt: Date;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Step state representation
|
|
41
|
+
*/
|
|
42
|
+
export interface StepState {
|
|
43
|
+
/** Unique step ID */
|
|
44
|
+
stepId: string;
|
|
45
|
+
/** Step status */
|
|
46
|
+
status: StepStatus;
|
|
47
|
+
/** Step result (if done) */
|
|
48
|
+
result?: any;
|
|
49
|
+
/** Step error (if error) */
|
|
50
|
+
error?: SerializedError;
|
|
51
|
+
/** Number of attempts made (starts at 1) */
|
|
52
|
+
attemptCount: number;
|
|
53
|
+
/** Maximum retry attempts allowed */
|
|
54
|
+
retries?: number;
|
|
55
|
+
/** Delay between retries */
|
|
56
|
+
retryDelay?: string | number;
|
|
57
|
+
/** Creation timestamp */
|
|
58
|
+
createdAt: Date;
|
|
59
|
+
/** Last update timestamp */
|
|
60
|
+
updatedAt: Date;
|
|
61
|
+
/** Timestamp when step started running */
|
|
62
|
+
runningAt?: Date;
|
|
63
|
+
/** Timestamp when step was scheduled */
|
|
64
|
+
scheduledAt?: Date;
|
|
65
|
+
/** Timestamp when step succeeded */
|
|
66
|
+
succeededAt?: Date;
|
|
67
|
+
/** Timestamp when step failed */
|
|
68
|
+
failedAt?: Date;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Core workflow definition
|
|
72
|
+
*/
|
|
73
|
+
export type CoreWorkflow<PikkuFunctionConfig extends CorePikkuFunctionConfig<any, any, any> = CorePikkuFunctionConfig<any, any, any>> = {
|
|
74
|
+
/** Unique workflow name */
|
|
75
|
+
name: string;
|
|
76
|
+
/** The workflow function */
|
|
77
|
+
func: PikkuFunctionConfig;
|
|
78
|
+
/** Middleware chain for this workflow */
|
|
79
|
+
middleware?: PikkuFunctionConfig['middleware'];
|
|
80
|
+
/** Permission requirements */
|
|
81
|
+
permissions?: PikkuFunctionConfig['permissions'];
|
|
82
|
+
/** Tags for organization and filtering */
|
|
83
|
+
tags?: string[];
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Workflow step options
|
|
87
|
+
*/
|
|
88
|
+
export interface WorkflowStepOptions {
|
|
89
|
+
/** Display name for logs/UI (optional, doesn't affect execution) */
|
|
90
|
+
description?: string;
|
|
91
|
+
/** Number of retry attempts for failed steps (only applies to local execution) */
|
|
92
|
+
retries?: number;
|
|
93
|
+
/** Delay between retry attempts (e.g., '1s', '2s', '2min') */
|
|
94
|
+
retryDelay?: string | number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Type signature for workflow.do() RPC form - used by inspector
|
|
98
|
+
*/
|
|
99
|
+
export type WorkflowWireDoRPC = <TOutput = any, TInput = any>(stepName: string, rpcName: string, data: TInput, options?: WorkflowStepOptions) => Promise<TOutput>;
|
|
100
|
+
/**
|
|
101
|
+
* Type signature for workflow.do() inline form - used by inspector
|
|
102
|
+
*/
|
|
103
|
+
export type WorkflowWireDoInline = <T>(stepName: string, fn: () => Promise<T> | T, options?: WorkflowStepOptions) => Promise<T>;
|
|
104
|
+
/**
|
|
105
|
+
* Type signature for workflow.sleep() - used by inspector
|
|
106
|
+
*/
|
|
107
|
+
export type WorkflowWireSleep = (stepName: string, duration: string) => Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Input source for step arguments in simple workflows
|
|
110
|
+
*/
|
|
111
|
+
export type InputSource = {
|
|
112
|
+
from: 'input';
|
|
113
|
+
path: string;
|
|
114
|
+
} | {
|
|
115
|
+
from: 'outputVar';
|
|
116
|
+
name: string;
|
|
117
|
+
path?: string;
|
|
118
|
+
} | {
|
|
119
|
+
from: 'item';
|
|
120
|
+
path: string;
|
|
121
|
+
} | {
|
|
122
|
+
from: 'literal';
|
|
123
|
+
value: unknown;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Output binding for return statements in simple workflows
|
|
127
|
+
*/
|
|
128
|
+
export interface OutputBinding {
|
|
129
|
+
from: 'outputVar' | 'input';
|
|
130
|
+
name?: string;
|
|
131
|
+
path?: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* RPC step metadata (base form)
|
|
135
|
+
*/
|
|
136
|
+
export interface RpcStepMeta {
|
|
137
|
+
/** RPC form - generates queue worker */
|
|
138
|
+
type: 'rpc';
|
|
139
|
+
/** Cache key (stepName from workflow.do) */
|
|
140
|
+
stepName: string;
|
|
141
|
+
/** RPC to invoke */
|
|
142
|
+
rpcName: string;
|
|
143
|
+
/** Output variable name (if assigned) */
|
|
144
|
+
outputVar?: string;
|
|
145
|
+
/** Input source mappings */
|
|
146
|
+
inputs?: Record<string, InputSource>;
|
|
147
|
+
/** Step options */
|
|
148
|
+
options?: WorkflowStepOptions;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Branch step metadata (if/else control flow)
|
|
152
|
+
*/
|
|
153
|
+
export interface BranchStepMeta {
|
|
154
|
+
type: 'branch';
|
|
155
|
+
/** Condition expression (as source string) */
|
|
156
|
+
condition: string;
|
|
157
|
+
/** Branch paths */
|
|
158
|
+
branches: {
|
|
159
|
+
then: WorkflowStepMeta[];
|
|
160
|
+
else?: WorkflowStepMeta[];
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Parallel group step metadata (Promise.all with multiple steps)
|
|
165
|
+
*/
|
|
166
|
+
export interface ParallelGroupStepMeta {
|
|
167
|
+
type: 'parallel';
|
|
168
|
+
/** Child steps to execute in parallel */
|
|
169
|
+
children: RpcStepMeta[];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Fanout step metadata (parallel or sequential iteration)
|
|
173
|
+
*/
|
|
174
|
+
export interface FanoutStepMeta {
|
|
175
|
+
type: 'fanout';
|
|
176
|
+
/** Step name for this fanout */
|
|
177
|
+
stepName: string;
|
|
178
|
+
/** Source array variable name */
|
|
179
|
+
sourceVar: string;
|
|
180
|
+
/** Iterator variable name */
|
|
181
|
+
itemVar: string;
|
|
182
|
+
/** Execution mode */
|
|
183
|
+
mode: 'parallel' | 'sequential';
|
|
184
|
+
/** Child step to execute per iteration */
|
|
185
|
+
child: RpcStepMeta;
|
|
186
|
+
/** Time between iterations (sequential mode only) */
|
|
187
|
+
timeBetween?: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Return step metadata (workflow output)
|
|
191
|
+
*/
|
|
192
|
+
export interface ReturnStepMeta {
|
|
193
|
+
type: 'return';
|
|
194
|
+
/** Output bindings */
|
|
195
|
+
outputs: Record<string, OutputBinding>;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Inline step metadata (legacy support)
|
|
199
|
+
*/
|
|
200
|
+
export interface InlineStepMeta {
|
|
201
|
+
/** Inline form - local execution */
|
|
202
|
+
type: 'inline';
|
|
203
|
+
/** Cache key (stepName from workflow.do) */
|
|
204
|
+
stepName: string;
|
|
205
|
+
/** Display name */
|
|
206
|
+
description?: string;
|
|
207
|
+
/** Step options */
|
|
208
|
+
options?: WorkflowStepOptions;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Sleep step metadata
|
|
212
|
+
*/
|
|
213
|
+
export interface SleepStepMeta {
|
|
214
|
+
/** Sleep step */
|
|
215
|
+
type: 'sleep';
|
|
216
|
+
/** Cache key (stepName from workflow.sleep) */
|
|
217
|
+
stepName: string;
|
|
218
|
+
/** Sleep duration */
|
|
219
|
+
duration: string | number;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Cancel step metadata
|
|
223
|
+
*/
|
|
224
|
+
export interface CancelStepMeta {
|
|
225
|
+
/** Cancel step */
|
|
226
|
+
type: 'cancel';
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Workflow step metadata (extracted by inspector)
|
|
230
|
+
*/
|
|
231
|
+
export type WorkflowStepMeta = RpcStepMeta | BranchStepMeta | ParallelGroupStepMeta | FanoutStepMeta | ReturnStepMeta | InlineStepMeta | SleepStepMeta | CancelStepMeta;
|
|
232
|
+
/**
|
|
233
|
+
* Workflow step wire context for RPC functions
|
|
234
|
+
* Provides step-level metadata including retry attempt tracking
|
|
235
|
+
*/
|
|
236
|
+
export interface WorkflowStepWire {
|
|
237
|
+
/** The workflow run ID */
|
|
238
|
+
runId: string;
|
|
239
|
+
/** The unique step ID */
|
|
240
|
+
stepId: string;
|
|
241
|
+
/** Current attempt number (1-indexed, increments on retry) */
|
|
242
|
+
attemptCount: number;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Workflow wire object for middleware
|
|
246
|
+
* Provides workflow-specific capabilities to function execution
|
|
247
|
+
*/
|
|
248
|
+
export interface PikkuWorkflowWire {
|
|
249
|
+
/** The workflow name */
|
|
250
|
+
workflowName: string;
|
|
251
|
+
/** The current run ID */
|
|
252
|
+
runId: string;
|
|
253
|
+
/** Get the current workflow run */
|
|
254
|
+
getRun: () => Promise<WorkflowRun>;
|
|
255
|
+
/** Execute a workflow step (overloaded - RPC or inline form) */
|
|
256
|
+
do: WorkflowWireDoRPC & WorkflowWireDoInline;
|
|
257
|
+
/** Sleep for a duration */
|
|
258
|
+
sleep: WorkflowWireSleep;
|
|
259
|
+
/** Cancel the current workflow run */
|
|
260
|
+
cancel: (reason?: string) => Promise<void>;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Workflow client interface
|
|
264
|
+
*/
|
|
265
|
+
export interface PikkuWorkflow {
|
|
266
|
+
/** Start a new workflow run */
|
|
267
|
+
start: <I>(input: I) => Promise<{
|
|
268
|
+
runId: string;
|
|
269
|
+
}>;
|
|
270
|
+
/** Get a workflow run by ID */
|
|
271
|
+
getRun: (runId: string) => Promise<WorkflowRun>;
|
|
272
|
+
/** Cancel a running workflow */
|
|
273
|
+
cancelRun: (runId: string) => Promise<void>;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Workflows metadata for inspector/CLI
|
|
277
|
+
*/
|
|
278
|
+
export type WorkflowsMeta = Record<string, CommonWireMeta & {
|
|
279
|
+
workflowName: string;
|
|
280
|
+
steps: WorkflowStepMeta[];
|
|
281
|
+
/** Whether this workflow conforms to simple workflow DSL */
|
|
282
|
+
simple?: boolean;
|
|
283
|
+
}>;
|
|
284
|
+
/**
|
|
285
|
+
* Interface for workflow orchestration
|
|
286
|
+
* Handles workflow execution, replay, orchestration logic, and run-level state
|
|
287
|
+
*/
|
|
288
|
+
export interface WorkflowService {
|
|
289
|
+
createRun(workflowName: string, input: any): Promise<string>;
|
|
290
|
+
getRun(id: string): Promise<WorkflowRun | null>;
|
|
291
|
+
getRunHistory(runId: string): Promise<Array<StepState & {
|
|
292
|
+
stepName: string;
|
|
293
|
+
}>>;
|
|
294
|
+
updateRunStatus(id: string, status: WorkflowStatus, output?: any, error?: SerializedError): Promise<void>;
|
|
295
|
+
withRunLock<T>(id: string, fn: () => Promise<T>): Promise<T>;
|
|
296
|
+
close(): Promise<void>;
|
|
297
|
+
resumeWorkflow(runId: string): Promise<void>;
|
|
298
|
+
setServices(singletonServices: CoreSingletonServices, createWireServices: CreateWireServices, config: CoreConfig): void;
|
|
299
|
+
startWorkflow<I>(name: string, input: I, rpcService: any): Promise<{
|
|
300
|
+
runId: string;
|
|
301
|
+
}>;
|
|
302
|
+
runWorkflowJob(runId: string, rpcService: any): Promise<void>;
|
|
303
|
+
orchestrateWorkflow(runId: string, rpcService: any): Promise<void>;
|
|
304
|
+
executeWorkflowSleep(runId: string, stepId: string): Promise<void>;
|
|
305
|
+
insertStepState(runId: string, stepName: string, rpcName: string, data: any, stepOptions?: {
|
|
306
|
+
retries?: number;
|
|
307
|
+
retryDelay?: string | number;
|
|
308
|
+
}): Promise<StepState>;
|
|
309
|
+
getStepState(runId: string, stepName: string): Promise<StepState>;
|
|
310
|
+
setStepRunning(stepId: string): Promise<void>;
|
|
311
|
+
setStepScheduled(stepId: string): Promise<void>;
|
|
312
|
+
setStepResult(stepId: string, result: any): Promise<void>;
|
|
313
|
+
setStepError(stepId: string, error: Error): Promise<void>;
|
|
314
|
+
createRetryAttempt(stepId: string, status: 'pending' | 'running'): Promise<StepState>;
|
|
315
|
+
executeWorkflowStep(runId: string, stepName: string, rpcName: string | null, data: any, rpcService: any): Promise<void>;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Worker input types for generated queue workers
|
|
319
|
+
*/
|
|
320
|
+
export type WorkflowStepInput = {
|
|
321
|
+
runId: string;
|
|
322
|
+
stepName: string;
|
|
323
|
+
rpcName: string;
|
|
324
|
+
data: any;
|
|
325
|
+
};
|
|
326
|
+
export type WorkflowOrchestratorInput = {
|
|
327
|
+
runId: string;
|
|
328
|
+
};
|
|
329
|
+
export type WorkflowSleeperInput = {
|
|
330
|
+
runId: string;
|
|
331
|
+
stepId: string;
|
|
332
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"author": "yasser.fadl@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"./middleware": "./dist/middleware/index.js",
|
|
21
21
|
"./function": "./dist/function/index.js",
|
|
22
22
|
"./channel": "./dist/wirings/channel/index.js",
|
|
23
|
+
"./workflow": "./dist/wirings/workflow/index.js",
|
|
23
24
|
"./channel/local": "./dist/wirings/channel/local/index.js",
|
|
24
25
|
"./channel/serverless": "./dist/wirings/channel/serverless/index.js",
|
|
25
26
|
"./http": "./dist/wirings/http/index.js",
|
|
@@ -32,8 +33,6 @@
|
|
|
32
33
|
"./errors": "./dist/errors/index.js",
|
|
33
34
|
"./services": "./dist/services/index.js",
|
|
34
35
|
"./services/local-content": "./dist/services/local-content.js",
|
|
35
|
-
"./services/file-channel-store": "./dist/services/file-channel-store.js",
|
|
36
|
-
"./services/file-eventhub-store": "./dist/services/file-eventhub-store.js",
|
|
37
36
|
"./schema": "./dist/schema.js",
|
|
38
37
|
"./types": "./dist/types/index.d.ts"
|
|
39
38
|
},
|
|
@@ -43,7 +42,7 @@
|
|
|
43
42
|
"picoquery": "^2.5.0"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^24.
|
|
45
|
+
"@types/node": "^24.10.1",
|
|
47
46
|
"tsx": "^4.20.6",
|
|
48
47
|
"typescript": "^5.9"
|
|
49
48
|
},
|
package/src/errors/errors.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { addError, PikkuError } from './error-handler.js'
|
|
5
5
|
|
|
6
|
-
export class
|
|
7
|
-
addError(
|
|
6
|
+
export class InvalidMiddlewareWireError extends PikkuError {}
|
|
7
|
+
addError(InvalidMiddlewareWireError, {
|
|
8
8
|
status: 500,
|
|
9
|
-
message: 'The middleware
|
|
9
|
+
message: 'The middleware wire is invalid for the current wiring type.',
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -7,44 +7,22 @@ import {
|
|
|
7
7
|
pikkuMiddlewareFactory,
|
|
8
8
|
} from './index.js'
|
|
9
9
|
|
|
10
|
-
test('pikkuPermission factory function', async () => {
|
|
11
|
-
const permission = pikkuPermission(async ({ logger }, data, session) => {
|
|
12
|
-
return true
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
assert.strictEqual(typeof permission, 'function')
|
|
16
|
-
assert.strictEqual(permission.length, 3) // services, data, session
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('pikkuMiddleware factory function', async () => {
|
|
20
|
-
const middleware = pikkuMiddleware(async ({ logger }, interactions, next) => {
|
|
21
|
-
await next()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
assert.strictEqual(typeof middleware, 'function')
|
|
25
|
-
assert.strictEqual(middleware.length, 3) // services, interactions, next
|
|
26
|
-
})
|
|
27
|
-
|
|
28
10
|
test('pikkuPermission returns the same function', async () => {
|
|
29
|
-
const originalFn = async (
|
|
11
|
+
const originalFn = async () => true
|
|
30
12
|
const wrappedFn = pikkuPermission(originalFn)
|
|
31
|
-
|
|
32
13
|
assert.strictEqual(wrappedFn, originalFn)
|
|
33
14
|
})
|
|
34
15
|
|
|
35
16
|
test('pikkuMiddleware returns the same function', async () => {
|
|
36
|
-
const originalFn = async ({ logger },
|
|
37
|
-
await next()
|
|
38
|
-
}
|
|
17
|
+
const originalFn = async ({ logger }, wires, next) => next
|
|
39
18
|
const wrappedFn = pikkuMiddleware(originalFn)
|
|
40
|
-
|
|
41
19
|
assert.strictEqual(wrappedFn, originalFn)
|
|
42
20
|
})
|
|
43
21
|
|
|
44
22
|
test('pikkuPermissionFactory creates a factory function', async () => {
|
|
45
23
|
const factory = pikkuPermissionFactory<{ role: string }>(({ role }) => {
|
|
46
|
-
return pikkuPermission(async ({ logger }, data,
|
|
47
|
-
return
|
|
24
|
+
return pikkuPermission(async ({ logger }, data, { initialSession }) => {
|
|
25
|
+
return (initialSession as any)?.role === role
|
|
48
26
|
})
|
|
49
27
|
})
|
|
50
28
|
|
|
@@ -59,7 +37,7 @@ test('pikkuPermissionFactory creates a factory function', async () => {
|
|
|
59
37
|
|
|
60
38
|
test('pikkuMiddlewareFactory creates a factory function', async () => {
|
|
61
39
|
const factory = pikkuMiddlewareFactory<{ message: string }>(({ message }) => {
|
|
62
|
-
return pikkuMiddleware(async ({ logger },
|
|
40
|
+
return pikkuMiddleware(async ({ logger }, wires, next) => {
|
|
63
41
|
logger.info(message)
|
|
64
42
|
await next()
|
|
65
43
|
})
|
|
@@ -71,26 +49,21 @@ test('pikkuMiddlewareFactory creates a factory function', async () => {
|
|
|
71
49
|
// Call the factory to get middleware
|
|
72
50
|
const middleware = factory({ message: 'test' })
|
|
73
51
|
assert.strictEqual(typeof middleware, 'function')
|
|
74
|
-
assert.strictEqual(middleware.length, 3) // services,
|
|
52
|
+
assert.strictEqual(middleware.length, 3) // services, wires, next
|
|
75
53
|
})
|
|
76
54
|
|
|
77
55
|
test('pikkuPermissionFactory returns the same factory', async () => {
|
|
78
|
-
const originalFactory = (
|
|
79
|
-
|
|
80
|
-
return session?.role === role
|
|
81
|
-
})
|
|
82
|
-
const wrappedFactory = pikkuPermissionFactory(originalFactory)
|
|
83
|
-
|
|
56
|
+
const originalFactory = () => pikkuPermission(async () => true)
|
|
57
|
+
const wrappedFactory = pikkuPermissionFactory(originalFactory as any)
|
|
84
58
|
assert.strictEqual(wrappedFactory, originalFactory)
|
|
85
59
|
})
|
|
86
60
|
|
|
87
61
|
test('pikkuMiddlewareFactory returns the same factory', async () => {
|
|
88
62
|
const originalFactory = ({ message }) =>
|
|
89
|
-
pikkuMiddleware(async ({ logger },
|
|
63
|
+
pikkuMiddleware(async ({ logger }, _wires, next) => {
|
|
90
64
|
logger.info(message)
|
|
91
65
|
await next()
|
|
92
66
|
})
|
|
93
67
|
const wrappedFactory = pikkuMiddlewareFactory(originalFactory)
|
|
94
|
-
|
|
95
68
|
assert.strictEqual(wrappedFactory, originalFactory)
|
|
96
69
|
})
|