@pikku/cli 0.11.2 → 0.11.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 (301) hide show
  1. package/.pikku/channel/pikku-channel-types.gen.ts +63 -6
  2. package/.pikku/channel/pikku-channels-map.gen.d.ts +4 -4
  3. package/.pikku/channel/pikku-channels-meta.gen.ts +4 -2
  4. package/.pikku/channel/pikku-channels.gen.ts +1 -1
  5. package/.pikku/cli/pikku-cli-channel.ts +1 -1
  6. package/.pikku/cli/pikku-cli-client.gen.ts +1 -1
  7. package/.pikku/cli/pikku-cli-types.gen.ts +1 -1
  8. package/.pikku/cli/pikku-cli-wirings-meta.gen.json +2 -1
  9. package/.pikku/cli/pikku-cli-wirings-meta.gen.ts +2 -2
  10. package/.pikku/cli/pikku-cli-wirings.gen.ts +1 -1
  11. package/.pikku/cli/pikku-cli.gen.ts +1 -1
  12. package/.pikku/forge/pikku-forge-types.gen.ts +83 -0
  13. package/.pikku/function/pikku-function-types.gen.ts +181 -35
  14. package/.pikku/function/pikku-functions-meta-verbose.gen.json +1030 -0
  15. package/.pikku/function/pikku-functions-meta.gen.json +88 -420
  16. package/.pikku/function/pikku-functions-meta.gen.ts +2 -2
  17. package/.pikku/http/pikku-http-types.gen.ts +19 -3
  18. package/.pikku/http/pikku-http-wirings-map.gen.d.ts +4 -4
  19. package/.pikku/http/pikku-http-wirings-meta.gen.json +9 -0
  20. package/.pikku/http/pikku-http-wirings-meta.gen.ts +4 -10
  21. package/.pikku/http/pikku-http-wirings.gen.ts +1 -1
  22. package/.pikku/mcp/pikku-mcp-types.gen.ts +69 -17
  23. package/.pikku/mcp/pikku-mcp-wirings-meta.gen.ts +4 -4
  24. package/.pikku/mcp/pikku-mcp-wirings.gen.ts +1 -1
  25. package/.pikku/pikku-bootstrap.gen.ts +7 -9
  26. package/.pikku/pikku-services.gen.ts +3 -2
  27. package/.pikku/pikku-types.gen.ts +4 -1
  28. package/.pikku/pikku-websocket.gen.ts +1 -1
  29. package/.pikku/queue/pikku-queue-types.gen.ts +1 -1
  30. package/.pikku/queue/pikku-queue-workers-wirings-map.gen.d.ts +4 -4
  31. package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.ts +2 -2
  32. package/.pikku/queue/pikku-queue-workers-wirings.gen.ts +1 -1
  33. package/.pikku/rpc/pikku-remote-rpc-workers.gen.ts +4 -1
  34. package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +12 -7
  35. package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +15 -9
  36. package/.pikku/scheduler/pikku-scheduler-types.gen.ts +1 -1
  37. package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.ts +2 -2
  38. package/.pikku/scheduler/pikku-schedulers-wirings.gen.ts +1 -1
  39. package/.pikku/schemas/register.gen.ts +9 -1
  40. package/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  41. package/.pikku/schemas/schemas/PikkuCLIOutput.schema.json +1 -1
  42. package/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
  43. package/.pikku/schemas/schemas/PikkuForgeNodesOutput.schema.json +1 -0
  44. package/.pikku/schemas/schemas/PikkuFunctionsOutput.schema.json +1 -1
  45. package/.pikku/schemas/schemas/PikkuHTTPOutput.schema.json +1 -1
  46. package/.pikku/schemas/schemas/PikkuMCPOutput.schema.json +1 -1
  47. package/.pikku/schemas/schemas/PikkuMiddlewareOutput.schema.json +1 -1
  48. package/.pikku/schemas/schemas/PikkuPackageOutput.schema.json +1 -0
  49. package/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -1
  50. package/.pikku/schemas/schemas/PikkuPublicRPCOutput.schema.json +1 -1
  51. package/.pikku/schemas/schemas/PikkuQueueOutput.schema.json +1 -1
  52. package/.pikku/schemas/schemas/PikkuRPCOutput.schema.json +1 -1
  53. package/.pikku/schemas/schemas/PikkuRemoteRPCOutput.schema.json +1 -1
  54. package/.pikku/schemas/schemas/PikkuSchedulerOutput.schema.json +1 -1
  55. package/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
  56. package/.pikku/schemas/schemas/PikkuWorkflowOutput.schema.json +1 -1
  57. package/.pikku/services/config.gen.json +11 -6
  58. package/.pikku/services/getInspectorState.gen.json +2 -2
  59. package/.pikku/services/jwt.gen.json +2 -2
  60. package/.pikku/services/logger.gen.json +2 -2
  61. package/.pikku/services/queueService.gen.json +2 -2
  62. package/.pikku/services/schedulerService.gen.json +2 -2
  63. package/.pikku/services/schema.gen.json +2 -2
  64. package/.pikku/services/secrets.gen.json +13 -0
  65. package/.pikku/services/variables.gen.json +2 -2
  66. package/.pikku/services/workflowService.gen.json +6 -6
  67. package/.pikku/workflow/pikku-workflow-map.gen.d.ts +2 -36
  68. package/.pikku/workflow/pikku-workflow-types.gen.ts +297 -45
  69. package/.pikku/workflow/pikku-workflow-wirings-meta.gen.ts +5 -4
  70. package/.pikku/workflow/pikku-workflow-wirings.gen.ts +1 -6
  71. package/CHANGELOG.md +23 -1
  72. package/cli.schema.json +1 -1
  73. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +47 -5
  74. package/dist/.pikku/channel/pikku-channel-types.gen.js +3 -13
  75. package/dist/.pikku/channel/pikku-channels-meta.gen.js +3 -2
  76. package/dist/.pikku/channel/pikku-channels.gen.d.ts +1 -1
  77. package/dist/.pikku/channel/pikku-channels.gen.js +1 -1
  78. package/dist/.pikku/cli/pikku-cli-channel.js +1 -1
  79. package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
  80. package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
  81. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
  82. package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
  83. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +2 -2
  84. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +2 -1
  85. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
  86. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
  87. package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
  88. package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
  89. package/dist/.pikku/forge/pikku-forge-types.gen.d.ts +72 -0
  90. package/dist/.pikku/forge/pikku-forge-types.gen.js +55 -0
  91. package/dist/.pikku/function/pikku-function-types.gen.d.ts +123 -31
  92. package/dist/.pikku/function/pikku-function-types.gen.js +37 -51
  93. package/dist/.pikku/function/pikku-functions-meta.gen.js +2 -2
  94. package/dist/.pikku/function/pikku-functions-meta.gen.json +88 -420
  95. package/dist/.pikku/http/pikku-http-types.gen.d.ts +18 -3
  96. package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
  97. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +3 -10
  98. package/dist/.pikku/http/pikku-http-wirings-meta.gen.json +9 -0
  99. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
  100. package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
  101. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +54 -14
  102. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +7 -31
  103. package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +4 -4
  104. package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +1 -1
  105. package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +1 -1
  106. package/dist/.pikku/pikku-bootstrap.gen.d.ts +7 -9
  107. package/dist/.pikku/pikku-bootstrap.gen.js +7 -9
  108. package/dist/.pikku/pikku-services.gen.d.ts +3 -2
  109. package/dist/.pikku/pikku-services.gen.js +1 -0
  110. package/dist/.pikku/pikku-types.gen.d.ts +2 -1
  111. package/dist/.pikku/pikku-types.gen.js +3 -1
  112. package/dist/.pikku/pikku-websocket.gen.d.ts +1 -1
  113. package/dist/.pikku/pikku-websocket.gen.js +1 -1
  114. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
  115. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
  116. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +2 -2
  117. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
  118. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
  119. package/dist/.pikku/rpc/pikku-remote-rpc-workers.gen.d.ts +4 -1
  120. package/dist/.pikku/rpc/pikku-remote-rpc-workers.gen.js +4 -1
  121. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
  122. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
  123. package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +2 -2
  124. package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +1 -1
  125. package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +1 -1
  126. package/dist/.pikku/schemas/register.gen.js +5 -1
  127. package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  128. package/dist/.pikku/schemas/schemas/PikkuCLIOutput.schema.json +1 -1
  129. package/dist/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
  130. package/dist/.pikku/schemas/schemas/PikkuForgeNodesOutput.schema.json +1 -0
  131. package/dist/.pikku/schemas/schemas/PikkuFunctionsOutput.schema.json +1 -1
  132. package/dist/.pikku/schemas/schemas/PikkuHTTPOutput.schema.json +1 -1
  133. package/dist/.pikku/schemas/schemas/PikkuMCPOutput.schema.json +1 -1
  134. package/dist/.pikku/schemas/schemas/PikkuMiddlewareOutput.schema.json +1 -1
  135. package/dist/.pikku/schemas/schemas/PikkuPackageOutput.schema.json +1 -0
  136. package/dist/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -1
  137. package/dist/.pikku/schemas/schemas/PikkuPublicRPCOutput.schema.json +1 -1
  138. package/dist/.pikku/schemas/schemas/PikkuQueueOutput.schema.json +1 -1
  139. package/dist/.pikku/schemas/schemas/PikkuRPCOutput.schema.json +1 -1
  140. package/dist/.pikku/schemas/schemas/PikkuRemoteRPCOutput.schema.json +1 -1
  141. package/dist/.pikku/schemas/schemas/PikkuSchedulerOutput.schema.json +1 -1
  142. package/dist/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
  143. package/dist/.pikku/schemas/schemas/PikkuWorkflowOutput.schema.json +1 -1
  144. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +207 -37
  145. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +104 -28
  146. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +3 -3
  147. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.d.ts +2 -6
  148. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +2 -6
  149. package/dist/src/functions/commands/all.js +117 -79
  150. package/dist/src/functions/commands/bootstrap.js +2 -9
  151. package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +0 -1
  152. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +49 -35
  153. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.js +49 -35
  154. package/dist/src/functions/wirings/channels/pikku-channels.js +1 -1
  155. package/dist/src/functions/wirings/channels/pikku-command-channels.js +18 -2
  156. package/dist/src/functions/wirings/channels/serialize-channel-types.js +62 -5
  157. package/dist/src/functions/wirings/channels/serialize-typed-channel-map.js +1 -2
  158. package/dist/src/functions/wirings/cli/pikku-command-cli.js +10 -2
  159. package/dist/src/functions/wirings/forge/pikku-command-forge-nodes.d.ts +1 -0
  160. package/dist/src/functions/wirings/forge/pikku-command-forge-nodes.js +90 -0
  161. package/dist/src/functions/wirings/forge/pikku-command-forge-types.d.ts +1 -0
  162. package/dist/src/functions/wirings/forge/pikku-command-forge-types.js +26 -0
  163. package/dist/src/functions/wirings/forge/serialize-forge-types.d.ts +4 -0
  164. package/dist/src/functions/wirings/forge/serialize-forge-types.js +90 -0
  165. package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +1 -1
  166. package/dist/src/functions/wirings/functions/pikku-command-function-types.js +7 -2
  167. package/dist/src/functions/wirings/functions/pikku-command-functions.js +33 -18
  168. package/dist/src/functions/wirings/functions/pikku-command-services.js +1 -1
  169. package/dist/src/functions/wirings/functions/pikku-function-types.js +2 -2
  170. package/dist/src/functions/wirings/functions/schemas.d.ts +1 -1
  171. package/dist/src/functions/wirings/functions/schemas.js +5 -4
  172. package/dist/src/functions/wirings/functions/serialize-function-imports.d.ts +3 -1
  173. package/dist/src/functions/wirings/functions/serialize-function-imports.js +7 -3
  174. package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
  175. package/dist/src/functions/wirings/functions/serialize-function-types.js +181 -34
  176. package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.d.ts +1 -1
  177. package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +19 -21
  178. package/dist/src/functions/wirings/http/openapi-spec-generator.js +1 -1
  179. package/dist/src/functions/wirings/http/pikku-command-http-routes.js +18 -2
  180. package/dist/src/functions/wirings/http/pikku-command-openapi.js +2 -2
  181. package/dist/src/functions/wirings/http/pikku-http-routes.js +1 -1
  182. package/dist/src/functions/wirings/http/serialize-http-types.js +18 -2
  183. package/dist/src/functions/wirings/http/serialize-typed-http-map.js +33 -8
  184. package/dist/src/functions/wirings/mcp/pikku-command-mcp.js +15 -6
  185. package/dist/src/functions/wirings/mcp/serialize-mcp-json.js +3 -2
  186. package/dist/src/functions/wirings/mcp/serialize-mcp-types.js +68 -16
  187. package/dist/src/functions/wirings/middleware/pikku-command-middleware.js +5 -2
  188. package/dist/src/functions/wirings/package/pikku-command-package.d.ts +1 -0
  189. package/dist/src/functions/wirings/package/pikku-command-package.js +58 -0
  190. package/dist/src/functions/wirings/package/serialize-package.d.ts +5 -0
  191. package/dist/src/functions/wirings/package/serialize-package.js +32 -0
  192. package/dist/src/functions/wirings/queue/pikku-command-queue.js +10 -2
  193. package/dist/src/functions/wirings/queue/pikku-queue.js +1 -9
  194. package/dist/src/functions/wirings/queue/serialize-queue-map.js +20 -3
  195. package/dist/src/functions/wirings/queue/serialize-queue-meta.js +1 -1
  196. package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +4 -4
  197. package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +1 -1
  198. package/dist/src/functions/wirings/rpc/serialize-remote-rpc.js +3 -0
  199. package/dist/src/functions/wirings/rpc/serialize-rpc-wrapper.js +1 -1
  200. package/dist/src/functions/wirings/rpc/serialize-typed-rpc-map.d.ts +1 -1
  201. package/dist/src/functions/wirings/rpc/serialize-typed-rpc-map.js +54 -8
  202. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.js +10 -1
  203. package/dist/src/functions/wirings/scheduler/serialize-scheduler-meta.js +1 -1
  204. package/dist/src/functions/wirings/workflow/pikku-command-workflow.js +56 -18
  205. package/dist/src/functions/wirings/workflow/serialize-workflow-map.d.ts +3 -0
  206. package/dist/src/functions/wirings/workflow/serialize-workflow-map.js +30 -32
  207. package/dist/src/functions/wirings/workflow/serialize-workflow-meta.d.ts +1 -3
  208. package/dist/src/functions/wirings/workflow/serialize-workflow-meta.js +43 -18
  209. package/dist/src/functions/wirings/workflow/serialize-workflow-registration.d.ts +7 -0
  210. package/dist/src/functions/wirings/workflow/serialize-workflow-registration.js +53 -0
  211. package/dist/src/functions/wirings/workflow/serialize-workflow-types.d.ts +3 -1
  212. package/dist/src/functions/wirings/workflow/serialize-workflow-types.js +299 -45
  213. package/dist/src/functions/wirings/workflow/serialize-workflow-workers.d.ts +1 -1
  214. package/dist/src/functions/wirings/workflow/serialize-workflow-workers.js +14 -27
  215. package/dist/src/services.js +4 -1
  216. package/dist/src/utils/command-summary.d.ts +2 -0
  217. package/dist/src/utils/command-summary.js +2 -0
  218. package/dist/src/utils/custom-types-generator.js +13 -15
  219. package/dist/src/utils/generate-bootstrap-file.js +1 -1
  220. package/dist/src/utils/pikku-cli-config.js +37 -9
  221. package/dist/src/utils/schema-generator.d.ts +4 -3
  222. package/dist/src/utils/schema-generator.js +135 -15
  223. package/dist/src/utils/strip-verbose-meta.d.ts +43 -0
  224. package/dist/src/utils/strip-verbose-meta.js +210 -0
  225. package/dist/tsconfig.tsbuildinfo +1 -1
  226. package/package.json +7 -4
  227. package/src/functions/commands/all.ts +144 -97
  228. package/src/functions/commands/bootstrap.ts +2 -10
  229. package/src/functions/runtimes/nextjs/pikku-command-nextjs.ts +0 -1
  230. package/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +49 -35
  231. package/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.ts +49 -35
  232. package/src/functions/wirings/channels/pikku-channels.ts +1 -1
  233. package/src/functions/wirings/channels/pikku-command-channels.ts +46 -3
  234. package/src/functions/wirings/channels/serialize-channel-types.ts +62 -5
  235. package/src/functions/wirings/channels/serialize-typed-channel-map.ts +3 -2
  236. package/src/functions/wirings/cli/pikku-command-cli.ts +21 -2
  237. package/src/functions/wirings/forge/pikku-command-forge-nodes.ts +135 -0
  238. package/src/functions/wirings/forge/pikku-command-forge-types.ts +38 -0
  239. package/src/functions/wirings/forge/serialize-forge-types.ts +94 -0
  240. package/src/functions/wirings/functions/pikku-command-function-types-split.ts +3 -2
  241. package/src/functions/wirings/functions/pikku-command-function-types.ts +17 -10
  242. package/src/functions/wirings/functions/pikku-command-functions.ts +47 -37
  243. package/src/functions/wirings/functions/pikku-command-services.ts +1 -1
  244. package/src/functions/wirings/functions/pikku-function-types.ts +3 -1
  245. package/src/functions/wirings/functions/schemas.ts +14 -4
  246. package/src/functions/wirings/functions/serialize-function-imports.ts +12 -3
  247. package/src/functions/wirings/functions/serialize-function-types.ts +182 -34
  248. package/src/functions/wirings/functions/serialize-pikku-types-hub.ts +27 -26
  249. package/src/functions/wirings/http/openapi-spec-generator.ts +1 -1
  250. package/src/functions/wirings/http/pikku-command-http-routes.ts +46 -2
  251. package/src/functions/wirings/http/pikku-command-openapi.ts +3 -2
  252. package/src/functions/wirings/http/pikku-http-routes.ts +1 -1
  253. package/src/functions/wirings/http/serialize-http-types.ts +18 -2
  254. package/src/functions/wirings/http/serialize-typed-http-map.ts +32 -8
  255. package/src/functions/wirings/mcp/pikku-command-mcp.ts +32 -10
  256. package/src/functions/wirings/mcp/serialize-mcp-json.ts +8 -6
  257. package/src/functions/wirings/mcp/serialize-mcp-types.ts +68 -16
  258. package/src/functions/wirings/middleware/pikku-command-middleware.ts +6 -2
  259. package/src/functions/wirings/package/pikku-command-package.ts +81 -0
  260. package/src/functions/wirings/package/serialize-package.ts +69 -0
  261. package/src/functions/wirings/queue/pikku-command-queue.ts +22 -2
  262. package/src/functions/wirings/queue/pikku-queue.ts +1 -10
  263. package/src/functions/wirings/queue/serialize-queue-map.ts +18 -3
  264. package/src/functions/wirings/queue/serialize-queue-meta.ts +1 -1
  265. package/src/functions/wirings/rpc/pikku-command-rpc-map.ts +7 -4
  266. package/src/functions/wirings/rpc/pikku-command-rpc.ts +1 -1
  267. package/src/functions/wirings/rpc/serialize-remote-rpc.ts +3 -0
  268. package/src/functions/wirings/rpc/serialize-rpc-wrapper.ts +1 -1
  269. package/src/functions/wirings/rpc/serialize-typed-rpc-map.ts +74 -8
  270. package/src/functions/wirings/scheduler/pikku-command-scheduler.ts +22 -1
  271. package/src/functions/wirings/scheduler/serialize-scheduler-meta.ts +1 -1
  272. package/src/functions/wirings/workflow/pikku-command-workflow.ts +104 -37
  273. package/src/functions/wirings/workflow/serialize-workflow-map.ts +38 -40
  274. package/src/functions/wirings/workflow/serialize-workflow-meta.ts +66 -26
  275. package/src/functions/wirings/workflow/serialize-workflow-registration.ts +83 -0
  276. package/src/functions/wirings/workflow/serialize-workflow-types.ts +299 -45
  277. package/src/functions/wirings/workflow/serialize-workflow-workers.ts +14 -27
  278. package/src/services.ts +8 -1
  279. package/src/utils/command-summary.ts +4 -0
  280. package/src/utils/custom-types-generator.ts +15 -15
  281. package/src/utils/generate-bootstrap-file.ts +1 -1
  282. package/src/utils/pikku-cli-config.ts +51 -18
  283. package/src/utils/schema-generator.ts +185 -22
  284. package/src/utils/strip-verbose-meta.ts +254 -0
  285. package/types/config.d.ts +37 -3
  286. package/.pikku/function/pikku-functions-meta.min.gen.json +0 -212
  287. package/.pikku/function/pikku-functions-meta.min.gen.ts +0 -6
  288. package/dist/.pikku/function/pikku-functions-meta.min.gen.d.ts +0 -1
  289. package/dist/.pikku/function/pikku-functions-meta.min.gen.js +0 -6
  290. package/dist/.pikku/function/pikku-functions-meta.min.gen.json +0 -212
  291. package/dist/src/functions/wirings/workflow/pikku-command-workflow-map.d.ts +0 -1
  292. package/dist/src/functions/wirings/workflow/pikku-command-workflow-map.js +0 -12
  293. package/dist/src/functions/wirings/workflow/pikku-command-workflow-types.d.ts +0 -1
  294. package/dist/src/functions/wirings/workflow/pikku-command-workflow-types.js +0 -13
  295. package/dist/src/functions/wirings/workflow/serialize-workflow-wirings.d.ts +0 -8
  296. package/dist/src/functions/wirings/workflow/serialize-workflow-wirings.js +0 -30
  297. package/src/functions/wirings/workflow/pikku-command-workflow-map.ts +0 -24
  298. package/src/functions/wirings/workflow/pikku-command-workflow-types.ts +0 -29
  299. package/src/functions/wirings/workflow/serialize-workflow-wirings.ts +0 -47
  300. /package/.pikku/{workflow/pikku-workflow-wirings-meta.gen.json → channel/pikku-channels-meta.gen.json} +0 -0
  301. /package/dist/.pikku/{workflow/pikku-workflow-wirings-meta.gen.json → channel/pikku-channels-meta.gen.json} +0 -0
@@ -11,7 +11,7 @@ export const serializeNextJsHTTPWrapper = (
11
11
  */
12
12
  import { CorePikkuFetchOptions } from '@pikku/fetch'
13
13
  import type { HTTPWiringsMap, HTTPWiringHandlerOf, HTTPWiringsWithMethod } from '${routesMapPath}'
14
- import type { RPCMap } from '${rpcMapPath}'
14
+ import type { FlattenedRPCMap } from '${rpcMapPath}'
15
15
  import { PikkuFetch } from '${pikkuFetchImport}'
16
16
 
17
17
  let _pikku: PikkuFetch | undefined
@@ -64,14 +64,16 @@ export const pikku = (options?: CorePikkuFetchOptions) => {
64
64
  *
65
65
  * @template Route - The route key with the POST method.
66
66
  * @param route - The route identifier.
67
- * @param data - The input data for the POST request, defaults to null.
67
+ * @param data - The input data for the POST request (required if input type is defined).
68
68
  * @returns A promise that resolves to the output of the POST handler.
69
69
  */
70
70
  const dynamicPost = <Route extends HTTPWiringsWithMethod<'POST'>>(
71
71
  route: Route,
72
- data: HTTPWiringHandlerOf<Route, 'POST'>['input'] = null
72
+ ...args: HTTPWiringHandlerOf<Route, 'POST'>['input'] extends null | undefined
73
+ ? [data?: HTTPWiringHandlerOf<Route, 'POST'>['input']]
74
+ : [data: NonNullable<HTTPWiringHandlerOf<Route, 'POST'>['input']>]
73
75
  ): Promise<HTTPWiringHandlerOf<Route, 'POST'>['output']> => {
74
- return dynamicActionRequest(route, 'POST', data)
76
+ return dynamicActionRequest(route, 'POST', args[0] ?? null)
75
77
  }
76
78
 
77
79
  /**
@@ -79,14 +81,16 @@ export const pikku = (options?: CorePikkuFetchOptions) => {
79
81
  *
80
82
  * @template Route - The route key with the GET method.
81
83
  * @param route - The route identifier.
82
- * @param data - The input data for the GET request, defaults to null.
84
+ * @param data - The input data for the GET request (required if input type is defined).
83
85
  * @returns A promise that resolves to the output of the GET handler.
84
86
  */
85
87
  const dynamicGet = <Route extends HTTPWiringsWithMethod<'GET'>>(
86
88
  route: Route,
87
- data: HTTPWiringHandlerOf<Route, 'GET'>['input'] = null
89
+ ...args: HTTPWiringHandlerOf<Route, 'GET'>['input'] extends null | undefined
90
+ ? [data?: HTTPWiringHandlerOf<Route, 'GET'>['input']]
91
+ : [data: NonNullable<HTTPWiringHandlerOf<Route, 'GET'>['input']>]
88
92
  ): Promise<HTTPWiringHandlerOf<Route, 'GET'>['output']> => {
89
- return dynamicActionRequest(route, 'GET', data)
93
+ return dynamicActionRequest(route, 'GET', args[0] ?? null)
90
94
  }
91
95
 
92
96
  /**
@@ -94,14 +98,16 @@ export const pikku = (options?: CorePikkuFetchOptions) => {
94
98
  *
95
99
  * @template Route - The route key with the PATCH method.
96
100
  * @param route - The route identifier.
97
- * @param data - The input data for the PATCH request, defaults to null.
101
+ * @param data - The input data for the PATCH request (required if input type is defined).
98
102
  * @returns A promise that resolves to the output of the PATCH handler.
99
103
  */
100
104
  const dynamicPatch = <Route extends HTTPWiringsWithMethod<'PATCH'>>(
101
105
  route: Route,
102
- data: HTTPWiringHandlerOf<Route, 'PATCH'>['input'] = null
106
+ ...args: HTTPWiringHandlerOf<Route, 'PATCH'>['input'] extends null | undefined
107
+ ? [data?: HTTPWiringHandlerOf<Route, 'PATCH'>['input']]
108
+ : [data: NonNullable<HTTPWiringHandlerOf<Route, 'PATCH'>['input']>]
103
109
  ): Promise<HTTPWiringHandlerOf<Route, 'PATCH'>['output']> => {
104
- return dynamicActionRequest(route, 'PATCH', data)
110
+ return dynamicActionRequest(route, 'PATCH', args[0] ?? null)
105
111
  }
106
112
 
107
113
  /**
@@ -109,14 +115,16 @@ export const pikku = (options?: CorePikkuFetchOptions) => {
109
115
  *
110
116
  * @template Route - The route key with the DELETE method.
111
117
  * @param route - The route identifier.
112
- * @param data - The input data for the DELETE request, defaults to null.
118
+ * @param data - The input data for the DELETE request (required if input type is defined).
113
119
  * @returns A promise that resolves to the output of the DELETE handler.
114
120
  */
115
121
  const dynamicDel = <Route extends HTTPWiringsWithMethod<'DELETE'>>(
116
122
  route: Route,
117
- data: HTTPWiringHandlerOf<Route, 'DELETE'>['input'] = null
123
+ ...args: HTTPWiringHandlerOf<Route, 'DELETE'>['input'] extends null | undefined
124
+ ? [data?: HTTPWiringHandlerOf<Route, 'DELETE'>['input']]
125
+ : [data: NonNullable<HTTPWiringHandlerOf<Route, 'DELETE'>['input']>]
118
126
  ): Promise<HTTPWiringHandlerOf<Route, 'DELETE'>['output']> => {
119
- return dynamicActionRequest(route, 'DELETE', data)
127
+ return dynamicActionRequest(route, 'DELETE', args[0] ?? null)
120
128
  }
121
129
 
122
130
  // Static Requests
@@ -126,14 +134,16 @@ export const pikku = (options?: CorePikkuFetchOptions) => {
126
134
  *
127
135
  * @template Route - The route key with the POST method.
128
136
  * @param route - The route identifier.
129
- * @param data - The input data for the POST request, defaults to null.
137
+ * @param data - The input data for the POST request (required if input type is defined).
130
138
  * @returns A promise that resolves to the output of the POST handler.
131
139
  */
132
140
  const staticPost = <Route extends HTTPWiringsWithMethod<'POST'>>(
133
141
  route: Route,
134
- data: HTTPWiringHandlerOf<Route, 'POST'>['input'] = null
142
+ ...args: HTTPWiringHandlerOf<Route, 'POST'>['input'] extends null | undefined
143
+ ? [data?: HTTPWiringHandlerOf<Route, 'POST'>['input']]
144
+ : [data: NonNullable<HTTPWiringHandlerOf<Route, 'POST'>['input']>]
135
145
  ): Promise<HTTPWiringHandlerOf<Route, 'POST'>['output']> => {
136
- return staticActionRequest(route, 'POST', data)
146
+ return staticActionRequest(route, 'POST', args[0] ?? null)
137
147
  }
138
148
 
139
149
  /**
@@ -141,49 +151,53 @@ export const pikku = (options?: CorePikkuFetchOptions) => {
141
151
  *
142
152
  * @template Route - The route key with the GET method.
143
153
  * @param route - The route identifier.
144
- * @param data - The input data for the GET request, defaults to null.
154
+ * @param data - The input data for the GET request (required if input type is defined).
145
155
  * @returns A promise that resolves to the output of the GET handler.
146
156
  */
147
157
  const staticGet = <Route extends HTTPWiringsWithMethod<'GET'>>(
148
158
  route: Route,
149
- data: HTTPWiringHandlerOf<Route, 'GET'>['input'] = null
159
+ ...args: HTTPWiringHandlerOf<Route, 'GET'>['input'] extends null | undefined
160
+ ? [data?: HTTPWiringHandlerOf<Route, 'GET'>['input']]
161
+ : [data: NonNullable<HTTPWiringHandlerOf<Route, 'GET'>['input']>]
150
162
  ): Promise<HTTPWiringHandlerOf<Route, 'GET'>['output']> => {
151
- return staticActionRequest(route, 'GET', data)
163
+ return staticActionRequest(route, 'GET', args[0] ?? null)
152
164
  }
153
165
 
154
166
  // RPC Requests
155
167
 
156
- /**
157
- * Type definition for RPC invocation.
158
- */
159
- type RPCInvoke = <Name extends keyof RPCMap>(
160
- name: Name,
161
- data: RPCMap[Name]['input']
162
- ) => Promise<RPCMap[Name]['output']>
163
-
164
168
  /**
165
169
  * Makes a dynamic RPC request.
166
170
  *
167
- * @template Name - The RPC function name from the RPCMap.
171
+ * @template Name - The RPC function name from the FlattenedRPCMap.
168
172
  * @param name - The RPC function identifier.
169
- * @param data - The input data for the RPC request.
173
+ * @param data - The input data for the RPC request (required if input type is defined).
170
174
  * @returns A promise that resolves to the output of the RPC handler.
171
175
  */
172
- const rpc: RPCInvoke = async (rpcName, data) => {
173
- return dynamicActionRequest(\`/rpc/\${rpcName}\` as any, 'POST', { data }) as any
176
+ const rpc = async <Name extends keyof FlattenedRPCMap>(
177
+ rpcName: Name,
178
+ ...args: FlattenedRPCMap[Name]['input'] extends null | undefined
179
+ ? [data?: FlattenedRPCMap[Name]['input']]
180
+ : [data: NonNullable<FlattenedRPCMap[Name]['input']>]
181
+ ): Promise<FlattenedRPCMap[Name]['output']> => {
182
+ return dynamicActionRequest('/rpc/:rpcName' as '/rpc/:rpcName', 'POST', { rpcName, data: args[0] ?? null }) as unknown as FlattenedRPCMap[Name]['output']
174
183
  }
175
184
 
176
185
  /**
177
186
  * Makes a static RPC request.
178
187
  * Note: In HTTP wrapper context, both rpc and rpcStatic behave the same way.
179
188
  *
180
- * @template Name - The RPC function name from the RPCMap.
189
+ * @template Name - The RPC function name from the FlattenedRPCMap.
181
190
  * @param name - The RPC function identifier.
182
- * @param data - The input data for the RPC request.
191
+ * @param data - The input data for the RPC request (required if input type is defined).
183
192
  * @returns A promise that resolves to the output of the RPC handler.
184
193
  */
185
- const staticRPC: RPCInvoke = async (rpcName, data) => {
186
- return staticActionRequest(\`/rpc/\${rpcName}\` as any, 'POST', { data }) as any
194
+ const staticRPC = async <Name extends keyof FlattenedRPCMap>(
195
+ rpcName: Name,
196
+ ...args: FlattenedRPCMap[Name]['input'] extends null | undefined
197
+ ? [data?: FlattenedRPCMap[Name]['input']]
198
+ : [data: NonNullable<FlattenedRPCMap[Name]['input']>]
199
+ ): Promise<FlattenedRPCMap[Name]['output']> => {
200
+ return staticActionRequest('/rpc/:rpcName' as '/rpc/:rpcName', 'POST', { rpcName, data: args[0] ?? null }) as unknown as FlattenedRPCMap[Name]['output']
187
201
  }
188
202
 
189
203
  return {
@@ -47,7 +47,7 @@ export const pikkuChannels: any = pikkuVoidFunc({
47
47
  await writeFileInDir(
48
48
  logger,
49
49
  channelsWiringMetaFile,
50
- `import { pikkuState } from '@pikku/core'\nimport { ChannelsMeta } from '@pikku/core/channel'\n${importStatement}\npikkuState('channel', 'meta', metaData as ChannelsMeta)`
50
+ `import { pikkuState } from '@pikku/core'\nimport { ChannelsMeta } from '@pikku/core/channel'\n${importStatement}\npikkuState(null, 'channel', 'meta', metaData as ChannelsMeta)`
51
51
  )
52
52
  },
53
53
  middleware: [
@@ -2,6 +2,11 @@ import { pikkuSessionlessFunc } from '../../../../.pikku/pikku-types.gen.js'
2
2
  import { serializeFileImports } from '../../../utils/file-imports-serializer.js'
3
3
  import { writeFileInDir } from '../../../utils/file-writer.js'
4
4
  import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js'
5
+ import { getFileImportRelativePath } from '../../../utils/file-import-path.js'
6
+ import {
7
+ stripVerboseFields,
8
+ hasVerboseFields,
9
+ } from '../../../utils/strip-verbose-meta.js'
5
10
 
6
11
  export const pikkuChannels: any = pikkuSessionlessFunc<
7
12
  void,
@@ -9,8 +14,13 @@ export const pikkuChannels: any = pikkuSessionlessFunc<
9
14
  >({
10
15
  func: async ({ logger, config, getInspectorState }) => {
11
16
  const visitState = await getInspectorState()
12
- const { channelsWiringFile, channelsWiringMetaFile, packageMappings } =
13
- config
17
+ const {
18
+ channelsWiringFile,
19
+ channelsWiringMetaFile,
20
+ channelsWiringMetaJsonFile,
21
+ packageMappings,
22
+ schema,
23
+ } = config
14
24
  const { channels } = visitState
15
25
 
16
26
  await writeFileInDir(
@@ -23,10 +33,43 @@ export const pikkuChannels: any = pikkuSessionlessFunc<
23
33
  packageMappings
24
34
  )
25
35
  )
36
+
37
+ // Write minimal JSON (runtime-only fields)
38
+ const minimalMeta = stripVerboseFields(channels.meta)
39
+ await writeFileInDir(
40
+ logger,
41
+ channelsWiringMetaJsonFile,
42
+ JSON.stringify(minimalMeta, null, 2)
43
+ )
44
+
45
+ // Write verbose JSON only if it has additional fields
46
+ if (hasVerboseFields(channels.meta)) {
47
+ const verbosePath = channelsWiringMetaJsonFile.replace(
48
+ /\.gen\.json$/,
49
+ '-verbose.gen.json'
50
+ )
51
+ await writeFileInDir(
52
+ logger,
53
+ verbosePath,
54
+ JSON.stringify(channels.meta, null, 2)
55
+ )
56
+ }
57
+
58
+ // Generate TypeScript file that imports the minimal JSON
59
+ const jsonImportPath = getFileImportRelativePath(
60
+ channelsWiringMetaFile,
61
+ channelsWiringMetaJsonFile,
62
+ packageMappings
63
+ )
64
+ const supportsImportAttributes = schema?.supportsImportAttributes ?? false
65
+ const importStatement = supportsImportAttributes
66
+ ? `import metaData from '${jsonImportPath}' with { type: 'json' }`
67
+ : `import metaData from '${jsonImportPath}'`
68
+
26
69
  await writeFileInDir(
27
70
  logger,
28
71
  channelsWiringMetaFile,
29
- `import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`
72
+ `import { pikkuState } from '@pikku/core'\nimport type { ChannelsMeta } from '@pikku/core/channel'\n${importStatement}\npikkuState(null, 'channel', 'meta', metaData as ChannelsMeta)`
30
73
  )
31
74
 
32
75
  return true
@@ -10,6 +10,12 @@ export const serializeChannelTypes = (functionTypesImportPath: string) => {
10
10
  import { CoreChannel, wireChannel as wireChannelCore } from '@pikku/core/channel'
11
11
  import { AssertHTTPWiringParams } from '@pikku/core/http'
12
12
  import type { PikkuFunctionConfig, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware } from '${functionTypesImportPath}'
13
+ import type { ZodLike, CorePermissionGroup } from '@pikku/core'
14
+
15
+ /**
16
+ * Helper type to infer the output type from a Zod schema
17
+ */
18
+ type InferZodOutput<T> = T extends ZodLike<infer U> ? U : never
13
19
 
14
20
  /**
15
21
  * Type definition for WebSocket channels with typed data exchange.
@@ -60,21 +66,72 @@ export const pikkuChannelDisconnectionFunc = (
60
66
  return typeof func === 'function' ? { func } : func
61
67
  }
62
68
 
69
+ /**
70
+ * Configuration object for channel functions with Zod schema validation.
71
+ */
72
+ type PikkuChannelFuncConfigWithSchema<
73
+ InputSchema extends ZodLike,
74
+ OutputSchema extends ZodLike | undefined = undefined
75
+ > = {
76
+ name?: string
77
+ tags?: string[]
78
+ expose?: boolean
79
+ internal?: boolean
80
+ func: PikkuFunctionSessionless<
81
+ InferZodOutput<InputSchema>,
82
+ OutputSchema extends ZodLike ? InferZodOutput<OutputSchema> : unknown,
83
+ 'channel' | 'session' | 'rpc'
84
+ >
85
+ auth?: boolean
86
+ permissions?: CorePermissionGroup<PikkuPermission<InferZodOutput<InputSchema>>>
87
+ middleware?: PikkuMiddleware[]
88
+ input: InputSchema
89
+ output?: OutputSchema
90
+ }
91
+
63
92
  /**
64
93
  * Creates a function that handles WebSocket channel messages.
65
94
  * Called when a message is received on a channel.
66
- * This is the same as pikkuSessionlessFunc but with ChannelData = unknown by default.
67
95
  *
68
- * @template In - Input type for channel messages
69
- * @template Out - Output type for channel responses
96
+ * Supports two patterns:
97
+ * 1. Generic types: \`pikkuChannelFunc<Input, Output>({ func: ... })\`
98
+ * 2. Zod schemas: \`pikkuChannelFunc({ input: z.object(...), func: ... })\`
99
+ *
100
+ * @template In - Input type for channel messages (inferred from schema if provided)
101
+ * @template Out - Output type for channel responses (inferred from schema if provided)
70
102
  * @param func - Function definition, either direct function or configuration object
71
103
  * @returns The normalized configuration object
104
+ *
105
+ * @example
106
+ * \`\`\`typescript
107
+ * // Pattern 1: Using generic types
108
+ * const handleMessage = pikkuChannelFunc<{text: string}, {received: boolean}>({
109
+ * func: async (_services, { text }) => ({ received: true })
110
+ * })
111
+ *
112
+ * // Pattern 2: Using Zod schemas
113
+ * const messageInput = z.object({ text: z.string() })
114
+ * const messageOutput = z.object({ received: z.boolean() })
115
+ *
116
+ * const handleMessage = pikkuChannelFunc({
117
+ * input: messageInput,
118
+ * output: messageOutput,
119
+ * func: async (_services, { text }) => ({ received: true })
120
+ * })
121
+ * \`\`\`
72
122
  */
73
- export const pikkuChannelFunc = <In, Out = unknown>(
123
+ export function pikkuChannelFunc<
124
+ InputSchema extends ZodLike,
125
+ OutputSchema extends ZodLike | undefined = undefined
126
+ >(
127
+ config: PikkuChannelFuncConfigWithSchema<InputSchema, OutputSchema>
128
+ ): PikkuFunctionConfig<InferZodOutput<InputSchema>, OutputSchema extends ZodLike ? InferZodOutput<OutputSchema> : unknown, 'channel' | 'session' | 'rpc'>
129
+ export function pikkuChannelFunc<In, Out = unknown>(
74
130
  func:
75
131
  | PikkuFunctionSessionless<In, Out, 'channel' | 'session' | 'rpc'>
76
132
  | PikkuFunctionConfig<In, Out, 'channel' | 'session' | 'rpc'>
77
- ) => {
133
+ ): PikkuFunctionConfig<In, Out, 'channel' | 'session' | 'rpc'>
134
+ export function pikkuChannelFunc(func: any) {
78
135
  return typeof func === 'function' ? { func } : func
79
136
  }
80
137
 
@@ -17,12 +17,12 @@ export const serializeTypedChannelsMap = (
17
17
  )
18
18
  typesMap.customTypes.forEach(({ references }) => {
19
19
  for (const reference of references) {
20
- // Skip __object types (placeholder types for invalid/broken functions)
21
20
  if (reference !== '__object' && !reference.startsWith('__object_')) {
22
21
  requiredTypes.add(reference)
23
22
  }
24
23
  }
25
24
  })
25
+
26
26
  const imports = serializeImportMap(
27
27
  relativeToPath,
28
28
  packageMappings,
@@ -30,10 +30,11 @@ export const serializeTypedChannelsMap = (
30
30
  requiredTypes
31
31
  )
32
32
  const serializedCustomTypes = generateCustomTypes(typesMap, requiredTypes)
33
+
33
34
  return `/**
34
35
  * This provides the structure needed for TypeScript to be aware of channels
35
36
  */
36
-
37
+
37
38
  ${imports}
38
39
  ${serializedCustomTypes}
39
40
 
@@ -3,6 +3,10 @@ import { serializeFileImports } from '../../../utils/file-imports-serializer.js'
3
3
  import { writeFileInDir } from '../../../utils/file-writer.js'
4
4
  import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js'
5
5
  import { getFileImportRelativePath } from '../../../utils/file-import-path.js'
6
+ import {
7
+ stripVerboseFields,
8
+ hasVerboseFields,
9
+ } from '../../../utils/strip-verbose-meta.js'
6
10
 
7
11
  export const pikkuCLI: any = pikkuSessionlessFunc<void, boolean | undefined>({
8
12
  func: async ({ logger, config, getInspectorState }) => {
@@ -28,12 +32,27 @@ export const pikkuCLI: any = pikkuSessionlessFunc<void, boolean | undefined>({
28
32
  )
29
33
  )
30
34
 
35
+ // Write minimal JSON (runtime-only fields)
36
+ const minimalMeta = stripVerboseFields(cli.meta)
31
37
  await writeFileInDir(
32
38
  logger,
33
39
  cliWiringMetaJsonFile,
34
- JSON.stringify(cli.meta, null, 2)
40
+ JSON.stringify(minimalMeta, null, 2)
35
41
  )
36
42
 
43
+ // Write verbose JSON only if it has additional fields
44
+ if (hasVerboseFields(cli.meta)) {
45
+ const verbosePath = cliWiringMetaJsonFile.replace(
46
+ /\.gen\.json$/,
47
+ '-verbose.gen.json'
48
+ )
49
+ await writeFileInDir(
50
+ logger,
51
+ verbosePath,
52
+ JSON.stringify(cli.meta, null, 2)
53
+ )
54
+ }
55
+
37
56
  const jsonImportPath = getFileImportRelativePath(
38
57
  cliWiringMetaFile,
39
58
  cliWiringMetaJsonFile,
@@ -48,7 +67,7 @@ export const pikkuCLI: any = pikkuSessionlessFunc<void, boolean | undefined>({
48
67
  await writeFileInDir(
49
68
  logger,
50
69
  cliWiringMetaFile,
51
- `import { pikkuState } from '@pikku/core'\nimport { CLIMeta } from '@pikku/core/cli'\n${importStatement}\npikkuState('cli', 'meta', metaData as CLIMeta)`
70
+ `import { pikkuState } from '@pikku/core'\nimport { CLIMeta } from '@pikku/core/cli'\n${importStatement}\npikkuState(null, 'cli', 'meta', metaData as CLIMeta)`
52
71
  )
53
72
 
54
73
  return true
@@ -0,0 +1,135 @@
1
+ import { pikkuSessionlessFunc } from '../../../../.pikku/pikku-types.gen.js'
2
+ import { ErrorCode } from '@pikku/inspector'
3
+ import { writeFileInDir } from '../../../utils/file-writer.js'
4
+ import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js'
5
+ import { readFile } from 'fs/promises'
6
+ import { join, isAbsolute } from 'path'
7
+ import {
8
+ stripVerboseFields,
9
+ hasVerboseFields,
10
+ } from '../../../utils/strip-verbose-meta.js'
11
+
12
+ /**
13
+ * Load and sanitize an SVG icon file.
14
+ * Returns the SVG content as a string, or undefined if not found.
15
+ */
16
+ const loadIcon = async (
17
+ iconPath: string | undefined,
18
+ rootDir: string,
19
+ logger: any
20
+ ): Promise<string | undefined> => {
21
+ if (!iconPath) return undefined
22
+
23
+ // Resolve the full path to the icon
24
+ const fullPath = isAbsolute(iconPath) ? iconPath : join(rootDir, iconPath)
25
+
26
+ try {
27
+ const content = await readFile(fullPath, 'utf-8')
28
+
29
+ // Basic SVG validation - must start with <svg
30
+ const trimmed = content.trim()
31
+ if (!trimmed.startsWith('<svg') && !trimmed.startsWith('<?xml')) {
32
+ logger.warn(`Icon file is not a valid SVG: ${fullPath}`)
33
+ return undefined
34
+ }
35
+
36
+ // Return the sanitized SVG (remove XML declaration if present)
37
+ return trimmed.replace(/<\?xml[^?]*\?>\s*/g, '').trim()
38
+ } catch (e) {
39
+ logger.warn(`Could not load icon: ${fullPath}`)
40
+ return undefined
41
+ }
42
+ }
43
+
44
+ export const pikkuForgeNodes: any = pikkuSessionlessFunc<
45
+ void,
46
+ boolean | undefined
47
+ >({
48
+ func: async ({ logger, config, getInspectorState }) => {
49
+ const { forgeNodes, forgeCredentials } = await getInspectorState()
50
+ const { forgeNodesMetaJsonFile, forge, rootDir } = config
51
+
52
+ const hasNodes = Object.keys(forgeNodes.meta).length > 0
53
+ const hasCredentials = Object.keys(forgeCredentials.meta).length > 0
54
+
55
+ // Only generate if there are forge nodes or credentials
56
+ if (!hasNodes && !hasCredentials) {
57
+ return undefined
58
+ }
59
+
60
+ // Validate categories if configured
61
+ const allowedCategories = forge?.node?.categories
62
+ if (allowedCategories && allowedCategories.length > 0) {
63
+ for (const [name, meta] of Object.entries(forgeNodes.meta) as [
64
+ string,
65
+ any,
66
+ ][]) {
67
+ if (!allowedCategories.includes(meta.category)) {
68
+ logger.critical(
69
+ ErrorCode.INVALID_VALUE,
70
+ `Forge node '${name}' has invalid category '${meta.category}'. ` +
71
+ `Allowed categories: ${allowedCategories.join(', ')}`
72
+ )
73
+ }
74
+ }
75
+ }
76
+
77
+ // Build the output metadata - remove per-node icon field
78
+ const outputMeta: Record<string, any> = {}
79
+ for (const [name, meta] of Object.entries(forgeNodes.meta) as [
80
+ string,
81
+ any,
82
+ ][]) {
83
+ // Remove icon from node meta - only package-level icon is used
84
+ const { icon: _icon, ...nodeMetaWithoutIcon } = meta
85
+ outputMeta[name] = nodeMetaWithoutIcon
86
+ }
87
+
88
+ // Load package-level icon
89
+ const packageIcon = await loadIcon(forge?.node?.icon, rootDir, logger)
90
+
91
+ const metaData = {
92
+ nodes: outputMeta,
93
+ credentials: forgeCredentials.meta,
94
+ package: {
95
+ displayName: forge?.node?.displayName,
96
+ description: forge?.node?.description,
97
+ icon: packageIcon,
98
+ categories: forge?.node?.categories,
99
+ },
100
+ }
101
+
102
+ if (forgeNodesMetaJsonFile) {
103
+ // Write minimal JSON (runtime-only fields)
104
+ const minimalMeta = stripVerboseFields(metaData)
105
+ await writeFileInDir(
106
+ logger,
107
+ forgeNodesMetaJsonFile,
108
+ JSON.stringify(minimalMeta, null, 2),
109
+ { ignoreModifyComment: true }
110
+ )
111
+
112
+ // Write verbose JSON only if it has additional fields
113
+ if (hasVerboseFields(metaData)) {
114
+ const verbosePath = forgeNodesMetaJsonFile.replace(
115
+ /\.gen\.json$/,
116
+ '-verbose.gen.json'
117
+ )
118
+ await writeFileInDir(
119
+ logger,
120
+ verbosePath,
121
+ JSON.stringify(metaData, null, 2),
122
+ { ignoreModifyComment: true }
123
+ )
124
+ }
125
+ }
126
+
127
+ return true
128
+ },
129
+ middleware: [
130
+ logCommandInfoAndTime({
131
+ commandStart: 'Generating Forge nodes metadata',
132
+ commandEnd: 'Generated Forge nodes metadata',
133
+ }),
134
+ ],
135
+ })
@@ -0,0 +1,38 @@
1
+ import { pikkuSessionlessFunc } from '../../../../.pikku/pikku-types.gen.js'
2
+ import { writeFileInDir } from '../../../utils/file-writer.js'
3
+ import { getFileImportRelativePath } from '../../../utils/file-import-path.js'
4
+ import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js'
5
+ import { serializeForgeTypes } from './serialize-forge-types.js'
6
+
7
+ export const pikkuForgeTypes: any = pikkuSessionlessFunc<void, void>({
8
+ func: async ({ logger, config }) => {
9
+ const {
10
+ forgeTypesFile,
11
+ rpcInternalMapDeclarationFile,
12
+ packageMappings,
13
+ forge,
14
+ } = config
15
+
16
+ // Get the import path for the RPC map declaration file
17
+ // The declaration file ends in .d.ts, but we need to import from .js
18
+ // getFileImportRelativePath converts .ts -> .js, so .d.ts -> .d.js
19
+ // We need to remove the extra .d extension
20
+ let rpcMapImportPath = getFileImportRelativePath(
21
+ forgeTypesFile,
22
+ rpcInternalMapDeclarationFile,
23
+ packageMappings
24
+ )
25
+ // Fix: .d.ts files should be imported as .js (TypeScript resolves types from .d.ts)
26
+ rpcMapImportPath = rpcMapImportPath.replace('.d.js', '.js')
27
+
28
+ const categories = forge?.node?.categories
29
+ const content = serializeForgeTypes(rpcMapImportPath, categories)
30
+ await writeFileInDir(logger, forgeTypesFile, content)
31
+ },
32
+ middleware: [
33
+ logCommandInfoAndTime({
34
+ commandStart: 'Creating Forge types',
35
+ commandEnd: 'Created Forge types',
36
+ }),
37
+ ],
38
+ })