Skip to content

feat(eventStream): the DicomEventStream facade and namespace wiring - #557

Merged
awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/eventstream-facade
Sep 30, 2026
Merged

awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/eventstream-facade

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This is the last slice of the writers wave: the DicomEventStream facade from the v2 rewrite, plus the namespace wiring that finally puts dcmjs.eventStream on the public default export. With the sources, listeners, and writer sinks all landed (#521–#556), the ergonomic wrapper over them is the only piece that was missing:

import { DicomEventStream, Naturalized, DicomWebJson } from "dcmjs/src/eventStream/api";

// one source, many sinks — the stream wraps a re-runnable run(listener) thunk
const events = DicomEventStream.fromPart10Stream(bytes);
const metadata = await events.toNaturalized();      // or Naturalized.from(events)
const json = await events.toDicomWebJson();         // or DicomWebJson.from(events)
const part10 = await events.toPart10();             // Part10Writer under the hood

// auto-detection, explicit listeners, and async iteration too
const meta2 = await DicomEventStream.from({ meta, dict }).toNaturalized();
for await (const ev of DicomEventStream.fromDicomWebJson(json).asyncIterable()) { ... }

What's verbatim, what's trimmed, what's hand-written:

  • src/eventStream/api.js is the v2 file (316 lines) trimmed to core scope (178 lines). The kept surface is verbatim from v2: fromPart10, fromPart10Stream (with its buffer-re-runnable / iterator-single-use split), fromDicomWebJson, fromDataSet, from, process, toNaturalized, toDicomWebJson, toPart10, toDataSet, asyncIterable, and the Naturalized / DicomWebJson sink helpers. Dropped: fromImage, fromPdf, fromVideo, fromVideoStream, fromFhir, toPdf, toVideo, toFhir and their imports — those belong to the media and FHIR waves.
  • src/eventStream/index.js additions and the src/index.js namespace wiring are hand-written — core's root index had no eventStream namespace, and v2's version drags in image/encapsulated/validation modules core doesn't have. eventStream slots into both the default export and the named exports.
  • Finding 14 by omission. The review flagged that fromVideo/fromVideoStream call createVideoEventSource eagerly at factory time, so a bad MP4 rejects with no handler attached until the caller drives the stream — an unhandled rejection under Node's defaults. Those factories are exactly the ones trimmed out here, so the finding doesn't apply to this branch. When the media wave ports them, the fix shape is to create the source promise lazily inside _run (or attach a no-op .catch() at factory time) so the rejection always surfaces to the caller's await.

Tests travel with the code:

  • test/eventStream/api.test.js and test/eventStream/crossSource.test.js are the v2 suites with fixture roots reworked to packages/fixtures/testImages + packages/fixtures/dicom. Nothing needed trimming — neither suite touches a dropped facade method (the media/FHIR source tests live in separate v2 files that travel with their waves).
  • test/eventStream/export.test.js asserts the namespace shape on dcmjs.eventStream, including CONTRACT_VERSION === "1.0.0-A" — core's constant matches v2's, so the assertion is unchanged (I added one line asserting DicomEventStream is exposed).
  • The describe.skip re-runnability block that has been waiting in test/eventStream/fromPart10Stream.test.js since the streaming reader landed is now live — it imports api.js, which didn't exist until this PR, and both tests (buffer inputs re-run cleanly; iterator inputs reject with the "already been consumed" error on a second .process()) pass.

Full suite: 832 passed / 14 skipped across 68 suites (was 791 / 16 — the two un-skipped re-runnability tests plus the three new suites). 431 insertions, no waiver needed.

🤖 Generated with Claude Code

The final slice of the writers wave: the recommended public source/sink
API (spec section 32). DicomEventStream wraps a re-runnable run(listener)
thunk so one source can drive multiple sinks; Naturalized.from() and
DicomWebJson.from() are the section-32 sink helpers.

Ported from the v2 rewrite trimmed to core scope: fromPart10,
fromPart10Stream, fromDicomWebJson, fromDataSet, from, process,
toNaturalized, toDicomWebJson, toPart10, toDataSet, asyncIterable. The
media factories (fromImage, fromPdf, fromVideo, fromVideoStream, toPdf,
toVideo) and the FHIR pair (fromFhir, toFhir) stay behind for the media
and FHIR waves -- which resolves review finding 14 (the video factory's
unhandled rejection) by omission for this branch; the media-wave port
should create the video source promise lazily inside _run (or attach a
no-op catch) when those factories land.

The eventStream namespace is wired into src/index.js by hand (core had
none), the facade exports join src/eventStream/index.js, and the
re-runnability suite that was waiting behind describe.skip in
fromPart10Stream.test.js is now live. Tests ported with fixture roots
reworked to the packages/fixtures layout.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit 0bdf57c into release/1.0-beta-core Sep 30, 2026
8 checks passed
@awatson1978
awatson1978 deleted the core/eventstream-facade branch September 30, 2026 14:46
awatson1978 added a commit that referenced this pull request Sep 30, 2026
…ne and event-stream findings

Engine findings 1/3/4/24/25/27/28/32 landed as PRs #544-#551; the
writers wave (#552-#557) fixed 5/6/7/11/22/23 in the ports and retired
14 by trimming the video factories from the core facade. Master
verdicts are now verified against origin/master, not just triaged.

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