@pikku/core 0.11.0 → 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 (184) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/dist/errors/error-handler.js +3 -3
  3. package/dist/errors/errors.d.ts +1 -1
  4. package/dist/errors/errors.js +3 -3
  5. package/dist/function/function-runner.d.ts +8 -8
  6. package/dist/function/function-runner.js +88 -23
  7. package/dist/function/functions.types.d.ts +104 -33
  8. package/dist/function/functions.types.js +50 -7
  9. package/dist/handle-error.d.ts +1 -1
  10. package/dist/handle-error.js +1 -1
  11. package/dist/index.d.ts +6 -2
  12. package/dist/index.js +5 -2
  13. package/dist/middleware/auth-apikey.d.ts +1 -1
  14. package/dist/middleware/auth-apikey.js +3 -3
  15. package/dist/middleware/auth-bearer.d.ts +1 -1
  16. package/dist/middleware/auth-bearer.js +3 -3
  17. package/dist/middleware/auth-cookie.d.ts +1 -1
  18. package/dist/middleware/auth-cookie.js +5 -5
  19. package/dist/middleware/timeout.d.ts +1 -1
  20. package/dist/middleware/timeout.js +3 -2
  21. package/dist/middleware-runner.d.ts +6 -20
  22. package/dist/middleware-runner.js +19 -20
  23. package/dist/permissions.d.ts +6 -89
  24. package/dist/permissions.js +24 -81
  25. package/dist/pikku-state.d.ts +32 -104
  26. package/dist/pikku-state.js +140 -66
  27. package/dist/schema.d.ts +8 -6
  28. package/dist/schema.js +25 -13
  29. package/dist/services/user-session-service.d.ts +7 -3
  30. package/dist/services/user-session-service.js +8 -1
  31. package/dist/services/workflow-service.d.ts +38 -0
  32. package/dist/services/workflow-service.js +1 -0
  33. package/dist/types/core.types.d.ts +40 -41
  34. package/dist/types/core.types.js +4 -15
  35. package/dist/types/state.types.d.ts +135 -0
  36. package/dist/types/state.types.js +1 -0
  37. package/dist/utils.d.ts +9 -1
  38. package/dist/utils.js +48 -3
  39. package/dist/wirings/channel/channel-common.js +2 -3
  40. package/dist/wirings/channel/channel-handler.d.ts +3 -2
  41. package/dist/wirings/channel/channel-handler.js +7 -10
  42. package/dist/wirings/channel/channel-runner.d.ts +2 -2
  43. package/dist/wirings/channel/channel-runner.js +5 -5
  44. package/dist/wirings/channel/channel.types.d.ts +10 -5
  45. package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
  46. package/dist/wirings/channel/local/local-channel-runner.js +19 -26
  47. package/dist/wirings/channel/log-channels.js +1 -1
  48. package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
  49. package/dist/wirings/channel/serverless/serverless-channel-runner.js +43 -48
  50. package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
  51. package/dist/wirings/cli/cli-runner.d.ts +5 -5
  52. package/dist/wirings/cli/cli-runner.js +20 -38
  53. package/dist/wirings/cli/cli.types.d.ts +16 -11
  54. package/dist/wirings/forge-node/forge-node.types.d.ts +120 -0
  55. package/dist/wirings/forge-node/forge-node.types.js +38 -0
  56. package/dist/wirings/forge-node/index.d.ts +1 -0
  57. package/dist/wirings/forge-node/index.js +1 -0
  58. package/dist/wirings/http/http-runner.d.ts +8 -8
  59. package/dist/wirings/http/http-runner.js +46 -51
  60. package/dist/wirings/http/http.types.d.ts +19 -11
  61. package/dist/wirings/http/log-http-routes.js +1 -1
  62. package/dist/wirings/http/routers/path-to-regex.js +2 -2
  63. package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
  64. package/dist/wirings/mcp/mcp-runner.js +33 -40
  65. package/dist/wirings/mcp/mcp.types.d.ts +6 -0
  66. package/dist/wirings/queue/queue-runner.d.ts +3 -3
  67. package/dist/wirings/queue/queue-runner.js +13 -23
  68. package/dist/wirings/queue/queue.types.d.ts +4 -11
  69. package/dist/wirings/rpc/index.d.ts +1 -1
  70. package/dist/wirings/rpc/index.js +1 -1
  71. package/dist/wirings/rpc/rpc-runner.d.ts +17 -16
  72. package/dist/wirings/rpc/rpc-runner.js +98 -61
  73. package/dist/wirings/rpc/rpc-types.d.ts +7 -0
  74. package/dist/wirings/scheduler/log-schedulers.js +1 -1
  75. package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
  76. package/dist/wirings/scheduler/scheduler-runner.js +18 -29
  77. package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
  78. package/dist/wirings/trigger/index.d.ts +2 -0
  79. package/dist/wirings/trigger/index.js +2 -0
  80. package/dist/wirings/trigger/trigger-runner.d.ts +29 -0
  81. package/dist/wirings/trigger/trigger-runner.js +57 -0
  82. package/dist/wirings/trigger/trigger.types.d.ts +42 -0
  83. package/dist/wirings/trigger/trigger.types.js +1 -0
  84. package/dist/wirings/workflow/dsl/index.d.ts +5 -0
  85. package/dist/wirings/workflow/dsl/index.js +4 -0
  86. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +286 -0
  87. package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
  88. package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
  89. package/dist/wirings/workflow/dsl/workflow-runner.js +22 -0
  90. package/dist/wirings/workflow/graph/graph-node.d.ts +122 -0
  91. package/dist/wirings/workflow/graph/graph-node.js +58 -0
  92. package/dist/wirings/workflow/graph/graph-runner.d.ts +35 -0
  93. package/dist/wirings/workflow/graph/graph-runner.js +452 -0
  94. package/dist/wirings/workflow/graph/index.d.ts +3 -0
  95. package/dist/wirings/workflow/graph/index.js +3 -0
  96. package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +95 -0
  97. package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
  98. package/dist/wirings/workflow/index.d.ts +7 -3
  99. package/dist/wirings/workflow/index.js +6 -3
  100. package/dist/wirings/workflow/pikku-workflow-service.d.ts +108 -10
  101. package/dist/wirings/workflow/pikku-workflow-service.js +274 -165
  102. package/dist/wirings/workflow/wire-workflow.d.ts +42 -0
  103. package/dist/wirings/workflow/wire-workflow.js +53 -0
  104. package/dist/wirings/workflow/workflow-utils.d.ts +23 -0
  105. package/dist/wirings/workflow/workflow-utils.js +66 -0
  106. package/dist/wirings/workflow/workflow.types.d.ts +135 -128
  107. package/package.json +11 -2
  108. package/src/errors/error-handler.ts +3 -3
  109. package/src/errors/errors.ts +3 -3
  110. package/src/factory-functions.test.ts +9 -36
  111. package/src/function/function-runner.test.ts +58 -69
  112. package/src/function/function-runner.ts +130 -37
  113. package/src/function/functions.types.ts +193 -54
  114. package/src/handle-error.ts +1 -1
  115. package/src/index.ts +10 -5
  116. package/src/middleware/auth-apikey.test.ts +360 -0
  117. package/src/middleware/auth-apikey.ts +3 -7
  118. package/src/middleware/auth-bearer.test.ts +447 -0
  119. package/src/middleware/auth-bearer.ts +27 -33
  120. package/src/middleware/auth-cookie.test.ts +525 -0
  121. package/src/middleware/auth-cookie.ts +6 -6
  122. package/src/middleware/timeout.ts +4 -2
  123. package/src/middleware-runner.test.ts +58 -127
  124. package/src/middleware-runner.ts +29 -25
  125. package/src/permissions.test.ts +68 -130
  126. package/src/permissions.ts +41 -100
  127. package/src/pikku-state.ts +156 -201
  128. package/src/schema.ts +42 -13
  129. package/src/services/user-session-service.ts +14 -4
  130. package/src/services/workflow-service.ts +74 -0
  131. package/src/types/core.types.ts +79 -58
  132. package/src/types/state.types.ts +195 -0
  133. package/src/utils.ts +59 -4
  134. package/src/wirings/channel/channel-common.ts +4 -7
  135. package/src/wirings/channel/channel-handler.ts +17 -23
  136. package/src/wirings/channel/channel-runner.ts +7 -7
  137. package/src/wirings/channel/channel.types.ts +14 -11
  138. package/src/wirings/channel/local/local-channel-runner.test.ts +8 -4
  139. package/src/wirings/channel/local/local-channel-runner.ts +23 -38
  140. package/src/wirings/channel/log-channels.ts +1 -1
  141. package/src/wirings/channel/serverless/serverless-channel-runner.ts +53 -79
  142. package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
  143. package/src/wirings/cli/cli-runner.test.ts +26 -26
  144. package/src/wirings/cli/cli-runner.ts +34 -71
  145. package/src/wirings/cli/cli.types.ts +23 -16
  146. package/src/wirings/forge-node/forge-node.types.ts +135 -0
  147. package/src/wirings/forge-node/index.ts +1 -0
  148. package/src/wirings/http/http-runner.test.ts +10 -10
  149. package/src/wirings/http/http-runner.ts +56 -66
  150. package/src/wirings/http/http.types.ts +19 -14
  151. package/src/wirings/http/log-http-routes.ts +1 -1
  152. package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
  153. package/src/wirings/http/routers/path-to-regex.ts +2 -2
  154. package/src/wirings/mcp/mcp-runner.ts +44 -69
  155. package/src/wirings/mcp/mcp.types.ts +6 -0
  156. package/src/wirings/queue/queue-runner.test.ts +641 -0
  157. package/src/wirings/queue/queue-runner.ts +16 -38
  158. package/src/wirings/queue/queue.types.ts +4 -11
  159. package/src/wirings/rpc/index.ts +1 -1
  160. package/src/wirings/rpc/rpc-runner.ts +129 -77
  161. package/src/wirings/rpc/rpc-types.ts +8 -0
  162. package/src/wirings/scheduler/log-schedulers.ts +1 -1
  163. package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
  164. package/src/wirings/scheduler/scheduler-runner.ts +29 -55
  165. package/src/wirings/scheduler/scheduler.types.ts +3 -9
  166. package/src/wirings/trigger/index.ts +2 -0
  167. package/src/wirings/trigger/trigger-runner.ts +96 -0
  168. package/src/wirings/trigger/trigger.types.ts +56 -0
  169. package/src/wirings/workflow/dsl/index.ts +30 -0
  170. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +312 -0
  171. package/src/wirings/workflow/dsl/workflow-runner.ts +27 -0
  172. package/src/wirings/workflow/graph/graph-node.ts +227 -0
  173. package/src/wirings/workflow/graph/graph-runner.ts +694 -0
  174. package/src/wirings/workflow/graph/index.ts +3 -0
  175. package/src/wirings/workflow/graph/workflow-graph.types.ts +126 -0
  176. package/src/wirings/workflow/index.ts +60 -12
  177. package/src/wirings/workflow/pikku-workflow-service.ts +401 -195
  178. package/src/wirings/workflow/wire-workflow.ts +94 -0
  179. package/src/wirings/workflow/workflow-utils.ts +120 -0
  180. package/src/wirings/workflow/workflow.types.ts +167 -188
  181. package/tsconfig.tsbuildinfo +1 -1
  182. package/dist/wirings/workflow/workflow-runner.d.ts +0 -35
  183. package/dist/wirings/workflow/workflow-runner.js +0 -68
  184. package/src/wirings/workflow/workflow-runner.ts +0 -85
@@ -1,67 +1,58 @@
1
- import { PikkuChannel } from '../wirings/channel/channel.types.js'
2
1
  import type {
3
2
  CoreServices,
4
3
  CoreSingletonServices,
5
4
  CoreUserSession,
6
- PikkuDocs,
7
5
  CorePikkuMiddleware,
6
+ PikkuWire,
7
+ PickRequired,
8
8
  } from '../types/core.types.js'
9
+ import { Session } from 'inspector'
9
10
 
10
11
  /**
11
12
  * Represents a core API function that performs an operation using core services and a user session.
12
13
  *
13
14
  * @template In - The input type.
14
15
  * @template Out - The output type.
15
- * @template ChannelData - The channel data type.
16
16
  * @template Services - The services type, defaults to `CoreServices`.
17
- * @template Session - The session type, defaults to `CoreUserSession`.
17
+ * @template Wire - The wire type, defaults to `PikkuWire<In, Out>`.
18
18
  */
19
19
  export type CorePikkuFunction<
20
20
  In,
21
21
  Out,
22
- ChannelData extends unknown | null = null,
23
- Services extends CoreSingletonServices = CoreServices &
24
- (ChannelData extends null
25
- ? {
26
- channel?: PikkuChannel<unknown, Out> | undefined
27
- }
28
- : {
29
- channel: PikkuChannel<ChannelData, Out>
30
- }),
31
- Session extends CoreUserSession = CoreUserSession,
22
+ Services extends CoreSingletonServices = CoreServices,
23
+ Wire extends PikkuWire<In, Out> = PikkuWire<In, Out, true, Session>,
32
24
  > = (
33
25
  services: Services,
34
26
  data: In,
35
- session: Session
36
- ) => ChannelData extends null ? Promise<Out> : Promise<Out> | Promise<void>
27
+ wire: Wire
28
+ ) => Wire['channel'] extends null ? Promise<Out> : Promise<Out> | Promise<void>
37
29
 
38
30
  /**
39
31
  * Represents a core API function that can be used without a session.
40
32
  *
41
33
  * @template In - The input type.
42
34
  * @template Out - The output type.
43
- * @template ChannelData - The channel data type.
44
35
  * @template Services - The services type, defaults to `CoreServices`.
45
- * @template Session - The session type, defaults to `CoreUserSession`.
36
+ * @template Wire - The wire type, defaults to `PikkuWire<In, Out>`.
46
37
  */
47
38
  export type CorePikkuFunctionSessionless<
48
39
  In,
49
40
  Out,
50
- ChannelData extends unknown | null = null,
51
- Services extends CoreSingletonServices = CoreServices &
52
- (ChannelData extends null
53
- ? {
54
- channel?: PikkuChannel<unknown, Out> | undefined
55
- }
56
- : {
57
- channel: PikkuChannel<ChannelData, Out>
58
- }),
59
- Session extends CoreUserSession = CoreUserSession,
41
+ Services extends CoreSingletonServices = CoreServices,
42
+ Wire extends PikkuWire<
43
+ In,
44
+ Out,
45
+ false,
46
+ CoreUserSession,
47
+ any,
48
+ any,
49
+ any
50
+ > = PikkuWire<In, Out, false, CoreUserSession, any, any, any>,
60
51
  > = (
61
52
  services: Services,
62
53
  data: In,
63
- session?: Session
64
- ) => ChannelData extends null ? Promise<Out> : Promise<Out> | Promise<void>
54
+ wire: Wire
55
+ ) => Wire['channel'] extends null ? Promise<Out> : Promise<Out> | Promise<void>
65
56
 
66
57
  /**
67
58
  * Represents a function that checks permissions for a given operation.
@@ -73,8 +64,16 @@ export type CorePikkuFunctionSessionless<
73
64
  export type CorePikkuPermission<
74
65
  In = any,
75
66
  Services extends CoreSingletonServices = CoreServices,
76
- Session extends CoreUserSession = CoreUserSession,
77
- > = (services: Services, data: In, session?: Session) => Promise<boolean>
67
+ Wire extends PikkuWire<
68
+ In,
69
+ never,
70
+ false,
71
+ CoreUserSession,
72
+ any,
73
+ never,
74
+ never
75
+ > = PikkuWire<In, never, false, CoreUserSession, never, never, never>,
76
+ > = (services: Services, data: In, wire: Wire) => Promise<boolean>
78
77
 
79
78
  /**
80
79
  * Configuration object for creating a permission with metadata
@@ -86,12 +85,17 @@ export type CorePikkuPermission<
86
85
  export type CorePikkuPermissionConfig<
87
86
  In = any,
88
87
  Services extends CoreSingletonServices = CoreServices,
89
- Session extends CoreUserSession = CoreUserSession,
88
+ Wire extends PikkuWire<In, never, false, CoreUserSession> = PikkuWire<
89
+ In,
90
+ never,
91
+ false,
92
+ CoreUserSession
93
+ >,
90
94
  > = {
91
95
  /** The permission function */
92
- func: CorePikkuPermission<In, Services, Session>
93
- /** Optional human-readable name for the permission */
94
- name?: string
96
+ func: CorePikkuPermission<In, Services, Wire>
97
+ /** Optional human-readable title for the permission */
98
+ title?: string
95
99
  /** Optional description of what the permission checks */
96
100
  description?: string
97
101
  }
@@ -104,17 +108,19 @@ export type CorePikkuPermissionConfig<
104
108
  * ```typescript
105
109
  * // Direct function syntax
106
110
  * export const adminPermission = pikkuPermission(
107
- * async ({ logger }, data, session) => {
108
- * return session?.role === 'admin'
111
+ * async ({ logger }, _data, { session }) => {
112
+ * const currentSession = await session.get()
113
+ * return currentSession?.role === 'admin'
109
114
  * }
110
115
  * )
111
116
  *
112
117
  * // Configuration object syntax with metadata
113
118
  * export const adminPermission = pikkuPermission({
114
- * name: 'Admin Permission',
119
+ * title: 'Admin Permission',
115
120
  * description: 'Checks if user has admin role',
116
- * func: async ({ logger }, data, session) => {
117
- * return session?.role === 'admin'
121
+ * func: async ({ logger }, _data, { session }) => {
122
+ * const currentSession = await session.get()
123
+ * return currentSession?.role === 'admin'
118
124
  * }
119
125
  * })
120
126
  * ```
@@ -122,12 +128,15 @@ export type CorePikkuPermissionConfig<
122
128
  export const pikkuPermission = <
123
129
  In = any,
124
130
  Services extends CoreSingletonServices = CoreServices,
125
- Session extends CoreUserSession = CoreUserSession,
131
+ Wire extends PickRequired<
132
+ PikkuWire<In, never, false, CoreUserSession>,
133
+ 'session'
134
+ > = PickRequired<PikkuWire<In, never, false, CoreUserSession>, 'session'>,
126
135
  >(
127
136
  permission:
128
- | CorePikkuPermission<In, Services, Session>
129
- | CorePikkuPermissionConfig<In, Services, Session>
130
- ): CorePikkuPermission<In, Services, Session> => {
137
+ | CorePikkuPermission<In, Services, Wire>
138
+ | CorePikkuPermissionConfig<In, Services, Wire>
139
+ ): CorePikkuPermission<In, Services, Wire> => {
131
140
  return typeof permission === 'function' ? permission : permission.func
132
141
  }
133
142
 
@@ -142,8 +151,13 @@ export const pikkuPermission = <
142
151
  export type CorePikkuPermissionFactory<
143
152
  In = any,
144
153
  Services extends CoreSingletonServices = CoreServices,
145
- Session extends CoreUserSession = CoreUserSession,
146
- > = (input: In) => CorePikkuPermission<any, Services, Session>
154
+ Wire extends PikkuWire<In, never, false, CoreUserSession> = PikkuWire<
155
+ In,
156
+ never,
157
+ false,
158
+ CoreUserSession
159
+ >,
160
+ > = (input: In) => CorePikkuPermission<any, Services, Wire>
147
161
 
148
162
  /**
149
163
  * Factory function for creating permission factories
@@ -154,8 +168,9 @@ export type CorePikkuPermissionFactory<
154
168
  * export const requireRole = pikkuPermissionFactory<{ role: string }>(({
155
169
  * role
156
170
  * }) => {
157
- * return pikkuPermission(async ({ logger }, data, session) => {
158
- * if (!session || session.role !== role) {
171
+ * return pikkuPermission(async ({ logger }, data, { session }) => {
172
+ * const currentSession = await session.get()
173
+ * if (!currentSession || currentSession.role !== role) {
159
174
  * logger.warn(`Permission denied: required role '${role}'`)
160
175
  * return false
161
176
  * }
@@ -174,24 +189,148 @@ export type CorePermissionGroup<PikkuPermission = CorePikkuPermission<any>> =
174
189
  | Record<string, PikkuPermission | PikkuPermission[]>
175
190
  | undefined
176
191
 
192
+ /**
193
+ * Zod schema type - matches z.ZodType shape for type inference
194
+ * This avoids requiring zod as a dependency while allowing schema inference
195
+ */
196
+ export type ZodLike<T = any> = {
197
+ _input: T
198
+ _output: T
199
+ }
200
+
177
201
  export type CorePikkuFunctionConfig<
178
202
  PikkuFunction extends
179
- | CorePikkuFunction<any, any, any, any, any>
180
- | CorePikkuFunctionSessionless<any, any, any, any, any>,
203
+ | CorePikkuFunction<any, any, any, any>
204
+ | CorePikkuFunctionSessionless<any, any, any, any>,
181
205
  PikkuPermission extends CorePikkuPermission<
182
206
  any,
183
207
  any,
184
208
  any
185
209
  > = CorePikkuPermission<any>,
186
- PikkuMiddleware extends CorePikkuMiddleware<any> = CorePikkuMiddleware<any>,
210
+ PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<
211
+ any,
212
+ any
213
+ >,
214
+ InputSchema extends ZodLike | undefined = undefined,
215
+ OutputSchema extends ZodLike | undefined = undefined,
187
216
  > = {
188
- name?: string
217
+ /** Optional human-readable title for the function */
218
+ title?: string
219
+ /** Optional description of what the function does */
220
+ description?: string
221
+ override?: string
222
+ tags?: string[]
189
223
  expose?: boolean
190
224
  internal?: boolean
191
225
  func: PikkuFunction
192
226
  auth?: boolean
193
227
  permissions?: CorePermissionGroup<PikkuPermission>
194
228
  middleware?: PikkuMiddleware[]
229
+ input?: InputSchema
230
+ output?: OutputSchema
231
+ }
232
+
233
+ /**
234
+ * A trigger function that sets up a subscription and returns a teardown function.
235
+ * The trigger is fired via wire.trigger.trigger(data).
236
+ *
237
+ * @template TConfig - Configuration type (hardcoded when wired)
238
+ * @template TOutput - Output type produced when trigger fires
239
+ * @template Services - Services available to the trigger
240
+ */
241
+ export type CorePikkuTriggerFunction<
242
+ TConfig = unknown,
243
+ TOutput = unknown,
244
+ Services extends CoreSingletonServices = CoreSingletonServices,
245
+ > = (
246
+ services: Services,
247
+ config: TConfig,
248
+ wire: { trigger: { trigger: (data: TOutput) => void } }
249
+ ) => Promise<() => void | Promise<void>>
250
+
251
+ /**
252
+ * Configuration object for creating a trigger function with metadata
253
+ */
254
+ export type CorePikkuTriggerFunctionConfig<
255
+ TConfig = unknown,
256
+ TOutput = unknown,
257
+ Services extends CoreSingletonServices = CoreSingletonServices,
258
+ ConfigSchema extends ZodLike | undefined = undefined,
259
+ OutputSchema extends ZodLike | undefined = undefined,
260
+ > = {
261
+ /** Optional human-readable title for the trigger */
262
+ title?: string
263
+ /** Optional description of what the trigger does */
264
+ description?: string
265
+ /** Optional tags for categorization */
195
266
  tags?: string[]
196
- docs?: PikkuDocs
267
+ /** The trigger function */
268
+ func: CorePikkuTriggerFunction<TConfig, TOutput, Services>
269
+ /** Optional Zod schema for config validation */
270
+ config?: ConfigSchema
271
+ /** Optional Zod schema for output validation */
272
+ output?: OutputSchema
273
+ }
274
+
275
+ /**
276
+ * Factory function for creating trigger functions
277
+ * Supports both direct function and configuration object syntax
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * // Direct function syntax
282
+ * export const redisSubscribeTrigger = pikkuTriggerFunc<
283
+ * { channel: string },
284
+ * { message: string }
285
+ * >(async ({ redis }, { channel }, { trigger }) => {
286
+ * const subscriber = redis.duplicate()
287
+ * await subscriber.subscribe(channel, (msg) => {
288
+ * trigger.trigger({ message: msg })
289
+ * })
290
+ * return () => subscriber.unsubscribe()
291
+ * })
292
+ *
293
+ * // Configuration object syntax with metadata
294
+ * export const redisSubscribeTrigger = pikkuTriggerFunc({
295
+ * title: 'Redis Subscribe Trigger',
296
+ * description: 'Listens to Redis pub/sub channel',
297
+ * config: z.object({ channel: z.string() }),
298
+ * output: z.object({ message: z.string() }),
299
+ * func: async ({ redis }, { channel }, { trigger }) => {
300
+ * const subscriber = redis.duplicate()
301
+ * await subscriber.subscribe(channel, (msg) => {
302
+ * trigger.trigger({ message: msg })
303
+ * })
304
+ * return () => subscriber.unsubscribe()
305
+ * }
306
+ * })
307
+ * ```
308
+ */
309
+ export const pikkuTriggerFunc = <
310
+ TConfig = unknown,
311
+ TOutput = unknown,
312
+ Services extends CoreSingletonServices = CoreSingletonServices,
313
+ ConfigSchema extends ZodLike | undefined = undefined,
314
+ OutputSchema extends ZodLike | undefined = undefined,
315
+ >(
316
+ triggerOrConfig:
317
+ | CorePikkuTriggerFunction<TConfig, TOutput, Services>
318
+ | CorePikkuTriggerFunctionConfig<
319
+ TConfig,
320
+ TOutput,
321
+ Services,
322
+ ConfigSchema,
323
+ OutputSchema
324
+ >
325
+ ): CorePikkuTriggerFunctionConfig<
326
+ TConfig,
327
+ TOutput,
328
+ Services,
329
+ ConfigSchema,
330
+ OutputSchema
331
+ > => {
332
+ if (typeof triggerOrConfig === 'function') {
333
+ return { func: triggerOrConfig }
334
+ }
335
+ return triggerOrConfig
197
336
  }
@@ -7,7 +7,7 @@ import { PikkuHTTP } from './wirings/http/http.types.js'
7
7
  * Handle errors that occur during route processing
8
8
  *
9
9
  * @param {any} e - The error that occurred
10
- * @param {PikkuHTTP | undefined} http - HTTP interaction object
10
+ * @param {PikkuHTTP | undefined} http - HTTP wire object
11
11
  * @param {string} trackerId - Unique ID for tracking this error
12
12
  * @param {Logger} logger - Logger service
13
13
  * @param {number[]} logWarningsForStatusCodes - HTTP status codes to log as warnings
package/src/index.ts CHANGED
@@ -17,16 +17,21 @@ export * from './wirings/scheduler/index.js'
17
17
  export * from './wirings/rpc/index.js'
18
18
  export * from './wirings/queue/index.js'
19
19
  export * from './wirings/workflow/index.js'
20
+ export * from './wirings/workflow/graph/index.js'
20
21
  export * from './wirings/mcp/index.js'
21
22
  export * from './wirings/cli/index.js'
23
+ export * from './wirings/forge-node/index.js'
24
+ export * from './wirings/trigger/index.js'
22
25
  export * from './errors/index.js'
23
26
  export * from './middleware/index.js'
24
27
  export * from './utils.js'
25
28
  export * from './time-utils.js'
26
- export { pikkuState } from './pikku-state.js'
27
29
  export {
28
- runMiddleware,
29
- addMiddleware,
30
- getMiddlewareByName,
31
- } from './middleware-runner.js'
30
+ pikkuState,
31
+ initializePikkuState,
32
+ resetPikkuState,
33
+ addPackageServiceFactories,
34
+ } from './pikku-state.js'
35
+ export type { PikkuPackageState } from './types/state.types.js'
36
+ export { runMiddleware, addMiddleware } from './middleware-runner.js'
32
37
  export { addPermission } from './permissions.js'