Skip to content

Commit

Permalink
use FieldPath.fromServerFormat for code simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Aug 3, 2023
1 parent c237dce commit bdcfeb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
9 changes: 4 additions & 5 deletions packages/firestore/test/unit/core/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
doc,
expectCorrectComparisons,
expectEqualitySets,
fieldPath,
filter,
orderBy,
orFilter,
Expand Down Expand Up @@ -844,12 +843,12 @@ describe('Query', () => {
query(
'foo',
filter('a', '<', 5),
filter('a.z', '>', 5),
filter(fieldPath('a.a'), '>', 5)
filter('a.z', '>', 5), // nested field
filter('`a.a`', '>', 5) // field name with dot
),
orderBy('a'),
orderBy('a.z'), // nested field
orderBy(fieldPath('a.a')), // field name with dot
orderBy('a.z'),
orderBy('`a.a`'),
orderBy(DOCUMENT_KEY_NAME)
);

Expand Down
15 changes: 4 additions & 11 deletions packages/firestore/test/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,10 @@ export function path(path: string, offset?: number): ResourcePath {
return new ResourcePath(splitPath(path, '/'), offset);
}

export function field(path: string | FieldPath): FieldPath {
return path instanceof FieldPath ? path : new FieldPath(path.split('.'));
export function field(path: string): FieldPath {
return FieldPath.fromServerFormat(path);
}

export function fieldPath(path: string): FieldPath {
return new FieldPath([path]);
}
export function fieldIndex(
collectionGroup: string,
options: {
Expand Down Expand Up @@ -264,11 +261,7 @@ export function blob(...bytes: number[]): Bytes {
return Bytes.fromUint8Array(new Uint8Array(bytes || []));
}

export function filter(
path: string | FieldPath,
op: string,
value: unknown
): FieldFilter {
export function filter(path: string, op: string, value: unknown): FieldFilter {
const dataValue = wrap(value);
const operator = op as Operator;
return FieldFilter.create(field(path), operator, dataValue);
Expand Down Expand Up @@ -743,7 +736,7 @@ export function resumeTokenForSnapshot(
}
}

export function orderBy(path: string | FieldPath, op?: string): OrderBy {
export function orderBy(path: string, op?: string): OrderBy {
op = op || 'asc';
debugAssert(op === 'asc' || op === 'desc', 'Unknown direction: ' + op);
const dir: Direction =
Expand Down

0 comments on commit bdcfeb6

Please sign in to comment.