@pikku/addon-graph 0.0.3 → 0.12.0

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