Skip to content

Commit 96a49f7

Browse files
committed
Move doc / querysnapshot fromJSON to func impl.
1 parent 2840bb3 commit 96a49f7

File tree

8 files changed

+325
-306
lines changed

8 files changed

+325
-306
lines changed

common/api-review/firestore.api.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,19 @@ export class DocumentSnapshot<AppModelType = DocumentData, DbModelType extends D
179179
protected constructor();
180180
data(options?: SnapshotOptions): AppModelType | undefined;
181181
exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;
182-
static fromJSON(db: Firestore, json: object): DocumentSnapshot;
183-
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
184182
get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
185183
get id(): string;
186184
readonly metadata: SnapshotMetadata;
187185
get ref(): DocumentReference<AppModelType, DbModelType>;
188186
toJSON(): object;
189187
}
190188

189+
// @public
190+
export function documentSnapshotFromJSON(db: Firestore, json: object): DocumentSnapshot;
191+
192+
// @public
193+
export function documentSnapshotFromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
194+
191195
export { EmulatorMockTokenOptions }
192196

193197
// @public @deprecated
@@ -657,14 +661,18 @@ export class QuerySnapshot<AppModelType = DocumentData, DbModelType extends Docu
657661
get docs(): Array<QueryDocumentSnapshot<AppModelType, DbModelType>>;
658662
get empty(): boolean;
659663
forEach(callback: (result: QueryDocumentSnapshot<AppModelType, DbModelType>) => void, thisArg?: unknown): void;
660-
static fromJSON(db: Firestore, json: object): QuerySnapshot;
661-
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
662664
readonly metadata: SnapshotMetadata;
663665
readonly query: Query<AppModelType, DbModelType>;
664666
get size(): number;
665667
toJSON(): object;
666668
}
667669

670+
// @public
671+
export function querySnapshotFromJSON(db: Firestore, json: object): QuerySnapshot;
672+
673+
// @public
674+
export function querySnapshotFromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
675+
668676
// @public
669677
export class QueryStartAtConstraint extends QueryConstraint {
670678
readonly type: 'startAt' | 'startAfter';

docs-devsite/firestore_.documentsnapshot.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export declare class DocumentSnapshot<AppModelType = DocumentData, DbModelType e
4040
| --- | --- | --- |
4141
| [data(options)](./firestore_.documentsnapshot.md#documentsnapshotdata) | | Retrieves all fields in the document as an <code>Object</code>. Returns <code>undefined</code> if the document doesn't exist.<!-- -->By default, <code>serverTimestamp()</code> values that have not yet been set to their final value will be returned as <code>null</code>. You can override this by passing an options object. |
4242
| [exists()](./firestore_.documentsnapshot.md#documentsnapshotexists) | | Returns whether or not the data exists. True if the document exists. |
43-
| [fromJSON(db, json)](./firestore_.documentsnapshot.md#documentsnapshotfromjson) | <code>static</code> | Builds a <code>DocumentSnapshot</code> instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->. |
44-
| [fromJSON(db, json, converter)](./firestore_.documentsnapshot.md#documentsnapshotfromjson) | <code>static</code> | Builds a <code>DocumentSnapshot</code> instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->. |
4543
| [get(fieldPath, options)](./firestore_.documentsnapshot.md#documentsnapshotget) | | Retrieves the field specified by <code>fieldPath</code>. Returns <code>undefined</code> if the document or field doesn't exist.<!-- -->By default, a <code>serverTimestamp()</code> that has not yet been set to its final value will be returned as <code>null</code>. You can override this by passing an options object. |
4644
| [toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson) | | Returns a JSON-serializable representation of this <code>DocumentSnapshot</code> instance. |
4745

@@ -122,53 +120,6 @@ exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;
122120

123121
this is [QueryDocumentSnapshot](./firestore_.querydocumentsnapshot.md#querydocumentsnapshot_class)<!-- -->&lt;AppModelType, DbModelType&gt;
124122

125-
## DocumentSnapshot.fromJSON()
126-
127-
Builds a `DocumentSnapshot` instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->.
128-
129-
<b>Signature:</b>
130-
131-
```typescript
132-
static fromJSON(db: Firestore, json: object): DocumentSnapshot;
133-
```
134-
135-
#### Parameters
136-
137-
| Parameter | Type | Description |
138-
| --- | --- | --- |
139-
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
140-
| json | object | a JSON object represention of a <code>DocumentSnapshot</code> instance. |
141-
142-
<b>Returns:</b>
143-
144-
[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)
145-
146-
an instance of [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
147-
148-
## DocumentSnapshot.fromJSON()
149-
150-
Builds a `DocumentSnapshot` instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->.
151-
152-
<b>Signature:</b>
153-
154-
```typescript
155-
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
156-
```
157-
158-
#### Parameters
159-
160-
| Parameter | Type | Description |
161-
| --- | --- | --- |
162-
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
163-
| json | object | a JSON object represention of a <code>DocumentSnapshot</code> instance. |
164-
| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<!-- -->&lt;AppModelType, DbModelType&gt; | Converts objects to and from Firestore. |
165-
166-
<b>Returns:</b>
167-
168-
[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<!-- -->&lt;AppModelType, DbModelType&gt;
169-
170-
an instance of [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
171-
172123
## DocumentSnapshot.get()
173124

174125
Retrieves the field specified by `fieldPath`<!-- -->. Returns `undefined` if the document or field doesn't exist.

docs-devsite/firestore_.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ https://github.com/firebase/firebase-js-sdk
1919
| [getFirestore(app)](./firestore_.md#getfirestore_cf608e1) | Returns the existing default [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)<!-- -->. If no instance exists, initializes a new instance with default settings. |
2020
| [getFirestore(app, databaseId)](./firestore_.md#getfirestore_48de6cb) | <b><i>(Public Preview)</i></b> Returns the existing named [Firestore](./firestore_.firestore.md#firestore_class) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)<!-- -->. If no instance exists, initializes a new instance with default settings. |
2121
| [initializeFirestore(app, settings, databaseId)](./firestore_.md#initializefirestore_fc7d200) | Initializes a new instance of [Firestore](./firestore_.firestore.md#firestore_class) with the provided settings. Can only be called before any other function, including [getFirestore()](./firestore_.md#getfirestore)<!-- -->. If the custom settings are empty, this function is equivalent to calling [getFirestore()](./firestore_.md#getfirestore)<!-- -->. |
22+
| <b>function(db, ...)</b> |
23+
| [documentSnapshotFromJSON(db, json)](./firestore_.md#documentsnapshotfromjson_a318ff2) | Builds a <code>DocumentSnapshot</code> instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->. |
24+
| [documentSnapshotFromJSON(db, json, converter)](./firestore_.md#documentsnapshotfromjson_ddb369d) | Builds a <code>DocumentSnapshot</code> instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->. |
25+
| [querySnapshotFromJSON(db, json)](./firestore_.md#querysnapshotfromjson_a318ff2) | Builds a <code>QuerySnapshot</code> instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->. |
26+
| [querySnapshotFromJSON(db, json, converter)](./firestore_.md#querysnapshotfromjson_ddb369d) | Builds a <code>QuerySnapshot</code> instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->. |
2227
| <b>function(firestore, ...)</b> |
2328
| [clearIndexedDbPersistence(firestore)](./firestore_.md#clearindexeddbpersistence_231a8e0) | Clears the persistent storage. This includes pending writes and cached documents.<!-- -->Must be called while the [Firestore](./firestore_.firestore.md#firestore_class) instance is not started (after the app is terminated or when the app is first initialized). On startup, this function must be called before other functions (other than [initializeFirestore()](./firestore_.md#initializefirestore_fc7d200) or [getFirestore()](./firestore_.md#getfirestore)<!-- -->)). If the [Firestore](./firestore_.firestore.md#firestore_class) instance is still running, the promise will be rejected with the error code of <code>failed-precondition</code>.<!-- -->Note: <code>clearIndexedDbPersistence()</code> is primarily intended to help write reliable tests that use Cloud Firestore. It uses an efficient mechanism for dropping existing data but does not attempt to securely overwrite or otherwise make cached data unrecoverable. For applications that are sensitive to the disclosure of cached data in between user sessions, we strongly recommend not enabling persistence at all. |
2429
| [collection(firestore, path, pathSegments)](./firestore_.md#collection_1eb4c23) | Gets a <code>CollectionReference</code> instance that refers to the collection at the specified absolute path. |
@@ -306,6 +311,102 @@ export declare function initializeFirestore(app: FirebaseApp, settings: Firestor
306311

307312
A newly initialized [Firestore](./firestore_.firestore.md#firestore_class) instance.
308313

314+
## function(db, ...)
315+
316+
### documentSnapshotFromJSON(db, json) {:#documentsnapshotfromjson_a318ff2}
317+
318+
Builds a `DocumentSnapshot` instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->.
319+
320+
<b>Signature:</b>
321+
322+
```typescript
323+
export declare function documentSnapshotFromJSON(db: Firestore, json: object): DocumentSnapshot;
324+
```
325+
326+
#### Parameters
327+
328+
| Parameter | Type | Description |
329+
| --- | --- | --- |
330+
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
331+
| json | object | a JSON object represention of a <code>DocumentSnapshot</code> instance. |
332+
333+
<b>Returns:</b>
334+
335+
[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)
336+
337+
an instance of [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
338+
339+
### documentSnapshotFromJSON(db, json, converter) {:#documentsnapshotfromjson_ddb369d}
340+
341+
Builds a `DocumentSnapshot` instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->.
342+
343+
<b>Signature:</b>
344+
345+
```typescript
346+
export declare function documentSnapshotFromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
347+
```
348+
349+
#### Parameters
350+
351+
| Parameter | Type | Description |
352+
| --- | --- | --- |
353+
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
354+
| json | object | a JSON object represention of a <code>DocumentSnapshot</code> instance. |
355+
| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<!-- -->&lt;AppModelType, DbModelType&gt; | Converts objects to and from Firestore. |
356+
357+
<b>Returns:</b>
358+
359+
[DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class)<!-- -->&lt;AppModelType, DbModelType&gt;
360+
361+
an instance of [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
362+
363+
### querySnapshotFromJSON(db, json) {:#querysnapshotfromjson_a318ff2}
364+
365+
Builds a `QuerySnapshot` instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->.
366+
367+
<b>Signature:</b>
368+
369+
```typescript
370+
export declare function querySnapshotFromJSON(db: Firestore, json: object): QuerySnapshot;
371+
```
372+
373+
#### Parameters
374+
375+
| Parameter | Type | Description |
376+
| --- | --- | --- |
377+
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
378+
| json | object | a JSON object represention of a <code>QuerySnapshot</code> instance. |
379+
380+
<b>Returns:</b>
381+
382+
[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)
383+
384+
an instance of [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
385+
386+
### querySnapshotFromJSON(db, json, converter) {:#querysnapshotfromjson_ddb369d}
387+
388+
Builds a `QuerySnapshot` instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->.
389+
390+
<b>Signature:</b>
391+
392+
```typescript
393+
export declare function querySnapshotFromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
394+
```
395+
396+
#### Parameters
397+
398+
| Parameter | Type | Description |
399+
| --- | --- | --- |
400+
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
401+
| json | object | a JSON object represention of a <code>QuerySnapshot</code> instance. |
402+
| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<!-- -->&lt;AppModelType, DbModelType&gt; | Converts objects to and from Firestore. |
403+
404+
<b>Returns:</b>
405+
406+
[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<!-- -->&lt;AppModelType, DbModelType&gt;
407+
408+
an instance of [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
409+
309410
## function(firestore, ...)
310411

311412
### clearIndexedDbPersistence(firestore) {:#clearindexeddbpersistence_231a8e0}

docs-devsite/firestore_.querysnapshot.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export declare class QuerySnapshot<AppModelType = DocumentData, DbModelType exte
3434
| --- | --- | --- |
3535
| [docChanges(options)](./firestore_.querysnapshot.md#querysnapshotdocchanges) | | Returns an array of the documents changes since the last snapshot. If this is the first snapshot, all documents will be in the list as 'added' changes. |
3636
| [forEach(callback, thisArg)](./firestore_.querysnapshot.md#querysnapshotforeach) | | Enumerates all of the documents in the <code>QuerySnapshot</code>. |
37-
| [fromJSON(db, json)](./firestore_.querysnapshot.md#querysnapshotfromjson) | <code>static</code> | Builds a <code>QuerySnapshot</code> instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->. |
38-
| [fromJSON(db, json, converter)](./firestore_.querysnapshot.md#querysnapshotfromjson) | <code>static</code> | Builds a <code>QuerySnapshot</code> instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->. |
3937
| [toJSON()](./firestore_.querysnapshot.md#querysnapshottojson) | | Returns a JSON-serializable representation of this <code>QuerySnapshot</code> instance. |
4038

4139
## QuerySnapshot.docs
@@ -129,53 +127,6 @@ forEach(callback: (result: QueryDocumentSnapshot<AppModelType, DbModelType>) =>
129127

130128
void
131129

132-
## QuerySnapshot.fromJSON()
133-
134-
Builds a `QuerySnapshot` instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->.
135-
136-
<b>Signature:</b>
137-
138-
```typescript
139-
static fromJSON(db: Firestore, json: object): QuerySnapshot;
140-
```
141-
142-
#### Parameters
143-
144-
| Parameter | Type | Description |
145-
| --- | --- | --- |
146-
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
147-
| json | object | a JSON object represention of a <code>QuerySnapshot</code> instance. |
148-
149-
<b>Returns:</b>
150-
151-
[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)
152-
153-
an instance of [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
154-
155-
## QuerySnapshot.fromJSON()
156-
157-
Builds a `QuerySnapshot` instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->.
158-
159-
<b>Signature:</b>
160-
161-
```typescript
162-
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
163-
```
164-
165-
#### Parameters
166-
167-
| Parameter | Type | Description |
168-
| --- | --- | --- |
169-
| db | [Firestore](./firestore_.firestore.md#firestore_class) | |
170-
| json | object | a JSON object represention of a <code>QuerySnapshot</code> instance. |
171-
| converter | [FirestoreDataConverter](./firestore_.firestoredataconverter.md#firestoredataconverter_interface)<!-- -->&lt;AppModelType, DbModelType&gt; | Converts objects to and from Firestore. |
172-
173-
<b>Returns:</b>
174-
175-
[QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class)<!-- -->&lt;AppModelType, DbModelType&gt;
176-
177-
an instance of [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
178-
179130
## QuerySnapshot.toJSON()
180131

181132
Returns a JSON-serializable representation of this `QuerySnapshot` instance.

packages/firestore/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ export {
8989
DocumentChange,
9090
DocumentChangeType,
9191
DocumentSnapshot,
92+
documentSnapshotFromJSON,
9293
FirestoreDataConverter,
9394
QueryDocumentSnapshot,
9495
QuerySnapshot,
96+
querySnapshotFromJSON,
9597
snapshotEqual,
9698
SnapshotMetadata,
9799
SnapshotOptions

0 commit comments

Comments
 (0)