fix(infra): do not re-encode store defaultValues in query builders - #899
Merged
Merged
Conversation
Stores already JSON-lower defaultValues at construction. Re-encoding an
ISO Date string through the Date codec throws "Expected a valid Date",
which failed filter({ select: [id] }) even when the select path never
decoded a document.
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.
Why
validateSample/store.filter({ select: [id] })was failing insideRepository.filteras anEncodingissue on aDate— even though the select branch never decodes a document. The store already JSON-lowersdefaultValuesat construction (json.toJson(config?.defaultValues ?? {})). Cosmos and SQL query builders then lowered them again (defaultValues = toJson(defaultValues)). Encoding an already-ISO string through aDatecodec throwsExpected a valid Date.Empirical proof:
makeJsonLower({ schema: Item }).toJson({ at: new Date(...) })yields{ at: "2024-06-01T00:00:00.000Z" }; feeding that object back through the same encoder throwsExpected a valid Date.What
Stop re-encoding
defaultValuesinbuildWhereCosmosQuery3andbuildWhereSQLQuery. Filter values still go throughjsonifyFilterbecause they arrive as native Encoded. Memory already encodes once at construction and never again — this matches that peer.How
toJson(defaultValues)in Cosmos and SQL query builders.Design angles: assumed goal is that store-lowered Date defaults must survive
filter(including select-only / validateSample) — peers Memory (encode once at construction) vs Cosmos/SQL query builders (re-encode); follow Memory, migrate Cosmos+SQL query builders in this PR.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.