@starci/eslint-canon-be 3.27.2 → 3.27.3

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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.27.3 - 2026-11-18
4
+
5
+ - 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.
6
+ - 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.
7
+
3
8
  ## 3.27.2 - 2026-11-18
4
9
 
5
10
  - 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;
@@ -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
@@ -34,12 +36,19 @@ const COMPOSER_FILE = "database.client.ts";
34
36
  const TAG_FILE = "database.sql.ts";
35
37
  /** The names that carry SQL text: the tag, its identifier check and their brands. */
36
38
  const SQL_TEXT_NAMES = new Set(["sql", "ident", "SqlText", "SqlIdent"]);
39
+ /** The package of the nivoos SDK, whose `reach.objects(Type).query(...)` is a typed object read and runs no SQL. */
40
+ const NIVOOS_SDK = "@starci/nivoos-sdk";
41
+ /** The SDK door that hands out a typed object handle. */
42
+ const OBJECTS_DOOR = "objects";
37
43
  /** The suffix of a spec file. */
38
44
  const SPEC_SUFFIX = ".spec.ts";
39
45
  /** A statement that writes an application table: it goes through the entity or the area's builder. */
40
46
  const TABLE_WRITE = /^\s*(?:INSERT\s+INTO|UPDATE|DELETE\s+FROM)\s+(?:public|be_access)\./i;
41
47
  /** True when a builder's first argument can be an entity class: neither absent nor a string. */
42
48
  const namesEntity = (argument) => argument !== undefined && argument.type !== "TemplateLiteral" && !(argument.type === "Literal" && typeof argument.value === "string");
49
+ /** True when a `.query(` receiver is `<reach>.objects(Type)`, the SDK's typed object handle. */
50
+ const isObjectHandle = (receiver) => receiver.type === "CallExpression" && receiver.callee.type === "MemberExpression" && !receiver.callee.computed &&
51
+ receiver.callee.property.type === "Identifier" && receiver.callee.property.name === OBJECTS_DOOR;
43
52
  /** The text of a template literal, each substitution standing as `?`. */
44
53
  const templateText = (template) => template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join("?");
45
54
  /** The pattern of a statement that is only a call of one listed function: `SELECT [* FROM] <fn>(...) [AS x]`. */
@@ -78,12 +87,15 @@ export const noRawSql = {
78
87
  const passThrough = new Set((hfs.ruleParams.sqlPassThrough ?? []).map((entry) => entry.file));
79
88
  const passThroughSpec = relative.endsWith(SPEC_SUFFIX) && passThrough.has(`${relative.slice(0, -SPEC_SUFFIX.length)}.ts`);
80
89
  const callOnly = callPattern([...listed]);
90
+ let importsSdk = false;
81
91
  return {
82
92
  Program(node) {
83
93
  if (!inWorld && !isTagModule && relative.endsWith(".sql.ts"))
84
94
  context.report({ node, messageId: "sqlFile" });
85
95
  },
86
96
  ImportDeclaration(node) {
97
+ if (node.source.value === NIVOOS_SDK || node.source.value.startsWith(`${NIVOOS_SDK}/`))
98
+ importsSdk = true;
87
99
  if (inWorld || isTagModule)
88
100
  return;
89
101
  for (const specifier of node.specifiers) {
@@ -108,6 +120,8 @@ export const noRawSql = {
108
120
  if (method === "query") {
109
121
  if (inWorld || passThroughSpec)
110
122
  return;
123
+ if (importsSdk && isObjectHandle(callee.object))
124
+ return;
111
125
  const first = node.arguments[0];
112
126
  if (isComposer && first?.type === "TemplateLiteral")
113
127
  return;
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.27.3",
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",
@@ -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": "5fb94d30387948cb258ca1742c533a14421f3bdc",
78
+ "starciSource": "96812461e9b9cfc4c1963daba1f85195ff48c2a6f108b871b4fc15f2aac37825"
79
79
  }