@pikku/cli 0.12.21 → 0.12.22

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 (430) hide show
  1. package/cli.schema.json +1 -1
  2. package/console-app/assets/index-C52h1B_L.css +1 -0
  3. package/console-app/assets/index-CAk106ji.js +232 -0
  4. package/console-app/index.html +3 -6
  5. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
  6. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +3 -3
  7. package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
  8. package/dist/.pikku/cli/pikku-cli-channel.d.ts +6 -6
  9. package/dist/.pikku/cli/pikku-cli-channel.js +280 -1
  10. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
  11. package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
  12. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
  13. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +782 -7
  14. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
  15. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
  16. package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
  17. package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
  18. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  19. package/dist/.pikku/function/pikku-function-types.gen.d.ts +41 -73
  20. package/dist/.pikku/function/pikku-function-types.gen.js +30 -40
  21. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  22. package/dist/.pikku/function/pikku-functions-meta.gen.json +1526 -491
  23. package/dist/.pikku/function/pikku-functions.gen.js +13 -1
  24. package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
  25. package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
  26. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
  27. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
  28. package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
  29. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
  30. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
  31. package/dist/.pikku/pikku-bootstrap.gen.d.ts +3 -1
  32. package/dist/.pikku/pikku-bootstrap.gen.js +3 -1
  33. package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
  34. package/dist/.pikku/pikku-meta-service.gen.js +1 -1
  35. package/dist/.pikku/pikku-services.gen.d.ts +2 -1
  36. package/dist/.pikku/pikku-services.gen.js +1 -0
  37. package/dist/.pikku/pikku-types.gen.d.ts +1 -1
  38. package/dist/.pikku/pikku-types.gen.js +1 -1
  39. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
  40. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
  41. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.d.ts +1 -0
  42. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +6 -0
  43. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.json +250 -0
  44. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +4 -0
  45. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +5 -0
  46. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
  47. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +56 -4
  48. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
  49. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
  50. package/dist/.pikku/schemas/register.gen.js +155 -13
  51. package/dist/.pikku/schemas/schemas/BinaryInput.schema.json +1 -0
  52. package/dist/.pikku/schemas/schemas/DbMigrateInput.schema.json +1 -0
  53. package/dist/.pikku/schemas/schemas/DbResetInput.schema.json +1 -0
  54. package/dist/.pikku/schemas/schemas/DbSeedInput.schema.json +1 -0
  55. package/dist/.pikku/schemas/schemas/FabricDbSchemaInput.schema.json +1 -0
  56. package/dist/.pikku/schemas/schemas/FabricDbSchemaOutput.schema.json +1 -0
  57. package/dist/.pikku/schemas/schemas/FabricDeployApplyInput.schema.json +1 -0
  58. package/dist/.pikku/schemas/schemas/FabricDeployApplyOutput.schema.json +1 -0
  59. package/dist/.pikku/schemas/schemas/FabricDeployListInput.schema.json +1 -0
  60. package/dist/.pikku/schemas/schemas/FabricDeployListOutput.schema.json +1 -0
  61. package/dist/.pikku/schemas/schemas/FabricDeployPlanInput.schema.json +1 -0
  62. package/dist/.pikku/schemas/schemas/FabricDeployPlanOutput.schema.json +1 -0
  63. package/dist/.pikku/schemas/schemas/FabricDeployUnitsInput.schema.json +1 -0
  64. package/dist/.pikku/schemas/schemas/FabricDeployUnitsOutput.schema.json +1 -0
  65. package/dist/.pikku/schemas/schemas/FabricDomainsAddInput.schema.json +1 -0
  66. package/dist/.pikku/schemas/schemas/FabricDomainsAddOutput.schema.json +1 -0
  67. package/dist/.pikku/schemas/schemas/FabricDomainsListInput.schema.json +1 -0
  68. package/dist/.pikku/schemas/schemas/FabricDomainsListOutput.schema.json +1 -0
  69. package/dist/.pikku/schemas/schemas/FabricDomainsRemoveInput.schema.json +1 -0
  70. package/dist/.pikku/schemas/schemas/FabricDomainsRemoveOutput.schema.json +1 -0
  71. package/dist/.pikku/schemas/schemas/FabricErrorsInput.schema.json +1 -0
  72. package/dist/.pikku/schemas/schemas/FabricErrorsOutput.schema.json +1 -0
  73. package/dist/.pikku/schemas/schemas/FabricInitInput.schema.json +1 -0
  74. package/dist/.pikku/schemas/schemas/FabricInitOutput.schema.json +1 -0
  75. package/dist/.pikku/schemas/schemas/FabricLLMKeyInput.schema.json +1 -0
  76. package/dist/.pikku/schemas/schemas/FabricLLMKeyOutput.schema.json +1 -0
  77. package/dist/.pikku/schemas/schemas/FabricLinkInput.schema.json +1 -0
  78. package/dist/.pikku/schemas/schemas/FabricLinkOutput.schema.json +1 -0
  79. package/dist/.pikku/schemas/schemas/FabricLoginInput.schema.json +1 -0
  80. package/dist/.pikku/schemas/schemas/FabricLoginOutput.schema.json +1 -0
  81. package/dist/.pikku/schemas/schemas/FabricLogsInput.schema.json +1 -0
  82. package/dist/.pikku/schemas/schemas/FabricLogsOutput.schema.json +1 -0
  83. package/dist/.pikku/schemas/schemas/FabricMetricsInput.schema.json +1 -0
  84. package/dist/.pikku/schemas/schemas/FabricMetricsOutput.schema.json +1 -0
  85. package/dist/.pikku/schemas/schemas/FabricRollbackInput.schema.json +1 -0
  86. package/dist/.pikku/schemas/schemas/FabricRollbackOutput.schema.json +1 -0
  87. package/dist/.pikku/schemas/schemas/FabricSecretsListInput.schema.json +1 -0
  88. package/dist/.pikku/schemas/schemas/FabricSecretsListOutput.schema.json +1 -0
  89. package/dist/.pikku/schemas/schemas/FabricSecretsSetInput.schema.json +1 -0
  90. package/dist/.pikku/schemas/schemas/FabricSecretsSetOutput.schema.json +1 -0
  91. package/dist/.pikku/schemas/schemas/FabricStatusInput.schema.json +1 -0
  92. package/dist/.pikku/schemas/schemas/FabricStatusOutput.schema.json +1 -0
  93. package/dist/.pikku/schemas/schemas/FabricTraceInput.schema.json +1 -0
  94. package/dist/.pikku/schemas/schemas/FabricTraceOutput.schema.json +1 -0
  95. package/dist/.pikku/schemas/schemas/FabricValidateInput.schema.json +1 -0
  96. package/dist/.pikku/schemas/schemas/FabricValidateOutput.schema.json +1 -0
  97. package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  98. package/dist/.pikku/schemas/schemas/PikkuCLIEntryOutput.schema.json +1 -0
  99. package/dist/.pikku/schemas/schemas/PikkuEventsScaffoldOutput.schema.json +1 -0
  100. package/dist/.pikku/schemas/schemas/PikkuMetaClientsInput.schema.json +1 -0
  101. package/dist/.pikku/schemas/schemas/PikkuMetaContextInput.schema.json +1 -0
  102. package/dist/.pikku/schemas/schemas/PikkuMetaFunctionsGetInput.schema.json +1 -0
  103. package/dist/.pikku/schemas/schemas/PikkuMetaFunctionsListInput.schema.json +1 -0
  104. package/dist/.pikku/schemas/schemas/PikkuMetaMiddlewareGetInput.schema.json +1 -0
  105. package/dist/.pikku/schemas/schemas/PikkuMetaMiddlewareListInput.schema.json +1 -0
  106. package/dist/.pikku/schemas/schemas/PikkuMetaPermissionsGetInput.schema.json +1 -0
  107. package/dist/.pikku/schemas/schemas/PikkuMetaPermissionsListInput.schema.json +1 -0
  108. package/dist/.pikku/schemas/schemas/PikkuMetaSchemasGetInput.schema.json +1 -0
  109. package/dist/.pikku/schemas/schemas/PikkuMetaSchemasListInput.schema.json +1 -0
  110. package/dist/.pikku/schemas/schemas/PikkuMetaWiresChannelInput.schema.json +1 -0
  111. package/dist/.pikku/schemas/schemas/PikkuMetaWiresHttpInput.schema.json +1 -0
  112. package/dist/.pikku/schemas/schemas/PikkuMetaWiresListInput.schema.json +1 -0
  113. package/dist/.pikku/schemas/schemas/PikkuMetaWiresQueueInput.schema.json +1 -0
  114. package/dist/.pikku/schemas/schemas/PikkuMetaWiresSchedulerInput.schema.json +1 -0
  115. package/dist/.pikku/schemas/schemas/PikkuMetaWiresTriggerInput.schema.json +1 -0
  116. package/dist/.pikku/schemas/schemas/PikkuMetaWiresTypeInput.schema.json +1 -0
  117. package/dist/.pikku/schemas/schemas/PikkuMetaWorkflowsGetInput.schema.json +1 -0
  118. package/dist/.pikku/schemas/schemas/PikkuMetaWorkflowsListInput.schema.json +1 -0
  119. package/dist/.pikku/schemas/schemas/PikkuSkillsInstallInput.schema.json +1 -0
  120. package/dist/.pikku/schemas/schemas/PikkuSkillsListInput.schema.json +1 -0
  121. package/dist/.pikku/schemas/schemas/PikkuTestsCoverageInput.schema.json +1 -0
  122. package/dist/.pikku/schemas/schemas/PikkuTestsInitInput.schema.json +1 -0
  123. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
  124. package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
  125. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
  126. package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
  127. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  128. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  129. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
  130. package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
  131. package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
  132. package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
  133. package/dist/.pikku/workflow/meta/allWorkflow.gen.json +235 -627
  134. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
  135. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
  136. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  137. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  138. package/dist/bin/pikku-bin.mjs +23 -0
  139. package/dist/bin/pikku.js +28 -1
  140. package/dist/src/cli.wiring.js +274 -8
  141. package/dist/src/deploy/analyzer/analyzer.d.ts +16 -1
  142. package/dist/src/deploy/analyzer/analyzer.js +83 -43
  143. package/dist/src/deploy/build-pipeline.js +83 -17
  144. package/dist/src/deploy/bundler/bundler.d.ts +1 -0
  145. package/dist/src/deploy/bundler/bundler.js +13 -5
  146. package/dist/src/deploy/codegen/per-unit-codegen.d.ts +8 -0
  147. package/dist/src/deploy/codegen/per-unit-codegen.js +46 -5
  148. package/dist/src/deploy/provider-adapter.d.ts +34 -0
  149. package/dist/src/deploy/server-entry.d.ts +16 -0
  150. package/dist/src/deploy/server-entry.js +81 -0
  151. package/dist/src/fabric/fabric-commands.d.ts +522 -0
  152. package/dist/src/fabric/fabric-commands.js +299 -0
  153. package/dist/src/fabric/functions/db-schema.function.d.ts +35 -0
  154. package/dist/src/fabric/functions/db-schema.function.js +37 -0
  155. package/dist/src/fabric/functions/deploy-list.function.d.ts +41 -0
  156. package/dist/src/fabric/functions/deploy-list.function.js +43 -0
  157. package/dist/src/fabric/functions/deploy-units.function.d.ts +35 -0
  158. package/dist/src/fabric/functions/deploy-units.function.js +41 -0
  159. package/dist/src/fabric/functions/deploy.function.d.ts +105 -0
  160. package/dist/src/fabric/functions/deploy.function.js +122 -0
  161. package/dist/src/fabric/functions/domains-add.function.d.ts +35 -0
  162. package/dist/src/fabric/functions/domains-add.function.js +46 -0
  163. package/dist/src/fabric/functions/domains-list.function.d.ts +20 -0
  164. package/dist/src/fabric/functions/domains-list.function.js +50 -0
  165. package/dist/src/fabric/functions/domains-remove.function.d.ts +24 -0
  166. package/dist/src/fabric/functions/domains-remove.function.js +44 -0
  167. package/dist/src/fabric/functions/errors.function.d.ts +44 -0
  168. package/dist/src/fabric/functions/errors.function.js +50 -0
  169. package/dist/src/fabric/functions/init.function.d.ts +51 -0
  170. package/dist/src/fabric/functions/init.function.js +54 -0
  171. package/dist/src/fabric/functions/link.function.d.ts +28 -0
  172. package/dist/src/fabric/functions/link.function.js +77 -0
  173. package/dist/src/fabric/functions/llm-key.function.d.ts +46 -0
  174. package/dist/src/fabric/functions/llm-key.function.js +76 -0
  175. package/dist/src/fabric/functions/login.function.d.ts +42 -0
  176. package/dist/src/fabric/functions/login.function.js +68 -0
  177. package/dist/src/fabric/functions/logs.function.d.ts +40 -0
  178. package/dist/src/fabric/functions/logs.function.js +84 -0
  179. package/dist/src/fabric/functions/metrics.function.d.ts +32 -0
  180. package/dist/src/fabric/functions/metrics.function.js +49 -0
  181. package/dist/src/fabric/functions/rollback.function.d.ts +76 -0
  182. package/dist/src/fabric/functions/rollback.function.js +69 -0
  183. package/dist/src/fabric/functions/secrets-list.function.d.ts +24 -0
  184. package/dist/src/fabric/functions/secrets-list.function.js +37 -0
  185. package/dist/src/fabric/functions/secrets-set.function.d.ts +32 -0
  186. package/dist/src/fabric/functions/secrets-set.function.js +36 -0
  187. package/dist/src/fabric/functions/status.function.d.ts +34 -0
  188. package/dist/src/fabric/functions/status.function.js +43 -0
  189. package/dist/src/fabric/functions/trace.function.d.ts +28 -0
  190. package/dist/src/fabric/functions/trace.function.js +45 -0
  191. package/dist/src/fabric/functions/validate.function.d.ts +50 -0
  192. package/dist/src/fabric/functions/validate.function.js +363 -0
  193. package/dist/src/fabric/lib/config.d.ts +64 -0
  194. package/dist/src/fabric/lib/config.js +62 -0
  195. package/dist/src/fabric/lib/console-url.d.ts +5 -0
  196. package/dist/src/fabric/lib/console-url.js +13 -0
  197. package/dist/src/fabric/lib/git.d.ts +53 -0
  198. package/dist/src/fabric/lib/git.js +151 -0
  199. package/dist/src/fabric/lib/http.d.ts +4 -0
  200. package/dist/src/fabric/lib/http.js +12 -0
  201. package/dist/src/fabric/lib/not-implemented.d.ts +5 -0
  202. package/dist/src/fabric/lib/not-implemented.js +8 -0
  203. package/dist/src/fabric/lib/output.d.ts +23 -0
  204. package/dist/src/fabric/lib/output.js +39 -0
  205. package/dist/src/fabric/lib/prompt.d.ts +12 -0
  206. package/dist/src/fabric/lib/prompt.js +32 -0
  207. package/dist/src/fabric/lib/stage.d.ts +7 -0
  208. package/dist/src/fabric/lib/stage.js +14 -0
  209. package/dist/src/fabric/sdk/pikku-fetch.gen.d.ts +14 -0
  210. package/dist/src/fabric/sdk/pikku-fetch.gen.js +30 -0
  211. package/dist/src/fabric/sdk/pikku-rpc.gen.d.ts +105 -0
  212. package/dist/src/fabric/sdk/pikku-rpc.gen.js +126 -0
  213. package/dist/src/functions/commands/all.d.ts +1 -1
  214. package/dist/src/functions/commands/binary.d.ts +7 -0
  215. package/dist/src/functions/commands/binary.js +40 -0
  216. package/dist/src/functions/commands/bootstrap.d.ts +1 -1
  217. package/dist/src/functions/commands/bootstrap.js +7 -4
  218. package/dist/src/functions/commands/console.d.ts +3 -3
  219. package/dist/src/functions/commands/db-migrate.d.ts +1 -0
  220. package/dist/src/functions/commands/db-migrate.js +35 -0
  221. package/dist/src/functions/commands/db-reset.d.ts +1 -0
  222. package/dist/src/functions/commands/db-reset.js +36 -0
  223. package/dist/src/functions/commands/db-seed.d.ts +1 -0
  224. package/dist/src/functions/commands/db-seed.js +27 -0
  225. package/dist/src/functions/commands/db-shared.d.ts +32 -0
  226. package/dist/src/functions/commands/db-shared.js +26 -0
  227. package/dist/src/functions/commands/deploy-apply.d.ts +3 -3
  228. package/dist/src/functions/commands/deploy-info.d.ts +1 -1
  229. package/dist/src/functions/commands/deploy-plan.d.ts +3 -3
  230. package/dist/src/functions/commands/dev.d.ts +3 -3
  231. package/dist/src/functions/commands/dev.js +142 -86
  232. package/dist/src/functions/commands/enable.d.ts +5 -4
  233. package/dist/src/functions/commands/enable.js +4 -0
  234. package/dist/src/functions/commands/info.d.ts +4 -4
  235. package/dist/src/functions/commands/load-user-project.d.ts +11 -0
  236. package/dist/src/functions/commands/load-user-project.js +40 -0
  237. package/dist/src/functions/commands/meta.d.ts +82 -0
  238. package/dist/src/functions/commands/meta.js +454 -0
  239. package/dist/src/functions/commands/new-addon.d.ts +3 -3
  240. package/dist/src/functions/commands/new-function.d.ts +3 -3
  241. package/dist/src/functions/commands/new-middleware.d.ts +3 -3
  242. package/dist/src/functions/commands/new-permission.d.ts +3 -3
  243. package/dist/src/functions/commands/new-wiring.d.ts +3 -3
  244. package/dist/src/functions/commands/pikku-command-bootstrap.d.ts +1 -1
  245. package/dist/src/functions/commands/pikku-command-bootstrap.js +15 -1
  246. package/dist/src/functions/commands/pikku-command-summary.d.ts +1 -1
  247. package/dist/src/functions/commands/pikku-command-summary.js +3 -0
  248. package/dist/src/functions/commands/skills.d.ts +26 -0
  249. package/dist/src/functions/commands/skills.js +184 -0
  250. package/dist/src/functions/commands/tests-coverage.d.ts +7 -0
  251. package/dist/src/functions/commands/tests-coverage.js +231 -0
  252. package/dist/src/functions/commands/tests-init.d.ts +7 -0
  253. package/dist/src/functions/commands/tests-init.js +225 -0
  254. package/dist/src/functions/commands/versions-check.d.ts +1 -1
  255. package/dist/src/functions/commands/versions-init.d.ts +3 -3
  256. package/dist/src/functions/commands/versions-update.d.ts +1 -1
  257. package/dist/src/functions/commands/watch.d.ts +3 -3
  258. package/dist/src/functions/commands/watch.js +1 -1
  259. package/dist/src/functions/db/local-db.d.ts +48 -0
  260. package/dist/src/functions/db/local-db.js +106 -0
  261. package/dist/src/functions/db/seed.d.ts +11 -0
  262. package/dist/src/functions/db/seed.js +22 -0
  263. package/dist/src/functions/db/sql-migrator.d.ts +26 -0
  264. package/dist/src/functions/db/sql-migrator.js +104 -0
  265. package/dist/src/functions/db/sqlite-codegen.d.ts +45 -0
  266. package/dist/src/functions/db/sqlite-codegen.js +294 -0
  267. package/dist/src/functions/db/zod-codegen.d.ts +10 -0
  268. package/dist/src/functions/db/zod-codegen.js +109 -0
  269. package/dist/src/functions/runtimes/fetch/index.d.ts +1 -1
  270. package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.d.ts +1 -1
  271. package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +21 -2
  272. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-worker-rpc-wrapper.d.ts +1 -0
  273. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-worker-rpc-wrapper.js +163 -0
  274. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts +1 -1
  275. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.js +5 -2
  276. package/dist/src/functions/runtimes/tanstack-start/pikku-command-tanstack-start.d.ts +1 -0
  277. package/dist/src/functions/runtimes/tanstack-start/pikku-command-tanstack-start.js +32 -0
  278. package/dist/src/functions/runtimes/tanstack-start/serialize-tanstack-start-shim.d.ts +11 -0
  279. package/dist/src/functions/runtimes/tanstack-start/serialize-tanstack-start-shim.js +36 -0
  280. package/dist/src/functions/runtimes/websocket/pikku-command-websocket-typed.d.ts +1 -1
  281. package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent-types.d.ts +1 -1
  282. package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent.d.ts +1 -1
  283. package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent.js +1 -10
  284. package/dist/src/functions/wirings/ai-agent/pikku-command-public-agent.d.ts +1 -1
  285. package/dist/src/functions/wirings/ai-agent/serialize-public-agent.js +76 -1
  286. package/dist/src/functions/wirings/channels/pikku-channels.d.ts +1 -1
  287. package/dist/src/functions/wirings/channels/pikku-command-channel-types.d.ts +1 -1
  288. package/dist/src/functions/wirings/channels/pikku-command-channels-map.d.ts +1 -1
  289. package/dist/src/functions/wirings/channels/pikku-command-channels.d.ts +1 -1
  290. package/dist/src/functions/wirings/cli/pikku-command-cli-entry.d.ts +1 -1
  291. package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +5 -2
  292. package/dist/src/functions/wirings/cli/pikku-command-cli-types.d.ts +5 -1
  293. package/dist/src/functions/wirings/cli/pikku-command-cli-types.js +8 -2
  294. package/dist/src/functions/wirings/cli/pikku-command-cli.d.ts +1 -1
  295. package/dist/src/functions/wirings/cli/serialize-channel-cli-client.js +27 -9
  296. package/dist/src/functions/wirings/cli/serialize-channel-cli.d.ts +5 -1
  297. package/dist/src/functions/wirings/cli/serialize-channel-cli.js +13 -3
  298. package/dist/src/functions/wirings/console/pikku-command-console-functions.d.ts +1 -1
  299. package/dist/src/functions/wirings/console/pikku-command-node-types.d.ts +1 -1
  300. package/dist/src/functions/wirings/console/pikku-command-nodes-meta.d.ts +1 -1
  301. package/dist/src/functions/wirings/console/serialize-console-functions.js +5 -0
  302. package/dist/src/functions/wirings/credentials/pikku-command-credentials.d.ts +1 -1
  303. package/dist/src/functions/wirings/functions/pikku-command-addon-types.d.ts +5 -1
  304. package/dist/src/functions/wirings/functions/pikku-command-addon-types.js +7 -2
  305. package/dist/src/functions/wirings/functions/pikku-command-function-types-split.d.ts +1 -1
  306. package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +1 -1
  307. package/dist/src/functions/wirings/functions/pikku-command-function-types.d.ts +1 -1
  308. package/dist/src/functions/wirings/functions/pikku-command-functions.d.ts +1 -1
  309. package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
  310. package/dist/src/functions/wirings/functions/schemas.d.ts +1 -1
  311. package/dist/src/functions/wirings/functions/serialize-function-types.js +78 -83
  312. package/dist/src/functions/wirings/gateway/pikku-command-gateway.d.ts +1 -1
  313. package/dist/src/functions/wirings/http/pikku-command-http-map.d.ts +1 -1
  314. package/dist/src/functions/wirings/http/pikku-command-http-routes.d.ts +1 -1
  315. package/dist/src/functions/wirings/http/pikku-command-http-types.d.ts +1 -1
  316. package/dist/src/functions/wirings/http/pikku-command-openapi.d.ts +1 -1
  317. package/dist/src/functions/wirings/http/pikku-http-routes.d.ts +1 -1
  318. package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.d.ts +1 -1
  319. package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.d.ts +1 -1
  320. package/dist/src/functions/wirings/mcp/pikku-command-mcp.d.ts +1 -1
  321. package/dist/src/functions/wirings/middleware/pikku-command-middleware.d.ts +1 -1
  322. package/dist/src/functions/wirings/package/pikku-command-package-types.d.ts +2 -2
  323. package/dist/src/functions/wirings/package/pikku-command-package.d.ts +1 -1
  324. package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -1
  325. package/dist/src/functions/wirings/queue/pikku-command-queue-map.d.ts +1 -1
  326. package/dist/src/functions/wirings/queue/pikku-command-queue-service.d.ts +1 -1
  327. package/dist/src/functions/wirings/queue/pikku-command-queue-types.d.ts +1 -1
  328. package/dist/src/functions/wirings/queue/pikku-command-queue.d.ts +1 -1
  329. package/dist/src/functions/wirings/queue/pikku-queue-map.d.ts +1 -1
  330. package/dist/src/functions/wirings/queue/pikku-queue.d.ts +1 -1
  331. package/dist/src/functions/wirings/realtime/pikku-command-events-scaffold.d.ts +1 -0
  332. package/dist/src/functions/wirings/realtime/pikku-command-events-scaffold.js +26 -0
  333. package/dist/src/functions/wirings/realtime/pikku-command-realtime.d.ts +1 -0
  334. package/dist/src/functions/wirings/realtime/pikku-command-realtime.js +35 -0
  335. package/dist/src/functions/wirings/realtime/serialize-events-scaffold.d.ts +23 -0
  336. package/dist/src/functions/wirings/realtime/serialize-events-scaffold.js +98 -0
  337. package/dist/src/functions/wirings/realtime/serialize-realtime-client.d.ts +22 -0
  338. package/dist/src/functions/wirings/realtime/serialize-realtime-client.js +337 -0
  339. package/dist/src/functions/wirings/rpc/pikku-command-public-rpc.d.ts +1 -1
  340. package/dist/src/functions/wirings/rpc/pikku-command-react-query.d.ts +1 -1
  341. package/dist/src/functions/wirings/rpc/pikku-command-remote-rpc.d.ts +1 -1
  342. package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.d.ts +1 -1
  343. package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.js +3 -1
  344. package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.d.ts +2 -2
  345. package/dist/src/functions/wirings/rpc/pikku-command-rpc.d.ts +2 -1
  346. package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +13 -7
  347. package/dist/src/functions/wirings/rpc/serialize-public-rpc.js +1 -0
  348. package/dist/src/functions/wirings/rpc/serialize-react-query-hooks.js +1 -1
  349. package/dist/src/functions/wirings/rpc/serialize-remote-rpc.js +7 -1
  350. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.d.ts +1 -1
  351. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.d.ts +1 -1
  352. package/dist/src/functions/wirings/secrets/pikku-command-secrets.d.ts +1 -1
  353. package/dist/src/functions/wirings/triggers/pikku-command-trigger-types.d.ts +1 -1
  354. package/dist/src/functions/wirings/triggers/pikku-command-trigger-types.js +1 -1
  355. package/dist/src/functions/wirings/triggers/pikku-command-trigger.d.ts +1 -1
  356. package/dist/src/functions/wirings/variables/pikku-command-variables.d.ts +1 -1
  357. package/dist/src/functions/wirings/workflow/pikku-command-workflow-routes.d.ts +1 -1
  358. package/dist/src/functions/wirings/workflow/pikku-command-workflow-routes.js +1 -1
  359. package/dist/src/functions/wirings/workflow/pikku-command-workflow.d.ts +5 -1
  360. package/dist/src/functions/wirings/workflow/pikku-command-workflow.js +18 -4
  361. package/dist/src/functions/wirings/workflow/serialize-workflow-bootstrap-map.d.ts +3 -0
  362. package/dist/src/functions/wirings/workflow/serialize-workflow-bootstrap-map.js +40 -0
  363. package/dist/src/functions/wirings/workflow/serialize-workflow-routes.js +14 -2
  364. package/dist/src/functions/workflows/all.workflow.js +41 -8
  365. package/dist/src/scaffold/rpc-remote.gen.d.ts +3 -3
  366. package/dist/src/scaffold/rpc-remote.gen.js +7 -2
  367. package/dist/src/scaffold/workflow-routes.gen.d.ts +18 -18
  368. package/dist/src/services/cli-logger.service.d.ts +0 -1
  369. package/dist/src/services/cli-logger.service.js +12 -22
  370. package/dist/src/services.js +24 -66
  371. package/dist/src/utils/generate-bootstrap-file.js +3 -0
  372. package/dist/src/utils/parse-cli-filters.d.ts +18 -0
  373. package/dist/src/utils/parse-cli-filters.js +99 -0
  374. package/dist/src/utils/pikku-cli-config.js +29 -9
  375. package/dist/tsconfig.tsbuildinfo +1 -1
  376. package/package.json +9 -4
  377. package/skills/pikku-addon/SKILL.md +330 -0
  378. package/skills/pikku-ai-agent/SKILL.md +227 -0
  379. package/skills/pikku-ai-vercel/SKILL.md +78 -0
  380. package/skills/pikku-ai-voice/SKILL.md +85 -0
  381. package/skills/pikku-auth-js/SKILL.md +106 -0
  382. package/skills/pikku-aws/SKILL.md +107 -0
  383. package/skills/pikku-backblaze/SKILL.md +70 -0
  384. package/skills/pikku-cli/SKILL.md +281 -0
  385. package/skills/pikku-concepts/SKILL.md +281 -0
  386. package/skills/pikku-concepts/references/concept-mapping.md +528 -0
  387. package/skills/pikku-config/SKILL.md +208 -0
  388. package/skills/pikku-cron/SKILL.md +211 -0
  389. package/skills/pikku-deploy-azure/SKILL.md +69 -0
  390. package/skills/pikku-deploy-cloudflare/SKILL.md +80 -0
  391. package/skills/pikku-deploy-express/SKILL.md +83 -0
  392. package/skills/pikku-deploy-fastify/SKILL.md +70 -0
  393. package/skills/pikku-deploy-lambda/SKILL.md +107 -0
  394. package/skills/pikku-deploy-nextjs/SKILL.md +76 -0
  395. package/skills/pikku-deploy-uws/SKILL.md +85 -0
  396. package/skills/pikku-fabric/SKILL.md +245 -0
  397. package/skills/pikku-feature/SKILL.md +258 -0
  398. package/skills/pikku-gateway-slack/SKILL.md +112 -0
  399. package/skills/pikku-http/SKILL.md +317 -0
  400. package/skills/pikku-i18n/SKILL.md +208 -0
  401. package/skills/pikku-info/SKILL.md +95 -0
  402. package/skills/pikku-jose/SKILL.md +102 -0
  403. package/skills/pikku-kysely/SKILL.md +145 -0
  404. package/skills/pikku-mcp/SKILL.md +237 -0
  405. package/skills/pikku-mongodb/SKILL.md +102 -0
  406. package/skills/pikku-n8n-addon-map/SKILL.md +178 -0
  407. package/skills/pikku-n8n-code-translate/SKILL.md +166 -0
  408. package/skills/pikku-pino/SKILL.md +77 -0
  409. package/skills/pikku-queue/SKILL.md +237 -0
  410. package/skills/pikku-react/SKILL.md +183 -0
  411. package/skills/pikku-react-query/SKILL.md +205 -0
  412. package/skills/pikku-realtime/SKILL.md +285 -0
  413. package/skills/pikku-redis/SKILL.md +87 -0
  414. package/skills/pikku-rpc/SKILL.md +168 -0
  415. package/skills/pikku-rtl/SKILL.md +205 -0
  416. package/skills/pikku-schedule/SKILL.md +54 -0
  417. package/skills/pikku-schema-ajv/SKILL.md +60 -0
  418. package/skills/pikku-schema-cfworker/SKILL.md +60 -0
  419. package/skills/pikku-security/SKILL.md +243 -0
  420. package/skills/pikku-services/SKILL.md +247 -0
  421. package/skills/pikku-template-clone/SKILL.md +39 -0
  422. package/skills/pikku-testing/SKILL.md +428 -0
  423. package/skills/pikku-trigger/SKILL.md +177 -0
  424. package/skills/pikku-versioning/SKILL.md +169 -0
  425. package/skills/pikku-websocket/SKILL.md +239 -0
  426. package/skills/pikku-workflow/SKILL.md +283 -0
  427. package/skills/pikku-workflows-client/SKILL.md +150 -0
  428. package/skills/pikku-ws/SKILL.md +45 -0
  429. package/console-app/assets/index-BpY2pSuA.css +0 -10
  430. package/console-app/assets/index-DXLy-_D4.js +0 -717
@@ -1,7 +1,7 @@
1
1
  export declare const watch: import("#pikku").PikkuFunctionConfig<{
2
2
  hmr?: boolean;
3
- }, void, "session" | "rpc", import("#pikku").PikkuFunctionSessionless<{
3
+ }, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<{
4
4
  hmr?: boolean;
5
- }, void, "session" | "rpc", import("#pikku").Services> | import("#pikku").PikkuFunction<{
5
+ }, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<{
6
6
  hmr?: boolean;
7
- }, void, "session" | "rpc", import("#pikku").Services>, undefined, undefined>;
7
+ }, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
@@ -43,7 +43,7 @@ export const watch = pikkuSessionlessFunc({
43
43
  if (timeout) {
44
44
  clearTimeout(timeout);
45
45
  }
46
- timeout = setTimeout(handle, 10);
46
+ timeout = setTimeout(handle, 1000);
47
47
  };
48
48
  watcher.on('change', deduped);
49
49
  watcher.on('add', deduped);
@@ -0,0 +1,48 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { type MigrateResult } from './sql-migrator.js';
3
+ import { type CodegenResult } from './sqlite-codegen.js';
4
+ import { type ZodCodegenResult } from './zod-codegen.js';
5
+ import { type SeedResult } from './seed.js';
6
+ export type DevDbConfig = true | {
7
+ file?: string;
8
+ };
9
+ export interface ResolvedLocalDb {
10
+ dbFile: string;
11
+ runtimeDir: string;
12
+ migrationsDir: string;
13
+ seedFile: string;
14
+ schemaFile: string;
15
+ coercionFile: string;
16
+ zodFile: string;
17
+ camelCase: boolean;
18
+ }
19
+ /**
20
+ * Resolve a DevDbConfig into absolute paths.
21
+ * - dbFile lives under runtimeDir (default: <rootDir>/.pikku-runtime)
22
+ * - schema/coercion/zod are generated into outDir/db
23
+ * - migrations and seed are authored source under rootDir/db
24
+ */
25
+ export declare function resolveLocalDb(config: DevDbConfig | undefined, rootDir: string, outDir: string, runtimeDir?: string): ResolvedLocalDb | null;
26
+ export interface MigrateAndCodegenOutcome {
27
+ migrate: MigrateResult;
28
+ codegen: CodegenResult;
29
+ zod: ZodCodegenResult;
30
+ }
31
+ /**
32
+ * Run the migrate routine (open → tracking-table → drift-check → apply →
33
+ * codegen → close). Used by both `pikku db migrate` and `pikku dev` boot.
34
+ */
35
+ export declare function migrateAndCodegen(resolved: ResolvedLocalDb): MigrateAndCodegenOutcome;
36
+ export declare function seed(resolved: ResolvedLocalDb): SeedResult;
37
+ /**
38
+ * Delete the dev DB file. Refuses if NODE_ENV is 'production' or the
39
+ * resolved file lives outside the project root (defensive against
40
+ * misconfigured absolute paths).
41
+ */
42
+ export declare function reset(resolved: ResolvedLocalDb, rootDir: string): void;
43
+ /**
44
+ * Construct the user-facing Kysely instance for the dev DB. Used by
45
+ * `pikku dev` to populate inMemoryServices.kysely.
46
+ * Wires the coercion plugin when db/coercion.gen.ts exists.
47
+ */
48
+ export declare function createKysely<DB>(resolved: ResolvedLocalDb): Promise<Kysely<DB>>;
@@ -0,0 +1,106 @@
1
+ import { DatabaseSync } from 'node:sqlite';
2
+ import { existsSync, mkdirSync, rmSync } from 'node:fs';
3
+ import { resolve, isAbsolute, relative, dirname, join } from 'node:path';
4
+ import { createNodeSqliteKysely, createCoercionPlugin, } from '@pikku/kysely-node-sqlite';
5
+ import { migrate } from './sql-migrator.js';
6
+ import { generateSchemaTypes } from './sqlite-codegen.js';
7
+ import { generateZodTypes } from './zod-codegen.js';
8
+ import { seed as runSeed } from './seed.js';
9
+ /**
10
+ * Resolve a DevDbConfig into absolute paths.
11
+ * - dbFile lives under runtimeDir (default: <rootDir>/.pikku-runtime)
12
+ * - schema/coercion/zod are generated into outDir/db
13
+ * - migrations and seed are authored source under rootDir/db
14
+ */
15
+ export function resolveLocalDb(config, rootDir, outDir, runtimeDir) {
16
+ if (!config)
17
+ return null;
18
+ const file = config === true ? undefined : config.file;
19
+ const resolvedRuntimeDir = runtimeDir ?? join(rootDir, '.pikku-runtime');
20
+ return {
21
+ dbFile: file
22
+ ? resolveAgainst(rootDir, file)
23
+ : join(resolvedRuntimeDir, 'dev.db'),
24
+ runtimeDir: resolvedRuntimeDir,
25
+ migrationsDir: resolveAgainst(rootDir, 'db/migrations'),
26
+ seedFile: resolveAgainst(rootDir, 'db/seed.sql'),
27
+ schemaFile: join(outDir, 'db', 'schema.d.ts'),
28
+ coercionFile: join(outDir, 'db', 'coercion.gen.ts'),
29
+ zodFile: join(outDir, 'db', 'zod.gen.ts'),
30
+ camelCase: true,
31
+ };
32
+ }
33
+ function resolveAgainst(root, p) {
34
+ return isAbsolute(p) ? p : resolve(root, p);
35
+ }
36
+ /**
37
+ * Run the migrate routine (open → tracking-table → drift-check → apply →
38
+ * codegen → close). Used by both `pikku db migrate` and `pikku dev` boot.
39
+ */
40
+ export function migrateAndCodegen(resolved) {
41
+ mkdirSync(dirname(resolved.dbFile), { recursive: true });
42
+ const db = new DatabaseSync(resolved.dbFile);
43
+ try {
44
+ const migrateResult = migrate(db, resolved.migrationsDir);
45
+ const codegenResult = generateSchemaTypes(db, {
46
+ outFile: resolved.schemaFile,
47
+ coercionFile: resolved.coercionFile,
48
+ camelCase: resolved.camelCase,
49
+ migrationsDir: resolved.migrationsDir,
50
+ });
51
+ const zodResult = generateZodTypes({
52
+ schemaFile: resolved.schemaFile,
53
+ outFile: resolved.zodFile,
54
+ });
55
+ return { migrate: migrateResult, codegen: codegenResult, zod: zodResult };
56
+ }
57
+ finally {
58
+ db.close();
59
+ }
60
+ }
61
+ export function seed(resolved) {
62
+ const db = new DatabaseSync(resolved.dbFile);
63
+ try {
64
+ return runSeed(db, resolved.seedFile);
65
+ }
66
+ finally {
67
+ db.close();
68
+ }
69
+ }
70
+ /**
71
+ * Delete the dev DB file. Refuses if NODE_ENV is 'production' or the
72
+ * resolved file lives outside the project root (defensive against
73
+ * misconfigured absolute paths).
74
+ */
75
+ export function reset(resolved, rootDir) {
76
+ if (process.env.NODE_ENV === 'production') {
77
+ throw new Error(`pikku db reset refused: NODE_ENV=production. This command only runs in dev.`);
78
+ }
79
+ const rel = relative(resolved.runtimeDir, resolved.dbFile);
80
+ if (rel.startsWith('..') || isAbsolute(rel)) {
81
+ throw new Error(`pikku db reset refused: resolved DB file (${resolved.dbFile}) is outside the runtime directory (${resolved.runtimeDir}). Override dev.db.file or set runtimeDir correctly.`);
82
+ }
83
+ if (existsSync(resolved.dbFile)) {
84
+ rmSync(resolved.dbFile);
85
+ }
86
+ }
87
+ /**
88
+ * Construct the user-facing Kysely instance for the dev DB. Used by
89
+ * `pikku dev` to populate inMemoryServices.kysely.
90
+ * Wires the coercion plugin when db/coercion.gen.ts exists.
91
+ */
92
+ export async function createKysely(resolved) {
93
+ let coercionMap;
94
+ try {
95
+ const mod = await import(resolved.coercionFile);
96
+ coercionMap = mod.coercionMap;
97
+ }
98
+ catch {
99
+ // coercion.gen.ts not yet generated — run `pikku db migrate` first
100
+ }
101
+ return createNodeSqliteKysely({
102
+ filename: resolved.dbFile,
103
+ camelCase: resolved.camelCase,
104
+ plugins: coercionMap ? [createCoercionPlugin({ map: coercionMap })] : [],
105
+ });
106
+ }
@@ -0,0 +1,11 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ export interface SeedResult {
3
+ applied: boolean;
4
+ bytes: number;
5
+ }
6
+ /**
7
+ * Apply db/seed.sql to the open db. Idempotency is the user's responsibility
8
+ * (e.g. `INSERT OR IGNORE`, upserts). Returns `applied: false` if the file
9
+ * doesn't exist; throws on SQL errors.
10
+ */
11
+ export declare function seed(db: DatabaseSync, seedFile: string): SeedResult;
@@ -0,0 +1,22 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ /**
3
+ * Apply db/seed.sql to the open db. Idempotency is the user's responsibility
4
+ * (e.g. `INSERT OR IGNORE`, upserts). Returns `applied: false` if the file
5
+ * doesn't exist; throws on SQL errors.
6
+ */
7
+ export function seed(db, seedFile) {
8
+ if (!existsSync(seedFile)) {
9
+ return { applied: false, bytes: 0 };
10
+ }
11
+ const raw = readFileSync(seedFile);
12
+ db.exec('BEGIN');
13
+ try {
14
+ db.exec(raw.toString('utf8'));
15
+ db.exec('COMMIT');
16
+ }
17
+ catch (err) {
18
+ db.exec('ROLLBACK');
19
+ throw err;
20
+ }
21
+ return { applied: true, bytes: raw.length };
22
+ }
@@ -0,0 +1,26 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ export declare class MigrationDriftError extends Error {
3
+ readonly file: string;
4
+ readonly recordedHash: string;
5
+ readonly currentHash: string | null;
6
+ readonly appliedAt: string;
7
+ constructor(file: string, recordedHash: string, currentHash: string | null, appliedAt: string);
8
+ }
9
+ export interface MigrateResult {
10
+ applied: string[];
11
+ skipped: string[];
12
+ }
13
+ /**
14
+ * Apply pending migrations from <migrationsDir>/*.sql against the open db.
15
+ * Hashes raw bytes on apply; subsequent runs re-hash and bail with
16
+ * MigrationDriftError if any applied file has changed on disk.
17
+ *
18
+ * The same bytes that get hashed are the bytes passed to db.exec — no
19
+ * splitting, trimming, or normalization. See docs/dev-builtin-sqlite.md.
20
+ */
21
+ export declare function migrate(db: DatabaseSync, migrationsDir: string): MigrateResult;
22
+ /**
23
+ * Wipe the tracking table. Used by `pikku db reset` after the DB file is
24
+ * removed (calling this on its own does NOT drop user tables).
25
+ */
26
+ export declare function dropTrackingTable(db: DatabaseSync): void;
@@ -0,0 +1,104 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFileSync, readdirSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ const TRACKING_TABLE = 'sql_migrations';
5
+ export class MigrationDriftError extends Error {
6
+ file;
7
+ recordedHash;
8
+ currentHash;
9
+ appliedAt;
10
+ constructor(file, recordedHash, currentHash, appliedAt) {
11
+ const onDisk = currentHash === null
12
+ ? 'file missing on disk'
13
+ : `sha256:${currentHash.slice(0, 8)}…`;
14
+ super(`[PKU-DB-DRIFT] db/migrations/${file}\n\n` +
15
+ `Migration content has changed since it was applied.\n` +
16
+ ` recorded: sha256:${recordedHash.slice(0, 8)}… applied ${appliedAt}\n` +
17
+ ` on disk: ${onDisk}\n\n` +
18
+ `If this edit was intentional, run \`pikku db reset\` to rebuild the dev\n` +
19
+ `database from scratch. Production migrations are immutable.`);
20
+ this.file = file;
21
+ this.recordedHash = recordedHash;
22
+ this.currentHash = currentHash;
23
+ this.appliedAt = appliedAt;
24
+ this.name = 'MigrationDriftError';
25
+ }
26
+ }
27
+ function sha256(bytes) {
28
+ return createHash('sha256').update(bytes).digest('hex');
29
+ }
30
+ function ensureTrackingTable(db) {
31
+ db.exec(`CREATE TABLE IF NOT EXISTS ${TRACKING_TABLE} (
32
+ name TEXT PRIMARY KEY,
33
+ hash TEXT NOT NULL,
34
+ applied_at TEXT NOT NULL DEFAULT (datetime('now'))
35
+ )`);
36
+ }
37
+ function listMigrationFiles(migrationsDir) {
38
+ return readdirSync(migrationsDir)
39
+ .filter((f) => f.endsWith('.sql'))
40
+ .sort();
41
+ }
42
+ function readApplied(db) {
43
+ return db
44
+ .prepare(`SELECT name, hash, applied_at FROM ${TRACKING_TABLE} ORDER BY name`)
45
+ .all();
46
+ }
47
+ function checkDrift(applied, migrationsDir) {
48
+ for (const row of applied) {
49
+ let currentHash = null;
50
+ try {
51
+ currentHash = sha256(readFileSync(join(migrationsDir, row.name)));
52
+ }
53
+ catch {
54
+ currentHash = null;
55
+ }
56
+ if (currentHash !== row.hash) {
57
+ throw new MigrationDriftError(row.name, row.hash, currentHash, row.applied_at);
58
+ }
59
+ }
60
+ }
61
+ /**
62
+ * Apply pending migrations from <migrationsDir>/*.sql against the open db.
63
+ * Hashes raw bytes on apply; subsequent runs re-hash and bail with
64
+ * MigrationDriftError if any applied file has changed on disk.
65
+ *
66
+ * The same bytes that get hashed are the bytes passed to db.exec — no
67
+ * splitting, trimming, or normalization. See docs/dev-builtin-sqlite.md.
68
+ */
69
+ export function migrate(db, migrationsDir) {
70
+ ensureTrackingTable(db);
71
+ const applied = readApplied(db);
72
+ checkDrift(applied, migrationsDir);
73
+ const appliedSet = new Set(applied.map((r) => r.name));
74
+ const files = listMigrationFiles(migrationsDir);
75
+ const result = { applied: [], skipped: [] };
76
+ const insertStmt = db.prepare(`INSERT INTO ${TRACKING_TABLE} (name, hash) VALUES (?, ?)`);
77
+ for (const name of files) {
78
+ if (appliedSet.has(name)) {
79
+ result.skipped.push(name);
80
+ continue;
81
+ }
82
+ const raw = readFileSync(join(migrationsDir, name));
83
+ const hash = sha256(raw);
84
+ db.exec('BEGIN');
85
+ try {
86
+ db.exec(raw.toString('utf8'));
87
+ insertStmt.run(name, hash);
88
+ db.exec('COMMIT');
89
+ }
90
+ catch (err) {
91
+ db.exec('ROLLBACK');
92
+ throw err;
93
+ }
94
+ result.applied.push(name);
95
+ }
96
+ return result;
97
+ }
98
+ /**
99
+ * Wipe the tracking table. Used by `pikku db reset` after the DB file is
100
+ * removed (calling this on its own does NOT drop user tables).
101
+ */
102
+ export function dropTrackingTable(db) {
103
+ db.exec(`DROP TABLE IF EXISTS ${TRACKING_TABLE}`);
104
+ }
@@ -0,0 +1,45 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { ColumnKind } from '@pikku/kysely-node-sqlite';
3
+ /** Internal annotation: column kind plus an optional TS type string (for @json). */
4
+ interface ColAnnotation {
5
+ kind: ColumnKind;
6
+ /** TypeScript type string, e.g. `string[]` or `Record<string, number>`. Only set for @json. */
7
+ tsType?: string;
8
+ }
9
+ /** Internal annotation map used during codegen. */
10
+ type AnnotationMap = Record<string, Record<string, ColAnnotation>>;
11
+ /**
12
+ * Parse `-- @bool | @date | @json [TypescriptType]` inline annotations from
13
+ * migration SQL files. The TypeScript type is optional and only meaningful for
14
+ * `@json` — it controls the generated TypeScript type (e.g. `string[]`,
15
+ * `Record<string, number>`).
16
+ *
17
+ * Returns an AnnotationMap: { table_name: { col_name: ColAnnotation } }.
18
+ */
19
+ export declare function parseAnnotations(migrationsDir: string): AnnotationMap;
20
+ export interface CodegenOptions {
21
+ outFile: string;
22
+ coercionFile: string;
23
+ camelCase?: boolean;
24
+ migrationsDir?: string;
25
+ }
26
+ export interface CodegenResult {
27
+ outFile: string;
28
+ coercionFile: string;
29
+ written: boolean;
30
+ coercionWritten: boolean;
31
+ tables: string[];
32
+ }
33
+ /**
34
+ * Introspect the open SQLite database and emit a Kysely DB type to outFile
35
+ * plus a CoercionMap to coercionFile.
36
+ *
37
+ * Columns are annotated via:
38
+ * 1. Naming conventions (_at/_on → date; is_/has_/can_ → bool)
39
+ * 2. Inline SQL comments: `col_name TYPE ... -- @bool|@date|@json [TsType]`
40
+ * For @json, an optional TypeScript type string controls the generated type.
41
+ *
42
+ * Returns `written: false` if the on-disk file already matches.
43
+ */
44
+ export declare function generateSchemaTypes(db: DatabaseSync, options: CodegenOptions): CodegenResult;
45
+ export {};
@@ -0,0 +1,294 @@
1
+ import { readFileSync, writeFileSync, mkdirSync, readdirSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ const SKIP_TABLES = new Set(['sqlite_sequence', 'sql_migrations']);
4
+ function snakeToPascal(name) {
5
+ return name
6
+ .split('_')
7
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
8
+ .join('');
9
+ }
10
+ function snakeToCamel(name) {
11
+ return name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
12
+ }
13
+ function mapType(sqlType) {
14
+ const upper = sqlType.toUpperCase();
15
+ if (upper.includes('INT'))
16
+ return 'number';
17
+ if (upper.includes('CHAR') ||
18
+ upper.includes('CLOB') ||
19
+ upper.includes('TEXT')) {
20
+ return 'string';
21
+ }
22
+ if (upper.includes('BLOB'))
23
+ return 'Buffer';
24
+ if (upper.includes('REAL') ||
25
+ upper.includes('FLOA') ||
26
+ upper.includes('DOUB')) {
27
+ return 'number';
28
+ }
29
+ if (upper.includes('NUMERIC') || upper.includes('DECIMAL'))
30
+ return 'number';
31
+ if (upper.includes('BOOL'))
32
+ return 'number';
33
+ return 'string';
34
+ }
35
+ function listTables(db) {
36
+ const tableRows = db
37
+ .prepare(`SELECT name FROM sqlite_master
38
+ WHERE type = 'table'
39
+ AND name NOT LIKE 'sqlite\\_%' ESCAPE '\\'
40
+ ORDER BY name`)
41
+ .all();
42
+ return tableRows
43
+ .filter((t) => !SKIP_TABLES.has(t.name))
44
+ .map((t) => {
45
+ const allColumns = db
46
+ .prepare(`PRAGMA table_xinfo(${escapeIdentifier(t.name)})`)
47
+ .all();
48
+ // hidden: 0=regular, 2=virtual generated, 3=stored generated — include all; skip 1 (vtab hidden)
49
+ const columns = allColumns.filter((c) => c.hidden !== 1);
50
+ return { name: t.name, columns };
51
+ });
52
+ }
53
+ function escapeIdentifier(name) {
54
+ return `"${name.replace(/"/g, '""')}"`;
55
+ }
56
+ // ─── Annotation parsing ──────────────────────────────────────────────────────
57
+ /**
58
+ * Determine column kind from naming conventions:
59
+ * *_at / *_on → date
60
+ * is_* / has_* / can_* → bool
61
+ */
62
+ function annotationFromName(colName) {
63
+ if (/_at$|_on$/.test(colName))
64
+ return { kind: 'date' };
65
+ if (/^is_|^has_|^can_/.test(colName))
66
+ return { kind: 'bool' };
67
+ return null;
68
+ }
69
+ /**
70
+ * Parse `-- @bool | @date | @json [TypescriptType]` inline annotations from
71
+ * migration SQL files. The TypeScript type is optional and only meaningful for
72
+ * `@json` — it controls the generated TypeScript type (e.g. `string[]`,
73
+ * `Record<string, number>`).
74
+ *
75
+ * Returns an AnnotationMap: { table_name: { col_name: ColAnnotation } }.
76
+ */
77
+ export function parseAnnotations(migrationsDir) {
78
+ let files;
79
+ try {
80
+ files = readdirSync(migrationsDir)
81
+ .filter((f) => f.endsWith('.sql'))
82
+ .sort();
83
+ }
84
+ catch {
85
+ return {};
86
+ }
87
+ const result = {};
88
+ for (const file of files) {
89
+ const content = readFileSync(join(migrationsDir, file), 'utf8');
90
+ const createTablePattern = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?"?(\w+)"?\s*\(([^;]+)\)/gis;
91
+ let tableMatch;
92
+ while ((tableMatch = createTablePattern.exec(content)) !== null) {
93
+ const tableName = tableMatch[1].toLowerCase();
94
+ const body = tableMatch[2];
95
+ for (const line of body.split('\n')) {
96
+ const trimmed = line.trim();
97
+ if (/^(PRIMARY|UNIQUE|CHECK|FOREIGN|CONSTRAINT)/i.test(trimmed))
98
+ continue;
99
+ // Match: col_name TYPE ... -- @kind [optional ts type]
100
+ const annotationMatch = trimmed.match(/^(\w+)\s+\w.*?--\s*@(bool|date|json)(?:\s+(.+?))?$/i);
101
+ if (annotationMatch) {
102
+ const colName = annotationMatch[1].toLowerCase();
103
+ const kind = annotationMatch[2].toLowerCase();
104
+ const tsType = annotationMatch[3]?.trim() || undefined;
105
+ if (!result[tableName])
106
+ result[tableName] = {};
107
+ result[tableName][colName] = {
108
+ kind,
109
+ tsType: kind === 'json' ? tsType : undefined,
110
+ };
111
+ }
112
+ }
113
+ }
114
+ }
115
+ return result;
116
+ }
117
+ /**
118
+ * Merge explicit SQL annotations with naming-convention-based ones.
119
+ * Explicit annotations take precedence.
120
+ */
121
+ function buildAnnotationMap(tables, explicit) {
122
+ const merged = {};
123
+ for (const table of tables) {
124
+ const explicitCols = explicit[table.name] ?? {};
125
+ for (const col of table.columns) {
126
+ const annotation = explicitCols[col.name] ?? annotationFromName(col.name);
127
+ if (annotation) {
128
+ if (!merged[table.name])
129
+ merged[table.name] = {};
130
+ merged[table.name][col.name] = annotation;
131
+ }
132
+ }
133
+ }
134
+ return merged;
135
+ }
136
+ // ─── Type expression ─────────────────────────────────────────────────────────
137
+ function columnTypeExpression(col, annotation) {
138
+ const nullable = !col.notnull && col.pk === 0;
139
+ const hasDefault = col.dflt_value !== null && col.dflt_value !== undefined;
140
+ const isAutoInt = col.pk === 1 && mapType(col.type) === 'number';
141
+ const isGenerated = col.hidden === 2 || col.hidden === 3;
142
+ const wrap = (inner) => hasDefault || isAutoInt || isGenerated ? `Generated<${inner}>` : inner;
143
+ if (annotation?.kind === 'bool') {
144
+ const base = nullable ? 'boolean | null' : 'boolean';
145
+ const rw = nullable ? 'boolean | number | null' : 'boolean | number';
146
+ return wrap(`ColumnType<${base}, ${rw}, ${rw}>`);
147
+ }
148
+ if (annotation?.kind === 'date') {
149
+ const base = nullable ? 'Date | null' : 'Date';
150
+ const rw = nullable ? 'Date | string | null' : 'Date | string';
151
+ return wrap(`ColumnType<${base}, ${rw}, ${rw}>`);
152
+ }
153
+ if (annotation?.kind === 'json') {
154
+ const base = annotation.tsType
155
+ ? nullable
156
+ ? `${annotation.tsType} | null`
157
+ : annotation.tsType
158
+ : nullable
159
+ ? 'unknown | null'
160
+ : 'unknown';
161
+ return wrap(base);
162
+ }
163
+ // Default: plain SQL-mapped type
164
+ const base = mapType(col.type);
165
+ if (isAutoInt)
166
+ return `Generated<${base}>`;
167
+ if (hasDefault || isGenerated)
168
+ return `Generated<${base}${nullable ? ' | null' : ''}>`;
169
+ return nullable ? `${base} | null` : base;
170
+ }
171
+ // ─── Interface emitter ───────────────────────────────────────────────────────
172
+ function emitInterface(table, camelCase, annotations) {
173
+ const ifaceName = snakeToPascal(table.name);
174
+ const tableCols = annotations[table.name] ?? {};
175
+ const fields = table.columns
176
+ .map((col) => {
177
+ const fieldName = camelCase ? snakeToCamel(col.name) : col.name;
178
+ const annotation = tableCols[col.name] ?? null;
179
+ const type = columnTypeExpression(col, annotation);
180
+ const safeName = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(fieldName)
181
+ ? fieldName
182
+ : JSON.stringify(fieldName);
183
+ return ` ${safeName}: ${type}`;
184
+ })
185
+ .join('\n');
186
+ return `export interface ${ifaceName} {\n${fields}\n}`;
187
+ }
188
+ /**
189
+ * Introspect the open SQLite database and emit a Kysely DB type to outFile
190
+ * plus a CoercionMap to coercionFile.
191
+ *
192
+ * Columns are annotated via:
193
+ * 1. Naming conventions (_at/_on → date; is_/has_/can_ → bool)
194
+ * 2. Inline SQL comments: `col_name TYPE ... -- @bool|@date|@json [TsType]`
195
+ * For @json, an optional TypeScript type string controls the generated type.
196
+ *
197
+ * Returns `written: false` if the on-disk file already matches.
198
+ */
199
+ export function generateSchemaTypes(db, options) {
200
+ const camelCase = options.camelCase ?? true;
201
+ const tables = listTables(db);
202
+ const explicitAnnotations = options.migrationsDir
203
+ ? parseAnnotations(options.migrationsDir)
204
+ : {};
205
+ const annotations = buildAnnotationMap(tables, explicitAnnotations);
206
+ // ── schema.d.ts ──
207
+ const interfaces = tables
208
+ .map((t) => emitInterface(t, camelCase, annotations))
209
+ .join('\n\n');
210
+ const dbEntries = tables
211
+ .map((t) => {
212
+ const tableKey = camelCase ? snakeToCamel(t.name) : t.name;
213
+ const safe = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(tableKey)
214
+ ? tableKey
215
+ : JSON.stringify(tableKey);
216
+ return ` ${safe}: ${snakeToPascal(t.name)}`;
217
+ })
218
+ .join('\n');
219
+ const schemaBody = [
220
+ `// Generated by @pikku/cli — do not edit by hand.`,
221
+ `// Run \`pikku db migrate\` to refresh.`,
222
+ ``,
223
+ `import type { ColumnType } from 'kysely'`,
224
+ ``,
225
+ `export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>`,
226
+ ` ? ColumnType<S, I | undefined, U>`,
227
+ ` : ColumnType<T, T | undefined, T>`,
228
+ ``,
229
+ interfaces,
230
+ ``,
231
+ `export interface DB {`,
232
+ dbEntries,
233
+ `}`,
234
+ ``,
235
+ ].join('\n');
236
+ // ── coercion.gen.ts (runtime map — only kind, not tsType) ──
237
+ const runtimeMap = {};
238
+ for (const [table, cols] of Object.entries(annotations)) {
239
+ for (const [col, ann] of Object.entries(cols)) {
240
+ if (!runtimeMap[table])
241
+ runtimeMap[table] = {};
242
+ runtimeMap[table][col] = ann.kind;
243
+ }
244
+ }
245
+ const coercionEntries = Object.entries(runtimeMap)
246
+ .map(([table, cols]) => {
247
+ const colEntries = Object.entries(cols)
248
+ .map(([col, kind]) => ` "${col}": "${kind}"`)
249
+ .join(',\n');
250
+ return ` "${table}": {\n${colEntries}\n }`;
251
+ })
252
+ .join(',\n');
253
+ const coercionBody = [
254
+ `// Generated by @pikku/cli — do not edit by hand.`,
255
+ `// Run \`pikku db migrate\` to refresh.`,
256
+ ``,
257
+ `export const coercionMap = {`,
258
+ coercionEntries,
259
+ `} as const`,
260
+ ``,
261
+ ].join('\n');
262
+ // ── write files ──
263
+ let existingSchema = null;
264
+ let existingCoercion = null;
265
+ try {
266
+ existingSchema = readFileSync(options.outFile, 'utf8');
267
+ }
268
+ catch {
269
+ /* ok */
270
+ }
271
+ try {
272
+ existingCoercion = readFileSync(options.coercionFile, 'utf8');
273
+ }
274
+ catch {
275
+ /* ok */
276
+ }
277
+ const schemaChanged = existingSchema !== schemaBody;
278
+ const coercionChanged = existingCoercion !== coercionBody;
279
+ if (schemaChanged) {
280
+ mkdirSync(dirname(options.outFile), { recursive: true });
281
+ writeFileSync(options.outFile, schemaBody, 'utf8');
282
+ }
283
+ if (coercionChanged) {
284
+ mkdirSync(dirname(options.coercionFile), { recursive: true });
285
+ writeFileSync(options.coercionFile, coercionBody, 'utf8');
286
+ }
287
+ return {
288
+ outFile: options.outFile,
289
+ coercionFile: options.coercionFile,
290
+ written: schemaChanged,
291
+ coercionWritten: coercionChanged,
292
+ tables: tables.map((t) => t.name),
293
+ };
294
+ }