Skip to content

Commit 41b82e9

Browse files
committed
Squashed commit of the following:
commit 05338d8 Author: DellaBitta <[email protected]> Date: Thu Apr 24 15:58:18 2025 -0400 test fixes commit 28c6da9 Author: DellaBitta <[email protected]> Date: Thu Apr 24 15:39:22 2025 -0400 update vector_value commit 0aa81ce Author: DellaBitta <[email protected]> Date: Thu Apr 24 15:39:11 2025 -0400 update reference commit e20bac9 Author: DellaBitta <[email protected]> Date: Thu Apr 24 15:24:50 2025 -0400 update timestamp commit 05b29c4 Author: DellaBitta <[email protected]> Date: Thu Apr 24 15:24:39 2025 -0400 update geopoint commit 4cf66f2 Author: DellaBitta <[email protected]> Date: Thu Apr 24 15:16:15 2025 -0400 convert DocumentReference to new JSON validator. commit 00a2423 Author: DellaBitta <[email protected]> Date: Thu Apr 24 13:44:27 2025 -0400 format fix. commit 09eb5cf Author: DellaBitta <[email protected]> Date: Thu Apr 24 13:43:13 2025 -0400 Bytes prototype. commit b753f49 Author: DellaBitta <[email protected]> Date: Thu Apr 24 13:26:41 2025 -0400 Linter doesn't like it, but API extractor does commit 775cc69 Author: DellaBitta <[email protected]> Date: Thu Apr 17 13:13:52 2025 -0400 lower case types commit 188c86f Author: DellaBitta <[email protected]> Date: Thu Apr 17 10:41:58 2025 -0400 DocumentReference unit and integration tests commit 44d8045 Author: DellaBitta <[email protected]> Date: Wed Apr 16 20:39:55 2025 -0400 map Timestamp fields to DbTimestamp fields commit f305182 Author: DellaBitta <[email protected]> Date: Wed Apr 16 15:54:23 2025 -0400 DocumentReference impl commit 05a49aa Author: DellaBitta <[email protected]> Date: Wed Apr 16 11:14:00 2025 -0400 Timestamp, GeoPoint, VectorValue commit 1652e8b Author: DellaBitta <[email protected]> Date: Tue Apr 15 17:33:51 2025 -0400 format commit 8a081e1 Author: DellaBitta <[email protected]> Date: Tue Apr 15 17:26:09 2025 -0400 Bytes and VectorValue to/from JSON commit 2a07791 Author: DellaBitta <[email protected]> Date: Tue Apr 15 14:07:25 2025 -0400 Bytes
1 parent 2d01a6d commit 41b82e9

25 files changed

+976
-18
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: 35 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>Bytes</code> instance from a JSON serialized version of <code>Bytes</code>. |
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,26 @@ static fromBase64String(base64: string): Bytes;
4951

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

54+
## Bytes.fromJSON()
55+
56+
Builds a `Bytes` instance from a JSON serialized version of `Bytes`<!-- -->.
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 | |
69+
70+
<b>Returns:</b>
71+
72+
[Bytes](./firestore_.bytes.md#bytes_class)
73+
5274
## Bytes.fromUint8Array()
5375

5476
Creates a new `Bytes` object from the given Uint8Array.
@@ -106,6 +128,19 @@ string
106128

107129
The Base64-encoded string created from the `Bytes` object.
108130

131+
## Bytes.toJSON()
132+
133+
Returns a JSON-serializable representation of this `Bytes` instance.
134+
135+
<b>Signature:</b>
136+
137+
```typescript
138+
toJSON(): object;
139+
```
140+
<b>Returns:</b>
141+
142+
object
143+
109144
## Bytes.toString()
110145

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

docs-devsite/firestore_.documentreference.md

Lines changed: 37 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 serialized version of <code>DocumentReference</code>. |
37+
| [toJSON()](./firestore_.documentreference.md#documentreferencetojson) | | Returns a JSON-serializable representation of this DocumentReference. |
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,41 @@ The type of this Firestore reference.
9698
readonly type = "document";
9799
```
98100

101+
## DocumentReference.fromJSON()
102+
103+
Builds a `DocumentReference` instance from a JSON serialized version of `DocumentReference`<!-- -->.
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 | |
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+
## DocumentReference.toJSON()
124+
125+
Returns a JSON-serializable representation of this DocumentReference.
126+
127+
<b>Signature:</b>
128+
129+
```typescript
130+
toJSON(): object;
131+
```
132+
<b>Returns:</b>
133+
134+
object
135+
99136
## DocumentReference.withConverter()
100137

101138
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: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export declare class GeoPoint
3737

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

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

81+
## GeoPoint.fromJSON()
82+
83+
Builds a `Timestamp` instance from a JSON serialized version of `Bytes`<!-- -->.
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 | |
96+
97+
<b>Returns:</b>
98+
99+
[GeoPoint](./firestore_.geopoint.md#geopoint_class)
100+
80101
## GeoPoint.isEqual()
81102

82103
Returns true if this `GeoPoint` is equal to the provided one.
@@ -109,9 +130,10 @@ Returns a JSON-serializable representation of this GeoPoint.
109130
toJSON(): {
110131
latitude: number;
111132
longitude: number;
133+
type: string;
112134
};
113135
```
114136
<b>Returns:</b>
115137

116-
{ latitude: number; longitude: number; }
138+
{ latitude: number; longitude: number; type: string; }
117139

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

docs-devsite/firestore_.vectorvalue.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,30 @@ export declare class VectorValue
2424

2525
| Method | Modifiers | Description |
2626
| --- | --- | --- |
27+
| [fromJSON(json)](./firestore_.vectorvalue.md#vectorvaluefromjson) | <code>static</code> | Builds a <code>Bytes</code> instance from a JSON serialized version of <code>Bytes</code>. |
2728
| [isEqual(other)](./firestore_.vectorvalue.md#vectorvalueisequal) | | Returns <code>true</code> if the two <code>VectorValue</code> values have the same raw number arrays, returns <code>false</code> otherwise. |
2829
| [toArray()](./firestore_.vectorvalue.md#vectorvaluetoarray) | | Returns a copy of the raw number array form of the vector. |
30+
| [toJSON()](./firestore_.vectorvalue.md#vectorvaluetojson) | | Returns a JSON-serializable representation of this <code>VectorValue</code> instance. |
31+
32+
## VectorValue.fromJSON()
33+
34+
Builds a `Bytes` instance from a JSON serialized version of `Bytes`<!-- -->.
35+
36+
<b>Signature:</b>
37+
38+
```typescript
39+
static fromJSON(json: object): VectorValue;
40+
```
41+
42+
#### Parameters
43+
44+
| Parameter | Type | Description |
45+
| --- | --- | --- |
46+
| json | object | |
47+
48+
<b>Returns:</b>
49+
50+
[VectorValue](./firestore_.vectorvalue.md#vectorvalue_class)
2951

3052
## VectorValue.isEqual()
3153

@@ -60,3 +82,16 @@ toArray(): number[];
6082

6183
number\[\]
6284

85+
## VectorValue.toJSON()
86+
87+
Returns a JSON-serializable representation of this `VectorValue` instance.
88+
89+
<b>Signature:</b>
90+
91+
```typescript
92+
toJSON(): object;
93+
```
94+
<b>Returns:</b>
95+
96+
object
97+

0 commit comments

Comments
 (0)