Skip to content

Extract rest-server.ts's error/fault-classification prologue — it is ADR-0112's concern, not the REST server's #8850

Description

@qq9340100

Filed by the domain:cli seat on the 2026-08-15 maintainer ruling on #5949 (「接受你的建议」, recorded at #5949 comment 5301726968). Card 1 of the two extractions that ruling authorised.

⚠️This is NOT the ADR-0076 D11 decomposition. That programme was ruled closed (option B — the second half is delineated, not split). This card stands on a different justification and would be worth doing even if the routes never move.

The justification — prism ① (coherence), not ③

packages/rest/src/rest-server.ts opens with ~1,980 lines before its first class declaration. That prologue (~732 code lines) is error and fault classification plus response shaping:

mapDataError · resolveErrorResponse · DATA_STORE_FAULT · UNCLASSIFIED_FAULT · isScriptFaultMessage · declaredHttpStatus · truncateClientMessage · sendError · sendFieldVisibilityFault · logWithheldServerFault · isExpectedDataStatus · isExpectedQueryRejection · isExpectedRouteError · logUnexpectedRouteError · handleRouteError · droppedFieldsHeaderValue · applyDroppedFieldsHeader · missingRelationIsObject

This is ADR-0112's domain — how a thrown thing becomes an HTTP answer — and it has zero coupling to the RestServer class: every one of these is a module-level function, declared before the class exists. It lives here for historical reasons, not structural ones.

Extracting it is a move, not a redesign.

Scope

  • Move the prologue to its own module in packages/rest/src/, re-exporting whatever rest-server.ts and any external consumer already import.
  • No behaviour change. This is a file move plus imports. Any change to what a caller receives is out of scope and a stop-and-report.
  • Do not touch the RestServer class body, and ⛔ do not extract any registerXxxEndpoints method — that is the programme option B closed.
  • export { zodIssuesToFields } at line ~188 is re-exported from here today; preserve the public surface exactly.

Premise to verify before moving

Measured on origin/main @ 04d03c3a0: first class declaration at line 1981, prologue is module-level functions only. Re-verify by symbol — this file has taken merges since, and this lane has been burned three times by trusting a stated line number.

⚠️ Also verify the zero-coupling claim rather than inheriting it: confirm no prologue function closes over class state or is referenced before its definition in a way that a module split would break. My reading was structural (declaration order), not a dependency trace.

Not claimed

Refs: #5949 (the ruling and the four-prism analysis), ADR-0112, ADR-0076 D11.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions