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