@pikku/core 0.11.1 → 0.11.2

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 (143) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/errors/error-handler.js +3 -3
  3. package/dist/function/function-runner.d.ts +4 -3
  4. package/dist/function/function-runner.js +60 -14
  5. package/dist/function/functions.types.d.ts +84 -5
  6. package/dist/function/functions.types.js +41 -1
  7. package/dist/index.d.ts +6 -2
  8. package/dist/index.js +5 -2
  9. package/dist/middleware/auth-apikey.d.ts +1 -1
  10. package/dist/middleware/auth-bearer.d.ts +1 -1
  11. package/dist/middleware/auth-cookie.d.ts +1 -1
  12. package/dist/middleware/timeout.d.ts +1 -1
  13. package/dist/middleware-runner.d.ts +3 -14
  14. package/dist/middleware-runner.js +8 -8
  15. package/dist/permissions.d.ts +3 -86
  16. package/dist/permissions.js +11 -67
  17. package/dist/pikku-state.d.ts +32 -104
  18. package/dist/pikku-state.js +140 -66
  19. package/dist/schema.d.ts +8 -6
  20. package/dist/schema.js +25 -13
  21. package/dist/services/workflow-service.d.ts +38 -0
  22. package/dist/services/workflow-service.js +1 -0
  23. package/dist/types/core.types.d.ts +12 -4
  24. package/dist/types/core.types.js +1 -1
  25. package/dist/types/state.types.d.ts +135 -0
  26. package/dist/types/state.types.js +1 -0
  27. package/dist/utils.d.ts +8 -0
  28. package/dist/utils.js +45 -0
  29. package/dist/wirings/channel/channel-handler.js +1 -1
  30. package/dist/wirings/channel/channel-runner.js +5 -5
  31. package/dist/wirings/channel/log-channels.js +1 -1
  32. package/dist/wirings/channel/serverless/serverless-channel-runner.js +2 -2
  33. package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
  34. package/dist/wirings/cli/cli-runner.js +10 -10
  35. package/dist/wirings/cli/cli.types.d.ts +1 -0
  36. package/dist/wirings/forge-node/forge-node.types.d.ts +120 -0
  37. package/dist/wirings/forge-node/forge-node.types.js +38 -0
  38. package/dist/wirings/forge-node/index.d.ts +1 -0
  39. package/dist/wirings/forge-node/index.js +1 -0
  40. package/dist/wirings/http/http-runner.d.ts +2 -2
  41. package/dist/wirings/http/http-runner.js +21 -12
  42. package/dist/wirings/http/http.types.d.ts +14 -1
  43. package/dist/wirings/http/log-http-routes.js +1 -1
  44. package/dist/wirings/http/routers/path-to-regex.js +2 -2
  45. package/dist/wirings/mcp/mcp-runner.js +21 -21
  46. package/dist/wirings/queue/queue-runner.js +6 -6
  47. package/dist/wirings/rpc/index.d.ts +1 -1
  48. package/dist/wirings/rpc/index.js +1 -1
  49. package/dist/wirings/rpc/rpc-runner.d.ts +7 -8
  50. package/dist/wirings/rpc/rpc-runner.js +62 -14
  51. package/dist/wirings/rpc/rpc-types.d.ts +7 -0
  52. package/dist/wirings/scheduler/log-schedulers.js +1 -1
  53. package/dist/wirings/scheduler/scheduler-runner.js +5 -5
  54. package/dist/wirings/trigger/index.d.ts +2 -0
  55. package/dist/wirings/trigger/index.js +2 -0
  56. package/dist/wirings/trigger/trigger-runner.d.ts +29 -0
  57. package/dist/wirings/trigger/trigger-runner.js +57 -0
  58. package/dist/wirings/trigger/trigger.types.d.ts +42 -0
  59. package/dist/wirings/trigger/trigger.types.js +1 -0
  60. package/dist/wirings/workflow/dsl/index.d.ts +5 -0
  61. package/dist/wirings/workflow/dsl/index.js +4 -0
  62. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +286 -0
  63. package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
  64. package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
  65. package/dist/wirings/workflow/dsl/workflow-runner.js +22 -0
  66. package/dist/wirings/workflow/graph/graph-node.d.ts +122 -0
  67. package/dist/wirings/workflow/graph/graph-node.js +58 -0
  68. package/dist/wirings/workflow/graph/graph-runner.d.ts +35 -0
  69. package/dist/wirings/workflow/graph/graph-runner.js +452 -0
  70. package/dist/wirings/workflow/graph/index.d.ts +3 -0
  71. package/dist/wirings/workflow/graph/index.js +3 -0
  72. package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +95 -0
  73. package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
  74. package/dist/wirings/workflow/index.d.ts +7 -12
  75. package/dist/wirings/workflow/index.js +6 -11
  76. package/dist/wirings/workflow/pikku-workflow-service.d.ts +96 -6
  77. package/dist/wirings/workflow/pikku-workflow-service.js +230 -103
  78. package/dist/wirings/workflow/wire-workflow.d.ts +42 -0
  79. package/dist/wirings/workflow/wire-workflow.js +53 -0
  80. package/dist/wirings/workflow/workflow-utils.d.ts +23 -0
  81. package/dist/wirings/workflow/workflow-utils.js +66 -0
  82. package/dist/wirings/workflow/workflow.types.d.ts +133 -211
  83. package/package.json +10 -1
  84. package/src/errors/error-handler.ts +3 -3
  85. package/src/function/function-runner.test.ts +1 -1
  86. package/src/function/function-runner.ts +86 -16
  87. package/src/function/functions.types.ts +126 -4
  88. package/src/index.ts +10 -5
  89. package/src/middleware-runner.ts +16 -9
  90. package/src/permissions.test.ts +28 -86
  91. package/src/permissions.ts +21 -80
  92. package/src/pikku-state.ts +156 -201
  93. package/src/schema.ts +42 -13
  94. package/src/services/workflow-service.ts +74 -0
  95. package/src/types/core.types.ts +12 -3
  96. package/src/types/state.types.ts +195 -0
  97. package/src/utils.ts +55 -0
  98. package/src/wirings/channel/channel-handler.ts +1 -1
  99. package/src/wirings/channel/channel-runner.ts +5 -5
  100. package/src/wirings/channel/local/local-channel-runner.test.ts +3 -1
  101. package/src/wirings/channel/log-channels.ts +1 -1
  102. package/src/wirings/channel/serverless/serverless-channel-runner.ts +2 -2
  103. package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
  104. package/src/wirings/cli/cli-runner.test.ts +19 -19
  105. package/src/wirings/cli/cli-runner.ts +10 -9
  106. package/src/wirings/cli/cli.types.ts +1 -0
  107. package/src/wirings/forge-node/forge-node.types.ts +135 -0
  108. package/src/wirings/forge-node/index.ts +1 -0
  109. package/src/wirings/http/http-runner.test.ts +2 -2
  110. package/src/wirings/http/http-runner.ts +30 -13
  111. package/src/wirings/http/http.types.ts +14 -0
  112. package/src/wirings/http/log-http-routes.ts +1 -1
  113. package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
  114. package/src/wirings/http/routers/path-to-regex.ts +2 -2
  115. package/src/wirings/mcp/mcp-runner.ts +21 -21
  116. package/src/wirings/queue/queue-runner.test.ts +19 -19
  117. package/src/wirings/queue/queue-runner.ts +6 -6
  118. package/src/wirings/rpc/index.ts +1 -1
  119. package/src/wirings/rpc/rpc-runner.ts +88 -22
  120. package/src/wirings/rpc/rpc-types.ts +8 -0
  121. package/src/wirings/scheduler/log-schedulers.ts +1 -1
  122. package/src/wirings/scheduler/scheduler-runner.test.ts +27 -27
  123. package/src/wirings/scheduler/scheduler-runner.ts +5 -5
  124. package/src/wirings/trigger/index.ts +2 -0
  125. package/src/wirings/trigger/trigger-runner.ts +96 -0
  126. package/src/wirings/trigger/trigger.types.ts +56 -0
  127. package/src/wirings/workflow/dsl/index.ts +30 -0
  128. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +312 -0
  129. package/src/wirings/workflow/dsl/workflow-runner.ts +27 -0
  130. package/src/wirings/workflow/graph/graph-node.ts +227 -0
  131. package/src/wirings/workflow/graph/graph-runner.ts +694 -0
  132. package/src/wirings/workflow/graph/index.ts +3 -0
  133. package/src/wirings/workflow/graph/workflow-graph.types.ts +126 -0
  134. package/src/wirings/workflow/index.ts +53 -26
  135. package/src/wirings/workflow/pikku-workflow-service.ts +333 -117
  136. package/src/wirings/workflow/wire-workflow.ts +94 -0
  137. package/src/wirings/workflow/workflow-utils.ts +120 -0
  138. package/src/wirings/workflow/workflow.types.ts +166 -277
  139. package/tsconfig.tsbuildinfo +1 -1
  140. package/dist/wirings/workflow/workflow-runner.d.ts +0 -34
  141. package/dist/wirings/workflow/workflow-runner.js +0 -65
  142. package/src/function/function-runner.ts.bak +0 -188
  143. package/src/wirings/workflow/workflow-runner.ts +0 -72
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Ref value - internal representation after input callback is evaluated
3
+ */
4
+ export interface RefValue {
5
+ __isRef: true
6
+ nodeId: string
7
+ path?: string
8
+ }
9
+
10
+ /**
11
+ * Helper to create a ref value
12
+ */
13
+ export const createRef = (nodeId: string, path?: string): RefValue => ({
14
+ __isRef: true,
15
+ nodeId,
16
+ path,
17
+ })
18
+
19
+ /**
20
+ * Check if a value is a ref
21
+ */
22
+ export const isRef = (value: unknown): value is RefValue =>
23
+ typeof value === 'object' &&
24
+ value !== null &&
25
+ '__isRef' in value &&
26
+ (value as RefValue).__isRef === true
27
+
28
+ /**
29
+ * Input reference for fetching step results
30
+ */
31
+ export interface InputRef {
32
+ nodeId: string
33
+ path?: string
34
+ }
35
+
36
+ /**
37
+ * Ref function type - provides type-safe references to other nodes' outputs
38
+ * The actual typing is done at the pikkuWorkflowGraph level
39
+ */
40
+ export type RefFn<NodeIds extends string = string> = (
41
+ nodeId: NodeIds,
42
+ path?: string
43
+ ) => RefValue
44
+
45
+ /**
46
+ * Next node configuration - fully serializable
47
+ * - string: single next node
48
+ * - string[]: parallel execution (all run concurrently)
49
+ * - Record<string, string | string[]>: branching (function calls graph.branch('key'))
50
+ */
51
+ export type NextConfig<NodeIds extends string = string> =
52
+ | NodeIds
53
+ | NodeIds[]
54
+ | Record<string, NodeIds | NodeIds[]>
55
+
56
+ /**
57
+ * Graph node configuration - references functions by RPC name
58
+ */
59
+ export interface GraphNodeConfig<NodeIds extends string = string> {
60
+ /** RPC function name */
61
+ func: string
62
+ /** Input mapping callback - receives ref function, returns input object */
63
+ input?: (ref: RefFn<NodeIds>) => Record<string, unknown>
64
+ /** Next nodes - string, array, or record for branching */
65
+ next?: NextConfig<NodeIds>
66
+ /** Error routing - node(s) to execute on error */
67
+ onError?: NodeIds | NodeIds[]
68
+ }
69
+
70
+ // Import unified wire types from workflow module
71
+ import type { WorkflowWires } from '../workflow.types.js'
72
+
73
+ export type { WorkflowWires }
74
+
75
+ /**
76
+ * Workflow graph definition (internal use)
77
+ */
78
+ export interface WorkflowGraphDefinition<
79
+ Nodes extends Record<string, GraphNodeConfig<string>> = Record<
80
+ string,
81
+ GraphNodeConfig
82
+ >,
83
+ > {
84
+ /** Unique workflow name */
85
+ name: string
86
+ /** Wire configuration */
87
+ wires: WorkflowWires
88
+ /** Graph nodes */
89
+ graph: Nodes
90
+ }
91
+
92
+ /**
93
+ * Graph wire context - available to functions running in a workflow graph
94
+ */
95
+ export interface PikkuGraphWire {
96
+ /** Workflow run ID */
97
+ runId: string
98
+ /** Graph name */
99
+ graphName: string
100
+ /** Current node ID */
101
+ nodeId: string
102
+ /**
103
+ * Select which branch to take for Record-based next config.
104
+ * Must be called if the node has a Record `next` configuration.
105
+ * @param key - The branch key to take (must match a key in the next Record)
106
+ */
107
+ branch: (key: string) => void
108
+ /**
109
+ * Set a state variable value.
110
+ * @param name - Variable name
111
+ * @param value - Value to store
112
+ */
113
+ setState: (name: string, value: unknown) => Promise<void>
114
+ /**
115
+ * Get the entire state object.
116
+ * @returns The state object with all variables
117
+ */
118
+ getState: () => Promise<Record<string, unknown>>
119
+ }
120
+
121
+ /**
122
+ * Internal mutable state for graph wire (used by runner to capture branch)
123
+ */
124
+ export interface GraphWireState {
125
+ branchKey?: string
126
+ }
@@ -1,13 +1,57 @@
1
1
  /**
2
2
  * Workflow module exports
3
3
  */
4
+ export {
5
+ PikkuWorkflowService,
6
+ WorkflowCancelledException,
7
+ } from './pikku-workflow-service.js'
4
8
 
5
- // Types
9
+ // Internal registration functions (used by generated code)
10
+ export { addWorkflow } from './dsl/workflow-runner.js'
11
+ export { addWorkflowGraph } from './graph/graph-runner.js'
12
+
13
+ // Unified wireWorkflow function
14
+ export { wireWorkflow } from './wire-workflow.js'
15
+ export type {
16
+ WorkflowDefinition,
17
+ WorkflowDefinitionFunc,
18
+ WorkflowDefinitionGraph,
19
+ } from './wire-workflow.js'
20
+
21
+ // Re-export all types from workflow.types
6
22
  export type {
23
+ WorkflowService,
24
+ WorkflowServiceConfig,
25
+ WorkflowHTTPWire,
26
+ WorkflowWires,
27
+ WorkflowStatus,
28
+ StepStatus,
29
+ WorkflowRun,
30
+ StepState,
7
31
  CoreWorkflow,
32
+ PikkuWorkflow,
33
+ ContextVariable,
34
+ WorkflowContext,
35
+ WorkflowsMeta,
36
+ WorkflowRuntimeMeta,
37
+ WorkflowsRuntimeMeta,
38
+ WorkflowStepInput,
39
+ WorkflowOrchestratorInput,
40
+ WorkflowSleeperInput,
41
+ } from './workflow.types.js'
42
+
43
+ // Re-export DSL types
44
+ export type {
8
45
  WorkflowStepOptions,
9
- WorkflowStepMeta,
46
+ WorkflowWireDoRPC,
47
+ WorkflowWireDoInline,
48
+ WorkflowWireSleep,
49
+ InputSource,
50
+ OutputBinding,
10
51
  RpcStepMeta,
52
+ SimpleCondition,
53
+ Condition,
54
+ BranchCase,
11
55
  BranchStepMeta,
12
56
  ParallelGroupStepMeta,
13
57
  FanoutStepMeta,
@@ -15,29 +59,12 @@ export type {
15
59
  InlineStepMeta,
16
60
  SleepStepMeta,
17
61
  CancelStepMeta,
18
- InputSource,
19
- OutputBinding,
62
+ SetStepMeta,
63
+ SwitchCaseMeta,
64
+ SwitchStepMeta,
65
+ FilterStepMeta,
66
+ ArrayPredicateStepMeta,
67
+ WorkflowStepMeta,
68
+ WorkflowStepWire,
20
69
  PikkuWorkflowWire,
21
- PikkuWorkflow,
22
- WorkflowsMeta,
23
- WorkflowRun,
24
- StepState,
25
- WorkflowStatus,
26
- StepStatus,
27
70
  } from './workflow.types.js'
28
-
29
- export { PikkuWorkflowService } from './pikku-workflow-service.js'
30
-
31
- // Internal registration function (used by generated code)
32
- export { addWorkflow } from './workflow-runner.js'
33
-
34
- /**
35
- * @deprecated This function is no longer used and will be removed in a future release.
36
- * It exists only for backwards compatibility with generated code.
37
- * TODO: Remove this export in a future release after updating code generation
38
- */
39
- export const wireWorkflow = <T extends { name: string; func: any }>(
40
- workflow: T
41
- ): void => {
42
- // Empty function - no longer used, kept for backwards compatibility
43
- }