@sdxc/kit 2026.10.17 → 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 +397 -22
- package/changelog.jsonl +1171 -1092
- package/config.schema.json +53 -1
- package/dist/cli.js +12 -0
- package/dist/commands/deploy.d.ts +23 -0
- package/dist/commands/deploy.js +167 -0
- package/dist/commands/destroy.d.ts +22 -0
- package/dist/commands/destroy.js +92 -0
- package/dist/commands/doctor.d.ts +26 -0
- package/dist/commands/doctor.js +65 -0
- package/dist/commands/initializers.d.ts +16 -0
- package/dist/commands/initializers.js +23 -0
- package/dist/commands/make.d.ts +78 -6
- package/dist/commands/make.js +134 -20
- package/dist/commands/middleware.d.ts +16 -0
- package/dist/commands/middleware.js +21 -0
- package/dist/commands/models.d.ts +18 -0
- package/dist/commands/models.js +29 -0
- package/dist/commands/notes.d.ts +17 -0
- package/dist/commands/notes.js +27 -0
- package/dist/commands/routes.d.ts +25 -0
- package/dist/commands/routes.js +50 -0
- package/dist/commands/run.d.ts +16 -0
- package/dist/commands/run.js +32 -11
- package/dist/commands/scaffold.d.ts +30 -0
- package/dist/commands/scaffold.js +34 -0
- package/dist/commands/schedule.d.ts +16 -0
- package/dist/commands/schedule.js +21 -0
- package/dist/commands/stats.d.ts +16 -0
- package/dist/commands/stats.js +21 -0
- package/dist/commands/ui/update.d.ts +6 -3
- package/dist/commands/ui/update.js +24 -7
- package/dist/commands/upgrade.d.ts +3 -1
- package/dist/commands/upgrade.js +88 -23
- package/dist/config.d.ts +20 -0
- package/dist/config.js +32 -1
- package/dist/contract.d.ts +101 -3
- package/dist/contract.js +371 -26
- package/dist/create/templates.js +3 -2
- package/dist/dependencies.d.ts +5 -1
- package/dist/dependencies.js +16 -1
- package/dist/deploy/plan.d.ts +49 -0
- package/dist/deploy/plan.js +68 -0
- package/dist/destroy.d.ts +40 -0
- package/dist/destroy.js +317 -0
- package/dist/doctor/check.d.ts +71 -0
- package/dist/doctor/check.js +53 -0
- package/dist/doctor/checks.d.ts +23 -0
- package/dist/doctor/checks.js +70 -0
- package/dist/doctor/define.d.ts +59 -0
- package/dist/doctor/define.js +16 -0
- package/dist/doctor/emails.d.ts +18 -0
- package/dist/doctor/emails.js +243 -0
- package/dist/doctor/env.d.ts +26 -0
- package/dist/doctor/env.js +88 -0
- package/dist/doctor/files.d.ts +14 -0
- package/dist/doctor/files.js +34 -0
- package/dist/doctor/fixture.d.ts +23 -0
- package/dist/doctor/fixture.js +46 -0
- package/dist/doctor/install.d.ts +17 -0
- package/dist/doctor/install.js +37 -0
- package/dist/doctor/installed.d.ts +11 -0
- package/dist/doctor/installed.js +79 -0
- package/dist/doctor/jsdoc.d.ts +44 -0
- package/dist/doctor/jsdoc.js +201 -0
- package/dist/doctor/layout.d.ts +23 -0
- package/dist/doctor/layout.js +83 -0
- package/dist/doctor/migrations.d.ts +16 -0
- package/dist/doctor/migrations.js +96 -0
- package/dist/doctor/models.d.ts +13 -0
- package/dist/doctor/models.js +69 -0
- package/dist/doctor/pins.d.ts +15 -0
- package/dist/doctor/pins.js +79 -0
- package/dist/doctor/project.d.ts +58 -0
- package/dist/doctor/project.js +261 -0
- package/dist/doctor/remix.d.ts +14 -0
- package/dist/doctor/remix.js +44 -0
- package/dist/doctor/routes.d.ts +11 -0
- package/dist/doctor/routes.js +49 -0
- package/dist/doctor/typegen.d.ts +13 -0
- package/dist/doctor/typegen.js +57 -0
- package/dist/doctor/ui.d.ts +14 -0
- package/dist/doctor/ui.js +51 -0
- package/dist/initializers.d.ts +25 -0
- package/dist/initializers.js +89 -0
- package/dist/lock.d.ts +2 -2
- package/dist/make/actions.d.ts +23 -0
- package/dist/make/actions.js +82 -0
- package/dist/make/declare.d.ts +31 -3
- package/dist/make/declare.js +284 -9
- package/dist/make/email.d.ts +23 -0
- package/dist/make/email.js +111 -0
- package/dist/make/from-fields.d.ts +30 -0
- package/dist/make/from-fields.js +162 -0
- package/dist/make/from-model.d.ts +39 -0
- package/dist/make/from-model.js +161 -0
- package/dist/make/generate.d.ts +25 -5
- package/dist/make/generate.js +76 -22
- package/dist/make/guard.d.ts +35 -0
- package/dist/make/guard.js +73 -0
- package/dist/make/imports.d.ts +6 -0
- package/dist/make/imports.js +19 -0
- package/dist/make/index.d.ts +49 -4
- package/dist/make/index.js +290 -29
- package/dist/make/kinds.d.ts +34 -2
- package/dist/make/kinds.js +92 -8
- package/dist/make/mount.d.ts +25 -0
- package/dist/make/mount.js +135 -0
- package/dist/make/schema-diff.d.ts +58 -0
- package/dist/make/schema-diff.js +609 -0
- package/dist/make/schema.d.ts +76 -0
- package/dist/make/schema.js +206 -0
- package/dist/make/stubs.d.ts +14 -7
- package/dist/make/stubs.js +24 -8
- package/dist/make/test.d.ts +43 -0
- package/dist/make/test.js +150 -0
- package/dist/make/trigger.d.ts +31 -0
- package/dist/make/trigger.js +163 -0
- package/dist/models.d.ts +42 -0
- package/dist/models.js +149 -0
- package/dist/notes.d.ts +28 -0
- package/dist/notes.js +66 -0
- package/dist/reference.d.ts +27 -0
- package/dist/reference.js +103 -0
- package/dist/releases.d.ts +9 -0
- package/dist/releases.js +29 -8
- package/dist/routes/chains.d.ts +34 -0
- package/dist/routes/chains.js +95 -0
- package/dist/routes/filter.d.ts +53 -0
- package/dist/routes/filter.js +147 -0
- package/dist/routes/format.d.ts +23 -0
- package/dist/routes/format.js +123 -0
- package/dist/routes/helpers.d.ts +21 -0
- package/dist/routes/helpers.js +165 -0
- package/dist/routes/index.d.ts +56 -0
- package/dist/routes/index.js +167 -0
- package/dist/routes/modules.d.ts +116 -0
- package/dist/routes/modules.js +235 -0
- package/dist/routes/parse.d.ts +161 -0
- package/dist/routes/parse.js +621 -0
- package/dist/routes/routers.d.ts +69 -0
- package/dist/routes/routers.js +327 -0
- package/dist/scaffold/fields.d.ts +129 -0
- package/dist/scaffold/fields.js +421 -0
- package/dist/scaffold/index.d.ts +39 -0
- package/dist/scaffold/index.js +622 -0
- package/dist/scaffold/render.d.ts +61 -0
- package/dist/scaffold/render.js +417 -0
- package/dist/schedule.d.ts +45 -0
- package/dist/schedule.js +124 -0
- package/dist/stats.d.ts +37 -0
- package/dist/stats.js +126 -0
- package/dist/ui/commands.d.ts +10 -3
- package/dist/ui/commands.js +85 -15
- package/dist/ui/registry.d.ts +8 -8
- package/dist/upgrade/agents.d.ts +49 -0
- package/dist/upgrade/agents.js +110 -0
- package/dist/upgrade/changelog.d.ts +2 -2
- package/dist/upgrade/project.d.ts +4 -0
- package/dist/upgrade/project.js +11 -1
- package/dist/upgrade/prompt.d.ts +11 -0
- package/dist/upgrade/prompt.js +50 -7
- package/package.json +6 -4
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/attachment.json +2 -2
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/color-picker.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/file-trigger.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/message-scroller.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/resizable.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/shared-element.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.resource.stub +23 -0
- package/stubs/controller.api.spec.stub +15 -0
- package/stubs/controller.form.stub +2 -2
- package/stubs/controller.form.test.stub +2 -2
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/controller.spec.stub +15 -0
- package/stubs/email.stub +9 -14
- package/stubs/email.test.stub +9 -9
- package/stubs/factory.stub +1 -1
- package/stubs/mcp.spec.stub +16 -0
- package/stubs/model.stub +3 -3
- package/stubs/policy.test.stub +34 -8
- package/stubs/scaffold.api.create.stub +34 -0
- package/stubs/scaffold.api.create.test.stub +37 -0
- package/stubs/scaffold.api.destroy.stub +34 -0
- package/stubs/scaffold.api.destroy.test.stub +44 -0
- package/stubs/scaffold.api.index.stub +23 -0
- package/stubs/scaffold.api.index.test.stub +31 -0
- package/stubs/scaffold.api.show.stub +27 -0
- package/stubs/scaffold.api.show.test.stub +41 -0
- package/stubs/scaffold.api.update.stub +44 -0
- package/stubs/scaffold.api.update.test.stub +46 -0
- package/stubs/scaffold.command.create.stub +22 -0
- package/stubs/scaffold.command.create.test.stub +30 -0
- package/stubs/scaffold.command.delete.stub +20 -0
- package/stubs/scaffold.command.delete.test.stub +39 -0
- package/stubs/scaffold.command.list.stub +18 -0
- package/stubs/scaffold.command.list.test.stub +31 -0
- package/stubs/scaffold.command.show.stub +19 -0
- package/stubs/scaffold.command.show.test.stub +37 -0
- package/stubs/scaffold.controller.destroy.stub +35 -0
- package/stubs/scaffold.controller.destroy.test.stub +65 -0
- package/stubs/scaffold.controller.edit.stub +97 -0
- package/stubs/scaffold.controller.edit.test.stub +91 -0
- package/stubs/scaffold.controller.index.stub +55 -0
- package/stubs/scaffold.controller.index.test.stub +32 -0
- package/stubs/scaffold.controller.new.stub +70 -0
- package/stubs/scaffold.controller.new.test.stub +81 -0
- package/stubs/scaffold.controller.show.stub +59 -0
- package/stubs/scaffold.controller.show.test.stub +43 -0
- package/stubs/scaffold.factory.stub +16 -0
- package/stubs/scaffold.form.stub +75 -0
- package/stubs/scaffold.mcp.create.stub +24 -0
- package/stubs/scaffold.mcp.create.test.stub +36 -0
- package/stubs/scaffold.mcp.delete.stub +31 -0
- package/stubs/scaffold.mcp.delete.test.stub +43 -0
- package/stubs/scaffold.mcp.get.stub +21 -0
- package/stubs/scaffold.mcp.get.test.stub +31 -0
- package/stubs/scaffold.mcp.list.stub +23 -0
- package/stubs/scaffold.mcp.list.test.stub +25 -0
- package/stubs/scaffold.mcp.update.stub +37 -0
- package/stubs/scaffold.mcp.update.test.stub +40 -0
- package/stubs/scaffold.migration.stub +3 -0
- package/stubs/scaffold.model.stub +35 -0
- package/stubs/scaffold.model.test.stub +25 -0
- package/stubs/scaffold.spec.stub +7 -0
- package/stubs/scaffold.test-database.stub +33 -0
- package/stubs/scaffold.test-mcp.stub +92 -0
- package/stubs/scaffold.validator.stub +18 -0
- package/stubs/scaffold.validator.test.stub +26 -0
- package/templates/app/AGENTS.md +167 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +33 -15
- package/templates/app/app/commands/console.test.ts +26 -0
- package/templates/app/app/commands/console.ts +19 -0
- package/templates/app/app/commands/db/fresh.test.ts +57 -0
- package/templates/app/app/commands/db/fresh.ts +37 -0
- package/templates/app/app/commands/db/migrate.test.ts +17 -1
- package/templates/app/app/commands/db/migrate.ts +51 -18
- package/templates/app/app/commands/db/prepare.test.ts +39 -0
- package/templates/app/app/commands/db/prepare.ts +35 -0
- package/templates/app/app/commands/db/seed.test.ts +38 -0
- package/templates/app/app/commands/db/seed.ts +26 -0
- package/templates/app/app/commands/deploy.test.ts +34 -0
- package/templates/app/app/commands/deploy.ts +18 -0
- package/templates/app/app/commands/emails/preview.test.tsx +63 -0
- package/templates/app/app/commands/emails/preview.ts +24 -0
- package/templates/app/app/commands/index.ts +57 -2
- package/templates/app/app/commands/typegen.test.ts +20 -1
- package/templates/app/app/commands/typegen.ts +16 -2
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/middleware/access.test.ts +43 -0
- package/templates/app/app/http/middleware/access.ts +41 -0
- package/templates/app/app/http/middleware/api.ts +12 -3
- package/templates/app/app/http/middleware/page.test.ts +4 -1
- package/templates/app/app/http/middleware/page.ts +7 -5
- package/templates/app/app/initializers/cli.ts +35 -2
- package/templates/app/app/initializers/dispatcher.ts +9 -1
- package/templates/app/app/initializers/mail-transport.test.ts +33 -0
- package/templates/app/app/initializers/mail-transport.ts +26 -0
- package/templates/app/app/initializers/mail.test.ts +17 -17
- package/templates/app/app/initializers/mail.ts +15 -7
- package/templates/app/app/initializers/router.test.ts +7 -0
- package/templates/app/app/initializers/router.tsx +13 -3
- package/templates/app/app/jobs/email.test.tsx +70 -0
- package/templates/app/app/jobs/email.ts +16 -0
- package/templates/app/app/jobs/index.ts +6 -2
- package/templates/app/app/policies/abilities.ts +13 -0
- package/templates/app/app/policies/policy.test.ts +15 -0
- package/templates/app/app/policies/policy.ts +30 -0
- package/templates/app/app/services/commands.ts +30 -0
- package/templates/app/app/services/migrations.test.ts +48 -1
- package/templates/app/app/services/migrations.ts +66 -9
- package/templates/app/app/test/cloudflare-workers.ts +2 -0
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/cloudflare.config.ts +3 -3
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +3 -1
- package/templates/app/spec/config.jsonc +16 -0
- package/stubs/policy.stub +0 -16
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a router initializer: the global middleware of each `createRouter()`, and every
|
|
3
|
+
* `router.map(target, handler)` with the controller its handler loads, the guards `lazy()`
|
|
4
|
+
* runs first and the middleware the controller declares for each action.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** The longest middleware expression shown whole; longer calls show as `callee(…)`. */
|
|
10
|
+
const NAME_LIMIT = 40;
|
|
11
|
+
/**
|
|
12
|
+
* A dynamic `import()` in an inline handler's source, which defers the module it loads to the
|
|
13
|
+
* first request the way `lazy()` does.
|
|
14
|
+
*/
|
|
15
|
+
const DYNAMIC_IMPORT = /\bimport\s*\(/;
|
|
16
|
+
/** The specifiers `createRouter` is imported from. */
|
|
17
|
+
const ROUTER_MODULES = new Set(["remix/router", "remix/fetch-router", "@remix-run/fetch-router"]);
|
|
18
|
+
/** The routers `module` creates, in source order. */
|
|
19
|
+
export async function readRouters(project, module) {
|
|
20
|
+
let factories = [...module.imports]
|
|
21
|
+
.filter(([, imported]) => imported.imported === "createRouter" && ROUTER_MODULES.has(imported.specifier))
|
|
22
|
+
.map(([local]) => local);
|
|
23
|
+
if (factories.length === 0)
|
|
24
|
+
return [];
|
|
25
|
+
let reader = module.reader;
|
|
26
|
+
let routers = [];
|
|
27
|
+
for (let index = 0; index < reader.tokens.length; index += 1) {
|
|
28
|
+
let token = reader.tokens[index];
|
|
29
|
+
if (token?.type !== "identifier" || !factories.includes(token.value))
|
|
30
|
+
continue;
|
|
31
|
+
if (reader.is(index - 1, ".") || reader.isWord(index - 1, "import"))
|
|
32
|
+
continue;
|
|
33
|
+
let call = reader.expression(index, reader.tokens.length).node;
|
|
34
|
+
if (call.kind !== "call")
|
|
35
|
+
continue;
|
|
36
|
+
let instance = instanceName(module, index);
|
|
37
|
+
let options = call.args[0]?.node;
|
|
38
|
+
let middleware = options?.kind === "object" ? property(options, "middleware") : undefined;
|
|
39
|
+
routers.push({
|
|
40
|
+
file: module.path,
|
|
41
|
+
middleware: middleware === undefined ? [] : await middlewareList(project, module, middleware),
|
|
42
|
+
mappings: instance === null ? [] : await readMappings(project, module, instance),
|
|
43
|
+
});
|
|
44
|
+
if (instance === null) {
|
|
45
|
+
project.diagnostics.push(`${module.path}: the router createRouter() builds is not assigned to a name`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return routers;
|
|
49
|
+
}
|
|
50
|
+
/** The name the `createRouter` call at `index` is assigned to: `let router = createRouter(…)`. */
|
|
51
|
+
function instanceName(module, index) {
|
|
52
|
+
let reader = module.reader;
|
|
53
|
+
if (!reader.is(index - 1, "="))
|
|
54
|
+
return null;
|
|
55
|
+
for (let back = index - 2; back >= Math.max(0, index - 30); back -= 1) {
|
|
56
|
+
if (["const", "let", "var"].some((word) => reader.isWord(back, word))) {
|
|
57
|
+
let name = reader.tokens[back + 1];
|
|
58
|
+
return name?.type === "identifier" ? name.value : null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/** Every `<instance>.map(target, handler)` call in `module`. */
|
|
64
|
+
async function readMappings(project, module, instance) {
|
|
65
|
+
let reader = module.reader;
|
|
66
|
+
let mappings = [];
|
|
67
|
+
for (let index = 0; index < reader.tokens.length; index += 1) {
|
|
68
|
+
if (!reader.isWord(index, instance) || reader.is(index - 1, "."))
|
|
69
|
+
continue;
|
|
70
|
+
if (!reader.is(index + 1, ".") ||
|
|
71
|
+
!reader.isWord(index + 2, "map") ||
|
|
72
|
+
!reader.is(index + 3, "(")) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let call = reader.expression(index, reader.tokens.length).node;
|
|
76
|
+
if (call.kind !== "call")
|
|
77
|
+
continue;
|
|
78
|
+
let [target, handler] = call.args;
|
|
79
|
+
if (target === undefined || handler === undefined)
|
|
80
|
+
continue;
|
|
81
|
+
mappings.push({
|
|
82
|
+
target: await project.evaluate(target.node, module),
|
|
83
|
+
handler: await mappedHandler(project, module, handler.node, 0),
|
|
84
|
+
text: reader.text(target.node),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return mappings;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Follows a mapping's handler: `lazy(() => import(…))` with its guards, an imported controller,
|
|
91
|
+
* a local helper that returns one, or an inline controller object.
|
|
92
|
+
*/
|
|
93
|
+
async function mappedHandler(project, module, node, depth) {
|
|
94
|
+
let text = module.reader.text(node);
|
|
95
|
+
let unresolved = {
|
|
96
|
+
text,
|
|
97
|
+
eager: [],
|
|
98
|
+
forAction: async () => ({
|
|
99
|
+
controller: { file: null, export: null },
|
|
100
|
+
guards: [],
|
|
101
|
+
middleware: [],
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
if (depth > 4)
|
|
105
|
+
return unresolved;
|
|
106
|
+
if (node.kind === "call" && node.callee.kind === "identifier") {
|
|
107
|
+
let binding = await project.bind(module, node.callee.name);
|
|
108
|
+
if (binding.kind === "import" && binding.imported === "lazy") {
|
|
109
|
+
return lazyHandler(project, module, node, text);
|
|
110
|
+
}
|
|
111
|
+
if (binding.kind === "local" &&
|
|
112
|
+
binding.node.kind === "function" &&
|
|
113
|
+
binding.node.body !== null) {
|
|
114
|
+
let inner = await mappedHandler(project, module, binding.node.body, depth + 1);
|
|
115
|
+
return { ...inner, text };
|
|
116
|
+
}
|
|
117
|
+
return unresolved;
|
|
118
|
+
}
|
|
119
|
+
if (node.kind === "identifier") {
|
|
120
|
+
let binding = await project.bind(module, node.name);
|
|
121
|
+
if (binding.kind === "local") {
|
|
122
|
+
let inner = await mappedHandler(project, module, binding.node, depth + 1);
|
|
123
|
+
return { ...inner, text };
|
|
124
|
+
}
|
|
125
|
+
if (binding.kind === "import" && binding.file !== null) {
|
|
126
|
+
let controller = { file: binding.file, export: binding.imported };
|
|
127
|
+
let chain = await controllerChain(project, controller);
|
|
128
|
+
return {
|
|
129
|
+
text,
|
|
130
|
+
eager: [[]],
|
|
131
|
+
forAction: async (path) => ({ controller, guards: [], middleware: chainFor(chain, path) }),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return unresolved;
|
|
135
|
+
}
|
|
136
|
+
if (node.kind === "object") {
|
|
137
|
+
let chain = await inlineChain(project, module, node);
|
|
138
|
+
let actions = property(node, "actions");
|
|
139
|
+
let ownHandler = property(node, "handler");
|
|
140
|
+
let actionHandlers = new Map();
|
|
141
|
+
let eager = [];
|
|
142
|
+
if (actions?.kind === "object") {
|
|
143
|
+
for (let entry of actions.entries) {
|
|
144
|
+
if ("spread" in entry)
|
|
145
|
+
continue;
|
|
146
|
+
let action = await mappedHandler(project, module, entry.value, depth + 1);
|
|
147
|
+
eager.push(...action.eager.map((path) => [entry.key, ...path]));
|
|
148
|
+
if (entry.value.kind !== "object")
|
|
149
|
+
actionHandlers.set(entry.key, action);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else if (ownHandler !== undefined) {
|
|
153
|
+
eager = (await mappedHandler(project, module, ownHandler, depth + 1)).eager;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
eager = [[]];
|
|
157
|
+
}
|
|
158
|
+
let inline = { file: module.path, export: null };
|
|
159
|
+
return {
|
|
160
|
+
text,
|
|
161
|
+
eager,
|
|
162
|
+
forAction: async (path) => {
|
|
163
|
+
let action = path[0] === undefined ? undefined : actionHandlers.get(path[0]);
|
|
164
|
+
if (action !== undefined) {
|
|
165
|
+
let handler = await action.forAction(path.slice(1));
|
|
166
|
+
return { ...handler, middleware: [...chain.middleware, ...handler.middleware] };
|
|
167
|
+
}
|
|
168
|
+
return { controller: inline, guards: [], middleware: chainFor(chain, path) };
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (node.kind === "function") {
|
|
173
|
+
let inline = { file: module.path, export: null };
|
|
174
|
+
return {
|
|
175
|
+
text,
|
|
176
|
+
eager: DYNAMIC_IMPORT.test(text) ? [] : [[]],
|
|
177
|
+
forAction: async () => ({ controller: inline, guards: [], middleware: [] }),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return unresolved;
|
|
181
|
+
}
|
|
182
|
+
/** A `lazy(load, guards?)` mapping: the module `load` imports, the export it picks, the guards. */
|
|
183
|
+
async function lazyHandler(project, module, call, text) {
|
|
184
|
+
let [load, guards] = call.args;
|
|
185
|
+
let loaded = load?.node.kind === "function" ? await loadedModule(project, module, load.node) : null;
|
|
186
|
+
let controller = loaded ?? { file: null, export: null };
|
|
187
|
+
let guardList = guards === undefined ? [] : await middlewareList(project, module, guards.node);
|
|
188
|
+
let chain = controller.file === null ? null : await controllerChain(project, controller);
|
|
189
|
+
return {
|
|
190
|
+
text,
|
|
191
|
+
eager: [],
|
|
192
|
+
forAction: async (path) => ({
|
|
193
|
+
controller,
|
|
194
|
+
guards: guardList,
|
|
195
|
+
middleware: chainFor(chain, path),
|
|
196
|
+
}),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* The file and export a `lazy()` loader imports: `() => import("…")` is the default export, and
|
|
201
|
+
* `.then((it) => it.name)` or `.then((it) => it.name(…))` picks `name`.
|
|
202
|
+
*/
|
|
203
|
+
async function loadedModule(project, module, loader) {
|
|
204
|
+
let body = loader.body;
|
|
205
|
+
let picked = "default";
|
|
206
|
+
if (body?.kind === "call" && body.callee.kind === "member" && body.callee.property === "then") {
|
|
207
|
+
let pick = body.args[0]?.node;
|
|
208
|
+
let selected = pick?.kind === "function" ? pick.body : null;
|
|
209
|
+
if (selected?.kind === "call")
|
|
210
|
+
selected = selected.callee;
|
|
211
|
+
picked = selected?.kind === "member" ? selected.property : null;
|
|
212
|
+
body = body.callee.object;
|
|
213
|
+
}
|
|
214
|
+
if (body?.kind !== "import")
|
|
215
|
+
return null;
|
|
216
|
+
let file = await project.resolve(module.path, body.specifier);
|
|
217
|
+
if (file === null) {
|
|
218
|
+
project.diagnostics.push(`${module.path}: ${body.specifier} does not resolve to a project file`);
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
return { file, export: picked };
|
|
222
|
+
}
|
|
223
|
+
/** The middleware the controller `ref` declares, read from its file; empty when it cannot be read. */
|
|
224
|
+
async function controllerChain(project, ref) {
|
|
225
|
+
if (ref.file === null || ref.export === null)
|
|
226
|
+
return null;
|
|
227
|
+
let module = await project.load(ref.file);
|
|
228
|
+
if (module === null)
|
|
229
|
+
return null;
|
|
230
|
+
let found = await project.exported(module, ref.export);
|
|
231
|
+
if (found === null)
|
|
232
|
+
return null;
|
|
233
|
+
let node = found.node;
|
|
234
|
+
if (node.kind === "identifier") {
|
|
235
|
+
let binding = await project.bind(found.module, node.name);
|
|
236
|
+
if (binding.kind !== "local")
|
|
237
|
+
return null;
|
|
238
|
+
node = binding.node;
|
|
239
|
+
}
|
|
240
|
+
if (node.kind === "object")
|
|
241
|
+
return inlineChain(project, found.module, node);
|
|
242
|
+
if (node.kind !== "call")
|
|
243
|
+
return null;
|
|
244
|
+
let options = [...node.args].reverse().find((argument) => argument.node.kind === "object")?.node;
|
|
245
|
+
return options?.kind === "object" ? inlineChain(project, found.module, options) : null;
|
|
246
|
+
}
|
|
247
|
+
/** The `middleware` of a controller or action object, and of each action under `actions`. */
|
|
248
|
+
async function inlineChain(project, module, node) {
|
|
249
|
+
let middleware = property(node, "middleware");
|
|
250
|
+
let actions = new Map();
|
|
251
|
+
let declared = property(node, "actions");
|
|
252
|
+
if (declared?.kind === "object") {
|
|
253
|
+
for (let entry of declared.entries) {
|
|
254
|
+
if ("spread" in entry || entry.value.kind !== "object")
|
|
255
|
+
continue;
|
|
256
|
+
actions.set(entry.key, await inlineChain(project, module, entry.value));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
middleware: middleware === undefined ? [] : await middlewareList(project, module, middleware),
|
|
261
|
+
actions,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** The chain for the action at `path`: the controller's own, then each nested action's. */
|
|
265
|
+
function chainFor(chain, path) {
|
|
266
|
+
if (chain === null)
|
|
267
|
+
return [];
|
|
268
|
+
let entries = [...chain.middleware];
|
|
269
|
+
let current = chain;
|
|
270
|
+
for (let key of path) {
|
|
271
|
+
current = current?.actions.get(key);
|
|
272
|
+
if (current === undefined)
|
|
273
|
+
break;
|
|
274
|
+
entries.push(...current.middleware);
|
|
275
|
+
}
|
|
276
|
+
return entries;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The middleware an expression lists. Arrays are read element by element, and an array held
|
|
280
|
+
* in a top-level variable (`CMS_GUARDS`), directly or spread, is expanded to what it holds.
|
|
281
|
+
*/
|
|
282
|
+
export async function middlewareList(project, module, node, seen = new Set()) {
|
|
283
|
+
if (node.kind === "array") {
|
|
284
|
+
let entries = [];
|
|
285
|
+
for (let element of node.elements) {
|
|
286
|
+
if (element.spread)
|
|
287
|
+
entries.push(...(await middlewareList(project, module, element.node, seen)));
|
|
288
|
+
else
|
|
289
|
+
entries.push(await middlewareEntry(project, module, element.node));
|
|
290
|
+
}
|
|
291
|
+
return entries;
|
|
292
|
+
}
|
|
293
|
+
if (node.kind === "identifier" && !seen.has(node.name)) {
|
|
294
|
+
let binding = await project.bind(module, node.name);
|
|
295
|
+
if (binding.kind === "local" && binding.node.kind === "array") {
|
|
296
|
+
return middlewareList(project, module, binding.node, new Set([...seen, node.name]));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return [await middlewareEntry(project, module, node)];
|
|
300
|
+
}
|
|
301
|
+
/** One middleware: its expression as written and the module its name comes from. */
|
|
302
|
+
async function middlewareEntry(project, module, node) {
|
|
303
|
+
let text = module.reader.text(node);
|
|
304
|
+
let name = node.kind === "function"
|
|
305
|
+
? "(inline)"
|
|
306
|
+
: text.length > NAME_LIMIT && node.kind === "call"
|
|
307
|
+
? `${module.reader.text(node.callee)}(…)`
|
|
308
|
+
: text;
|
|
309
|
+
let root = node;
|
|
310
|
+
while (root.kind === "call" || root.kind === "member") {
|
|
311
|
+
root = root.kind === "call" ? root.callee : root.object;
|
|
312
|
+
}
|
|
313
|
+
let from = null;
|
|
314
|
+
if (root.kind === "identifier") {
|
|
315
|
+
let binding = await project.bind(module, root.name);
|
|
316
|
+
if (binding.kind === "import")
|
|
317
|
+
from = binding.file ?? binding.specifier;
|
|
318
|
+
}
|
|
319
|
+
return { name, from };
|
|
320
|
+
}
|
|
321
|
+
/** The value of `key` in an object literal, or `undefined`. */
|
|
322
|
+
function property(node, key) {
|
|
323
|
+
for (let entry of node.entries)
|
|
324
|
+
if (!("spread" in entry) && entry.key === key)
|
|
325
|
+
return entry.value;
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fields `sdxc scaffold` and `sdxc make model` take as `name`, `name:type` or `name?`, with
|
|
3
|
+
* an `:index` or `:unique` modifier, the type a bare name takes by convention, and what each type becomes in the layers that read it as
|
|
4
|
+
* data: the table column, the form and tool schemas, and the samples a test fills it with.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Result } from "@sdxc/result";
|
|
10
|
+
import type { AnyTable, ColumnBuilder, ColumnNamespace } from "remix/data-table";
|
|
11
|
+
/** A field type `sdxc scaffold` and `sdxc make model` know. */
|
|
12
|
+
export type FieldTypeName = "string" | "text" | "integer" | "boolean" | "date" | "timestamp" | "email" | "url" | "references";
|
|
13
|
+
/** The row a reference points at: its model, its table and the type of its `id`. */
|
|
14
|
+
export interface Reference {
|
|
15
|
+
/** The referenced model's kebab-case name, as `sdxc make model` names its file. */
|
|
16
|
+
model: string;
|
|
17
|
+
table: string;
|
|
18
|
+
/** `text` for the UUIDv7 ids models create, `integer` for a table keyed by a number. */
|
|
19
|
+
key: "text" | "integer";
|
|
20
|
+
}
|
|
21
|
+
/** One parsed field. */
|
|
22
|
+
export interface Field {
|
|
23
|
+
/** The column's snake_case name, which is also the form field's and the row's key. */
|
|
24
|
+
column: string;
|
|
25
|
+
/** The column as words, the first capitalized: `published_on` reads `Published on`. */
|
|
26
|
+
label: string;
|
|
27
|
+
/** The command flag's kebab-case name. */
|
|
28
|
+
flag: string;
|
|
29
|
+
/** The command flag's camelCase key. */
|
|
30
|
+
key: string;
|
|
31
|
+
type: FieldTypeName;
|
|
32
|
+
/** A trailing `?` makes the column nullable, and its form control and command flag optional. */
|
|
33
|
+
nullable: boolean;
|
|
34
|
+
/** Set on a `references` field only. */
|
|
35
|
+
reference?: Reference;
|
|
36
|
+
/**
|
|
37
|
+
* `:index` adds an index to the table's migration; `:unique` makes the column unique, which
|
|
38
|
+
* the model declares and the migration enforces with a unique index.
|
|
39
|
+
*/
|
|
40
|
+
index: FieldModifier | null;
|
|
41
|
+
}
|
|
42
|
+
/** A modifier a field may carry after its name or type. */
|
|
43
|
+
export type FieldModifier = "index" | "unique";
|
|
44
|
+
/** Every modifier, in the order the help lists them. */
|
|
45
|
+
export declare const FIELD_MODIFIERS: readonly FieldModifier[];
|
|
46
|
+
/** What one field type is in the layers that read it as data. */
|
|
47
|
+
export interface FieldType {
|
|
48
|
+
/** The `remix/data-table` column, as source and as the builder the migration renders. */
|
|
49
|
+
column: string;
|
|
50
|
+
build: (c: ColumnNamespace) => ColumnBuilder;
|
|
51
|
+
/**
|
|
52
|
+
* The test a submitted, non-blank value passes, as an expression over `value`, with the
|
|
53
|
+
* message a refusal shows; `null` for a box, which `coerce.boolean()` reads instead.
|
|
54
|
+
*/
|
|
55
|
+
test: {
|
|
56
|
+
expression: string;
|
|
57
|
+
message: string;
|
|
58
|
+
} | null;
|
|
59
|
+
/** The expression over `value` that turns the submitted text into the column's value. */
|
|
60
|
+
convert: string | null;
|
|
61
|
+
/** The tool input's JSON Schema builder. */
|
|
62
|
+
json: string;
|
|
63
|
+
/** The command flag's builder: `string`, `number` or `boolean`. */
|
|
64
|
+
flag: "string" | "number" | "boolean";
|
|
65
|
+
/** A value a submission fills it with, as form text, a tool call, as JSON source, and a flag. */
|
|
66
|
+
formSample: string;
|
|
67
|
+
jsonSample: string;
|
|
68
|
+
flagSample: string;
|
|
69
|
+
/** A second value for a tool's update, as JSON source, different from the factory's. */
|
|
70
|
+
changedSample: string;
|
|
71
|
+
/** Form text the form schema refuses. */
|
|
72
|
+
invalidSample: string;
|
|
73
|
+
}
|
|
74
|
+
/** Every field type `sdxc scaffold` writes pages for, in the order the help lists them. */
|
|
75
|
+
export declare const FIELD_TYPES: Readonly<Record<Exclude<FieldTypeName, "references">, FieldType>>;
|
|
76
|
+
/** Every type a field may name, the reference included, in the order the help lists them. */
|
|
77
|
+
export declare const FIELD_TYPE_NAMES: readonly FieldTypeName[];
|
|
78
|
+
/**
|
|
79
|
+
* The type a bare name takes by convention, from its snake_case words. The rules are checked in
|
|
80
|
+
* this order, so `published_at` is a timestamp and `published` a box, and a name no rule
|
|
81
|
+
* matches is a `string`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function conventionalType(words: readonly string[]): FieldTypeName;
|
|
84
|
+
/**
|
|
85
|
+
* Parses `specs` into fields. Each spec is a name with an optional `:type` and an optional
|
|
86
|
+
* `:index` or `:unique`, and a trailing `?` on any part makes the field nullable; a bare name takes {@link conventionalType}, and an
|
|
87
|
+
* explicit type always wins. `author:references` and a bare `author_id` both write `author_id`,
|
|
88
|
+
* pointing at the `authors` table until {@link resolveReferences} reads the model's own table.
|
|
89
|
+
* A reserved, repeated or invalid name, an unknown type, a nullable box and a password column are
|
|
90
|
+
* failures naming the spec.
|
|
91
|
+
*/
|
|
92
|
+
export declare function parseFields(specs: readonly string[]): Result<Field[], Error>;
|
|
93
|
+
/**
|
|
94
|
+
* `fields` with each reference pointing at the table its model in `app/models/` declares, and at
|
|
95
|
+
* that table's `id` type. A reference to a model the project lacks keeps the plural table name,
|
|
96
|
+
* as `sdxc scaffold` names tables, and a text id.
|
|
97
|
+
*/
|
|
98
|
+
export declare function resolveReferences(root: string, fields: readonly Field[]): Promise<Field[]>;
|
|
99
|
+
/**
|
|
100
|
+
* The `remix/data-table` column source of `field` in the table `table`: its type's builder, a
|
|
101
|
+
* reference's foreign key named `<table>_<column>_fkey`, `.unique()` after `:unique`, and
|
|
102
|
+
* `.nullable()` after a `?`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function columnSource(field: Field, table: string): string;
|
|
105
|
+
/** The column `columnSource` writes, built with `c`, for a table rendered from it. */
|
|
106
|
+
export declare function buildColumn(field: Field, table: string, c: ColumnNamespace): ColumnBuilder;
|
|
107
|
+
/**
|
|
108
|
+
* One `CREATE INDEX` per `:index` field of `table`, named `<table>_<column>_index`. The model
|
|
109
|
+
* declares no plain index, so the migration is where it lives; a `:unique` field's index comes
|
|
110
|
+
* from its column instead.
|
|
111
|
+
*/
|
|
112
|
+
export declare function fieldIndexes(table: string, fields: readonly Field[]): string[];
|
|
113
|
+
/**
|
|
114
|
+
* The table a model with `fields` declares under `name`, as the model stub writes it: a text `id`
|
|
115
|
+
* key, each field's column, then the `created_at` and `updated_at` its timestamps stamp. Its
|
|
116
|
+
* migration is rendered from this table, so the two always list the same columns.
|
|
117
|
+
*/
|
|
118
|
+
export declare function fieldsTable(name: string, fields: readonly Field[]): AnyTable;
|
|
119
|
+
/**
|
|
120
|
+
* A factory attribute's source for `field`, text numbered by the sequence so two rows a test
|
|
121
|
+
* creates differ. A nullable reference is `null`; a required one is `null` too, which the caller
|
|
122
|
+
* leaves out, since only a test knows which row it should point at.
|
|
123
|
+
*/
|
|
124
|
+
export declare function factorySource(field: Field): string | null;
|
|
125
|
+
/**
|
|
126
|
+
* The plural of a kebab-case `name`, pluralizing its last word by three English rules: a
|
|
127
|
+
* sibilant ending adds `es`, a consonant before `y` becomes `ies`, and anything else adds `s`.
|
|
128
|
+
*/
|
|
129
|
+
export declare function pluralize(name: string): string;
|