@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,53 @@
1
+ /**
2
+ * Narrows a route listing to what `sdxc routes` was asked about: a search across names, patterns,
3
+ * methods and controllers, one controller, one method, one contract, paths to leave out, or the
4
+ * routes no router maps, then sorts it. Both run before any output, so the table and `--json` agree.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { RouteListing } from "./index.js";
10
+ /** What to keep; a route stays when it passes every filter given. */
11
+ export interface RouteFilters {
12
+ /**
13
+ * Matched, ignoring case, against the name, pattern, method and `file#export` of the
14
+ * controller, as plain text or as a regular expression, so `/posts/:id` and `^posts\.` both work.
15
+ */
16
+ grep?: string;
17
+ /** A controller file, with or without `app/http/controllers/` and its extension; a folder keeps every controller in it. */
18
+ controller?: string;
19
+ /** `GET`, `post`, …; a route declared for `ANY` method answers every one, so it stays. */
20
+ method?: string;
21
+ /** A contract in `routes/`, as `web`, `routes/web` or `routes/web.ts`. */
22
+ contract?: string;
23
+ /** Keeps the routes a contract declares and no router maps. */
24
+ unused?: boolean;
25
+ /** Leaves out the routes whose pattern starts with any of these, as `/api` or `/mcp`. */
26
+ exceptPath?: readonly string[];
27
+ }
28
+ /** What `--sort` orders the routes by. */
29
+ export declare const ROUTE_SORTS: readonly ["name", "pattern", "method", "controller"];
30
+ /** One of {@link ROUTE_SORTS}. */
31
+ export type RouteSort = (typeof ROUTE_SORTS)[number];
32
+ /** Whether any filter is set, so the command can tell an empty project from an empty result. */
33
+ export declare function hasFilters(filters: RouteFilters): boolean;
34
+ /**
35
+ * The listing with only the routes that pass every filter, and only the routers that map one of
36
+ * them, so a narrowed table carries no global middleware it does not list. Without filters the
37
+ * listing comes back as it is.
38
+ */
39
+ export declare function filterRoutes(listing: RouteListing, filters: RouteFilters): RouteListing;
40
+ /**
41
+ * The controller files among `files` no route of `listing` loads, narrowed by
42
+ * `--grep` and `--controller`, which both read the file. A `--method` or `--contract` filter
43
+ * leaves none, since a file no route maps has neither.
44
+ *
45
+ * @param files - The controller sources no module imports statically, project-relative
46
+ * @param listing - The listing before any filter, so a route filtered out still counts as a use
47
+ */
48
+ export declare function unmappedControllers(files: readonly string[], listing: RouteListing, filters: RouteFilters): string[];
49
+ /**
50
+ * The listing with its routes ordered by `sort`, ties kept in declaration order; a route no
51
+ * router maps sorts last by controller. Without `sort` the listing comes back as it is.
52
+ */
53
+ export declare function sortRoutes(listing: RouteListing, sort: RouteSort | undefined): RouteListing;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Narrows a route listing to what `sdxc routes` was asked about: a search across names, patterns,
3
+ * methods and controllers, one controller, one method, one contract, paths to leave out, or the
4
+ * routes no router maps, then sorts it. Both run before any output, so the table and `--json` agree.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { isSuccess, wrap } from "@sdxc/result";
10
+ /** The folder a controller lives in, which `--controller` lets a reader leave out. */
11
+ const CONTROLLERS_FOLDER = "app/http/controllers/";
12
+ /** What `--sort` orders the routes by. */
13
+ export const ROUTE_SORTS = ["name", "pattern", "method", "controller"];
14
+ /** Whether any filter is set, so the command can tell an empty project from an empty result. */
15
+ export function hasFilters(filters) {
16
+ return (filters.grep !== undefined ||
17
+ filters.controller !== undefined ||
18
+ filters.method !== undefined ||
19
+ filters.contract !== undefined ||
20
+ filters.unused === true ||
21
+ (filters.exceptPath ?? []).length > 0);
22
+ }
23
+ /**
24
+ * The listing with only the routes that pass every filter, and only the routers that map one of
25
+ * them, so a narrowed table carries no global middleware it does not list. Without filters the
26
+ * listing comes back as it is.
27
+ */
28
+ export function filterRoutes(listing, filters) {
29
+ if (!hasFilters(filters))
30
+ return listing;
31
+ let search = filters.grep === undefined ? null : matcher(filters.grep);
32
+ let routes = listing.routes.filter((route) => matches(route, filters, search));
33
+ let used = new Set(routes.map((route) => route.router));
34
+ return {
35
+ ...listing,
36
+ routes,
37
+ routers: listing.routers.filter((router) => used.has(router.file)),
38
+ };
39
+ }
40
+ /**
41
+ * The controller files among `files` no route of `listing` loads, narrowed by
42
+ * `--grep` and `--controller`, which both read the file. A `--method` or `--contract` filter
43
+ * leaves none, since a file no route maps has neither.
44
+ *
45
+ * @param files - The controller sources no module imports statically, project-relative
46
+ * @param listing - The listing before any filter, so a route filtered out still counts as a use
47
+ */
48
+ export function unmappedControllers(files, listing, filters) {
49
+ if (filters.method !== undefined || filters.contract !== undefined)
50
+ return [];
51
+ let mapped = new Set(listing.routes.map((route) => route.controller?.file));
52
+ let search = filters.grep === undefined ? null : matcher(filters.grep);
53
+ return files.filter((file) => !mapped.has(file) &&
54
+ (search === null || search(file)) &&
55
+ (filters.controller === undefined || controllerMatches(file, filters.controller)));
56
+ }
57
+ /** Whether `route` passes every filter in `filters`, with `--grep` compiled once as `search`. */
58
+ function matches(route, filters, search) {
59
+ if (filters.unused === true && route.controller !== null)
60
+ return false;
61
+ if ((filters.exceptPath ?? []).some((prefix) => pathStartsWith(route.pattern, prefix))) {
62
+ return false;
63
+ }
64
+ if (filters.method !== undefined) {
65
+ let method = filters.method.toUpperCase();
66
+ if (route.method !== method && route.method !== "ANY")
67
+ return false;
68
+ }
69
+ if (filters.contract !== undefined &&
70
+ contractName(route.contract) !== contractName(filters.contract)) {
71
+ return false;
72
+ }
73
+ if (filters.controller !== undefined) {
74
+ let file = route.controller?.file ?? null;
75
+ if (file === null || !controllerMatches(file, filters.controller))
76
+ return false;
77
+ }
78
+ if (search !== null) {
79
+ let fields = [route.name, route.pattern, route.method];
80
+ if (route.controller?.file)
81
+ fields.push(route.controller.file);
82
+ let named = route.controller?.export;
83
+ if (named !== undefined && named !== null && named !== "default")
84
+ fields.push(named);
85
+ if (!fields.some(search))
86
+ return false;
87
+ }
88
+ return true;
89
+ }
90
+ /**
91
+ * A case-insensitive test for `pattern` as plain text or as a regular expression: a URL pattern
92
+ * whose `(`, `.` or `*` mean something to a regular expression still finds itself, and text that
93
+ * is no valid expression searches as plain text alone.
94
+ */
95
+ function matcher(pattern) {
96
+ let text = pattern.toLowerCase();
97
+ let compiled = wrap(() => new RegExp(pattern, "i"));
98
+ let expression = isSuccess(compiled) ? compiled.data : null;
99
+ return (value) => value.toLowerCase().includes(text) || (expression?.test(value) ?? false);
100
+ }
101
+ /**
102
+ * Whether `pattern` is `prefix` or sits under it by whole segments, so `/api` leaves out
103
+ * `/api/posts` and keeps `/apiary`.
104
+ */
105
+ function pathStartsWith(pattern, prefix) {
106
+ let base = `/${prefix.trim().replace(/^\/+|\/+$/g, "")}`;
107
+ if (base === "/")
108
+ return true;
109
+ return pattern === base || pattern.startsWith(`${base}/`);
110
+ }
111
+ /**
112
+ * The listing with its routes ordered by `sort`, ties kept in declaration order; a route no
113
+ * router maps sorts last by controller. Without `sort` the listing comes back as it is.
114
+ */
115
+ export function sortRoutes(listing, sort) {
116
+ if (sort === undefined)
117
+ return listing;
118
+ let key = (route) => {
119
+ if (sort === "controller")
120
+ return route.controller?.file ?? "\uffff";
121
+ return route[sort];
122
+ };
123
+ let routes = [...listing.routes].sort((a, b) => key(a).localeCompare(key(b)));
124
+ return { ...listing, routes };
125
+ }
126
+ /** Whether the controller `file` is `wanted` or sits in the folder `wanted` names. */
127
+ function controllerMatches(file, wanted) {
128
+ let name = controllerName(file);
129
+ let target = controllerName(wanted);
130
+ return name === target || name.startsWith(`${target}/`);
131
+ }
132
+ /** A controller path without `./`, its folder, its extension or a trailing `/index`, lowercased. */
133
+ function controllerName(path) {
134
+ let name = path.trim().toLowerCase().replace(/^\.\//, "").replace(/\/+$/, "");
135
+ if (name.startsWith(CONTROLLERS_FOLDER))
136
+ name = name.slice(CONTROLLERS_FOLDER.length);
137
+ return name.replace(/\.[cm]?[jt]sx?$/, "").replace(/\/index$/, "");
138
+ }
139
+ /** A contract path without `./`, `routes/` or its extension, lowercased. */
140
+ function contractName(path) {
141
+ return path
142
+ .trim()
143
+ .toLowerCase()
144
+ .replace(/^\.\//, "")
145
+ .replace(/^routes\//, "")
146
+ .replace(/\.[cm]?[jt]sx?$/, "");
147
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The two shapes `sdxc routes` prints: a table per route contract for a terminal, under each
3
+ * router's global middleware, and a JSON array an agent parses, the same for every run over
4
+ * the same files.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { RouteListing } from "./index.js";
10
+ /** The listing as pretty-printed JSON: the routes array alone, with a trailing newline. */
11
+ export declare function formatJSON(listing: RouteListing): string;
12
+ /**
13
+ * The listing as text: each router's global middleware once, since every route it maps runs it
14
+ * first, then one aligned table per contract. MIDDLEWARE lists `lazy()` guards, then the
15
+ * controller's chain, in the order they run.
16
+ */
17
+ export declare function formatTable(listing: RouteListing): string;
18
+ /**
19
+ * The listing as one block per route, every field on its own line, for a terminal too narrow
20
+ * for the table. Middleware is split by where it runs: the router's, `lazy()` guards, then the
21
+ * controller's chain, each in its run order.
22
+ */
23
+ export declare function formatExpanded(listing: RouteListing): string;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The two shapes `sdxc routes` prints: a table per route contract for a terminal, under each
3
+ * router's global middleware, and a JSON array an agent parses, the same for every run over
4
+ * the same files.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /** Where a router's global middleware wraps, a width every terminal shows whole. */
10
+ const LINE_WIDTH = 100;
11
+ /** The listing as pretty-printed JSON: the routes array alone, with a trailing newline. */
12
+ export function formatJSON(listing) {
13
+ return `${JSON.stringify(listing.routes, null, 2)}\n`;
14
+ }
15
+ /**
16
+ * The listing as text: each router's global middleware once, since every route it maps runs it
17
+ * first, then one aligned table per contract. MIDDLEWARE lists `lazy()` guards, then the
18
+ * controller's chain, in the order they run.
19
+ */
20
+ export function formatTable(listing) {
21
+ if (listing.routes.length === 0)
22
+ return "No routes found in routes/.\n";
23
+ let lines = [];
24
+ let multiple = listing.routers.length > 1;
25
+ for (let router of listing.routers) {
26
+ lines.push(`Router ${router.file}`);
27
+ if (router.middleware.length === 0)
28
+ lines.push(" (no global middleware)");
29
+ else
30
+ lines.push(...wrap(router.middleware.map((entry) => entry.name)));
31
+ lines.push("");
32
+ }
33
+ let contracts = [...new Set(listing.routes.map((route) => route.contract))];
34
+ for (let contract of contracts) {
35
+ let routes = listing.routes.filter((route) => route.contract === contract);
36
+ let header = [
37
+ "METHOD",
38
+ "PATTERN",
39
+ "NAME",
40
+ ...(multiple ? ["ROUTER"] : []),
41
+ "CONTROLLER",
42
+ "MIDDLEWARE",
43
+ ];
44
+ let rows = routes.map((route) => [
45
+ route.method,
46
+ route.pattern,
47
+ route.name,
48
+ ...(multiple ? [route.router ?? ""] : []),
49
+ controller(route),
50
+ names([...route.middleware.guards, ...route.middleware.controller]),
51
+ ]);
52
+ let widths = header.map((cell, column) => Math.max(cell.length, ...rows.map((row) => (row[column] ?? "").length)));
53
+ lines.push(contract);
54
+ for (let row of [header, ...rows]) {
55
+ lines.push(` ${row
56
+ .map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column] ?? 0))
57
+ .join(" ")
58
+ .trimEnd()}`);
59
+ }
60
+ lines.push("");
61
+ }
62
+ return `${lines.join("\n").trimEnd()}\n`;
63
+ }
64
+ /**
65
+ * The listing as one block per route, every field on its own line, for a terminal too narrow
66
+ * for the table. Middleware is split by where it runs: the router's, `lazy()` guards, then the
67
+ * controller's chain, each in its run order.
68
+ */
69
+ export function formatExpanded(listing) {
70
+ if (listing.routes.length === 0)
71
+ return "No routes found in routes/.\n";
72
+ let blocks = listing.routes.map((route, index) => {
73
+ let fields = [
74
+ ["Method", route.method],
75
+ ["Pattern", route.pattern],
76
+ ["Name", route.name],
77
+ ["Contract", route.contract],
78
+ ["Router", route.router ?? ""],
79
+ ["Controller", controller(route)],
80
+ ["Router middleware", names(route.middleware.router)],
81
+ ["Guards", names(route.middleware.guards)],
82
+ ["Controller middleware", names(route.middleware.controller)],
83
+ ];
84
+ let width = Math.max(...fields.map(([label]) => label.length));
85
+ let lines = fields.map(([label, value]) => `${label.padEnd(width)} | ${value}`.trimEnd());
86
+ let title = `--[ Route ${index + 1} ]`;
87
+ let rule = Math.min(LINE_WIDTH, Math.max(...lines.map((line) => line.length)));
88
+ return [title.padEnd(rule, "-"), ...lines].join("\n");
89
+ });
90
+ return `${blocks.join("\n\n")}\n`;
91
+ }
92
+ /** The controller column: the file with a named export after `#`, or why there is none. */
93
+ function controller(route) {
94
+ if (route.controller === null)
95
+ return "(not mapped)";
96
+ if (route.controller.file === null)
97
+ return "(unresolved)";
98
+ if (route.controller.export === null || route.controller.export === "default") {
99
+ return route.controller.file;
100
+ }
101
+ return `${route.controller.file}#${route.controller.export}`;
102
+ }
103
+ /** Names joined by commas in lines of at most {@link LINE_WIDTH} columns, each indented two spaces. */
104
+ function wrap(items) {
105
+ let lines = [];
106
+ let line = "";
107
+ for (let [index, item] of items.entries()) {
108
+ let piece = index === items.length - 1 ? item : `${item},`;
109
+ if (line !== "" && line.length + 1 + piece.length > LINE_WIDTH - 2) {
110
+ lines.push(` ${line}`);
111
+ line = piece;
112
+ }
113
+ else
114
+ line = line === "" ? piece : `${line} ${piece}`;
115
+ }
116
+ if (line !== "")
117
+ lines.push(` ${line}`);
118
+ return lines;
119
+ }
120
+ /** Middleware names joined in the order they run. */
121
+ function names(entries) {
122
+ return entries.map((entry) => entry.name).join(", ");
123
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The `remix/routes` helpers restated over evaluated values: method routes, `route()` with its
3
+ * prefix, `form()`, `resources()` and `resource()` with `only`, `exclude`, `param` and `names`.
4
+ * They follow the rules the helpers apply at runtime, so a listed pattern is the one the router matches.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Value } from "./modules.js";
10
+ /** The canonical helper an import binds, or `null` when it is not a route helper. */
11
+ export declare function helperName(specifier: string, imported: string): string | null;
12
+ /**
13
+ * Applies the helper `name` to evaluated arguments. An argument the reader could not evaluate
14
+ * leaves the result opaque, and `report` names an entry a route map drops.
15
+ */
16
+ export declare function applyHelper(name: string, args: Value[], report: (message: string) => void): Value;
17
+ /**
18
+ * Joins two patterns as a route prefix does: `/` on either side leaves the other, and otherwise
19
+ * exactly one slash separates them.
20
+ */
21
+ export declare function joinPatterns(base: string, pattern: string): string;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * The `remix/routes` helpers restated over evaluated values: method routes, `route()` with its
3
+ * prefix, `form()`, `resources()` and `resource()` with `only`, `exclude`, `param` and `names`.
4
+ * They follow the rules the helpers apply at runtime, so a listed pattern is the one the router matches.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /** The specifiers the route helpers are imported from. */
10
+ const ROUTE_MODULES = new Set([
11
+ "remix/routes",
12
+ "remix/fetch-router",
13
+ "remix/fetch-router/routes",
14
+ "@remix-run/fetch-router",
15
+ "@remix-run/fetch-router/routes",
16
+ ]);
17
+ /** Every exported helper name, shorthand and long form, to its canonical name. */
18
+ const HELPERS = {
19
+ route: "route",
20
+ createRoutes: "route",
21
+ get: "GET",
22
+ createGetRoute: "GET",
23
+ post: "POST",
24
+ createPostRoute: "POST",
25
+ put: "PUT",
26
+ createPutRoute: "PUT",
27
+ patch: "PATCH",
28
+ createPatchRoute: "PATCH",
29
+ del: "DELETE",
30
+ createDeleteRoute: "DELETE",
31
+ head: "HEAD",
32
+ createHeadRoute: "HEAD",
33
+ options: "OPTIONS",
34
+ createOptionsRoute: "OPTIONS",
35
+ form: "form",
36
+ createFormRoutes: "form",
37
+ resources: "resources",
38
+ createResourcesRoutes: "resources",
39
+ resource: "resource",
40
+ createResourceRoutes: "resource",
41
+ };
42
+ /** `resources()`'s actions in the order it declares them, with each one's method and pattern. */
43
+ const RESOURCES_ACTIONS = [
44
+ ["index", "GET", () => "/"],
45
+ ["new", "GET", () => "/new"],
46
+ ["show", "GET", (param) => `/:${param}`],
47
+ ["create", "POST", () => "/"],
48
+ ["edit", "GET", (param) => `/:${param}/edit`],
49
+ ["update", "PUT", (param) => `/:${param}`],
50
+ ["destroy", "DELETE", (param) => `/:${param}`],
51
+ ];
52
+ /** `resource()`'s actions, a singular resource with no index and no param. */
53
+ const RESOURCE_ACTIONS = [
54
+ ["new", "GET", () => "/new"],
55
+ ["show", "GET", () => "/"],
56
+ ["create", "POST", () => "/"],
57
+ ["edit", "GET", () => "/edit"],
58
+ ["update", "PUT", () => "/"],
59
+ ["destroy", "DELETE", () => "/"],
60
+ ];
61
+ /** The opaque value. */
62
+ const OPAQUE = { kind: "opaque" };
63
+ /** The canonical helper an import binds, or `null` when it is not a route helper. */
64
+ export function helperName(specifier, imported) {
65
+ if (!ROUTE_MODULES.has(specifier))
66
+ return null;
67
+ return HELPERS[imported] ?? null;
68
+ }
69
+ /**
70
+ * Applies the helper `name` to evaluated arguments. An argument the reader could not evaluate
71
+ * leaves the result opaque, and `report` names an entry a route map drops.
72
+ */
73
+ export function applyHelper(name, args, report) {
74
+ let [first, second] = args;
75
+ if (name === "route") {
76
+ if (first?.kind === "string" && second?.kind === "map")
77
+ return build(first.value, second, report);
78
+ if (first?.kind === "map")
79
+ return build("/", first, report);
80
+ return OPAQUE;
81
+ }
82
+ if (first?.kind !== "string")
83
+ return OPAQUE;
84
+ let options = second?.kind === "map" ? second : null;
85
+ if (name === "form") {
86
+ let names = mapOf(options?.entries.get("names"));
87
+ let method = stringOf(options?.entries.get("formMethod")) ?? "POST";
88
+ let defs = new Map([
89
+ [stringOf(names?.entries.get("index")) ?? "index", route("GET", "/")],
90
+ [stringOf(names?.entries.get("action")) ?? "action", route(method, "/")],
91
+ ]);
92
+ return build(first.value, { kind: "map", entries: defs }, report);
93
+ }
94
+ if (name === "resources" || name === "resource") {
95
+ let actions = name === "resources" ? RESOURCES_ACTIONS : RESOURCE_ACTIONS;
96
+ let only = stringsOf(options?.entries.get("only"));
97
+ let exclude = stringsOf(options?.entries.get("exclude"));
98
+ let param = stringOf(options?.entries.get("param")) ?? "id";
99
+ let names = mapOf(options?.entries.get("names"));
100
+ let defs = new Map();
101
+ for (let [action, method, pattern] of actions) {
102
+ if (only !== null && !only.includes(action))
103
+ continue;
104
+ if (only === null && exclude !== null && exclude.includes(action))
105
+ continue;
106
+ defs.set(stringOf(names?.entries.get(action)) ?? action, route(method, pattern(param)));
107
+ }
108
+ return build(first.value, { kind: "map", entries: defs }, report);
109
+ }
110
+ return route(name, first.value);
111
+ }
112
+ /**
113
+ * Joins two patterns as a route prefix does: `/` on either side leaves the other, and otherwise
114
+ * exactly one slash separates them.
115
+ */
116
+ export function joinPatterns(base, pattern) {
117
+ if (pattern === "" || pattern === "/")
118
+ return base === "" ? "/" : base;
119
+ if (base === "" || base === "/")
120
+ return pattern.startsWith("/") ? pattern : `/${pattern}`;
121
+ return `${base.replace(/\/+$/, "")}/${pattern.replace(/^\/+/, "")}`;
122
+ }
123
+ /**
124
+ * A route map with `base` joined onto every route under `defs`, each a new route object. A bare
125
+ * string is an `ANY` route and `{ method, pattern }` a route, as `route()` reads them.
126
+ */
127
+ function build(base, defs, report) {
128
+ let entries = new Map();
129
+ for (let [key, def] of defs.entries) {
130
+ if (def.kind === "route")
131
+ entries.set(key, route(def.method, joinPatterns(base, def.pattern)));
132
+ else if (def.kind === "string")
133
+ entries.set(key, route("ANY", joinPatterns(base, def.value)));
134
+ else if (def.kind === "map") {
135
+ let pattern = stringOf(def.entries.get("pattern"));
136
+ if (pattern !== null) {
137
+ let method = stringOf(def.entries.get("method")) ?? "ANY";
138
+ entries.set(key, route(method, joinPatterns(base, pattern)));
139
+ }
140
+ else
141
+ entries.set(key, build(base, def, report));
142
+ }
143
+ else
144
+ report(`\`${key}\` is declared with code sdxc routes does not evaluate; it is left out`);
145
+ }
146
+ return { kind: "map", entries };
147
+ }
148
+ /** A new route object, so each declaration has its own identity. */
149
+ function route(method, pattern) {
150
+ return { kind: "route", method, pattern };
151
+ }
152
+ /** The string a value holds, or `null` when it holds anything else. */
153
+ function stringOf(value) {
154
+ return value?.kind === "string" ? value.value : null;
155
+ }
156
+ /** The map a value holds, or `null` when it holds anything else. */
157
+ function mapOf(value) {
158
+ return value?.kind === "map" ? value : null;
159
+ }
160
+ /** The strings of an array value, or `null` when it is not an array of strings. */
161
+ function stringsOf(value) {
162
+ if (value?.kind !== "array")
163
+ return null;
164
+ return value.items.flatMap((item) => (item.kind === "string" ? [item.value] : []));
165
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Lists every route of a project as `sdxc routes` prints it: each route contract in `routes/`
3
+ * evaluated to full patterns, joined with what the router initializers in `app/initializers/`
4
+ * map onto it. Reads source only, so it runs without bindings, a build or an install.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { ControllerRef, MiddlewareEntry, Router } from "./routers.js";
10
+ export type { ControllerRef, MiddlewareEntry, Router } from "./routers.js";
11
+ /** One route, and what runs for it; the shape `sdxc routes --json` prints. */
12
+ export interface RouteEntry {
13
+ /** `GET`, `POST`, …, or `ANY` for a bare pattern. */
14
+ method: string;
15
+ pattern: string;
16
+ /** The route contract it is declared in; a contract composed into another reports the outer one. */
17
+ contract: string;
18
+ /** Its key path in the contract, `posts.show`. */
19
+ name: string;
20
+ /** The initializer that maps it, or `null` when no router does. */
21
+ router: string | null;
22
+ /** `null` when no router maps it; its `file` is `null` when the mapping cannot be followed. */
23
+ controller: ControllerRef | null;
24
+ middleware: {
25
+ /** The router's global middleware, which runs first. */
26
+ router: MiddlewareEntry[];
27
+ /** `lazy()`'s second argument, which answers before the controller loads. */
28
+ guards: MiddlewareEntry[];
29
+ /** The controller's middleware, then the action's own. */
30
+ controller: MiddlewareEntry[];
31
+ };
32
+ }
33
+ /** Everything `sdxc routes` prints. */
34
+ export interface RouteListing {
35
+ routes: RouteEntry[];
36
+ /** Every router found, for printing each one's global middleware once. */
37
+ routers: RouterSummary[];
38
+ /** Problems the reader met, each naming its file. */
39
+ diagnostics: string[];
40
+ }
41
+ /** A router as the listing reports it. */
42
+ export interface RouterSummary extends Pick<Router, "file" | "middleware"> {
43
+ /**
44
+ * Each `map()` whose handler loads with the router, as its target and handler, or as its target
45
+ * and the action key path when only that action does, since that code loads on every request.
46
+ */
47
+ eager: string[];
48
+ }
49
+ /** Lists the routes of the project at `root`. */
50
+ export declare function listRoutes(root: string): Promise<RouteListing>;
51
+ /**
52
+ * The sources under `app/http/controllers/` that no module in `app/` or `bootstrap/` imports
53
+ * statically. A helper shared by controllers, or a handler the router takes as an option, is
54
+ * imported that way, so what is left is reached by a route's `lazy()` import or by nothing.
55
+ */
56
+ export declare function unimportedControllers(root: string): Promise<string[]>;