Skip to content

Commit dc138a5

Browse files
refactor(driver-sql): the by-path readers read the sql-driver facade, so the codemod moves the five path-reader members (#30147 phase 2c) (#30363)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBWMEECkfNfe2VjW9rMJG3n7)_ Part of #30147 (phase 2c of 2a-2d: the readers that sliced `sql-driver.ts` by path read the facade form, so the codemod moves the five path-reader members. 2d and the phase 3 measurement stay open on the card.) ## 维护者速读 - 改了什么:新增 `scripts/sql-driver-split-source.mjs`,把 `SqlDriver` 重新读成一份文本(每个 codemod stub 的方法体换成它所调用的 facet 方法体,leaf 放回类前);cli 的 5 个 generate-* pin 和 `check-keyed-text-bounds.mjs` 改用它。codemod 因此清空 2 个 pin 和 10 个 needle,`createColumn` 写出返回类型 `void`,重新生成后 5 个成员变成委托,登记表 73 → 68。 - 为什么改:这些读者只认 `sql-driver.ts` 本文件的文字,codemod 只好把这 5 个方法留在类上(#30147,裁决 6597555122 第 3 条:读者与模块同一个 PR 里跟上)。 - 风险与回滚:方法体逐字节不变(180/180),公开 `.d.ts` 与 base 相同;5 个 pin 断言一条未改,只换了读取来源。回滚即 revert。 - 先看:`sql-driver-split-source.mjs`(约 160 行,只认 codemod 写的 stub 形态,认不出就抛错而不是读 stub);`cross-package-test-inputs.mjs` 与 `turbo.json` 里为 cli 新增的声明。 - 两分钟验证:`node scripts/codemod-split-sql-driver.mjs --self-test`(新电池 "split readers (#30147)" 8 例)和 `node scripts/check-keyed-text-bounds.mjs --self-test`(新增 3 例),都退出 0。 - 需要你做的:无,席位审阅并落地。 Clause-②: no Metadata-protocol: none ## What changes Five members stayed on `SqlDriver` because readers sliced `sql-driver.ts` by path: `createColumn`, `createAuditTimestampColumn`, `varcharColumnChars`, `ensureShardTable` and `initObjects`. Each reader now reads `SqlDriver` as one text, and the codemod tables that held the five go. **`scripts/sql-driver-split-source.mjs` (new, with its `.d.mts`).** `readSqlDriverSource(srcDir)` returns `sql-driver.ts` with the body of every codemod stub replaced by the body of the facet method it calls, and the leaf (`sql-driver-top-level.ts`) put back ahead of the class. A method's own signature on the class is then followed by its own body, as before the split. It follows exactly the stub the codemod writes: one statement, carrying the `[#29520 codemod]` marker, returning `<X>Facet.<m>(…)` or `<X>Facet.<m>.call(<x>Host.of(this), …)` (or the generic spelling), with the module named in the marker. A marked body of any other shape, a missing module, or a facet without that static member throws. The reader never hands back the stub text. Unmarked bodies (the hand-series delegations) stay as they are. It is a reading, not an undo: imports, a private docblock and the stub-side spellings stay as the split has them. `--verify` remains the byte-for-byte proof. **Readers.** - The five `packages/cli` generate-* pins (`builtin-id-column`, `field-type-vocabulary`, `file-reference-width`, `multiple-json-column`, `string-family-width`) build `SQL_DRIVER_SOURCE` from `readSqlDriverSource(DRIVER_SQL_SRC).text` instead of `readFileSync(…/sql-driver.ts)`. No assertion, anchor or message changes. - `scripts/check-keyed-text-bounds.mjs` reads its emitter the same way. A reader refusal becomes the gate's existing `{ error }` refusal. **Codemod (`scripts/codemod-split-sql-driver.mjs`).** - `PATH_READER_PINS` (2 rows) and `PATH_READER_NEEDLES` (10 rows) are emptied. Both tables stay, with a note on why they are empty. - `EXPLICIT_RETURN_TYPES` gains `createColumn: 'void'`, copied from the base `dist/index.d.ts` (`protected createColumn(…): void;`). - Regenerated from `21510bba`: `createColumn`, `createAuditTimestampColumn` and `varcharColumnChars` move to `sql-driver-column-creation.ts`; `ensureShardTable` and `initObjects` move to `sql-driver-rotation.ts`; two top-level declarations move to the leaf. `sql-driver.ts` goes from 10,624 to 9,741 lines. **Declarations.** The pins now read every `sql-driver-*.ts` module a stub names, through paths the cross-package scan cannot name. `scripts/cross-package-test-inputs.mjs` gives `@objectstack/cli` the glob `packages/drivers/driver-sql/src/sql-driver-*.ts` plus the reader and its `.d.mts`, with `heldBy` witnesses naming the five pins (and one for `sql-driver.ts`, which no literal names any more). `turbo.json` `@objectstack/cli#test` carries the same three inputs. The glob also matches the package's tests; that adds no re-run, because `cli#test` already depends on `build` → `^build`, and driver-sql's `build` hashes `$TURBO_DEFAULT$`. **Registry.** The five rows are deleted, so 73 rows become 68 (the base has 73: #30264 added four `engine.ts` rows after 2b's count of 69). | card | before | after | |:--|--:|--:| | #30020 | 19 | 19 | | #30054 | 16 | 16 | | #30055 | 6 | 6 | | #30147 | 32 | 27 (sql-driver.ts 8 → 3) | | total | 73 | 68 | The three `sql-driver.ts` rows left on #30147 are `applyFilterCondition` (2d), `get supports` and `static DIALECT_CONNECT_TIMEOUT` (phase 3 names both). ## Tests - Codemod `--self-test` gains a seventh battery, "split readers (#30147)", with 8 cases, driven over a split the script generates and lays out on disk: - every stub is followed; - each followed stub reads its base body byte for byte after the signature the class keeps; - no stub text survives; - the leaf stands ahead of the class; - an unsplit file is read as it stands; - a missing module, a facet without the static, and a marked stub of another shape each refuse. 106 cases in 7 batteries (98 in 6 before); the battery floor goes 6 → 7. - `check-keyed-text-bounds --self-test` gains 3 cases in "the emitter-derived family" (floor 3 → 6): the family is read through a stub from the facet module, and a stub naming an undeclared facet or of another shape refuses. - No assertion in any of the five pins changes. Before the reader change, the regenerated tree reds 28 of their cases and `check-keyed-text-bounds` exits 2 ("could not find the keyed-text arm"). Measured. - The suites below ran at base `bfca0efb` and at head; the counts are equal. | suite | base | head | |:--|:--|:--| | driver-sql (`vitest run`) | 238 files passed, 12 skipped; 3,859 passed, 216 skipped | the same | | driver-turso (subclasses `SqlDriver`) | 97 files; 2,514 passed, 34 skipped | the same | | driver-sqlite-wasm (subclasses `SqlDriver`) | 40 files; 750 passed | the same | | cli by-path pins (9 files, the five generate-* pins among them) | 9 files; 116 passed | the same | | types / metadata / metadata-protocol by-path tests, spec `check-liveness.test` | 53 / 11 / 33 / 74 passed | the same | ## Acceptance notes - The facade gate script and its self-test are untouched. `check-keyed-text-bounds.mjs` and the cli pins are by-path readers. - No changeset, as #30139, #30249 and #30306 (`skip-changeset`): no published behaviour or surface changes. ## Verification Head `d67df0b5`, base `origin/main` `bfca0efb`. <details><summary>Proof readings</summary> - Byte-identity: `node scripts/codemod-split-sql-driver.mjs --verify --base 21510bb` exit 0, "180/180 moved bodies identical to base (body, parameters, return type, async); 129/129 moved top-level declarations identical to base (leading comments included); sql-driver.ts 18334 -> 9741 lines; undoing the split does rebuild the base byte-for-byte". - Determinism: two `--write` runs from the unsplit input give output tree sha256 `0d2ba8a299610def947cd879cee7e7c36aae58aecfca0f8acacc395339f7bf16` both times (input sha256 `2d2ebebd…`), and the tree on disk is unchanged by either. - Public `.d.ts`: `dts-public.mjs` over the base and head `dist` exit 0, `pass: true`, both files raw-equal (`index.d.ts` sha256 `92e2cfb2…` on both sides, as at 2a and 2b). - Typecheck: `pnpm --filter @objectstack/driver-sql typecheck` and `pnpm --filter @objectstack/cli typecheck` (which includes `check:test-typecheck`, so the pins' import of the `.d.mts`) exit 0. - `check-tenant-chokepoint`: 24/21/3/4/0 across 39 files at base and head; `--self-test` exit 0. - Durability gate `--list` at base and head: 52 durability seams with the same verdicts (103 read seams); the only change is the line of the two `runWideningAlters()` seams inside `sql-driver-rotation.ts` (`:321`/`:367` → `:661`/`:707`), because `ensureShardTable` and `initObjects` moved in above them. - `check-keyed-text-bounds`: exit 0 over the tree, the family read through the stub is the same 8 types; `--self-test` exit 0. - `check-cross-package-test-inputs` and `check-ci-filter-parity` exit 0. - Facade gate exit 0, "5 facade class(es) in 3 file(s) hold delegations only, 68 named exception(s)"; `--self-test` exit 0 (gate script and its cases untouched). - `node scripts/pm/dispatch-gates.mjs --commands`: 79 derived commands, each run, all exit 0; `--ran` reconciles 79 derived, 79 run, 0 NOT-MEASURED. Also run: the codemod, `check-keyed-text-bounds`, durability, `check-tenant-chokepoint` and facade gate `--self-test`s, `check:lean-entry-closure`, eslint over the changed files (0 errors), all exit 0. - Changed lines 2,417 (+1,407 / -1,010), under the 3,000 threshold. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzj4B2cbnRLVdgtLcDZ)_ Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 29702d5 commit dc138a5

17 files changed

Lines changed: 1407 additions & 1010 deletions

‎packages/cli/src/commands/generate-builtin-id-column.pin.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import fs from 'node:fs';
8989
import path from 'node:path';
9090
import { fileURLToPath } from 'node:url';
9191

92+
import { readSqlDriverSource } from '../../../../scripts/sql-driver-split-source.mjs';
9293
import { describe, expect, it } from 'vitest';
9394

9495
import { generateMigrationSql, generateMigrationTs } from './generate.js';
@@ -99,7 +100,9 @@ const GENERATE_SOURCE = fs.readFileSync(GENERATE_TS, 'utf8');
99100

100101
/** The authority, read where it lives — never transcribed here. */
101102
const DRIVER_SQL_SRC = path.resolve(HERE, '../../../drivers/driver-sql/src');
102-
const SQL_DRIVER_SOURCE = fs.readFileSync(path.join(DRIVER_SQL_SRC, 'sql-driver.ts'), 'utf8');
103+
// `SqlDriver` as one text: `sql-driver.ts` with each codemod stub's body read
104+
// from the facet module it moved to, and the leaf ahead of the class (#30147).
105+
const SQL_DRIVER_SOURCE = readSqlDriverSource(DRIVER_SQL_SRC).text;
103106

104107
/** The one line the driver emits for a managed table's primary key. */
105108
const DRIVER_ID_COLUMN = "table.string('id').primary();";

‎packages/cli/src/commands/generate-field-type-vocabulary.pin.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ import {
136136
REFERENCE_VALUE_TYPES,
137137
STRUCTURED_JSON_TYPES,
138138
} from '@objectstack/spec/data';
139+
import { readSqlDriverSource } from '../../../../scripts/sql-driver-split-source.mjs';
139140
import { describe, expect, it } from 'vitest';
140141

141142
import { generateMigrationSql, generateMigrationTs, generateTypesFromConfig } from './generate.js';
@@ -318,7 +319,9 @@ describe('generate.ts field-type vocabularies (#13871)', () => {
318319

319320
/** `packages/drivers/driver-sql/src` — declared for `@objectstack/cli#test` in `turbo.json`. */
320321
const DRIVER_SQL_SRC = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../drivers/driver-sql/src');
321-
const SQL_DRIVER_SOURCE = fs.readFileSync(path.join(DRIVER_SQL_SRC, 'sql-driver.ts'), 'utf8');
322+
// `SqlDriver` as one text: `sql-driver.ts` with each codemod stub's body read
323+
// from the facet module it moved to, and the leaf ahead of the class (#30147).
324+
const SQL_DRIVER_SOURCE = readSqlDriverSource(DRIVER_SQL_SRC).text;
322325
const SCHEMA_DRIFT_SOURCE = fs.readFileSync(path.join(DRIVER_SQL_SRC, 'schema-drift.ts'), 'utf8');
323326

324327
/**

‎packages/cli/src/commands/generate-file-reference-width.pin.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ import path from 'node:path';
6767
import { fileURLToPath } from 'node:url';
6868

6969
import { FILE_REFERENCE_TYPES, REFERENCE_VALUE_TYPES } from '@objectstack/spec/data';
70+
import { readSqlDriverSource } from '../../../../scripts/sql-driver-split-source.mjs';
7071
import { describe, expect, it } from 'vitest';
7172

7273
import { generateMigrationSql, generateMigrationTs } from './generate.js';
7374

7475
/** `packages/drivers/driver-sql/src` — declared for `@objectstack/cli#test` in `turbo.json`. */
7576
const DRIVER_SQL_SRC = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../drivers/driver-sql/src');
76-
const SQL_DRIVER_SOURCE = fs.readFileSync(path.join(DRIVER_SQL_SRC, 'sql-driver.ts'), 'utf8');
77+
// `SqlDriver` as one text: `sql-driver.ts` with each codemod stub's body read
78+
// from the facet module it moved to, and the leaf ahead of the class (#30147).
79+
const SQL_DRIVER_SOURCE = readSqlDriverSource(DRIVER_SQL_SRC).text;
7780

7881
/** The control the generator documents, plus the arm the family used to ride. */
7982
const CONTROL_TYPES = ['text', ...REFERENCE_VALUE_TYPES, 'autonumber'] as const;

‎packages/cli/src/commands/generate-multiple-json-column.pin.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import path from 'node:path';
8888
import { fileURLToPath } from 'node:url';
8989

9090
import { isMultiValueField, MULTI_CAPABLE_TYPES, MULTI_OPTION_TYPES } from '@objectstack/spec/data';
91+
import { readSqlDriverSource } from '../../../../scripts/sql-driver-split-source.mjs';
9192
import { describe, expect, it } from 'vitest';
9293

9394
import {
@@ -377,7 +378,8 @@ describe('#14829 — `multiple: true` is one answer across all three surfaces',
377378
// this rule, these fail and whoever moved it re-derives the generators.
378379

379380
it('driver-sql `createColumn` still decides `multiple` BEFORE the type switch', () => {
380-
const source = fs.readFileSync(path.join(DRIVER_SQL_SRC, 'sql-driver.ts'), 'utf8');
381+
// `SqlDriver` as one text, each codemod stub's body read where it moved (#30147).
382+
const source = readSqlDriverSource(DRIVER_SQL_SRC).text;
381383
// Non-vacuity: the file was really read, and the two landmarks really found.
382384
expect(source.length).toBeGreaterThan(10_000);
383385
const start = source.indexOf('protected createColumn(');

‎packages/cli/src/commands/generate-string-family-width.pin.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ import {
251251
MULTI_OPTION_TYPES,
252252
STRUCTURED_JSON_TYPES,
253253
} from '@objectstack/spec/data';
254+
import { readSqlDriverSource } from '../../../../scripts/sql-driver-split-source.mjs';
254255
import { afterAll, describe, expect, it } from 'vitest';
255256

256257
import { generateMigrationSql, generateMigrationTs } from './generate.js';
@@ -260,7 +261,9 @@ const GENERATE_SOURCE = fs.readFileSync(path.resolve(HERE, 'generate.ts'), 'utf8
260261

261262
/** The authority, read where it lives — never transcribed here. */
262263
const DRIVER_SQL_SRC = path.resolve(HERE, '../../../drivers/driver-sql/src');
263-
const SQL_DRIVER_SOURCE = fs.readFileSync(path.join(DRIVER_SQL_SRC, 'sql-driver.ts'), 'utf8');
264+
// `SqlDriver` as one text: `sql-driver.ts` with each codemod stub's body read
265+
// from the facet module it moved to, and the leaf ahead of the class (#30147).
266+
const SQL_DRIVER_SOURCE = readSqlDriverSource(DRIVER_SQL_SRC).text;
264267
const SCHEMA_DRIFT_SOURCE = fs.readFileSync(path.join(DRIVER_SQL_SRC, 'schema-drift.ts'), 'utf8');
265268

266269
/** The authority for which types exist at all. Imported, never listed here. */

0 commit comments

Comments
 (0)