Skip to content

Commit bdcfeb6

Browse files
committed
use FieldPath.fromServerFormat for code simplicity
1 parent c237dce commit bdcfeb6

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

packages/firestore/test/unit/core/query.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import {
5050
doc,
5151
expectCorrectComparisons,
5252
expectEqualitySets,
53-
fieldPath,
5453
filter,
5554
orderBy,
5655
orFilter,
@@ -844,12 +843,12 @@ describe('Query', () => {
844843
query(
845844
'foo',
846845
filter('a', '<', 5),
847-
filter('a.z', '>', 5),
848-
filter(fieldPath('a.a'), '>', 5)
846+
filter('a.z', '>', 5), // nested field
847+
filter('`a.a`', '>', 5) // field name with dot
849848
),
850849
orderBy('a'),
851-
orderBy('a.z'), // nested field
852-
orderBy(fieldPath('a.a')), // field name with dot
850+
orderBy('a.z'),
851+
orderBy('`a.a`'),
853852
orderBy(DOCUMENT_KEY_NAME)
854853
);
855854

packages/firestore/test/util/helpers.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,10 @@ export function path(path: string, offset?: number): ResourcePath {
226226
return new ResourcePath(splitPath(path, '/'), offset);
227227
}
228228

229-
export function field(path: string | FieldPath): FieldPath {
230-
return path instanceof FieldPath ? path : new FieldPath(path.split('.'));
229+
export function field(path: string): FieldPath {
230+
return FieldPath.fromServerFormat(path);
231231
}
232232

233-
export function fieldPath(path: string): FieldPath {
234-
return new FieldPath([path]);
235-
}
236233
export function fieldIndex(
237234
collectionGroup: string,
238235
options: {
@@ -264,11 +261,7 @@ export function blob(...bytes: number[]): Bytes {
264261
return Bytes.fromUint8Array(new Uint8Array(bytes || []));
265262
}
266263

267-
export function filter(
268-
path: string | FieldPath,
269-
op: string,
270-
value: unknown
271-
): FieldFilter {
264+
export function filter(path: string, op: string, value: unknown): FieldFilter {
272265
const dataValue = wrap(value);
273266
const operator = op as Operator;
274267
return FieldFilter.create(field(path), operator, dataValue);
@@ -743,7 +736,7 @@ export function resumeTokenForSnapshot(
743736
}
744737
}
745738

746-
export function orderBy(path: string | FieldPath, op?: string): OrderBy {
739+
export function orderBy(path: string, op?: string): OrderBy {
747740
op = op || 'asc';
748741
debugAssert(op === 'asc' || op === 'desc', 'Unknown direction: ' + op);
749742
const dir: Direction =

0 commit comments

Comments
 (0)