fix: prevent double .where() from overwriting scope predicate#21
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.
Problem
Drizzle's
where()overwritesconfig.whererather than ANDing. The scopedwhere()returned the raw Drizzle builder, so a second.where()call replaced the injected scope predicate entirely (Issue #19).The
ScopedWhereBuildertype hid.where()from TS users, but at runtime the raw builder exposed it — reachable by JS users,as anycasters, orany-typed variables.Fix
Three changes, all returning facades instead of raw builders:
Select:
where()now returns aScopedWhereBuilderfacade (built from a Promise +limit/offset/orderBymethods) that does NOT expose.where()at runtime.limit/offset/orderBydelegate to the raw builder and return the same facade.Update:
set().where()returns a thenable facade that hides.where()and other scope-unsafe builder methods.Delete:
where()returns the same thenable facade.The facades are proper Promises (via
Object.assign(promise, methods)), soawaitand.then()work normally. The scope predicate cannot be overwritten because.where()simply doesn't exist on the returned objects.Tests
Added 5 regression tests:
.where()on select is prevented (facade has no.where).limit()/.offset()/.orderBy()chaining.where()on update is prevented.where()on delete is preventedAlso updated the fake DB's
where()to simulate Drizzle's overwrite behavior (returns an object with.where()that overwrites, not ANDs).Validation
Closes #19