@pikku/addon-graph 0.0.3 → 0.12.3

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 (176) hide show
  1. package/dist/.pikku/addon/pikku-addon-types.gen.d.ts +3 -3
  2. package/dist/.pikku/addon/pikku-addon-types.gen.d.ts.map +1 -1
  3. package/dist/.pikku/addon/pikku-addon-types.gen.js +6 -2
  4. package/dist/.pikku/addon/pikku-addon-types.gen.js.map +1 -1
  5. package/dist/.pikku/addon/pikku-package.gen.js +2 -1
  6. package/dist/.pikku/addon/pikku-package.gen.js.map +1 -1
  7. package/dist/.pikku/agent/pikku-agent-map.gen.d.ts +2 -14
  8. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
  9. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +112 -0
  10. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts.map +1 -0
  11. package/dist/.pikku/channel/pikku-channel-types.gen.js +60 -0
  12. package/dist/.pikku/channel/pikku-channel-types.gen.js.map +1 -0
  13. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +78 -0
  14. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts.map +1 -0
  15. package/dist/.pikku/cli/pikku-cli-types.gen.js +61 -0
  16. package/dist/.pikku/cli/pikku-cli-types.gen.js.map +1 -0
  17. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  18. package/dist/.pikku/function/pikku-function-types.gen.d.ts +57 -86
  19. package/dist/.pikku/function/pikku-function-types.gen.d.ts.map +1 -1
  20. package/dist/.pikku/function/pikku-function-types.gen.js +46 -57
  21. package/dist/.pikku/function/pikku-function-types.gen.js.map +1 -1
  22. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  23. package/dist/.pikku/function/pikku-functions-meta.gen.json +476 -449
  24. package/dist/.pikku/function/pikku-functions.gen.js +2 -2
  25. package/dist/.pikku/function/pikku-functions.gen.js.map +1 -1
  26. package/dist/.pikku/http/pikku-http-types.gen.d.ts +120 -0
  27. package/dist/.pikku/http/pikku-http-types.gen.d.ts.map +1 -0
  28. package/dist/.pikku/http/pikku-http-types.gen.js +72 -0
  29. package/dist/.pikku/http/pikku-http-types.gen.js.map +1 -0
  30. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +131 -0
  31. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts.map +1 -0
  32. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +38 -0
  33. package/dist/.pikku/mcp/pikku-mcp-types.gen.js.map +1 -0
  34. package/dist/.pikku/pikku-bootstrap.gen.d.ts +4 -2
  35. package/dist/.pikku/pikku-bootstrap.gen.d.ts.map +1 -1
  36. package/dist/.pikku/pikku-bootstrap.gen.js +2 -10
  37. package/dist/.pikku/pikku-bootstrap.gen.js.map +1 -1
  38. package/dist/.pikku/pikku-meta-service.gen.d.ts +8 -0
  39. package/dist/.pikku/pikku-meta-service.gen.d.ts.map +1 -0
  40. package/dist/.pikku/pikku-meta-service.gen.js +10 -0
  41. package/dist/.pikku/pikku-meta-service.gen.js.map +1 -0
  42. package/dist/.pikku/pikku-services.gen.d.ts +8 -3
  43. package/dist/.pikku/pikku-services.gen.d.ts.map +1 -1
  44. package/dist/.pikku/pikku-services.gen.js +7 -1
  45. package/dist/.pikku/pikku-services.gen.js.map +1 -1
  46. package/dist/.pikku/pikku-types.gen.d.ts +1 -1
  47. package/dist/.pikku/pikku-types.gen.js +1 -1
  48. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +24 -0
  49. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts.map +1 -0
  50. package/dist/.pikku/queue/pikku-queue-types.gen.js +17 -0
  51. package/dist/.pikku/queue/pikku-queue-types.gen.js.map +1 -0
  52. package/dist/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +429 -57
  53. package/dist/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +430 -58
  54. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.d.ts +2 -0
  55. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.d.ts.map +1 -0
  56. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +7 -0
  57. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js.map +1 -0
  58. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +27 -0
  59. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +22 -0
  60. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts.map +1 -0
  61. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +17 -0
  62. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js.map +1 -0
  63. package/dist/.pikku/schemas/register.gen.js +3 -1
  64. package/dist/.pikku/schemas/register.gen.js.map +1 -1
  65. package/dist/.pikku/schemas/schemas/AggregateInput.schema.json +1 -1
  66. package/dist/.pikku/schemas/schemas/AggregateOutput.schema.json +1 -1
  67. package/dist/.pikku/schemas/schemas/ChunkInput.schema.json +1 -1
  68. package/dist/.pikku/schemas/schemas/ChunkOutput.schema.json +1 -1
  69. package/dist/.pikku/schemas/schemas/CoalesceInput.schema.json +1 -1
  70. package/dist/.pikku/schemas/schemas/CoalesceOutput.schema.json +1 -1
  71. package/dist/.pikku/schemas/schemas/CryptoInput.schema.json +1 -1
  72. package/dist/.pikku/schemas/schemas/CryptoOutput.schema.json +1 -1
  73. package/dist/.pikku/schemas/schemas/DateTimeInput.schema.json +1 -1
  74. package/dist/.pikku/schemas/schemas/DateTimeOutput.schema.json +1 -1
  75. package/dist/.pikku/schemas/schemas/EditFieldsInput.schema.json +1 -1
  76. package/dist/.pikku/schemas/schemas/EditFieldsOutput.schema.json +1 -1
  77. package/dist/.pikku/schemas/schemas/FindInput.schema.json +1 -1
  78. package/dist/.pikku/schemas/schemas/FindOutput.schema.json +1 -1
  79. package/dist/.pikku/schemas/schemas/GroupByInput.schema.json +1 -1
  80. package/dist/.pikku/schemas/schemas/GroupByOutput.schema.json +1 -1
  81. package/dist/.pikku/schemas/schemas/JwtDecodeInput.schema.json +1 -1
  82. package/dist/.pikku/schemas/schemas/JwtDecodeOutput.schema.json +1 -1
  83. package/dist/.pikku/schemas/schemas/JwtSignInput.schema.json +1 -1
  84. package/dist/.pikku/schemas/schemas/JwtSignOutput.schema.json +1 -1
  85. package/dist/.pikku/schemas/schemas/LimitInput.schema.json +1 -1
  86. package/dist/.pikku/schemas/schemas/LimitOutput.schema.json +1 -1
  87. package/dist/.pikku/schemas/schemas/MathInput.schema.json +1 -1
  88. package/dist/.pikku/schemas/schemas/MathOutput.schema.json +1 -1
  89. package/dist/.pikku/schemas/schemas/MergeInput.schema.json +1 -1
  90. package/dist/.pikku/schemas/schemas/MergeOutput.schema.json +1 -1
  91. package/dist/.pikku/schemas/schemas/OmitInput.schema.json +1 -1
  92. package/dist/.pikku/schemas/schemas/OmitOutput.schema.json +1 -1
  93. package/dist/.pikku/schemas/schemas/PickInput.schema.json +1 -1
  94. package/dist/.pikku/schemas/schemas/PickOutput.schema.json +1 -1
  95. package/dist/.pikku/schemas/schemas/RemoveDuplicatesInput.schema.json +1 -1
  96. package/dist/.pikku/schemas/schemas/RemoveDuplicatesOutput.schema.json +1 -1
  97. package/dist/.pikku/schemas/schemas/RenameKeysInput.schema.json +1 -1
  98. package/dist/.pikku/schemas/schemas/RenameKeysOutput.schema.json +1 -1
  99. package/dist/.pikku/schemas/schemas/ReverseInput.schema.json +1 -1
  100. package/dist/.pikku/schemas/schemas/ReverseOutput.schema.json +1 -1
  101. package/dist/.pikku/schemas/schemas/SleepInput.schema.json +1 -1
  102. package/dist/.pikku/schemas/schemas/SleepOutput.schema.json +1 -0
  103. package/dist/.pikku/schemas/schemas/SortInput.schema.json +1 -1
  104. package/dist/.pikku/schemas/schemas/SortOutput.schema.json +1 -1
  105. package/dist/.pikku/schemas/schemas/SplitOutInput.schema.json +1 -1
  106. package/dist/.pikku/schemas/schemas/SplitOutOutput.schema.json +1 -1
  107. package/dist/.pikku/schemas/schemas/StringTransformInput.schema.json +1 -1
  108. package/dist/.pikku/schemas/schemas/StringTransformOutput.schema.json +1 -1
  109. package/dist/.pikku/schemas/schemas/SummarizeInput.schema.json +1 -1
  110. package/dist/.pikku/schemas/schemas/SummarizeOutput.schema.json +1 -1
  111. package/dist/.pikku/schemas/schemas/TypeConvertInput.schema.json +1 -1
  112. package/dist/.pikku/schemas/schemas/TypeConvertOutput.schema.json +1 -1
  113. package/dist/.pikku/schemas/schemas/UniqueInput.schema.json +1 -1
  114. package/dist/.pikku/schemas/schemas/UniqueOutput.schema.json +1 -1
  115. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
  116. package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
  117. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
  118. package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
  119. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  120. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  121. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
  122. package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
  123. package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
  124. package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
  125. package/dist/.pikku/workflow/pikku-workflow-map.gen.d.ts +9 -5
  126. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +3 -24
  127. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts.map +1 -1
  128. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -14
  129. package/dist/.pikku/workflow/pikku-workflow-types.gen.js.map +1 -1
  130. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  131. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.d.ts +1 -1
  132. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  133. package/dist/src/functions/data/jwt.function.d.ts.map +1 -1
  134. package/dist/src/functions/data/jwt.function.js +3 -2
  135. package/dist/src/functions/data/jwt.function.js.map +1 -1
  136. package/dist/src/functions/data/sleep.function.d.ts +1 -0
  137. package/dist/src/functions/data/sleep.function.d.ts.map +1 -1
  138. package/dist/src/functions/data/sleep.function.js +2 -1
  139. package/dist/src/functions/data/sleep.function.js.map +1 -1
  140. package/package.json +6 -9
  141. package/dist/.pikku/addon/pikku-addon-types.gen.ts +0 -100
  142. package/dist/.pikku/addon/pikku-package.gen.ts +0 -9
  143. package/dist/.pikku/agent/pikku-agent-types.gen.ts +0 -82
  144. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.d.ts +0 -2
  145. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.d.ts.map +0 -1
  146. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.js +0 -7
  147. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.js.map +0 -1
  148. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.json +0 -3
  149. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.ts +0 -7
  150. package/dist/.pikku/agent/pikku-agent-wirings.gen.d.ts +0 -5
  151. package/dist/.pikku/agent/pikku-agent-wirings.gen.d.ts.map +0 -1
  152. package/dist/.pikku/agent/pikku-agent-wirings.gen.js +0 -5
  153. package/dist/.pikku/agent/pikku-agent-wirings.gen.js.map +0 -1
  154. package/dist/.pikku/agent/pikku-agent-wirings.gen.ts +0 -3
  155. package/dist/.pikku/console/pikku-addon-meta.gen.json +0 -281
  156. package/dist/.pikku/console/pikku-node-types.gen.ts +0 -8
  157. package/dist/.pikku/function/pikku-function-types.gen.ts +0 -686
  158. package/dist/.pikku/function/pikku-functions-meta-verbose.gen.json +0 -610
  159. package/dist/.pikku/function/pikku-functions-meta.gen.ts +0 -7
  160. package/dist/.pikku/function/pikku-functions.gen.ts +0 -56
  161. package/dist/.pikku/pikku-bootstrap.gen.ts +0 -15
  162. package/dist/.pikku/pikku-services.gen.ts +0 -34
  163. package/dist/.pikku/pikku-types.gen.ts +0 -21
  164. package/dist/.pikku/schema-cache.json +0 -1
  165. package/dist/.pikku/schemas/pikku.cache.json +0 -1
  166. package/dist/.pikku/schemas/register.gen.ts +0 -199
  167. package/dist/.pikku/secrets/pikku-secret-types.gen.ts +0 -5
  168. package/dist/.pikku/secrets/pikku-secrets-meta.gen.json +0 -1
  169. package/dist/.pikku/secrets/pikku-secrets.gen.ts +0 -21
  170. package/dist/.pikku/trigger/pikku-trigger-types.gen.ts +0 -160
  171. package/dist/.pikku/variables/pikku-variable-types.gen.ts +0 -5
  172. package/dist/.pikku/variables/pikku-variables-meta.gen.json +0 -1
  173. package/dist/.pikku/variables/pikku-variables.gen.ts +0 -21
  174. package/dist/.pikku/workflow/pikku-workflow-types.gen.ts +0 -214
  175. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.ts +0 -9
  176. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.ts +0 -3
@@ -1,686 +0,0 @@
1
- /**
2
- * This file was generated by @pikku/cli@0.12.8
3
- */
4
- /**
5
- * Core function, middleware, and permission types for all wirings
6
- */
7
-
8
- import { CorePikkuFunctionConfig, CorePikkuAuth, CorePikkuAuthConfig, CorePikkuPermission, CorePikkuMiddleware, CorePermissionGroup, addMiddleware as addMiddlewareCore, addPermission as addPermissionCore, PikkuWire, PickRequired } from '@pikku/core'
9
- import { pikkuState as __pikkuState, CreateWireServices } from '@pikku/core/internal'
10
- import { pikkuAuth as pikkuAuthCore } from '@pikku/core'
11
- import { PikkuError } from '@pikku/core/errors'
12
- import type { NodeType } from '@pikku/core/node'
13
- import type { StandardSchemaV1 } from '@standard-schema/spec'
14
- import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
15
-
16
- import type { UserSession } from '../../types/application-types.d.js'
17
- import type { SingletonServices } from '../../types/application-types.d.js'
18
- import type { Services } from '../../types/application-types.d.js'
19
- import type { Config } from '../../types/application-types.d.js'
20
- import type { TypedPikkuRPC, FlattenedRPCMap } from '../rpc/pikku-rpc-wirings-map.internal.gen.d.js'
21
- import type { RequiredSingletonServices, RequiredWireServices } from '../pikku-services.gen.js'
22
- import type { TypedWorkflow } from '../workflow/pikku-workflow-types.gen.js'
23
-
24
- export type { SingletonServices as SingletonServices }
25
- export type { Services as Services }
26
- export type Session = UserSession
27
-
28
-
29
- /**
30
- * Inline node configuration for function definitions.
31
- */
32
- export type NodeConfig = {
33
- displayName: string
34
- category: string
35
- type: NodeType
36
- errorOutput?: boolean
37
- }
38
-
39
- /**
40
- * Type-safe API permission definition that integrates with your application's session type.
41
- * Use this to define authorization logic for your API endpoints.
42
- *
43
- * @template In - The input type that the permission check will receive
44
- * @template RequiredServices - The services required for this permission check
45
- */
46
- export type PikkuPermission<In = unknown, RequiredServices extends Services = Services> = CorePikkuPermission<In, RequiredServices, PikkuWire<In, never, false, Session>>
47
-
48
- /**
49
- * Type-safe middleware definition that can access your application's services and session.
50
- * Use this to define reusable middleware that can be applied to multiple wirings.
51
- *
52
- * @template RequiredServices - The services required for this middleware
53
- */
54
- export type PikkuMiddleware<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuMiddleware<RequiredServices>
55
-
56
- /**
57
- * Configuration object for creating a permission with metadata
58
- */
59
- export type PikkuPermissionConfig<In = unknown, RequiredServices extends Services = Services> = {
60
- /** The permission function */
61
- func: PikkuPermission<In, RequiredServices>
62
- /** Optional human-readable name for the permission */
63
- name?: string
64
- /** Optional description of what the permission checks */
65
- description?: string
66
- }
67
-
68
- /**
69
- * Factory function for creating permissions with tree-shaking support.
70
- * Supports both direct function and configuration object syntax.
71
- *
72
- * @example
73
- * ```typescript
74
- * // Direct function syntax
75
- * const permission = pikkuPermission(async ({ logger }, data, { session }) => {
76
- * const session = await session?.get()
77
- * return session?.role === 'admin'
78
- * })
79
- *
80
- * // Configuration object syntax with metadata
81
- * const adminPermission = pikkuPermission({
82
- * name: 'Admin Permission',
83
- * description: 'Checks if user has admin role',
84
- * func: async ({ logger }, data, { session }) => {
85
- * const session = await session?.get()
86
- * return session?.role === 'admin'
87
- * }
88
- * })
89
- * ```
90
- */
91
- export const pikkuPermission = <In>(
92
- permission: PikkuPermission<In> | PikkuPermissionConfig<In>
93
- ): PikkuPermission<In> => {
94
- return typeof permission === 'function' ? permission : permission.func
95
- }
96
-
97
- /**
98
- * Type-safe auth-only permission that only needs services and session.
99
- * Use this for upfront authorization gates (MCP tools, AI agents, workflows)
100
- * where request data isn't available yet.
101
- *
102
- * @template RequiredServices - The services required for this auth check
103
- */
104
- export type PikkuAuth<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuAuth<RequiredServices, Session>
105
-
106
- /**
107
- * Configuration object for creating an auth permission with metadata
108
- */
109
- export type PikkuAuthConfig<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuAuthConfig<RequiredServices, Session>
110
-
111
- /**
112
- * Factory function for creating auth-only permissions with tree-shaking support.
113
- * Auth permissions only receive services and session (no request data),
114
- * making them evaluable before request data is available.
115
- *
116
- * @example
117
- * \`\`\`typescript
118
- * const isAuthenticated = pikkuAuth(async ({ logger }, session) => {
119
- * return !!session
120
- * })
121
- *
122
- * const isAdmin = pikkuAuth({
123
- * name: 'Admin Auth',
124
- * description: 'Checks if user is an admin',
125
- * func: async ({ logger }, session) => {
126
- * return session?.role === 'admin'
127
- * }
128
- * })
129
- * \`\`\`
130
- */
131
- export const pikkuAuth = <RequiredServices extends SingletonServices = SingletonServices>(
132
- auth: PikkuAuth<RequiredServices> | PikkuAuthConfig<RequiredServices>
133
- ): PikkuPermission<any, any> => {
134
- return pikkuAuthCore(auth as any) as any
135
- }
136
-
137
- /**
138
- * Configuration object for creating middleware with metadata
139
- */
140
- export type PikkuMiddlewareConfig<RequiredServices extends SingletonServices = SingletonServices> = {
141
- /** The middleware function */
142
- func: PikkuMiddleware<RequiredServices>
143
- /** Optional human-readable name for the middleware */
144
- name?: string
145
- /** Optional description of what the middleware does */
146
- description?: string
147
- }
148
-
149
- /**
150
- * Factory function for creating middleware with tree-shaking support.
151
- * Supports both direct function and configuration object syntax.
152
- *
153
- * @example
154
- * ```typescript
155
- * // Direct function syntax
156
- * const middleware = pikkuMiddleware(({ logger }, wires, next) => {
157
- * logger.info('Middleware executed')
158
- * await next()
159
- * })
160
- *
161
- * // Configuration object syntax with metadata
162
- * const logMiddleware = pikkuMiddleware({
163
- * name: 'Request Logger',
164
- * description: 'Logs all incoming requests',
165
- * func: async ({ logger }, wires, next) => {
166
- * logger.info('Request started')
167
- * await next()
168
- * }
169
- * })
170
- * ```
171
- */
172
- export const pikkuMiddleware = <RequiredServices extends SingletonServices = SingletonServices>(
173
- middleware: PikkuMiddleware<RequiredServices> | PikkuMiddlewareConfig<RequiredServices>
174
- ): PikkuMiddleware<RequiredServices> => {
175
- return typeof middleware === 'function' ? middleware : middleware.func
176
- }
177
-
178
- /**
179
- * Factory function for creating middleware factories
180
- * Use this when your middleware needs configuration/input parameters
181
- *
182
- * @example
183
- * ```typescript
184
- * export const logMiddleware = pikkuMiddlewareFactory<LogOptions>(({
185
- * message,
186
- * level = 'info'
187
- * }) => {
188
- * return pikkuMiddleware(async ({ logger }, next) => {
189
- * logger[level](message)
190
- * await next()
191
- * })
192
- * })
193
- * ```
194
- */
195
- export const pikkuMiddlewareFactory = <In = any>(
196
- factory: (input: In) => PikkuMiddleware
197
- ): ((input: In) => PikkuMiddleware) => {
198
- return factory
199
- }
200
-
201
- /**
202
- * Factory function for creating permission factories
203
- * Use this when your permission needs configuration/input parameters
204
- *
205
- * @example
206
- * ```typescript
207
- * export const requireRole = pikkuPermissionFactory<{ role: string }>(({
208
- * role
209
- * }) => {
210
- * return pikkuPermission(async ({ logger }, data, { session }) => {
211
- * if (!session || session.role !== role) {
212
- * logger.warn(`Permission denied: required role '${role}'`)
213
- * return false
214
- * }
215
- * return true
216
- * })
217
- * })
218
- * ```
219
- */
220
- export const pikkuPermissionFactory = <In = any>(
221
- factory: (input: In) => PikkuPermission<any>
222
- ): ((input: In) => PikkuPermission<any>) => {
223
- return factory
224
- }
225
-
226
- /**
227
- * A function that generates a human-readable description of a pending approval action.
228
- * Used by AI agents to show meaningful approval prompts instead of raw tool arguments.
229
- *
230
- * @template In - The input type (same as the function it describes)
231
- * @template RequiredServices - The services required for this description function
232
- */
233
- export type PikkuApprovalDescription<In = unknown, RequiredServices extends Services = Services> = (
234
- services: RequiredServices,
235
- data: In
236
- ) => Promise<string>
237
-
238
- /**
239
- * Factory function for creating approval description functions with tree-shaking support.
240
- *
241
- * @example
242
- * ```typescript
243
- * export const deleteTodoApproval = pikkuApprovalDescription(
244
- * async ({ todoStore }, { id }) => {
245
- * const todo = await todoStore.get(id)
246
- * return \`Delete todo: "${todo.title}"\`
247
- * }
248
- * )
249
- * ```
250
- */
251
- export const pikkuApprovalDescription = <In = unknown, RequiredServices extends Services = Services>(
252
- fn: PikkuApprovalDescription<In, RequiredServices>
253
- ): PikkuApprovalDescription<In, RequiredServices> => {
254
- return fn
255
- }
256
-
257
- /**
258
- * A sessionless API function that doesn't require user authentication.
259
- * Use this for public endpoints, health checks, or operations that don't need user context.
260
- *
261
- * @template In - The input type
262
- * @template Out - The output type that the function returns
263
- * @template RequiredServices - Services required by this function
264
- */
265
- export type PikkuFunctionSessionless<
266
- In = unknown,
267
- Out = never,
268
- RequiredWires extends keyof PikkuWire = never,
269
- RequiredServices extends Services = Services
270
- > = CorePikkuFunctionSessionless<
271
- In,
272
- Out,
273
- RequiredServices,
274
- Session,
275
- PickRequired<PikkuWire<In, Out, false, Session, TypedPikkuRPC, null, any, TypedWorkflow>, RequiredWires>
276
- >
277
-
278
- /**
279
- * A session-aware API function that requires user authentication.
280
- * Use this for protected endpoints that need access to user session data.
281
- *
282
- * @template In - The input type
283
- * @template Out - The output type that the function returns
284
- * @template RequiredServices - Services required by this function
285
- */
286
- export type PikkuFunction<
287
- In = unknown,
288
- Out = never,
289
- RequiredWires extends keyof PikkuWire = 'session',
290
- RequiredServices extends Services = Services
291
- > = CorePikkuFunction<
292
- In,
293
- Out,
294
- RequiredServices,
295
- Session,
296
- PickRequired<PikkuWire<In, Out, true, Session, TypedPikkuRPC, null, any, TypedWorkflow>, RequiredWires>
297
- >
298
-
299
- /**
300
- * Helper type to infer the output type from a Standard Schema
301
- */
302
- export type InferSchemaOutput<T> = T extends StandardSchemaV1<any, infer Output> ? Output : never
303
-
304
- /**
305
- * Configuration object for Pikku functions with optional middleware, permissions, tags, and documentation.
306
- * This type wraps CorePikkuFunctionConfig with the user's custom types.
307
- *
308
- * @template In - The input type
309
- * @template Out - The output type
310
- * @template PikkuFunc - The function type (can be narrowed to PikkuFunction or PikkuFunctionSessionless)
311
- */
312
- export type PikkuFunctionConfig<
313
- In = unknown,
314
- Out = unknown,
315
- RequiredWires extends keyof PikkuWire = never,
316
- PikkuFunc extends PikkuFunction<In, Out, RequiredWires> | PikkuFunctionSessionless<In, Out, RequiredWires> = PikkuFunction<In, Out, RequiredWires> | PikkuFunctionSessionless<In, Out, RequiredWires>,
317
- InputSchema extends StandardSchemaV1 | undefined = undefined,
318
- OutputSchema extends StandardSchemaV1 | undefined = undefined
319
- > = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware, InputSchema, OutputSchema>
320
-
321
- /**
322
- * Configuration object for Pikku functions with Zod schema validation.
323
- * Use this when you want to define input/output schemas using Zod.
324
- * Types are automatically inferred from the schemas.
325
- */
326
- export type PikkuFunctionConfigWithSchema<
327
- InputSchema extends StandardSchemaV1 | undefined = undefined,
328
- OutputSchema extends StandardSchemaV1 | undefined = undefined,
329
- RequiredWires extends keyof PikkuWire = never
330
- > = {
331
- name?: string
332
- tags?: string[]
333
- expose?: boolean
334
- mcp?: boolean
335
- internal?: boolean
336
- approvalRequired?: boolean
337
- approvalDescription?: InputSchema extends StandardSchemaV1 ? PikkuApprovalDescription<InferSchemaOutput<InputSchema>> : never
338
- func: PikkuFunction<
339
- InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown,
340
- OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown,
341
- RequiredWires
342
- > | PikkuFunctionSessionless<
343
- InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown,
344
- OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown,
345
- RequiredWires
346
- >
347
- auth?: boolean
348
- permissions?: InputSchema extends StandardSchemaV1 ? CorePermissionGroup<PikkuPermission<InferSchemaOutput<InputSchema>>> : undefined
349
- middleware?: PikkuMiddleware[]
350
- input?: InputSchema
351
- output?: OutputSchema
352
- node?: NodeConfig
353
- errors?: Array<typeof PikkuError>
354
- }
355
-
356
- /**
357
- * Creates a Pikku function that can be either session-aware or sessionless.
358
- * This is the main function wrapper for creating API endpoints.
359
- *
360
- * Supports two patterns:
361
- * 1. Generic types: `pikkuFunc<Input, Output>({ func: ... })`
362
- * 2. Zod schemas: `pikkuFunc({ input: z.object(...), output: z.object(...), func: ... })`
363
- *
364
- * @template In - Input type for the function (inferred from schema if provided)
365
- * @template Out - Output type for the function (inferred from schema if provided)
366
- * @param func - Function definition, either direct function or configuration object
367
- * @returns The normalized configuration object
368
- *
369
- * @example
370
- * ```typescript
371
- * // Pattern 1: Using generic types
372
- * const createUser = pikkuFunc<{name: string, email: string}, {id: number}>({
373
- * func: async ({db}, input) => {
374
- * const user = await db.users.create(input)
375
- * return { id: user.id }
376
- * }
377
- * })
378
- *
379
- * // Pattern 2: Using Zod schemas (types inferred automatically)
380
- * const createUserInput = z.object({ name: z.string(), email: z.string() })
381
- * const createUserOutput = z.object({ id: z.number() })
382
- *
383
- * const createUser = pikkuFunc({
384
- * input: createUserInput,
385
- * output: createUserOutput,
386
- * func: async ({db}, input) => {
387
- * // input is typed as { name: string, email: string }
388
- * const user = await db.users.create(input)
389
- * return { id: user.id } // must match output schema
390
- * }
391
- * })
392
- * ```
393
- */
394
- export function pikkuFunc<
395
- InputSchema extends StandardSchemaV1 | undefined = undefined,
396
- OutputSchema extends StandardSchemaV1 | undefined = undefined
397
- >(
398
- config: PikkuFunctionConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc'>
399
- ): PikkuFunctionConfig<InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown, 'session' | 'rpc'>
400
- export function pikkuFunc<In, Out = unknown>(
401
- func:
402
- | PikkuFunction<In, Out, 'session' | 'rpc'>
403
- | PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
404
- ): PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
405
- export function pikkuFunc(func: any) {
406
- return typeof func === 'function' ? { func } : func
407
- }
408
-
409
- /**
410
- * Configuration object for sessionless Pikku functions with Zod schema validation.
411
- */
412
- export type PikkuFunctionSessionlessConfigWithSchema<
413
- InputSchema extends StandardSchemaV1 | undefined = undefined,
414
- OutputSchema extends StandardSchemaV1 | undefined = undefined,
415
- RequiredWires extends keyof PikkuWire = never
416
- > = {
417
- name?: string
418
- description?: string
419
- tags?: string[]
420
- expose?: boolean
421
- mcp?: boolean
422
- internal?: boolean
423
- remote?: boolean
424
- approvalRequired?: boolean
425
- approvalDescription?: InputSchema extends StandardSchemaV1 ? PikkuApprovalDescription<InferSchemaOutput<InputSchema>> : never
426
- func: PikkuFunctionSessionless<
427
- InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown,
428
- OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown,
429
- RequiredWires
430
- >
431
- auth?: boolean
432
- permissions?: InputSchema extends StandardSchemaV1 ? CorePermissionGroup<PikkuPermission<InferSchemaOutput<InputSchema>>> : undefined
433
- middleware?: PikkuMiddleware[]
434
- input?: InputSchema
435
- output?: OutputSchema
436
- node?: NodeConfig
437
- errors?: Array<typeof PikkuError>
438
- }
439
-
440
- /**
441
- * Creates a sessionless Pikku function that doesn't require user authentication.
442
- * Use this for public endpoints, webhooks, or background tasks.
443
- *
444
- * Supports two patterns:
445
- * 1. Generic types: `pikkuSessionlessFunc<Input, Output>({ func: ... })`
446
- * 2. Zod schemas: `pikkuSessionlessFunc({ input: z.object(...), func: ... })`
447
- *
448
- * @template In - Input type for the function (inferred from schema if provided)
449
- * @template Out - Output type for the function (inferred from schema if provided)
450
- * @param func - Function definition, either direct function or configuration object
451
- * @returns The normalized configuration object
452
- *
453
- * @example
454
- * ```typescript
455
- * // Pattern 1: Using generic types
456
- * const healthCheck = pikkuSessionlessFunc<void, {status: string}>({
457
- * func: async ({logger}) => {
458
- * return { status: 'healthy' }
459
- * }
460
- * })
461
- *
462
- * // Pattern 2: Using Zod schemas
463
- * const greetInput = z.object({ name: z.string() })
464
- * const greetOutput = z.object({ message: z.string() })
465
- *
466
- * const greet = pikkuSessionlessFunc({
467
- * input: greetInput,
468
- * output: greetOutput,
469
- * func: async (_services, { name }) => {
470
- * return { message: `Hello, ${name}!` }
471
- * }
472
- * })
473
- * ```
474
- */
475
- export function pikkuSessionlessFunc<
476
- InputSchema extends StandardSchemaV1 | undefined = undefined,
477
- OutputSchema extends StandardSchemaV1 | undefined = undefined
478
- >(
479
- config: PikkuFunctionSessionlessConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc'>
480
- ): PikkuFunctionConfig<InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown, 'session' | 'rpc'>
481
- export function pikkuSessionlessFunc<In, Out = unknown>(
482
- func:
483
- | PikkuFunctionSessionless<In, Out, 'session' | 'rpc'>
484
- | PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
485
- ): PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
486
- export function pikkuSessionlessFunc(func: any) {
487
- return typeof func === 'function' ? { func } : func
488
- }
489
-
490
- /**
491
- * Creates a function that takes no input and returns no output.
492
- * Useful for health checks, triggers, or cleanup operations.
493
- *
494
- * @param func - Function definition, either direct function or configuration object
495
- * @returns The normalized configuration object
496
- *
497
- * @example
498
- * ```typescript
499
- * const cleanupTempFiles = pikkuVoidFunc(async ({fileSystem, logger}) => {
500
- * logger.info('Starting cleanup of temporary files')
501
- * await fileSystem.deleteDirectory('/tmp/uploads')
502
- * logger.info('Cleanup completed')
503
- * })
504
- * ```
505
- */
506
- export const pikkuVoidFunc = (
507
- func:
508
- | PikkuFunctionSessionless<void, void, 'session' | 'rpc'>
509
- | PikkuFunctionConfig<void, void, 'session' | 'rpc'>
510
- ) => {
511
- return typeof func === 'function' ? { func } : func
512
- }
513
-
514
- /**
515
- * Creates a wrapper function for addon package functions that are exposed via RPC.
516
- * This allows you to wire addon functions to any wiring type (HTTP, queue, etc.)
517
- * without type compatibility issues.
518
- *
519
- * @template Name - The RPC method name (must be a key in FlattenedRPCMap)
520
- * @param rpcName - The name of the RPC method to invoke
521
- * @returns A Pikku function that proxies calls to the addon RPC method
522
- *
523
- * @example
524
- * ```typescript
525
- * // Wire an addon function via HTTP
526
- * wireHTTP({
527
- * auth: false,
528
- * method: 'get',
529
- * route: '/addon/hello',
530
- * func: addon('ext:hello'),
531
- * tags: ['addon'],
532
- * })
533
- * ```
534
- */
535
- export const addon = <Name extends keyof FlattenedRPCMap>(
536
- rpcName: Name
537
- ): PikkuFunctionConfig<
538
- FlattenedRPCMap[Name]['input'],
539
- FlattenedRPCMap[Name]['output'],
540
- 'session' | 'rpc'
541
- > => {
542
- return {
543
- func: async (_services: any, data: FlattenedRPCMap[Name]['input'], { rpc }: any) => {
544
- return rpc.invoke(rpcName, data)
545
- }
546
- } as PikkuFunctionConfig<
547
- FlattenedRPCMap[Name]['input'],
548
- FlattenedRPCMap[Name]['output'],
549
- 'session' | 'rpc'
550
- >
551
- }
552
-
553
- /**
554
- * Creates a Pikku config factory.
555
- * Use this to define your application's configuration factory.
556
- *
557
- * @param func - Config factory function that returns your application's config
558
- * @returns The config factory function
559
- *
560
- * @example
561
- * ```typescript
562
- * export const createConfig = pikkuConfig(async () => {
563
- * return {
564
- * apiUrl: process.env.API_URL || 'http://localhost:3000',
565
- * dbUrl: process.env.DATABASE_URL
566
- * }
567
- * })
568
- * ```
569
- */
570
- export const pikkuConfig = (
571
- func: (variables?: any, ...args: any[]) => Promise<Config>
572
- ) => func
573
-
574
-
575
- /**
576
- * Creates a Pikku singleton services factory.
577
- * Use this to define services that are created once and shared across all requests.
578
- *
579
- * @param func - Singleton services factory function
580
- * @returns The singleton services factory function
581
- *
582
- * @example
583
- * ```typescript
584
- * export const createSingletonServices = pikkuServices(async (config, existingServices) => {
585
- * return {
586
- * config,
587
- * logger: new CustomLogger(),
588
- * db: await createDatabaseConnection(config.dbUrl)
589
- * }
590
- * })
591
- * ```
592
- */
593
- export const pikkuServices = (
594
- func: (config: Config, existingServices: Partial<SingletonServices>) => Promise<RequiredSingletonServices>
595
- ) => {
596
- return async (config: Config, existingServices: Partial<SingletonServices> = {}) => {
597
- const services = await func(config, existingServices)
598
- __pikkuState(null, 'package', 'singletonServices', services as any)
599
- return services
600
- }
601
- }
602
-
603
- /**
604
- * Creates a Pikku wire services factory.
605
- * Use this to define services that are created per-request/session.
606
- *
607
- * @param func - Wire services factory function
608
- * @returns The wire services factory function
609
- *
610
- * @example
611
- * ```typescript
612
- * export const createWireServices = pikkuWireServices(async (services, wire) => {
613
- * const session = await wire.session?.get()
614
- * return {
615
- * userCache: new UserCache(session?.userId)
616
- * }
617
- * })
618
- * ```
619
- */
620
- export const pikkuWireServices = (
621
- func: (
622
- services: SingletonServices,
623
- wire: any
624
- ) => Promise<RequiredWireServices>
625
- ): CreateWireServices => {
626
- const factories = __pikkuState(null, 'package', 'factories')
627
- __pikkuState(null, 'package', 'factories', { ...factories, createWireServices: func as any })
628
- return func as unknown as CreateWireServices
629
- }
630
-
631
- /**
632
- * Adds global middleware for a specific tag.
633
- *
634
- * This function allows you to register middleware that will be applied to
635
- * any wiring (HTTP, Channel, Queue, Scheduler, MCP) that includes the matching tag.
636
- *
637
- * @param tag - The tag that the middleware should apply to.
638
- * @param middleware - The middleware array to apply for the specified tag.
639
- *
640
- * @throws Error if middleware for the tag already exists.
641
- *
642
- * @example
643
- * ```typescript
644
- * // Add admin middleware for admin endpoints
645
- * addMiddleware('admin', [adminMiddleware])
646
- *
647
- * // Add authentication middleware for auth endpoints
648
- * addMiddleware('auth', [authMiddleware])
649
- *
650
- * // Add logging middleware for all API endpoints
651
- * addMiddleware('api', [loggingMiddleware])
652
- * ```
653
- */
654
- export const addMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
655
- addMiddlewareCore(tag, middleware as any, '@pikku/addon-graph')
656
- }
657
-
658
- /**
659
- * Adds global permissions for a specific tag.
660
- *
661
- * This function allows you to register permissions that will be applied to
662
- * any wiring (HTTP, Channel, Queue, Scheduler, MCP) that includes the matching tag.
663
- *
664
- * @param tag - The tag that the permissions should apply to.
665
- * @param permissions - The permissions array or object to apply for the specified tag.
666
- *
667
- * @throws Error if permissions for the tag already exist.
668
- *
669
- * @example
670
- * ```typescript
671
- * // Add admin permissions for admin endpoints
672
- * addPermission('admin', [adminPermission])
673
- *
674
- * // Add authentication permissions for auth endpoints
675
- * addPermission('auth', [authPermission])
676
- *
677
- * // Add read permissions for all API endpoints (as object)
678
- * addPermission('api', { read: readPermission })
679
- * ```
680
- */
681
- export const addPermission = <In = unknown>(tag: string, permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
682
- addPermissionCore(tag, permissions as any, '@pikku/addon-graph')
683
- }
684
-
685
- export { wireAddon } from '@pikku/core'
686
- export type { WireAddonConfig } from '@pikku/core'