Repository navigation
feat(media): the DicomEventStream media factories (review finding 14) - #587
Merged
Merged
Conversation
Port fromImage, fromPdf, fromVideo, fromVideoStream, toPdf, and toVideo from v2's src/eventStream/api.js, importing from @dcmjs-org/pdfs and @dcmjs-org/video. The video factories create their event source lazily on first consumption (cached across re-runs) instead of eagerly at factory time, so a bad input can no longer raise an unhandled promise rejection before anyone calls .process() — review finding 14. Co-Authored-By: Claude Fable 5 <[email protected]>
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 gives the
DicomEventStreamfacade its media factories:fromImage,fromPdf,fromVideo,fromVideoStream,toPdf, andtoVideo. With these merged, the facade speaks every bulk-data dialect on this staging branch in both directions — decoded pixels, a PDF, or an MP4 go in and Part 10 bytes come out; a parsed instance goes in and the embedded PDF or the verbatim video stream comes back out. The factory bodies are ports from v2'ssrc/eventStream/api.js, but the imports now come from the workspace packages (encapsulatePdf/extractEncapsulatedPdffrom@dcmjs-org/pdfs;buildImageDataset/createVideoEventSource/extractEncapsulatedVideofrom@dcmjs-org/video), so the root facade composes the packages rather than duplicating them.fromFhir/toFhirare deliberately absent — they belong to the FHIR wave.One fix rides in the port: review finding 14. v2's video factories called
createVideoEventSource(...)eagerly at factory time, and the onlyawaiton that promise sat inside the run thunk. SoDicomEventStream.fromVideo(bytesThatAreNotAnMp4)followed by any unrelatedawaitproduced an unhandled promise rejection — under Node's default--unhandled-rejections=throwthat terminates the process before the caller ever gets a chance to catch anything. The ported code creates the source promise lazily inside the run thunk instead, cached after the first consumption so minted UIDs stay stable across re-runs of the same stream, exactly as before. The error now surfaces from.process()(or whichever sink runs first), which is the documented contract. Same fix infromVideoStream.I did this red-green: the regression test went in first, against the verbatim eager port. It registers a
process.on("unhandledRejection")listener, callsfromVideo(garbage), performs an unrelatedawait, and asserts the captured-rejections array is empty and that the error instead rejects the sink call. Against the eager port both finding-14 tests failed with the leakedparseMp4Info: input is not an MP4 file (missing ftyp box)rejection:After the lazy fix, all six pass and the full suite stays green.
To be plain about provenance: the six factory bodies and their doc comments are verbatim v2 except for the two lazy video thunks (the fix) and the import block, and
test/eventStream/fromImage.test.jsis the v2 file ported unchanged — it synthesizes its pixels in code, so no fixture-path rework turned out to be needed. Hand-written: the lazy thunks, the rootpackage.jsonworkspace deps (@dcmjs-org/pdfs,@dcmjs-org/video), andtest/eventStream/mediaFactories.test.js— the finding-14 regression pair plus facade round trips in both directions for PDF (byte-identical through the writer's odd-length OB pad and back) and video (the syntheticmakeTinyMp4recovered byte-identically viatoVideo), and the correctivetoPdf-on-a-non-PDF error.10 new tests (6 + 4 ported). Full suite on this branch: 945 passing (957 total, 12 skipped), build green.
🤖 Generated with Claude Code