@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,25 @@
1
+ /**
2
+ * The `cloudflare:workers` module under Vitest, which imports the app's modules in Node, outside
3
+ * the Worker runtime. It carries the development secrets `.env.example` lists, so a module that
4
+ * reads `env` at import loads the same way it does under `bun dev`. Its bindings are in-memory
5
+ * stand-ins that behave like Cloudflare's, so a test reads and writes real SQL through `DB`.
6
+ */
7
+
8
+ import {
9
+ createD1Database,
10
+ createKVNamespace,
11
+ createRateLimit,
12
+ createSendEmail,
13
+ } from "@sdxc/cloudflare-mocks";
14
+
15
+ /** The bindings and secrets the app reads, with the values a project starts with for development. */
16
+ export const env = {
17
+ DB: createD1Database(),
18
+ EMAIL: createSendEmail(),
19
+ RATE_LIMITER: createRateLimit(),
20
+ SESSIONS: createKVNamespace(),
21
+ SESSION_SECRET: "development-session-secret",
22
+ HONEYPOT_SECRET: "development-honeypot-secret",
23
+ TURNSTILE_SITE_KEY: "1x00000000000000000000AA",
24
+ TURNSTILE_SECRET_KEY: "1x0000000000000000000000000000000AA",
25
+ } as Partial<Cloudflare.Env> as Cloudflare.Env;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A temporary project for a command test: its own migration chain and local database file,
3
+ * installed in place of the project's own, so `db fresh`, `db seed` and `db prepare` run for
4
+ * real and leave the rows `bun dev` serves untouched; `postsSeed` stands in for the app's seed.
5
+ */
6
+
7
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+
11
+ import { createModel, createModels } from "@sdxc/data-model";
12
+ import { defineSeed } from "@sdxc/data-model/seed";
13
+ import { unwrap } from "@sdxc/result";
14
+ import { column as c, table } from "remix/data-table";
15
+ import { vi } from "vitest";
16
+
17
+ /** Where the temporary project keeps its database, and the project's root. */
18
+ export interface TemporaryProject {
19
+ root: string;
20
+ databaseFile: string;
21
+ }
22
+
23
+ /**
24
+ * Replaces `~/app/initializers/local-database` with one rooted in a new temporary folder that
25
+ * holds `migrations`. Call it before importing the command line, which reads the replacement.
26
+ *
27
+ * @param migrations Each migration's SQL by file name, as `database/migrations/` would hold it.
28
+ * @example let project = useTemporaryProject({ "0001_CreatePosts.sql": "CREATE TABLE posts (id TEXT)" });
29
+ */
30
+ export function useTemporaryProject(
31
+ migrations: Readonly<Record<string, string>>,
32
+ ): TemporaryProject {
33
+ let root = mkdtempSync(join(tmpdir(), "app-"));
34
+ let directory = join(root, "database/migrations");
35
+ mkdirSync(directory, { recursive: true });
36
+ for (let [name, sql] of Object.entries(migrations)) writeFileSync(join(directory, name), sql);
37
+ let databaseFile = join(root, "local.sqlite");
38
+
39
+ vi.doMock("~/app/initializers/local-database", async (importOriginal) => {
40
+ let original = await importOriginal<typeof import("~/app/initializers/local-database")>();
41
+ return {
42
+ ...original,
43
+ PROJECT_ROOT: root,
44
+ LOCAL_DATABASE_FILE: databaseFile,
45
+ openLocalDatabase: (filename = databaseFile) => original.openLocalDatabase(filename),
46
+ };
47
+ });
48
+ return { root, databaseFile };
49
+ }
50
+
51
+ /** A `posts` table holding only an id, as the temporary project's migration creates it. */
52
+ const POSTS = table({ name: "posts", columns: { id: c.text().primaryKey() } });
53
+
54
+ /**
55
+ * A seed with one `posts` step creating a post with each id, through a model over `POSTS`.
56
+ *
57
+ * @example vi.doMock("~/database/seed", () => ({ default: postsSeed("p1") }));
58
+ */
59
+ export function postsSeed(...ids: string[]) {
60
+ let Post = createModel(POSTS, {});
61
+ let registry = createModels({ post: Post });
62
+ return defineSeed(registry, {
63
+ posts: async ({ models }) => {
64
+ for (let id of ids) unwrap(await models.post.create({ id }));
65
+ },
66
+ });
67
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Signs a visitor in for a test the way the app does: a request through the session middleware
3
+ * stores them under the session's `actor` key, and the cookie it answers is what a test sends
4
+ * back, so a request carrying it reaches every page as that `member`.
5
+ */
6
+
7
+ import { session } from "remix/middleware/session";
8
+ import { createRouter } from "remix/router";
9
+
10
+ import type { Actor } from "~/app/policies/policy";
11
+
12
+ import { ACTOR_KEY } from "~/app/http/middleware/access";
13
+ import { sessionCookie, sessionStorage } from "~/app/initializers/session";
14
+
15
+ /**
16
+ * Stores `actor` in a new session and answers its `Cookie` header.
17
+ *
18
+ * @example let cookie = await signIn(); await router.fetch(new Request(url, { headers: { cookie } }));
19
+ */
20
+ export async function signIn(actor: Actor = { id: "1" }): Promise<string> {
21
+ let router = createRouter({ middleware: [session(sessionCookie, sessionStorage)] });
22
+ router.post("/", (ctx) => {
23
+ ctx.session.set(ACTOR_KEY, actor);
24
+ return new Response(null, { status: 204 });
25
+ });
26
+ let response = await router.fetch(new Request("https://example.com/", { method: "POST" }));
27
+ return response.headers.get("set-cookie")?.split(";")[0] ?? "";
28
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The command line's entry point, started by `bun run cli` or `sdxc run`: it runs the command
2
+ * The command line's entry point, started by `sdxc run`: it runs the command
3
3
  * the arguments name and exits with its code. The Worker never imports it, so no command ships
4
4
  * in the server build.
5
5
  */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The REPL's entry point, preloaded into Bun's REPL by `sdxc run console`: it opens the local
3
+ * database `bun dev` serves and binds the app's models to it, as `db` and `models` on
4
+ * `globalThis`, so every line typed at the prompt reads and writes the dev server's rows.
5
+ */
6
+
7
+ import { openLocalDatabase } from "~/app/initializers/local-database";
8
+ import registry from "~/app/models";
9
+
10
+ /** The local database, open for the REPL's whole session. */
11
+ const DATABASE = openLocalDatabase();
12
+
13
+ Object.assign(globalThis, { db: DATABASE, models: registry.bind({ db: DATABASE }) });
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The Worker's entry point. `fetch` builds the router and forwards the request to it, and
3
- * `queue` hands each delivered batch to the job dispatcher, so every request and every job
4
- * reaches the app through the initializers that configure it.
2
+ * The Worker's entry point. `fetch` forwards each request to the router, which serves pages
3
+ * and the API alike, and `queue` hands each delivered batch to the job dispatcher, so every
4
+ * request and every job reaches the app through the initializers that configure it.
5
5
  */
6
6
 
7
7
  import * as cloudflare from "@sdxc/jobs/cloudflare";
@@ -13,7 +13,7 @@ import { createWebRouter } from "~/app/initializers/router";
13
13
  const JOBS = cloudflare.worker(dispatcher);
14
14
 
15
15
  export default {
16
- /** Answers a request through the web router. */
16
+ /** Answers a request through the router. */
17
17
  async fetch(request) {
18
18
  let router = createWebRouter();
19
19
  return await router.fetch(request);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Cloudflare configuration for the Worker, read by `cf` and the Vite plugin alike. Every
3
- * binding and trigger the app reads is declared here, so `bun cf:typegen` types `env` from
3
+ * binding and trigger the app reads is declared here, so `sdxc run typegen` types `env` from
4
4
  * this file and local development simulates exactly what production provides.
5
5
  */
6
6
 
@@ -21,8 +21,36 @@ export default defineConfig({
21
21
  */
22
22
  triggers: [triggers.queue({ name: manifest.name })],
23
23
  env: {
24
- /** Where the job dispatcher enqueues; `cf queues create <name>` before the first deploy. */
24
+ /**
25
+ * The app's database. `cf d1 create --name <name>` prints the id to put here, where the
26
+ * `sdxc run db` commands read it; until then, `bun dev` runs on a local copy.
27
+ */
28
+ DB: bindings.d1({ name: manifest.name, id: "00000000-0000-4000-8000-000000000000" }),
29
+ /**
30
+ * Sends the app's email. Cloudflare delivers only from an address on a domain with Email
31
+ * Routing enabled, so set `MAIL_FROM` in `config/constants.ts` to one before deploying.
32
+ */
33
+ EMAIL: bindings.sendEmail(),
34
+ /** Where the job dispatcher enqueues; `cf queues create --queue-name <name>` before the first deploy. */
25
35
  QUEUE: bindings.queue({ name: manifest.name }),
36
+ /**
37
+ * 100 requests per minute per client address, across every route. The router's
38
+ * adapter declares the same budget for the `RateLimit` headers; keep the two in step.
39
+ */
40
+ RATE_LIMITER: bindings.rateLimit({ namespace: "1001", simple: { limit: 100, period: 60 } }),
41
+ /**
42
+ * Visitors' sessions. `cf kv namespaces create --title <name>` prints the id to put here; until
43
+ * then, `bun dev` keeps sessions in a local copy.
44
+ */
45
+ SESSIONS: bindings.kv({ id: "00000000000000000000000000000000" }),
46
+ /** Signs the session cookie. */
47
+ SESSION_SECRET: bindings.secret(),
48
+ /** Signs the honeypot fields every page form carries. */
49
+ HONEYPOT_SECRET: bindings.secret(),
50
+ /** The Turnstile widget's site key, which a form renders. */
51
+ TURNSTILE_SITE_KEY: bindings.secret(),
52
+ /** Verifies the Turnstile token a form submits. */
53
+ TURNSTILE_SECRET_KEY: bindings.secret(),
26
54
  },
27
55
  },
28
56
  });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Values the app is configured with that never change between requests. Edit them when the app
3
+ * gets its own domain, since links and identifiers built from them are published.
4
+ */
5
+
6
+ /** The origin the app is published at: canonical links, the sitemap and robots.txt name it. */
7
+ export const SITE_URL = "https://example.com";
8
+
9
+ /** The app's name, as `og:site_name` and structured data publish it. */
10
+ export const SITE_NAME = "App";
11
+
12
+ /** The description a page without its own publishes, in search results and link previews. */
13
+ export const SITE_DESCRIPTION = "A Remix app on Cloudflare Workers.";
14
+
15
+ /** Where problem `type` URIs point; each problem's slug follows it, so it ends in `/`. */
16
+ export const PROBLEMS_URL = "https://example.com/problems/";
17
+
18
+ /** Who the app's email comes from: an address on a domain Cloudflare Email Routing verified. */
19
+ export const MAIL_FROM = { email: "no-reply@example.com", name: "App" };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Every problem the API answers with, by name. A handler returns `problems.<name>()` and the
3
+ * OpenAPI document publishes each entry, so a client branches on a `type` the server declared.
4
+ */
5
+
6
+ import * as s from "@sdxc/json-schema";
7
+ import { defineProblems, ISSUES_SCHEMA } from "@sdxc/problem";
8
+
9
+ import { PROBLEMS_URL } from "~/config/constants";
10
+
11
+ export default defineProblems(PROBLEMS_URL, {
12
+ notFound: { slug: "not-found", status: 404, title: "The resource does not exist" },
13
+ tooManyRequests: {
14
+ slug: "too-many-requests",
15
+ status: 429,
16
+ title: "Too many requests from this address",
17
+ },
18
+ validationError: {
19
+ slug: "validation-error",
20
+ status: 422,
21
+ title: "The request failed validation",
22
+ extensions: s.object({ errors: ISSUES_SCHEMA }),
23
+ },
24
+ });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The security headers every page is sent with: a Content-Security-Policy that admits this
3
+ * origin and the response's nonce, and the headers that keep the page out of frames and its
4
+ * referrer and device APIs to itself. Name an origin here before a page loads from it.
5
+ */
6
+
7
+ import type { SecurityHeaders } from "@sdxc/security-headers";
8
+
9
+ /** Where Cloudflare Turnstile loads its script and renders its challenge frame. */
10
+ const TURNSTILE_ORIGIN = "https://challenges.cloudflare.com";
11
+
12
+ /** The policy `app/http/middleware/page.ts` applies to every page response. */
13
+ export const SECURITY_POLICY: SecurityHeaders.Policy = {
14
+ contentSecurityPolicy: {
15
+ defaultSrc: ["self"],
16
+ /** The document's inline import map is admitted by the response's nonce. */
17
+ scriptSrc: ["self", "nonce", TURNSTILE_ORIGIN],
18
+ /** `css()` styles render as `<style>` elements while the page streams, before any nonce. */
19
+ styleSrc: ["self", "unsafe-inline"],
20
+ imgSrc: ["self", "data:"],
21
+ fontSrc: ["self"],
22
+ /** Same-origin requests, including the dev server's HMR socket. */
23
+ connectSrc: ["self"],
24
+ frameSrc: [TURNSTILE_ORIGIN],
25
+ formAction: ["self"],
26
+ frameAncestors: ["none"],
27
+ baseUri: ["none"],
28
+ objectSrc: ["none"],
29
+ },
30
+ strictTransportSecurity: { maxAge: 31_536_000 },
31
+ referrerPolicy: "strict-origin-when-cross-origin",
32
+ crossOriginOpenerPolicy: "same-origin",
33
+ permissionsPolicy: { camera: [], microphone: [], geolocation: [], payment: [], usb: [] },
34
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The app's security.txt (RFC 9116), served at `/.well-known/security.txt` so a researcher who
3
+ * finds a vulnerability knows where to report it. Review it before `expires`; a test fails a
4
+ * month ahead so the file never goes stale.
5
+ */
6
+
7
+ import type { SecurityTxt } from "@sdxc/well-known/security-txt";
8
+
9
+ import { serve } from "@sdxc/well-known/middleware";
10
+ import { securityTxt } from "@sdxc/well-known/security-txt";
11
+
12
+ import { SITE_URL } from "~/config/constants";
13
+
14
+ /** Where reports go and until when this file is current; replace the contact with yours. */
15
+ export const SECURITY_TXT: SecurityTxt = {
16
+ contact: [new URL("mailto:security@example.com")],
17
+ expires: new Date("2027-10-15T00:00:00Z"),
18
+ encryption: [],
19
+ acknowledgments: [],
20
+ preferredLanguages: ["en"],
21
+ canonical: [new URL("/.well-known/security.txt", SITE_URL)],
22
+ policy: [],
23
+ hiring: [],
24
+ extensions: {},
25
+ };
26
+
27
+ /** The entry the router's `wellKnown()` serves the file through. */
28
+ export const securityTxtEntry = serve(securityTxt, () => SECURITY_TXT);
File without changes
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The rows `sdxc run db seed` writes into the local database: named steps, run in order, each
3
+ * writing fixed rows through `models` or generated ones through `factories`, with the
4
+ * factories in `database/factories/`.
5
+ */
6
+
7
+ import { defineSeed } from "@sdxc/data-model/seed";
8
+
9
+ import registry from "~/app/models";
10
+
11
+ /** Add a step per set of rows, as `posts: ({ factories }) => factories.createMany(PostFactory, 10)`. */
12
+ export default defineSeed(registry, {});
@@ -3,36 +3,67 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "build": "vite build",
7
- "cf:deploy": "cf deploy --prebuilt",
8
- "cf:typegen": "cf workers types",
6
+ "build": "vp build",
9
7
  "check": "vp check",
10
8
  "cli": "bun ./bootstrap/cli.ts",
11
- "dev": "vite dev",
12
- "start": "vite preview",
9
+ "dev": "vp dev",
10
+ "start": "vp preview",
13
11
  "test": "vp test run",
14
12
  "typecheck": "tsc --noEmit"
15
13
  },
16
14
  "dependencies": {
17
15
  "@pitlane/assets": "0.1.0",
18
16
  "@sdxc/assets-middleware": "0.0.1",
17
+ "@sdxc/authz": "0.0.1",
18
+ "@sdxc/captcha": "0.0.1",
19
19
  "@sdxc/cli": "0.0.1",
20
+ "@sdxc/data-model": "0.0.1",
21
+ "@sdxc/data-table-d1": "0.0.1",
22
+ "@sdxc/database-middleware": "0.0.1",
23
+ "@sdxc/get-client-ip": "0.0.1",
24
+ "@sdxc/honeypot": "0.0.1",
25
+ "@sdxc/http": "0.0.1",
26
+ "@sdxc/i18n": "0.0.1",
20
27
  "@sdxc/jobs": "0.0.1",
28
+ "@sdxc/json-schema": "0.0.1",
21
29
  "@sdxc/lazy-route": "0.0.1",
22
30
  "@sdxc/logger": "0.0.1",
31
+ "@sdxc/mail": "0.0.1",
23
32
  "@sdxc/mcp": "0.0.1",
33
+ "@sdxc/no-www-middleware": "0.0.1",
34
+ "@sdxc/openapi": "0.0.1",
35
+ "@sdxc/problem": "0.0.1",
36
+ "@sdxc/rate-limit": "0.0.1",
37
+ "@sdxc/result": "0.0.1",
38
+ "@sdxc/robots": "0.0.1",
39
+ "@sdxc/sample": "0.0.1",
40
+ "@sdxc/security-headers": "0.0.1",
41
+ "@sdxc/seo": "0.0.1",
42
+ "@sdxc/server-timing": "0.0.1",
43
+ "@sdxc/session-storage-kv": "0.0.1",
44
+ "@sdxc/sitemap": "0.0.1",
45
+ "@sdxc/spam": "0.0.1",
46
+ "@sdxc/trace-context": "0.0.1",
47
+ "@sdxc/trailing-slash-middleware": "0.0.1",
24
48
  "@sdxc/ui": "0.0.1",
49
+ "@sdxc/user-agent": "0.0.1",
50
+ "@sdxc/well-known": "0.0.1",
25
51
  "remix": "3.0.0"
26
52
  },
27
53
  "devDependencies": {
28
54
  "@cloudflare/vite-plugin": "2.0.0-beta.sha-ad79608dd",
29
55
  "@pitlane/vite-plugin-remix": "0.8.0",
56
+ "@sdxc/cloudflare-mocks": "0.0.1",
57
+ "@sdxc/kit": "0.0.1",
30
58
  "@types/node": "^26.6.5",
31
59
  "cf": "1.0.0-beta.5",
32
60
  "typescript": "^6.0.3",
33
- "vite": "^8.3.4",
61
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.3",
34
62
  "vite-plus": "0.3.3",
35
63
  "vitest": "4.1.11"
36
64
  },
65
+ "overrides": {
66
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.3"
67
+ },
37
68
  "packageManager": "bun@1.4.2"
38
69
  }
@@ -1,15 +1,21 @@
1
1
  /**
2
- * The HTML document every page renders inside: the head tags, the page title, and the
2
+ * The HTML document every page renders inside: the head tags, the page's title, description,
3
+ * canonical link and link-preview tags, and the
3
4
  * stylesheets imported below in cascade order. The client entry is linked only by a page
4
5
  * that carries an island.
5
6
  */
6
7
 
7
8
  import type { DocumentAssets } from "@sdxc/assets-middleware";
9
+ import type { I18n } from "@sdxc/i18n";
8
10
  import type { Handle, RemixNode } from "remix/component";
9
11
 
12
+ import { IntlProvider } from "@sdxc/i18n/ui";
13
+ import { Seo } from "@sdxc/seo";
10
14
  import { css } from "remix/component";
11
15
  import { ImportMap } from "remix/component/server";
12
16
 
17
+ import { seo } from "~/app/initializers/seo";
18
+
13
19
  import "@sdxc/ui/reset.css";
14
20
  import "@sdxc/ui/theme.css";
15
21
 
@@ -17,9 +23,18 @@ namespace DocumentLayout {
17
23
  export interface Props {
18
24
  /** The page's content, rendered inside `<main>`. */
19
25
  children: RemixNode;
20
- /** The stylesheets and client entry the request resolved, from `ctx.assets`. */
26
+ /**
27
+ * The stylesheets, client entry and CSP nonce the request resolved, from `ctx.assets`;
28
+ * the nonce is read only when the page hydrates, for its inline import map.
29
+ */
21
30
  assets: DocumentAssets;
31
+ /** The request's translator, from `ctx.intl`: it sets `<html lang>` and is what `intl(handle)` reads below it. */
32
+ intl: I18n;
22
33
  title: string;
34
+ /** The page's summary in search results and link previews; the site's description by default. */
35
+ description?: string;
36
+ /** The request's URL, from `ctx.url`, which the canonical link names on `SITE_URL`. */
37
+ url: URL;
23
38
  /** Whether the page carries an island, the only reason to link the client entry. */
24
39
  hydrates?: boolean;
25
40
  }
@@ -28,11 +43,11 @@ namespace DocumentLayout {
28
43
  /** Renders the `<html>`, `<head>` and `<body>` shell around a page. */
29
44
  export default function DocumentLayout(handle: Handle<DocumentLayout.Props>) {
30
45
  return () => {
31
- let { assets, children, hydrates = false, title } = handle.props;
46
+ let { assets, children, description, hydrates = false, intl, title, url } = handle.props;
32
47
  let { script, stylesheets } = assets;
33
48
 
34
49
  return (
35
- <html lang="en" class="system">
50
+ <html lang={intl.locale} class="system">
36
51
  <head>
37
52
  <meta charSet="utf-8" data-rmx-key="charset" />
38
53
  <meta
@@ -40,15 +55,21 @@ export default function DocumentLayout(handle: Handle<DocumentLayout.Props>) {
40
55
  content="width=device-width, initial-scale=1"
41
56
  data-rmx-key="viewport"
42
57
  />
43
- <title data-rmx-key="title">{title}</title>
58
+ <Seo.Meta
59
+ title={title}
60
+ description={description}
61
+ canonical={seo.canonical(url)}
62
+ site={seo.site}
63
+ og={{ locale: intl.locale }}
64
+ />
44
65
  {stylesheets.map((href) => (
45
66
  <link key={href} rel="stylesheet" href={href} data-rmx-key={href} />
46
67
  ))}
47
- {hydrates ? <ImportMap value={script.importMap} /> : null}
68
+ {hydrates ? <ImportMap value={script.importMap} nonce={assets.nonce} /> : null}
48
69
  </head>
49
70
  <body>
50
71
  <main mix={css({ maxInlineSize: "48rem", marginInline: "auto", padding: "1.5rem" })}>
51
- {children}
72
+ <IntlProvider intl={intl}>{children}</IntlProvider>
52
73
  </main>
53
74
  {hydrates ? <script type="module" src={script.href}></script> : null}
54
75
  </body>
@@ -0,0 +1,10 @@
1
+ {
2
+ "home": {
3
+ "title": "Welcome",
4
+ "body": "Edit {#file}app/http/controllers/home.tsx{/file}, or add a page with {#command}sdxc make controller <name>{/command}."
5
+ },
6
+ "notFound": {
7
+ "title": "Not found",
8
+ "back": "Back home"
9
+ }
10
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The API route contract: every endpoint a machine client calls, and the OpenAPI operation
3
+ * that types each documented one, so the published document and the handler that parses a
4
+ * request read the same schemas.
5
+ */
6
+
7
+ import * as s from "@sdxc/json-schema";
8
+ import { defineOperation } from "@sdxc/openapi";
9
+ import { get, post, route } from "remix/routes";
10
+
11
+ /** The JSON endpoints under `/api`, and the MCP endpoint an agent connects to. */
12
+ const ROUTES = route({
13
+ api: {
14
+ health: get("/api/health"),
15
+ openapi: get("/api/openapi.json"),
16
+ notFound: "/api/*path",
17
+ },
18
+ mcp: post("/mcp"),
19
+ });
20
+
21
+ export default ROUTES;
22
+
23
+ /** GET /api/health, the check a monitor or load balancer polls. */
24
+ export const HEALTH = defineOperation("health", ROUTES.api.health, {
25
+ summary: "Check the service",
26
+ responses: {
27
+ 200: { description: "The service is up", body: s.object({ status: s.literal("ok") }) },
28
+ },
29
+ });
@@ -1,12 +1,14 @@
1
1
  /**
2
- * The web route contract: every URL the app answers, by name. Controllers and links build
2
+ * The web route contract: every page the app serves, by name. Controllers and links build
3
3
  * URLs with `routes.<name>.href()`, so a pattern changes here and nowhere else.
4
4
  */
5
5
 
6
- import { get, post, route } from "remix/routes";
6
+ import { get, route } from "remix/routes";
7
7
 
8
- /** The home page and the MCP endpoint an agent connects to. */
8
+ /** The pages, and the 404 page for any path no other route claims. */
9
9
  export default route({
10
10
  home: get("/"),
11
- mcp: post("/mcp"),
11
+ robots: get("/robots.txt"),
12
+ sitemap: get("/sitemap.xml"),
13
+ notFound: "/*path",
12
14
  });
@@ -26,6 +26,10 @@ export default defineConfig({
26
26
 
27
27
  test: {
28
28
  include: ["app/**/*.test.ts?(x)", "resources/**/*.test.ts?(x)"],
29
+ /** Vitest runs modules in Node, so the Worker runtime's module resolves to a stand-in. */
30
+ alias: {
31
+ "cloudflare:workers": new URL("app/test/cloudflare-workers.ts", import.meta.url).pathname,
32
+ },
29
33
  },
30
34
 
31
35
  fmt: {
package/stubs/policy.stub DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * The {{title}} policy: describe who may do what, and why the rule sits here.
3
- */
4
-
5
- /** Who an authorization rule is asked about; `null` for an anonymous visitor. */
6
- export interface Actor {
7
- id: string;
8
- }
9
-
10
- /** Whether `actor` passes the {{title}} rule. */
11
- export function {{key}}(actor: Actor | null): boolean {
12
- return actor !== null;
13
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * What the router's global middleware adds to every request context: `render()` publishes
3
- * `ctx.render` and `formData()` publishes `ctx.formData`. Declaring them here lets the
4
- * default handler and any helper typed as `RequestContext` read them.
5
- */
6
-
7
- import type { RemixNode } from "remix/component";
8
- import type { Renderer } from "remix/middleware/render";
9
- import type {} from "remix/router";
10
-
11
- declare module "remix/router" {
12
- interface RequestContext {
13
- /** Renders a `remix/component` node into an HTML `Response`. */
14
- render: Renderer<RemixNode>;
15
- /** The request's parsed form body. */
16
- formData: FormData;
17
- }
18
- }
19
-
20
- export {};