@starci/eslint-canon-be 3.27.2 → 3.28.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.28.0 - 2026-11-20
4
+
5
+ - Changed: one app edition (R212, owner ruling 2026-11-20). The edition gate (`pluginForEdition`) is gone: every rule of the plugin runs for every app. Requires @starci/hfs ~6.14.0.
6
+ - Removed: `sql-text-only` and `no-query-builder` (R36 BE_SQL_OUTSIDE_PERSISTENCE, a full-only rule no app ran); R334 `no-raw-sql` holds the persistence boundary. `event-bus-lite-shape` and the lite entity list of `module-layering` judge every app.
7
+
8
+ ## 3.27.3 - 2026-11-18
9
+
10
+ - Fixed (`no-raw-sql`): the nivoos SDK's typed object read, `reach.objects(Type).query({ where, sort, limit })`, is no SQL: a `.query(` whose receiver is an `.objects(...)` call, in a file that imports `@starci/nivoos-sdk`, passes. Any other `.query(` in that file is still refused.
11
+ - Fixed (`schema-bounded`): a record keyed by a closed `z.enum` (`z.record`, `z.partialRecord`, `z.looseRecord`) is bounded by its keys. The nivoos package check refuses `.refine` as code, so the enum key is the bound a package schema can state; the `.refine` form stays accepted elsewhere.
12
+
3
13
  ## 3.27.2 - 2026-11-18
4
14
 
5
15
  - Changed (`lib/nivoos-profile.ts`): the nivoos authoring profile no longer applies `no-non-ascii-source` to a declared package (Vietnamese in literals, comments and identifiers); the literal-only narrowing inside the rule is removed and the rule is listed in `NIVOOS_RELAXED` with its reason. An undeclared package keeps the whole rule.
package/README.md CHANGED
@@ -66,7 +66,7 @@ A sample, not the list:
66
66
  | **Log safety** | A call on the `Logger` port (found by the receiver's type) passes no `Secret` or `Pii` value and no value named like a credential or a personal identifier (`no-secret-in-log`); a constructed error (its type derives from `Error`) carries no `Secret` value and no text value named like a credential (`no-secret-in-error`) |
67
67
  | **Async and types** | An `async` function awaits; handlers and public methods declare a return type; no `Function` type, no `eval`; an inline object type takes a name; no `const enum`. Casts, `x!` and `any` are refused in every file, specs included, by the typescript-eslint rules the factory turns on (`async-needs-await`, `explicit-handler-return-type`, `no-function-or-eval`, `no-inline-param-type`, `no-inline-object-type`, `no-const-enum`) |
68
68
  | **Migrations and input** | A migration's `down()` reverses its `up()`; every property of an input class has the `class-validator` decorators its type calls for (string `@MaxLength`, enum `@IsEnum`, array `@ArrayMaxSize`, nested `@ValidateNested()` and `@Type`); reads page by cursor, never by `skip`, `offset` or `OFFSET`; a door opened for `PublicReason.AuthHandshake` or `PublicReason.SignedWebhook` carries `RateTier.Strict` of `platform/http-security` on the method or its class (`migration-down-reversible`, `input-bounded`, `no-offset-pagination`, `auth-door-strict-rate-tier`) |
69
- | **Boundary schema** (R304, R305) | `zod` reads only boundary data that never reaches a DTO (a provider response, model output, a queue or outbox payload read back): it is imported only from a `<name>.schema.ts` of a domain, platform or integrations owner, or from any file of a root workspace package (tier `package`: `packages/<name>/`, whose node, block and vocabulary contracts are zod schemas), never in a feature, a transport door or a `dto/` folder, and a schema file imports no `class-validator`, `class-transformer` or `@nestjs/graphql` (`schema-place`) and holds only zod values and types (`schema-file-values-only`; its spec is exempt from the testing module of R281 only while this holds); every string, array, set, record and map of a schema has an upper bound and `z.any()`, `z.unknown()` and `z.json()` do not exist (`schema-bounded`) |
69
+ | **Boundary schema** (R304, R305) | `zod` reads only boundary data that never reaches a DTO (a provider response, model output, a queue or outbox payload read back): it is imported only from a `<name>.schema.ts` of a domain, platform or integrations owner, or from any file of a root workspace package (tier `package`: `packages/<name>/`, whose node, block and vocabulary contracts are zod schemas), never in a feature, a transport door or a `dto/` folder, and a schema file imports no `class-validator`, `class-transformer` or `@nestjs/graphql` (`schema-place`) and holds only zod values and types (`schema-file-values-only`; its spec is exempt from the testing module of R281 only while this holds); every string, array, set, record and map of a schema has an upper bound (a record by a refinement on its entry count or by a closed `z.enum` key set, the bound a nivoos package schema can state) and `z.any()`, `z.unknown()` and `z.json()` do not exist (`schema-bounded`) |
70
70
  | **Spec quality** | A spec does not read repository source with `fs` (`spec-no-source-read`); the borrowed `consistent-type-assertions` (`never`) and `no-non-null-assertion` leave no `as` and no `x!` in a spec, and `no-ambient-clock` and `no-direct-env-read` cover specs, so no `Date.now()`, argless `new Date()` or `process.env`. A unit spec is `<name>.service.spec.ts`: it builds its subject with `Test.createTestingModule({ providers })` from `@nestjs/testing`, `.compile()` and `moduleRef.get(...)` (`spec-builds-with-testing-module`), never `new` on the service (`spec-no-new-subject`), no `imports` key and no `override*` (`spec-module-definition-only-providers`), no `jest.mock`/`doMock`/`unstable_mockModule`/`requireMock` of an own module or a library (`spec-no-module-mock`), no cast-laundering helper in a spec or fixture: a return-only generic, an `unknown` handed back as another type, `JSON.parse(JSON.stringify(x))`, `Object.assign(new X(), y)` returned as another type (`no-return-only-generic`); a provider `{ provide: TOKEN, useValue: X }` takes X from the matching `@starci/jest-preset` double, the token table being `ruleParams.be.specDoubles` of the slot manifest (`spec-infra-double-from-kit`); a unit spec asserts exact values, never `expect.any(String)`, `expect.any(Number)` or `expect.any(Date)` (`expect` being the jest global or the `@jest/globals` import): ids come from `fakeIds()` and dates from `FakeClock` (`spec-exact-values`); the EntityManager double is the kit's `mockEntityManager()`/`fakeTransaction()`, never ad hoc (`spec-typed-entity-manager`); test data goes through builders, see the **Test data builders** row |
71
71
  | **Test data builders** (R98 to R101) | Builders live only in `src/tests/fixtures/builders/<area>.builder.ts`: a module of the test tree that exports a function creating persisted rows through an EntityManager, DataSource or QueryRunner is a builder wherever it sits (`persisting-builder-in-builders-slot`, R98); a spec never runs a raw INSERT/UPDATE/DELETE or a direct write (`save`, `insert`, `upsert`, `update`, `delete`, `remove`) on a typeorm receiver and never builds the same `@Entity` class as an object literal twice (`spec-no-raw-insert`, `spec-no-repeated-row-literal`, R99); a builder never asserts and has deterministic defaults (`builder-arranges-only`, R101); nothing under `src/tests` disables or drops a constraint (`tests-keep-constraints`, R100) |
72
72
  | **CQRS** | A message extends `Command<R>` / `Query<R>` from `@nestjs/cqrs`, carries one `readonly params: ExecuteParams<X>` (no entity reachable from `X`), a handler extends `ICQRSHandler` and overrides `process`; a handler is thin: it injects only `*Service` classes and the Logger, and `process` is one `return this.<service>.<method>(...)` with no branch, loop, EntityManager or second call (`handler-is-thin`); no `*.use-case.ts`, no forwarder service, no `EventBus`, `@nestjs/event-emitter`, `EventEmitter` or RxJS `Subject` constructed or extended, and no class that stores callbacks other code registers (`handler-overrides-process`, `message-carries-params-only`, `message-typed-result`, `execute-params-shape`, `no-use-case`, `no-event-bus`) |
@@ -12,7 +12,9 @@
12
12
  * (a transport door answers to `class-validator`), never in a `dto/` folder, and a schema file does not also carry
13
13
  * `class-validator` or a GraphQL type.
14
14
  * - `schema-bounded` (R305) holds the cost. Every string, array, set, map and record a schema builds has an upper bound
15
- * (`.max(n)`, `.length(n)`, `.size(n)`, or for a record and a map a `.refine`/`.check` on its entry count), and `z.any()`,
15
+ * (`.max(n)`, `.length(n)`, `.size(n)`; a map a `.refine`/`.check` on its entry count; a record either that or a closed key set,
16
+ * `z.record(z.enum([...]), value)`, whose size is its keys' count and which is pure data: the nivoos package check refuses a
17
+ * `.refine` as code, so the enum key is the bound a package schema can state), and `z.any()`,
16
18
  * `z.unknown()` and `z.json()` are refused: an unbounded array whose elements all fail validation allocates an issue each
17
19
  * (GHSA-mrhx-c7xc-m3w5), and an unbounded string is an unbounded cost whatever the zod version.
18
20
  */
@@ -34,6 +36,10 @@ const ISO_STRINGY = new Set(["datetime", "date", "time", "duration"]);
34
36
  const COUNTED = new Set(["array", "set"]);
35
37
  /** Constructors whose entry count only a refinement can bound. */
36
38
  const REFINED = new Set(["record", "looseRecord", "partialRecord", "map"]);
39
+ /** The record constructors: an enum key closes their entry count. */
40
+ const RECORDS = new Set(["record", "looseRecord", "partialRecord"]);
41
+ /** The key constructor that closes a record's entry count. */
42
+ const CLOSED_KEY = "enum";
37
43
  /** Constructors that accept anything: refused outright. */
38
44
  const OPEN = new Set(["any", "unknown", "json"]);
39
45
  /** The chain members that bound a string or a counted container. */
@@ -96,7 +102,7 @@ export const schemaBounded = {
96
102
  messages: {
97
103
  string: "`z.{{name}}()` has no `.max(n)` or `.length(n)`, so a string of any length is accepted. Bound it: `z.{{name}}().max(200)`.",
98
104
  counted: "`z.{{name}}(...)` has no `.max(n)`, `.length(n)` or `.size(n)`, so a collection of any count is accepted (and every failing element allocates an issue). Bound it: `z.{{name}}(item).max(100)`.",
99
- refined: "`z.{{name}}(...)` has no bound on its entry count. Add `.refine((entries) => Object.keys(entries).length <= N)` (a `Map`: `.size`), or key it by a `z.enum` so its size is closed.",
105
+ refined: "`z.{{name}}(...)` has no bound on its entry count. Key it by a `z.enum` so its size is closed (the one bound a nivoos package schema can state: its check refuses a `.refine` as code), or add `.refine((entries) => Object.keys(entries).length <= N)` outside a package (a `Map`: `.size`).",
100
106
  open: "`z.{{name}}()` accepts any value, so nothing is validated. Describe the shape: an object of bounded fields, or a bounded union.",
101
107
  bound: "`.{{name}}()` here is no bound (a missing, non-positive or infinite argument). Give a finite positive count.",
102
108
  },
@@ -135,6 +141,9 @@ export const schemaBounded = {
135
141
  return;
136
142
  const chain = chainOf(node);
137
143
  if (kind === "refined") {
144
+ const key = node.arguments.length > 1 ? node.arguments[0] : undefined;
145
+ if (RECORDS.has(name) && key?.type === "CallExpression" && constructorOf(key.callee, namespaces, named) === CLOSED_KEY)
146
+ return;
138
147
  if (!chain.some((entry) => REFINING.has(entry.name)))
139
148
  context.report({ node, messageId: "refined", data: { name } });
140
149
  return;
@@ -163,7 +163,7 @@ export const publicNeedsReason = {
163
163
  export const publicReasonClosed = {
164
164
  meta: {
165
165
  type: "problem",
166
- docs: { description: "`PublicReason` is closed to Health, AuthHandshake, SignedWebhook and CatalogRead in both editions." },
166
+ docs: { description: "`PublicReason` is closed to Health, AuthHandshake, SignedWebhook and CatalogRead." },
167
167
  schema: [],
168
168
  messages: {
169
169
  closed: "BE_PUBLIC_REASON_CLOSED: `PublicReason` has exactly Health, AuthHandshake, SignedWebhook and CatalogRead. An API-key or tool-token route authenticates with its own guard; do not add a public reason.",
@@ -5,5 +5,5 @@ export declare const entityExtendsBase: RuleModule;
5
5
  export declare const rules: {
6
6
  "entity-extends-base": RuleModule;
7
7
  };
8
- /** On at error; both editions. */
8
+ /** On at error. */
9
9
  export declare const recommended: Recommended;
@@ -113,5 +113,5 @@ export const entityExtendsBase = {
113
113
  };
114
114
  /** The rules of the entity-base law, by name. */
115
115
  export const rules = { "entity-extends-base": entityExtendsBase };
116
- /** On at error; both editions. */
116
+ /** On at error. */
117
117
  export const recommended = { "starci-be/entity-extends-base": "error" };
@@ -1,4 +1,3 @@
1
- import { hfsOf } from "./lib/hfs.js";
2
1
  /** The public entry of the event bus capability. */
3
2
  const EVENT_BUS_MODULE = "@modules/platform/event-bus";
4
3
  /** The base class every typed event extends. */
@@ -72,7 +71,7 @@ export const eventDedupeKey = {
72
71
  },
73
72
  },
74
73
  create(context) {
75
- if (hfsOf(context).edition !== "lite" || !EVENT_FILE.test(context.filename))
74
+ if (!EVENT_FILE.test(context.filename))
76
75
  return {};
77
76
  let declarations = new Map();
78
77
  const judge = (node) => {
@@ -101,8 +100,6 @@ export const eventSubscriptionStatic = {
101
100
  },
102
101
  },
103
102
  create(context) {
104
- if (hfsOf(context).edition !== "lite")
105
- return {};
106
103
  const topicQueues = new Set();
107
104
  let importsBus = false;
108
105
  const literalOptions = (node) => node.type === "ObjectExpression" && node.properties.every((property) => property.type === "Property" && !property.computed && property.value.type === "Literal");
@@ -3,5 +3,5 @@ import type { Recommended, RuleModule, Rules } from "./lib/rule.js";
3
3
  export declare const functionLineBudget: RuleModule;
4
4
  /** The rule this law contributes to the plugin. */
5
5
  export declare const rules: Rules;
6
- /** The function budget is an error in both editions. */
6
+ /** The function budget is an error. */
7
7
  export declare const recommended: Recommended;
@@ -42,5 +42,5 @@ export const functionLineBudget = {
42
42
  };
43
43
  /** The rule this law contributes to the plugin. */
44
44
  export const rules = { "function-line-budget": functionLineBudget };
45
- /** The function budget is an error in both editions. */
45
+ /** The function budget is an error. */
46
46
  export const recommended = { "starci-be/function-line-budget": "error" };
package/dist/index.js CHANGED
@@ -18,7 +18,6 @@
18
18
  */
19
19
  import { extEslintConfigs } from "@starci/hfs/runtime/scripts/lib/project-ext.mjs";
20
20
  import { buildBeConfig, buildBePackagesConfig } from "./lib/config.js";
21
- import { pluginForEdition } from "./lib/edition.js";
22
21
  import { recommended as aiGatewayRecommended, rules as aiGatewayRules } from "./ai-gateway.js";
23
22
  import { recommended as authPassportRecommended, rules as authPassportRules } from "./auth-passport.js";
24
23
  import { recommended as noRawSqlRecommended, rules as noRawSqlRules } from "./no-raw-sql.js";
@@ -182,7 +181,7 @@ export default plugin;
182
181
  * @returns The flat config.
183
182
  */
184
183
  export const starciBeConfig = async ({ hfs }) => [
185
- ...(await buildBeConfig({ hfs, plugin: pluginForEdition({ plugin, hfs }), recommended })),
184
+ ...(await buildBeConfig({ hfs, plugin, recommended })),
186
185
  ...withExtRules(hfs, "be"),
187
186
  ];
188
187
  /**
@@ -204,7 +203,7 @@ const packageRecommended = Object.fromEntries(Object.entries(recommended).filter
204
203
  * @returns The flat config.
205
204
  */
206
205
  export const starciBePackagesConfig = async ({ hfs }) => [
207
- ...(await buildBePackagesConfig({ hfs, plugin: pluginForEdition({ plugin, hfs }), recommended: packageRecommended })),
206
+ ...(await buildBePackagesConfig({ hfs, plugin, recommended: packageRecommended })),
208
207
  ...withExtRules(hfs, "packages"),
209
208
  ];
210
209
  export { linterOptions } from "./lib/config.js";
@@ -5,5 +5,5 @@ export declare const jobsSchedulerOwner: RuleModule;
5
5
  export declare const rules: {
6
6
  "jobs-scheduler-owner": RuleModule;
7
7
  };
8
- /** On at error in both editions. */
8
+ /** On at error. */
9
9
  export declare const recommended: Recommended;
@@ -81,5 +81,5 @@ export const jobsSchedulerOwner = {
81
81
  };
82
82
  /** The rule of the tick scheduler law, by name. */
83
83
  export const rules = { "jobs-scheduler-owner": jobsSchedulerOwner };
84
- /** On at error in both editions. */
84
+ /** On at error. */
85
85
  export const recommended = { "starci-be/jobs-scheduler-owner": "error" };
@@ -151,7 +151,6 @@ export interface HfsView {
151
151
  readonly repoRoot: string;
152
152
  readonly profile: string;
153
153
  readonly side: string | null;
154
- readonly edition: string;
155
154
  readonly grammar?: string;
156
155
  readonly apps: readonly HfsApp[];
157
156
  readonly connections?: readonly HfsConnection[];
@@ -183,7 +183,7 @@ export const noFolderReexport = {
183
183
  create(context) {
184
184
  const filename = context.filename || context.getFilename();
185
185
  const hfs = hfsOf(context);
186
- const isIndex = isIndexFile(filename) && !(hfs.edition === "lite" && LITE_ENTITY_LIST.test(hfs.relative(filename)));
186
+ const isIndex = isIndexFile(filename) && !LITE_ENTITY_LIST.test(hfs.relative(filename));
187
187
  const max = indexExportBudget(hfs, filename);
188
188
  let count = 0;
189
189
  return {
@@ -8,6 +8,8 @@
8
8
  * the one composer, whose statements are the templates R68 checks; (3) a file `ruleParams.be.sqlPassThrough` or hfs.json
9
9
  * `sides.be.sqlPassThrough` lists with a reason, while its first argument is not a template literal or a `+` expression;
10
10
  * (4) the `*.spec.ts` beside such a file. `platform/database` has no blanket exemption.
11
+ * The nivoos SDK's typed object read is not SQL: `reach.objects(Type).query({ where, sort, limit })` is a call on the result of an
12
+ * `.objects(...)` call in a file that imports `@starci/nivoos-sdk`; it passes, and any other `.query(` in that file is still refused.
11
13
  * - `template`: a `sql` tagged template outside the world. `sqlFile`: a `*.sql.ts` file outside the world. `sqlTagImport`: an import
12
14
  * of `sql`, `ident`, `SqlText` or `SqlIdent` outside the world. The tag's own module (`platform/database/database.sql.ts`) is exempt.
13
15
  * - `worldCallHelper`, `worldTableWrite`: a `sql` template inside the world that only calls a listed function (it is
@@ -17,7 +19,6 @@
17
19
  * pg built-ins, bare, plus every other function schema-qualified, including hfs.json `sides.be.dbFunctions`).
18
20
  * - `builder`: a query builder names its entity (`createQueryBuilder(Entity, "alias")`); a builder over a table-name string, a
19
21
  * builder with no entity, and a `getRepository(...)` are refused (the world excepted).
20
- * The rule runs in lite only (the catalog's `editions`); full keeps R36.
21
22
  *
22
23
  * Schema authority stays `db/migrations/*.sql`; whether the entities match it is `BE_ENTITY_SCHEMA_DRIFT` of `starci app db drift`.
23
24
  */
@@ -34,12 +35,19 @@ const COMPOSER_FILE = "database.client.ts";
34
35
  const TAG_FILE = "database.sql.ts";
35
36
  /** The names that carry SQL text: the tag, its identifier check and their brands. */
36
37
  const SQL_TEXT_NAMES = new Set(["sql", "ident", "SqlText", "SqlIdent"]);
38
+ /** The package of the nivoos SDK, whose `reach.objects(Type).query(...)` is a typed object read and runs no SQL. */
39
+ const NIVOOS_SDK = "@starci/nivoos-sdk";
40
+ /** The SDK door that hands out a typed object handle. */
41
+ const OBJECTS_DOOR = "objects";
37
42
  /** The suffix of a spec file. */
38
43
  const SPEC_SUFFIX = ".spec.ts";
39
44
  /** A statement that writes an application table: it goes through the entity or the area's builder. */
40
45
  const TABLE_WRITE = /^\s*(?:INSERT\s+INTO|UPDATE|DELETE\s+FROM)\s+(?:public|be_access)\./i;
41
46
  /** True when a builder's first argument can be an entity class: neither absent nor a string. */
42
47
  const namesEntity = (argument) => argument !== undefined && argument.type !== "TemplateLiteral" && !(argument.type === "Literal" && typeof argument.value === "string");
48
+ /** True when a `.query(` receiver is `<reach>.objects(Type)`, the SDK's typed object handle. */
49
+ const isObjectHandle = (receiver) => receiver.type === "CallExpression" && receiver.callee.type === "MemberExpression" && !receiver.callee.computed &&
50
+ receiver.callee.property.type === "Identifier" && receiver.callee.property.name === OBJECTS_DOOR;
43
51
  /** The text of a template literal, each substitution standing as `?`. */
44
52
  const templateText = (template) => template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join("?");
45
53
  /** The pattern of a statement that is only a call of one listed function: `SELECT [* FROM] <fn>(...) [AS x]`. */
@@ -78,12 +86,15 @@ export const noRawSql = {
78
86
  const passThrough = new Set((hfs.ruleParams.sqlPassThrough ?? []).map((entry) => entry.file));
79
87
  const passThroughSpec = relative.endsWith(SPEC_SUFFIX) && passThrough.has(`${relative.slice(0, -SPEC_SUFFIX.length)}.ts`);
80
88
  const callOnly = callPattern([...listed]);
89
+ let importsSdk = false;
81
90
  return {
82
91
  Program(node) {
83
92
  if (!inWorld && !isTagModule && relative.endsWith(".sql.ts"))
84
93
  context.report({ node, messageId: "sqlFile" });
85
94
  },
86
95
  ImportDeclaration(node) {
96
+ if (node.source.value === NIVOOS_SDK || node.source.value.startsWith(`${NIVOOS_SDK}/`))
97
+ importsSdk = true;
87
98
  if (inWorld || isTagModule)
88
99
  return;
89
100
  for (const specifier of node.specifiers) {
@@ -108,6 +119,8 @@ export const noRawSql = {
108
119
  if (method === "query") {
109
120
  if (inWorld || passThroughSpec)
110
121
  return;
122
+ if (importsSdk && isObjectHandle(callee.object))
123
+ return;
111
124
  const first = node.arguments[0];
112
125
  if (isComposer && first?.type === "TemplateLiteral")
113
126
  return;
@@ -1,8 +1,4 @@
1
1
  import type { Recommended, RuleModule } from "./lib/rule.js";
2
- /** SQL text is `SqlText`, and only a persistence `.sql.ts` builds it. */
3
- export declare const sqlTextOnly: RuleModule;
4
- /** There is one way to write a complex read, and it is SQL. */
5
- export declare const noQueryBuilder: RuleModule;
6
2
  /** A statement is text plus parameters; a value never becomes part of the text. */
7
3
  export declare const noInterpolatedSql: RuleModule;
8
4
  /** A list read states its bound. */
@@ -11,8 +7,6 @@ export declare const queryNeedsLimit: RuleModule;
11
7
  export declare const noQueryInLoop: RuleModule;
12
8
  /** The rules this law contributes to the plugin. */
13
9
  export declare const rules: {
14
- "sql-text-only": RuleModule;
15
- "no-query-builder": RuleModule;
16
10
  "no-interpolated-sql": RuleModule;
17
11
  "query-needs-limit": RuleModule;
18
12
  "no-query-in-loop": RuleModule;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The rules that keep a database call safe to run in production (R36, R68, R69, R77).
2
+ * The rules that keep a database call safe to run in production (R68, R69, R77).
3
3
  *
4
4
  * SQL text is a `SqlText` constant built with the `sql` tag in a persistence `<name>.sql.ts`; a dynamic identifier is a
5
5
  * `SqlIdent` from `ident()`; a value is a numbered parameter. Every receiver is identified by its TypeScript type
@@ -7,12 +7,9 @@
7
7
  * HFS slot view. No rule here parses SQL text: what a statement reads and writes is judged by the architecture
8
8
  * machine (R86).
9
9
  *
10
- * - `sql-text-only` (R36 `BE_SQL_OUTSIDE_PERSISTENCE`) - the first argument of `.query(` is a `SqlText`, and the `sql`
11
- * tag is called only in a persistence `<name>.sql.ts`.
12
- * - `no-query-builder` (R36) - no `createQueryBuilder(` call.
13
10
  * - `no-interpolated-sql` (R68 `BE_SQL_INTERPOLATED`) - a substitution inside the `sql` tag is a `SqlIdent`; a `.query(`
14
- * string built by template or concatenation is refused. One file is the owner R334 names for the lite call and LISTEN statements,
15
- * `platform/database/database.client.ts` of a lite app: there a `.query(` template may substitute only the checked parts its own
11
+ * string built by template or concatenation is refused. One file is the owner R334 names for the call and LISTEN statements,
12
+ * `platform/database/database.client.ts` of an app: there a `.query(` template may substitute only the checked parts its own
16
13
  * validator brands (`DbFunctionPart`, `DbParameterList` declared in that file); any other substitution, a `+` and the same
17
14
  * template in any other file stay refused.
18
15
  * - `query-needs-limit` (R69 `BE_QUERY_UNBOUNDED`) - `find`, `findBy` and `findAndCount` on an `EntityManager` carry `take`.
@@ -38,68 +35,12 @@ const hasBrand = (context, hfs, node, name) => typeOrigins(context, node).some((
38
35
  /** Whether a call goes through `.query` on a manager, runner or data source. */
39
36
  const isQueryCall = (context, node) => calleeProperty(node) === "query" && node.callee.type === "MemberExpression" && infraTypeOf(context, node.callee.object) !== null;
40
37
  // -- R36 -----------------------------------------------------------------------------------------------
41
- /** SQL text is `SqlText`, and only a persistence `.sql.ts` builds it. */
42
- export const sqlTextOnly = {
43
- meta: {
44
- type: "problem",
45
- docs: { description: "`.query(...)` takes a `SqlText`, and the `sql` tag is called only in a persistence `<name>.sql.ts`." },
46
- schema: [],
47
- messages: {
48
- notSqlText: "The first argument of `.query(...)` is not a `SqlText`. SQL text is a constant built with the `sql` tag in the `persistence/<name>.sql.ts` of the owning capability and imported here; the row shape and its mapper live in `<name>.rows.ts`.",
49
- tagOutsideSqlFile: "The `sql` tag is called outside a persistence `<name>.sql.ts`. Write the statement as an exported constant in the `persistence/<name>.sql.ts` of the capability that owns the tables, and import it.",
50
- },
51
- },
52
- create(context) {
53
- const hfs = hfsOf(context);
54
- const filename = context.filename || context.getFilename();
55
- const migration = isMigrationFile(hfs, filename);
56
- const sqlFile = hfs.slotOf(filename) === "be.persistence" && baseNameOf(filename).endsWith(".sql.ts");
57
- const isSqlTag = (node) => typeOrigins(context, node).some((origin) => origin.name === "sql" && fromDatabaseCapability(hfs, origin));
58
- return {
59
- CallExpression(node) {
60
- if (isSqlTag(node.callee) && !sqlFile)
61
- context.report({ node, messageId: "tagOutsideSqlFile" });
62
- if (migration || !isQueryCall(context, node))
63
- return;
64
- const first = node.arguments[0];
65
- if (!first || !hasBrand(context, hfs, first, "SqlText"))
66
- context.report({ node: first ?? node, messageId: "notSqlText" });
67
- },
68
- TaggedTemplateExpression(node) {
69
- if (isSqlTag(node.tag) && !sqlFile)
70
- context.report({ node, messageId: "tagOutsideSqlFile" });
71
- },
72
- };
73
- },
74
- };
75
- /** There is one way to write a complex read, and it is SQL. */
76
- export const noQueryBuilder = {
77
- meta: {
78
- type: "problem",
79
- docs: { description: "No `createQueryBuilder(...)` call." },
80
- schema: [],
81
- messages: {
82
- builder: "`createQueryBuilder(...)` is banned. A read is `manager.find(Entity, { where, take })`, or a `SqlText` constant in the capability's `persistence/<name>.sql.ts` run with `manager.query(...)`.",
83
- },
84
- },
85
- create(context) {
86
- return {
87
- CallExpression(node) {
88
- const callee = node.callee;
89
- const name = callee.type === "Identifier" ? callee.name : calleeProperty(node);
90
- if (name === "createQueryBuilder")
91
- context.report({ node, messageId: "builder" });
92
- },
93
- };
94
- },
95
- };
96
- // -- R68 -----------------------------------------------------------------------------------------------
97
- /** The one file R334 names as the composer of a lite function-call statement: `platform/database/database.client.ts`. */
38
+ /** The one file R334 names as the composer of a function-call statement: `platform/database/database.client.ts`. */
98
39
  const CALL_STATEMENT_FILE = "database.client.ts";
99
40
  /** The brands the call-statement file gives the checked parts it splices: a function-name part and a numbered parameter list. */
100
41
  const CALL_STATEMENT_BRANDS = ["DbFunctionPart", "DbParameterList"];
101
- /** Whether a file is the lite call-statement owner of the platform database capability. */
102
- const isCallStatementFile = (hfs, filename) => hfs.edition === "lite" && baseNameOf(filename) === CALL_STATEMENT_FILE && inDatabaseCapability(hfs, filename);
42
+ /** Whether a file is the call-statement owner of the platform database capability. */
43
+ const isCallStatementFile = (hfs, filename) => baseNameOf(filename) === CALL_STATEMENT_FILE && inDatabaseCapability(hfs, filename);
103
44
  /** Whether a substitution has a brand the call-statement file itself declares for the parts it checked. */
104
45
  const isCheckedCallPart = (context, hfs, node) => typeOrigins(context, node).some((origin) => CALL_STATEMENT_BRANDS.includes(origin.name) && isCallStatementFile(hfs, origin.file));
105
46
  /** A statement is text plus parameters; a value never becomes part of the text. */
@@ -222,16 +163,12 @@ export const noQueryInLoop = {
222
163
  };
223
164
  /** The rules this law contributes to the plugin. */
224
165
  export const rules = {
225
- "sql-text-only": sqlTextOnly,
226
- "no-query-builder": noQueryBuilder,
227
166
  "no-interpolated-sql": noInterpolatedSql,
228
167
  "query-needs-limit": queryNeedsLimit,
229
168
  "no-query-in-loop": noQueryInLoop,
230
169
  };
231
170
  /** Every rule of this law ships at `error`; no baseline exists. */
232
171
  export const recommended = {
233
- "starci-be/sql-text-only": "error",
234
- "starci-be/no-query-builder": "error",
235
172
  "starci-be/no-interpolated-sql": "error",
236
173
  "starci-be/query-needs-limit": "error",
237
174
  "starci-be/no-query-in-loop": "error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/eslint-canon-be",
3
- "version": "3.27.2",
3
+ "version": "3.28.0",
4
4
  "description": "The StarCi back-end lint canon: every rule its laws publish, gathered as one flat-config plugin.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "node": ">=22.13.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "@starci/hfs": "~6.13.0",
43
+ "@starci/hfs": "~6.14.0",
44
44
  "eslint": ">=9",
45
45
  "typescript": ">=5.9"
46
46
  },
@@ -74,6 +74,6 @@
74
74
  "typescript": "^6.0.3"
75
75
  },
76
76
  "types": "./dist/index.d.ts",
77
- "gitHead": "bf57eda186e017fced7929e422e3d9a521d98273",
78
- "starciSource": "c058d7203457adca5866a74866f78af8611c069075553bfc9f8cb36dd3ee81f5"
77
+ "gitHead": "0bf97f870be00547f1058f9418c2f675f6e0c74d",
78
+ "starciSource": "0a9b528f5c9a11c82de0989c2bdbe4bf792c5e14d0d4842b37056992a49dc0ff"
79
79
  }
@@ -1,24 +0,0 @@
1
- /**
2
- * The edition gate of the back-end plugin.
3
- *
4
- * Edition applicability belongs to the HFS rule catalog, beside the law and its enforcer. A rule
5
- * that the catalog does not judge in this app's edition still ships in the plugin, but its `create`
6
- * returns no listeners. The plugin wiring therefore has one generic gate instead of edition checks
7
- * scattered through rule bodies.
8
- */
9
- import { type RuleCatalog } from "@starci/hfs/runtime/scripts/hfs/rule-catalog.mjs";
10
- import type { CanonPlugin } from "./config.js";
11
- /**
12
- * The plugin view for one HFS edition.
13
- *
14
- * Both editions read the catalog: full is the default edition, and a rule whose catalog entries name only lite (R334
15
- * `no-raw-sql`) is inactive there, as a full-only rule is in lite. The bundled catalog is loaded once per lint process;
16
- * tests may inject a catalog to prove the generic filtering independently of the bundled copy.
17
- */
18
- export declare const pluginForEdition: <P extends CanonPlugin>({ plugin, hfs, catalog }: {
19
- plugin: P;
20
- hfs?: {
21
- readonly edition?: string;
22
- } | null | undefined;
23
- catalog?: Pick<RuleCatalog, "enforcerJudgedIn"> | undefined;
24
- }) => P;
@@ -1,37 +0,0 @@
1
- /**
2
- * The edition gate of the back-end plugin.
3
- *
4
- * Edition applicability belongs to the HFS rule catalog, beside the law and its enforcer. A rule
5
- * that the catalog does not judge in this app's edition still ships in the plugin, but its `create`
6
- * returns no listeners. The plugin wiring therefore has one generic gate instead of edition checks
7
- * scattered through rule bodies.
8
- */
9
- import { loadRuleCatalog } from "@starci/hfs/runtime/scripts/hfs/rule-catalog.mjs";
10
- import { RUNTIME_ROOT as RUNTIME } from "./runtime-root.js";
11
- let catalogCache;
12
- /** The bundled rule catalog, loaded once per lint process. */
13
- const bundledCatalog = () => {
14
- catalogCache ??= loadRuleCatalog({ root: RUNTIME });
15
- return catalogCache;
16
- };
17
- /** A rule which intentionally registers no listeners in this edition. */
18
- const inactive = (rule) => Object.freeze({ ...rule, create: () => ({}) });
19
- /**
20
- * The plugin view for one HFS edition.
21
- *
22
- * Both editions read the catalog: full is the default edition, and a rule whose catalog entries name only lite (R334
23
- * `no-raw-sql`) is inactive there, as a full-only rule is in lite. The bundled catalog is loaded once per lint process;
24
- * tests may inject a catalog to prove the generic filtering independently of the bundled copy.
25
- */
26
- export const pluginForEdition = ({ plugin, hfs, catalog }) => {
27
- const edition = hfs?.edition === undefined ? "full" : hfs.edition;
28
- if (edition !== "full" && edition !== "lite") {
29
- throw new RangeError(`Unknown HFS edition ${JSON.stringify(edition)}; expected "full" or "lite"`);
30
- }
31
- const loaded = catalog ?? bundledCatalog();
32
- const rules = Object.fromEntries(Object.entries(plugin.rules).map(([id, rule]) => [
33
- id,
34
- loaded.enforcerJudgedIn("eslint-be", id, edition) ? rule : inactive(rule),
35
- ]));
36
- return Object.freeze({ ...plugin, rules: Object.freeze(rules) });
37
- };