17
17
18
18
import * as firestore from '@firebase/firestore-types' ;
19
19
20
+ import * as api from '../protos/firestore_proto_api' ;
21
+
20
22
import { FirebaseApp } from '@firebase/app-types' ;
21
- import { FirebaseService , _FirebaseApp } from '@firebase/app-types/private' ;
23
+ import { _FirebaseApp , FirebaseService } from '@firebase/app-types/private' ;
22
24
import { DatabaseId , DatabaseInfo } from '../core/database_info' ;
23
25
import { ListenOptions } from '../core/event_manager' ;
24
26
import { FirestoreClient , PersistenceSettings } from '../core/firestore_client' ;
@@ -38,14 +40,11 @@ import { MemoryPersistenceProvider } from '../local/memory_persistence';
38
40
import { PersistenceProvider } from '../local/persistence' ;
39
41
import { Document , MaybeDocument , NoDocument } from '../model/document' ;
40
42
import { DocumentKey } from '../model/document_key' ;
41
- import {
42
- ArrayValue ,
43
- FieldValue ,
44
- RefValue ,
45
- ServerTimestampValue
46
- } from '../model/field_value' ;
47
43
import { DeleteMutation , Mutation , Precondition } from '../model/mutation' ;
48
44
import { FieldPath , ResourcePath } from '../model/path' ;
45
+ import { JsonProtoSerializer } from '../remote/serializer' ;
46
+ import { isServerTimestamp } from '../model/server_timestamps' ;
47
+ import { refValue } from '../model/values' ;
49
48
import { PlatformSupport } from '../platform/platform' ;
50
49
import { makeConstructorPrivate } from '../util/api' ;
51
50
import { assert , fail } from '../util/assert' ;
@@ -555,7 +554,10 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
555
554
return value ;
556
555
}
557
556
} ;
558
- return new UserDataReader ( preConverter ) ;
557
+ const serializer = new JsonProtoSerializer ( databaseId , {
558
+ useProto3Json : PlatformSupport . getPlatform ( ) . useProto3Json
559
+ } ) ;
560
+ return new UserDataReader ( serializer , preConverter ) ;
559
561
}
560
562
561
563
private static databaseIdFromApp ( app : FirebaseApp ) : DatabaseId {
@@ -1390,7 +1392,7 @@ export class DocumentSnapshot<T = firestore.DocumentData>
1390
1392
options . serverTimestamps ,
1391
1393
/* converter= */ undefined
1392
1394
) ;
1393
- return userDataWriter . convertValue ( this . _document . data ( ) ) as T ;
1395
+ return userDataWriter . convertValue ( this . _document . toProto ( ) ) as T ;
1394
1396
}
1395
1397
}
1396
1398
}
@@ -1495,7 +1497,7 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
1495
1497
] ;
1496
1498
validateStringEnum ( 'Query.where' , whereFilterOpEnums , 2 , opStr ) ;
1497
1499
1498
- let fieldValue : FieldValue ;
1500
+ let fieldValue : api . Value ;
1499
1501
const fieldPath = fieldPathFromArgument ( 'Query.where' , field ) ;
1500
1502
const operator = Operator . fromString ( opStr ) ;
1501
1503
if ( fieldPath . isKeyField ( ) ) {
@@ -1510,11 +1512,11 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
1510
1512
) ;
1511
1513
} else if ( operator === Operator . IN ) {
1512
1514
this . validateDisjunctiveFilterElements ( value , operator ) ;
1513
- const referenceList : FieldValue [ ] = [ ] ;
1514
- for ( const arrayValue of value as FieldValue [ ] ) {
1515
+ const referenceList : api . Value [ ] = [ ] ;
1516
+ for ( const arrayValue of value as api . Value [ ] ) {
1515
1517
referenceList . push ( this . parseDocumentIdValue ( arrayValue ) ) ;
1516
1518
}
1517
- fieldValue = new ArrayValue ( referenceList ) ;
1519
+ fieldValue = { arrayValue : { values : referenceList } } ;
1518
1520
} else {
1519
1521
fieldValue = this . parseDocumentIdValue ( value ) ;
1520
1522
}
@@ -1720,7 +1722,7 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
1720
1722
`${ methodName } ().`
1721
1723
) ;
1722
1724
}
1723
- return this . boundFromDocument ( methodName , snap . _document ! , before ) ;
1725
+ return this . boundFromDocument ( snap . _document ! , before ) ;
1724
1726
} else {
1725
1727
const allFields = [ docOrField ] . concat ( fields ) ;
1726
1728
return this . boundFromFields ( methodName , allFields , before ) ;
@@ -1738,12 +1740,8 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
1738
1740
* of the query or if any of the fields in the order by are an uncommitted
1739
1741
* server timestamp.
1740
1742
*/
1741
- private boundFromDocument (
1742
- methodName : string ,
1743
- doc : Document ,
1744
- before : boolean
1745
- ) : Bound {
1746
- const components : FieldValue [ ] = [ ] ;
1743
+ private boundFromDocument ( doc : Document , before : boolean ) : Bound {
1744
+ const components : api . Value [ ] = [ ] ;
1747
1745
1748
1746
// Because people expect to continue/end a query at the exact document
1749
1747
// provided, we need to use the implicit sort order rather than the explicit
@@ -1754,10 +1752,10 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
1754
1752
// results.
1755
1753
for ( const orderBy of this . _query . orderBy ) {
1756
1754
if ( orderBy . field . isKeyField ( ) ) {
1757
- components . push ( new RefValue ( this . firestore . _databaseId , doc . key ) ) ;
1755
+ components . push ( refValue ( this . firestore . _databaseId , doc . key ) ) ;
1758
1756
} else {
1759
1757
const value = doc . field ( orderBy . field ) ;
1760
- if ( value instanceof ServerTimestampValue ) {
1758
+ if ( isServerTimestamp ( value ) ) {
1761
1759
throw new FirestoreError (
1762
1760
Code . INVALID_ARGUMENT ,
1763
1761
'Invalid query. You are trying to start or end a query using a ' +
@@ -1801,7 +1799,7 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
1801
1799
) ;
1802
1800
}
1803
1801
1804
- const components : FieldValue [ ] = [ ] ;
1802
+ const components : api . Value [ ] = [ ] ;
1805
1803
for ( let i = 0 ; i < values . length ; i ++ ) {
1806
1804
const rawValue = values [ i ] ;
1807
1805
const orderByComponent = orderBy [ i ] ;
@@ -1835,7 +1833,7 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
1835
1833
) ;
1836
1834
}
1837
1835
const key = new DocumentKey ( path ) ;
1838
- components . push ( new RefValue ( this . firestore . _databaseId , key ) ) ;
1836
+ components . push ( refValue ( this . firestore . _databaseId , key ) ) ;
1839
1837
} else {
1840
1838
const wrapped = this . firestore . _dataReader . parseQueryValue (
1841
1839
methodName ,
@@ -2034,7 +2032,7 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
2034
2032
* appropriate errors if the value is anything other than a DocumentReference
2035
2033
* or String, or if the string is malformed.
2036
2034
*/
2037
- private parseDocumentIdValue ( documentIdValue : unknown ) : RefValue {
2035
+ private parseDocumentIdValue ( documentIdValue : unknown ) : api . Value {
2038
2036
if ( typeof documentIdValue === 'string' ) {
2039
2037
if ( documentIdValue === '' ) {
2040
2038
throw new FirestoreError (
@@ -2065,10 +2063,10 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
2065
2063
`but '${ path } ' is not because it has an odd number of segments (${ path . length } ).`
2066
2064
) ;
2067
2065
}
2068
- return new RefValue ( this . firestore . _databaseId , new DocumentKey ( path ) ) ;
2066
+ return refValue ( this . firestore . _databaseId , new DocumentKey ( path ) ) ;
2069
2067
} else if ( documentIdValue instanceof DocumentReference ) {
2070
2068
const ref = documentIdValue as DocumentReference < T > ;
2071
- return new RefValue ( this . firestore . _databaseId , ref . _key ) ;
2069
+ return refValue ( this . firestore . _databaseId , ref . _key ) ;
2072
2070
} else {
2073
2071
throw new FirestoreError (
2074
2072
Code . INVALID_ARGUMENT ,
0 commit comments