Skip to content

Commit 011ac37

Browse files
committed
Merge branch 'ddb-firestore-result-serialization' into ddb-sync-bundle-parse
2 parents 95b69f6 + c211ea2 commit 011ac37

25 files changed

+1054
-22
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ export function average(field: string | FieldPath): AggregateField<number | null
6868
// @public
6969
export class Bytes {
7070
static fromBase64String(base64: string): Bytes;
71+
static fromJSON(json: object): Bytes;
7172
static fromUint8Array(array: Uint8Array): Bytes;
7273
isEqual(other: Bytes): boolean;
7374
toBase64(): string;
75+
toJSON(): object;
7476
toString(): string;
7577
toUint8Array(): Uint8Array;
7678
}
@@ -135,9 +137,11 @@ export function documentId(): FieldPath;
135137
export class DocumentReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> {
136138
readonly converter: FirestoreDataConverter<AppModelType, DbModelType> | null;
137139
readonly firestore: Firestore;
140+
static fromJSON<NewAppModelType = DocumentData, NewDbModelType extends DocumentData = DocumentData>(firestore: Firestore, json: object, converter?: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
138141
get id(): string;
139142
get parent(): CollectionReference<AppModelType, DbModelType>;
140143
get path(): string;
144+
toJSON(): object;
141145
readonly type = "document";
142146
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
143147
withConverter(converter: null): DocumentReference<DocumentData, DocumentData>;
@@ -205,12 +209,14 @@ export type FirestoreErrorCode = 'cancelled' | 'unknown' | 'invalid-argument' |
205209
// @public
206210
export class GeoPoint {
207211
constructor(latitude: number, longitude: number);
212+
static fromJSON(json: object): GeoPoint;
208213
isEqual(other: GeoPoint): boolean;
209214
get latitude(): number;
210215
get longitude(): number;
211216
toJSON(): {
212217
latitude: number;
213218
longitude: number;
219+
type: string;
214220
};
215221
}
216222

@@ -416,6 +422,7 @@ export class Timestamp {
416422
seconds: number,
417423
nanoseconds: number);
418424
static fromDate(date: Date): Timestamp;
425+
static fromJSON(json: object): Timestamp;
419426
static fromMillis(milliseconds: number): Timestamp;
420427
isEqual(other: Timestamp): boolean;
421428
readonly nanoseconds: number;
@@ -425,6 +432,7 @@ export class Timestamp {
425432
toJSON(): {
426433
seconds: number;
427434
nanoseconds: number;
435+
type: string;
428436
};
429437
toMillis(): number;
430438
toString(): string;
@@ -466,8 +474,10 @@ export function vector(values?: number[]): VectorValue;
466474
// @public
467475
export class VectorValue {
468476
/* Excluded from this release type: __constructor */
477+
static fromJSON(json: object): VectorValue;
469478
isEqual(other: VectorValue): boolean;
470479
toArray(): number[];
480+
toJSON(): object;
471481
}
472482

473483
// @public

common/api-review/firestore.api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ export function average(field: string | FieldPath): AggregateField<number | null
6868
// @public
6969
export class Bytes {
7070
static fromBase64String(base64: string): Bytes;
71+
static fromJSON(json: object): Bytes;
7172
static fromUint8Array(array: Uint8Array): Bytes;
7273
isEqual(other: Bytes): boolean;
7374
toBase64(): string;
75+
toJSON(): object;
7476
toString(): string;
7577
toUint8Array(): Uint8Array;
7678
}
@@ -161,9 +163,11 @@ export function documentId(): FieldPath;
161163
export class DocumentReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> {
162164
readonly converter: FirestoreDataConverter<AppModelType, DbModelType> | null;
163165
readonly firestore: Firestore;
166+
static fromJSON<NewAppModelType = DocumentData, NewDbModelType extends DocumentData = DocumentData>(firestore: Firestore, json: object, converter?: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
164167
get id(): string;
165168
get parent(): CollectionReference<AppModelType, DbModelType>;
166169
get path(): string;
170+
toJSON(): object;
167171
readonly type = "document";
168172
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
169173
withConverter(converter: null): DocumentReference<DocumentData, DocumentData>;
@@ -266,12 +270,14 @@ export interface FirestoreSettings {
266270
// @public
267271
export class GeoPoint {
268272
constructor(latitude: number, longitude: number);
273+
static fromJSON(json: object): GeoPoint;
269274
isEqual(other: GeoPoint): boolean;
270275
get latitude(): number;
271276
get longitude(): number;
272277
toJSON(): {
273278
latitude: number;
274279
longitude: number;
280+
type: string;
275281
};
276282
}
277283

@@ -740,6 +746,7 @@ export class Timestamp {
740746
seconds: number,
741747
nanoseconds: number);
742748
static fromDate(date: Date): Timestamp;
749+
static fromJSON(json: object): Timestamp;
743750
static fromMillis(milliseconds: number): Timestamp;
744751
isEqual(other: Timestamp): boolean;
745752
readonly nanoseconds: number;
@@ -749,6 +756,7 @@ export class Timestamp {
749756
toJSON(): {
750757
seconds: number;
751758
nanoseconds: number;
759+
type: string;
752760
};
753761
toMillis(): number;
754762
toString(): string;
@@ -795,8 +803,10 @@ export function vector(values?: number[]): VectorValue;
795803
// @public
796804
export class VectorValue {
797805
/* Excluded from this release type: __constructor */
806+
static fromJSON(json: object): VectorValue;
798807
isEqual(other: VectorValue): boolean;
799808
toArray(): number[];
809+
toJSON(): object;
800810
}
801811

802812
// @public

docs-devsite/firestore_.bytes.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ export declare class Bytes
2323
| Method | Modifiers | Description |
2424
| --- | --- | --- |
2525
| [fromBase64String(base64)](./firestore_.bytes.md#bytesfrombase64string) | <code>static</code> | Creates a new <code>Bytes</code> object from the given Base64 string, converting it to bytes. |
26+
| [fromJSON(json)](./firestore_.bytes.md#bytesfromjson) | <code>static</code> | Builds a <code>Byes</code> instance from a JSON object created by [Bytes.toJSON()](./firestore_.bytes.md#bytestojson)<!-- -->. |
2627
| [fromUint8Array(array)](./firestore_.bytes.md#bytesfromuint8array) | <code>static</code> | Creates a new <code>Bytes</code> object from the given Uint8Array. |
2728
| [isEqual(other)](./firestore_.bytes.md#bytesisequal) | | Returns true if this <code>Bytes</code> object is equal to the provided one. |
2829
| [toBase64()](./firestore_.bytes.md#bytestobase64) | | Returns the underlying bytes as a Base64-encoded string. |
30+
| [toJSON()](./firestore_.bytes.md#bytestojson) | | Returns a JSON-serializable representation of this <code>Bytes</code> instance. |
2931
| [toString()](./firestore_.bytes.md#bytestostring) | | Returns a string representation of the <code>Bytes</code> object. |
3032
| [toUint8Array()](./firestore_.bytes.md#bytestouint8array) | | Returns the underlying bytes in a new <code>Uint8Array</code>. |
3133

@@ -49,6 +51,28 @@ static fromBase64String(base64: string): Bytes;
4951

5052
[Bytes](./firestore_.bytes.md#bytes_class)
5153

54+
## Bytes.fromJSON()
55+
56+
Builds a `Byes` instance from a JSON object created by [Bytes.toJSON()](./firestore_.bytes.md#bytestojson)<!-- -->.
57+
58+
<b>Signature:</b>
59+
60+
```typescript
61+
static fromJSON(json: object): Bytes;
62+
```
63+
64+
#### Parameters
65+
66+
| Parameter | Type | Description |
67+
| --- | --- | --- |
68+
| json | object | a JSON object represention of a <code>Bytes</code> instance |
69+
70+
<b>Returns:</b>
71+
72+
[Bytes](./firestore_.bytes.md#bytes_class)
73+
74+
an instance of [Bytes](./firestore_.bytes.md#bytes_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
75+
5276
## Bytes.fromUint8Array()
5377

5478
Creates a new `Bytes` object from the given Uint8Array.
@@ -106,6 +130,21 @@ string
106130

107131
The Base64-encoded string created from the `Bytes` object.
108132

133+
## Bytes.toJSON()
134+
135+
Returns a JSON-serializable representation of this `Bytes` instance.
136+
137+
<b>Signature:</b>
138+
139+
```typescript
140+
toJSON(): object;
141+
```
142+
<b>Returns:</b>
143+
144+
object
145+
146+
a JSON representation of this object.
147+
109148
## Bytes.toString()
110149

111150
Returns a string representation of the `Bytes` object.

docs-devsite/firestore_.documentreference.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export declare class DocumentReference<AppModelType = DocumentData, DbModelType
3333

3434
| Method | Modifiers | Description |
3535
| --- | --- | --- |
36+
| [fromJSON(firestore, json, converter)](./firestore_.documentreference.md#documentreferencefromjson) | <code>static</code> | Builds a <code>DocumentReference</code> instance from a JSON object created by [DocumentReference.toJSON()](./firestore_.documentreference.md#documentreferencetojson)<!-- -->. |
37+
| [toJSON()](./firestore_.documentreference.md#documentreferencetojson) | | Returns a JSON-serializable representation of this <code>DocumentReference</code> instance. |
3638
| [withConverter(converter)](./firestore_.documentreference.md#documentreferencewithconverter) | | Applies a custom data converter to this <code>DocumentReference</code>, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc_ee215ad)<!-- -->, [getDoc()](./firestore_lite.md#getdoc_4569087)<!-- -->, etc. with the returned <code>DocumentReference</code> instance, the provided converter will convert between Firestore data of type <code>NewDbModelType</code> and your custom type <code>NewAppModelType</code>. |
3739
| [withConverter(converter)](./firestore_.documentreference.md#documentreferencewithconverter) | | Removes the current converter. |
3840

@@ -96,6 +98,45 @@ The type of this Firestore reference.
9698
readonly type = "document";
9799
```
98100

101+
## DocumentReference.fromJSON()
102+
103+
Builds a `DocumentReference` instance from a JSON object created by [DocumentReference.toJSON()](./firestore_.documentreference.md#documentreferencetojson)<!-- -->.
104+
105+
<b>Signature:</b>
106+
107+
```typescript
108+
static fromJSON<NewAppModelType = DocumentData, NewDbModelType extends DocumentData = DocumentData>(firestore: Firestore, json: object, converter?: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
109+
```
110+
111+
#### Parameters
112+
113+
| Parameter | Type | Description |
114+
| --- | --- | --- |
115+
| firestore | [Firestore](./firestore_.firestore.md#firestore_class) | |
116+
| json | object | a JSON object represention of a <code>DocumentReference</code> instance |
117+
| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<!-- -->&lt;NewAppModelType, NewDbModelType&gt; | |
118+
119+
<b>Returns:</b>
120+
121+
[DocumentReference](./firestore_.documentreference.md#documentreference_class)<!-- -->&lt;NewAppModelType, NewDbModelType&gt;
122+
123+
an instance of [DocumentReference](./firestore_.documentreference.md#documentreference_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
124+
125+
## DocumentReference.toJSON()
126+
127+
Returns a JSON-serializable representation of this `DocumentReference` instance.
128+
129+
<b>Signature:</b>
130+
131+
```typescript
132+
toJSON(): object;
133+
```
134+
<b>Returns:</b>
135+
136+
object
137+
138+
a JSON representation of this object.
139+
99140
## DocumentReference.withConverter()
100141

101142
Applies a custom data converter to this `DocumentReference`<!-- -->, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc_ee215ad)<!-- -->, [getDoc()](./firestore_lite.md#getdoc_4569087)<!-- -->, etc. with the returned `DocumentReference` instance, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`<!-- -->.

docs-devsite/firestore_.geopoint.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ export declare class GeoPoint
3737

3838
| Method | Modifiers | Description |
3939
| --- | --- | --- |
40+
| [fromJSON(json)](./firestore_.geopoint.md#geopointfromjson) | <code>static</code> | Builds a <code>GeoPoint</code> instance from a JSON object created by [GeoPoint.toJSON()](./firestore_.geopoint.md#geopointtojson)<!-- -->. |
4041
| [isEqual(other)](./firestore_.geopoint.md#geopointisequal) | | Returns true if this <code>GeoPoint</code> is equal to the provided one. |
41-
| [toJSON()](./firestore_.geopoint.md#geopointtojson) | | Returns a JSON-serializable representation of this GeoPoint. |
42+
| [toJSON()](./firestore_.geopoint.md#geopointtojson) | | Returns a JSON-serializable representation of this <code>GeoPoint</code> instance. |
4243

4344
## GeoPoint.(constructor)
4445

@@ -77,6 +78,28 @@ The longitude of this `GeoPoint` instance.
7778
get longitude(): number;
7879
```
7980

81+
## GeoPoint.fromJSON()
82+
83+
Builds a `GeoPoint` instance from a JSON object created by [GeoPoint.toJSON()](./firestore_.geopoint.md#geopointtojson)<!-- -->.
84+
85+
<b>Signature:</b>
86+
87+
```typescript
88+
static fromJSON(json: object): GeoPoint;
89+
```
90+
91+
#### Parameters
92+
93+
| Parameter | Type | Description |
94+
| --- | --- | --- |
95+
| json | object | a JSON object represention of a <code>GeoPoint</code> instance |
96+
97+
<b>Returns:</b>
98+
99+
[GeoPoint](./firestore_.geopoint.md#geopoint_class)
100+
101+
an instance of [GeoPoint](./firestore_.geopoint.md#geopoint_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
102+
80103
## GeoPoint.isEqual()
81104

82105
Returns true if this `GeoPoint` is equal to the provided one.
@@ -101,17 +124,20 @@ true if this `GeoPoint` is equal to the provided one.
101124

102125
## GeoPoint.toJSON()
103126

104-
Returns a JSON-serializable representation of this GeoPoint.
127+
Returns a JSON-serializable representation of this `GeoPoint` instance.
105128

106129
<b>Signature:</b>
107130

108131
```typescript
109132
toJSON(): {
110133
latitude: number;
111134
longitude: number;
135+
type: string;
112136
};
113137
```
114138
<b>Returns:</b>
115139

116-
{ latitude: number; longitude: number; }
140+
{ latitude: number; longitude: number; type: string; }
141+
142+
a JSON representation of this object.
117143

docs-devsite/firestore_.timestamp.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export declare class Timestamp
4040
| Method | Modifiers | Description |
4141
| --- | --- | --- |
4242
| [fromDate(date)](./firestore_.timestamp.md#timestampfromdate) | <code>static</code> | Creates a new timestamp from the given date. |
43+
| [fromJSON(json)](./firestore_.timestamp.md#timestampfromjson) | <code>static</code> | Builds a <code>Timestamp</code> instance from a JSON serialized version of <code>Bytes</code>. |
4344
| [fromMillis(milliseconds)](./firestore_.timestamp.md#timestampfrommillis) | <code>static</code> | Creates a new timestamp from the given number of milliseconds. |
4445
| [isEqual(other)](./firestore_.timestamp.md#timestampisequal) | | Returns true if this <code>Timestamp</code> is equal to the provided one. |
4546
| [now()](./firestore_.timestamp.md#timestampnow) | <code>static</code> | Creates a new timestamp with the current date, with millisecond precision. |
@@ -110,6 +111,26 @@ static fromDate(date: Date): Timestamp;
110111

111112
A new `Timestamp` representing the same point in time as the given date.
112113

114+
## Timestamp.fromJSON()
115+
116+
Builds a `Timestamp` instance from a JSON serialized version of `Bytes`<!-- -->.
117+
118+
<b>Signature:</b>
119+
120+
```typescript
121+
static fromJSON(json: object): Timestamp;
122+
```
123+
124+
#### Parameters
125+
126+
| Parameter | Type | Description |
127+
| --- | --- | --- |
128+
| json | object | |
129+
130+
<b>Returns:</b>
131+
132+
[Timestamp](./firestore_.timestamp.md#timestamp_class)
133+
113134
## Timestamp.fromMillis()
114135

115136
Creates a new timestamp from the given number of milliseconds.
@@ -194,11 +215,12 @@ Returns a JSON-serializable representation of this `Timestamp`<!-- -->.
194215
toJSON(): {
195216
seconds: number;
196217
nanoseconds: number;
218+
type: string;
197219
};
198220
```
199221
<b>Returns:</b>
200222

201-
{ seconds: number; nanoseconds: number; }
223+
{ seconds: number; nanoseconds: number; type: string; }
202224

203225
## Timestamp.toMillis()
204226

0 commit comments

Comments
 (0)