@sdxc/kit 2026.10.24 → 2026.10.26
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 +28 -15
- package/changelog.jsonl +125 -4
- package/dist/architecture/graph.d.ts +16 -3
- package/dist/architecture/graph.js +37 -19
- package/dist/architecture/layers.d.ts +10 -3
- package/dist/architecture/layers.js +38 -9
- package/dist/commands/destroy.d.ts +1 -1
- package/dist/commands/make.d.ts +5 -5
- package/dist/commands/make.js +11 -8
- package/dist/commands/scaffold.d.ts +1 -1
- package/dist/contract.d.ts +3 -3
- package/dist/doctor/checks.d.ts +2 -2
- package/dist/doctor/checks.js +14 -2
- package/dist/doctor/constant-names.d.ts +17 -0
- package/dist/doctor/constant-names.js +106 -0
- package/dist/doctor/dependencies.d.ts +3 -3
- package/dist/doctor/dependencies.js +3 -3
- package/dist/doctor/fan-out.d.ts +3 -2
- package/dist/doctor/fan-out.js +4 -3
- package/dist/doctor/fetch-param.d.ts +15 -0
- package/dist/doctor/fetch-param.js +37 -0
- package/dist/doctor/files.d.ts +2 -0
- package/dist/doctor/files.js +4 -0
- package/dist/doctor/local-const.d.ts +15 -0
- package/dist/doctor/local-const.js +54 -0
- package/dist/doctor/logger.d.ts +15 -0
- package/dist/doctor/logger.js +41 -0
- package/dist/doctor/orphans.d.ts +3 -3
- package/dist/doctor/orphans.js +33 -7
- package/dist/doctor/process-env.d.ts +15 -0
- package/dist/doctor/process-env.js +39 -0
- package/dist/doctor/project.js +17 -13
- package/dist/doctor/result-throws.d.ts +5 -4
- package/dist/doctor/result-throws.js +6 -5
- package/dist/doctor/source-rule.d.ts +35 -0
- package/dist/doctor/source-rule.js +52 -0
- package/dist/doctor/stack-imports.d.ts +15 -0
- package/dist/doctor/stack-imports.js +60 -0
- package/dist/doctor/syntax.d.ts +31 -0
- package/dist/doctor/syntax.js +56 -0
- package/dist/make/binding.d.ts +13 -8
- package/dist/make/binding.js +96 -64
- package/dist/make/from-model.js +2 -7
- package/dist/make/index.js +2 -7
- package/dist/package-manager.d.ts +6 -0
- package/dist/package-manager.js +25 -2
- package/dist/scaffold/index.js +25 -19
- package/dist/ui/commands.js +2 -5
- package/dist/ui/registry.d.ts +2 -2
- package/dist/ui/registry.js +1 -1
- package/dist/upgrade/changelog.d.ts +2 -0
- package/dist/upgrade/changelog.js +2 -0
- package/dist/upgrade/project.d.ts +2 -2
- package/dist/upgrade/prompt.d.ts +3 -2
- package/dist/upgrade/prompt.js +43 -2
- package/package.json +5 -5
- package/registry/ui/youtube-embed.json +3 -3
- package/stubs/scaffold.test-mcp.stub +5 -1
- package/templates/app/AGENTS.md +3 -1
- package/templates/app/app/commands/db/fresh.ts +20 -13
- package/templates/app/app/commands/db/migrate.ts +42 -32
- package/templates/app/app/http/controllers/api/openapi.test.ts +29 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +8 -2
- package/templates/app/app/http/controllers/health.test.ts +35 -0
- package/templates/app/app/http/controllers/health.ts +16 -0
- package/templates/app/app/http/controllers/mcp.test.ts +16 -0
- package/templates/app/app/http/middleware/access.ts +6 -3
- package/templates/app/app/http/middleware/page.ts +3 -4
- package/templates/app/app/http/middleware/server-timing.test.ts +1 -1
- package/templates/app/app/initializers/database.test.ts +6 -1
- package/templates/app/app/initializers/health.ts +17 -0
- package/templates/app/app/initializers/openapi.ts +5 -4
- package/templates/app/app/initializers/router.test.ts +1 -1
- package/templates/app/app/initializers/router.tsx +5 -6
- package/templates/app/app/test/cloudflare-workers.test.ts +27 -0
- package/templates/app/app/test/cloudflare-workers.ts +17 -4
- package/templates/app/app/test/database.ts +33 -0
- package/templates/app/app/test/mcp.ts +96 -0
- package/templates/app/package.json +1 -0
- package/templates/app/resources/layouts/document.tsx +2 -3
- package/templates/app/routes/api.ts +17 -7
- package/templates/app/app/http/controllers/api/health.tsx +0 -15
|
@@ -14,6 +14,11 @@ export interface ImportEdge {
|
|
|
14
14
|
to: string;
|
|
15
15
|
/** The specifier as written in the source. */
|
|
16
16
|
specifier: string;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the import is a dynamic `import()`, which loads the target on first use: a
|
|
19
|
+
* `lazy()` mapping in a router, dispatcher or command line, or a load that breaks a cycle.
|
|
20
|
+
*/
|
|
21
|
+
deferred: boolean;
|
|
17
22
|
}
|
|
18
23
|
/** An edge between two layers, with how many module edges it aggregates. */
|
|
19
24
|
export interface LayerEdge {
|
|
@@ -29,11 +34,16 @@ export interface ProjectGraph {
|
|
|
29
34
|
modules: string[];
|
|
30
35
|
/** Relative and `~/` imports that resolve inside the project. */
|
|
31
36
|
edges: ImportEdge[];
|
|
37
|
+
/** Imports from the project's test files into its modules, which keep a test helper in use. */
|
|
38
|
+
testEdges: ImportEdge[];
|
|
32
39
|
/** Module edges rolled up by layer, for the architecture diagram. */
|
|
33
40
|
layers: LayerEdge[];
|
|
34
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Strongly connected components with more than one module, or a self-cycle, over static
|
|
43
|
+
* imports: a deferred import resolves after every module has loaded.
|
|
44
|
+
*/
|
|
35
45
|
cycles: string[][];
|
|
36
|
-
/**
|
|
46
|
+
/** Static module edges that point from an inner layer to an outer one. */
|
|
37
47
|
violations: ImportEdge[];
|
|
38
48
|
}
|
|
39
49
|
/**
|
|
@@ -41,7 +51,10 @@ export interface ProjectGraph {
|
|
|
41
51
|
* layout folders. Specifiers that leave the project (packages, absolute URLs) are ignored.
|
|
42
52
|
*/
|
|
43
53
|
export declare function projectGraph(root: string): Promise<ProjectGraph>;
|
|
44
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Rolls module edges into layer-to-layer counts. A deferred edge counts toward its pair and
|
|
56
|
+
* leaves it allowed, since a `lazy()` mapping is how an initializer reaches what it maps.
|
|
57
|
+
*/
|
|
45
58
|
export declare function aggregateLayers(edges: readonly ImportEdge[]): LayerEdge[];
|
|
46
59
|
/**
|
|
47
60
|
* Resolves `specifier` written in `file` to a project-relative path without extension, or
|
|
@@ -18,42 +18,58 @@ import { allowsDependency, layerOf } from "./layers.js";
|
|
|
18
18
|
*/
|
|
19
19
|
export async function projectGraph(root) {
|
|
20
20
|
let modules = [];
|
|
21
|
-
let
|
|
21
|
+
let tests = [];
|
|
22
22
|
let known = new Set();
|
|
23
23
|
for (let folder of PROJECT_FOLDERS) {
|
|
24
|
-
for (let file of
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
for (let file of await listFiles(root, folder)) {
|
|
25
|
+
if (isAppSource(file)) {
|
|
26
|
+
modules.push(file);
|
|
27
|
+
known.add(file);
|
|
28
|
+
known.add(withoutExtension(file));
|
|
29
|
+
}
|
|
30
|
+
else if (TEST_FILE.test(file)) {
|
|
31
|
+
tests.push(file);
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
|
|
35
|
+
let edges = await importEdges(root, modules, known);
|
|
36
|
+
let testEdges = await importEdges(root, tests, known);
|
|
37
|
+
let loaded = edges.filter((edge) => !edge.deferred);
|
|
38
|
+
return {
|
|
39
|
+
modules,
|
|
40
|
+
edges,
|
|
41
|
+
testEdges,
|
|
42
|
+
layers: aggregateLayers(edges),
|
|
43
|
+
cycles: findCycles(modules, loaded),
|
|
44
|
+
violations: loaded.filter((edge) => !allowsDependency(edge.from, edge.to)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Every import in `files` that resolves to a `known` module. */
|
|
48
|
+
async function importEdges(root, files, known) {
|
|
49
|
+
let edges = [];
|
|
50
|
+
for (let file of files) {
|
|
31
51
|
let source = await wrap(() => readFile(join(root, file), "utf8"));
|
|
32
52
|
if (isFailure(source))
|
|
33
53
|
continue;
|
|
34
54
|
let references = findModuleReferences(file, source.data);
|
|
35
55
|
if (isFailure(references))
|
|
36
56
|
continue;
|
|
37
|
-
for (let { specifier } of references.data) {
|
|
57
|
+
for (let { specifier, kind } of references.data) {
|
|
38
58
|
let target = resolveSpecifier(specifier, file);
|
|
39
59
|
if (target === null)
|
|
40
60
|
continue;
|
|
41
61
|
let resolved = resolveKnown(target, known);
|
|
42
62
|
if (resolved === null)
|
|
43
63
|
continue;
|
|
44
|
-
edges.push({ from: file, to: resolved, specifier });
|
|
64
|
+
edges.push({ from: file, to: resolved, specifier, deferred: kind === "dynamic" });
|
|
45
65
|
}
|
|
46
66
|
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
modules,
|
|
50
|
-
edges,
|
|
51
|
-
layers: aggregateLayers(edges),
|
|
52
|
-
cycles: findCycles(modules, edges),
|
|
53
|
-
violations,
|
|
54
|
-
};
|
|
67
|
+
return edges;
|
|
55
68
|
}
|
|
56
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Rolls module edges into layer-to-layer counts. A deferred edge counts toward its pair and
|
|
71
|
+
* leaves it allowed, since a `lazy()` mapping is how an initializer reaches what it maps.
|
|
72
|
+
*/
|
|
57
73
|
export function aggregateLayers(edges) {
|
|
58
74
|
let counts = new Map();
|
|
59
75
|
for (let edge of edges) {
|
|
@@ -65,7 +81,7 @@ export function aggregateLayers(edges) {
|
|
|
65
81
|
let existing = counts.get(key);
|
|
66
82
|
if (existing) {
|
|
67
83
|
existing.count += 1;
|
|
68
|
-
if (!allowsDependency(edge.from, edge.to))
|
|
84
|
+
if (!edge.deferred && !allowsDependency(edge.from, edge.to))
|
|
69
85
|
existing.allowed = false;
|
|
70
86
|
continue;
|
|
71
87
|
}
|
|
@@ -73,7 +89,7 @@ export function aggregateLayers(edges) {
|
|
|
73
89
|
from,
|
|
74
90
|
to,
|
|
75
91
|
count: 1,
|
|
76
|
-
allowed: allowsDependency(edge.from, edge.to),
|
|
92
|
+
allowed: edge.deferred || allowsDependency(edge.from, edge.to),
|
|
77
93
|
});
|
|
78
94
|
}
|
|
79
95
|
return [...counts.values()].sort((a, b) => a.from === b.from ? a.to.localeCompare(b.to) : a.from.localeCompare(b.from));
|
|
@@ -89,6 +105,8 @@ export function resolveSpecifier(specifier, file) {
|
|
|
89
105
|
return null;
|
|
90
106
|
return posix.normalize(posix.join(dirname(file).split("\\").join("/"), specifier));
|
|
91
107
|
}
|
|
108
|
+
/** A test file, whose imports keep a module in use without being part of the app's graph. */
|
|
109
|
+
const TEST_FILE = /\.test\.[cm]?[jt]sx?$/;
|
|
92
110
|
/** Matches a resolved specifier against known modules, trying common extensions. */
|
|
93
111
|
function resolveKnown(target, known) {
|
|
94
112
|
let candidates = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app-layout layers Clean Architecture's dependency rule maps onto: outer kinds may import
|
|
3
3
|
* inner ones, never the reverse, so a model never reaches a controller and a view never pulls a
|
|
4
|
-
* job.
|
|
4
|
+
* job. Route contracts and handler declarations are data every layer may read.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
* outside the rule so anyone may import them.
|
|
12
12
|
*/
|
|
13
13
|
export type Layer = "models" | "policies" | "services" | "initializers" | "http" | "jobs" | "mcp" | "emails" | "commands" | "resources" | "routes" | "bootstrap" | "test";
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Higher rank is more inward; an import may only reach a layer at this rank or higher. Route
|
|
16
|
+
* contracts are innermost, since controllers, views and the router all read them, and views sit
|
|
17
|
+
* between the handlers that render them and the instances they read.
|
|
18
|
+
*/
|
|
15
19
|
export declare const LAYER_RANK: Readonly<Record<Layer, number>>;
|
|
16
20
|
/** Display order for architecture diagrams, outer first. */
|
|
17
21
|
export declare const LAYER_ORDER: readonly Layer[];
|
|
@@ -24,6 +28,9 @@ export declare const LAYER_ORDER: readonly Layer[];
|
|
|
24
28
|
export declare function layerOf(path: string): Layer | null;
|
|
25
29
|
/**
|
|
26
30
|
* Whether an import from `from` to `to` obeys the dependency rule. Unranked endpoints are left
|
|
27
|
-
* alone so config and packages stay free to import
|
|
31
|
+
* alone so config and packages stay free to import, any layer reads a declaration module, and
|
|
32
|
+
* an initializer reads the middleware its router's global chain lists.
|
|
28
33
|
*/
|
|
29
34
|
export declare function allowsDependency(from: string, to: string): boolean;
|
|
35
|
+
/** Whether `path` is a module that declares a runtime's jobs, commands, emails or MCP handlers. */
|
|
36
|
+
export declare function isDeclaration(path: string): boolean;
|
|
@@ -1,43 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app-layout layers Clean Architecture's dependency rule maps onto: outer kinds may import
|
|
3
3
|
* inner ones, never the reverse, so a model never reaches a controller and a view never pulls a
|
|
4
|
-
* job.
|
|
4
|
+
* job. Route contracts and handler declarations are data every layer may read.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Higher rank is more inward; an import may only reach a layer at this rank or higher. Route
|
|
11
|
+
* contracts are innermost, since controllers, views and the router all read them, and views sit
|
|
12
|
+
* between the handlers that render them and the instances they read.
|
|
13
|
+
*/
|
|
10
14
|
export const LAYER_RANK = {
|
|
15
|
+
routes: 50,
|
|
11
16
|
models: 40,
|
|
12
17
|
policies: 30,
|
|
13
18
|
services: 30,
|
|
14
19
|
initializers: 30,
|
|
20
|
+
resources: 25,
|
|
15
21
|
http: 20,
|
|
16
22
|
jobs: 20,
|
|
17
23
|
mcp: 20,
|
|
18
24
|
emails: 20,
|
|
19
25
|
commands: 20,
|
|
20
26
|
test: 20,
|
|
21
|
-
resources: 10,
|
|
22
|
-
routes: 10,
|
|
23
27
|
bootstrap: 10,
|
|
24
28
|
};
|
|
25
29
|
/** Display order for architecture diagrams, outer first. */
|
|
26
30
|
export const LAYER_ORDER = [
|
|
27
31
|
"bootstrap",
|
|
28
|
-
"routes",
|
|
29
|
-
"resources",
|
|
30
32
|
"http",
|
|
31
33
|
"jobs",
|
|
32
34
|
"mcp",
|
|
33
35
|
"emails",
|
|
34
36
|
"commands",
|
|
35
37
|
"test",
|
|
38
|
+
"resources",
|
|
36
39
|
"initializers",
|
|
37
40
|
"services",
|
|
38
41
|
"policies",
|
|
39
42
|
"models",
|
|
43
|
+
"routes",
|
|
40
44
|
];
|
|
45
|
+
/**
|
|
46
|
+
* The modules that declare what a runtime offers: jobs, commands, emails, MCP tools and
|
|
47
|
+
* resources. Each holds names and schemas only, so the initializer that maps them and the
|
|
48
|
+
* handlers that enqueue or send through them both read it.
|
|
49
|
+
*/
|
|
50
|
+
const DECLARATIONS = new Set([
|
|
51
|
+
"app/jobs/index.ts",
|
|
52
|
+
"app/commands/index.ts",
|
|
53
|
+
"app/emails/index.ts",
|
|
54
|
+
"app/mcp/tools/index.ts",
|
|
55
|
+
"app/mcp/resources/index.ts",
|
|
56
|
+
]);
|
|
57
|
+
/** Where an app's own middleware lives, which the router initializer composes into its chain. */
|
|
58
|
+
const MIDDLEWARE = "app/http/middleware/";
|
|
41
59
|
/** Prefixes that assign a path to a layer, most specific first. */
|
|
42
60
|
const LAYER_PREFIXES = [
|
|
43
61
|
["app/http/", "http"],
|
|
@@ -61,7 +79,7 @@ const LAYER_PREFIXES = [
|
|
|
61
79
|
* @param path - Project-relative path with `/` separators.
|
|
62
80
|
*/
|
|
63
81
|
export function layerOf(path) {
|
|
64
|
-
let normalized = path
|
|
82
|
+
let normalized = normalize(path);
|
|
65
83
|
for (let [prefix, layer] of LAYER_PREFIXES) {
|
|
66
84
|
if (normalized === prefix.slice(0, -1) || normalized.startsWith(prefix))
|
|
67
85
|
return layer;
|
|
@@ -70,12 +88,23 @@ export function layerOf(path) {
|
|
|
70
88
|
}
|
|
71
89
|
/**
|
|
72
90
|
* Whether an import from `from` to `to` obeys the dependency rule. Unranked endpoints are left
|
|
73
|
-
* alone so config and packages stay free to import
|
|
91
|
+
* alone so config and packages stay free to import, any layer reads a declaration module, and
|
|
92
|
+
* an initializer reads the middleware its router's global chain lists.
|
|
74
93
|
*/
|
|
75
94
|
export function allowsDependency(from, to) {
|
|
76
95
|
let source = layerOf(from);
|
|
77
96
|
let target = layerOf(to);
|
|
78
|
-
if (source === null || target === null)
|
|
97
|
+
if (source === null || target === null || isDeclaration(to))
|
|
98
|
+
return true;
|
|
99
|
+
if (source === "initializers" && normalize(to).startsWith(MIDDLEWARE))
|
|
79
100
|
return true;
|
|
80
101
|
return LAYER_RANK[source] <= LAYER_RANK[target];
|
|
81
102
|
}
|
|
103
|
+
/** Whether `path` is a module that declares a runtime's jobs, commands, emails or MCP handlers. */
|
|
104
|
+
export function isDeclaration(path) {
|
|
105
|
+
return DECLARATIONS.has(normalize(path));
|
|
106
|
+
}
|
|
107
|
+
/** `path` with `/` separators. */
|
|
108
|
+
function normalize(path) {
|
|
109
|
+
return path.split("\\").join("/");
|
|
110
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** Removes what `sdxc make` wrote for one kind and name, after one confirmation. */
|
|
10
10
|
declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
|
|
11
|
-
readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "
|
|
11
|
+
readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "controller" | "middleware" | "validator" | "job" | "model" | "factory" | "service" | "initializer" | "mcp">;
|
|
12
12
|
readonly name: import("@sdxc/cli").Argument<string>;
|
|
13
13
|
}, {
|
|
14
14
|
readonly yes: import("@sdxc/cli").Flag<boolean>;
|
package/dist/commands/make.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const controller: import("@sdxc/cli").CommandAction<import("@sdxc
|
|
|
14
14
|
readonly path: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
15
15
|
readonly routes: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
16
16
|
readonly resource: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
17
|
-
readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "
|
|
17
|
+
readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "create" | "update" | "all" | "show" | "edit" | "destroy", false, true, false>;
|
|
18
18
|
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
19
19
|
readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
20
20
|
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
@@ -257,7 +257,7 @@ export declare const stubs: import("@sdxc/cli").CommandAction<import("@sdxc/cli"
|
|
|
257
257
|
value: string;
|
|
258
258
|
property: "packageRoot";
|
|
259
259
|
}>]>;
|
|
260
|
-
/** `sdxc make secret`. */
|
|
260
|
+
/** `sdxc make secret`, which declares the secret and lists it in `.env.example`. */
|
|
261
261
|
export declare const secret: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
|
|
262
262
|
readonly name: import("@sdxc/cli").Argument<string>;
|
|
263
263
|
}, {
|
|
@@ -272,7 +272,7 @@ export declare const secret: import("@sdxc/cli").CommandAction<import("@sdxc/cli
|
|
|
272
272
|
value: string;
|
|
273
273
|
property: "packageRoot";
|
|
274
274
|
}>]>;
|
|
275
|
-
/** `sdxc make binding`. */
|
|
275
|
+
/** `sdxc make binding`, which declares one `bindings.<kind>()` entry in the Worker's `env`. */
|
|
276
276
|
export declare const binding: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
|
|
277
277
|
readonly kind: import("@sdxc/cli").Argument<"secret" | "kv" | "d1" | "r2" | "queue" | "rateLimit" | "sendEmail" | "durableObject">;
|
|
278
278
|
readonly name: import("@sdxc/cli").Argument<string>;
|
|
@@ -288,7 +288,7 @@ export declare const binding: import("@sdxc/cli").CommandAction<import("@sdxc/cl
|
|
|
288
288
|
value: string;
|
|
289
289
|
property: "packageRoot";
|
|
290
290
|
}>]>;
|
|
291
|
-
/** `sdxc make do
|
|
291
|
+
/** `sdxc make do`, which writes a Durable Object class with its export and binding. */
|
|
292
292
|
export declare const durableObject: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
|
|
293
293
|
readonly name: import("@sdxc/cli").Argument<string>;
|
|
294
294
|
}, {
|
|
@@ -329,7 +329,7 @@ export declare const group: import("@sdxc/cli").CommandAction<import("@sdxc/cli"
|
|
|
329
329
|
readonly path: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
330
330
|
readonly routes: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
331
331
|
readonly resource: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
332
|
-
readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "
|
|
332
|
+
readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "create" | "update" | "all" | "show" | "edit" | "destroy", false, true, false>;
|
|
333
333
|
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
334
334
|
readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
335
335
|
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
package/dist/commands/make.js
CHANGED
|
@@ -11,7 +11,7 @@ import { isFailure } from "@sdxc/result";
|
|
|
11
11
|
import { METHODS, SDXC_COMMANDS } from "../contract.js";
|
|
12
12
|
import { makeActions } from "../make/actions.js";
|
|
13
13
|
import { makeBinding, makeDo, makeSecret } from "../make/binding.js";
|
|
14
|
-
import { make } from "../make/index.js";
|
|
14
|
+
import { finish, make } from "../make/index.js";
|
|
15
15
|
import { copyStubs } from "../make/stubs.js";
|
|
16
16
|
import { makeTest } from "../make/test.js";
|
|
17
17
|
import { packageRoot, project } from "../middleware.js";
|
|
@@ -233,9 +233,10 @@ export const stubs = createCommand(SDXC_COMMANDS.make.stubs, {
|
|
|
233
233
|
return success();
|
|
234
234
|
},
|
|
235
235
|
});
|
|
236
|
-
/** `sdxc make secret`. */
|
|
236
|
+
/** `sdxc make secret`, which declares the secret and lists it in `.env.example`. */
|
|
237
237
|
export const secret = createCommand(SDXC_COMMANDS.make.secret, {
|
|
238
238
|
middleware: MAKE_MIDDLEWARE,
|
|
239
|
+
/** Formats what it edited, as every kind does, then notes `sdxc run typegen`. */
|
|
239
240
|
async handler(ctx) {
|
|
240
241
|
let made = await makeSecret(ctx, ctx.project.root, {
|
|
241
242
|
name: ctx.arguments.name,
|
|
@@ -244,12 +245,13 @@ export const secret = createCommand(SDXC_COMMANDS.make.secret, {
|
|
|
244
245
|
});
|
|
245
246
|
if (isFailure(made))
|
|
246
247
|
return made;
|
|
247
|
-
return
|
|
248
|
+
return finish(ctx, ctx.project, made.data);
|
|
248
249
|
},
|
|
249
250
|
});
|
|
250
|
-
/** `sdxc make binding`. */
|
|
251
|
+
/** `sdxc make binding`, which declares one `bindings.<kind>()` entry in the Worker's `env`. */
|
|
251
252
|
export const binding = createCommand(SDXC_COMMANDS.make.binding, {
|
|
252
253
|
middleware: MAKE_MIDDLEWARE,
|
|
254
|
+
/** Formats what it edited, as every kind does, then notes `sdxc run typegen`. */
|
|
253
255
|
async handler(ctx) {
|
|
254
256
|
let made = await makeBinding(ctx, ctx.project.root, {
|
|
255
257
|
kind: ctx.arguments.kind,
|
|
@@ -259,14 +261,15 @@ export const binding = createCommand(SDXC_COMMANDS.make.binding, {
|
|
|
259
261
|
});
|
|
260
262
|
if (isFailure(made))
|
|
261
263
|
return made;
|
|
262
|
-
return
|
|
264
|
+
return finish(ctx, ctx.project, made.data);
|
|
263
265
|
},
|
|
264
266
|
});
|
|
265
|
-
/** `sdxc make do
|
|
267
|
+
/** `sdxc make do`, which writes a Durable Object class with its export and binding. */
|
|
266
268
|
export const durableObject = createCommand(SDXC_COMMANDS.make.do, {
|
|
267
269
|
middleware: MAKE_MIDDLEWARE,
|
|
270
|
+
/** Formats what it wrote and edited, as every kind does, then notes `sdxc run typegen`. */
|
|
268
271
|
async handler(ctx) {
|
|
269
|
-
let made = await makeDo(ctx, ctx.project.root,
|
|
272
|
+
let made = await makeDo(ctx, ctx.project.root, {
|
|
270
273
|
name: ctx.arguments.name,
|
|
271
274
|
role: ctx.flags.role,
|
|
272
275
|
binding: ctx.flags.binding,
|
|
@@ -275,7 +278,7 @@ export const durableObject = createCommand(SDXC_COMMANDS.make.do, {
|
|
|
275
278
|
});
|
|
276
279
|
if (isFailure(made))
|
|
277
280
|
return made;
|
|
278
|
-
return
|
|
281
|
+
return finish(ctx, ctx.project, made.data);
|
|
279
282
|
},
|
|
280
283
|
});
|
|
281
284
|
/**
|
|
@@ -14,7 +14,7 @@ declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Co
|
|
|
14
14
|
readonly mcp: import("@sdxc/cli").Flag<boolean>;
|
|
15
15
|
readonly command: import("@sdxc/cli").Flag<boolean>;
|
|
16
16
|
readonly api: import("@sdxc/cli").Flag<boolean>;
|
|
17
|
-
readonly skip: import("@sdxc/cli").ValueFlag<"
|
|
17
|
+
readonly skip: import("@sdxc/cli").ValueFlag<"validator" | "model" | "migration" | "factory" | "policy" | "pages", false, true, false>;
|
|
18
18
|
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
19
19
|
readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
20
20
|
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
package/dist/contract.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare const SDXC_COMMANDS: import("@sdxc/cli").Group<Omit<{
|
|
|
22
22
|
readonly skip: import("@sdxc/cli").ValueFlag<"build" | "migrate" | "deploy", false, true, false>;
|
|
23
23
|
}>;
|
|
24
24
|
readonly destroy: import("@sdxc/cli").Command<{
|
|
25
|
-
readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "
|
|
25
|
+
readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "controller" | "middleware" | "validator" | "job" | "model" | "factory" | "service" | "initializer" | "mcp">;
|
|
26
26
|
readonly name: import("@sdxc/cli").Argument<string>;
|
|
27
27
|
}, {
|
|
28
28
|
readonly yes: import("@sdxc/cli").Flag<boolean>;
|
|
@@ -76,7 +76,7 @@ export declare const SDXC_COMMANDS: import("@sdxc/cli").Group<Omit<{
|
|
|
76
76
|
readonly path: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
77
77
|
readonly routes: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
78
78
|
readonly resource: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
79
|
-
readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "
|
|
79
|
+
readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "create" | "update" | "all" | "show" | "edit" | "destroy", false, true, false>;
|
|
80
80
|
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
81
81
|
readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
82
82
|
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
@@ -247,7 +247,7 @@ export declare const SDXC_COMMANDS: import("@sdxc/cli").Group<Omit<{
|
|
|
247
247
|
readonly mcp: import("@sdxc/cli").Flag<boolean>;
|
|
248
248
|
readonly command: import("@sdxc/cli").Flag<boolean>;
|
|
249
249
|
readonly api: import("@sdxc/cli").Flag<boolean>;
|
|
250
|
-
readonly skip: import("@sdxc/cli").ValueFlag<"
|
|
250
|
+
readonly skip: import("@sdxc/cli").ValueFlag<"validator" | "model" | "migration" | "factory" | "policy" | "pages", false, true, false>;
|
|
251
251
|
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
252
252
|
readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
253
253
|
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
package/dist/doctor/checks.d.ts
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import type { Check, CheckReport } from "./check.js";
|
|
10
10
|
/**
|
|
11
11
|
* Every built-in check: release drift, the install and the `remix` peer first, then the
|
|
12
|
-
* Worker's secrets and types, then the app's own code, layout
|
|
13
|
-
* copied components.
|
|
12
|
+
* Worker's secrets and types, then the app's own code, layout, quality metrics and source
|
|
13
|
+
* conventions, then copied components.
|
|
14
14
|
*/
|
|
15
15
|
export declare const CHECKS: readonly Check[];
|
|
16
16
|
/** Whether any check failed, which makes `sdxc doctor` exit 1. */
|
package/dist/doctor/checks.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
9
|
import { complexityCheck } from "./complexity.js";
|
|
10
|
+
import { constantNamesCheck } from "./constant-names.js";
|
|
10
11
|
import { crapCheck } from "./crap.js";
|
|
11
12
|
import { dependenciesCheck } from "./dependencies.js";
|
|
12
13
|
import { duplicationCheck } from "./duplication.js";
|
|
@@ -14,25 +15,30 @@ import { emailsCheck } from "./emails.js";
|
|
|
14
15
|
import { envCheck } from "./env.js";
|
|
15
16
|
import { fanOutCheck } from "./fan-out.js";
|
|
16
17
|
import { featureScatterCheck } from "./feature-scatter.js";
|
|
18
|
+
import { fetchParamCheck } from "./fetch-param.js";
|
|
17
19
|
import { installedCheck } from "./installed.js";
|
|
18
20
|
import { jsdocCheck } from "./jsdoc.js";
|
|
19
21
|
import { layoutCheck } from "./layout.js";
|
|
22
|
+
import { localConstCheck } from "./local-const.js";
|
|
23
|
+
import { loggerCheck } from "./logger.js";
|
|
20
24
|
import { migrationsCheck } from "./migrations.js";
|
|
21
25
|
import { modelsCheck } from "./models.js";
|
|
22
26
|
import { moduleSizeCheck } from "./module-size.js";
|
|
23
27
|
import { mutationCheck } from "./mutation.js";
|
|
24
28
|
import { orphansCheck } from "./orphans.js";
|
|
25
29
|
import { pinsCheck } from "./pins.js";
|
|
30
|
+
import { processEnvCheck } from "./process-env.js";
|
|
26
31
|
import { remixCheck } from "./remix.js";
|
|
27
32
|
import { resultThrowsCheck } from "./result-throws.js";
|
|
28
33
|
import { routesCheck } from "./routes.js";
|
|
34
|
+
import { stackImportsCheck } from "./stack-imports.js";
|
|
29
35
|
import { testRatioCheck } from "./test-ratio.js";
|
|
30
36
|
import { typegenCheck } from "./typegen.js";
|
|
31
37
|
import { uiCheck } from "./ui.js";
|
|
32
38
|
/**
|
|
33
39
|
* Every built-in check: release drift, the install and the `remix` peer first, then the
|
|
34
|
-
* Worker's secrets and types, then the app's own code, layout
|
|
35
|
-
* copied components.
|
|
40
|
+
* Worker's secrets and types, then the app's own code, layout, quality metrics and source
|
|
41
|
+
* conventions, then copied components.
|
|
36
42
|
*/
|
|
37
43
|
export const CHECKS = [
|
|
38
44
|
pinsCheck,
|
|
@@ -54,6 +60,12 @@ export const CHECKS = [
|
|
|
54
60
|
featureScatterCheck,
|
|
55
61
|
duplicationCheck,
|
|
56
62
|
resultThrowsCheck,
|
|
63
|
+
localConstCheck,
|
|
64
|
+
constantNamesCheck,
|
|
65
|
+
stackImportsCheck,
|
|
66
|
+
processEnvCheck,
|
|
67
|
+
fetchParamCheck,
|
|
68
|
+
loggerCheck,
|
|
57
69
|
testRatioCheck,
|
|
58
70
|
crapCheck,
|
|
59
71
|
mutationCheck,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `constant-names` check: a module-level `const` holding a value is named in
|
|
3
|
+
* `UPPER_SNAKE_CASE`, so a reader tells a module's data from its functions at the use site.
|
|
4
|
+
* Exports are public names chosen for callers, and a call's result may be a service, so both are left out.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { SourceFinding, SourceRule } from "./source-rule.js";
|
|
10
|
+
/** Every non-exported module-level `const` whose value is a literal, named in another case. */
|
|
11
|
+
export declare const CONSTANT_NAMES_RULE: SourceRule;
|
|
12
|
+
/** Warns on each module-level constant value whose name is not `UPPER_SNAKE_CASE`. */
|
|
13
|
+
export declare const constantNamesCheck: import("./check.js").Check;
|
|
14
|
+
/** Each top-level, non-exported `const` in `source` holding a literal value under another case. */
|
|
15
|
+
export declare function findConstantNames(file: string, source: string): SourceFinding[];
|
|
16
|
+
/** `name` in `UPPER_SNAKE_CASE`: `maxRetries` is `MAX_RETRIES`. */
|
|
17
|
+
export declare function toUpperSnake(name: string): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `constant-names` check: a module-level `const` holding a value is named in
|
|
3
|
+
* `UPPER_SNAKE_CASE`, so a reader tells a module's data from its functions at the use site.
|
|
4
|
+
* Exports are public names chosen for callers, and a call's result may be a service, so both are left out.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { sourceCheck } from "./source-rule.js";
|
|
10
|
+
import { isNode, lineAt, parseModule } from "./syntax.js";
|
|
11
|
+
/** A name in `UPPER_SNAKE_CASE`. */
|
|
12
|
+
const UPPER_SNAKE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
13
|
+
/** Constructors whose instance is a value the module holds, as a literal is. */
|
|
14
|
+
const VALUE_CONSTRUCTORS = new Set(["Set", "Map", "WeakSet", "WeakMap", "RegExp", "URL", "Date"]);
|
|
15
|
+
/** Expressions that only annotate the value they wrap. */
|
|
16
|
+
const WRAPPERS = new Set(["TSAsExpression", "TSSatisfiesExpression", "ParenthesizedExpression"]);
|
|
17
|
+
/** Function expressions, which make a property a member function rather than data. */
|
|
18
|
+
const FUNCTIONS = new Set(["FunctionExpression", "ArrowFunctionExpression"]);
|
|
19
|
+
/** Every non-exported module-level `const` whose value is a literal, named in another case. */
|
|
20
|
+
export const CONSTANT_NAMES_RULE = {
|
|
21
|
+
name: "constant-names",
|
|
22
|
+
tests: true,
|
|
23
|
+
find: findConstantNames,
|
|
24
|
+
passed: "Every module-level constant value is named in UPPER_SNAKE_CASE",
|
|
25
|
+
noun: ["constant not in UPPER_SNAKE_CASE", "constants not in UPPER_SNAKE_CASE"],
|
|
26
|
+
fix: "Rename it in UPPER_SNAKE_CASE; functions and objects of functions keep camelCase",
|
|
27
|
+
};
|
|
28
|
+
/** Warns on each module-level constant value whose name is not `UPPER_SNAKE_CASE`. */
|
|
29
|
+
export const constantNamesCheck = sourceCheck(CONSTANT_NAMES_RULE);
|
|
30
|
+
/** Each top-level, non-exported `const` in `source` holding a literal value under another case. */
|
|
31
|
+
export function findConstantNames(file, source) {
|
|
32
|
+
let parsed = parseModule(file, source);
|
|
33
|
+
if (parsed === null)
|
|
34
|
+
return [];
|
|
35
|
+
let findings = [];
|
|
36
|
+
for (let statement of nodes(parsed.program.body)) {
|
|
37
|
+
if (statement.type !== "VariableDeclaration" || statement.kind !== "const")
|
|
38
|
+
continue;
|
|
39
|
+
if (statement.declare === true)
|
|
40
|
+
continue;
|
|
41
|
+
for (let declarator of nodes(statement.declarations)) {
|
|
42
|
+
let id = declarator.id;
|
|
43
|
+
if (!isNode(id) || id.type !== "Identifier" || typeof id.name !== "string")
|
|
44
|
+
continue;
|
|
45
|
+
if (UPPER_SNAKE.test(id.name) || !isValue(declarator.init))
|
|
46
|
+
continue;
|
|
47
|
+
findings.push({
|
|
48
|
+
line: lineAt(source, declarator.start),
|
|
49
|
+
message: `${id.name} holds a value; name it ${toUpperSnake(id.name)}`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return findings;
|
|
54
|
+
}
|
|
55
|
+
/** `name` in `UPPER_SNAKE_CASE`: `maxRetries` is `MAX_RETRIES`. */
|
|
56
|
+
export function toUpperSnake(name) {
|
|
57
|
+
return name
|
|
58
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
59
|
+
.replace(/[^A-Za-z0-9]+/g, "_")
|
|
60
|
+
.replace(/^_+|_+$/g, "")
|
|
61
|
+
.toUpperCase();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether `init` is data: a literal, template, array, object of non-function members, or a
|
|
65
|
+
* `Set`, `Map`, `RegExp`, `URL` or `Date` built in place.
|
|
66
|
+
*/
|
|
67
|
+
function isValue(init) {
|
|
68
|
+
let node = unwrap(init);
|
|
69
|
+
if (node === null)
|
|
70
|
+
return false;
|
|
71
|
+
switch (node.type) {
|
|
72
|
+
case "Literal":
|
|
73
|
+
case "TemplateLiteral":
|
|
74
|
+
case "ArrayExpression":
|
|
75
|
+
return true;
|
|
76
|
+
case "UnaryExpression":
|
|
77
|
+
return isNode(node.argument) && node.argument.type === "Literal";
|
|
78
|
+
case "ObjectExpression":
|
|
79
|
+
return nodes(node.properties).every(isDataMember);
|
|
80
|
+
case "NewExpression":
|
|
81
|
+
return isNode(node.callee) && VALUE_CONSTRUCTORS.has(String(node.callee.name));
|
|
82
|
+
default:
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** An object member that holds data: a spread, or a property whose value is not a function. */
|
|
87
|
+
function isDataMember(member) {
|
|
88
|
+
if (member.type === "SpreadElement")
|
|
89
|
+
return true;
|
|
90
|
+
if (member.type !== "Property" || member.method === true || member.kind !== "init")
|
|
91
|
+
return false;
|
|
92
|
+
let value = unwrap(member.value);
|
|
93
|
+
return value !== null && !FUNCTIONS.has(value.type);
|
|
94
|
+
}
|
|
95
|
+
/** `value` without the type assertions and parentheses around it. */
|
|
96
|
+
function unwrap(value) {
|
|
97
|
+
let node = isNode(value) ? value : null;
|
|
98
|
+
while (node !== null && WRAPPERS.has(node.type)) {
|
|
99
|
+
node = isNode(node.expression) ? node.expression : null;
|
|
100
|
+
}
|
|
101
|
+
return node;
|
|
102
|
+
}
|
|
103
|
+
/** The nodes in a list field of a node. */
|
|
104
|
+
function nodes(value) {
|
|
105
|
+
return Array.isArray(value) ? value.filter(isNode) : [];
|
|
106
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `dependencies` check: import cycles and Clean Architecture breaches against the
|
|
3
|
-
* layers
|
|
4
|
-
*
|
|
2
|
+
* The `dependencies` check: static import cycles and Clean Architecture breaches against the
|
|
3
|
+
* app-layout layers, so models stay inward of services and http. A `lazy()` mapping or another
|
|
4
|
+
* deferred `import()` loads after startup, so it closes no cycle and breaches no layer.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|