Skip to content

Commit d3ca391

Browse files
committed
refactor(driver-sql): the durability gate and the compile-refusal enumeration read the sql-driver facade, so the codemod moves four more members (#30147 phase 2b)
check-durability-degradation-log-level.mjs follows a catch's log helper across the facade (FACADE_LOG_HOP): `this.x()` in a sql-driver-*.ts facet module resolves to SqlDriver#x through the module's host interface, and a `<X>Facet.x.call(<y>Host.of(this), ...)` stub is read as the facet body. sql-driver-compile-refusal-seam.test.ts reads every sql-driver-*.ts module and names a facet static as the SqlDriver method it is. The codemod drops the logDurabilityFailure pin, the runWideningAlters needle and the CLASS_PATH_READER_NEEDLES rows; regenerated from 21510bb, logDurabilityFailure, migrateMysqlDatetimeColumns, migrateMysqlTimeColumns and resolveWithheldFilterRefusal move (175/175 bodies identical, public .d.ts byte-identical). Registry 73 -> 69 rows. Claude-Session: https://claude.ai/code/session_01WGufzj4B2cbnRLVdgtLcDZ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9b8a586 commit d3ca391

8 files changed

Lines changed: 542 additions & 198 deletions

‎packages/drivers/driver-sql/src/sql-driver-class-head.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
/**
44
* [#29520 codemod] The "Class head: dialect probes, logger, configuration"
5-
* section of `SqlDriver`: the bodies of `logger`, `emissionClients`,
6-
* `clientSpelling`, `insertReturnsStoredRows`, `aliasIdentifierSql`,
7-
* `dateGranularityCapabilities`, `dateBucketSql`, `knexConfigFor`,
8-
* `withConnectBound`, `withUtcSession`, `withMysqlCalendarDayAsText`,
9-
* `withPostgresCalendarDayAsText`, `installQueryTiming`, `assertSchemaMutable`,
10-
* `assertDialectEmits` moved out of `sql-driver.ts` whole by
11-
* `scripts/codemod-split-sql-driver.mjs`.
5+
* section of `SqlDriver`: the bodies of `logger`, `logDurabilityFailure`,
6+
* `emissionClients`, `clientSpelling`, `insertReturnsStoredRows`,
7+
* `aliasIdentifierSql`, `dateGranularityCapabilities`, `dateBucketSql`,
8+
* `knexConfigFor`, `withConnectBound`, `withUtcSession`,
9+
* `withMysqlCalendarDayAsText`, `withPostgresCalendarDayAsText`,
10+
* `installQueryTiming`, `assertSchemaMutable`, `assertDialectEmits` moved out
11+
* of `sql-driver.ts` whole by `scripts/codemod-split-sql-driver.mjs`.
1212
*
1313
* A MOVE, not a redesign. {@link ClassHeadFacet} is a stateless facet of `SqlDriver`
1414
* (ruling 6624345766): each static method of it is the body of the `SqlDriver`
@@ -65,6 +65,7 @@ export interface ClassHeadHost {
6565
readonly isPostgres: SqlDriverClass['isPostgres'];
6666
readonly isSqlite: SqlDriverClass['isSqlite'];
6767
readonly knex: SqlDriverClass['knex'];
68+
readonly logger: SqlDriverClass['logger'];
6869
openedEmptyInMemory: SqlDriverClass['openedEmptyInMemory'];
6970
readonly schemaMode: SqlDriverClass['schemaMode'];
7071
}
@@ -79,6 +80,12 @@ export class ClassHeadFacet {
7980
};
8081
}
8182

83+
/** The body of `SqlDriver#logDurabilityFailure`; the method's docblock there is its contract. */
84+
static logDurabilityFailure(this: Pick<ClassHeadHost, 'logger'>, msg: string, meta?: any): void {
85+
if (this.logger.error) this.logger.error(msg, meta);
86+
else this.logger.warn(msg, meta);
87+
}
88+
8289
/** The body of `SqlDriver#emissionClients`; the method's docblock there is its contract. */
8390
static emissionClients(): string[] {
8491
return [

‎packages/drivers/driver-sql/src/sql-driver-compile-refusal-seam.test.ts‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
* fault module `sql-driver-read-exit-fault.ts` (#25521 cut 15) and the
3333
* predicate-emitter module `sql-driver-predicate-emitters.ts` (#25521 cut 16)
3434
* and the generated top-level leaf `sql-driver-top-level.ts` (#29520 codemod),
35+
* and, since #30147, every other `sql-driver-*.ts` module beside it (a
36+
* facet member is named as the `SqlDriver` method whose body it is),
3537
* and lists every function that builds an `INVALID_FILTER` error. Only three may call
3638
* `unsupportedFilterError` directly (the seam itself, the `'author'`
3739
* re-issue, and the column refusal raised from a dialect error AFTER the
@@ -48,7 +50,7 @@
4850
*/
4951

5052
import { describe, it, expect, beforeEach } from 'vitest';
51-
import { readFileSync } from 'node:fs';
53+
import { readdirSync, readFileSync } from 'node:fs';
5254
import ts from 'typescript';
5355
import { SqlDriver } from './index.js';
5456
import { markFilterSubtreeProvenance, type FilterCondition } from '@objectstack/spec/data';
@@ -275,12 +277,12 @@ const DOORS: readonly Door[] = [
275277
// ── Half 1: the enumeration ───────────────────────────────────────────────────
276278

277279
/**
278-
* Every function in `sql-driver.ts`, `sql-driver-cross-field-comparison.ts`,
279-
* `sql-driver-read-exit-fault.ts` and `sql-driver-predicate-emitters.ts` that builds an `INVALID_FILTER` error, by the route it takes. Read with the TypeScript parser, not a regex, so a call
280+
* Every function in `sql-driver.ts` and every `sql-driver-*.ts` module beside it that builds an `INVALID_FILTER` error, by the route it takes. Read with the TypeScript parser, not a regex, so a call
280281
* split across lines, an inline `throw`, or a builder written as a method or an
281282
* arrow cannot slip past the count.
282283
*/
283284
function enumerateRefusalBuilders(): {
285+
files: string[];
284286
directCallers: Set<string>;
285287
seamCallers: Set<string>;
286288
codeWriters: Set<string>;
@@ -293,13 +295,14 @@ function enumerateRefusalBuilders(): {
293295
// `$empty` refusals; the scan reads it too.
294296
// [#29520 codemod] The top-level declarations ahead of the class moved to a
295297
// generated leaf, with the refusal builders among them; the scan reads it too.
296-
const sources = [
297-
['sql-driver.ts', readFileSync(new URL('./sql-driver.ts', import.meta.url), 'utf8')],
298-
['sql-driver-cross-field-comparison.ts', readFileSync(new URL('./sql-driver-cross-field-comparison.ts', import.meta.url), 'utf8')],
299-
['sql-driver-read-exit-fault.ts', readFileSync(new URL('./sql-driver-read-exit-fault.ts', import.meta.url), 'utf8')],
300-
['sql-driver-predicate-emitters.ts', readFileSync(new URL('./sql-driver-predicate-emitters.ts', import.meta.url), 'utf8')],
301-
['sql-driver-top-level.ts', readFileSync(new URL('./sql-driver-top-level.ts', import.meta.url), 'utf8')],
302-
] as const;
298+
// [#30147] The codemod moves a class method's body into a facet class
299+
// (`export class <X>Facet`) in any section module, so the scan reads every
300+
// `sql-driver-*.ts` module, not a list a move can outrun, and names a facet's
301+
// static `x` as `SqlDriver.x`: it is that method's body.
302+
const files = readdirSync(new URL('.', import.meta.url))
303+
.filter((f) => /^sql-driver(-[a-z0-9-]+)?\.ts$/.test(f) && !f.endsWith('.test.ts'))
304+
.sort();
305+
const sources = files.map((f) => [f, readFileSync(new URL(`./${f}`, import.meta.url), 'utf8')] as const);
303306
const directCallers = new Set<string>();
304307
const seamCallers = new Set<string>();
305308
const codeWriters = new Set<string>();
@@ -310,7 +313,7 @@ function enumerateRefusalBuilders(): {
310313
if (ts.isMethodDeclaration(at) && ts.isIdentifier(at.name)) {
311314
const owner = at.parent;
312315
const cls = ts.isClassDeclaration(owner) && owner.name ? owner.name.text : '?';
313-
return `${cls}.${at.name.text}`;
316+
return `${/^[A-Z][A-Za-z0-9]*Facet$/.test(cls) ? 'SqlDriver' : cls}.${at.name.text}`;
314317
}
315318
if ((ts.isArrowFunction(at) || ts.isFunctionExpression(at)) && ts.isVariableDeclaration(at.parent)) {
316319
const decl = at.parent;
@@ -357,7 +360,7 @@ function enumerateRefusalBuilders(): {
357360
ts.forEachChild(node, visit);
358361
};
359362
for (const [name, source] of sources) visit(ts.createSourceFile(name, source, ts.ScriptTarget.Latest, true));
360-
return { directCallers, seamCallers, codeWriters };
363+
return { files, directCallers, seamCallers, codeWriters };
361364
}
362365

363366
describe('[#20039] the filter-compile refusal class is closed — enumeration', () => {
@@ -376,6 +379,12 @@ describe('[#20039] the filter-compile refusal class is closed — enumeration',
376379
expect(found.seamCallers, builder).toContain(builder);
377380
}
378381
expect(found.directCallers).toContain('unresolvableFilterColumnError');
382+
// [#30147] The modules the builders were found in before the scan read
383+
// every module, and one facet module, are among those it reads.
384+
for (const f of ['sql-driver.ts', 'sql-driver-cross-field-comparison.ts', 'sql-driver-read-exit-fault.ts',
385+
'sql-driver-predicate-emitters.ts', 'sql-driver-top-level.ts', 'sql-driver-filter-helpers.ts']) {
386+
expect(found.files, `the scan lost ${f}`).toContain(f);
387+
}
379388
});
380389

381390
it('only three functions build the envelope WITHOUT the seam, none of them on the compile path', () => {

‎packages/drivers/driver-sql/src/sql-driver-filter-helpers.ts‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
* `temporalFilterColumnSql`, `isJsonColumn`, `jsonColumnFieldClass`,
1212
* `isNonTextColumn`, `applyTextOperatorOverNonTextColumn`,
1313
* `declaredValueShape`, `assertOperatorAppliesToColumn`, `applyFilters`,
14-
* `logWithheldFilterDiagnostic`, `withWithheldFilterLog`, `compileFilters`,
15-
* `applyContainsLike`, `declaredFieldsFor`, `applyFalseConstant` moved out of
16-
* `sql-driver.ts` whole by `scripts/codemod-split-sql-driver.mjs`.
14+
* `resolveWithheldFilterRefusal`, `logWithheldFilterDiagnostic`,
15+
* `withWithheldFilterLog`, `compileFilters`, `applyContainsLike`,
16+
* `declaredFieldsFor`, `applyFalseConstant` moved out of `sql-driver.ts` whole
17+
* by `scripts/codemod-split-sql-driver.mjs`.
1718
*
1819
* A MOVE, not a redesign. {@link FilterHelpersFacet} is a stateless facet of `SqlDriver`
1920
* (ruling 6624345766): each static method of it is the body of the `SqlDriver`
@@ -38,16 +39,18 @@
3839
* evaluation cycle. `index.ts` re-exports nothing from this module.
3940
*/
4041

42+
import { resolveFilterSubtreeProvenance } from '@objectstack/spec/data';
4143
import type { DriverOptions, ValueShapeFieldDef } from '@objectstack/spec/data';
4244
import { JSON_COLUMN_INCOMPATIBLE_OPERATORS, findMisplacedReadableIds, presentAsNumber, refuseReadableIdsOnce, temporalStorageForm } from '@objectstack/core';
4345
import type { JsonColumnFieldClass } from '@objectstack/core';
4446
import { StorageNameMapping } from '@objectstack/spec/system';
4547
import type { Knex } from 'knex';
4648
import {
47-
AUDIT_TIMESTAMP_COLUMNS, SQLITE_TIME_EXPR_REFS, WITHHELD_FILTER_LOGGED, assertCompilableComparand,
48-
assertDefinedComparands, canonicalTimeOfDay, canonicalUtcDatetime, emptyFieldConstraintError,
49-
filterArrayReachedDriverError, isEmptyFieldConstraint, jsonColumnOperatorError, mysqlDatetimeLiteral,
50-
normalizeSqliteDatetimeOutput, presentAuditTimestampOutput, refusalSubtree, withheldFilterDiagnosticOf,
49+
AUDIT_TIMESTAMP_COLUMNS, SQLITE_TIME_EXPR_REFS, WITHHELD_FILTER_AUTHOR_TEXT, WITHHELD_FILTER_LOGGED,
50+
WITHHELD_FILTER_SUBTREE, assertCompilableComparand, assertDefinedComparands, canonicalTimeOfDay,
51+
canonicalUtcDatetime, emptyFieldConstraintError, filterArrayReachedDriverError, isEmptyFieldConstraint,
52+
jsonColumnOperatorError, mysqlDatetimeLiteral, normalizeSqliteDatetimeOutput, presentAuditTimestampOutput,
53+
refusalSubtree, unsupportedFilterError, withheldFilterDiagnosticOf,
5154
} from './sql-driver-top-level.js';
5255
import type { ReadPresentationKind } from './sql-driver-top-level.js';
5356
import type { SqlDriver } from './sql-driver.js';
@@ -79,6 +82,7 @@ export interface FilterHelpersHost {
7982
readonly isSqlite: SqlDriver['isSqlite'];
8083
jsonColumnFieldClass: SqlDriver['jsonColumnFieldClass'];
8184
readonly jsonFields: SqlDriver['jsonFields'];
85+
logWithheldFilterDiagnostic: SqlDriver['logWithheldFilterDiagnostic'];
8286
readonly logger: SqlDriver['logger'];
8387
readonly managedObjectFields: SqlDriver['managedObjectFields'];
8488
readonly mediaFields: SqlDriver['mediaFields'];
@@ -430,6 +434,22 @@ export class FilterHelpersFacet {
430434
}
431435
}
432436

437+
/** The body of `SqlDriver#resolveWithheldFilterRefusal`; the method's docblock there is its contract. */
438+
static resolveWithheldFilterRefusal(this: Pick<FilterHelpersHost, 'logWithheldFilterDiagnostic'>, err: unknown, rootFilter: unknown): unknown {
439+
const diagnostic = withheldFilterDiagnosticOf(err);
440+
if (diagnostic === null) return err;
441+
const carrier = err as Record<symbol, unknown>;
442+
const subtree = carrier[WITHHELD_FILTER_SUBTREE];
443+
const provenance =
444+
subtree === undefined ? null : resolveFilterSubtreeProvenance(rootFilter, subtree);
445+
if (provenance === 'author') {
446+
const authorText = carrier[WITHHELD_FILTER_AUTHOR_TEXT];
447+
return unsupportedFilterError(typeof authorText === 'string' ? authorText : diagnostic);
448+
}
449+
this.logWithheldFilterDiagnostic(err);
450+
return err;
451+
}
452+
433453
/** The body of `SqlDriver#logWithheldFilterDiagnostic`; the method's docblock there is its contract. */
434454
static logWithheldFilterDiagnostic(this: Pick<FilterHelpersHost, 'logger'>, err: unknown): void {
435455
const diagnostic = withheldFilterDiagnosticOf(err);

0 commit comments

Comments
 (0)