Skip to content

refactor(firestore): modernize internal proto call sites and eliminate local declarations (#9076) - #9076

Draft
quirogas wants to merge 2 commits into
chore/presubmit-bundle-size-guardfrom
refactor/firestore-modernize-proto-types
Draft

refactor(firestore): modernize internal proto call sites and eliminate local declarations (#9076)#9076
quirogas wants to merge 2 commits into
chore/presubmit-bundle-size-guardfrom
refactor/firestore-modernize-proto-types

Conversation

@quirogas

@quirogas quirogas commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Part 4 of stacked disentanglement (#8928). Transition @google-cloud/firestore to directly consume @google-cloud/firestore-api as its native Single Source of Truth for TypeScript declarations, removing static checked-in local proto types.

Background & Motivation

Historically, dev/protos/update.sh compiled static TypeScript interfaces (firestore_v1_proto_api.d.ts) using custom build transformations:

  • Used --force-enum-string to convert protobuf numeric enums into string literal unions ('ASCENDING' | 'DESCENDING').
  • Executed a Perl regex to replace 64-bit integer Long references with string.

While this simplified early static method signatures, it created dependency on static checked-in declaration files that risk drifting out of sync as upstream protobuf definitions evolve over time. Transitioning directly to @google-cloud/firestore-api provides continuous automated type generation without build script maintenance.

Summary of Changes

  • Eliminate Static Local Types: Complete removal of dev/protos/firestore_v1_proto_api.d.ts, dev/protos/firestore_v1_proto_api.js, and dev/protos/v1.json, making @google-cloud/firestore-api our native Single Source of Truth.
  • Bundle Protocol Isolation: Extract custom offline bundle persistence interfaces (bundle.proto), which belong strictly to the handwritten SDK wrapper and are independent of GAPIC models, into standalone local modules (dev/src/bundle-proto).
  • Call-Site & Comparator Modernization: Update internal query dictionaries (directionOperators, comparisonOperators) and sorting algorithms to natively consume GAPIC enum objects and 64-bit Long structures.

Backward Compatibility Guarantee

  • All internal sorting and query comparator algorithms implement dual matching (orderBy.direction === 'ASCENDING' || orderBy.direction === api.StructuredQuery.Direction.ASCENDING) to support both literal strings and numeric GAPIC enums interchangeably.
  • Verified that during HTTP REST fallback execution (fallback: true), proto3-json-serializer inspects GAPIC reflection models and automatically translates numeric integer enum codes back into standard JSON string schema names before transmitting payloads over HTTP, guaranteeing zero regressions for REST consumers.

Internal: b/531788771


📚 Stack Navigation Index

  1. Layer 1 (Base Disentanglement & Runtime Forwarding): feat(firestore): decouple handwritten sdk wrapper from embedded gapic clients #8928
  2. Layer 2 (Complete Decoupling & Dead Code Cleanup): feat(firestore)!: complete gapic decoupling, adopt subpath imports, and remove legacy proto code (#9074) #9074
  3. Layer 3 (Automated Presubmit Bundle Size Guard): chore(firestore): add automated presubmit serverless bundle size regression guard (#9075) #9075
  4. Layer 4 (Call-Site Modernization & Eliminate Local Protos): refactor(firestore): modernize internal proto call sites and eliminate local declarations (#9076) #9076

@product-auto-label product-auto-label Bot added the api: firestore Issues related to the Firestore API. label Aug 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new TypeScript declaration file, bundle.d.ts, defining the custom Firestore bundle persistence protocol types. The review feedback focuses on improving type safety across these declarations. Specifically, it is recommended to replace several any types for time-related fields (createTime and readTime) with a dedicated Timestamp interface, define that Timestamp interface, and restrict the limitType field to the specific string union values 'FIRST' | 'LAST'.

}
export interface BundleMetadata {
id?: string | null;
createTime?: any | null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using any for createTime reduces type safety. We should use a Timestamp interface instead.

Suggested change
createTime?: any | null;
createTime?: Timestamp | null;

export interface NamedQuery {
name?: string | null;
bundledQuery?: BundledQuery | null;
readTime?: any | null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using any for readTime reduces type safety. We should use a Timestamp interface instead.

Suggested change
readTime?: any | null;
readTime?: Timestamp | null;

}
export interface BundledDocumentMetadata {
name?: string | null;
readTime?: any | null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using any for readTime reduces type safety. We should use a Timestamp interface instead.

Suggested change
readTime?: any | null;
readTime?: Timestamp | null;

Comment on lines +44 to +48
export interface BundledQuery {
parent?: string | null;
structuredQuery?: any | null;
limitType?: string | null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Define a Timestamp interface to represent protobuf Timestamps, and restrict limitType to the allowed string union values 'FIRST' | 'LAST' for better type safety.

  export interface BundledQuery {
    parent?: string | null;
    structuredQuery?: any | null;
    limitType?: 'FIRST' | 'LAST' | null;
  }
  export interface Timestamp {
    seconds?: string | number | null;
    nanos?: number | null;
  }

@quirogas quirogas changed the title refactor(firestore): extract bundle serialization interface and begin callsite modernization (#8928) refactor(firestore): modernize internal proto call sites and remove local declarations (#8928) Aug 4, 2026
…e local declarations (#8928)

- Remove dev/protos/firestore_v1_proto_api.* and dev/protos/v1.json to transition @google-cloud/firestore-api into our automated Single Source of Truth for TypeScript declarations
- Extract custom offline bundle persistence interface definitions into standalone dev/src/bundle-proto.* modules
- Update query operator dictionaries (directionOperators, comparisonOperators) and internal comparators to consume native GAPIC enum objects and 64-bit Long structures
- Verify 100% clean compilation and passing unit test suites across watch, partition-query, aggregate-query, and transaction operations
@quirogas quirogas changed the title refactor(firestore): modernize internal proto call sites and remove local declarations (#8928) refactor(firestore): modernize internal proto call sites and eliminate local declarations (#9076) Aug 5, 2026
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.

1 participant