Sachin/adding draft mode - #1
Merged
Merged
Conversation
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.
Split merging from validation and add draft mode
Problem
assembleWith did two things at once. it merged baseline → existing → observed → derived into one document, and then it validated that document and threw CodeJSONValidationError if anything was missing. Merging was welded to enforcing, so the only way to get a merged result was to have a complete, schema-valid one.
That doesn't fit every caller. A generator that scrapes a repository can only observe some fields so the rest come back at their baseline values for someone to fill in later. Producing a partial code.json for someone to finish is a valid outcome, not a failure, but the library had no way to express it so callers either got a valid file or an exception.
Solution
Split assemble.ts into two layers. mergeWith does steps 1 to 3. assembleWith is now mergeWith plus validation.
Result
Callers pick their contract.
assemblestill means "give me a finished file or throw" whiledraftmeans "give me whatever the merge produced". Callers that want both can draft and then run validate on the result to report what's missing without throwing. Drafts written to disk now keep every baseline key, including the blank enums, so the fields a human has to fill in are visible in the file.Test Plan
bun test