@hublo/sentinel 1.7.0-alpha.38 → 1.7.0-alpha.39
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-NYNS4TLN.js → chunk-GYDS3OMU.js} +1 -1
- package/dist/chunk-GYDS3OMU.js.map +1 -0
- package/dist/{chunk-QWZ63CDX.js → chunk-OBI4TDJ7.js} +39 -12
- package/dist/index.js +2 -2
- package/dist/roles/sql/config.d.ts +3 -2
- package/dist/roles/sql/config.js +1 -1
- package/docs/sql-adoption.md +19 -13
- package/package.json +1 -1
- package/dist/chunk-NYNS4TLN.js.map +0 -1
package/dist/bin/sentinel.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
presetNotInstalledYet,
|
|
14
14
|
registerAdapters,
|
|
15
15
|
resolve
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-OBI4TDJ7.js";
|
|
17
17
|
import "../chunk-ZZMYV576.js";
|
|
18
18
|
import {
|
|
19
19
|
resolveContext,
|
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
VERBS
|
|
46
46
|
} from "../chunk-YOFCDKTI.js";
|
|
47
47
|
import "../chunk-QJCZ2EDV.js";
|
|
48
|
-
import "../chunk-
|
|
48
|
+
import "../chunk-GYDS3OMU.js";
|
|
49
49
|
import "../chunk-XYOIXC6A.js";
|
|
50
50
|
import "../chunk-PXTU5MPW.js";
|
|
51
51
|
import "../chunk-U7G2Y6YC.js";
|
|
@@ -0,0 +1 @@
|
|
|
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 \"indexesFrom\": []\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 \"orm\": {\n \"referenceTables\": [],\n \"perRowWrites\": [],\n \"scripts\": [\n \"**/{scripts,backfills,seeders,seeds,load-tests}/**\",\n \"**/seed*.{ts,mts,cts}\",\n \"**/*.seed.{ts,mts,cts}\",\n \"**/*.seed.*.{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 * Other migrations directories, relative to the module, of a database this module queries:\n * never checked, read for their indexes and for the Prisma schema beside them, by\n * `leading-wildcard-like` (trigram indexes) and the rules on Prisma calls (`orm/orm-context.ts`).\n *\n * For a module that queries a database another module migrates. On the monorepo every trigram\n * index is in `libs/nest/db-main` (main 190dc8e3595), and `mission`, `network` or `institution`\n * query its tables: without this, the rule would say of their searches that no index serves\n * them. Empty by default: the module's own migrations only, and the message says so.\n */\n indexesFrom: 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 /** What the rules on Prisma Client calls read beyond the code (`orm/`). */\n orm: {\n /**\n * Small reference tables (a list of types, modes, settings) the module names: a read of one\n * with no index costs nothing, and sentinel cannot know the size of a table. Decided on the\n * ORM study: 24 of the 101 missing indexes found on main were on such tables.\n */\n referenceTables: string[]\n /**\n * The writes the module makes once per row on purpose, `{ file, call: 'model.operation',\n * reason }`: `prisma-write-in-loop` stays silent on them. Decided on the ORM study: 22 of the\n * 113 writes in a loop found on main were deliberate.\n */\n perRowWrites: Array<{ file: string; call: string; reason: string }>\n /**\n * The module's one-off scripts: a backfill, a seeder, a load test, which may create their own\n * PrismaClient (`prisma-new-client` stays silent there). Measured on the monorepo's main: every\n * `new PrismaClient` outside tests is in one of these folders.\n */\n scripts: 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\n/**\n * A config another version of `defineSql` resolved, with this version's defaults under it.\n *\n * ⛔ A module's `sql.config.mjs` imports `defineSql` from the sentinel its own `node_modules` holds,\n * which may be older than the one running: a setting added since (`migrations.indexesFrom`,\n * 1.7.0-alpha.34) is then missing, and the rule reading it threw, its findings dropped with nothing\n * said (found on the alpha.34 replay). Every value the module resolved is kept; only a missing\n * setting takes the default.\n */\nexport function withDefaults(resolved: ResolvedSqlConfig): ResolvedSqlConfig {\n return mergeInto<SqlDefaults>(defaults, resolved) as ResolvedSqlConfig\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE,YAAc;AAAA,IACZ,SAAW,CAAC,+BAA+B;AAAA,IAC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IAAM,aAAgC,CAAC,QAAQ,WAAW;AAGnD,SAAS,UAAU,QAAkB,CAAC,GAAsB;AAGjE,QAAM,UAAU,OAAO,KAAK,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW,SAAS,GAAG,CAAC;AAC5E,MAAI,QAAQ,SAAS,GAAG;AACtB,UAAM,IAAI;AAAA,MACR,mBAAmB,WAAW,IAAI,CAAC,QAAQ,KAAK,GAAG,IAAI,EAAE,KAAK,OAAO,CAAC,KACjE,QAAQ,IAAI,CAAC,QAAQ,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC;AAAA,IACpD;AAAA,EACF;AACA,SAAO;AAAA,IACL,GAAG,UAAU,UAAU,MAAM,SAAS;AAAA,IACtC,MAAM,MAAM,QAAQ;AAAA,IACpB,OAAO,UAAU,MAAM,SAAS,EAAE,KAAK;AAAA,EACzC;AACF;AAWO,SAAS,aAAa,UAAgD;AAC3E,SAAO,UAAuB,UAAU,QAAQ;AAClD;","names":[]}
|
|
@@ -145,7 +145,7 @@ import {
|
|
|
145
145
|
defineSql,
|
|
146
146
|
squawkRules,
|
|
147
147
|
withDefaults
|
|
148
|
-
} from "./chunk-
|
|
148
|
+
} from "./chunk-GYDS3OMU.js";
|
|
149
149
|
import {
|
|
150
150
|
CODE_CHURN_CONFIG_FILE,
|
|
151
151
|
REPORT_DIR as REPORT_DIR2,
|
|
@@ -15509,7 +15509,7 @@ function keyName(property) {
|
|
|
15509
15509
|
|
|
15510
15510
|
// src/roles/sql/orm/check-orm.ts
|
|
15511
15511
|
async function checkOrmCalls(cwd, files, readFile, { rules, context: context2 }) {
|
|
15512
|
-
const run = { calls: 0, writes: 0, unparsed: [], findings: [] };
|
|
15512
|
+
const run = { calls: 0, writes: 0, schemas: [], unparsed: [], findings: [] };
|
|
15513
15513
|
if (rules.length === 0 || files.length === 0) return run;
|
|
15514
15514
|
const loaded2 = await parserLoaded();
|
|
15515
15515
|
if (!loaded2.ok) {
|
|
@@ -15524,6 +15524,7 @@ async function checkOrmCalls(cwd, files, readFile, { rules, context: context2 })
|
|
|
15524
15524
|
}
|
|
15525
15525
|
checkFile({ file, text }, rules, context2, run);
|
|
15526
15526
|
}
|
|
15527
|
+
if (run.calls + run.writes > 0) run.schemas = context2.schemas();
|
|
15527
15528
|
return run;
|
|
15528
15529
|
}
|
|
15529
15530
|
function checkFile(input, rules, context2, run) {
|
|
@@ -15980,6 +15981,7 @@ function blockAttribute(model, line) {
|
|
|
15980
15981
|
var clientNameOf = (model) => model.name.charAt(0).toLowerCase() + model.name.slice(1);
|
|
15981
15982
|
|
|
15982
15983
|
// src/roles/sql/orm/orm-context.ts
|
|
15984
|
+
var NO_SCHEMA = "no Prisma schema on PostgreSQL was read, so these calls are not judged: a module that queries another module's database names that database's migrations in `migrations.indexesFrom` (its schema is read beside them).";
|
|
15983
15985
|
function ormContext(cwd, settings) {
|
|
15984
15986
|
let read2;
|
|
15985
15987
|
const models = () => {
|
|
@@ -15994,7 +15996,8 @@ function ormContext(cwd, settings) {
|
|
|
15994
15996
|
isPostgreSqlModel: (name) => models().postgres.has(name) && !models().others.has(name),
|
|
15995
15997
|
referenceTables: new Set(settings.referenceTables),
|
|
15996
15998
|
perRowWrites: settings.perRowWrites ?? [],
|
|
15997
|
-
scripts: settings.scripts ?? []
|
|
15999
|
+
scripts: settings.scripts ?? [],
|
|
16000
|
+
schemas: () => models().schemas
|
|
15998
16001
|
};
|
|
15999
16002
|
}
|
|
16000
16003
|
function readModels(cwd, settings) {
|
|
@@ -16013,6 +16016,7 @@ function readModels(cwd, settings) {
|
|
|
16013
16016
|
const judged = /* @__PURE__ */ new Map();
|
|
16014
16017
|
const postgres = /* @__PURE__ */ new Set();
|
|
16015
16018
|
const others = /* @__PURE__ */ new Set();
|
|
16019
|
+
const read2 = [];
|
|
16016
16020
|
for (const schema of new Set(schemas)) {
|
|
16017
16021
|
const text = readText(join56(cwd, schema));
|
|
16018
16022
|
if (text === void 0) continue;
|
|
@@ -16020,12 +16024,13 @@ function readModels(cwd, settings) {
|
|
|
16020
16024
|
const declared = parsed2.provider === "postgresql" ? postgres : others;
|
|
16021
16025
|
for (const model of parsed2.models) declared.add(clientNameOf(model));
|
|
16022
16026
|
if (parsed2.provider !== "postgresql") continue;
|
|
16027
|
+
read2.push(schema);
|
|
16023
16028
|
for (const one of judgedOf(cwd, schema, parsed2)) {
|
|
16024
16029
|
const name = clientNameOf(one.model);
|
|
16025
16030
|
judged.set(name, [...judged.get(name) ?? [], one]);
|
|
16026
16031
|
}
|
|
16027
16032
|
}
|
|
16028
|
-
return { judged, postgres, others };
|
|
16033
|
+
return { judged, postgres, others, schemas: read2.sort() };
|
|
16029
16034
|
}
|
|
16030
16035
|
function judgedModelsOf(cwd, schema) {
|
|
16031
16036
|
const text = readText(join56(cwd, schema));
|
|
@@ -17164,7 +17169,9 @@ function readCard(report) {
|
|
|
17164
17169
|
report.read.length > 0 ? plural2(report.read.length, "migration") : null,
|
|
17165
17170
|
report.unsafe.read.length > 0 ? `${plural2(report.unsafe.read.length, "file")} with raw SQL calls` : null,
|
|
17166
17171
|
report.templates.templates > 0 ? plural2(report.templates.templates, "SQL template") : null,
|
|
17167
|
-
(report.orm?.calls ?? 0) > 0 ? plural2(report.orm?.calls ?? 0, "Prisma read") : null
|
|
17172
|
+
(report.orm?.calls ?? 0) > 0 ? plural2(report.orm?.calls ?? 0, "Prisma read") : null,
|
|
17173
|
+
(report.orm?.writes ?? 0) > 0 ? plural2(report.orm?.writes ?? 0, "Prisma write") : null,
|
|
17174
|
+
(report.schemaChanges?.length ?? 0) > 0 ? plural2(report.schemaChanges?.length ?? 0, "Prisma schema") : null
|
|
17168
17175
|
].filter((part) => part !== null);
|
|
17169
17176
|
const notRead = notReadCount(report);
|
|
17170
17177
|
return `<div class="kpi${notRead > 0 ? " band-above" : ""}">
|
|
@@ -17368,7 +17375,12 @@ function ormLine(report) {
|
|
|
17368
17375
|
if (orm.read.length === 0) {
|
|
17369
17376
|
return `<p><b>Prisma reads.</b> ${plural2(orm.files.length, "file")} of the module ${orm.files.length === 1 ? "makes" : "make"} Prisma Client reads; none is added or changed by this branch, so none is read.</p>`;
|
|
17370
17377
|
}
|
|
17371
|
-
|
|
17378
|
+
const writes = orm.writes > 0 ? ` and ${plural2(orm.writes, "write")} (<code>create</code>, <code>update</code>, <code>upsert</code>, <code>delete</code>)` : "";
|
|
17379
|
+
return `<p><b>Prisma calls.</b> ${plural2(orm.calls, "Prisma Client read")} (<code>findMany</code>, <code>findFirst</code>, <code>findUnique</code>)${writes} in the ${plural2(orm.read.length, "file")} this branch adds or changes, against the module's Prisma schemas and the indexes their migrations create.</p>${noSchema(orm)}${fileList(orm.read)}`;
|
|
17380
|
+
}
|
|
17381
|
+
function noSchema(orm) {
|
|
17382
|
+
if (orm.calls + orm.writes === 0 || orm.schemas === void 0 || orm.schemas.length > 0) return "";
|
|
17383
|
+
return `<p class="note">${prose2(NO_SCHEMA)}</p>`;
|
|
17372
17384
|
}
|
|
17373
17385
|
function fileList(files) {
|
|
17374
17386
|
if (files.length === 0) return "";
|
|
@@ -17444,6 +17456,7 @@ function renderMarkdown5(report) {
|
|
|
17444
17456
|
...syntaxBlock(report),
|
|
17445
17457
|
...unsafeBlock(report),
|
|
17446
17458
|
...templatesLine2(report),
|
|
17459
|
+
...noSchemaLine(report),
|
|
17447
17460
|
...fileBlocks(report),
|
|
17448
17461
|
"",
|
|
17449
17462
|
`<sub>Every place, with the SQL behind it and sentinel's notes, is in the \`sql.html\` this run keeps. Measured by sentinel ${report.sentinel}.</sub>`,
|
|
@@ -17457,7 +17470,9 @@ function headline4(report) {
|
|
|
17457
17470
|
const files = report.unsafe.read.length;
|
|
17458
17471
|
const templates = report.templates.read.length > 0 ? report.templates.templates : 0;
|
|
17459
17472
|
const ormCalls = report.orm !== void 0 && report.orm.read.length > 0 ? report.orm.calls : 0;
|
|
17460
|
-
|
|
17473
|
+
const ormWrites = report.orm !== void 0 && report.orm.read.length > 0 ? report.orm.writes : 0;
|
|
17474
|
+
const schemas = report.schemaChanges?.length ?? 0;
|
|
17475
|
+
if (migrations === 0 && files === 0 && templates === 0 && ormCalls === 0 && ormWrites === 0 && schemas === 0) {
|
|
17461
17476
|
return `No migration or raw SQL call added or changed by this branch, ${against}: nothing to check.`;
|
|
17462
17477
|
}
|
|
17463
17478
|
const counts = (count, what, noun) => `**${count}** ${what} ${noun}${count === 1 ? "" : "s"}`;
|
|
@@ -17469,7 +17484,9 @@ function headline4(report) {
|
|
|
17469
17484
|
...migrations > 0 ? [`**${migrations}** migration${migrations === 1 ? "" : "s"}`] : [],
|
|
17470
17485
|
...files > 0 ? calls : [],
|
|
17471
17486
|
...templates > 0 ? [counts(templates, "SQL", "template")] : [],
|
|
17472
|
-
...ormCalls > 0 ? [counts(ormCalls, "Prisma", "read")] : []
|
|
17487
|
+
...ormCalls > 0 ? [counts(ormCalls, "Prisma", "read")] : [],
|
|
17488
|
+
...ormWrites > 0 ? [counts(ormWrites, "Prisma", "write")] : [],
|
|
17489
|
+
...schemas > 0 ? [counts(schemas, "Prisma", "schema")] : []
|
|
17473
17490
|
];
|
|
17474
17491
|
const codeFiles2 = (/* @__PURE__ */ new Set([
|
|
17475
17492
|
...report.unsafe.read,
|
|
@@ -17485,7 +17502,7 @@ function headline4(report) {
|
|
|
17485
17502
|
return `Read ${read2} this branch adds or changes, ${against}: ${found}.`;
|
|
17486
17503
|
}
|
|
17487
17504
|
function readAnything(report) {
|
|
17488
|
-
return report.read.length > 0 || report.unsafe.read.length > 0 || report.templates.read.length > 0 || (report.orm?.read.length ?? 0) > 0;
|
|
17505
|
+
return report.read.length > 0 || report.unsafe.read.length > 0 || report.templates.read.length > 0 || (report.orm?.read.length ?? 0) > 0 || (report.schemaChanges?.length ?? 0) > 0;
|
|
17489
17506
|
}
|
|
17490
17507
|
function fileBlocks(report) {
|
|
17491
17508
|
const findings = report.findings.filter((finding3) => finding3.rule !== SYNTAX_ERROR);
|
|
@@ -17550,6 +17567,12 @@ function syntaxBlock(report) {
|
|
|
17550
17567
|
)
|
|
17551
17568
|
];
|
|
17552
17569
|
}
|
|
17570
|
+
function noSchemaLine(report) {
|
|
17571
|
+
const orm = report.orm;
|
|
17572
|
+
if (orm === void 0 || orm.calls + orm.writes === 0 || orm.schemas === void 0 || orm.schemas.length > 0)
|
|
17573
|
+
return [];
|
|
17574
|
+
return ["", `\u26A0\uFE0F **Prisma calls not judged**: ${NO_SCHEMA}`];
|
|
17575
|
+
}
|
|
17553
17576
|
function templatesLine2(report) {
|
|
17554
17577
|
const { read: read2, templates, parsed: parsed2, unread, unparsed } = report.templates;
|
|
17555
17578
|
if (read2.length === 0) return [];
|
|
@@ -18200,6 +18223,7 @@ function ormLines(orm) {
|
|
|
18200
18223
|
}
|
|
18201
18224
|
return [
|
|
18202
18225
|
`read ${orm.calls} Prisma Client read(s) (findMany, findFirst, findUnique) and ${orm.writes} write(s) (create, update, upsert, delete) in the ${orm.read} file(s) this branch adds or changes.`,
|
|
18226
|
+
...orm.calls + orm.writes > 0 && orm.schemas.length === 0 ? [` ${NO_SCHEMA}`] : [],
|
|
18203
18227
|
...orm.unparsed.map(({ file, reason }) => ` ${file}: ${reason}`)
|
|
18204
18228
|
];
|
|
18205
18229
|
}
|
|
@@ -18514,6 +18538,7 @@ var SquawkAdapter = class extends BaseAdapter {
|
|
|
18514
18538
|
read: ormCode.length,
|
|
18515
18539
|
calls: orm.calls,
|
|
18516
18540
|
writes: orm.writes,
|
|
18541
|
+
schemas: orm.schemas,
|
|
18517
18542
|
unparsed: orm.unparsed
|
|
18518
18543
|
}
|
|
18519
18544
|
};
|
|
@@ -18532,7 +18557,7 @@ var SquawkAdapter = class extends BaseAdapter {
|
|
|
18532
18557
|
reportOf(
|
|
18533
18558
|
ctx,
|
|
18534
18559
|
config,
|
|
18535
|
-
{ reading, read: read2, code: unsafeOff ? [] : code, templateCode, ormCode },
|
|
18560
|
+
{ reading, read: read2, code: unsafeOff ? [] : code, templateCode, ormCode, schemaCode },
|
|
18536
18561
|
{
|
|
18537
18562
|
outcome,
|
|
18538
18563
|
findings
|
|
@@ -18642,7 +18667,7 @@ function formatterReason(pass) {
|
|
|
18642
18667
|
return ` (${said.length > 200 ? `${said.slice(0, 197)}\u2026` : said})`;
|
|
18643
18668
|
}
|
|
18644
18669
|
function describeRun(outcome, reading, config, quietNote = null) {
|
|
18645
|
-
const holdsCode = reading.unsafeFiles > 0 || reading.templates.length > 0;
|
|
18670
|
+
const holdsCode = reading.unsafeFiles > 0 || reading.templates.length > 0 || reading.orm.length > 0;
|
|
18646
18671
|
if (outcome.total === 0 && !holdsCode && outcome.findings.length === 0) {
|
|
18647
18672
|
return [
|
|
18648
18673
|
`nothing to read here: no migration (${config.migrations.include.join(", ")}) and no raw SQL call in ${reading.codeFiles} TypeScript file(s).`,
|
|
@@ -18794,7 +18819,7 @@ function metricsOf(outcome) {
|
|
|
18794
18819
|
};
|
|
18795
18820
|
}
|
|
18796
18821
|
function reportOf(ctx, config, files, result) {
|
|
18797
|
-
const { reading, read: read2, code, templateCode, ormCode } = files;
|
|
18822
|
+
const { reading, read: read2, code, templateCode, ormCode, schemaCode } = files;
|
|
18798
18823
|
const { outcome, findings } = result;
|
|
18799
18824
|
return {
|
|
18800
18825
|
module: ctx.module,
|
|
@@ -18827,8 +18852,10 @@ function reportOf(ctx, config, files, result) {
|
|
|
18827
18852
|
read: [...ormCode],
|
|
18828
18853
|
calls: outcome.orm?.calls ?? 0,
|
|
18829
18854
|
writes: outcome.orm?.writes ?? 0,
|
|
18855
|
+
schemas: [...outcome.orm?.schemas ?? []],
|
|
18830
18856
|
unparsed: [...outcome.orm?.unparsed ?? []]
|
|
18831
18857
|
},
|
|
18858
|
+
schemaChanges: [...schemaCode],
|
|
18832
18859
|
settings: settingsList2(config)
|
|
18833
18860
|
};
|
|
18834
18861
|
}
|
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-OBI4TDJ7.js";
|
|
10
10
|
import "./chunk-ZZMYV576.js";
|
|
11
11
|
import {
|
|
12
12
|
BaseAdapter
|
|
@@ -20,7 +20,7 @@ import "./chunk-QXFCZON7.js";
|
|
|
20
20
|
import "./chunk-KKHKRY7P.js";
|
|
21
21
|
import "./chunk-YOFCDKTI.js";
|
|
22
22
|
import "./chunk-QJCZ2EDV.js";
|
|
23
|
-
import "./chunk-
|
|
23
|
+
import "./chunk-GYDS3OMU.js";
|
|
24
24
|
import "./chunk-XYOIXC6A.js";
|
|
25
25
|
import "./chunk-PXTU5MPW.js";
|
|
26
26
|
import "./chunk-U7G2Y6YC.js";
|
|
@@ -14,8 +14,9 @@ interface SqlDefaults {
|
|
|
14
14
|
/** Migrations a module chooses not to read. Empty by default. */
|
|
15
15
|
exclude: string[];
|
|
16
16
|
/**
|
|
17
|
-
* Other migrations directories, relative to the module,
|
|
18
|
-
*
|
|
17
|
+
* Other migrations directories, relative to the module, of a database this module queries:
|
|
18
|
+
* never checked, read for their indexes and for the Prisma schema beside them, by
|
|
19
|
+
* `leading-wildcard-like` (trigram indexes) and the rules on Prisma calls (`orm/orm-context.ts`).
|
|
19
20
|
*
|
|
20
21
|
* For a module that queries a database another module migrates. On the monorepo every trigram
|
|
21
22
|
* index is in `libs/nest/db-main` (main 190dc8e3595), and `mission`, `network` or `institution`
|
package/dist/roles/sql/config.js
CHANGED
package/docs/sql-adoption.md
CHANGED
|
@@ -180,19 +180,19 @@ 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 | 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
|
|
188
|
-
| `orm.referenceTables` | `[]` | small reference tables the module names: `prisma-filter-without-index` stays silent on them
|
|
189
|
-
| `orm.perRowWrites` | `[]` | writes made once per row on purpose, `{ file, call: 'model.operation', reason }`: `prisma-write-in-loop` stays silent on them
|
|
190
|
-
| `orm.scripts` | backfills, seeders, scripts, load tests | the module's one-off scripts: `prisma-new-client` stays silent there
|
|
191
|
-
| `unsafe.includeTests` | `true` | whether calls in test files are checked, by both rules
|
|
192
|
-
| `unsafe.tests` | test folders and `*.spec`/`*.test`/… files | what counts as a test file
|
|
193
|
-
| `ignore` | `node_modules`, `dist`, `coverage` | never read, by either check
|
|
194
|
-
| `pgVersion` | `"16.8"` | the PostgreSQL version squawk checks against
|
|
195
|
-
| `rules` | `{}`, every rule at its default | a level per rule, by its name
|
|
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, relative to the module, of a database this module queries: their indexes, and the Prisma schema beside them, are read by `leading-wildcard-like` and the rules on Prisma calls, never checked |
|
|
188
|
+
| `orm.referenceTables` | `[]` | small reference tables the module names: `prisma-filter-without-index` stays silent on them |
|
|
189
|
+
| `orm.perRowWrites` | `[]` | writes made once per row on purpose, `{ file, call: 'model.operation', reason }`: `prisma-write-in-loop` stays silent on them |
|
|
190
|
+
| `orm.scripts` | backfills, seeders, scripts, load tests | the module's one-off scripts: `prisma-new-client` stays silent there |
|
|
191
|
+
| `unsafe.includeTests` | `true` | whether calls in test files are checked, by both rules |
|
|
192
|
+
| `unsafe.tests` | test folders and `*.spec`/`*.test`/… files | what counts as a test file |
|
|
193
|
+
| `ignore` | `node_modules`, `dist`, `coverage` | never read, by either check |
|
|
194
|
+
| `pgVersion` | `"16.8"` | the PostgreSQL version squawk checks against |
|
|
195
|
+
| `rules` | `{}`, every rule at its default | a level per rule, by its name |
|
|
196
196
|
|
|
197
197
|
An example that blocks two rules, silences one and turns an opt-in rule on:
|
|
198
198
|
|
|
@@ -642,6 +642,12 @@ call in the TypeScript: a filter (`where`) whose columns no index starts with ma
|
|
|
642
642
|
every row of the table. Prisma's own guide asks for it: "index fields used in where"
|
|
643
643
|
([best practices](https://www.prisma.io/docs/orm/v7/more/best-practices)).
|
|
644
644
|
|
|
645
|
+
**A module with no Prisma schema of its own**, one that queries another module's database (on the
|
|
646
|
+
monorepo, `network` and `mission` read db-main's tables), names that database's migrations in
|
|
647
|
+
`migrations.indexesFrom`, as above. Without it, no rule on Prisma calls has a schema to judge them
|
|
648
|
+
against, and the report says so on the line that counts the reads, rather than a silent "no
|
|
649
|
+
finding" (found validating 1.7.0-alpha.38).
|
|
650
|
+
|
|
645
651
|
What it reads: the module's Prisma schemas (`*.prisma`) and the one beside each folder
|
|
646
652
|
`migrations.indexesFrom` names, and the indexes the migrations beside each schema create, since a
|
|
647
653
|
schema does not declare them all (db-main's migrations create 458 where its schema declares 361).
|
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.39",
|
|
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 \"indexesFrom\": []\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 \"orm\": {\n \"referenceTables\": [],\n \"perRowWrites\": [],\n \"scripts\": [\n \"**/{scripts,backfills,seeders,seeds,load-tests}/**\",\n \"**/seed*.{ts,mts,cts}\",\n \"**/*.seed.{ts,mts,cts}\",\n \"**/*.seed.*.{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 * Other migrations directories, relative to the module, whose INDEXES this module's queries\n * use: never checked, only read for the trigram indexes `leading-wildcard-like` asks about.\n *\n * For a module that queries a database another module migrates. On the monorepo every trigram\n * index is in `libs/nest/db-main` (main 190dc8e3595), and `mission`, `network` or `institution`\n * query its tables: without this, the rule would say of their searches that no index serves\n * them. Empty by default: the module's own migrations only, and the message says so.\n */\n indexesFrom: 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 /** What the rules on Prisma Client calls read beyond the code (`orm/`). */\n orm: {\n /**\n * Small reference tables (a list of types, modes, settings) the module names: a read of one\n * with no index costs nothing, and sentinel cannot know the size of a table. Decided on the\n * ORM study: 24 of the 101 missing indexes found on main were on such tables.\n */\n referenceTables: string[]\n /**\n * The writes the module makes once per row on purpose, `{ file, call: 'model.operation',\n * reason }`: `prisma-write-in-loop` stays silent on them. Decided on the ORM study: 22 of the\n * 113 writes in a loop found on main were deliberate.\n */\n perRowWrites: Array<{ file: string; call: string; reason: string }>\n /**\n * The module's one-off scripts: a backfill, a seeder, a load test, which may create their own\n * PrismaClient (`prisma-new-client` stays silent there). Measured on the monorepo's main: every\n * `new PrismaClient` outside tests is in one of these folders.\n */\n scripts: 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\n/**\n * A config another version of `defineSql` resolved, with this version's defaults under it.\n *\n * ⛔ A module's `sql.config.mjs` imports `defineSql` from the sentinel its own `node_modules` holds,\n * which may be older than the one running: a setting added since (`migrations.indexesFrom`,\n * 1.7.0-alpha.34) is then missing, and the rule reading it threw, its findings dropped with nothing\n * said (found on the alpha.34 replay). Every value the module resolved is kept; only a missing\n * setting takes the default.\n */\nexport function withDefaults(resolved: ResolvedSqlConfig): ResolvedSqlConfig {\n return mergeInto<SqlDefaults>(defaults, resolved) as ResolvedSqlConfig\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE,YAAc;AAAA,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