Skip to content

Commit b662f8c

Browse files
Release Firestore Bundles as a prototype patched feature. (#4168)
* Add bundles to d.ts and rearrange bundles source code for building it as a separate module (#4120) * Add bundles to d.ts and rearrange bundles source code for building it as a separate module. * Roll bundle with prebuilt (#4128) Build firestore sdks with prebuilt to support bundle as a prototype patched feature. * Add JSDoc for bundles (#4155) Add JSDoc for bundles. * Create changeset * Update old-lobsters-pull.md * A few fixes for Firestore bundle sdk builds (#4177) * Actually creates firebase/firestore/bundle package.json * Fix standard node/browser builds for bundles * Make it release from remote branch. * Add bundle to firebase complete build and fix missing proto for memory build. * Make rollup.config.js more organized. * Revert "Make it release from remote branch." This reverts commit 2c91fd1. * 2017 -> 2020 * Update comment. * Address comments * Update .changeset/old-lobsters-pull.md Co-authored-by: Sebastian Schmidt <[email protected]> * Update .changeset/old-lobsters-pull.md Co-authored-by: Sebastian Schmidt <[email protected]> * Add toc. * Remove webpack change. Co-authored-by: Sebastian Schmidt <[email protected]>
1 parent 9634efd commit b662f8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1111
-613
lines changed

.changeset/old-lobsters-pull.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"firebase": minor
3+
"@firebase/firestore-types": minor
4+
"@firebase/firestore": minor
5+
---
6+
7+
Release Firestore Bundles (pre-packaged Firestore data). For NPM users, this can
8+
be enabled via an additional import: 'firebase/firestore/bundle'. For CDN usage,
9+
it is enabled by default.

integration/firestore/firebase_export.ts

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

1818
import firebase from '@firebase/app';
1919
import '@firebase/firestore';
20+
import '@firebase/firestore/bundle';
2021
import { FirebaseApp } from '@firebase/app-types';
2122
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2223

integration/firestore/firebase_export_memory.ts

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

1818
import firebase from '@firebase/app';
1919
import '@firebase/firestore/memory';
20+
import '@firebase/firestore/memory-bundle';
2021
import { FirebaseApp } from '@firebase/app-types';
2122
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2223

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
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import '@firebase/firestore/bundle';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "firebase/firestore/bundle",
3+
"description": "The bundle loading feature of the Cloud Firestore component.",
4+
"main": "dist/index.node.cjs.js",
5+
"module": "dist/index.esm.js",
6+
"typings": "../empty-import.d.ts"
7+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import '@firebase/firestore';
19+
import '@firebase/firestore/bundle';

packages/firestore/rollup.config.rn.memory.js renamed to packages/firebase/firestore/memory/bundle/index.ts

+5-17
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as path from 'path';
19-
import memoryPkg from './memory/package.json';
20-
21-
const util = require('./rollup.shared');
18+
/**
19+
* This file serves as the public entrypoint for users that import
20+
* `firebase/firestore/memory`.
21+
*/
2222

23-
export default {
24-
input: 'index.rn.memory.ts',
25-
output: {
26-
file: path.resolve('./memory', memoryPkg['react-native']),
27-
format: 'es',
28-
sourcemap: true
29-
},
30-
plugins: util.es2017Plugins('rn', /* mangled= */ true),
31-
external: util.resolveBrowserExterns,
32-
treeshake: {
33-
moduleSideEffects: false
34-
}
35-
};
23+
import '@firebase/firestore/memory-bundle';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "firebase/firestore/memory",
3+
"description": "The bundle loading feature for the memory-only build of the Cloud Firestore JS SDK.",
4+
"main": "dist/index.node.cjs.js",
5+
"module": "dist/index.esm.js",
6+
"typings": "../../empty-import.d.ts"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* This file serves as the public entrypoint for users that import
20+
* `firebase/firestore/memory`.
21+
*/
22+
23+
import '@firebase/firestore/memory';
24+
import '@firebase/firestore/memory-bundle';
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "firebase/firestore",
33
"description": "The Cloud Firestore component of the Firebase JS SDK.",
4-
"main": "dist/index.cjs.js",
4+
"main": "dist/index.node.cjs.js",
55
"module": "dist/index.esm.js",
66
"typings": "../empty-import.d.ts"
77
}

packages/firebase/index.d.ts

+97
Original file line numberDiff line numberDiff line change
@@ -8289,12 +8289,109 @@ declare namespace firebase.firestore {
82898289
*/
82908290
terminate(): Promise<void>;
82918291

8292+
/**
8293+
* Loads a Firestore bundle into the local cache.
8294+
*
8295+
* @param bundleData
8296+
* An object representing the bundle to be loaded. Valid objects are `ArrayBuffer`,
8297+
* `ReadableStream<Uint8Array>` or `string`.
8298+
*
8299+
* @return
8300+
* A `LoadBundleTask` object, which notifies callers with progress updates, and completion
8301+
* or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
8302+
*/
8303+
loadBundle(
8304+
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
8305+
): LoadBundleTask;
8306+
8307+
/**
8308+
* Reads a Firestore `Query` from local cache, identified by the given name.
8309+
*
8310+
* The named queries are packaged into bundles on the server side (along
8311+
* with resulting documents), and loaded to local cache using `loadBundle`. Once in local
8312+
* cache, use this method to extract a `Query` by name.
8313+
*/
8314+
namedQuery(name: string): Promise<Query<DocumentData> | null>;
8315+
82928316
/**
82938317
* @hidden
82948318
*/
82958319
INTERNAL: { delete: () => Promise<void> };
82968320
}
82978321

8322+
/**
8323+
* Represents the task of loading a Firestore bundle. It provides progress of bundle
8324+
* loading, as well as task completion and error events.
8325+
*
8326+
* The API is compatible with `Promise<LoadBundleTaskProgress>`.
8327+
*/
8328+
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
8329+
/**
8330+
* Registers functions to listen to bundle loading progress events.
8331+
* @param next
8332+
* Called when there is a progress update from bundle loading. Typically `next` calls occur
8333+
* each time a Firestore document is loaded from the bundle.
8334+
* @param error
8335+
* Called when an error occurs during bundle loading. The task aborts after reporting the
8336+
* error, and there should be no more updates after this.
8337+
* @param complete
8338+
* Called when the loading task is complete.
8339+
*/
8340+
onProgress(
8341+
next?: (progress: LoadBundleTaskProgress) => any,
8342+
error?: (error: Error) => any,
8343+
complete?: () => void
8344+
): void;
8345+
8346+
/**
8347+
* Implements the `Promise<LoadBundleTaskProgress>.then` interface.
8348+
*
8349+
* @param onFulfilled
8350+
* Called on the completion of the loading task with a final `LoadBundleTaskProgress` update.
8351+
* The update will always have its `taskState` set to `"Success"`.
8352+
* @param onRejected
8353+
* Called when an error occurs during bundle loading.
8354+
*/
8355+
then<T, R>(
8356+
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
8357+
onRejected?: (a: Error) => R | PromiseLike<R>
8358+
): Promise<T | R>;
8359+
8360+
/**
8361+
* Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
8362+
*
8363+
* @param onRejected
8364+
* Called when an error occurs during bundle loading.
8365+
*/
8366+
catch<R>(
8367+
onRejected: (a: Error) => R | PromiseLike<R>
8368+
): Promise<R | LoadBundleTaskProgress>;
8369+
}
8370+
8371+
/**
8372+
* Represents a progress update or a final state from loading bundles.
8373+
*/
8374+
export interface LoadBundleTaskProgress {
8375+
/** How many documents have been loaded. */
8376+
documentsLoaded: number;
8377+
/** How many documents are in the bundle being loaded. */
8378+
totalDocuments: number;
8379+
/** How many bytes have been loaded. */
8380+
bytesLoaded: number;
8381+
/** How many bytes are in the bundle being loaded. */
8382+
totalBytes: number;
8383+
/** Current task state. */
8384+
taskState: TaskState;
8385+
}
8386+
8387+
/**
8388+
* Represents the state of bundle loading tasks.
8389+
*
8390+
* Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
8391+
* be no more updates after they are reported.
8392+
*/
8393+
export type TaskState = 'Error' | 'Running' | 'Success';
8394+
82988395
/**
82998396
* An immutable object representing a geo point in Firestore. The geo point
83008397
* is represented as latitude/longitude pair.

packages/firebase/rollup.config.js

+83-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ import pkg from './package.json';
2828

2929
import appPkg from './app/package.json';
3030

31+
import firestorePkg from './firestore/package.json';
32+
import firestoreBundlePkg from './firestore/bundle/package.json';
33+
34+
import firestoreMemoryPkg from './firestore/memory/package.json';
35+
import firestoreMemoryBundlePkg from './firestore/memory/bundle/package.json';
36+
3137
function createUmdOutputConfig(output) {
3238
return {
3339
file: output,
@@ -111,7 +117,9 @@ const appBuilds = [
111117

112118
const componentBuilds = pkg.components
113119
// The "app" component is treated differently because it doesn't depend on itself.
114-
.filter(component => component !== 'app')
120+
// The "firestore" component is treated differently because it contains multiple
121+
// sub components for different builds.
122+
.filter(component => component !== 'app' && component !== 'firestore')
115123
.map(component => {
116124
const pkg = require(`./${component}/package.json`);
117125
return [
@@ -149,17 +157,67 @@ const componentBuilds = pkg.components
149157
})
150158
.reduce((a, b) => a.concat(b), []);
151159

160+
const firestoreBuilds = [
161+
{
162+
input: `firestore/index.ts`,
163+
output: [
164+
{
165+
file: resolve('firestore', firestorePkg.main),
166+
format: 'cjs',
167+
sourcemap: true
168+
},
169+
{
170+
file: resolve('firestore', firestorePkg.module),
171+
format: 'es',
172+
sourcemap: true
173+
}
174+
],
175+
plugins,
176+
external
177+
},
178+
{
179+
input: `firestore/bundle/index.ts`,
180+
output: [
181+
{
182+
file: resolve('firestore/bundle', firestoreBundlePkg.main),
183+
format: 'cjs',
184+
sourcemap: true
185+
},
186+
{
187+
file: resolve('firestore/bundle', firestoreBundlePkg.module),
188+
format: 'es',
189+
sourcemap: true
190+
}
191+
],
192+
plugins,
193+
external
194+
},
195+
{
196+
input: `firestore/index.cdn.ts`,
197+
output: createUmdOutputConfig(`firebase-firestore.js`),
198+
plugins: [
199+
...plugins,
200+
uglify({
201+
output: {
202+
ascii_only: true // escape unicode chars
203+
}
204+
})
205+
],
206+
external: ['@firebase/app']
207+
}
208+
];
209+
152210
const firestoreMemoryBuilds = [
153211
{
154212
input: `firestore/memory/index.ts`,
155213
output: [
156214
{
157-
file: resolve('firestore/memory', pkg.main),
215+
file: resolve('firestore/memory', firestoreMemoryPkg.main),
158216
format: 'cjs',
159217
sourcemap: true
160218
},
161219
{
162-
file: resolve('firestore/memory', pkg.module),
220+
file: resolve('firestore/memory', firestoreMemoryPkg.module),
163221
format: 'es',
164222
sourcemap: true
165223
}
@@ -168,7 +226,27 @@ const firestoreMemoryBuilds = [
168226
external
169227
},
170228
{
171-
input: `firestore/memory/index.ts`,
229+
input: `firestore/memory/bundle/index.ts`,
230+
output: [
231+
{
232+
file: resolve('firestore/memory/bundle', firestoreMemoryBundlePkg.main),
233+
format: 'cjs',
234+
sourcemap: true
235+
},
236+
{
237+
file: resolve(
238+
'firestore/memory/bundle',
239+
firestoreMemoryBundlePkg.module
240+
),
241+
format: 'es',
242+
sourcemap: true
243+
}
244+
],
245+
plugins,
246+
external
247+
},
248+
{
249+
input: `firestore/memory/index.cdn.ts`,
172250
output: createUmdOutputConfig(`firebase-firestore.memory.js`),
173251
plugins: [...plugins, uglify()],
174252
external: ['@firebase/app']
@@ -276,6 +354,7 @@ const completeBuilds = [
276354
export default [
277355
...appBuilds,
278356
...componentBuilds,
357+
...firestoreBuilds,
279358
...firestoreMemoryBuilds,
280359
...completeBuilds
281360
];

packages/firebase/src/index.cdn.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { name, version } from '../package.json';
3333
import '../auth';
3434
import '../database';
3535
import '../firestore';
36+
import '../firestore/bundle';
3637
import '../functions';
3738
import '../messaging';
3839
import '../storage';

0 commit comments

Comments
 (0)