@sdxc/kit 2026.10.16 → 2026.10.20

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 (358) hide show
  1. package/README.md +391 -20
  2. package/changelog.jsonl +1160 -1035
  3. package/config.schema.json +47 -1
  4. package/dist/author.d.ts +36 -0
  5. package/dist/author.js +107 -0
  6. package/dist/cli.js +12 -0
  7. package/dist/commands/create.js +9 -4
  8. package/dist/commands/deploy.d.ts +23 -0
  9. package/dist/commands/deploy.js +167 -0
  10. package/dist/commands/destroy.d.ts +22 -0
  11. package/dist/commands/destroy.js +92 -0
  12. package/dist/commands/doctor.d.ts +26 -0
  13. package/dist/commands/doctor.js +65 -0
  14. package/dist/commands/initializers.d.ts +16 -0
  15. package/dist/commands/initializers.js +23 -0
  16. package/dist/commands/make.d.ts +72 -6
  17. package/dist/commands/make.js +127 -19
  18. package/dist/commands/middleware.d.ts +16 -0
  19. package/dist/commands/middleware.js +21 -0
  20. package/dist/commands/models.d.ts +18 -0
  21. package/dist/commands/models.js +29 -0
  22. package/dist/commands/notes.d.ts +17 -0
  23. package/dist/commands/notes.js +27 -0
  24. package/dist/commands/routes.d.ts +25 -0
  25. package/dist/commands/routes.js +50 -0
  26. package/dist/commands/run.d.ts +18 -2
  27. package/dist/commands/run.js +35 -12
  28. package/dist/commands/scaffold.d.ts +29 -0
  29. package/dist/commands/scaffold.js +33 -0
  30. package/dist/commands/schedule.d.ts +16 -0
  31. package/dist/commands/schedule.js +21 -0
  32. package/dist/commands/stats.d.ts +16 -0
  33. package/dist/commands/stats.js +21 -0
  34. package/dist/commands/ui/update.d.ts +6 -3
  35. package/dist/commands/ui/update.js +24 -7
  36. package/dist/commands/upgrade.d.ts +3 -1
  37. package/dist/commands/upgrade.js +88 -23
  38. package/dist/config.d.ts +18 -0
  39. package/dist/config.js +28 -1
  40. package/dist/contract.d.ts +97 -3
  41. package/dist/contract.js +360 -26
  42. package/dist/create/templates.d.ts +8 -1
  43. package/dist/create/templates.js +26 -2
  44. package/dist/dependencies.d.ts +4 -1
  45. package/dist/dependencies.js +13 -1
  46. package/dist/deploy/plan.d.ts +49 -0
  47. package/dist/deploy/plan.js +68 -0
  48. package/dist/destroy.d.ts +40 -0
  49. package/dist/destroy.js +311 -0
  50. package/dist/doctor/check.d.ts +71 -0
  51. package/dist/doctor/check.js +53 -0
  52. package/dist/doctor/checks.d.ts +23 -0
  53. package/dist/doctor/checks.js +68 -0
  54. package/dist/doctor/define.d.ts +59 -0
  55. package/dist/doctor/define.js +16 -0
  56. package/dist/doctor/emails.d.ts +18 -0
  57. package/dist/doctor/emails.js +243 -0
  58. package/dist/doctor/env.d.ts +26 -0
  59. package/dist/doctor/env.js +88 -0
  60. package/dist/doctor/files.d.ts +14 -0
  61. package/dist/doctor/files.js +34 -0
  62. package/dist/doctor/fixture.d.ts +23 -0
  63. package/dist/doctor/fixture.js +46 -0
  64. package/dist/doctor/install.d.ts +17 -0
  65. package/dist/doctor/install.js +37 -0
  66. package/dist/doctor/installed.d.ts +11 -0
  67. package/dist/doctor/installed.js +79 -0
  68. package/dist/doctor/layout.d.ts +23 -0
  69. package/dist/doctor/layout.js +83 -0
  70. package/dist/doctor/migrations.d.ts +16 -0
  71. package/dist/doctor/migrations.js +96 -0
  72. package/dist/doctor/models.d.ts +13 -0
  73. package/dist/doctor/models.js +69 -0
  74. package/dist/doctor/pins.d.ts +15 -0
  75. package/dist/doctor/pins.js +79 -0
  76. package/dist/doctor/project.d.ts +58 -0
  77. package/dist/doctor/project.js +261 -0
  78. package/dist/doctor/remix.d.ts +14 -0
  79. package/dist/doctor/remix.js +44 -0
  80. package/dist/doctor/routes.d.ts +11 -0
  81. package/dist/doctor/routes.js +49 -0
  82. package/dist/doctor/typegen.d.ts +13 -0
  83. package/dist/doctor/typegen.js +57 -0
  84. package/dist/doctor/ui.d.ts +14 -0
  85. package/dist/doctor/ui.js +51 -0
  86. package/dist/init.d.ts +5 -3
  87. package/dist/init.js +15 -7
  88. package/dist/initializers.d.ts +25 -0
  89. package/dist/initializers.js +89 -0
  90. package/dist/lock.d.ts +2 -2
  91. package/dist/make/actions.d.ts +23 -0
  92. package/dist/make/actions.js +82 -0
  93. package/dist/make/declare.d.ts +32 -4
  94. package/dist/make/declare.js +405 -27
  95. package/dist/make/email.d.ts +23 -0
  96. package/dist/make/email.js +111 -0
  97. package/dist/make/from-fields.d.ts +30 -0
  98. package/dist/make/from-fields.js +162 -0
  99. package/dist/make/from-model.d.ts +39 -0
  100. package/dist/make/from-model.js +161 -0
  101. package/dist/make/generate.d.ts +16 -5
  102. package/dist/make/generate.js +43 -14
  103. package/dist/make/guard.d.ts +35 -0
  104. package/dist/make/guard.js +73 -0
  105. package/dist/make/imports.d.ts +6 -0
  106. package/dist/make/imports.js +19 -0
  107. package/dist/make/index.d.ts +47 -4
  108. package/dist/make/index.js +287 -25
  109. package/dist/make/kinds.d.ts +31 -3
  110. package/dist/make/kinds.js +82 -9
  111. package/dist/make/mount.d.ts +25 -0
  112. package/dist/make/mount.js +135 -0
  113. package/dist/make/schema-diff.d.ts +58 -0
  114. package/dist/make/schema-diff.js +609 -0
  115. package/dist/make/schema.d.ts +76 -0
  116. package/dist/make/schema.js +206 -0
  117. package/dist/make/stubs.d.ts +7 -5
  118. package/dist/make/stubs.js +16 -5
  119. package/dist/make/test.d.ts +43 -0
  120. package/dist/make/test.js +149 -0
  121. package/dist/make/trigger.d.ts +31 -0
  122. package/dist/make/trigger.js +163 -0
  123. package/dist/models.d.ts +42 -0
  124. package/dist/models.js +149 -0
  125. package/dist/notes.d.ts +28 -0
  126. package/dist/notes.js +66 -0
  127. package/dist/reference.d.ts +27 -0
  128. package/dist/reference.js +103 -0
  129. package/dist/releases.d.ts +9 -0
  130. package/dist/releases.js +29 -8
  131. package/dist/routes/chains.d.ts +34 -0
  132. package/dist/routes/chains.js +95 -0
  133. package/dist/routes/filter.d.ts +53 -0
  134. package/dist/routes/filter.js +147 -0
  135. package/dist/routes/format.d.ts +23 -0
  136. package/dist/routes/format.js +123 -0
  137. package/dist/routes/helpers.d.ts +21 -0
  138. package/dist/routes/helpers.js +165 -0
  139. package/dist/routes/index.d.ts +56 -0
  140. package/dist/routes/index.js +167 -0
  141. package/dist/routes/modules.d.ts +116 -0
  142. package/dist/routes/modules.js +235 -0
  143. package/dist/routes/parse.d.ts +161 -0
  144. package/dist/routes/parse.js +621 -0
  145. package/dist/routes/routers.d.ts +69 -0
  146. package/dist/routes/routers.js +327 -0
  147. package/dist/scaffold/fields.d.ts +129 -0
  148. package/dist/scaffold/fields.js +421 -0
  149. package/dist/scaffold/index.d.ts +37 -0
  150. package/dist/scaffold/index.js +613 -0
  151. package/dist/scaffold/render.d.ts +51 -0
  152. package/dist/scaffold/render.js +332 -0
  153. package/dist/schedule.d.ts +45 -0
  154. package/dist/schedule.js +124 -0
  155. package/dist/stats.d.ts +37 -0
  156. package/dist/stats.js +126 -0
  157. package/dist/testing.d.ts +12 -2
  158. package/dist/testing.js +22 -3
  159. package/dist/ui/commands.d.ts +10 -3
  160. package/dist/ui/commands.js +85 -15
  161. package/dist/ui/registry.d.ts +8 -8
  162. package/dist/upgrade/agents.d.ts +49 -0
  163. package/dist/upgrade/agents.js +110 -0
  164. package/dist/upgrade/changelog.d.ts +2 -2
  165. package/dist/upgrade/project.d.ts +4 -0
  166. package/dist/upgrade/project.js +11 -1
  167. package/dist/upgrade/prompt.d.ts +11 -0
  168. package/dist/upgrade/prompt.js +50 -7
  169. package/package.json +6 -4
  170. package/registry/ui/alert-dialog.json +2 -2
  171. package/registry/ui/attachment.json +2 -2
  172. package/registry/ui/calendar.json +2 -2
  173. package/registry/ui/color-picker.json +2 -2
  174. package/registry/ui/command.json +2 -2
  175. package/registry/ui/date-picker.json +2 -2
  176. package/registry/ui/date-range-picker.json +2 -2
  177. package/registry/ui/dialog.json +2 -2
  178. package/registry/ui/file-trigger.json +2 -2
  179. package/registry/ui/heading-scope.json +2 -2
  180. package/registry/ui/message-scroller.json +2 -2
  181. package/registry/ui/number-field.json +2 -2
  182. package/registry/ui/range-calendar.json +2 -2
  183. package/registry/ui/resizable.json +2 -2
  184. package/registry/ui/select.json +2 -2
  185. package/registry/ui/shared-element.json +2 -2
  186. package/stubs/command.stub +4 -0
  187. package/stubs/command.test.stub +3 -0
  188. package/stubs/controller.api.resource.stub +23 -0
  189. package/stubs/controller.api.stub +21 -0
  190. package/stubs/controller.api.test.stub +18 -0
  191. package/stubs/controller.form.stub +40 -10
  192. package/stubs/controller.form.test.stub +61 -0
  193. package/stubs/controller.resource.form.stub +67 -0
  194. package/stubs/controller.resource.stub +28 -0
  195. package/stubs/controller.stub +15 -8
  196. package/stubs/controller.test.stub +3 -0
  197. package/stubs/email.stub +15 -38
  198. package/stubs/email.test.stub +12 -7
  199. package/stubs/factory.stub +4 -1
  200. package/stubs/initializer.stub +2 -0
  201. package/stubs/initializer.test.stub +3 -0
  202. package/stubs/job.cron.stub +4 -0
  203. package/stubs/job.stub +4 -0
  204. package/stubs/job.test.stub +3 -0
  205. package/stubs/mcp.resource.stub +3 -0
  206. package/stubs/mcp.stub +3 -0
  207. package/stubs/mcp.test.stub +3 -0
  208. package/stubs/middleware.stub +6 -1
  209. package/stubs/middleware.test.stub +3 -0
  210. package/stubs/model.stub +12 -3
  211. package/stubs/model.test.stub +3 -0
  212. package/stubs/policy.test.stub +36 -7
  213. package/stubs/scaffold.api.create.stub +34 -0
  214. package/stubs/scaffold.api.create.test.stub +37 -0
  215. package/stubs/scaffold.api.destroy.stub +34 -0
  216. package/stubs/scaffold.api.destroy.test.stub +44 -0
  217. package/stubs/scaffold.api.index.stub +23 -0
  218. package/stubs/scaffold.api.index.test.stub +31 -0
  219. package/stubs/scaffold.api.show.stub +27 -0
  220. package/stubs/scaffold.api.show.test.stub +41 -0
  221. package/stubs/scaffold.api.update.stub +44 -0
  222. package/stubs/scaffold.api.update.test.stub +46 -0
  223. package/stubs/scaffold.command.create.stub +22 -0
  224. package/stubs/scaffold.command.create.test.stub +30 -0
  225. package/stubs/scaffold.command.delete.stub +20 -0
  226. package/stubs/scaffold.command.delete.test.stub +39 -0
  227. package/stubs/scaffold.command.list.stub +18 -0
  228. package/stubs/scaffold.command.list.test.stub +31 -0
  229. package/stubs/scaffold.command.show.stub +19 -0
  230. package/stubs/scaffold.command.show.test.stub +37 -0
  231. package/stubs/scaffold.controller.destroy.stub +35 -0
  232. package/stubs/scaffold.controller.destroy.test.stub +65 -0
  233. package/stubs/scaffold.controller.edit.stub +97 -0
  234. package/stubs/scaffold.controller.edit.test.stub +91 -0
  235. package/stubs/scaffold.controller.index.stub +55 -0
  236. package/stubs/scaffold.controller.index.test.stub +32 -0
  237. package/stubs/scaffold.controller.new.stub +70 -0
  238. package/stubs/scaffold.controller.new.test.stub +81 -0
  239. package/stubs/scaffold.controller.show.stub +59 -0
  240. package/stubs/scaffold.controller.show.test.stub +43 -0
  241. package/stubs/scaffold.factory.stub +16 -0
  242. package/stubs/scaffold.form.stub +75 -0
  243. package/stubs/scaffold.mcp.create.stub +24 -0
  244. package/stubs/scaffold.mcp.create.test.stub +36 -0
  245. package/stubs/scaffold.mcp.delete.stub +31 -0
  246. package/stubs/scaffold.mcp.delete.test.stub +43 -0
  247. package/stubs/scaffold.mcp.get.stub +21 -0
  248. package/stubs/scaffold.mcp.get.test.stub +31 -0
  249. package/stubs/scaffold.mcp.list.stub +23 -0
  250. package/stubs/scaffold.mcp.list.test.stub +25 -0
  251. package/stubs/scaffold.mcp.update.stub +37 -0
  252. package/stubs/scaffold.mcp.update.test.stub +40 -0
  253. package/stubs/scaffold.migration.stub +2 -0
  254. package/stubs/scaffold.model.stub +35 -0
  255. package/stubs/scaffold.model.test.stub +25 -0
  256. package/stubs/scaffold.test-database.stub +33 -0
  257. package/stubs/scaffold.test-mcp.stub +92 -0
  258. package/stubs/scaffold.validator.stub +18 -0
  259. package/stubs/scaffold.validator.test.stub +26 -0
  260. package/stubs/service.stub +4 -0
  261. package/stubs/service.test.stub +3 -0
  262. package/stubs/validator.stub +3 -0
  263. package/stubs/validator.test.stub +3 -0
  264. package/templates/app/.env.example +16 -0
  265. package/templates/app/AGENTS.md +163 -0
  266. package/templates/app/CLAUDE.md +1 -0
  267. package/templates/app/README.md +79 -37
  268. package/templates/app/app/commands/about.test.ts +1 -1
  269. package/templates/app/app/commands/console.test.ts +26 -0
  270. package/templates/app/app/commands/console.ts +19 -0
  271. package/templates/app/app/commands/db/console.ts +6 -0
  272. package/templates/app/app/commands/db/fresh.test.ts +57 -0
  273. package/templates/app/app/commands/db/fresh.ts +37 -0
  274. package/templates/app/app/commands/db/migrate.test.ts +46 -0
  275. package/templates/app/app/commands/db/migrate.ts +88 -0
  276. package/templates/app/app/commands/db/prepare.test.ts +39 -0
  277. package/templates/app/app/commands/db/prepare.ts +35 -0
  278. package/templates/app/app/commands/db/seed.test.ts +38 -0
  279. package/templates/app/app/commands/db/seed.ts +26 -0
  280. package/templates/app/app/commands/deploy.test.ts +34 -0
  281. package/templates/app/app/commands/deploy.ts +18 -0
  282. package/templates/app/app/commands/emails/preview.test.tsx +63 -0
  283. package/templates/app/app/commands/emails/preview.ts +24 -0
  284. package/templates/app/app/commands/index.ts +72 -1
  285. package/templates/app/app/commands/typegen.test.ts +17 -0
  286. package/templates/app/app/commands/typegen.ts +16 -0
  287. package/templates/app/app/emails/index.ts +10 -0
  288. package/templates/app/app/http/controllers/api/health.tsx +15 -0
  289. package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
  290. package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
  291. package/templates/app/app/http/controllers/home.tsx +21 -13
  292. package/templates/app/app/http/controllers/mcp.tsx +16 -0
  293. package/templates/app/app/http/controllers/not-found.tsx +23 -18
  294. package/templates/app/app/http/controllers/robots.test.ts +18 -0
  295. package/templates/app/app/http/controllers/robots.ts +24 -0
  296. package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
  297. package/templates/app/app/http/controllers/sitemap.ts +25 -0
  298. package/templates/app/app/http/middleware/access.test.ts +43 -0
  299. package/templates/app/app/http/middleware/access.ts +41 -0
  300. package/templates/app/app/http/middleware/api.ts +19 -0
  301. package/templates/app/app/http/middleware/page.test.ts +43 -0
  302. package/templates/app/app/http/middleware/page.ts +51 -0
  303. package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
  304. package/templates/app/app/http/middleware/server-timing.ts +42 -0
  305. package/templates/app/app/initializers/assets.ts +1 -1
  306. package/templates/app/app/initializers/captcha.ts +11 -0
  307. package/templates/app/app/initializers/cli.ts +68 -2
  308. package/templates/app/app/initializers/database.test.ts +18 -0
  309. package/templates/app/app/initializers/database.ts +18 -0
  310. package/templates/app/app/initializers/dispatcher.ts +26 -0
  311. package/templates/app/app/initializers/honeypot.ts +11 -0
  312. package/templates/app/app/initializers/i18n.test.ts +16 -0
  313. package/templates/app/app/initializers/i18n.ts +28 -0
  314. package/templates/app/app/initializers/local-database.test.ts +33 -0
  315. package/templates/app/app/initializers/local-database.ts +53 -0
  316. package/templates/app/app/initializers/mail-transport.test.ts +27 -0
  317. package/templates/app/app/initializers/mail-transport.ts +26 -0
  318. package/templates/app/app/initializers/mail.test.ts +27 -0
  319. package/templates/app/app/initializers/mail.ts +19 -0
  320. package/templates/app/app/initializers/mcp.ts +1 -1
  321. package/templates/app/app/initializers/openapi.ts +21 -0
  322. package/templates/app/app/initializers/router.test.ts +68 -0
  323. package/templates/app/app/initializers/router.tsx +81 -25
  324. package/templates/app/app/initializers/seo.ts +15 -0
  325. package/templates/app/app/initializers/session.test.ts +34 -0
  326. package/templates/app/app/initializers/session.ts +29 -0
  327. package/templates/app/app/initializers/spam.ts +10 -0
  328. package/templates/app/app/jobs/email.test.tsx +70 -0
  329. package/templates/app/app/jobs/email.ts +16 -0
  330. package/templates/app/app/jobs/index.ts +6 -2
  331. package/templates/app/app/models/index.ts +10 -0
  332. package/templates/app/app/policies/abilities.ts +13 -0
  333. package/templates/app/app/policies/policy.test.ts +15 -0
  334. package/templates/app/app/policies/policy.ts +30 -0
  335. package/templates/app/app/services/commands.ts +30 -0
  336. package/templates/app/app/services/migrations.test.ts +92 -0
  337. package/templates/app/app/services/migrations.ts +117 -0
  338. package/templates/app/app/test/cloudflare-workers.ts +25 -0
  339. package/templates/app/app/test/local-database.ts +67 -0
  340. package/templates/app/app/test/session.ts +28 -0
  341. package/templates/app/bootstrap/cli.ts +1 -1
  342. package/templates/app/bootstrap/console.ts +13 -0
  343. package/templates/app/bootstrap/worker.ts +4 -4
  344. package/templates/app/cloudflare.config.ts +30 -2
  345. package/templates/app/config/constants.ts +19 -0
  346. package/templates/app/config/problems.ts +24 -0
  347. package/templates/app/config/security-policy.ts +34 -0
  348. package/templates/app/config/security-txt.ts +28 -0
  349. package/templates/app/database/migrations/.gitkeep +0 -0
  350. package/templates/app/database/seed.ts +12 -0
  351. package/templates/app/package.json +37 -6
  352. package/templates/app/resources/layouts/document.tsx +28 -7
  353. package/templates/app/resources/locales/en.json +10 -0
  354. package/templates/app/routes/api.ts +29 -0
  355. package/templates/app/routes/web.ts +6 -4
  356. package/templates/app/vite.config.ts +4 -0
  357. package/stubs/policy.stub +0 -13
  358. package/templates/app/config/router-context.d.ts +0 -20
@@ -0,0 +1,89 @@
1
+ /**
2
+ * `sdxc initializers`: every module in `app/initializers/`, what it exports and the factories
3
+ * it builds them with, such as `createRouter` from `remix/router`, so where the app's one
4
+ * instance of each thing comes from reads as one table.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { readFile } from "node:fs/promises";
10
+ import { join } from "node:path";
11
+ import { isFailure, wrap } from "@sdxc/result";
12
+ import { isAppSource, listFiles } from "./doctor/files.js";
13
+ /** The folder the layout gives initializers. */
14
+ const INITIALIZERS_FOLDER = "app/initializers";
15
+ /** An imported name that builds an instance: `createRouter`, `openDatabase`, `defineFlags`… */
16
+ const FACTORY = /^(?:create|open|define|connect)[A-Z]\w*$/;
17
+ /**
18
+ * Each named import of `source` from a package, by local name, with the package it comes from.
19
+ * Node's built-in modules and the app's own modules build nothing of the app's, so they are
20
+ * left out.
21
+ */
22
+ function namedImports(source) {
23
+ let imports = new Map();
24
+ for (let match of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*"([^"]+)"/g)) {
25
+ if (match[0].startsWith("import type") || /^(?:node:|~\/|\.)/.test(match[2] ?? ""))
26
+ continue;
27
+ for (let part of (match[1] ?? "").split(",")) {
28
+ let [imported = "", local = imported] = part
29
+ .trim()
30
+ .replace(/^type\s+/, "")
31
+ .split(/\s+as\s+/);
32
+ if (imported !== "")
33
+ imports.set(local.trim(), { imported: imported.trim(), from: match[2] ?? "" });
34
+ }
35
+ }
36
+ return imports;
37
+ }
38
+ /** The names `source` exports, `default` for its default export, in source order. */
39
+ export function exportedNames(source) {
40
+ let names = [];
41
+ for (let match of source.matchAll(/export\s+(?:async\s+)?(?:const|let|function\*?|class)\s+([A-Za-z_$][\w$]*)/g)) {
42
+ names.push([match.index, match[1]]);
43
+ }
44
+ for (let match of source.matchAll(/export\s+default\b/g))
45
+ names.push([match.index, "default"]);
46
+ for (let match of source.matchAll(/export\s*\{([^}]*)\}(?!\s*from)/g)) {
47
+ for (let part of (match[1] ?? "").split(",")) {
48
+ let name = part
49
+ .trim()
50
+ .split(/\s+as\s+/)
51
+ .at(-1)
52
+ ?.trim() ?? "";
53
+ if (name !== "" && !name.startsWith("type "))
54
+ names.push([match.index, name]);
55
+ }
56
+ }
57
+ return names.sort((a, b) => a[0] - b[0]).map(([, name]) => name);
58
+ }
59
+ /** Reads every initializer of the project at `root`, tests left out. */
60
+ export async function listInitializers(root) {
61
+ let initializers = [];
62
+ for (let file of (await listFiles(root, INITIALIZERS_FOLDER)).filter(isAppSource)) {
63
+ let source = await wrap(() => readFile(join(root, file), "utf8"));
64
+ if (isFailure(source))
65
+ continue;
66
+ let factories = [...namedImports(source.data)]
67
+ .filter(([local, { imported }]) => FACTORY.test(imported) && new RegExp(`\\b${local}\\s*\\(`).test(source.data))
68
+ .map(([, { imported, from }]) => ({ name: imported, from }));
69
+ initializers.push({ file, exports: exportedNames(source.data), factories });
70
+ }
71
+ return initializers;
72
+ }
73
+ /** The initializers as a table: file, exports, and the factories that build them. */
74
+ export function formatInitializers(initializers) {
75
+ if (initializers.length === 0)
76
+ return `No initializers in ${INITIALIZERS_FOLDER}/.\n`;
77
+ let rows = initializers.map((initializer) => [
78
+ initializer.file,
79
+ initializer.exports.join(", "),
80
+ initializer.factories.map((factory) => `${factory.name} (${factory.from})`).join(", "),
81
+ ]);
82
+ let header = ["File", "Exports", "Built with"];
83
+ let widths = header.map((title, column) => Math.max(title.length, ...rows.map((row) => row[column]?.length ?? 0)));
84
+ let line = (row) => row
85
+ .map((cell, column) => cell.padEnd(widths[column] ?? 0))
86
+ .join(" ")
87
+ .trimEnd();
88
+ return `${[line(header), ...rows.map(line)].join("\n")}\n`;
89
+ }
package/dist/lock.d.ts CHANGED
@@ -16,13 +16,13 @@ export declare const DEFAULT_LOCK = ".config/sdxc.lock.jsonl";
16
16
  export declare const UI_LOCK_ENTRY: s.Schema<{
17
17
  name: string;
18
18
  kind: "ui";
19
- release: string;
20
19
  files: Record<string, string>;
20
+ release: string;
21
21
  }, {
22
22
  name: string;
23
23
  kind: "ui";
24
- release: string;
25
24
  files: Record<string, string>;
25
+ release: string;
26
26
  }>;
27
27
  /** A `ui` entry as the commands read and write it. */
28
28
  export type UILockEntry = s.InferOutput<typeof UI_LOCK_ENTRY>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `sdxc make controller <name> --actions`: one controller per action of a resource, each
3
+ * declared under `<name>` with the method and route a resource's pages or JSON endpoints take,
4
+ * and, with `--resource`, guarded by the ability the action needs.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Result } from "@sdxc/result";
10
+ import type { Project } from "../middleware.js";
11
+ import type { MakeContext, MakeInput } from "./index.js";
12
+ /** What `--actions` was given beside the controller's own flags. */
13
+ export interface ActionsInput extends Omit<MakeInput, "kind" | "method" | "path" | "ability"> {
14
+ actions: readonly string[];
15
+ }
16
+ /**
17
+ * Makes one controller per action in `input.actions` under `input.name`, in the order the
18
+ * contract lists them. Every action's file is checked free before the first is written, so a
19
+ * taken name stops the run with nothing written.
20
+ *
21
+ * @param packageRoot - The `@sdxc/kit` package, whose `stubs/` holds the built-in stubs.
22
+ */
23
+ export declare function makeActions(ctx: MakeContext, project: Project, packageRoot: string, input: ActionsInput): Promise<Result<void, Error>>;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `sdxc make controller <name> --actions`: one controller per action of a resource, each
3
+ * declared under `<name>` with the method and route a resource's pages or JSON endpoints take,
4
+ * and, with `--resource`, guarded by the ability the action needs.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { failure, isFailure } from "@sdxc/result";
10
+ import { exists } from "./generate.js";
11
+ import { parseName } from "./names.js";
12
+ import { finish, makeUnformatted } from "./index.js";
13
+ /** The pages of a resource, as `sdxc scaffold` routes them. */
14
+ const PAGE_ACTIONS = {
15
+ index: { method: "get", suffix: "", ability: null },
16
+ new: { method: "form", suffix: "/new", ability: "create" },
17
+ show: { method: "get", suffix: "/:id", ability: "read" },
18
+ edit: { method: "form", suffix: "/:id/edit", ability: "update" },
19
+ destroy: { method: "post", suffix: "/:id/destroy", ability: "delete" },
20
+ };
21
+ /** The JSON endpoints of a resource, one per method. */
22
+ const API_ACTIONS = {
23
+ index: { method: "get", suffix: "", ability: null },
24
+ show: { method: "get", suffix: "/:id", ability: "read" },
25
+ create: { method: "post", suffix: "", ability: "create" },
26
+ update: { method: "patch", suffix: "/:id", ability: "update" },
27
+ destroy: { method: "delete", suffix: "/:id", ability: "delete" },
28
+ };
29
+ /** The contract whose controllers answer JSON, so its actions are the endpoints. */
30
+ const API_CONTRACT = "api";
31
+ /**
32
+ * Makes one controller per action in `input.actions` under `input.name`, in the order the
33
+ * contract lists them. Every action's file is checked free before the first is written, so a
34
+ * taken name stops the run with nothing written.
35
+ *
36
+ * @param packageRoot - The `@sdxc/kit` package, whose `stubs/` holds the built-in stubs.
37
+ */
38
+ export async function makeActions(ctx, project, packageRoot, input) {
39
+ let routes = input.routes ?? project.config.make.routes;
40
+ let table = routes === API_CONTRACT ? API_ACTIONS : PAGE_ACTIONS;
41
+ let wanted = input.actions.includes("all") ? Object.keys(table) : [...new Set(input.actions)];
42
+ let unknown = wanted.filter((action) => !(action in table));
43
+ if (unknown.length > 0) {
44
+ let contract = routes === API_CONTRACT ? "the api contract" : `routes/${routes}`;
45
+ return failure(new Error(`${unknown.join(", ")} ${unknown.length === 1 ? "is not an action" : "are not actions"} of ${contract}; use ${Object.keys(table).join(", ")} or all`));
46
+ }
47
+ let base = parseName(input.name);
48
+ if (isFailure(base))
49
+ return base;
50
+ let folder = base.data.segments.join("/");
51
+ let ordered = Object.keys(table).filter((action) => wanted.includes(action));
52
+ for (let action of ordered) {
53
+ let path = `app/http/controllers/${folder}/${action}.tsx`;
54
+ if (input.force !== true && (await exists(project.root, path))) {
55
+ return failure(new Error(`${path} already exists; sdxc make leaves it as it is unless --force`));
56
+ }
57
+ }
58
+ let changed = [];
59
+ let notes = [];
60
+ for (let action of ordered) {
61
+ let route = table[action];
62
+ let guarded = input.guardedBy !== undefined && route.ability !== null;
63
+ let made = await makeUnformatted(ctx, project, packageRoot, {
64
+ ...input,
65
+ kind: "controller",
66
+ name: `${folder}/${action}`,
67
+ method: route.method,
68
+ path: `/${folder}${route.suffix}`,
69
+ routes,
70
+ guardedBy: guarded ? input.guardedBy : undefined,
71
+ ability: guarded ? (route.ability ?? undefined) : undefined,
72
+ });
73
+ if (isFailure(made))
74
+ return made;
75
+ changed.push(...made.data.changed.filter((path) => !changed.includes(path)));
76
+ notes.push(...made.data.notes.filter((note) => !notes.includes(note)));
77
+ }
78
+ if (input.guardedBy !== undefined && ordered.includes("index")) {
79
+ notes.push(`${folder}/index lists rows, so it checks no single one; show each row a visitor may read with ctx.access.can(abilities.<resource>.read, { <resource>: row })\n`);
80
+ }
81
+ return finish(ctx, project, { changed, notes });
82
+ }
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Declares and maps what `make job`, `make controller`, `make mcp` and `make command` generate:
3
3
  * the entry in the job map, route contract, MCP or command declaration module, and the mapping
4
- * in the initializer that serves it, so the new handler answers as soon as the command finishes. Both edits are
5
- * computed before anything is written; when either cannot be placed, neither is made and the
6
- * command prints them for the user instead, so a declaration never ships without its mapping.
4
+ * in the initializer that serves it, plus a page's sitemap decision; `make model` registers the
5
+ * model in `app/models/index.ts` and `make policy` a resource's abilities and grants the same
6
+ * way. Every edit is computed before anything is written; when one cannot be placed, none is
7
+ * made and the command prints them for the user instead.
7
8
  *
8
9
  * @author [Sergio Xalambrí](https://sergiodxa.com)
9
10
  * @copyright Sergio Xalambrí 2026
@@ -11,7 +12,7 @@
11
12
  import type { Name } from "./names.js";
12
13
  /** What to declare and map, as the command line asked for it. */
13
14
  export interface DeclarationRequest {
14
- kind: "job" | "controller" | "mcp" | "command";
15
+ kind: "job" | "controller" | "mcp" | "command" | "model" | "policy" | "email";
15
16
  name: Name;
16
17
  /** `cron` for a scheduled job, `resource` for an MCP resource, `null` otherwise. */
17
18
  variant: string | null;
@@ -29,6 +30,20 @@ export interface DeclarationRequest {
29
30
  tool: string;
30
31
  uri: string;
31
32
  title: string;
33
+ /** A page's sitemap decision in place of the one its pattern implies. */
34
+ sitemap?: string;
35
+ /** A tool's or a command's options in place of the empty ones `make` declares; an email's props. */
36
+ options?: DeclarationOptions;
37
+ }
38
+ /**
39
+ * The options of a tool or a command whose input the caller knows: the object literal's lines,
40
+ * written with the local name each of `imports` is bound to in the declarations module, which
41
+ * gains the import when it lacks it. A tool's lines replace its description and input too.
42
+ */
43
+ export interface DeclarationOptions {
44
+ /** The schema builder `s`, and a command's `argument` and `flag`. */
45
+ imports: readonly ("s" | "argument" | "flag")[];
46
+ lines: (locals: Readonly<Record<string, string>>) => string[];
32
47
  }
33
48
  /** One file's text before and after an edit, by path relative to the project root. */
34
49
  export interface FileEdit {
@@ -52,3 +67,16 @@ export type Declared = {
52
67
  };
53
68
  /** Plans the declaration and mapping for `request` in the project at `root`. */
54
69
  export declare function declare(request: DeclarationRequest, root: string): Promise<Declared>;
70
+ /**
71
+ * Whether `app/policies/abilities.ts` declares a group at `path` in its `abilities({ … })`, as
72
+ * `make policy` does for a resource. An unreadable catalog, or one without the call, declares none.
73
+ */
74
+ export declare function declaresAbilities(root: string, path: readonly string[]): Promise<boolean>;
75
+ /**
76
+ * The row type a resource's model exports, `PostRow` from `app/models/post.ts`, or `null` when
77
+ * the resource has no model or its model exports no such type.
78
+ */
79
+ export declare function findRow(root: string, name: Name): Promise<{
80
+ path: string;
81
+ type: string;
82
+ } | null>;