@sdxc/kit 2026.10.16 → 2026.10.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +391 -20
- package/changelog.jsonl +1160 -1035
- package/config.schema.json +47 -1
- package/dist/author.d.ts +36 -0
- package/dist/author.js +107 -0
- package/dist/cli.js +12 -0
- package/dist/commands/create.js +9 -4
- 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 +72 -6
- package/dist/commands/make.js +127 -19
- 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 +18 -2
- package/dist/commands/run.js +35 -12
- package/dist/commands/scaffold.d.ts +29 -0
- package/dist/commands/scaffold.js +33 -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 +18 -0
- package/dist/config.js +28 -1
- package/dist/contract.d.ts +97 -3
- package/dist/contract.js +360 -26
- package/dist/create/templates.d.ts +8 -1
- package/dist/create/templates.js +26 -2
- package/dist/dependencies.d.ts +4 -1
- package/dist/dependencies.js +13 -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 +311 -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 +68 -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/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/init.d.ts +5 -3
- package/dist/init.js +15 -7
- 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 +32 -4
- package/dist/make/declare.js +405 -27
- 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 +16 -5
- package/dist/make/generate.js +43 -14
- 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 +47 -4
- package/dist/make/index.js +287 -25
- package/dist/make/kinds.d.ts +31 -3
- package/dist/make/kinds.js +82 -9
- 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 +7 -5
- package/dist/make/stubs.js +16 -5
- package/dist/make/test.d.ts +43 -0
- package/dist/make/test.js +149 -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 +37 -0
- package/dist/scaffold/index.js +613 -0
- package/dist/scaffold/render.d.ts +51 -0
- package/dist/scaffold/render.js +332 -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/testing.d.ts +12 -2
- package/dist/testing.js +22 -3
- 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/stubs/command.stub +4 -0
- package/stubs/command.test.stub +3 -0
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.api.stub +21 -0
- package/stubs/controller.api.test.stub +18 -0
- package/stubs/controller.form.stub +40 -10
- package/stubs/controller.form.test.stub +61 -0
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/controller.stub +15 -8
- package/stubs/controller.test.stub +3 -0
- package/stubs/email.stub +15 -38
- package/stubs/email.test.stub +12 -7
- package/stubs/factory.stub +4 -1
- package/stubs/initializer.stub +2 -0
- package/stubs/initializer.test.stub +3 -0
- package/stubs/job.cron.stub +4 -0
- package/stubs/job.stub +4 -0
- package/stubs/job.test.stub +3 -0
- package/stubs/mcp.resource.stub +3 -0
- package/stubs/mcp.stub +3 -0
- package/stubs/mcp.test.stub +3 -0
- package/stubs/middleware.stub +6 -1
- package/stubs/middleware.test.stub +3 -0
- package/stubs/model.stub +12 -3
- package/stubs/model.test.stub +3 -0
- package/stubs/policy.test.stub +36 -7
- 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 +2 -0
- package/stubs/scaffold.model.stub +35 -0
- package/stubs/scaffold.model.test.stub +25 -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/stubs/service.stub +4 -0
- package/stubs/service.test.stub +3 -0
- package/stubs/validator.stub +3 -0
- package/stubs/validator.test.stub +3 -0
- package/templates/app/.env.example +16 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +79 -37
- package/templates/app/app/commands/about.test.ts +1 -1
- 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/console.ts +6 -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 +46 -0
- package/templates/app/app/commands/db/migrate.ts +88 -0
- 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 +72 -1
- package/templates/app/app/commands/typegen.test.ts +17 -0
- package/templates/app/app/commands/typegen.ts +16 -0
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/controllers/api/health.tsx +15 -0
- package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
- package/templates/app/app/http/controllers/home.tsx +21 -13
- package/templates/app/app/http/controllers/mcp.tsx +16 -0
- package/templates/app/app/http/controllers/not-found.tsx +23 -18
- package/templates/app/app/http/controllers/robots.test.ts +18 -0
- package/templates/app/app/http/controllers/robots.ts +24 -0
- package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
- package/templates/app/app/http/controllers/sitemap.ts +25 -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 +19 -0
- package/templates/app/app/http/middleware/page.test.ts +43 -0
- package/templates/app/app/http/middleware/page.ts +51 -0
- package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
- package/templates/app/app/http/middleware/server-timing.ts +42 -0
- package/templates/app/app/initializers/assets.ts +1 -1
- package/templates/app/app/initializers/captcha.ts +11 -0
- package/templates/app/app/initializers/cli.ts +68 -2
- package/templates/app/app/initializers/database.test.ts +18 -0
- package/templates/app/app/initializers/database.ts +18 -0
- package/templates/app/app/initializers/dispatcher.ts +26 -0
- package/templates/app/app/initializers/honeypot.ts +11 -0
- package/templates/app/app/initializers/i18n.test.ts +16 -0
- package/templates/app/app/initializers/i18n.ts +28 -0
- package/templates/app/app/initializers/local-database.test.ts +33 -0
- package/templates/app/app/initializers/local-database.ts +53 -0
- package/templates/app/app/initializers/mail-transport.test.ts +27 -0
- package/templates/app/app/initializers/mail-transport.ts +26 -0
- package/templates/app/app/initializers/mail.test.ts +27 -0
- package/templates/app/app/initializers/mail.ts +19 -0
- package/templates/app/app/initializers/mcp.ts +1 -1
- package/templates/app/app/initializers/openapi.ts +21 -0
- package/templates/app/app/initializers/router.test.ts +68 -0
- package/templates/app/app/initializers/router.tsx +81 -25
- package/templates/app/app/initializers/seo.ts +15 -0
- package/templates/app/app/initializers/session.test.ts +34 -0
- package/templates/app/app/initializers/session.ts +29 -0
- package/templates/app/app/initializers/spam.ts +10 -0
- 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/models/index.ts +10 -0
- 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 +92 -0
- package/templates/app/app/services/migrations.ts +117 -0
- package/templates/app/app/test/cloudflare-workers.ts +25 -0
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/cli.ts +1 -1
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/bootstrap/worker.ts +4 -4
- package/templates/app/cloudflare.config.ts +30 -2
- package/templates/app/config/constants.ts +19 -0
- package/templates/app/config/problems.ts +24 -0
- package/templates/app/config/security-policy.ts +34 -0
- package/templates/app/config/security-txt.ts +28 -0
- package/templates/app/database/migrations/.gitkeep +0 -0
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +37 -6
- package/templates/app/resources/layouts/document.tsx +28 -7
- package/templates/app/resources/locales/en.json +10 -0
- package/templates/app/routes/api.ts +29 -0
- package/templates/app/routes/web.ts +6 -4
- package/templates/app/vite.config.ts +4 -0
- package/stubs/policy.stub +0 -13
- package/templates/app/config/router-context.d.ts +0 -20
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc models [name]`: each model's table as the app runs it, loaded in the project's own
|
|
3
|
+
* runtime, and whether the migration chain creates exactly that table, so a model and its
|
|
4
|
+
* migrations that drifted apart show before a deploy does.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { AnyCommandContext } from "@sdxc/cli";
|
|
10
|
+
import type { Result } from "@sdxc/result";
|
|
11
|
+
import type { Project } from "./middleware.js";
|
|
12
|
+
/** One column, as the table declares it. */
|
|
13
|
+
export interface ModelColumn {
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
nullable: boolean;
|
|
17
|
+
/** The default as data-table describes it, `null` without one. */
|
|
18
|
+
default: unknown;
|
|
19
|
+
/** `primary`, `unique`, or the table and column a foreign key points at. */
|
|
20
|
+
key: string | null;
|
|
21
|
+
}
|
|
22
|
+
/** One model's table and how the migration chain compares with it. */
|
|
23
|
+
export interface ModelSummary {
|
|
24
|
+
/** The model's name as `sdxc make model` takes it: its file under `app/models/`. */
|
|
25
|
+
name: string;
|
|
26
|
+
file: string;
|
|
27
|
+
table: string;
|
|
28
|
+
columns: ModelColumn[];
|
|
29
|
+
/** The statements the chain lacks to match the table; none when it matches. */
|
|
30
|
+
pending: string[];
|
|
31
|
+
/** The factory `sdxc make model` writes beside it, or `null` when the project has none. */
|
|
32
|
+
factory: string | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Loads each model `names` asks for, every one without names, and compares its table with the
|
|
36
|
+
* default migration chain. A model that fails to load fails the run with the runtime's error.
|
|
37
|
+
*/
|
|
38
|
+
export declare function summarizeModels(ctx: Pick<AnyCommandContext, "exec">, project: Project, names: readonly string[]): Promise<Result<ModelSummary[], Error>>;
|
|
39
|
+
/** One row per model: its name, file, table, column count and migration status. */
|
|
40
|
+
export declare function formatModelList(models: readonly ModelSummary[]): string;
|
|
41
|
+
/** One model in full: its columns, its migration status and its factory. */
|
|
42
|
+
export declare function formatModel(model: ModelSummary): string;
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc models [name]`: each model's table as the app runs it, loaded in the project's own
|
|
3
|
+
* runtime, and whether the migration chain creates exactly that table, so a model and its
|
|
4
|
+
* migrations that drifted apart show before a deploy does.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
12
|
+
import { isAppSource, listFiles } from "./doctor/files.js";
|
|
13
|
+
import { loadTables, readChain } from "./make/from-model.js";
|
|
14
|
+
import { chainFolder } from "./make/migrations.js";
|
|
15
|
+
import { parseName } from "./make/names.js";
|
|
16
|
+
import { planMigration } from "./make/schema-diff.js";
|
|
17
|
+
/** The folder the layout gives models, and the registry beside them. */
|
|
18
|
+
const MODELS_FOLDER = "app/models";
|
|
19
|
+
/** A module that defines a model or a table, rather than a helper beside them. */
|
|
20
|
+
const DEFINES_TABLE = /\b(?:createModel|table)\s*\(/;
|
|
21
|
+
/** Every model module under `app/models/`, the registry left out, by the name `make` takes. */
|
|
22
|
+
async function modelFiles(root) {
|
|
23
|
+
let models = [];
|
|
24
|
+
for (let file of (await listFiles(root, MODELS_FOLDER)).filter(isAppSource)) {
|
|
25
|
+
if (file === `${MODELS_FOLDER}/index.ts`)
|
|
26
|
+
continue;
|
|
27
|
+
let source = await wrap(() => readFile(join(root, file), "utf8"));
|
|
28
|
+
if (isFailure(source) || !DEFINES_TABLE.test(source.data))
|
|
29
|
+
continue;
|
|
30
|
+
let name = file.slice(MODELS_FOLDER.length + 1).replace(/\.[cm]?[jt]sx?$/, "");
|
|
31
|
+
models.push({ name, file });
|
|
32
|
+
}
|
|
33
|
+
return models;
|
|
34
|
+
}
|
|
35
|
+
/** The columns of `table`, in declaration order. */
|
|
36
|
+
function columnsOf(table) {
|
|
37
|
+
return Object.entries(table.columns).map(([name, definition]) => {
|
|
38
|
+
let reference = definition.references;
|
|
39
|
+
let key = table.primaryKey.includes(name)
|
|
40
|
+
? "primary"
|
|
41
|
+
: reference !== undefined
|
|
42
|
+
? `${reference.table.name}.${reference.columns.join(", ")}`
|
|
43
|
+
: definition.unique !== undefined && definition.unique !== false
|
|
44
|
+
? "unique"
|
|
45
|
+
: null;
|
|
46
|
+
return {
|
|
47
|
+
name,
|
|
48
|
+
type: definition.type,
|
|
49
|
+
nullable: definition.nullable === true,
|
|
50
|
+
default: definition.default ?? null,
|
|
51
|
+
key,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Loads each model `names` asks for, every one without names, and compares its table with the
|
|
57
|
+
* default migration chain. A model that fails to load fails the run with the runtime's error.
|
|
58
|
+
*/
|
|
59
|
+
export async function summarizeModels(ctx, project, names) {
|
|
60
|
+
let { root } = project;
|
|
61
|
+
let files = await modelFiles(root);
|
|
62
|
+
let wanted = files;
|
|
63
|
+
if (names.length > 0) {
|
|
64
|
+
wanted = [];
|
|
65
|
+
for (let requested of names) {
|
|
66
|
+
let name = parseName(requested);
|
|
67
|
+
if (isFailure(name))
|
|
68
|
+
return name;
|
|
69
|
+
let found = files.find((model) => model.name === name.data.segments.join("/"));
|
|
70
|
+
if (found === undefined) {
|
|
71
|
+
let known = files.map((model) => model.name).join(", ") || "none";
|
|
72
|
+
return failure(new Error(`No model ${requested} in ${MODELS_FOLDER}/; models: ${known}`));
|
|
73
|
+
}
|
|
74
|
+
wanted.push(found);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
let folder = chainFolder(project.config.make.migrations, undefined);
|
|
78
|
+
if (isFailure(folder))
|
|
79
|
+
return folder;
|
|
80
|
+
let chain = await readChain(root, folder.data);
|
|
81
|
+
let summaries = [];
|
|
82
|
+
for (let model of wanted) {
|
|
83
|
+
let tables = await loadTables(ctx, root, model.file);
|
|
84
|
+
if (isFailure(tables))
|
|
85
|
+
return tables;
|
|
86
|
+
let planned = isFailure(chain) ? null : planMigration(chain.data, tables.data);
|
|
87
|
+
let pending = planned === null || isFailure(planned) ? [] : planned.data.statements;
|
|
88
|
+
let factory = `database/factories/${model.name}.ts`;
|
|
89
|
+
let hasFactory = (await listFiles(root, "database/factories")).includes(factory);
|
|
90
|
+
for (let table of tables.data) {
|
|
91
|
+
summaries.push({
|
|
92
|
+
name: model.name,
|
|
93
|
+
file: model.file,
|
|
94
|
+
table: table.name,
|
|
95
|
+
columns: columnsOf(table),
|
|
96
|
+
pending,
|
|
97
|
+
factory: hasFactory ? factory : null,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return success(summaries);
|
|
102
|
+
}
|
|
103
|
+
/** The migration status line of `model`: in step, or the command that catches the chain up. */
|
|
104
|
+
function migrationStatus(model) {
|
|
105
|
+
if (model.pending.length === 0)
|
|
106
|
+
return "the migrations create this table";
|
|
107
|
+
return `the migrations create a different table; sdxc make migration sync-${model.table.replaceAll("_", "-")} --from-model ${model.name} writes the SQL that catches them up`;
|
|
108
|
+
}
|
|
109
|
+
/** One row per model: its name, file, table, column count and migration status. */
|
|
110
|
+
export function formatModelList(models) {
|
|
111
|
+
if (models.length === 0)
|
|
112
|
+
return `No models in ${MODELS_FOLDER}/.\n`;
|
|
113
|
+
let rows = models.map((model) => [
|
|
114
|
+
model.name,
|
|
115
|
+
model.file,
|
|
116
|
+
model.table,
|
|
117
|
+
String(model.columns.length),
|
|
118
|
+
model.pending.length === 0 ? "in step" : "behind",
|
|
119
|
+
]);
|
|
120
|
+
return table(["Model", "File", "Table", "Columns", "Migrations"], rows);
|
|
121
|
+
}
|
|
122
|
+
/** One model in full: its columns, its migration status and its factory. */
|
|
123
|
+
export function formatModel(model) {
|
|
124
|
+
let rows = model.columns.map((column) => [
|
|
125
|
+
column.name,
|
|
126
|
+
column.type,
|
|
127
|
+
column.nullable ? "yes" : "no",
|
|
128
|
+
column.default === null ? "" : JSON.stringify(column.default),
|
|
129
|
+
column.key ?? "",
|
|
130
|
+
]);
|
|
131
|
+
return [
|
|
132
|
+
`${model.name}: the ${model.table} table, in ${model.file}`,
|
|
133
|
+
"",
|
|
134
|
+
table(["Column", "Type", "Null", "Default", "Key"], rows).trimEnd(),
|
|
135
|
+
"",
|
|
136
|
+
`Migrations: ${migrationStatus(model)}`,
|
|
137
|
+
`Factory: ${model.factory ?? `none; sdxc make factory ${model.name} writes one`}`,
|
|
138
|
+
"",
|
|
139
|
+
].join("\n");
|
|
140
|
+
}
|
|
141
|
+
/** `rows` under `header`, each column as wide as its widest cell. */
|
|
142
|
+
function table(header, rows) {
|
|
143
|
+
let widths = header.map((title, column) => Math.max(title.length, ...rows.map((row) => row[column]?.length ?? 0)));
|
|
144
|
+
let line = (row) => row
|
|
145
|
+
.map((cell, column) => cell.padEnd(widths[column] ?? 0))
|
|
146
|
+
.join(" ")
|
|
147
|
+
.trimEnd();
|
|
148
|
+
return `${[line(header), ...rows.map(line)].join("\n")}\n`;
|
|
149
|
+
}
|
package/dist/notes.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc notes`: every `TODO`, `FIXME`, `HACK` and `OPTIMIZE` comment in the app's code, by file
|
|
3
|
+
* and line, so the work a generated file left to fill in, and the work anyone left for later,
|
|
4
|
+
* reads as one list.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** The tags `notes` looks for without `--tag`. */
|
|
10
|
+
export declare const DEFAULT_TAGS: string[];
|
|
11
|
+
/** One note. */
|
|
12
|
+
export interface Note {
|
|
13
|
+
/** The file, relative to the project root. */
|
|
14
|
+
file: string;
|
|
15
|
+
line: number;
|
|
16
|
+
tag: string;
|
|
17
|
+
/** The text after the tag, its `:` dropped. */
|
|
18
|
+
text: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The notes in one file's `text`: a tag as a whole word after a comment marker (`//`, `/*`,
|
|
22
|
+
* `*`, `{/*`, `--` or `<!--`) on the same line, matched in upper case as written.
|
|
23
|
+
*/
|
|
24
|
+
export declare function findNotes(file: string, text: string, tags: readonly string[]): Note[];
|
|
25
|
+
/** Every note under the project's layout folders, in file order. */
|
|
26
|
+
export declare function projectNotes(root: string, tags: readonly string[]): Promise<Note[]>;
|
|
27
|
+
/** The notes grouped by file, each line numbered as `[12] TODO: …`, as `rails notes` prints. */
|
|
28
|
+
export declare function formatNotes(notes: readonly Note[]): string;
|
package/dist/notes.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc notes`: every `TODO`, `FIXME`, `HACK` and `OPTIMIZE` comment in the app's code, by file
|
|
3
|
+
* and line, so the work a generated file left to fill in, and the work anyone left for later,
|
|
4
|
+
* reads as one list.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
12
|
+
import { listFiles } from "./doctor/files.js";
|
|
13
|
+
import { PROJECT_FOLDERS } from "./stats.js";
|
|
14
|
+
/** The tags `notes` looks for without `--tag`. */
|
|
15
|
+
export const DEFAULT_TAGS = ["TODO", "FIXME", "HACK", "OPTIMIZE"];
|
|
16
|
+
/** The files read: source, SQL, stylesheets and Markdown, where a comment can hold a note. */
|
|
17
|
+
const READ = /\.(?:[cm]?[jt]sx?|sql|css|md)$/;
|
|
18
|
+
/**
|
|
19
|
+
* The notes in one file's `text`: a tag as a whole word after a comment marker (`//`, `/*`,
|
|
20
|
+
* `*`, `{/*`, `--` or `<!--`) on the same line, matched in upper case as written.
|
|
21
|
+
*/
|
|
22
|
+
export function findNotes(file, text, tags) {
|
|
23
|
+
let pattern = new RegExp(`(?:\\/\\/|\\/\\*|^\\s*\\*|\\{\\/\\*|--|<!--)\\s*(${tags.map(escapeRegExp).join("|")})\\b:?\\s*(.*?)\\s*(?:\\*\\/\\}?|-->)?\\s*$`);
|
|
24
|
+
let notes = [];
|
|
25
|
+
text.split("\n").forEach((line, index) => {
|
|
26
|
+
let match = pattern.exec(line);
|
|
27
|
+
if (match === null)
|
|
28
|
+
return;
|
|
29
|
+
notes.push({ file, line: index + 1, tag: match[1], text: match[2] ?? "" });
|
|
30
|
+
});
|
|
31
|
+
return notes;
|
|
32
|
+
}
|
|
33
|
+
/** `value` with every character a regular expression reads specially escaped. */
|
|
34
|
+
function escapeRegExp(value) {
|
|
35
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
36
|
+
}
|
|
37
|
+
/** Every note under the project's layout folders, in file order. */
|
|
38
|
+
export async function projectNotes(root, tags) {
|
|
39
|
+
let notes = [];
|
|
40
|
+
for (let folder of PROJECT_FOLDERS) {
|
|
41
|
+
for (let path of await listFiles(root, folder)) {
|
|
42
|
+
if (!READ.test(path))
|
|
43
|
+
continue;
|
|
44
|
+
let text = await wrap(() => readFile(join(root, path), "utf8"));
|
|
45
|
+
if (isFailure(text))
|
|
46
|
+
continue;
|
|
47
|
+
notes.push(...findNotes(path, text.data, tags));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return notes;
|
|
51
|
+
}
|
|
52
|
+
/** The notes grouped by file, each line numbered as `[12] TODO: …`, as `rails notes` prints. */
|
|
53
|
+
export function formatNotes(notes) {
|
|
54
|
+
let width = Math.max(0, ...notes.map((note) => String(note.line).length));
|
|
55
|
+
let groups = new Map();
|
|
56
|
+
for (let note of notes)
|
|
57
|
+
groups.set(note.file, [...(groups.get(note.file) ?? []), note]);
|
|
58
|
+
let blocks = [...groups].map(([file, entries]) => {
|
|
59
|
+
let lines = entries.map((note) => {
|
|
60
|
+
let text = note.text === "" ? note.tag : `${note.tag}: ${note.text}`;
|
|
61
|
+
return ` [${String(note.line).padStart(width)}] ${text}`;
|
|
62
|
+
});
|
|
63
|
+
return `${file}:\n${lines.join("\n")}`;
|
|
64
|
+
});
|
|
65
|
+
return `${blocks.join("\n\n")}\n`;
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The README's per-command reference, rendered from the contract's description: one heading per
|
|
3
|
+
* command with its arguments, its description and a table of its flags. Rendering it from the
|
|
4
|
+
* contract keeps the README in step with `sdxc <command> --help`, and a test fails when it drifts.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { CommandDescription } from "@sdxc/cli";
|
|
10
|
+
/**
|
|
11
|
+
* Every command under `root` as Markdown, in contract order, its tables padded as the formatter
|
|
12
|
+
* writes them. A group with no arguments or flags of its own gets no entry; its members do.
|
|
13
|
+
*
|
|
14
|
+
* @example let reference = renderReference(createSDXC().describe()!);
|
|
15
|
+
*/
|
|
16
|
+
export declare function renderReference(root: CommandDescription): string;
|
|
17
|
+
/**
|
|
18
|
+
* The reference section of `readme`: from the first command heading up to the blank line before
|
|
19
|
+
* the `### Configuration` heading, so it compares equal to `renderReference`'s output. `null`
|
|
20
|
+
* when either heading is missing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readReference(readme: string): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* `readme` with its reference section replaced by `reference`, or `null` when either heading
|
|
25
|
+
* bounding the section is missing.
|
|
26
|
+
*/
|
|
27
|
+
export declare function replaceReference(readme: string, reference: string): string | null;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The README's per-command reference, rendered from the contract's description: one heading per
|
|
3
|
+
* command with its arguments, its description and a table of its flags. Rendering it from the
|
|
4
|
+
* contract keeps the README in step with `sdxc <command> --help`, and a test fails when it drifts.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** The first line of the reference section, the heading every command's entry starts with. */
|
|
10
|
+
const SECTION_START = "#### `sdxc ";
|
|
11
|
+
/** The heading right after the reference section, which the section ends before. */
|
|
12
|
+
const SECTION_END = "### Configuration";
|
|
13
|
+
/**
|
|
14
|
+
* Every command under `root` as Markdown, in contract order, its tables padded as the formatter
|
|
15
|
+
* writes them. A group with no arguments or flags of its own gets no entry; its members do.
|
|
16
|
+
*
|
|
17
|
+
* @example let reference = renderReference(createSDXC().describe()!);
|
|
18
|
+
*/
|
|
19
|
+
export function renderReference(root) {
|
|
20
|
+
let blocks = [];
|
|
21
|
+
for (let command of root.commands)
|
|
22
|
+
blocks.push(...renderCommand(command));
|
|
23
|
+
return `${blocks.join("\n\n")}\n`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The reference section of `readme`: from the first command heading up to the blank line before
|
|
27
|
+
* the `### Configuration` heading, so it compares equal to `renderReference`'s output. `null`
|
|
28
|
+
* when either heading is missing.
|
|
29
|
+
*/
|
|
30
|
+
export function readReference(readme) {
|
|
31
|
+
let range = referenceRange(readme);
|
|
32
|
+
return range === null ? null : readme.slice(range.start, range.end);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `readme` with its reference section replaced by `reference`, or `null` when either heading
|
|
36
|
+
* bounding the section is missing.
|
|
37
|
+
*/
|
|
38
|
+
export function replaceReference(readme, reference) {
|
|
39
|
+
let range = referenceRange(readme);
|
|
40
|
+
if (range === null)
|
|
41
|
+
return null;
|
|
42
|
+
return `${readme.slice(0, range.start)}${reference}${readme.slice(range.end)}`;
|
|
43
|
+
}
|
|
44
|
+
/** Where the reference section starts and ends in `readme`. */
|
|
45
|
+
function referenceRange(readme) {
|
|
46
|
+
let start = readme.indexOf(SECTION_START);
|
|
47
|
+
if (start === -1)
|
|
48
|
+
return null;
|
|
49
|
+
let end = readme.indexOf(`\n${SECTION_END}\n`, start);
|
|
50
|
+
if (end === -1)
|
|
51
|
+
return null;
|
|
52
|
+
return { start, end };
|
|
53
|
+
}
|
|
54
|
+
/** One command's entry followed by its members', each a Markdown block. */
|
|
55
|
+
function renderCommand(command) {
|
|
56
|
+
let flags = command.flags.filter((flag) => !flag.builtin);
|
|
57
|
+
let blocks = [];
|
|
58
|
+
if (command.commands.length === 0 || command.arguments.length > 0 || flags.length > 0) {
|
|
59
|
+
blocks.push(`#### \`${heading(command)}\``);
|
|
60
|
+
if (command.description)
|
|
61
|
+
blocks.push(escapeHTML(command.description));
|
|
62
|
+
if (flags.length > 0) {
|
|
63
|
+
blocks.push(table(["Flag", "Does"], flags.map((flag) => [
|
|
64
|
+
`\`${flagName(flag)}\``,
|
|
65
|
+
escapeHTML(flag.description ?? "").replaceAll("|", "\\|"),
|
|
66
|
+
])));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (let member of command.commands)
|
|
70
|
+
blocks.push(...renderCommand(member));
|
|
71
|
+
return blocks;
|
|
72
|
+
}
|
|
73
|
+
/** The command line as the help's usage writes it: `<name>` required, `[name]` optional. */
|
|
74
|
+
function heading(command) {
|
|
75
|
+
let words = command.arguments.map((argument) => {
|
|
76
|
+
if (argument.variadic || argument.rest)
|
|
77
|
+
return `[${argument.name}...]`;
|
|
78
|
+
return argument.required ? `<${argument.name}>` : `[${argument.name}]`;
|
|
79
|
+
});
|
|
80
|
+
return [command.title, ...words].join(" ");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The flag as typed: its short alias first, a boolean on by default spelled `--no-<name>`, and
|
|
84
|
+
* the value name a non-boolean takes.
|
|
85
|
+
*/
|
|
86
|
+
function flagName(flag) {
|
|
87
|
+
let long = `--${flag.negatable && flag.default === true ? "no-" : ""}${flag.name}`;
|
|
88
|
+
let names = flag.short ? `-${flag.short}, ${long}` : long;
|
|
89
|
+
return flag.value ? `${names} <${flag.value}>` : names;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A description as Markdown text: `<` and `>` as entities, so a placeholder such as `<name>`
|
|
93
|
+
* renders instead of reading as an HTML tag.
|
|
94
|
+
*/
|
|
95
|
+
function escapeHTML(text) {
|
|
96
|
+
return text.replaceAll("<", "<").replaceAll(">", ">");
|
|
97
|
+
}
|
|
98
|
+
/** A Markdown table with every column padded to its widest cell. */
|
|
99
|
+
function table(header, rows) {
|
|
100
|
+
let widths = header.map((cell, column) => Math.max(cell.length, ...rows.map((row) => (row[column] ?? "").length)));
|
|
101
|
+
let line = (cells) => `| ${cells.map((cell, column) => cell.padEnd(widths[column] ?? 0)).join(" | ")} |`;
|
|
102
|
+
return [line(header), line(widths.map((width) => "-".repeat(width))), ...rows.map(line)].join("\n");
|
|
103
|
+
}
|
package/dist/releases.d.ts
CHANGED
|
@@ -31,10 +31,19 @@ export declare function versionAtRelease(packument: Packument, release: string):
|
|
|
31
31
|
* is `null`. A package with no version at that release is a failure naming both.
|
|
32
32
|
*/
|
|
33
33
|
export declare function resolveRelease(names: Iterable<string>, release: string | null, signal?: AbortSignal): Promise<Result<Map<string, string>, Error>>;
|
|
34
|
+
/** The registry document of each of `names`, sorted by name; the first npm cannot serve fails. */
|
|
35
|
+
export declare function fetchPackuments(names: Iterable<string>, signal?: AbortSignal): Promise<Result<Packument[], Error>>;
|
|
36
|
+
/**
|
|
37
|
+
* Each package's version at `release`, or at its `latest` dist-tag when `release` is `null`,
|
|
38
|
+
* by name. A package with no version at that release is a failure naming both.
|
|
39
|
+
*/
|
|
40
|
+
export declare function versionsAt(packuments: readonly Packument[], release: string | null): Result<Map<string, string>, Error>;
|
|
34
41
|
/**
|
|
35
42
|
* The release a project is on: the newest date among the exact `@sdxc/*` pins its dependency
|
|
36
43
|
* sections list, or `null` when it pins none to a dated version.
|
|
37
44
|
*/
|
|
38
45
|
export declare function projectRelease(sections: ReadonlyArray<Readonly<Record<string, string>> | undefined>): string | null;
|
|
46
|
+
/** The dated version an exact pin names, `2026.10.14` from `^2026.10.14`, or `null` for any other range. */
|
|
47
|
+
export declare function datedPin(range: string): string | null;
|
|
39
48
|
/** The npm package a module specifier comes from, `@sdxc/auth/issuer` from `@sdxc/auth`, or `null`. */
|
|
40
49
|
export declare function scopedPackageOf(specifier: string): string | null;
|
package/dist/releases.js
CHANGED
|
@@ -65,20 +65,37 @@ export function versionAtRelease(packument, release) {
|
|
|
65
65
|
* is `null`. A package with no version at that release is a failure naming both.
|
|
66
66
|
*/
|
|
67
67
|
export async function resolveRelease(names, release, signal) {
|
|
68
|
+
let packuments = await fetchPackuments(names, signal);
|
|
69
|
+
if (isFailure(packuments))
|
|
70
|
+
return packuments;
|
|
71
|
+
return versionsAt(packuments.data, release);
|
|
72
|
+
}
|
|
73
|
+
/** The registry document of each of `names`, sorted by name; the first npm cannot serve fails. */
|
|
74
|
+
export async function fetchPackuments(names, signal) {
|
|
68
75
|
let sorted = [...new Set(names)].sort();
|
|
69
76
|
let fetched = await Promise.all(sorted.map((name) => fetchPackument(name, signal)));
|
|
70
|
-
let
|
|
77
|
+
let packuments = [];
|
|
71
78
|
for (let packument of fetched) {
|
|
72
79
|
if (isFailure(packument))
|
|
73
80
|
return packument;
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
packuments.push(packument.data);
|
|
82
|
+
}
|
|
83
|
+
return success(packuments);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Each package's version at `release`, or at its `latest` dist-tag when `release` is `null`,
|
|
87
|
+
* by name. A package with no version at that release is a failure naming both.
|
|
88
|
+
*/
|
|
89
|
+
export function versionsAt(packuments, release) {
|
|
90
|
+
let versions = new Map();
|
|
91
|
+
for (let packument of packuments) {
|
|
92
|
+
let version = release === null ? packument.latest : versionAtRelease(packument, release);
|
|
76
93
|
if (version === null) {
|
|
77
94
|
return failure(new Error(release === null
|
|
78
|
-
? `${name} has no latest version on npm`
|
|
79
|
-
: `${name} has no release on or before ${release}`));
|
|
95
|
+
? `${packument.name} has no latest version on npm`
|
|
96
|
+
: `${packument.name} has no release on or before ${release}`));
|
|
80
97
|
}
|
|
81
|
-
versions.set(name, version);
|
|
98
|
+
versions.set(packument.name, version);
|
|
82
99
|
}
|
|
83
100
|
return success(versions);
|
|
84
101
|
}
|
|
@@ -92,8 +109,8 @@ export function projectRelease(sections) {
|
|
|
92
109
|
for (let [name, range] of Object.entries(section ?? {})) {
|
|
93
110
|
if (!name.startsWith(SCOPE))
|
|
94
111
|
continue;
|
|
95
|
-
let version =
|
|
96
|
-
if (version ===
|
|
112
|
+
let version = datedPin(range);
|
|
113
|
+
if (version === null)
|
|
97
114
|
continue;
|
|
98
115
|
if (newest === null || compare(version, newest) > 0)
|
|
99
116
|
newest = version;
|
|
@@ -101,6 +118,10 @@ export function projectRelease(sections) {
|
|
|
101
118
|
}
|
|
102
119
|
return newest;
|
|
103
120
|
}
|
|
121
|
+
/** The dated version an exact pin names, `2026.10.14` from `^2026.10.14`, or `null` for any other range. */
|
|
122
|
+
export function datedPin(range) {
|
|
123
|
+
return DATED_PIN.exec(range.trim())?.[1] ?? null;
|
|
124
|
+
}
|
|
104
125
|
/** The npm package a module specifier comes from, `@sdxc/auth/issuer` from `@sdxc/auth`, or `null`. */
|
|
105
126
|
export function scopedPackageOf(specifier) {
|
|
106
127
|
if (!specifier.startsWith(SCOPE))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc middleware`: every chain a request can run, in the order it runs it. Each router's global
|
|
3
|
+
* middleware comes first, then every module in `app/http/middleware/`: a chain such as `page`
|
|
4
|
+
* expanded to its members, or a single middleware, each with the number of routes that run it.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { MiddlewareEntry } from "./routers.js";
|
|
10
|
+
/** One module in the middleware folder. */
|
|
11
|
+
export interface MiddlewareModule {
|
|
12
|
+
file: string;
|
|
13
|
+
/**
|
|
14
|
+
* `chain` for a module whose default export is `createMiddleware(…)`, whose `middleware`
|
|
15
|
+
* lists what it runs in order; `middleware` for one that is a middleware itself.
|
|
16
|
+
*/
|
|
17
|
+
kind: "chain" | "middleware";
|
|
18
|
+
middleware: MiddlewareEntry[];
|
|
19
|
+
/** The routes whose router, guards or controller run it, directly or through a chain. */
|
|
20
|
+
routes: number;
|
|
21
|
+
}
|
|
22
|
+
/** What `sdxc middleware` prints. */
|
|
23
|
+
export interface MiddlewareListing {
|
|
24
|
+
/** Each router's global middleware, which runs before anything else. */
|
|
25
|
+
routers: Array<{
|
|
26
|
+
file: string;
|
|
27
|
+
middleware: MiddlewareEntry[];
|
|
28
|
+
}>;
|
|
29
|
+
modules: MiddlewareModule[];
|
|
30
|
+
}
|
|
31
|
+
/** Reads the routers and the middleware folder of the project at `root`. */
|
|
32
|
+
export declare function listMiddleware(root: string): Promise<MiddlewareListing>;
|
|
33
|
+
/** The listing as text: each router's chain, then each module, members numbered in run order. */
|
|
34
|
+
export declare function formatMiddleware(listing: MiddlewareListing): string;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc middleware`: every chain a request can run, in the order it runs it. Each router's global
|
|
3
|
+
* middleware comes first, then every module in `app/http/middleware/`: a chain such as `page`
|
|
4
|
+
* expanded to its members, or a single middleware, each with the number of routes that run it.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { isAppSource, listFiles } from "../doctor/files.js";
|
|
10
|
+
import { Project } from "./modules.js";
|
|
11
|
+
import { middlewareList } from "./routers.js";
|
|
12
|
+
import { listRoutes } from "./index.js";
|
|
13
|
+
/** The folder the app's middleware lives in. */
|
|
14
|
+
const MIDDLEWARE_FOLDER = "app/http/middleware";
|
|
15
|
+
/** Reads the routers and the middleware folder of the project at `root`. */
|
|
16
|
+
export async function listMiddleware(root) {
|
|
17
|
+
let listing = await listRoutes(root);
|
|
18
|
+
let project = new Project(root);
|
|
19
|
+
let modules = [];
|
|
20
|
+
for (let file of (await listFiles(root, MIDDLEWARE_FOLDER)).filter(isAppSource)) {
|
|
21
|
+
let members = await chainMembers(project, file);
|
|
22
|
+
modules.push({
|
|
23
|
+
file,
|
|
24
|
+
kind: members === null ? "middleware" : "chain",
|
|
25
|
+
middleware: members ?? [],
|
|
26
|
+
routes: 0,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
for (let module of modules) {
|
|
30
|
+
let chains = modules
|
|
31
|
+
.filter((chain) => chain.middleware.some((entry) => entry.from === module.file))
|
|
32
|
+
.map((chain) => chain.file);
|
|
33
|
+
let runs = new Set([module.file, ...chains]);
|
|
34
|
+
module.routes = listing.routes.filter((route) => [...route.middleware.router, ...route.middleware.guards, ...route.middleware.controller].some((entry) => entry.from !== null && runs.has(entry.from))).length;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
routers: listing.routers.map((router) => ({
|
|
38
|
+
file: router.file,
|
|
39
|
+
middleware: router.middleware,
|
|
40
|
+
})),
|
|
41
|
+
modules,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The members of the chain `file` default-exports as `createMiddleware(a, b, …)`, each array
|
|
46
|
+
* argument expanded, or `null` when its default export is something else.
|
|
47
|
+
*/
|
|
48
|
+
async function chainMembers(project, file) {
|
|
49
|
+
let module = await project.load(file);
|
|
50
|
+
if (module === null)
|
|
51
|
+
return null;
|
|
52
|
+
let found = await project.exported(module, "default");
|
|
53
|
+
if (found === null)
|
|
54
|
+
return null;
|
|
55
|
+
let node = found.node;
|
|
56
|
+
if (node.kind === "identifier") {
|
|
57
|
+
let binding = await project.bind(found.module, node.name);
|
|
58
|
+
if (binding.kind !== "local")
|
|
59
|
+
return null;
|
|
60
|
+
node = binding.node;
|
|
61
|
+
}
|
|
62
|
+
if (node.kind !== "call" || node.callee.kind !== "identifier")
|
|
63
|
+
return null;
|
|
64
|
+
let imported = found.module.imports.get(node.callee.name);
|
|
65
|
+
if (imported?.imported !== "createMiddleware")
|
|
66
|
+
return null;
|
|
67
|
+
let members = [];
|
|
68
|
+
for (let argument of node.args) {
|
|
69
|
+
members.push(...(await middlewareList(project, found.module, argument.node)));
|
|
70
|
+
}
|
|
71
|
+
return members;
|
|
72
|
+
}
|
|
73
|
+
/** The listing as text: each router's chain, then each module, members numbered in run order. */
|
|
74
|
+
export function formatMiddleware(listing) {
|
|
75
|
+
let block = (title, entries) => {
|
|
76
|
+
let width = Math.max(0, ...entries.map((entry) => entry.name.length));
|
|
77
|
+
let digits = String(entries.length).length;
|
|
78
|
+
let lines = entries.map((entry, index) => {
|
|
79
|
+
let from = entry.from === null ? "" : ` ${entry.from}`;
|
|
80
|
+
let number = `${index + 1}.`.padStart(digits + 1);
|
|
81
|
+
return ` ${number} ${entry.name.padEnd(width)}${from}`.trimEnd();
|
|
82
|
+
});
|
|
83
|
+
return [title, ...lines].join("\n");
|
|
84
|
+
};
|
|
85
|
+
let blocks = [
|
|
86
|
+
...listing.routers.map((router) => block(`${router.file}, the router's global middleware:`, router.middleware)),
|
|
87
|
+
...listing.modules.map((module) => {
|
|
88
|
+
let used = `${module.routes} route${module.routes === 1 ? "" : "s"}`;
|
|
89
|
+
return module.kind === "chain"
|
|
90
|
+
? block(`${module.file}, a chain ${used} run:`, module.middleware)
|
|
91
|
+
: `${module.file}, a middleware ${used} run`;
|
|
92
|
+
}),
|
|
93
|
+
];
|
|
94
|
+
return blocks.length === 0 ? "No routers or middleware found.\n" : `${blocks.join("\n\n")}\n`;
|
|
95
|
+
}
|