Repository navigation
refactor: remove the generator → legacy edge by relocating the Part 10 envelope into core - #596
Merged
Conversation
…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]>
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Part10Writeris by design a thin layer over the canonical Part 10 encoder, and that encoder lived on the legacy surface type asDicomDict.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:
refactor(core): the relocation. The full envelope body ofDicomDict.write()— 128-byte preamble +DICM, meta group written explicit little endian with the computedFileMetaInformationGroupLength, 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 intocore/writeCore.jsaswritePart10({ meta, dict }, writeOptions), next to thewriteDataSet/writeTagObject/getTagWriteValuesprimitives 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 inTag.write/ValueRepresentation, which are core's.DicomDict.write()becomes a two-line delegating call — options, semantics, and even the in-place TransferSyntaxUID default onthis.metaunchanged, with the write-deflate, lossless-read-write, and hardening-era suites as the behavior pins.refactor(generator): the edge removal.Part10WriterimportswritePart10from@dcmjs-org/core,@dcmjs-org/legacyleaves 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.writeBytesstill wrote its items through the late-boundDicomMessageslot, because a staticValueRepresentation → writeCoreimport recreates theTag.jsevaluation-order cycle (ValueRepresentation.setTagClassruns 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 threwDicomMessage.writeundefined. The fix keeps the slot late-bound but flips who populates it: a newValueRepresentation.setWriteDataSetslot, wired bywriteCore.jsat its own module evaluation (writeCore already imports ValueRepresentation, so no new edge and no cycle). It is behavior-identical — legacy'sDicomMessage.writestatic delegates to the samewriteDataSet— 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.setDicomMessageClassstays as a readerless compatibility slot (the wrapper index, legacy'sDicomMessagemodule, and three root test files still call it — the same kept-for-API-compatibility patternTag.jsalready 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 virtualjest.mock("@dcmjs-org/legacy")tripwire that throws if legacy ever loads, and runs Part10Writer end to end — events → bytes →fromPart10Streamreadback — for plain ELE and for the DEFLATED transfer syntax, so the relocated deflate branch is proven legacy-free. Before the relocation the tripwire fired atPart10Writer.js:5and 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.jsbyte-compares the delegatingDicomDict.write()against directwritePart10on the same input: the CT1_UNC explicit-little-endian fixture, theimage_dfldeflated fixture, and the missing-TransferSyntaxUID defaulting path —Buffer.compareequal 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 ofwritePart10.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