refactor(firestore): modernize internal proto call sites and eliminate local declarations (#9076) - #9076
Conversation
… callsite modernization (#8928)
There was a problem hiding this comment.
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; |
…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
… with firestore-api@0.4.0 (#9076) - Connect standalone bundle-proto module directly to firestore-api@0.4.0 GAPIC message roots and automate copy during postcompile - Normalize unary and composite field filter operator serializations to cleanly emit canonical GAPIC numeric enums - Update unit test builder helpers across query, vector-query, and bundle verification suites to ensure 100% passing test compatibility against official firestore-api@0.4.0 release
…s shell compatibility (#9076) - Remove minifyProtoJson execution from postcompile script as static runtime GAPIC .js/.json files are now minified upstream inside @google-cloud/firestore-api - Strip POSIX stream error redirection syntax (2>/dev/null) to prevent command failures on Windows cmd and PowerShell CI runners - Preserve directory initialization and raw bundle.proto schema copy steps required by conformance test suites
| */ | ||
|
|
||
| import * as protos from '../../protos/firestore_v1_proto_api'; | ||
| import * as protos from "@google-cloud/firestore-api/build/protos/protos"; |
There was a problem hiding this comment.
is /build in the path intentional? seems like the entrypoint should be @google-cloud/firestore-api/protos/protos. Same across most files in this PR
There was a problem hiding this comment.
looking back at the change to exports in firestore-api, I guess I missed this as a reviewer. we can change this later since firestore-api is not yet v1.0
| { | ||
| parent: query.toProto().parent, | ||
| structuredQuery: query.toProto().structuredQuery, | ||
| structuredQuery: require("@google-cloud/firestore-api/build/protos/protos").google.firestore.v1.StructuredQuery.fromObject(query.toProto().structuredQuery).toJSON(), |
There was a problem hiding this comment.
Is the require("@google-cloud/firestore-api/build/protos/protos") necessary here given we already have the import at the top of the file?
| { | ||
| parent: newQuery.toProto().parent, | ||
| structuredQuery: newQuery.toProto().structuredQuery, | ||
| structuredQuery: require("@google-cloud/firestore-api/build/protos/protos").google.firestore.v1.StructuredQuery.fromObject(newQuery.toProto().structuredQuery).toJSON(), |
| constructor( | ||
| private filters: FilterInternal[], | ||
| private operator: api.StructuredQuery.CompositeFilter.Operator, | ||
| private operator: api.StructuredQuery.CompositeFilter.Operator | any, |
There was a problem hiding this comment.
This applies across the board regarding parameters with enum types that have been extended as ... | any. It would be safer to use EnumType | keyof typeof EnumType.
api.StructuredQuery.CompositeFilter.Operator | keyof typeof api.StructuredQuery.CompositeFilter.Operator
| * @internal | ||
| */ | ||
| public _getOperator(): api.StructuredQuery.CompositeFilter.Operator { | ||
| public _getOperator(): api.StructuredQuery.CompositeFilter.Operator | any { |
| } | ||
| export interface BundledQuery { | ||
| parent?: string | null; | ||
| structuredQuery?: any | null; |
There was a problem hiding this comment.
| structuredQuery?: any | null; | |
| structuredQuery?: google.firestore.v1.IStructuredQuery | null; |
| } | ||
| export interface BundledDocumentMetadata { | ||
| name?: string | null; | ||
| readTime?: any | null; |
There was a problem hiding this comment.
| readTime?: any | null; | |
| readTime?: google.protobuf.ITimestamp | null; |
| export interface NamedQuery { | ||
| name?: string | null; | ||
| bundledQuery?: BundledQuery | null; | ||
| readTime?: any | null; |
There was a problem hiding this comment.
| readTime?: any | null; | |
| readTime?: google.protobuf.ITimestamp | null; |
| export interface BundledQuery { | ||
| parent?: string | null; | ||
| structuredQuery?: any | null; | ||
| limitType?: string | null; |
There was a problem hiding this comment.
| limitType?: string | null; | |
| limitType?: 'FIRST' | 'LAST' | null; |
| createTime?: any | null; | ||
| version?: number | null; | ||
| totalDocuments?: number | null; | ||
| totalBytes?: number | null; |
There was a problem hiding this comment.
| totalBytes?: number | null; | |
| totalBytes?: number | string | null; |
Part 4 of stacked disentanglement (#8928). Transition
@google-cloud/firestoreto directly consume@google-cloud/firestore-apias its native Single Source of Truth for TypeScript declarations, removing static checked-in local proto types.Background & Motivation
Historically,
dev/protos/update.shcompiled static TypeScript interfaces (firestore_v1_proto_api.d.ts) using custom build transformations:--force-enum-stringto convert protobuf numeric enums into string literal unions ('ASCENDING' | 'DESCENDING').Longreferences withstring.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-apiprovides continuous automated type generation without build script maintenance.Summary of Changes
dev/protos/firestore_v1_proto_api.d.ts,dev/protos/firestore_v1_proto_api.js, anddev/protos/v1.json, making@google-cloud/firestore-apiour native Single Source of Truth.bundle.proto), which belong strictly to the handwritten SDK wrapper and are independent of GAPIC models, into standalone local modules (dev/src/bundle-proto).directionOperators,comparisonOperators) and sorting algorithms to natively consume GAPIC enum objects and 64-bitLongstructures.Backward Compatibility Guarantee
orderBy.direction === 'ASCENDING' || orderBy.direction === api.StructuredQuery.Direction.ASCENDING) to support both literal strings and numeric GAPIC enums interchangeably.fallback: true),proto3-json-serializerinspects 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