@sdxc/kit 2026.10.16 → 2026.10.17

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 (114) hide show
  1. package/README.md +1 -0
  2. package/changelog.jsonl +57 -0
  3. package/dist/author.d.ts +36 -0
  4. package/dist/author.js +107 -0
  5. package/dist/commands/create.js +9 -4
  6. package/dist/commands/run.d.ts +2 -2
  7. package/dist/commands/run.js +5 -3
  8. package/dist/contract.js +1 -1
  9. package/dist/create/templates.d.ts +8 -1
  10. package/dist/create/templates.js +25 -2
  11. package/dist/init.d.ts +5 -3
  12. package/dist/init.js +15 -7
  13. package/dist/make/declare.d.ts +4 -4
  14. package/dist/make/declare.js +124 -21
  15. package/dist/make/generate.js +8 -2
  16. package/dist/make/index.js +5 -1
  17. package/dist/make/kinds.d.ts +2 -1
  18. package/dist/make/kinds.js +3 -2
  19. package/dist/testing.d.ts +12 -2
  20. package/dist/testing.js +22 -3
  21. package/package.json +3 -3
  22. package/stubs/command.stub +4 -0
  23. package/stubs/command.test.stub +3 -0
  24. package/stubs/controller.api.stub +21 -0
  25. package/stubs/controller.api.test.stub +18 -0
  26. package/stubs/controller.form.stub +39 -9
  27. package/stubs/controller.form.test.stub +61 -0
  28. package/stubs/controller.stub +15 -8
  29. package/stubs/controller.test.stub +3 -0
  30. package/stubs/email.stub +12 -30
  31. package/stubs/email.test.stub +6 -1
  32. package/stubs/factory.stub +3 -0
  33. package/stubs/initializer.stub +2 -0
  34. package/stubs/initializer.test.stub +3 -0
  35. package/stubs/job.cron.stub +4 -0
  36. package/stubs/job.stub +4 -0
  37. package/stubs/job.test.stub +3 -0
  38. package/stubs/mcp.resource.stub +3 -0
  39. package/stubs/mcp.stub +3 -0
  40. package/stubs/mcp.test.stub +3 -0
  41. package/stubs/middleware.stub +6 -1
  42. package/stubs/middleware.test.stub +3 -0
  43. package/stubs/model.stub +10 -1
  44. package/stubs/model.test.stub +3 -0
  45. package/stubs/policy.stub +3 -0
  46. package/stubs/policy.test.stub +3 -0
  47. package/stubs/service.stub +4 -0
  48. package/stubs/service.test.stub +3 -0
  49. package/stubs/validator.stub +3 -0
  50. package/stubs/validator.test.stub +3 -0
  51. package/templates/app/.env.example +16 -0
  52. package/templates/app/README.md +62 -35
  53. package/templates/app/app/commands/about.test.ts +1 -1
  54. package/templates/app/app/commands/db/console.ts +6 -0
  55. package/templates/app/app/commands/db/migrate.test.ts +30 -0
  56. package/templates/app/app/commands/db/migrate.ts +55 -0
  57. package/templates/app/app/commands/index.ts +16 -0
  58. package/templates/app/app/commands/typegen.test.ts +17 -0
  59. package/templates/app/app/commands/typegen.ts +16 -0
  60. package/templates/app/app/http/controllers/api/health.tsx +15 -0
  61. package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
  62. package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
  63. package/templates/app/app/http/controllers/home.tsx +21 -13
  64. package/templates/app/app/http/controllers/mcp.tsx +16 -0
  65. package/templates/app/app/http/controllers/not-found.tsx +23 -18
  66. package/templates/app/app/http/controllers/robots.test.ts +18 -0
  67. package/templates/app/app/http/controllers/robots.ts +24 -0
  68. package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
  69. package/templates/app/app/http/controllers/sitemap.ts +25 -0
  70. package/templates/app/app/http/middleware/api.ts +10 -0
  71. package/templates/app/app/http/middleware/page.test.ts +40 -0
  72. package/templates/app/app/http/middleware/page.ts +49 -0
  73. package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
  74. package/templates/app/app/http/middleware/server-timing.ts +42 -0
  75. package/templates/app/app/initializers/assets.ts +1 -1
  76. package/templates/app/app/initializers/captcha.ts +11 -0
  77. package/templates/app/app/initializers/cli.ts +42 -2
  78. package/templates/app/app/initializers/database.test.ts +18 -0
  79. package/templates/app/app/initializers/database.ts +18 -0
  80. package/templates/app/app/initializers/dispatcher.ts +18 -0
  81. package/templates/app/app/initializers/honeypot.ts +11 -0
  82. package/templates/app/app/initializers/i18n.test.ts +16 -0
  83. package/templates/app/app/initializers/i18n.ts +28 -0
  84. package/templates/app/app/initializers/local-database.test.ts +33 -0
  85. package/templates/app/app/initializers/local-database.ts +53 -0
  86. package/templates/app/app/initializers/mail.test.ts +27 -0
  87. package/templates/app/app/initializers/mail.ts +11 -0
  88. package/templates/app/app/initializers/mcp.ts +1 -1
  89. package/templates/app/app/initializers/openapi.ts +21 -0
  90. package/templates/app/app/initializers/router.test.ts +61 -0
  91. package/templates/app/app/initializers/router.tsx +72 -26
  92. package/templates/app/app/initializers/seo.ts +15 -0
  93. package/templates/app/app/initializers/session.test.ts +34 -0
  94. package/templates/app/app/initializers/session.ts +29 -0
  95. package/templates/app/app/initializers/spam.ts +10 -0
  96. package/templates/app/app/models/index.ts +10 -0
  97. package/templates/app/app/services/migrations.test.ts +45 -0
  98. package/templates/app/app/services/migrations.ts +60 -0
  99. package/templates/app/app/test/cloudflare-workers.ts +25 -0
  100. package/templates/app/bootstrap/cli.ts +1 -1
  101. package/templates/app/bootstrap/worker.ts +4 -4
  102. package/templates/app/cloudflare.config.ts +29 -1
  103. package/templates/app/config/constants.ts +19 -0
  104. package/templates/app/config/problems.ts +24 -0
  105. package/templates/app/config/security-policy.ts +34 -0
  106. package/templates/app/config/security-txt.ts +28 -0
  107. package/templates/app/database/migrations/.gitkeep +0 -0
  108. package/templates/app/package.json +35 -5
  109. package/templates/app/resources/layouts/document.tsx +28 -7
  110. package/templates/app/resources/locales/en.json +10 -0
  111. package/templates/app/routes/api.ts +29 -0
  112. package/templates/app/routes/web.ts +6 -4
  113. package/templates/app/vite.config.ts +4 -0
  114. package/templates/app/config/router-context.d.ts +0 -20
package/dist/init.d.ts CHANGED
@@ -32,7 +32,9 @@ export declare function init(root: string, options: {
32
32
  }): Promise<Result<InitOutcome, Error>>;
33
33
  /**
34
34
  * The configuration file `init` writes: `$schema` first, then every key in schema order with
35
- * its description as a comment. A key with a default is written with it; a key without one is
36
- * written commented out with its first example.
35
+ * its description as a comment. A top-level key in `values` is written with that value, any
36
+ * other key with its default, and a key with neither commented out with its first example.
37
+ *
38
+ * @example renderConfig({ format: ["bunx", "vp", "fmt"] })
37
39
  */
38
- export declare function renderConfig(): Result<string, Error>;
40
+ export declare function renderConfig(values?: Record<string, unknown>): Result<string, Error>;
package/dist/init.js CHANGED
@@ -46,20 +46,25 @@ export async function init(root, options) {
46
46
  }
47
47
  /**
48
48
  * The configuration file `init` writes: `$schema` first, then every key in schema order with
49
- * its description as a comment. A key with a default is written with it; a key without one is
50
- * written commented out with its first example.
49
+ * its description as a comment. A top-level key in `values` is written with that value, any
50
+ * other key with its default, and a key with neither commented out with its first example.
51
+ *
52
+ * @example renderConfig({ format: ["bunx", "vp", "fmt"] })
51
53
  */
52
- export function renderConfig() {
54
+ export function renderConfig(values = {}) {
53
55
  let schema = configJSONSchema();
54
56
  if (isFailure(schema))
55
57
  return schema;
56
58
  let lines = ["{", `\t${JSON.stringify("$schema")}: ${JSON.stringify(SCHEMA_REFERENCE)},`];
57
- renderProperties(schema.data, 1, lines);
59
+ renderProperties(schema.data, 1, lines, values);
58
60
  lines.push("}");
59
61
  return success(`${lines.join("\n")}\n`);
60
62
  }
61
- /** Appends one line per key of `schema`'s properties, nesting into a group that has its own. */
62
- function renderProperties(schema, depth, lines) {
63
+ /**
64
+ * Appends one line per key of `schema`'s properties, nesting into a group that has its own;
65
+ * a key in `values` is written with its value there.
66
+ */
67
+ function renderProperties(schema, depth, lines, values = {}) {
63
68
  let indent = "\t".repeat(depth);
64
69
  for (let [key, property] of Object.entries(schema.properties ?? {})) {
65
70
  if (key === "$schema" || typeof property === "boolean")
@@ -67,7 +72,10 @@ function renderProperties(schema, depth, lines) {
67
72
  if (typeof property.description === "string")
68
73
  lines.push(`${indent}// ${property.description}`);
69
74
  let name = JSON.stringify(key);
70
- if (property.properties !== undefined) {
75
+ if (key in values) {
76
+ lines.push(`${indent}${name}: ${inline(values[key])},`);
77
+ }
78
+ else if (property.properties !== undefined) {
71
79
  lines.push(`${indent}${name}: {`);
72
80
  renderProperties(property, depth + 1, lines);
73
81
  lines.push(`${indent}},`);
@@ -1,9 +1,9 @@
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` the same way. Every edit is computed before anything is written;
6
+ * when one cannot be placed, none is made and the command prints them for the user instead.
7
7
  *
8
8
  * @author [Sergio Xalambrí](https://sergiodxa.com)
9
9
  * @copyright Sergio Xalambrí 2026
@@ -11,7 +11,7 @@
11
11
  import type { Name } from "./names.js";
12
12
  /** What to declare and map, as the command line asked for it. */
13
13
  export interface DeclarationRequest {
14
- kind: "job" | "controller" | "mcp" | "command";
14
+ kind: "job" | "controller" | "mcp" | "command" | "model";
15
15
  name: Name;
16
16
  /** `cron` for a scheduled job, `resource` for an MCP resource, `null` otherwise. */
17
17
  variant: string | null;
@@ -1,9 +1,9 @@
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` the same way. Every edit is computed before anything is written;
6
+ * when one cannot be placed, none is made and the command prints them for the user instead.
7
7
  *
8
8
  * @author [Sergio Xalambrí](https://sergiodxa.com)
9
9
  * @copyright Sergio Xalambrí 2026
@@ -24,6 +24,8 @@ const ROUTE_HELPERS = {
24
24
  delete: "del",
25
25
  form: "form",
26
26
  };
27
+ /** The route helpers that declare a page, which a sitemap built with `fromRoutes` must decide. */
28
+ const PAGE_HELPERS = new Set(["get", "form"]);
27
29
  /** The name an instance gets when the initializer that creates it cannot be read, by factory. */
28
30
  const INSTANCE_NAMES = {
29
31
  createRouter: "router",
@@ -38,6 +40,8 @@ export async function declare(request, root) {
38
40
  return declareController(request, root);
39
41
  if (request.kind === "command")
40
42
  return declareCommand(request, root);
43
+ if (request.kind === "model")
44
+ return declareModel(request, root);
41
45
  return declareMcp(request, root);
42
46
  }
43
47
  /** Declares a job in `app/jobs/index.ts` and maps it on the job dispatcher. */
@@ -107,7 +111,7 @@ async function declareController(request, root) {
107
111
  let { name } = request;
108
112
  let module = `routes/${request.routes}`;
109
113
  let contract = await findContract(root, module);
110
- let initializer = await findInitializer(root, module, null);
114
+ let initializer = await findInitializer(root, module, "createRouter", "required");
111
115
  let instance = initializer === null ? "router" : instanceOf(initializer, "createRouter");
112
116
  let local = initializer === null ? "routes" : (defaultLocal(initializer, module) ?? "routes");
113
117
  let path = [...name.segments.slice(0, -1).map(camel), name.key];
@@ -117,11 +121,23 @@ async function declareController(request, root) {
117
121
  let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
118
122
  let lazyLocal = "lazy";
119
123
  let statement = (lazy) => `${instance}.map(${local}.${path.join(".")}, ${lazy}(() => import(${literal(handler)})));`;
124
+ let sitemap = PAGE_HELPERS.has(helper) ? await findSitemap(root, module) : null;
125
+ let decision = sitemapDecision(helper, pattern);
120
126
  let manual = (reason) => ({
121
127
  kind: "manual",
122
128
  path: path.join("."),
123
129
  reason,
124
- instructions: instructions(`${contract ?? `${module}.ts`}, in route({ … })${groupNote(path)}`, `${path.at(-1)}: ${value},`, initializer?.path ?? `the initializer that maps ${module}`, statement(lazyLocal)),
130
+ instructions: [
131
+ instructions(`${contract ?? `${module}.ts`}, in route({ … })${groupNote(path)}`, `${path.at(-1)}: ${value},`, initializer?.path ?? `the initializer that maps ${module}`, statement(lazyLocal)),
132
+ sitemap === null
133
+ ? null
134
+ : [
135
+ `In ${sitemap.path}, in fromRoutes(…)'s decisions${groupNote(path)}:`,
136
+ indent(`${path.at(-1)}: ${decision},`),
137
+ ].join("\n"),
138
+ ]
139
+ .filter((text) => text !== null)
140
+ .join("\n"),
125
141
  });
126
142
  if (contract === null)
127
143
  return manual(`there is no route contract ${module}.ts`);
@@ -150,14 +166,60 @@ async function declareController(request, root) {
150
166
  let mapped = mapAfter(withLazy, module, local, statement(lazyLocal), `${instance}.map`, "createRouter");
151
167
  if (isFailure(mapped))
152
168
  return manual(mapped.error.message);
153
- return {
154
- kind: "edits",
155
- path: path.join("."),
156
- edits: [
157
- { path: contract, before: file.data.source, after: added.data.source },
158
- { path: initializer.path, before: initializer.source, after: mapped.data },
159
- ],
160
- };
169
+ let edits = [
170
+ { path: contract, before: file.data.source, after: added.data.source },
171
+ { path: initializer.path, before: initializer.source, after: mapped.data },
172
+ ];
173
+ if (sitemap !== null) {
174
+ let decided = addProperty(sitemap.path, sitemap.source, {
175
+ call: "fromRoutes",
176
+ argument: 2,
177
+ path: path.slice(0, -1),
178
+ key: name.key,
179
+ value: decision,
180
+ });
181
+ if (isSuccess(decided)) {
182
+ edits.push({ path: sitemap.path, before: sitemap.source, after: decided.data.source });
183
+ }
184
+ else if (decided.error.code === "invalid-output") {
185
+ return manual(decided.error.message);
186
+ }
187
+ }
188
+ return { kind: "edits", path: path.join("."), edits };
189
+ }
190
+ /**
191
+ * The sitemap decision a new page starts with: listed, or an empty list of pages when its pattern
192
+ * has required params, so it is in the sitemap until the developer changes it. A `form` route
193
+ * decides its page under `index`.
194
+ */
195
+ function sitemapDecision(helper, pattern) {
196
+ let required = /[:*][A-Za-z_$]/.test(pattern.replace(/\([^)]*\)/g, ""));
197
+ let page = required ? "[]" : "true";
198
+ return helper === "form" ? `{ index: ${page} }` : page;
199
+ }
200
+ /**
201
+ * The controller that builds a sitemap with `fromRoutes` over the contract `module`, which needs
202
+ * a decision for every page the contract declares; `null` when the app has none.
203
+ */
204
+ async function findSitemap(root, module) {
205
+ let folder = "app/http/controllers";
206
+ let entries = await wrap(() => readdir(join(root, folder), { recursive: true }));
207
+ if (isFailure(entries))
208
+ return null;
209
+ for (let entry of entries.data.sort()) {
210
+ if (!/\.tsx?$/.test(entry) || /\.test\.tsx?$/.test(entry))
211
+ continue;
212
+ let file = await readSource(root, posix.join(folder, entry.split("\\").join("/")));
213
+ if (isFailure(file) || !file.data.source.includes("fromRoutes("))
214
+ continue;
215
+ let local = defaultLocal(file.data, module);
216
+ if (local === null)
217
+ continue;
218
+ if (new RegExp(`\\bfromRoutes\\(\\s*${escape(local)}\\s*,`).test(file.data.source)) {
219
+ return file.data;
220
+ }
221
+ }
222
+ return null;
161
223
  }
162
224
  /** Declares an MCP tool or resource beside the others and maps it on the MCP handler. */
163
225
  async function declareMcp(request, root) {
@@ -324,6 +386,45 @@ async function declareCommand(request, root) {
324
386
  ],
325
387
  };
326
388
  }
389
+ /**
390
+ * Registers a model in `app/models/index.ts`'s `createModels({ … })` under its key, as an import
391
+ * the registry runs on first use, so `ctx.models.<key>` reaches it on every request, job and
392
+ * command once the command finishes.
393
+ */
394
+ async function declareModel(request, root) {
395
+ let declarations = "app/models/index.ts";
396
+ let key = request.name.key;
397
+ let file = await readSource(root, declarations);
398
+ let specifier = isFailure(file)
399
+ ? `./${request.name.segments.join("/")}`
400
+ : specifierFor(declarations, request.handler, staticSpecifiers(file.data), false);
401
+ let value = `() => import(${literal(specifier)})`;
402
+ let manual = (reason) => ({
403
+ kind: "manual",
404
+ path: key,
405
+ reason,
406
+ instructions: [
407
+ `In ${declarations}, in createModels({ … }):`,
408
+ indent(`${keyText(key)}: ${value},`),
409
+ ].join("\n"),
410
+ });
411
+ if (isFailure(file))
412
+ return manual(`${declarations} could not be read`);
413
+ let call = file.data.references
414
+ .find((reference) => reference.kind === "import" &&
415
+ reference.names.some((bound) => bound.imported === "createModels"))
416
+ ?.names.find((bound) => bound.imported === "createModels")?.local;
417
+ if (call === undefined)
418
+ return manual(`${declarations} does not import createModels()`);
419
+ let added = addProperty(declarations, file.data.source, { call, path: [], key, value });
420
+ if (isFailure(added))
421
+ return manual(added.error.message);
422
+ return {
423
+ kind: "edits",
424
+ path: key,
425
+ edits: [{ path: declarations, before: file.data.source, after: added.data.source }],
426
+ };
427
+ }
327
428
  /**
328
429
  * A `commands({ … })` group holding `entry`, wrapped in one more group for each of `levels`,
329
430
  * outermost first, for the folders of a command name that have no group yet.
@@ -367,10 +468,11 @@ function mapAfter(file, module, local, statement, call, factory) {
367
468
  return success(inserted.data.source);
368
469
  }
369
470
  /**
370
- * The first initializer in `app/initializers/` that imports `module`, or failing that, one that
371
- * calls `factory`; `null` when none does. Test files are skipped.
471
+ * The initializer in `app/initializers/` that imports `module` and calls `factory`, else the
472
+ * first that imports it, else (unless `importing` is required) one that calls `factory`; `null`
473
+ * when none does. Test files are skipped.
372
474
  */
373
- async function findInitializer(root, module, factory) {
475
+ async function findInitializer(root, module, factory, importing = "preferred") {
374
476
  let folder = "app/initializers";
375
477
  let entries = await wrap(() => readdir(join(root, folder)));
376
478
  if (isFailure(entries))
@@ -387,12 +489,13 @@ async function findInitializer(root, module, factory) {
387
489
  let aliased = !isFailure(tsconfig) && tsconfig.data.includes('"~/app/*"');
388
490
  for (let file of files)
389
491
  file.aliased = aliased;
390
- let importing = files.find((file) => file.references.some((reference) => reference.kind === "import" && resolvesTo(reference.specifier, file.path, module)));
391
- if (importing !== undefined)
392
- return importing;
393
- if (factory === null)
492
+ let calling = factory === null ? null : new RegExp(`\\b${factory}\\(`);
493
+ let importers = files.filter((file) => file.references.some((reference) => reference.kind === "import" && resolvesTo(reference.specifier, file.path, module)));
494
+ let found = importers.find((file) => calling?.test(file.source) ?? true) ?? importers[0];
495
+ if (found !== undefined)
496
+ return found;
497
+ if (calling === null || importing === "required")
394
498
  return null;
395
- let calling = new RegExp(`\\b${factory}\\(`);
396
499
  return files.find((file) => calling.test(file.source)) ?? null;
397
500
  }
398
501
  /** The route contract file for `module` (`routes/web`), `.ts` or `.tsx`, or `null`. */
@@ -7,8 +7,9 @@
7
7
  * @copyright Sergio Xalambrí 2026
8
8
  */
9
9
  import { readFile, stat } from "node:fs/promises";
10
- import { join } from "node:path";
10
+ import { dirname, join } from "node:path";
11
11
  import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
12
+ import { headerTags, resolveAuthor } from "../author.js";
12
13
  import { COMMON_PLACEHOLDERS, KINDS, MCP_RESOURCES_FOLDER } from "./kinds.js";
13
14
  import { chainFolder, nextMigrationFile } from "./migrations.js";
14
15
  import { camel } from "./names.js";
@@ -68,10 +69,14 @@ export function folderOf(kind, variant) {
68
69
  }
69
70
  /**
70
71
  * Renders the kind's stub, or its test stub, with `values`. A variant's own stub wins; a
71
- * variant without its own test stub uses the kind's.
72
+ * variant without its own test stub uses the kind's. A controller with no variant takes its
73
+ * contract's stub when one exists (`controller.api.stub` for `routes/api`), else the kind's.
72
74
  */
73
75
  async function renderFile(request, values, test, root, config, packageRoot) {
74
76
  let names = [stubName(request.kind, request.variant, test)];
77
+ if (request.kind === "controller" && request.variant === null) {
78
+ names.unshift(stubName(request.kind, request.routes, test));
79
+ }
75
80
  if (request.variant !== null && test)
76
81
  names.push(stubName(request.kind, null, true));
77
82
  let stub = await loadStub(names, root, config.make.stubs, packageRoot);
@@ -92,6 +97,7 @@ async function placeholders(request, root, file) {
92
97
  snake: name.snake,
93
98
  title: name.title,
94
99
  specifier: `~/${file}`,
100
+ header: headerTags(await resolveAuthor(dirname(join(root, file)))),
95
101
  };
96
102
  let declarationPath = name.segments.map(camel).join(".");
97
103
  let extra = {
@@ -41,7 +41,11 @@ export async function make(ctx, project, packageRoot, input) {
41
41
  routes: input.routes ?? config.make.routes,
42
42
  };
43
43
  let declared = null;
44
- if (kind === "job" || kind === "controller" || kind === "mcp" || kind === "command") {
44
+ if (kind === "job" ||
45
+ kind === "controller" ||
46
+ kind === "mcp" ||
47
+ kind === "command" ||
48
+ kind === "model") {
45
49
  let segments = request.name.segments;
46
50
  declared = await declare({
47
51
  kind,
@@ -22,7 +22,8 @@ export interface Kind {
22
22
  }
23
23
  /**
24
24
  * The placeholders every stub may use: the file's base name (`name`), its camelCase `key`, its
25
- * PascalCase `Name`, its `snake` and `title` spellings, and the import `specifier` of the file.
25
+ * PascalCase `Name`, its `snake` and `title` spellings, the import `specifier` of the file, and
26
+ * the `header` tags crediting its author, placed at the end of the module JSDoc's description.
26
27
  */
27
28
  export declare const COMMON_PLACEHOLDERS: string[];
28
29
  /**
@@ -8,9 +8,10 @@
8
8
  */
9
9
  /**
10
10
  * The placeholders every stub may use: the file's base name (`name`), its camelCase `key`, its
11
- * PascalCase `Name`, its `snake` and `title` spellings, and the import `specifier` of the file.
11
+ * PascalCase `Name`, its `snake` and `title` spellings, the import `specifier` of the file, and
12
+ * the `header` tags crediting its author, placed at the end of the module JSDoc's description.
12
13
  */
13
- export const COMMON_PLACEHOLDERS = ["name", "key", "Name", "snake", "title", "specifier"];
14
+ export const COMMON_PLACEHOLDERS = ["name", "key", "Name", "snake", "title", "specifier", "header"];
14
15
  /**
15
16
  * Every kind, in the order `sdxc make --help` lists them. `path` is the declaration's key path
16
17
  * in its map (`trials.expire`), `routes` the route contract's specifier, `tool` the MCP tool
package/dist/testing.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Builds a project from a built-in template the way a consumer's install would see it, for the
3
3
  * tests that type check templates and generated code: dependencies are linked from this
4
- * workspace instead of installed, and the Worker's types are generated as `cf:typegen` does.
4
+ * workspace instead of installed, and the Worker's types are generated as `sdxc run typegen` does.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
8
8
  */
9
+ import type { Exec } from "@sdxc/cli";
9
10
  import type { Result } from "@sdxc/result";
10
11
  /** What a spawned command printed and how it exited. */
11
12
  export interface Spawned {
@@ -35,7 +36,9 @@ export declare function linkDependencies(project: string): Promise<Result<void,
35
36
  export declare function registryDocument(name: string, versions?: readonly string[]): Record<string, unknown>;
36
37
  /**
37
38
  * Links what `package.json` gained since, generates the Worker's types with the project's own
38
- * `cf`, then type checks the project with the workspace's TypeScript, answering what it printed.
39
+ * `cf`, then type checks the project through its own `vp check`, answering what it printed. That
40
+ * is the checker a consumer's `bun run check` runs, and it reports `vite.config.ts` type errors
41
+ * TypeScript 6's `tsc` passes.
39
42
  */
40
43
  export declare function typecheck(project: string): Promise<Spawned>;
41
44
  /**
@@ -48,3 +51,10 @@ export declare function runCommandLine(project: string, argv: string[]): Promise
48
51
  * `--no-color` so the summary reads as plain text on CI too, where Vite+ colors it otherwise.
49
52
  */
50
53
  export declare function testProject(project: string): Promise<Spawned>;
54
+ /**
55
+ * An exec that runs `bunx vp …` with the project's own Vite+, as `bunx` resolves it from an
56
+ * install, so a test runs the `format` command a built-in template configures without a download.
57
+ */
58
+ export declare function projectExec(project: string): Exec;
59
+ /** Runs the project's own Vite+ formatter in check mode over the whole project, as `vp check` does. */
60
+ export declare function checkFormatting(project: string): Promise<Spawned>;
package/dist/testing.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Builds a project from a built-in template the way a consumer's install would see it, for the
3
3
  * tests that type check templates and generated code: dependencies are linked from this
4
- * workspace instead of installed, and the Worker's types are generated as `cf:typegen` does.
4
+ * workspace instead of installed, and the Worker's types are generated as `sdxc run typegen` does.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
@@ -10,6 +10,7 @@ import { spawn } from "node:child_process";
10
10
  import { access, lstat, mkdir, mkdtemp, readFile, symlink } from "node:fs/promises";
11
11
  import { tmpdir } from "node:os";
12
12
  import { dirname, join } from "node:path";
13
+ import { spawnExec } from "@sdxc/cli";
13
14
  import { invoke } from "@sdxc/cli/test";
14
15
  import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
15
16
  import { createSDXC } from "./cli.js";
@@ -74,7 +75,9 @@ export function registryDocument(name, versions = ["0.0.1"]) {
74
75
  }
75
76
  /**
76
77
  * Links what `package.json` gained since, generates the Worker's types with the project's own
77
- * `cf`, then type checks the project with the workspace's TypeScript, answering what it printed.
78
+ * `cf`, then type checks the project through its own `vp check`, answering what it printed. That
79
+ * is the checker a consumer's `bun run check` runs, and it reports `vite.config.ts` type errors
80
+ * TypeScript 6's `tsc` passes.
78
81
  */
79
82
  export async function typecheck(project) {
80
83
  let linked = await linkDependencies(project);
@@ -83,7 +86,7 @@ export async function typecheck(project) {
83
86
  let types = await run([join(project, "node_modules/cf/bin/cf"), "workers", "types"], project);
84
87
  if (types.code !== 0)
85
88
  return types;
86
- return run([join(project, "node_modules/typescript/bin/tsc"), "--noEmit", "-p", project], project);
89
+ return run([join(project, "node_modules/vite-plus/bin/vp"), "check", "--no-fmt", "--no-lint"], project);
87
90
  }
88
91
  /**
89
92
  * Runs the project's own command line, `bootstrap/cli.ts`, under Bun with `argv`, as
@@ -99,6 +102,22 @@ export function runCommandLine(project, argv) {
99
102
  export function testProject(project) {
100
103
  return run([join(project, "node_modules/vite-plus/bin/vp"), "test", "run", "--no-color"], project);
101
104
  }
105
+ /**
106
+ * An exec that runs `bunx vp …` with the project's own Vite+, as `bunx` resolves it from an
107
+ * install, so a test runs the `format` command a built-in template configures without a download.
108
+ */
109
+ export function projectExec(project) {
110
+ return (command, request) => {
111
+ let [runner, binary, ...rest] = command;
112
+ if (runner !== "bunx" || binary !== "vp")
113
+ return spawnExec(command, request);
114
+ return spawnExec([process.execPath, join(project, "node_modules/vite-plus/bin/vp"), ...rest], request);
115
+ };
116
+ }
117
+ /** Runs the project's own Vite+ formatter in check mode over the whole project, as `vp check` does. */
118
+ export function checkFormatting(project) {
119
+ return run([join(project, "node_modules/vite-plus/bin/vp"), "fmt", "--check"], project);
120
+ }
102
121
  /** The directory `dependency` is installed at for this package or, failing that, the workspace. */
103
122
  async function installed(packageRoot, dependency) {
104
123
  let candidates = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdxc/kit",
3
- "version": "2026.10.16",
3
+ "version": "2026.10.17",
4
4
  "description": "The sdxc command line: start a Remix v3 app, generate its files, copy UI components into it and upgrade it",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@sdxc/cli": "2026.10.16",
17
- "@sdxc/codemod": "2026.10.16",
17
+ "@sdxc/codemod": "2026.10.17",
18
18
  "@sdxc/json-schema": "2026.10.16",
19
19
  "@sdxc/jsonc": "2026.10.16",
20
20
  "@sdxc/jsonl": "2026.10.16",
@@ -24,7 +24,7 @@
24
24
  "peerDependencies": {
25
25
  "remix": "3.0.0"
26
26
  },
27
- "gitHead": "1e547d8431568f5ed9bdb079ca3046c936240fde",
27
+ "gitHead": "4f4bce453e9afe69f53194368af9e9739d73a876",
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
@@ -1,5 +1,8 @@
1
1
  /**
2
2
  * `{{command}}`: describe what it changes, what it prints, and whether it is safe to run twice.
3
+ *
4
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/your-apps-command-line}
5
+ * @see {@link https://sdxc.dev/api/cli}{{header}}
3
6
  */
4
7
 
5
8
  import { createCommand, success } from "@sdxc/cli";
@@ -7,6 +10,7 @@ import { createCommand, success } from "@sdxc/cli";
7
10
  import commandset from "~/app/commands";
8
11
 
9
12
  export default createCommand(commandset{{member}}, (ctx) => {
13
+ // TODO: do the work, then report what changed
10
14
  ctx.stdout("{{title}}\n");
11
15
  return success();
12
16
  });
@@ -1,5 +1,8 @@
1
1
  /**
2
2
  * The `{{command}}` command, run through the app's command line.
3
+ *
4
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/your-apps-command-line}
5
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
3
6
  */
4
7
 
5
8
  import { invoke } from "@sdxc/cli/test";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The {{title}} endpoint: describe what a client sends, what it gets back and which errors it
3
+ * should expect.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
6
+ * @see {@link https://sdxc.dev/docs/building-remix-apps/forms-and-params}{{header}}
7
+ */
8
+
9
+ import { createAction } from "remix/router";
10
+
11
+ import api from "~/app/http/middleware/api";
12
+ import routes from "{{routes}}";
13
+
14
+ export default createAction(routes.{{path}}, {
15
+ middleware: api,
16
+ /** Answers {{title}} as JSON; report a failure with a builder from `~/config/problems`. */
17
+ handler: () => {
18
+ // TODO: answer the request
19
+ return Response.json({});
20
+ },
21
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The {{title}} endpoint.
3
+ *
4
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
5
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
6
+ */
7
+
8
+ import { describe, expect, test } from "vitest";
9
+
10
+ import controller from "{{specifier}}";
11
+
12
+ describe("{{name}}", () => {
13
+ test("exports what the router maps", () => {
14
+ expect(controller).toBeDefined();
15
+ });
16
+
17
+ test.todo("answers {{title}} as JSON");
18
+ });
@@ -1,33 +1,63 @@
1
1
  /**
2
2
  * The {{title}} form: the page that shows it and the action that receives it. Describe what
3
3
  * a submission changes and where the visitor lands afterwards.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/building-remix-apps/forms-and-params}
6
+ * @see {@link https://sdxc.dev/docs/identity-and-security/protect-forms}{{header}}
4
7
  */
5
8
 
9
+ import { captcha } from "@sdxc/captcha/middleware";
10
+ import { TurnstileWidget } from "@sdxc/captcha/turnstile/ui";
11
+ import { HoneypotFields } from "@sdxc/honeypot/ui";
12
+ import { unwrap } from "@sdxc/result";
13
+ import { spam } from "@sdxc/spam/middleware";
14
+ import { env } from "cloudflare:workers";
6
15
  import { createController } from "remix/router";
7
16
 
17
+ import page from "~/app/http/middleware/page";
18
+ import { turnstile } from "~/app/initializers/captcha";
19
+ import { spamFilter } from "~/app/initializers/spam";
8
20
  import DocumentLayout from "~/resources/layouts/document";
9
21
  import routes from "{{routes}}";
10
22
 
11
23
  export default createController(routes.{{path}}, {
24
+ middleware: page,
12
25
  actions: {
13
- /** Renders the form. */
14
- index(ctx) {
26
+ /**
27
+ * Renders the form with fresh honeypot fields, which the page middleware checks on submit,
28
+ * and the Turnstile widget, admitted by the response's CSP nonce.
29
+ */
30
+ async index(ctx) {
31
+ let fields = unwrap(await ctx.honeypot.issue());
15
32
  return ctx.render(
16
- <DocumentLayout assets={ctx.assets} title="{{title}}">
33
+ <DocumentLayout assets={ctx.assets} intl={ctx.intl} url={ctx.url} title="{{title}}">
17
34
  <h1>{{title}}</h1>
18
35
  <form method="post" action={routes.{{path}}.action.href()}>
36
+ <HoneypotFields {...fields} />
37
+ {/* TODO: replace the message field with the fields this form submits */}
38
+ <label>
39
+ Message <textarea name="message" required />
40
+ </label>
41
+ <TurnstileWidget siteKey={env.TURNSTILE_SITE_KEY} nonce={ctx.assets.nonce} />
19
42
  <button type="submit">Send</button>
20
43
  </form>
21
44
  </DocumentLayout>,
22
45
  );
23
46
  },
24
47
 
25
- /** Receives a submission and sends the visitor back to the form. */
26
- action() {
27
- return new Response(null, {
28
- status: 303,
29
- headers: { location: routes.{{path}}.index.href() },
30
- });
48
+ /**
49
+ * Receives a submission that passed the honeypot, the CAPTCHA (a 403 otherwise) and the
50
+ * spam filter (a 422 otherwise), and sends the visitor back to the form.
51
+ */
52
+ action: {
53
+ middleware: [captcha(turnstile), spam(spamFilter, { fields: { content: "message" } })],
54
+ async handler(ctx) {
55
+ // TODO: save the submission, then redirect where the visitor should land
56
+ return new Response(null, {
57
+ status: 303,
58
+ headers: { location: routes.{{path}}.index.href() },
59
+ });
60
+ },
31
61
  },
32
62
  },
33
63
  });