Skip to content

refactor: remove the generator → legacy edge by relocating the Part 10 envelope into core - #596

Merged
awatson1978 merged 2 commits into
release/1.0-beta-corefrom
core/part10writer-legacy-edge
Oct 3, 2026
Merged

awatson1978 merged 2 commits into
release/1.0-beta-corefrom
core/part10writer-legacy-edge

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This PR removes the one declared temporary edge in the workspace graph: @dcmjs-org/generator → @dcmjs-org/legacy. #567 flagged it honestly when the generator package was born: Part10Writer is by design a thin layer over the canonical Part 10 encoder, and that encoder lived on the legacy surface type as DicomDict.write(). The removal plan written there — "the edge disappears when that serializer grows a home that is not the legacy surface type" — is what lands here: the envelope moves into core, and both legacy and the generator consume it.

Two commits:

  1. refactor(core): the relocation. The full envelope body of DicomDict.write() — 128-byte preamble + DICM, meta group written explicit little endian with the computed FileMetaInformationGroupLength, the deflate-on-write branch from feat: write the deflated transfer syntax #560 (raw-deflate per PS3.10 A.5, meta group never compressed), and the missing-TransferSyntaxUID default — moves verbatim into core/writeCore.js as writePart10({ meta, dict }, writeOptions), next to the writeDataSet/writeTagObject/getTagWriteValues primitives refactor: split the event-stream writer sinks into packages/generator #567 already relocated there. The only edits in the moved body are the mechanical renames (DicomMessage.write → writeDataSet, this.meta → meta); pako was already a core dependency, and padding/Big16 live below this in Tag.write/ValueRepresentation, which are core's. DicomDict.write() becomes a two-line delegating call — options, semantics, and even the in-place TransferSyntaxUID default on this.meta unchanged, with the write-deflate, lossless-read-write, and hardening-era suites as the behavior pins.

  2. refactor(generator): the edge removal. Part10Writer imports writePart10 from @dcmjs-org/core, @dcmjs-org/legacy leaves the package's dependencies (it was never in devDependencies), the lockfile drops the link, and the README's declared-edge paragraph now records when and how the edge closed.

The seam #567 said couldn't be a static import. That PR's footnote reported that SequenceOfItems.writeBytes still wrote its items through the late-bound DicomMessage slot, because a static ValueRepresentation → writeCore import recreates the Tag.js evaluation-order cycle (ValueRepresentation.setTagClass runs at Tag module evaluation). That made the first cut of the standalone test fail in a second, more interesting way: with legacy truly absent, writing any SQ threw DicomMessage.write undefined. The fix keeps the slot late-bound but flips who populates it: a new ValueRepresentation.setWriteDataSet slot, wired by writeCore.js at its own module evaluation (writeCore already imports ValueRepresentation, so no new edge and no cycle). It is behavior-identical — legacy's DicomMessage.write static delegates to the same writeDataSet — but it is populated whenever core loads, so the whole write path is legacy-free. This is the same seam #580 landed on the dicomdir staging branch; I kept the method body, call-site replacement, and comments textually identical to that PR so the two branches converge as cleanly as possible when they meet. DicomDict.setDicomMessageClass stays as a readerless compatibility slot (the wrapper index, legacy's DicomMessage module, and three root test files still call it — the same kept-for-API-compatibility pattern Tag.js already uses), but nothing reads it anymore.

Red-first, both reds observed. packages/generator/test/standalone.test.js (the pattern of the dicomdir wave's standalone test) imports only core + parser + generator by package name, arms a virtual jest.mock("@dcmjs-org/legacy") tripwire that throws if legacy ever loads, and runs Part10Writer end to end — events → bytes → fromPart10Stream readback — for plain ELE and for the DEFLATED transfer syntax, so the relocated deflate branch is proven legacy-free. Before the relocation the tripwire fired at Part10Writer.js:5 and killed the suite at module load; after the relocation but before the seam, the SQ write threw as above; now green.

Byte-exactness. test/core/writePart10.test.js byte-compares the delegating DicomDict.write() against direct writePart10 on the same input: the CT1_UNC explicit-little-endian fixture, the image_dfl deflated fixture, and the missing-TransferSyntaxUID defaulting path — Buffer.compare equal on all three. The full suite is 852 passed / 11 skipped / 863 (baseline 847/11/858 plus the five tests added here).

Follow-up (not in this PR): the dicomdir wave re-created a deflate-less version of this exact envelope inline in packages/dicomdir/src/dicomdir.js (~45 lines, verified byte-identical at the time). That package stages on a different branch, so it is untouched here — but once this lands there, the inline copy can be deleted in favor of writePart10.

The hand-written total is about 85 changed source lines (writeCore's inserted lines minus the ~46-line verbatim envelope body, the ValueRepresentation seam ~17, the DicomDict delegation and compat-slot comments ~14, the Part10Writer rewiring ~11, plus the README paragraph and two export lines), with the two new test files (101 + 92 lines) on top — under 300 hand-written in all, well inside the 500 budget; the envelope body is the declared verbatim move.

🤖 Generated with Claude Code

awatson1978 and others added 2 commits October 3, 2026 00:15
…Part10

The full envelope from legacy DicomDict.write() - 128-byte preamble +
DICM, meta group as explicit little endian with computed
FileMetaInformationGroupLength, the deflate-on-write branch for
1.2.840.10008.1.2.1.99, and the default-transfer-syntax fallback - moves
verbatim into core/writeCore.js as writePart10({ meta, dict }, options).
DicomDict.write() becomes a delegating call with unchanged options and
semantics (including the in-place TransferSyntaxUID default on meta).

SequenceOfItems.writeBytes used to write items through the late-bound
DicomMessage slot, which only legacy populates; it now goes through a new
setWriteDataSet slot that writeCore wires at its own module evaluation -
behavior-identical (the legacy static delegates to the same writeDataSet)
but populated whenever core loads, so the whole write path works with no
@dcmjs-org/legacy in the module graph. The slot stays late-bound per the
module-eval-cycle discipline around Tag.js, and its text matches PR #580
(the dicomdir wave landed the identical seam on its staging branch) so
the branches converge cleanly.

DicomDict keeps its setDicomMessageClass slot for API compatibility
(the wrapper index, legacy's DicomMessage module, and existing tests
still call it), but nothing reads it anymore - the same readerless-slot
pattern Tag.js already uses.

test/core/writePart10.test.js pins byte-exactness: for the same input,
the delegating DicomDict.write() and direct writePart10 produce
byte-identical output on an ELE fixture, a deflated fixture, and the
missing-TransferSyntaxUID defaulting path.

Co-Authored-By: Claude Fable 5 <[email protected]>
Part10Writer now serializes through core's writePart10 instead of
constructing a legacy DicomDict, and @dcmjs-org/legacy leaves the
package's dependencies (it was never in devDependencies). The README's
declared-edge paragraph is rewritten to record that the edge closed in
October 2026 with the envelope's relocation.

packages/generator/test/standalone.test.js is the regression: it imports
only core + parser + generator by package name, arms a virtual jest.mock
tripwire that throws if @dcmjs-org/legacy ever loads, and exercises
Part10Writer end to end (events -> bytes -> fromPart10Stream readback)
for both explicit little endian and the DEFLATED transfer syntax, so the
relocated deflate branch is proven legacy-free. Red-first: before the
relocation the tripwire fired at Part10Writer.js:5 and failed the whole
suite at module load.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit 92ac967 into release/1.0-beta-core Oct 3, 2026
10 checks passed
@awatson1978
awatson1978 deleted the core/part10writer-legacy-edge branch October 3, 2026 05:34
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant