@pikku/cli 0.9.16-next.0 → 0.10.1

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 (268) hide show
  1. package/.pikku/channel/pikku-channel-types.gen.ts +28 -29
  2. package/.pikku/channel/pikku-channels-map.gen.d.ts +44 -0
  3. package/.pikku/channel/pikku-channels-meta.gen.ts +5 -0
  4. package/.pikku/channel/pikku-channels.gen.ts +4 -0
  5. package/.pikku/cli/pikku-cli-channel.gen.ts +34 -0
  6. package/.pikku/cli/pikku-cli-client.gen.ts +43 -0
  7. package/.pikku/cli/pikku-cli-types.gen.ts +14 -15
  8. package/.pikku/cli/pikku-cli-wirings-meta.gen.ts +142 -2
  9. package/.pikku/cli/pikku-cli-wirings.gen.ts +4 -2
  10. package/.pikku/cli/pikku-cli.gen.ts +41 -0
  11. package/.pikku/function/pikku-function-types.gen.ts +167 -19
  12. package/.pikku/function/pikku-functions-meta.gen.ts +220 -192
  13. package/.pikku/function/pikku-functions-meta.min.gen.ts +61 -56
  14. package/.pikku/function/pikku-functions.gen.ts +3 -1
  15. package/.pikku/http/pikku-http-types.gen.ts +28 -3
  16. package/.pikku/http/pikku-http-wirings-map.gen.d.ts +43 -0
  17. package/.pikku/http/pikku-http-wirings-meta.gen.ts +13 -0
  18. package/.pikku/http/pikku-http-wirings.gen.ts +4 -0
  19. package/.pikku/mcp/pikku-mcp-types.gen.ts +15 -13
  20. package/.pikku/mcp/pikku-mcp-wirings-meta.gen.ts +7 -0
  21. package/.pikku/mcp/pikku-mcp-wirings.gen.ts +4 -0
  22. package/.pikku/mcp/pikku-mcp.gen.json +5 -0
  23. package/.pikku/pikku-bootstrap.gen.ts +11 -1
  24. package/.pikku/pikku-services.gen.ts +1 -5
  25. package/.pikku/pikku-types.gen.ts +1 -2
  26. package/.pikku/pikku-websocket.gen.ts +76 -0
  27. package/.pikku/queue/pikku-queue-types.gen.ts +1 -2
  28. package/.pikku/queue/pikku-queue-workers-wirings-map.gen.d.ts +57 -0
  29. package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.ts +5 -0
  30. package/.pikku/queue/pikku-queue-workers-wirings.gen.ts +4 -0
  31. package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +5 -4
  32. package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +19 -17
  33. package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +15 -14
  34. package/.pikku/scheduler/pikku-scheduler-types.gen.ts +1 -2
  35. package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.ts +5 -0
  36. package/.pikku/scheduler/pikku-schedulers-wirings.gen.ts +4 -0
  37. package/.pikku/schemas/register.gen.ts +15 -11
  38. package/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  39. package/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
  40. package/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
  41. package/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
  42. package/CHANGELOG.md +15 -0
  43. package/bin/pikku.ts +63 -11
  44. package/build.sh +1 -1
  45. package/cli.schema.json +1 -1
  46. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +11 -20
  47. package/dist/.pikku/channel/pikku-channel-types.gen.js +9 -11
  48. package/dist/.pikku/channel/pikku-channels-meta.gen.d.ts +1 -0
  49. package/dist/.pikku/channel/pikku-channels-meta.gen.js +5 -0
  50. package/dist/.pikku/channel/pikku-channels.gen.d.ts +4 -0
  51. package/dist/.pikku/channel/pikku-channels.gen.js +5 -0
  52. package/dist/.pikku/cli/pikku-cli-channel.gen.d.ts +1 -0
  53. package/dist/.pikku/cli/pikku-cli-channel.gen.js +33 -0
  54. package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +10 -0
  55. package/dist/.pikku/cli/pikku-cli-client.gen.js +34 -0
  56. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +9 -12
  57. package/dist/.pikku/cli/pikku-cli-types.gen.js +5 -4
  58. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +142 -2
  59. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +3 -2
  60. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +4 -3
  61. package/dist/.pikku/cli/pikku-cli.gen.d.ts +10 -0
  62. package/dist/.pikku/cli/pikku-cli.gen.js +38 -0
  63. package/dist/.pikku/function/pikku-function-types.gen.d.ts +141 -20
  64. package/dist/.pikku/function/pikku-function-types.gen.js +108 -12
  65. package/dist/.pikku/function/pikku-functions-meta.gen.js +220 -192
  66. package/dist/.pikku/function/pikku-functions-meta.min.gen.js +61 -56
  67. package/dist/.pikku/function/pikku-functions.gen.js +3 -1
  68. package/dist/.pikku/http/pikku-http-types.gen.d.ts +21 -2
  69. package/dist/.pikku/http/pikku-http-types.gen.js +24 -3
  70. package/dist/.pikku/http/pikku-http-wirings-meta.gen.d.ts +1 -0
  71. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +13 -0
  72. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +4 -0
  73. package/dist/.pikku/http/pikku-http-wirings.gen.js +5 -0
  74. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +11 -8
  75. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +6 -6
  76. package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.d.ts +1 -0
  77. package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +7 -0
  78. package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +4 -0
  79. package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +5 -0
  80. package/dist/.pikku/pikku-bootstrap.gen.d.ts +11 -1
  81. package/dist/.pikku/pikku-bootstrap.gen.js +11 -1
  82. package/dist/.pikku/pikku-services.gen.d.ts +1 -4
  83. package/dist/.pikku/pikku-services.gen.js +0 -6
  84. package/dist/.pikku/pikku-types.gen.d.ts +1 -2
  85. package/dist/.pikku/pikku-types.gen.js +1 -2
  86. package/dist/.pikku/pikku-websocket.gen.d.ts +31 -0
  87. package/dist/.pikku/pikku-websocket.gen.js +49 -0
  88. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -2
  89. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -2
  90. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.d.ts +1 -0
  91. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +5 -0
  92. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +4 -0
  93. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +5 -0
  94. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +15 -14
  95. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -2
  96. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -2
  97. package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.d.ts +1 -0
  98. package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +5 -0
  99. package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +4 -0
  100. package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +5 -0
  101. package/dist/.pikku/schemas/register.gen.js +9 -7
  102. package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  103. package/dist/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
  104. package/dist/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
  105. package/dist/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
  106. package/dist/bin/pikku.d.ts +1 -1
  107. package/dist/bin/pikku.js +37 -6
  108. package/dist/src/cli.wiring.js +99 -75
  109. package/dist/src/functions/commands/all.js +10 -0
  110. package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +10 -8
  111. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts +1 -1
  112. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +2 -2
  113. package/dist/src/functions/wirings/channels/pikku-channels.js +0 -5
  114. package/dist/src/functions/wirings/channels/pikku-command-channel-types.js +0 -2
  115. package/dist/src/functions/wirings/channels/pikku-command-channels-map.js +0 -5
  116. package/dist/src/functions/wirings/channels/pikku-command-channels.js +0 -5
  117. package/dist/src/functions/wirings/channels/pikku-command-websocket-typed.js +6 -3
  118. package/dist/src/functions/wirings/channels/serialize-channel-types.js +27 -28
  119. package/dist/src/functions/wirings/channels/serialize-typed-channel-map.js +4 -1
  120. package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +31 -8
  121. package/dist/src/functions/wirings/cli/pikku-command-cli-types.js +0 -2
  122. package/dist/src/functions/wirings/cli/pikku-command-cli.js +0 -2
  123. package/dist/src/functions/wirings/cli/serialize-channel-cli-client.d.ts +6 -2
  124. package/dist/src/functions/wirings/cli/serialize-channel-cli-client.js +88 -11
  125. package/dist/src/functions/wirings/cli/serialize-channel-cli.d.ts +1 -1
  126. package/dist/src/functions/wirings/cli/serialize-channel-cli.js +1 -18
  127. package/dist/src/functions/wirings/cli/serialize-cli-types.js +13 -14
  128. package/dist/src/functions/wirings/cli/serialize-local-cli-bootstrap.js +19 -14
  129. package/dist/src/functions/wirings/fetch/index.js +6 -3
  130. package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +6 -5
  131. package/dist/src/functions/wirings/functions/pikku-command-function-types.js +0 -2
  132. package/dist/src/functions/wirings/functions/pikku-command-functions.js +0 -2
  133. package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
  134. package/dist/src/functions/wirings/functions/pikku-command-services.js +11 -21
  135. package/dist/src/functions/wirings/functions/pikku-function-types.js +0 -2
  136. package/dist/src/functions/wirings/functions/schemas.js +0 -2
  137. package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
  138. package/dist/src/functions/wirings/functions/serialize-function-types.js +167 -19
  139. package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +0 -1
  140. package/dist/src/functions/wirings/http/openapi-spec-generator.d.ts +2 -1
  141. package/dist/src/functions/wirings/http/pikku-command-http-map.js +0 -5
  142. package/dist/src/functions/wirings/http/pikku-command-http-routes.js +0 -5
  143. package/dist/src/functions/wirings/http/pikku-command-http-types.js +0 -2
  144. package/dist/src/functions/wirings/http/pikku-command-openapi.js +7 -4
  145. package/dist/src/functions/wirings/http/pikku-http-routes.js +0 -5
  146. package/dist/src/functions/wirings/http/serialize-http-types.js +27 -2
  147. package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.js +0 -5
  148. package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.js +0 -2
  149. package/dist/src/functions/wirings/mcp/pikku-command-mcp.js +0 -5
  150. package/dist/src/functions/wirings/mcp/serialize-mcp-json.d.ts +1 -1
  151. package/dist/src/functions/wirings/mcp/serialize-mcp-types.js +14 -12
  152. package/dist/src/functions/wirings/middleware/pikku-command-middleware.js +0 -2
  153. package/dist/src/functions/wirings/middleware/serialize-middleware-groups-meta.js +1 -7
  154. package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -0
  155. package/dist/src/functions/wirings/permissions/pikku-command-permissions.js +28 -0
  156. package/dist/src/functions/wirings/permissions/serialize-permissions-imports.d.ts +2 -0
  157. package/dist/src/functions/wirings/permissions/serialize-permissions-imports.js +43 -0
  158. package/dist/src/functions/wirings/queue/pikku-command-queue-map.js +0 -5
  159. package/dist/src/functions/wirings/queue/pikku-command-queue-service.js +6 -3
  160. package/dist/src/functions/wirings/queue/pikku-command-queue-types.js +0 -2
  161. package/dist/src/functions/wirings/queue/pikku-command-queue.js +0 -5
  162. package/dist/src/functions/wirings/queue/pikku-queue-map.js +0 -5
  163. package/dist/src/functions/wirings/queue/pikku-queue.js +1 -5
  164. package/dist/src/functions/wirings/queue/serialize-queue-meta.d.ts +1 -1
  165. package/dist/src/functions/wirings/queue/serialize-queue-types.js +0 -1
  166. package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.js +5 -3
  167. package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +0 -4
  168. package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +0 -2
  169. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.js +0 -2
  170. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.js +0 -5
  171. package/dist/src/functions/wirings/scheduler/serialize-scheduler-types.js +0 -1
  172. package/dist/src/middleware/log-command-info-and-time.d.ts +2 -8
  173. package/dist/src/middleware/log-command-info-and-time.js +2 -14
  174. package/dist/src/services/cli-logger-forwarder.service.d.ts +6 -2
  175. package/dist/src/services/cli-logger-forwarder.service.js +9 -0
  176. package/dist/src/services/cli-logger.service.d.ts +4 -0
  177. package/dist/src/services/cli-logger.service.js +11 -0
  178. package/dist/src/services.d.ts +5 -0
  179. package/dist/src/services.js +111 -13
  180. package/dist/src/utils/check-required-types.js +11 -1
  181. package/dist/src/utils/custom-types-generator.js +8 -2
  182. package/dist/src/utils/file-writer.d.ts +4 -1
  183. package/dist/src/utils/file-writer.js +13 -3
  184. package/dist/src/utils/get-cli-version.d.ts +5 -0
  185. package/dist/src/utils/get-cli-version.js +27 -0
  186. package/dist/src/utils/pikku-cli-config.d.ts +1 -2
  187. package/dist/src/utils/pikku-cli-config.js +9 -28
  188. package/dist/src/utils/schema-generator.js +3 -2
  189. package/dist/src/utils/serialize-import-map.js +0 -3
  190. package/dist/tsconfig.tsbuildinfo +1 -1
  191. package/package.json +10 -8
  192. package/pikku.config.json +4 -2
  193. package/src/cli.wiring.ts +101 -74
  194. package/src/functions/commands/all.ts +12 -0
  195. package/src/functions/runtimes/nextjs/pikku-command-nextjs.ts +12 -12
  196. package/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +2 -2
  197. package/src/functions/wirings/channels/pikku-channels.ts +0 -5
  198. package/src/functions/wirings/channels/pikku-command-channel-types.ts +0 -2
  199. package/src/functions/wirings/channels/pikku-command-channels-map.ts +0 -5
  200. package/src/functions/wirings/channels/pikku-command-channels.ts +0 -5
  201. package/src/functions/wirings/channels/pikku-command-websocket-typed.ts +7 -3
  202. package/src/functions/wirings/channels/serialize-channel-types.ts +27 -28
  203. package/src/functions/wirings/channels/serialize-typed-channel-map.ts +4 -1
  204. package/src/functions/wirings/cli/pikku-command-cli-entry.ts +52 -9
  205. package/src/functions/wirings/cli/pikku-command-cli-types.ts +0 -2
  206. package/src/functions/wirings/cli/pikku-command-cli.ts +0 -2
  207. package/src/functions/wirings/cli/serialize-channel-cli-client.ts +111 -12
  208. package/src/functions/wirings/cli/serialize-channel-cli.ts +2 -23
  209. package/src/functions/wirings/cli/serialize-cli-types.ts +13 -14
  210. package/src/functions/wirings/cli/serialize-local-cli-bootstrap.ts +19 -14
  211. package/src/functions/wirings/fetch/index.ts +7 -3
  212. package/src/functions/wirings/functions/pikku-command-function-types-split.ts +14 -5
  213. package/src/functions/wirings/functions/pikku-command-function-types.ts +0 -2
  214. package/src/functions/wirings/functions/pikku-command-functions.ts +0 -2
  215. package/src/functions/wirings/functions/pikku-command-services.ts +13 -24
  216. package/src/functions/wirings/functions/pikku-function-types.ts +0 -2
  217. package/src/functions/wirings/functions/schemas.ts +0 -2
  218. package/src/functions/wirings/functions/serialize-function-types.ts +169 -19
  219. package/src/functions/wirings/functions/serialize-pikku-types-hub.ts +0 -1
  220. package/src/functions/wirings/http/openapi-spec-generator.ts +2 -1
  221. package/src/functions/wirings/http/pikku-command-http-map.ts +0 -5
  222. package/src/functions/wirings/http/pikku-command-http-routes.ts +0 -5
  223. package/src/functions/wirings/http/pikku-command-http-types.ts +0 -2
  224. package/src/functions/wirings/http/pikku-command-openapi.ts +9 -4
  225. package/src/functions/wirings/http/pikku-http-routes.ts +0 -5
  226. package/src/functions/wirings/http/serialize-http-types.ts +27 -2
  227. package/src/functions/wirings/mcp/pikku-command-mcp-json.ts +0 -5
  228. package/src/functions/wirings/mcp/pikku-command-mcp-types.ts +0 -2
  229. package/src/functions/wirings/mcp/pikku-command-mcp.ts +0 -5
  230. package/src/functions/wirings/mcp/serialize-mcp-json.ts +1 -1
  231. package/src/functions/wirings/mcp/serialize-mcp-types.ts +14 -12
  232. package/src/functions/wirings/middleware/pikku-command-middleware.ts +0 -2
  233. package/src/functions/wirings/middleware/serialize-middleware-groups-meta.ts +1 -7
  234. package/src/functions/wirings/permissions/pikku-command-permissions.ts +49 -0
  235. package/src/functions/wirings/permissions/serialize-permissions-imports.test.ts +274 -0
  236. package/src/functions/wirings/permissions/serialize-permissions-imports.ts +78 -0
  237. package/src/functions/wirings/queue/pikku-command-queue-map.ts +0 -5
  238. package/src/functions/wirings/queue/pikku-command-queue-service.ts +7 -3
  239. package/src/functions/wirings/queue/pikku-command-queue-types.ts +0 -2
  240. package/src/functions/wirings/queue/pikku-command-queue.ts +0 -5
  241. package/src/functions/wirings/queue/pikku-queue-map.ts +0 -5
  242. package/src/functions/wirings/queue/pikku-queue.ts +3 -6
  243. package/src/functions/wirings/queue/serialize-queue-meta.ts +1 -1
  244. package/src/functions/wirings/queue/serialize-queue-types.ts +0 -1
  245. package/src/functions/wirings/rpc/pikku-command-rpc-client.ts +6 -3
  246. package/src/functions/wirings/rpc/pikku-command-rpc-map.ts +0 -4
  247. package/src/functions/wirings/rpc/pikku-command-rpc.ts +0 -2
  248. package/src/functions/wirings/scheduler/pikku-command-scheduler-types.ts +0 -2
  249. package/src/functions/wirings/scheduler/pikku-command-scheduler.ts +0 -5
  250. package/src/functions/wirings/scheduler/serialize-scheduler-types.ts +0 -1
  251. package/src/middleware/log-command-info-and-time.ts +2 -28
  252. package/src/services/cli-logger-forwarder.service.ts +15 -2
  253. package/src/services/cli-logger.service.ts +15 -0
  254. package/src/services.ts +148 -19
  255. package/src/utils/check-required-types.ts +16 -1
  256. package/src/utils/custom-types-generator.ts +8 -2
  257. package/src/utils/file-writer.ts +19 -3
  258. package/src/utils/get-cli-version.ts +28 -0
  259. package/src/utils/pikku-cli-config.ts +6 -35
  260. package/src/utils/schema-generator.ts +7 -3
  261. package/src/utils/serialize-import-map.ts +0 -4
  262. package/types/application-types.d.ts +4 -1
  263. package/types/config.d.ts +15 -3
  264. package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.d.ts +0 -6
  265. package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.js +0 -6
  266. package/dist/src/serialize-pikku-types.d.ts +0 -4
  267. package/dist/src/serialize-pikku-types.js +0 -605
  268. package/src/serialize-pikku-types.ts +0 -613
@@ -1,4 +1,6 @@
1
- import { Logger, LogLevel, PikkuChannel } from '@pikku/core'
1
+ import { Logger, LogLevel } from '@pikku/core'
2
+ import { PikkuChannel } from '@pikku/core/channel'
3
+ import { ErrorCode } from '@pikku/inspector'
2
4
 
3
5
  /**
4
6
  * Log message structure sent through the channel
@@ -18,7 +20,7 @@ export class CLILoggerForwarder implements Logger {
18
20
 
19
21
  constructor(
20
22
  private logger: Logger,
21
- private channel: PikkuChannel<unknown, ForwardedLogMessage>
23
+ private channel: PikkuChannel<unknown, any>
22
24
  ) {}
23
25
 
24
26
  setLevel(level: LogLevel): void {
@@ -74,4 +76,15 @@ export class CLILoggerForwarder implements Logger {
74
76
  trace(message: string, ..._meta: any[]) {
75
77
  this.log('trace', LogLevel.trace, message)
76
78
  }
79
+
80
+ critical(code: ErrorCode, message: string) {
81
+ const url = `https://pikku.dev/docs/cli-errors/${code.toLowerCase()}`
82
+ const formattedMessage = `[${code}] ${message}\n → ${url}`
83
+ this.error(formattedMessage)
84
+ }
85
+
86
+ hasCriticalErrors(): boolean {
87
+ // The underlying logger (CLILogger) tracks critical errors
88
+ return (this.logger as any).hasCriticalErrors?.() ?? false
89
+ }
77
90
  }
@@ -1,5 +1,6 @@
1
1
  import chalk from 'chalk'
2
2
  import { Logger, LogLevel } from '@pikku/core'
3
+ import { ErrorCode } from '@pikku/inspector'
3
4
 
4
5
  const logo = `
5
6
  ______ _ _ _
@@ -10,9 +11,12 @@ const logo = `
10
11
  |_| |_|_| _)_| _)____/
11
12
  `
12
13
 
14
+ const BASE_ERROR_URL = 'https://pikku.dev/errors'
15
+
13
16
  export class CLILogger implements Logger {
14
17
  private silent: boolean
15
18
  private level: LogLevel = LogLevel.info
19
+ private criticalErrors: string[] = []
16
20
 
17
21
  constructor({
18
22
  logLogo,
@@ -60,6 +64,17 @@ export class CLILogger implements Logger {
60
64
  console.log(chalk.gray(message))
61
65
  }
62
66
 
67
+ critical(code: ErrorCode, message: string) {
68
+ const url = `${BASE_ERROR_URL}/${code.toLowerCase()}`
69
+ const formattedMessage = `[${code}] ${message}\n → ${url}`
70
+ this.criticalErrors.push(formattedMessage)
71
+ console.error(chalk.red.bold(formattedMessage))
72
+ }
73
+
74
+ hasCriticalErrors(): boolean {
75
+ return this.criticalErrors.length > 0
76
+ }
77
+
63
78
  private logPikkuLogo() {
64
79
  this.primary(logo)
65
80
  // // When running from dist/, __filename is dist/src/services/cli-logger.service.js
package/src/services.ts CHANGED
@@ -8,12 +8,19 @@ import {
8
8
  CreateConfig,
9
9
  CreateSessionServices,
10
10
  CreateSingletonServices,
11
- pikkuCLIRender,
12
11
  } from '@pikku/core'
12
+ import { pikkuCLIRender } from '@pikku/core/cli'
13
13
  import { LocalVariablesService } from '@pikku/core/services'
14
14
  import { CLILogger } from './services/cli-logger.service.js'
15
15
  import { getPikkuCLIConfig } from './utils/pikku-cli-config.js'
16
- import { inspect, InspectorState } from '@pikku/inspector'
16
+ import {
17
+ inspect,
18
+ InspectorState,
19
+ InspectorFilters,
20
+ serializeInspectorState,
21
+ deserializeInspectorState,
22
+ filterInspectorState,
23
+ } from '@pikku/inspector'
17
24
  import { glob } from 'tinyglobby'
18
25
  import path from 'path'
19
26
  import { PikkuCLIConfig } from '../types/config.js'
@@ -21,9 +28,66 @@ import {
21
28
  CLILoggerForwarder,
22
29
  ForwardedLogMessage,
23
30
  } from './services/cli-logger-forwarder.service.js'
31
+ import { readFile, writeFile } from 'fs/promises'
24
32
 
25
33
  const logger = new CLILogger({ logLogo: true, silent: false })
26
34
 
35
+ /**
36
+ * Parse a comma-separated string or array into an array of trimmed, non-empty strings
37
+ * Returns undefined if the input is empty/undefined or results in an empty array
38
+ */
39
+ function parseCommaSeparated(
40
+ value: string | string[] | undefined
41
+ ): string[] | undefined {
42
+ if (!value) return undefined
43
+
44
+ // If already an array, flatten and split any comma-separated values
45
+ if (Array.isArray(value)) {
46
+ const flattened = value
47
+ .flatMap((item) => item.split(','))
48
+ .map((item) => item.trim())
49
+ .filter((item) => item.length > 0)
50
+ return flattened.length > 0 ? flattened : undefined
51
+ }
52
+
53
+ // If string, split by comma
54
+ const parsed = value
55
+ .split(',')
56
+ .map((item) => item.trim())
57
+ .filter((item) => item.length > 0)
58
+
59
+ return parsed.length > 0 ? parsed : undefined
60
+ }
61
+
62
+ /**
63
+ * Parse CLI filter arguments into InspectorFilters format
64
+ */
65
+ function parseCLIFilters(data: any): InspectorFilters {
66
+ const filters: InspectorFilters = {}
67
+
68
+ if (data.filters) {
69
+ return JSON.parse(data.filters)
70
+ }
71
+
72
+ // Parse each filter type from CLI arguments
73
+ const names = parseCommaSeparated(data.names)
74
+ const tags = parseCommaSeparated(data.tags)
75
+ const types = parseCommaSeparated(data.types)
76
+ const directories = parseCommaSeparated(data.directories)
77
+ const httpRoutes = parseCommaSeparated(data.httpRoutes)
78
+ const httpMethods = parseCommaSeparated(data.httpMethods)
79
+
80
+ // Only include non-undefined values in the result
81
+ if (names) filters.names = names
82
+ if (tags) filters.tags = tags
83
+ if (types) filters.types = types
84
+ if (directories) filters.directories = directories
85
+ if (httpRoutes) filters.httpRoutes = httpRoutes
86
+ if (httpMethods) filters.httpMethods = httpMethods
87
+
88
+ return filters
89
+ }
90
+
27
91
  /**
28
92
  * Default CLI renderer that logs output using the logger
29
93
  */
@@ -36,20 +100,50 @@ export const defaultCLIRenderer = pikkuCLIRender<
36
100
  }
37
101
  })
38
102
 
103
+ /**
104
+ * Client-safe CLI renderer that outputs to console (no service dependencies)
105
+ * This renderer can be used in CLI-over-channel clients
106
+ */
107
+ export const clientCLIRenderer = pikkuCLIRender<ForwardedLogMessage>(
108
+ (_services, data) => {
109
+ if (data) {
110
+ // Simple console output without service dependencies
111
+ const prefix = data.type ? `[${data.type}] ` : ''
112
+ console.log(`${prefix}${data.message}`)
113
+ }
114
+ }
115
+ )
116
+
39
117
  export const createConfig: CreateConfig<Config, [PikkuCLIConfig]> = async (
40
118
  _variablesService,
41
119
  data
42
120
  ) => {
43
- const cliConfig = await getPikkuCLIConfig(
44
- logger,
45
- data.configFile,
46
- [],
47
- data,
48
- true
49
- )
121
+ const cliConfig = await getPikkuCLIConfig(logger, data.configFile, [], true)
122
+
123
+ // Load inspector state from file if stateInput is provided
124
+ let preloadedInspectorState: Omit<InspectorState, 'typesLookup'> | undefined =
125
+ undefined
126
+
127
+ if (data.stateInput) {
128
+ try {
129
+ logger.info(`Loading inspector state from ${data.stateInput}`)
130
+ const stateJson = await readFile(data.stateInput, 'utf-8')
131
+ const serializedState = JSON.parse(stateJson)
132
+ preloadedInspectorState = deserializeInspectorState(serializedState)
133
+ logger.info(`Inspector state loaded successfully`)
134
+ } catch (error: any) {
135
+ logger.error(
136
+ `Failed to load inspector state from ${data.stateInput}: ${error.message}`
137
+ )
138
+ throw error
139
+ }
140
+ }
141
+
50
142
  return {
51
143
  ...cliConfig,
52
144
  ...data,
145
+ filters: parseCLIFilters(data),
146
+ preloadedInspectorState,
53
147
  }
54
148
  }
55
149
 
@@ -61,12 +155,25 @@ export const createSingletonServices: CreateSingletonServices<
61
155
  Config,
62
156
  SingletonServices
63
157
  > = async (config) => {
64
- const { rootDir, srcDirectories, filters } = config
158
+ const {
159
+ rootDir,
160
+ srcDirectories,
161
+ filters,
162
+ preloadedInspectorState,
163
+ stateOutput,
164
+ } = config
65
165
  const variables = new LocalVariablesService()
66
166
 
67
- let inspectorState: InspectorState | undefined = undefined
167
+ // Store unfiltered state
168
+ let unfilteredState:
169
+ | InspectorState
170
+ | Omit<InspectorState, 'typesLookup'>
171
+ | undefined = preloadedInspectorState
172
+
68
173
  const getInspectorState = async (refresh: boolean = false) => {
69
- if (refresh || !inspectorState) {
174
+ // Get or refresh the unfiltered state
175
+ if (!unfilteredState || refresh) {
176
+ // Run inspector WITHOUT filters to get full state
70
177
  const wiringFiles = (
71
178
  await Promise.all(
72
179
  srcDirectories.map((dir) =>
@@ -74,18 +181,40 @@ export const createSingletonServices: CreateSingletonServices<
74
181
  )
75
182
  )
76
183
  ).flat()
77
- inspectorState = await inspect(logger, wiringFiles, {
78
- filters,
184
+ unfilteredState = await inspect(logger, wiringFiles, {
185
+ // NO filters here - inspector returns full unfiltered state
79
186
  types: {
80
187
  configFileType: config.configFile,
81
- userSessionType: config.tags?.[0], // TODO: Properly handle type selection
82
- singletonServicesFactoryType: undefined,
83
- sessionServicesFactoryType: undefined,
188
+ userSessionType: config.userSessionType,
189
+ singletonServicesFactoryType: config.singletonServicesFactoryType,
190
+ sessionServicesFactoryType: config.sessionServicesFactoryType,
84
191
  },
85
192
  })
86
- return inspectorState
193
+
194
+ // Save unfiltered inspector state to file if stateOutput is provided
195
+ if (stateOutput && 'typesLookup' in unfilteredState) {
196
+ try {
197
+ logger.info(`Saving inspector state to ${stateOutput}`)
198
+ const serialized = serializeInspectorState(unfilteredState)
199
+ await writeFile(
200
+ stateOutput,
201
+ JSON.stringify(serialized, null, 2),
202
+ 'utf-8'
203
+ )
204
+ logger.info(`Inspector state saved successfully`)
205
+ } catch (error: any) {
206
+ logger.error(
207
+ `Failed to save inspector state to ${stateOutput}: ${error.message}`
208
+ )
209
+ // Don't throw - state saving is optional/nice-to-have
210
+ }
211
+ }
87
212
  }
88
- return inspectorState!
213
+
214
+ // Apply filters as a post-processing step
215
+ const filteredState = filterInspectorState(unfilteredState, filters, logger)
216
+
217
+ return filteredState as InspectorState
89
218
  }
90
219
 
91
220
  return {
@@ -13,8 +13,23 @@ export const checkRequiredTypes = (
13
13
  errors: FilesAndMethodsErrors,
14
14
  requires: RequiredTypes = {}
15
15
  ): void => {
16
+ // Filter out errors that are about missing Types when we have the corresponding Factory
17
+ // e.g., if we have a CreateConfig factory, we don't need a CoreConfig type
18
+ const errorMessages = Array.from(errors.keys())
19
+ const hasCreateConfigFactory = errorMessages.every(
20
+ (msg) => !msg.includes('No CreateConfig found')
21
+ )
22
+
16
23
  // Only throw if there are errors AND we require those types
17
- const hasRequiredErrors = Array.from(errors.keys()).some((message) => {
24
+ const hasRequiredErrors = errorMessages.some((message) => {
25
+ // Skip CoreConfig type errors if we have a CreateConfig factory
26
+ if (
27
+ requires.config &&
28
+ message.includes('No CoreConfig found') &&
29
+ hasCreateConfigFactory
30
+ ) {
31
+ return false
32
+ }
18
33
  if (requires.config && message.includes('CoreConfig')) return true
19
34
  if (requires.sessionServiceType && message.includes('CoreServices'))
20
35
  return true
@@ -9,8 +9,14 @@ export function generateCustomTypes(
9
9
  // or are broken into simpler types
10
10
  ${Array.from(typesMap.customTypes.entries())
11
11
  .map(([name, { type, references }]) => {
12
- references.forEach((name) => {
13
- requiredTypes.add(name)
12
+ references.forEach((refName) => {
13
+ // Skip __object types (including those with suffixes like __object_abc123)
14
+ // These are placeholder types created by the inspector for invalid/broken functions
15
+ // (e.g., functions with type errors or missing return statements). Attempting to
16
+ // import these would fail since the source files don't actually export __object.
17
+ if (refName !== '__object' && !refName.startsWith('__object_')) {
18
+ requiredTypes.add(refName)
19
+ }
14
20
  })
15
21
 
16
22
  // Extract type names from the type string that might not be in references
@@ -1,10 +1,11 @@
1
1
  import { dirname } from 'path'
2
- import { mkdir, readFile, writeFile } from 'fs/promises'
2
+ import { mkdir, readFile, writeFile, rm } from 'fs/promises'
3
+ import { existsSync } from 'fs'
3
4
  import { CLILogger } from '../services/cli-logger.service.js'
5
+ import { getCLIVersion } from './get-cli-version.js'
4
6
 
5
- // TODO: add version back in once the ESM dust settles
6
7
  export const DO_NOT_MODIFY_COMMENT = `/**
7
- * This file was generated by the @pikku/cli
8
+ * This file was generated by @pikku/cli@${getCLIVersion()}
8
9
  */
9
10
  `
10
11
 
@@ -54,3 +55,18 @@ export const writeFileInDir = async (
54
55
  }
55
56
  }
56
57
  }
58
+
59
+ export const removeFileInDir = async (
60
+ logger: CLILogger,
61
+ path: string,
62
+ { logRemove = true }: { logRemove?: boolean } = {}
63
+ ) => {
64
+ // Check if file exists before attempting removal
65
+ if (existsSync(path)) {
66
+ await rm(path, { force: true })
67
+
68
+ if (logRemove) {
69
+ logger.info({ message: `✓ File removed at ${path}`, type: 'success' })
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,28 @@
1
+ import { dirname, join } from 'path'
2
+ import { readFile } from 'fs/promises'
3
+ import { fileURLToPath } from 'url'
4
+
5
+ // Get package version for generated file comments
6
+ const __dirname = dirname(fileURLToPath(import.meta.url))
7
+ let version = 'unknown'
8
+
9
+ try {
10
+ // Try from src/ first (development), then from dist/src/ (built)
11
+ const pkgPath = join(__dirname, '..', '..', 'package.json')
12
+ const pkgJson = JSON.parse(await readFile(pkgPath, 'utf-8'))
13
+ version = pkgJson.version
14
+ } catch {
15
+ try {
16
+ const pkgPath = join(__dirname, '..', '..', '..', 'package.json')
17
+ const pkgJson = JSON.parse(await readFile(pkgPath, 'utf-8'))
18
+ version = pkgJson.version
19
+ } catch {
20
+ // Fallback to unknown if package.json can't be found
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Returns the CLI version string
26
+ * Works from both src/ and dist/src/ locations
27
+ */
28
+ export const getCLIVersion = () => version
@@ -1,8 +1,6 @@
1
1
  import { join, dirname, resolve, isAbsolute } from 'path'
2
2
  import { readdir, readFile } from 'fs/promises'
3
3
  import { PikkuCLIConfig } from '../../types/config.js'
4
- import { InspectorFilters } from '@pikku/inspector'
5
- import { PikkuWiringTypes } from '@pikku/core'
6
4
  import { CLILogger } from '../services/cli-logger.service.js'
7
5
 
8
6
  const CONFIG_DIR_FILES = [
@@ -19,14 +17,12 @@ export const getPikkuCLIConfig = async (
19
17
  logger: CLILogger,
20
18
  configFile: string | undefined = undefined,
21
19
  requiredFields: Array<keyof PikkuCLIConfig>,
22
- filters: InspectorFilters = {},
23
20
  exitProcess: boolean = false
24
21
  ): Promise<PikkuCLIConfig> => {
25
22
  const config = await _getPikkuCLIConfig(
26
23
  logger,
27
24
  configFile,
28
25
  requiredFields,
29
- filters,
30
26
  exitProcess
31
27
  )
32
28
  return config
@@ -36,7 +32,6 @@ const _getPikkuCLIConfig = async (
36
32
  logger: CLILogger,
37
33
  configFile: string | undefined = undefined,
38
34
  requiredFields: Array<keyof PikkuCLIConfig>,
39
- filters: InspectorFilters = {},
40
35
  exitProcess: boolean = false
41
36
  ): Promise<PikkuCLIConfig> => {
42
37
  if (!configFile) {
@@ -59,7 +54,6 @@ const _getPikkuCLIConfig = async (
59
54
  logger,
60
55
  resolve(configDir, config.extends),
61
56
  [],
62
- filters,
63
57
  exitProcess
64
58
  )
65
59
  result = {
@@ -246,6 +240,12 @@ const _getPikkuCLIConfig = async (
246
240
  )
247
241
  }
248
242
 
243
+ // Permissions
244
+ const permissionsDir = join(result.outDir, 'permissions')
245
+ if (!result.permissionsFile) {
246
+ result.permissionsFile = join(permissionsDir, 'pikku-permissions.gen.ts')
247
+ }
248
+
249
249
  // Bootstrap files
250
250
  if (!result.bootstrapFile) {
251
251
  result.bootstrapFile = join(result.outDir, 'pikku-bootstrap.gen.ts')
@@ -279,15 +279,6 @@ const _getPikkuCLIConfig = async (
279
279
  result.cliTypesFile = join(cliDir, 'pikku-cli-types.gen.ts')
280
280
  }
281
281
 
282
- result.bootstrapFiles = result.bootstrapFiles || {}
283
- for (const key of Object.keys(PikkuWiringTypes)) {
284
- const eventDir = join(result.outDir, key.toLowerCase())
285
- result.bootstrapFiles[key] = join(
286
- eventDir,
287
- `pikku-bootstrap-${key}.gen.ts`
288
- )
289
- }
290
-
291
282
  if (requiredFields.length > 0) {
292
283
  validateCLIConfig(result, requiredFields)
293
284
  }
@@ -306,26 +297,6 @@ const _getPikkuCLIConfig = async (
306
297
  }
307
298
  }
308
299
 
309
- // Separately normalize bootstrapFiles (Record<string, string>)
310
- if (result.bootstrapFiles && typeof result.bootstrapFiles === 'object') {
311
- for (const [key, value] of Object.entries(result.bootstrapFiles)) {
312
- if (typeof value === 'string' && !isAbsolute(value)) {
313
- result.bootstrapFiles[key] = join(result.rootDir, value)
314
- }
315
- }
316
- }
317
-
318
- result.filters = result.filters || {}
319
- if (filters.tags && filters.tags.length > 0) {
320
- result.filters.tags = filters.tags
321
- }
322
- if (filters.types && filters.types.length > 0) {
323
- result.filters.types = filters.types
324
- }
325
- if (filters.directories && filters.directories.length > 0) {
326
- result.filters.directories = filters.directories
327
- }
328
-
329
300
  if (!isAbsolute(result.tsconfig)) {
330
301
  result.tsconfig = join(result.rootDir, result.tsconfig)
331
302
  }
@@ -3,7 +3,7 @@ import { writeFileInDir } from './file-writer.js'
3
3
  import { mkdir, writeFile } from 'fs/promises'
4
4
  import { FunctionsMeta, JSONValue } from '@pikku/core'
5
5
  import { HTTPWiringsMeta } from '@pikku/core/http'
6
- import { TypesMap } from '@pikku/inspector'
6
+ import { TypesMap, ErrorCode } from '@pikku/inspector'
7
7
  import { CLILogger } from '../services/cli-logger.service.js'
8
8
 
9
9
  export async function generateSchemas(
@@ -66,10 +66,14 @@ export async function generateSchemas(
66
66
  } catch (e) {
67
67
  // Ignore rootless errors
68
68
  if (e instanceof RootlessError) {
69
- logger.error(`Error generating schema since it has no root: ${schema}`)
69
+ logger.error(
70
+ `[${ErrorCode.SCHEMA_NO_ROOT}] Error generating schema since it has no root: ${schema}`
71
+ )
70
72
  return
71
73
  }
72
- logger.error(`Error generating schema: ${schema}`)
74
+ logger.error(
75
+ `[${ErrorCode.SCHEMA_GENERATION_ERROR}] Error generating schema: ${schema}. Message: ${e.message}`
76
+ )
73
77
  }
74
78
  })
75
79
 
@@ -82,10 +82,6 @@ export const serializeImportMap = (
82
82
  }
83
83
  const variables = paths.get(path) || []
84
84
 
85
- if (uniqueName === '__object') {
86
- return
87
- }
88
-
89
85
  const importName =
90
86
  originalName === uniqueName
91
87
  ? originalName
@@ -8,7 +8,10 @@ import type { CLILogger } from '../src/services/cli-logger.service.js'
8
8
  import { PikkuCLIConfig } from '../types/config.d.ts'
9
9
  import { InspectorState } from '@pikku/inspector'
10
10
 
11
- export interface Config extends CoreConfig<PikkuCLIConfig> {}
11
+ export interface Config extends CoreConfig<PikkuCLIConfig> {
12
+ // Preloaded inspector state from stateInput file (if provided)
13
+ preloadedInspectorState?: Omit<InspectorState, 'typesLookup'>
14
+ }
12
15
 
13
16
  export interface SingletonServices extends CoreSingletonServices<Config> {
14
17
  logger: CLILogger
package/types/config.d.ts CHANGED
@@ -64,9 +64,11 @@ export interface PikkuCLICoreOutputFiles {
64
64
  middlewareFile: string
65
65
  middlewareGroupsMetaFile: string
66
66
 
67
+ // Permissions
68
+ permissionsFile: string
69
+
67
70
  // Application bootstrap
68
71
  bootstrapFile: string
69
- bootstrapFiles: Record<PikkuWiringTypes, string>
70
72
  }
71
73
 
72
74
  export type PikkuCLIInput = {
@@ -121,10 +123,13 @@ export type PikkuCLIInput = {
121
123
  >
122
124
  }
123
125
 
124
- middlewareServices?: string[]
126
+ forceRequiredServices?: string[]
125
127
 
126
128
  schemasFromTypes?: string[]
127
129
 
130
+ stateOutput?: string
131
+ stateInput?: string
132
+
128
133
  filters: InspectorFilters
129
134
  } & PikkuCLICoreOutputFiles
130
135
 
@@ -142,6 +147,10 @@ export type PikkuCLIConfig = {
142
147
  tags?: string[]
143
148
  types?: string[]
144
149
 
150
+ userSessionType?: string
151
+ singletonServicesFactoryType?: string
152
+ sessionServicesFactoryType?: string
153
+
145
154
  configDir: string
146
155
  tsconfig: string
147
156
 
@@ -184,9 +193,12 @@ export type PikkuCLIConfig = {
184
193
  >
185
194
  }
186
195
 
187
- middlewareServices?: string[]
196
+ forceRequiredServices?: string[]
188
197
 
189
198
  schemasFromTypes?: string[]
190
199
 
200
+ stateOutput?: string
201
+ stateInput?: string
202
+
191
203
  filters: InspectorFilters
192
204
  } & PikkuCLICoreOutputFiles
@@ -1,6 +0,0 @@
1
- /**
2
- * This file was generated by the @pikku/cli
3
- */
4
- import '../function/pikku-functions-meta.min.gen.js';
5
- import '../function/pikku-functions.gen.js';
6
- import '../schemas/register.gen.js';
@@ -1,6 +0,0 @@
1
- /**
2
- * This file was generated by the @pikku/cli
3
- */
4
- import '../function/pikku-functions-meta.min.gen.js';
5
- import '../function/pikku-functions.gen.js';
6
- import '../schemas/register.gen.js';
@@ -1,4 +0,0 @@
1
- /**
2
- *
3
- */
4
- export declare const serializePikkuTypes: (userSessionTypeImport: string, userSessionTypeName: string, singletonServicesTypeImport: string, singletonServicesTypeName: string, sessionServicesTypeImport: string, sessionServicesTypeName: string, rpcMapTypeImport: string) => string;