Skip to content

Commit 58db6bf

Browse files
committed
Fixing tests and improving test coverage
1 parent fa56207 commit 58db6bf

File tree

10 files changed

+1150
-875
lines changed

10 files changed

+1150
-875
lines changed

packages/firestore/lite/pipelines/pipelines.ts

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export {
107107
bitXor,
108108
divide,
109109
isNotNan,
110-
manhattanDistance,
111110
map,
112111
isNotNull,
113112
isNull,

packages/firestore/src/api_pipelines.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
export { PipelineSource } from './lite-api/pipeline-source';
1919

20-
export { PipelineResult, PipelineSnapshot } from './lite-api/pipeline-result';
20+
export {
21+
PipelineResult,
22+
PipelineSnapshot,
23+
pipelineResultEqual
24+
} from './lite-api/pipeline-result';
2125

2226
export { Pipeline } from './api/pipeline';
2327

@@ -130,7 +134,6 @@ export {
130134
mapMerge,
131135
documentId,
132136
substr,
133-
manhattanDistance,
134137
Expr,
135138
ExprWithAlias,
136139
Field,

packages/firestore/src/core/pipeline-util.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export function toPipelineBooleanExpr(f: FilterInternal): BooleanExpr {
6565
}
6666
} else if (isNullValue(f.value)) {
6767
if (f.op === Operator.EQUAL) {
68-
return and(fieldValue.exists(), fieldValue.eq(null));
68+
return and(fieldValue.exists(), fieldValue.isNull());
6969
} else {
70-
return and(fieldValue.exists(), fieldValue.neq(null));
70+
return and(fieldValue.exists(), fieldValue.isNotNull());
7171
}
7272
} else {
7373
// Comparison filters
@@ -113,7 +113,7 @@ export function toPipelineBooleanExpr(f: FilterInternal): BooleanExpr {
113113
Constant._fromProto(val)
114114
);
115115
if (!values) {
116-
return fieldValue.exists();
116+
return and(fieldValue.exists(), fieldValue.eqAny([]));
117117
} else if (values.length === 1) {
118118
return and(fieldValue.exists(), fieldValue.eq(values[0]));
119119
} else {
@@ -131,7 +131,7 @@ export function toPipelineBooleanExpr(f: FilterInternal): BooleanExpr {
131131
Constant._fromProto(val)
132132
);
133133
if (!values) {
134-
return fieldValue.exists();
134+
return and(fieldValue.exists(), fieldValue.notEqAny([]));
135135
} else if (values.length === 1) {
136136
return and(fieldValue.exists(), fieldValue.neq(values[0]));
137137
} else {
@@ -215,13 +215,13 @@ export function toPipeline(query: Query, db: Firestore): Pipeline {
215215
// cursors
216216
if (query.startAt !== null) {
217217
pipeline = pipeline.where(
218-
whereConditionsFromCursor(query.startAt, orderings, 'before')
218+
whereConditionsFromCursor(query.startAt, orderings, 'after')
219219
);
220220
}
221221

222222
if (query.endAt !== null) {
223223
pipeline = pipeline.where(
224-
whereConditionsFromCursor(query.endAt, orderings, 'after')
224+
whereConditionsFromCursor(query.endAt, orderings, 'before')
225225
);
226226
}
227227

@@ -265,7 +265,7 @@ function whereConditionsFromCursor(
265265
const conditions: BooleanExpr[] = cursorSubset.map((cursor, index) => {
266266
if (index < cursorSubset.length - 1) {
267267
return eq(orderings[index].expr as Field, cursor);
268-
} else if (bound.inclusive && i === orderings.length) {
268+
} else if (bound.inclusive && i === orderings.length - 1) {
269269
return filterInclusiveFunc(orderings[index].expr as Field, cursor);
270270
} else {
271271
return filterFunc(orderings[index].expr as Field, cursor);

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

+20-124
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ export abstract class Expr implements ProtoValueSerializable, UserData {
12081208
...others: Array<Expr | unknown>
12091209
): FunctionExpr {
12101210
const values = [second, ...others];
1211-
return new FunctionExpr('logical_min', [
1211+
return new FunctionExpr('logical_minimum', [
12121212
this,
12131213
...values.map(valueToDefaultExpr)
12141214
]);
@@ -1314,39 +1314,6 @@ export abstract class Expr implements ProtoValueSerializable, UserData {
13141314
return new FunctionExpr('euclidean_distance', [this, vectorToExpr(other)]);
13151315
}
13161316

1317-
/**
1318-
* @beta
1319-
*
1320-
* Calculates the Manhattan distance between the result of this expression and another VectorValue.
1321-
*
1322-
* ```typescript
1323-
* // Calculate the Manhattan distance between the 'location' field and a target location
1324-
* field("location").manhattanDistance(new VectorValue([37.7749, -122.4194]));
1325-
* ```
1326-
*
1327-
* @param vector The other vector (as a VectorValue) to compare against.
1328-
* @return A new {@code Expr} representing the Manhattan distance between the two vectors.
1329-
*/
1330-
manhattanDistance(vector: VectorValue | number[]): FunctionExpr;
1331-
1332-
/**
1333-
* @beta
1334-
*
1335-
* Calculates the Manhattan distance between two vector expressions.
1336-
*
1337-
* ```typescript
1338-
* // Calculate the Manhattan distance between two vector fields: 'pointA' and 'pointB'
1339-
* field("pointA").manhattanDistance(field("pointB"));
1340-
* ```
1341-
*
1342-
* @param vectorExpression The other vector (represented as an Expr) to compare against.
1343-
* @return A new {@code Expr} representing the Manhattan distance between the two vectors.
1344-
*/
1345-
manhattanDistance(vectorExpression: Expr): FunctionExpr;
1346-
manhattanDistance(other: Expr | number[] | VectorValue): FunctionExpr {
1347-
return new FunctionExpr('manhattan_distance', [this, vectorToExpr(other)]);
1348-
}
1349-
13501317
/**
13511318
* Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC)
13521319
* and returns a timestamp.
@@ -2281,8 +2248,6 @@ export function field(nameOrPath: string | FieldPath): Field {
22812248
return new Field(documentIdFieldPath()._internalPath);
22822249
}
22832250
return new Field(fieldPathFromArgument('of', nameOrPath));
2284-
} else if (documentIdFieldPath().isEqual(nameOrPath)) {
2285-
return new Field(documentIdFieldPath()._internalPath);
22862251
} else {
22872252
return new Field(nameOrPath._internalPath);
22882253
}
@@ -4611,6 +4576,21 @@ export function arrayContainsAll(
46114576
return fieldOfOrExpr(array).arrayContainsAll(values);
46124577
}
46134578

4579+
/**
4580+
* @beta
4581+
*
4582+
* Creates an expression that calculates the length of an array in a specified field.
4583+
*
4584+
* ```typescript
4585+
* // Get the number of items in field 'cart'
4586+
* arrayLength('cart');
4587+
* ```
4588+
*
4589+
* @param fieldName The name of the field containing an array to calculate the length of.
4590+
* @return A new {@code Expr} representing the length of the array.
4591+
*/
4592+
export function arrayLength(fieldName: string): FunctionExpr;
4593+
46144594
/**
46154595
* @beta
46164596
*
@@ -4624,8 +4604,9 @@ export function arrayContainsAll(
46244604
* @param array The array expression to calculate the length of.
46254605
* @return A new {@code Expr} representing the length of the array.
46264606
*/
4627-
export function arrayLength(array: Expr): FunctionExpr {
4628-
return array.arrayLength();
4607+
export function arrayLength(array: Expr): FunctionExpr;
4608+
export function arrayLength(array: Expr | string): FunctionExpr {
4609+
return fieldOfOrExpr(array).arrayLength();
46294610
}
46304611

46314612
/**
@@ -5883,7 +5864,7 @@ export function strConcat(
58835864
second: string | Expr,
58845865
...elements: Array<string | Expr>
58855866
): FunctionExpr {
5886-
return valueToDefaultExpr(first).strConcat(
5867+
return fieldOfOrExpr(first).strConcat(
58875868
valueToDefaultExpr(second),
58885869
...elements.map(valueToDefaultExpr)
58895870
);
@@ -6366,91 +6347,6 @@ export function euclideanDistance(
63666347
return expr1.euclideanDistance(expr2);
63676348
}
63686349

6369-
/**
6370-
* @beta
6371-
*
6372-
* Calculates the Manhattan distance between a field's vector value and a double array.
6373-
*
6374-
* ```typescript
6375-
* // Calculate the Manhattan distance between the 'location' field and a target location
6376-
* manhattanDistance("location", [37.7749, -122.4194]);
6377-
* ```
6378-
*
6379-
* @param fieldName The name of the field containing the first vector.
6380-
* @param vector The other vector (as an array of doubles or VectorValue) to compare against.
6381-
* @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6382-
*/
6383-
export function manhattanDistance(
6384-
fieldName: string,
6385-
vector: number[] | VectorValue
6386-
): FunctionExpr;
6387-
6388-
/**
6389-
* @beta
6390-
*
6391-
* Calculates the Manhattan distance between a field's vector value and a vector expression.
6392-
*
6393-
* ```typescript
6394-
* // Calculate the Manhattan distance between two vector fields: 'pointA' and 'pointB'
6395-
* manhattanDistance("pointA", field("pointB"));
6396-
* ```
6397-
*
6398-
* @param fieldName The name of the field containing the first vector.
6399-
* @param vectorExpression The other vector (represented as an Expr) to compare against.
6400-
* @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6401-
*/
6402-
export function manhattanDistance(
6403-
fieldName: string,
6404-
vectorExpression: Expr
6405-
): FunctionExpr;
6406-
6407-
/**
6408-
* @beta
6409-
*
6410-
* Calculates the Manhattan distance between a vector expression and a double array.
6411-
*
6412-
* ```typescript
6413-
* // Calculate the Manhattan distance between the 'location' field and a target location
6414-
*
6415-
* manhattanDistance(field("location"), [37.7749, -122.4194]);
6416-
* ```
6417-
*
6418-
* @param vectorExpression The first vector (represented as an Expr) to compare against.
6419-
* @param vector The other vector (as an array of doubles or VectorValue) to compare against.
6420-
* @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6421-
*/
6422-
export function manhattanDistance(
6423-
vectorExpression: Expr,
6424-
vector: number[] | VectorValue
6425-
): FunctionExpr;
6426-
6427-
/**
6428-
* @beta
6429-
*
6430-
* Calculates the Manhattan distance between two vector expressions.
6431-
*
6432-
* ```typescript
6433-
* // Calculate the Manhattan distance between two vector fields: 'pointA' and 'pointB'
6434-
* manhattanDistance(field("pointA"), field("pointB"));
6435-
* ```
6436-
*
6437-
* @param vectorExpression The first vector (represented as an Expr) to compare against.
6438-
* @param otherVectorExpression The other vector (represented as an Expr) to compare against.
6439-
* @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6440-
*/
6441-
export function manhattanDistance(
6442-
vectorExpression: Expr,
6443-
otherVectorExpression: Expr
6444-
): FunctionExpr;
6445-
export function manhattanDistance(
6446-
fieldOrExpr: Expr | string,
6447-
other: Expr | number[] | VectorValue
6448-
): FunctionExpr {
6449-
const expr1 = fieldOfOrExpr(fieldOrExpr);
6450-
const expr2 = vectorToExpr(other);
6451-
return expr1.manhattanDistance(expr2);
6452-
}
6453-
64546350
/**
64556351
* @beta
64566352
*

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,9 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
812812
if (typeof selectable === 'string') {
813813
result.set(selectable as string, field(selectable));
814814
} else if (selectable instanceof Field) {
815-
result.set((selectable as Field).fieldName(), selectable);
815+
result.set(selectable.alias, selectable.expr);
816816
} else if (selectable instanceof ExprWithAlias) {
817-
const expr = selectable as ExprWithAlias;
818-
result.set(expr.alias, expr.expr);
817+
result.set(selectable.alias, selectable.expr);
819818
}
820819
}
821820
return result;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ export class Unnest implements Stage {
464464
* @beta
465465
*/
466466
export class Replace implements Stage {
467-
name = 'replace';
467+
name = 'replace_with';
468468

469469
constructor(
470470
private field: Field,

0 commit comments

Comments
 (0)