Skip to content

refactor: split the event-stream reading side into packages/parser - #566

Merged
awatson1978 merged 4 commits into
release/1.0-beta-corefrom
split/parser-package
Oct 2, 2026
Merged

awatson1978 merged 4 commits into
release/1.0-beta-corefrom
split/parser-package

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This PR starts the @dcmjs/parser package — the reading half of the event-stream engine, following @dcmjs/core (#564) and @dcmjs/legacy (#565). The contract (EventStreamListener, the vocabulary, CONTRACT_VERSION, mergeFragmentsPerBotWindow), the collecting and naturalizing listeners, the four event generators (fromPart10, fromPart10Stream, fromDicomWebJson, fromDataSet), the shared emit helpers, the async-iterator adapter, and the element-decode core all move into packages/parser, depending on @dcmjs/core and pako — and NOT on @dcmjs/legacy. A second PR for packages/generator (the writer sinks) follows right behind it.

Same commit shape as the last two, with one extra commit up front:

  1. The first commit is the scaffold: packages/parser/package.json and a README (private, version 0.0.0 until the publish switch flips), plus the lockfile pickup.
  2. The second commit is the piece refactor: split the shared building blocks into packages/core #564 deliberately left behind: it breaks decodeCore's edge into the legacy reader before anything moves. Three small relocations plus a seam, all hand-written and suite-green on their own: singleVRs (the canonical element-shaping list, the one with LT) moves from DicomMessage to core's constants/dicom.js; DicomMessage.lookupTag's one-line body moves to DicomMetaDictionary.lookupTag (it only ever read DicomMetaDictionary.dictionary, which is core's); and ValueRepresentation gains getDicomMessageClass() — the read side of the late-binding slot it has carried all along for sequence reads. In each case the DicomMessage surface keeps its name as a re-export or delegating static, so nothing visible changes.
  3. The third commit is a pure git mv, zero edits — all ten files record as R100 renames into packages/parser/src/, relative structure preserved (eventStream/ siblings keep importing each other unchanged; decodeCore keeps its core/ spot).
  4. The fourth commit is the hand-written rewiring: the moved files' building-block imports come from @dcmjs/core by name, a two-line shim at each old path keeps every existing import in src/, test/, and the wrapper working unchanged, and packages/parser/src/index.js exports the package surface. One line was added to core's index for it: lookupPrivateTag, the single by-name function of the packed private dictionary (the data blobs around it stay module-path imports, per core's existing note).

How the legacy edge was actually broken. decodeCore didn't just use lookupTag/singleVRs — its narrow fallback decodeWithEagerReadTag runs DicomMessage._readTag over rare element shapes, and fromPart10Stream force-reads bare (meta-less, DIMSE-style) datasets through DicomMessage.readFile. Both delegations are deliberate (byte-parity with the eager reader is the point), so reimplementing them was off the table for a move PR, and moving _readTag/readFile into core would have planted the eager engine in the one package it must never touch. Instead both call sites resolve the eager reader at call time through core's existing late-binding slot (ValueRepresentation.getDicomMessageClass()), with a clear error when nothing wired it. Legacy's DicomMessage module now wires the slots itself at load (the wrapper index's identical calls stay and are idempotent), and the shims for fromPart10, fromPart10Stream, and decodeCore carry a one-line side-effect import of ../DicomMessage.js — so every existing entry point keeps exactly the reach the static import gave it. The only behavior that differs anywhere is @dcmjs/parser loaded truly standalone: the two fallbacks throw a descriptive "import @dcmjs/legacy first" error instead of being silently available, which is the deprecability rule working as intended.

What stays put, on purpose: src/eventStream/api.js and index.js (the DicomEventStream facade and the barrel) are wrapper-level glue spanning the reading and writing sides — they stay in root src/ for the wrapper package, importing through the shims with zero edits. The writer sinks (Part10Writer, StreamingPart10Writer, DicomWebJsonWriter) stay for the generator-package PR next.

The hand-written total is about 240 changed lines (scaffold 42, seam commit 51, rewiring ~145 across import blocks, the seam guard, the parser index, core's one-line export, and ten shims), well under the 500 budget; the pure moves are exempt and declared above. After the full commit group: the suite is 844 passed / 12 skipped / 856, pnpm run build produces the same bundle surface (UMD export names checked against the previous build), and lint and format pass over the existing packages/*/src globs.

🤖 Generated with Claude Code

awatson1978 and others added 4 commits October 1, 2026 23:59
Adds packages/parser/package.json and README.md, following the same
scaffold precedent as @dcmjs/core and @dcmjs/legacy (private, version
0.0.0 until the publish switch flips). The package depends on
@dcmjs/core via workspace:* plus pako (the streaming reader inflates
deflated transfer syntaxes); the lockfile picks up the new project.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ader seam

Preparation for moving the streaming reader into packages/parser, where
it must carry no static edge to @dcmjs/legacy:

- singleVRs (the canonical element-shaping list, the one with LT) moves
  from DicomMessage to core's constants/dicom.js; DicomMessage imports
  and re-exports it, so its historic surface is unchanged
- DicomMessage.lookupTag's body moves to DicomMetaDictionary.lookupTag
  (it was a one-line read of DicomMetaDictionary.dictionary, which is
  core's); the DicomMessage static delegates to it
- ValueRepresentation gains getDicomMessageClass(), the read side of
  the late-binding slot it already carries, so the streaming reader's
  narrow eager-delegation fallbacks can resolve the eager reader at
  call time instead of importing it
- legacy's DicomMessage module wires the ValueRepresentation / Tag /
  DicomDict seams at load, not only via the dcmjs wrapper index, so
  direct module consumers keep exactly the reach they had when the
  streaming modules imported DicomMessage statically (the wrapper's
  identical calls stay; the setters are idempotent)

Co-Authored-By: Claude Fable 5 <[email protected]>
…re git mv)

The contract (EventStreamListener, the vocabulary, CONTRACT_VERSION,
mergeFragmentsPerBotWindow), the collecting and naturalizing listeners,
the shared emit helpers, the async-iterator adapter, the four event
generators (fromPart10, fromPart10Stream, fromDicomWebJson,
fromDataSet), and the element-decode core move under
packages/parser/src/ with their relative structure preserved. Zero
edits; git records every file as an R100 rename. The wrapper-level glue
(src/eventStream/api.js and index.js) and the writers stay put for the
follow-up rewiring and generator-package commits.

Co-Authored-By: Claude Fable 5 <[email protected]>
Hand-written rewiring for the pure-move commit before it:

- the moved modules import their building blocks from @dcmjs/core by
  name instead of relative paths; sibling imports inside the package
  stay relative and needed no edits
- the two deliberate eager-reader delegations — decodeCore's
  decodeWithEagerReadTag (DicomMessage._readTag over rare element
  shapes) and fromPart10Stream's bare-dataset fallback
  (DicomMessage.readFile) — now resolve the eager reader at call time
  through core's late-binding slot (requireEagerReader over
  ValueRepresentation.getDicomMessageClass), with a clear error when
  no eager reader is loaded, so this package carries no static edge
  to @dcmjs/legacy
- a shim at each old path under src/ re-exports from the new
  packages/parser location; the fromPart10, fromPart10Stream, and
  decodeCore shims also side-effect import ../DicomMessage.js so
  direct consumers of the old paths keep exactly the reach the static
  import gave them
- packages/parser/src/index.js exports the package surface (the
  contract, the listeners, the sources, and the emit helpers); the
  eventStream barrel and the DicomEventStream facade stay in root src/
  as wrapper-level glue, unchanged
- core's index additionally exports lookupPrivateTag, the packed
  private dictionary's one by-name function, for the naturalized
  listener

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit ab76429 into release/1.0-beta-core Oct 2, 2026
10 checks passed
@awatson1978
awatson1978 deleted the split/parser-package branch October 2, 2026 14:23
@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