Skip to content

Commit df90a2e

Browse files
Fixes for Constant.of(...) (#8677)
1 parent a9a0b82 commit df90a2e

File tree

4 files changed

+129
-17
lines changed

4 files changed

+129
-17
lines changed

common/api-review/firestore-lite.api.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,13 @@ export class Constant {
375375
static of(value: string): Constant;
376376
static of(value: boolean): Constant;
377377
static of(value: null): Constant;
378-
static of(value: undefined): Constant;
379378
static of(value: GeoPoint): Constant;
380379
static of(value: Timestamp): Constant;
381380
static of(value: Date): Constant;
382-
static of(value: Uint8Array): Constant;
381+
static of(value: Bytes): Constant;
383382
static of(value: DocumentReference): Constant;
384383
static of(value: any[]): Constant;
385-
static of(value: Map<string, any>): Constant;
384+
static of(value: Record<string, any>): Constant;
386385
static of(value: VectorValue): Constant;
387386
regexContains(pattern: string): RegexContains;
388387
regexContains(pattern: Constant): RegexContains;
@@ -2205,8 +2204,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;
22052204

22062205
// Warnings were encountered during analysis:
22072206
//
2208-
// /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
2209-
// /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
2210-
// /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
2207+
// /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
2208+
// /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
2209+
// /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
22112210

22122211
```

common/api-review/firestore.api.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,13 @@ export class Constant {
390390
static of(value: string): Constant;
391391
static of(value: boolean): Constant;
392392
static of(value: null): Constant;
393-
static of(value: undefined): Constant;
394393
static of(value: GeoPoint): Constant;
395394
static of(value: Timestamp): Constant;
396395
static of(value: Date): Constant;
397-
static of(value: Uint8Array): Constant;
396+
static of(value: Bytes): Constant;
398397
static of(value: DocumentReference): Constant;
399398
static of(value: any[]): Constant;
400-
static of(value: Map<string, any>): Constant;
399+
static of(value: Record<string, any>): Constant;
401400
static of(value: VectorValue): Constant;
402401
regexContains(pattern: string): RegexContains;
403402
regexContains(pattern: Constant): RegexContains;
@@ -2509,8 +2508,8 @@ export function xor(left: FilterExpr, ...right: FilterExpr[]): Xor;
25092508

25102509
// Warnings were encountered during analysis:
25112510
//
2512-
// /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
2513-
// /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
2514-
// /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
2511+
// /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
2512+
// /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
2513+
// /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
25152514

25162515
```

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from '../remote/serializer';
3131
import { hardAssert } from '../util/assert';
3232

33+
import { Bytes } from './bytes';
3334
import { documentId, FieldPath } from './field_path';
3435
import { GeoPoint } from './geo_point';
3536
import { Pipeline } from './pipeline';
@@ -2084,6 +2085,8 @@ export class Constant extends Expr {
20842085

20852086
/**
20862087
* Creates a `Constant` instance for an undefined value.
2088+
* @private
2089+
* @internal
20872090
*
20882091
* @param value The undefined value.
20892092
* @return A new `Constant` instance.
@@ -2115,12 +2118,12 @@ export class Constant extends Expr {
21152118
static of(value: Date): Constant;
21162119

21172120
/**
2118-
* Creates a `Constant` instance for a Uint8Array value.
2121+
* Creates a `Constant` instance for a Bytes value.
21192122
*
2120-
* @param value The Uint8Array value.
2123+
* @param value The Bytes value.
21212124
* @return A new `Constant` instance.
21222125
*/
2123-
static of(value: Uint8Array): Constant;
2126+
static of(value: Bytes): Constant;
21242127

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

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

21592162
/**
21602163
* Creates a `Constant` instance for a VectorValue value.

packages/firestore/test/integration/api/pipeline.test.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import { expect, use } from 'chai';
1919
import chaiAsPromised from 'chai-as-promised';
2020

21+
import { Bytes, vector } from '../../../src/api';
22+
import { GeoPoint } from '../../../src/lite-api/geo_point';
23+
import { Timestamp } from '../../../src/lite-api/timestamp';
2124
import { addEqualityMatcher } from '../../util/equality_matcher';
2225
import { Deferred } from '../../util/promise';
2326
import {
@@ -476,6 +479,114 @@ apiDescribe('Pipelines', persistence => {
476479
);
477480
});
478481

482+
it('accepts and returns all data types', async () => {
483+
const refDate = new Date();
484+
const refTimestamp = Timestamp.now();
485+
const constants = [
486+
Constant.of(1).as('number'),
487+
Constant.of('a string').as('string'),
488+
Constant.of(true).as('boolean'),
489+
Constant.of(null).as('null'),
490+
Constant.of(new GeoPoint(0.1, 0.2)).as('geoPoint'),
491+
Constant.of(refTimestamp).as('timestamp'),
492+
Constant.of(refDate).as('date'),
493+
Constant.of(
494+
Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0]))
495+
).as('bytes'),
496+
Constant.of(doc(firestore, 'foo', 'bar')).as('documentReference'),
497+
Constant.of(vector([1, 2, 3])).as('vectorValue'),
498+
Constant.of({
499+
'number': 1,
500+
'string': 'a string',
501+
'boolean': true,
502+
'null': null,
503+
'geoPoint': new GeoPoint(0.1, 0.2),
504+
'timestamp': refTimestamp,
505+
'date': refDate,
506+
'uint8Array': Bytes.fromUint8Array(
507+
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])
508+
),
509+
'documentReference': doc(firestore, 'foo', 'bar'),
510+
'vectorValue': vector([1, 2, 3]),
511+
'map': {
512+
'number': 2,
513+
'string': 'b string'
514+
},
515+
'array': [1, 'c string']
516+
}).as('map'),
517+
Constant.of([
518+
1,
519+
'a string',
520+
true,
521+
null,
522+
new GeoPoint(0.1, 0.2),
523+
refTimestamp,
524+
refDate,
525+
Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])),
526+
doc(firestore, 'foo', 'bar'),
527+
vector([1, 2, 3]),
528+
{
529+
'number': 2,
530+
'string': 'b string'
531+
}
532+
]).as('array')
533+
];
534+
535+
const results = await randomCol
536+
.pipeline()
537+
.limit(1)
538+
.select(...constants)
539+
.execute();
540+
541+
expectResults(results, {
542+
'number': 1,
543+
'string': 'a string',
544+
'boolean': true,
545+
'null': null,
546+
'geoPoint': new GeoPoint(0.1, 0.2),
547+
'timestamp': refTimestamp,
548+
'date': Timestamp.fromDate(refDate),
549+
'bytes': Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])),
550+
'documentReference': doc(firestore, 'foo', 'bar'),
551+
'vectorValue': vector([1, 2, 3]),
552+
'map': {
553+
'number': 1,
554+
'string': 'a string',
555+
'boolean': true,
556+
'null': null,
557+
'geoPoint': new GeoPoint(0.1, 0.2),
558+
'timestamp': refTimestamp,
559+
'date': Timestamp.fromDate(refDate),
560+
'uint8Array': Bytes.fromUint8Array(
561+
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])
562+
),
563+
'documentReference': doc(firestore, 'foo', 'bar'),
564+
'vectorValue': vector([1, 2, 3]),
565+
'map': {
566+
'number': 2,
567+
'string': 'b string'
568+
},
569+
'array': [1, 'c string']
570+
},
571+
'array': [
572+
1,
573+
'a string',
574+
true,
575+
null,
576+
new GeoPoint(0.1, 0.2),
577+
refTimestamp,
578+
Timestamp.fromDate(refDate),
579+
Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])),
580+
doc(firestore, 'foo', 'bar'),
581+
vector([1, 2, 3]),
582+
{
583+
'number': 2,
584+
'string': 'b string'
585+
}
586+
]
587+
});
588+
});
589+
479590
it('cond works', async () => {
480591
const results = await randomCol
481592
.pipeline()

0 commit comments

Comments
 (0)