Skip to content

Commit

Permalink
allow skipping aliasing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannas committed May 2, 2024
1 parent b0bd072 commit 596dadb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
1 change: 0 additions & 1 deletion packages/firestore/rollup.shared.js
Expand Up @@ -108,7 +108,6 @@ const externsPaths = externs.map(p => path.resolve(__dirname, '../../', p));
const publicIdentifiers = extractPublicIdentifiers(externsPaths);
// manually add `_delegate` because we don't have typings for the compat package
publicIdentifiers.add('_delegate');
publicIdentifiers.add('ToRunAggregationQueryRequestReturnType');

/**
* Transformers that remove calls to `debugAssert` and messages for 'fail` and
Expand Down
18 changes: 7 additions & 11 deletions packages/firestore/src/remote/internal_serializer.ts
Expand Up @@ -54,15 +54,10 @@ export function _internalQueryToProtoQueryTarget(query: Query): any {
*
* This function is for internal use only.
*
* Returns
* {
* request: RunAggregationQueryRequest;
* aliasMap: Record<string, string>;
* parent: ResourcePath;
* }
* which contains the proto representation of the given aggregation query.
* Returns null if the Firestore client associated with the given query has not
* been initialized or has been terminated.
* Returns `RunAggregationQueryRequest` which contains the proto representation
* of the given aggregation query request. Returns null if the Firestore client
* associated with the given query has not been initialized or has been
* terminated.
*
* @param query - The Query to convert to proto representation.
* @param aggregateSpec - The set of aggregations and their aliases.
Expand All @@ -88,6 +83,7 @@ export function _internalAggregationQueryToProtoRunAggregationQueryRequest<
return toRunAggregationQueryRequest(
serializer!,
queryToAggregateTarget(query._query),
aggregates
);
aggregates,
/* skipAliasing= */ true
).request;
}
21 changes: 10 additions & 11 deletions packages/firestore/src/remote/serializer.ts
Expand Up @@ -900,19 +900,16 @@ export function toQueryTarget(
return { queryTarget, parent };
}

// Note: keep this interface declaration in order to avoid its minification when
// used by _internalAggregationQueryToProtoRunAggregationQueryRequest.
declare interface ToRunAggregationQueryRequestReturnType {
request: ProtoRunAggregationQueryRequest;
aliasMap: Record<string, string>;
parent: ResourcePath;
}

export function toRunAggregationQueryRequest(
serializer: JsonProtoSerializer,
target: Target,
aggregates: Aggregate[]
): ToRunAggregationQueryRequestReturnType {
aggregates: Aggregate[],
skipAliasing?: boolean
): {
request: ProtoRunAggregationQueryRequest;
aliasMap: Record<string, string>;
parent: ResourcePath;
} {
const { queryTarget, parent } = toQueryTarget(serializer, target);
const aliasMap: Record<string, string> = {};

Expand All @@ -923,7 +920,9 @@ export function toRunAggregationQueryRequest(
// Map all client-side aliases to a unique short-form
// alias. This avoids issues with client-side aliases that
// exceed the 1500-byte string size limit.
const serverAlias = `aggregate_${aggregationNum++}`;
const serverAlias = skipAliasing
? aggregate.alias
: `aggregate_${aggregationNum++}`;
aliasMap[serverAlias] = aggregate.alias;

if (aggregate.aggregateType === 'count') {
Expand Down

0 comments on commit 596dadb

Please sign in to comment.