Skip to content

Commit 814e268

Browse files
committed
Fixing circular dependency errors in the build.
1 parent e62f29b commit 814e268

File tree

9 files changed

+85
-110
lines changed

9 files changed

+85
-110
lines changed

packages/firestore/src/api/snapshot.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ import {
3131
import { LiteUserDataWriter } from '../lite-api/reference_impl';
3232
import {
3333
DocumentSnapshot as LiteDocumentSnapshot,
34-
fieldPathFromArgument,
3534
FirestoreDataConverter as LiteFirestoreDataConverter
3635
} from '../lite-api/snapshot';
37-
import { UntypedFirestoreDataConverter } from '../lite-api/user_data_reader';
36+
import {
37+
fieldPathFromArgument,
38+
UntypedFirestoreDataConverter
39+
} from '../lite-api/user_data_reader';
3840
import { AbstractUserDataWriter } from '../lite-api/user_data_writer';
3941
import { fromBundledQuery } from '../local/local_serializer';
4042
import { documentKeySet } from '../model/collections';

packages/firestore/src/lite-api/expressions.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7272,3 +7272,48 @@ export class Ordering implements ProtoValueSerializable, UserData {
72727272

72737273
_protoValueType: 'ProtoValue' = 'ProtoValue';
72747274
}
7275+
7276+
export function isSelectable(val: unknown): val is Selectable {
7277+
const candidate = val as Selectable;
7278+
return (
7279+
candidate.selectable && isString(candidate.alias) && isExpr(candidate.expr)
7280+
);
7281+
}
7282+
7283+
export function isOrdering(val: unknown): val is Ordering {
7284+
const candidate = val as Ordering;
7285+
return (
7286+
isExpr(candidate.expr) &&
7287+
(candidate.direction === 'ascending' ||
7288+
candidate.direction === 'descending')
7289+
);
7290+
}
7291+
7292+
export function isAliasedAggregate(val: unknown): val is AggregateWithAlias {
7293+
const candidate = val as AggregateWithAlias;
7294+
return (
7295+
isString(candidate.alias) &&
7296+
candidate.aggregate instanceof AggregateFunction
7297+
);
7298+
}
7299+
7300+
export function isExpr(val: unknown): val is Expression {
7301+
return val instanceof Expression;
7302+
}
7303+
7304+
export function isBooleanExpr(val: unknown): val is BooleanExpression {
7305+
return val instanceof BooleanExpression;
7306+
}
7307+
7308+
export function isField(val: unknown): val is Field {
7309+
return val instanceof Field;
7310+
}
7311+
7312+
export function toField(value: string | Field): Field {
7313+
if (isString(value)) {
7314+
const result = field(value);
7315+
return result;
7316+
} else {
7317+
return value as Field;
7318+
}
7319+
}

packages/firestore/src/lite-api/pipeline-result.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import { ObjectValue } from '../model/object_value';
1919
import { isOptionalEqual } from '../util/misc';
2020

21-
import { Field } from './expressions';
21+
import { Field, isField } from './expressions';
2222
import { FieldPath } from './field_path';
2323
import { Pipeline } from './pipeline';
2424
import { DocumentData, DocumentReference, refEqual } from './reference';
25-
import { fieldPathFromArgument } from './snapshot';
2625
import { Timestamp } from './timestamp';
26+
import { fieldPathFromArgument } from './user_data_reader';
2727
import { AbstractUserDataWriter } from './user_data_writer';
2828

2929
export class PipelineSnapshot {
@@ -200,6 +200,9 @@ export class PipelineResult<AppModelType = DocumentData> {
200200
if (this._fields === undefined) {
201201
return undefined;
202202
}
203+
if (isField(fieldPath)) {
204+
fieldPath = fieldPath.fieldName;
205+
}
203206

204207
const value = this._fields.field(
205208
fieldPathFromArgument('DocumentSnapshot.get', fieldPath)

packages/firestore/src/lite-api/pipeline-source.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
import { DatabaseId } from '../core/database_info';
1919
import { toPipeline } from '../core/pipeline-util';
2020
import { Code, FirestoreError } from '../util/error';
21-
import { isCollectionReference, isString } from '../util/types';
21+
import { isString } from '../util/types';
2222

2323
import { Pipeline } from './pipeline';
24-
import { CollectionReference, DocumentReference, Query } from './reference';
24+
import {
25+
CollectionReference,
26+
DocumentReference,
27+
isCollectionReference,
28+
Query
29+
} from './reference';
2530
import {
2631
CollectionGroupSource,
2732
CollectionSource,

packages/firestore/src/lite-api/pipeline.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@ import {
2929
selectablesToMap,
3030
vectorToExpr
3131
} from '../util/pipeline_util';
32-
import {
33-
isAliasedAggregate,
34-
isBooleanExpr,
35-
isExpr,
36-
isField,
37-
isLitePipeline,
38-
isOrdering,
39-
isSelectable,
40-
isString,
41-
toField
42-
} from '../util/types';
32+
import { isString } from '../util/types';
4333

4434
import { Firestore } from './database';
4535
import {
@@ -53,7 +43,14 @@ import {
5343
field,
5444
Ordering,
5545
Selectable,
56-
_field
46+
_field,
47+
isSelectable,
48+
isField,
49+
isBooleanExpr,
50+
isAliasedAggregate,
51+
toField,
52+
isOrdering,
53+
isExpr
5754
} from './expressions';
5855
import {
5956
AddFields,
@@ -1214,7 +1211,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
12141211
// Process argument union(s) from method overloads
12151212
let options: {};
12161213
let otherPipeline: Pipeline;
1217-
if (isLitePipeline(otherOrOptions)) {
1214+
if (isPipeline(otherOrOptions)) {
12181215
options = {};
12191216
otherPipeline = otherOrOptions;
12201217
} else {
@@ -1437,3 +1434,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
14371434
return new Pipeline(db, userDataReader, userDataWriter, stages);
14381435
}
14391436
}
1437+
1438+
export function isPipeline(val: unknown): val is Pipeline {
1439+
return val instanceof Pipeline;
1440+
}

packages/firestore/src/lite-api/query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ import {
5252

5353
import { FieldPath } from './field_path';
5454
import { DocumentData, DocumentReference, Query } from './reference';
55-
import { DocumentSnapshot, fieldPathFromArgument } from './snapshot';
55+
import { DocumentSnapshot } from './snapshot';
5656
import {
57+
fieldPathFromArgument,
5758
newUserDataReader,
5859
parseQueryValue,
5960
UserDataReader

packages/firestore/src/lite-api/reference.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ export class CollectionReference<
440440
}
441441
}
442442

443+
export function isCollectionReference(
444+
val: unknown
445+
): val is CollectionReference {
446+
return val instanceof CollectionReference;
447+
}
448+
443449
/**
444450
* Gets a `CollectionReference` instance that refers to the collection at
445451
* the specified absolute path.

packages/firestore/src/lite-api/snapshot.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { Compat, getModularInstance } from '@firebase/util';
18+
import { getModularInstance } from '@firebase/util';
1919

2020
import { Document } from '../model/document';
2121
import { DocumentKey } from '../model/document_key';
22-
import { FieldPath as InternalFieldPath } from '../model/path';
2322
import { arrayEquals } from '../util/misc';
2423

2524
import { Firestore } from './database';
26-
import { Field } from './expressions';
2725
import { FieldPath } from './field_path';
2826
import {
2927
DocumentData,
@@ -35,7 +33,7 @@ import {
3533
WithFieldValue
3634
} from './reference';
3735
import {
38-
fieldPathFromDotSeparatedString,
36+
fieldPathFromArgument,
3937
UntypedFirestoreDataConverter
4038
} from './user_data_reader';
4139
import { AbstractUserDataWriter } from './user_data_writer';
@@ -510,21 +508,3 @@ export function snapshotEqual<AppModelType, DbModelType extends DocumentData>(
510508

511509
return false;
512510
}
513-
514-
/**
515-
* Helper that calls `fromDotSeparatedString()` but wraps any error thrown.
516-
*/
517-
export function fieldPathFromArgument(
518-
methodName: string,
519-
arg: string | FieldPath | Compat<FieldPath> | Field
520-
): InternalFieldPath {
521-
if (typeof arg === 'string') {
522-
return fieldPathFromDotSeparatedString(methodName, arg);
523-
} else if (arg instanceof FieldPath) {
524-
return arg._internalPath;
525-
} else if (arg instanceof Field) {
526-
return fieldPathFromDotSeparatedString(methodName, arg.fieldName);
527-
} else {
528-
return arg._delegate._internalPath;
529-
}
530-
}

packages/firestore/src/util/types.ts

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { CollectionReference } from '../api';
19-
import {
20-
AggregateFunction,
21-
AggregateWithAlias,
22-
BooleanExpression,
23-
Expression,
24-
field,
25-
Field,
26-
Ordering,
27-
Selectable
28-
} from '../lite-api/expressions';
29-
import { Pipeline as LitePipeline } from '../lite-api/pipeline';
30-
3118
/** Sentinel value that sorts before any Mutation Batch ID. */
3219
export const BATCHID_UNKNOWN = -1;
3320

@@ -97,58 +84,3 @@ export type OneOf<T> = {
9784
[P in Exclude<keyof T, K>]?: undefined;
9885
};
9986
}[keyof T];
100-
101-
export function isSelectable(val: unknown): val is Selectable {
102-
const candidate = val as Selectable;
103-
return (
104-
candidate.selectable && isString(candidate.alias) && isExpr(candidate.expr)
105-
);
106-
}
107-
108-
export function isOrdering(val: unknown): val is Ordering {
109-
const candidate = val as Ordering;
110-
return (
111-
isExpr(candidate.expr) &&
112-
(candidate.direction === 'ascending' ||
113-
candidate.direction === 'descending')
114-
);
115-
}
116-
117-
export function isAliasedAggregate(val: unknown): val is AggregateWithAlias {
118-
const candidate = val as AggregateWithAlias;
119-
return (
120-
isString(candidate.alias) &&
121-
candidate.aggregate instanceof AggregateFunction
122-
);
123-
}
124-
125-
export function isExpr(val: unknown): val is Expression {
126-
return val instanceof Expression;
127-
}
128-
129-
export function isBooleanExpr(val: unknown): val is BooleanExpression {
130-
return val instanceof BooleanExpression;
131-
}
132-
133-
export function isField(val: unknown): val is Field {
134-
return val instanceof Field;
135-
}
136-
137-
export function isLitePipeline(val: unknown): val is LitePipeline {
138-
return val instanceof LitePipeline;
139-
}
140-
141-
export function isCollectionReference(
142-
val: unknown
143-
): val is CollectionReference {
144-
return val instanceof CollectionReference;
145-
}
146-
147-
export function toField(value: string | Field): Field {
148-
if (isString(value)) {
149-
const result = field(value);
150-
return result;
151-
} else {
152-
return value as Field;
153-
}
154-
}

0 commit comments

Comments
 (0)