@hublo/sentinel 1.7.0-alpha.32 → 1.7.0-alpha.34
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/dist/bin/sentinel.js +2 -2
- package/dist/{chunk-SHF46ALB.js → chunk-53HYHJTD.js} +3 -2
- package/dist/chunk-53HYHJTD.js.map +1 -0
- package/dist/{chunk-UJ5VLEZF.js → chunk-Z2QRW7T4.js} +404 -127
- package/dist/index.js +2 -2
- package/dist/roles/sql/config.d.ts +10 -0
- package/dist/roles/sql/config.js +1 -1
- package/docs/sql-adoption.md +58 -19
- package/package.json +1 -1
- package/dist/chunk-SHF46ALB.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
registerAdapters,
|
|
7
7
|
resolve,
|
|
8
8
|
setDefaultRunner
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-Z2QRW7T4.js";
|
|
10
10
|
import "./chunk-ZZMYV576.js";
|
|
11
11
|
import {
|
|
12
12
|
BaseAdapter
|
|
@@ -18,7 +18,7 @@ import "./chunk-QXFCZON7.js";
|
|
|
18
18
|
import "./chunk-YUZB4LRJ.js";
|
|
19
19
|
import "./chunk-APBEGLRI.js";
|
|
20
20
|
import "./chunk-TMVKYXZ3.js";
|
|
21
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-53HYHJTD.js";
|
|
22
22
|
import "./chunk-XYOIXC6A.js";
|
|
23
23
|
import "./chunk-PXTU5MPW.js";
|
|
24
24
|
import "./chunk-4EIY7TTR.js";
|
|
@@ -13,6 +13,16 @@ interface SqlDefaults {
|
|
|
13
13
|
include: string[];
|
|
14
14
|
/** Migrations a module chooses not to read. Empty by default. */
|
|
15
15
|
exclude: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Other migrations directories, relative to the module, whose INDEXES this module's queries
|
|
18
|
+
* use: never checked, only read for the trigram indexes `leading-wildcard-like` asks about.
|
|
19
|
+
*
|
|
20
|
+
* For a module that queries a database another module migrates. On the monorepo every trigram
|
|
21
|
+
* index is in `libs/nest/db-main` (main 190dc8e3595), and `mission`, `network` or `institution`
|
|
22
|
+
* query its tables: without this, the rule would say of their searches that no index serves
|
|
23
|
+
* them. Empty by default: the module's own migrations only, and the message says so.
|
|
24
|
+
*/
|
|
25
|
+
indexesFrom: string[];
|
|
16
26
|
};
|
|
17
27
|
/** What the `Unsafe` rule reads. */
|
|
18
28
|
unsafe: {
|
package/dist/roles/sql/config.js
CHANGED
package/docs/sql-adoption.md
CHANGED
|
@@ -180,15 +180,16 @@ every setting the module can move and the role's value today, generated from the
|
|
|
180
180
|
cannot drift from them. A setting the module leaves out keeps the role's value; a setting it writes
|
|
181
181
|
**replaces** it, including inside a list, and the html report shows it as overridden by this module.
|
|
182
182
|
|
|
183
|
-
| Setting
|
|
184
|
-
|
|
|
185
|
-
| `migrations.include`
|
|
186
|
-
| `migrations.exclude`
|
|
187
|
-
| `
|
|
188
|
-
| `unsafe.
|
|
189
|
-
| `
|
|
190
|
-
| `
|
|
191
|
-
| `
|
|
183
|
+
| Setting | Default | What it moves |
|
|
184
|
+
| ------------------------ | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
|
185
|
+
| `migrations.include` | `["**/migrations/*/migration.sql"]` | which files are migrations |
|
|
186
|
+
| `migrations.exclude` | `[]` | migrations never read |
|
|
187
|
+
| `migrations.indexesFrom` | `[]` | other migrations folders whose trigram indexes this module's queries use, read for `leading-wildcard-like` only |
|
|
188
|
+
| `unsafe.includeTests` | `true` | whether calls in test files are checked, by both rules |
|
|
189
|
+
| `unsafe.tests` | test folders and `*.spec`/`*.test`/… files | what counts as a test file |
|
|
190
|
+
| `ignore` | `node_modules`, `dist`, `coverage` | never read, by either check |
|
|
191
|
+
| `pgVersion` | `"16.8"` | the PostgreSQL version squawk checks against |
|
|
192
|
+
| `rules` | `{}`, every rule at its default | a level per rule, by its name |
|
|
192
193
|
|
|
193
194
|
An example that blocks two rules, silences one and turns an opt-in rule on:
|
|
194
195
|
|
|
@@ -573,22 +574,60 @@ counted.
|
|
|
573
574
|
**Tests are read**, as the `Unsafe` rule reads them: `unsafe.includeTests`, which a module may set
|
|
574
575
|
to `false` for both.
|
|
575
576
|
|
|
576
|
-
| Rule | Default | Reports
|
|
577
|
-
| --------------------------------- | ------- |
|
|
578
|
-
| `exists-union-correlated-outside` | **on** | an `EXISTS` over a derived `UNION` filtered only outside it
|
|
579
|
-
| `update-delete-without-where` | **on** | an `UPDATE` or `DELETE` with no `WHERE`, `UPDATE … FROM` included
|
|
580
|
-
| `insert-without-columns` | **on** | an `INSERT` with values and no column list
|
|
581
|
-
| `select-star` | **on** | `SELECT *` or `t.*` on a table of the schema
|
|
582
|
-
| `leading-wildcard-like` | **on** | a
|
|
583
|
-
| `offset-pagination` | opt-in | `OFFSET` in a query or in the fragment that pages it
|
|
584
|
-
| `select-distinct` | opt-in | a plain `SELECT DISTINCT`
|
|
585
|
-
| `not-in-subquery` | opt-in | `NOT IN (SELECT …)`, which one `NULL` in the result empties
|
|
577
|
+
| Rule | Default | Reports | Leaves alone |
|
|
578
|
+
| --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------- |
|
|
579
|
+
| `exists-union-correlated-outside` | **on** | an `EXISTS` over a derived `UNION` filtered only outside it | a `UNION` whose branches each carry the correlation (mission's `UNION ALL`) |
|
|
580
|
+
| `update-delete-without-where` | **on** | an `UPDATE` or `DELETE` with no `WHERE`, `UPDATE … FROM` included | a `SET` fragment |
|
|
581
|
+
| `insert-without-columns` | **on** | an `INSERT` with values and no column list | `DEFAULT VALUES`, a `VALUES` fragment |
|
|
582
|
+
| `select-star` | **on** | `SELECT *` or `t.*` on a table of the schema | `EXISTS (SELECT * …)`, `count(*)`, a `WITH` table, a subquery, `jsonb_to_recordset(…)` |
|
|
583
|
+
| `leading-wildcard-like` | **on** | a `LIKE` / `ILIKE` pattern starting with `%`, written in the SQL or built by the TypeScript, on an expression no trigram index of the migrations read serves | an anchored pattern, one whose start the code does not show, a served search, a `CHECK` constraint |
|
|
584
|
+
| `offset-pagination` | opt-in | `OFFSET` in a query or in the fragment that pages it | `LIMIT` alone |
|
|
585
|
+
| `select-distinct` | opt-in | a plain `SELECT DISTINCT` | `DISTINCT ON (…)` |
|
|
586
|
+
| `not-in-subquery` | opt-in | `NOT IN (SELECT …)`, which one `NULL` in the result empties | `NOT IN (1, 2)`, `NOT EXISTS` |
|
|
586
587
|
|
|
587
588
|
Measured over every template of `main` 837abe3f29c: the five rules on by default report 3
|
|
588
589
|
templates of production code (all `select-star` on a table) and 15 in tests (fixtures that update
|
|
589
590
|
every row or insert by position, and two `ILIKE '%…'` on `pg_indexes`). Turned on, the opt-in
|
|
590
591
|
ones would report 14, 22 and 0 templates of production code.
|
|
591
592
|
|
|
593
|
+
### Searches inside the text, `leading-wildcard-like`
|
|
594
|
+
|
|
595
|
+
A pattern that starts with `%` cannot use a B-tree index: every row is read. A trigram index
|
|
596
|
+
(`pg_trgm`, `gin_trgm_ops` or `gist_trgm_ops`) on the very expression searched serves it, so the
|
|
597
|
+
rule speaks only when none is in the migrations it read.
|
|
598
|
+
|
|
599
|
+
It reads the pattern wherever it is written: a literal (`'%x'`), SQL that builds it (`'%' || $1`,
|
|
600
|
+
`concat('%', $1)`, `LIKE … ESCAPE`), and the TypeScript that builds and binds it
|
|
601
|
+
(``${`%${word}%`}``, or a `const` of the file), through `lower`, `upper`, `unaccent` and
|
|
602
|
+
`immutable_unaccent`. A pattern whose start the code does not show, a function parameter, is not
|
|
603
|
+
judged.
|
|
604
|
+
|
|
605
|
+
The index must be on the same expression: an index on `"searchName"` does not serve
|
|
606
|
+
`unaccent(w."searchName")`. When a fragment does not say which table it reads (its `FROM` is in
|
|
607
|
+
another template), an index on that expression of any table counts.
|
|
608
|
+
|
|
609
|
+
**A module that queries another module's database** names that module's migrations, or the rule
|
|
610
|
+
would say that no index serves searches that one does:
|
|
611
|
+
|
|
612
|
+
```js
|
|
613
|
+
// apps/nest/microservices/mission/sql.config.mjs
|
|
614
|
+
export default defineSql({
|
|
615
|
+
root: import.meta.dirname,
|
|
616
|
+
overrides: { migrations: { indexesFrom: ['../../../../libs/nest/db-main/prisma/migrations'] } },
|
|
617
|
+
})
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
Those migrations are read for their indexes only, never checked. An index created by hand in a
|
|
621
|
+
database is in no migration: the message says which migrations were read, and that such an index
|
|
622
|
+
is not seen.
|
|
623
|
+
|
|
624
|
+
Measured on `main` 190dc8e3595, production code: the literal pattern alone, the rule of
|
|
625
|
+
1.7.0-alpha.33, reported **0** places. This one reports 38 with each module's own migrations, and
|
|
626
|
+
**26** once the modules name `libs/nest/db-main`'s, where the 9 trigram indexes of the monorepo
|
|
627
|
+
are: 12 searches are served and stay silent. The 26 were read one by one: none has a trigram index
|
|
628
|
+
on its expression in any migration (`unaccent(w."searchName")` on an index of `"searchName"`,
|
|
629
|
+
recruitment's searches on a database whose migrations create the extension and no index).
|
|
630
|
+
|
|
592
631
|
### The 19 May incident, `exists-union-correlated-outside`
|
|
593
632
|
|
|
594
633
|
```sql
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hublo/sentinel",
|
|
3
|
-
"version": "1.7.0-alpha.
|
|
3
|
+
"version": "1.7.0-alpha.34",
|
|
4
4
|
"description": "One CLI that guards code health across Hublo repos: shared lint/typescript/build/test presets, static & dynamic analysis, and architecture checks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/roles/sql/presets/shared.json","../src/roles/sql/presets/squawk-rules.json","../src/roles/sql/preset-data.ts","../src/roles/sql/configs/define.ts"],"sourcesContent":["{\n \"migrations\": {\n \"include\": [\"**/migrations/*/migration.sql\"],\n \"exclude\": []\n },\n \"unsafe\": {\n \"includeTests\": true,\n \"tests\": [\n \"**/{test,tests,__tests__,e2e,fixtures,mocks,__mocks__,test-utils}/**\",\n \"**/*.{spec,test,integration-spec,e2e-spec,steps,test-util,mock}.{ts,mts,cts}\"\n ]\n },\n \"ignore\": [\"**/node_modules/**\", \"**/dist/**\", \"**/coverage/**\"],\n \"pgVersion\": \"16.8\",\n \"rules\": {}\n}\n","{\n \"squawk\": \"2.72.0\",\n \"rules\": [\n \"adding-field-with-default\",\n \"adding-foreign-key-constraint\",\n \"adding-not-nullable-field\",\n \"adding-required-field\",\n \"adding-serial-primary-key-field\",\n \"ban-add-column\",\n \"ban-add-composite-attribute\",\n \"ban-add-enum-value\",\n \"ban-alter-database-options\",\n \"ban-alter-domain-with-add-constraint\",\n \"ban-alter-extension\",\n \"ban-alter-function-options\",\n \"ban-alter-generated-expression\",\n \"ban-alter-identity\",\n \"ban-alter-policy-condition\",\n \"ban-alter-policy-roles\",\n \"ban-alter-role-options\",\n \"ban-alter-row-level-security\",\n \"ban-alter-sequence-values\",\n \"ban-alter-system-options\",\n \"ban-alter-view-options\",\n \"ban-char-field\",\n \"ban-concurrent-index-creation-in-transaction\",\n \"ban-create-domain-with-constraint\",\n \"ban-create-policy\",\n \"ban-detach-inheritance\",\n \"ban-disable-trigger\",\n \"ban-drop-column\",\n \"ban-drop-constraint\",\n \"ban-drop-database\",\n \"ban-drop-default\",\n \"ban-drop-domain\",\n \"ban-drop-extension\",\n \"ban-drop-function\",\n \"ban-drop-generated-expression\",\n \"ban-drop-index\",\n \"ban-drop-not-null\",\n \"ban-drop-policy\",\n \"ban-drop-schema\",\n \"ban-drop-sequence\",\n \"ban-drop-table\",\n \"ban-drop-trigger\",\n \"ban-drop-type\",\n \"ban-drop-view\",\n \"ban-duplicate-column-assignments\",\n \"ban-new-write-restriction\",\n \"ban-replace-view-function\",\n \"ban-replica-identity\",\n \"ban-revoke\",\n \"ban-set-default\",\n \"ban-set-schema\",\n \"ban-truncate-cascade\",\n \"ban-uncommitted-transaction\",\n \"changing-column-type\",\n \"constraint-missing-not-valid\",\n \"disallowed-unique-constraint\",\n \"identifier-too-long\",\n \"prefer-bigint-over-int\",\n \"prefer-bigint-over-smallint\",\n \"prefer-identity\",\n \"prefer-repack\",\n \"prefer-robust-stmts\",\n \"prefer-text-field\",\n \"prefer-timestamp-tz\",\n \"renaming-column\",\n \"renaming-object\",\n \"renaming-table\",\n \"require-concurrent-index-creation\",\n \"require-concurrent-index-deletion\",\n \"require-concurrent-partition-detach\",\n \"require-concurrent-reindex\",\n \"require-enum-value-ordering\",\n \"require-lock-timeout\",\n \"require-statement-timeout\",\n \"require-table-schema\",\n \"transaction-nesting\"\n ],\n \"optIn\": [\n \"ban-add-column\",\n \"ban-add-composite-attribute\",\n \"ban-add-enum-value\",\n \"ban-alter-database-options\",\n \"ban-alter-extension\",\n \"ban-alter-function-options\",\n \"ban-alter-generated-expression\",\n \"ban-alter-policy-condition\",\n \"ban-alter-policy-roles\",\n \"ban-alter-role-options\",\n \"ban-alter-row-level-security\",\n \"ban-alter-sequence-values\",\n \"ban-alter-system-options\",\n \"ban-alter-view-options\",\n \"ban-create-policy\",\n \"ban-detach-inheritance\",\n \"ban-disable-trigger\",\n \"ban-drop-index\",\n \"ban-drop-policy\",\n \"ban-drop-trigger\",\n \"ban-new-write-restriction\",\n \"ban-replace-view-function\",\n \"ban-replica-identity\",\n \"ban-revoke\",\n \"ban-set-default\",\n \"require-table-schema\"\n ],\n \"aliases\": {\n \"prefer-timestamptz\": [\"prefer-timestamp-tz\"],\n \"require-timeout-settings\": [\"require-lock-timeout\", \"require-statement-timeout\"]\n }\n}\n","/**\n * The SQL role's values: what it reads, where it writes, and what a module may move.\n *\n * ## What this role guards, and in which order\n *\n * The study behind it (`docs/sql-verification-study.md`, HUB-45374, issue #150) measured where our\n * SQL lives and set the order, cheapest first:\n *\n * 1. **migrations**, read by squawk. On the monorepo (`main` 0eb8be6550d, 2026-11-14): 871\n * `migration.sql` across 21 modules, 135 of them added by 84 pull requests in five weeks.\n * 2. **the `Unsafe` calls** (`$queryRawUnsafe`, `$executeRawUnsafe`), read by a rule of ours. 226\n * calls the same day: 23 in production code, 203 in tests. And `Prisma.raw`, whose text is SQL\n * inside a tagged query, by the same rule under its own name: 97 calls on `main` f12da701121.\n *\n * 3. **the SQL of tagged templates** (`$queryRaw`, `$executeRaw`, `Prisma.sql`), read with\n * PostgreSQL's own parser (`libpg-query`) by rules of ours, the 19 May incident's first (#178):\n * 1 587 templates on `main` 837abe3f29c, 91 % of the production ones read alone.\n *\n * The ORM chain comes later, in this same role.\n *\n * ## Which modules: the ones that hold SQL, whatever their preset\n *\n * Decided from what the module HOLDS, never from its preset, which is the rule sentinel already\n * follows: the build role reads its own Vite config rather than trusting a preset. A preset says\n * which stack a module is written in, not whether it talks to a database. `libs/nest/signal-bus`\n * is `nest` (its code imports `@nestjs/`) and holds no SQL at all, it carries signals over Redis;\n * `libs/nest/db-main` holds 442 of the 871 migrations. Both are `nest`, and only one concerns this\n * role.\n *\n * So the role applies to every preset, like six of the seven before it, and `--init` skips a module\n * holding neither a migration nor an `Unsafe` call. A front end holds neither, so it is skipped\n * with no line of code about front ends. Measured with dry runs on `apps/front/host-admin`,\n * `libs/front/components`, `libs/nest/signal-bus` (skipped), `libs/nest/db-main` and `network`\n * (adopted).\n */\nimport sharedData from './presets/shared.json'\nimport squawkRulesData from './presets/squawk-rules.json'\n\n/** The target this role serves, and the flag that runs it: `sentinel --run --sql`. */\nexport const TARGET = 'sql'\n\n/** The file a module writes at its root to move a setting. Optional at every moment. */\nexport const SQL_CONFIG_FILE = 'sql.config.mjs'\n\n/**\n * Where the files of `--output json|html|markdown` land, inside the module.\n *\n * Its own directory rather than `static-analysis-report/`: two roles writing into one folder would\n * each clear the other's stale files.\n */\nexport const REPORT_DIR = 'sql-report'\n\n/**\n * One script per shape a DEVELOPER runs. `markdown` gets none: it is the pull request comment a CI\n * workflow produces, the decision static analysis took for the same reason.\n */\nexport const SCRIPTS = {\n console: 'sql',\n json: 'sql:json',\n html: 'sql:html',\n} as const\n\n/** A rule's level. `off` is a module's decision, and the report prints it as one. */\nexport type Severity = 'off' | 'warn' | 'error'\n\nexport interface SqlDefaults {\n /** The migration files squawk reads, as globs relative to the module. */\n migrations: {\n /**\n * ⛔ `migration.sql` BY NAME, and that is what keeps the rollback scripts out. Beside the 871\n * migrations sit 385 `down.sql`, 2 `drop.sql` and one `donw.sql`: scripts a human runs by hand,\n * which Prisma never applies. Reading them would report every `DROP` they are made of, for a\n * file that never reaches production through a deploy. Naming the file Prisma applies, rather\n * than excluding the others, also keeps out the misspelling nobody would think to exclude.\n */\n include: string[]\n /** Migrations a module chooses not to read. Empty by default. */\n exclude: string[]\n }\n /** What the `Unsafe` rule reads. */\n unsafe: {\n /**\n * Read the tests too. ON by default: 203 of the 226 `Unsafe` calls are in tests, and a call\n * that is safe today is not safe by construction tomorrow. A module that decides otherwise sets\n * it to false, and the report says so; the decision is the team's.\n */\n includeTests: boolean\n /**\n * What counts as a test, by PATH. Measured on the monorepo before it was written: the filter\n * `*.spec.*` alone let 149 test calls through as production, because `*.integration-spec.ts`,\n * `*.steps.ts`, `tests/database/` and `*.test-util.ts` are all test code and none of them\n * matches it.\n */\n tests: string[]\n }\n /** Directories never read, whatever the includes say. */\n ignore: string[]\n /**\n * The PostgreSQL version squawk checks against, since some rules depend on it.\n *\n * 16.8 is the version the monorepo pins (`postgres:16.8`, in its integration tests and its\n * database tooling). The role reads what the repository declares and never asks production.\n */\n pgVersion: string\n /**\n * Each rule's level, by name. Empty means every rule at its default, `warn` in this version: the\n * role refuses nothing while its adoption runs.\n */\n rules: Record<string, Severity>\n}\n\n/**\n * The role's values, read from `presets/shared.json`: preset data is JSON, never TypeScript, in every\n * role (AGENTS.md, and `tests/role-layout.test.ts` holds it). The reasons for each value are the\n * comments on `SqlDefaults` above, since JSON carries none.\n */\nexport const defaults: SqlDefaults = sharedData as SqlDefaults\n\n/**\n * squawk's rule names, for the version sentinel pins: what `rules` in `sql.config.mjs` may name.\n *\n * Data about the tool rather than a preset, kept beside the presets like `build`'s\n * `requirements.json`. Taken from squawk's own source at the pinned tag\n * (`crates/squawk_linter/src/lib.rs`, the names a finding carries and `is_opt_in`), and held to the\n * binary by a test: every name here is accepted by the installed squawk, and the version here is\n * the version installed, so a squawk bump that renames a rule fails the build instead of a module.\n *\n * - `rules`, the names findings carry. `unused-ignore` is left out: squawk reports it about its own\n * ignore comments, and refuses it in a config.\n * - `optIn`, the rules squawk runs only when a config names them.\n * - `aliases`, names squawk accepts that no finding carries. A level set on one would never meet a\n * finding, so the role refuses it and names the rule(s) it stands for.\n */\nexport interface SquawkRules {\n squawk: string\n rules: string[]\n optIn: string[]\n aliases: Record<string, string[]>\n}\n\nexport const squawkRules: SquawkRules = squawkRulesData\n","/**\n * `defineSql`: what a module imports to declare its own SQL settings.\n *\n * ```js\n * // sql.config.mjs\n * import { defineSql } from '@hublo/sentinel/sql'\n *\n * export default defineSql({\n * root: import.meta.dirname,\n * overrides: { unsafe: { includeTests: false } },\n * })\n * ```\n *\n * The shape of `defineStaticAnalysis`, for the two reasons stated there. A function receives the\n * module's INTENT, the keys it actually passed, and merges them here, so setting one key never\n * drops its siblings: a spread in the module's file would replace the whole `unsafe` block to set\n * `includeTests`, and lose `tests` with nobody seeing it. And the defaults are never copied into a\n * module, so a changed default reaches every module at the next release instead of leaving stale\n * copies behind.\n *\n * `overrides` REPLACES what it names, lists included, and every path it sets lands in `moved`, so\n * the report prints `(module)` beside it: two modules measured with different settings no longer\n * compare, and the reader has to be told.\n */\nimport { isPlainObject } from '../../../shared/deep-merge.js'\nimport { defaults, type SqlDefaults } from '../preset-data.js'\n\ntype DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] }\n\n/** What a module's config file passes. Everything is optional, including the file itself. */\nexport interface SqlInput {\n /** The module's own directory, normally `import.meta.dirname`. */\n root?: string\n /** The seam. Replaces whatever it names, and every path it sets lands in `moved`. */\n overrides?: DeepPartial<SqlDefaults>\n}\n\nexport interface ResolvedSqlConfig extends SqlDefaults {\n /** The module's directory, or null when its config file did not say. */\n root: string | null\n /** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */\n moved: string[]\n}\n\n/**\n * Merge `patch` into `base`, recursively, patch winning.\n *\n * Arrays are REPLACED, never concatenated: a merge that concatenates cannot express \"replace this\n * list\", which is exactly what a team reaching for `overrides` asks for. `rules` is a record, so\n * a module naming one rule keeps the levels of every other.\n */\nfunction mergeInto<T>(base: T, patch: unknown): T {\n if (!isPlainObject(patch)) return base\n if (!isPlainObject(base)) return patch as T\n const out: Record<string, unknown> = { ...base }\n for (const [key, value] of Object.entries(patch)) {\n out[key] = isPlainObject(value) ? mergeInto(out[key], value) : value\n }\n return out as T\n}\n\n/** Every leaf path in `patch`, dotted, so a reader can be told what the module decided. */\nfunction leafPaths(patch: unknown, prefix = ''): string[] {\n if (!isPlainObject(patch)) return prefix ? [prefix] : []\n return Object.entries(patch).flatMap(([key, value]) =>\n leafPaths(value, prefix ? `${prefix}.${key}` : key),\n )\n}\n\n/** The keys `defineSql` reads. */\nconst INPUT_KEYS: readonly string[] = ['root', 'overrides']\n\n/** Resolve a module's declaration against this role's defaults. */\nexport function defineSql(input: SqlInput = {}): ResolvedSqlConfig {\n // ⛔ `override:` for `overrides:` would otherwise resolve to the defaults in silence, the module\n // believing it moved a setting. Thrown, so the loader names the file and the key.\n const unknown = Object.keys(input).filter((key) => !INPUT_KEYS.includes(key))\n if (unknown.length > 0) {\n throw new Error(\n `defineSql takes ${INPUT_KEYS.map((key) => `\\`${key}\\``).join(' and ')}; ` +\n `${unknown.map((key) => `\\`${key}\\``).join(', ')} would be ignored.`,\n )\n }\n return {\n ...mergeInto(defaults, input.overrides),\n root: input.root ?? null,\n moved: leafPaths(input.overrides).sort(),\n }\n}\n"],"mappings":"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","names":[]}
|