Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Constant.of(...) #8677

Open
wants to merge 2 commits into
base: feat/pipelines
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,13 @@ export class Constant {
static of(value: string): Constant;
static of(value: boolean): Constant;
static of(value: null): Constant;
static of(value: undefined): Constant;
static of(value: GeoPoint): Constant;
static of(value: Timestamp): Constant;
static of(value: Date): Constant;
static of(value: Uint8Array): Constant;
static of(value: Bytes): Constant;
static of(value: DocumentReference): Constant;
static of(value: any[]): Constant;
static of(value: Map<string, any>): Constant;
static of(value: Record<string, any>): Constant;
static of(value: VectorValue): Constant;
regexContains(pattern: string): RegexContains;
regexContains(pattern: Constant): RegexContains;
Expand Down Expand Up @@ -2205,8 +2204,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;

// Warnings were encountered during analysis:
//
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9244:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9245:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9274:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9238:9 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9239:9 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/lite/index.d.ts:9268:9 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta

```
11 changes: 5 additions & 6 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,13 @@ export class Constant {
static of(value: string): Constant;
static of(value: boolean): Constant;
static of(value: null): Constant;
static of(value: undefined): Constant;
static of(value: GeoPoint): Constant;
static of(value: Timestamp): Constant;
static of(value: Date): Constant;
static of(value: Uint8Array): Constant;
static of(value: Bytes): Constant;
static of(value: DocumentReference): Constant;
static of(value: any[]): Constant;
static of(value: Map<string, any>): Constant;
static of(value: Record<string, any>): Constant;
static of(value: VectorValue): Constant;
regexContains(pattern: string): RegexContains;
regexContains(pattern: Constant): RegexContains;
Expand Down Expand Up @@ -2509,8 +2508,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;

// Warnings were encountered during analysis:
//
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10173:26 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10173:61 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /Users/markduckworth/projects/firebase-js-sdk/packages/firestore/dist/index.d.ts:10200:21 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10167:26 - (ae-incompatible-release-tags) The symbol "accumulators" is marked as @public, but its signature references "AccumulatorTarget" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10167:61 - (ae-incompatible-release-tags) The symbol "groups" is marked as @public, but its signature references "Selectable" which is marked as @beta
// /home/runner/work/firebase-js-sdk/firebase-js-sdk/packages/firestore/dist/index.d.ts:10194:21 - (ae-incompatible-release-tags) The symbol "orderings" is marked as @public, but its signature references "Ordering" which is marked as @beta

```
13 changes: 8 additions & 5 deletions packages/firestore/src/lite-api/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '../remote/serializer';
import { hardAssert } from '../util/assert';

import { Bytes } from './bytes';
import { documentId, FieldPath } from './field_path';
import { GeoPoint } from './geo_point';
import { Pipeline } from './pipeline';
Expand Down Expand Up @@ -2084,6 +2085,8 @@ export class Constant extends Expr {

/**
* Creates a `Constant` instance for an undefined value.
* @private
* @internal
*
* @param value The undefined value.
* @return A new `Constant` instance.
Expand Down Expand Up @@ -2115,12 +2118,12 @@ export class Constant extends Expr {
static of(value: Date): Constant;

/**
* Creates a `Constant` instance for a Uint8Array value.
* Creates a `Constant` instance for a Bytes value.
*
* @param value The Uint8Array value.
* @param value The Bytes value.
* @return A new `Constant` instance.
*/
static of(value: Uint8Array): Constant;
static of(value: Bytes): Constant;

/**
* Creates a `Constant` instance for a DocumentReference value.
Expand All @@ -2130,9 +2133,9 @@ export class Constant extends Expr {
*/
static of(value: DocumentReference): Constant;

// TODO(pipeline) if we make this public, then the Proto types should also be documented
/**
* Creates a `Constant` instance for a Firestore proto value.
* For internal use only.
* @private
* @internal
* @param value The Firestore proto value.
Expand All @@ -2154,7 +2157,7 @@ export class Constant extends Expr {
* @param value The map value.
* @return A new `Constant` instance.
*/
static of(value: Map<string, any>): Constant;
static of(value: Record<string, any>): Constant;

/**
* Creates a `Constant` instance for a VectorValue value.
Expand Down
111 changes: 111 additions & 0 deletions packages/firestore/test/integration/api/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';

import { Bytes, vector } from '../../../src/api';
import { GeoPoint } from '../../../src/lite-api/geo_point';
import { Timestamp } from '../../../src/lite-api/timestamp';
import { addEqualityMatcher } from '../../util/equality_matcher';
import { Deferred } from '../../util/promise';
import {
Expand Down Expand Up @@ -476,6 +479,114 @@ apiDescribe('Pipelines', persistence => {
);
});

it('accepts and returns all data types', async () => {
const refDate = new Date();
const refTimestamp = Timestamp.now();
const constants = [
Constant.of(1).as('number'),
Constant.of('a string').as('string'),
Constant.of(true).as('boolean'),
Constant.of(null).as('null'),
Constant.of(new GeoPoint(0.1, 0.2)).as('geoPoint'),
Constant.of(refTimestamp).as('timestamp'),
Constant.of(refDate).as('date'),
Constant.of(
Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0]))
).as('bytes'),
Constant.of(doc(firestore, 'foo', 'bar')).as('documentReference'),
Constant.of(vector([1, 2, 3])).as('vectorValue'),
Constant.of({
'number': 1,
'string': 'a string',
'boolean': true,
'null': null,
'geoPoint': new GeoPoint(0.1, 0.2),
'timestamp': refTimestamp,
'date': refDate,
'uint8Array': Bytes.fromUint8Array(
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])
),
'documentReference': doc(firestore, 'foo', 'bar'),
'vectorValue': vector([1, 2, 3]),
'map': {
'number': 2,
'string': 'b string'
},
'array': [1, 'c string']
}).as('map'),
Constant.of([
1,
'a string',
true,
null,
new GeoPoint(0.1, 0.2),
refTimestamp,
refDate,
Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])),
doc(firestore, 'foo', 'bar'),
vector([1, 2, 3]),
{
'number': 2,
'string': 'b string'
}
]).as('array')
];

const results = await randomCol
.pipeline()
.limit(1)
.select(...constants)
.execute();

expectResults(results, {
'number': 1,
'string': 'a string',
'boolean': true,
'null': null,
'geoPoint': new GeoPoint(0.1, 0.2),
'timestamp': refTimestamp,
'date': Timestamp.fromDate(refDate),
'bytes': Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])),
'documentReference': doc(firestore, 'foo', 'bar'),
'vectorValue': vector([1, 2, 3]),
'map': {
'number': 1,
'string': 'a string',
'boolean': true,
'null': null,
'geoPoint': new GeoPoint(0.1, 0.2),
'timestamp': refTimestamp,
'date': Timestamp.fromDate(refDate),
'uint8Array': Bytes.fromUint8Array(
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])
),
'documentReference': doc(firestore, 'foo', 'bar'),
'vectorValue': vector([1, 2, 3]),
'map': {
'number': 2,
'string': 'b string'
},
'array': [1, 'c string']
},
'array': [
1,
'a string',
true,
null,
new GeoPoint(0.1, 0.2),
refTimestamp,
Timestamp.fromDate(refDate),
Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])),
doc(firestore, 'foo', 'bar'),
vector([1, 2, 3]),
{
'number': 2,
'string': 'b string'
}
]
});
});

it('cond works', async () => {
const results = await randomCol
.pipeline()
Expand Down