Skip to content

Commit bad6f72

Browse files
committed
Minify fix.
1 parent 36e4fd5 commit bad6f72

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

packages/firestore/src/api/snapshot.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,16 @@ export class DocumentSnapshot<
505505

506506
toJSON(): object {
507507
const document = this._document;
508+
const result : any = { };
509+
result['bundle'] = '';
510+
result['source'] = 'DocumentSnapshot';
511+
508512
if (
509513
!document ||
510514
!document.isValidDocument() ||
511515
!document.isFoundDocument()
512516
) {
513-
return { bundle: '' };
517+
return result;
514518
}
515519
const builder: BundleBuilder = new BundleBuilder(
516520
this._firestore,
@@ -534,7 +538,8 @@ export class DocumentSnapshot<
534538
document
535539
)
536540
);
537-
return { bundle: builder.build() };
541+
result['bundle'] = builder.build();
542+
return result;
538543
}
539544
}
540545

@@ -693,6 +698,8 @@ export class QuerySnapshot<
693698
}
694699

695700
toJSON(): object {
701+
const result : any = { };
702+
result['source'] = 'QuerySnapshot';
696703
const builder: BundleBuilder = new BundleBuilder(
697704
this._firestore,
698705
AutoId.newId()
@@ -731,7 +738,8 @@ export class QuerySnapshot<
731738
docBundleDataArray
732739
};
733740
builder.addBundleQuery(bundleData);
734-
return { bundle: builder.build() };
741+
result['bundle'] = builder.build();
742+
return result;
735743
}
736744
}
737745

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ import {
3737
endAt,
3838
endBefore,
3939
GeoPoint,
40+
getDocFromCache,
4041
getDocs,
4142
limit,
4243
limitToLast,
44+
loadBundle,
4345
onSnapshot,
4446
or,
4547
orderBy,
@@ -74,6 +76,47 @@ import { captureExistenceFilterMismatches } from '../util/testing_hooks_util';
7476
apiDescribe('Queries', persistence => {
7577
addEqualityMatcher();
7678

79+
it('QuerySnapshot.toJSON bundle getDocFromCache', async () => {
80+
let path: string | null = null;
81+
let jsonBundle: object | null = null;
82+
const testDocs = {
83+
a: { k: 'a' },
84+
b: { k: 'b' },
85+
c: { k: 'c' }
86+
};
87+
// Write an initial document in an isolated Firestore instance so it's not stored in the cache.
88+
await withTestCollection(persistence, testDocs, async collection => {
89+
await getDocs(query(collection)).then(querySnapshot => {
90+
expect(querySnapshot.docs.length).to.equal(3);
91+
// Find the path to a known doc.
92+
querySnapshot.docs.forEach(docSnapshot => {
93+
if (docSnapshot.ref.path.endsWith('a')) {
94+
path = docSnapshot.ref.path;
95+
}
96+
});
97+
expect(path).to.not.be.null;
98+
jsonBundle = querySnapshot.toJSON();
99+
});
100+
});
101+
expect(jsonBundle).to.not.be.null;
102+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
103+
const json = (jsonBundle as any).bundle;
104+
console.log("DEDB checking if json exists");
105+
expect(json).to.exist;
106+
expect(json.length).to.be.greaterThan(0);
107+
108+
if (path !== null) {
109+
await withTestDb(persistence, async db => {
110+
const docRef = doc(db, path!);
111+
await loadBundle(db, json);
112+
const docSnap = await getDocFromCache(docRef);
113+
console.log("DEDB checking if docSnap exists");
114+
expect(docSnap.exists);
115+
expect(docSnap.data()).to.deep.equal(testDocs.a);
116+
});
117+
}
118+
});
119+
77120
it('can issue limit queries', () => {
78121
const testDocs = {
79122
a: { k: 'a' },

0 commit comments

Comments
 (0)