Skip to content

Commit c453e2f

Browse files
committed
refactor(metadata-protocol): keep the methods that read no class member in protocol.ts
A moved body that reads no member would never read its `host` parameter, which the package's noUnusedParameters refuses, so such a method now stays (stay rule no-host-read). Regenerated: 69/284 methods move; protocol.ts goes from 23135 to 13915 lines. Claude-Session: https://claude.ai/code/session_01WGufzgddMBbTQd9yVo4Yuz Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 018ddc7 commit c453e2f

3 files changed

Lines changed: 24 additions & 26 deletions

File tree

‎packages/metadata-protocol/src/protocol-discovery-and-bases.ts‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
/**
44
* [#29985 codemod] The "Discovery, types, diagnostics, packaged bases,
55
* credential carry-forward" section of `ObjectStackProtocolImplementation`: the
6-
* bodies of `getDiscovery`, `getMetaTypes`,
7-
* `rethrowUnlessMetadataStoreUnprovisioned`, `getPackagedObjectBase`,
6+
* bodies of `getDiscovery`, `getMetaTypes`, `getPackagedObjectBase`,
87
* `packagedArtifactBase`, `objectRegistrationRefusal`,
98
* `restoreTranslatedObjectEchoes`, `restoreInjectedColumnEchoes`,
109
* `registeredTranslationBundle`, `readCodeLayerForCarryForward` moved out of
@@ -35,7 +34,6 @@ import type { ApiRoutes, CapabilityDescriptor, ServiceInfo, WellKnownCapabilitie
3534
import { engineCanRollBack } from '@objectstack/core';
3635
import { resolveDiscoveryVersion } from './discovery-version.js';
3736
import type { SysMetadataRepository } from './sys-metadata-repository.js';
38-
import { isMissingTableError } from '@objectstack/metadata/errors';
3937
import { PLURAL_TO_SINGULAR, SINGULAR_TO_PLURAL, unrecognisedMetaTypeRefusal } from '@objectstack/spec/shared';
4038
import { CORE_SERVICE_PROVIDER, serviceUnavailableMessage } from '@objectstack/spec/system';
4139
import type { TranslationBundle } from '@objectstack/spec/system';
@@ -55,7 +53,6 @@ import {
5553
canonicalMetaType,
5654
toJsonSchemaSafe,
5755
} from './protocol-meta-type-schema.js';
58-
import { metadataReadFailureError } from './protocol-client-failures.js';
5956
import { SERVICE_CONFIG } from './protocol-discovery-services.js';
6057
import type { SaveMetaItemRequest } from './protocol-door-requests.js';
6158
import type { ProtocolHost } from './protocol-host.js';
@@ -684,23 +681,6 @@ export async function getMetaTypes(host: Pick<ProtocolHost, 'envWritableTypes' |
684681
return listing;
685682
}
686683

687-
/** The body of `ObjectStackProtocolImplementation#rethrowUnlessMetadataStoreUnprovisioned`; the method's docblock there is its contract. */
688-
export function rethrowUnlessMetadataStoreUnprovisioned(host: ProtocolHost, error: unknown, readObject: string): void {
689-
// [commit 4cda78c9b] `readObject` is REQUIRED, deliberately. This helper serves
690-
// callers that read four different tables (`sys_metadata`,
691-
// `sys_metadata_audit`, `sys_metadata_commit`, `sys_metadata_history`),
692-
// so a default would silently answer about the wrong one for three of
693-
// them — measured, not hypothetical: the first draft of this repair
694-
// hardcoded `sys_metadata` and turned `diffMetaItem`'s genuinely
695-
// unprovisioned `sys_metadata_history` into a loud failure. A required
696-
// parameter makes the compiler ask the question at every new call site.
697-
if (isMissingTableError(error, readObject)) return;
698-
// [#12536] CLASSIFY, do not assume. A read can fail because the store
699-
// is unreachable OR because a metadata app's hook refused it in its
700-
// own words — see {@link metadataReadFailureError}.
701-
throw metadataReadFailureError(error);
702-
}
703-
704684
/** The body of `ObjectStackProtocolImplementation#getPackagedObjectBase`; the method's docblock there is its contract. */
705685
export function getPackagedObjectBase(host: Pick<ProtocolHost, 'engine'>, name: string): unknown {
706686
if (typeof name !== 'string' || name === '') return undefined;

‎packages/metadata-protocol/src/protocol.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ import {
638638
registeredTranslationBundle,
639639
restoreInjectedColumnEchoes,
640640
restoreTranslatedObjectEchoes,
641-
rethrowUnlessMetadataStoreUnprovisioned,
642641
} from './protocol-discovery-and-bases.js';
643642
// [#29985 codemod] Data CRUD: the methods of the same names below hand the bodies the host (`protocol-host.ts`).
644643
import { cloneData, findData, getData } from './protocol-data-crud.js';
@@ -2829,8 +2828,19 @@ export class ObjectStackProtocolImplementation implements
28292828
* the overlay as absent.
28302829
*/
28312830
private rethrowUnlessMetadataStoreUnprovisioned(error: unknown, readObject: string): void {
2832-
// [#29985 codemod] The body moved to `protocol-discovery-and-bases.ts`; it reaches this class through `protocol-host.ts`.
2833-
return rethrowUnlessMetadataStoreUnprovisioned(protocolHost(this), error, readObject);
2831+
// [commit 4cda78c9b] `readObject` is REQUIRED, deliberately. This helper serves
2832+
// callers that read four different tables (`sys_metadata`,
2833+
// `sys_metadata_audit`, `sys_metadata_commit`, `sys_metadata_history`),
2834+
// so a default would silently answer about the wrong one for three of
2835+
// them — measured, not hypothetical: the first draft of this repair
2836+
// hardcoded `sys_metadata` and turned `diffMetaItem`'s genuinely
2837+
// unprovisioned `sys_metadata_history` into a loud failure. A required
2838+
// parameter makes the compiler ask the question at every new call site.
2839+
if (isMissingTableError(error, readObject)) return;
2840+
// [#12536] CLASSIFY, do not assume. A read can fail because the store
2841+
// is unreachable OR because a metadata app's hook refused it in its
2842+
// own words — see {@link metadataReadFailureError}.
2843+
throw metadataReadFailureError(error);
28342844
}
28352845

28362846
/**

‎scripts/codemod-split-protocol.mjs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ const STAY_REASONS = Object.freeze({
194194
'host-entry-conflict': 'it needs a host entry that differs from the one protocol-host.ts already carries for that member',
195195
'host-entry-predicate': 'it reaches a type-predicate method through a host entry not yet written (the forwarding closure would drop the predicate)',
196196
'indent-irreversible': 'its body\'s re-indentation cannot be undone byte for byte (a whitespace-only or under-indented line)',
197+
'no-host-read': 'its body reads no member of the class, so the moved function would never read its `host` parameter (`noUnusedParameters`)',
197198
'no-yield': 'its stub would be no shorter than its body (moving it would grow protocol.ts)',
198199
});
199200

@@ -621,6 +622,7 @@ function plan(T, text, hostText, { anchors = SECTION_ANCHORS, pins = PATH_READER
621622
if (have !== undefined && have !== entry.iface) add(`host-entry-conflict: ${member}`);
622623
if (have === undefined && predicateMembers.has(member)) add(`host-entry-predicate: ${member}`);
623624
}
625+
if (moved.sites.length === 0) add('no-host-read');
624626
const movedBody = functionBodyOf(ts, moved.fnText);
625627
const baseBody = text.slice(m.body.getStart(sf), m.body.getEnd());
626628
if (movedBody === null || undoBody(ts, movedBody, privateStatics) !== baseBody) add('indent-irreversible');
@@ -1261,7 +1263,7 @@ async function main(argv) {
12611263
let selfTestReachedVerdict = false;
12621264

12631265
const SELF_TEST_BATTERIES = Object.freeze({
1264-
'stay rules': 14,
1266+
'stay rules': 15,
12651267
'host entries': 4,
12661268
'byte-identity proof': 9,
12671269
'determinism': 2,
@@ -1341,7 +1343,12 @@ ${pad}
13411343
13421344
public inferred() {
13431345
${pad}
1344-
return 1;
1346+
return this.count;
1347+
}
1348+
1349+
private readsNoMember(n: number): number {
1350+
${pad}
1351+
return n;
13451352
}
13461353
13471354
private destructured({ a }: { a: number }): number {
@@ -1443,6 +1450,7 @@ async function selfTest() {
14431450
stays('bareThis', 'closed-set');
14441451
stays('viaConstructor', 'constructor-rewrite');
14451452
moves('inferred', 'an inferred return type moves, as the hand series moved getMetaItems and validateData');
1453+
stays('readsNoMember', 'no-host-read');
14461454
stays('destructured', 'parameter-shape');
14471455
stays('shadows', 'parameter-shadows');
14481456
stays('alreadyMoved', 'already-moved');

0 commit comments

Comments
 (0)