@pikku/core 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/crypto-utils.d.ts +2 -0
  3. package/dist/crypto-utils.js +78 -0
  4. package/dist/errors/error-handler.js +3 -3
  5. package/dist/errors/errors.d.ts +8 -0
  6. package/dist/errors/errors.js +16 -0
  7. package/dist/errors/index.d.ts +0 -1
  8. package/dist/errors/index.js +0 -1
  9. package/dist/function/function-runner.d.ts +10 -3
  10. package/dist/function/function-runner.js +136 -31
  11. package/dist/function/functions.types.d.ts +35 -12
  12. package/dist/function/functions.types.js +16 -6
  13. package/dist/function/index.d.ts +2 -2
  14. package/dist/function/index.js +1 -2
  15. package/dist/handle-error.js +1 -10
  16. package/dist/index.d.ts +30 -24
  17. package/dist/index.js +19 -27
  18. package/dist/middleware/auth-apikey.d.ts +1 -1
  19. package/dist/middleware/auth-apikey.js +3 -3
  20. package/dist/middleware/auth-bearer.d.ts +1 -1
  21. package/dist/middleware/auth-bearer.js +3 -6
  22. package/dist/middleware/auth-cookie.d.ts +1 -1
  23. package/dist/middleware/auth-cookie.js +6 -8
  24. package/dist/middleware/cors.d.ts +46 -0
  25. package/dist/middleware/cors.js +73 -0
  26. package/dist/middleware/index.d.ts +5 -3
  27. package/dist/middleware/index.js +5 -3
  28. package/dist/middleware/remote-auth.d.ts +5 -0
  29. package/dist/middleware/remote-auth.js +55 -0
  30. package/dist/middleware/timeout.d.ts +1 -1
  31. package/dist/middleware-runner.d.ts +3 -14
  32. package/dist/middleware-runner.js +14 -16
  33. package/dist/permissions.d.ts +3 -86
  34. package/dist/permissions.js +20 -80
  35. package/dist/pikku-state.d.ts +33 -104
  36. package/dist/pikku-state.js +150 -66
  37. package/dist/schema.d.ts +8 -6
  38. package/dist/schema.js +31 -18
  39. package/dist/services/ai-agent-runner-service.d.ts +24 -0
  40. package/dist/services/ai-agent-runner-service.js +1 -0
  41. package/dist/services/ai-run-state-service.d.ts +13 -0
  42. package/dist/services/ai-run-state-service.js +1 -0
  43. package/dist/services/ai-storage-service.d.ts +18 -0
  44. package/dist/services/ai-storage-service.js +1 -0
  45. package/dist/services/deployment-service.d.ts +19 -0
  46. package/dist/services/deployment-service.js +1 -0
  47. package/dist/services/gopass-secrets.d.ts +47 -0
  48. package/dist/services/gopass-secrets.js +94 -0
  49. package/dist/services/in-memory-trigger-service.d.ts +23 -0
  50. package/dist/services/in-memory-trigger-service.js +50 -0
  51. package/dist/services/in-memory-workflow-service.d.ts +59 -0
  52. package/dist/services/in-memory-workflow-service.js +287 -0
  53. package/dist/services/index.d.ts +25 -11
  54. package/dist/services/index.js +10 -13
  55. package/dist/services/local-secrets.d.ts +23 -0
  56. package/dist/services/local-secrets.js +45 -0
  57. package/dist/services/local-variables.d.ts +5 -0
  58. package/dist/services/local-variables.js +18 -0
  59. package/dist/services/scheduler-service.d.ts +21 -1
  60. package/dist/services/scheduler-service.js +14 -0
  61. package/dist/services/schema-service.d.ts +6 -0
  62. package/dist/services/scoped-secret-service.d.ts +16 -0
  63. package/dist/services/scoped-secret-service.js +35 -0
  64. package/dist/services/secret-service.d.ts +25 -4
  65. package/dist/services/trigger-service.d.ts +23 -0
  66. package/dist/services/trigger-service.js +1 -0
  67. package/dist/services/typed-secret-service.d.ts +30 -0
  68. package/dist/services/typed-secret-service.js +40 -0
  69. package/dist/services/typed-variables-service.d.ts +27 -0
  70. package/dist/services/typed-variables-service.js +46 -0
  71. package/dist/services/user-session-service.d.ts +13 -0
  72. package/dist/services/user-session-service.js +17 -0
  73. package/dist/services/variables-service.d.ts +5 -0
  74. package/dist/services/workflow-service.d.ts +43 -0
  75. package/dist/services/workflow-service.js +1 -0
  76. package/dist/types/core.types.d.ts +54 -10
  77. package/dist/types/core.types.js +7 -0
  78. package/dist/types/state.types.d.ts +127 -0
  79. package/dist/types/state.types.js +1 -0
  80. package/dist/utils.d.ts +10 -1
  81. package/dist/utils.js +60 -3
  82. package/dist/version.d.ts +6 -0
  83. package/dist/version.js +19 -0
  84. package/dist/wirings/ai-agent/ai-agent-memory.d.ts +29 -0
  85. package/dist/wirings/ai-agent/ai-agent-memory.js +199 -0
  86. package/dist/wirings/ai-agent/ai-agent-model-config.d.ts +9 -0
  87. package/dist/wirings/ai-agent/ai-agent-model-config.js +36 -0
  88. package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +60 -0
  89. package/dist/wirings/ai-agent/ai-agent-prepare.js +312 -0
  90. package/dist/wirings/ai-agent/ai-agent-registry.d.ts +15 -0
  91. package/dist/wirings/ai-agent/ai-agent-registry.js +47 -0
  92. package/dist/wirings/ai-agent/ai-agent-runner.d.ts +3 -0
  93. package/dist/wirings/ai-agent/ai-agent-runner.js +96 -0
  94. package/dist/wirings/ai-agent/ai-agent-stream.d.ts +11 -0
  95. package/dist/wirings/ai-agent/ai-agent-stream.js +503 -0
  96. package/dist/wirings/ai-agent/ai-agent.types.d.ts +254 -0
  97. package/dist/wirings/ai-agent/ai-agent.types.js +1 -0
  98. package/dist/wirings/ai-agent/index.d.ts +5 -0
  99. package/dist/wirings/ai-agent/index.js +4 -0
  100. package/dist/wirings/channel/channel-common.d.ts +7 -4
  101. package/dist/wirings/channel/channel-common.js +15 -8
  102. package/dist/wirings/channel/channel-handler.js +13 -4
  103. package/dist/wirings/channel/channel-middleware-runner.d.ts +9 -0
  104. package/dist/wirings/channel/channel-middleware-runner.js +73 -0
  105. package/dist/wirings/channel/channel-runner.js +12 -12
  106. package/dist/wirings/channel/channel.types.d.ts +5 -1
  107. package/dist/wirings/channel/define-channel-routes.d.ts +21 -0
  108. package/dist/wirings/channel/define-channel-routes.js +23 -0
  109. package/dist/wirings/channel/index.d.ts +10 -8
  110. package/dist/wirings/channel/index.js +7 -8
  111. package/dist/wirings/channel/local/index.d.ts +3 -3
  112. package/dist/wirings/channel/local/index.js +3 -3
  113. package/dist/wirings/channel/local/local-channel-runner.js +18 -6
  114. package/dist/wirings/channel/log-channels.js +1 -1
  115. package/dist/wirings/channel/serverless/index.d.ts +1 -1
  116. package/dist/wirings/channel/serverless/index.js +1 -1
  117. package/dist/wirings/channel/serverless/serverless-channel-runner.js +17 -6
  118. package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
  119. package/dist/wirings/cli/channel/index.d.ts +1 -1
  120. package/dist/wirings/cli/channel/index.js +1 -1
  121. package/dist/wirings/cli/cli-runner.d.ts +1 -1
  122. package/dist/wirings/cli/cli-runner.js +22 -18
  123. package/dist/wirings/cli/cli.types.d.ts +7 -6
  124. package/dist/wirings/cli/define-cli-commands.d.ts +19 -0
  125. package/dist/wirings/cli/define-cli-commands.js +20 -0
  126. package/dist/wirings/cli/index.d.ts +2 -3
  127. package/dist/wirings/cli/index.js +1 -3
  128. package/dist/wirings/http/http-routes.d.ts +69 -0
  129. package/dist/wirings/http/http-routes.js +139 -0
  130. package/dist/wirings/http/http-runner.d.ts +2 -2
  131. package/dist/wirings/http/http-runner.js +62 -27
  132. package/dist/wirings/http/http.types.d.ts +77 -24
  133. package/dist/wirings/http/index.d.ts +5 -4
  134. package/dist/wirings/http/index.js +4 -3
  135. package/dist/wirings/http/log-http-routes.js +1 -1
  136. package/dist/wirings/http/routers/path-to-regex.js +2 -2
  137. package/dist/wirings/mcp/index.d.ts +4 -3
  138. package/dist/wirings/mcp/index.js +3 -3
  139. package/dist/wirings/mcp/mcp-runner.d.ts +1 -3
  140. package/dist/wirings/mcp/mcp-runner.js +42 -56
  141. package/dist/wirings/mcp/mcp.types.d.ts +3 -3
  142. package/dist/wirings/node/index.d.ts +2 -0
  143. package/dist/wirings/node/index.js +1 -0
  144. package/dist/wirings/node/node.types.d.ts +20 -0
  145. package/dist/wirings/node/node.types.js +1 -0
  146. package/dist/wirings/oauth2/index.d.ts +3 -0
  147. package/dist/wirings/oauth2/index.js +2 -0
  148. package/dist/wirings/oauth2/oauth2-client.d.ts +47 -0
  149. package/dist/wirings/oauth2/oauth2-client.js +267 -0
  150. package/dist/wirings/oauth2/oauth2.types.d.ts +65 -0
  151. package/dist/wirings/oauth2/oauth2.types.js +4 -0
  152. package/dist/wirings/oauth2/wire-oauth2-credential.d.ts +20 -0
  153. package/dist/wirings/oauth2/wire-oauth2-credential.js +21 -0
  154. package/dist/wirings/queue/index.d.ts +2 -2
  155. package/dist/wirings/queue/index.js +1 -1
  156. package/dist/wirings/queue/queue-runner.d.ts +7 -0
  157. package/dist/wirings/queue/queue-runner.js +23 -12
  158. package/dist/wirings/queue/queue.types.d.ts +8 -2
  159. package/dist/wirings/rpc/index.d.ts +1 -1
  160. package/dist/wirings/rpc/index.js +1 -1
  161. package/dist/wirings/rpc/rpc-runner.d.ts +40 -13
  162. package/dist/wirings/rpc/rpc-runner.js +191 -25
  163. package/dist/wirings/rpc/rpc-types.d.ts +15 -4
  164. package/dist/wirings/scheduler/index.d.ts +3 -3
  165. package/dist/wirings/scheduler/index.js +2 -3
  166. package/dist/wirings/scheduler/log-schedulers.js +1 -1
  167. package/dist/wirings/scheduler/scheduler-runner.d.ts +5 -0
  168. package/dist/wirings/scheduler/scheduler-runner.js +28 -10
  169. package/dist/wirings/secret/index.d.ts +3 -0
  170. package/dist/wirings/secret/index.js +2 -0
  171. package/dist/wirings/secret/secret.types.d.ts +27 -0
  172. package/dist/wirings/secret/secret.types.js +1 -0
  173. package/dist/wirings/secret/validate-secret-definitions.d.ts +6 -0
  174. package/dist/wirings/secret/validate-secret-definitions.js +55 -0
  175. package/dist/wirings/trigger/index.d.ts +3 -0
  176. package/dist/wirings/trigger/index.js +2 -0
  177. package/dist/wirings/trigger/pikku-trigger-service.d.ts +26 -0
  178. package/dist/wirings/trigger/pikku-trigger-service.js +75 -0
  179. package/dist/wirings/trigger/trigger-runner.d.ts +42 -0
  180. package/dist/wirings/trigger/trigger-runner.js +85 -0
  181. package/dist/wirings/trigger/trigger.types.d.ts +130 -0
  182. package/dist/wirings/trigger/trigger.types.js +40 -0
  183. package/dist/wirings/variable/index.d.ts +3 -0
  184. package/dist/wirings/variable/index.js +2 -0
  185. package/dist/wirings/variable/validate-variable-definitions.d.ts +6 -0
  186. package/dist/wirings/variable/validate-variable-definitions.js +45 -0
  187. package/dist/wirings/variable/variable.types.d.ts +18 -0
  188. package/dist/wirings/variable/variable.types.js +1 -0
  189. package/dist/wirings/workflow/dsl/index.d.ts +5 -0
  190. package/dist/wirings/workflow/dsl/index.js +4 -0
  191. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +292 -0
  192. package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
  193. package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
  194. package/dist/wirings/workflow/dsl/workflow-runner.js +23 -0
  195. package/dist/wirings/workflow/graph/graph-node.d.ts +117 -0
  196. package/dist/wirings/workflow/graph/graph-node.js +58 -0
  197. package/dist/wirings/workflow/graph/graph-runner.d.ts +9 -0
  198. package/dist/wirings/workflow/graph/graph-runner.js +540 -0
  199. package/dist/wirings/workflow/graph/index.d.ts +4 -0
  200. package/dist/wirings/workflow/graph/index.js +3 -0
  201. package/dist/wirings/workflow/graph/template.d.ts +15 -0
  202. package/dist/wirings/workflow/graph/template.js +27 -0
  203. package/dist/wirings/workflow/graph/wire-workflow-graph.d.ts +15 -0
  204. package/dist/wirings/workflow/graph/wire-workflow-graph.js +8 -0
  205. package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +82 -0
  206. package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
  207. package/dist/wirings/workflow/index.d.ts +7 -12
  208. package/dist/wirings/workflow/index.js +8 -11
  209. package/dist/wirings/workflow/pikku-workflow-service.d.ts +114 -10
  210. package/dist/wirings/workflow/pikku-workflow-service.js +386 -115
  211. package/dist/wirings/workflow/workflow-helpers.d.ts +36 -0
  212. package/dist/wirings/workflow/workflow-helpers.js +38 -0
  213. package/dist/wirings/workflow/workflow-utils.d.ts +1 -0
  214. package/dist/wirings/workflow/workflow-utils.js +1 -0
  215. package/dist/wirings/workflow/workflow.types.d.ts +83 -214
  216. package/package.json +13 -6
  217. package/run-tests.sh +4 -1
  218. package/src/crypto-utils.ts +99 -0
  219. package/src/errors/error-handler.ts +3 -3
  220. package/src/errors/errors.ts +17 -0
  221. package/src/errors/index.ts +0 -1
  222. package/src/factory-functions.test.ts +42 -2
  223. package/src/function/function-runner.test.ts +5 -12
  224. package/src/function/function-runner.ts +195 -40
  225. package/src/function/functions.types.ts +66 -14
  226. package/src/function/index.ts +5 -2
  227. package/src/handle-error.ts +2 -10
  228. package/src/index.ts +106 -27
  229. package/src/middleware/auth-apikey.test.ts +15 -12
  230. package/src/middleware/auth-apikey.ts +3 -3
  231. package/src/middleware/auth-bearer.test.ts +17 -14
  232. package/src/middleware/auth-bearer.ts +25 -27
  233. package/src/middleware/auth-cookie.test.ts +16 -13
  234. package/src/middleware/auth-cookie.ts +6 -8
  235. package/src/middleware/cors.ts +96 -0
  236. package/src/middleware/index.ts +5 -3
  237. package/src/middleware/remote-auth.ts +68 -0
  238. package/src/middleware-runner.test.ts +122 -0
  239. package/src/middleware-runner.ts +24 -17
  240. package/src/permissions.test.ts +102 -86
  241. package/src/permissions.ts +32 -93
  242. package/src/pikku-state.ts +168 -201
  243. package/src/run-tests-script.test.ts +49 -0
  244. package/src/schema.ts +50 -18
  245. package/src/services/ai-agent-runner-service.ts +29 -0
  246. package/src/services/ai-run-state-service.ts +20 -0
  247. package/src/services/ai-storage-service.ts +39 -0
  248. package/src/services/deployment-service.ts +22 -0
  249. package/src/services/gopass-secrets.ts +95 -0
  250. package/src/services/in-memory-trigger-service.ts +68 -0
  251. package/src/services/in-memory-workflow-service.ts +395 -0
  252. package/src/services/index.ts +49 -14
  253. package/src/services/local-secrets.ts +51 -0
  254. package/src/services/local-variables.ts +22 -0
  255. package/src/services/scheduler-service.ts +29 -1
  256. package/src/services/schema-service.ts +7 -0
  257. package/src/services/scoped-secret-service.ts +41 -0
  258. package/src/services/secret-service.ts +25 -4
  259. package/src/services/trigger-service.ts +38 -0
  260. package/src/services/typed-secret-service.ts +70 -0
  261. package/src/services/typed-variables-service.ts +81 -0
  262. package/src/services/user-session-service.ts +23 -0
  263. package/src/services/variables-service.ts +5 -0
  264. package/src/services/workflow-service.ts +94 -0
  265. package/src/types/core.types.ts +82 -8
  266. package/src/types/state.types.ts +169 -0
  267. package/src/utils.ts +74 -5
  268. package/src/version.test.ts +80 -0
  269. package/src/version.ts +25 -0
  270. package/src/wirings/ai-agent/ai-agent-memory.ts +300 -0
  271. package/src/wirings/ai-agent/ai-agent-model-config.ts +43 -0
  272. package/src/wirings/ai-agent/ai-agent-prepare.ts +470 -0
  273. package/src/wirings/ai-agent/ai-agent-registry.test.ts +37 -0
  274. package/src/wirings/ai-agent/ai-agent-registry.ts +82 -0
  275. package/src/wirings/ai-agent/ai-agent-runner.test.ts +75 -0
  276. package/src/wirings/ai-agent/ai-agent-runner.ts +137 -0
  277. package/src/wirings/ai-agent/ai-agent-stream.test.ts +246 -0
  278. package/src/wirings/ai-agent/ai-agent-stream.ts +774 -0
  279. package/src/wirings/ai-agent/ai-agent.types.ts +273 -0
  280. package/src/wirings/ai-agent/index.ts +28 -0
  281. package/src/wirings/channel/channel-common.ts +32 -19
  282. package/src/wirings/channel/channel-handler.ts +18 -5
  283. package/src/wirings/channel/channel-middleware-runner.ts +119 -0
  284. package/src/wirings/channel/channel-runner.ts +14 -15
  285. package/src/wirings/channel/channel.types.ts +17 -1
  286. package/src/wirings/channel/define-channel-routes.ts +25 -0
  287. package/src/wirings/channel/index.ts +23 -8
  288. package/src/wirings/channel/local/index.ts +3 -3
  289. package/src/wirings/channel/local/local-channel-runner.test.ts +47 -2
  290. package/src/wirings/channel/local/local-channel-runner.ts +22 -6
  291. package/src/wirings/channel/log-channels.ts +1 -1
  292. package/src/wirings/channel/serverless/index.ts +5 -1
  293. package/src/wirings/channel/serverless/serverless-channel-runner.ts +22 -6
  294. package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
  295. package/src/wirings/cli/channel/index.ts +1 -1
  296. package/src/wirings/cli/cli-runner.test.ts +28 -28
  297. package/src/wirings/cli/cli-runner.ts +27 -19
  298. package/src/wirings/cli/cli.types.ts +12 -11
  299. package/src/wirings/cli/command-parser.test.ts +8 -8
  300. package/src/wirings/cli/define-cli-commands.ts +24 -0
  301. package/src/wirings/cli/index.ts +10 -4
  302. package/src/wirings/http/http-routes.test.ts +322 -0
  303. package/src/wirings/http/http-routes.ts +198 -0
  304. package/src/wirings/http/http-runner.test.ts +5 -5
  305. package/src/wirings/http/http-runner.ts +80 -29
  306. package/src/wirings/http/http.types.ts +121 -23
  307. package/src/wirings/http/index.ts +16 -4
  308. package/src/wirings/http/log-http-routes.ts +1 -1
  309. package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
  310. package/src/wirings/http/routers/path-to-regex.ts +2 -2
  311. package/src/wirings/mcp/index.ts +27 -3
  312. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +3 -3
  313. package/src/wirings/mcp/mcp-runner.ts +56 -67
  314. package/src/wirings/mcp/mcp.types.ts +3 -3
  315. package/src/wirings/node/index.ts +2 -0
  316. package/src/wirings/node/node.types.ts +23 -0
  317. package/src/wirings/oauth2/index.ts +3 -0
  318. package/src/wirings/oauth2/oauth2-client.test.ts +929 -0
  319. package/src/wirings/oauth2/oauth2-client.ts +335 -0
  320. package/src/wirings/oauth2/oauth2.types.ts +69 -0
  321. package/src/wirings/oauth2/wire-oauth2-credential.ts +23 -0
  322. package/src/wirings/queue/index.ts +14 -2
  323. package/src/wirings/queue/queue-runner.test.ts +115 -73
  324. package/src/wirings/queue/queue-runner.ts +39 -13
  325. package/src/wirings/queue/queue.types.ts +12 -2
  326. package/src/wirings/rpc/index.ts +1 -1
  327. package/src/wirings/rpc/rpc-runner.ts +270 -34
  328. package/src/wirings/rpc/rpc-types.ts +21 -4
  329. package/src/wirings/scheduler/index.ts +7 -4
  330. package/src/wirings/scheduler/log-schedulers.ts +1 -1
  331. package/src/wirings/scheduler/scheduler-runner.test.ts +97 -53
  332. package/src/wirings/scheduler/scheduler-runner.ts +50 -10
  333. package/src/wirings/secret/index.ts +9 -0
  334. package/src/wirings/secret/secret.types.ts +32 -0
  335. package/src/wirings/secret/validate-secret-definitions.ts +82 -0
  336. package/src/wirings/trigger/index.ts +10 -0
  337. package/src/wirings/trigger/pikku-trigger-service.ts +134 -0
  338. package/src/wirings/trigger/trigger-runner.ts +138 -0
  339. package/src/wirings/trigger/trigger.types.ts +178 -0
  340. package/src/wirings/variable/index.ts +8 -0
  341. package/src/wirings/variable/validate-variable-definitions.ts +69 -0
  342. package/src/wirings/variable/variable.types.ts +22 -0
  343. package/src/wirings/workflow/dsl/index.ts +31 -0
  344. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +320 -0
  345. package/src/wirings/workflow/dsl/workflow-runner.ts +28 -0
  346. package/src/wirings/workflow/graph/graph-node.ts +222 -0
  347. package/src/wirings/workflow/graph/graph-runner.test.ts +495 -0
  348. package/src/wirings/workflow/graph/graph-runner.ts +816 -0
  349. package/src/wirings/workflow/graph/index.ts +14 -0
  350. package/src/wirings/workflow/graph/template.ts +42 -0
  351. package/src/wirings/workflow/graph/wire-workflow-graph.ts +29 -0
  352. package/src/wirings/workflow/graph/workflow-graph.types.ts +104 -0
  353. package/src/wirings/workflow/index.ts +64 -26
  354. package/src/wirings/workflow/pikku-workflow-service.test.ts +212 -0
  355. package/src/wirings/workflow/pikku-workflow-service.ts +571 -136
  356. package/src/wirings/workflow/workflow-helpers.ts +79 -0
  357. package/src/wirings/workflow/workflow-utils.ts +0 -0
  358. package/src/wirings/workflow/workflow.types.ts +123 -279
  359. package/tsconfig.tsbuildinfo +1 -1
  360. package/dist/wirings/workflow/workflow-runner.d.ts +0 -34
  361. package/dist/wirings/workflow/workflow-runner.js +0 -65
  362. package/src/function/function-runner.ts.bak +0 -188
  363. package/src/wirings/workflow/workflow-runner.ts +0 -72
@@ -1,8 +1,7 @@
1
- export * from './channel-runner.js';
2
- export * from './channel.types.js';
3
- export * from './log-channels.js';
4
- export * from './pikku-abstract-channel-handler.js';
5
- export * from './eventhub-service.js';
6
- export * from './eventhub-service.js';
7
- export * from './channel-store.js';
8
- export * from './eventhub-store.js';
1
+ export { wireChannel, openChannel } from './channel-runner.js';
2
+ export { addChannelMiddleware, combineChannelMiddleware, wrapChannelWithMiddleware, } from './channel-middleware-runner.js';
3
+ export { logChannels } from './log-channels.js';
4
+ export { PikkuAbstractChannelHandler } from './pikku-abstract-channel-handler.js';
5
+ export { ChannelStore } from './channel-store.js';
6
+ export { EventHubStore } from './eventhub-store.js';
7
+ export { defineChannelRoutes } from './define-channel-routes.js';
@@ -1,3 +1,3 @@
1
- export * from './local-channel-handler.js';
2
- export * from './local-channel-runner.js';
3
- export * from './local-eventhub-service.js';
1
+ export { PikkuLocalChannelHandler } from './local-channel-handler.js';
2
+ export { runLocalChannel } from './local-channel-runner.js';
3
+ export { LocalEventHubService } from './local-eventhub-service.js';
@@ -1,3 +1,3 @@
1
- export * from './local-channel-handler.js';
2
- export * from './local-channel-runner.js';
3
- export * from './local-eventhub-service.js';
1
+ export { PikkuLocalChannelHandler } from './local-channel-handler.js';
2
+ export { runLocalChannel } from './local-channel-runner.js';
3
+ export { LocalEventHubService } from './local-eventhub-service.js';
@@ -4,10 +4,11 @@ import { closeWireServices } from '../../../utils.js';
4
4
  import { processMessageHandlers } from '../channel-handler.js';
5
5
  import { PikkuLocalChannelHandler } from './local-channel-handler.js';
6
6
  import { handleHTTPError } from '../../../handle-error.js';
7
- import { PikkuSessionService } from '../../../services/user-session-service.js';
7
+ import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../../services/user-session-service.js';
8
8
  import { runChannelLifecycleWithMiddleware } from '../channel-common.js';
9
9
  export const runLocalChannel = async ({ singletonServices, channelId, request, response, route, createWireServices, skipUserSession = false, respondWith404 = true, coerceDataFromSchema = true, logWarningsForStatusCodes = [], bubbleErrors = false, }) => {
10
10
  let wireServices;
11
+ let closedWireServices = false;
11
12
  let channelHandler;
12
13
  const userSession = new PikkuSessionService();
13
14
  let http;
@@ -39,10 +40,20 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
39
40
  try {
40
41
  channelHandler = new PikkuLocalChannelHandler(channelId, channelConfig.name, openingData);
41
42
  const channel = channelHandler.getChannel();
42
- const wire = { channel, session: userSession };
43
+ const wire = {
44
+ channel,
45
+ ...createMiddlewareSessionWireProps(userSession),
46
+ };
43
47
  if (createWireServices) {
44
48
  wireServices = await createWireServices(singletonServices, wire);
45
49
  }
50
+ const closeServices = async () => {
51
+ if (!wireServices || closedWireServices) {
52
+ return;
53
+ }
54
+ closedWireServices = true;
55
+ await closeWireServices(singletonServices.logger, wireServices);
56
+ };
46
57
  const services = { ...singletonServices, ...wireServices };
47
58
  channelHandler.registerOnOpen(async () => {
48
59
  if (channelConfig.onConnect && meta.connect) {
@@ -55,6 +66,7 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
55
66
  services,
56
67
  channel,
57
68
  data: openingData,
69
+ channelMiddlewareMeta: meta.channelMiddleware,
58
70
  });
59
71
  if (result !== undefined) {
60
72
  await channel.send(result);
@@ -76,6 +88,7 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
76
88
  lifecycleType: 'disconnect',
77
89
  services,
78
90
  channel,
91
+ channelMiddlewareMeta: meta.channelMiddleware,
79
92
  });
80
93
  }
81
94
  catch (e) {
@@ -83,9 +96,7 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
83
96
  channel.send({ error: e.message || 'Unknown error' });
84
97
  }
85
98
  }
86
- if (wireServices) {
87
- await closeWireServices(singletonServices.logger, wireServices);
88
- }
99
+ await closeServices();
89
100
  });
90
101
  const onMessage = processMessageHandlers(services, channelConfig, channelHandler, userSession);
91
102
  channelHandler.registerOnMessage(async (data) => {
@@ -103,7 +114,8 @@ export const runLocalChannel = async ({ singletonServices, channelId, request, r
103
114
  handleHTTPError(e, http, channelId, singletonServices.logger, logWarningsForStatusCodes, respondWith404, bubbleErrors);
104
115
  }
105
116
  finally {
106
- if (wireServices) {
117
+ if (!channelHandler && wireServices && !closedWireServices) {
118
+ closedWireServices = true;
107
119
  await closeWireServices(singletonServices.logger, wireServices);
108
120
  }
109
121
  }
@@ -4,7 +4,7 @@ import { pikkuState } from '../../pikku-state.js';
4
4
  * @param logger - A logger for logging information.
5
5
  */
6
6
  export const logChannels = (logger) => {
7
- const channels = pikkuState('channel', 'channels');
7
+ const channels = pikkuState(null, 'channel', 'channels');
8
8
  if (channels.size === 0) {
9
9
  logger.info('No channels added');
10
10
  return;
@@ -1 +1 @@
1
- export * from './serverless-channel-runner.js';
1
+ export { runChannelConnect, runChannelDisconnect, runChannelMessage, } from './serverless-channel-runner.js';
@@ -1 +1 @@
1
- export * from './serverless-channel-runner.js';
1
+ export { runChannelConnect, runChannelDisconnect, runChannelMessage, } from './serverless-channel-runner.js';
@@ -3,14 +3,14 @@ import { processMessageHandlers } from '../channel-handler.js';
3
3
  import { openChannel } from '../channel-runner.js';
4
4
  import { createHTTPWire } from '../../http/http-runner.js';
5
5
  import { handleHTTPError } from '../../../handle-error.js';
6
- import { PikkuSessionService } from '../../../services/user-session-service.js';
6
+ import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../../services/user-session-service.js';
7
7
  import { pikkuState } from '../../../pikku-state.js';
8
8
  import { PikkuFetchHTTPRequest } from '../../http/pikku-fetch-http-request.js';
9
9
  import { runChannelLifecycleWithMiddleware } from '../channel-common.js';
10
10
  const getVariablesForChannel = ({ channelId, channelName, channelHandlerFactory, openingData, }) => {
11
- const channels = pikkuState('channel', 'channels');
11
+ const channels = pikkuState(null, 'channel', 'channels');
12
12
  const channelConfig = channels.get(channelName);
13
- const channelsMeta = pikkuState('channel', 'meta');
13
+ const channelsMeta = pikkuState(null, 'channel', 'meta');
14
14
  const meta = channelsMeta[channelName];
15
15
  if (!channelConfig) {
16
16
  throw new Error(`Channel not found: ${channelName}`);
@@ -54,7 +54,10 @@ export const runChannelConnect = async ({ singletonServices, channelId, channelO
54
54
  channelHandlerFactory,
55
55
  channelName: channelConfig.name,
56
56
  });
57
- const wire = { channel, session: userSession };
57
+ const wire = {
58
+ channel,
59
+ ...createMiddlewareSessionWireProps(userSession),
60
+ };
58
61
  if (createWireServices) {
59
62
  wireServices = await createWireServices(singletonServices, wire);
60
63
  }
@@ -71,6 +74,7 @@ export const runChannelConnect = async ({ singletonServices, channelId, channelO
71
74
  services,
72
75
  channel,
73
76
  data: openingData,
77
+ channelMiddlewareMeta: meta.channelMiddleware,
74
78
  });
75
79
  }
76
80
  http?.response?.status(101);
@@ -106,7 +110,10 @@ export const runChannelDisconnect = async ({ singletonServices, ...params }) =>
106
110
  });
107
111
  const userSession = new PikkuSessionService(params.channelStore, params.channelId);
108
112
  userSession.setInitial(session);
109
- const wire = { channel, session: userSession };
113
+ const wire = {
114
+ channel,
115
+ ...createMiddlewareSessionWireProps(userSession),
116
+ };
110
117
  if (!wireServices && params.createWireServices) {
111
118
  wireServices = await params.createWireServices(singletonServices, wire);
112
119
  }
@@ -123,6 +130,7 @@ export const runChannelDisconnect = async ({ singletonServices, ...params }) =>
123
130
  lifecycleType: 'disconnect',
124
131
  services,
125
132
  channel,
133
+ channelMiddlewareMeta: meta.channelMiddleware,
126
134
  });
127
135
  }
128
136
  catch (e) {
@@ -144,7 +152,10 @@ export const runChannelMessage = async ({ singletonServices, ...params }, data)
144
152
  });
145
153
  const userSession = new PikkuSessionService(params.channelStore, params.channelId);
146
154
  userSession.setInitial(session);
147
- const wire = { channel, session: userSession };
155
+ const wire = {
156
+ channel,
157
+ ...createMiddlewareSessionWireProps(userSession),
158
+ };
148
159
  if (params.createWireServices) {
149
160
  wireServices = await params.createWireServices(singletonServices, wire);
150
161
  }
@@ -12,10 +12,11 @@ const defaultJSONRenderer = (_services, data) => {
12
12
  */
13
13
  export async function executeCLIViaChannel({ programName, pikkuWS, args = process.argv.slice(2), renderers = {}, defaultRenderer, }) {
14
14
  // Get CLI metadata from state
15
- const allCLIMeta = pikkuState('cli', 'meta');
16
- if (!allCLIMeta) {
15
+ const cliMeta = pikkuState(null, 'cli', 'meta');
16
+ if (!cliMeta || !('programs' in cliMeta)) {
17
17
  throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/docs/pikku-cli/errors/pku342 for more information.');
18
18
  }
19
+ const allCLIMeta = cliMeta;
19
20
  const programMeta = allCLIMeta.programs[programName];
20
21
  if (!programMeta) {
21
22
  console.error(`Error: CLI program "${programName}" not found`);
@@ -1 +1 @@
1
- export * from './cli-channel-runner.js';
1
+ export { executeCLIViaChannel } from './cli-channel-runner.js';
@@ -1 +1 @@
1
- export * from './cli-channel-runner.js';
1
+ export { executeCLIViaChannel } from './cli-channel-runner.js';
@@ -36,7 +36,7 @@ export declare const pikkuCLIRender: <Data, Services extends CoreSingletonServic
36
36
  export declare function executeCLI({ programName, args, createConfig, createSingletonServices, createWireServices, }: {
37
37
  programName: string;
38
38
  args?: string[];
39
- createConfig: CreateConfig<any, any>;
39
+ createConfig?: CreateConfig<any, any>;
40
40
  createSingletonServices: CreateSingletonServices<any, any>;
41
41
  createWireServices?: CreateWireServices<any, any, any>;
42
42
  }): Promise<void>;
@@ -1,7 +1,7 @@
1
- import { NotFoundError } from '../../errors/errors.js';
1
+ import { NotFoundError, PikkuMissingMetaError } from '../../errors/errors.js';
2
2
  import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
3
3
  import { pikkuState } from '../../pikku-state.js';
4
- import { PikkuSessionService } from '../../services/user-session-service.js';
4
+ import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../services/user-session-service.js';
5
5
  import { LocalVariablesService } from '../../services/local-variables.js';
6
6
  import { generateCommandHelp, parseCLIArguments } from './command-parser.js';
7
7
  /**
@@ -27,12 +27,12 @@ const defaultJSONRenderer = (_services, data) => {
27
27
  */
28
28
  export const wireCLI = (cli) => {
29
29
  // Get the existing metadata that was generated during inspection
30
- const cliMeta = pikkuState('cli', 'meta') || {};
30
+ const cliMeta = pikkuState(null, 'cli', 'meta') || {};
31
31
  if (!cliMeta.programs?.[cli.program]) {
32
- throw new Error(`CLI metadata not found for program '${cli.program}'. Did you run 'pikku all'?`);
32
+ throw new PikkuMissingMetaError(`CLI metadata not found for program '${cli.program}'`);
33
33
  }
34
34
  // Get existing programs state and add this program
35
- const programs = pikkuState('cli', 'programs') || {};
35
+ const programs = pikkuState(null, 'cli', 'programs') || {};
36
36
  programs[cli.program] = {
37
37
  defaultRenderer: (cli.render ||
38
38
  defaultJSONRenderer),
@@ -40,7 +40,7 @@ export const wireCLI = (cli) => {
40
40
  renderers: {},
41
41
  tags: cli.tags,
42
42
  };
43
- pikkuState('cli', 'programs', programs);
43
+ pikkuState(null, 'cli', 'programs', programs);
44
44
  // Register all command functions recursively
45
45
  registerCLICommands(cli.commands, [], cli.options || {}, cli.program);
46
46
  };
@@ -72,7 +72,7 @@ function unwrapFunc(command) {
72
72
  */
73
73
  function registerCLICommands(commands, path = [], inheritedOptions = {}, program) {
74
74
  // Get the CLI metadata to find actual function names
75
- const cliMeta = pikkuState('cli', 'meta').programs[program];
75
+ const cliMeta = pikkuState(null, 'cli', 'meta').programs[program];
76
76
  for (const [name, command] of Object.entries(commands)) {
77
77
  const fullPath = [...path, name];
78
78
  const commandId = fullPath.join('.');
@@ -81,7 +81,7 @@ function registerCLICommands(commands, path = [], inheritedOptions = {}, program
81
81
  for (let i = 1; i < fullPath.length; i++) {
82
82
  currentMeta = currentMeta?.subcommands?.[fullPath[i]];
83
83
  }
84
- const funcName = currentMeta?.pikkuFuncName;
84
+ const funcName = currentMeta?.pikkuFuncId;
85
85
  // Skip if no function name (could be a command group)
86
86
  if (!funcName) {
87
87
  // Recursively register subcommands if they exist
@@ -96,7 +96,7 @@ function registerCLICommands(commands, path = [], inheritedOptions = {}, program
96
96
  const commandOptions = typeof command === 'object' ? command.options || {} : {};
97
97
  const mergedOptions = { ...inheritedOptions, ...commandOptions };
98
98
  // Store the options and middleware in program state for use during execution
99
- const programs = pikkuState('cli', 'programs');
99
+ const programs = pikkuState(null, 'cli', 'programs');
100
100
  if (programs[program]) {
101
101
  if (!programs[program].commandOptions) {
102
102
  programs[program].commandOptions = {};
@@ -127,10 +127,10 @@ function registerCLICommands(commands, path = [], inheritedOptions = {}, program
127
127
  * Plucks only the data that the function expects based on its schema
128
128
  */
129
129
  function pluckCLIData(mergedData, funcName, availableOptions) {
130
- const funcMeta = pikkuState('function', 'meta')[funcName];
130
+ const funcMeta = pikkuState(null, 'function', 'meta')[funcName];
131
131
  const schemaName = funcMeta?.inputSchemaName;
132
132
  const schema = schemaName
133
- ? pikkuState('misc', 'schemas').get(schemaName)
133
+ ? pikkuState(null, 'misc', 'schemas').get(schemaName)
134
134
  : null;
135
135
  if (schema && schema.properties) {
136
136
  // If we have a schema, only include fields that are in the schema
@@ -156,7 +156,7 @@ function pluckCLIData(mergedData, funcName, availableOptions) {
156
156
  */
157
157
  export async function runCLICommand({ program, commandPath, data, singletonServices, createWireServices, }) {
158
158
  // Get the command metadata to find the function name
159
- const cliMeta = pikkuState('cli', 'meta');
159
+ const cliMeta = pikkuState(null, 'cli', 'meta');
160
160
  const programMeta = cliMeta.programs?.[program];
161
161
  if (!programMeta) {
162
162
  throw new NotFoundError(`Program not found: ${program}`);
@@ -173,9 +173,9 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
173
173
  }
174
174
  currentCommand = currentCommand.subcommands[commandPath[i]];
175
175
  }
176
- const funcName = currentCommand.pikkuFuncName;
176
+ const funcName = currentCommand.pikkuFuncId;
177
177
  // Get program-specific data
178
- const programs = pikkuState('cli', 'programs') || {};
178
+ const programs = pikkuState(null, 'cli', 'programs') || {};
179
179
  const programData = programs[program];
180
180
  // Combine program middleware + command middleware from the hierarchy
181
181
  const allWireMiddleware = [
@@ -222,7 +222,7 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
222
222
  data: pluckedData,
223
223
  channel,
224
224
  },
225
- session: userSession,
225
+ ...createMiddlewareSessionWireProps(userSession),
226
226
  };
227
227
  try {
228
228
  const result = await runPikkuFunc('cli', commandId, funcName, {
@@ -236,9 +236,11 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
236
236
  wirePermissions: undefined,
237
237
  tags: programData?.tags,
238
238
  wire,
239
+ sessionService: userSession,
239
240
  });
240
241
  // Apply renderer one final time with the final output (if renderer exists)
241
- if (renderer) {
242
+ // Skip if result is undefined (void functions handle their own output)
243
+ if (renderer && result !== undefined) {
242
244
  await Promise.resolve(renderer(singletonServices, result, userSession.get()));
243
245
  }
244
246
  return result;
@@ -266,7 +268,7 @@ export async function executeCLI({ programName, args, createConfig, createSingle
266
268
  }
267
269
  try {
268
270
  // Get CLI metadata from state
269
- const allCLIMeta = pikkuState('cli', 'meta');
271
+ const allCLIMeta = pikkuState(null, 'cli', 'meta');
270
272
  if (!allCLIMeta) {
271
273
  throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/docs/pikku-cli/errors/pku342 for more information.');
272
274
  }
@@ -306,7 +308,9 @@ export async function executeCLI({ programName, args, createConfig, createSingle
306
308
  // Merge positionals and options into single data object
307
309
  const data = { ...parsed.positionals, ...parsed.options };
308
310
  // Create config (pass data in case it needs to use any parsed options)
309
- const config = await createConfig(new LocalVariablesService(), data);
311
+ const config = createConfig
312
+ ? await createConfig(new LocalVariablesService(), data)
313
+ : {};
310
314
  // Create services with config
311
315
  const singletonServices = await createSingletonServices(config);
312
316
  // Execute the command
@@ -51,7 +51,7 @@ export interface CLIProgramState {
51
51
  */
52
52
  export interface CLICommandMeta {
53
53
  parameters?: string;
54
- pikkuFuncName: string;
54
+ pikkuFuncId: string;
55
55
  positionals: CLIPositional[];
56
56
  options: Record<string, CLIOption>;
57
57
  renderName?: string;
@@ -100,7 +100,7 @@ export type CorePikkuCLIRender<Data, Services extends CoreSingletonServices = Co
100
100
  /**
101
101
  * Extract input parameters from a Pikku function config type
102
102
  */
103
- export type ExtractFunctionInput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<infer Input, any, any, any> | CorePikkuFunctionSessionless<infer Input, any, any, any> ? Input : never : never;
103
+ export type ExtractFunctionInput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<infer Input, any, any, any, any> | CorePikkuFunctionSessionless<infer Input, any, any, any, any> ? Input : never : never;
104
104
  /**
105
105
  * Strip < > [ ] characters from a string
106
106
  */
@@ -132,7 +132,7 @@ export type ValidateParameters<Params extends string, Input> = AllParamsValid<Ex
132
132
  /**
133
133
  * Extract output type from a Pikku function config type
134
134
  */
135
- export type ExtractFunctionOutput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<any, infer Output, any, any> | CorePikkuFunctionSessionless<any, infer Output, any, any> ? Output : never : never;
135
+ export type ExtractFunctionOutput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<any, infer Output, any, any, any> | CorePikkuFunctionSessionless<any, infer Output, any, any, any> ? Output : never : never;
136
136
  /**
137
137
  * CLI command configuration that infers options from function input type.
138
138
  * This is a helper type for creating type-safe CLI commands.
@@ -140,6 +140,7 @@ export type ExtractFunctionOutput<Func> = Func extends CorePikkuFunctionConfig<i
140
140
  export type CoreCLICommandConfig<FuncConfig, PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<any, any>, PikkuCLIRender extends CorePikkuCLIRender<any, any, any> = CorePikkuCLIRender<any, any>, Params extends string = string> = {
141
141
  parameters?: ValidateParameters<Params, ExtractFunctionInput<FuncConfig>>;
142
142
  func?: FuncConfig;
143
+ title?: string;
143
144
  description?: string;
144
145
  render?: PikkuCLIRender;
145
146
  options?: {
@@ -158,7 +159,7 @@ export type CoreCLICommandConfig<FuncConfig, PikkuMiddleware extends CorePikkuMi
158
159
  /**
159
160
  * CLI command definition
160
161
  */
161
- export interface CoreCLICommand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any> | CorePikkuFunctionSessionless<In, Out, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> {
162
+ export interface CoreCLICommand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> {
162
163
  parameters?: string;
163
164
  func: PikkuFunctionConfig;
164
165
  render?: CorePikkuCLIRender<Out>;
@@ -176,11 +177,11 @@ export interface CoreCLICommand<In, Out, PikkuFunctionConfig extends CorePikkuFu
176
177
  /**
177
178
  * Shorthand command definition (just a function)
178
179
  */
179
- export type CLICommandShorthand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any> | CorePikkuFunctionSessionless<In, Out, any, any>>> = PikkuFunctionConfig;
180
+ export type CLICommandShorthand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>> = PikkuFunctionConfig;
180
181
  /**
181
182
  * Command definition (either full or shorthand)
182
183
  */
183
- export type CLICommandDefinition<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any> | CorePikkuFunctionSessionless<In, Out, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> = CoreCLICommand<In, Out, PikkuFunctionConfig, PikkuPermission, PikkuMiddleware, Options, Subcommands> | CLICommandShorthand<In, Out, PikkuFunctionConfig>;
184
+ export type CLICommandDefinition<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> = CoreCLICommand<In, Out, PikkuFunctionConfig, PikkuPermission, PikkuMiddleware, Options, Subcommands> | CLICommandShorthand<In, Out, PikkuFunctionConfig>;
184
185
  /**
185
186
  * CLI wiring configuration
186
187
  */
@@ -0,0 +1,19 @@
1
+ import type { CoreCLICommandConfig } from './cli.types.js';
2
+ /**
3
+ * Type-safe helper for defining CLI commands that can be composed.
4
+ * Returns the commands record as-is (identity function) for use with `wireCLI`.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * export const chatCommands = defineCLICommands({
9
+ * chat: pikkuCLICommand({ func: chatFunc }),
10
+ * 'chat:history': pikkuCLICommand({ func: historyFunc }),
11
+ * })
12
+ *
13
+ * wireCLI({
14
+ * program: 'my-app',
15
+ * commands: { ...chatCommands, other: pikkuCLICommand({ func: otherFunc }) }
16
+ * })
17
+ * ```
18
+ */
19
+ export declare function defineCLICommands<T extends Record<string, CoreCLICommandConfig<any, any, any, any>>>(commands: T): T;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Type-safe helper for defining CLI commands that can be composed.
3
+ * Returns the commands record as-is (identity function) for use with `wireCLI`.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * export const chatCommands = defineCLICommands({
8
+ * chat: pikkuCLICommand({ func: chatFunc }),
9
+ * 'chat:history': pikkuCLICommand({ func: historyFunc }),
10
+ * })
11
+ *
12
+ * wireCLI({
13
+ * program: 'my-app',
14
+ * commands: { ...chatCommands, other: pikkuCLICommand({ func: otherFunc }) }
15
+ * })
16
+ * ```
17
+ */
18
+ export function defineCLICommands(commands) {
19
+ return commands;
20
+ }
@@ -1,5 +1,4 @@
1
- export * from './cli.types.js';
2
- export * from './cli-runner.js';
3
- export * from './command-parser.js';
4
1
  export { wireCLI, runCLICommand, pikkuCLIRender, executeCLI, CLIError, } from './cli-runner.js';
5
2
  export { parseCLIArguments, generateCommandHelp } from './command-parser.js';
3
+ export { defineCLICommands } from './define-cli-commands.js';
4
+ export type { CLIMeta, CLICommandMeta, CLIProgramMeta, CoreCLI, CoreCLICommandConfig, CorePikkuCLIRender, } from './cli.types.js';
@@ -1,5 +1,3 @@
1
- export * from './cli.types.js';
2
- export * from './cli-runner.js';
3
- export * from './command-parser.js';
4
1
  export { wireCLI, runCLICommand, pikkuCLIRender, executeCLI, CLIError, } from './cli-runner.js';
5
2
  export { parseCLIArguments, generateCommandHelp } from './command-parser.js';
3
+ export { defineCLICommands } from './define-cli-commands.js';
@@ -0,0 +1,69 @@
1
+ import type { HTTPRouteMap, HTTPRouteContract, HTTPRoutesGroupConfig, WireHTTPRoutesConfig } from './http.types.js';
2
+ /**
3
+ * Type-safe helper for defining route contracts that can be composed.
4
+ * Supports optional group-level config that cascades to all routes.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // Simple routes without group config
9
+ * export const todosRoutes = defineHTTPRoutes({
10
+ * list: { method: 'get', route: '/todos', func: listTodos },
11
+ * get: { method: 'get', route: '/todos/:id', func: getTodo },
12
+ * })
13
+ *
14
+ * // Routes with group-level config
15
+ * export const todosRoutes = defineHTTPRoutes({
16
+ * auth: true,
17
+ * tags: ['todos'],
18
+ * routes: {
19
+ * list: { method: 'get', route: '/todos', func: listTodos },
20
+ * get: { method: 'get', route: '/todos/:id', func: getTodo },
21
+ * }
22
+ * })
23
+ * ```
24
+ */
25
+ export declare function defineHTTPRoutes<T extends HTTPRouteMap>(routes: T): HTTPRouteContract<T>;
26
+ export declare function defineHTTPRoutes<T extends HTTPRouteMap>(config: HTTPRoutesGroupConfig & {
27
+ routes: T;
28
+ }): HTTPRouteContract<T>;
29
+ /**
30
+ * Wires multiple HTTP routes from a nested map or array configuration.
31
+ * Inspired by ts-rest's contract pattern, provides a single place to wire an entire API.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Nested object format
36
+ * wireHTTPRoutes({
37
+ * basePath: '/api/v1',
38
+ * tags: ['api'],
39
+ * routes: {
40
+ * todos: {
41
+ * list: { method: 'get', route: '/todos', func: listTodos },
42
+ * get: { method: 'get', route: '/todos/:id', func: getTodo },
43
+ * },
44
+ * auth: {
45
+ * login: { method: 'post', route: '/auth/login', func: login, auth: false },
46
+ * },
47
+ * },
48
+ * })
49
+ *
50
+ * // Flat array format
51
+ * wireHTTPRoutes({
52
+ * basePath: '/api',
53
+ * routes: [
54
+ * { method: 'get', route: '/todos', func: listTodos },
55
+ * { method: 'post', route: '/todos', func: createTodo },
56
+ * ],
57
+ * })
58
+ *
59
+ * // Composing route contracts
60
+ * wireHTTPRoutes({
61
+ * basePath: '/api/v1',
62
+ * routes: {
63
+ * todos: todosRoutes, // from defineHTTPRoutes()
64
+ * auth: authRoutes, // from defineHTTPRoutes()
65
+ * },
66
+ * })
67
+ * ```
68
+ */
69
+ export declare const wireHTTPRoutes: (config: WireHTTPRoutesConfig) => void;