Skip to content

Commit 367dc17

Browse files
authored
Merge 161e64a into b08248a
2 parents b08248a + 161e64a commit 367dc17

20 files changed

+383
-407
lines changed

integration/firestore/firebase_export_memory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import firebase from '@firebase/app';
1919
import '@firebase/firestore/memory';
20-
import '@firebase/firestore/bundle';
20+
import '@firebase/firestore/memory-bundle';
2121
import { FirebaseApp } from '@firebase/app-types';
2222
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2323

integration/firestore/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "yarn build:memory; karma start --single-run; yarn build:persistence; karma start --single-run;",
1010
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
1111
"test:persistence": " yarn build:persistence; karma start --single-run",
12-
"test:persistence:debug:": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
12+
"test:persistence:debug": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
1313
"test:memory": "yarn build:memory; karma start --single-run",
1414
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
1515
},

packages/firebase/firestore/memory/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
*/
2222

2323
import '@firebase/firestore/memory';
24-
import '@firebase/firestore/bundle';
24+
import '@firebase/firestore/memory-bundle';

packages/firestore/exp/src/api/snapshot.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ export interface DocumentChange<T = DocumentData> {
176176
* access will return 'undefined'. You can use the `exists()` method to
177177
* explicitly verify a document's existence.
178178
*/
179-
export class DocumentSnapshot<
180-
T = DocumentData
181-
> extends LiteDocumentSnapshot<T> {
179+
export class DocumentSnapshot<T = DocumentData> extends LiteDocumentSnapshot<
180+
T
181+
> {
182182
private readonly _firestoreImpl: FirebaseFirestore;
183183

184184
/**
@@ -291,9 +291,9 @@ export class DocumentSnapshot<
291291
* `exists` property will always be true and `data()` will never return
292292
* 'undefined'.
293293
*/
294-
export class QueryDocumentSnapshot<
295-
T = DocumentData
296-
> extends DocumentSnapshot<T> {
294+
export class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<
295+
T
296+
> {
297297
/**
298298
* Retrieves all fields in the document as an `Object`.
299299
*

packages/firestore/index.bundle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function registerBundle(instance: typeof Firestore): void {
3434
return namedQuery(this, queryName);
3535
};
3636

37-
//TODO: add loadBundle and namedQuery to the firestore namespace
37+
//TODO(wuandy): add loadBundle and namedQuery to the firestore namespace
3838
}
3939

4040
registerBundle(Firestore);

packages/firestore/lite/src/api/snapshot.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ export class DocumentSnapshot<T = DocumentData> {
211211
* `exists` property will always be true and `data()` will never return
212212
* 'undefined'.
213213
*/
214-
export class QueryDocumentSnapshot<
215-
T = DocumentData
216-
> extends DocumentSnapshot<T> {
214+
export class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<
215+
T
216+
> {
217217
/**
218218
* Retrieves all fields in the document as an `Object`.
219219
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@firebase/firestore/memory-bundle",
3+
"description": "Firestore bundle",
4+
"main": "../dist/memory/node-cjs/bundle.js",
5+
"main-esm2017": "../dist/memory/node-esm2017/bundle.js",
6+
"react-native": "../dist/memory/rn/bundle.js",
7+
"browser": "../dist/memory/esm5/bundle.js",
8+
"module": "../dist/memory/esm5/bundle.js",
9+
"esm2017": "../dist/memory/esm2017/bundle.js"
10+
}

packages/firestore/rollup.config.browser.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import pkg from './package.json';
22
import path from 'path';
33
import memoryPkg from './memory/package.json';
44
import bundlePkg from './bundle/package.json';
5+
import memoryBundlePkg from './memory-bundle/package.json';
56

67
/**
78
* @license
@@ -50,7 +51,7 @@ export default [
5051
},
5152
plugins: [
5253
util.applyPrebuilt(),
53-
...util.es2017Plugins('browser', /* mangled= */ true)
54+
...util.es2017Plugins('browser', /* mangled= */ false)
5455
],
5556
external: util.resolveBrowserExterns,
5657
treeshake: {
@@ -89,7 +90,7 @@ export default [
8990
},
9091
plugins: [
9192
util.applyPrebuilt(),
92-
...util.es2017Plugins('browser', /* mangled= */ true)
93+
...util.es2017Plugins('browser', /* mangled= */ false)
9394
],
9495
external: util.resolveBrowserExterns,
9596
treeshake: {
@@ -100,7 +101,7 @@ export default [
100101
{
101102
input: {
102103
index: path.resolve('./memory', memoryPkg['esm2017']),
103-
bundle: path.resolve('./bundle', bundlePkg['esm2017'])
104+
bundle: path.resolve('./bundle', memoryBundlePkg['esm2017'])
104105
},
105106
output: [
106107
{

packages/firestore/rollup.config.node.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import copy from 'rollup-plugin-copy';
2020
import pkg from './package.json';
2121
import bundlePkg from './bundle/package.json';
2222
import memoryPkg from './memory/package.json';
23+
import memoryBundlePkg from './memory-bundle/package.json';
2324
import path from 'path';
2425

2526
const util = require('./rollup.shared');
@@ -91,7 +92,7 @@ export default [
9192
{
9293
input: {
9394
index: path.resolve('./memory', memoryPkg['main-esm2017']),
94-
bundle: path.resolve('./bundle', bundlePkg['main-esm2017'])
95+
bundle: path.resolve('./bundle', memoryBundlePkg['main-esm2017'])
9596
},
9697
output: [
9798
{

packages/firestore/rollup.config.rn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default [
4545
},
4646
plugins: [
4747
util.applyPrebuilt('prebuilt.rn.js'),
48-
...util.es2017Plugins('rn', /* mangled= */ true)
48+
...util.es2017Plugins('rn', /* mangled= */ false)
4949
],
5050
external: util.resolveBrowserExterns,
5151
treeshake: {

packages/firestore/rollup.shared.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ const manglePrivatePropertiesOptions = {
204204
exports.manglePrivatePropertiesOptions = manglePrivatePropertiesOptions;
205205

206206
exports.applyPrebuilt = function (name = 'prebuilt.js') {
207-
alias({
207+
return alias({
208208
entries: [
209209
{
210210
find: /^(.*)\/export$/,
211-
replacement: `$1\/dist/${name}.js`
211+
replacement: `$1\/dist/${name}`
212212
}
213213
]
214214
});

packages/firestore/src/core/bundle.ts

+11-95
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,18 @@ import {
3131
import * as api from '../protos/firestore_proto_api';
3232
import { DocumentKey } from '../model/document_key';
3333
import { MaybeDocument, NoDocument } from '../model/document';
34-
import { debugAssert, debugCast } from '../util/assert';
35-
import { LocalStore } from '../local/local_store';
36-
import { BundleReader, SizedBundleElement } from '../util/bundle_reader';
34+
import { debugAssert } from '../util/assert';
35+
import {
36+
applyBundleDocuments,
37+
LocalStore,
38+
saveNamedQuery
39+
} from '../local/local_store';
40+
import { SizedBundleElement } from '../util/bundle_reader';
3741
import {
3842
documentKeySet,
3943
DocumentKeySet,
4044
MaybeDocumentMap
4145
} from '../model/collections';
42-
import { LoadBundleTask } from '../api/bundle';
43-
import {
44-
emitNewSnapsAndNotifyLocalStore,
45-
SyncEngine,
46-
SyncEngineImpl
47-
} from './sync_engine';
48-
import { logWarn } from '../util/log';
49-
import { LOG_TAG } from '../../lite/src/api/components';
50-
import {
51-
applyBundleDocuments,
52-
hasNewerBundle,
53-
saveBundle,
54-
saveNamedQuery
55-
} from '../local/local_store_bundle';
5646

5747
/**
5848
* Represents a bundled document, including the metadata and the document
@@ -105,7 +95,7 @@ export class BundleConverter {
10595
* Returns a `LoadBundleTaskProgress` representing the initial progress of
10696
* loading a bundle.
10797
*/
108-
function bundleInitialProgress(
98+
export function bundleInitialProgress(
10999
metadata: ProtoBundleMetadata
110100
): LoadBundleTaskProgress {
111101
return {
@@ -121,7 +111,7 @@ function bundleInitialProgress(
121111
* Returns a `LoadBundleTaskProgress` representing the progress that the loading
122112
* has succeeded.
123113
*/
124-
function bundleSuccessProgress(
114+
export function bundleSuccessProgress(
125115
metadata: ProtoBundleMetadata
126116
): LoadBundleTaskProgress {
127117
return {
@@ -133,7 +123,7 @@ function bundleSuccessProgress(
133123
};
134124
}
135125

136-
class BundleLoadResult {
126+
export class BundleLoadResult {
137127
constructor(
138128
readonly progress: LoadBundleTaskProgress,
139129
readonly changedDocs: MaybeDocumentMap
@@ -144,7 +134,7 @@ class BundleLoadResult {
144134
* A class to process the elements from a bundle, load them into local
145135
* storage and provide progress update while loading.
146136
*/
147-
class BundleLoader {
137+
export class BundleLoader {
148138
/** The current progress of loading */
149139
private progress: LoadBundleTaskProgress;
150140
/** Batched queries to be saved into storage */
@@ -249,77 +239,3 @@ class BundleLoader {
249239
return new BundleLoadResult({ ...this.progress }, changedDocuments);
250240
}
251241
}
252-
253-
/**
254-
* Loads a Firestore bundle into the SDK. The returned promise resolves when
255-
* the bundle finished loading.
256-
*
257-
* @param bundleReader Bundle to load into the SDK.
258-
* @param task LoadBundleTask used to update the loading progress to public API.
259-
*/
260-
export function syncEngineLoadBundle(
261-
syncEngine: SyncEngine,
262-
bundleReader: BundleReader,
263-
task: LoadBundleTask
264-
): void {
265-
const syncEngineImpl = debugCast(syncEngine, SyncEngineImpl);
266-
267-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
268-
loadBundleImpl(syncEngineImpl, bundleReader, task).then(() => {
269-
syncEngineImpl.sharedClientState.notifyBundleLoaded();
270-
});
271-
}
272-
273-
async function loadBundleImpl(
274-
syncEngine: SyncEngineImpl,
275-
reader: BundleReader,
276-
task: LoadBundleTask
277-
): Promise<void> {
278-
try {
279-
const metadata = await reader.getMetadata();
280-
const skip = await hasNewerBundle(syncEngine.localStore, metadata);
281-
if (skip) {
282-
await reader.close();
283-
task._completeWith(bundleSuccessProgress(metadata));
284-
return;
285-
}
286-
287-
task._updateProgress(bundleInitialProgress(metadata));
288-
289-
const loader = new BundleLoader(
290-
metadata,
291-
syncEngine.localStore,
292-
reader.serializer
293-
);
294-
let element = await reader.nextElement();
295-
while (element) {
296-
debugAssert(
297-
!element.payload.metadata,
298-
'Unexpected BundleMetadata element.'
299-
);
300-
const progress = await loader.addSizedElement(element);
301-
if (progress) {
302-
task._updateProgress(progress);
303-
}
304-
305-
element = await reader.nextElement();
306-
}
307-
308-
const result = await loader.complete();
309-
// TODO(b/160876443): This currently raises snapshots with
310-
// `fromCache=false` if users already listen to some queries and bundles
311-
// has newer version.
312-
await emitNewSnapsAndNotifyLocalStore(
313-
syncEngine,
314-
result.changedDocs,
315-
/* remoteEvent */ undefined
316-
);
317-
318-
// Save metadata, so loading the same bundle will skip.
319-
await saveBundle(syncEngine.localStore, metadata);
320-
task._completeWith(result.progress);
321-
} catch (e) {
322-
logWarn(LOG_TAG, `Loading bundle failed with ${e}`);
323-
task._failWith(e);
324-
}
325-
}

packages/firestore/src/core/firestore_client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { User } from '../auth/user';
2525
import {
2626
executeQuery,
27+
getNamedQuery,
2728
handleUserChange,
2829
LocalStore,
2930
readLocalDocument
@@ -54,6 +55,7 @@ import {
5455
registerPendingWritesCallback,
5556
SyncEngine,
5657
syncEngineListen,
58+
syncEngineLoadBundle,
5759
syncEngineUnlisten,
5860
syncEngineWrite
5961
} from './sync_engine';
@@ -77,11 +79,9 @@ import { Persistence } from '../local/persistence';
7779
import { Datastore } from '../remote/datastore';
7880
import { LoadBundleTask } from '../api/bundle';
7981
import { newSerializer, newTextEncoder } from '../platform/serializer';
80-
import { getNamedQuery } from '../local/local_store_bundle';
8182
import { JsonProtoSerializer } from '../remote/serializer';
8283
import { BundleReader } from '../util/bundle_reader';
8384
import { toByteStreamReader } from '../platform/byte_stream_reader';
84-
import { syncEngineLoadBundle } from './bundle';
8585
import { NamedQuery } from './bundle_types';
8686

8787
const LOG_TAG = 'FirestoreClient';

0 commit comments

Comments
 (0)