Skip to content

Commit 045e4b5

Browse files
authored
Build and release Firestore compat (#4616)
* build firestore compat * save * various compat builds * update externs * create firestore-compat folder * publish firestore-compat * fix auth-compat build * abortOnError false * use the correct plugin * Fix order * fix script * fix typo * correct dist folder path * replace all * copy d.ts files * use regex * fix lint errors * address comments * remove bundle and memory builds * update release build * remove bundle build * remove dangling code * fix lint
1 parent ed4c96d commit 045e4b5

Some content is hidden

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

51 files changed

+838
-142
lines changed

packages-exp/auth-compat-exp/rollup.config.shared.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export function getEs5Builds(additionalTypescriptPlugins = {}) {
7575
extend: true,
7676
name: 'firebase',
7777
globals: {
78-
'@firebase/app-compat': 'firebase'
78+
'@firebase/app-compat': 'firebase',
79+
'@firebase/app': 'firebase.INTERNAL.modularAPIs'
7980
},
8081
/**
8182
* use iife to avoid below error in the old Safari browser
@@ -97,7 +98,7 @@ export function getEs5Builds(additionalTypescriptPlugins = {}) {
9798
}`
9899
},
99100
plugins: [...es5BuildPlugins, uglify()],
100-
external: ['@firebase/app-compat']
101+
external: ['@firebase/app-compat', '@firebase/app']
101102
}
102103
];
103104
}

packages/firestore/compat/bundle.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license
3+
* Copyright 2021 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 {
19+
loadBundle as expLoadBundle,
20+
namedQuery as expNamedQuery,
21+
LoadBundleTask
22+
} from '../exp/index';
23+
import { Firestore, Query } from '../src/api/database';
24+
25+
export function loadBundle(
26+
this: Firestore,
27+
data: ArrayBuffer | ReadableStream<Uint8Array> | string
28+
): LoadBundleTask {
29+
return expLoadBundle(this._delegate, data);
30+
}
31+
32+
export function namedQuery(
33+
this: Firestore,
34+
queryName: string
35+
): Promise<Query | null> {
36+
return expNamedQuery(this._delegate, queryName).then(expQuery => {
37+
if (!expQuery) {
38+
return null;
39+
}
40+
return new Query(
41+
this,
42+
// We can pass `expQuery` here directly since named queries don't have a UserDataConverter.
43+
// Otherwise, we would have to create a new ExpQuery and pass the old UserDataConverter.
44+
expQuery
45+
);
46+
});
47+
}
48+
49+
/**
50+
* Prototype patches bundle loading to Firestore.
51+
*/
52+
export function registerBundle(instance: typeof Firestore): void {
53+
instance.prototype.loadBundle = loadBundle;
54+
instance.prototype.namedQuery = namedQuery;
55+
}

packages/firestore/compat/config.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* @license
3+
* Copyright 2021 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+
// eslint-disable-next-line import/no-extraneous-dependencies
19+
import { FirebaseApp } from '@firebase/app-compat';
20+
import { FirebaseNamespace } from '@firebase/app-types';
21+
import { _FirebaseNamespace } from '@firebase/app-types/private';
22+
import { Component, ComponentType } from '@firebase/component';
23+
24+
import {
25+
FirebaseFirestore,
26+
CACHE_SIZE_UNLIMITED,
27+
FieldPath,
28+
GeoPoint,
29+
Timestamp,
30+
FieldValue
31+
} from '../exp/index'; // import from the exp public API
32+
import { Blob } from '../src/api/blob';
33+
import {
34+
Firestore,
35+
Transaction,
36+
CollectionReference,
37+
DocumentReference,
38+
DocumentSnapshot,
39+
Query,
40+
QueryDocumentSnapshot,
41+
QuerySnapshot,
42+
WriteBatch,
43+
setLogLevel
44+
} from '../src/api/database';
45+
46+
const firestoreNamespace = {
47+
Firestore,
48+
GeoPoint,
49+
Timestamp,
50+
Blob,
51+
Transaction,
52+
WriteBatch,
53+
DocumentReference,
54+
DocumentSnapshot,
55+
Query,
56+
QueryDocumentSnapshot,
57+
QuerySnapshot,
58+
CollectionReference,
59+
FieldPath,
60+
FieldValue,
61+
setLogLevel,
62+
CACHE_SIZE_UNLIMITED
63+
};
64+
65+
/**
66+
* Configures Firestore as part of the Firebase SDK by calling registerComponent.
67+
*
68+
* @param firebase - The FirebaseNamespace to register Firestore with
69+
* @param firestoreFactory - A factory function that returns a new Firestore
70+
* instance.
71+
*/
72+
export function configureForFirebase(
73+
firebase: FirebaseNamespace,
74+
firestoreFactory: (
75+
app: FirebaseApp,
76+
firestoreExp: FirebaseFirestore
77+
) => Firestore
78+
): void {
79+
(firebase as _FirebaseNamespace).INTERNAL.registerComponent(
80+
new Component(
81+
'firestore',
82+
container => {
83+
const app = container.getProvider('app-compat').getImmediate()!;
84+
const firestoreExp = container
85+
.getProvider('firestore-exp')
86+
.getImmediate()!;
87+
return firestoreFactory(app, firestoreExp);
88+
},
89+
ComponentType.PUBLIC
90+
).setServiceProps({ ...firestoreNamespace })
91+
);
92+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license
3+
* Copyright 2017 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+
// eslint-disable-next-line import/no-extraneous-dependencies
19+
import firebase from '@firebase/app-compat';
20+
import { FirebaseNamespace } from '@firebase/app-types';
21+
22+
import { name, version } from '../package.json';
23+
import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database';
24+
25+
import { registerBundle } from './bundle';
26+
import { configureForFirebase } from './config';
27+
28+
import '../register-module';
29+
30+
/**
31+
* Registers the main Firestore Node build with the components framework.
32+
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
33+
*/
34+
export function registerFirestore(instance: FirebaseNamespace): void {
35+
configureForFirebase(
36+
instance,
37+
(app, firestoreExp) =>
38+
new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider())
39+
);
40+
instance.registerVersion(name, version, 'node');
41+
}
42+
43+
registerFirestore((firebase as unknown) as FirebaseNamespace);
44+
registerBundle(Firestore);

packages/firestore/compat/index.rn.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
// eslint-disable-next-line import/no-extraneous-dependencies
19+
import firebase from '@firebase/app-compat';
20+
import { FirebaseNamespace } from '@firebase/app-types';
21+
22+
import { name, version } from '../package.json';
23+
import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database';
24+
25+
import { registerBundle } from './bundle';
26+
import { configureForFirebase } from './config';
27+
28+
import '../register-module';
29+
30+
/**
31+
* Registers the main Firestore ReactNative build with the components framework.
32+
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
33+
*/
34+
export function registerFirestore(instance: FirebaseNamespace): void {
35+
configureForFirebase(
36+
instance,
37+
(app, firestoreExp) =>
38+
new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider())
39+
);
40+
instance.registerVersion(name, version, 'rn');
41+
}
42+
43+
registerFirestore((firebase as unknown) as FirebaseNamespace);
44+
registerBundle(Firestore);

packages/firestore/compat/index.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
// eslint-disable-next-line import/no-extraneous-dependencies
19+
import firebase from '@firebase/app-compat';
20+
import { FirebaseNamespace } from '@firebase/app-types';
21+
22+
import { name, version } from '../package.json';
23+
import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database';
24+
25+
import { registerBundle } from './bundle';
26+
import { configureForFirebase } from './config';
27+
28+
import '../register-module';
29+
30+
/**
31+
* Registers the main Firestore build with the components framework.
32+
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
33+
*/
34+
export function registerFirestore(instance: FirebaseNamespace): void {
35+
configureForFirebase(
36+
instance,
37+
(app, firestoreExp) =>
38+
new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider())
39+
);
40+
instance.registerVersion(name, version);
41+
}
42+
43+
registerFirestore((firebase as unknown) as FirebaseNamespace);
44+
registerBundle(Firestore);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@firebase/firestore-compat",
3+
"version": "0.0.900",
4+
"description": "The Cloud Firestore component of the Firebase JS SDK.",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"main": "../dist/compat/node-cjs/index.js",
7+
"main-esm2017": "../dist/compat/node-esm2017/index.js",
8+
"react-native": "../dist/compat/rn/index.js",
9+
"browser": "../dist/compat/esm5/index.js",
10+
"module": "../dist/compat/esm5/index.js",
11+
"esm2017": "../dist/compat/esm2017/index.js",
12+
"license": "Apache-2.0",
13+
"typings": "../dist/compat/esm5/packages/firestore/compat/index.d.ts"
14+
}
15+

packages/firestore/exp/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export {
3434
terminate,
3535
useFirestoreEmulator,
3636
loadBundle,
37-
namedQuery
37+
namedQuery,
38+
ensureFirestoreConfigured
3839
} from '../src/exp/database';
3940

4041
export {
@@ -87,12 +88,11 @@ export {
8788
WhereFilterOp
8889
} from '../src/exp/query';
8990

90-
export { Unsubscribe } from '../src/exp/reference_impl';
91+
export { Unsubscribe, SnapshotListenOptions } from '../src/exp/reference_impl';
9192

9293
export { runTransaction, Transaction } from '../src/exp/transaction';
9394

9495
export {
95-
SnapshotListenOptions,
9696
getDoc,
9797
getDocFromCache,
9898
getDocFromServer,
@@ -104,7 +104,8 @@ export {
104104
setDoc,
105105
updateDoc,
106106
deleteDoc,
107-
addDoc
107+
addDoc,
108+
executeWrite
108109
} from '../src/exp/reference_impl';
109110

110111
export { FieldValue } from '../src/exp/field_value';
@@ -130,3 +131,5 @@ export { Timestamp } from '../src/exp/timestamp';
130131
export { CACHE_SIZE_UNLIMITED } from '../src/exp/database';
131132

132133
export { FirestoreErrorCode, FirestoreError } from '../src/util/error';
134+
135+
export { AbstractUserDataWriter } from '../src/lite/user_data_writer';

packages/firestore/externs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"packages/app-types/private.d.ts",
1717
"packages-exp/app-exp/dist/app-exp.d.ts",
1818
"packages/auth-interop-types/index.d.ts",
19-
"packages/firestore/dist/lite/index.d.ts",
20-
"packages/firestore/dist/exp/index.d.ts",
19+
"packages/firestore/dist/lite/internal.d.ts",
20+
"packages/firestore/dist/exp/internal.d.ts",
2121
"packages/firestore-types/index.d.ts",
2222
"packages/firebase/index.d.ts",
2323
"packages/component/dist/src/component.d.ts",

packages/firestore/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"prebuild": "tsc --emitDeclarationOnly --declaration -p tsconfig.json; yarn api-report",
1212
"build": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js' build:lite build:exp",
1313
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
14-
"prebuild:release": "yarn prebuild",
1514
"build:release": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js'",
1615
"build:deps": "lerna run --scope @firebase/firestore --include-dependencies build",
16+
"build:compat": "run-p 'bundle ./rollup.config.browser.compat.js' 'bundle ./rollup.config.node.compat.js' 'bundle ./rollup.config.rn.compat.js'",
1717
"build:console": "node tools/console.build.js",
1818
"build:exp": "rollup -c rollup.config.exp.js",
1919
"build:lite": "rollup -c rollup.config.lite.js",
20-
"build:exp:release": "yarn build:exp && yarn build:lite",
20+
"build:exp:release": "yarn build:exp && yarn build:lite && yarn build:compat",
2121
"postbuild:exp:release": "node ../../scripts/exp/remove-exp.js dist/exp/index.d.ts && node ../../scripts/exp/remove-exp.js dist/lite/index.d.ts",
2222
"build:browser": "rollup -c rollup.config.browser.js",
2323
"predev": "yarn prebuild",
@@ -104,7 +104,7 @@
104104
"bugs": {
105105
"url": "https://github.com/firebase/firebase-js-sdk/issues"
106106
},
107-
"typings": "dist/index.d.ts",
107+
"typings": "dist/firestore/index.d.ts",
108108
"nyc": {
109109
"extension": [
110110
".ts"

0 commit comments

Comments
 (0)