@pikku/core 0.11.0 → 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 (105) hide show
  1. package/CHANGELOG.md +11 -1
  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 +22 -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/middleware/auth-apikey.js +3 -3
  11. package/dist/middleware/auth-bearer.js +3 -3
  12. package/dist/middleware/auth-cookie.js +5 -5
  13. package/dist/middleware/timeout.js +3 -2
  14. package/dist/middleware-runner.d.ts +3 -6
  15. package/dist/middleware-runner.js +11 -12
  16. package/dist/permissions.d.ts +6 -6
  17. package/dist/permissions.js +15 -16
  18. package/dist/services/user-session-service.d.ts +7 -3
  19. package/dist/services/user-session-service.js +8 -1
  20. package/dist/types/core.types.d.ts +29 -38
  21. package/dist/types/core.types.js +3 -14
  22. package/dist/utils.d.ts +1 -1
  23. package/dist/utils.js +3 -3
  24. package/dist/wirings/channel/channel-common.js +2 -3
  25. package/dist/wirings/channel/channel-handler.d.ts +3 -2
  26. package/dist/wirings/channel/channel-handler.js +6 -9
  27. package/dist/wirings/channel/channel-runner.d.ts +2 -2
  28. package/dist/wirings/channel/channel.types.d.ts +10 -5
  29. package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
  30. package/dist/wirings/channel/local/local-channel-runner.js +19 -26
  31. package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
  32. package/dist/wirings/channel/serverless/serverless-channel-runner.js +41 -46
  33. package/dist/wirings/cli/cli-runner.d.ts +5 -5
  34. package/dist/wirings/cli/cli-runner.js +10 -28
  35. package/dist/wirings/cli/cli.types.d.ts +15 -11
  36. package/dist/wirings/http/http-runner.d.ts +6 -6
  37. package/dist/wirings/http/http-runner.js +25 -39
  38. package/dist/wirings/http/http.types.d.ts +5 -10
  39. package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
  40. package/dist/wirings/mcp/mcp-runner.js +12 -19
  41. package/dist/wirings/mcp/mcp.types.d.ts +6 -0
  42. package/dist/wirings/queue/queue-runner.d.ts +3 -3
  43. package/dist/wirings/queue/queue-runner.js +7 -17
  44. package/dist/wirings/queue/queue.types.d.ts +4 -11
  45. package/dist/wirings/rpc/rpc-runner.d.ts +10 -8
  46. package/dist/wirings/rpc/rpc-runner.js +36 -47
  47. package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
  48. package/dist/wirings/scheduler/scheduler-runner.js +13 -24
  49. package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
  50. package/dist/wirings/workflow/index.d.ts +11 -2
  51. package/dist/wirings/workflow/index.js +10 -2
  52. package/dist/wirings/workflow/pikku-workflow-service.d.ts +12 -4
  53. package/dist/wirings/workflow/pikku-workflow-service.js +61 -79
  54. package/dist/wirings/workflow/workflow-runner.d.ts +3 -4
  55. package/dist/wirings/workflow/workflow-runner.js +11 -14
  56. package/dist/wirings/workflow/workflow.types.d.ts +114 -29
  57. package/package.json +2 -2
  58. package/src/errors/errors.ts +3 -3
  59. package/src/factory-functions.test.ts +9 -36
  60. package/src/function/function-runner.test.ts +57 -68
  61. package/src/function/function-runner.ts +51 -28
  62. package/src/function/function-runner.ts.bak +188 -0
  63. package/src/function/functions.types.ts +68 -51
  64. package/src/handle-error.ts +1 -1
  65. package/src/middleware/auth-apikey.test.ts +360 -0
  66. package/src/middleware/auth-apikey.ts +3 -7
  67. package/src/middleware/auth-bearer.test.ts +447 -0
  68. package/src/middleware/auth-bearer.ts +27 -33
  69. package/src/middleware/auth-cookie.test.ts +525 -0
  70. package/src/middleware/auth-cookie.ts +6 -6
  71. package/src/middleware/timeout.ts +4 -2
  72. package/src/middleware-runner.test.ts +58 -127
  73. package/src/middleware-runner.ts +13 -16
  74. package/src/permissions.test.ts +41 -45
  75. package/src/permissions.ts +21 -21
  76. package/src/services/user-session-service.ts +14 -4
  77. package/src/types/core.types.ts +67 -55
  78. package/src/utils.ts +4 -4
  79. package/src/wirings/channel/channel-common.ts +4 -7
  80. package/src/wirings/channel/channel-handler.ts +16 -22
  81. package/src/wirings/channel/channel-runner.ts +2 -2
  82. package/src/wirings/channel/channel.types.ts +14 -11
  83. package/src/wirings/channel/local/local-channel-runner.test.ts +5 -3
  84. package/src/wirings/channel/local/local-channel-runner.ts +23 -38
  85. package/src/wirings/channel/serverless/serverless-channel-runner.ts +51 -77
  86. package/src/wirings/cli/cli-runner.test.ts +7 -7
  87. package/src/wirings/cli/cli-runner.ts +24 -62
  88. package/src/wirings/cli/cli.types.ts +22 -16
  89. package/src/wirings/http/http-runner.test.ts +8 -8
  90. package/src/wirings/http/http-runner.ts +29 -56
  91. package/src/wirings/http/http.types.ts +5 -14
  92. package/src/wirings/mcp/mcp-runner.ts +23 -48
  93. package/src/wirings/mcp/mcp.types.ts +6 -0
  94. package/src/wirings/queue/queue-runner.test.ts +641 -0
  95. package/src/wirings/queue/queue-runner.ts +10 -32
  96. package/src/wirings/queue/queue.types.ts +4 -11
  97. package/src/wirings/rpc/rpc-runner.ts +41 -55
  98. package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
  99. package/src/wirings/scheduler/scheduler-runner.ts +24 -50
  100. package/src/wirings/scheduler/scheduler.types.ts +3 -9
  101. package/src/wirings/workflow/index.ts +24 -3
  102. package/src/wirings/workflow/pikku-workflow-service.ts +83 -93
  103. package/src/wirings/workflow/workflow-runner.ts +12 -25
  104. package/src/wirings/workflow/workflow.types.ts +144 -54
  105. package/tsconfig.tsbuildinfo +1 -1
@@ -1,10 +1,9 @@
1
1
  import {
2
- PikkuDocs,
3
- MiddlewareMetadata,
4
2
  SerializedError,
5
3
  CoreSingletonServices,
6
- CreateSessionServices,
4
+ CreateWireServices,
7
5
  CoreConfig,
6
+ CommonWireMeta,
8
7
  } from '../../types/core.types.js'
9
8
  import { CorePikkuFunctionConfig } from '../../function/functions.types.js'
10
9
 
@@ -97,8 +96,6 @@ export type CoreWorkflow<
97
96
  > = {
98
97
  /** Unique workflow name */
99
98
  name: string
100
- /** Description of the workflow */
101
- description?: string
102
99
  /** The workflow function */
103
100
  func: PikkuFunctionConfig
104
101
  /** Middleware chain for this workflow */
@@ -107,8 +104,6 @@ export type CoreWorkflow<
107
104
  permissions?: PikkuFunctionConfig['permissions']
108
105
  /** Tags for organization and filtering */
109
106
  tags?: string[]
110
- /** Documentation metadata */
111
- docs?: PikkuDocs
112
107
  }
113
108
 
114
109
  /**
@@ -127,7 +122,7 @@ export interface WorkflowStepOptions {
127
122
  /**
128
123
  * Type signature for workflow.do() RPC form - used by inspector
129
124
  */
130
- export type WorkflowInteractionDoRPC = <TOutput = any, TInput = any>(
125
+ export type WorkflowWireDoRPC = <TOutput = any, TInput = any>(
131
126
  stepName: string,
132
127
  rpcName: string,
133
128
  data: TInput,
@@ -137,7 +132,7 @@ export type WorkflowInteractionDoRPC = <TOutput = any, TInput = any>(
137
132
  /**
138
133
  * Type signature for workflow.do() inline form - used by inspector
139
134
  */
140
- export type WorkflowInteractionDoInline = <T>(
135
+ export type WorkflowWireDoInline = <T>(
141
136
  stepName: string,
142
137
  fn: () => Promise<T> | T,
143
138
  options?: WorkflowStepOptions
@@ -146,51 +141,150 @@ export type WorkflowInteractionDoInline = <T>(
146
141
  /**
147
142
  * Type signature for workflow.sleep() - used by inspector
148
143
  */
149
- export type WorkflowInteractionSleep = (
144
+ export type WorkflowWireSleep = (
150
145
  stepName: string,
151
146
  duration: string
152
147
  ) => Promise<void>
153
148
 
149
+ /**
150
+ * Input source for step arguments in simple workflows
151
+ */
152
+ export type InputSource =
153
+ | { from: 'input'; path: string }
154
+ | { from: 'outputVar'; name: string; path?: string }
155
+ | { from: 'item'; path: string }
156
+ | { from: 'literal'; value: unknown }
157
+
158
+ /**
159
+ * Output binding for return statements in simple workflows
160
+ */
161
+ export interface OutputBinding {
162
+ from: 'outputVar' | 'input'
163
+ name?: string
164
+ path?: string
165
+ }
166
+
167
+ /**
168
+ * RPC step metadata (base form)
169
+ */
170
+ export interface RpcStepMeta {
171
+ /** RPC form - generates queue worker */
172
+ type: 'rpc'
173
+ /** Cache key (stepName from workflow.do) */
174
+ stepName: string
175
+ /** RPC to invoke */
176
+ rpcName: string
177
+ /** Output variable name (if assigned) */
178
+ outputVar?: string
179
+ /** Input source mappings */
180
+ inputs?: Record<string, InputSource>
181
+ /** Step options */
182
+ options?: WorkflowStepOptions
183
+ }
184
+
185
+ /**
186
+ * Branch step metadata (if/else control flow)
187
+ */
188
+ export interface BranchStepMeta {
189
+ type: 'branch'
190
+ /** Condition expression (as source string) */
191
+ condition: string
192
+ /** Branch paths */
193
+ branches: {
194
+ then: WorkflowStepMeta[]
195
+ else?: WorkflowStepMeta[]
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Parallel group step metadata (Promise.all with multiple steps)
201
+ */
202
+ export interface ParallelGroupStepMeta {
203
+ type: 'parallel'
204
+ /** Child steps to execute in parallel */
205
+ children: RpcStepMeta[]
206
+ }
207
+
208
+ /**
209
+ * Fanout step metadata (parallel or sequential iteration)
210
+ */
211
+ export interface FanoutStepMeta {
212
+ type: 'fanout'
213
+ /** Step name for this fanout */
214
+ stepName: string
215
+ /** Source array variable name */
216
+ sourceVar: string
217
+ /** Iterator variable name */
218
+ itemVar: string
219
+ /** Execution mode */
220
+ mode: 'parallel' | 'sequential'
221
+ /** Child step to execute per iteration */
222
+ child: RpcStepMeta
223
+ /** Time between iterations (sequential mode only) */
224
+ timeBetween?: string
225
+ }
226
+
227
+ /**
228
+ * Return step metadata (workflow output)
229
+ */
230
+ export interface ReturnStepMeta {
231
+ type: 'return'
232
+ /** Output bindings */
233
+ outputs: Record<string, OutputBinding>
234
+ }
235
+
236
+ /**
237
+ * Inline step metadata (legacy support)
238
+ */
239
+ export interface InlineStepMeta {
240
+ /** Inline form - local execution */
241
+ type: 'inline'
242
+ /** Cache key (stepName from workflow.do) */
243
+ stepName: string
244
+ /** Display name */
245
+ description?: string
246
+ /** Step options */
247
+ options?: WorkflowStepOptions
248
+ }
249
+
250
+ /**
251
+ * Sleep step metadata
252
+ */
253
+ export interface SleepStepMeta {
254
+ /** Sleep step */
255
+ type: 'sleep'
256
+ /** Cache key (stepName from workflow.sleep) */
257
+ stepName: string
258
+ /** Sleep duration */
259
+ duration: string | number
260
+ }
261
+
262
+ /**
263
+ * Cancel step metadata
264
+ */
265
+ export interface CancelStepMeta {
266
+ /** Cancel step */
267
+ type: 'cancel'
268
+ }
269
+
154
270
  /**
155
271
  * Workflow step metadata (extracted by inspector)
156
272
  */
157
273
  export type WorkflowStepMeta =
158
- | {
159
- /** RPC form - generates queue worker */
160
- type: 'rpc'
161
- /** Cache key (stepName from workflow.do) */
162
- stepName: string
163
- /** RPC to invoke */
164
- rpcName: string
165
- /** Display name */
166
- description?: string
167
- /** Step options */
168
- options?: WorkflowStepOptions
169
- }
170
- | {
171
- /** Inline form - local execution */
172
- type: 'inline'
173
- /** Cache key (stepName from workflow.do) */
174
- stepName: string
175
- /** Display name */
176
- description?: string
177
- /** Step options */
178
- options?: WorkflowStepOptions
179
- }
180
- | {
181
- /** Sleep step */
182
- type: 'sleep'
183
- /** Cache key (stepName from workflow.sleep) */
184
- stepName: string
185
- /** Sleep duration */
186
- duration: string | number
187
- }
274
+ | RpcStepMeta
275
+ | BranchStepMeta
276
+ | ParallelGroupStepMeta
277
+ | FanoutStepMeta
278
+ | ReturnStepMeta
279
+ | InlineStepMeta
280
+ | SleepStepMeta
281
+ | CancelStepMeta
188
282
 
189
283
  /**
190
- * Workflow step interaction context for RPC functions
284
+ * Workflow step wire context for RPC functions
191
285
  * Provides step-level metadata including retry attempt tracking
192
286
  */
193
- export interface WorkflowStepInteraction {
287
+ export interface WorkflowStepWire {
194
288
  /** The workflow run ID */
195
289
  runId: string
196
290
  /** The unique step ID */
@@ -200,10 +294,10 @@ export interface WorkflowStepInteraction {
200
294
  }
201
295
 
202
296
  /**
203
- * Workflow interaction object for middleware
297
+ * Workflow wire object for middleware
204
298
  * Provides workflow-specific capabilities to function execution
205
299
  */
206
- export interface PikkuWorkflowInteraction {
300
+ export interface PikkuWorkflowWire {
207
301
  /** The workflow name */
208
302
  workflowName: string
209
303
  /** The current run ID */
@@ -212,10 +306,10 @@ export interface PikkuWorkflowInteraction {
212
306
  getRun: () => Promise<WorkflowRun>
213
307
 
214
308
  /** Execute a workflow step (overloaded - RPC or inline form) */
215
- do: WorkflowInteractionDoRPC & WorkflowInteractionDoInline
309
+ do: WorkflowWireDoRPC & WorkflowWireDoInline
216
310
 
217
311
  /** Sleep for a duration */
218
- sleep: WorkflowInteractionSleep
312
+ sleep: WorkflowWireSleep
219
313
 
220
314
  /** Cancel the current workflow run */
221
315
  cancel: (reason?: string) => Promise<void>
@@ -238,15 +332,11 @@ export interface PikkuWorkflow {
238
332
  */
239
333
  export type WorkflowsMeta = Record<
240
334
  string,
241
- {
242
- pikkuFuncName: string
335
+ CommonWireMeta & {
243
336
  workflowName: string
244
- description?: string
245
- session?: undefined
246
- docs?: PikkuDocs
247
- tags?: string[]
248
- middleware?: MiddlewareMetadata[]
249
337
  steps: WorkflowStepMeta[]
338
+ /** Whether this workflow conforms to simple workflow DSL */
339
+ simple?: boolean
250
340
  }
251
341
  >
252
342
 
@@ -272,7 +362,7 @@ export interface WorkflowService {
272
362
  resumeWorkflow(runId: string): Promise<void>
273
363
  setServices(
274
364
  singletonServices: CoreSingletonServices,
275
- createSessionServices: CreateSessionServices,
365
+ createWireServices: CreateWireServices,
276
366
  config: CoreConfig
277
367
  ): void
278
368
  startWorkflow<I>(