@sdxc/kit 2026.10.20 → 2026.10.21
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.
- package/README.md +95 -90
- package/changelog.jsonl +11 -0
- package/config.schema.json +6 -0
- package/dist/commands/make.d.ts +6 -0
- package/dist/commands/make.js +7 -1
- package/dist/commands/scaffold.d.ts +1 -0
- package/dist/commands/scaffold.js +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +4 -0
- package/dist/contract.d.ts +4 -0
- package/dist/contract.js +16 -5
- package/dist/dependencies.d.ts +2 -1
- package/dist/dependencies.js +4 -1
- package/dist/destroy.d.ts +4 -4
- package/dist/destroy.js +11 -5
- package/dist/doctor/checks.js +2 -0
- package/dist/doctor/jsdoc.d.ts +44 -0
- package/dist/doctor/jsdoc.js +201 -0
- package/dist/make/generate.d.ts +11 -2
- package/dist/make/generate.js +47 -16
- package/dist/make/index.d.ts +4 -2
- package/dist/make/index.js +4 -1
- package/dist/make/kinds.d.ts +5 -0
- package/dist/make/kinds.js +14 -2
- package/dist/make/stubs.d.ts +7 -2
- package/dist/make/stubs.js +8 -3
- package/dist/make/test.js +1 -0
- package/dist/scaffold/index.d.ts +2 -0
- package/dist/scaffold/index.js +13 -4
- package/dist/scaffold/render.d.ts +11 -1
- package/dist/scaffold/render.js +86 -1
- package/package.json +2 -2
- package/registry/ui/sidebar.json +3 -3
- package/registry/ui/typeset.json +3 -3
- package/stubs/command.spec.stub +15 -0
- package/stubs/controller.api.spec.stub +15 -0
- package/stubs/controller.spec.stub +15 -0
- package/stubs/mcp.spec.stub +16 -0
- package/stubs/scaffold.migration.stub +2 -1
- package/stubs/scaffold.spec.stub +7 -0
- package/templates/app/AGENTS.md +8 -4
- package/templates/app/README.md +6 -3
- package/templates/app/app/commands/typegen.test.ts +20 -1
- package/templates/app/app/commands/typegen.ts +16 -2
- package/templates/app/app/initializers/cli.ts +7 -0
- package/templates/app/app/initializers/mail-transport.test.ts +8 -2
- package/templates/app/app/test/cloudflare-workers.ts +2 -0
- package/templates/app/package.json +1 -0
- package/templates/app/spec/config.jsonc +16 -0
package/dist/dependencies.js
CHANGED
|
@@ -27,11 +27,14 @@ const SUBPATH_PEERS = {
|
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
29
|
* Every `@sdxc/*` package `files` import, statically or dynamically, with the optional peers
|
|
30
|
-
* an imported subpath needs at runtime,
|
|
30
|
+
* an imported subpath needs at runtime, and `@sdxc/spec` when any file is a pairing `.spec`,
|
|
31
|
+
* sorted.
|
|
31
32
|
*/
|
|
32
33
|
export function importedPackages(files) {
|
|
33
34
|
let names = new Set();
|
|
34
35
|
for (let file of files) {
|
|
36
|
+
if (file.path.endsWith(".spec"))
|
|
37
|
+
names.add("@sdxc/spec");
|
|
35
38
|
let references = findModuleReferences(file.path, file.content);
|
|
36
39
|
if (isFailure(references))
|
|
37
40
|
continue;
|
package/dist/destroy.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `sdxc destroy <kind> <name>`: the reverse of `sdxc make`. It removes the file, its test
|
|
3
|
-
* for a model, its factory, then the mapping that loads the file, the
|
|
4
|
-
* names and the Worker trigger of a schedule no other job runs on.
|
|
5
|
-
* listed for the user to remove.
|
|
2
|
+
* `sdxc destroy <kind> <name>`: the reverse of `sdxc make`. It removes the file, its test, its
|
|
3
|
+
* pairing `.spec` and, for a model, its factory, then the mapping that loads the file, the
|
|
4
|
+
* declaration that mapping names and the Worker trigger of a schedule no other job runs on.
|
|
5
|
+
* Every other reference is listed for the user to remove.
|
|
6
6
|
*
|
|
7
7
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
8
|
* @copyright Sergio Xalambrí 2026
|
package/dist/destroy.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `sdxc destroy <kind> <name>`: the reverse of `sdxc make`. It removes the file, its test
|
|
3
|
-
* for a model, its factory, then the mapping that loads the file, the
|
|
4
|
-
* names and the Worker trigger of a schedule no other job runs on.
|
|
5
|
-
* listed for the user to remove.
|
|
2
|
+
* `sdxc destroy <kind> <name>`: the reverse of `sdxc make`. It removes the file, its test, its
|
|
3
|
+
* pairing `.spec` and, for a model, its factory, then the mapping that loads the file, the
|
|
4
|
+
* declaration that mapping names and the Worker trigger of a schedule no other job runs on.
|
|
5
|
+
* Every other reference is listed for the user to remove.
|
|
6
6
|
*
|
|
7
7
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
8
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -12,7 +12,7 @@ import { join, posix } from "node:path";
|
|
|
12
12
|
import { findStatements, removeProperty, removeStatements, tokenize } from "@sdxc/codemod";
|
|
13
13
|
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
14
14
|
import { listFiles } from "./doctor/files.js";
|
|
15
|
-
import { exists, folderOf } from "./make/generate.js";
|
|
15
|
+
import { exists, folderOf, specPathOf } from "./make/generate.js";
|
|
16
16
|
import { KINDS } from "./make/kinds.js";
|
|
17
17
|
import { parseName } from "./make/names.js";
|
|
18
18
|
import { planUntrigger } from "./make/trigger.js";
|
|
@@ -255,6 +255,12 @@ export async function planDestroy(root, input) {
|
|
|
255
255
|
return failure(new Error(`${file} does not exist; sdxc destroy removes what sdxc make wrote`));
|
|
256
256
|
}
|
|
257
257
|
let candidates = [file, `${base}.test${kind.extension}`];
|
|
258
|
+
if (kind.specs === true) {
|
|
259
|
+
candidates.push(specPathOf({
|
|
260
|
+
kind: input.kind,
|
|
261
|
+
name: name.data,
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
258
264
|
if (input.kind === "model")
|
|
259
265
|
candidates.push(`database/factories/${name.data.segments.join("/")}.ts`);
|
|
260
266
|
let remove = [];
|
package/dist/doctor/checks.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { emailsCheck } from "./emails.js";
|
|
10
10
|
import { envCheck } from "./env.js";
|
|
11
11
|
import { installedCheck } from "./installed.js";
|
|
12
|
+
import { jsdocCheck } from "./jsdoc.js";
|
|
12
13
|
import { layoutCheck } from "./layout.js";
|
|
13
14
|
import { migrationsCheck } from "./migrations.js";
|
|
14
15
|
import { modelsCheck } from "./models.js";
|
|
@@ -32,6 +33,7 @@ export const CHECKS = [
|
|
|
32
33
|
routesCheck,
|
|
33
34
|
modelsCheck,
|
|
34
35
|
emailsCheck,
|
|
36
|
+
jsdocCheck,
|
|
35
37
|
uiCheck,
|
|
36
38
|
];
|
|
37
39
|
/** Whether any check failed, which makes `sdxc doctor` exit 1. */
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `jsdoc` check: every comment in the app's source is a JSDoc block whose description stays
|
|
3
|
+
* within three prose lines, so an edit cannot leave a long narrative or a `//` aside beside the
|
|
4
|
+
* code it describes. Tags are left out of the line budget; `@param`, `@returns` and `@throws`
|
|
5
|
+
* stay on one line, and `@description` is refused.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { Check } from "./check.js";
|
|
11
|
+
/** The most prose lines a JSDoc description may hold. */
|
|
12
|
+
export declare const MAX_DESCRIPTION_LINES = 3;
|
|
13
|
+
/** One finding the check reports for a comment. */
|
|
14
|
+
export interface JsdocFinding {
|
|
15
|
+
/** The file, relative to the project root. */
|
|
16
|
+
file: string;
|
|
17
|
+
/** The 1-based line the comment starts on. */
|
|
18
|
+
line: number;
|
|
19
|
+
/** What is wrong with the comment. */
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Warns on each non-JSDoc comment that is not a tooling directive, each description longer than
|
|
24
|
+
* three prose lines, each banned `@description`, and each `@param` / `@returns` / `@throws` that
|
|
25
|
+
* spills onto a second line.
|
|
26
|
+
*/
|
|
27
|
+
export declare const jsdocCheck: Check;
|
|
28
|
+
/**
|
|
29
|
+
* Every rule breach in `source`, in source order. A file the scanner cannot tokenize is left
|
|
30
|
+
* alone so the type checker names the syntax error.
|
|
31
|
+
*
|
|
32
|
+
* @param file - Path reported in each finding.
|
|
33
|
+
* @param source - The module's text.
|
|
34
|
+
*/
|
|
35
|
+
export declare function inspectComments(file: string, source: string): JsdocFinding[];
|
|
36
|
+
/**
|
|
37
|
+
* Whether `value` is a JSDoc block (`/** … *\/`), the only comment shape a symbol may carry.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isJsdoc(value: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Whether `value` is a shebang, a triple-slash reference, or a tooling directive the repository
|
|
42
|
+
* keeps as the only non-JSDoc comments.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isToolingDirective(value: string): boolean;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `jsdoc` check: every comment in the app's source is a JSDoc block whose description stays
|
|
3
|
+
* within three prose lines, so an edit cannot leave a long narrative or a `//` aside beside the
|
|
4
|
+
* code it describes. Tags are left out of the line budget; `@param`, `@returns` and `@throws`
|
|
5
|
+
* stay on one line, and `@description` is refused.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { readFile } from "node:fs/promises";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { tokenize } from "@sdxc/codemod";
|
|
13
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
14
|
+
import { PROJECT_FOLDERS } from "../stats.js";
|
|
15
|
+
import { passed, skipped } from "./check.js";
|
|
16
|
+
import { isAppSource, listFiles } from "./files.js";
|
|
17
|
+
/** Tags whose description must stay on the same line as the tag. */
|
|
18
|
+
const ONE_LINE_TAGS = new Set([
|
|
19
|
+
"param",
|
|
20
|
+
"arg",
|
|
21
|
+
"argument",
|
|
22
|
+
"returns",
|
|
23
|
+
"return",
|
|
24
|
+
"throws",
|
|
25
|
+
"exception",
|
|
26
|
+
]);
|
|
27
|
+
/** Tags that belong in the comment's prose, not as a block tag. */
|
|
28
|
+
const BANNED_TAGS = new Set(["description", "desc"]);
|
|
29
|
+
/**
|
|
30
|
+
* Tooling directives the repository keeps as the only non-JSDoc comments, matched on the
|
|
31
|
+
* comment body after its markers.
|
|
32
|
+
*/
|
|
33
|
+
const TOOLING = /(?:@ts-(?:expect-error|ignore|nocheck)\b|oxlint-disable(?:-next-line)?\b|biome-ignore\b|eslint-disable(?:-next-line)?\b|prettier-ignore\b|@jsxImportSource\b|@vitest-environment\b|v8 ignore\b|c8 ignore\b|istanbul ignore\b|#__PURE__\b|\/?\s*<reference\b)/;
|
|
34
|
+
/** The most prose lines a JSDoc description may hold. */
|
|
35
|
+
export const MAX_DESCRIPTION_LINES = 3;
|
|
36
|
+
/**
|
|
37
|
+
* Warns on each non-JSDoc comment that is not a tooling directive, each description longer than
|
|
38
|
+
* three prose lines, each banned `@description`, and each `@param` / `@returns` / `@throws` that
|
|
39
|
+
* spills onto a second line.
|
|
40
|
+
*/
|
|
41
|
+
export const jsdocCheck = {
|
|
42
|
+
name: "jsdoc",
|
|
43
|
+
async run(context) {
|
|
44
|
+
let findings = [];
|
|
45
|
+
let files = 0;
|
|
46
|
+
for (let folder of PROJECT_FOLDERS) {
|
|
47
|
+
for (let file of (await listFiles(context.root, folder)).filter(isAppSource)) {
|
|
48
|
+
files += 1;
|
|
49
|
+
let source = await wrap(() => readFile(join(context.root, file), "utf8"));
|
|
50
|
+
if (isFailure(source))
|
|
51
|
+
continue;
|
|
52
|
+
for (let finding of inspectComments(file, source.data)) {
|
|
53
|
+
findings.push(`${finding.file}:${finding.line}: ${finding.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (files === 0)
|
|
58
|
+
return skipped("No app source to read for comments");
|
|
59
|
+
if (findings.length === 0) {
|
|
60
|
+
return passed("Every comment is JSDoc within three description lines");
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
status: "warn",
|
|
64
|
+
message: findings.length === 1
|
|
65
|
+
? "Found 1 comment outside the JSDoc rules"
|
|
66
|
+
: `Found ${findings.length} comments outside the JSDoc rules`,
|
|
67
|
+
findings,
|
|
68
|
+
fix: "Write comments as /** … */, keep the description to 3 lines, put @param/@returns/@throws on one line, and drop @description",
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Every rule breach in `source`, in source order. A file the scanner cannot tokenize is left
|
|
74
|
+
* alone so the type checker names the syntax error.
|
|
75
|
+
*
|
|
76
|
+
* @param file - Path reported in each finding.
|
|
77
|
+
* @param source - The module's text.
|
|
78
|
+
*/
|
|
79
|
+
export function inspectComments(file, source) {
|
|
80
|
+
let tokens = tokenize(file, source);
|
|
81
|
+
if (isFailure(tokens))
|
|
82
|
+
return [];
|
|
83
|
+
let findings = [];
|
|
84
|
+
for (let token of tokens.data) {
|
|
85
|
+
if (token.type !== "comment")
|
|
86
|
+
continue;
|
|
87
|
+
let line = lineOf(source, token.start);
|
|
88
|
+
let value = token.value;
|
|
89
|
+
if (value.startsWith("#!"))
|
|
90
|
+
continue;
|
|
91
|
+
if (isJsdoc(value)) {
|
|
92
|
+
findings.push(...inspectJsdoc(file, line, value));
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (isToolingDirective(value))
|
|
96
|
+
continue;
|
|
97
|
+
let kind = value.startsWith("//") ? "//" : "/* … */";
|
|
98
|
+
findings.push({
|
|
99
|
+
file,
|
|
100
|
+
line,
|
|
101
|
+
message: `${kind} comment; write JSDoc (/** … */) or a tooling directive`,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return findings;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether `value` is a JSDoc block (`/** … *\/`), the only comment shape a symbol may carry.
|
|
108
|
+
*/
|
|
109
|
+
export function isJsdoc(value) {
|
|
110
|
+
return value.startsWith("/**");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Whether `value` is a shebang, a triple-slash reference, or a tooling directive the repository
|
|
114
|
+
* keeps as the only non-JSDoc comments.
|
|
115
|
+
*/
|
|
116
|
+
export function isToolingDirective(value) {
|
|
117
|
+
if (value.startsWith("#!"))
|
|
118
|
+
return true;
|
|
119
|
+
return TOOLING.test(value);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Findings inside one JSDoc block: a description longer than three prose lines, a banned
|
|
123
|
+
* `@description`, or a one-line tag that continues onto further lines.
|
|
124
|
+
*/
|
|
125
|
+
function inspectJsdoc(file, line, value) {
|
|
126
|
+
let blocks = splitBlocks(commentLines(value));
|
|
127
|
+
let findings = [];
|
|
128
|
+
let prose = (blocks[0] ?? []).filter((entry) => entry.trim() !== "");
|
|
129
|
+
if (prose.length > MAX_DESCRIPTION_LINES) {
|
|
130
|
+
findings.push({
|
|
131
|
+
file,
|
|
132
|
+
line,
|
|
133
|
+
message: `description has ${prose.length} lines; keep it to ${MAX_DESCRIPTION_LINES}`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
for (let tagLines of blocks.slice(1)) {
|
|
137
|
+
let first = tagLines[0] ?? "";
|
|
138
|
+
let match = /^@(\S+)/.exec(first);
|
|
139
|
+
let name = match?.[1] ?? "";
|
|
140
|
+
if (BANNED_TAGS.has(name)) {
|
|
141
|
+
findings.push({
|
|
142
|
+
file,
|
|
143
|
+
line,
|
|
144
|
+
message: `@${name} is not allowed; put the prose before the tags`,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (ONE_LINE_TAGS.has(name) && tagLines.slice(1).some((entry) => entry.trim() !== "")) {
|
|
148
|
+
findings.push({
|
|
149
|
+
file,
|
|
150
|
+
line,
|
|
151
|
+
message: `@${name} spans ${tagLines.filter((entry) => entry.trim() !== "").length} lines; keep it on one line`,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return findings;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Strip the comment markers and the per-line `*` gutter, keeping relative indentation that a
|
|
159
|
+
* fenced `@example` may need.
|
|
160
|
+
*/
|
|
161
|
+
function commentLines(raw) {
|
|
162
|
+
let text = raw.trim();
|
|
163
|
+
if (text.startsWith("/**"))
|
|
164
|
+
text = text.slice(3);
|
|
165
|
+
else if (text.startsWith("/*"))
|
|
166
|
+
text = text.slice(2);
|
|
167
|
+
if (text.endsWith("*/"))
|
|
168
|
+
text = text.slice(0, -2);
|
|
169
|
+
return text.split("\n").map((entry) => entry.replace(/^[ \t]*\*? ?/, "").trimEnd());
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Cut the lines at every block tag that starts a line outside a fenced code block, so the first
|
|
173
|
+
* group is the description and each later group is one tag.
|
|
174
|
+
*/
|
|
175
|
+
function splitBlocks(lines) {
|
|
176
|
+
let blocks = [[]];
|
|
177
|
+
let fence = null;
|
|
178
|
+
for (let line of lines) {
|
|
179
|
+
let fenced = /^\s*(```+|~~~+)/.exec(line);
|
|
180
|
+
if (fenced?.[1]) {
|
|
181
|
+
if (fence === null)
|
|
182
|
+
fence = fenced[1][0] ?? null;
|
|
183
|
+
else if (fenced[1].startsWith(fence))
|
|
184
|
+
fence = null;
|
|
185
|
+
}
|
|
186
|
+
if (fence === null && /^@\S/.test(line))
|
|
187
|
+
blocks.push([line]);
|
|
188
|
+
else
|
|
189
|
+
blocks.at(-1)?.push(line);
|
|
190
|
+
}
|
|
191
|
+
return blocks;
|
|
192
|
+
}
|
|
193
|
+
/** The 1-based line number of `offset` in `source`. */
|
|
194
|
+
function lineOf(source, offset) {
|
|
195
|
+
let line = 1;
|
|
196
|
+
for (let index = 0; index < offset; index++) {
|
|
197
|
+
if (source.charCodeAt(index) === 10)
|
|
198
|
+
line += 1;
|
|
199
|
+
}
|
|
200
|
+
return line;
|
|
201
|
+
}
|
package/dist/make/generate.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plans the files one `sdxc make` run writes: the file of the requested kind at the folder the
|
|
3
|
-
* layout gives it
|
|
4
|
-
* policy writes its test alone.
|
|
3
|
+
* layout gives it, when tests are on its test beside it, and when specs are on a pairing `.spec`
|
|
4
|
+
* under `spec/`, each rendered from its stub; a policy writes its test alone.
|
|
5
5
|
* Nothing is written while planning, and a file that already exists stops the plan unless the
|
|
6
6
|
* request replaces it.
|
|
7
7
|
*
|
|
@@ -23,10 +23,14 @@ export interface MakeRequest {
|
|
|
23
23
|
variant: string | null;
|
|
24
24
|
/** Whether to write a test beside the file. */
|
|
25
25
|
tests: boolean;
|
|
26
|
+
/** Whether to write a pairing `.spec` under `spec/` for kinds that support one. */
|
|
27
|
+
specs: boolean;
|
|
26
28
|
/** The migration chain, for `make migration`. */
|
|
27
29
|
chain?: string;
|
|
28
30
|
/** The route contract a controller is declared in, a module in `routes/`. */
|
|
29
31
|
routes: string;
|
|
32
|
+
/** The route pattern a controller answers, for the pairing `.spec`'s URL. */
|
|
33
|
+
url?: string;
|
|
30
34
|
/** Replace a file the plan would write that already exists, instead of stopping. */
|
|
31
35
|
replace?: boolean;
|
|
32
36
|
/** Plan the test alone, for a file that exists already. */
|
|
@@ -50,6 +54,11 @@ export interface Plan {
|
|
|
50
54
|
* @param overrides - Placeholder values a declaration decided, such as a job's reused group.
|
|
51
55
|
*/
|
|
52
56
|
export declare function plan(request: MakeRequest, root: string, config: Config, packageRoot: string, overrides?: Readonly<Record<string, string>>): Promise<Result<Plan, Error>>;
|
|
57
|
+
/**
|
|
58
|
+
* The pairing `.spec` path for `request`: controllers under `spec/`, commands under
|
|
59
|
+
* `spec/commands/`, MCP tools under `spec/mcp/`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function specPathOf(request: Pick<MakeRequest, "kind" | "name">): string;
|
|
53
62
|
/** Whether `path`, relative to `root`, exists. */
|
|
54
63
|
export declare function exists(root: string, path: string): Promise<boolean>;
|
|
55
64
|
/** The folder a kind's files go in; a migration's comes from its chain instead. */
|
package/dist/make/generate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plans the files one `sdxc make` run writes: the file of the requested kind at the folder the
|
|
3
|
-
* layout gives it
|
|
4
|
-
* policy writes its test alone.
|
|
3
|
+
* layout gives it, when tests are on its test beside it, and when specs are on a pairing `.spec`
|
|
4
|
+
* under `spec/`, each rendered from its stub; a policy writes its test alone.
|
|
5
5
|
* Nothing is written while planning, and a file that already exists stops the plan unless the
|
|
6
6
|
* request replaces it.
|
|
7
7
|
*
|
|
@@ -44,9 +44,18 @@ export async function plan(request, root, config, packageRoot, overrides = {}) {
|
|
|
44
44
|
}
|
|
45
45
|
let path = `${folder}/${file}${kind.extension}`;
|
|
46
46
|
let testPath = `${folder}/${file}.test${kind.extension}`;
|
|
47
|
+
let specPath = specPathOf(request);
|
|
47
48
|
let writesTest = kind.tests && (request.tests || request.testAlone === true);
|
|
49
|
+
let writesSpec = kind.specs === true &&
|
|
50
|
+
request.specs &&
|
|
51
|
+
request.testAlone !== true &&
|
|
52
|
+
request.variant !== "resource";
|
|
48
53
|
let writesMain = kind.testOnly !== true && request.testAlone !== true;
|
|
49
|
-
let paths = [
|
|
54
|
+
let paths = [
|
|
55
|
+
...(writesMain ? [path] : []),
|
|
56
|
+
...(writesTest ? [testPath] : []),
|
|
57
|
+
...(writesSpec ? [specPath] : []),
|
|
58
|
+
];
|
|
50
59
|
for (let candidate of paths) {
|
|
51
60
|
if (request.replace !== true && (await exists(root, candidate))) {
|
|
52
61
|
return failure(new Error(`${candidate} already exists; sdxc make leaves it as it is unless --force`));
|
|
@@ -56,19 +65,37 @@ export async function plan(request, root, config, packageRoot, overrides = {}) {
|
|
|
56
65
|
Object.assign(values, overrides);
|
|
57
66
|
let files = [];
|
|
58
67
|
if (writesMain) {
|
|
59
|
-
let main = await renderFile(request, values,
|
|
68
|
+
let main = await renderFile(request, values, "main", root, config, packageRoot);
|
|
60
69
|
if (isFailure(main))
|
|
61
70
|
return main;
|
|
62
71
|
files.push({ path, content: main.data });
|
|
63
72
|
}
|
|
64
73
|
if (writesTest) {
|
|
65
|
-
let test = await renderFile(request, values,
|
|
74
|
+
let test = await renderFile(request, values, "test", root, config, packageRoot);
|
|
66
75
|
if (isFailure(test))
|
|
67
76
|
return test;
|
|
68
77
|
files.push({ path: testPath, content: test.data });
|
|
69
78
|
}
|
|
79
|
+
if (writesSpec) {
|
|
80
|
+
let spec = await renderFile(request, values, "spec", root, config, packageRoot);
|
|
81
|
+
if (isFailure(spec))
|
|
82
|
+
return spec;
|
|
83
|
+
files.push({ path: specPath, content: spec.data });
|
|
84
|
+
}
|
|
70
85
|
return success({ files, values });
|
|
71
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* The pairing `.spec` path for `request`: controllers under `spec/`, commands under
|
|
89
|
+
* `spec/commands/`, MCP tools under `spec/mcp/`.
|
|
90
|
+
*/
|
|
91
|
+
export function specPathOf(request) {
|
|
92
|
+
let file = request.name.segments.join("/");
|
|
93
|
+
if (request.kind === "command")
|
|
94
|
+
return `spec/commands/${file}.spec`;
|
|
95
|
+
if (request.kind === "mcp")
|
|
96
|
+
return `spec/mcp/${file}.spec`;
|
|
97
|
+
return `spec/${file}.spec`;
|
|
98
|
+
}
|
|
72
99
|
/** Whether `path`, relative to `root`, exists. */
|
|
73
100
|
export async function exists(root, path) {
|
|
74
101
|
return isSuccess(await wrap(() => stat(join(root, path))));
|
|
@@ -78,23 +105,25 @@ export function folderOf(kind, variant) {
|
|
|
78
105
|
return kind === "mcp" && variant === "resource" ? MCP_RESOURCES_FOLDER : KINDS[kind].folder;
|
|
79
106
|
}
|
|
80
107
|
/**
|
|
81
|
-
* Renders the kind's stub, or its
|
|
82
|
-
* variant without its own
|
|
83
|
-
* contract's stub when one exists (`controller.api.stub`
|
|
84
|
-
*
|
|
108
|
+
* Renders the kind's stub, its test stub or its pairing `.spec` stub with `values`. A variant's
|
|
109
|
+
* own stub wins; a variant without its own companion stub uses the kind's. A controller with no
|
|
110
|
+
* variant takes its contract's stub when one exists (`controller.api.stub` /
|
|
111
|
+
* `controller.api.spec.stub` for `routes/api`), else the kind's, and a guarded one its contract's
|
|
112
|
+
* `resource` stub the same way.
|
|
85
113
|
*/
|
|
86
|
-
async function renderFile(request, values,
|
|
87
|
-
let
|
|
114
|
+
async function renderFile(request, values, role, root, config, packageRoot) {
|
|
115
|
+
let companion = role !== "main";
|
|
116
|
+
let names = [stubName(request.kind, request.variant, role)];
|
|
88
117
|
let contractual = request.variant === null || request.variant === "resource";
|
|
89
118
|
if (request.kind === "controller" && contractual) {
|
|
90
119
|
let variant = [request.routes, request.variant].filter((part) => part !== null).join(".");
|
|
91
|
-
names.unshift(stubName(request.kind, variant,
|
|
120
|
+
names.unshift(stubName(request.kind, variant, role));
|
|
92
121
|
}
|
|
93
|
-
if (request.kind === "controller" && request.variant?.startsWith("resource") &&
|
|
94
|
-
names.push(stubName(request.kind, request.routes,
|
|
122
|
+
if (request.kind === "controller" && request.variant?.startsWith("resource") && companion) {
|
|
123
|
+
names.push(stubName(request.kind, request.routes, role));
|
|
95
124
|
}
|
|
96
|
-
if (request.variant !== null &&
|
|
97
|
-
names.push(stubName(request.kind, null,
|
|
125
|
+
if (request.variant !== null && companion)
|
|
126
|
+
names.push(stubName(request.kind, null, role));
|
|
98
127
|
let stub = await loadStub(names, root, config.make.stubs, packageRoot);
|
|
99
128
|
if (isFailure(stub))
|
|
100
129
|
return stub;
|
|
@@ -125,6 +154,8 @@ async function placeholders(request, root, file) {
|
|
|
125
154
|
command: name.segments.join(" "),
|
|
126
155
|
member: memberAccess(name.segments),
|
|
127
156
|
words: name.segments.map((segment) => literal(segment)).join(", "),
|
|
157
|
+
args: name.segments.map((segment) => literal(segment)).join(" "),
|
|
158
|
+
url: request.url ?? `/${name.segments.join("/")}`,
|
|
128
159
|
table: pluralize(name.snake),
|
|
129
160
|
attributes: "",
|
|
130
161
|
ability: "",
|
package/dist/make/index.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface MakeInput {
|
|
|
20
20
|
name: string;
|
|
21
21
|
/** Whether to write a test beside the file; `undefined` takes `make.tests`. */
|
|
22
22
|
test: boolean | undefined;
|
|
23
|
+
/** Whether to write a pairing `.spec`; `undefined` takes `make.specs`. */
|
|
24
|
+
spec?: boolean | undefined;
|
|
23
25
|
dryRun: boolean;
|
|
24
26
|
/** `make job`: a scheduled job with this expression. */
|
|
25
27
|
cron?: string | undefined;
|
|
@@ -50,8 +52,8 @@ export interface MakeInput {
|
|
|
50
52
|
/** `make model`: the companions to leave out. */
|
|
51
53
|
skip?: readonly ModelCompanion[] | undefined;
|
|
52
54
|
/**
|
|
53
|
-
* Replace the file and its
|
|
54
|
-
* mapping and mount, and an existing model keeps its migrations.
|
|
55
|
+
* Replace the file, its test and its pairing `.spec` when they exist. A file that existed
|
|
56
|
+
* keeps its declaration, mapping and mount, and an existing model keeps its migrations.
|
|
55
57
|
*/
|
|
56
58
|
force?: boolean | undefined;
|
|
57
59
|
}
|
package/dist/make/index.js
CHANGED
|
@@ -101,8 +101,10 @@ export async function makeUnformatted(ctx, project, packageRoot, input) {
|
|
|
101
101
|
guarded: input.guardedBy !== undefined,
|
|
102
102
|
}),
|
|
103
103
|
tests: input.test ?? config.make.tests,
|
|
104
|
+
specs: input.spec ?? config.make.specs,
|
|
104
105
|
chain: input.chain,
|
|
105
106
|
routes: input.routes ?? config.make.routes,
|
|
107
|
+
url: pattern ?? `/${name.data.segments.join("/")}`,
|
|
106
108
|
replace: input.force === true,
|
|
107
109
|
};
|
|
108
110
|
let replacing = input.force === true && (await existsAlready(root, request));
|
|
@@ -337,6 +339,7 @@ async function modelCompanions(project, packageRoot, companion) {
|
|
|
337
339
|
name: name.data,
|
|
338
340
|
variant: null,
|
|
339
341
|
tests: false,
|
|
342
|
+
specs: false,
|
|
340
343
|
chain: companion.chain,
|
|
341
344
|
}, root, config, packageRoot);
|
|
342
345
|
if (isFailure(migration))
|
|
@@ -349,7 +352,7 @@ async function modelCompanions(project, packageRoot, companion) {
|
|
|
349
352
|
return source === null ? [] : [`\t${field.column}: ${source},`];
|
|
350
353
|
});
|
|
351
354
|
let attributes = values.length === 0 ? "" : `\n${values.join("\n")}\n`;
|
|
352
|
-
let factory = await plan({ ...request, kind: "factory", variant: null, tests: false }, root, config, packageRoot, { attributes });
|
|
355
|
+
let factory = await plan({ ...request, kind: "factory", variant: null, tests: false, specs: false }, root, config, packageRoot, { attributes });
|
|
353
356
|
if (isFailure(factory))
|
|
354
357
|
return factory;
|
|
355
358
|
let [file] = factory.data.files;
|
package/dist/make/kinds.d.ts
CHANGED
|
@@ -15,6 +15,11 @@ export interface Kind {
|
|
|
15
15
|
extension: ".ts" | ".tsx" | ".sql";
|
|
16
16
|
/** Whether `make.tests` writes a test beside the file. */
|
|
17
17
|
tests: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether `make.specs` writes a pairing `.spec` under `spec/` for black-box coverage of the
|
|
20
|
+
* generated surface (a page, an API route, a command or an MCP tool).
|
|
21
|
+
*/
|
|
22
|
+
specs?: boolean;
|
|
18
23
|
/**
|
|
19
24
|
* Whether the kind writes its test alone: a policy's abilities and grants are edits to the
|
|
20
25
|
* app's catalog and policy, so the only file it writes is the test that checks them.
|
package/dist/make/kinds.js
CHANGED
|
@@ -32,8 +32,18 @@ export const KINDS = {
|
|
|
32
32
|
folder: "app/http/controllers",
|
|
33
33
|
extension: ".tsx",
|
|
34
34
|
tests: true,
|
|
35
|
+
specs: true,
|
|
35
36
|
nested: true,
|
|
36
|
-
placeholders: [
|
|
37
|
+
placeholders: [
|
|
38
|
+
"path",
|
|
39
|
+
"routes",
|
|
40
|
+
"ability",
|
|
41
|
+
"access",
|
|
42
|
+
"pageAccess",
|
|
43
|
+
"params",
|
|
44
|
+
"sampleParams",
|
|
45
|
+
"url",
|
|
46
|
+
],
|
|
37
47
|
},
|
|
38
48
|
middleware: {
|
|
39
49
|
folder: "app/http/middleware",
|
|
@@ -113,6 +123,7 @@ export const KINDS = {
|
|
|
113
123
|
folder: "app/mcp/tools",
|
|
114
124
|
extension: ".ts",
|
|
115
125
|
tests: true,
|
|
126
|
+
specs: true,
|
|
116
127
|
nested: true,
|
|
117
128
|
placeholders: ["path", "tool", "uri"],
|
|
118
129
|
},
|
|
@@ -120,8 +131,9 @@ export const KINDS = {
|
|
|
120
131
|
folder: "app/commands",
|
|
121
132
|
extension: ".ts",
|
|
122
133
|
tests: true,
|
|
134
|
+
specs: true,
|
|
123
135
|
nested: true,
|
|
124
|
-
placeholders: ["command", "member", "words"],
|
|
136
|
+
placeholders: ["command", "member", "words", "args"],
|
|
125
137
|
},
|
|
126
138
|
};
|
|
127
139
|
/** What `make model` writes beside the model unless `--skip` names it. */
|
package/dist/make/stubs.d.ts
CHANGED
|
@@ -20,8 +20,13 @@ export interface CopiedStubs {
|
|
|
20
20
|
written: string[];
|
|
21
21
|
kept: string[];
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
export
|
|
23
|
+
/** Whether a stub is the main file, its Vitest sibling, or its pairing `.spec`. */
|
|
24
|
+
export type StubRole = "main" | "test" | "spec";
|
|
25
|
+
/**
|
|
26
|
+
* The stub file name for `kind`, its `variant` and `role`: `controller.api.spec.stub`,
|
|
27
|
+
* `command.test.stub`, `mcp.stub`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function stubName(kind: KindName, variant: string | null, role?: StubRole): string;
|
|
25
30
|
/** The folder of built-in stubs in the `@sdxc/kit` package at `packageRoot`. */
|
|
26
31
|
export declare function builtinStubsDir(packageRoot: string): string;
|
|
27
32
|
/**
|
package/dist/make/stubs.js
CHANGED
|
@@ -11,9 +11,14 @@ import { join } from "node:path";
|
|
|
11
11
|
import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
|
|
12
12
|
/** A placeholder as stubs spell it: `{{name}}`, spaces inside the braces allowed. */
|
|
13
13
|
const PLACEHOLDER = /\{\{\s*([A-Za-z]+)\s*\}\}/g;
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The stub file name for `kind`, its `variant` and `role`: `controller.api.spec.stub`,
|
|
16
|
+
* `command.test.stub`, `mcp.stub`.
|
|
17
|
+
*/
|
|
18
|
+
export function stubName(kind, variant, role = "main") {
|
|
19
|
+
return [kind, variant, role === "main" ? null : role, "stub"]
|
|
20
|
+
.filter((part) => part !== null)
|
|
21
|
+
.join(".");
|
|
17
22
|
}
|
|
18
23
|
/** The folder of built-in stubs in the `@sdxc/kit` package at `packageRoot`. */
|
|
19
24
|
export function builtinStubsDir(packageRoot) {
|
package/dist/make/test.js
CHANGED
package/dist/scaffold/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface ScaffoldInput {
|
|
|
23
23
|
api?: boolean;
|
|
24
24
|
/** Whether to write tests; `undefined` takes `make.tests`. */
|
|
25
25
|
test: boolean | undefined;
|
|
26
|
+
/** Whether to write one feature `.spec`; `undefined` takes `make.specs`. */
|
|
27
|
+
spec?: boolean | undefined;
|
|
26
28
|
dryRun: boolean;
|
|
27
29
|
/** The pieces to leave out, each one the project already has or does without. */
|
|
28
30
|
skip?: readonly ScaffoldPiece[];
|