code-auditor-mcp 3.8.1 → 3.9.1
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/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +89 -0
- package/README.md +12 -0
- package/dist/__tests__/fixtures/spec-52/item-01-prepare-in-loop.d.ts +14 -0
- package/dist/__tests__/fixtures/spec-52/item-01-prepare-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-01-prepare-in-loop.js +16 -0
- package/dist/__tests__/fixtures/spec-52/item-01-prepare-in-loop.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-02-prepare-bind-accumulate-batch.d.ts +15 -0
- package/dist/__tests__/fixtures/spec-52/item-02-prepare-bind-accumulate-batch.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-02-prepare-bind-accumulate-batch.js +17 -0
- package/dist/__tests__/fixtures/spec-52/item-02-prepare-bind-accumulate-batch.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-03-exec-in-loop.d.ts +14 -0
- package/dist/__tests__/fixtures/spec-52/item-03-exec-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-03-exec-in-loop.js +13 -0
- package/dist/__tests__/fixtures/spec-52/item-03-exec-in-loop.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-04-storage-sql-exec-in-loop.d.ts +24 -0
- package/dist/__tests__/fixtures/spec-52/item-04-storage-sql-exec-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-04-storage-sql-exec-in-loop.js +19 -0
- package/dist/__tests__/fixtures/spec-52/item-04-storage-sql-exec-in-loop.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-05-upsert-forms.d.ts +19 -0
- package/dist/__tests__/fixtures/spec-52/item-05-upsert-forms.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-05-upsert-forms.js +19 -0
- package/dist/__tests__/fixtures/spec-52/item-05-upsert-forms.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-06-chained-prepare-run-in-loop.d.ts +17 -0
- package/dist/__tests__/fixtures/spec-52/item-06-chained-prepare-run-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-06-chained-prepare-run-in-loop.js +19 -0
- package/dist/__tests__/fixtures/spec-52/item-06-chained-prepare-run-in-loop.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-07-chained-prepare-bind-first-in-loop.d.ts +25 -0
- package/dist/__tests__/fixtures/spec-52/item-07-chained-prepare-bind-first-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-07-chained-prepare-bind-first-in-loop.js +21 -0
- package/dist/__tests__/fixtures/spec-52/item-07-chained-prepare-bind-first-in-loop.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-08-promise-all-of-statements-in-loop.d.ts +15 -0
- package/dist/__tests__/fixtures/spec-52/item-08-promise-all-of-statements-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-08-promise-all-of-statements-in-loop.js +19 -0
- package/dist/__tests__/fixtures/spec-52/item-08-promise-all-of-statements-in-loop.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-09-promise-all-map-of-statements-in-loop.d.ts +14 -0
- package/dist/__tests__/fixtures/spec-52/item-09-promise-all-map-of-statements-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-09-promise-all-map-of-statements-in-loop.js +14 -0
- package/dist/__tests__/fixtures/spec-52/item-09-promise-all-map-of-statements-in-loop.js.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-10-promise-all-map-of-eager-all-in-loop.d.ts +15 -0
- package/dist/__tests__/fixtures/spec-52/item-10-promise-all-map-of-eager-all-in-loop.d.ts.map +1 -0
- package/dist/__tests__/fixtures/spec-52/item-10-promise-all-map-of-eager-all-in-loop.js +16 -0
- package/dist/__tests__/fixtures/spec-52/item-10-promise-all-map-of-eager-all-in-loop.js.map +1 -0
- package/dist/analyzers/applicability.d.ts +38 -0
- package/dist/analyzers/applicability.d.ts.map +1 -1
- package/dist/analyzers/applicability.js +55 -0
- package/dist/analyzers/applicability.js.map +1 -1
- package/dist/analyzers/cross-language/SchemaValidator.d.ts +11 -0
- package/dist/analyzers/cross-language/SchemaValidator.d.ts.map +1 -1
- package/dist/analyzers/cross-language/SchemaValidator.js +28 -52
- package/dist/analyzers/cross-language/SchemaValidator.js.map +1 -1
- package/dist/analyzers/crossDomain/CrossDomainAnalyzer.d.ts +1 -1
- package/dist/analyzers/crossDomain/CrossDomainAnalyzer.js +1 -1
- package/dist/analyzers/universal/UniversalDataAccessAnalyzer.d.ts +7 -0
- package/dist/analyzers/universal/UniversalDataAccessAnalyzer.d.ts.map +1 -1
- package/dist/analyzers/universal/UniversalDataAccessAnalyzer.js +110 -4
- package/dist/analyzers/universal/UniversalDataAccessAnalyzer.js.map +1 -1
- package/dist/analyzers/universal/UniversalSOLIDAnalyzer.d.ts +9 -2
- package/dist/analyzers/universal/UniversalSOLIDAnalyzer.d.ts.map +1 -1
- package/dist/analyzers/universal/UniversalSOLIDAnalyzer.js +65 -3
- package/dist/analyzers/universal/UniversalSOLIDAnalyzer.js.map +1 -1
- package/dist/analyzers/universal/schema/codeAnalysis.d.ts +19 -5
- package/dist/analyzers/universal/schema/codeAnalysis.d.ts.map +1 -1
- package/dist/analyzers/universal/schema/codeAnalysis.js +36 -13
- package/dist/analyzers/universal/schema/codeAnalysis.js.map +1 -1
- package/dist/analyzers/universal/schema/discovery.js +1 -1
- package/dist/analyzers/universal/schema/discovery.js.map +1 -1
- package/dist/auditRouter.d.ts.map +1 -1
- package/dist/auditRouter.js +0 -2
- package/dist/auditRouter.js.map +1 -1
- package/dist/cli.js +3 -25
- package/dist/cli.js.map +1 -1
- package/dist/codeIndexDB.d.ts +3 -5
- package/dist/codeIndexDB.d.ts.map +1 -1
- package/dist/codeIndexDB.js +10 -40
- package/dist/codeIndexDB.js.map +1 -1
- package/dist/conventions/conventionMiner.d.ts +3 -3
- package/dist/conventions/conventionMiner.d.ts.map +1 -1
- package/dist/conventions/conventionMiner.js.map +1 -1
- package/dist/generators/AWSQConfigGenerator.js +1 -1
- package/dist/generators/AWSQConfigGenerator.js.map +1 -1
- package/dist/generators/AiderConfigGenerator.js +1 -1
- package/dist/generators/AiderConfigGenerator.js.map +1 -1
- package/dist/generators/ClaudeConfigGenerator.js +1 -1
- package/dist/generators/ClaudeConfigGenerator.js.map +1 -1
- package/dist/generators/ClineConfigGenerator.js +1 -1
- package/dist/generators/ClineConfigGenerator.js.map +1 -1
- package/dist/generators/CodeiumConfigGenerator.js +1 -1
- package/dist/generators/CodeiumConfigGenerator.js.map +1 -1
- package/dist/generators/CodexConfigGenerator.js +1 -1
- package/dist/generators/CodexConfigGenerator.js.map +1 -1
- package/dist/generators/ConfigGeneratorFactory.d.ts.map +1 -1
- package/dist/generators/ConfigGeneratorFactory.js +2 -0
- package/dist/generators/ConfigGeneratorFactory.js.map +1 -1
- package/dist/generators/ContinueConfigGenerator.js +1 -1
- package/dist/generators/CopilotConfigGenerator.js +1 -1
- package/dist/generators/CopilotConfigGenerator.js.map +1 -1
- package/dist/generators/CursorConfigGenerator.js +1 -1
- package/dist/generators/CursorConfigGenerator.js.map +1 -1
- package/dist/generators/GeminiConfigGenerator.js +2 -2
- package/dist/generators/GeminiConfigGenerator.js.map +1 -1
- package/dist/generators/JetBrainsConfigGenerator.js +1 -1
- package/dist/generators/JetBrainsConfigGenerator.js.map +1 -1
- package/dist/generators/VSCodeConfigGenerator.js +1 -1
- package/dist/generators/VSCodeConfigGenerator.js.map +1 -1
- package/dist/generators/ZCodeConfigGenerator.d.ts +21 -0
- package/dist/generators/ZCodeConfigGenerator.d.ts.map +1 -0
- package/dist/generators/ZCodeConfigGenerator.js +64 -0
- package/dist/generators/ZCodeConfigGenerator.js.map +1 -0
- package/dist/generators/index.d.ts +3 -2
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +3 -2
- package/dist/generators/index.js.map +1 -1
- package/dist/graph/blastRadius.d.ts +2 -2
- package/dist/graph/blastRadius.d.ts.map +1 -1
- package/dist/graph/blastRadius.js.map +1 -1
- package/dist/graph/callGraph.d.ts +6 -6
- package/dist/graph/callGraph.d.ts.map +1 -1
- package/dist/graph/callGraph.js.map +1 -1
- package/dist/graph/importGraph.d.ts +5 -5
- package/dist/graph/importGraph.d.ts.map +1 -1
- package/dist/graph/importGraph.js.map +1 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +8 -0
- package/dist/installer.js.map +1 -1
- package/dist/languages/LanguageOrchestrator.d.ts +0 -17
- package/dist/languages/LanguageOrchestrator.d.ts.map +1 -1
- package/dist/languages/LanguageOrchestrator.js +23 -50
- package/dist/languages/LanguageOrchestrator.js.map +1 -1
- package/dist/ledger.d.ts +19 -19
- package/dist/ledger.d.ts.map +1 -1
- package/dist/ledger.js.map +1 -1
- package/dist/mcp-tools/whitelistTools.d.ts +1 -1
- package/dist/mcp-tools-shared.js +1 -1
- package/dist/mcp-tools-shared.js.map +1 -1
- package/dist/mcp.js +4 -3
- package/dist/mcp.js.map +1 -1
- package/dist/mcpAuditJobs.js.map +1 -1
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +12 -1
- package/dist/pipeline.js.map +1 -1
- package/dist/pipelineAdapters.d.ts.map +1 -1
- package/dist/pipelineAdapters.js +14 -3
- package/dist/pipelineAdapters.js.map +1 -1
- package/dist/search/QueryParser.d.ts.map +1 -1
- package/dist/search/QueryParser.js +5 -1
- package/dist/search/QueryParser.js.map +1 -1
- package/dist/services/auditJobService.d.ts +5 -5
- package/dist/services/auditJobService.d.ts.map +1 -1
- package/dist/services/auditJobService.js.map +1 -1
- package/dist/sqlite/betterSqlite3.d.ts +27 -0
- package/dist/sqlite/betterSqlite3.d.ts.map +1 -0
- package/dist/sqlite/betterSqlite3.js +79 -0
- package/dist/sqlite/betterSqlite3.js.map +1 -0
- package/dist/sqlite/driver.d.ts +24 -0
- package/dist/sqlite/driver.d.ts.map +1 -0
- package/dist/sqlite/driver.js +90 -0
- package/dist/sqlite/driver.js.map +1 -0
- package/dist/sqlite/nodeSqlite.d.ts +27 -0
- package/dist/sqlite/nodeSqlite.d.ts.map +1 -0
- package/dist/sqlite/nodeSqlite.js +168 -0
- package/dist/sqlite/nodeSqlite.js.map +1 -0
- package/dist/sqlite/types.d.ts +52 -0
- package/dist/sqlite/types.d.ts.map +1 -0
- package/dist/sqlite/types.js +15 -0
- package/dist/sqlite/types.js.map +1 -0
- package/dist/styles/styleIndexer.d.ts +2 -2
- package/dist/styles/styleIndexer.d.ts.map +1 -1
- package/dist/styles/styleIndexer.js.map +1 -1
- package/dist/workers/auditJobRunner.js +4 -3
- package/dist/workers/auditJobRunner.js.map +1 -1
- package/package.json +8 -11
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/skills/code-auditor/SKILL.md +1 -1
- package/server.json +2 -2
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"name": "code-auditor",
|
|
11
11
|
"source": "./plugin",
|
|
12
12
|
"description": "Diff-scoped code quality auditing on every edit. Indexes your codebase, enforces invariants, and feeds violations back to the agent so fixes happen inline.",
|
|
13
|
-
"version": "3.
|
|
13
|
+
"version": "3.9.1",
|
|
14
14
|
"author": {
|
|
15
15
|
"name": "Ben Hammond"
|
|
16
16
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,95 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the Code Auditor MCP project.
|
|
4
4
|
|
|
5
|
+
## [3.9.1] — 2026-09-11
|
|
6
|
+
|
|
7
|
+
### Findings from a real D1/Workers audit (Spec 52)
|
|
8
|
+
|
|
9
|
+
Three defects surfaced by auditing an unseen Cloudflare D1 project, each fixed
|
|
10
|
+
with a false-positive / true-positive two-direction proof:
|
|
11
|
+
|
|
12
|
+
- **`loop-query` treated statement construction as execution (R1).** `.prepare()` /
|
|
13
|
+
`.bind()` build a statement object with no I/O; execution happens only at
|
|
14
|
+
`.run()` / `.all()` / `.first()` / `.raw()` / `.exec()` / `.batch()`. The
|
|
15
|
+
accumulate-then-batch shape (`stmts.push(db.prepare(sql).bind(x))` consumed by
|
|
16
|
+
a single `.batch()` after the loop) is no longer flagged, while a genuine N+1 —
|
|
17
|
+
an eager call in a loop, *including* `db.prepare(sql).bind(x).run()` — still
|
|
18
|
+
fires. `too-many-queries` no longer counts `.prepare()` SQL, but now counts the
|
|
19
|
+
eager execution methods (`.run()` / `.all()` / `.first()` / `.raw()` /
|
|
20
|
+
`.batch()`, including the typed D1 forms `.all<T>()` / `.first<T>()`), so a
|
|
21
|
+
genuine `db.prepare(sql).bind(x).all<Row>()` chain is still counted while a
|
|
22
|
+
pure statement factory is not. `Promise.all(...)` is excluded and `.exec()` is
|
|
23
|
+
deliberately not counted (indistinguishable from `regex.exec()` in a text
|
|
24
|
+
heuristic).
|
|
25
|
+
- **`INSERT OR IGNORE` and friends were not recognized as writes (R2).** The write
|
|
26
|
+
classifier now matches `INSERT OR IGNORE INTO`, `INSERT OR REPLACE INTO`,
|
|
27
|
+
`REPLACE INTO`, and `INSERT … ON CONFLICT … DO UPDATE`, so the write set that
|
|
28
|
+
`written-never-read` / `read-never-written` / `multi-table-write` /
|
|
29
|
+
`unknown-table` read is correct.
|
|
30
|
+
- **Whole-program rules were unsound under a scoped run (R3).**
|
|
31
|
+
`written-never-read`, `read-never-written`, `no-validator-reachable`, and
|
|
32
|
+
`unknown-table` draw a global conclusion that a partial file set cannot
|
|
33
|
+
support, so a scoped/diff run now reports them `notApplicable` ("requires
|
|
34
|
+
whole-project analysis; this run was scoped to N file(s)") rather than firing
|
|
35
|
+
an unqualified global claim. Full runs are unchanged.
|
|
36
|
+
|
|
37
|
+
Edge-case follow-up (same pass): `loop-query`'s `Promise.all` guard now also
|
|
38
|
+
crosses an arrow function — `Promise.all(rows.map(r => db.prepare(sql).bind(r)))`
|
|
39
|
+
in a loop is statement construction (not N+1), while
|
|
40
|
+
`Promise.all(rows.map(r => db.prepare(sql).bind(r).all()))` still fires. And
|
|
41
|
+
`countQueries` no longer double-counts the `DO UPDATE` / `KEY UPDATE` clause of
|
|
42
|
+
an upsert as a second query (knex `too-many-queries` 196 → 193).
|
|
43
|
+
|
|
44
|
+
### ZCode installation support
|
|
45
|
+
Added first-class ZCode (Z.AI's agentic AI coding IDE) support:
|
|
46
|
+
- `code-audit install --agent zcode` installs the skill (ZCode reads the `.agents`
|
|
47
|
+
skills convention).
|
|
48
|
+
- The `generate` MCP tool now emits ZCode MCP config — `.zcode/config.json`
|
|
49
|
+
(project scope) or `~/.zcode/cli/config.json` (user scope), using ZCode's
|
|
50
|
+
native `mcp.servers` key.
|
|
51
|
+
|
|
52
|
+
### `solid/dependency-inversion` — escapes-vs-held false positive
|
|
53
|
+
An external audit found the rule firing on `new AppError(...)` thrown from a
|
|
54
|
+
Durable Object method — a *value type*, not a collaborator the class holds. The
|
|
55
|
+
predicate now distinguishes **escapes** from **held**: a construction whose value
|
|
56
|
+
is thrown or returned is a value type (not a dependency); one assigned to a field
|
|
57
|
+
or captured as state is a dependency. The escape check walks through transparent
|
|
58
|
+
wrappers (`parenthesized_expression`, `as_expression`, `type_assertion`,
|
|
59
|
+
`satisfies_expression`, `non_null_expression`), so `return new Foo() as Bar` and
|
|
60
|
+
`throw (new AppError())` are also cleared. This clears `throw new AppError(...)`
|
|
61
|
+
and `return new Foo(...)` factory values while every held-collaborator positive
|
|
62
|
+
still fires. Corpus deltas (only this rule moved): knex 20 → 12 (−8, dialect/Client
|
|
63
|
+
factory accessors that `return new QueryBuilder(this)` etc.), blitz 12 → 11
|
|
64
|
+
(−1, a `return new Response(...)` value). recall-protocol (3), hhra-org (8),
|
|
65
|
+
primer-css (0) unchanged — no weakening to zero. Survivors sampled and confirmed
|
|
66
|
+
field-held collaborators: `GuildAgent` (`this.#migrations = new SQLSchemaMigrations(...)`),
|
|
67
|
+
`StrategistManager` (`this.reconnect = new ReconnectController(...)`),
|
|
68
|
+
`OrgTrackerDatabase` (`this.pool = new Pool(...)`), `Client`
|
|
69
|
+
(`this.logger = new Logger(...)` / `this.pool = new KnexPool(...)` — fires despite
|
|
70
|
+
its many `return new X()` factory accessors), `Generator`
|
|
71
|
+
(`this.enquirer = new Enquirer()`).
|
|
72
|
+
|
|
73
|
+
## [3.9.0] — 2026-09-09
|
|
74
|
+
|
|
75
|
+
### SQLite without a native install (Spec 51)
|
|
76
|
+
`better-sqlite3` is no longer a hard dependency. The tool now selects its SQLite
|
|
77
|
+
backend at runtime: the built-in `node:sqlite` (`DatabaseSync`/`StatementSync`)
|
|
78
|
+
is the primary backend on Node 23.4+ and needs no native install or prebuilt
|
|
79
|
+
binary, so a fresh `npm install` on npm 11.2+/12 (which block install scripts by
|
|
80
|
+
default) just works. `better-sqlite3` remains as an `optionalDependencies`
|
|
81
|
+
fallback for Node 18–23.3.
|
|
82
|
+
|
|
83
|
+
- Backend selection is a runtime capability check, not a version-string match
|
|
84
|
+
(`CODE_AUDITOR_SQLITE_BACKEND=node-sqlite|better-sqlite3` forces one for the
|
|
85
|
+
parity suite). The active backend is reported in `code-audit --version`.
|
|
86
|
+
- `node:sqlite`'s missing `.transaction()`/`.pragma()` and its stricter
|
|
87
|
+
named-parameter binding are shimmed behind the same interface; error codes are
|
|
88
|
+
normalized to better-sqlite3's `SqliteError` shape so callers branching on
|
|
89
|
+
`SQLITE_BUSY` etc. behave identically.
|
|
90
|
+
- Full-suite and corpus parity verified: both backends produce byte-identical
|
|
91
|
+
results (recall-protocol corpus: 4,351 advisory findings under both).
|
|
92
|
+
- **Node floor:** `>=18` to run, `>=23.4` for the zero-native-install path.
|
|
93
|
+
|
|
5
94
|
## [3.8.1] — 2026-09-08
|
|
6
95
|
|
|
7
96
|
### Fresh-install fix — better-sqlite3 prebuild gap
|
package/README.md
CHANGED
|
@@ -26,6 +26,17 @@ claude plugin install code-auditor
|
|
|
26
26
|
|
|
27
27
|
The hook auto-installs the auditor on first use via npx.
|
|
28
28
|
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
- **Node 18+** to run. **Node 23.4+** gets the zero-native-install path: Code
|
|
32
|
+
Auditor uses the built-in `node:sqlite` module, so nothing needs to compile or
|
|
33
|
+
download a prebuilt binary on install.
|
|
34
|
+
- On older Node (18–23.3), Code Auditor falls back to `better-sqlite3`, an
|
|
35
|
+
*optional* dependency whose install script must be approved once on npm
|
|
36
|
+
11.2+/12 (they block dependency install scripts by default):
|
|
37
|
+
`npm install-scripts approve better-sqlite3 && npm rebuild better-sqlite3`
|
|
38
|
+
(with pnpm: `pnpm approve-builds`, then select `better-sqlite3`).
|
|
39
|
+
|
|
29
40
|
## Prompt examples
|
|
30
41
|
|
|
31
42
|
**"Index the codebase and run a full audit, then walk the violations file-by-file with `code-audit next-file`."**
|
|
@@ -68,6 +79,7 @@ One skill, one CLI, one MCP server. Every agent gets the same audit engine — t
|
|
|
68
79
|
| Gemini CLI | `code-audit install --agent gemini` | No | Yes | 2026-07-19 |
|
|
69
80
|
| VS Code / Copilot | `code-audit install --agent agents` | No | Yes | 2026-07-19 |
|
|
70
81
|
| Other SKILL.md tools | `code-audit install --agent agents` | No | Yes | 2026-07-19 |
|
|
82
|
+
| ZCode | `code-audit install --agent zcode` | No (plugin-scoped) | Yes | 2026-09-10 |
|
|
71
83
|
|
|
72
84
|
Hook behavior: **Blocking** means the diff-scoped `changed` gate is tripped — an invariant rule that declares `gating: true` (a binary, per-rule flag, independent of severity) blocks the edit from landing (the agent sees the violation and fixes inline). **Advisory** means violations are reported through the strongest available feedback channel but the edit has already occurred. Cursor's `afterFileEdit` hook is fire-and-forget with no output consumption. MCP is available everywhere for shell-less use.
|
|
73
85
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 1 — loop-query FALSE positive (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* `db.prepare(sql)` inside a loop builds a statement object; it performs no I/O.
|
|
5
|
+
* The statements are accumulated and executed once by a single `.batch()` after
|
|
6
|
+
* the loop. This is the `mod.ts:213/218/223/266` shape — not an N+1.
|
|
7
|
+
*/
|
|
8
|
+
interface Row {
|
|
9
|
+
id: number;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function insertMany(db: any, rows: Row[]): Promise<void>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=item-01-prepare-in-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-01-prepare-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-01-prepare-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,UAAU,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,UAAU,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAOpE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 1 — loop-query FALSE positive (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* `db.prepare(sql)` inside a loop builds a statement object; it performs no I/O.
|
|
5
|
+
* The statements are accumulated and executed once by a single `.batch()` after
|
|
6
|
+
* the loop. This is the `mod.ts:213/218/223/266` shape — not an N+1.
|
|
7
|
+
*/
|
|
8
|
+
export async function insertMany(db, rows) {
|
|
9
|
+
const stmts = [];
|
|
10
|
+
for (const row of rows) {
|
|
11
|
+
const stmt = db.prepare('INSERT INTO items (id, name) VALUES (?, ?)');
|
|
12
|
+
stmts.push(stmt);
|
|
13
|
+
}
|
|
14
|
+
await db.batch(stmts);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=item-01-prepare-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-01-prepare-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-01-prepare-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,EAAO,EAAE,IAAW;IACnD,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC;QACtE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 2 — accumulate-then-batch (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* The explicit accumulate-then-batch shape: each loop iteration prepares and
|
|
5
|
+
* binds a statement (statement construction — no I/O), pushes it to an array,
|
|
6
|
+
* and a single `.batch()` after the loop executes them all. The eager call sits
|
|
7
|
+
* outside the loop, so this is not an N+1.
|
|
8
|
+
*/
|
|
9
|
+
interface ScoreRow {
|
|
10
|
+
id: number;
|
|
11
|
+
score: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function rescoreMany(db: any, items: ScoreRow[]): Promise<void>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=item-02-prepare-bind-accumulate-batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-02-prepare-bind-accumulate-batch.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-02-prepare-bind-accumulate-batch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,UAAU,QAAQ;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 2 — accumulate-then-batch (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* The explicit accumulate-then-batch shape: each loop iteration prepares and
|
|
5
|
+
* binds a statement (statement construction — no I/O), pushes it to an array,
|
|
6
|
+
* and a single `.batch()` after the loop executes them all. The eager call sits
|
|
7
|
+
* outside the loop, so this is not an N+1.
|
|
8
|
+
*/
|
|
9
|
+
export async function rescoreMany(db, items) {
|
|
10
|
+
const stmts = [];
|
|
11
|
+
for (const item of items) {
|
|
12
|
+
const stmt = db.prepare('UPDATE scores SET score = ? WHERE id = ?').bind(item.score, item.id);
|
|
13
|
+
stmts.push(stmt);
|
|
14
|
+
}
|
|
15
|
+
await db.batch(stmts);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=item-02-prepare-bind-accumulate-batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-02-prepare-bind-accumulate-batch.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-02-prepare-bind-accumulate-batch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAO,EAAE,KAAiB;IAC1D,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,0CAA0C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9F,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 3 — loop-query TRUE positive (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* `db.exec(sql)` inside a loop is an eager member call — immediate I/O on every
|
|
5
|
+
* iteration. This is the simplest genuine-N+1 positive arm: the prepare/bind
|
|
6
|
+
* skip must be surgical and leave eager member methods firing.
|
|
7
|
+
*/
|
|
8
|
+
interface ItemRow {
|
|
9
|
+
id: number;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function renameAll(db: any, items: ItemRow[]): Promise<void>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=item-03-exec-in-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-03-exec-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-03-exec-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,UAAU,OAAO;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAIxE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 3 — loop-query TRUE positive (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* `db.exec(sql)` inside a loop is an eager member call — immediate I/O on every
|
|
5
|
+
* iteration. This is the simplest genuine-N+1 positive arm: the prepare/bind
|
|
6
|
+
* skip must be surgical and leave eager member methods firing.
|
|
7
|
+
*/
|
|
8
|
+
export async function renameAll(db, items) {
|
|
9
|
+
for (const item of items) {
|
|
10
|
+
db.exec(`UPDATE items SET name = 'renamed' WHERE id = ${item.id}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=item-03-exec-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-03-exec-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-03-exec-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAAO,EAAE,KAAgB;IACvD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,EAAE,CAAC,IAAI,CAAC,gDAAgD,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 4 — loop-query TRUE positive (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* The `Leaderboard.ts:113` discriminating positive: `this.ctx.storage.sql.exec(...)`
|
|
5
|
+
* inside a loop. `.exec()` is an eager method (immediate I/O), so this is a real
|
|
6
|
+
* N+1 that must keep firing — the two-direction proof's positive arm.
|
|
7
|
+
*/
|
|
8
|
+
interface RankRow {
|
|
9
|
+
id: number;
|
|
10
|
+
rank: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class Leaderboard {
|
|
13
|
+
private ctx;
|
|
14
|
+
constructor(ctx: {
|
|
15
|
+
storage: {
|
|
16
|
+
sql: {
|
|
17
|
+
exec: (query: string, ...bind: unknown[]) => void;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
applyRanks(rows: RankRow[]): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=item-04-storage-sql-exec-in-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-04-storage-sql-exec-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-04-storage-sql-exec-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,UAAU,OAAO;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,GAAG,CAA8E;IAEzF,YAAY,GAAG,EAAE;QAAE,OAAO,EAAE;YAAE,GAAG,EAAE;gBAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,EAE3F;IAEK,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/C;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 4 — loop-query TRUE positive (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* The `Leaderboard.ts:113` discriminating positive: `this.ctx.storage.sql.exec(...)`
|
|
5
|
+
* inside a loop. `.exec()` is an eager method (immediate I/O), so this is a real
|
|
6
|
+
* N+1 that must keep firing — the two-direction proof's positive arm.
|
|
7
|
+
*/
|
|
8
|
+
export class Leaderboard {
|
|
9
|
+
ctx;
|
|
10
|
+
constructor(ctx) {
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
}
|
|
13
|
+
async applyRanks(rows) {
|
|
14
|
+
for (const row of rows) {
|
|
15
|
+
this.ctx.storage.sql.exec('UPDATE leaderboard SET rank = ? WHERE id = ?', row.rank, row.id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=item-04-storage-sql-exec-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-04-storage-sql-exec-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-04-storage-sql-exec-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,MAAM,OAAO,WAAW;IACd,GAAG,CAA8E;IAEzF,YAAY,GAAgF;QAC1F,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAe;QAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,8CAA8C,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R2 — the four SQLite/Postgres upsert write forms (oracle: all MUST be
|
|
3
|
+
* classified as `insert` writes).
|
|
4
|
+
*
|
|
5
|
+
* `INSERT OR IGNORE INTO`, `INSERT OR REPLACE INTO`, `REPLACE INTO`, and
|
|
6
|
+
* `INSERT INTO ... ON CONFLICT ... DO UPDATE` all mutate the target table; the
|
|
7
|
+
* write classifier previously only matched `INSERT INTO`, so every rule reading
|
|
8
|
+
* the write set (written-never-read, multi-table-write) missed them.
|
|
9
|
+
*
|
|
10
|
+
* This fixture is exercised by the spec-52 test through `parseSqlTables`, which
|
|
11
|
+
* is the table-extraction path that feeds `schema_usage.usage_type`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const UPSERT_QUERIES: {
|
|
14
|
+
readonly insertOrIgnore: 'INSERT OR IGNORE INTO feature_flags (key, enabled) VALUES (?, ?)';
|
|
15
|
+
readonly insertOrReplace: 'INSERT OR REPLACE INTO feature_flags (key, enabled) VALUES (?, ?)';
|
|
16
|
+
readonly replaceInto: 'REPLACE INTO feature_flags (key, enabled) VALUES (?, ?)';
|
|
17
|
+
readonly onConflictDoUpdate: 'INSERT INTO feature_flags (key, enabled) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET enabled = excluded.enabled';
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=item-05-upsert-forms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-05-upsert-forms.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-05-upsert-forms.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,cAAc;aACzB,cAAc,EACZ,kEAAkE;aACpE,eAAe,EACb,mEAAmE;aACrE,WAAW,EACT,yDAAyD;aAC3D,kBAAkB,EAChB,mHAAmH;CAC7G,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R2 — the four SQLite/Postgres upsert write forms (oracle: all MUST be
|
|
3
|
+
* classified as `insert` writes).
|
|
4
|
+
*
|
|
5
|
+
* `INSERT OR IGNORE INTO`, `INSERT OR REPLACE INTO`, `REPLACE INTO`, and
|
|
6
|
+
* `INSERT INTO ... ON CONFLICT ... DO UPDATE` all mutate the target table; the
|
|
7
|
+
* write classifier previously only matched `INSERT INTO`, so every rule reading
|
|
8
|
+
* the write set (written-never-read, multi-table-write) missed them.
|
|
9
|
+
*
|
|
10
|
+
* This fixture is exercised by the spec-52 test through `parseSqlTables`, which
|
|
11
|
+
* is the table-extraction path that feeds `schema_usage.usage_type`.
|
|
12
|
+
*/
|
|
13
|
+
export const UPSERT_QUERIES = {
|
|
14
|
+
insertOrIgnore: 'INSERT OR IGNORE INTO feature_flags (key, enabled) VALUES (?, ?)',
|
|
15
|
+
insertOrReplace: 'INSERT OR REPLACE INTO feature_flags (key, enabled) VALUES (?, ?)',
|
|
16
|
+
replaceInto: 'REPLACE INTO feature_flags (key, enabled) VALUES (?, ?)',
|
|
17
|
+
onConflictDoUpdate: 'INSERT INTO feature_flags (key, enabled) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET enabled = excluded.enabled',
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=item-05-upsert-forms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-05-upsert-forms.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-05-upsert-forms.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,cAAc,EACZ,kEAAkE;IACpE,eAAe,EACb,mEAAmE;IACrE,WAAW,EACT,yDAAyD;IAC3D,kBAAkB,EAChB,mHAAmH;CAC7G,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 6 — chained prepare→bind→run in a loop (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* `db.prepare(sql).bind(x).run()` executes I/O on every iteration. Unlike the
|
|
5
|
+
* accumulate-then-batch shape (where the statement is pushed to an array and a
|
|
6
|
+
* single `.batch()` runs after the loop), the eager `.run()` sits *inside* the
|
|
7
|
+
* loop here, so this is a genuine N+1. The prepare/bind skip must be surgical:
|
|
8
|
+
* it skips standalone construction but leaves a prepare/bind that is chained
|
|
9
|
+
* into an eager call firing.
|
|
10
|
+
*/
|
|
11
|
+
interface SyncJob {
|
|
12
|
+
id: number;
|
|
13
|
+
slug: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function syncBuildsForHeroes(db: any, jobs: SyncJob[]): Promise<void>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=item-06-chained-prepare-run-in-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-06-chained-prepare-run-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-06-chained-prepare-run-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,UAAU,OAAO;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CASjF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 6 — chained prepare→bind→run in a loop (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* `db.prepare(sql).bind(x).run()` executes I/O on every iteration. Unlike the
|
|
5
|
+
* accumulate-then-batch shape (where the statement is pushed to an array and a
|
|
6
|
+
* single `.batch()` runs after the loop), the eager `.run()` sits *inside* the
|
|
7
|
+
* loop here, so this is a genuine N+1. The prepare/bind skip must be surgical:
|
|
8
|
+
* it skips standalone construction but leaves a prepare/bind that is chained
|
|
9
|
+
* into an eager call firing.
|
|
10
|
+
*/
|
|
11
|
+
export async function syncBuildsForHeroes(db, jobs) {
|
|
12
|
+
for (const job of jobs) {
|
|
13
|
+
await db
|
|
14
|
+
.prepare(`UPDATE sync_jobs SET status = 'running', started_at = datetime('now') WHERE id = ?`)
|
|
15
|
+
.bind(job.id)
|
|
16
|
+
.run();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=item-06-chained-prepare-run-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-06-chained-prepare-run-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-06-chained-prepare-run-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,EAAO,EAAE,IAAe;IAChE,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,EAAE;aACL,OAAO,CACN,oFAAoF,CACrF;aACA,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;aACZ,GAAG,EAAE,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 7 — chained prepare→bind→first<Row>() in a loop (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* The typed-read N+1: `.first<Row>()` (and `.all<Row>()`) is the D1 read idiom.
|
|
5
|
+
* The generic type argument must not hide the eager method from detection — the
|
|
6
|
+
* same gap that bit `too-many-queries`'s text regex. The AST path reads the
|
|
7
|
+
* property name directly, so `first` is visible regardless of `<Row>`.
|
|
8
|
+
*/
|
|
9
|
+
interface HeroRow {
|
|
10
|
+
id: number;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
interface Statement {
|
|
14
|
+
bind(...args: unknown[]): Statement;
|
|
15
|
+
first<T>(): T | null;
|
|
16
|
+
all<T>(): T[];
|
|
17
|
+
run(): unknown;
|
|
18
|
+
}
|
|
19
|
+
interface Db {
|
|
20
|
+
prepare(sql: string): Statement;
|
|
21
|
+
batch(stmts: unknown[]): unknown;
|
|
22
|
+
}
|
|
23
|
+
export declare function fetchHeroById(db: Db, ids: number[]): Promise<HeroRow[]>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=item-07-chained-prepare-bind-first-in-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-07-chained-prepare-bind-first-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-07-chained-prepare-bind-first-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,UAAU,OAAO;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAID,UAAU,SAAS;IACjB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IACpC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACrB,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;IACd,GAAG,IAAI,OAAO,CAAC;CAChB;AACD,UAAU,EAAE;IACV,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;CAClC;AAED,wBAAsB,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAU7E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 7 — chained prepare→bind→first<Row>() in a loop (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* The typed-read N+1: `.first<Row>()` (and `.all<Row>()`) is the D1 read idiom.
|
|
5
|
+
* The generic type argument must not hide the eager method from detection — the
|
|
6
|
+
* same gap that bit `too-many-queries`'s text regex. The AST path reads the
|
|
7
|
+
* property name directly, so `first` is visible regardless of `<Row>`.
|
|
8
|
+
*/
|
|
9
|
+
export async function fetchHeroById(db, ids) {
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const id of ids) {
|
|
12
|
+
const row = await db
|
|
13
|
+
.prepare('SELECT id, name FROM heroes WHERE id = ?')
|
|
14
|
+
.bind(id)
|
|
15
|
+
.first();
|
|
16
|
+
if (row)
|
|
17
|
+
out.push(row);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=item-07-chained-prepare-bind-first-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-07-chained-prepare-bind-first-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-07-chained-prepare-bind-first-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoBH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,EAAM,EAAE,GAAa;IACvD,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,GAAG,GAAG,MAAM,EAAE;aACjB,OAAO,CAAC,0CAA0C,CAAC;aACnD,IAAI,CAAC,EAAE,CAAC;aACR,KAAK,EAAW,CAAC;QACpB,IAAI,GAAG;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 8 — Promise.all of plain statements in a loop (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* `Promise.all([db.prepare(sql).bind(x), …])` wraps *statement objects* (no
|
|
5
|
+
* `.run()`/`.all()`/`.first()`), so nothing executes inside the loop. This is
|
|
6
|
+
* construction, not an N+1. `Promise.all` must not be misread as the eager D1
|
|
7
|
+
* `.all()` method just because its property name is "all".
|
|
8
|
+
*/
|
|
9
|
+
interface ItemRow {
|
|
10
|
+
id: number;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function stageMany(db: any, items: ItemRow[]): Promise<unknown[]>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=item-08-promise-all-of-statements-in-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-08-promise-all-of-statements-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-08-promise-all-of-statements-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,UAAU,OAAO;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAW7E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 8 — Promise.all of plain statements in a loop (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* `Promise.all([db.prepare(sql).bind(x), …])` wraps *statement objects* (no
|
|
5
|
+
* `.run()`/`.all()`/`.first()`), so nothing executes inside the loop. This is
|
|
6
|
+
* construction, not an N+1. `Promise.all` must not be misread as the eager D1
|
|
7
|
+
* `.all()` method just because its property name is "all".
|
|
8
|
+
*/
|
|
9
|
+
export async function stageMany(db, items) {
|
|
10
|
+
const staged = [];
|
|
11
|
+
for (const item of items) {
|
|
12
|
+
staged.push(await Promise.all([
|
|
13
|
+
db.prepare('SELECT id FROM items WHERE id = ?').bind(item.id),
|
|
14
|
+
db.prepare('SELECT name FROM items WHERE id = ?').bind(item.id),
|
|
15
|
+
]));
|
|
16
|
+
}
|
|
17
|
+
return staged;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=item-08-promise-all-of-statements-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-08-promise-all-of-statements-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-08-promise-all-of-statements-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAAO,EAAE,KAAgB;IACvD,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,IAAI,CACT,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,EAAE,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7D,EAAE,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;SAChE,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 9 — Promise.all of a .map() of plain statements (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* `Promise.all(rows.map(r => db.prepare(sql).bind(r)))` wraps *statement
|
|
5
|
+
* objects* (no `.run()`/`.all()`/`.first()`), so nothing executes inside the
|
|
6
|
+
* loop. The walk-up must cross the arrow function boundary and still recognise
|
|
7
|
+
* `Promise.all` as the promise combinator, not the eager D1 `.all()`.
|
|
8
|
+
*/
|
|
9
|
+
interface ItemRow {
|
|
10
|
+
id: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function stageMapped(db: any, rows: ItemRow[]): Promise<void>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=item-09-promise-all-map-of-statements-in-loop.d.ts.map
|
package/dist/__tests__/fixtures/spec-52/item-09-promise-all-map-of-statements-in-loop.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-09-promise-all-map-of-statements-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-09-promise-all-map-of-statements-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,UAAU,OAAO;IACf,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAsB,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 9 — Promise.all of a .map() of plain statements (oracle: MUST NOT fire).
|
|
3
|
+
*
|
|
4
|
+
* `Promise.all(rows.map(r => db.prepare(sql).bind(r)))` wraps *statement
|
|
5
|
+
* objects* (no `.run()`/`.all()`/`.first()`), so nothing executes inside the
|
|
6
|
+
* loop. The walk-up must cross the arrow function boundary and still recognise
|
|
7
|
+
* `Promise.all` as the promise combinator, not the eager D1 `.all()`.
|
|
8
|
+
*/
|
|
9
|
+
export async function stageMapped(db, rows) {
|
|
10
|
+
for (const row of rows) {
|
|
11
|
+
await Promise.all(rows.map((r) => db.prepare('SELECT id FROM items WHERE id = ?').bind(r.id)));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=item-09-promise-all-map-of-statements-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-09-promise-all-map-of-statements-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-09-promise-all-map-of-statements-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAO,EAAE,IAAe;IACxD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAC5E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 10 — Promise.all of a .map() of eager `.all()` calls (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* The discriminating positive for the Promise.all guard: `Promise.all` is a
|
|
5
|
+
* promise combinator and must be *skipped*, but the eager D1 `.all()` on each
|
|
6
|
+
* mapped statement still executes per row — a genuine N+1. Crossing the arrow
|
|
7
|
+
* function to reach the eager method (and skip the combinator on the way) is
|
|
8
|
+
* exactly what the guard must get right.
|
|
9
|
+
*/
|
|
10
|
+
interface ItemRow {
|
|
11
|
+
id: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function fetchMapped(db: any, rows: ItemRow[]): Promise<unknown[]>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=item-10-promise-all-map-of-eager-all-in-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-10-promise-all-map-of-eager-all-in-loop.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-10-promise-all-map-of-eager-all-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,UAAU,OAAO;IACf,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAsB,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAO9E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec-52 R1 item 10 — Promise.all of a .map() of eager `.all()` calls (oracle: MUST fire).
|
|
3
|
+
*
|
|
4
|
+
* The discriminating positive for the Promise.all guard: `Promise.all` is a
|
|
5
|
+
* promise combinator and must be *skipped*, but the eager D1 `.all()` on each
|
|
6
|
+
* mapped statement still executes per row — a genuine N+1. Crossing the arrow
|
|
7
|
+
* function to reach the eager method (and skip the combinator on the way) is
|
|
8
|
+
* exactly what the guard must get right.
|
|
9
|
+
*/
|
|
10
|
+
export async function fetchMapped(db, rows) {
|
|
11
|
+
for (const row of rows) {
|
|
12
|
+
await Promise.all(rows.map((r) => db.prepare('SELECT id FROM items WHERE id = ?').bind(r.id).all()));
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=item-10-promise-all-map-of-eager-all-in-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-10-promise-all-map-of-eager-all-in-loop.js","sourceRoot":"","sources":["../../../../src/__tests__/fixtures/spec-52/item-10-promise-all-map-of-eager-all-in-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAO,EAAE,IAAe;IACxD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAClF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|