Skip to content

Commit d437b8e

Browse files
committed
Merge branch 'feat/pipelines' of github.com:firebase/firebase-js-sdk into markduckworth/ppl-mep
2 parents d2291d0 + df90a2e commit d437b8e

File tree

2 files changed

+121
-4
lines changed

2 files changed

+121
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import { hardAssert } from '../util/assert';
3232
import { isFirestoreValue } from '../util/proto';
3333

34+
import { Bytes } from './bytes';
3435
import { documentId, FieldPath } from './field_path';
3536
import { GeoPoint } from './geo_point';
3637
import { Pipeline } from './pipeline';
@@ -2073,6 +2074,8 @@ export class Constant extends Expr {
20732074

20742075
/**
20752076
* Creates a `Constant` instance for an undefined value.
2077+
* @private
2078+
* @internal
20762079
*
20772080
* @param value The undefined value.
20782081
* @return A new `Constant` instance.
@@ -2104,12 +2107,12 @@ export class Constant extends Expr {
21042107
static of(value: Date): Constant;
21052108

21062109
/**
2107-
* Creates a `Constant` instance for a Uint8Array value.
2110+
* Creates a `Constant` instance for a Bytes value.
21082111
*
2109-
* @param value The Uint8Array value.
2112+
* @param value The Bytes value.
21102113
* @return A new `Constant` instance.
21112114
*/
2112-
static of(value: Uint8Array): Constant;
2115+
static of(value: Bytes): Constant;
21132116

21142117
/**
21152118
* Creates a `Constant` instance for a DocumentReference value.
@@ -2121,6 +2124,7 @@ export class Constant extends Expr {
21212124

21222125
/**
21232126
* Creates a `Constant` instance for a Firestore proto value.
2127+
* For internal use only.
21242128
* @private
21252129
* @internal
21262130
* @param value The Firestore proto value.
@@ -2142,7 +2146,7 @@ export class Constant extends Expr {
21422146
* @param value The map value.
21432147
* @return A new `Constant` instance.
21442148
*/
2145-
static of(value: Map<string, any>): Constant;
2149+
static of(value: Record<string, any>): Constant;
21462150

21472151
/**
21482152
* Creates a `Constant` instance for a VectorValue value.

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

Lines changed: 113 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,116 @@ apiDescribe.only('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(
550+
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])
551+
),
552+
'documentReference': doc(firestore, 'foo', 'bar'),
553+
'vectorValue': vector([1, 2, 3]),
554+
'map': {
555+
'number': 1,
556+
'string': 'a string',
557+
'boolean': true,
558+
'null': null,
559+
'geoPoint': new GeoPoint(0.1, 0.2),
560+
'timestamp': refTimestamp,
561+
'date': Timestamp.fromDate(refDate),
562+
'uint8Array': Bytes.fromUint8Array(
563+
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])
564+
),
565+
'documentReference': doc(firestore, 'foo', 'bar'),
566+
'vectorValue': vector([1, 2, 3]),
567+
'map': {
568+
'number': 2,
569+
'string': 'b string'
570+
},
571+
'array': [1, 'c string']
572+
},
573+
'array': [
574+
1,
575+
'a string',
576+
true,
577+
null,
578+
new GeoPoint(0.1, 0.2),
579+
refTimestamp,
580+
Timestamp.fromDate(refDate),
581+
Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])),
582+
doc(firestore, 'foo', 'bar'),
583+
vector([1, 2, 3]),
584+
{
585+
'number': 2,
586+
'string': 'b string'
587+
}
588+
]
589+
});
590+
});
591+
479592
it('cond works', async () => {
480593
const results = await randomCol
481594
.pipeline()

0 commit comments

Comments
 (0)