@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.
- package/CHANGELOG.md +35 -1
- package/dist/errors/error-handler.js +3 -3
- package/dist/errors/errors.d.ts +1 -1
- package/dist/errors/errors.js +3 -3
- package/dist/function/function-runner.d.ts +8 -8
- package/dist/function/function-runner.js +88 -23
- package/dist/function/functions.types.d.ts +104 -33
- package/dist/function/functions.types.js +50 -7
- package/dist/handle-error.d.ts +1 -1
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -2
- package/dist/middleware/auth-apikey.d.ts +1 -1
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -1
- package/dist/middleware/auth-bearer.js +3 -3
- package/dist/middleware/auth-cookie.d.ts +1 -1
- package/dist/middleware/auth-cookie.js +5 -5
- package/dist/middleware/timeout.d.ts +1 -1
- package/dist/middleware/timeout.js +3 -2
- package/dist/middleware-runner.d.ts +6 -20
- package/dist/middleware-runner.js +19 -20
- package/dist/permissions.d.ts +6 -89
- package/dist/permissions.js +24 -81
- package/dist/pikku-state.d.ts +32 -104
- package/dist/pikku-state.js +140 -66
- package/dist/schema.d.ts +8 -6
- package/dist/schema.js +25 -13
- package/dist/services/user-session-service.d.ts +7 -3
- package/dist/services/user-session-service.js +8 -1
- package/dist/services/workflow-service.d.ts +38 -0
- package/dist/services/workflow-service.js +1 -0
- package/dist/types/core.types.d.ts +40 -41
- package/dist/types/core.types.js +4 -15
- package/dist/types/state.types.d.ts +135 -0
- package/dist/types/state.types.js +1 -0
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +48 -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 +7 -10
- package/dist/wirings/channel/channel-runner.d.ts +2 -2
- package/dist/wirings/channel/channel-runner.js +5 -5
- 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/log-channels.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +43 -48
- package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
- package/dist/wirings/cli/cli-runner.d.ts +5 -5
- package/dist/wirings/cli/cli-runner.js +20 -38
- package/dist/wirings/cli/cli.types.d.ts +16 -11
- package/dist/wirings/forge-node/forge-node.types.d.ts +120 -0
- package/dist/wirings/forge-node/forge-node.types.js +38 -0
- package/dist/wirings/forge-node/index.d.ts +1 -0
- package/dist/wirings/forge-node/index.js +1 -0
- package/dist/wirings/http/http-runner.d.ts +8 -8
- package/dist/wirings/http/http-runner.js +46 -51
- package/dist/wirings/http/http.types.d.ts +19 -11
- package/dist/wirings/http/log-http-routes.js +1 -1
- package/dist/wirings/http/routers/path-to-regex.js +2 -2
- package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
- package/dist/wirings/mcp/mcp-runner.js +33 -40
- 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 +13 -23
- package/dist/wirings/queue/queue.types.d.ts +4 -11
- 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 +17 -16
- package/dist/wirings/rpc/rpc-runner.js +98 -61
- package/dist/wirings/rpc/rpc-types.d.ts +7 -0
- package/dist/wirings/scheduler/log-schedulers.js +1 -1
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
- package/dist/wirings/scheduler/scheduler-runner.js +18 -29
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
- package/dist/wirings/trigger/index.d.ts +2 -0
- package/dist/wirings/trigger/index.js +2 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +29 -0
- package/dist/wirings/trigger/trigger-runner.js +57 -0
- package/dist/wirings/trigger/trigger.types.d.ts +42 -0
- package/dist/wirings/trigger/trigger.types.js +1 -0
- package/dist/wirings/workflow/dsl/index.d.ts +5 -0
- package/dist/wirings/workflow/dsl/index.js +4 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +286 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.js +22 -0
- package/dist/wirings/workflow/graph/graph-node.d.ts +122 -0
- package/dist/wirings/workflow/graph/graph-node.js +58 -0
- package/dist/wirings/workflow/graph/graph-runner.d.ts +35 -0
- package/dist/wirings/workflow/graph/graph-runner.js +452 -0
- package/dist/wirings/workflow/graph/index.d.ts +3 -0
- package/dist/wirings/workflow/graph/index.js +3 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +95 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
- package/dist/wirings/workflow/index.d.ts +7 -3
- package/dist/wirings/workflow/index.js +6 -3
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +108 -10
- package/dist/wirings/workflow/pikku-workflow-service.js +274 -165
- package/dist/wirings/workflow/wire-workflow.d.ts +42 -0
- package/dist/wirings/workflow/wire-workflow.js +53 -0
- package/dist/wirings/workflow/workflow-utils.d.ts +23 -0
- package/dist/wirings/workflow/workflow-utils.js +66 -0
- package/dist/wirings/workflow/workflow.types.d.ts +135 -128
- package/package.json +11 -2
- package/src/errors/error-handler.ts +3 -3
- package/src/errors/errors.ts +3 -3
- package/src/factory-functions.test.ts +9 -36
- package/src/function/function-runner.test.ts +58 -69
- package/src/function/function-runner.ts +130 -37
- package/src/function/functions.types.ts +193 -54
- package/src/handle-error.ts +1 -1
- package/src/index.ts +10 -5
- 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 +29 -25
- package/src/permissions.test.ts +68 -130
- package/src/permissions.ts +41 -100
- package/src/pikku-state.ts +156 -201
- package/src/schema.ts +42 -13
- package/src/services/user-session-service.ts +14 -4
- package/src/services/workflow-service.ts +74 -0
- package/src/types/core.types.ts +79 -58
- package/src/types/state.types.ts +195 -0
- package/src/utils.ts +59 -4
- package/src/wirings/channel/channel-common.ts +4 -7
- package/src/wirings/channel/channel-handler.ts +17 -23
- package/src/wirings/channel/channel-runner.ts +7 -7
- package/src/wirings/channel/channel.types.ts +14 -11
- package/src/wirings/channel/local/local-channel-runner.test.ts +8 -4
- package/src/wirings/channel/local/local-channel-runner.ts +23 -38
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +53 -79
- package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
- package/src/wirings/cli/cli-runner.test.ts +26 -26
- package/src/wirings/cli/cli-runner.ts +34 -71
- package/src/wirings/cli/cli.types.ts +23 -16
- package/src/wirings/forge-node/forge-node.types.ts +135 -0
- package/src/wirings/forge-node/index.ts +1 -0
- package/src/wirings/http/http-runner.test.ts +10 -10
- package/src/wirings/http/http-runner.ts +56 -66
- package/src/wirings/http/http.types.ts +19 -14
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
- package/src/wirings/http/routers/path-to-regex.ts +2 -2
- package/src/wirings/mcp/mcp-runner.ts +44 -69
- 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 +16 -38
- package/src/wirings/queue/queue.types.ts +4 -11
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +129 -77
- package/src/wirings/rpc/rpc-types.ts +8 -0
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
- package/src/wirings/scheduler/scheduler-runner.ts +29 -55
- package/src/wirings/scheduler/scheduler.types.ts +3 -9
- package/src/wirings/trigger/index.ts +2 -0
- package/src/wirings/trigger/trigger-runner.ts +96 -0
- package/src/wirings/trigger/trigger.types.ts +56 -0
- package/src/wirings/workflow/dsl/index.ts +30 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +312 -0
- package/src/wirings/workflow/dsl/workflow-runner.ts +27 -0
- package/src/wirings/workflow/graph/graph-node.ts +227 -0
- package/src/wirings/workflow/graph/graph-runner.ts +694 -0
- package/src/wirings/workflow/graph/index.ts +3 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +126 -0
- package/src/wirings/workflow/index.ts +60 -12
- package/src/wirings/workflow/pikku-workflow-service.ts +401 -195
- package/src/wirings/workflow/wire-workflow.ts +94 -0
- package/src/wirings/workflow/workflow-utils.ts +120 -0
- package/src/wirings/workflow/workflow.types.ts +167 -188
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/workflow/workflow-runner.d.ts +0 -35
- package/dist/wirings/workflow/workflow-runner.js +0 -68
- 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
|
|
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
|
-
|
|
23
|
-
|
|
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
|
-
|
|
36
|
-
) =>
|
|
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
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
64
|
-
) =>
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
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,
|
|
93
|
-
/** Optional human-readable
|
|
94
|
-
|
|
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 },
|
|
108
|
-
*
|
|
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
|
-
*
|
|
119
|
+
* title: 'Admin Permission',
|
|
115
120
|
* description: 'Checks if user has admin role',
|
|
116
|
-
* func: async ({ logger },
|
|
117
|
-
*
|
|
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
|
-
|
|
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,
|
|
129
|
-
| CorePikkuPermissionConfig<In, Services,
|
|
130
|
-
): CorePikkuPermission<In, Services,
|
|
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
|
-
|
|
146
|
-
|
|
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
|
-
*
|
|
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
|
|
180
|
-
| CorePikkuFunctionSessionless<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<
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/handle-error.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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'
|