@pikku/cli 0.8.2 → 0.9.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 (175) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/bin/pikku-all.ts +41 -32
  3. package/bin/pikku-fetch.ts +1 -1
  4. package/bin/pikku-openapi.ts +2 -2
  5. package/bin/pikku-queue-service.ts +2 -2
  6. package/bin/pikku-websocket.ts +1 -1
  7. package/cli.schema.json +30 -30
  8. package/dist/bin/pikku-all.js +32 -32
  9. package/dist/bin/pikku-fetch.js +1 -1
  10. package/dist/bin/pikku-openapi.js +2 -2
  11. package/dist/bin/pikku-queue-service.js +2 -2
  12. package/dist/bin/pikku-websocket.js +1 -1
  13. package/dist/bin/pikku.js +0 -0
  14. package/dist/src/events/channels/pikku-channels.js +3 -3
  15. package/dist/src/events/channels/pikku-command-channels.js +3 -3
  16. package/dist/src/events/channels/serialize-typed-channel-map.js +2 -2
  17. package/dist/src/events/channels/serialize-websocket-wrapper.js +15 -1
  18. package/dist/src/events/fetch/index.js +2 -2
  19. package/dist/src/events/http/openapi-spec-generator.d.ts +2 -2
  20. package/dist/src/events/http/pikku-command-http-map.js +4 -4
  21. package/dist/src/events/http/pikku-command-http-routes.js +3 -3
  22. package/dist/src/events/http/pikku-command-nextjs.d.ts +2 -0
  23. package/dist/src/events/http/pikku-command-nextjs.js +36 -0
  24. package/dist/src/events/http/pikku-http-routes.js +3 -3
  25. package/dist/src/events/http/serialize-typed-http-map.d.ts +2 -2
  26. package/dist/src/events/http/serialize-typed-http-map.js +11 -11
  27. package/dist/src/events/mcp/pikku-command-mcp.js +3 -3
  28. package/dist/src/events/queue/pikku-command-queue-service.js +6 -6
  29. package/dist/src/events/queue/pikku-command-queue.js +3 -3
  30. package/dist/src/events/queue/pikku-queue.js +3 -3
  31. package/dist/src/events/rpc/index.d.ts +2 -0
  32. package/dist/src/events/rpc/index.js +12 -0
  33. package/dist/src/events/rpc/pikku-command-rpc-client.js +6 -6
  34. package/dist/src/events/rpc/pikku-command-rpc.js +2 -2
  35. package/dist/src/events/rpc/pikku-rpc.js +2 -2
  36. package/dist/src/events/rpc/serialize-rpc-wrapper.js +40 -1
  37. package/dist/src/events/scheduler/pikku-command-scheduler.js +3 -3
  38. package/dist/src/inspector-glob.js +2 -2
  39. package/dist/src/pikku-cli-config.d.ts +17 -17
  40. package/dist/src/pikku-cli-config.js +31 -31
  41. package/dist/src/runtimes/nextjs/pikku-command-nextjs.js +3 -3
  42. package/dist/src/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +29 -29
  43. package/dist/src/runtimes/nextjs/serialize-nextjs-http-wrapper.js +28 -28
  44. package/dist/src/schema-generator.d.ts +2 -2
  45. package/dist/src/schema-generator.js +2 -2
  46. package/dist/src/serialize-pikku-types.js +67 -67
  47. package/dist/src/utils.js +8 -0
  48. package/dist/src/wirings/channels/pikku-channels.d.ts +2 -0
  49. package/dist/src/wirings/channels/pikku-channels.js +9 -0
  50. package/dist/src/wirings/channels/pikku-command-channels-map.d.ts +2 -0
  51. package/dist/src/wirings/channels/pikku-command-channels-map.js +8 -0
  52. package/dist/src/wirings/channels/pikku-command-channels.d.ts +2 -0
  53. package/dist/src/wirings/channels/pikku-command-channels.js +9 -0
  54. package/dist/src/wirings/channels/pikku-command-websocket-typed.d.ts +2 -0
  55. package/dist/src/wirings/channels/pikku-command-websocket-typed.js +15 -0
  56. package/dist/src/wirings/channels/serialize-typed-channel-map.d.ts +4 -0
  57. package/dist/src/wirings/channels/serialize-typed-channel-map.js +111 -0
  58. package/dist/src/wirings/channels/serialize-websocket-wrapper.d.ts +1 -0
  59. package/dist/src/wirings/channels/serialize-websocket-wrapper.js +75 -0
  60. package/dist/src/wirings/fetch/index.d.ts +2 -0
  61. package/dist/src/wirings/fetch/index.js +12 -0
  62. package/dist/src/wirings/functions/pikku-command-function-types.d.ts +2 -0
  63. package/dist/src/wirings/functions/pikku-command-function-types.js +13 -0
  64. package/dist/src/wirings/functions/pikku-command-functions.d.ts +6 -0
  65. package/dist/src/wirings/functions/pikku-command-functions.js +35 -0
  66. package/dist/src/wirings/functions/pikku-command-services.d.ts +3 -0
  67. package/dist/src/wirings/functions/pikku-command-services.js +73 -0
  68. package/dist/src/wirings/functions/pikku-function-types.d.ts +2 -0
  69. package/dist/src/wirings/functions/pikku-function-types.js +13 -0
  70. package/dist/src/wirings/functions/pikku-functions.d.ts +6 -0
  71. package/dist/src/wirings/functions/pikku-functions.js +35 -0
  72. package/dist/src/wirings/http/openapi-spec-generator.d.ts +79 -0
  73. package/dist/src/wirings/http/openapi-spec-generator.js +145 -0
  74. package/dist/src/wirings/http/pikku-command-http-map.d.ts +2 -0
  75. package/dist/src/wirings/http/pikku-command-http-map.js +8 -0
  76. package/dist/src/wirings/http/pikku-command-http-routes.d.ts +2 -0
  77. package/dist/src/wirings/http/pikku-command-http-routes.js +9 -0
  78. package/dist/src/wirings/http/pikku-command-openapi.d.ts +2 -0
  79. package/dist/src/wirings/http/pikku-command-openapi.js +20 -0
  80. package/dist/src/wirings/http/pikku-http-routes.d.ts +2 -0
  81. package/dist/src/wirings/http/pikku-http-routes.js +9 -0
  82. package/dist/src/wirings/http/serialize-fetch-wrapper.d.ts +1 -0
  83. package/dist/src/wirings/http/serialize-fetch-wrapper.js +67 -0
  84. package/dist/src/wirings/http/serialize-typed-http-map.d.ts +4 -0
  85. package/dist/src/wirings/http/serialize-typed-http-map.js +100 -0
  86. package/dist/src/wirings/mcp/pikku-command-mcp-json.d.ts +2 -0
  87. package/dist/src/wirings/mcp/pikku-command-mcp-json.js +13 -0
  88. package/dist/src/wirings/mcp/pikku-command-mcp.d.ts +2 -0
  89. package/dist/src/wirings/mcp/pikku-command-mcp.js +54 -0
  90. package/dist/src/wirings/mcp/serialize-mcp-json.d.ts +5 -0
  91. package/dist/src/wirings/mcp/serialize-mcp-json.js +101 -0
  92. package/dist/src/wirings/queue/pikku-command-queue-map.d.ts +2 -0
  93. package/dist/src/wirings/queue/pikku-command-queue-map.js +8 -0
  94. package/dist/src/wirings/queue/pikku-command-queue-service.d.ts +2 -0
  95. package/dist/src/wirings/queue/pikku-command-queue-service.js +15 -0
  96. package/dist/src/wirings/queue/pikku-command-queue.d.ts +2 -0
  97. package/dist/src/wirings/queue/pikku-command-queue.js +10 -0
  98. package/dist/src/wirings/queue/pikku-queue-map.d.ts +2 -0
  99. package/dist/src/wirings/queue/pikku-queue-map.js +8 -0
  100. package/dist/src/wirings/queue/pikku-queue.d.ts +2 -0
  101. package/dist/src/wirings/queue/pikku-queue.js +10 -0
  102. package/dist/src/wirings/queue/serialize-queue-map.d.ts +4 -0
  103. package/dist/src/wirings/queue/serialize-queue-map.js +77 -0
  104. package/dist/src/wirings/queue/serialize-queue-meta.d.ts +2 -0
  105. package/dist/src/wirings/queue/serialize-queue-meta.js +6 -0
  106. package/dist/src/wirings/queue/serialize-queue-wrapper.d.ts +1 -0
  107. package/dist/src/wirings/queue/serialize-queue-wrapper.js +35 -0
  108. package/dist/src/wirings/rpc/pikku-command-rpc-client.d.ts +2 -0
  109. package/dist/src/wirings/rpc/pikku-command-rpc-client.js +15 -0
  110. package/dist/src/wirings/rpc/pikku-command-rpc-map.d.ts +2 -0
  111. package/dist/src/wirings/rpc/pikku-command-rpc-map.js +8 -0
  112. package/dist/src/wirings/rpc/pikku-command-rpc.d.ts +2 -0
  113. package/dist/src/wirings/rpc/pikku-command-rpc.js +6 -0
  114. package/dist/src/wirings/rpc/pikku-rpc.d.ts +2 -0
  115. package/dist/src/wirings/rpc/pikku-rpc.js +6 -0
  116. package/dist/src/wirings/rpc/serialize-rpc-wrapper.d.ts +1 -0
  117. package/dist/src/wirings/rpc/serialize-rpc-wrapper.js +68 -0
  118. package/dist/src/wirings/rpc/serialize-typed-rpc-map.d.ts +4 -0
  119. package/dist/src/wirings/rpc/serialize-typed-rpc-map.js +66 -0
  120. package/dist/src/wirings/scheduler/pikku-command-scheduler.d.ts +2 -0
  121. package/dist/src/wirings/scheduler/pikku-command-scheduler.js +10 -0
  122. package/dist/src/wirings/scheduler/serialize-scheduler-meta.d.ts +2 -0
  123. package/dist/src/wirings/scheduler/serialize-scheduler-meta.js +10 -0
  124. package/dist/tsconfig.tsbuildinfo +1 -1
  125. package/lcov.info +582 -0
  126. package/package.json +3 -3
  127. package/src/inspector-glob.ts +2 -2
  128. package/src/pikku-cli-config.ts +67 -52
  129. package/src/runtimes/nextjs/pikku-command-nextjs.ts +3 -3
  130. package/src/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +29 -29
  131. package/src/runtimes/nextjs/serialize-nextjs-http-wrapper.ts +28 -28
  132. package/src/schema-generator.ts +3 -3
  133. package/src/serialize-pikku-types.ts +67 -67
  134. package/src/utils.test.ts +38 -0
  135. package/src/utils.ts +9 -0
  136. package/src/{events → wirings}/channels/pikku-channels.ts +5 -4
  137. package/src/{events → wirings}/channels/pikku-command-channels.ts +5 -4
  138. package/src/{events → wirings}/channels/serialize-typed-channel-map.ts +3 -3
  139. package/src/{events → wirings}/channels/serialize-websocket-wrapper.ts +19 -5
  140. package/src/{events → wirings}/fetch/index.ts +2 -2
  141. package/src/{events → wirings}/http/openapi-spec-generator.ts +3 -3
  142. package/src/{events → wirings}/http/pikku-command-http-map.ts +5 -5
  143. package/src/{events → wirings}/http/pikku-command-http-routes.ts +5 -5
  144. package/src/{events → wirings}/http/pikku-http-routes.ts +5 -5
  145. package/src/wirings/http/serialize-fetch-wrapper.ts +67 -0
  146. package/src/{events → wirings}/http/serialize-typed-http-map.ts +17 -17
  147. package/src/{events → wirings}/mcp/pikku-command-mcp.ts +5 -5
  148. package/src/{events → wirings}/queue/pikku-command-queue-service.ts +9 -6
  149. package/src/{events → wirings}/queue/pikku-command-queue.ts +8 -5
  150. package/src/{events → wirings}/queue/pikku-queue.ts +8 -5
  151. package/src/{events → wirings}/rpc/pikku-command-rpc-client.ts +9 -6
  152. package/src/{events → wirings}/rpc/pikku-command-rpc.ts +2 -2
  153. package/src/{events → wirings}/rpc/pikku-rpc.ts +2 -2
  154. package/src/wirings/rpc/serialize-rpc-wrapper.ts +68 -0
  155. package/src/{events → wirings}/scheduler/pikku-command-scheduler.ts +8 -4
  156. package/src/events/http/serialize-fetch-wrapper.ts +0 -67
  157. package/src/events/rpc/serialize-rpc-wrapper.ts +0 -29
  158. /package/src/{events → wirings}/channels/pikku-command-channels-map.ts +0 -0
  159. /package/src/{events → wirings}/channels/pikku-command-websocket-typed.ts +0 -0
  160. /package/src/{events → wirings}/functions/pikku-command-function-types.ts +0 -0
  161. /package/src/{events → wirings}/functions/pikku-command-functions.ts +0 -0
  162. /package/src/{events → wirings}/functions/pikku-command-services.ts +0 -0
  163. /package/src/{events → wirings}/functions/pikku-function-types.ts +0 -0
  164. /package/src/{events → wirings}/functions/pikku-functions.ts +0 -0
  165. /package/src/{events → wirings}/http/pikku-command-openapi.ts +0 -0
  166. /package/src/{events → wirings}/mcp/pikku-command-mcp-json.ts +0 -0
  167. /package/src/{events → wirings}/mcp/serialize-mcp-json.ts +0 -0
  168. /package/src/{events → wirings}/queue/pikku-command-queue-map.ts +0 -0
  169. /package/src/{events → wirings}/queue/pikku-queue-map.ts +0 -0
  170. /package/src/{events → wirings}/queue/serialize-queue-map.ts +0 -0
  171. /package/src/{events → wirings}/queue/serialize-queue-meta.ts +0 -0
  172. /package/src/{events → wirings}/queue/serialize-queue-wrapper.ts +0 -0
  173. /package/src/{events → wirings}/rpc/pikku-command-rpc-map.ts +0 -0
  174. /package/src/{events → wirings}/rpc/serialize-typed-rpc-map.ts +0 -0
  175. /package/src/{events → wirings}/scheduler/serialize-scheduler-meta.ts +0 -0
@@ -13,13 +13,13 @@ export const serializePikkuTypes = (
13
13
  * This is used to provide the application types in the typescript project
14
14
  */
15
15
 
16
- import { CoreAPIPermission, PikkuMiddleware } from '@pikku/core'
17
- import { CoreAPIFunction, CoreAPIFunctionSessionless } from '@pikku/core/function'
18
- import { CoreHTTPFunctionRoute, AssertRouteParams, addHTTPRoute as addCoreHTTPRoute } from '@pikku/core/http'
19
- import { CoreScheduledTask, addScheduledTask as addCoreScheduledTask } from '@pikku/core/scheduler'
20
- import { CoreAPIChannel, PikkuChannel, addChannel as addCoreChannel } from '@pikku/core/channel'
21
- import { CoreQueueWorker, addQueueWorker as addCoreQueueWorker } from '@pikku/core/queue'
22
- import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, addMCPResource as addCoreMCPResource, addMCPTool as addCoreMCPTool, addMCPPrompt as addCoreMCPPrompt, MCPResourceResponse, MCPToolResponse, MCPPromptResponse, PikkuMCP } from '@pikku/core'
16
+ import { CorePikkuPermission, PikkuMiddleware } from '@pikku/core'
17
+ import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
18
+ import { CoreHTTPFunctionWiring, AssertHTTPWiringParams, wireHTTP as wireHTTPCore } from '@pikku/core/http'
19
+ import { CoreScheduledTask, wireScheduler as wireSchedulerCore } from '@pikku/core/scheduler'
20
+ import { CoreChannel, PikkuChannel, wireChannel as wireChannelCore } from '@pikku/core/channel'
21
+ import { CoreQueueWorker, wireQueueWorker as wireQueueWorkerCore } from '@pikku/core/queue'
22
+ import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, wireMCPResource as wireMCPResourceCore, wireMCPTool as wireMCPToolCore, wireMCPPrompt as wireMCPPromptCore, MCPResourceResponse, MCPToolResponse, MCPPromptResponse, PikkuMCP } from '@pikku/core'
23
23
 
24
24
  ${userSessionTypeImport}
25
25
  ${singletonServicesTypeImport}
@@ -33,11 +33,11 @@ ${rpcMapTypeImport}
33
33
  * @template In - The input type that the permission check will receive
34
34
  * @template RequiredServices - The services required for this permission check
35
35
  */
36
- export type APIPermission<In = unknown, RequiredServices extends ${singletonServicesTypeName} = ${singletonServicesTypeName}> = CoreAPIPermission<In, RequiredServices, ${userSessionTypeName}>
36
+ export type PikkuPermission<In = unknown, RequiredServices extends ${singletonServicesTypeName} = ${singletonServicesTypeName}> = CorePikkuPermission<In, RequiredServices, ${userSessionTypeName}>
37
37
 
38
38
  /**
39
39
  * Type-safe middleware definition that can access your application's services and session.
40
- * Use this to define reusable middleware that can be applied to multiple routes.
40
+ * Use this to define reusable middleware that can be applied to multiple HTTP wirings.
41
41
  *
42
42
  * @template RequiredServices - The services required for this middleware
43
43
  */
@@ -53,7 +53,7 @@ export type APIMiddleware<RequiredServices extends ${singletonServicesTypeName}
53
53
  * @template MCPData - MCP data type (null = optional MCP)
54
54
  * @template RequiredServices - Services required by this function
55
55
  */
56
- type APIFunctionSessionless<
56
+ type PikkuFunctionSessionless<
57
57
  In = unknown,
58
58
  Out = never,
59
59
  ChannelData = null, // null means optional channel
@@ -67,7 +67,7 @@ type APIFunctionSessionless<
67
67
  ? { mcp?: PikkuMCP } // Optional MCP
68
68
  : { mcp: PikkuMCP } // Required MCP
69
69
  )
70
- > = CoreAPIFunctionSessionless<In, Out, ChannelData, RequiredServices, ${userSessionTypeName}>
70
+ > = CorePikkuFunctionSessionless<In, Out, ChannelData, RequiredServices, ${userSessionTypeName}>
71
71
 
72
72
  /**
73
73
  * A session-aware API function that requires user authentication.
@@ -79,7 +79,7 @@ type APIFunctionSessionless<
79
79
  * @template MCPData - MCP data type (null = optional MCP)
80
80
  * @template RequiredServices - Services required by this function
81
81
  */
82
- type APIFunction<
82
+ type PikkuFunction<
83
83
  In = unknown,
84
84
  Out = never,
85
85
  ChannelData = null, // null means optional channel
@@ -93,17 +93,17 @@ type APIFunction<
93
93
  ? { mcp?: PikkuMCP } // Optional MCP
94
94
  : { mcp: PikkuMCP } // Required MCP
95
95
  )
96
- > = CoreAPIFunction<In, Out, ChannelData, RequiredServices, ${userSessionTypeName}>
96
+ > = CorePikkuFunction<In, Out, ChannelData, RequiredServices, ${userSessionTypeName}>
97
97
 
98
98
  /**
99
- * Type definition for HTTP API routes with type-safe path parameters.
99
+ * Type definition for HTTP API wirings with type-safe path parameters.
100
100
  * Supports both authenticated and unauthenticated functions.
101
101
  *
102
- * @template In - Input type for the route
103
- * @template Out - Output type for the route
104
- * @template Route - String literal type for the route path (e.g., "/users/:id")
102
+ * @template In - Input type for the HTTP wiring
103
+ * @template Out - Output type for the HTTP wiring
104
+ * @template Route - String literal type for the HTTP path (e.g., "/users/:id")
105
105
  */
106
- type APIRoute<In, Out, Route extends string> = CoreHTTPFunctionRoute<In, Out, Route, APIFunction<In, Out>, APIFunctionSessionless<In, Out>, APIPermission<In>, APIMiddleware>
106
+ type HTTPWiring<In, Out, Route extends string> = CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction<In, Out>, PikkuFunctionSessionless<In, Out>, PikkuPermission<In>, APIMiddleware>
107
107
 
108
108
  /**
109
109
  * Type definition for WebSocket channels with typed data exchange.
@@ -112,13 +112,13 @@ type APIRoute<In, Out, Route extends string> = CoreHTTPFunctionRoute<In, Out, Ro
112
112
  * @template ChannelData - Type of data exchanged through the channel
113
113
  * @template Channel - String literal type for the channel name
114
114
  */
115
- type APIChannel<ChannelData, Channel extends string> = CoreAPIChannel<ChannelData, Channel, APIFunction<void, unknown> | APIFunction<void, unknown, ChannelData>, APIFunction<void, void> | APIFunction<void, void, ChannelData>, APIFunction<any, any> | APIFunction<any, any, ChannelData>, APIPermission>
115
+ type ChannelWiring<ChannelData, Channel extends string> = CoreChannel<ChannelData, Channel, PikkuFunction<void, unknown> | PikkuFunction<void, unknown, ChannelData>, PikkuFunction<void, void> | PikkuFunction<void, void, ChannelData>, PikkuFunction<any, any> | PikkuFunction<any, any, ChannelData>, PikkuPermission>
116
116
 
117
117
  /**
118
118
  * Type definition for scheduled tasks that run at specified intervals.
119
119
  * These are sessionless functions that execute based on cron expressions.
120
120
  */
121
- type ScheduledTask = CoreScheduledTask<APIFunctionSessionless<void, void>>
121
+ type SchedulerWiring = CoreScheduledTask<PikkuFunctionSessionless<void, void>>
122
122
 
123
123
  /**
124
124
  * Type definition for queue workers that process background jobs.
@@ -126,28 +126,28 @@ type ScheduledTask = CoreScheduledTask<APIFunctionSessionless<void, void>>
126
126
  * @template In - Input type for the queue job
127
127
  * @template Out - Output type for the queue job
128
128
  */
129
- type QueueWorker<In, Out> = CoreQueueWorker<APIFunctionSessionless<In, Out>>
129
+ type QueueWiring<In, Out> = CoreQueueWorker<PikkuFunctionSessionless<In, Out>>
130
130
 
131
131
  /**
132
132
  * Type definition for MCP resources that provide data to AI models.
133
133
  *
134
134
  * @template In - Input type for the resource request
135
135
  */
136
- type MCPResource<In> = CoreMCPResource<APIFunctionSessionless<In, MCPResourceResponse, null, true>>
136
+ type MCPResourceWiring<In> = CoreMCPResource<PikkuFunctionSessionless<In, MCPResourceResponse, null, true>>
137
137
 
138
138
  /**
139
139
  * Type definition for MCP tools that AI models can invoke.
140
140
  *
141
141
  * @template In - Input type for the tool invocation
142
142
  */
143
- type MCPTool<In> = CoreMCPTool<APIFunctionSessionless<In, MCPToolResponse, null, true>>
143
+ type MCPToolWiring<In> = CoreMCPTool<PikkuFunctionSessionless<In, MCPToolResponse, null, true>>
144
144
 
145
145
  /**
146
146
  * Type definition for MCP prompts that provide templates to AI models.
147
147
  *
148
148
  * @template In - Input type for the prompt parameters
149
149
  */
150
- type MCPPrompt<In> = CoreMCPPrompt<APIFunctionSessionless<In, MCPPromptResponse, null, true>>
150
+ type MCPPromptWiring<In> = CoreMCPPrompt<PikkuFunctionSessionless<In, MCPPromptResponse, null, true>>
151
151
 
152
152
  /**
153
153
  * Creates a Pikku function that can be either session-aware or sessionless.
@@ -172,14 +172,14 @@ type MCPPrompt<In> = CoreMCPPrompt<APIFunctionSessionless<In, MCPPromptResponse,
172
172
  */
173
173
  export const pikkuFunc = <In, Out = unknown>(
174
174
  func:
175
- | APIFunction<In, Out>
175
+ | PikkuFunction<In, Out>
176
176
  | {
177
- func: APIFunction<In, Out>
177
+ func: PikkuFunction<In, Out>
178
178
  auth?: true
179
179
  name?: string
180
180
  }
181
181
  | {
182
- func: APIFunctionSessionless<In, Out>
182
+ func: PikkuFunctionSessionless<In, Out>
183
183
  auth: false
184
184
  name?: string
185
185
  }
@@ -209,9 +209,9 @@ export const pikkuFunc = <In, Out = unknown>(
209
209
  */
210
210
  export const pikkuSessionlessFunc = <In, Out = unknown>(
211
211
  func:
212
- | APIFunctionSessionless<In, Out>
212
+ | PikkuFunctionSessionless<In, Out>
213
213
  | {
214
- func: APIFunctionSessionless<In, Out>
214
+ func: PikkuFunctionSessionless<In, Out>
215
215
  name?: string
216
216
  }
217
217
  ) => {
@@ -240,9 +240,9 @@ export const pikkuSessionlessFunc = <In, Out = unknown>(
240
240
  */
241
241
  export const pikkuChannelConnectionFunc = <Out = unknown, ChannelData = unknown>(
242
242
  func:
243
- | APIFunctionSessionless<void, Out, ChannelData>
243
+ | PikkuFunctionSessionless<void, Out, ChannelData>
244
244
  | {
245
- func: APIFunctionSessionless<void, Out, ChannelData>
245
+ func: PikkuFunctionSessionless<void, Out, ChannelData>
246
246
  name?: string
247
247
  }
248
248
  ) => {
@@ -269,9 +269,9 @@ export const pikkuChannelConnectionFunc = <Out = unknown, ChannelData = unknown>
269
269
  */
270
270
  export const pikkuChannelDisconnectionFunc = <ChannelData = unknown>(
271
271
  func:
272
- | APIFunctionSessionless<void, void, ChannelData>
272
+ | PikkuFunctionSessionless<void, void, ChannelData>
273
273
  | {
274
- func: APIFunction<void, void, ChannelData>
274
+ func: PikkuFunction<void, void, ChannelData>
275
275
  name?: string
276
276
  }
277
277
  ) => {
@@ -299,9 +299,9 @@ export const pikkuChannelDisconnectionFunc = <ChannelData = unknown>(
299
299
  */
300
300
  export const pikkuChannelFunc = <In = unknown, Out = unknown, ChannelData = unknown>(
301
301
  func:
302
- | APIFunctionSessionless<In, Out, ChannelData>
302
+ | PikkuFunctionSessionless<In, Out, ChannelData>
303
303
  | {
304
- func: APIFunctionSessionless<In, Out, ChannelData>
304
+ func: PikkuFunctionSessionless<In, Out, ChannelData>
305
305
  name?: string
306
306
  }
307
307
  ) => {
@@ -326,9 +326,9 @@ export const pikkuChannelFunc = <In = unknown, Out = unknown, ChannelData = unkn
326
326
  */
327
327
  export const pikkuVoidFunc = (
328
328
  func:
329
- | APIFunctionSessionless<void, void>
329
+ | PikkuFunctionSessionless<void, void>
330
330
  | {
331
- func: APIFunctionSessionless<void, void>
331
+ func: PikkuFunctionSessionless<void, void>
332
332
  name?: string
333
333
  }
334
334
  ) => {
@@ -342,24 +342,24 @@ export const pikkuVoidFunc = (
342
342
  * @template Channel - String literal type for the channel name
343
343
  * @param channel - Channel definition with connection, disconnection, and message handlers
344
344
  */
345
- export const addChannel = <ChannelData, Channel extends string>(
346
- channel: APIChannel<ChannelData, Channel> & AssertRouteParams<ChannelData, Channel>
345
+ export const wireChannel = <ChannelData, Channel extends string>(
346
+ channel: ChannelWiring<ChannelData, Channel> & AssertHTTPWiringParams<ChannelData, Channel>
347
347
  ) => {
348
- addCoreChannel(channel as any) // TODO
348
+ wireChannelCore(channel as any) // TODO
349
349
  }
350
350
 
351
351
  /**
352
- * Registers an HTTP route with the Pikku framework.
352
+ * Registers an HTTP wiring with the Pikku framework.
353
353
  *
354
- * @template In - Input type for the route
355
- * @template Out - Output type for the route
356
- * @template Route - String literal type for the route path (e.g., "/users/:id")
357
- * @param route - Route definition with handler, method, and optional middleware
354
+ * @template In - Input type for the HTTP wiring
355
+ * @template Out - Output type for the HTTP wiring
356
+ * @template Route - String literal type for the HTTP path (e.g., "/users/:id")
357
+ * @param httpWiring - HTTP wiring definition with handler, method, and optional middleware
358
358
  */
359
- export const addHTTPRoute = <In, Out, Route extends string>(
360
- route: APIRoute<In, Out, Route> & AssertRouteParams<In, Route>
359
+ export const wireHTTP = <In, Out, Route extends string>(
360
+ httpWiring: HTTPWiring<In, Out, Route> & AssertHTTPWiringParams<In, Route>
361
361
  ) => {
362
- addCoreHTTPRoute(route)
362
+ wireHTTPCore(httpWiring)
363
363
  }
364
364
 
365
365
  /**
@@ -368,8 +368,8 @@ export const addHTTPRoute = <In, Out, Route extends string>(
368
368
  *
369
369
  * @param task - Scheduled task definition with cron expression and handler
370
370
  */
371
- export const addScheduledTask = (task: ScheduledTask) => {
372
- addCoreScheduledTask(task as any) // TODO
371
+ export const wireScheduler = (task: SchedulerWiring) => {
372
+ wireSchedulerCore(task as any) // TODO
373
373
  }
374
374
 
375
375
  /**
@@ -378,8 +378,8 @@ export const addScheduledTask = (task: ScheduledTask) => {
378
378
  *
379
379
  * @param queueWorker - Queue worker definition with job handler
380
380
  */
381
- export const addQueueWorker = (queueWorker: QueueWorker<any, any>) => {
382
- addCoreQueueWorker(queueWorker as any) // TODO
381
+ export const wireQueueWorker = (queueWorker: QueueWiring<any, any>) => {
382
+ wireQueueWorkerCore(queueWorker as any) // TODO
383
383
  }
384
384
 
385
385
  /**
@@ -389,10 +389,10 @@ export const addQueueWorker = (queueWorker: QueueWorker<any, any>) => {
389
389
  * @template In - Input type for the resource request
390
390
  * @param mcpResource - MCP resource definition with data provider function
391
391
  */
392
- export const addMCPResource = <In>(
393
- mcpResource: MCPResource<In>
392
+ export const wireMCPResource = <In>(
393
+ mcpResource: MCPResourceWiring<In>
394
394
  ) => {
395
- addCoreMCPResource(mcpResource as any)
395
+ wireMCPResourceCore(mcpResource as any)
396
396
  }
397
397
 
398
398
  /**
@@ -402,10 +402,10 @@ export const addMCPResource = <In>(
402
402
  * @template In - Input type for the tool invocation
403
403
  * @param mcpTool - MCP tool definition with action function
404
404
  */
405
- export const addMCPTool = <In>(
406
- mcpTool: MCPTool<In>
405
+ export const wireMCPTool = <In>(
406
+ mcpTool: MCPToolWiring<In>
407
407
  ) => {
408
- addCoreMCPTool(mcpTool as any)
408
+ wireMCPToolCore(mcpTool as any)
409
409
  }
410
410
 
411
411
  /**
@@ -415,10 +415,10 @@ export const addMCPTool = <In>(
415
415
  * @template In - Input type for the prompt parameters
416
416
  * @param mcpPrompt - MCP prompt definition with template function
417
417
  */
418
- export const addMCPPrompt = <In>(
419
- mcpPrompt: MCPPrompt<In>
418
+ export const wireMCPPrompt = <In>(
419
+ mcpPrompt: MCPPromptWiring<In>
420
420
  ) => {
421
- addCoreMCPPrompt(mcpPrompt as any)
421
+ wireMCPPromptCore(mcpPrompt as any)
422
422
  }
423
423
 
424
424
  /**
@@ -446,9 +446,9 @@ export const addMCPPrompt = <In>(
446
446
  */
447
447
  export const pikkuMCPPromptFunc = <In>(
448
448
  func:
449
- | APIFunctionSessionless<In, MCPPromptResponse>
449
+ | PikkuFunctionSessionless<In, MCPPromptResponse>
450
450
  | {
451
- func: APIFunctionSessionless<In, MCPPromptResponse>
451
+ func: PikkuFunctionSessionless<In, MCPPromptResponse>
452
452
  name?: string
453
453
  }
454
454
  ) => {
@@ -478,9 +478,9 @@ export const pikkuMCPPromptFunc = <In>(
478
478
  */
479
479
  export const pikkuMCPToolFunc = <In>(
480
480
  func:
481
- | APIFunctionSessionless<In, MCPToolResponse, null, true>
481
+ | PikkuFunctionSessionless<In, MCPToolResponse, null, true>
482
482
  | {
483
- func: APIFunctionSessionless<In, MCPToolResponse, null, true>
483
+ func: PikkuFunctionSessionless<In, MCPToolResponse, null, true>
484
484
  name?: string
485
485
  }
486
486
  ) => {
@@ -511,9 +511,9 @@ export const pikkuMCPToolFunc = <In>(
511
511
  */
512
512
  export const pikkuMCPResourceFunc = <In>(
513
513
  func:
514
- | APIFunctionSessionless<In, MCPResourceResponse, null, true>
514
+ | PikkuFunctionSessionless<In, MCPResourceResponse, null, true>
515
515
  | {
516
- func: APIFunctionSessionless<In, MCPResourceResponse, null, true>
516
+ func: PikkuFunctionSessionless<In, MCPResourceResponse, null, true>
517
517
  name?: string
518
518
  }
519
519
  ) => {
package/src/utils.test.ts CHANGED
@@ -134,4 +134,42 @@ describe('getFileImportRelativePath', () => {
134
134
 
135
135
  assert.strictEqual(result, './file2.tsx'.replace('.ts', '.js'))
136
136
  })
137
+
138
+ test('should strip everything before and including node_modules/', () => {
139
+ const from =
140
+ '/project/packages/functions/.pikku/http/pikku-http-routes-map.gen.d.ts'
141
+ const to =
142
+ '/project/packages/functions/../../../../node_modules/@pikku/core/dist/types/core.types.d.ts'
143
+ const packageMappings = {}
144
+
145
+ const result = getFileImportRelativePath(from, to, packageMappings)
146
+
147
+ assert.strictEqual(result, '@pikku/core/dist/types/core.types.d.js')
148
+ })
149
+
150
+ test('should handle node_modules path with package mappings', () => {
151
+ const from = '/project/packages/app/src/file1.ts'
152
+ const to = '/project/packages/app/node_modules/@myorg/utils/dist/utils.d.ts'
153
+ const packageMappings = {
154
+ 'packages/app': '@myorg/app',
155
+ }
156
+
157
+ const result = getFileImportRelativePath(from, to, packageMappings)
158
+
159
+ assert.strictEqual(result, '@myorg/utils/dist/utils.d.js')
160
+ })
161
+
162
+ test('should handle deeply nested node_modules paths', () => {
163
+ const from =
164
+ '/Users/user/project/workspace-starter/packages/functions/.pikku/http/pikku-http-routes-map.gen.d.ts'
165
+ const to =
166
+ '/Users/user/project/workspace-starter/packages/functions/../../../../node_modules/@pikku/core/dist/types/core.types.d.ts'
167
+ const packageMappings = {
168
+ 'packages/functions': '@workspace/functions',
169
+ }
170
+
171
+ const result = getFileImportRelativePath(from, to, packageMappings)
172
+
173
+ assert.strictEqual(result, '@pikku/core/dist/types/core.types.d.js')
174
+ })
137
175
  })
package/src/utils.ts CHANGED
@@ -63,6 +63,15 @@ export const getFileImportRelativePath = (
63
63
  filePath = `./${filePath}`
64
64
  }
65
65
 
66
+ // If the path includes node_modules, strip everything before and including node_modules/
67
+ if (filePath.includes('node_modules')) {
68
+ const nodeModulesIndex = filePath.indexOf('node_modules/')
69
+ if (nodeModulesIndex !== -1) {
70
+ filePath = filePath.substring(nodeModulesIndex + 'node_modules/'.length)
71
+ }
72
+ return filePath.replace('.ts', '.js')
73
+ }
74
+
66
75
  const absolutePath = resolve(dirname(from), to)
67
76
  const fromAbsolutePath = resolve(dirname(from))
68
77
 
@@ -18,21 +18,22 @@ export const pikkuChannels: PikkuCommand = async (
18
18
  'Found channels',
19
19
  [visitState.channels.files.size === 0],
20
20
  async () => {
21
- const { channelsFile, channelsMetaFile, packageMappings } = cliConfig
21
+ const { channelsWiringFile, channelsWiringMetaFile, packageMappings } =
22
+ cliConfig
22
23
  const { channels } = visitState
23
24
  await writeFileInDir(
24
25
  logger,
25
- channelsFile,
26
+ channelsWiringFile,
26
27
  serializeFileImports(
27
28
  'addChannel',
28
- channelsFile,
29
+ channelsWiringFile,
29
30
  channels.files,
30
31
  packageMappings
31
32
  )
32
33
  )
33
34
  await writeFileInDir(
34
35
  logger,
35
- channelsMetaFile,
36
+ channelsWiringMetaFile,
36
37
  `import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`
37
38
  )
38
39
  }
@@ -16,21 +16,22 @@ export const pikkuChannels: PikkuCommand = async (
16
16
  'Found channels',
17
17
  [visitState.channels.files.size === 0],
18
18
  async () => {
19
- const { channelsFile, channelsMetaFile, packageMappings } = cliConfig
19
+ const { channelsWiringFile, channelsWiringMetaFile, packageMappings } =
20
+ cliConfig
20
21
  const { channels } = visitState
21
22
  await writeFileInDir(
22
23
  logger,
23
- channelsFile,
24
+ channelsWiringFile,
24
25
  serializeFileImports(
25
26
  'addChannel',
26
- channelsFile,
27
+ channelsWiringFile,
27
28
  channels.files,
28
29
  packageMappings
29
30
  )
30
31
  )
31
32
  await writeFileInDir(
32
33
  logger,
33
- channelsMetaFile,
34
+ channelsWiringMetaFile,
34
35
  `import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`
35
36
  )
36
37
  }
@@ -46,7 +46,7 @@ export type ChannelDefaultHandlerOf<Channel extends keyof ChannelsMap> =
46
46
  ? ChannelHandler<I, O>
47
47
  : never;
48
48
 
49
- export type ChannelRouteHandlerOf<
49
+ export type ChannelWiringHandlerOf<
50
50
  Channel extends keyof ChannelsMap,
51
51
  Route extends keyof ChannelsMap[Channel]['routes'],
52
52
  Method extends keyof ChannelsMap[Channel]['routes'][Route],
@@ -80,7 +80,7 @@ function generateChannels(
80
80
  > = {}
81
81
 
82
82
  for (const meta of Object.values(channelsMeta)) {
83
- const { name, messageRoutes, message } = meta
83
+ const { name, messageWirings, message } = meta
84
84
 
85
85
  if (!channelsObject[name]) {
86
86
  channelsObject[name] = { message: null, routes: {} }
@@ -103,7 +103,7 @@ function generateChannels(
103
103
  outputTypes?.forEach((type) => requiredTypes.add(type))
104
104
  }
105
105
 
106
- for (const [key, route] of Object.entries(messageRoutes)) {
106
+ for (const [key, route] of Object.entries(messageWirings)) {
107
107
  if (!channelsObject[name].routes[key]) {
108
108
  channelsObject[name].routes[key] = {}
109
109
  }
@@ -1,11 +1,11 @@
1
1
  export const serializeWebsocketWrapper = (channelsMapPath: string) => {
2
2
  return `import { CorePikkuWebsocket, CorePikkuRouteHandler } from '@pikku/websocket'
3
- import { ChannelDefaultHandlerOf, ChannelRouteHandlerOf, ChannelsMap } from '${channelsMapPath}';
3
+ import { ChannelDefaultHandlerOf, ChannelWiringHandlerOf, ChannelsMap } from '${channelsMapPath}';
4
4
 
5
5
  class PikkuWebSocketRoute<Channel extends keyof ChannelsMap, Route extends keyof ChannelsMap[Channel]['routes']> extends CorePikkuRouteHandler {
6
6
  public subscribe<
7
7
  Method extends keyof ChannelsMap[Channel]['routes'][Route],
8
- Data extends ChannelRouteHandlerOf<Channel, Route, Method>['output']
8
+ Data extends ChannelWiringHandlerOf<Channel, Route, Method>['output']
9
9
  >(method: Method, callback: (data: Data) => void
10
10
  ) {
11
11
  super.subscribe(method.toString(), callback)
@@ -13,20 +13,20 @@ class PikkuWebSocketRoute<Channel extends keyof ChannelsMap, Route extends keyof
13
13
 
14
14
  public unsubscribe<
15
15
  Method extends keyof ChannelsMap[Channel]['routes'][Route],
16
- Data extends ChannelRouteHandlerOf<Channel, Route, Method>['output']
16
+ Data extends ChannelWiringHandlerOf<Channel, Route, Method>['output']
17
17
  >(method: Method, callback?: (data: Data) => void) {
18
18
  super.unsubscribe(method.toString(), callback)
19
19
  }
20
20
 
21
21
  public send<
22
22
  Method extends keyof ChannelsMap[Channel]['routes'][Route],
23
- Data extends ChannelRouteHandlerOf<Channel, Route, Method>['input']
23
+ Data extends ChannelWiringHandlerOf<Channel, Route, Method>['input']
24
24
  >(method: Method, data: Data) {
25
25
  super.send(method.toString(), data)
26
26
  }
27
27
  }
28
28
 
29
- export class PikkuWebSocket<Channel extends keyof ChannelsMap> extends CorePikkuWebsocket {
29
+ export class PikkuWebSocket<Channel extends keyof ChannelsMap, EventHubTopics extends Record<string, any> = {}> extends CorePikkuWebsocket {
30
30
  /**
31
31
  * Send a message to a specific route and method.
32
32
  * Validates the input data type.
@@ -56,6 +56,20 @@ export class PikkuWebSocket<Channel extends keyof ChannelsMap> extends CorePikku
56
56
  public send(data: ChannelDefaultHandlerOf<Channel>['input']) {
57
57
  super.send(data)
58
58
  }
59
+
60
+ /**
61
+ * Subscribe to a topic from the EventHub system with strong typing.
62
+ */
63
+ public subscribeToEventHub<Topic extends keyof EventHubTopics>(
64
+ topic: Topic,
65
+ callback: (data: EventHubTopics[Topic]) => void
66
+ ) {
67
+ super.subscribe((data) => {
68
+ if (data.topic === topic) {
69
+ callback(data as EventHubTopics[Topic])
70
+ }
71
+ })
72
+ }
59
73
  }
60
74
  `
61
75
  }
@@ -8,7 +8,7 @@ import { PikkuCommandWithoutState } from '../../types.js'
8
8
 
9
9
  export const pikkuFetch: PikkuCommandWithoutState = async (
10
10
  logger,
11
- { fetchFile, httpRoutesMapDeclarationFile, packageMappings }
11
+ { fetchFile, httpMapDeclarationFile, packageMappings }
12
12
  ) => {
13
13
  return await logCommandInfoAndTime(
14
14
  logger,
@@ -22,7 +22,7 @@ export const pikkuFetch: PikkuCommandWithoutState = async (
22
22
 
23
23
  const routesMapDeclarationPath = getFileImportRelativePath(
24
24
  fetchFile,
25
- httpRoutesMapDeclarationFile,
25
+ httpMapDeclarationFile,
26
26
  packageMappings
27
27
  )
28
28
 
@@ -1,4 +1,4 @@
1
- import { FunctionsMeta, HTTPRoutesMeta, pikkuState } from '@pikku/core'
1
+ import { FunctionsMeta, HTTPWiringsMeta, pikkuState } from '@pikku/core'
2
2
  import _convertSchema from '@openapi-contrib/json-schema-to-openapi-schema'
3
3
  const convertSchema =
4
4
  'default' in _convertSchema ? (_convertSchema.default as any) : _convertSchema
@@ -76,7 +76,7 @@ const getErrorResponseForConstructorName = (constructorName: string) => {
76
76
 
77
77
  const convertSchemasToBodyPayloads = async (
78
78
  functionsMeta: FunctionsMeta,
79
- routesMeta: HTTPRoutesMeta,
79
+ routesMeta: HTTPWiringsMeta,
80
80
  schemas: Record<string, any>
81
81
  ) => {
82
82
  const requiredSchemas = new Set(
@@ -105,7 +105,7 @@ const convertSchemasToBodyPayloads = async (
105
105
 
106
106
  export async function generateOpenAPISpec(
107
107
  functionsMeta: FunctionsMeta,
108
- routeMeta: HTTPRoutesMeta,
108
+ routeMeta: HTTPWiringsMeta,
109
109
  schemas: Record<string, any>,
110
110
  additionalInfo: OpenAPISpecInfo
111
111
  ): Promise<OpenAPISpec> {
@@ -1,10 +1,10 @@
1
1
  import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js'
2
- import { serializeTypedRoutesMap } from './serialize-typed-http-map.js'
2
+ import { serializeTypedHTTPWiringsMap } from './serialize-typed-http-map.js'
3
3
  import { PikkuCommand } from '../../types.js'
4
4
 
5
5
  export const pikkuHTTPMap: PikkuCommand = async (
6
6
  logger,
7
- { httpRoutesMapDeclarationFile, packageMappings },
7
+ { httpMapDeclarationFile, packageMappings },
8
8
  { http, functions }
9
9
  ) => {
10
10
  return await logCommandInfoAndTime(
@@ -13,15 +13,15 @@ export const pikkuHTTPMap: PikkuCommand = async (
13
13
  'Created HTTP map',
14
14
  [http.files.size === 0],
15
15
  async () => {
16
- const content = serializeTypedRoutesMap(
17
- httpRoutesMapDeclarationFile,
16
+ const content = serializeTypedHTTPWiringsMap(
17
+ httpMapDeclarationFile,
18
18
  packageMappings,
19
19
  functions.typesMap,
20
20
  functions.meta,
21
21
  http.meta,
22
22
  http.metaInputTypes
23
23
  )
24
- await writeFileInDir(logger, httpRoutesMapDeclarationFile, content)
24
+ await writeFileInDir(logger, httpMapDeclarationFile, content)
25
25
  }
26
26
  )
27
27
  }
@@ -18,21 +18,21 @@ export const pikkuHTTP: PikkuCommand = async (
18
18
  'Found HTTP routes',
19
19
  [visitState.http.files.size === 0],
20
20
  async () => {
21
- const { httpRoutesFile, httpRoutesMetaFile, packageMappings } = cliConfig
21
+ const { httpWiringsFile, httpWiringMetaFile, packageMappings } = cliConfig
22
22
  const { http } = visitState
23
23
  await writeFileInDir(
24
24
  logger,
25
- httpRoutesFile,
25
+ httpWiringsFile,
26
26
  serializeFileImports(
27
- 'addHTTPRoute',
28
- httpRoutesFile,
27
+ 'wireHTTP',
28
+ httpWiringsFile,
29
29
  http.files,
30
30
  packageMappings
31
31
  )
32
32
  )
33
33
  await writeFileInDir(
34
34
  logger,
35
- httpRoutesMetaFile,
35
+ httpWiringMetaFile,
36
36
  `import { pikkuState } from '@pikku/core'\npikkuState('http', 'meta', ${JSON.stringify(http.meta, null, 2)})`
37
37
  )
38
38
  }