Skip to content

refactor: split the event-stream writer sinks into packages/generator - #567

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

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

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This PR starts the @dcmjs/generator package — the writing half of the event-stream engine, closing the four-package split that #564 (@dcmjs/core), #565 (@dcmjs/legacy), and #566 (@dcmjs/parser) built up to. The three writer sinks — Part10Writer, StreamingPart10Writer, DicomWebJsonWriter — move into packages/generator.

Same commit shape as #566:

  1. The first commit is the scaffold: packages/generator/package.json and a README (private, version 0.0.0), plus the lockfile pickup. Its dependencies are the honest news and the README spells them out: @dcmjs/parser for the contract and the collector, @dcmjs/core for the write primitives, and — temporarily — @dcmjs/legacy, about which more below.
  2. The second commit relocates the write primitives to core, so the streaming writer needs no legacy edge at all: DicomMessage.write, writeTagObject, and _getTagWriteValues move verbatim into core's core/writeCore.js (as writeDataSet / writeTagObject / getTagWriteValues — everything they touch was already core's: Tag.write, ValueRepresentation, deepEqual), isEncapsulated's one-liner moves to isEncapsulatedSyntax next to the syntax table it reads, and _normalizeSyntax now delegates to core's existing normalizeSyntax instead of duplicating it. Every DicomMessage static stays as a delegating surface, so DicomDict, the tests, and external callers are untouched. Tag.write also stops reaching those two helpers through its late-binding DicomMessage slot and imports them directly — the slot and its setter stay for API compatibility, now readerless inside Tag.
  3. The third commit is a pure git mv, zero edits — all three writers record as R100 renames into packages/generator/src/eventStream/.
  4. The fourth commit is the hand-written rewiring: the writers import the contract from @dcmjs/parser and the primitives from @dcmjs/core, a two-line shim at each old path keeps every existing import working unchanged, and packages/generator/src/index.js exports the three sinks. The eventStream barrel and the DicomEventStream facade stay in root src/ as wrapper-level glue, zero edits — with this PR, every module they re-export now lives in a package.

The declared temporary edge: @dcmjs/generator → @dcmjs/legacy, for Part10Writer only. That writer is by design a thin layer over the canonical encoder — it collects events into a { meta, dict } tree and delegates serialization to DicomDict.write(), which owns deflate, padding, Big16, and the group-length recomputation. Cutting that edge today would mean either moving DicomDict (the legacy surface type) into core or growing a second meta-group serializer — a real redesign, not a move. So the edge stays, confined to one import in one module and flagged in the package README. The one-line removal plan: when the collect-then-serialize path is reimplemented over StreamingPart10Writer (or the canonical encoder moves out of the legacy surface type), the DicomDict delegation and the workspace dependency go with it.

StreamingPart10Writer comes out legacy-free as promised: after commit 2 its only imports are the parser contract and core (WriteBufferStream, the syntax constants, writeDataSet, writeTagObject); it self-builds every sequence/item/fragment header. One honest footnote: an element whose value is a sequence written through writeTagObject still routes through ValueRepresentation's late-bound DicomMessage.write slot — I tried pointing that slot's one write call at writeCore directly, and it recreates exactly the evaluation-order cycle the slots exist to avoid (Tag.js calls ValueRepresentation.setTagClass at module-evaluation time, and a static ValueRepresentation → writeCore → Tag edge turns that into a crash). Event sources emit sequences structurally, so that path is not reachable from the contract; it matters only to direct writeTagObject callers, who have legacy loaded today anyway.

The hand-written total is about 185 changed lines (scaffold 53, the writeCore relocation commit 119 gross — of which ~77 are the verbatim relocated bodies — and rewiring ~35 across the three import blocks, three shims, and the package index), 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, eventStream keys identical), and lint and format pass over the existing packages/*/src globs.

🤖 Generated with Claude Code

awatson1978 and others added 4 commits October 2, 2026 09:24
Adds packages/generator/package.json and README.md, following the same
scaffold precedent as the core, legacy, and parser packages (private,
version 0.0.0 until the publish switch flips). The package depends on
@dcmjs/parser (the contract and the collector), @dcmjs/core (the write
primitives), and — temporarily, for Part10Writer's delegation to the
canonical DicomDict.write encoder only — @dcmjs/legacy; the README
spells that edge out. The lockfile picks up the new project and links.

Co-Authored-By: Claude Fable 5 <[email protected]>
Preparation for moving the writer sinks into packages/generator, so the
streaming writer needs no edge to @dcmjs/legacy:

- DicomMessage.write, writeTagObject, and _getTagWriteValues move
  verbatim into core's core/writeCore.js (as writeDataSet,
  writeTagObject, getTagWriteValues) — everything they touch is
  core's: Tag.write drives the element encoding through
  ValueRepresentation, deepEqual backs the _rawValue fidelity check.
  The DicomMessage statics delegate, so every existing caller
  (DicomDict, the tests, external users) is unaffected
- DicomMessage.isEncapsulated's body moves to isEncapsulatedSyntax in
  core's constants/dicom.js, next to the syntax table it reads, and
  DicomMessage._normalizeSyntax now delegates to core's existing
  normalizeSyntax instead of duplicating it; both statics remain as
  delegating surfaces
- Tag.write resolves those two helpers directly instead of through its
  late-binding DicomMessage slot, which now has no readers inside Tag
  (the setter stays for API compatibility)
- ValueRepresentation's sequence-item writer keeps calling the
  late-bound DicomMessage.write slot rather than importing writeCore:
  Tag.js wires ValueRepresentation.setTagClass at module-evaluation
  time, so a static ValueRepresentation -> writeCore -> Tag edge would
  recreate exactly the cycle the slots exist to avoid

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

Pure file moves, zero edits: Part10Writer, StreamingPart10Writer, and
DicomWebJsonWriter record as R100 renames into
packages/generator/src/eventStream/. The rewiring commit in this PR
repoints their imports at @dcmjs/parser, @dcmjs/core, and (for
Part10Writer's DicomDict delegation only) @dcmjs/legacy, and adds shims
at the old paths.

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

- the writers import the contract from @dcmjs/parser
  (EventStreamListener, CollectorListener) and the write machinery
  from @dcmjs/core (WriteBufferStream, the syntax constants,
  writeDataSet, writeTagObject); StreamingPart10Writer and
  DicomWebJsonWriter carry no other edges
- Part10Writer keeps its by-design delegation to the canonical
  DicomDict.write encoder, now as an explicit — and TEMPORARY —
  @dcmjs/legacy import, flagged in the package README and the PR
- a shim at each old path under src/eventStream/ re-exports from the
  new packages/generator location, so every existing import in src/,
  test/, and the barrel keeps working unchanged
- packages/generator/src/index.js exports the three sinks; the
  eventStream barrel and the DicomEventStream facade stay in root
  src/ as wrapper-level glue, unchanged

Co-Authored-By: Claude Fable 5 <[email protected]>
@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