Skip to content

feat(firestore): Defer pipeline user data validation to execute()#7816

Merged
dlarocque merged 11 commits intomainfrom
dl/defer-validation
Mar 24, 2026
Merged

feat(firestore): Defer pipeline user data validation to execute()#7816
dlarocque merged 11 commits intomainfrom
dl/defer-validation

Conversation

@dlarocque
Copy link
Copy Markdown
Contributor

@dlarocque dlarocque commented Mar 18, 2026

To support standalone stage initializers (such as subcollection()), that can be constructed without an existing pipeline, we need to decouple stage initialization and user data validation. Standalone functions do not have access to Firestore or databaseId context when called, so validation must be deferred until the pipeline is executed with execute(pipeline).

Implementation Details:

  1. Removed user data parsing in stage methods (select, where, addFields, ...).
  2. Added a _validateUserData() traversal to Pipeline class and all stages.
  3. Modified execute() to trigger pipeline._validateUserData() before executing the pipeline.

Breaking Change:
Errors regarding invalid user data in stages will now be thrown when execute(pipeline) is called, rather than during the initialization of the stage (pipeline.collection().addFields(/* invalid data */)).
This aligns with the behaviour on both iOS, Android, and Java SDKs.

// Previously: error threw here
const ppl = firestore.pipeline().collection('books').select(field, undefined); // undefined is an unsupported field value

// Now: error throws here
await execute(ppl);

Ported from: firebase/firebase-js-sdk#9715

I also updated the ESLint config rules to allow args to be unused if their identifier starts with an underscore (_name). Previously the rule was that they can only be underscores (_), which causes issues if there's more than one unused argument. I ran into this issue when implementing the _validateUserData(name: string, ignoreUndefinedProperties: boolean) methods.

@dlarocque dlarocque requested a review from MarkDuckworth March 18, 2026 15:33
@dlarocque dlarocque requested a review from a team as a code owner March 18, 2026 15:33
@product-auto-label product-auto-label Bot added the api: firestore Issues related to the Firestore API. label Mar 18, 2026
Copy link
Copy Markdown
Contributor

@MarkDuckworth MarkDuckworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with suggestions

Comment thread handwritten/firestore/types/firestore.d.ts Outdated
@dlarocque dlarocque merged commit c26967c into main Mar 24, 2026
35 checks passed
@dlarocque dlarocque deleted the dl/defer-validation branch March 24, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: firestore Issues related to the Firestore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants