Repository navigation
feat: add the event-stream contract and its reference collector - #530
Merged
Merged
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]>
awatson1978
marked this pull request as ready for review
September 29, 2026 04:47
This was referenced Sep 29, 2026
|
🎉 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 is the first engine slice from RELEASE_PLAN.md (section 6, step 5). It defines the event-stream contract — the shared vocabulary every reader, writer, filter, and anonymizer in the rewrite will speak — plus a reference consumer to validate future generators against.
I opened it as a draft on purpose. Section 5 of the plan says new engine code needs a second set of eyes, so nothing here self-merges.
First, the idea, since this PR is where it starts. An "event stream" means a parser doesn't build one big tree and hand it back at the end. Instead, it calls a listener once per thing it encounters:
startElement,value,endElement,startSequence, and so on. That callback vocabulary is the contract. Everything later in the refactor — byte readers, DICOMweb JSON sources, writers, anonymizers — produces or consumes these same calls.Three files land in
src/eventStream/:EventStreamListener.jsdefines the vocabulary itself (EVENT_STREAM_VOCABULARY, fifteen callbacks covering dataset lifecycle, structure, values, and binary data) and the listener base class. Delivery is push: producers call the listener's methods synchronously, which keeps the hot path free of per-event allocations. Backpressure — letting a slow consumer pause a fast producer — happens out of band instead: producersawait listener.awaitDrain()only at defined checkpoints (top-level element boundaries and binary fragments). Filters are first class; each one can wrap any vocabulary method in anext-style chain.mergeFragmentsPerBotWindow, the fragment-windowing helper. It merges encapsulated pixel-data fragments into one buffer per Basic Offset Table window, so listeners that rebuild a dataset can match the eager reader's one-entry-per-frame shape.CollectorListener.jsis the reference consumer. It rebuilds a tag-keyed{ meta, dict }tree from the events — deliberately the same raw{ vr, Value }shape thatDicomMessage.readFileproduces, so later generators can be validated by deep-comparing their collected output against the existing parse.Here's the contract in motion, condensed from the tests — events in, tree out:
The tests (
test/eventStream/EventStreamListener.test.jsandCollectorListener.test.js) drive listeners through hand-written event sequences like that one and assert the rebuilt tree, filter chaining, drain behavior, and fragment handling.Two things are deliberately not here. The
index.jsbarrel re-exports only what has landed. And the async pull adapter is excluded until review finding 13 is fixed in its own PR — the finding is that breaking out of the iterable leaks the producer.fromDataSet, the first real generator, follows as the next slice with its tests.One more note: I triaged the routing of all 33 review findings against the rewrite branch tonight; it's drafted in FINDINGS-CHECKLIST.md in the workspace, ready for the tracking issue.
🤖 Generated with Claude Code